15 #ifndef VISIONTRANSFER_RECONSTRUCT3D_OPEN3D_H
16 #define VISIONTRANSFER_RECONSTRUCT3D_OPEN3D_H
20 namespace visiontransfer {
28 const ImageSet& imageSet, ColorSource colSource,
unsigned short minDisparity,
unsigned short maxDisparity) {
30 int numPoints = imageSet.getWidth() * imageSet.getHeight();
31 std::shared_ptr<open3d::geometry::PointCloud> ret(
new open3d::geometry::PointCloud());
34 ret->points_.resize(numPoints);
36 float* points =
createPointMap(imageSet, minDisparity, maxDisparity);
37 float* end = &points[4*numPoints];
38 Eigen::Vector3d* dest = &ret->points_[0];
40 while(points != end) {
41 float x = *(points++);
42 float y = *(points++);
43 float z = *(points++);
46 *dest = Eigen::Vector3d(x, y, z);
53 if(colSource !=
COLOR_NONE && imageSet.hasImageType(colImg)) {
54 ret->colors_.resize(numPoints);
55 unsigned char* pixel = imageSet.getPixelData(colImg);
56 Eigen::Vector3d* color = &ret->colors_[0];
57 Eigen::Vector3d* colorEnd = &ret->colors_[numPoints];
59 switch(imageSet.getPixelFormat(colImg)) {
61 while(color != colorEnd) {
62 double col = double(*(pixel++))/0xFF;
63 *(color++) = Eigen::Vector3d(col, col, col);
67 while(color != colorEnd) {
68 double col = double(*
reinterpret_cast<unsigned short*
>(pixel))/0xFFF;
70 *(color++) = Eigen::Vector3d(col, col, col);
74 while(color != colorEnd) {
75 double r = double(*(pixel++))/0xFF;
76 double g = double(*(pixel++))/0xFF;
77 double b = double(*(pixel++))/0xFF;
78 *(color++) = Eigen::Vector3d(r, g, b);
81 default:
throw std::runtime_error(
"Illegal pixel format");
89 ColorSource colSource,
unsigned short minDisparity) {
91 std::shared_ptr<open3d::geometry::RGBDImage> ret(
new open3d::geometry::RGBDImage);
94 ret->depth_.width_ = imageSet.getWidth();
95 ret->depth_.height_ = imageSet.getHeight();
96 ret->depth_.num_of_channels_ = 1;
97 ret->depth_.bytes_per_channel_ =
sizeof(float);
98 ret->depth_.data_.resize(ret->depth_.width_*ret->depth_.height_*ret->depth_.bytes_per_channel_);
101 memcpy(&ret->depth_.data_[0], zMap, ret->depth_.data_.size());
104 ret->color_.width_ = imageSet.getWidth();
105 ret->color_.height_ = imageSet.getHeight();
106 ret->color_.num_of_channels_ = 3;
107 ret->color_.bytes_per_channel_ = 1;
108 ret->color_.data_.resize(ret->color_.width_ * ret->color_.height_ *
109 ret->color_.num_of_channels_ * ret->color_.bytes_per_channel_);
113 unsigned char* srcPixel = imageSet.getPixelData(colImg);
114 unsigned char* dstPixel = &ret->color_.data_[0];
115 unsigned char* dstEnd = &ret->color_.data_[ret->color_.data_.size()];
117 switch(imageSet.getPixelFormat(colImg)) {
119 while(dstPixel != dstEnd) {
120 *(dstPixel++) = *srcPixel;
121 *(dstPixel++) = *srcPixel;
122 *(dstPixel++) = *(srcPixel++);
126 while(dstPixel != dstEnd) {
127 unsigned short pixel16Bit = *
reinterpret_cast<unsigned short*
>(srcPixel);
128 unsigned char pixel8Bit = pixel16Bit / 0xF;
131 *(dstPixel++) = pixel8Bit;
132 *(dstPixel++) = pixel8Bit;
133 *(dstPixel++) = pixel8Bit;
137 memcpy(&ret->color_.data_[0], srcPixel, ret->color_.data_.size());
139 default:
throw std::runtime_error(
"Illegal pixel format");