shapes_from_aabbs.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 
5 #include <Eigen/Core>
6 
7 #include <pcl/point_cloud.h>
8 #include <pcl/point_types.h>
9 #include <pcl/PointIndices.h>
10 
11 #include <SemanticObjectRelations/Shapes/shape_containers.h>
12 #include <SemanticObjectRelations/Shapes/AxisAlignedBoundingBox.h>
13 
14 #include <SimoxUtility/math/SoftMinMax.h>
15 #include <SimoxUtility/shapes/AxisAlignedBoundingBox.h>
16 
18 
19 
20 namespace armarx::semantic
21 {
22 
23  /// Get the AABBs of each point cloud segment in `pointCloud`.
24  semrel::ShapeList getShapesFromAABBs(const pcl::PointCloud<pcl::PointXYZL>& pointCloud);
25  /// Get the AABBs of each point cloud segment in `pointCloud`.
26  semrel::ShapeList getShapesFromAABBs(const pcl::PointCloud<pcl::PointXYZRGBL>& pointCloud);
27 
28  /// Return the AABBs of each point cloud segment in a `pointCloud`.
29  semrel::ShapeList
30  getShapesFromSoftAABBs(const pcl::PointCloud<pcl::PointXYZL>& pointCloud, float outlierRatio);
31  /// Return the AABBs of each point cloud segment in a `pointCloud`.
32  semrel::ShapeList
33  getShapesFromSoftAABBs(const pcl::PointCloud<pcl::PointXYZRGBL>& pointCloud, float outlierRatio);
34 
35  /// Get the given AABBs as a `semrel::ShapeList`.
36  semrel::ShapeList getShapesFromAABBs(const std::map<uint32_t, semrel::AxisAlignedBoundingBox>& segmentAABBs);
37 
38 
39  /// Get the AABB of the given point cloud segment.
40  template <class PointT, class IndicesT = pcl::PointIndices>
42  getAABB(const pcl::PointCloud<PointT>& pointCloud, const IndicesT& segmentIndices);
43 
44  /**
45  * @brief Get the AABB of each point cloud segment.
46  * Only keys of `segmentIndices` are used; point labels are not used.
47  */
48  template <class PointT, class IndicesT = pcl::PointIndices>
49  std::map<uint32_t, semrel::AxisAlignedBoundingBox>
50  getAABBs(const pcl::PointCloud<PointT>& pointCloud,
51  const std::map<uint32_t, IndicesT>& segmentIndices);
52 
53 
54  /**
55  * @brief Get the soft AABB of the given point cloud segment.
56  * @param outlierRatio The allowed outlier ratio. (@see `semrel::SoftMinMax`)
57  */
58  template <class PointT>
60  getSoftAABB(const pcl::PointCloud<PointT>& pointCloud, const pcl::PointIndices& segmentIndices,
61  float outlierRatio);
62 
63  /**
64  * @brief Get the soft AABBs of each point cloud segment.
65  * @param outlierRatio The allowed outlier ratio. (@see `semrel::SoftMinMax`)
66  */
67  template <class PointT>
68  std::map<uint32_t, semrel::AxisAlignedBoundingBox>
69  getSoftAABBs(const pcl::PointCloud<PointT>& pointCloud,
70  const std::map<uint32_t, pcl::PointIndices>& segmentIndices,
71  float outlierRatio);
72 
73 }
74 
76 {
77  /// @throws `armarx::ExpressionException` if `a` is not less or equal `b`.
78  void checkLessEqual(float a, float b, const std::string& msg = "");
79 }
80 
81 
82 
83 template <class PointT, class IndicesT>
85 armarx::semantic::getAABB(const pcl::PointCloud<PointT>& pointCloud, const IndicesT& segmentIndices)
86 {
87  return semrel::AxisAlignedBoundingBox(visionx::tools::getAABB(pointCloud, segmentIndices));
88 }
89 
90 template <class PointT, class IndicesT>
91 std::map<uint32_t, semrel::AxisAlignedBoundingBox> armarx::semantic::getAABBs(
92  const pcl::PointCloud<PointT>& pointCloud, const std::map<uint32_t, IndicesT>& segmentIndices)
93 {
94  std::map<uint32_t, semrel::AxisAlignedBoundingBox> aabbs;
95  for (const auto& [label, aabb] : visionx::tools::getSegmentAABBs(pointCloud, segmentIndices))
96  {
97  aabbs.emplace(label, semrel::AxisAlignedBoundingBox(aabb.limits()));
98  }
99  return aabbs;
100 }
101 
102 
103 
104 template <class PointT>
106 armarx::semantic::getSoftAABB(const pcl::PointCloud<PointT>& pointCloud,
107  const pcl::PointIndices& indices, float outlierRatio)
108 {
109  detail::checkLessEqual(0, outlierRatio);
110  detail::checkLessEqual(outlierRatio, 0.5f);
111 
112  simox::math::SoftMinMax minMaxX(outlierRatio, indices.indices.size());
113  simox::math::SoftMinMax minMaxY(outlierRatio, indices.indices.size());
114  simox::math::SoftMinMax minMaxZ(outlierRatio, indices.indices.size());
115 
116  for (int index : indices.indices)
117  {
118  const PointT& point = pointCloud[static_cast<std::size_t>(index)];
119 
120  minMaxX.add(point.x);
121  minMaxY.add(point.y);
122  minMaxZ.add(point.z);
123  }
124 
126  aabb.minX() = minMaxX.getSoftMin();
127  aabb.maxX() = minMaxX.getSoftMax();
128  aabb.minY() = minMaxY.getSoftMin();
129  aabb.maxY() = minMaxY.getSoftMax();
130  aabb.minZ() = minMaxZ.getSoftMin();
131  aabb.maxZ() = minMaxZ.getSoftMax();
132 
133  return aabb;
134 }
135 
136 
137 template <class PointT>
138 std::map<uint32_t, semrel::AxisAlignedBoundingBox>
139 armarx::semantic::getSoftAABBs(const pcl::PointCloud<PointT>& pointCloud,
140  const std::map<uint32_t, pcl::PointIndices>& segmentIndices,
141  float outlierRatio)
142 {
143  std::map<uint32_t, semrel::AxisAlignedBoundingBox> segmentAABBs;
144  for (const auto& [label, indices] : segmentIndices)
145  {
146  segmentAABBs[label] = getSoftAABB(pointCloud, indices, outlierRatio);;
147  }
148  return segmentAABBs;
149 }
armarx::semantic::getShapesFromSoftAABBs
semrel::ShapeList getShapesFromSoftAABBs(const pcl::PointCloud< pcl::PointXYZL > &pointCloud, float outlierRatio)
Return the AABBs of each point cloud segment in a pointCloud.
Definition: shapes_from_aabbs.cpp:63
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::semantic::getShapesFromAABBs
semrel::ShapeList getShapesFromAABBs(const pcl::PointCloud< pcl::PointXYZL > &pointCloud)
Get the AABBs of each point cloud segment in pointCloud.
Definition: shapes_from_aabbs.cpp:25
armarx::semantic::getAABBs
std::map< uint32_t, semrel::AxisAlignedBoundingBox > getAABBs(const pcl::PointCloud< PointT > &pointCloud, const std::map< uint32_t, IndicesT > &segmentIndices)
Get the AABB of each point cloud segment.
Definition: shapes_from_aabbs.h:91
armarx::semantic::detail
Definition: shapes_from_aabbs.h:75
segments.h
armarx::aron::simox::arondto::AxisAlignedBoundingBox
::simox::arondto::AxisAlignedBoundingBox AxisAlignedBoundingBox
Definition: simox.h:14
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
pcl::graph::indices
pcl::PointIndices::Ptr indices(const PCG &g)
Retrieve the indices of the points of the point cloud stored in a point cloud graph that actually bel...
Definition: point_cloud_graph.h:737
visionx::tools::getSegmentAABBs
std::vector< simox::AxisAlignedBoundingBox > getSegmentAABBs(const pcl::PointCloud< PointT > &pointCloud, const std::vector< IndicesT > &segmentIndices)
Definition: segments.h:161
armarx::PointT
pcl::PointXYZRGBL PointT
Definition: Common.h:28
armarx::semantic::getAABB
semrel::AxisAlignedBoundingBox getAABB(const pcl::PointCloud< PointT > &pointCloud, const IndicesT &segmentIndices)
Get the AABB of the given point cloud segment.
Definition: shapes_from_aabbs.h:85
visionx::tools::getAABB
simox::AxisAlignedBoundingBox getAABB(const PointCloudT &pointCloud, const pcl::PointIndices &indices={})
Get the axis-aligned bounding-box of the given point cloud.
Definition: AABB.h:27
armarx::semantic::detail::checkLessEqual
void checkLessEqual(float a, float b, const std::string &msg="")
Definition: shapes_from_aabbs.cpp:74
armarx::semantic
Definition: ShapesSupportRelations.cpp:32
armarx::semantic::getSoftAABBs
std::map< uint32_t, semrel::AxisAlignedBoundingBox > getSoftAABBs(const pcl::PointCloud< PointT > &pointCloud, const std::map< uint32_t, pcl::PointIndices > &segmentIndices, float outlierRatio)
Get the soft AABBs of each point cloud segment.
Definition: shapes_from_aabbs.h:139
armarx::semantic::getSoftAABB
semrel::AxisAlignedBoundingBox getSoftAABB(const pcl::PointCloud< PointT > &pointCloud, const pcl::PointIndices &segmentIndices, float outlierRatio)
Get the soft AABB of the given point cloud segment.
Definition: shapes_from_aabbs.h:106