ArVizStorage.h
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 RobotAPI::ArmarXObjects::ArViz
17  * @author Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <atomic>
26 #include <condition_variable>
27 #include <filesystem>
28 #include <mutex>
29 
33 
34 #include <RobotAPI/interface/ArViz.h>
35 
36 namespace armarx
37 {
38 
39  /**
40  * @defgroup Component-ArVizStorage ArVizStorage
41  * @ingroup RobotAPI-Components
42  *
43  * The ArViz storage stores visualization elements published by ArViz
44  * clients and provides them for visualizing components such as the
45  * ArViz gui plugin.
46  *
47  * In addition, the ArViz storage can be used to record and replay
48  * visualization episodes.
49  *
50  *
51  * @class ArVizStorage
52  * @ingroup Component-ArVizStorage
53  *
54  * @brief Stores visualization elements drawn by ArViz clients.
55  *
56  */
57  class ArVizStorage :
58  virtual public armarx::Component,
59  virtual public armarx::viz::StorageAndTopicInterface
60  {
61  public:
62  /// armarx::ManagedIceObject::getDefaultName()
63  std::string getDefaultName() const override;
64 
65 
66  /// PropertyUser::createPropertyDefinitions()
68 
69  /// armarx::ManagedIceObject::onInitComponent()
70  void onInitComponent() override;
71 
72  /// armarx::ManagedIceObject::onConnectComponent()
73  void onConnectComponent() override;
74 
75  /// armarx::ManagedIceObject::onDisconnectComponent()
76  void onDisconnectComponent() override;
77 
78  /// armarx::ManagedIceObject::onExitComponent()
79  void onExitComponent() override;
80 
81 
82  // Topic interface
83  void updateLayers(viz::data::LayerUpdateSeq const& updates, const Ice::Current&) override;
84 
85  // StorageInterface interface
86  viz::data::CommitResult commitAndReceiveInteractions(viz::data::CommitInput const& input,
87  const Ice::Current&) override;
88 
89  viz::data::LayerUpdates pullUpdatesSince(Ice::Long revision, const Ice::Current&) override;
90  viz::data::LayerUpdates
92  viz::data::InteractionFeedbackSeq const& interactions,
93  const Ice::Current&) override;
94  std::string startRecording(std::string const& prefix, const Ice::Current&) override;
95  void stopRecording(const Ice::Current&) override;
96  viz::data::RecordingsInfo getAllRecordings(const Ice::Current&) override;
97  viz::data::RecordingBatch
98  getRecordingBatch(const std::string&, Ice::Long, const Ice::Current&) override;
99 
100  private:
101  void record();
102 
103  void recordBatch(viz::data::RecordingBatch& batch);
104 
105  private:
106  struct Properties
107  {
108  std::string topicName = "ArVizTopic";
109  int maxHistorySize = 1000;
110  std::filesystem::path historyPath = "RobotAPI/ArVizStorage";
111 
112  float componentWarnFrequency = 30;
113 
114  } properties_;
115 
116  std::mutex historyMutex;
117 
118  std::vector<viz::data::TimestampedLayerUpdate> currentState;
119  std::vector<viz::data::TimestampedLayerUpdate> history;
120  long revision = 0;
121  bool firstBatch = false;
122 
123  // We store all interactions in here
124  // But we curate them, so that only the last interaction with an element is reported
125  // in case the component never retrieves the interactions
126  std::vector<viz::data::InteractionFeedback> interactionBuffer;
127 
128  std::mutex recordingMutex;
129  std::filesystem::path recordingPath;
130  std::vector<viz::data::TimestampedLayerUpdate> recordingInitialState;
131  std::vector<viz::data::RecordingBatch> recordingBuffer;
132  viz::data::Recording recordingMetaData;
133  std::condition_variable recordingCondition;
135 
136 
137  std::map<std::string, std::vector<armarx::DateTime>> updateHistoryForComponents;
138  };
139 } // namespace armarx
armarx::ArVizStorage::pullUpdatesSinceAndSendInteractions
viz::data::LayerUpdates pullUpdatesSinceAndSendInteractions(Ice::Long revision, viz::data::InteractionFeedbackSeq const &interactions, const Ice::Current &) override
Definition: ArVizStorage.cpp:348
armarx::ArVizStorage::stopRecording
void stopRecording(const Ice::Current &) override
Definition: ArVizStorage.cpp:653
armarx::ArVizStorage::onExitComponent
void onExitComponent() override
armarx::ManagedIceObject::onExitComponent()
Definition: ArVizStorage.cpp:135
DateTime.h
armarx::ArVizStorage::updateLayers
void updateLayers(viz::data::LayerUpdateSeq const &updates, const Ice::Current &) override
Definition: ArVizStorage.cpp:140
armarx::ArVizStorage::getAllRecordings
viz::data::RecordingsInfo getAllRecordings(const Ice::Current &) override
Definition: ArVizStorage.cpp:676
RunningTask.h
armarx::ArVizStorage::startRecording
std::string startRecording(std::string const &prefix, const Ice::Current &) override
Definition: ArVizStorage.cpp:602
armarx::ArVizStorage::onConnectComponent
void onConnectComponent() override
armarx::ManagedIceObject::onConnectComponent()
Definition: ArVizStorage.cpp:113
armarx::ArVizStorage::getDefaultName
std::string getDefaultName() const override
armarx::ManagedIceObject::getDefaultName()
Definition: ArVizStorage.cpp:64
armarx::ArVizStorage
Stores visualization elements drawn by ArViz clients.
Definition: ArVizStorage.h:57
armarx::ArVizStorage::onDisconnectComponent
void onDisconnectComponent() override
armarx::ManagedIceObject::onDisconnectComponent()
Definition: ArVizStorage.cpp:125
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::ArVizStorage::commitAndReceiveInteractions
viz::data::CommitResult commitAndReceiveInteractions(viz::data::CommitInput const &input, const Ice::Current &) override
Definition: ArVizStorage.cpp:233
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::ArVizStorage::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
PropertyUser::createPropertyDefinitions()
Definition: ArVizStorage.cpp:70
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ArVizStorage::onInitComponent
void onInitComponent() override
armarx::ManagedIceObject::onInitComponent()
Definition: ArVizStorage.cpp:95
armarx::ArVizStorage::getRecordingBatch
viz::data::RecordingBatch getRecordingBatch(const std::string &, Ice::Long, const Ice::Current &) override
Definition: ArVizStorage.cpp:705
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ArVizStorage::pullUpdatesSince
viz::data::LayerUpdates pullUpdatesSince(Ice::Long revision, const Ice::Current &) override
Definition: ArVizStorage.cpp:323