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