SemanticGraphExample.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::SemanticGraphExample
17  * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18  * @date 2020
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "SemanticGraphExample.h"
24 
25 #include <VirtualRobot/VirtualRobot.h>
26 
28 
29 #include "MyGraph.h"
30 #include "json.h"
31 
32 namespace armarx
33 {
34 
36  std::string prefix) :
38  {
39  }
40 
43  {
46 
47  defs->topic(graphTopic, "SemanticGraphTopic");
48 
49  return defs;
50  }
51 
52  std::string
54  {
55  return "SemanticGraphExample";
56  }
57 
58  void
60  {
61  }
62 
63  void
65  {
66  mygraph::MyGraph graph;
67 
68  // Add vertices and set attributes.
69 
70  // Option 1: Prepare vertex attributes beforehand.
71  mygraph::MyVertex vattribs;
72  vattribs.name = "A";
73  vattribs.value = 0.0;
74  auto a = graph.addVertex(semrel::ShapeID{0}, vattribs);
75 
76  vattribs.name = "B";
77  vattribs.value = 0.5;
78  auto b = graph.addVertex(semrel::ShapeID{1}, vattribs);
79 
80  // Option 1: Set attributes after adding.
81  auto c = graph.addVertex(semrel::ShapeID{5});
82  c.attrib().name = "C";
83  c.attrib().value = 1.0;
84 
85  // Add edges and set attributes.
86  auto ab = graph.addEdge(a, b);
87  ab.attrib().value = 0;
88  auto ac = graph.addEdge(a, c);
89  ac.attrib().value = 1;
90  auto bc = graph.addEdge(b, c);
91  bc.attrib().value = 2;
92 
93  // Set graph attributes
94  graph.attrib().position = {1, 2, 3};
95 
96  graphTopic->reportGraph("MyGraph", armarx::semantic::toIce(graph));
97  }
98 
99  void
101  {
102  }
103 
104  void
106  {
107  }
108 
109 } // namespace armarx
mygraph::MyVertex::name
std::string name
Definition: MyGraph.h:9
SemanticGraphExample.h
mygraph::MyVertex
Definition: MyGraph.h:7
semrel::RelationGraph
Definition: forward_declarations.h:27
armarx::SemanticGraphExample::onConnectComponent
void onConnectComponent() override
Definition: SemanticGraphExample.cpp:64
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::semantic::toIce
data::Graph toIce(const semrel::AttributedGraph &input)
Definition: graph.cpp:15
armarx::SemanticGraphExamplePropertyDefinitions
Property definitions of SemanticGraphExample.
Definition: SemanticGraphExample.h:36
mygraph::MyVertex::value
float value
Definition: MyGraph.h:10
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::SemanticGraphExample::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SemanticGraphExample.cpp:42
armarx::SemanticGraphExample::onDisconnectComponent
void onDisconnectComponent() override
Definition: SemanticGraphExample.cpp:100
armarx::SemanticGraphExample::onInitComponent
void onInitComponent() override
Definition: SemanticGraphExample.cpp:59
armarx::SemanticGraphExample::onExitComponent
void onExitComponent() override
Definition: SemanticGraphExample.cpp:105
armarx::SemanticGraphExamplePropertyDefinitions::SemanticGraphExamplePropertyDefinitions
SemanticGraphExamplePropertyDefinitions(std::string prefix)
Definition: SemanticGraphExample.cpp:35
armarx::SemanticGraphExample::getDefaultName
std::string getDefaultName() const override
Definition: SemanticGraphExample.cpp:53
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle< class PropertyDefinitionContainer >
json.h
ice_serialization.h
MyGraph.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27