Example #1
0
OpenNIDevice::OpenNIDevice (xn::Context& context, const xn::NodeInfo& device_node, const xn::NodeInfo& image_node,
                            const xn::NodeInfo& depth_node) throw (OpenNIException)
: device_node_info_ (device_node)
, context_ (context)
, running_ (true) // Must be initialized before the threads!
, image_thread_ (&OpenNIDevice::ImageDataThreadFunction, this)
, depth_thread_ (&OpenNIDevice::DepthDataThreadFunction, this)
{
  // create the production nodes
  XnStatus status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(depth_node));
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating depth generator failed. Reason: %s", xnGetStatusString (status));

  status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(image_node));
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating image generator failed. Reason: %s", xnGetStatusString (status));

  // get production node instances
  status = depth_node.GetInstance (depth_generator_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating depth generator instance failed. Reason: %s", xnGetStatusString (status));

  status = image_node.GetInstance (image_generator_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating image generator instance failed. Reason: %s", xnGetStatusString (status));
}
Example #2
0
	XnMNodeInfo::XnMNodeInfo(xn::NodeInfo nodeInfo)
	{
		m_InstanceName = XnMHelper::CreateString(nodeInfo.GetInstanceName());
		m_CreationInfo = XnMHelper::CreateString(nodeInfo.GetCreationInfo()); 
		
		XnProductionNodeDescription desc = nodeInfo.GetDescription();
		m_Vendor = XnMHelper::CreateString(desc.strVendor);
		m_Name = XnMHelper::CreateString(desc.strName); 
		m_Type = (XnMProductionNodeType)desc.Type;
	}
//----------------------------------------------
bool myDepthGenerator::setup(xn::NodeInfo const& node, int num){
    if ( thisNum == 0) bDraw[thisNum] = true;
    
    depthMAX = 8000;
    depthMIN = 0;
    
    thisNum = num;
    XnStatus result = XN_STATUS_OK;
    result = node.GetInstance(depth_generator);
    if (result != XN_STATUS_OK) {
        ofLogError("myDepthGenerator.setup()", xnGetStatusString(result));
        return false;
    } else {
        depth_generator.SetMapOutputMode(out_put_modes);
        return true;
    }
    
    for (int i = 0; i < TOTAL_PIXEL; i++) {
        bgDepth[i] = depthMAX;
        bgDepthChar[i] = 0;
    }
    bgImg.allocate(CAPTURE_WIDTH, CAPTURE_HEIGHT, OF_IMAGE_GRAYSCALE);
    
    depthBgPixel.allocate(CAPTURE_WIDTH, CAPTURE_HEIGHT, 1);
    loadBgImage();
    vboMesh.setMode(OF_PRIMITIVE_POINTS);
    vboMesh.disableNormals();
    
}
XnStatus XnExportedSensorImageGenerator::IsSupportedForDevice(xn::Context& context, xn::NodeInfo& sensorInfo, XnBool* pbSupported)
{
	XnStatus nRetVal = XN_STATUS_OK;

	nRetVal = XnExportedSensorGenerator::IsSupportedForDevice(context, sensorInfo, pbSupported);
	XN_IS_STATUS_OK(nRetVal);

	if (*pbSupported == FALSE)
	{
		return XN_STATUS_OK;
	}

	xn::Device sensor;
	nRetVal = sensorInfo.GetInstance(sensor);
	XN_IS_STATUS_OK(nRetVal);

	XnUInt64 nImageSupported = FALSE;

	if (sensor.IsValid())
	{
		nRetVal = sensor.GetIntProperty(XN_MODULE_PROPERTY_IMAGE_SUPPORTED, nImageSupported);
		XN_IS_STATUS_OK(nRetVal);
	}
	else
	{
		// Don't create sensor through OpenNI. This will cause it to soft-reset.
		// instead, "talk" directly to the sensor class
		XnSensor lowLevelSensor(FALSE);
		XnDeviceConfig config;
		config.DeviceMode = XN_DEVICE_MODE_READ;
		config.cpConnectionString = sensorInfo.GetCreationInfo();
		config.SharingMode = XN_DEVICE_EXCLUSIVE;
		config.pInitialValues = NULL;
		nRetVal = lowLevelSensor.Init(&config);
		XN_IS_STATUS_OK(nRetVal);

		nRetVal = lowLevelSensor.GetProperty(XN_MODULE_NAME_DEVICE, XN_MODULE_PROPERTY_IMAGE_SUPPORTED, &nImageSupported);
		XN_IS_STATUS_OK(nRetVal);
	}

	if (nImageSupported != TRUE)
	{
		*pbSupported = FALSE;
	}

	return (XN_STATUS_OK);
}
//----------------------------------------------
bool myDepthGenerator::setup(xn::NodeInfo const& node, int num) {
    depthMIN = 10000;
    depthMAX = 0;
    xtionNum = num;
    XnStatus result = XN_STATUS_OK;
    result = node.GetInstance(depth_generator);
    if (result != XN_STATUS_OK) {
        ofLogError("myDepthGenerator.setup()", xnGetStatusString(result));
        return false;
    } else {
        depth_generator.SetMapOutputMode(out_put_modes);
        return true;
    }


}
Example #6
0
openni_wrapper::OpenNIDevice::OpenNIDevice (xn::Context& context, const xn::NodeInfo& device_node, const xn::NodeInfo& image_node, const xn::NodeInfo& depth_node, const xn::NodeInfo& ir_node) 
  : context_ (context),
    device_node_info_ (device_node)
{
  // This magic value is taken from a calibration routine.
  rgb_focal_length_SXGA_  = 1050;

// workaround for MAC from Alex Ichim
#ifdef __APPLE__
  XnStatus rc;

  xn::EnumerationErrors errors;
  rc = context_.InitFromXmlFile ("/etc/openni/SamplesConfig.xml", &errors);
  if (rc == XN_STATUS_NO_NODE_PRESENT)
  {
    XnChar strError[1024];
    errors.ToString(strError, 1024);
    printf ("%s\n", strError);
  }
  else if (rc != XN_STATUS_OK)
  {
    printf ("Open failed: %s\n", xnGetStatusString(rc));
  }

  XnStatus status = context_.FindExistingNode(XN_NODE_TYPE_DEPTH, depth_generator_);
  if (status != XN_STATUS_OK)
    cerr << "node depth problems" << endl;
  status = context_.FindExistingNode(XN_NODE_TYPE_IMAGE, image_generator_);
  if (status != XN_STATUS_OK)
    cerr << "node image problems" << endl;
  status = context_.FindExistingNode(XN_NODE_TYPE_IR, ir_generator_);
    if (status != XN_STATUS_OK)
      cerr << "node ir problems" << endl;

#else

#if (XN_MINOR_VERSION >= 3)
// create the production nodes
  XnStatus status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(depth_node), depth_generator_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating depth generator failed. Reason: %s", xnGetStatusString (status));

  status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(image_node), image_generator_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating image generator failed. Reason: %s", xnGetStatusString (status));

  status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(ir_node), ir_generator_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating IR generator failed. Reason: %s", xnGetStatusString (status));
#else
  XnStatus status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(depth_node));
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating depth generator failed. Reason: %s", xnGetStatusString (status));

  status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(image_node));
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating image generator failed. Reason: %s", xnGetStatusString (status));

  status = context_.CreateProductionTree (const_cast<xn::NodeInfo&>(ir_node));
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating IR generator failed. Reason: %s", xnGetStatusString (status));

  // get production node instances
  status = depth_node.GetInstance (depth_generator_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating depth generator instance failed. Reason: %s", xnGetStatusString (status));

  status = image_node.GetInstance (image_generator_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating image generator instance failed. Reason: %s", xnGetStatusString (status));

  status = ir_node.GetInstance (ir_generator_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("creating IR generator instance failed. Reason: %s", xnGetStatusString (status));
#endif // (XN_MINOR_VERSION >= 3)
  ir_generator_.RegisterToNewDataAvailable ((xn::StateChangedHandler)NewIRDataAvailable, this, ir_callback_handle_);
#endif // __APPLE__

  depth_generator_.RegisterToNewDataAvailable ((xn::StateChangedHandler)NewDepthDataAvailable, this, depth_callback_handle_);
  image_generator_.RegisterToNewDataAvailable ((xn::StateChangedHandler)NewImageDataAvailable, this, image_callback_handle_);

  Init ();
}
Example #7
0
std::string NodeInfo_GetCreationInfo_wrapped(xn::NodeInfo& self){
	return std::string(self.GetCreationInfo());
}
Example #8
0
std::string NodeInfo_GetInstanceName_wrapped(xn::NodeInfo& self){
	return std::string(self.GetInstanceName());
}
Example #9
0
XnVersion NodeInfo_GetVersion_wrapped(xn::NodeInfo& self){
	return self.GetDescription().Version;
}
Example #10
0
std::string NodeInfo_GetName_wrapped(xn::NodeInfo& self){
	return std::string(self.GetDescription().strName);
}
Example #11
0
std::string NodeInfo_GetVendor_wrapped(xn::NodeInfo& self){
	return std::string(self.GetDescription().strVendor);
}
Example #12
0
XnProductionNodeType NodeInfo_GetNodeType_wrapped(xn::NodeInfo& self){
	return self.GetDescription().Type;
}