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
27
28// Include headers you only need in function definitions in the .cpp.
29
30// #include <Eigen/Core>
31
32// #include <SimoxUtility/color/Color.h>
33
37
39{
40
41 const std::string MemoryGrapher::defaultName = "MemoryGrapher";
42
45 {
48
49 // Publish to a topic (passing the TopicListenerPrx).
50 def->topic(graphTopic, "MemoryGraphTopic");
51
52 // Subscribe to a topic (passing the topic name).
53 // def->topic<PlatformUnitListener>("MyTopic");
54
55 // Use (and depend on) another component (passing the ComponentInterfacePrx).
56 // def->component(myComponentProxy)
57
58
59 // Add a required property. (The component won't start without a value being set.)
60 // def->required(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz.");
61
62 // Add an optionalproperty.
63
64 return def;
65 }
66
67 void
69 {
70 // Topics and properties defined above are automagically registered.
71
72 // Keep debug observer data until calling `sendDebugObserverBatch()`.
73 // (Requies the armarx::DebugObserverComponentPluginUser.)
74 // setDebugObserverBatchModeEnabled(true);
75 }
76
77 void
79 {
80 // Do things after connecting to topics and components.
81
82 /* (Requies the armarx::DebugObserverComponentPluginUser.)
83 // Use the debug observer to log data over time.
84 // The data can be viewed in the ObserverView and the LivePlotter.
85 // (Before starting any threads, we don't need to lock mutexes.)
86 {
87 setDebugObserverDatafield("numBoxes", properties.numBoxes);
88 setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
89 sendDebugObserverBatch();
90 }
91 */
92
93 /* (Requires the armarx::ArVizComponentPluginUser.)
94 // Draw boxes in ArViz.
95 // (Before starting any threads, we don't need to lock mutexes.)
96 drawBoxes(properties, arviz);
97 */
98
99 // Setup the remote GUI.
100 {
103 }
104 }
105
106 void
107 MemoryGrapher::run(const std::string& memoryID)
108 {
111 armarx::armem::id_graph::MemoryGraph graph = resolver.resolveToGraph(converted);
112
113 graphTopic->reportGraph("MemoryGraph", armarx::semantic::toIce(graph));
114 finished.store(true, std::memory_order_release);
115 }
116
117 void
119 {
120 if (worker.joinable())
121 {
122 worker.join();
123 }
124 }
125
126 void
128 {
129 if (worker.joinable())
130 {
131 worker.join();
132 }
133 }
134
135 std::string
137 {
138 return defaultName;
139 }
140
141 std::string
143 {
144 return GetDefaultName();
145 }
146
147 void
149 {
150 using namespace armarx::RemoteGui::Client;
151
152 // Setup the widgets.
153
154 tab.memoryID.setValue("");
155 tab.memoryID.setName("Memory ID");
156
157 tab.createGraph.setLabel("Create Graph");
158
159 // Setup the layout.
160
161 HBoxLayout root = {tab.memoryID, tab.createGraph};
162 RemoteGui_createTab(getName(), root, &tab);
163 }
164
165 void
167 {
168 if (tab.createGraph.wasClicked())
169 {
170 std::string memoryID = tab.memoryID.getValue();
171
172 if (worker.joinable())
173 {
174 if (finished.load(std::memory_order_acquire))
175 {
176 worker.join();
177 }
178 else
179 {
180 return;
181 }
182 }
183 finished.store(false, std::memory_order_release);
184 worker = std::thread([this, memoryID]() { this->run(memoryID); });
185 }
186 }
187
188 /* (Requires the armarx::ArVizComponentPluginUser.)
189 void
190 MemoryGrapher::drawBoxes(const Component::Properties& p, viz::Client& arviz)
191 {
192 // Draw something in ArViz (requires the armarx::ArVizComponentPluginUser.
193 // See the ArVizExample in RobotAPI for more examples.
194
195 viz::Layer layer = arviz.layer(p.boxLayerName);
196 for (int i = 0; i < p.numBoxes; ++i)
197 {
198 layer.add(viz::Box("box_" + std::to_string(i))
199 .position(Eigen::Vector3f(i * 100, 0, 0))
200 .size(20).color(simox::Color::blue()));
201 }
202 arviz.commit(layer);
203 }
204 */
205
206
207
209} // namespace armarx::visionx::components::MemoryGrapher
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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.
std::string getDefaultName() const override
Retrieve default name of component.
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)