47 void DepthImage::fillDepthImageRaw(
unsigned width,
unsigned height,
unsigned short* depth_buffer,
unsigned line_step)
const throw (
OpenNIException)
49 if (width > depth_md_->XRes () || height > depth_md_->YRes ())
50 THROW_OPENNI_EXCEPTION (
"upsampling not supported: %d x %d -> %d x %d", depth_md_->XRes (), depth_md_->YRes (), width, height);
52 if (depth_md_->XRes () % width != 0 || depth_md_->YRes () % height != 0)
53 THROW_OPENNI_EXCEPTION (
"downsampling only supported for integer scale: %d x %d -> %d x %d", depth_md_->XRes (), depth_md_->YRes (), width, height);
56 line_step = width *
sizeof (
unsigned short);
59 if (width == depth_md_->XRes () && height == depth_md_->YRes () && (line_step == width *
sizeof (
unsigned short)))
61 memcpy (depth_buffer, depth_md_->WritableData(), depth_md_->DataSize ());
66 unsigned bufferSkip = line_step - width *
sizeof (
unsigned short);
69 unsigned xStep = depth_md_->XRes () / width;
70 unsigned ySkip = (depth_md_->YRes () / height - 1) * depth_md_->XRes ();
73 short bad_point = numeric_limits<short>::quiet_NaN ();
74 unsigned depthIdx = 0;
76 for (
unsigned yIdx = 0; yIdx < height; ++yIdx, depthIdx += ySkip)
78 for (
unsigned xIdx = 0; xIdx < width; ++xIdx, depthIdx += xStep, ++depth_buffer)
81 if ((*depth_md_)[depthIdx] == 0 ||
82 (*depth_md_)[depthIdx] == no_sample_value_ ||
83 (*depth_md_)[depthIdx] == shadow_value_)
84 *depth_buffer = bad_point;
87 *depth_buffer = (
unsigned short) (*depth_md_)[depthIdx];
93 char* cBuffer =
reinterpret_cast<char*
> (depth_buffer);
94 depth_buffer =
reinterpret_cast<unsigned short*
> (cBuffer + bufferSkip);
99 void DepthImage::fillDepthImage (
unsigned width,
unsigned height,
float* depth_buffer,
unsigned line_step)
const throw (
OpenNIException)
101 if (width > depth_md_->XRes () || height > depth_md_->YRes ())
102 THROW_OPENNI_EXCEPTION (
"upsampling not supported: %d x %d -> %d x %d", depth_md_->XRes (), depth_md_->YRes (), width, height);
104 if (depth_md_->XRes () % width != 0 || depth_md_->YRes () % height != 0)
105 THROW_OPENNI_EXCEPTION (
"downsampling only supported for integer scale: %d x %d -> %d x %d", depth_md_->XRes (), depth_md_->YRes (), width, height);
108 line_step = width *
sizeof (float);
111 unsigned bufferSkip = line_step - width *
sizeof (float);
114 unsigned xStep = depth_md_->XRes () / width;
115 unsigned ySkip = (depth_md_->YRes () / height - 1) * depth_md_->XRes();
118 float bad_point = numeric_limits<float>::quiet_NaN ();
119 unsigned depthIdx = 0;
121 for (
unsigned yIdx = 0; yIdx < height; ++yIdx, depthIdx += ySkip)
123 for (
unsigned xIdx = 0; xIdx < width; ++xIdx, depthIdx += xStep, ++depth_buffer)
126 if ((*depth_md_)[depthIdx] == 0 ||
127 (*depth_md_)[depthIdx] == no_sample_value_ ||
128 (*depth_md_)[depthIdx] == shadow_value_)
129 *depth_buffer = bad_point;
132 *depth_buffer = (float) (*depth_md_)[depthIdx] * 0.001f;
138 char* cBuffer =
reinterpret_cast<char*
> (depth_buffer);
139 depth_buffer =
reinterpret_cast<float*
> (cBuffer + bufferSkip);
144 void DepthImage::fillDisparityImage (
unsigned width,
unsigned height,
float* disparity_buffer,
unsigned line_step)
const throw (
OpenNIException)
146 if (width > depth_md_->XRes () || height > depth_md_->YRes ())
147 THROW_OPENNI_EXCEPTION (
"upsampling not supported: %d x %d -> %d x %d", depth_md_->XRes (), depth_md_->YRes (), width, height);
149 if (depth_md_->XRes () % width != 0 || depth_md_->YRes () % height != 0)
150 THROW_OPENNI_EXCEPTION (
"downsampling only supported for integer scale: %d x %d -> %d x %d", depth_md_->XRes (), depth_md_->YRes (), width, height);
153 line_step = width *
sizeof (float);
155 unsigned xStep = depth_md_->XRes () / width;
156 unsigned ySkip = (depth_md_->YRes () / height - 1) * depth_md_->XRes ();
158 unsigned bufferSkip = line_step - width *
sizeof (float);
163 float constant = focal_length_ * baseline_ * 1000.0 / (float) xStep;
165 for (
unsigned yIdx = 0, depthIdx = 0; yIdx < height; ++yIdx, depthIdx += ySkip)
167 for (
unsigned xIdx = 0; xIdx < width; ++xIdx, depthIdx += xStep, ++disparity_buffer)
169 if ((*depth_md_)[depthIdx] == 0 ||
170 (*depth_md_)[depthIdx] == no_sample_value_ ||
171 (*depth_md_)[depthIdx] == shadow_value_)
172 *disparity_buffer = 0.0;
174 *disparity_buffer = constant / (double) (*depth_md_)[depthIdx];
180 char* cBuffer =
reinterpret_cast<char*
> (disparity_buffer);
181 disparity_buffer =
reinterpret_cast<float*
> (cBuffer + bufferSkip);
#define THROW_OPENNI_EXCEPTION(format,...)