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
36namespace 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 */
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
91 pullUpdatesSinceAndSendInteractions(Ice::Long revision,
92 viz::data::InteractionFeedbackSeq const& interactions,
93 const Ice::Current&) override;
94
95 std::string startRecording(std::string const& prefix, const Ice::Current&) override;
96 std::string startRecordingToDirectory(std::string const& recordingPath, const Ice::Current&) override;
97
98 void stopRecording(const Ice::Current&) override;
99 viz::data::RecordingsInfo getAllRecordings(const Ice::Current&) override;
100 viz::data::RecordingBatch
101 getRecordingBatch(const std::string&, Ice::Long, const Ice::Current&) override;
102
103 private:
104 void record();
105
106 void recordBatch(viz::data::RecordingBatch& batch);
107
108 private:
109 struct Properties
110 {
111 std::string topicName = "ArVizTopic";
112 int maxHistorySize = 1000;
113 std::filesystem::path historyPath = "RobotAPI/ArVizStorage";
114
115 float componentWarnFrequency = 30;
116
117 } properties_;
118
119 std::mutex historyMutex;
120
121 std::vector<viz::data::TimestampedLayerUpdate> currentState;
122 std::vector<viz::data::TimestampedLayerUpdate> history;
123 long revision = 0;
124 bool firstBatch = false;
125
126 // We store all interactions in here
127 // But we curate them, so that only the last interaction with an element is reported
128 // in case the component never retrieves the interactions
129 std::vector<viz::data::InteractionFeedback> interactionBuffer;
130
131 std::mutex recordingMutex;
132 std::filesystem::path recordingPath;
133 std::vector<viz::data::TimestampedLayerUpdate> recordingInitialState;
134 std::vector<viz::data::RecordingBatch> recordingBuffer;
135 viz::data::Recording recordingMetaData;
136 std::condition_variable recordingCondition;
138
139
140 std::map<std::string, std::vector<armarx::DateTime>> updateHistoryForComponents;
141 };
142} // namespace armarx
Stores visualization elements drawn by ArViz clients.
viz::data::CommitResult commitAndReceiveInteractions(viz::data::CommitInput const &input, const Ice::Current &) override
void onInitComponent() override
armarx::ManagedIceObject::onInitComponent()
std::string startRecording(std::string const &prefix, const Ice::Current &) override
void updateLayers(viz::data::LayerUpdateSeq const &updates, const Ice::Current &) override
void onDisconnectComponent() override
armarx::ManagedIceObject::onDisconnectComponent()
viz::data::LayerUpdates pullUpdatesSinceAndSendInteractions(Ice::Long revision, viz::data::InteractionFeedbackSeq const &interactions, const Ice::Current &) override
viz::data::LayerUpdates pullUpdatesSince(Ice::Long revision, const Ice::Current &) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
PropertyUser::createPropertyDefinitions()
std::string startRecordingToDirectory(std::string const &recordingPath, const Ice::Current &) override
viz::data::RecordingsInfo getAllRecordings(const Ice::Current &) override
void onConnectComponent() override
armarx::ManagedIceObject::onConnectComponent()
viz::data::RecordingBatch getRecordingBatch(const std::string &, Ice::Long, const Ice::Current &) override
void stopRecording(const Ice::Current &) override
void onExitComponent() override
armarx::ManagedIceObject::onExitComponent()
std::string getDefaultName() const override
armarx::ManagedIceObject::getDefaultName()
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.