ShapesSupportRelations.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::ShapesSupportRelations
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 "ShapesSupportRelations.h"
24 
25 #include <SemanticObjectRelations/SupportAnalysis/json.h>
26 
30 
31 
33 {
36  {
37  // ICE
38 
39  defineOptionalProperty<std::string>("ice.ShapesTopicName", "ShapesTopic",
40  "Name of the topic on which shapes are reported.");
41 
42  defineOptionalProperty<std::string>("ice.SemanticGraphName", "Support",
43  "Name of the graph when reported to the SemanticGraphStorage topic.");
44  defineOptionalProperty<std::string>("ice.SemanticGraphTopicName", "SemanticGraphTopic",
45  "Name of SemanticGraphStorage topic.");
46 
47  defineOptionalProperty<std::string>("ice.RobotStateComponentName", "RobotStateComponent",
48  "Name of the robot state component.");
49 
50  defineOptionalProperty<std::string>("pc.PointCloudFrameName", GlobalFrame,
51  "Name of the frame of the point cloud coordinates. \n"
52  "Used to determine the gravity vector.");
53 
54  defineOptionalProperty<std::string>("ice.DebugObserverName", "DebugObserver",
55  "Name of the topic the DebugObserver listens to.");
56 
57 
58  // PARAMETERS
59 
60  defineOptionalProperty<float>(
61  "GR.ContactMargin", 10.,
62  "Distance by which objects are increased for contact computation [mm].")
63  .setMin(0.);
64 
65  defineOptionalProperty<float>(
66  "GR.VerticalSepPlaneAngleMax", 10.,
67  "Maximal angle [degree] between gravity and separating plane for \n"
68  "separating plane to be considered vertical.")
69  .setMin(0.);
70 
71  defineOptionalProperty<bool>(
72  "GR.VerticalSepPlaneAssumeSupport", false,
73  "If true, edges are added if the separating plane is vertical.");
74 
75 
76  defineOptionalProperty<bool>(
77  "UD.enabled", true,
78  "Enable or disble uncertainty detection (UD).");
79 
80  defineOptionalProperty<float>(
81  "UD.SupportAreaRatioMin", 0.7f,
82  "Minimal support area ratio of an object to consider it safe.")
83  .setMin(0.).setMax(1.);
84 
85 
86 
87  // VISUALIZATION
88 
90  semrel::VisuLevel::DISABLED);
91  }
92 
94  {
95  return "ShapesSupportRelations";
96  }
97 
98 
100  {
101  // Register offered topices and used proxies here.
102 
103  usingTopicFromProperty("ice.ShapesTopicName");
104 
105  offeringTopicFromProperty("ice.SemanticGraphTopicName");
106  getProperty(graphName, "ice.SemanticGraphName");
107 
108  offeringTopicFromProperty("ice.DebugObserverName");
109  debugDrawer.offeringTopic(*this); // Calls this->offeringTopic().
110 
111  // usingProxyFromProperty("ice.RobotStateComponentName"); // RobotStateComponent is not required.
112  getProperty(pointCloudFrameName, "pc.PointCloudFrameName");
113 
114  supportAnalysis.setContactMargin(getProperty<float>("GR.ContactMargin"));
115  supportAnalysis.setVertSepPlaneAngleMax(getProperty<float>("GR.VerticalSepPlaneAngleMax"));
116  supportAnalysis.setVertSepPlaneAssumeSupport(getProperty<bool>("GR.VerticalSepPlaneAssumeSupport"));
117 
118  supportAnalysis.setUncertaintyDetectionEnabled(getProperty<bool>("UD.enabled"));
119  supportAnalysis.setSupportAreaRatioMin(getProperty<float>("UD.SupportAreaRatioMin"));
120  }
121 
122 
124  {
125  // Get topics and proxies here. Pass the *InterfacePrx type as template argument.
126  // Robot state component may not be available.
127  getProxyFromProperty(robotStateComponent, "ice.RobotStateComponentName", false, "", false);
128  getTopicFromProperty(graphTopic, "ice.SemanticGraphTopicName");
129 
130  if (!robotStateComponent)
131  {
132  ARMARX_INFO << "RobotStateComponent is not available. Global gravity vector "
133  << gravityInGlobal.transpose() << " will be used.";
134  }
135 
136  getTopicFromProperty(debugObserver, "ice.DebugObserverName");
137  debugDrawer.getTopic(*this); // Calls this->getTopic().
138 
139  setArmarXHooksAsImplementation(debugDrawer, getName());
141  }
142 
143 
145  {
146  robotStateComponent = nullptr;
147  }
148 
149 
151  {
152  }
153 
154 
156  const std::string& name, const data::ShapeList& objectsIce, const Ice::Current&)
157  {
158  const semrel::ShapeList objects = semantic::fromIce(objectsIce);
159  const semrel::ShapeMap objectsMap = semrel::toShapeMap(objects);
160 
161  std::set<semrel::ShapeID> safeObjectsIDs;
162  // Use the lowest object as safe object?
163 
164  const data::Graph graph = extractSupportGraph(objectsMap, safeObjectsIDs);
165 
166  std::stringstream graphName;
167  graphName << this->graphName << " (" << name << ")";
168  graphTopic->reportGraph(graphName.str(), graph);
169  }
170 
171 
173  const data::ShapeList& objectsIce, const Ice::LongSeq& safeObjectIDsIce, const Ice::Current&)
174  {
175  const semrel::ShapeList objects = semantic::fromIce(objectsIce);
176  const semrel::ShapeMap objectsMap = semrel::toShapeMap(objects);
177 
178  std::set<semrel::ShapeID> safeObjectIDs;
179  for (long id : safeObjectIDsIce)
180  {
181  safeObjectIDs.insert(semrel::ShapeID { id });
182  }
183 
184  const data::Graph ice = extractSupportGraph(objectsMap, safeObjectIDs);
185  return ice;
186  }
187 
189  const semrel::ShapeMap& objects, const std::set<semrel::ShapeID>& safeObjectIDs)
190  {
191  // Update gravity vector.
192  supportAnalysis.setGravityVector(getGravityFromRobotStateComponent());
193 
194  // Perform support analysis.
195  const semrel::SupportGraph supportGraph = supportAnalysis.performSupportAnalysis(objects, safeObjectIDs);
196  ARMARX_INFO << "Support Graph: " << supportGraph.str();
197 
198  const data::Graph graphIce = semantic::toIce(supportGraph, objects);
199  return graphIce;
200  }
201 
202 
203  Eigen::Vector3f ShapesSupportRelations::getGravityFromRobotStateComponent()
204  {
205  if (!robotStateComponent || pointCloudFrameName == armarx::GlobalFrame)
206  {
207  return gravityInGlobal;
208  }
209  else
210  {
212  robotStateComponent, "", {}, VirtualRobot::RobotIO::eStructure);
213 
214  FramedDirection dir(gravityInGlobal, armarx::GlobalFrame, "");
215  dir.changeFrame(robot, pointCloudFrameName);
216  return dir.toEigen();
217  }
218  }
219 
220 
222  {
225  }
226 
227 
228 }
armarx::DebugDrawerTopic::offeringTopic
void offeringTopic(ManagedIceObject &component, const std::string &topicNameOverride="") const
Call offeringTopic([topicName]) on the given component.
Definition: DebugDrawerTopic.cpp:73
hooks.h
armarx::GlobalFrame
const std::string GlobalFrame
Definition: FramedPose.h:62
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::ShapesSupportRelations::extractSupportGraph
data::Graph extractSupportGraph(const data::ShapeList &objects, const Ice::LongSeq &safeObjectIDs, const Ice::Current &=Ice::emptyCurrent) override
Service: Extract the support graph for objects and return it.
Definition: ShapesSupportRelations.cpp:172
armarx::semantic::setArmarXHooksAsImplementation
void setArmarXHooksAsImplementation(const DebugDrawerInterfacePrx &debugDrawer, const std::string &logTag="SemanticObjectRelations")
Definition: hooks.cpp:7
ShapesSupportRelations.h
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
armarx::Component::getProxyFromProperty
ProxyType getProxyFromProperty(const std::string &propertyName, bool addToDependencies=false, const std::string &endpoints="", bool throwOnProxyError=true)
Get a proxy whose name is specified by the given property.
Definition: Component.h:236
armarx::semantic::ShapesSupportRelationsPropertyDefinitions
Property definitions of ShapesSupportRelations.
Definition: ShapesSupportRelations.h:48
armarx::semantic::ShapesSupportRelations::onInitComponent
void onInitComponent() override
Definition: ShapesSupportRelations.cpp:99
FramedPose.h
armarx::semantic::ShapesSupportRelations::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ShapesSupportRelations.cpp:221
armarx::semantic::properties::defineVisualizationLevel
void defineVisualizationLevel(armarx::ComponentPropertyDefinitions &defs, const std::string &propertyName=defaults::visualizationLevelName, semrel::VisuLevel defaultLevel=semrel::VisuLevel::RESULT, const std::string &description=defaults::visualizationLevelDescription)
Definition: ArmarXVisualizer.cpp:151
armarx::Component::usingTopicFromProperty
void usingTopicFromProperty(const std::string &propertyName, bool orderedPublishing=false)
Use a topic whose name is specified by the given property.
Definition: Component.cpp:160
armarx::Graph
boost::subgraph< CloudGraph > Graph
Definition: Common.h:54
armarx::semantic::ShapesSupportRelationsPropertyDefinitions::ShapesSupportRelationsPropertyDefinitions
ShapesSupportRelationsPropertyDefinitions(std::string prefix)
Definition: ShapesSupportRelations.cpp:34
armarx::semantic::ShapesSupportRelations::onExitComponent
void onExitComponent() override
Definition: ShapesSupportRelations.cpp:150
armarx::semantic::ShapesSupportRelations::onDisconnectComponent
void onDisconnectComponent() override
Definition: ShapesSupportRelations.cpp:144
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::semantic
Definition: ShapesSupportRelations.cpp:32
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::VariantType::FramedDirection
const VariantTypeId FramedDirection
Definition: FramedPose.h:38
armarx::semantic::properties::defaults::visualizationLevelName
const std::string visualizationLevelName
Definition: ArmarXVisualizer.cpp:145
armarx::PropertyUser::getProperty
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
Definition: PropertyUser.h:179
armarx::RemoteRobot::createLocalClone
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
Definition: RemoteRobot.cpp:328
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::semantic::ShapesSupportRelations::reportShapes
void reportShapes(const std::string &name, const data::ShapeList &objects, const Ice::Current &) override
Topic/pipeline: Extract the support graph for objects and publish it to the graph topic.
Definition: ShapesSupportRelations.cpp:155
ice_serialization.h
armarx::DebugDrawerTopic::getTopic
DebugDrawerInterfacePrx getTopic() const
Get the topic.
Definition: DebugDrawerTopic.cpp:58
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::semantic::fromIce
semrel::AttributedGraph fromIce(const semantic::data::Graph &graph)
Definition: graph.h:30
armarx::semantic::ShapesSupportRelations::getDefaultName
std::string getDefaultName() const override
Definition: ShapesSupportRelations.cpp:93
armarx::semantic::ShapesSupportRelations::onConnectComponent
void onConnectComponent() override
Definition: ShapesSupportRelations.cpp:123
armarx::semantic::properties::setMinimumVisuLevel
void setMinimumVisuLevel(armarx::PropertyUser &defs, const std::string &propertyName=defaults::visualizationLevelName)
Definition: ArmarXVisualizer.cpp:168
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18