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 <VirtualRobot/VirtualRobot.h>
24 
25 #include "SemanticGraphExample.h"
26 
28 
29 #include "MyGraph.h"
30 #include "json.h"
31 
32 
33 namespace armarx
34 {
35 
38  {
39  }
40 
42  {
44 
45  defs->topic(graphTopic, "SemanticGraphTopic");
46 
47  return defs;
48  }
49 
51  {
52  return "SemanticGraphExample";
53  }
54 
55 
57  {
58  }
59 
60 
61 
63  {
64  mygraph::MyGraph graph;
65 
66  // Add vertices and set attributes.
67 
68  // Option 1: Prepare vertex attributes beforehand.
69  mygraph::MyVertex vattribs;
70  vattribs.name = "A";
71  vattribs.value = 0.0;
72  auto a = graph.addVertex(semrel::ShapeID{0}, vattribs);
73 
74  vattribs.name = "B";
75  vattribs.value = 0.5;
76  auto b = graph.addVertex(semrel::ShapeID{1}, vattribs);
77 
78  // Option 1: Set attributes after adding.
79  auto c = graph.addVertex(semrel::ShapeID{5});
80  c.attrib().name = "C";
81  c.attrib().value = 1.0;
82 
83  // Add edges and set attributes.
84  auto ab = graph.addEdge(a, b);
85  ab.attrib().value = 0;
86  auto ac = graph.addEdge(a, c);
87  ac.attrib().value = 1;
88  auto bc = graph.addEdge(b, c);
89  bc.attrib().value = 2;
90 
91  // Set graph attributes
92  graph.attrib().position = {1, 2, 3};
93 
94  graphTopic->reportGraph("MyGraph", armarx::semantic::toIce(graph));
95  }
96 
97 
99  {
100  }
101 
102 
104  {
105  }
106 
107 }
mygraph::MyVertex::name
std::string name
Definition: MyGraph.h:10
SemanticGraphExample.h
mygraph::MyVertex
Definition: MyGraph.h:8
semrel::RelationGraph
Definition: forward_declarations.h:28
armarx::SemanticGraphExample::onConnectComponent
void onConnectComponent() override
Definition: SemanticGraphExample.cpp:62
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::semantic::toIce
data::Graph toIce(const semrel::AttributedGraph &input)
Definition: graph.cpp:15
armarx::SemanticGraphExamplePropertyDefinitions
Property definitions of SemanticGraphExample.
Definition: SemanticGraphExample.h:37
mygraph::MyVertex::value
float value
Definition: MyGraph.h:11
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:41
armarx::SemanticGraphExample::onDisconnectComponent
void onDisconnectComponent() override
Definition: SemanticGraphExample.cpp:98
armarx::SemanticGraphExample::onInitComponent
void onInitComponent() override
Definition: SemanticGraphExample.cpp:56
armarx::SemanticGraphExample::onExitComponent
void onExitComponent() override
Definition: SemanticGraphExample.cpp:103
armarx::SemanticGraphExamplePropertyDefinitions::SemanticGraphExamplePropertyDefinitions
SemanticGraphExamplePropertyDefinitions(std::string prefix)
Definition: SemanticGraphExample.cpp:36
armarx::SemanticGraphExample::getDefaultName
std::string getDefaultName() const override
Definition: SemanticGraphExample.cpp:50
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
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:28