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 
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>("ice.ShapesTopicName",
48  "ShapesTopic",
49  "Name of the topic on which shapes are reported.");
50  defineOptionalProperty<std::string>(
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
86  {
87  }
88 
89  void
91  {
92  }
93 
94  void
96  {
97  // Fetch input point cloud.
98  pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
99  if (waitForPointClouds())
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  {
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 
155  {
158  }
159 
160 } // 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::SegmentAABBShapesProviderPropertyDefinitions::SegmentAABBShapesProviderPropertyDefinitions
SegmentAABBShapesProviderPropertyDefinitions(std::string prefix)
Definition: SegmentAABBShapesProvider.cpp:39
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:1152
visionx::SegmentAABBShapesProvider::getDefaultName
std::string getDefaultName() const override
Definition: SegmentAABBShapesProvider.cpp:61
Pose.h
visionx::SegmentAABBShapesProvider::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Definition: SegmentAABBShapesProvider.cpp:67
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: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
visionx::SegmentAABBShapesProvider::process
void process() override
Definition: SegmentAABBShapesProvider.cpp:95
visionx::SegmentAABBShapesProvider::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Definition: SegmentAABBShapesProvider.cpp:76
visionx::SegmentAABBShapesProvider::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Definition: SegmentAABBShapesProvider.cpp:90
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:221
visionx::PointCloudProcessor::waitForPointClouds
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Definition: PointCloudProcessor.cpp:458
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:207
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::SegmentAABBShapesProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SegmentAABBShapesProvider.cpp:154
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::SegmentAABBShapesProvider::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Definition: SegmentAABBShapesProvider.cpp:85
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
visionx::SegmentAABBShapesProviderPropertyDefinitions
Property definitions of SegmentAABBShapesProvider.
Definition: SegmentAABBShapesProvider.h:43
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
SegmentAABBShapesProvider.h