MIRA
Visualization.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_VISUALIZATION_H_
48 #define _MIRA_VISUALIZATION_H_
49 
50 #include <factory/Factory.h>
51 #include <utils/Time.h>
52 
54 
55 namespace mira {
56 
58 
63 class IVisualizationSite// : public IAuthorityProvider
64 {
65 public:
66  virtual ~IVisualizationSite() {}
67 };
68 
74 {
75 public:
77 
78  virtual const std::string& getFixedFrame() const = 0;
79  virtual const std::string& getCameraFrame() const = 0;
80 };
81 
83 
89  public Object, public IAuthorityProvider, public Authority
90 {
92 public:
93 
94  Visualization();
95  virtual ~Visualization() {};
96 
97 public:
98 
99  template <typename Reflector>
100  void reflect(Reflector& r)
101  {
102  r.roproperty("Status", &getStatusManager(), "The status of this visualization");
103  r.member("Enabled", mEnabled, "Is true if the visualization is enabled and visible");
104  r.member("Name", mDisplayedName, "The name that is shown to the user");
105  }
106 
107 public:
108 
117  virtual void init(IVisualizationSite* site) = 0;
118 
124  virtual IVisualizationSite* getSite() = 0;
125 
126 public:
127 
133  virtual void processUpdate(Duration dt);
134 
135 public:
136 
138  bool isEnabled() const { return mEnabled; }
139 
147  virtual void setEnabled(bool enabled) { mEnabled = enabled; }
148 
149 public:
150 
152  const std::string& getName() const { return mDisplayedName; }
153 
155  void setName(const std::string& name) { mDisplayedName = name; }
156 
157 protected:
158 
163  virtual void update(Duration dt) {
164  onUpdate(dt); // for backward compatibility.
165  };
166 
171  virtual void onUpdate(Duration dt) {};
172 
173 public:
174 
182  {
183 
185 
186  template<typename T>
188  type(typeName<T>()), property(&iProperty) {}
189 
192  };
193 
204 
205 
213  void setupDataConnectionChannel(const std::string& channelID)
214  {
215  DataConnection connection = getDataConnection();
216  if(connection.property==NULL) // if no data connection channel, abort here
217  return;
218 
219  // set the id
220  connection.property->set(channelID, this);
221  // and add the property to our property set, for regularl update of the properties
222  mChannelProperties.insert(connection.property);
223  }
224 
225 protected:
226 
228  {
231  };
232 
246  template<typename T, typename Reflector>
247  void channelProperty(Reflector& r, const std::string& name,
248  ChannelProperty<T>& channel, const std::string& comment, OptionalMode optional=REQUIRED)
249  {
250  ChannelProperty<T>::channelProperty(r,name, channel,comment,this);
251  mChannelProperties.insert(&channel);
252  channel.setName(name);
253  if(optional==NOT_REQUIRED)
254  channel.setOptional();
255  r.roproperty(std::string(name+" Updates").c_str(),
256  getter<uint32>(boost::bind(&ChannelProperty<T>::getDataUpdateCount, &channel)),
257  "How many data updates were received");
258  }
259 
260 private:
261  std::set<ChannelPropertyBase*> mChannelProperties;
262  bool mEnabled;
263  std::string mDisplayedName; // the name of this visualization that is shown to the user
264 
265 public: // implementation of IAuthorityProvider
266 
267  virtual Authority& getAuthority();
268 
269 };
270 
272 
273 }
274 
275 #endif
virtual DataConnection getDataConnection()
Returns information about the direct data connection for this visualization.
Definition: Visualization.h:203
void reflect(Reflector &r)
Definition: Visualization.h:100
Description of ChannelProperty and related classes.
static void channelProperty(Reflector &r, const std::string &name, ChannelProperty &channel, const std::string &comment, IAuthorityProvider *authorityProvider)
Special property-method that should be called within the reflect method to specify a ChannelProperty...
Definition: ChannelProperty.h:396
void setName(const std::string &name)
Sets the name of this visualization.
Definition: Visualization.h:155
virtual void update(Duration dt)
This method can be implemented in the derived Visualization classes.
Definition: Visualization.h:163
virtual Authority & getAuthority()
Return the authority as reference.
virtual IVisualizationSite * getSite()=0
Returns a pointer to the IVisualizationSite interface that was set in the init() method.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Abstract base class for all derived visualizations, namely Visualization3D and Visualization2D.
Definition: Visualization.h:88
std::string Typename
Definition: Typename.h:60
virtual ~IVisualizationSite()
Definition: Visualization.h:66
virtual void processUpdate(Duration dt)
Is called regularly by the VisualizationView to update the visualization.
virtual const std::string & getFixedFrame() const =0
ChannelPropertyBase * property
Definition: Visualization.h:191
Time and Duration wrapper class.
void channelProperty(Reflector &r, const std::string &name, ChannelProperty< T > &channel, const std::string &comment, OptionalMode optional=REQUIRED)
Special property-method that should be called within the reflect method to specify a ChannelProperty...
Definition: Visualization.h:247
virtual void onUpdate(Duration dt)
Provided for backward compatibility.
Definition: Visualization.h:171
bool isEnabled() const
Returns true, if this visualization is enabled and visible.
Definition: Visualization.h:138
void setupDataConnectionChannel(const std::string &channelID)
Sets up the data connection channel property (if any) with the specified channel id.
Definition: Visualization.h:213
The interface between a Visualization and the container of the visualization (e.g.
Definition: Visualization.h:73
The data structure that is returned by getDataConnection.
Definition: Visualization.h:181
virtual const std::string & getCameraFrame() const =0
#define MIRA_ABSTRACT_OBJECT(classIdentifier)
Use this MACRO instead of MIRA_OBJECT to declare the class as abstract.
Definition: FactoryMacros.h:235
$Header file containing base classes to enable class creation using a class factory$ ...
StatusManager & getStatusManager()
The primary interface between a Visualization and the container of the visualization (e...
Definition: Visualization.h:63
const std::string & getName() const
Returns the associated name of this visualization.
Definition: Visualization.h:152
Definition: Visualization.h:230
Definition: Visualization.h:229
virtual ~Visualization()
Definition: Visualization.h:95
Abstract interface for classes that can provide an authority via the getAuthority() method...
Definition: AuthorityProvider.h:61
Use this class to represent time durations.
Definition: Time.h:106
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
void setName(const std::string &name)
Sets the name of the property.
Definition: ChannelProperty.h:83
Base class for ChannelProperty template class.
Definition: ChannelProperty.h:68
virtual void setEnabled(bool enabled)
Changes the enabled-state and therefore the visibility of this visualization.
Definition: Visualization.h:147
Authorities act as a facade to the framework.
Definition: Authority.h:94
virtual ~IVisualizationSiteTransformable()
Definition: Visualization.h:76
The concrete typed ChannelProperty template class.
Definition: ChannelProperty.h:212
OptionalMode
Definition: Visualization.h:227
void setOptional()
For internal use only.
Definition: ChannelProperty.h:109
Typename type
Definition: Visualization.h:190
virtual void set(const std::string &id, IAuthorityProvider *authorityProvider)
Sets the channelID and a necessary authority provider that is used to obtain the authority for subscr...
Definition: ChannelProperty.h:129
Typename typeName(bool cvqualify=true)
Returns a compiler and platform independent typename of T.
Definition: Typename.h:103
DataConnection(ChannelProperty< T > &iProperty)
Definition: Visualization.h:187
DataConnection()
Definition: Visualization.h:184