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
24
25#include <VirtualRobot/VirtualRobot.h>
26
28
29#include "MyGraph.h"
30#include "json.h"
31
32namespace armarx
33{
34
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
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
103
104 void
108
109} // namespace armarx
constexpr T c
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Property definitions of SemanticGraphExample.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
std::string getDefaultName() const override
data::Graph toIce(const semrel::AttributedGraph &input)
Definition graph.cpp:15
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
semrel::RelationGraph< MyVertex, MyEdge, MyGraphAttributes > MyGraph
Definition MyGraph.h:24
std::string name
Definition MyGraph.h:9