shapes_from_aabbs.cpp
Go to the documentation of this file.
1 #include "shapes_from_aabbs.h"
2 
4 
5 #include <SemanticObjectRelations/ShapeExtraction/util/SoftMinMax.h>
6 #include <SemanticObjectRelations/Shapes.h>
7 
8 
9 using namespace semrel;
10 using namespace armarx;
11 
12 namespace
13 {
14  template <class PointT>
15  ShapeList
16  getShapesFromAABBs(const pcl::PointCloud<PointT>& pointCloud)
17  {
18  const std::map<uint32_t, pcl::PointIndices> segmentIndices =
19  visionx::tools::getSegmentIndices(pointCloud, false);
20  const std::map<uint32_t, AxisAlignedBoundingBox> aabbs =
21  semantic::getAABBs(pointCloud, segmentIndices);
22  return semantic::getShapesFromAABBs(aabbs);
23  }
24 } // namespace
25 
26 ShapeList
27 semantic::getShapesFromAABBs(const pcl::PointCloud<pcl::PointXYZL>& pointCloud)
28 {
29  return ::getShapesFromAABBs<pcl::PointXYZL>(pointCloud);
30 }
31 
32 ShapeList
33 semantic::getShapesFromAABBs(const pcl::PointCloud<pcl::PointXYZRGBL>& pointCloud)
34 {
35  return ::getShapesFromAABBs<pcl::PointXYZRGBL>(pointCloud);
36 }
37 
38 ShapeList
39 semantic::getShapesFromAABBs(const std::map<uint32_t, AxisAlignedBoundingBox>& segmentAABBs)
40 {
41  semrel::ShapeList shapes;
42  shapes.reserve(segmentAABBs.size());
43  for (const auto& [label, aabb] : segmentAABBs)
44  {
45  shapes.emplace_back(new semrel::Box(aabb, semrel::ShapeID(label)));
46  }
47  return shapes;
48 }
49 
50 namespace
51 {
52  template <class PointT>
53  ShapeList
54  getShapesFromSoftAABBs(const pcl::PointCloud<PointT>& pointCloud, float outlierRatio)
55  {
56  const std::map<uint32_t, pcl::PointIndices> segmentIndices =
57  visionx::tools::getSegmentIndices(pointCloud, false);
58 
59  std::map<uint32_t, AxisAlignedBoundingBox> segmentAABBs;
60  for (const auto& [label, indices] : segmentIndices)
61  {
62  segmentAABBs[label] = semantic::getSoftAABB(pointCloud, indices, outlierRatio);
63  }
64 
65  return semantic::getShapesFromAABBs(segmentAABBs);
66  }
67 } // namespace
68 
69 ShapeList
70 semantic::getShapesFromSoftAABBs(const pcl::PointCloud<pcl::PointXYZL>& pointCloud,
71  float outlierRatio)
72 {
73  return ::getShapesFromSoftAABBs(pointCloud, outlierRatio);
74 }
75 
76 ShapeList
77 semantic::getShapesFromSoftAABBs(const pcl::PointCloud<pcl::PointXYZRGBL>& pointCloud,
78  float outlierRatio)
79 {
80  return ::getShapesFromSoftAABBs(pointCloud, outlierRatio);
81 }
82 
83 void
84 armarx::semantic::detail::checkLessEqual(float a, float b, const std::string& msg)
85 {
86  ARMARX_CHECK_LESS_EQUAL(a, b) << msg;
87 }
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:70
visionx::tools::getSegmentIndices
std::map< uint32_t, pcl::PointIndices > getSegmentIndices(const pcl::PointCloud< LabeledPointT > &labeledCloud, bool excludeZero=false)
Get a map from segment labels to indices of segments' points.
Definition: segments.h:79
shapes_from_aabbs.h
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:27
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:90
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:717
ARMARX_CHECK_LESS_EQUAL
#define ARMARX_CHECK_LESS_EQUAL(lhs, rhs)
This macro evaluates whether lhs is less or equal (<=) rhs and if it turns out to be false it will th...
Definition: ExpressionException.h:109
ExpressionException.h
armarx::semantic::detail::checkLessEqual
void checkLessEqual(float a, float b, const std::string &msg="")
Definition: shapes_from_aabbs.cpp:84
semrel
This file is part of ArmarX.
Definition: forward_declarations.h:24
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:103
shapes
MiscLib::Vector< std::pair< MiscLib::RefCountPtr< PrimitiveShape >, size_t > > shapes
Definition: ReadMe.txt:92
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27