MemoryGrapher.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::MemoryGrapher
17 * @author [Author Name] ( [Author Email] )
18 * @date 2021
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
24#include "MemoryGrapher.h"
25
26// Include headers you only need in function definitions in the .cpp.
27
28// #include <Eigen/Core>
29
30// #include <SimoxUtility/color/Color.h>
31
35
37{
38
39 const std::string MemoryGrapher::defaultName = "MemoryGrapher";
40
43 {
46
47 // Publish to a topic (passing the TopicListenerPrx).
48 def->topic(graphTopic, "MemoryGraphTopic");
49
50 // Subscribe to a topic (passing the topic name).
51 // def->topic<PlatformUnitListener>("MyTopic");
52
53 // Use (and depend on) another component (passing the ComponentInterfacePrx).
54 // def->component(myComponentProxy)
55
56
57 // Add a required property. (The component won't start without a value being set.)
58 // def->required(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz.");
59
60 // Add an optionalproperty.
61
62 return def;
63 }
64
65 void
67 {
68 // Topics and properties defined above are automagically registered.
69
70 // Keep debug observer data until calling `sendDebugObserverBatch()`.
71 // (Requies the armarx::DebugObserverComponentPluginUser.)
72 // setDebugObserverBatchModeEnabled(true);
73 }
74
75 void
77 {
78 // Do things after connecting to topics and components.
79
80 /* (Requies the armarx::DebugObserverComponentPluginUser.)
81 // Use the debug observer to log data over time.
82 // The data can be viewed in the ObserverView and the LivePlotter.
83 // (Before starting any threads, we don't need to lock mutexes.)
84 {
85 setDebugObserverDatafield("numBoxes", properties.numBoxes);
86 setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
87 sendDebugObserverBatch();
88 }
89 */
90
91 /* (Requires the armarx::ArVizComponentPluginUser.)
92 // Draw boxes in ArViz.
93 // (Before starting any threads, we don't need to lock mutexes.)
94 drawBoxes(properties, arviz);
95 */
96
97 // Setup the remote GUI.
98 {
101 }
102 }
103
104 void
105 MemoryGrapher::run(const std::string& memoryID)
106 {
109 armarx::armem::id_graph::MemoryGraph graph = resolver.resolveToGraph(converted);
110
111 graphTopic->reportGraph("MemoryGraph", armarx::semantic::toIce(graph));
112 finished.store(true, std::memory_order_release);
113 }
114
115 void
117 {
118 if (worker.joinable())
119 {
120 worker.join();
121 }
122 }
123
124 void
126 {
127 if (worker.joinable())
128 {
129 worker.join();
130 }
131 }
132
133 std::string
135 {
136 return MemoryGrapher::defaultName;
137 }
138
139 void
141 {
142 using namespace armarx::RemoteGui::Client;
143
144 // Setup the widgets.
145
146 tab.memoryID.setValue("");
147 tab.memoryID.setName("Memory ID");
148
149 tab.createGraph.setLabel("Create Graph");
150
151 // Setup the layout.
152
153 HBoxLayout root = {tab.memoryID, tab.createGraph};
154 RemoteGui_createTab(getName(), root, &tab);
155 }
156
157 void
159 {
160 if (tab.createGraph.wasClicked())
161 {
162 std::string memoryID = tab.memoryID.getValue();
163
164 if (worker.joinable())
165 {
166 if (finished.load(std::memory_order_acquire))
167 {
168 worker.join();
169 }
170 else
171 {
172 return;
173 }
174 }
175 finished.store(false, std::memory_order_release);
176 worker = std::thread([this, memoryID]() { this->run(memoryID); });
177 }
178 }
179
180 /* (Requires the armarx::ArVizComponentPluginUser.)
181 void
182 MemoryGrapher::drawBoxes(const Component::Properties& p, viz::Client& arviz)
183 {
184 // Draw something in ArViz (requires the armarx::ArVizComponentPluginUser.
185 // See the ArVizExample in RobotAPI for more examples.
186
187 viz::Layer layer = arviz.layer(p.boxLayerName);
188 for (int i = 0; i < p.numBoxes; ++i)
189 {
190 layer.add(viz::Box("box_" + std::to_string(i))
191 .position(Eigen::Vector3f(i * 100, 0, 0))
192 .size(20).color(simox::Color::blue()));
193 }
194 arviz.commit(layer);
195 }
196 */
197
198
199} // namespace armarx::visionx::components::MemoryGrapher
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
std::string getName() const
Retrieve name of object.
static MemoryID fromString(const std::string &string)
Alias for constructor from string.
Definition MemoryID.cpp:188
void RemoteGui_update() override
After calling RemoteGui_startRunningTask, this function is called periodically in a separate thread.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void createRemoteGuiTab()
This function should be called once in onConnect() or when you need to re-create the Remote GUI tab.
semrel::RelationGraph< MemoryVertex, MemoryEdge, MemoryGraphAttributes > MemoryGraph
Definition MemoryGraph.h:51
data::Graph toIce(const semrel::AttributedGraph &input)
Definition graph.cpp:15
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)