Skip to content

Commit

Permalink
Add new virtual method CMetricMap::boundingBox()
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Nov 5, 2023
1 parent e0a2e8a commit d4b407c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- All classes derived from mrpt::maps::CVoxelMapOccupancyBase
- mrpt::maps::COccupancyGridMap2D
- mrpt::maps::COccupancyGridMap2D
- New virtual method mrpt::maps::CMetricMap::boundingBox()
- \ref mrpt_core_grp
- Add the `[[nodiscard]]` attribute to all functions returning a value in `<mrpt/core/bits_math.h>`

Expand Down
7 changes: 7 additions & 0 deletions libs/maps/include/mrpt/maps/COccupancyGridMap2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ class COccupancyGridMap2D
return static_cast<int>((y - ymin) / m_resolution);
}

mrpt::math::TBoundingBoxf boundingBox() const override
{
return {
{m_xMin, m_yMin, insertionOptions.mapAltitude},
{m_xMax, m_yMax, insertionOptions.mapAltitude}};
}

/** Scales an integer representation of the log-odd into a real valued
* probability in [0,1], using p=exp(l)/(1+exp(l)) */
static inline float l2p(const cellType l)
Expand Down
9 changes: 9 additions & 0 deletions libs/maps/include/mrpt/maps/COccupancyGridMap3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ class COccupancyGridMap3D
void getVisualizationInto(
mrpt::opengl::CSetOfObjects& outObj) const override;

mrpt::math::TBoundingBoxf boundingBox() const override
{
return {
mrpt::math::TPoint3Df(
m_grid.getXMin(), m_grid.getYMin(), m_grid.getZMin()),
mrpt::math::TPoint3Df(
m_grid.getXMax(), m_grid.getYMax(), m_grid.getZMax())};
}

/** With this struct options are provided to the observation insertion
* process.
* \sa CObservation::insertIntoGridMap */
Expand Down
2 changes: 1 addition & 1 deletion libs/maps/include/mrpt/maps/CPointsMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ class CPointsMap : public CMetricMap,
* Results are cached unless the map is somehow modified to avoid repeated
* calculations.
*/
mrpt::math::TBoundingBoxf boundingBox() const;
mrpt::math::TBoundingBoxf boundingBox() const override;

/** Extracts the points in the map within a cylinder in 3D defined the
* provided radius and zmin/zmax values.
Expand Down
15 changes: 8 additions & 7 deletions libs/maps/include/mrpt/maps/CVoxelMapOccupancyBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <mrpt/maps/NearestNeighborsCapable.h>
#include <mrpt/maps/OccupancyGridCellType.h>
#include <mrpt/maps/logoddscell_traits.h>
#include <mrpt/math/TBoundingBox.h>
#include <mrpt/obs/obs_frwds.h>

namespace mrpt::maps
Expand Down Expand Up @@ -174,7 +175,7 @@ class CVoxelMapOccupancyBase : public CVoxelMapBase<voxel_node_t>,
/** This visits all cells to calculate a bounding box, caching the result
* so subsequent calls are cheap until the voxelmap is changed in some way.
*/
mrpt::math::TBoundingBox getBoundingBox() const;
mrpt::math::TBoundingBoxf boundingBox() const override;

/// The options used when inserting observations in the map:
TVoxelMap_InsertionOptions insertionOptions;
Expand Down Expand Up @@ -346,7 +347,7 @@ class CVoxelMapOccupancyBase : public CVoxelMapBase<voxel_node_t>,

void updateCachedProperties() const;
mutable mrpt::maps::CSimplePointsMap::Ptr m_cachedOccupied;
mutable mrpt::math::TBoundingBox m_bbox;
mutable mrpt::math::TBoundingBoxf m_bbox;
};

// ============= Implementations ===============
Expand Down Expand Up @@ -377,7 +378,7 @@ void CVoxelMapOccupancyBase<voxel_node_t, occupancy_t>::getAsOctoMapVoxels(
auto& grid =
const_cast<Bonxai::VoxelGrid<voxel_node_t>&>(base_t::m_impl->grid);

const mrpt::math::TBoundingBox bbox = this->getBoundingBox();
const mrpt::math::TBoundingBoxf bbox = this->boundingBox();
double bbox_span_z = bbox.max.z - bbox.min.z;
if (bbox_span_z < 0) bbox_span_z = 1;
const double bbox_span_z_inv = 1.0 / bbox_span_z;
Expand Down Expand Up @@ -675,7 +676,7 @@ void CVoxelMapOccupancyBase<voxel_node_t, occupancy_t>::updateCachedProperties()
if (m_cachedOccupied) return; // done

m_cachedOccupied = mrpt::maps::CSimplePointsMap::Create();
m_bbox = mrpt::math::TBoundingBox::PlusMinusInfinity();
m_bbox = mrpt::math::TBoundingBoxf::PlusMinusInfinity();

// forEachCell() has no const version
auto& grid =
Expand Down Expand Up @@ -703,7 +704,7 @@ void CVoxelMapOccupancyBase<voxel_node_t, occupancy_t>::updateCachedProperties()
grid.forEachCell(lmbdPerVoxel);

// If no cell is active, use default bbox:
if (m_bbox == mrpt::math::TBoundingBox::PlusMinusInfinity()) m_bbox = {};
if (m_bbox == mrpt::math::TBoundingBoxf::PlusMinusInfinity()) m_bbox = {};
}

template <typename voxel_node_t, typename occupancy_t>
Expand All @@ -715,8 +716,8 @@ mrpt::maps::CSimplePointsMap::Ptr
}

template <typename voxel_node_t, typename occupancy_t>
mrpt::math::TBoundingBox
CVoxelMapOccupancyBase<voxel_node_t, occupancy_t>::getBoundingBox() const
mrpt::math::TBoundingBoxf
CVoxelMapOccupancyBase<voxel_node_t, occupancy_t>::boundingBox() const
{
updateCachedProperties();
return m_bbox;
Expand Down
10 changes: 10 additions & 0 deletions libs/obs/include/mrpt/maps/CMetricMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <mrpt/maps/CMetricMapEvents.h>
#include <mrpt/maps/TMetricMapInitializer.h>
#include <mrpt/maps/metric_map_types.h>
#include <mrpt/math/TBoundingBox.h>
#include <mrpt/math/math_frwds.h>
#include <mrpt/obs/CObservation.h>
#include <mrpt/obs/obs_frwds.h>
Expand Down Expand Up @@ -113,6 +114,15 @@ class CMetricMap : public mrpt::serialization::CSerializable,
*/
virtual bool isEmpty() const = 0;

/** Returns the bounding box of the metric map, or (0,0,0)-(0,0,0) (the
* default value of mrpt::math::TBoundingBoxf() if not implemented in the
* derived class or the map is empty.
*/
virtual auto boundingBox() const -> mrpt::math::TBoundingBoxf
{
return {}; // default impl: no bbox
}

/** Load the map contents from a CSimpleMap object, erasing all previous
* content of the map. This is done invoking `insertObservation()` for each
* observation at the mean 3D robot pose of each pose-observations pair in
Expand Down
1 change: 0 additions & 1 deletion libs/opengl/src/CPointCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,5 +491,4 @@ void CPointCloud::toYAMLMap(mrpt::containers::yaml& propertiesMap) const
{
CRenderizable::toYAMLMap(propertiesMap);
propertiesMap["point_count"] = m_points.size();
propertiesMap["bounding_box"] = this->getBoundingBox().asString();
}

0 comments on commit d4b407c

Please sign in to comment.