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
9using namespace semrel;
10using namespace armarx;
11
12namespace
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
26ShapeList
27semantic::getShapesFromAABBs(const pcl::PointCloud<pcl::PointXYZL>& pointCloud)
28{
29 return ::getShapesFromAABBs<pcl::PointXYZL>(pointCloud);
30}
31
32ShapeList
33semantic::getShapesFromAABBs(const pcl::PointCloud<pcl::PointXYZRGBL>& pointCloud)
34{
35 return ::getShapesFromAABBs<pcl::PointXYZRGBL>(pointCloud);
36}
37
38ShapeList
39semantic::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
50namespace
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
69ShapeList
70semantic::getShapesFromSoftAABBs(const pcl::PointCloud<pcl::PointXYZL>& pointCloud,
71 float outlierRatio)
72{
73 return ::getShapesFromSoftAABBs(pointCloud, outlierRatio);
74}
75
76ShapeList
77semantic::getShapesFromSoftAABBs(const pcl::PointCloud<pcl::PointXYZRGBL>& pointCloud,
78 float outlierRatio)
79{
80 return ::getShapesFromSoftAABBs(pointCloud, outlierRatio);
81}
82
83void
84armarx::semantic::detail::checkLessEqual(float a, float b, const std::string& msg)
85{
86 ARMARX_CHECK_LESS_EQUAL(a, b) << msg;
87}
#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...
void checkLessEqual(float a, float b, const std::string &msg="")
semrel::ShapeList getShapesFromSoftAABBs(const pcl::PointCloud< pcl::PointXYZL > &pointCloud, float outlierRatio)
Return the AABBs of each point cloud segment in a pointCloud.
semrel::ShapeList getShapesFromAABBs(const pcl::PointCloud< pcl::PointXYZL > &pointCloud)
Get the AABBs of each point cloud segment in pointCloud.
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.
semrel::AxisAlignedBoundingBox getSoftAABB(const pcl::PointCloud< PointT > &pointCloud, const pcl::PointIndices &segmentIndices, float outlierRatio)
Get the soft AABB of the given point cloud segment.
This file offers overloads of toIce() and fromIce() functions for STL container types.
This file is part of ArmarX.
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