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 class QGLWidget;
61 
62 namespace mira {
63 
65 
71 {
73  ("Name", "3D")
74  ("Description", "3D view for channel data")
75  ("Category" , "Visualization")
76  ("Visualization", "mira::Visualization3D"))
77 Q_OBJECT
78 
79 public:
81 
82  virtual ~Visualization3DView()
83  {
84  // we must make sure that we destroy our tools and visualizations
85  // before we destroy ourself to give them the chance to cleanup
86  // (during cleanup they may need a fully operational Visualization3DView)
87  destroyVisualizations();
88  destroyTools();
89  }
90 
91 public:
92 
93  template <typename Reflector>
94  void reflect(Reflector& r)
95  {
97  r.property("Camera Mode", mCameraMode,
98  setter(&Visualization3DView::setCameraMode, this),
99  "The view mode of the camera", PERSPECTIVE,
100  PropertyHints::enumeration("Perspective Orbit;Orthographic Orbit;Bird's-Eye"));
101 
102  r.property("Camera", mCameraSettings, "Camera view", Camera());
103 
104  r.property("Background", mBackgroundMode, setter(&Visualization3DView::setBackgroundMode, this), "Background mode", BACKGROUND_GRADIENT,
105  PropertyHints::enumeration("Solid;Gradient;White;Black"));
106  r.property("Background Color", mBackgroundColor1, setter(&Visualization3DView::setBackgroundColor1, this), "Solid background color / Top gradient color", Ogre::ColourValue(0.78f,0.86f,1.0f) );
107  r.property("Background Gradient Color", mBackgroundColor2, setter(&Visualization3DView::setBackgroundColor2, this), "Bottom gradient color", Ogre::ColourValue(0.90f,0.94f,1.0f) );
108 
109  r.property("Render Mode", mRenderMode,
110  setter(&Visualization3DView::setRenderMode, this),
111  "The view mode of the camera", NORMAL,
112  PropertyHints::enumeration("Normal;Wireframe;Wireframe (hidden line)"));
113 
114  r.property("Stereo Mode", mStereoMode,
115  setter(&Visualization3DView::setStereoMode, this),
116  "The view mode of the camera", NONE,
117  PropertyHints::enumeration("None;Cross-eyed / parallel"));
118  r.property("Stereo Eye Distance", mStereoEyeDistance, "in meter, >0 for cross view, <0 for parallel view", 0.2f);
119 
120  r.property("Show Bounding Boxes", mShowBoundingBoxes, setter(&Visualization3DView::showBoundingBoxes, this), "Show bounding boxes of all objects (for debugging)", false);
121 
122  r.property("Light Color", mLightColor, setterNotify(mLightColor, &Visualization3DView::changeLightColor, this), "The color of the default light", Ogre::ColourValue::White);
123  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));
124  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));
125  r.property("Ambient Light", mLightAmbient, setterNotify(mLightAmbient, &Visualization3DView::changeAmbientLight, this), "The strength of the ambient light", 0.3f, PropertyHints::minimum(0.0f));
126 
127  r.property("SaveContentMinPictureSize", mSaveContentMinPictureSize,
128  "Minimum width or height of the image saved by rendering the viewport at an appropriate resolution.", 2048);
129  }
130 
131 public:
132 
134  QGLWidget* getGLRenderWidget();
135 
136  virtual QImage captureContent();
137 
138 public: // implementation of VisualizationView
139 
140  virtual void addVisualization(Visualization* vis);
141  virtual void moveUpVisualization(Visualization* vis);
142  virtual void moveDownVisualization(Visualization* vis);
143 
144  virtual void addTool(VisualizationTool* tool);
145 
146  virtual const Class& supportedVisualizationClass() const;
147  virtual const Class& supportedVisualizationToolClass() const;
148 
149 protected:
150 
151  virtual void update(Duration dt);
152 
153  void changeLightColor();
154  virtual void changeLightDirection();
155  void changeAmbientLight();
156 
157 protected:
158 
159  virtual QWidget* createVisualizationPart();
160 
161  virtual void resetView();
162  virtual void saveContentToFile();
163 
164 protected: // implementation of VisualizationViewTransformable
165 
166  virtual void setCameraFrame(const TransformProperty& frame);
167 
168 public: // implementation of IVisualization3DSite
169 
170  virtual Ogre::SceneManager* getSceneManager();
171 
172  virtual void registerInteractionListener(InteractionListener3D* listener);
173  virtual void removeInteractionListener(InteractionListener3D* listener);
174  virtual std::set<InteractionListener3D*> getInteractionListeners();
175 
176  virtual const std::string& getFixedFrame() const {
177  return mFixedFrame.getID();
178  }
179 
180  virtual const std::string& getCameraFrame() const {
181  return mCameraFrame.getID();
182  }
183 
184 public:
185 
186  virtual const Camera& getCamera() const;
187  virtual void setCamera(const Camera& camera);
188 
189  virtual Ogre::Camera* acquireCamera(boost::function<void()> lostCameraCallback = boost::function<void()>());
190  virtual void releaseCamera();
191 
192 private:
193 
194  class RenderModeTechniqueMod;
195  class UI;
196  UI* ui;
197 
198  class RenderQueueSorter;
199 
200 private:
201  friend class UI;
202  friend class RenderModeTechniqueMod;
203  friend class RenderQueueSorter;
204 
205  void setupVisualizations();
206  void setupTools();
207 
208  void updateCamera();
209 
210 private:
211  void populateDefaultVisualizations();
212  void createDefaultVisualization(const std::string& className, const std::string& displayName);
213 
214 private:
215  enum CameraMode
216  {
217  PERSPECTIVE=0,
218  ORTHOGRAPHIC,
219  BIRDS_EYE
220  };
221 
222  enum StereoMode
223  {
224  NONE,
225  CROSSED_EYE
226  };
227 
228  enum BackgroundMode
229  {
230  BACKGROUND_SOLID=0,
231  BACKGROUND_GRADIENT,
232  BACKGROUND_WHITE,
233  BACKGROUND_BLACK
234  };
235 
236  enum RenderMode
237  {
238  NORMAL = 0,
239  WIREFRAME,
240  HIDDEN_LINE
241  };
242 
243  void setCameraMode(CameraMode mode);
244 
245  void setBackgroundMode(BackgroundMode mode);
246  void setBackgroundColor1(Ogre::ColourValue color);
247  void setBackgroundColor2(Ogre::ColourValue color);
248  void showBoundingBoxes(bool show=true);
249 
250  void setRenderMode(RenderMode mode);
251  void setStereoMode(StereoMode mode);
252 
253 private:
254 
255  ChannelProperty<float> mIntrinsicParamsChannel;
256 
257  CameraMode mCameraMode;
258  Camera mCameraSettings;
259 
260  bool mCameraAcquired;
261  boost::function<void()> mLostCameraCallback;
262 
263  BackgroundMode mBackgroundMode;
264  Ogre::ColourValue mBackgroundColor1;
265  Ogre::ColourValue mBackgroundColor2;
266 
267  RenderMode mRenderMode;
268  StereoMode mStereoMode;
269  float mStereoEyeDistance;
270 
271  bool mShowBoundingBoxes;
272 
273  Ogre::ColourValue mLightColor;
274  float mLightAzimuth;
275  float mLightHeight;
276  float mLightAmbient;
277  boost::mutex mListenerMutex;
278  std::set<InteractionListener3D*> mListeners;
279 
280  uint mSaveContentMinPictureSize;
281 };
282 
284 
285 }
286 
287 #endif
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:90
Provides a special setter, that simply sets the value of the member to the given value AND calls a us...
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:956
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
const RGB White(1.0f, 1.0f, 1.0f)
Use this class instead of a string property whenever your module has a transform frame as property...
Definition: TransformProperty.h:72
virtual const std::string & getFixedFrame() const
Definition: Visualization3DView.h:176
void reflect(Reflector &r)
Definition: Visualization3DView.h:94
Declaration of Visualization3D and related classes.
Abstract base class for 2D, 3D, text and plot visualization views (namely Visualization2DView and Vis...
Definition: VisualizationView.h:338
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:208
TODO Add description.
Use this class to represent time durations.
Definition: Time.h:104
virtual const std::string & getCameraFrame() const
Definition: Visualization3DView.h:180
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
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
#define MIRA_GUI_VIEWS_EXPORT
Definition: GuiViewsExports.h:61
PropertyHint step(const T &step)
Sets the attribute "step" to the specified value.
Definition: PropertyHint.h:265
Non intrusive reflect for OGRE color class.
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:70