Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * setup.h - OpenNI utility methods: setup routines 00004 * 00005 * Created: Thu Mar 24 10:21:31 2011 00006 * Copyright 2006-2011 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_OPENNI_UTILS_SETUP_H_ 00024 #define __PLUGINS_OPENNI_UTILS_SETUP_H_ 00025 00026 #include <core/exception.h> 00027 #include <core/utils/lockptr.h> 00028 00029 #include <XnCppWrapper.h> 00030 #include <string> 00031 00032 namespace fawkes { 00033 class Configuration; 00034 00035 namespace openni { 00036 #if 0 /* just to make Emacs auto-indent happy */ 00037 } 00038 } 00039 #endif 00040 00041 void get_resolution(fawkes::Configuration *config, 00042 unsigned int &width, unsigned int &height); 00043 00044 void setup_map_generator(xn::MapGenerator &generator, 00045 fawkes::Configuration *config); 00046 00047 void setup_alternate_viewpoint(xn::Generator &gen, xn::Generator &target); 00048 void setup_synchronization(xn::Generator &gen, xn::Generator &target); 00049 00050 /** Find existing or create new node. 00051 * This method will first try to find an existing node of the given type. 00052 * If this fails, it tries to create a new node of the desired type (leaving 00053 * the choice of the implementation to the system. 00054 * @param openni context to use, note that the context must have been locked 00055 * outside of this method call! 00056 * @param type node type 00057 * @param node instance that will be initialized for the node type 00058 * @exception Exception thrown if an error occurs while trying to find or 00059 * create the node. It may contain enumeration errors. 00060 */ 00061 template<class ProdNodeClass> 00062 void find_or_create_node(fawkes::LockPtr<xn::Context> &openni, 00063 XnProductionNodeType type, ProdNodeClass *node) 00064 { 00065 XnStatus st; 00066 if ((st = openni->FindExistingNode(type, *node)) != XN_STATUS_OK) { 00067 xn::EnumerationErrors errors; 00068 if (node->Create(*(openni.operator->()), 0, &errors) != XN_STATUS_OK) { 00069 fawkes::Exception e("Failed to create user generator (%s)", 00070 xnGetStatusString(st)); 00071 for (xn::EnumerationErrors::Iterator i = errors.Begin(); 00072 i != errors.End(); ++i) 00073 { 00074 XnProductionNodeDescription d = i.Description(); 00075 e.append("%s: %s/%s/%u.%u.%u.%u: %s", 00076 xnProductionNodeTypeToString(d.Type), 00077 d.strVendor, d.strName, d.Version.nMajor, d.Version.nMinor, 00078 d.Version.nMaintenance, d.Version.nBuild, 00079 xnGetStatusString(i.Error())); 00080 } 00081 00082 throw e; 00083 } 00084 } 00085 } 00086 00087 } // end namespace fawkes::openni 00088 } // end namespace fawkes 00089 00090 00091 00092 00093 00094 #endif