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 <RobotAPI/interface/ArViz.h>
28 
29 #include <mutex>
30 #include <atomic>
31 #include <condition_variable>
32 #include <filesystem>
33 
34 
35 namespace armarx
36 {
37 
38  /**
39  * @defgroup Component-ArVizStorage ArVizStorage
40  * @ingroup RobotAPI-Components
41  *
42  * The ArViz storage stores visualization elements published by ArViz
43  * clients and provides them for visualizing components such as the
44  * ArViz gui plugin.
45  *
46  * In addition, the ArViz storage can be used to record and replay
47  * visualization episodes.
48  *
49  *
50  * @class ArVizStorage
51  * @ingroup Component-ArVizStorage
52  *
53  * @brief Stores visualization elements drawn by ArViz clients.
54  *
55  */
57  : virtual public armarx::Component
58  , virtual public armarx::viz::StorageAndTopicInterface
59  {
60  public:
61 
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, const Ice::Current&) override;
87 
88  viz::data::LayerUpdates pullUpdatesSince(Ice::Long revision, const Ice::Current&) override;
89  viz::data::LayerUpdates pullUpdatesSinceAndSendInteractions(
90  Ice::Long revision,
91  viz::data::InteractionFeedbackSeq const& interactions,
92  const Ice::Current&) override;
93  std::string startRecording(std::string const& prefix, const Ice::Current&) override;
94  void stopRecording(const Ice::Current&) override;
95  viz::data::RecordingsInfo getAllRecordings(const Ice::Current&) override;
96  viz::data::RecordingBatch getRecordingBatch(const std::string&, Ice::Long, const Ice::Current&) override;
97 
98  private:
99  void record();
100 
101  void recordBatch(viz::data::RecordingBatch& batch);
102 
103  private:
104  std::string topicName = "ArVizTopic";
105  int maxHistorySize = 1000;
106  std::filesystem::path historyPath;
107 
108  std::mutex historyMutex;
109 
110  std::vector<viz::data::TimestampedLayerUpdate> currentState;
111  std::vector<viz::data::TimestampedLayerUpdate> history;
112  long revision = 0;
113  bool firstBatch = false;
114 
115  // We store all interactions in here
116  // But we curate them, so that only the last interaction with an element is reported
117  // in case the component never retrieves the interactions
118  std::vector<viz::data::InteractionFeedback> interactionBuffer;
119 
120  std::mutex recordingMutex;
121  std::filesystem::path recordingPath;
122  std::vector<viz::data::TimestampedLayerUpdate> recordingInitialState;
123  std::vector<viz::data::RecordingBatch> recordingBuffer;
124  viz::data::Recording recordingMetaData;
125  std::condition_variable recordingCondition;
127  };
128 }
armarx::ArVizStorage::pullUpdatesSinceAndSendInteractions
viz::data::LayerUpdates pullUpdatesSinceAndSendInteractions(Ice::Long revision, viz::data::InteractionFeedbackSeq const &interactions, const Ice::Current &) override
Definition: ArVizStorage.cpp:304
armarx::ArVizStorage::stopRecording
void stopRecording(const Ice::Current &) override
Definition: ArVizStorage.cpp:597
armarx::ArVizStorage::onExitComponent
void onExitComponent() override
armarx::ManagedIceObject::onExitComponent()
Definition: ArVizStorage.cpp:127
armarx::ArVizStorage::updateLayers
void updateLayers(viz::data::LayerUpdateSeq const &updates, const Ice::Current &) override
Definition: ArVizStorage.cpp:132
armarx::ArVizStorage::getAllRecordings
viz::data::RecordingsInfo getAllRecordings(const Ice::Current &) override
Definition: ArVizStorage.cpp:619
RunningTask.h
armarx::ArVizStorage::startRecording
std::string startRecording(std::string const &prefix, const Ice::Current &) override
Definition: ArVizStorage.cpp:546
armarx::ArVizStorage::onConnectComponent
void onConnectComponent() override
armarx::ManagedIceObject::onConnectComponent()
Definition: ArVizStorage.cpp:105
armarx::ArVizStorage::getDefaultName
std::string getDefaultName() const override
armarx::ManagedIceObject::getDefaultName()
Definition: ArVizStorage.cpp:60
armarx::ArVizStorage
Stores visualization elements drawn by ArViz clients.
Definition: ArVizStorage.h:56
armarx::ArVizStorage::onDisconnectComponent
void onDisconnectComponent() override
armarx::ManagedIceObject::onDisconnectComponent()
Definition: ArVizStorage.cpp:117
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:193
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::ArVizStorage::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
PropertyUser::createPropertyDefinitions()
Definition: ArVizStorage.cpp:66
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:85
armarx::ArVizStorage::getRecordingBatch
viz::data::RecordingBatch getRecordingBatch(const std::string &, Ice::Long, const Ice::Current &) override
Definition: ArVizStorage.cpp:646
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:281