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 
33 
36 
37 
39 {
40 
41  const std::string MemoryGrapher::defaultName = "MemoryGrapher";
42 
43 
45  MemoryGrapher::createPropertyDefinitions()
46  {
49 
50  // Publish to a topic (passing the TopicListenerPrx).
51  def->topic(graphTopic, "MemoryGraphTopic");
52 
53  // Subscribe to a topic (passing the topic name).
54  // def->topic<PlatformUnitListener>("MyTopic");
55 
56  // Use (and depend on) another component (passing the ComponentInterfacePrx).
57  // def->component(myComponentProxy)
58 
59 
60  // Add a required property. (The component won't start without a value being set.)
61  // def->required(properties.boxLayerName, "p.box.LayerName", "Name of the box layer in ArViz.");
62 
63  // Add an optionalproperty.
64 
65  return def;
66  }
67 
68 
69  void
70  MemoryGrapher::onInitComponent()
71  {
72  // Topics and properties defined above are automagically registered.
73 
74  // Keep debug observer data until calling `sendDebugObserverBatch()`.
75  // (Requies the armarx::DebugObserverComponentPluginUser.)
76  // setDebugObserverBatchModeEnabled(true);
77  }
78 
79 
80  void
81  MemoryGrapher::onConnectComponent()
82  {
83  // Do things after connecting to topics and components.
84 
85  /* (Requies the armarx::DebugObserverComponentPluginUser.)
86  // Use the debug observer to log data over time.
87  // The data can be viewed in the ObserverView and the LivePlotter.
88  // (Before starting any threads, we don't need to lock mutexes.)
89  {
90  setDebugObserverDatafield("numBoxes", properties.numBoxes);
91  setDebugObserverDatafield("boxLayerName", properties.boxLayerName);
92  sendDebugObserverBatch();
93  }
94  */
95 
96  /* (Requires the armarx::ArVizComponentPluginUser.)
97  // Draw boxes in ArViz.
98  // (Before starting any threads, we don't need to lock mutexes.)
99  drawBoxes(properties, arviz);
100  */
101 
102  // Setup the remote GUI.
103  {
106  }
107  }
108 
109  void
110  MemoryGrapher::run(const std::string& memoryID)
111  {
114  armarx::armem::id_graph::MemoryGraph graph = resolver.resolveToGraph(converted);
115 
116  graphTopic->reportGraph("MemoryGraph", armarx::semantic::toIce(graph));
117  finished.store(true, std::memory_order_release);
118  }
119 
120 
121  void
122  MemoryGrapher::onDisconnectComponent()
123  {
124  if (worker.joinable())
125  {
126  worker.join();
127  }
128  }
129 
130 
131  void
132  MemoryGrapher::onExitComponent()
133  {
134  if (worker.joinable())
135  {
136  worker.join();
137  }
138  }
139 
140 
141  std::string
142  MemoryGrapher::getDefaultName() const
143  {
144  return MemoryGrapher::defaultName;
145  }
146 
147 
148  void
149  MemoryGrapher::createRemoteGuiTab()
150  {
151  using namespace armarx::RemoteGui::Client;
152 
153  // Setup the widgets.
154 
155  tab.memoryID.setValue("");
156  tab.memoryID.setName("Memory ID");
157 
158  tab.createGraph.setLabel("Create Graph");
159 
160  // Setup the layout.
161 
162  HBoxLayout root = {tab.memoryID, tab.createGraph};
163  RemoteGui_createTab(getName(), root, &tab);
164  }
165 
166 
167  void
169  {
170  if (tab.createGraph.wasClicked())
171  {
172  std::string memoryID = tab.memoryID.getValue();
173 
174  if (worker.joinable())
175  {
176  if (finished.load(std::memory_order_acquire))
177  {
178  worker.join();
179  }
180  else
181  {
182  return;
183  }
184  }
185  finished.store(false, std::memory_order_release);
186  worker = std::thread([this, memoryID]() { this->run(memoryID); });
187  }
188  }
189 
190 
191  /* (Requires the armarx::ArVizComponentPluginUser.)
192  void
193  MemoryGrapher::drawBoxes(const Component::Properties& p, viz::Client& arviz)
194  {
195  // Draw something in ArViz (requires the armarx::ArVizComponentPluginUser.
196  // See the ArVizExample in RobotAPI for more examples.
197 
198  viz::Layer layer = arviz.layer(p.boxLayerName);
199  for (int i = 0; i < p.numBoxes; ++i)
200  {
201  layer.add(viz::Box("box_" + std::to_string(i))
202  .position(Eigen::Vector3f(i * 100, 0, 0))
203  .size(20).color(simox::Color::blue()));
204  }
205  arviz.commit(layer);
206  }
207  */
208 
209 
210 } // namespace VisionX::components::MemoryGrapher
armarx::armem::client::plugins::PluginUser::memoryNameSystem
MemoryNameSystem & memoryNameSystem()
Definition: PluginUser.cpp:22
MemoryIDResolver.h
semrel::RelationGraph
Definition: forward_declarations.h:28
armarx::semantic::toIce
data::Graph toIce(const semrel::AttributedGraph &input)
Definition: graph.cpp:15
armarx::armem::id_graph::MemoryIDResolver
Definition: MemoryIDResolver.h:38
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
json_conversions.h
MemoryGrapher.h
armarx::armem::MemoryID::fromString
static MemoryID fromString(const std::string &string)
Alias for constructor from string.
Definition: MemoryID.cpp:183
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_startRunningTask
void RemoteGui_startRunningTask()
Definition: LightweightRemoteGuiComponentPlugin.cpp:110
armarx::RemoteGui::Client::HBoxLayout
Definition: Widgets.h:160
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
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_createTab
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
Definition: LightweightRemoteGuiComponentPlugin.cpp:95
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::index::memoryID
const MemoryID memoryID
Definition: memory_ids.cpp:29
armarx::visionx::components::MemoryGrapher
Definition: MemoryGrapher.cpp:38
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
ice_serialization.h
armarx::visionx::components::MemoryGrapher::MemoryGrapher::RemoteGui_update
void RemoteGui_update() override
After calling RemoteGui_startRunningTask, this function is called periodically in a separate thread.
Definition: MemoryGrapher.cpp:168
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
armarx::visionx::components::MemoryGrapher::MemoryGrapher::createRemoteGuiTab
void createRemoteGuiTab()
This function should be called once in onConnect() or when you need to re-create the Remote GUI tab.
Definition: MemoryGrapher.cpp:149