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 
23 #include <VirtualRobot/VirtualRobot.h>
24 
26 
27 #include <SemanticObjectRelations/Shapes.h>
28 #include <SemanticObjectRelations/Spatial.h>
29 #include <SemanticObjectRelations/RelationGraph/json.h>
30 
32 
35 
36 
37 namespace visionx
38 {
39 
42  {
43  defineOptionalProperty<std::string>("ice.DebugObserverName", "DebugObserver",
44  "Name of the topic the DebugObserver listens to.");
45 
46  defineOptionalProperty<std::string>("ice.ShapesTopicName", "ShapesTopic",
47  "Name of the topic on which shapes are reported.");
48  defineOptionalProperty<std::string>("ice.ShapesName", "SegmentAABBs",
49  "Name to use when reporting the extracted shapes.");
50 
51  defineOptionalProperty<float>("aabb.OutlierRate", 0.01f, "Allowed outliers for soft AABBs.")
52  .setMin(0).setMax(0.5);
53 
54  defineOptionalProperty<bool>("visu.Enabled", false, "Enable visualization of result.");
55  }
56 
57 
59  {
60  return "SegmentAABBShapesProvider";
61  }
62 
63 
65  {
66  offeringTopicFromProperty("ice.ShapesTopicName");
67 
68  offeringTopicFromProperty("ice.DebugObserverName");
69  debugDrawer.offeringTopic(*this);
70  }
71 
72 
74  {
75  getTopicFromProperty(shapesTopic, "ice.ShapesTopicName");
76 
77  getTopicFromProperty(debugObserver, "ice.DebugObserverName");
78  debugDrawer.getTopic(*this);
79  }
80 
81 
83  {
84  }
85 
87  {
88  }
89 
90 
92  {
93  // Fetch input point cloud.
94  pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
95  if (waitForPointClouds())
96  {
97  getPointClouds(inputCloud);
98  }
99  else
100  {
101  ARMARX_VERBOSE << "Timeout or error while waiting for point cloud data";
102  return;
103  }
104 
105  // Do processing.
106 
107  const float outlierRate = getProperty<float>("aabb.OutlierRate");
108 
109  semrel::ShapeList shapes;
110  if (outlierRate > 0 && outlierRate < 1)
111  {
112  shapes = armarx::semantic::getShapesFromSoftAABBs(*inputCloud, outlierRate);
113  }
114  else
115  {
117  }
118 
119  const semrel::ShapeMap shapeMap = semrel::toShapeMap(shapes);
120  const semrel::SpatialGraph graph = semrel::spatial::evaluateStaticRelations(shapeMap);
121 
122  debugObserver->setDebugChannel(getName(),
123  {
124  { "Point Cloud Size", new armarx::Variant(static_cast<int>(inputCloud->size())) },
125  { "Point Cloud Time", new armarx::Variant(static_cast<int>(inputCloud->header.stamp)) },
126  { "Num Objects", new armarx::Variant(static_cast<int>(shapes.size())) },
127  });
128 
129  const std::string shapesName = getProperty<std::string>("ice.ShapesName");
130  shapesTopic->reportShapes(shapesName, armarx::semantic::toIce(shapes));
131 
132  if (getProperty<bool>("visu.Enabled"))
133  {
134  for (const auto& [id, box] : shapeMap)
135  {
136  std::stringstream ss;
137  ss << id;
138  debugDrawer.drawBox({ getName(), ss.str() },
139  box->getPosition(), box->getOrientation(), box->getAABB().extents(),
140  debugDrawer.getGlasbeyLUTColor(int(id), 0.5));
141  }
142  }
143  }
144 
145 
147  {
149  }
150 
151 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::DebugDrawerTopic::offeringTopic
void offeringTopic(ManagedIceObject &component, const std::string &topicNameOverride="") const
Call offeringTopic([topicName]) on the given component.
Definition: DebugDrawerTopic.cpp:73
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:63
visionx::SegmentAABBShapesProviderPropertyDefinitions::SegmentAABBShapesProviderPropertyDefinitions
SegmentAABBShapesProviderPropertyDefinitions(std::string prefix)
Definition: SegmentAABBShapesProvider.cpp:40
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::DebugDrawerTopic::getGlasbeyLUTColor
static DrawColor getGlasbeyLUTColor(int id, float alpha=1.f)
Get a color from the Glasbey look-up-table.
Definition: DebugDrawerTopic.cpp:1008
visionx::SegmentAABBShapesProvider::getDefaultName
std::string getDefaultName() const override
Definition: SegmentAABBShapesProvider.cpp:58
Pose.h
visionx::SegmentAABBShapesProvider::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Definition: SegmentAABBShapesProvider.cpp:64
shapes_from_aabbs.h
armarx::Component::offeringTopicFromProperty
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
Definition: Component.cpp:154
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:25
visionx::SegmentAABBShapesProvider::process
void process() override
Definition: SegmentAABBShapesProvider.cpp:91
visionx::SegmentAABBShapesProvider::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Definition: SegmentAABBShapesProvider.cpp:73
visionx::SegmentAABBShapesProvider::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Definition: SegmentAABBShapesProvider.cpp:86
armarx::semantic::toIce
data::Graph toIce(const semrel::AttributedGraph &input)
Definition: graph.cpp:15
armarx::Component::getTopicFromProperty
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
Definition: Component.h:218
visionx::PointCloudProcessor::waitForPointClouds
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Definition: PointCloudProcessor.cpp:433
armarx::DebugDrawerTopic::drawBox
void drawBox(const VisuID &id, const Eigen::Vector3f &position, const Eigen::Quaternionf &orientation, const Eigen::Vector3f &extents, const DrawColor &color=DEFAULTS.colorBox, bool ignoreLengthScale=false)
Draw a box.
Definition: DebugDrawerTopic.cpp:179
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:173
visionx::PointCloudProcessor::getPointClouds
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
Definition: PointCloudProcessor.h:373
visionx::SegmentAABBShapesProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SegmentAABBShapesProvider.cpp:146
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::SegmentAABBShapesProvider::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Definition: SegmentAABBShapesProvider.cpp:82
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
ice_serialization.h
armarx::DebugDrawerTopic::getTopic
DebugDrawerInterfacePrx getTopic() const
Get the topic.
Definition: DebugDrawerTopic.cpp:58
visionx::SegmentAABBShapesProviderPropertyDefinitions
Property definitions of SegmentAABBShapesProvider.
Definition: SegmentAABBShapesProvider.h:44
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
shapes
MiscLib::Vector< std::pair< MiscLib::RefCountPtr< PrimitiveShape >, size_t > > shapes
Definition: ReadMe.txt:92
SegmentAABBShapesProvider.h