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 
56 
57 namespace mira {
58 
60 
65 class IVisualizationSite// : public IAuthorityProvider
66 {
67 public:
68  virtual ~IVisualizationSite() {}
69 };
70 
76 {
77 public:
79 
80  virtual const std::string& getFixedFrame() const = 0;
81  virtual const std::string& getCameraFrame() const = 0;
82 };
83 
85 
91  public Object, public IAuthorityProvider, public Authority
92 {
94 public:
95 
96  Visualization();
97  virtual ~Visualization() {};
98 
99 public:
100 
101  template <typename Reflector>
102  void reflect(Reflector& r)
103  {
104  r.roproperty("Status", &getStatusManager(), "The status of this visualization");
105  r.member("Enabled", mEnabled, "Is true if the visualization is enabled and visible");
106  r.member("Name", mDisplayedName, "The name that is shown to the user");
107  }
108 
109 public:
110 
119  virtual void init(IVisualizationSite* site) = 0;
120 
126  virtual IVisualizationSite* getSite() = 0;
127 
128 public:
129 
135  virtual void processUpdate(Duration dt);
136 
137 public:
138 
140  bool isEnabled() const { return mEnabled; }
141 
149  virtual void setEnabled(bool enabled) { mEnabled = enabled; }
150 
151 public:
152 
154  const std::string& getName() const { return mDisplayedName; }
155 
157  void setName(const std::string& name) { mDisplayedName = name; }
158 
159 protected:
160 
165  virtual void update(Duration dt) {
166  onUpdate(dt); // for backward compatibility.
167  };
168 
173  virtual void onUpdate(Duration dt) {};
174 
175 public:
176 
184  {
185 
186  DataConnection() : property(NULL) {}
187 
188  template<typename T>
190  type(typeName<T>()), property(&iProperty) {}
191 
194  };
195 
206 
207 
215  void setupDataConnectionChannel(const std::string& channelID)
216  {
217  DataConnection connection = getDataConnection();
218  if(connection.property==NULL) // if no data connection channel, abort here
219  return;
220 
221  // set the id
222  connection.property->set(channelID, this);
223  // and add the property to our property set, for regularl update of the properties
224  mChannelProperties.insert(connection.property);
225  }
226 
227 protected:
228 
230  {
232  REQUIRED
233  };
234 
248  template<typename T, typename Reflector>
249  void channelProperty(Reflector& r, const std::string& name,
250  ChannelProperty<T>& channel, const std::string& comment, OptionalMode optional=REQUIRED)
251  {
252  ChannelProperty<T>::channelProperty(r,name, channel,comment,this);
253  mChannelProperties.insert(&channel);
254  channel.setName(name);
255  if(optional==NOT_REQUIRED)
256  channel.setOptional();
257  r.roproperty(std::string(name+" Updates").c_str(),
258  getter<uint32>(boost::bind(&ChannelProperty<T>::getDataUpdateCount, &channel)),
259  "How many data updates were received");
260  }
261 
262 private:
263  std::set<ChannelPropertyBase*> mChannelProperties;
264  bool mEnabled;
265  std::string mDisplayedName; // the name of this visualization that is shown to the user
266 
267 public: // implementation of IAuthorityProvider
268 
269  virtual Authority& getAuthority();
270 
271 };
272 
274 
275 }
276 
277 #endif
virtual DataConnection getDataConnection()
Returns information about the direct data connection for this visualization.
Definition: Visualization.h:205
void reflect(Reflector &r)
Definition: Visualization.h:102
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:385
void setName(const std::string &name)
Sets the name of this visualization.
Definition: Visualization.h:157
virtual void update(Duration dt)
This method can be implemented in the derived Visualization classes.
Definition: Visualization.h:165
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:90
std::string Typename
Definition: Typename.h:60
virtual ~IVisualizationSite()
Definition: Visualization.h:68
virtual const std::string & getFixedFrame() const =0
ChannelPropertyBase * property
Definition: Visualization.h:193
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:249
virtual void onUpdate(Duration dt)
Provided for backward compatibility.
Definition: Visualization.h:173
bool isEnabled() const
Returns true, if this visualization is enabled and visible.
Definition: Visualization.h:140
void setupDataConnectionChannel(const std::string &channelID)
Sets up the data connection channel property (if any) with the specified channel id.
Definition: Visualization.h:215
The interface between a Visualization and the container of the visualization (e.g.
Definition: Visualization.h:75
The data structure that is returned by getDataConnection.
Definition: Visualization.h:183
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:239
$Header file containing base classes to enable class creation using a class factory$ ...
The primary interface between a Visualization and the container of the visualization (e...
Definition: Visualization.h:65
const std::string & getName() const
Returns the associated name of this visualization.
Definition: Visualization.h:154
Definition: Visualization.h:231
virtual ~Visualization()
Definition: Visualization.h:97
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
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:104
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:85
Base class for ChannelProperty template class.
Definition: ChannelProperty.h:70
virtual void setEnabled(bool enabled)
Changes the enabled-state and therefore the visibility of this visualization.
Definition: Visualization.h:149
Authorities act as a facade to the framework.
Definition: Authority.h:93
#define MIRA_GUI_VISUALIZATION_EXPORT
Definition: GuiVisualizationExports.h:61
virtual ~IVisualizationSiteTransformable()
Definition: Visualization.h:78
The concrete typed ChannelProperty template class.
Definition: ChannelProperty.h:214
FrameworkVis export macro declaration.
OptionalMode
Definition: Visualization.h:229
void setOptional()
For internal use only.
Definition: ChannelProperty.h:111
Typename type
Definition: Visualization.h:192
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:131
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:189
DataConnection()
Definition: Visualization.h:186