pointcloud_bitfield.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * A repertory of multi primitive-to-primitive (MP2P) ICP algorithms in C++
3  * Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
12 #pragma once
13 
14 #include <mp2p_icp/layer_name_t.h>
15 #include <mp2p_icp/metricmap.h>
16 
17 #include <cstdint>
18 #include <cstdlib>
19 #include <map>
20 #include <optional>
21 #include <set>
22 #include <vector>
23 
24 namespace mp2p_icp
25 {
35 {
36  pointcloud_bitfield_t() = default;
37  ~pointcloud_bitfield_t() = default;
38 
40  {
41  public:
42  DenseOrSparseBitField() = default;
43  ~DenseOrSparseBitField() = default;
44 
45  void assign(size_t numElements, bool dense)
46  {
47  if (dense)
48  {
49  sparse_.clear();
50  if (!dense_) dense_.emplace();
51  dense_->assign(numElements, false);
52  }
53  else
54  {
55  dense_.reset();
56  sparse_.clear();
57  }
58  }
59 
60  [[nodiscard]] bool operator[](const size_t id) const
61  {
62  if (dense_.has_value())
63  return dense_.value()[id];
64  else
65  return sparse_.count(id) != 0;
66  }
67  void mark_as_set(const size_t id)
68  {
69  if (dense_.has_value())
70  dense_.value()[id] = true;
71  else
72  sparse_.insert(id);
73  }
74 
75  private:
76  std::optional<std::vector<bool>> dense_;
77  std::set<uint64_t> sparse_;
78  };
79 
82  std::map<layer_name_t, DenseOrSparseBitField> point_layers;
83  std::vector<bool> lines;
84  std::vector<bool> planes;
87  void initialize_from(const metric_map_t& pc)
88  {
89  // Points:
90  // Done in this way to avoid avoidable memory reallocations.
91  for (const auto& kv : pc.layers)
92  {
93  ASSERT_(kv.second);
94  auto* nn = mp2p_icp::MapToNN(*kv.second, false /*dont throw*/);
95  if (!nn) continue;
96  point_layers[kv.first].assign(
97  nn->nn_index_count(), nn->nn_has_indices_or_ids());
98  }
99  std::set<layer_name_t> layersToRemove;
100  for (auto& kv : point_layers)
101  {
102  if (pc.layers.count(kv.first) == 0) layersToRemove.insert(kv.first);
103  }
104  for (const auto& ly : layersToRemove) point_layers.erase(ly);
105 
106  // Lines:
107  lines.assign(pc.lines.size(), false);
108 
109  // planes:
110  planes.assign(pc.planes.size(), false);
111  }
112 };
113 
116 } // namespace mp2p_icp
mp2p_icp::pointcloud_bitfield_t::lines
std::vector< bool > lines
Definition: pointcloud_bitfield.h:83
mp2p_icp
Definition: covariance.h:17
mp2p_icp::pointcloud_bitfield_t::initialize_from
void initialize_from(const metric_map_t &pc)
Definition: pointcloud_bitfield.h:87
mp2p_icp::pointcloud_bitfield_t::planes
std::vector< bool > planes
Definition: pointcloud_bitfield.h:84
mp2p_icp::pointcloud_bitfield_t::DenseOrSparseBitField::operator[]
bool operator[](const size_t id) const
Definition: pointcloud_bitfield.h:60
mp2p_icp::pointcloud_bitfield_t::DenseOrSparseBitField
Definition: pointcloud_bitfield.h:39
mp2p_icp::pointcloud_bitfield_t::DenseOrSparseBitField::~DenseOrSparseBitField
~DenseOrSparseBitField()=default
layer_name_t.h
mp2p_icp::pointcloud_bitfield_t::DenseOrSparseBitField::dense_
std::optional< std::vector< bool > > dense_
Definition: pointcloud_bitfield.h:76
mp2p_icp::metric_map_t::planes
std::vector< plane_patch_t > planes
Definition: metricmap.h:82
mp2p_icp::pointcloud_bitfield_t::DenseOrSparseBitField::DenseOrSparseBitField
DenseOrSparseBitField()=default
mp2p_icp::metric_map_t::lines
std::vector< mrpt::math::TLine3D > lines
Definition: metricmap.h:79
mp2p_icp::pointcloud_bitfield_t::DenseOrSparseBitField::assign
void assign(size_t numElements, bool dense)
Definition: pointcloud_bitfield.h:45
mp2p_icp::pointcloud_bitfield_t::DenseOrSparseBitField::mark_as_set
void mark_as_set(const size_t id)
Definition: pointcloud_bitfield.h:67
mp2p_icp::pointcloud_bitfield_t::pointcloud_bitfield_t
pointcloud_bitfield_t()=default
mp2p_icp::pointcloud_bitfield_t::point_layers
std::map< layer_name_t, DenseOrSparseBitField > point_layers
Definition: pointcloud_bitfield.h:82
metricmap.h
Generic representation of pointcloud(s) and/or extracted features.
mp2p_icp::metric_map_t
Generic container of pointcloud(s), extracted features and other maps.
Definition: metricmap.h:49
mp2p_icp::pointcloud_bitfield_t::DenseOrSparseBitField::sparse_
std::set< uint64_t > sparse_
Definition: pointcloud_bitfield.h:77
mp2p_icp::pointcloud_bitfield_t::~pointcloud_bitfield_t
~pointcloud_bitfield_t()=default
mp2p_icp::MapToNN
const mrpt::maps::NearestNeighborsCapable * MapToNN(const mrpt::maps::CMetricMap &map, bool throwIfNotImplemented)
Definition: metricmap.cpp:686
mp2p_icp::pointcloud_bitfield_t
Definition: pointcloud_bitfield.h:34
mp2p_icp::metric_map_t::layers
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
Definition: metricmap.h:76


mp2p_icp
Author(s):
autogenerated on Wed Oct 23 2024 02:45:40