Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
setup.h
1 
2 /***************************************************************************
3  * setup.h - OpenNI utility methods: setup routines
4  *
5  * Created: Thu Mar 24 10:21:31 2011
6  * Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __PLUGINS_OPENNI_UTILS_SETUP_H_
24 #define __PLUGINS_OPENNI_UTILS_SETUP_H_
25 
26 #include <core/exception.h>
27 #include <core/utils/lockptr.h>
28 
29 #include <XnCppWrapper.h>
30 #include <string>
31 
32 namespace fawkes {
33  class Configuration;
34 
35  namespace openni {
36 #if 0 /* just to make Emacs auto-indent happy */
37  }
38 }
39 #endif
40 
41 void get_resolution(fawkes::Configuration *config,
42  unsigned int &width, unsigned int &height);
43 
44 void setup_map_generator(xn::MapGenerator &generator,
45  fawkes::Configuration *config);
46 
47 void setup_alternate_viewpoint(xn::Generator &gen, xn::Generator &target);
48 void setup_synchronization(xn::Generator &gen, xn::Generator &target);
49 
50 /** Find existing or create new node.
51  * This method will first try to find an existing node of the given type.
52  * If this fails, it tries to create a new node of the desired type (leaving
53  * the choice of the implementation to the system.
54  * @param openni context to use, note that the context must have been locked
55  * outside of this method call!
56  * @param type node type
57  * @param node instance that will be initialized for the node type
58  * @exception Exception thrown if an error occurs while trying to find or
59  * create the node. It may contain enumeration errors.
60  */
61 template<class ProdNodeClass>
62 void find_or_create_node(fawkes::LockPtr<xn::Context> &openni,
63  XnProductionNodeType type, ProdNodeClass *node)
64 {
65  XnStatus st;
66  if ((st = openni->FindExistingNode(type, *node)) != XN_STATUS_OK) {
67  xn::EnumerationErrors errors;
68  if (node->Create(*(openni.operator->()), 0, &errors) != XN_STATUS_OK) {
69  fawkes::Exception e("Failed to create user generator (%s)",
70  xnGetStatusString(st));
71  for (xn::EnumerationErrors::Iterator i = errors.Begin();
72  i != errors.End(); ++i)
73  {
74  XnProductionNodeDescription d = i.Description();
75  e.append("%s: %s/%s/%u.%u.%u.%u: %s",
76  xnProductionNodeTypeToString(d.Type),
77  d.strVendor, d.strName, d.Version.nMajor, d.Version.nMinor,
78  d.Version.nMaintenance, d.Version.nBuild,
79  xnGetStatusString(i.Error()));
80  }
81 
82  throw e;
83  }
84  }
85 }
86 
87 } // end namespace fawkes::openni
88 } // end namespace fawkes
89 
90 
91 
92 
93 
94 #endif