12 #include <octomap/octomap.h> 13 #include <octomap/OcTree.h> 53 insertionOpts.loadFromConfigFile(
source, sectionNamePrefix+
string(
"_insertOpts") );
54 likelihoodOpts.loadFromConfigFile(
source, sectionNamePrefix+
string(
"_likelihoodOpts") );
61 this->insertionOpts.dumpToTextStream(out);
62 this->likelihoodOpts.dumpToTextStream(out);
82 m_octomap.ptr.reset(
new octomap::OcTree(resolution));
104 this->likelihoodOptions.writeToStream(out);
105 this->renderingOptions.writeToStream(out);
106 out << genericMapParams;
110 const_cast<octomap::OcTree*
>(&
PIMPL_GET_REF(OcTree, m_octomap))->writeBinary(tmpFil);
132 if (
version>=1) this->renderingOptions.readFromStream(
in);
140 if (chunk.getTotalBytesCount())
143 if (!chunk.saveBufferToFile( tmpFil ) )
THROW_EXCEPTION(
"Error saving temporary file");
158 octomap::point3d sensorPt;
159 octomap::Pointcloud scan;
160 if (!internal_build_PointCloud_for_observation(obs,robotPose, sensorPt, scan))
163 PIMPL_GET_REF(OcTree, m_octomap).insertPointCloud(scan, sensorPt, insertionOptions.maxrange, insertionOptions.pruning);
174 octomap::OcTree::tree_iterator it_end =
PIMPL_GET_REF(OcTree, m_octomap).end_tree();
176 const unsigned char max_depth = 0;
178 const TColor general_color_u(general_color.
R*255,general_color.
G*255,general_color.
B*255,general_color.
A*255);
188 const size_t nLeafs = this->getNumLeafNodes();
192 double xmin, xmax, ymin, ymax, zmin,
zmax, inv_dz;
193 this->getMetricMin(xmin, ymin, zmin);
194 this->getMetricMax(xmax, ymax,
zmax);
195 inv_dz = 1/(
zmax-zmin + 0.01);
197 for(octomap::OcTree::tree_iterator it =
PIMPL_GET_REF(OcTree, m_octomap).begin_tree(max_depth);it!=it_end; ++it)
199 const octomap::point3d vx_center = it.getCoordinate();
200 const double vx_length = it.getSize();
201 const double L = 0.5*vx_length;
206 const double occ = it->getOccupancy();
207 if ( (occ>=0.5 && renderingOptions.generateOccupiedVoxels) ||
208 (occ<0.5 && renderingOptions.generateFreeVoxels) )
213 case COctoMapVoxels::FIXED:
214 vx_color = general_color_u;
216 case COctoMapVoxels::COLOR_FROM_HEIGHT:
217 coefc = 255*inv_dz*(vx_center.z()-zmin);
218 vx_color =
TColor(coefc*general_color.
R, coefc*general_color.
G, coefc*general_color.
B, 255.0*general_color.
A);
221 case COctoMapVoxels::COLOR_FROM_OCCUPANCY:
222 coefc = 240*(1-occ) + 15;
223 vx_color =
TColor(coefc*general_color.
R, coefc*general_color.
G, coefc*general_color.
B, 255.0*general_color.
A);
226 case COctoMapVoxels::TRANSPARENCY_FROM_OCCUPANCY:
227 coeft = 255 - 510*(1-occ);
228 if (coeft < 0) { coeft = 0; }
229 vx_color =
TColor(255*general_color.
R, 255*general_color.
G, 255*general_color.
B, coeft);
232 case COctoMapVoxels::TRANS_AND_COLOR_FROM_OCCUPANCY:
233 coefc = 240*(1-occ) + 15;
234 vx_color =
TColor(coefc*general_color.
R, coefc*general_color.
G, coefc*general_color.
B, 50);
237 case COctoMapVoxels::MIXED:
238 coefc = 255*inv_dz*(vx_center.z()-zmin);
239 coeft = 255 - 510*(1-occ);
240 if (coeft < 0) { coeft = 0; }
241 vx_color =
TColor(coefc*general_color.
R, coefc*general_color.
G, coefc*general_color.
B, coeft);
253 else if (renderingOptions.generateGridLines)
269 this->getMetricMin(bbmin.
x,bbmin.
y,bbmin.
z);
270 this->getMetricMax(bbmax.
x,bbmax.
y,bbmax.
z);
275 void COctoMap::insertRay(
const float end_x,
const float end_y,
const float end_z,
const float sensor_x,
const float sensor_y,
const float sensor_z)
277 PIMPL_GET_REF(OcTree, m_octomap).insertRay(octomap::point3d(sensor_x, sensor_y, sensor_z), octomap::point3d(end_x, end_y, end_z), insertionOptions.maxrange, insertionOptions.pruning);
279 void COctoMap::updateVoxel(
const double x,
const double y,
const double z,
bool occupied)
283 bool COctoMap::isPointWithinOctoMap(
const float x,
const float y,
const float z)
const 285 octomap::OcTreeKey key;
289 double COctoMap::getResolution()
const {
return PIMPL_GET_CONSTREF(OcTree, m_octomap).getResolution(); }
290 unsigned int COctoMap::getTreeDepth()
const {
return PIMPL_GET_CONSTREF(OcTree, m_octomap).getTreeDepth(); }
293 size_t COctoMap::memoryUsageNode()
const {
return PIMPL_GET_CONSTREF(OcTree, m_octomap).memoryUsageNode(); }
294 size_t COctoMap::memoryFullGrid()
const {
return PIMPL_GET_CONSTREF(OcTree, m_octomap).memoryFullGrid(); }
295 double COctoMap::volume() {
return PIMPL_GET_REF(OcTree, m_octomap).volume(); }
296 void COctoMap::getMetricSize(
double&
x,
double&
y,
double&
z) {
return PIMPL_GET_REF(OcTree, m_octomap).getMetricSize(
x,
y,
z); }
297 void COctoMap::getMetricSize(
double&
x,
double&
y,
double&
z)
const {
return PIMPL_GET_CONSTREF(OcTree, m_octomap).getMetricSize(
x,
y,
z); }
298 void COctoMap::getMetricMin(
double&
x,
double&
y,
double&
z) {
return PIMPL_GET_REF(OcTree, m_octomap).getMetricMin(
x,
y,
z); }
299 void COctoMap::getMetricMin(
double&
x,
double&
y,
double&
z)
const {
return PIMPL_GET_CONSTREF(OcTree, m_octomap).getMetricMin(
x,
y,
z); }
300 void COctoMap::getMetricMax(
double&
x,
double&
y,
double&
z) {
return PIMPL_GET_REF(OcTree, m_octomap).getMetricMax(
x,
y,
z); }
301 void COctoMap::getMetricMax(
double&
x,
double&
y,
double&
z)
const {
return PIMPL_GET_CONSTREF(OcTree, m_octomap).getMetricMax(
x,
y,
z); }
302 size_t COctoMap::calcNumNodes()
const {
return PIMPL_GET_REF(OcTree, m_octomap).calcNumNodes(); }
303 size_t COctoMap::getNumLeafNodes()
const {
return PIMPL_GET_CONSTREF(OcTree, m_octomap).getNumLeafNodes(); }
304 void COctoMap::setOccupancyThres(
double prob) {
PIMPL_GET_REF(OcTree, m_octomap).setOccupancyThres(prob); }
305 void COctoMap::setProbHit(
double prob) {
PIMPL_GET_REF(OcTree, m_octomap).setProbHit(prob); }
306 void COctoMap::setProbMiss(
double prob) {
PIMPL_GET_REF(OcTree, m_octomap).setProbMiss(prob); }
307 void COctoMap::setClampingThresMin(
double thresProb) {
PIMPL_GET_REF(OcTree, m_octomap).setClampingThresMin(thresProb); }
308 void COctoMap::setClampingThresMax(
double thresProb) {
PIMPL_GET_REF(OcTree, m_octomap).setClampingThresMax(thresProb); }
309 double COctoMap::getOccupancyThres()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getOccupancyThres(); }
310 float COctoMap::getOccupancyThresLog()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getOccupancyThresLog(); }
311 double COctoMap::getProbHit()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getProbHit(); }
312 float COctoMap::getProbHitLog()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getProbHitLog(); }
313 double COctoMap::getProbMiss()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getProbMiss(); }
314 float COctoMap::getProbMissLog()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getProbMissLog(); }
315 double COctoMap::getClampingThresMin()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getClampingThresMin(); }
316 float COctoMap::getClampingThresMinLog()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getClampingThresMinLog(); }
317 double COctoMap::getClampingThresMax()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getClampingThresMax(); }
318 float COctoMap::getClampingThresMaxLog()
const {
return PIMPL_GET_REF(OcTree, m_octomap).getClampingThresMaxLog(); }
319 void COctoMap::internal_clear() {
PIMPL_GET_REF(OcTree, m_octomap).clear(); }
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, e.g.
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
void reserveVoxels(const size_t set_index, const size_t nVoxels)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
double resolution
The finest resolution of the octomap (default: 0.10 meters)
#define THROW_EXCEPTION(msg)
#define LOADABLEOPTS_DUMP_VAR(variableName, variableType)
Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types a...
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 reserveGridCubes(const size_t nCubes)
double z
X,Y,Z coordinates.
void clear()
Clears everything.
IMPLEMENTS_SERIALIZABLE(CLogFileRecord_FullEval, CHolonomicLogFileRecord, mrpt::nav) IMPLEMENTS_SERIALIZABLE(CHolonomicFullEval
GLsizei GLsizei GLuint * obj
void clear()
Clear the contents of this container.
This class allows loading and storing values and vectors of different types from a configuration text...
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
A flexible renderer of voxels, typically from a 3D octo map (see mrpt::maps::COctoMap).
void push_back_GridCube(const TGridCube &c)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
This base provides a set of functions for maths stuff.
std::string BASE_IMPEXP getTempFileName()
Returns the name of a proposed temporary file name.
#define PIMPL_GET_CONSTREF(_TYPE, _VAR_NAME)
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
mrpt::maps::COctoMap::TInsertionOptions insertionOpts
Observations insertion options.
mrpt::maps::COctoMap::TLikelihoodOptions likelihoodOpts
Probabilistic observation likelihood options.
This namespace contains representation of robot actions and observations.
A memory buffer (implements CStream) which can be itself serialized.
A three-dimensional probabilistic occupancy grid, implemented as an octo-tree with the "octomap" C++ ...
GLsizei const GLchar ** string
#define PIMPL_GET_REF(_TYPE, _VAR_NAME)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
The info of each grid block.
void push_back_Voxel(const size_t set_index, const TVoxel &v)
#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...
The info of each of the voxels.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define MAP_DEFINITION_REGISTER(_CLASSNAME_STRINGS, _CLASSNAME_WITH_NS)
Registers one map class into TMetricMapInitializer factory.
Declares a virtual base class for all metric maps storage classes.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Declares a class that represents any robot's observation.
void resizeVoxelSets(const size_t nVoxelSets)
visualization_mode_t getVisualizationMode() const
The namespace for 3D scene representation and rendering.
GLsizei GLsizei GLchar * source
A RGB color - floats in the range [0,1].
bool BASE_IMPEXP deleteFile(const std::string &fileName)
Deletes a single file.
bool loadBufferFromFile(const std::string &file_name)
Loads the entire buffer from a file *.
bool isCubeTransparencyEnabled() const
PIMPL_IMPLEMENT(octomap::OcTree)
mrpt::utils::TColorf getColor() const
Returns the object color property as a TColorf.