33 #include <pdal/io/BufferReader.hpp> 34 #include <pdal/StageFactory.hpp> 35 #include <pdal/PluginManager.hpp> 37 #ifdef RTABMAP_PDAL_16 38 #include <pdal/pdal_defines.h> 40 #include <pdal/pdal_features.hpp> 49 #if PDAL_VERSION_MAJOR>1 || (PDAL_VERSION_MAJOR == 1 && PDAL_VERSION_MINOR > 7) || (PDAL_VERSION_MAJOR == 1 && PDAL_VERSION_MINOR == 7 && PDAL_VERSION_MINOR>=1) 51 pdal::PluginManager<pdal::Stage>::loadAll();
52 pdal::StringList stages = pdal::PluginManager<pdal::Stage>::names();
54 pdal::StageFactory f(
false);
55 pdal::StringList stages = pdal::PluginManager::names(PF_PluginType_Writer);
57 for(pdal::StringList::iterator iter=stages.begin(); iter!=stages.end(); ++iter)
63 if(iter->compare(
"writers.null") == 0)
67 if(iter!=stages.begin())
77 const pcl::PointCloud<pcl::PointXYZ> & cloud,
78 const std::vector<int> & cameraIds,
81 UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
82 uFormat(
"cameraIds=%d cloud=%d", (
int)cameraIds.size(), (int)cloud.size()).c_str());
84 pdal::PointTable table;
86 if(!cameraIds.empty())
88 table.layout()->registerDims({
89 pdal::Dimension::Id::X,
90 pdal::Dimension::Id::Y,
91 pdal::Dimension::Id::Z,
92 pdal::Dimension::Id::PointSourceId});
96 table.layout()->registerDims({
97 pdal::Dimension::Id::X,
98 pdal::Dimension::Id::Y,
99 pdal::Dimension::Id::Z});
101 pdal::BufferReader bufferReader;
103 pdal::PointViewPtr view(
new pdal::PointView(table));
104 for(
size_t i=0; i<cloud.size(); ++i)
106 view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
107 view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
108 view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
109 if(!cameraIds.empty())
111 view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
114 bufferReader.addView(view);
116 pdal::StageFactory factory;
118 pdal::Stage *writer = factory.createStage(
"writers." + ext);
121 pdal::Options writerOps;
122 writerOps.add(
"filename", filePath);
123 if(ext.compare(
"ply")==0) writerOps.add(
"storage_mode", binary?
"little endian":
"ascii");
124 if(ext.compare(
"pcd")==0) writerOps.add(
"compression", binary?
"binary":
"ascii");
126 writer->setOptions(writerOps);
127 writer->setInput(bufferReader);
129 writer->prepare(table);
130 writer->execute(table);
134 UERROR(
"PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
144 const pcl::PointCloud<pcl::PointXYZRGB> & cloud,
145 const std::vector<int> & cameraIds,
147 const std::vector<float> & intensities)
149 UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
150 uFormat(
"cameraIds=%d cloud=%d", (
int)cameraIds.size(), (int)cloud.size()).c_str());
151 UASSERT_MSG(intensities.empty() || intensities.size() == cloud.size(),
152 uFormat(
"intensities=%d cloud=%d", (
int)intensities.size(), (int)cloud.size()).c_str());
154 pdal::PointTable table;
156 if(!intensities.empty() && !cameraIds.empty())
158 table.layout()->registerDims({
159 pdal::Dimension::Id::X,
160 pdal::Dimension::Id::Y,
161 pdal::Dimension::Id::Z,
162 pdal::Dimension::Id::Red,
163 pdal::Dimension::Id::Green,
164 pdal::Dimension::Id::Blue,
165 pdal::Dimension::Id::PointSourceId,
166 pdal::Dimension::Id::Intensity});
168 else if(!intensities.empty())
170 table.layout()->registerDims({
171 pdal::Dimension::Id::X,
172 pdal::Dimension::Id::Y,
173 pdal::Dimension::Id::Z,
174 pdal::Dimension::Id::Red,
175 pdal::Dimension::Id::Green,
176 pdal::Dimension::Id::Blue,
177 pdal::Dimension::Id::Intensity});
179 else if(!cameraIds.empty())
181 table.layout()->registerDims({
182 pdal::Dimension::Id::X,
183 pdal::Dimension::Id::Y,
184 pdal::Dimension::Id::Z,
185 pdal::Dimension::Id::Red,
186 pdal::Dimension::Id::Green,
187 pdal::Dimension::Id::Blue,
188 pdal::Dimension::Id::PointSourceId});
192 table.layout()->registerDims({
193 pdal::Dimension::Id::X,
194 pdal::Dimension::Id::Y,
195 pdal::Dimension::Id::Z,
196 pdal::Dimension::Id::Red,
197 pdal::Dimension::Id::Green,
198 pdal::Dimension::Id::Blue});
200 pdal::BufferReader bufferReader;
202 pdal::PointViewPtr view(
new pdal::PointView(table));
203 for(
size_t i=0; i<cloud.size(); ++i)
205 view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
206 view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
207 view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
208 view->setField(pdal::Dimension::Id::Red, i, cloud.at(i).r);
209 view->setField(pdal::Dimension::Id::Green, i, cloud.at(i).g);
210 view->setField(pdal::Dimension::Id::Blue, i, cloud.at(i).b);
211 if(!cameraIds.empty())
213 view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
215 if(!intensities.empty())
217 view->setField(pdal::Dimension::Id::Intensity, i, (
unsigned short)intensities.at(i));
220 bufferReader.addView(view);
222 pdal::StageFactory factory;
224 pdal::Stage *writer = factory.createStage(
"writers." + ext);
227 pdal::Options writerOps;
228 writerOps.add(
"filename", filePath);
229 if(ext.compare(
"ply")==0) writerOps.add(
"storage_mode", binary?
"little endian":
"ascii");
230 if(ext.compare(
"pcd")==0) writerOps.add(
"compression", binary?
"binary":
"ascii");
232 writer->setOptions(writerOps);
233 writer->setInput(bufferReader);
235 writer->prepare(table);
236 writer->execute(table);
240 UERROR(
"PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
250 const pcl::PointCloud<pcl::PointXYZRGBNormal> & cloud,
251 const std::vector<int> & cameraIds,
253 const std::vector<float> & intensities)
255 UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
256 uFormat(
"cameraIds=%d cloud=%d", (
int)cameraIds.size(), (int)cloud.size()).c_str());
257 UASSERT_MSG(intensities.empty() || intensities.size() == cloud.size(),
258 uFormat(
"intensities=%d cloud=%d", (
int)intensities.size(), (int)cloud.size()).c_str());
260 pdal::PointTable table;
262 if(!intensities.empty() && !cameraIds.empty())
264 table.layout()->registerDims({
265 pdal::Dimension::Id::X,
266 pdal::Dimension::Id::Y,
267 pdal::Dimension::Id::Z,
268 pdal::Dimension::Id::Red,
269 pdal::Dimension::Id::Green,
270 pdal::Dimension::Id::Blue,
271 pdal::Dimension::Id::NormalX,
272 pdal::Dimension::Id::NormalY,
273 pdal::Dimension::Id::NormalZ,
274 pdal::Dimension::Id::PointSourceId,
275 pdal::Dimension::Id::Intensity});
277 else if(!intensities.empty())
279 table.layout()->registerDims({
280 pdal::Dimension::Id::X,
281 pdal::Dimension::Id::Y,
282 pdal::Dimension::Id::Z,
283 pdal::Dimension::Id::Red,
284 pdal::Dimension::Id::Green,
285 pdal::Dimension::Id::Blue,
286 pdal::Dimension::Id::NormalX,
287 pdal::Dimension::Id::NormalY,
288 pdal::Dimension::Id::NormalZ,
289 pdal::Dimension::Id::Intensity});
291 else if(!cameraIds.empty())
293 table.layout()->registerDims({
294 pdal::Dimension::Id::X,
295 pdal::Dimension::Id::Y,
296 pdal::Dimension::Id::Z,
297 pdal::Dimension::Id::Red,
298 pdal::Dimension::Id::Green,
299 pdal::Dimension::Id::Blue,
300 pdal::Dimension::Id::NormalX,
301 pdal::Dimension::Id::NormalY,
302 pdal::Dimension::Id::NormalZ,
303 pdal::Dimension::Id::PointSourceId});
307 table.layout()->registerDims({
308 pdal::Dimension::Id::X,
309 pdal::Dimension::Id::Y,
310 pdal::Dimension::Id::Z,
311 pdal::Dimension::Id::Red,
312 pdal::Dimension::Id::Green,
313 pdal::Dimension::Id::Blue,
314 pdal::Dimension::Id::NormalX,
315 pdal::Dimension::Id::NormalY,
316 pdal::Dimension::Id::NormalZ});
318 pdal::BufferReader bufferReader;
320 pdal::PointViewPtr view(
new pdal::PointView(table));
321 for(
size_t i=0; i<cloud.size(); ++i)
323 view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
324 view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
325 view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
326 view->setField(pdal::Dimension::Id::Red, i, cloud.at(i).r);
327 view->setField(pdal::Dimension::Id::Green, i, cloud.at(i).g);
328 view->setField(pdal::Dimension::Id::Blue, i, cloud.at(i).b);
329 view->setField(pdal::Dimension::Id::NormalX, i, cloud.at(i).normal_x);
330 view->setField(pdal::Dimension::Id::NormalY, i, cloud.at(i).normal_y);
331 view->setField(pdal::Dimension::Id::NormalZ, i, cloud.at(i).normal_z);
332 if(!cameraIds.empty())
334 view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
336 if(!intensities.empty())
338 view->setField(pdal::Dimension::Id::Intensity, i, (
unsigned short)intensities.at(i));
341 bufferReader.addView(view);
343 pdal::StageFactory factory;
345 pdal::Stage *writer = factory.createStage(
"writers." + ext);
348 pdal::Options writerOps;
349 writerOps.add(
"filename", filePath);
350 if(ext.compare(
"ply")==0) writerOps.add(
"storage_mode", binary?
"little endian":
"ascii");
351 if(ext.compare(
"pcd")==0) writerOps.add(
"compression", binary?
"binary":
"ascii");
353 writer->setOptions(writerOps);
354 writer->setInput(bufferReader);
356 writer->prepare(table);
357 writer->execute(table);
361 UERROR(
"PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
371 const pcl::PointCloud<pcl::PointXYZI> & cloud,
372 const std::vector<int> & cameraIds,
375 UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
376 uFormat(
"cameraIds=%d cloud=%d", (
int)cameraIds.size(), (int)cloud.size()).c_str());
378 pdal::PointTable table;
380 if(!cameraIds.empty())
382 table.layout()->registerDims({
383 pdal::Dimension::Id::X,
384 pdal::Dimension::Id::Y,
385 pdal::Dimension::Id::Z,
386 pdal::Dimension::Id::Intensity,
387 pdal::Dimension::Id::PointSourceId});
391 table.layout()->registerDims({
392 pdal::Dimension::Id::X,
393 pdal::Dimension::Id::Y,
394 pdal::Dimension::Id::Z,
395 pdal::Dimension::Id::Intensity});
397 pdal::BufferReader bufferReader;
399 pdal::PointViewPtr view(
new pdal::PointView(table));
400 for(
size_t i=0; i<cloud.size(); ++i)
402 view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
403 view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
404 view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
405 view->setField(pdal::Dimension::Id::Intensity, i, (
unsigned short)cloud.at(i).intensity);
406 if(!cameraIds.empty())
408 view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
411 bufferReader.addView(view);
413 pdal::StageFactory factory;
415 pdal::Stage *writer = factory.createStage(
"writers." + ext);
418 pdal::Options writerOps;
419 writerOps.add(
"filename", filePath);
420 if(ext.compare(
"ply")==0) writerOps.add(
"storage_mode", binary?
"little endian":
"ascii");
421 if(ext.compare(
"pcd")==0) writerOps.add(
"compression", binary?
"binary":
"ascii");
423 writer->setOptions(writerOps);
424 writer->setInput(bufferReader);
426 writer->prepare(table);
427 writer->execute(table);
431 UERROR(
"PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
441 const pcl::PointCloud<pcl::PointXYZINormal> & cloud,
442 const std::vector<int> & cameraIds,
445 UASSERT_MSG(cameraIds.empty() || cameraIds.size() == cloud.size(),
446 uFormat(
"cameraIds=%d cloud=%d", (
int)cameraIds.size(), (int)cloud.size()).c_str());
448 pdal::PointTable table;
450 if(!cameraIds.empty())
452 table.layout()->registerDims({
453 pdal::Dimension::Id::X,
454 pdal::Dimension::Id::Y,
455 pdal::Dimension::Id::Z,
456 pdal::Dimension::Id::Intensity,
457 pdal::Dimension::Id::NormalX,
458 pdal::Dimension::Id::NormalY,
459 pdal::Dimension::Id::NormalZ,
460 pdal::Dimension::Id::PointSourceId});
464 table.layout()->registerDims({
465 pdal::Dimension::Id::X,
466 pdal::Dimension::Id::Y,
467 pdal::Dimension::Id::Z,
468 pdal::Dimension::Id::Intensity,
469 pdal::Dimension::Id::NormalX,
470 pdal::Dimension::Id::NormalY,
471 pdal::Dimension::Id::NormalZ});
473 pdal::BufferReader bufferReader;
475 pdal::PointViewPtr view(
new pdal::PointView(table));
476 for(
size_t i=0; i<cloud.size(); ++i)
478 view->setField(pdal::Dimension::Id::X, i, cloud.at(i).x);
479 view->setField(pdal::Dimension::Id::Y, i, cloud.at(i).y);
480 view->setField(pdal::Dimension::Id::Z, i, cloud.at(i).z);
481 view->setField(pdal::Dimension::Id::Intensity, i, (
unsigned short)cloud.at(i).intensity);
482 view->setField(pdal::Dimension::Id::NormalX, i, cloud.at(i).normal_x);
483 view->setField(pdal::Dimension::Id::NormalY, i, cloud.at(i).normal_y);
484 view->setField(pdal::Dimension::Id::NormalZ, i, cloud.at(i).normal_z);
485 if(!cameraIds.empty())
487 view->setField(pdal::Dimension::Id::PointSourceId, i, cameraIds.at(i));
490 bufferReader.addView(view);
492 pdal::StageFactory factory;
494 pdal::Stage *writer = factory.createStage(
"writers." + ext);
497 pdal::Options writerOps;
498 writerOps.add(
"filename", filePath);
499 if(ext.compare(
"ply")==0) writerOps.add(
"storage_mode", binary?
"little endian":
"ascii");
500 if(ext.compare(
"pcd")==0) writerOps.add(
"compression", binary?
"binary":
"ascii");
502 writer->setOptions(writerOps);
503 writer->setInput(bufferReader);
505 writer->prepare(table);
506 writer->execute(table);
510 UERROR(
"PDAL: cannot find writer for extension \"%s\". Available extensions: \"%s\"",
int savePDALFile(const std::string &filePath, const pcl::PointCloud< pcl::PointXYZ > &cloud, const std::vector< int > &cameraIds=std::vector< int >(), bool binary=false)
Some conversion functions.
std::string getExtension()
bool uStrContains(const std::string &string, const std::string &substring)
Wrappers of STL for convenient functions.
std::string getPDALSupportedWriters()
#define UASSERT_MSG(condition, msg_str)
ULogger class and convenient macros.
std::string UTILITE_EXP uFormat(const char *fmt,...)