supereight
Loading...
Searching...
No Matches
map.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
3 * SPDX-FileCopyrightText: 2019-2023 Smart Robotics Lab, Imperial College London, Technical University of Munich
4 * SPDX-FileCopyrightText: 2019-2023 Nils Funk
5 * SPDX-FileCopyrightText: 2019-2023 Sotiris Papatheodorou
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef SE_MAP_HPP
10#define SE_MAP_HPP
11
12#include <optional>
14#include <se/common/yaml.hpp>
17#include <se/map/raycaster.hpp>
18
19
20
21namespace se {
22
23// Forward Declaration
24template<typename DataT = se::Data<Field::TSDF, Colour::Off, Semantics::Off>,
25 Res ResT = Res::Single,
26 int BlockSize = 8>
27class Map;
28
29
30
31template<Field FldT, Colour ColB, Semantics SemB, Res ResT, int BlockSize>
32class Map<se::Data<FldT, ColB, SemB>, ResT, BlockSize> {
33 public:
39
40 struct Config {
43 Eigen::Vector3f dim = Eigen::Vector3f::Constant(10.0f);
44
47 float res = 0.1f;
48
51 Eigen::Isometry3f T_MW = Eigen::Isometry3f(Eigen::Translation3f(dim / 2));
52
56 void readYaml(const std::string& yaml_file);
57
58 // The definition of this function MUST be inside the definition of Config for template
59 // argument deduction to work.
60 friend std::ostream& operator<<(std::ostream& os, const Config& c)
61 {
62 os << str_utils::volume_to_pretty_str(c.dim, "dim") << " m\n";
63 os << str_utils::value_to_pretty_str(c.res, "res") << " m/voxel\n";
64 os << str_utils::eigen_matrix_to_pretty_str(c.T_MW.matrix(), "T_MW") << "\n";
65 return os;
66 }
67
68 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
69 };
70
80 Map(const Eigen::Vector3f& dim,
81 const float res,
84
94
97 Map(const Map&) = delete;
98
101 Map& operator=(const Map&) = delete;
102
109 bool contains(const Eigen::Vector3f& point_W) const;
110
116 const Eigen::Isometry3f& getTMW() const
117 {
118 return T_MW_;
119 };
120
126 const Eigen::Isometry3f& getTWM() const
127 {
128 return T_WM_;
129 };
130
136 const Eigen::Vector3f& getDim() const
137 {
138 return dimension_;
139 }
140
146 float getRes() const
147 {
148 return resolution_;
149 }
150
157 {
158 return data_config_;
159 }
160
168 template<Safe SafeB = Safe::Off>
169 DataType getData(const Eigen::Vector3f& point_W) const;
170
180 template<Safe SafeB = Safe::Off, Res ResTDummy = ResT>
181 typename std::enable_if_t<ResTDummy == Res::Multi, DataType>
182 getMinData(const Eigen::Vector3f& point_W, const int scale_desired) const;
183
193 template<Safe SafeB = Safe::Off, Res ResTDummy = ResT>
194 typename std::enable_if_t<ResTDummy == Res::Multi, DataType>
195 getMaxData(const Eigen::Vector3f& point_W, const int scale_desired) const
196 {
197 Eigen::Vector3i voxel_coord;
198
199 if constexpr (SafeB == Safe::Off) // Evaluate at compile time
200 {
202 }
203 else {
205 return DataType();
206 }
207 }
208
210 }
211
237 template<typename ValidF, typename GetF, Safe SafeB = Safe::Off, Res ResTDummy = ResT>
238 typename std::enable_if_t<ResTDummy == Res::Multi,
239 std::optional<std::invoke_result_t<GetF, DataType>>>
240 getInterp(const Eigen::Vector3f& point_W, ValidF valid, GetF get, int& returned_scale) const;
241
246 template<Safe SafeB = Safe::Off, typename ValidF, typename GetF>
247 std::optional<std::invoke_result_t<GetF, DataType>>
248 getInterp(const Eigen::Vector3f& point_W, ValidF valid, GetF get) const;
249
257 template<Safe SafeB = Safe::Off>
258 std::optional<se::field_t> getFieldInterp(const Eigen::Vector3f& point_W) const;
259
269 template<Safe SafeB = Safe::Off, Res ResTDummy = ResT>
270 typename std::enable_if_t<ResTDummy == Res::Multi, std::optional<se::field_t>>
271 getFieldInterp(const Eigen::Vector3f& point_W, int& returned_scale) const;
272
281 template<Safe SafeB = Safe::Off, Res ResTDummy = ResT, Colour ColourTDummy = ColB>
282 typename std::enable_if_t<ResTDummy == Res::Multi && ColourTDummy == Colour::On,
283 std::optional<colour_t>>
284 getColourInterp(const Eigen::Vector3f& point_W, int& returned_scale) const;
285
290 template<Safe SafeB = Safe::Off, Colour ColourTDummy = ColB>
291 typename std::enable_if_t<ColourTDummy == Colour::On, std::optional<colour_t>>
292 getColourInterp(const Eigen::Vector3f& point_W) const;
293
301 template<Safe SafeB = Safe::Off>
302 std::optional<se::field_vec_t> getFieldGrad(const Eigen::Vector3f& point_W) const;
303
319 int saveFieldSlices(const std::string& filename_x,
320 const std::string& filename_y,
321 const std::string& filename_z,
322 const Eigen::Vector3f& point_W) const;
323
340 template<se::Field FldTDummy = FldT>
341 typename std::enable_if_t<FldTDummy == se::Field::Occupancy, int>
342 saveMinFieldSlices(const std::string& filename_x,
343 const std::string& filename_y,
344 const std::string& filename_z,
345 const Eigen::Vector3f& point_W,
346 const int scale) const;
347
364 template<se::Field FldTDummy = FldT>
365 typename std::enable_if_t<FldTDummy == se::Field::Occupancy, int>
366 saveMaxFieldSlices(const std::string& filename_x,
367 const std::string& filename_y,
368 const std::string& filename_z,
369 const Eigen::Vector3f& point_W,
370 const int scale) const;
371
387 template<Res ResTDummy = ResT>
388 typename std::enable_if_t<ResTDummy == Res::Multi, int>
389 saveScaleSlices(const std::string& filename_x,
390 const std::string& filename_y,
391 const std::string& filename_z,
392 const Eigen::Vector3f& point_W) const;
393
401 SurfaceMesh mesh(const Eigen::Affine3f& T_OW = Eigen::Affine3f::Identity(),
402 const int min_desired_scale = 0) const;
403
409 int saveMesh(const std::string& filename,
410 const Eigen::Affine3f& T_OW = Eigen::Affine3f::Identity(),
411 const int min_desired_scale = 0) const;
412
417 StructureMesh structure(const Eigen::Affine3f& T_OW = Eigen::Affine3f::Identity(),
418 const bool only_leaves = true) const;
419
425 int saveStructure(const std::string& filename,
426 const Eigen::Affine3f& T_OW = Eigen::Affine3f::Identity(),
427 const bool only_leaves = true) const;
428
437 void voxelToPoint(const Eigen::Vector3i& voxel_coord, Eigen::Vector3f& point_W) const;
438
446 void voxelToPoint(const Eigen::Vector3i& voxel_coord,
447 const int voxel_size,
448 Eigen::Vector3f& point_W) const;
449
458 void voxelToCornerPoints(const Eigen::Vector3i& voxel_coord,
459 Eigen::Matrix<float, 3, 8>& corner_points_W) const;
460
468 void voxelToCornerPoints(const Eigen::Vector3i& voxel_coord,
469 const int voxel_size,
470 Eigen::Matrix<float, 3, 8>& corner_points_W) const;
471
482 template<se::Safe SafeB = se::Safe::On>
483 typename std::enable_if_t<SafeB == se::Safe::On, bool>
484 pointToVoxel(const Eigen::Vector3f& point_W, Eigen::Vector3i& voxel_coord) const;
485
494 template<se::Safe SafeB>
495 typename std::enable_if_t<SafeB == se::Safe::Off, bool>
496 pointToVoxel(const Eigen::Vector3f& point_W, Eigen::Vector3i& voxel_coord) const;
497
506 template<se::Safe SafeB = se::Safe::On>
507 typename std::enable_if_t<SafeB == se::Safe::On, bool>
508 pointToVoxel(const Eigen::Vector3f& point_W, Eigen::Vector3f& voxel_coord_f) const;
509
518 template<se::Safe SafeB>
519 typename std::enable_if_t<SafeB == se::Safe::Off, bool>
520 pointToVoxel(const Eigen::Vector3f& point_W, Eigen::Vector3f& voxel_coord_f) const;
521
530 template<se::Safe SafeB = se::Safe::On>
531 typename std::enable_if_t<SafeB == se::Safe::On, bool> pointsToVoxels(
532 const std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f>>& points_W,
533 std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i>>& voxel_coords)
534 const;
535
544 template<se::Safe SafeB>
545 typename std::enable_if_t<SafeB == se::Safe::Off, bool> pointsToVoxels(
546 const std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f>>& points_W,
547 std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i>>& voxel_coords)
548 const;
549
552 {
553 return octree_;
554 };
555
557 const OctreeType& getOctree() const
558 {
559 return octree_;
560 };
561
566 const Eigen::AlignedBox3f& aabb() const;
567
568 static constexpr Field fld_ = FldT;
569 static constexpr Colour col_ = ColB;
570 static constexpr Semantics sem_ = SemB;
571
572 static constexpr Res res_ = ResT;
573
574 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
575
576 protected:
578 const float resolution_;
579 const Eigen::Vector3f dimension_;
580 const Eigen::Isometry3f T_MW_;
581 const Eigen::Isometry3f T_WM_;
582
583 const Eigen::Vector3f lb_M_;
584 const Eigen::Vector3f ub_M_;
585
587
588 mutable Eigen::AlignedBox3f cached_aabb_;
589 mutable Eigen::AlignedBox3i cached_octree_aabb_;
590
592 static const Eigen::Matrix<float, 3, 8> corner_rel_steps_;
593};
594
600 int BlockSize = 8>
602
603
604// Occupancy map setups
605template<se::Res ResT = se::Res::Multi, int BlockSize = 8>
607
608template<se::Res ResT = se::Res::Multi, int BlockSize = 8>
610
611template<se::Res ResT = se::Res::Multi, int BlockSize = 8>
613
614template<se::Res ResT = se::Res::Multi, int BlockSize = 8>
616
617
618// TSDF map setups
619template<se::Res ResT = se::Res::Single, int BlockSize = 8>
621
622template<se::Res ResT = se::Res::Single, int BlockSize = 8>
624
625template<se::Res ResT = se::Res::Single, int BlockSize = 8>
627
628template<se::Res ResT = se::Res::Single, int BlockSize = 8>
630
631} // namespace se
632
633#include "impl/map_impl.hpp"
634
635#endif // SE_MAP_HPP
Definition image.hpp:19
const Eigen::Vector3f dimension_
The dimensions of the map.
Definition map.hpp:579
DataType getData(const Eigen::Vector3f &point_W) const
Get the stored data at the provided coordinates in [meter].
const Eigen::Isometry3f T_MW_
The transformation from world to map frame.
Definition map.hpp:580
std::enable_if_t< ResTDummy==Res::Multi, std::optional< se::field_t > > getFieldInterp(const Eigen::Vector3f &point_W, int &returned_scale) const
Get the interpolated field value at the provided coordinates and the scale it is stored at.
const DataConfigType & getDataConfig() const
Get the data configuration of the map.
Definition map.hpp:156
const Eigen::Vector3f ub_M_
The upper map bound.
Definition map.hpp:584
bool contains(const Eigen::Vector3f &point_W) const
Verify if a point is inside the map.
std::optional< se::field_vec_t > getFieldGrad(const Eigen::Vector3f &point_W) const
Get the field gradient at the provided coordinates.
SurfaceMesh mesh(const Eigen::Affine3f &T_OW=Eigen::Affine3f::Identity(), const int min_desired_scale=0) const
Return a mesh of the reconstructed surface in the world frame in units of metres.
StructureMesh structure(const Eigen::Affine3f &T_OW=Eigen::Affine3f::Identity(), const bool only_leaves=true) const
Return a mesh of the octree structure in the world frame in units of metres.
const Eigen::Isometry3f T_WM_
The transformation from map to world frame.
Definition map.hpp:581
int saveMesh(const std::string &filename, const Eigen::Affine3f &T_OW=Eigen::Affine3f::Identity(), const int min_desired_scale=0) const
Save the mesh returned by se::Map::mesh() in filename.
std::enable_if_t< ResTDummy==Res::Multi, std::optional< std::invoke_result_t< GetF, DataType > > > getInterp(const Eigen::Vector3f &point_W, ValidF valid, GetF get, int &returned_scale) const
Interpolate a member of DataType at the supplied coordinates and the finest possible scale.
int saveStructure(const std::string &filename, const Eigen::Affine3f &T_OW=Eigen::Affine3f::Identity(), const bool only_leaves=true) const
Save the mesh returned by se::Map::structure_meshing() in filename.
std::enable_if_t< ResTDummy==Res::Multi, int > saveScaleSlices(const std::string &filename_x, const std::string &filename_y, const std::string &filename_z, const Eigen::Vector3f &point_W) const
Save three slices of the integration scale, each perpendicular to one of the axes (x,...
const Eigen::Vector3f & getDim() const
Get the dimensions of the map in [meter] (length x width x height)
Definition map.hpp:136
Map & operator=(const Map &)=delete
The copy assignment operator is explicitly deleted.
OctreeType & getOctree()
Return a reference to the internal se::Octree.
Definition map.hpp:551
Map(const Config &map_config, const typename Data< FldT, ColB, SemB >::Config &data_config=typename Data< FldT, ColB, SemB >::Config())
The map constructor.
void voxelToPoint(const Eigen::Vector3i &voxel_coord, const int voxel_size, Eigen::Vector3f &point_W) const
Convert voxel coordinates in [voxel] for a given voxel size to its centre point coordinates in [meter...
Map(const Map &)=delete
The copy constructor is explicitly deleted.
const float resolution_
The resolution of the map.
Definition map.hpp:578
const OctreeType & getOctree() const
Return a constant reference to the internal se::Octree.
Definition map.hpp:557
void voxelToCornerPoints(const Eigen::Vector3i &voxel_coord, const int voxel_size, Eigen::Matrix< float, 3, 8 > &corner_points_W) const
Convert voxel coordinates in [voxel] for a given voxel size to its eight corner point coordinates in ...
std::enable_if_t< ResTDummy==Res::Multi &&ColourTDummy==Colour::On, std::optional< colour_t > > getColourInterp(const Eigen::Vector3f &point_W, int &returned_scale) const
Interpolate the colour at the supplied coordinates and the finest possible scale.
static const Eigen::Matrix< float, 3, 8 > corner_rel_steps_
The eight relative unit corner offsets.
Definition map.hpp:592
const Eigen::Vector3f lb_M_
The lower map bound.
Definition map.hpp:583
const Eigen::AlignedBox3f & aabb() const
Return the axis-aligned bounding box in the world frame W of the map's allocated leaves.
void voxelToCornerPoints(const Eigen::Vector3i &voxel_coord, Eigen::Matrix< float, 3, 8 > &corner_points_W) const
Convert voxel coordinates in [voxel] for a given voxel size to its eight corner point coordinates in ...
int saveFieldSlices(const std::string &filename_x, const std::string &filename_y, const std::string &filename_z, const Eigen::Vector3f &point_W) const
Save three slices of the field value, each perpendicular to one of the axes (x, y and z) at the provi...
const DataConfigType data_config_
The configuration of the data.
Definition map.hpp:586
std::optional< std::invoke_result_t< GetF, DataType > > getInterp(const Eigen::Vector3f &point_W, ValidF valid, GetF get) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::enable_if_t< ResTDummy==Res::Multi, DataType > getMaxData(const Eigen::Vector3f &point_W, const int scale_desired) const
Get the stored max data at the provided coordinates in [meter] for a given scale.
Definition map.hpp:195
Eigen::AlignedBox3i cached_octree_aabb_
Definition map.hpp:589
const Eigen::Isometry3f & getTMW() const
Get the transformation from world to map frame.
Definition map.hpp:116
Eigen::AlignedBox3f cached_aabb_
Definition map.hpp:588
se::Octree< DataType, ResT, BlockSize > OctreeType
Definition map.hpp:36
OctreeType::SurfaceMesh SurfaceMesh
Definition map.hpp:37
std::enable_if_t< SafeB==se::Safe::On, bool > pointToVoxel(const Eigen::Vector3f &point_W, Eigen::Vector3f &voxel_coord_f) const
Convert point coordinates in [meter] to its voxel coordinates in [voxel].
Data< FldT, ColB, SemB > DataType
Definition map.hpp:34
std::enable_if_t< ResTDummy==Res::Multi, DataType > getMinData(const Eigen::Vector3f &point_W, const int scale_desired) const
Get the stored min data at the provided coordinates in [meter] for a given scale.
std::enable_if_t< SafeB==se::Safe::On, bool > pointsToVoxels(const std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > &points_W, std::vector< Eigen::Vector3i, Eigen::aligned_allocator< Eigen::Vector3i > > &voxel_coords) const
Convert a vector of point coordinates in [meter] to its voxel coordinates in [voxel].
std::enable_if_t< SafeB==se::Safe::Off, bool > pointToVoxel(const Eigen::Vector3f &point_W, Eigen::Vector3f &voxel_coord_f) const
Convert point coordinates in [meter] to its voxel coordinates in [voxel].
float getRes() const
Get the resolution of the map in [meter/voxel].
Definition map.hpp:146
Map(const Eigen::Vector3f &dim, const float res, const typename Data< FldT, ColB, SemB >::Config &data_config=typename Data< FldT, ColB, SemB >::Config())
The map constructor.
std::enable_if_t< FldTDummy==se::Field::Occupancy, int > saveMinFieldSlices(const std::string &filename_x, const std::string &filename_y, const std::string &filename_z, const Eigen::Vector3f &point_W, const int scale) const
Save three slices of the minimum field value, each perpendicular to one of the axes (x,...
void voxelToPoint(const Eigen::Vector3i &voxel_coord, Eigen::Vector3f &point_W) const
Convert voxel coordinates in [voxel] to its centre point coordinates in [meter].
std::enable_if_t< FldTDummy==se::Field::Occupancy, int > saveMaxFieldSlices(const std::string &filename_x, const std::string &filename_y, const std::string &filename_z, const Eigen::Vector3f &point_W, const int scale) const
Save three slices of the maximum field value, each perpendicular to one of the axes (x,...
Data< FldT, ColB, SemB >::Config DataConfigType
Definition map.hpp:35
std::enable_if_t< ColourTDummy==Colour::On, std::optional< colour_t > > getColourInterp(const Eigen::Vector3f &point_W) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::optional< se::field_t > getFieldInterp(const Eigen::Vector3f &point_W) const
Get the interpolated field value at the provided coordinates.
std::enable_if_t< SafeB==se::Safe::On, bool > pointToVoxel(const Eigen::Vector3f &point_W, Eigen::Vector3i &voxel_coord) const
Convert point coordinates in [meter] to its voxel coordinates (bottom, front, left corner) in [voxel]...
const Eigen::Isometry3f & getTWM() const
Get the transformation from map to world frame.
Definition map.hpp:126
OctreeType::StructureMesh StructureMesh
Definition map.hpp:38
std::enable_if_t< SafeB==se::Safe::Off, bool > pointToVoxel(const Eigen::Vector3f &point_W, Eigen::Vector3i &voxel_coord) const
Convert point coordinates in [meter] to its voxel coordinates (bottom, front, left corner) in [voxel]...
std::enable_if_t< SafeB==se::Safe::Off, bool > pointsToVoxels(const std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > &points_W, std::vector< Eigen::Vector3i, Eigen::aligned_allocator< Eigen::Vector3i > > &voxel_coords) const
Convert a vector of point coordinates in [meter] to its voxel coordinates in [voxel].
Definition map.hpp:27
std::enable_if_t< OctreeT::DataType::fld_==Field::Occupancy, typename OctreeT::DataType > getMaxData(const OctreeT &octree, const Eigen::Vector3i &voxel_coord, const int scale_desired)
Get the max occupancy data at a given scale.
Helper wrapper to allocate and de-allocate octants in the octree.
Definition bounded_vector.hpp:14
Res
Definition setup_util.hpp:23
Field
Definition setup_util.hpp:18
Semantics
Definition setup_util.hpp:20
Colour
Definition setup_util.hpp:19
Definition config.hpp:105
Definition data.hpp:28
Definition data.hpp:19
void readYaml(const std::string &yaml_file)
Reads the struct members from the "map" node of a YAML file.
friend std::ostream & operator<<(std::ostream &os, const Config &c)
Definition map.hpp:60