NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkVLSceneView.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef niftkVLSceneView_h
16 #define niftkVLSceneView_h
17 
18 #include <niftkVLExports.h>
19 #include <niftkVLMapper.h>
21 #include <vlGraphics/UIEventListener.hpp>
22 #include <mitkDataStorage.h>
23 #include <mitkDataNode.h>
24 #include <mitkImage.h>
25 
27 
28 namespace mitk
29 {
30  class PointSet;
31  class CoordinateAxesData;
32  class DataStorage;
33  class Surface;
34 }
35 
36 namespace niftk
37 {
38 
39 class VLWidget;
40 #ifdef _USE_CUDA
41  class CudaTest;
42 #endif
43 
70 class NIFTKVL_EXPORT VLSceneView : public vl::UIEventListener
71 {
72 public:
73  typedef std::map< mitk::DataNode::ConstPointer, vl::ref<VLMapper> > DataNodeVLMapperMapType;
74 
75 public:
76  VLSceneView( VLWidget* vlwidget );
77  ~VLSceneView();
78 
83  void setDataStorage(mitk::DataStorage* ds);
84 
88  bool setCameraTrackingNode(const mitk::DataNode* node);
89 
93  void setEyeHandFileName(const std::string& fileName);
94 
98  bool setBackgroundNode(const mitk::DataNode* node);
99 
103  void setRenderingMode( vl::Vivid::ERenderingMode );
104  vl::Vivid::ERenderingMode renderingMode() const;
105 
109  void setBackgroundColor(float r, float g, float b);
110  vl::vec3 backgroundColor() const;
111 
115  void setStencilEnabled( bool enabled );
116  bool isStencilEnabled() const;
117 
121  void setStencilBackgroundColor( const vl::vec4& color );
122  const vl::vec4& stencilBackgroundColor() const;
123 
127  void setStencilSmoothness( float smoothness );
128  float stencilSmoothness() const;
129 
133  void setOpacity( float opacity );
134  float opacity() const;
135 
141  void setDepthPeelingPasses( int n );
142  int depthPeelingPasses() const;
143 
147  void reInit(const vl::vec3& dir = vl::vec3(0,0,1), const vl::vec3& up = vl::vec3(0,1,0), float bias=1.0f);
148 
152  void globalReInit(const vl::vec3& dir = vl::vec3(0,0,1), const vl::vec3& up = vl::vec3(0,1,0), float bias=1.0f);
153 
157  vl::VividRendering* vividRendering() { return m_VividRendering.get(); }
158  const vl::VividRendering* vividRendering() const { return m_VividRendering.get(); }
159 
163  niftk::VLTrackballManipulator* trackball() { return m_Trackball.get(); }
164  const niftk::VLTrackballManipulator* trackball() const { return m_Trackball.get(); }
165 
169  vl::CalibratedCamera* camera() { return m_Camera.get(); }
170  const vl::CalibratedCamera* camera() const { return m_Camera.get(); }
171 
175  mitk::DataStorage* dataStorage() { return m_DataStorage.GetPointer(); }
176  const mitk::DataStorage* dataStorage() const { return m_DataStorage.GetPointer(); }
177 
181  void scheduleSceneRebuild();
182 
183 protected:
184  void initSceneFromDataStorage();
185  void clearScene();
186  void updateScene();
187  void renderScene();
188  void addDataStorageListeners();
189  void removeDataStorageListeners();
190  void scheduleTrackballAdjustView(bool schedule = true);
191 
193  void scheduleNodeAdd(const mitk::DataNode* node);
194 
196  void scheduleNodeRemove(const mitk::DataNode* node);
197 
199  void scheduleNodeUpdate(const mitk::DataNode* node);
200 
202  void addDataNode(const mitk::DataNode* node);
203 
205  void removeDataNode(const mitk::DataNode* node);
206 
208  void updateDataNode(const mitk::DataNode* node);
209 
211  void updateCameraParameters();
212 
214  VLMapper* getVLMapper(const mitk::DataNode* node);
215 
216 protected:
217  // Used by niftk::ScopedOGLContext
219 
220  vl::ref<vl::VividRendering> m_VividRendering;
221  vl::ref<vl::VividRenderer> m_VividRenderer;
222  vl::ref<vl::SceneManagerActorTree> m_SceneManager;
223  vl::ref<vl::CalibratedCamera> m_Camera;
224  vl::ref<niftk::VLTrackballManipulator> m_Trackball;
225 
226  mitk::DataStorage::Pointer m_DataStorage;
227  DataNodePropertyListener::Pointer m_NodeVisibilityListener;
228  DataNodePropertyListener::Pointer m_NodeColorPropertyListener;
229  DataNodePropertyListener::Pointer m_NodeOpacityPropertyListener;
230 
231  DataNodeVLMapperMapType m_DataNodeVLMapperMap;
232  std::set<mitk::DataNode::ConstPointer> m_NodesToUpdate;
233  std::set<mitk::DataNode::ConstPointer> m_NodesToAdd;
234  std::set<mitk::DataNode::ConstPointer> m_NodesToRemove;
235  mitk::DataNode::ConstPointer m_CameraNode;
236 
237  mitk::DataNode::ConstPointer m_BackgroundNode;
238  mitk::Image::ConstPointer m_BackgroundImage;
239  vl::mat4 m_EyeHandMatrix;
240 
244 
245  // CUDA support
246 
247 #ifdef _USE_CUDA
248  niftk::CUDAImage::ConstPointer m_BackgroundCUDAImage;
249  CudaTest* m_CudaTest;
250 #endif
251 
252 protected:
253 
254  // vl::UIEventListener implementation
255 
256  virtual void initEvent();
257  virtual void resizeEvent(int width, int height);
258  virtual void updateEvent();
259  virtual void destroyEvent();
260 
261  virtual void addedListenerEvent(vl::OpenGLContext *) { }
262  virtual void removedListenerEvent(vl::OpenGLContext *) { }
263  virtual void enableEvent(bool) { }
264  virtual void visibilityEvent(bool) { }
265  virtual void mouseMoveEvent(int, int) { }
266  virtual void mouseUpEvent(vl::EMouseButton, int, int) { }
267  virtual void mouseDownEvent(vl::EMouseButton, int, int) { }
268  virtual void mouseWheelEvent(int) { }
269  virtual void keyPressEvent(unsigned short, vl::EKey) { }
270  virtual void keyReleaseEvent(unsigned short, vl::EKey) { }
271  virtual void fileDroppedEvent(const std::vector<vl::String>&) { }
272 };
273 
274 }
275 
276 #endif
277 
vl::VividRendering * vividRendering()
Definition: niftkVLSceneView.h:157
Definition: niftkVLTrackballManipulator.h:28
mitk::DataNode::ConstPointer m_BackgroundNode
Definition: niftkVLSceneView.h:237
virtual void keyPressEvent(unsigned short, vl::EKey)
Definition: niftkVLSceneView.h:269
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2537
virtual void mouseWheelEvent(int)
Definition: niftkVLSceneView.h:268
virtual void addedListenerEvent(vl::OpenGLContext *)
Definition: niftkVLSceneView.h:261
bool m_ScheduleInitScene
Definition: niftkVLSceneView.h:242
Definition: ReceptorMemberCommandTest.cxx:25
vl::ref< vl::VividRendering > m_VividRendering
Definition: niftkVLSceneView.h:220
GLboolean GLboolean g
Definition: glew.h:8272
vl::ref< vl::CalibratedCamera > m_Camera
Definition: niftkVLSceneView.h:223
std::map< mitk::DataNode::ConstPointer, vl::ref< VLMapper > > DataNodeVLMapperMapType
Definition: niftkVLSceneView.h:73
GLdouble GLdouble GLdouble b
Definition: glew.h:7885
virtual void mouseUpEvent(vl::EMouseButton, int, int)
Definition: niftkVLSceneView.h:266
bool m_ScheduleTrackballAdjustView
Definition: niftkVLSceneView.h:241
virtual void removedListenerEvent(vl::OpenGLContext *)
Definition: niftkVLSceneView.h:262
vl::CalibratedCamera * camera()
Definition: niftkVLSceneView.h:169
GLfloat bias
Definition: glew.h:9069
virtual void mouseMoveEvent(int, int)
Definition: niftkVLSceneView.h:265
const niftk::VLTrackballManipulator * trackball() const
Definition: niftkVLSceneView.h:164
vl::ref< vl::SceneManagerActorTree > m_SceneManager
Definition: niftkVLSceneView.h:222
A vl::UIEventListener bound to a QGLWidget (niftk::VLWidget) managing all VL/Vivid rendering and opti...
Definition: niftkVLSceneView.h:70
DataNodePropertyListener::Pointer m_NodeColorPropertyListener
Definition: niftkVLSceneView.h:228
A VL representation of a mitk::DataNode for rendering purposes.
Definition: niftkVLMapper.h:65
DataNodeVLMapperMapType m_DataNodeVLMapperMap
Definition: niftkVLSceneView.h:231
mitk::DataStorage * dataStorage()
Definition: niftkVLSceneView.h:175
GLuint color
Definition: glew.h:6687
const vl::VividRendering * vividRendering() const
Definition: niftkVLSceneView.h:158
const vl::CalibratedCamera * camera() const
Definition: niftkVLSceneView.h:170
mitk::Image::ConstPointer m_BackgroundImage
Definition: niftkVLSceneView.h:238
niftk::VLTrackballManipulator * trackball()
Definition: niftkVLSceneView.h:163
virtual void fileDroppedEvent(const std::vector< vl::String > &)
Definition: niftkVLSceneView.h:271
vl::mat4 m_EyeHandMatrix
Definition: niftkVLSceneView.h:239
std::set< mitk::DataNode::ConstPointer > m_NodesToAdd
Definition: niftkVLSceneView.h:233
A QGLWidget containing a niftk::VLSceneView.
Definition: niftkVLWidget.h:48
vl::ref< vl::VividRenderer > m_VividRenderer
Definition: niftkVLSceneView.h:221
GLdouble GLdouble GLdouble r
Definition: glew.h:1390
DataNodePropertyListener::Pointer m_NodeVisibilityListener
Definition: niftkVLSceneView.h:227
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1236
std::set< mitk::DataNode::ConstPointer > m_NodesToUpdate
Definition: niftkVLSceneView.h:232
bool m_RenderingInProgressGuard
Definition: niftkVLSceneView.h:243
GLclampd n
Definition: glew.h:6789
mitk::DataStorage::Pointer m_DataStorage
Definition: niftkVLSceneView.h:226
virtual void visibilityEvent(bool)
Definition: niftkVLSceneView.h:264
VLWidget * m_VLWidget
Definition: niftkVLSceneView.h:218
virtual void mouseDownEvent(vl::EMouseButton, int, int)
Definition: niftkVLSceneView.h:267
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1236
std::set< mitk::DataNode::ConstPointer > m_NodesToRemove
Definition: niftkVLSceneView.h:234
vl::ref< niftk::VLTrackballManipulator > m_Trackball
Definition: niftkVLSceneView.h:224
DataNodePropertyListener::Pointer m_NodeOpacityPropertyListener
Definition: niftkVLSceneView.h:229
const mitk::DataStorage * dataStorage() const
Definition: niftkVLSceneView.h:176
virtual void keyReleaseEvent(unsigned short, vl::EKey)
Definition: niftkVLSceneView.h:270
mitk::DataNode::ConstPointer m_CameraNode
Definition: niftkVLSceneView.h:235
Definition: niftkExceptionObject.h:21
GLsizei const GLcharARB ** string
Definition: glew.h:5194
virtual void enableEvent(bool)
Definition: niftkVLSceneView.h:263
GLclampf f
Definition: glew.h:3136