|
| 1 | +/* +------------------------------------------------------------------------+ |
| 2 | + | Mobile Robot Programming Toolkit (MRPT) | |
| 3 | + | https://www.mrpt.org/ | |
| 4 | + | | |
| 5 | + | Copyright (c) 2005-2023, Individual contributors, see AUTHORS file | |
| 6 | + | See: https://www.mrpt.org/Authors - All rights reserved. | |
| 7 | + | Released under BSD License. See: https://www.mrpt.org/License | |
| 8 | + +------------------------------------------------------------------------+ */ |
| 9 | + |
| 10 | +#include "maps-precomp.h" // Precomp header |
| 11 | +// |
| 12 | +#include <mrpt/maps/CVoxelMap.h> |
| 13 | + |
| 14 | +using namespace mrpt::maps; |
| 15 | + |
| 16 | +// =========== Begin of Map definition ============ |
| 17 | +MAP_DEFINITION_REGISTER("mrpt::maps::CVoxelMap", mrpt::maps::CVoxelMap) |
| 18 | + |
| 19 | +CVoxelMap::TMapDefinition::TMapDefinition() = default; |
| 20 | +void CVoxelMap::TMapDefinition::loadFromConfigFile_map_specific( |
| 21 | + const mrpt::config::CConfigFileBase& source, |
| 22 | + const std::string& sectionNamePrefix) |
| 23 | +{ |
| 24 | + // [<sectionNamePrefix>+"_creationOpts"] |
| 25 | + const std::string sSectCreation = |
| 26 | + sectionNamePrefix + string("_creationOpts"); |
| 27 | + MRPT_LOAD_CONFIG_VAR(resolution, double, source, sSectCreation); |
| 28 | + |
| 29 | + insertionOpts.loadFromConfigFile( |
| 30 | + source, sectionNamePrefix + string("_insertOpts")); |
| 31 | + likelihoodOpts.loadFromConfigFile( |
| 32 | + source, sectionNamePrefix + string("_likelihoodOpts")); |
| 33 | +} |
| 34 | + |
| 35 | +void CVoxelMap::TMapDefinition::dumpToTextStream_map_specific( |
| 36 | + std::ostream& out) const |
| 37 | +{ |
| 38 | + LOADABLEOPTS_DUMP_VAR(resolution, double); |
| 39 | + |
| 40 | + this->insertionOpts.dumpToTextStream(out); |
| 41 | + this->likelihoodOpts.dumpToTextStream(out); |
| 42 | +} |
| 43 | + |
| 44 | +mrpt::maps::CMetricMap* CVoxelMap::internal_CreateFromMapDefinition( |
| 45 | + const mrpt::maps::TMetricMapInitializer& _def) |
| 46 | +{ |
| 47 | + const CVoxelMap::TMapDefinition& def = |
| 48 | + *dynamic_cast<const CVoxelMap::TMapDefinition*>(&_def); |
| 49 | + auto* obj = new CVoxelMap(def.resolution); |
| 50 | + obj->insertionOptions = def.insertionOpts; |
| 51 | + obj->likelihoodOptions = def.likelihoodOpts; |
| 52 | + return obj; |
| 53 | +} |
| 54 | +// =========== End of Map definition Block ========= |
| 55 | + |
| 56 | +IMPLEMENTS_SERIALIZABLE(CVoxelMap, CMetricMap, mrpt::maps) |
| 57 | + |
| 58 | +/*--------------------------------------------------------------- |
| 59 | + Constructor |
| 60 | + ---------------------------------------------------------------*/ |
| 61 | +CVoxelMap::CVoxelMap(const double resolution) |
| 62 | + : CVoxelMapBase<octomap::OcTree, octomap::OcTreeNode>(resolution) |
| 63 | +{ |
| 64 | +} |
| 65 | + |
| 66 | +CVoxelMap::~CVoxelMap() = default; |
| 67 | +uint8_t CVoxelMap::serializeGetVersion() const { return 0; } |
| 68 | +void CVoxelMap::serializeTo(mrpt::serialization::CArchive& out) const |
| 69 | +{ |
| 70 | + this->likelihoodOptions.writeToStream(out); |
| 71 | + this->renderingOptions.writeToStream(out); // Added in v1 |
| 72 | + out << genericMapParams; |
| 73 | + // const_cast<octomap::OcTree*>(&m_impl->m_octomap)->writeBinary(ss); |
| 74 | +} |
| 75 | + |
| 76 | +void CVoxelMap::serializeFrom( |
| 77 | + mrpt::serialization::CArchive& in, uint8_t version) |
| 78 | +{ |
| 79 | + switch (version) |
| 80 | + { |
| 81 | + case 0: |
| 82 | + { |
| 83 | + likelihoodOptions.readFromStream(in); |
| 84 | + renderingOptions.readFromStream(in); |
| 85 | + in >> genericMapParams; |
| 86 | + |
| 87 | + this->clear(); |
| 88 | + |
| 89 | + m_impl->m_octomap.readBinary(ss); |
| 90 | + } |
| 91 | + break; |
| 92 | + default: MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version); |
| 93 | + }; |
| 94 | +} |
| 95 | + |
| 96 | +bool CVoxelMap::internal_insertObservation( |
| 97 | + const mrpt::obs::CObservation& obs, |
| 98 | + const std::optional<const mrpt::poses::CPose3D>& robotPose) |
| 99 | +{ |
| 100 | + octomap::point3d sensorPt; |
| 101 | + octomap::Pointcloud scan; |
| 102 | + if (!internal_build_PointCloud_for_observation( |
| 103 | + obs, robotPose, sensorPt, scan)) |
| 104 | + return false; // Nothing to do. |
| 105 | + // Insert rays: |
| 106 | + m_impl->m_octomap.insertPointCloud( |
| 107 | + scan, sensorPt, insertionOptions.maxrange, insertionOptions.pruning); |
| 108 | + return true; |
| 109 | +} |
0 commit comments