| 254 | } |
| 255 | |
| 256 | void |
| 257 | pcl::io::DepthImage::fillDisparityImage (unsigned width, unsigned height, float* disparity_buffer, unsigned line_step) const |
| 258 | { |
| 259 | if (width > wrapper_->getWidth () || height > wrapper_->getHeight ()) |
| 260 | THROW_IO_EXCEPTION ("upsampling not supported: %d x %d -> %d x %d", wrapper_->getWidth (), wrapper_->getHeight (), width, height); |
| 261 | |
| 262 | if (wrapper_->getWidth () % width != 0 || wrapper_->getHeight () % height != 0) |
| 263 | THROW_IO_EXCEPTION ("downsampling only supported for integer scale: %d x %d -> %d x %d", wrapper_->getWidth (), wrapper_->getHeight (), width, height); |
| 264 | |
| 265 | if (line_step == 0) |
| 266 | line_step = width * static_cast<unsigned> (sizeof (float)); |
| 267 | |
| 268 | unsigned xStep = wrapper_->getWidth () / width; |
| 269 | unsigned ySkip = (wrapper_->getHeight () / height - 1) * wrapper_->getWidth (); |
| 270 | |
| 271 | unsigned bufferSkip = line_step - width * static_cast<unsigned> (sizeof (float)); |
| 272 | |
| 273 | // Fill in the depth image data |
| 274 | // iterate over all elements and fill disparity matrix: disp[x,y] = f * b / z_distance[x,y]; |
| 275 | // focal length is for the native image resolution -> focal_length = focal_length_ / xStep; |
| 276 | float constant = focal_length_ * baseline_ * 1000.0f / static_cast<float> (xStep); |
| 277 | |
| 278 | const auto* inputBuffer = static_cast<const unsigned short*> (wrapper_->getData ()); |
| 279 | |
| 280 | for (unsigned yIdx = 0, depthIdx = 0; yIdx < height; ++yIdx, depthIdx += ySkip) |
| 281 | { |
| 282 | for (unsigned xIdx = 0; xIdx < width; ++xIdx, depthIdx += xStep, ++disparity_buffer) |
| 283 | { |
| 284 | unsigned short pixel = inputBuffer[depthIdx]; |
| 285 | if (pixel == 0 || pixel == no_sample_value_ || pixel == shadow_value_) |
| 286 | *disparity_buffer = 0.0; |
| 287 | else |
| 288 | *disparity_buffer = constant / static_cast<float> (pixel); |
| 289 | } |
| 290 | |
| 291 | // if we have padding |
| 292 | if (bufferSkip > 0) |
| 293 | { |
| 294 | char* cBuffer = reinterpret_cast<char*> (disparity_buffer); |
| 295 | disparity_buffer = reinterpret_cast<float*> (cBuffer + bufferSkip); |
| 296 | } |
| 297 | } |
| 298 | } |