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 
36 namespace 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>(
48  "ice.SemanticGraphTopicName",
49  "SemanticGraphTopic",
50  "Name of the topic on which attributed graphs are reported.");
51 
52  defineOptionalProperty<std::string>(
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 
79  enableResultPointClouds<PointT>();
80  }
81 
82  void
84  {
85  }
86 
87  void
89  {
90  }
91 
92  void
94  {
95  // Fetch input point cloud.
96  pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
97  if (waitForPointClouds())
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  {
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 
139  {
142  }
143 
144 } // namespace visionx
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
armarx::DebugDrawerTopic::offeringTopic
void offeringTopic(ManagedIceObject &component, const std::string &topicNameOverride="") const
Call offeringTopic([topicName]) on the given component.
Definition: DebugDrawerTopic.cpp:80
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
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::SegmentSpatialRelationsPropertyDefinitions
Property definitions of SegmentSpatialRelations.
Definition: SegmentSpatialRelations.h:43
visionx::SegmentSpatialRelations::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Definition: SegmentSpatialRelations.cpp:83
Pose.h
shapes_from_aabbs.h
visionx::SegmentSpatialRelations::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Definition: SegmentSpatialRelations.cpp:88
armarx::Component::offeringTopicFromProperty
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Definition: Component.cpp:159
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::toIce
data::Graph toIce(const semrel::AttributedGraph &input)
Definition: graph.cpp:15
visionx::SegmentSpatialRelations::getDefaultName
std::string getDefaultName() const override
Definition: SegmentSpatialRelations.cpp:59
armarx::Component::getTopicFromProperty
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
Definition: Component.h:221
SegmentSpatialRelations.h
visionx::SegmentSpatialRelations::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SegmentSpatialRelations.cpp:138
visionx::PointCloudProcessor::waitForPointClouds
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Definition: PointCloudProcessor.cpp:458
visionx::SegmentSpatialRelations::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Definition: SegmentSpatialRelations.cpp:73
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:166
visionx::PointCloudProcessor::getPointClouds
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
Definition: PointCloudProcessor.h:380
visionx::SegmentSpatialRelationsPropertyDefinitions::SegmentSpatialRelationsPropertyDefinitions
SegmentSpatialRelationsPropertyDefinitions(std::string prefix)
Definition: SegmentSpatialRelations.cpp:39
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
visionx::SegmentSpatialRelations::process
void process() override
Definition: SegmentSpatialRelations.cpp:93
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::SegmentSpatialRelations::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Definition: SegmentSpatialRelations.cpp:65
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
ice_serialization.h
armarx::DebugDrawerTopic::getTopic
DebugDrawerInterfacePrx getTopic() const
Get the topic.
Definition: DebugDrawerTopic.cpp:62
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
shapes
MiscLib::Vector< std::pair< MiscLib::RefCountPtr< PrimitiveShape >, size_t > > shapes
Definition: ReadMe.txt:92