MIRA
Visualization3DBasic.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_VISUALIZATION3DBASIC_H_
48 #define _MIRA_VISUALIZATION3DBASIC_H_
49 
50 #ifndef Q_MOC_RUN
51 #include <OGRE/OgreSceneManager.h>
52 #include <OGRE/OgreSceneNode.h>
53 #endif
54 
56 
57 #include <widgets/OgreUtils.h>
58 
59 namespace mira {
60 
62 
74 template <typename T>
76 {
77 public:
78 
82  Visualization3DBasic(const std::string channelDisplayName = "Channel") :
83  mChannelDisplayName(channelDisplayName),
84  mNode(NULL) {
85  mDataChannel.setDataChangedCallback(
86  boost::bind(&Visualization3DBasic::dataChangedCallback, this, _1));
87  mDataChannel.setChannelChangedCallback(
89  }
90 
92  if(getSite()==NULL)
93  return;
94  getSite()->getSceneManager()->destroySceneNode(mNode);
95  }
96 
97  template <typename Reflector>
98  void reflect(Reflector& r) {
101  "The channel to be visualized");
102  }
103 
104 public:
105 
106  virtual void setupScene(IVisualization3DSite* site) {
107  Ogre::SceneManager* mgr = site->getSceneManager();
108  mNode = mgr->getRootSceneNode()->createChildSceneNode();
109  setupScene(mgr, mNode);
110  mNode->setVisible(isEnabled());
111  }
112 
118  virtual void setupScene(Ogre::SceneManager* mgr, Ogre::SceneNode* node) = 0;
119 
120  virtual Ogre::SceneNode* getNode()
121  {
122  return mNode;
123  }
124 
125 public:
126 
127  void setEnabled(bool enabled) {
129  if (mNode != NULL)
130  mNode->setVisible(enabled);
131  }
132 
133 public:
134 
137  }
138 
139 protected:
140 
141  virtual void update(Duration dt) {
142  if (!mDataChannel.isValid() || mDataChannel.getDataUpdateCount() == 0)
143  return;
144 
145  if (mDataFrameID.empty())
146  MIRA_THROW(TransformerBase::XTransform,
147  "Data has no frame for transforming it into the view's camera frame");
148 
150  try {
151  d = getAuthority().template getTransform<RigidTransform3f>(
155  }
156  catch(Exception& ex) { // fall back to non interpolating versions
157  d = getAuthority().template getTransform<RigidTransform3f>(
160  getSite()->getFixedFrame());
161  }
162 
164  }
165 
167  mDataFrameID = data->frameID;
168  mDataTimestamp = data->timestamp;
169  dataChanged(data);
170  }
171 
173  mDataFrameID = "";
174  try {
175  this->setName(mDataChannel.getID());
176  }
177  catch (XRuntime&) {}
178  channelChanged();
179  }
180 
184  virtual void channelChanged() {}
185 
189  virtual void dataChanged(ChannelRead<T> data) {
190  onDataChanged(data); // only for backward compatibility
191  }
192 
196  virtual void onDataChanged(ChannelRead<T> data) {}
197 
198 protected:
199 
201  std::string mChannelDisplayName;
202 
203  std::string mDataFrameID;
205 
206  Ogre::SceneNode* mNode;
207 };
208 
210 
211 }
212 
213 #endif
Time mDataTimestamp
Definition: Visualization3DBasic.h:204
The interface of a Visualization3DSite.
Definition: Visualization3D.h:84
void setName(const std::string &name)
Sets the name of this visualization.
Definition: Visualization.h:157
virtual Authority & getAuthority()
Return the authority as reference.
virtual void setupScene(IVisualization3DSite *site)
Must be implemented in derived classes.
Definition: Visualization3DBasic.h:106
std::string mChannelDisplayName
Definition: Visualization3DBasic.h:201
virtual void dataChanged(ChannelRead< T > data)
Overwrite this method to listen on channel callbacks.
Definition: Visualization3DBasic.h:189
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
virtual const std::string & getFixedFrame() const =0
virtual void onDataChanged(ChannelRead< T > data)
Definition: Visualization3DBasic.h:196
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
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 Ogre::SceneNode * getNode()
Must be implemented in derived classes to return the scene node to which this visualization attaches ...
Definition: Visualization3DBasic.h:120
Declaration of helper functions for converting from and to Ogre.
ChannelProperty< T > mDataChannel
Definition: Visualization3DBasic.h:200
An object that allows read access to data of a channel.
Definition: ChannelReadWrite.h:494
bool isEnabled() const
Returns true, if this visualization is enabled and visible.
Definition: Visualization.h:140
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
The data structure that is returned by getDataConnection.
Definition: Visualization.h:183
virtual const std::string & getCameraFrame() const =0
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:418
Declaration of Visualization3D and related classes.
virtual void channelChanged()
Overwrite this method to get notified when the connected channel changes.
Definition: Visualization3DBasic.h:184
Use this class to represent time durations.
Definition: Time.h:106
void reflect(Reflector &r)
Definition: Visualization3DBasic.h:98
virtual void setEnabled(bool enabled)
Changes the enabled-state and therefore the visibility of this visualization.
Definition: Visualization.h:149
virtual ~Visualization3DBasic()
Definition: Visualization3DBasic.h:91
Visualization3DBasic(const std::string channelDisplayName="Channel")
Constructor taking a name of the visualized channel.
Definition: Visualization3DBasic.h:82
std::string mDataFrameID
Definition: Visualization3DBasic.h:203
1D linear interpolator.
Definition: LinearInterpolator.h:137
void dataChangedCallback(ChannelRead< T > data)
Definition: Visualization3DBasic.h:166
Base class for exceptions.
Definition: Exception.h:199
The concrete typed ChannelProperty template class.
Definition: ChannelProperty.h:214
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:481
Abstract base class for all 3D visualization that are used by Visualization3DView.
Definition: Visualization3D.h:169
Inherit from this class if you want to implement a simple 3D visualization.
Definition: Visualization3DBasic.h:75
virtual Ogre::SceneManager * getSceneManager()=0
Ogre::SceneNode * mNode
Definition: Visualization3DBasic.h:206
void channelChangedCallback()
Definition: Visualization3DBasic.h:172
virtual DataConnection getDataConnection()
Returns information about the direct data connection for this visualization.
Definition: Visualization3DBasic.h:135
void setEnabled(bool enabled)
Changes the enabled-state and therefore the visibility of this visualization.
Definition: Visualization3DBasic.h:127
virtual void update(Duration dt)
This method can be implemented in the derived Visualization classes.
Definition: Visualization3DBasic.h:141
virtual IVisualization3DSite * getSite()
Returns a pointer to the IVisualization3DSite interface that was set in the init() method...
MIRA_GUI_WIDGETS_EXPORT void setTransform(Ogre::SceneNode *node, const RigidTransform2f &t)
Sets position and orientation of the scene node according to the specified transform.