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
26
27#include <VirtualRobot/VirtualRobot.h>
28
30
31#include "MyGraph.h"
32#include "json.h"
33
34namespace armarx
35{
36
42
45 {
48
49 defs->topic(graphTopic, "SemanticGraphTopic");
50
51 return defs;
52 }
53
54 std::string
56 {
57 return "SemanticGraphExample";
58 }
59
60 std::string
65
66 void
70
71 void
73 {
74 mygraph::MyGraph graph;
75
76 // Add vertices and set attributes.
77
78 // Option 1: Prepare vertex attributes beforehand.
79 mygraph::MyVertex vattribs;
80 vattribs.name = "A";
81 vattribs.value = 0.0;
82 auto a = graph.addVertex(semrel::ShapeID{0}, vattribs);
83
84 vattribs.name = "B";
85 vattribs.value = 0.5;
86 auto b = graph.addVertex(semrel::ShapeID{1}, vattribs);
87
88 // Option 1: Set attributes after adding.
89 auto c = graph.addVertex(semrel::ShapeID{5});
90 c.attrib().name = "C";
91 c.attrib().value = 1.0;
92
93 // Add edges and set attributes.
94 auto ab = graph.addEdge(a, b);
95 ab.attrib().value = 0;
96 auto ac = graph.addEdge(a, c);
97 ac.attrib().value = 1;
98 auto bc = graph.addEdge(b, c);
99 bc.attrib().value = 2;
100
101 // Set graph attributes
102 graph.attrib().position = {1, 2, 3};
103
104 graphTopic->reportGraph("MyGraph", armarx::semantic::toIce(graph));
105 }
106
107 void
111
112 void
116
117
119} // namespace armarx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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.
Brief description of class SemanticGraphExample.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
std::string getDefaultName() const override
Retrieve default name of component.
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