XnStatus XnShiftToDepthStreamHelper::InitShiftToDepth() { XnStatus nRetVal = XN_STATUS_OK; // register to any shift-to-depth property (so tables can be updated if needed) const XnChar* propNames[] = { XN_STREAM_PROPERTY_MIN_DEPTH, XN_STREAM_PROPERTY_MAX_DEPTH, XN_STREAM_PROPERTY_CONST_SHIFT, XN_STREAM_PROPERTY_PIXEL_SIZE_FACTOR, XN_STREAM_PROPERTY_PARAM_COEFF, XN_STREAM_PROPERTY_SHIFT_SCALE, XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE }; XnUInt32 nPropCount = sizeof(propNames) / sizeof(const XnChar*); XnCallbackHandle hDummy; XnProperty* pProperty = NULL; for (XnUInt32 i = 0; i < nPropCount; ++i) { nRetVal = m_pModule->GetProperty(propNames[i], &pProperty); XN_IS_STATUS_OK(nRetVal); nRetVal = pProperty->OnChangeEvent().Register(ShiftToDepthPropertyValueChangedCallback, this, hDummy); XN_IS_STATUS_OK(nRetVal); } // register for tables size properties nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_MAX_SHIFT, &pProperty); XN_IS_STATUS_OK(nRetVal); nRetVal = pProperty->OnChangeEvent().Register(DeviceS2DTablesSizeChangedCallback, this, hDummy); XN_IS_STATUS_OK(nRetVal); nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_DEVICE_MAX_DEPTH, &pProperty); XN_IS_STATUS_OK(nRetVal); nRetVal = pProperty->OnChangeEvent().Register(DeviceS2DTablesSizeChangedCallback, this, hDummy); XN_IS_STATUS_OK(nRetVal); // now init the tables XnShiftToDepthConfig Config; nRetVal = GetShiftToDepthConfig(Config); XN_IS_STATUS_OK(nRetVal); nRetVal = XnShiftToDepthInit(&m_ShiftToDepthTables, &Config); XN_IS_STATUS_OK(nRetVal); // replace tables buffers m_ShiftToDepthTable.ReplaceBuffer(m_ShiftToDepthTables.pShiftToDepthTable, m_ShiftToDepthTables.nShiftsCount * sizeof(XnDepthPixel)); m_DepthToShiftTable.ReplaceBuffer(m_ShiftToDepthTables.pDepthToShiftTable, m_ShiftToDepthTables.nDepthsCount * sizeof(XnUInt16)); return (XN_STATUS_OK); }
XnStatus XnShiftToDepthStreamHelper::OnDeviceS2DTablesSizeChanged() { XnStatus nRetVal = XN_STATUS_OK; // free the tables, and re-init them XnShiftToDepthFree(&m_ShiftToDepthTables); XnShiftToDepthConfig Config; nRetVal = GetShiftToDepthConfig(Config); XN_IS_STATUS_OK(nRetVal); nRetVal = XnShiftToDepthInit(&m_ShiftToDepthTables, &Config); XN_IS_STATUS_OK(nRetVal); nRetVal = RaiseChangeEvents(); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnStatus XnShiftToDepthStreamHelper::OnDeviceS2DTablesSizeChanged() { XnStatus nRetVal = XN_STATUS_OK; // free the tables, and re-init them XnShiftToDepthFree(&m_ShiftToDepthTables); XnShiftToDepthConfig Config; nRetVal = GetShiftToDepthConfig(Config); XN_IS_STATUS_OK(nRetVal); nRetVal = XnShiftToDepthInit(&m_ShiftToDepthTables, &Config); XN_IS_STATUS_OK(nRetVal); // replace tables buffers m_ShiftToDepthTable.ReplaceBuffer(m_ShiftToDepthTables.pShiftToDepthTable, m_ShiftToDepthTables.nShiftsCount * sizeof(OniDepthPixel)); m_DepthToShiftTable.ReplaceBuffer(m_ShiftToDepthTables.pDepthToShiftTable, m_ShiftToDepthTables.nDepthsCount * sizeof(XnUInt16)); nRetVal = RaiseChangeEvents(); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnStatus XnShiftToDepthStreamHelper::InitShiftToDepth() { XnStatus nRetVal = XN_STATUS_OK; xnLogVerbose("S2D", "test1"); // register to any shift-to-depth property (so tables can be updated if needed) XnUInt32 propIds[] = { XN_STREAM_PROPERTY_MIN_DEPTH, XN_STREAM_PROPERTY_MAX_DEPTH, XN_STREAM_PROPERTY_CONST_SHIFT, XN_STREAM_PROPERTY_PIXEL_SIZE_FACTOR, XN_STREAM_PROPERTY_PARAM_COEFF, XN_STREAM_PROPERTY_SHIFT_SCALE, XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE, XN_STREAM_PROPERTY_OUTPUT_FORMAT, XN_STREAM_PROPERTY_CUSTOM_S2D_TABLE_ID }; xnLogVerbose("S2D", "test2"); XnUInt32 nPropCount = sizeof(propIds) / sizeof(propIds[0]); xnLogVerbose("S2D", "test3"); XnCallbackHandle hDummy; XnProperty* pProperty = NULL; for (XnUInt32 i = 0; i < nPropCount; ++i) { xnLogVerbose("S2D", "test4"); nRetVal = m_pModule->GetProperty(propIds[i], &pProperty); xnLogVerbose("S2D", "test5 %s", xnGetStatusString(nRetVal)); XN_IS_STATUS_OK(nRetVal); nRetVal = pProperty->OnChangeEvent().Register(ShiftToDepthPropertyValueChangedCallback, this, hDummy); XN_IS_STATUS_OK(nRetVal); xnLogVerbose("S2D", "test6"); } // XnUInt64 CustomTableID = ((XnActualIntProperty*)pProperty)->GetValue(); // xnLogVerbose("S2D", "S2D custom table ID: %d", CustomTableID); // register for tables size properties nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_MAX_SHIFT, &pProperty); XN_IS_STATUS_OK(nRetVal); nRetVal = pProperty->OnChangeEvent().Register(DeviceS2DTablesSizeChangedCallback, this, hDummy); XN_IS_STATUS_OK(nRetVal); nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_DEVICE_MAX_DEPTH, &pProperty); XN_IS_STATUS_OK(nRetVal); nRetVal = pProperty->OnChangeEvent().Register(DeviceS2DTablesSizeChangedCallback, this, hDummy); XN_IS_STATUS_OK(nRetVal); nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_OUTPUT_FORMAT, &pProperty); XN_IS_STATUS_OK(nRetVal); nRetVal = pProperty->OnChangeEvent().Register(DeviceS2DTablesSizeChangedCallback, this, hDummy); XN_IS_STATUS_OK(nRetVal); // now init the tables XnShiftToDepthConfig Config; nRetVal = GetShiftToDepthConfig(Config); XN_IS_STATUS_OK(nRetVal); nRetVal = XnShiftToDepthInit(&m_ShiftToDepthTables, &Config); XN_IS_STATUS_OK(nRetVal); // replace tables buffers m_ShiftToDepthTable.ReplaceBuffer(m_ShiftToDepthTables.pShiftToDepthTable, m_ShiftToDepthTables.nShiftsCount * sizeof(OniDepthPixel)); m_DepthToShiftTable.ReplaceBuffer(m_ShiftToDepthTables.pDepthToShiftTable, m_ShiftToDepthTables.nDepthsCount * sizeof(XnUInt16)); return (XN_STATUS_OK); }
XnStatus XnFileDevice::UpdateS2DTables(const xn::DepthGenerator& depth) { XnStatus nRetVal = XN_STATUS_OK; XnUInt64 nTemp; XnDouble dTemp; // get config XnShiftToDepthConfig config; nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, nTemp); XN_IS_STATUS_OK(nRetVal); config.nZeroPlaneDistance = (XnDepthPixel)nTemp; nRetVal = depth.GetRealProperty(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, dTemp); XN_IS_STATUS_OK(nRetVal); config.fZeroPlanePixelSize = (XnFloat)dTemp; nRetVal = depth.GetRealProperty(XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE, dTemp); XN_IS_STATUS_OK(nRetVal); config.fEmitterDCmosDistance = (XnFloat)dTemp; nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_MAX_SHIFT, nTemp); XN_IS_STATUS_OK(nRetVal); config.nDeviceMaxShiftValue = (XnUInt32)nTemp; config.nDeviceMaxDepthValue = depth.GetDeviceMaxDepth(); nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_CONST_SHIFT, nTemp); XN_IS_STATUS_OK(nRetVal); config.nConstShift = (XnUInt32)nTemp; nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_PIXEL_SIZE_FACTOR, nTemp); XN_IS_STATUS_OK(nRetVal); config.nPixelSizeFactor = (XnUInt32)nTemp; nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_PARAM_COEFF, nTemp); XN_IS_STATUS_OK(nRetVal); config.nParamCoeff = (XnUInt32)nTemp; nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_SHIFT_SCALE, nTemp); XN_IS_STATUS_OK(nRetVal); config.nShiftScale = (XnUInt32)nTemp; config.nDepthMinCutOff = 0; config.nDepthMaxCutOff = (XnDepthPixel)config.nDeviceMaxDepthValue; if (!m_ShiftToDepth.bIsInitialized) { nRetVal = XnShiftToDepthInit(&m_ShiftToDepth, &config); XN_IS_STATUS_OK(nRetVal); } else { nRetVal = XnShiftToDepthUpdate(&m_ShiftToDepth, &config); XN_IS_STATUS_OK(nRetVal); } // notify nRetVal = m_pNotifications->OnNodeGeneralPropChanged(m_pNotificationsCookie, depth.GetName(), XN_STREAM_PROPERTY_S2D_TABLE, m_ShiftToDepth.nShiftsCount * sizeof(XnDepthPixel), m_ShiftToDepth.pShiftToDepthTable); XN_IS_STATUS_OK(nRetVal); nRetVal = m_pNotifications->OnNodeGeneralPropChanged(m_pNotificationsCookie, depth.GetName(), XN_STREAM_PROPERTY_D2S_TABLE, m_ShiftToDepth.nDepthsCount * sizeof(XnUInt16), m_ShiftToDepth.pDepthToShiftTable); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }