22 #include <plugins/openni/utils/setup.h> 23 #include <config/config.h> 40 unsigned int &width,
unsigned int &height)
43 std::string cfg_resolution = config->
get_string(
"/plugins/openni/resolution");
45 XnResolution res = XN_RES_VGA;
47 if (cfg_resolution ==
"QQVGA") {
49 }
else if (cfg_resolution ==
"CGA") {
51 }
else if (cfg_resolution ==
"QVGA") {
53 }
else if (cfg_resolution ==
"VGA") {
55 }
else if (cfg_resolution ==
"SVGA") {
57 }
else if (cfg_resolution ==
"XGA") {
59 }
else if (cfg_resolution ==
"720P") {
61 }
else if (cfg_resolution ==
"SXGA") {
63 }
else if (cfg_resolution ==
"UXGA") {
65 }
else if (cfg_resolution ==
"1080P") {
68 throw Exception(
"get_resolution(): Unknown resolution '%s'",
69 cfg_resolution.c_str());
72 xn::Resolution resolution(res);
73 width = resolution.GetXResolution();
74 height = resolution.GetYResolution();
86 setup_map_generator(xn::MapGenerator &generator,
89 unsigned int width = 0, height = 0;
90 get_resolution(config, width, height);
91 unsigned int cfg_fps = config->
get_uint(
"/plugins/openni/fps");
93 XnMapOutputMode output_mode;
94 output_mode.nXRes = width;
95 output_mode.nYRes = height;
96 output_mode.nFPS = cfg_fps;
98 if ((st = generator.SetMapOutputMode(output_mode)) != XN_STATUS_OK) {
99 throw Exception(
"OpenNI: failed to set map output mode: %s",
100 xnGetStatusString(st));
113 setup_alternate_viewpoint(xn::Generator &gen, xn::Generator &target)
115 if (gen.GetAlternativeViewPointCap().IsViewPointAs(target)) {
120 if (! gen.GetAlternativeViewPointCap().IsViewPointSupported(target)) {
121 throw Exception(
"Alternate viewpoint '%s' is not supported by %s",
122 target.GetName(), gen.GetName());
125 XnStatus status = gen.GetAlternativeViewPointCap().SetViewPoint(target);
127 if (status != XN_STATUS_OK) {
128 throw Exception(
"Setting alternate viewpoint '%s' by %s failed: %s",
129 target.GetName(), gen.GetName(), xnGetStatusString(status));
139 setup_synchronization(xn::Generator &gen, xn::Generator &target)
141 if (gen.GetFrameSyncCap().IsFrameSyncedWith(target)) {
145 if (! gen.IsCapabilitySupported(XN_CAPABILITY_FRAME_SYNC)) {
146 throw Exception(
"Generator '%s' does not support frame synchronization",
150 if (! gen.GetFrameSyncCap().CanFrameSyncWith(target)) {
151 throw Exception(
"Generator '%s' cannot synchronize with '%s'",
152 gen.GetName(), target.GetName());
155 XnStatus status = gen.GetFrameSyncCap().FrameSyncWith(target);
157 if (status != XN_STATUS_OK) {
158 throw Exception(
"Setting synchronization of '%s' with '%s' failed: %s",
159 target.GetName(), gen.GetName(), xnGetStatusString(status));
170 get_usb_info(xn::Generator &gen,
unsigned short &vendor,
unsigned short &product)
172 xn::NodeInfo node_info = gen.GetInfo();
173 xn::NodeInfoList &depnodes = node_info.GetNeededNodes();
174 for (xn::NodeInfoList::Iterator n = depnodes.Begin(); n != depnodes.End(); ++n) {
175 const XnProductionNodeDescription &pnd = (*n).GetDescription();
177 if ((pnd.Type == XN_NODE_TYPE_DEVICE) &&
178 (strcmp(pnd.strVendor,
"PrimeSense") == 0) &&
179 (strcmp(pnd.strName,
"SensorV2") == 0) )
182 unsigned short int usb_vendor = 0, usb_product = 0;
183 unsigned char bus = 0, addr = 0;
184 if (sscanf((*n).GetCreationInfo(),
"%04hx/%04hx@%hhu/%hhu",
185 &usb_vendor, &usb_product, &bus, &addr) == 4) {
190 product = usb_product;
196 throw Exception(
"No matching device node found to retrieve USB info from");
Fawkes library namespace.
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
Interface for configuration handling.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.