supereight2
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, Id::Off>,
25 Res ResT = Res::Single,
26 int BlockSize = 8>
27class Map;
28
29
30
31template<Field FldT, Colour ColB, Id IdB, Res ResT, int BlockSize>
32class Map<se::Data<FldT, ColB, IdB>, ResT, BlockSize> {
33 public:
41
42 struct Config {
45 Eigen::Vector3f dim = Eigen::Vector3f::Constant(10.0f);
46
49 float res = 0.1f;
50
53 Eigen::Isometry3f T_MW = Eigen::Isometry3f(Eigen::Translation3f(dim / 2));
54
58 void readYaml(const std::string& yaml_file);
59
60 // The definition of this function MUST be inside the definition of Config for template
61 // argument deduction to work.
62 friend std::ostream& operator<<(std::ostream& os, const Config& c)
63 {
64 os << str_utils::volume_to_pretty_str(c.dim, "dim") << " m\n";
65 os << str_utils::value_to_pretty_str(c.res, "res") << " m/voxel\n";
66 os << str_utils::eigen_matrix_to_pretty_str(c.T_MW.matrix(), "T_MW") << "\n";
67 return os;
68 }
69
70 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
71 };
72
82 Map(const Eigen::Vector3f& dim,
83 const float res,
86
96
99 Map(const Map&) = delete;
100
103 Map& operator=(const Map&) = delete;
104
111 bool contains(const Eigen::Vector3f& point_W) const;
112
118 const Eigen::Isometry3f& getTMW() const
119 {
120 return T_MW_;
121 };
122
128 const Eigen::Isometry3f& getTWM() const
129 {
130 return T_WM_;
131 };
132
138 const Eigen::Vector3f& getDim() const
139 {
140 return dimension_;
141 }
142
148 float getRes() const
149 {
150 return resolution_;
151 }
152
159 {
160 return data_config_;
161 }
162
170 template<Safe SafeB = Safe::Off>
171 DataType getData(const Eigen::Vector3f& point_W) const;
172
182 template<Safe SafeB = Safe::Off, Res ResTDummy = ResT>
183 typename std::enable_if_t<ResTDummy == Res::Multi, DataType>
184 getMinData(const Eigen::Vector3f& point_W, const int scale_desired) const;
185
195 template<Safe SafeB = Safe::Off, Res ResTDummy = ResT>
196 typename std::enable_if_t<ResTDummy == Res::Multi, DataType>
197 getMaxData(const Eigen::Vector3f& point_W, const int scale_desired) const
198 {
199 Eigen::Vector3i voxel_coord;
200
201 if constexpr (SafeB == Safe::Off) // Evaluate at compile time
202 {
204 }
205 else {
207 return DataType();
208 }
209 }
210
212 }
213
239 template<typename ValidF, typename GetF, Safe SafeB = Safe::Off, Res ResTDummy = ResT>
240 typename std::enable_if_t<ResTDummy == Res::Multi,
241 std::optional<std::invoke_result_t<GetF, DataType>>>
242 getInterp(const Eigen::Vector3f& point_W, ValidF valid, GetF get, int& returned_scale) const;
243
248 template<Safe SafeB = Safe::Off, typename ValidF, typename GetF>
249 std::optional<std::invoke_result_t<GetF, DataType>>
250 getInterp(const Eigen::Vector3f& point_W, ValidF valid, GetF get) const;
251
259 template<Safe SafeB = Safe::Off>
260 std::optional<se::field_t> getFieldInterp(const Eigen::Vector3f& point_W) const;
261
271 template<Safe SafeB = Safe::Off, Res ResTDummy = ResT>
272 typename std::enable_if_t<ResTDummy == Res::Multi, std::optional<se::field_t>>
273 getFieldInterp(const Eigen::Vector3f& point_W, int& returned_scale) const;
274
283 template<Safe SafeB = Safe::Off, Res ResTDummy = ResT, Colour ColourTDummy = ColB>
284 typename std::enable_if_t<ResTDummy == Res::Multi && ColourTDummy == Colour::On,
285 std::optional<colour_t>>
286 getColourInterp(const Eigen::Vector3f& point_W, int& returned_scale) const;
287
292 template<Safe SafeB = Safe::Off, Colour ColourTDummy = ColB>
293 typename std::enable_if_t<ColourTDummy == Colour::On, std::optional<colour_t>>
294 getColourInterp(const Eigen::Vector3f& point_W) const;
295
303 template<Safe SafeB = Safe::Off>
304 std::optional<se::field_vec_t> getFieldGrad(const Eigen::Vector3f& point_W) const;
305
321 int saveFieldSlices(const std::string& filename_x,
322 const std::string& filename_y,
323 const std::string& filename_z,
324 const Eigen::Vector3f& point_W) const;
325
342 template<se::Field FldTDummy = FldT>
343 typename std::enable_if_t<FldTDummy == se::Field::Occupancy, int>
344 saveMinFieldSlices(const std::string& filename_x,
345 const std::string& filename_y,
346 const std::string& filename_z,
347 const Eigen::Vector3f& point_W,
348 const int scale) const;
349
366 template<se::Field FldTDummy = FldT>
367 typename std::enable_if_t<FldTDummy == se::Field::Occupancy, int>
368 saveMaxFieldSlices(const std::string& filename_x,
369 const std::string& filename_y,
370 const std::string& filename_z,
371 const Eigen::Vector3f& point_W,
372 const int scale) const;
373
389 template<Res ResTDummy = ResT>
390 typename std::enable_if_t<ResTDummy == Res::Multi, int>
391 saveScaleSlices(const std::string& filename_x,
392 const std::string& filename_y,
393 const std::string& filename_z,
394 const Eigen::Vector3f& point_W) const;
395
403 SurfaceMesh mesh(const Eigen::Affine3f& T_OW = Eigen::Affine3f::Identity(),
404 const int min_desired_scale = 0) const;
405
411 int saveMesh(const std::string& filename,
412 const Eigen::Affine3f& T_OW = Eigen::Affine3f::Identity(),
413 const int min_desired_scale = 0) const;
414
419 StructureMesh structure(const Eigen::Affine3f& T_OW = Eigen::Affine3f::Identity(),
420 const bool only_leaves = true) const;
421
427 int saveStructure(const std::string& filename,
428 const Eigen::Affine3f& T_OW = Eigen::Affine3f::Identity(),
429 const bool only_leaves = true) const;
430
439 void voxelToPoint(const Eigen::Vector3i& voxel_coord, Eigen::Vector3f& point_W) const;
440
448 void voxelToPoint(const Eigen::Vector3i& voxel_coord,
449 const int voxel_size,
450 Eigen::Vector3f& point_W) const;
451
460 void voxelToCornerPoints(const Eigen::Vector3i& voxel_coord,
461 Eigen::Matrix<float, 3, 8>& corner_points_W) const;
462
470 void voxelToCornerPoints(const Eigen::Vector3i& voxel_coord,
471 const int voxel_size,
472 Eigen::Matrix<float, 3, 8>& corner_points_W) const;
473
484 template<se::Safe SafeB = se::Safe::On>
485 typename std::enable_if_t<SafeB == se::Safe::On, bool>
486 pointToVoxel(const Eigen::Vector3f& point_W, Eigen::Vector3i& voxel_coord) const;
487
496 template<se::Safe SafeB>
497 typename std::enable_if_t<SafeB == se::Safe::Off, bool>
498 pointToVoxel(const Eigen::Vector3f& point_W, Eigen::Vector3i& voxel_coord) const;
499
508 template<se::Safe SafeB = se::Safe::On>
509 typename std::enable_if_t<SafeB == se::Safe::On, bool>
510 pointToVoxel(const Eigen::Vector3f& point_W, Eigen::Vector3f& voxel_coord_f) const;
511
520 template<se::Safe SafeB>
521 typename std::enable_if_t<SafeB == se::Safe::Off, bool>
522 pointToVoxel(const Eigen::Vector3f& point_W, Eigen::Vector3f& voxel_coord_f) const;
523
532 template<se::Safe SafeB = se::Safe::On>
533 typename std::enable_if_t<SafeB == se::Safe::On, bool> pointsToVoxels(
534 const std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f>>& points_W,
535 std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i>>& voxel_coords)
536 const;
537
546 template<se::Safe SafeB>
547 typename std::enable_if_t<SafeB == se::Safe::Off, bool> pointsToVoxels(
548 const std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f>>& points_W,
549 std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i>>& voxel_coords)
550 const;
551
554 {
555 return octree_;
556 };
557
559 const OctreeType& getOctree() const
560 {
561 return octree_;
562 };
563
568 const Eigen::AlignedBox3f& aabb() const;
569
570 static constexpr Field fld_ = FldT;
571 static constexpr Colour col_ = ColB;
572 static constexpr Id id_ = IdB;
573
574 static constexpr Res res_ = ResT;
575
576 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
577
578 protected:
580 const float resolution_;
581 const Eigen::Vector3f dimension_;
582 const Eigen::Isometry3f T_MW_;
583 const Eigen::Isometry3f T_WM_;
584
585 const Eigen::Vector3f lb_M_;
586 const Eigen::Vector3f ub_M_;
587
589
590 mutable Eigen::AlignedBox3f cached_aabb_;
591 mutable Eigen::AlignedBox3i cached_octree_aabb_;
592
594 static const Eigen::Matrix<float, 3, 8> corner_rel_steps_;
595};
596
602 int BlockSize = 8>
604
605
606// Occupancy map setups
607template<se::Res ResT = se::Res::Multi, int BlockSize = 8>
609
610template<se::Res ResT = se::Res::Multi, int BlockSize = 8>
612
613template<se::Res ResT = se::Res::Multi, int BlockSize = 8>
615
616template<se::Res ResT = se::Res::Multi, int BlockSize = 8>
618
619
620// TSDF map setups
621template<se::Res ResT = se::Res::Single, int BlockSize = 8>
623
624template<se::Res ResT = se::Res::Single, int BlockSize = 8>
626
627template<se::Res ResT = se::Res::Single, int BlockSize = 8>
629
630template<se::Res ResT = se::Res::Single, int BlockSize = 8>
632
633} // namespace se
634
635#include "impl/map_impl.hpp"
636
637#endif // SE_MAP_HPP
Definition image.hpp:19
const Eigen::Isometry3f T_MW_
The transformation from world to map frame.
Definition map.hpp:582
OctreeType::DataConfigType DataConfigType
Definition map.hpp:36
OctreeType & getOctree()
Return a reference to the internal se::Octree.
Definition map.hpp:553
const Eigen::Vector3f ub_M_
The upper map bound.
Definition map.hpp:586
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,...
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...
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.
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.
bool contains(const Eigen::Vector3f &point_W) const
Verify if a point is inside the map.
Eigen::AlignedBox3i cached_octree_aabb_
Definition map.hpp:591
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::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]...
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...
std::optional< se::field_vec_t > getFieldGrad(const Eigen::Vector3f &point_W) const
Get the field gradient at the provided coordinates.
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.
OctreeType::NodeType NodeType
Definition map.hpp:38
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]...
OctreeType::BlockType BlockType
Definition map.hpp:37
OctreeType::DataType DataType
Definition map.hpp:35
Eigen::AlignedBox3f cached_aabb_
Definition map.hpp:590
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.
const Eigen::AlignedBox3f & aabb() const
Return the axis-aligned bounding box in the world frame W of the map's allocated leaves.
Map(const Map &)=delete
The copy constructor is explicitly deleted.
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.
const float resolution_
The resolution of the map.
Definition map.hpp:580
DataType getData(const Eigen::Vector3f &point_W) const
Get the stored data at the provided coordinates in [meter].
const Eigen::Vector3f lb_M_
The lower map bound.
Definition map.hpp:585
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].
const DataConfigType & getDataConfig() const
Get the data configuration of the map.
Definition map.hpp:158
const DataConfigType data_config_
The configuration of the data.
Definition map.hpp:588
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].
Map(const Eigen::Vector3f &dim, const float res, const typename Data< FldT, ColB, IdB >::Config &data_config=typename Data< FldT, ColB, IdB >::Config())
The map constructor.
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].
const Eigen::Isometry3f & getTWM() const
Get the transformation from map to world frame.
Definition map.hpp:128
void voxelToPoint(const Eigen::Vector3i &voxel_coord, Eigen::Vector3f &point_W) const
Convert voxel coordinates in [voxel] to its centre point coordinates in [meter].
Octree< Data< FldT, ColB, IdB >, ResT, BlockSize > OctreeType
Definition map.hpp:34
const Eigen::Isometry3f T_WM_
The transformation from map to world frame.
Definition map.hpp:583
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...
Map & operator=(const Map &)=delete
The copy assignment operator is explicitly deleted.
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...
Map(const Config &map_config, const typename Data< FldT, ColB, IdB >::Config &data_config=typename Data< FldT, ColB, IdB >::Config())
The map constructor.
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< 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.
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:197
const Eigen::Isometry3f & getTMW() const
Get the transformation from world to map frame.
Definition map.hpp:118
const OctreeType & getOctree() const
Return a constant reference to the internal se::Octree.
Definition map.hpp:559
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 ...
const Eigen::Vector3f dimension_
The dimensions of the map.
Definition map.hpp:581
OctreeType::SurfaceMesh SurfaceMesh
Definition map.hpp:39
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.
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, 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,...
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 Eigen::Vector3f & getDim() const
Get the dimensions of the map in [meter] (length x width x height)
Definition map.hpp:138
static const Eigen::Matrix< float, 3, 8 > corner_rel_steps_
The eight relative unit corner offsets.
Definition map.hpp:594
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,...
float getRes() const
Get the resolution of the map in [meter/voxel].
Definition map.hpp:148
OctreeType::StructureMesh StructureMesh
Definition map.hpp:40
Definition map.hpp:27
DataT::Config DataConfigType
Definition octree.hpp:41
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
Id
Definition setup_util.hpp:20
Res
Definition setup_util.hpp:23
Field
Definition setup_util.hpp:18
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:62