3232
3333namespace {
3434
35- inline Voxel ToVoxelCoordinates (const Eigen::Vector3d &point, const double voxel_size) {
36- return Voxel (static_cast <int >(std::floor (point.x () / voxel_size)),
37- static_cast <int >(std::floor (point.y () / voxel_size)),
38- static_cast <int >(std::floor (point.z () / voxel_size)));
35+ inline Eigen::Vector3i ToVoxelCoordinates (const Eigen::Vector3d &point, const double voxel_size) {
36+ return Eigen::Vector3i (static_cast <int >(std::floor (point.x () / voxel_size)),
37+ static_cast <int >(std::floor (point.y () / voxel_size)),
38+ static_cast <int >(std::floor (point.z () / voxel_size)));
3939}
4040
4141static constexpr unsigned int min_points_for_covariance_computation = 10 ;
@@ -79,22 +79,22 @@ VoxelMap::VoxelMap(const double voxel_size, const double max_distance)
7979
8080void VoxelMap::IntegrateFrame (const Vector3dVector &points, const Eigen::Matrix4d &pose) {
8181 Vector3dVector points_transformed (points.size ());
82- const auto &R = pose.block <3 , 3 >(0 , 0 );
83- const auto &t = pose.block <3 , 1 >(0 , 3 );
82+ const Eigen::Matrix3d &R = pose.block <3 , 3 >(0 , 0 );
83+ const Eigen::Vector3d &t = pose.block <3 , 1 >(0 , 3 );
8484 std::transform (points.cbegin (), points.cend (), points_transformed.begin (),
8585 [&](const auto &point) { return R * point + t; });
8686 AddPoints (points_transformed);
8787}
8888
8989void VoxelMap::AddPoints (const Vector3dVector &points) {
90- std::for_each (points.cbegin (), points.cend (), [&](const auto &point) {
91- const auto voxel = ToVoxelCoordinates (point, voxel_size_);
90+ std::for_each (points.cbegin (), points.cend (), [&](const Eigen::Vector3d &point) {
91+ const Voxel voxel = ToVoxelCoordinates (point, voxel_size_);
9292 const auto &[it, inserted] = map_.insert ({voxel, VoxelBlock ()});
9393 if (!inserted) {
94- const auto &voxel_points = it->second ;
95- if (voxel_points .size () == max_points_per_normal_computation ||
96- std::any_of (voxel_points .cbegin (), voxel_points .cend (),
97- [&](const auto &voxel_point) {
94+ const VoxelBlock &voxel_block = it->second ;
95+ if (voxel_block .size () == max_points_per_normal_computation ||
96+ std::any_of (voxel_block .cbegin (), voxel_block .cend (),
97+ [&](const Eigen::Vector3d &voxel_point) {
9898 return (voxel_point - point).norm () < map_resolution_;
9999 })) {
100100 return ;
@@ -108,9 +108,10 @@ Vector3dVector VoxelMap::Pointcloud() const {
108108 Vector3dVector points;
109109 points.reserve (map_.size () * max_points_per_normal_computation);
110110 std::for_each (map_.cbegin (), map_.cend (), [&](const auto &map_element) {
111- const auto &voxel_points = map_element.second ;
112- std::for_each (voxel_points.cbegin (), voxel_points.cend (),
113- [&](const auto &p) { points.emplace_back (p.template cast <double >()); });
111+ const VoxelBlock &voxel_block = map_element.second ;
112+ std::for_each (voxel_block.cbegin (), voxel_block.cend (), [&](const Eigen::Vector3d &p) {
113+ points.emplace_back (p.template cast <double >());
114+ });
114115 });
115116 points.shrink_to_fit ();
116117 return points;
@@ -121,8 +122,8 @@ std::tuple<Vector3dVector, Vector3dVector> VoxelMap::PerVoxelMeanAndNormal() con
121122 voxel_means.reserve (map_.size ());
122123 Vector3dVector voxel_normals;
123124 voxel_normals.reserve (map_.size ());
124- std::for_each (map_.cbegin (), map_.cend (), [&](const auto &inner_block ) {
125- const auto &voxel_block = inner_block .second ;
125+ std::for_each (map_.cbegin (), map_.cend (), [&](const auto &map_element ) {
126+ const VoxelBlock &voxel_block = map_element .second ;
126127 if (voxel_block.size () >= min_points_for_covariance_computation) {
127128 const auto &[mean, normal] = ComputeMeanAndNormal (voxel_block);
128129 voxel_means.emplace_back (mean);
@@ -135,10 +136,10 @@ std::tuple<Vector3dVector, Vector3dVector> VoxelMap::PerVoxelMeanAndNormal() con
135136}
136137
137138void VoxelMap::RemovePointsFarFromLocation (const Eigen::Vector3d &origin) {
138- const auto max_distance2 = max_distance_ * max_distance_;
139+ const double max_distance2 = max_distance_ * max_distance_;
139140 for (auto it = map_.begin (); it != map_.end ();) {
140141 const auto &[voxel, voxel_points] = *it;
141- const auto &pt = voxel_points.front ();
142+ const Eigen::Vector3d &pt = voxel_points.front ();
142143 if ((pt - origin).squaredNorm () >= (max_distance2)) {
143144 it = map_.erase (it);
144145 } else {
0 commit comments