66 inline uint16_t getUint16(
const uint8_t *p,
bool bigendian,
size_t i)
73 ret=
static_cast<uint16_t
>(((p[j]<<8)|p[j+1]));
78 ret=
static_cast<uint16_t
>(((p[j+1]<<8)|p[j]));
87 std::shared_ptr<const Image>
left,
88 std::shared_ptr<const Image> disp,
89 std::shared_ptr<const Image> conf,
90 std::shared_ptr<const Image> error)
94 size_t width=disp->getWidth();
95 size_t height=disp->getHeight();
96 bool bigendian=disp->isBigEndian();
97 size_t ds=(left->getWidth()+disp->getWidth()-1)/disp->getWidth();
105 const uint8_t *dps=disp->getPixels();
106 size_t dstep=disp->getWidth()*
sizeof(uint16_t)+disp->getXPadding();
112 const uint32_t vinvalid=0xffffffff;
113 std::vector<uint32_t> vindex(width*height);
116 for (
size_t k=0; k<height; k++)
119 for (
size_t i=0; i<width; i++)
122 if ((dps[j]|dps[j+1]) != 0) vindex[vi]=n++;
131 dps=disp->getPixels();
135 const uint16_t vstep=
static_cast<uint16_t
>(std::ceil(2/scale));
138 for (
size_t k=1; k<height; k++)
140 for (
size_t i=1; i<width; i++)
143 v[0]=getUint16(dps, bigendian, i-1);
144 v[1]=getUint16(dps, bigendian, i);
145 v[2]=getUint16(dps+dstep, bigendian, i-1);
146 v[3]=getUint16(dps+dstep, bigendian, i);
152 for (
int jj=0; jj<4; jj++)
156 vmin=std::min(vmin, v[jj]);
157 vmax=std::max(vmax, v[jj]);
162 if (valid >= 3 && vmax-vmin <= vstep)
171 dps=disp->getPixels();
175 const uint8_t *cps=0, *eps=0;
176 size_t cstep=0, estep=0;
180 cps=conf->getPixels();
181 cstep=conf->getWidth()*
sizeof(uint8_t)+conf->getXPadding();
186 eps=error->getPixels();
187 estep=error->getWidth()*
sizeof(uint8_t)+error->getXPadding();
192 if (name.size() == 0)
195 double timestamp=left->getTimestampNS()/1000000000.0;
196 os <<
"rc_visard_" << std::setprecision(16) << timestamp <<
".ply";
200 std::ofstream out(name);
202 out <<
"ply" << std::endl;
203 out <<
"format ascii 1.0" << std::endl;
204 out <<
"comment Created with gc_pointcloud from Roboception GmbH" << std::endl;
205 out <<
"comment Camera [1 0 0; 0 1 0; 0 0 1] [0 0 0]" << std::endl;
206 out <<
"element vertex " << n << std::endl;
207 out <<
"property float32 x" << std::endl;
208 out <<
"property float32 y" << std::endl;
209 out <<
"property float32 z" << std::endl;
210 out <<
"property float32 scan_size" << std::endl;
214 out <<
"property float32 scan_conf" << std::endl;
219 out <<
"property float32 scan_error" << std::endl;
222 out <<
"property uint8 diffuse_red" << std::endl;
223 out <<
"property uint8 diffuse_green" << std::endl;
224 out <<
"property uint8 diffuse_blue" << std::endl;
225 out <<
"element face " << tn << std::endl;
226 out <<
"property list uint8 uint32 vertex_indices" << std::endl;
227 out <<
"end_header" << std::endl;
231 for (
size_t k=0; k<height; k++)
233 for (
size_t i=0; i<width; i++)
237 double d=scale*getUint16(dps, bigendian, i);
245 double x=(i+0.5-0.5*width)*t/d;
246 double y=(k+0.5-0.5*height)*t/d;
251 double x2=(i-0.5*width)*t/d;
257 getColor(rgb, left, static_cast<uint32_t>(ds), static_cast<uint32_t>(i),
258 static_cast<uint32_t>(k));
262 out << x <<
" " << y <<
" " << z <<
" " << size <<
" ";
266 out << cps[i]/255.0 <<
" ";
271 out << eps[i]*scale*f*t/(d*d) <<
" ";
274 out << static_cast<int>(rgb[0]) <<
" ";
275 out << static_cast<int>(rgb[1]) <<
" ";
276 out << static_cast<int>(rgb[2]) << std::endl;
285 dps=disp->getPixels();
289 uint32_t *ips=vindex.data();
290 for (
size_t k=1; k<height; k++)
292 for (
size_t i=1; i<width; i++)
295 v[0]=getUint16(dps, bigendian, i-1);
296 v[1]=getUint16(dps, bigendian, i);
297 v[2]=getUint16(dps+dstep, bigendian, i-1);
298 v[3]=getUint16(dps+dstep, bigendian, i);
304 for (
int jj=0; jj<4; jj++)
308 vmin=std::min(vmin, v[jj]);
309 vmax=std::max(vmax, v[jj]);
314 if (valid >= 3 && vmax-vmin <= vstep)
319 if (ips[i-1] != vinvalid)
324 if (ips[width+i-1] != vinvalid)
326 fc[j++]=ips[width+i-1];
329 if (ips[width+i] != vinvalid)
331 fc[j++]=ips[width+i];
334 if (ips[i] != vinvalid)
339 out <<
"3 " << fc[0] <<
' ' << fc[1] <<
' ' << fc[2] << std::endl;
343 out <<
"3 " << fc[2] <<
' ' << fc[3] <<
' ' << fc[0] << std::endl;
void storePointCloud(std::string name, double f, double t, double scale, std::shared_ptr< const Image > left, std::shared_ptr< const Image > disp, std::shared_ptr< const Image > conf, std::shared_ptr< const Image > error)
LOG4CPP_EXPORT CategoryStream & left(CategoryStream &os)
left manipulator
void getColor(uint8_t rgb[3], const std::shared_ptr< const Image > &img, uint32_t ds, uint32_t i, uint32_t k)
Expects an image in Mono8 or YCbCr411_8 format and returns the color as RGB value at the given pixel ...