1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
/*****************************************************************************
* *
* OpenNI 2.x Alpha *
* Copyright (C) 2012 PrimeSense Ltd. *
* *
* This file is part of OpenNI. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
*****************************************************************************/
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "XnOniDepthStream.h"
#include "../Sensor/XnSensorDepthStream.h"
//---------------------------------------------------------------------------
// XnOniDepthStream class
//---------------------------------------------------------------------------
XnOniDepthStream::XnOniDepthStream(XnSensor* pSensor, XnOniDevice* pDevice) :
XnOniMapStream(pSensor, XN_STREAM_TYPE_DEPTH, ONI_SENSOR_DEPTH, pDevice)
{
}
OniStatus XnOniDepthStream::getProperty(int propertyId, void* data, int* pDataSize)
{
switch (propertyId)
{
case ONI_STREAM_PROPERTY_MAX_VALUE:
if (*pDataSize != sizeof(int))
{
return ONI_STATUS_BAD_PARAMETER;
}
XnUInt64 nValue;
m_pSensor->GetProperty(m_strType, XN_STREAM_PROPERTY_DEVICE_MAX_DEPTH, &nValue);
*(int*)data = (int)nValue;
return ONI_STATUS_OK;
case ONI_STREAM_PROPERTY_MIN_VALUE:
if (*pDataSize != sizeof(int))
{
return ONI_STATUS_BAD_PARAMETER;
}
*(int*)data = 0;
return ONI_STATUS_OK;
case XN_STREAM_PROPERTY_DEPTH_SENSOR_CALIBRATION_INFO:
return ((XnSensorDepthStream*)m_pDeviceStream)->GetSensorCalibrationInfo(data, pDataSize);
default:
return XnOniMapStream::getProperty(propertyId, data, pDataSize);
}
}
OniBool XnOniDepthStream::isPropertySupported(int propertyId)
{
return (
propertyId == ONI_STREAM_PROPERTY_MAX_VALUE ||
propertyId == ONI_STREAM_PROPERTY_MIN_VALUE ||
propertyId == XN_STREAM_PROPERTY_DEPTH_SENSOR_CALIBRATION_INFO ||
XnOniMapStream::isPropertySupported(propertyId));
}
void XnOniDepthStream::notifyAllProperties()
{
XnOniMapStream::notifyAllProperties();
XnUInt32 nValue;
int size = sizeof(nValue);
// white balance
getProperty(XN_STREAM_PROPERTY_WHITE_BALANCE_ENABLED, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_WHITE_BALANCE_ENABLED, &nValue, size);
// gain
getProperty(XN_STREAM_PROPERTY_GAIN, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_GAIN, &nValue, size);
// hole filter
getProperty(XN_STREAM_PROPERTY_HOLE_FILTER, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_HOLE_FILTER, &nValue, size);
// registration type
getProperty(XN_STREAM_PROPERTY_REGISTRATION_TYPE, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_REGISTRATION_TYPE, &nValue, size);
// const shift
getProperty(XN_STREAM_PROPERTY_CONST_SHIFT, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_CONST_SHIFT, &nValue, size);
// pixel size factor
getProperty(XN_STREAM_PROPERTY_PIXEL_SIZE_FACTOR, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_PIXEL_SIZE_FACTOR, &nValue, size);
// max shift
getProperty(XN_STREAM_PROPERTY_MAX_SHIFT, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_MAX_SHIFT, &nValue, size);
// param coeff
getProperty(XN_STREAM_PROPERTY_PARAM_COEFF, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_PARAM_COEFF, &nValue, size);
// shift scale
getProperty(XN_STREAM_PROPERTY_SHIFT_SCALE, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_SHIFT_SCALE, &nValue, size);
// zero plane distance
getProperty(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, &nValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, &nValue, size);
XnDouble dValue;
size = sizeof(dValue);
// zero plane pixel size
getProperty(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, &dValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, &dValue, size);
// emitter/depth-cmos distance
getProperty(XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE, &dValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE, &dValue, size);
// depth-cmos/RGB-cmos distance
getProperty(XN_STREAM_PROPERTY_DCMOS_RCMOS_DISTANCE, &dValue, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_DCMOS_RCMOS_DISTANCE, &dValue, size);
XnSensorDepthStream* pDepthStream = (XnSensorDepthStream*)m_pDeviceStream;
// shift-to-depth table
raisePropertyChanged(XN_STREAM_PROPERTY_S2D_TABLE, pDepthStream->GetShiftToDepthTable(), sizeof(OniDepthPixel)*(pDepthStream->GetMaxShift()+1));
// depth-to-shift table
raisePropertyChanged(XN_STREAM_PROPERTY_D2S_TABLE, pDepthStream->GetDepthToShiftTable(), sizeof(XnUInt16)*(pDepthStream->GetDeviceMaxDepth()+1));
DepthUtilsSensorCalibrationInfo calibrationInfo;
size = sizeof(DepthUtilsSensorCalibrationInfo);
((XnSensorDepthStream*)m_pDeviceStream)->GetSensorCalibrationInfo(&calibrationInfo, &size);
raisePropertyChanged(XN_STREAM_PROPERTY_DEPTH_SENSOR_CALIBRATION_INFO, &calibrationInfo, size);
}
OniStatus XnOniDepthStream::convertDepthToColorCoordinates(StreamBase* colorStream, int depthX, int depthY, OniDepthPixel depthZ, int* pColorX, int* pColorY)
{
// take video mode from the color stream
XnOniMapStream* pColorStream = (XnOniMapStream*)colorStream;
OniVideoMode videoMode;
XnStatus retVal = pColorStream->GetVideoMode(&videoMode);
if (retVal != XN_STATUS_OK)
{
XN_ASSERT(FALSE);
return ONI_STATUS_ERROR;
}
// translate it to the internal property
XnPixelRegistration pixelArgs;
pixelArgs.nDepthX = depthX;
pixelArgs.nDepthY = depthY;
pixelArgs.nDepthValue = depthZ;
pixelArgs.nImageXRes = videoMode.resolutionX;
pixelArgs.nImageYRes = videoMode.resolutionY;
int pixelArgsSize = sizeof(pixelArgs);
if (ONI_STATUS_OK != getProperty(XN_STREAM_PROPERTY_PIXEL_REGISTRATION, &pixelArgs, &pixelArgsSize))
{
return ONI_STATUS_ERROR;
}
// take output
*pColorX = pixelArgs.nImageX;
*pColorY = pixelArgs.nImageY;
return ONI_STATUS_OK;
}
|