SegmentAABBShapesProvider.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package VisionX::ArmarXObjects::SegmentAABBShapesProvider
17 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18 * @date 2019
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
25#include <VirtualRobot/VirtualRobot.h>
26
28
31
32#include <SemanticObjectRelations/RelationGraph/json.h>
33#include <SemanticObjectRelations/Shapes.h>
34#include <SemanticObjectRelations/Spatial.h>
35
36namespace visionx
37{
38
40 std::string prefix) :
42 {
43 defineOptionalProperty<std::string>("ice.DebugObserverName",
44 "DebugObserver",
45 "Name of the topic the DebugObserver listens to.");
46
47 defineOptionalProperty<std::string>("ice.ShapesTopicName",
48 "ShapesTopic",
49 "Name of the topic on which shapes are reported.");
51 "ice.ShapesName", "SegmentAABBs", "Name to use when reporting the extracted shapes.");
52
53 defineOptionalProperty<float>("aabb.OutlierRate", 0.01f, "Allowed outliers for soft AABBs.")
54 .setMin(0)
55 .setMax(0.5);
56
57 defineOptionalProperty<bool>("visu.Enabled", false, "Enable visualization of result.");
58 }
59
60 std::string
62 {
63 return "SegmentAABBShapesProvider";
64 }
65
66 void
68 {
69 offeringTopicFromProperty("ice.ShapesTopicName");
70
71 offeringTopicFromProperty("ice.DebugObserverName");
72 debugDrawer.offeringTopic(*this);
73 }
74
75 void
77 {
78 getTopicFromProperty(shapesTopic, "ice.ShapesTopicName");
79
80 getTopicFromProperty(debugObserver, "ice.DebugObserverName");
81 debugDrawer.getTopic(*this);
82 }
83
84 void
88
89 void
93
94 void
96 {
97 // Fetch input point cloud.
98 pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
100 {
101 getPointClouds(inputCloud);
102 }
103 else
104 {
105 ARMARX_VERBOSE << "Timeout or error while waiting for point cloud data";
106 return;
107 }
108
109 // Do processing.
110
111 const float outlierRate = getProperty<float>("aabb.OutlierRate");
112
113 semrel::ShapeList shapes;
114 if (outlierRate > 0 && outlierRate < 1)
115 {
116 shapes = armarx::semantic::getShapesFromSoftAABBs(*inputCloud, outlierRate);
117 }
118 else
119 {
120 shapes = armarx::semantic::getShapesFromAABBs(*inputCloud);
121 }
122
123 const semrel::ShapeMap shapeMap = semrel::toShapeMap(shapes);
124 const semrel::SpatialGraph graph = semrel::spatial::evaluateStaticRelations(shapeMap);
125
126 debugObserver->setDebugChannel(
127 getName(),
128 {
129 {"Point Cloud Size", new armarx::Variant(static_cast<int>(inputCloud->size()))},
130 {"Point Cloud Time",
131 new armarx::Variant(static_cast<int>(inputCloud->header.stamp))},
132 {"Num Objects", new armarx::Variant(static_cast<int>(shapes.size()))},
133 });
134
135 const std::string shapesName = getProperty<std::string>("ice.ShapesName");
136 shapesTopic->reportShapes(shapesName, armarx::semantic::toIce(shapes));
137
138 if (getProperty<bool>("visu.Enabled"))
139 {
140 for (const auto& [id, box] : shapeMap)
141 {
142 std::stringstream ss;
143 ss << id;
144 debugDrawer.drawBox({getName(), ss.str()},
145 box->getPosition(),
146 box->getOrientation(),
147 box->getAABB().extents(),
148 debugDrawer.getGlasbeyLUTColor(int(id), 0.5));
149 }
150 }
151 }
152
159
160} // namespace visionx
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
Definition Component.h:221
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
std::string getName() const
Retrieve name of object.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
The Variant class is described here: Variants.
Definition Variant.h:224
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Property definitions of SegmentAABBShapesProvider.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
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.
data::Graph toIce(const semrel::AttributedGraph &input)
Definition graph.cpp:15
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.