SegmentSpatialRelations.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::SegmentSpatialRelations
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
48 "ice.SemanticGraphTopicName",
49 "SemanticGraphTopic",
50 "Name of the topic on which attributed graphs are reported.");
51
53 "ice.GraphName", "Spatial", "Name to use when reporting the extracted graph.");
54
55 defineOptionalProperty<float>("aabb.OutlierRate", 0.01f, "Allowed outliers for AABBs.");
56 }
57
58 std::string
60 {
61 return "SegmentSpatialRelations";
62 }
63
64 void
66 {
67 offeringTopicFromProperty("ice.DebugObserverName");
68 offeringTopicFromProperty("ice.SemanticGraphTopicName");
69 debugDrawer.offeringTopic(*this);
70 }
71
72 void
74 {
75 getTopicFromProperty(debugObserver, "ice.DebugObserverName");
76 getTopicFromProperty(graphStorage, "ice.SemanticGraphTopicName");
77 debugDrawer.getTopic(*this);
78
80 }
81
82 void
86
87 void
91
92 void
94 {
95 // Fetch input point cloud.
96 pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
98 {
99 getPointClouds(inputCloud);
100 }
101 else
102 {
103 ARMARX_VERBOSE << "Timeout or error while waiting for point cloud data";
104 return;
105 }
106
107 // Do processing.
108
109 const float outlierRate = getProperty<float>("aabb.OutlierRate");
110
111 semrel::ShapeList shapes;
112 if (outlierRate > 0 && outlierRate < 1)
113 {
114 shapes = armarx::semantic::getShapesFromSoftAABBs(*inputCloud, outlierRate);
115 }
116 else
117 {
118 shapes = armarx::semantic::getShapesFromAABBs(*inputCloud);
119 }
120
121 const semrel::ShapeMap shapeMap = semrel::toShapeMap(shapes);
122 const semrel::SpatialGraph graph = semrel::spatial::evaluateStaticRelations(shapeMap);
123
124 debugObserver->setDebugChannel(
125 getName(),
126 {
127 {"Point Cloud Size", new armarx::Variant(static_cast<int>(inputCloud->size()))},
128 {"Point Cloud Time",
129 new armarx::Variant(static_cast<int>(inputCloud->header.stamp))},
130 {"Num Objects", new armarx::Variant(static_cast<int>(shapes.size()))},
131 });
132
133 const std::string graphName = getProperty<std::string>("ice.GraphName");
134 graphStorage->reportGraph(graphName, armarx::semantic::toIce(graph, shapeMap));
135 }
136
143
144} // 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
void enableResultPointClouds(std::string resultProviderName="")
Enables visualization.
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Property definitions of SegmentSpatialRelations.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
std::string getDefaultName() const 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.