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
31namespace fawkes {
32class Configuration;
33
34namespace openni {
35
36void get_resolution(fawkes::Configuration *config, unsigned int &width, unsigned int &height);
37
38void setup_map_generator(xn::MapGenerator &generator, fawkes::Configuration *config);
39
40void setup_alternate_viewpoint(xn::Generator &gen, xn::Generator &target);
41void setup_synchronization(xn::Generator &gen, xn::Generator &target);
42
43void get_usb_info(xn::Generator &gen, unsigned short &vendor, unsigned short &product);
44
45/** Find existing or create new node.
46 * This method will first try to find an existing node of the given type.
47 * If this fails, it tries to create a new node of the desired type (leaving
48 * the choice of the implementation to the system.
49 * @param openni context to use, note that the context must have been locked
50 * outside of this method call!
51 * @param type node type
52 * @param node instance that will be initialized for the node type
53 * @exception Exception thrown if an error occurs while trying to find or
54 * create the node. It may contain enumeration errors.
55 */
56template <class ProdNodeClass>
57void
58find_or_create_node(fawkes::LockPtr<xn::Context> &openni,
59 XnProductionNodeType type,
60 ProdNodeClass * node)
61{
62 XnStatus st;
63 if ((st = openni->FindExistingNode(type, *node)) != XN_STATUS_OK) {
64 xn::EnumerationErrors errors;
65 if (node->Create(*(openni.operator->()), 0, &errors) != XN_STATUS_OK) {
66 fawkes::Exception e("Failed to create user generator (%s)", xnGetStatusString(st));
67 for (xn::EnumerationErrors::Iterator i = errors.Begin(); i != errors.End(); ++i) {
68 XnProductionNodeDescription d = i.Description();
69 e.append("%s: %s/%s/%u.%u.%u.%u: %s",
70 xnProductionNodeTypeToString(d.Type),
71 d.strVendor,
72 d.strName,
73 d.Version.nMajor,
74 d.Version.nMinor,
75 d.Version.nMaintenance,
76 d.Version.nBuild,
77 xnGetStatusString(i.Error()));
78 }
79
80 throw e;
81 }
82 }
83}
84
85} // namespace openni
86} // end namespace fawkes
87
88#endif
Interface for configuration handling.
Definition: config.h:68
Base class for exceptions in Fawkes.
Definition: exception.h:36
Fawkes library namespace.