6 #include <pcl/point_cloud.h>
7 #include <pcl/PointIndices.h>
9 #include <VisionX/interface/core/DataTypes.h>
11 #include <SimoxUtility/shapes/AxisAlignedBoundingBox.h>
19 void addSegmentIndex(std::map<uint32_t, pcl::PointIndices>& segmentIndices,
20 uint32_t label, std::size_t
index);
22 void addSegmentIndex(std::map<uint32_t, pcl::PointIndices::Ptr>& segmentIndices,
23 uint32_t label, std::size_t
index);
25 template <
class LabeledPo
intT,
class MapValueT>
27 std::map<uint32_t, MapValueT>& segmentIndices,
28 bool excludeZero =
false)
30 for (std::size_t i = 0; i < labeledCloud.points.size(); i++)
32 const uint32_t currentLabel = labeledCloud.points[i].label;
33 if (!(excludeZero && currentLabel == 0))
51 template <
class LabeledPo
intT>
53 const pcl::PointCloud<LabeledPointT>& labeledCloud,
54 bool excludeZero =
false)
59 template <
class LabeledPo
intT>
61 const pcl::PointCloud<LabeledPointT>& labeledCloud,
62 bool excludeZero =
false)
73 template <
class LabeledPo
intT>
75 const pcl::PointCloud<LabeledPointT>& labeledCloud,
bool excludeZero =
false)
77 std::map<uint32_t, pcl::PointIndices> segmentIndices;
79 return segmentIndices;
84 template <
class LabeledPo
intT>
86 const pcl::PointCloud<LabeledPointT>& labeledCloud,
bool excludeZero =
false)
88 std::map<uint32_t, pcl::PointIndices::Ptr> segmentIndices;
90 return segmentIndices;
95 template <
typename LabeledPo
intT>
96 std::set<uint32_t>
getLabelSet(
const pcl::PointCloud<LabeledPointT>& pointCloud)
98 std::set<uint32_t> labels;
99 for (
const auto& point : pointCloud)
101 labels.insert(point.label);
107 template <
class ValueT>
108 std::set<uint32_t>
getLabelSet(
const std::map<uint32_t, ValueT>& segmentIndices)
110 std::set<uint32_t> labels;
111 for (
const auto& [label, _] : segmentIndices)
113 labels.insert(label);
119 template <
class ValueT>
120 std::vector<uint32_t>
getUniqueLabels(
const std::map<uint32_t, ValueT>& segmentIndices)
122 std::vector<uint32_t> labels;
123 labels.reserve(segmentIndices.size());
124 for (
const auto& [label, _] : segmentIndices)
126 labels.push_back(label);
132 template <
class Po
intT>
133 void relabel(pcl::PointCloud<PointT>& pointCloud,
134 const std::map<uint32_t, pcl::PointIndices>& segmentIndices)
136 for (
const auto& [label,
indices] : segmentIndices)
140 pointCloud.at(
index).label = label;
145 template <
class Po
intT>
146 void relabel(pcl::PointCloud<PointT>& pointCloud,
147 const std::map<uint32_t, pcl::PointIndices::Ptr>& segmentIndices)
149 for (
const auto& [label,
indices] : segmentIndices)
153 pointCloud.at(
index).label = label;
159 template <
class Po
intT,
class IndicesT = pcl::Po
intIndices>
160 std::vector<simox::AxisAlignedBoundingBox>
162 const std::vector<IndicesT>& segmentIndices)
164 std::vector<simox::AxisAlignedBoundingBox> aabbs;
165 aabbs.reserve(segmentIndices.size());
166 for (
const auto&
indices : segmentIndices)
173 template <
class Po
intT,
class IndicesT = pcl::Po
intIndices>
174 std::map<uint32_t, simox::AxisAlignedBoundingBox>
176 const std::map<uint32_t, IndicesT>& segmentIndices)
178 std::map<uint32_t, simox::AxisAlignedBoundingBox> aabbs;
179 for (
const auto& [label,
indices] : segmentIndices)