12 #include <octomap/octomap.h>
13 #include <octomap/ColorOcTree.h>
32 octomap::ColorOcTreeNode>;
49 void CColouredOctoMap::TMapDefinition::loadFromConfigFile_map_specific(
55 sectionNamePrefix +
string(
"_creationOpts");
58 insertionOpts.loadFromConfigFile(
59 source, sectionNamePrefix +
string(
"_insertOpts"));
60 likelihoodOpts.loadFromConfigFile(
61 source, sectionNamePrefix +
string(
"_likelihoodOpts"));
64 void CColouredOctoMap::TMapDefinition::dumpToTextStream_map_specific(
65 std::ostream& out)
const
69 this->insertionOpts.dumpToTextStream(out);
70 this->likelihoodOpts.dumpToTextStream(out);
89 m_colour_method(INTEGRATE)
93 CColouredOctoMap::~CColouredOctoMap() {}
94 uint8_t CColouredOctoMap::serializeGetVersion()
const {
return 3; }
97 this->likelihoodOptions.writeToStream(out);
98 this->renderingOptions.writeToStream(out);
99 out << genericMapParams;
102 std::stringstream ss;
103 m_impl->m_octomap.writeBinaryConst(ss);
108 void CColouredOctoMap::serializeFrom(
118 "Deserialization of old versions of this class was "
119 "discontinued in MRPT 1.9.9 [no CMemoryChunk]");
124 this->likelihoodOptions.readFromStream(
in);
125 if (version >= 1) this->renderingOptions.readFromStream(
in);
126 if (version >= 2)
in >> genericMapParams;
135 std::stringstream ss;
138 m_impl->m_octomap.readBinary(ss);
150 bool CColouredOctoMap::internal_insertObservation(
153 octomap::point3d sensorPt;
154 octomap::Pointcloud scan;
158 robotPose3D = (*robotPose);
175 octomap::point3d(sensorPose.
x(), sensorPose.
y(), sensorPose.z());
179 const size_t nPts = scanPts->
size();
185 for (
size_t i = 0; i < nPts; i++)
195 scan.push_back(gx, gy, gz);
199 m_impl->m_octomap.insertPointCloud(
200 scan, sensorPt, insertionOptions.maxrange,
201 insertionOptions.pruning);
217 mrpt::make_aligned_shared<mrpt::opengl::CPointCloudColoured>();
228 octomap::point3d(sensorPose.
x(), sensorPose.
y(), sensorPose.z());
230 const size_t sizeRangeScan = pts->size();
231 scan.reserve(sizeRangeScan);
233 for (
size_t i = 0; i < sizeRangeScan; i++)
239 if (pt.
x != 0 || pt.
y != 0 || pt.
z != 0)
240 scan.push_back(pt.
x, pt.
y, pt.
z);
244 octomap::KeySet free_cells, occupied_cells;
247 scan, sensorPt, free_cells, occupied_cells,
248 insertionOptions.maxrange);
252 it != free_cells.end(); ++it)
254 m_impl->m_octomap.updateNode(*it,
false,
false);
257 it != occupied_cells.end(); ++it)
259 m_impl->m_octomap.updateNode(*it,
true,
false);
263 const float colF2B = 255.0f;
264 for (
size_t i = 0; i < sizeRangeScan; i++)
270 if (pt.
x != 0 || pt.
y != 0 || pt.
z != 0)
271 this->updateVoxelColour(
277 if (insertionOptions.pruning)
278 m_impl->m_octomap.prune();
289 bool CColouredOctoMap::getPointColour(
293 octomap::OcTreeKey key;
294 if (m_impl->m_octomap
295 .coordToKeyChecked(octomap::point3d(
x,
y,
z), key))
297 octomap::ColorOcTreeNode* node =
298 m_impl->m_octomap.search(key, 0 );
299 if (!node)
return false;
301 const octomap::ColorOcTreeNode::Color& col = node->getColor();
312 void CColouredOctoMap::updateVoxelColour(
313 const double x,
const double y,
const double z,
const uint8_t r,
316 switch (m_colour_method)
320 .integrateNodeColor(
x,
y,
z,
r,
g,
b);
324 .setNodeColor(
x,
y,
z,
r,
g,
b);
328 .averageNodeColor(
x,
y,
z,
r,
g,
b);
337 void CColouredOctoMap::getAsOctoMapVoxels(
343 octomap::ColorOcTree::tree_iterator it_end =
344 m_impl->m_octomap.end_tree();
346 const unsigned char max_depth = 0;
348 const TColor general_color_u(
349 general_color.
R * 255, general_color.
G * 255, general_color.
B * 255,
350 general_color.
A * 255);
361 const size_t nLeafs = this->getNumLeafNodes();
365 double xmin, xmax, ymin, ymax, zmin,
zmax;
366 this->getMetricMin(xmin, ymin, zmin);
367 this->getMetricMax(xmax, ymax,
zmax);
369 for (octomap::ColorOcTree::tree_iterator it =
370 m_impl->m_octomap.begin_tree(max_depth);
373 const octomap::point3d vx_center = it.getCoordinate();
374 const double vx_length = it.getSize();
375 const double L = 0.5 * vx_length;
380 const double occ = it->getOccupancy();
381 if ((occ >= 0.5 && renderingOptions.generateOccupiedVoxels) ||
382 (occ < 0.5 && renderingOptions.generateFreeVoxels))
385 octomap::ColorOcTreeNode::Color node_color = it->getColor();
386 vx_color =
TColor(node_color.r, node_color.g, node_color.b);
388 const size_t vx_set =
389 (m_impl->m_octomap.isNodeOccupied(*it))
396 TPoint3D(vx_center.x(), vx_center.y(), vx_center.z()),
397 vx_length, vx_color));
400 else if (renderingOptions.generateGridLines)
404 vx_center.x() - L, vx_center.y() - L, vx_center.z() - L);
406 vx_center.x() + L, vx_center.y() + L, vx_center.z() + L);
419 this->getMetricMin(bbmin.
x, bbmin.
y, bbmin.
z);
420 this->getMetricMax(bbmax.
x, bbmax.
y, bbmax.
z);
425 void CColouredOctoMap::insertRay(
426 const float end_x,
const float end_y,
const float end_z,
427 const float sensor_x,
const float sensor_y,
const float sensor_z)
431 octomap::point3d(sensor_x, sensor_y, sensor_z),
432 octomap::point3d(end_x, end_y, end_z), insertionOptions.maxrange,
433 insertionOptions.pruning);
435 void CColouredOctoMap::updateVoxel(
436 const double x,
const double y,
const double z,
bool occupied)
438 m_impl->m_octomap.updateNode(
x,
y,
z, occupied);
440 bool CColouredOctoMap::isPointWithinOctoMap(
441 const float x,
const float y,
const float z)
const
443 octomap::OcTreeKey key;
444 return m_impl->m_octomap
445 .coordToKeyChecked(octomap::point3d(
x,
y,
z), key);
448 double CColouredOctoMap::getResolution()
const
450 return m_impl->m_octomap.getResolution();
452 unsigned int CColouredOctoMap::getTreeDepth()
const
454 return m_impl->m_octomap.getTreeDepth();
458 return m_impl->m_octomap.size();
460 size_t CColouredOctoMap::memoryUsage()
const
462 return m_impl->m_octomap.memoryUsage();
464 size_t CColouredOctoMap::memoryUsageNode()
const
466 return m_impl->m_octomap.memoryUsageNode();
468 size_t CColouredOctoMap::memoryFullGrid()
const
470 return m_impl->m_octomap.memoryFullGrid();
472 double CColouredOctoMap::volume()
474 return m_impl->m_octomap.volume();
476 void CColouredOctoMap::getMetricSize(
double&
x,
double&
y,
double&
z)
478 return m_impl->m_octomap.getMetricSize(
x,
y,
z);
480 void CColouredOctoMap::getMetricSize(
double&
x,
double&
y,
double&
z)
const
482 return m_impl->m_octomap.getMetricSize(
x,
y,
z);
484 void CColouredOctoMap::getMetricMin(
double&
x,
double&
y,
double&
z)
486 return m_impl->m_octomap.getMetricMin(
x,
y,
z);
488 void CColouredOctoMap::getMetricMin(
double&
x,
double&
y,
double&
z)
const
490 return m_impl->m_octomap.getMetricMin(
x,
y,
z);
492 void CColouredOctoMap::getMetricMax(
double&
x,
double&
y,
double&
z)
494 return m_impl->m_octomap.getMetricMax(
x,
y,
z);
496 void CColouredOctoMap::getMetricMax(
double&
x,
double&
y,
double&
z)
const
498 return m_impl->m_octomap.getMetricMax(
x,
y,
z);
500 size_t CColouredOctoMap::calcNumNodes()
const
502 return m_impl->m_octomap.calcNumNodes();
504 size_t CColouredOctoMap::getNumLeafNodes()
const
506 return m_impl->m_octomap.getNumLeafNodes();
508 void CColouredOctoMap::setOccupancyThres(
double prob)
510 m_impl->m_octomap.setOccupancyThres(prob);
512 void CColouredOctoMap::setProbHit(
double prob)
514 m_impl->m_octomap.setProbHit(prob);
516 void CColouredOctoMap::setProbMiss(
double prob)
518 m_impl->m_octomap.setProbMiss(prob);
520 void CColouredOctoMap::setClampingThresMin(
double thresProb)
522 m_impl->m_octomap.setClampingThresMin(thresProb);
524 void CColouredOctoMap::setClampingThresMax(
double thresProb)
526 m_impl->m_octomap.setClampingThresMax(thresProb);
528 double CColouredOctoMap::getOccupancyThres()
const
530 return m_impl->m_octomap.getOccupancyThres();
532 float CColouredOctoMap::getOccupancyThresLog()
const
534 return m_impl->m_octomap.getOccupancyThresLog();
536 double CColouredOctoMap::getProbHit()
const
538 return m_impl->m_octomap.getProbHit();
540 float CColouredOctoMap::getProbHitLog()
const
542 return m_impl->m_octomap.getProbHitLog();
544 double CColouredOctoMap::getProbMiss()
const
546 return m_impl->m_octomap.getProbMiss();
548 float CColouredOctoMap::getProbMissLog()
const
550 return m_impl->m_octomap.getProbMissLog();
552 double CColouredOctoMap::getClampingThresMin()
const
554 return m_impl->m_octomap.getClampingThresMin();
556 float CColouredOctoMap::getClampingThresMinLog()
const
558 return m_impl->m_octomap.getClampingThresMinLog();
560 double CColouredOctoMap::getClampingThresMax()
const
562 return m_impl->m_octomap.getClampingThresMax();
564 float CColouredOctoMap::getClampingThresMaxLog()
const
566 return m_impl->m_octomap.getClampingThresMaxLog();
568 void CColouredOctoMap::internal_clear()
570 m_impl->m_octomap.clear();