22 #include <config/config.h>
23 #include <plugins/openni/utils/setup.h>
38 std::string cfg_resolution = config->
get_string(
"/plugins/openni/resolution");
40 XnResolution res = XN_RES_VGA;
42 if (cfg_resolution ==
"QQVGA") {
44 }
else if (cfg_resolution ==
"CGA") {
46 }
else if (cfg_resolution ==
"QVGA") {
48 }
else if (cfg_resolution ==
"VGA") {
50 }
else if (cfg_resolution ==
"SVGA") {
52 }
else if (cfg_resolution ==
"XGA") {
54 }
else if (cfg_resolution ==
"720P") {
56 }
else if (cfg_resolution ==
"SXGA") {
58 }
else if (cfg_resolution ==
"UXGA") {
60 }
else if (cfg_resolution ==
"1080P") {
63 throw Exception(
"get_resolution(): Unknown resolution '%s'", cfg_resolution.c_str());
66 xn::Resolution resolution(res);
67 width = resolution.GetXResolution();
68 height = resolution.GetYResolution();
81 unsigned int width = 0, height = 0;
82 get_resolution(config, width, height);
83 unsigned int cfg_fps = config->
get_uint(
"/plugins/openni/fps");
85 XnMapOutputMode output_mode;
86 output_mode.nXRes = width;
87 output_mode.nYRes = height;
88 output_mode.nFPS = cfg_fps;
90 if ((st = generator.SetMapOutputMode(output_mode)) != XN_STATUS_OK) {
91 throw Exception(
"OpenNI: failed to set map output mode: %s", xnGetStatusString(st));
103 setup_alternate_viewpoint(xn::Generator &gen, xn::Generator &target)
105 if (gen.GetAlternativeViewPointCap().IsViewPointAs(target)) {
110 if (!gen.GetAlternativeViewPointCap().IsViewPointSupported(target)) {
111 throw Exception(
"Alternate viewpoint '%s' is not supported by %s",
116 XnStatus status = gen.GetAlternativeViewPointCap().SetViewPoint(target);
118 if (status != XN_STATUS_OK) {
119 throw Exception(
"Setting alternate viewpoint '%s' by %s failed: %s",
122 xnGetStatusString(status));
131 setup_synchronization(xn::Generator &gen, xn::Generator &target)
133 if (gen.GetFrameSyncCap().IsFrameSyncedWith(target)) {
137 if (!gen.IsCapabilitySupported(XN_CAPABILITY_FRAME_SYNC)) {
138 throw Exception(
"Generator '%s' does not support frame synchronization", gen.GetName());
141 if (!gen.GetFrameSyncCap().CanFrameSyncWith(target)) {
142 throw Exception(
"Generator '%s' cannot synchronize with '%s'", gen.GetName(), target.GetName());
145 XnStatus status = gen.GetFrameSyncCap().FrameSyncWith(target);
147 if (status != XN_STATUS_OK) {
148 throw Exception(
"Setting synchronization of '%s' with '%s' failed: %s",
151 xnGetStatusString(status));
162 get_usb_info(xn::Generator &gen,
unsigned short &vendor,
unsigned short &product)
164 xn::NodeInfo node_info = gen.GetInfo();
165 xn::NodeInfoList &depnodes = node_info.GetNeededNodes();
166 for (xn::NodeInfoList::Iterator n = depnodes.Begin(); n != depnodes.End(); ++n) {
167 const XnProductionNodeDescription &pnd = (*n).GetDescription();
169 if ((pnd.Type == XN_NODE_TYPE_DEVICE) && (strcmp(pnd.strVendor,
"PrimeSense") == 0)
170 && (strcmp(pnd.strName,
"SensorV2") == 0)) {
172 unsigned short int usb_vendor = 0, usb_product = 0;
173 unsigned char bus = 0, addr = 0;
175 (*n).GetCreationInfo(),
"%04hx/%04hx@%hhu/%hhu", &usb_vendor, &usb_product, &bus, &addr)
181 product = usb_product;
187 throw Exception(
"No matching device node found to retrieve USB info from");