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();
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
#define MAP_DEFINITION_REGISTER(_CLASSNAME_STRINGS, _CLASSNAME_WITH_NS)
Registers one map class into TMetricMapInitializer factory.
This class allows loading and storing values and vectors of different types from a configuration text...
A three-dimensional probabilistic occupancy grid, implemented as an octo-tree with the "octomap" C++ ...
Declares a virtual base class for all metric maps storage classes.
A three-dimensional probabilistic occupancy grid, implemented as an octo-tree with the "octomap" C++ ...
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors.
void getPointFast(size_t index, float &x, float &y, float &z) const
Just like getPoint() but without checking out-of-bound index and without returning the point weight,...
size_t size() const
Returns the number of stored points in the map.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
const POINTSMAP * buildAuxPointsMap(const void *options=nullptr) const
Returns a cached points map representing this laser scan, building it upon the first call.
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement,...
virtual void load() const override
Makes sure all images and other fields which may be externally stored are loaded in memory.
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot.
Declares a class that represents any robot's observation.
A flexible renderer of voxels, typically from a 3D octo map (see mrpt::maps::COctoMap).
void clear()
Clears everything.
void push_back_Voxel(const size_t set_index, const TVoxel &v)
bool isCubeTransparencyEnabled() const
void setBoundingBox(const mrpt::math::TPoint3D &bb_min, const mrpt::math::TPoint3D &bb_max)
Manually changes the bounding box (normally the user doesn't need to call this)
void reserveVoxels(const size_t set_index, const size_t nVoxels)
void showVoxels(unsigned int voxel_set, bool show)
Shows/hides the voxels (voxel_set is a 0-based index for the set of voxels to modify,...
void reserveGridCubes(const size_t nCubes)
void resizeVoxelSets(const size_t nVoxelSets)
void push_back_GridCube(const TGridCube &c)
std::shared_ptr< CPointCloudColoured > Ptr
mrpt::img::TColorf getColor() const
Returns the object color property as a TColorf.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
void composeFrom(const CPose3D &A, const CPose3D &B)
Makes "this = A (+) B"; this method is slightly more efficient than "this= A + B;" since it avoids th...
double x() const
Common members of all points & poses classes.
Virtual base class for "archives": classes abstracting I/O streams.
#define MRPT_LOAD_CONFIG_VAR( variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
#define LOADABLEOPTS_DUMP_VAR(variableName, variableType)
Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types a...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define THROW_EXCEPTION(msg)
GLsizei GLsizei GLuint * obj
GLdouble GLdouble GLdouble r
GLsizei const GLchar ** string
GLsizei GLsizei GLchar * source
void clear()
Clear the contents of this container.
This base provides a set of functions for maths stuff.
void project3DPointsFromDepthImageInto(mrpt::obs::CObservation3DRangeScan &src_obs, POINTMAP &dest_pointcloud, const mrpt::obs::T3DPointsProjectionParams &projectParams, const mrpt::obs::TRangeImageFilterParams &filterParams)
This namespace contains representation of robot actions and observations.
The namespace for 3D scene representation and rendering.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A RGB color - floats in the range [0,1].
mrpt::maps::CColouredOctoMap::TInsertionOptions insertionOpts
meters)
double resolution
The finest resolution of the octomap (default: 0.10.
mrpt::maps::CColouredOctoMap::TLikelihoodOptions likelihoodOpts
Probabilistic observation likelihood options.
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
double x
X,Y,Z coordinates.
Lightweight 3D point (float version).
Used in CObservation3DRangeScan::project3DPointsFromDepthImageInto()
bool PROJ3D_USE_LUT
(Default:true) [Only used when range_is_depth=true] Whether to use a Look-up-table (LUT) to speed up ...
const mrpt::poses::CPose3D * robotPoseInTheWorld
(Default: nullptr) Read takeIntoAccountSensorPoseOnRobot
The info of each grid block.
The info of each of the voxels.