Editor.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <list>
4 
10 
11 namespace armarx
12 {
13 
14  class Editor;
15 
16 
18  {
20  bool allowTransforming = true;
21 
22  std::vector<std::string> options {};
23  std::optional<float> alpha {};
24  std::optional<simox::Color> color {};
25 
26  // Context menu indices.
34  };
35 
36 
37 
39  {
40  public:
41  explicit ChangeState(Editor* editor) : editor(editor) {} ;
42 
43  void clear();
45  bool applyTo(objpose::ObjectPose& pose);
46  void visualizeNewObjects();
49 
50  void cloneObject(objpose::ObjectPose const& object);
51  void createObject(std::string const& objectID, Eigen::Matrix4f const& pose);
52  void deleteObject(objpose::ObjectPose const& object);
53  void resetObject(objpose::ObjectPose const& object);
54  void moveObject(objpose::ObjectPose const& object, Eigen::Matrix4f const& transform);
55 
56  private:
57  enum ChangeKind
58  {
59  MOVE,
60  CREATE,
61  DELETE
62  };
63 
64  using ObjectPoseList = std::list<objpose::ObjectPose>;
65 
66  struct Change
67  {
68  ChangeKind kind = MOVE;
70  ObjectPoseList::iterator iterator {};
71  };
72 
73  Editor* editor;
74 
75  ObjectPoseList newPoses;
76  std::map<std::string, Change> changed;
77  };
78 
79 
80 
82  {
83  public:
84  explicit PlaceholderState(Editor* editor) : editor(editor) {} ;
85 
86  struct Placeholder
87  {
88  simox::OrientedBoxf box;
90  };
91 
92  void addPlaceholder(simox::OrientedBoxf box);
93  void visualizePlaceholders();
94  void movePlaceholder(size_t id, Eigen::Matrix4f const& transform);
95  void removePlaceholder(size_t id);
96  void specifyObject(size_t id, std::string const& objectID, ChangeState& changeState);
97 
98  private:
99  size_t getID();
100 
101  Editor* editor;
102 
103  std::priority_queue<size_t, std::vector<size_t>, std::greater<>> unusedIDs;
104  struct PlaceholderEntry
105  {
106  Placeholder placeholder;
107  bool isActive;
108  };
109  std::vector<PlaceholderEntry> placeholders;
110  };
111 
112 
113 
114  class Editor
115  {
116  public:
117  struct Properties
118  {
119  std::string providerName;
120 
121  float const& objectScaling;
122  float const& confidenceThreshold;
123 
124  std::vector<data::ObjectID> const& availableObjects;
125  };
126 
127 
128  public:
129 
130  explicit Editor(viz::Client& client,
131  Properties properties,
132  std::function<void(objpose::ProvidedObjectPoseSeq&)> pushToMemory,
133  std::function<objpose::ObjectPoseSeq(void)> pullFromMemory);
134  void step();
135 
136  private:
137 
138  void visualizeMemory();
139  void visualizeMeta();
140 
141  void commit();
142  objpose::ObjectPoseSeq update();
143  void reset();
144 
145  void visualizeObject(objpose::ObjectPose &objectPose);
146  void visualizePlaceholder(PlaceholderState::Placeholder const& placeholder, size_t id);
147 
148  private:
149  static constexpr const char* memoryLayerName = "Memory";
150  static constexpr const char* metaLayerName = "Meta";
151  static constexpr const char* lineString = "---------------------------";
152 
153  std::vector<std::string> placeholderOptions;
154 
155  Properties properties;
156  ObjectFinder objectFinder;
157 
158  viz::Client& client;
159  const std::function<void(objpose::ProvidedObjectPoseSeq&)> pushToMemory;
160  const std::function<objpose::ObjectPoseSeq(void)> pullFromMemory;
161 
162  viz::Layer memoryLayer {client.layer(memoryLayerName)};
163  viz::Layer metaLayer {client.layer(metaLayerName)};
164 
165  InteractionObserver observer;
166 
167  objpose::ObjectPoseSeq storedPoses;
168 
169  ChangeState changes{this};
170  PlaceholderState placeholders{this};
171 
172  bool isCommitRequired;
173  bool isUpdateRequired;
174  bool isResetRequired;
175  bool isMemoryVizRequired;
176  bool isMetaVizRequired;
177 
178  friend ChangeState;
179  friend PlaceholderState;
180  };
181 } // namespace armarx
ArVizComponentPlugin.h
armarx::PlaceholderState::Placeholder
Definition: Editor.h:86
armarx::ChangeState::ChangeState
ChangeState(Editor *editor)
Definition: Editor.h:41
ObjectPoseProviderPlugin.h
armarx::Editor::Editor
Editor(viz::Client &client, Properties properties, std::function< void(objpose::ProvidedObjectPoseSeq &)> pushToMemory, std::function< objpose::ObjectPoseSeq(void)> pullFromMemory)
Definition: Editor.cpp:10
armarx::objpose::ObjectPoseSeq
std::vector< ObjectPose > ObjectPoseSeq
Definition: forward_declarations.h:20
armarx::VisualizationDescription::transform
Eigen::Matrix4f transform
Definition: Editor.h:19
armarx::ChangeState::applyTo
bool applyTo(objpose::ObjectPose &pose)
Definition: Editor.cpp:281
ObjectPoseClientPlugin.h
armarx::VisualizationDescription
Definition: Editor.h:17
armarx::VisualizationDescription::options
std::vector< std::string > options
Definition: Editor.h:22
armarx::PlaceholderState::movePlaceholder
void movePlaceholder(size_t id, Eigen::Matrix4f const &transform)
Definition: Editor.cpp:511
armarx::VisualizationDescription::prototypeIndex
size_t prototypeIndex
Definition: Editor.h:30
armarx::ChangeState
Definition: Editor.h:38
armarx::PlaceholderState::addPlaceholder
void addPlaceholder(simox::OrientedBoxf box)
Definition: Editor.cpp:489
armarx::ObjectFinder
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
Definition: ObjectFinder.h:23
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
InteractionObserver.h
armarx::Editor::Properties::providerName
std::string providerName
Definition: Editor.h:119
armarx::ChangeState::clear
void clear()
Definition: Editor.cpp:269
armarx::Editor
Definition: Editor.h:114
armarx::PlaceholderState::Placeholder::transform
Eigen::Matrix4f transform
Definition: Editor.h:89
armarx::ChangeState::resetObject
void resetObject(objpose::ObjectPose const &object)
Definition: Editor.cpp:453
armarx::ChangeState::moveObject
void moveObject(objpose::ObjectPose const &object, Eigen::Matrix4f const &transform)
Definition: Editor.cpp:469
armarx::VisualizationDescription::cloneIndex
size_t cloneIndex
Definition: Editor.h:27
armarx::ChangeState::createObject
void createObject(std::string const &objectID, Eigen::Matrix4f const &pose)
Definition: Editor.cpp:413
armarx::PlaceholderState::PlaceholderState
PlaceholderState(Editor *editor)
Definition: Editor.h:84
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::VisualizationDescription::updateIndex
size_t updateIndex
Definition: Editor.h:32
armarx::VisualizationDescription::resetAllIndex
size_t resetAllIndex
Definition: Editor.h:33
armarx::objpose::ProvidedObjectPoseSeq
std::vector< ProvidedObjectPose > ProvidedObjectPoseSeq
Definition: forward_declarations.h:25
armarx::Editor::Properties::confidenceThreshold
float const & confidenceThreshold
Definition: Editor.h:122
armarx::ChangeState::deleteObject
void deleteObject(objpose::ObjectPose const &object)
Definition: Editor.cpp:448
armarx::Editor::Properties::objectScaling
float const & objectScaling
Definition: Editor.h:121
armarx::VisualizationDescription::resetIndex
size_t resetIndex
Definition: Editor.h:29
armarx::ChangeState::getTransform
Eigen::Matrix4f getTransform(objpose::ObjectPose const &object)
Definition: Editor.cpp:475
armarx::ChangeState::moveNewObjectsTo
void moveNewObjectsTo(objpose::ObjectPoseSeq &seq)
Definition: Editor.cpp:275
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::VisualizationDescription::color
std::optional< simox::Color > color
Definition: Editor.h:24
armarx::PlaceholderState::specifyObject
void specifyObject(size_t id, std::string const &objectID, ChangeState &changeState)
Definition: Editor.cpp:538
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:315
armarx::VisualizationDescription::deleteIndex
size_t deleteIndex
Definition: Editor.h:28
armarx::Editor::Properties::availableObjects
std::vector< data::ObjectID > const & availableObjects
Definition: Editor.h:124
armarx::PlaceholderState
Definition: Editor.h:81
armarx::PlaceholderState::removePlaceholder
void removePlaceholder(size_t id)
Definition: Editor.cpp:517
armarx::VisualizationDescription::allowTransforming
bool allowTransforming
Definition: Editor.h:20
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:73
armarx::viz::Client
Definition: Client.h:109
armarx::ChangeState::visualizeNewObjects
void visualizeNewObjects()
Definition: Editor.cpp:301
armarx::VisualizationDescription::commitIndex
size_t commitIndex
Definition: Editor.h:31
armarx::viz::Layer
Definition: Layer.h:12
armarx::VisualizationDescription::alpha
std::optional< float > alpha
Definition: Editor.h:23
armarx::PlaceholderState::Placeholder::box
simox::OrientedBoxf box
Definition: Editor.h:88
armarx::Editor::Properties
Definition: Editor.h:117
armarx::ChangeState::cloneObject
void cloneObject(objpose::ObjectPose const &object)
Definition: Editor.cpp:381
armarx::ChangeState::buildVisualizationDescription
VisualizationDescription buildVisualizationDescription(objpose::ObjectPose &object)
Definition: Editor.cpp:309
armarx::PlaceholderState::visualizePlaceholders
void visualizePlaceholders()
Definition: Editor.cpp:498
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::objpose::ObjectPose
An object pose as stored by the ObjectPoseStorage.
Definition: ObjectPose.h:36
armarx::Editor::step
void step()
Definition: Editor.cpp:32
ObjectFinder.h