MIRA
Visualization3DView.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_VISUALIZATION3DVIEW_H_
48 #define _MIRA_VISUALIZATION3DVIEW_H_
49 
50 #include <geometry/Point.h>
51 
55 
57 
59 
60 namespace mira {
61 
63 
69 {
71  ("Name", "3D")
72  ("Description", "3D view for channel data")
73  ("Category" , "Visualization")
74  ("Visualization", "mira::Visualization3D"))
75 Q_OBJECT
76 
77 public:
79 
80  virtual ~Visualization3DView()
81  {
82  // we must make sure that we destroy our tools and visualizations
83  // before we destroy ourself to give them the chance to cleanup
84  // (during cleanup they may need a fully operational Visualization3DView)
86  destroyTools();
87  }
88 
89 public:
90 
91  template <typename Reflector>
92  void reflect(Reflector& r)
93  {
95  r.property("Camera Mode", mCameraMode,
96  setter(&Visualization3DView::setCameraMode, this),
97  "The view mode of the camera", PERSPECTIVE,
98  PropertyHints::enumeration("Perspective Orbit;Orthographic Orbit;Bird's-Eye"));
99 
100  r.property("Camera", mCameraSettings, "Camera view", Camera());
101 
102  r.property("Background", mBackgroundMode, setter(&Visualization3DView::setBackgroundMode, this), "Background mode", BACKGROUND_GRADIENT,
103  PropertyHints::enumeration("Solid;Gradient;White;Black"));
104  r.property("Background Color", mBackgroundColor1, setter(&Visualization3DView::setBackgroundColor1, this), "Solid background color / Top gradient color", Ogre::ColourValue(0.78f,0.86f,1.0f) );
105  r.property("Background Gradient Color", mBackgroundColor2, setter(&Visualization3DView::setBackgroundColor2, this), "Bottom gradient color", Ogre::ColourValue(0.90f,0.94f,1.0f) );
106 
107  r.property("Render Mode", mRenderMode,
108  setter(&Visualization3DView::setRenderMode, this),
109  "The view mode of the camera", NORMAL,
110  PropertyHints::enumeration("Normal;Wireframe;Wireframe (hidden line)"));
111 
112  r.property("Stereo Mode", mStereoMode,
113  setter(&Visualization3DView::setStereoMode, this),
114  "The view mode of the camera", NONE,
115  PropertyHints::enumeration("None;Cross-eyed / parallel"));
116  r.property("Stereo Eye Distance", mStereoEyeDistance, "in meter, >0 for cross view, <0 for parallel view", 0.2f);
117 
118  r.property("Show Bounding Boxes", mShowBoundingBoxes, setter(&Visualization3DView::showBoundingBoxes, this), "Show bounding boxes of all objects (for debugging)", false);
119 
120  r.property("Light Color", mLightColor, setterNotify(mLightColor, &Visualization3DView::changeLightColor, this), "The color of the default light", Ogre::ColourValue::White);
121  r.property("Light Azimuth", mLightAzimuth, setterNotify(mLightAzimuth, &Visualization3DView::changeLightDirection, this), "The azimuth of the light source [deg]", -135.0f, PropertyHints::limits(-180.0f,180.0f) | PropertyHints::step(5.0f));
122  r.property("Light Height", mLightHeight, setterNotify(mLightHeight, &Visualization3DView::changeLightDirection, this), "The height of the light source [deg]", 45.0f, PropertyHints::limits(-90.0f,90.0f) | PropertyHints::step(5.0f));
123  r.property("Ambient Light", mLightAmbient, setterNotify(mLightAmbient, &Visualization3DView::changeAmbientLight, this), "The strength of the ambient light", 0.3f, PropertyHints::minimum(0.0f));
124 
125  r.property("SaveContentMinPictureSize", mSaveContentMinPictureSize,
126  "Minimum width or height of the image saved by rendering the viewport at an appropriate resolution.", 2048);
127  }
128 
129 public:
130  virtual QImage captureContent();
131 
132 public: // implementation of VisualizationView
133 
134  virtual void addVisualization(Visualization* vis);
135  virtual void moveUpVisualization(Visualization* vis);
136  virtual void moveDownVisualization(Visualization* vis);
137 
138  virtual void addTool(VisualizationTool* tool);
139 
140  virtual const Class& supportedVisualizationClass() const;
141  virtual const Class& supportedVisualizationToolClass() const;
142 
143 protected:
144 
145  virtual void update(Duration dt);
146 
147  void changeLightColor();
148  virtual void changeLightDirection();
149  void changeAmbientLight();
150 
151 protected:
152 
153  virtual QWidget* createVisualizationPart();
154 
155  virtual void resetView();
156  virtual void saveContentToFile();
157 
158 protected: // implementation of VisualizationViewTransformable
159 
160  virtual void setCameraFrame(const TransformProperty& frame);
161 
162 public: // implementation of IVisualization3DSite
163 
164  virtual Ogre::SceneManager* getSceneManager();
165 
166  virtual void registerInteractionListener(InteractionListener3D* listener);
167  virtual void removeInteractionListener(InteractionListener3D* listener);
168  virtual std::set<InteractionListener3D*> getInteractionListeners();
169 
170  virtual const std::string& getFixedFrame() const {
171  return mFixedFrame.getID();
172  }
173 
174  virtual const std::string& getCameraFrame() const {
175  return mCameraFrame.getID();
176  }
177 
178 public:
179 
180  virtual const Camera& getCamera() const;
181  virtual void setCamera(const Camera& camera);
182 
183  virtual Ogre::Camera* acquireCamera(boost::function<void()> lostCameraCallback = boost::function<void()>());
184  virtual void releaseCamera();
185 
186 private:
187 
189  class UI;
190  UI* ui;
191 
193 
194 private:
195  friend class UI;
197  friend class RenderQueueSorter;
198 
199  void setupVisualizations();
200  void setupTools();
201 
202  void updateCamera();
203 
204 private:
205  void populateDefaultVisualizations();
206  void createDefaultVisualization(const std::string& className, const std::string& displayName);
207 
208 private:
209  enum CameraMode
210  {
211  PERSPECTIVE=0,
212  ORTHOGRAPHIC,
213  BIRDS_EYE
214  };
215 
216  enum StereoMode
217  {
218  NONE,
219  CROSSED_EYE
220  };
221 
222  enum BackgroundMode
223  {
224  BACKGROUND_SOLID=0,
225  BACKGROUND_GRADIENT,
226  BACKGROUND_WHITE,
227  BACKGROUND_BLACK
228  };
229 
230  enum RenderMode
231  {
232  NORMAL = 0,
233  WIREFRAME,
234  HIDDEN_LINE
235  };
236 
237  void setCameraMode(CameraMode mode);
238 
239  void setBackgroundMode(BackgroundMode mode);
240  void setBackgroundColor1(Ogre::ColourValue color);
241  void setBackgroundColor2(Ogre::ColourValue color);
242  void showBoundingBoxes(bool show=true);
243 
244  void setRenderMode(RenderMode mode);
245  void setStereoMode(StereoMode mode);
246 
247 private:
248 
249  ChannelProperty<float> mIntrinsicParamsChannel;
250 
251  CameraMode mCameraMode;
252  Camera mCameraSettings;
253 
254  bool mCameraAcquired;
255  boost::function<void()> mLostCameraCallback;
256 
257  BackgroundMode mBackgroundMode;
258  Ogre::ColourValue mBackgroundColor1;
259  Ogre::ColourValue mBackgroundColor2;
260 
261  RenderMode mRenderMode;
262  StereoMode mStereoMode;
263  float mStereoEyeDistance;
264 
265  bool mShowBoundingBoxes;
266 
267  Ogre::ColourValue mLightColor;
268  float mLightAzimuth;
269  float mLightHeight;
270  float mLightAmbient;
271  boost::mutex mListenerMutex;
272  std::set<InteractionListener3D*> mListeners;
273 
274  uint mSaveContentMinPictureSize;
275 };
276 
278 
279 }
280 
281 #endif
virtual void moveDownVisualization(Visualization *vis)
Change order of visualizations in the view, move the specified visualization down.
The interface of a Visualization3DSite.
Definition: Visualization3D.h:84
Definition: VisualizationTool.h:59
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
virtual std::set< InteractionListener3D * > getInteractionListeners()
Provides a special setter, that simply sets the value of the member to the given value AND calls a us...
friend class RenderQueueSorter
Definition: Visualization3DView.h:197
PropertyHint enumeration(const std::string &values)
Sets the attribute "enumeration".
Definition: PropertyHint.h:306
Class for 2D, 3D and N-dimensional points.
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
virtual void registerInteractionListener(InteractionListener3D *listener)
Class object which supports some kind of class reflection.
Definition: Class.h:97
Setter< T > setter(void(*f)(const T &))
Creates a Setter for global or static class methods taking the argument by const reference.
Definition: GetterSetter.h:443
virtual QImage captureContent()
Returns the content of the editor part as QImage.
const RGB White(1.0f, 1.0f, 1.0f)
TransformProperty mFixedFrame
Definition: VisualizationView.h:365
Use this class instead of a string property whenever your module has a transform frame as property...
Definition: TransformProperty.h:70
virtual const std::string & getFixedFrame() const
Definition: Visualization3DView.h:170
virtual void setCamera(const Camera &camera)
void reflect(Reflector &r)
Definition: Visualization3DView.h:92
virtual Ogre::Camera * acquireCamera(boost::function< void()> lostCameraCallback=boost::function< void()>())
Requests the camera of the visualization site.
Declaration of Visualization3D and related classes.
Abstract base class for 2D, 3D, text and plot visualization views (namely Visualization2DView and Vis...
Definition: VisualizationView.h:337
virtual const Camera & getCamera() const
Obtains the current camera settings (position, orientation, etc.) of the views own camera...
PropertyHint limits(const T &min, const T &max)
Sets both attributes "minimum" and "maximum" to the specified values.
Definition: PropertyHint.h:275
#define MIRA_META_OBJECT(classIdentifier, MetaInfo)
Use this MACRO instead of MIRA_OBJECT if you like to add meta information to your class...
Definition: FactoryMacros.h:204
virtual void setCameraFrame(const TransformProperty &frame)
TODO Add description.
Use this class to represent time durations.
Definition: Time.h:106
virtual void update(Duration dt)
Is called by this class within the update timer event to update the view.
virtual const std::string & getCameraFrame() const
Definition: Visualization3DView.h:174
friend class RenderModeTechniqueMod
Definition: Visualization3DView.h:196
virtual const Class & supportedVisualizationToolClass() const
Derived visualization views may return the base class of their supported tools.
virtual void addVisualization(Visualization *vis)
Adds an existing visualization to this view.
Listener for mouse events on movable objects in a 3D view.
Definition: InteractionListener3D.h:66
PropertyHint minimum(const T &min)
Sets the attribute "minimum" to the specified value.
Definition: PropertyHint.h:243
TransformProperty mCameraFrame
Definition: VisualizationView.h:366
virtual void moveUpVisualization(Visualization *vis)
Change order of visualizations in the view, move the specified visualization up.
Setter< T > setterNotify(T &member, boost::function< void()> notifyFn)
Creates a setter that simply sets the value of the specified member to the given value AND calls a us...
Definition: SetterNotify.h:86
const std::string & getID() const
Returns the frame ID of this property.
Definition: TransformProperty.h:93
PropertyHint step(const T &step)
Sets the attribute "step" to the specified value.
Definition: PropertyHint.h:265
virtual void removeInteractionListener(InteractionListener3D *listener)
Non intrusive reflect for OGRE color class.
virtual void releaseCamera()
Releases a camera that previously was acquired.
virtual QWidget * createVisualizationPart()
Declaration of VisualizationView and VisualizationViewTransformable.
virtual void changeLightDirection()
3D view of a scene that may contain different visualization objects which show the actual content of ...
Definition: Visualization3DView.h:68
virtual const Class & supportedVisualizationClass() const
Derived visualization views must return the base class of their supported visualizations.
virtual Ogre::SceneManager * getSceneManager()
friend class UI
Definition: Visualization3DView.h:192
virtual void resetView()
virtual void saveContentToFile()
virtual void addTool(VisualizationTool *tool)
Adds an existing tool to this view.