Beispiel #1
0
/**
 * @brief	Initializes the Scene Analyzer (_scene_analyzer).
 *
 * @retval	true if the Scene Analyzer was successfully created.
 * @retval	false if some error occurred.
 */
bool NIKinect::init_scene_analyzer(int index){
	static xn::NodeInfoList depth_nodes;
	XnStatus rc;
	rc = this->_context->EnumerateProductionTrees (XN_NODE_TYPE_SCENE, NULL, depth_nodes, NULL);

	int counter = 0;
	for (xn::NodeInfoList::Iterator nodeIt =depth_nodes.Begin(); nodeIt != depth_nodes.End(); ++nodeIt, counter++) {
		if(counter == 0){
			xn::NodeInfo info = *nodeIt;
			const XnProductionNodeDescription& description = info.GetDescription();

			rc = this->_context->CreateProductionTree (info);

			rc = info.GetInstance (this->_scene_analyzer);
		
			if (rc != XN_STATUS_OK)
			{
				printf("The Depth Node could not be created.%s\n",xnGetStatusString(rc));
				this->_flags[NIKinect::SCENE_A] = false;

			}
			else{
				this->_flags[NIKinect::SCENE_A] = true;
			}

			break;
		}
	}
	
	if(this->_flags[NIKinect::SCENE_A]){
		this->_scene_analyzer.GetMetaData(this->_scene_md);
	}

	//XnStatus rc = 1;
	////rc = _context->FindExistingNode(XN_NODE_TYPE_SCENE,this->_scene_analyzer);
	////If the generator was already created, don't create it again.
	//if (rc != XN_STATUS_OK)
	//{
	//	rc = _scene_analyzer.Create(_context);

	//	if (rc != XN_STATUS_OK)
	//	{
	//		printf("The Scene Analyzer Node could not be created.%s\n",xnGetStatusString(rc));
	//		this->_flags[NIKinect::SCENE_A] = false;
	//	}
	//	else{
	//		this->_flags[NIKinect::SCENE_A] = true;
	//	}
	//}
	//else{
	//	this->_flags[NIKinect::SCENE_A] = true;
	//}
	
	return this->_flags[NIKinect::SCENE_A];
}
XnStatus XnExportedSensorGenerator::EnumerateProductionTrees(xn::Context& context, xn::NodeInfoList& TreesList, xn::EnumerationErrors* pErrors)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnProductionNodeDescription Description;
	GetDescription(&Description);

	// perform a query to be sure the device we'll find is the same one exported from this DLL.
	xn::Query query;
	query.SetVendor(XN_VENDOR_PRIMESENSE);
	query.SetName(XN_DEVICE_NAME);
	query.SetMinVersion(Description.Version);
	query.SetMaxVersion(Description.Version);

	nRetVal = context.AutoEnumerateOverSingleInput(TreesList, Description, NULL, XN_NODE_TYPE_DEVICE, pErrors, &query);
	XN_IS_STATUS_OK(nRetVal);

	if (!m_bIsAvailableInLowBand)
	{
		xn::NodeInfoList::Iterator it = TreesList.Begin();
		while (it != TreesList.End())
		{
			xn::NodeInfoList::Iterator curr = it;
			it++;

			xn::NodeInfo node = *curr;

			// take sensor node
			xn::NodeInfo sensorNode = *node.GetNeededNodes().Begin();

			XnBool bIsLowBand;
			nRetVal = XnSensorIO::IsSensorLowBandwidth(sensorNode.GetCreationInfo(), &bIsLowBand);
			XN_IS_STATUS_OK(nRetVal);

			if (bIsLowBand)
			{
				// sensor is low band
				nRetVal = TreesList.Remove(curr);
				XN_IS_STATUS_OK(nRetVal);
			}
		}

		if (TreesList.IsEmpty())
		{
			return XN_STATUS_NO_NODE_PRESENT;
		}
	}
	
	return (XN_STATUS_OK);
}
XnStatus XnExportedFileDevice::EnumerateProductionTrees(xn::Context& context, xn::NodeInfoList& TreesList, xn::EnumerationErrors* pErrors)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	XnProductionNodeDescription Description;
	GetDescription(&Description);
	nRetVal = TreesList.Add(Description, NULL, NULL);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
Beispiel #4
0
XnStatus ExportedRecorder::EnumerateProductionTrees(xn::Context& context, xn::NodeInfoList& TreesList, xn::EnumerationErrors* pErrors)
{
	XnProductionNodeDescription description;
	XnStatus nRetVal = XN_STATUS_OK;
	
	GetDescription(&description);
	nRetVal = TreesList.Add(description, CREATION_INFO, NULL);
	XN_IS_STATUS_OK(nRetVal);
		
	return XN_STATUS_OK;
}
XnStatus ExportedSampleDepth::EnumerateProductionTrees( xn::Context& context, xn::NodeInfoList& TreesList, xn::EnumerationErrors* pErrors )
{
	XnStatus nRetVal = XN_STATUS_OK;

	// return one option
	XnProductionNodeDescription desc;
	GetDescription(&desc);

	nRetVal = TreesList.Add(desc, NULL, NULL);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
XnStatus XnExportedSensorDevice::EnumerateProductionTrees(xn::Context& context, xn::NodeInfoList& TreesList, xn::EnumerationErrors* /*pErrors*/)
{
	XnStatus nRetVal = XN_STATUS_OK;

	// enumerate connected sensors
	XnUInt32 nCount = 0;

	// check if sensor is connected
	nRetVal = XnSensor::Enumerate(NULL, &nCount);
	if (nRetVal != XN_STATUS_OUTPUT_BUFFER_OVERFLOW)
	{
		// no sensor connected
		return XN_STATUS_DEVICE_NOT_CONNECTED;
	}

	// allocate according to count
	XnConnectionString* pConnStrings;
	XN_VALIDATE_CALLOC(pConnStrings, XnConnectionString, nCount);

	nRetVal = XnSensor::Enumerate(pConnStrings, &nCount);
	if (nRetVal != XN_STATUS_OK)
	{
		xnOSFree(pConnStrings);
		return (nRetVal);
	}

	XnProductionNodeDescription Description;
	GetDescription(&Description);

	for (XnUInt32 i = 0; i < nCount; ++i)
	{
		// Each connection string is a sensor. Return it if it wasn't created already.
		if (FindCreatedDevice(context.GetUnderlyingObject(), pConnStrings[i]) == m_createdDevices.End())
		{
			nRetVal = TreesList.Add(Description, pConnStrings[i], NULL);
			if (nRetVal != XN_STATUS_OK)
			{
				xnOSFree(pConnStrings);
				return (nRetVal);
			}
		}
	}

	xnOSFree(pConnStrings);
	return (XN_STATUS_OK);
}
XnStatus XnExportedSensorDevice::EnumerateProductionTrees(xn::Context& context, xn::NodeInfoList& TreesList, xn::EnumerationErrors* pErrors)
{
	XnStatus nRetVal = XN_STATUS_OK;

	// enumerate connected sensors
	XnUInt32 nCount = 0;

	// check if sensor is connected
	nRetVal = XnSensor::Enumerate(NULL, &nCount);
	if (nRetVal != XN_STATUS_OUTPUT_BUFFER_OVERFLOW)
	{
		// no sensor connected
		XN_LOG_WARNING_RETURN(XN_STATUS_DEVICE_NOT_CONNECTED, XN_MASK_DEVICE_SENSOR, "No PS sensor is connected!");
	}

	// allocate according to count
	XnConnectionString* pConnStrings;
	XN_VALIDATE_CALLOC(pConnStrings, XnConnectionString, nCount);

	nRetVal = XnSensor::Enumerate(pConnStrings, &nCount);
	if (nRetVal != XN_STATUS_OK)
	{
		xnOSFree(pConnStrings);
		return (nRetVal);
	}

	XnProductionNodeDescription Description;
	GetDescription(&Description);

	// each connection string is a sensor. return it
	for (XnUInt32 i = 0; i < nCount; ++i)
	{
		nRetVal = TreesList.Add(Description, pConnStrings[i], NULL);
		if (nRetVal != XN_STATUS_OK)
		{
			xnOSFree(pConnStrings);
			return (nRetVal);
		}
	}

	xnOSFree(pConnStrings);

	return (XN_STATUS_OK);
}
int userTracker::enumerate(xn::Context context, XnPredefinedProductionNodeType type, xn::NodeInfoList& list, std::string infoMsg) {
	//std::cout << "Enumerating " << infoMsg << endl;
	
	XnStatus status = context.EnumerateProductionTrees (type, NULL, list, NULL);

	if (status != XN_STATUS_OK && list.Begin () != list.End ()) { 
		std::cout << "Enumerating " << infoMsg << " failed. Reason: " <<  xnGetStatusString (status) << std::endl; 
		return -1;
	}
	else if (list.Begin () == list.End ()) {
		std::cout << "No " << infoMsg << " found." << std::endl;
		return -1;
	}

	int numNodes = 0;
	for (xn::NodeInfoList::Iterator nodeIt = list.Begin (); nodeIt != list.End (); ++nodeIt, numNodes++) {
		const xn::NodeInfo& info = *nodeIt;
		const XnProductionNodeDescription& description = info.GetDescription();
		printf("device %d vendor %s name %s, instance %s\n", numNodes, description.strVendor, description.strName, info.GetInstanceName());
	}

	//std::cout << "Finishing enumerating: " << infoMsg << endl;
	return numNodes;
}
Beispiel #9
0
XnStatus XnXmlScriptNode::Run(xn::NodeInfoList& createdNodes, xn::EnumerationErrors& errors)
{
	return RunXmlScriptImpl(m_context.GetUnderlyingObject(), &m_doc, createdNodes.GetUnderlyingObject(), errors.GetUnderlying());
}
Beispiel #10
0
unsigned 
openni_wrapper::OpenNIDriver::updateDeviceList ()
{
  // clear current list of devices
  device_context_.clear ();
  // clear maps
  bus_map_.clear ();
  serial_map_.clear ();
  connection_string_map_.clear ();

  // enumerate all devices
  static xn::NodeInfoList node_info_list;
  XnStatus status = context_.EnumerateProductionTrees (XN_NODE_TYPE_DEVICE, NULL, node_info_list);
  if (status != XN_STATUS_OK && node_info_list.Begin () != node_info_list.End ())
    THROW_OPENNI_EXCEPTION ("enumerating devices failed. Reason: %s", xnGetStatusString (status));
  else if (node_info_list.Begin () == node_info_list.End ())
    return 0; // no exception

  for (xn::NodeInfoList::Iterator nodeIt = node_info_list.Begin (); nodeIt != node_info_list.End (); ++nodeIt)
  {
    connection_string_map_[(*nodeIt).GetCreationInfo ()] = static_cast<unsigned int> (device_context_.size ());
    device_context_.emplace_back(*nodeIt);
  }

  // enumerate depth nodes
  static xn::NodeInfoList depth_nodes;
  status = context_.EnumerateProductionTrees (XN_NODE_TYPE_DEPTH, NULL, depth_nodes, NULL);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("enumerating depth generators failed. Reason: %s", xnGetStatusString (status));

  for (xn::NodeInfoList::Iterator nodeIt = depth_nodes.Begin (); nodeIt != depth_nodes.End (); ++nodeIt)
  {
    // check if to which device this node is assigned to
    for (xn::NodeInfoList::Iterator neededIt = (*nodeIt).GetNeededNodes ().Begin (); neededIt != (*nodeIt).GetNeededNodes ().End (); ++neededIt)
    {
      if ( connection_string_map_.count ((*neededIt).GetCreationInfo ()) )
      {
        unsigned device_index = connection_string_map_[(*neededIt).GetCreationInfo ()];
        device_context_[device_index].depth_node.reset (new xn::NodeInfo(*nodeIt));
      }
    }
  }

  // enumerate image nodes
  static xn::NodeInfoList image_nodes;
  status = context_.EnumerateProductionTrees (XN_NODE_TYPE_IMAGE, NULL, image_nodes, NULL);


  // Suat: This is an ugly ASUS Xtion workaround.
  if (status == XN_STATUS_OK)
  {
    //THROW_OPENNI_EXCEPTION ("enumerating image generators failed. Reason: %s", xnGetStatusString (status));

    for (xn::NodeInfoList::Iterator nodeIt = image_nodes.Begin (); nodeIt != image_nodes.End (); ++nodeIt)
    {
      // check to which device this node is assigned to
      for (xn::NodeInfoList::Iterator neededIt = (*nodeIt).GetNeededNodes ().Begin (); neededIt != (*nodeIt).GetNeededNodes ().End (); ++neededIt)
      {
        if ( connection_string_map_.count ((*neededIt).GetCreationInfo ()) )
        {
          unsigned device_index = connection_string_map_[(*neededIt).GetCreationInfo ()];
          device_context_[device_index].image_node.reset (new xn::NodeInfo(*nodeIt));
        }
      }
    }
  }

  // enumerate IR nodes
  static xn::NodeInfoList ir_nodes;
  status = context_.EnumerateProductionTrees (XN_NODE_TYPE_IR, NULL, ir_nodes, NULL);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("enumerating IR generators failed. Reason: %s", xnGetStatusString (status));

  for (xn::NodeInfoList::Iterator nodeIt = ir_nodes.Begin (); nodeIt != ir_nodes.End (); ++nodeIt)
  {
    // check if to which device this node is assigned to
    for (xn::NodeInfoList::Iterator neededIt = (*nodeIt).GetNeededNodes ().Begin (); neededIt != (*nodeIt).GetNeededNodes ().End (); ++neededIt)
    {
      if ( connection_string_map_.count ((*neededIt).GetCreationInfo ()) )
      {
        unsigned device_index = connection_string_map_[(*neededIt).GetCreationInfo ()];
        device_context_[device_index].ir_node.reset (new xn::NodeInfo(*nodeIt));
      }
    }
  }

#ifndef _WIN32
  // add context object for each found device
  for (size_t deviceIdx = 0; deviceIdx < device_context_.size (); ++deviceIdx)
  {
    // register bus@address to the corresponding context object
    unsigned short vendor_id;
    unsigned short product_id;
    unsigned char bus;
    unsigned char address;
    sscanf (device_context_[deviceIdx].device_node.GetCreationInfo (), "%hx/%hx@%hhu/%hhu", &vendor_id, &product_id, &bus, &address);
    bus_map_ [bus][address] = deviceIdx;
  }

  // get additional info about connected devices like serial number, vendor name and prduct name
  getDeviceInfos ();
#endif
  // build serial number -> device index map
  for (size_t deviceIdx = 0; deviceIdx < device_context_.size (); ++deviceIdx)
  {
    std::string serial_number = getSerialNumber (deviceIdx);
    if (!serial_number.empty ())
      serial_map_[serial_number] = deviceIdx;
  }


  // redundant, but needed for Windows right now and also for Xtion
  for (const auto &device : device_context_)
  {
    unsigned short product_id;
    unsigned short vendor_id;

    getDeviceType(device.device_node.GetCreationInfo (), vendor_id, product_id );

#if _WIN32
    if (vendor_id == 0x45e)
    {
      strcpy (const_cast<char*> (device_context_[device].device_node.GetDescription ().strVendor), "Microsoft");
      strcpy (const_cast<char*> (device_context_[device].device_node.GetDescription ().strName), "Xbox NUI Camera");
    }
    else
#endif
    if (vendor_id == 0x1d27 && device.image_node.get () == 0)
    {
      strcpy (const_cast<char*> (device.device_node.GetDescription ().strVendor), "ASUS");
      strcpy (const_cast<char*> (device.device_node.GetDescription ().strName), "Xtion Pro");
    }
  }
  return (static_cast<unsigned int> (device_context_.size ()));
}
Beispiel #11
0
XnStatus XnExportedSensorImageGenerator::EnumerateProductionTrees(xn::Context& context, xn::NodeInfoList& TreesList, xn::EnumerationErrors* pErrors)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	nRetVal = XnExportedSensorGenerator::EnumerateProductionTrees(context, TreesList, pErrors);
	XN_IS_STATUS_OK(nRetVal);

	XnStringToBoolHash Devices;

	// make sure device has image CMOS
	xn::NodeInfoList::Iterator it = TreesList.Begin();
	while (it != TreesList.End())
	{
		xn::NodeInfoList::Iterator curr = it;
		it++;

		xn::NodeInfo node = *curr;

		// take sensor node
		xn::NodeInfo sensorNode = *node.GetNeededNodes().Begin();

		XnBool bHasImageCMOS = TRUE;

		if (XN_STATUS_OK != Devices.Get(sensorNode.GetCreationInfo(), bHasImageCMOS))
		{
			// wasn't checked yet. check it now
			xn::Device sensor;
			nRetVal = sensorNode.GetInstance(sensor);
			XN_IS_STATUS_OK(nRetVal);

			XnBool bShouldCreated = (!sensor.IsValid());

			if (bShouldCreated)
			{
				nRetVal = context.CreateProductionTree(sensorNode);
				XN_IS_STATUS_OK(nRetVal);

				nRetVal = sensorNode.GetInstance(sensor);
				XN_IS_STATUS_OK(nRetVal);
			}

			// This is an ugly patch to find out if this sensor has an image CMOS. It will be fixed
			// in future firmwares so we can just ask.
			XnCmosBlankingUnits units;
			units.nCmosID = XN_CMOS_TYPE_IMAGE;
			nRetVal = sensor.GetGeneralProperty(XN_MODULE_PROPERTY_CMOS_BLANKING_UNITS, sizeof(units), &units);
			if (nRetVal != XN_STATUS_OK || units.nUnits == 0)
			{
				// Failed. this means no image CMOS
				bHasImageCMOS = FALSE;
			}

			if (bShouldCreated)
			{
				sensor.Release();
			}

			// add to checked list
			Devices.Set(sensorNode.GetCreationInfo(), bHasImageCMOS);
		}

		if (!bHasImageCMOS)
		{
			// remove it from enumeration
			nRetVal = TreesList.Remove(curr);
			XN_IS_STATUS_OK(nRetVal);
		}
	}

	if (TreesList.IsEmpty())
	{
		return XN_STATUS_NO_NODE_PRESENT;
	}
	
	return (XN_STATUS_OK);
}
Beispiel #12
0
/**
 * @brief	Initializes the Image Generator (_image_generator).
 *
 * @retval	true if the generator was successfully created.
 * @retval	false if some error occurred.
 */
bool NIKinect::init_image_generator(int index){
	static xn::NodeInfoList image_nodes;
	XnStatus rc;
	rc = this->_context->EnumerateProductionTrees (XN_NODE_TYPE_IMAGE, NULL, image_nodes, NULL);

	int counter = 0;
	for (xn::NodeInfoList::Iterator nodeIt =image_nodes.Begin(); nodeIt != image_nodes.End(); ++nodeIt, counter++) {
		if(counter == 0){
			xn::NodeInfo info = *nodeIt;
			const XnProductionNodeDescription& description = info.GetDescription();

			rc = this->_context->CreateProductionTree (info);

			this->_image_generator = new xn::ImageGenerator();
			rc = info.GetInstance (*this->_image_generator);
		
			if (rc != XN_STATUS_OK)
			{
				printf("The Depth Node could not be created.%s\n",xnGetStatusString(rc));
				this->_flags[NIKinect::IMAGE_G] = false;
				this->_flags_processing[NIKinect::IMAGE_P] = false;

			}
			else{
				this->_flags[NIKinect::IMAGE_G] = true;
				this->_flags_processing[NIKinect::IMAGE_P] = true;
			}

			this->_image_generator->SetMapOutputMode(_image_mode);
			//this->_image_generator->GetMetaData(this->_image_md);
			this->_image_generator->StartGenerating();

			break;
		}
	}

	if(this->_flags[NIKinect::IMAGE_G]){
		this->_image_generator->GetMetaData(this->_image_md);	
		//if(this->_flags[NIKinect::DEPTH_G]){
		//	this->_depth_generator->GetAlternativeViewPointCap().SetViewPoint(*this->_image_generator);
		//}
	}

	//XnStatus rc;
	//rc = _context->FindExistingNode(XN_NODE_TYPE_IMAGE,this->_image_generator);
	////If the generator was already created, don't create it again.
	//if (rc != XN_STATUS_OK)
	//{
	//	rc = _image_generator->Create(_context);

	//	if (rc != XN_STATUS_OK)
	//	{
	//		printf("The Image Node could not be created.%s\n",xnGetStatusString(rc));
	//		this->_flags[NIKinect::IMAGE_G] = false;
	//		this->_flags_processing[NIKinect::IMAGE_P] = false;
	//	}
	//	else{
	//		this->_flags[NIKinect::IMAGE_G] = true;
	//		this->_flags_processing[NIKinect::IMAGE_P] = true;
	//	}
	//}
	//else{
	//	this->_flags[NIKinect::IMAGE_G] = true;
	//	this->_flags_processing[NIKinect::IMAGE_P] = true;
	//}

	//if(this->_flags[NIKinect::IMAGE_G]){
	//	this->_image_generator->GetMetaData(this->_image_md);		
	//	this->_depth_generator->GetAlternativeViewPointCap().SetViewPoint(this->_image_generator);
	//}

	return this->_flags[NIKinect::IMAGE_G];
}
Beispiel #13
0
/**
 * @brief	Initializes the Depth Generator (_depth_generator).
 *
 * @retval	true if the generator was successfully created.
 * @retval	false if some error occurred.
 */
bool NIKinect::init_depth_generator(int index){
	static xn::NodeInfoList depth_nodes;
	XnStatus rc;
	rc = this->_context->EnumerateProductionTrees (XN_NODE_TYPE_DEPTH, NULL, depth_nodes, NULL);

	int counter = 0;
	for (xn::NodeInfoList::Iterator nodeIt =depth_nodes.Begin(); nodeIt != depth_nodes.End(); ++nodeIt, counter++) {
		if(counter == index){
			xn::NodeInfo info = *nodeIt;
			const XnProductionNodeDescription& description = info.GetDescription();
	
			XnMapOutputMode mode;
			mode.nXRes	= 640;
			mode.nYRes	= 480;
			mode.nFPS	= 30;

			rc = this->_context->CreateProductionTree (info);
		
			this->_depth_generator = new xn::DepthGenerator();
			//DepthMetaData* g_depthMD = new DepthMetaData();

			rc = info.GetInstance (*this->_depth_generator);
		
			if (rc != XN_STATUS_OK)
			{
				printf("The Depth Node could not be created.%s\n",xnGetStatusString(rc));
				this->_flags[NIKinect::DEPTH_G] = false;
				this->_flags_processing[NIKinect::DEPTH_P] = false;
				this->_flags_processing[NIKinect::MASK_P] = false;

			}
			else{
				this->_flags[NIKinect::DEPTH_G] = true;
				this->_flags_processing[NIKinect::DEPTH_P] = true;
				this->_flags_processing[NIKinect::MASK_P] = true;
			}

			this->_depth_generator->SetMapOutputMode(mode);
			//this->_depth_generator->GetMetaData(this->_depth_md);
			this->_depth_generator->StartGenerating();

			break;
		}
	}

	if(this->_flags[NIKinect::DEPTH_G]){
		this->_depth_generator->GetMetaData(this->_depth_md);
	}

	//rc = _context->FindExistingNode(XN_NODE_TYPE_DEPTH,this->_depth_generator);
	////If the generator was already created, don't create it again.
	//if (rc != XN_STATUS_OK)
	//{
	//	rc = _depth_generator->Create(_context);

	//	if (rc != XN_STATUS_OK)
	//	{
	//		printf("The Depth Node could not be created.%s\n",xnGetStatusString(rc));
	//		this->_flags[NIKinect::DEPTH_G] = false;
	//		this->_flags_processing[NIKinect::DEPTH_P] = false;
	//		this->_flags_processing[NIKinect::MASK_P] = false;

	//	}
	//	else{
	//		this->_flags[NIKinect::DEPTH_G] = true;
	//		this->_flags_processing[NIKinect::DEPTH_P] = true;
	//		this->_flags_processing[NIKinect::MASK_P] = true;
	//	}
	//}
	//else{
	//	this->_flags[NIKinect::DEPTH_G] = true;
	//	this->_flags_processing[NIKinect::DEPTH_P] = true;
	//	this->_flags_processing[NIKinect::MASK_P] = true;
	//}

	return this->_flags[NIKinect::DEPTH_G];
}
// most code came from: http://groups.google.com/group/openni-dev/browse_thread/thread/cde3217c242a3687/3c1463337f6f2951?lnk=gst&q=multiple#3c1463337f6f2951
void MultipleKinects::init() {
	printf("MultipleKinects.init()\n");

	XnStatus returnCode;

	printf("Initializing context ...\n");
	returnCode = this->context.Init();
	if(returnCode != XN_STATUS_OK) { THROW_XN_EXCEPTION("Initialisation failed!", returnCode); }

	printf("Looking for connected devices...\n");
	static xn::NodeInfoList deviceInfoList;
	returnCode = this->context.EnumerateProductionTrees(XN_NODE_TYPE_DEVICE, NULL, deviceInfoList);
	if(returnCode != XN_STATUS_OK) { THROW_XN_EXCEPTION("Enumerating device nodes failed!", returnCode); }

	if(deviceInfoList.Begin() == deviceInfoList.End()) {
		std::string errorMsg = "Device node list is empty! (Probably no devices connected?!)";
		throw errorMsg;
	}
	std::vector<xn::NodeInfo> deviceInfos;
	int c = 0; // i'd like to have a "c++" ;)
	for (xn::NodeInfoList::Iterator it = deviceInfoList.Begin(); it != deviceInfoList.End(); ++it) {
		deviceInfos.push_back(*it);
		c++; // yeah!!! :)))
	}
	printf("Connected devices: %i\n", c);

//	printf("Looking for available depth generators...\n");
//	static xn::NodeInfoList depth_nodes;
//	status = context_.EnumerateProductionTrees (XN_NODE_TYPE_DEPTH, NULL, depth_nodes, NULL);
//	if(returnCode != XN_STATUS_OK) { THROW_XN_EXCEPTION("Enumerating depth generator nodes failed!", returnCode); }
//	vector<xn::NodeInfo> depth_info;
//	for (xn::NodeInfoList::Iterator nodeIt = depth_nodes.Begin (); nodeIt != depth_nodes.End (); ++nodeIt) {
//		depth_info.push_back (*nodeIt);
//	}

	printf("Looking for available image generators...\n");
	static xn::NodeInfoList imageInfoList;
	returnCode = this->context.EnumerateProductionTrees(XN_NODE_TYPE_IMAGE, NULL,imageInfoList, NULL);
	if(returnCode != XN_STATUS_OK) { THROW_XN_EXCEPTION("Enumerating image nodes failed!", returnCode); }

	std::vector<xn::NodeInfo> imageInfos;
	for (xn::NodeInfoList::Iterator it = imageInfoList.Begin(); it != imageInfoList.End(); ++it) {
		imageInfos.push_back(*it);
	}

	if(deviceInfos.size() != imageInfos.size() /* || dev.size != depth.size */) {
		std::string errorMsg = "Number of devices does not match number of image streams!";
		throw errorMsg;
	}

	for (unsigned i = 0; i < deviceInfos.size(); i++) {
		printf("Processing device number %i#.\n", (i+1));
		xn::NodeInfo deviceInfo = deviceInfos[i];
		xn::NodeInfo imageInfo = imageInfos[i];

	//	returnCode = this->context.CreateProductionTree(const_cast<xn::NodeInfo&>(deviceInfo));
	//	if(returnCode != XN_STATUS_OK) { THROW_XN_EXCEPTION("Creating depth generator failed!", returnCode); }

		printf("Creating image generator production node...\n");
		returnCode = this->context.CreateProductionTree(const_cast<xn::NodeInfo&>(imageInfo));
		if(returnCode != XN_STATUS_OK) { THROW_XN_EXCEPTION("Creating image generator instance failed!", returnCode); }

		// get production node instances
	//	returnCode = depth_node.GetInstance(depth_generator_);
	//	if(returnCode != XN_STATUS_OK) { THROW_XN_EXCEPTION("Creating depth generator instance failed!", returnCode); }

		xn::ImageGenerator imageGenerator;
		returnCode = imageInfo.GetInstance (imageGenerator);
		if(returnCode != XN_STATUS_OK) { THROW_XN_EXCEPTION("Creating image generator instance failed!", returnCode); }

		NiDevice* device = new NiDevice(deviceInfo, imageInfo, imageGenerator, this->imageSaver);
		device->printToString();
		device->init();
		this->devices.push_back(device);
	}
}