Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkBaseRenderer.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef BASERENDERER_H_HEADER_INCLUDED_C1CCA0F4
14 #define BASERENDERER_H_HEADER_INCLUDED_C1CCA0F4
15 
17 #include "mitkDataStorage.h"
18 #include "mitkPlaneGeometry.h"
19 #include "mitkPlaneGeometryData.h"
21 #include "mitkTimeGeometry.h"
22 
24 #include "mitkDispatcher.h"
25 
26 #include <vtkRenderWindow.h>
27 #include <vtkRenderer.h>
28 
29 #include <map>
30 #include <set>
31 
32 // DEPRECATED
33 #include <mitkTimeSlicedGeometry.h>
34 
35 namespace mitk
36 {
37  class NavigationController;
38  class SliceNavigationController;
39  class CameraRotationController;
40  class CameraController;
41  class DataStorage;
42  class Mapper;
43  class BaseLocalStorageHandler;
44  class KeyEvent;
45 
46  //##Documentation
47  //## @brief Organizes the rendering process
48  //##
49  //## Organizes the rendering process. A Renderer contains a reference to a
50  //## DataStorage and asks the mappers of the data objects to render
51  //## the data into the renderwindow it is associated to.
52  //##
53  //## \#Render() checks if rendering is currently allowed by calling
54  //## RenderWindow::PrepareRendering(). Initialization of a rendering context
55  //## can also be performed in this method.
56  //##
57  //## The actual rendering code has been moved to \#Repaint()
58  //## Both \#Repaint() and \#Update() are declared protected now.
59  //##
60  //## Note: Separation of the Repaint and Update processes (rendering vs
61  //## creating a vtk prop tree) still needs to be worked on. The whole
62  //## rendering process also should be reworked to use VTK based classes for
63  //## both 2D and 3D rendering.
64  //## @ingroup Renderer
65  class MITKCORE_EXPORT BaseRenderer : public itk::Object
66  {
67  public:
68  typedef std::map<vtkRenderWindow *, BaseRenderer *> BaseRendererMapType;
69  static BaseRendererMapType baseRendererMap;
70 
71  static BaseRenderer *GetInstance(vtkRenderWindow *renWin);
72  static void AddInstance(vtkRenderWindow *renWin, BaseRenderer *baseRenderer);
73  static void RemoveInstance(vtkRenderWindow *renWin);
74 
75  static BaseRenderer *GetByName(const std::string &name);
76  static vtkRenderWindow *GetRenderWindowByName(const std::string &name);
77 
78 #pragma GCC visibility push(default)
79  itkEventMacro(RendererResetEvent, itk::AnyEvent);
80 #pragma GCC visibility pop
81 
84 
85  BaseRenderer(const char *name = nullptr, vtkRenderWindow *renWin = nullptr);
86 
87  //##Documentation
88  //## @brief MapperSlotId defines which kind of mapper (e.g. 2D or 3D) should be used.
89  typedef int MapperSlotId;
90 
92  {
93  Standard2D = 1,
94  Standard3D = 2
95  };
96 
97  //##Documentation
98  //## @brief Possible view directions for render windows.
99  enum class ViewDirection
100  {
101  AXIAL = 0,
102  SAGITTAL,
103  CORONAL,
104  THREE_D
105  };
106 
107  virtual void SetDataStorage(DataStorage *storage);
108 
109  //##Documentation
110  //## return the DataStorage that is used for rendering
111  virtual DataStorage::Pointer GetDataStorage() const { return m_DataStorage.GetPointer(); }
112  //##Documentation
113  //## @brief Access the RenderWindow into which this renderer renders.
114  vtkRenderWindow *GetRenderWindow() const { return m_RenderWindow; }
115  vtkRenderer *GetVtkRenderer() const { return m_VtkRenderer; }
116  //##Documentation
117  //## @brief Returns the Dispatcher which handles Events for this BaseRenderer
118  Dispatcher::Pointer GetDispatcher() const;
119 
120  //##Documentation
121  //## @brief Default mapper id to use.
122  static const MapperSlotId defaultMapper;
123 
124  //##Documentation
125  //## @brief Do the rendering and flush the result.
126  virtual void Paint();
127 
128  //##Documentation
129  //## @brief Initialize the RenderWindow. Should only be called from RenderWindow.
130  virtual void Initialize();
131 
132  //##Documentation
133  //## @brief Called to inform the renderer that the RenderWindow has been resized.
134  virtual void Resize(int w, int h);
135 
136  //##Documentation
137  //## @brief Initialize the renderer with a RenderWindow (@a renderwindow).
138  virtual void InitRenderer(vtkRenderWindow *renderwindow);
139 
140  //##Documentation
141  //## @brief Set the initial size. Called by RenderWindow after it has become
142  //## visible for the first time.
143  virtual void InitSize(int w, int h);
144 
145  //##Documentation
146  //## @brief Draws a point on the widget.
147  //## Should be used during conferences to show the position of the remote mouse
148  virtual void DrawOverlayMouse(Point2D &p2d);
149 
150  //##Documentation
151  //## @brief Set/Get the WorldGeometry (m_WorldGeometry) for 3D and 2D rendering, that describing the
152  //## (maximal) area to be rendered.
153  //##
154  //## Depending of the type of the passed BaseGeometry more or less information can be extracted:
155  //## \li if it is a PlaneGeometry (which is a sub-class of BaseGeometry), m_CurrentWorldPlaneGeometry is
156  //## also set to point to it. m_WorldTimeGeometry is set to nullptr.
157  //## \li if it is a TimeGeometry, m_WorldTimeGeometry is also set to point to it.
158  //## If m_WorldTimeGeometry contains instances of SlicedGeometry3D, m_CurrentWorldPlaneGeometry is set to
159  //## one of geometries stored in the SlicedGeometry3D according to the value of m_Slice; otherwise
160  //## a PlaneGeometry describing the top of the bounding-box of the BaseGeometry is set as the
161  //## m_CurrentWorldPlaneGeometry.
162  //## \li otherwise a PlaneGeometry describing the top of the bounding-box of the BaseGeometry
163  //## is set as the m_CurrentWorldPlaneGeometry. m_WorldTimeGeometry is set to nullptr.
164  //## @todo add calculation of PlaneGeometry describing the top of the bounding-box of the BaseGeometry
165  //## when the passed BaseGeometry is not sliced.
166  //## \sa m_WorldGeometry
167  //## \sa m_WorldTimeGeometry
168  //## \sa m_CurrentWorldPlaneGeometry
169  virtual void SetWorldGeometry3D(const BaseGeometry *geometry);
170  virtual void SetWorldTimeGeometry(const mitk::TimeGeometry *geometry);
171 
176  DEPRECATED(void SetWorldGeometry3D(TimeSlicedGeometry *geometry));
177 
178  itkGetConstObjectMacro(WorldTimeGeometry, TimeGeometry)
179 
180  //##Documentation
181  //## @brief Get the current 3D-worldgeometry (m_CurrentWorldGeometry) used for 3D-rendering
182  itkGetConstObjectMacro(CurrentWorldGeometry, BaseGeometry)
183 
184  //##Documentation
185  //## @brief Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering
186  itkGetConstObjectMacro(CurrentWorldPlaneGeometry, PlaneGeometry)
190  DEPRECATED(const PlaneGeometry *GetCurrentWorldGeometry2D())
191  {
192  return GetCurrentWorldPlaneGeometry();
193  };
194 
195  //##Documentation
196  //## Calculates the bounds of the DataStorage (if it contains any valid data),
197  //## creates a geometry from these bounds and sets it as world geometry of the renderer.
198  //##
199  //## Call this method to re-initialize the renderer to the current DataStorage
200  //## (e.g. after loading an additional dataset), to ensure that the view is
201  //## aligned correctly.
202  //## \warn This is not implemented yet.
203  virtual bool SetWorldGeometryToDataStorageBounds() { return false; }
204  //##Documentation
205  //## @brief Set/Get m_Slice which defines together with m_TimeStep the 2D geometry
206  //## stored in m_WorldTimeGeometry used as m_CurrentWorldPlaneGeometry
207  //##
208  //## \sa m_Slice
209  virtual void SetSlice(unsigned int slice);
210 
211  itkGetConstMacro(Slice, unsigned int)
212 
213  //##Documentation
214  //## @brief Set/Get m_TimeStep which defines together with m_Slice the 2D geometry
215  //## stored in m_WorldTimeGeometry used as m_CurrentWorldPlaneGeometry
216  //##
217  //## \sa m_TimeStep
218  virtual void SetTimeStep(unsigned int timeStep);
219 
220  itkGetConstMacro(TimeStep, unsigned int)
221 
222  //##Documentation
223  //## @brief Get the time-step of a BaseData object which
224  //## exists at the time of the currently displayed content
225  //##
226  //## Returns -1 or mitk::BaseData::m_TimeSteps if there
227  //## is no data at the current time.
228  //## \sa GetTimeStep, m_TimeStep
229  int GetTimeStep(const BaseData *data) const;
230 
231  //##Documentation
232  //## @brief Get the time in ms of the currently displayed content
233  //##
234  //## \sa GetTimeStep, m_TimeStep
235  ScalarType GetTime() const;
236 
237  //##Documentation
238  //## @brief SetWorldGeometry is called according to the geometrySliceEvent,
239  //## which is supposed to be a SliceNavigationController::GeometrySendEvent
240  virtual void SetGeometry(const itk::EventObject &geometrySliceEvent);
241 
242  //##Documentation
243  //## @brief UpdateWorldGeometry is called to re-read the 2D geometry from the
244  //## slice navigation controller
245  virtual void UpdateGeometry(const itk::EventObject &geometrySliceEvent);
246 
247  //##Documentation
248  //## @brief SetSlice is called according to the geometrySliceEvent,
249  //## which is supposed to be a SliceNavigationController::GeometrySliceEvent
250  virtual void SetGeometrySlice(const itk::EventObject &geometrySliceEvent);
251 
252  //##Documentation
253  //## @brief SetTimeStep is called according to the geometrySliceEvent,
254  //## which is supposed to be a SliceNavigationController::GeometryTimeEvent
255  virtual void SetGeometryTime(const itk::EventObject &geometryTimeEvent);
256 
257  //##Documentation
258  //## @brief Get a DataNode pointing to a data object containing the current 2D-worldgeometry
259  // m_CurrentWorldPlaneGeometry (for 2D rendering)
260  itkGetObjectMacro(CurrentWorldPlaneGeometryNode, DataNode)
264  DEPRECATED(DataNode *GetCurrentWorldGeometry2DNode())
265  {
266  return GetCurrentWorldPlaneGeometryNode();
267  };
268 
269  //##Documentation
270  //## @brief Sets timestamp of CurrentWorldPlaneGeometry and forces so reslicing in that renderwindow
271  void SendUpdateSlice();
272 
273  //##Documentation
274  //## @brief Get timestamp of last call of SetCurrentWorldPlaneGeometry
275  unsigned long GetCurrentWorldPlaneGeometryUpdateTime() { return m_CurrentWorldPlaneGeometryUpdateTime; }
280  {
281  return GetCurrentWorldPlaneGeometryUpdateTime();
282  };
283  //##Documentation
284  //## @brief Get timestamp of last change of current TimeStep
285  unsigned long GetTimeStepUpdateTime() { return m_TimeStepUpdateTime; }
286  //##Documentation
287  //## @brief Perform a picking: find the x,y,z world coordinate of a
288  //## display x,y coordinate.
289  //## @warning Has to be overwritten in subclasses for the 3D-case.
290  //##
291  //## Implemented here only for 2D-rendering
292  virtual void PickWorldPoint(const Point2D &diplayPosition, Point3D &worldPosition) const = 0;
293 
299  virtual DataNode *PickObject(const Point2D & /*displayPosition*/, Point3D & /*worldPosition*/) const
300  {
301  return nullptr;
302  }
303 
304  //##Documentation
305  //## @brief Get the MapperSlotId to use.
306  itkGetMacro(MapperID, MapperSlotId) itkGetConstMacro(MapperID, MapperSlotId)
307 
308  //##Documentation
309  //## @brief Set the MapperSlotId to use.
310  itkSetMacro(MapperID, MapperSlotId)
311 
312  virtual int *GetSize() const;
313  virtual int *GetViewportSize() const;
314 
315  void SetSliceNavigationController(SliceNavigationController *SlicenavigationController);
316  itkGetObjectMacro(CameraController, CameraController)
319 
320  itkGetMacro(EmptyWorldGeometry, bool)
321 
322  //##Documentation
323  //## @brief Tells if the displayed region is shifted and rescaled if the render window is resized.
324  itkGetMacro(KeepDisplayedRegion, bool)
325  //##Documentation
326  //## @brief Tells if the displayed region should be shifted and rescaled if the render window is resized.
327  itkSetMacro(KeepDisplayedRegion, bool)
328 
329  //##Documentation
330  //## @brief get the name of the Renderer
331  //## @note
332  const char *GetName() const
333  {
334  return m_Name.c_str();
335  }
336 
337  //##Documentation
338  //## @brief get the x_size of the RendererWindow
339  //## @note
340  int GetSizeX() const { return GetSize()[0]; }
341  //##Documentation
342  //## @brief get the y_size of the RendererWindow
343  //## @note
344  int GetSizeY() const { return GetSize()[1]; }
345  const double *GetBounds() const;
346 
347  void RequestUpdate();
348  void ForceImmediateUpdate();
349 
352  unsigned int GetNumberOfVisibleLODEnabledMappers() const;
353 
354  //##Documentation
355  //## @brief This method converts a display point to the 3D world index
356  //## using the geometry of the renderWindow.
357  void DisplayToWorld(const Point2D &displayPoint, Point3D &worldIndex) const;
358 
359  //##Documentation
360  //## @brief This method converts a display point to the 2D world index, mapped onto the display plane
361  //## using the geometry of the renderWindow.
362  void DisplayToPlane(const Point2D &displayPoint, Point2D &planePointInMM) const;
363 
364  //##Documentation
365  //## @brief This method converts a 3D world index to the display point
366  //## using the geometry of the renderWindow.
367  void WorldToDisplay(const Point3D &worldIndex, Point2D &displayPoint) const;
368 
369  //##Documentation
370  //## @brief This method converts a 3D world index to the point on the viewport
371  //## using the geometry of the renderWindow.
372  void WorldToView(const Point3D &worldIndex, Point2D &viewPoint) const;
373 
374  //##Documentation
375  //## @brief This method converts a 2D plane coordinate to the display point
376  //## using the geometry of the renderWindow.
377  void PlaneToDisplay(const Point2D &planePointInMM, Point2D &displayPoint) const;
378 
379  //##Documentation
380  //## @brief This method converts a 2D plane coordinate to the point on the viewport
381  //## using the geometry of the renderWindow.
382  void PlaneToView(const Point2D &planePointInMM, Point2D &viewPoint) const;
383 
384 
385  double GetScaleFactorMMPerDisplayUnit() const;
386 
387  Point2D GetDisplaySizeInMM() const;
388  Point2D GetViewportSizeInMM() const;
389 
390  Point2D GetOriginInMM() const;
391 
392  itkGetConstMacro(ConstrainZoomingAndPanning, bool) virtual void SetConstrainZoomingAndPanning(bool constrain);
393 
399  DEPRECATED(virtual Point3D Map2DRendererPositionTo3DWorldPosition(const Point2D &mousePosition) const);
400 
401  protected:
402  ~BaseRenderer() override;
403 
404  //##Documentation
405  //## @brief Call update of all mappers. To be implemented in subclasses.
406  virtual void Update() = 0;
407 
408  vtkRenderWindow *m_RenderWindow;
409  vtkRenderer *m_VtkRenderer;
410 
411  //##Documentation
412  //## @brief MapperSlotId to use. Defines which kind of mapper (e.g., 2D or 3D) shoud be used.
413  MapperSlotId m_MapperID;
414 
415  //##Documentation
416  //## @brief The DataStorage that is used for rendering.
418 
419  //##Documentation
420  //## @brief Timestamp of last call of Update().
421  unsigned long m_LastUpdateTime;
422 
423  //##Documentation
424  //## @brief CameraController for 3D rendering
425  //## @note preliminary.
429 
430  //##Documentation
431  //## @brief Sets m_CurrentWorldPlaneGeometry
432  virtual void SetCurrentWorldPlaneGeometry(const PlaneGeometry *geometry2d);
436  DEPRECATED(void SetCurrentWorldGeometry2D(PlaneGeometry *geometry2d)) { SetCurrentWorldPlaneGeometry(geometry2d); };
437  //##Documentation
438  //## @brief Sets m_CurrentWorldGeometry
439  virtual void SetCurrentWorldGeometry(const BaseGeometry *geometry);
440 
441  private:
442  //##Documentation
443  //## m_WorldTimeGeometry is set by SetWorldGeometry if the passed BaseGeometry is a
444  //## TimeGeometry (or a sub-class of it). If it contains instances of SlicedGeometry3D,
445  //## m_Slice and m_TimeStep (set via SetSlice and SetTimeStep, respectively) define
446  //## which 2D geometry stored in m_WorldTimeGeometry (if available)
447  //## is used as m_CurrentWorldPlaneGeometry.
448  //## \sa m_CurrentWorldPlaneGeometry
449  TimeGeometry::ConstPointer m_WorldTimeGeometry;
450 
451  //##Documentation
452  //## Pointer to the current 3D-worldgeometry.
453  BaseGeometry::ConstPointer m_CurrentWorldGeometry;
454 
455  //##Documentation
456  //## Pointer to the current 2D-worldgeometry. The 2D-worldgeometry
457  //## describes the maximal area (2D manifold) to be rendered in case we
458  //## are doing 2D-rendering.
459  //## It is const, since we are not allowed to change it (it may be taken
460  //## directly from the geometry of an image-slice and thus it would be
461  //## very strange when suddenly the image-slice changes its geometry).
462  PlaneGeometry::Pointer m_CurrentWorldPlaneGeometry;
463 
464  //##Documentation
465  //## Defines together with m_Slice which 2D geometry stored in m_WorldTimeGeometry
466  //## is used as m_CurrentWorldPlaneGeometry: m_WorldTimeGeometry->GetPlaneGeometry(m_Slice, m_TimeStep).
467  //## \sa m_WorldTimeGeometry
468  unsigned int m_Slice;
469  //##Documentation
470  //## Defines together with m_TimeStep which 2D geometry stored in m_WorldTimeGeometry
471  //## is used as m_CurrentWorldPlaneGeometry: m_WorldTimeGeometry->GetPlaneGeometry(m_Slice, m_TimeStep).
472  //## \sa m_WorldTimeGeometry
473  unsigned int m_TimeStep;
474 
475  //##Documentation
476  //## @brief timestamp of last call of SetWorldGeometry
477  itk::TimeStamp m_CurrentWorldPlaneGeometryUpdateTime;
478 
479  //##Documentation
480  //## @brief timestamp of last change of the current time step
481  itk::TimeStamp m_TimeStepUpdateTime;
482 
483  //##Documentation
484  //## @brief Helper class which establishes connection between Interactors and Dispatcher via a common DataStorage.
485  BindDispatcherInteractor *m_BindDispatcherInteractor;
486 
487  //##Documentation
488  //## @brief Tells if the displayed region should be shifted or rescaled if the render window is resized.
489  bool m_KeepDisplayedRegion;
490 
491  protected:
492  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
493 
494  //##Documentation
495  //## Data object containing the m_CurrentWorldPlaneGeometry defined above.
497 
498  //##Documentation
499  //## DataNode objects containing the m_CurrentWorldPlaneGeometryData defined above.
501 
502  //##Documentation
503  //## @brief test only
505 
506  std::string m_Name;
507 
508  double m_Bounds[6];
509 
511 
512  typedef std::set<Mapper *> LODEnabledMappersType;
513 
517 
518  // Local Storage Handling for mappers
519 
520  protected:
521  std::list<mitk::BaseLocalStorageHandler *> m_RegisteredLocalStorageHandlers;
522 
524 
525  public:
526  void RemoveAllLocalStorages();
527  void RegisterLocalStorageHandler(mitk::BaseLocalStorageHandler *lsh);
528  void UnregisterLocalStorageHandler(mitk::BaseLocalStorageHandler *lsh);
529  };
530 } // namespace mitk
531 
532 #endif /* BASERENDERER_H_HEADER_INCLUDED_C1CCA0F4 */
std::map< vtkRenderWindow *, BaseRenderer * > BaseRendererMapType
PlaneGeometryData::Pointer m_CurrentWorldPlaneGeometryData
Data management class that handles &#39;was created by&#39; relations.
This Class is used to connect a DataStorage with the Dispatcher.
#define MITKCORE_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:37
vtkRenderer * GetVtkRenderer() const
virtual bool SetWorldGeometryToDataStorageBounds()
double ScalarType
Organizes the rendering process.
std::set< Mapper * > LODEnabledMappersType
static void Update(vtkPolyData *)
Definition: mitkSurface.cpp:31
std::list< mitk::BaseLocalStorageHandler * > m_RegisteredLocalStorageHandlers
DataCollection - Class to facilitate loading/accessing structured data.
unsigned long GetCurrentWorldGeometry2DUpdateTime()
Interface for accessing (templated) LocalStorageHandler instances.
static const MapperSlotId defaultMapper
Default mapper id to use.
CameraRotationController::Pointer m_CameraRotationController
unsigned long m_LastUpdateTime
Timestamp of last call of Update().
Controls the selection of the slice the associated BaseRenderer will display.
#define DEPRECATED(func)
Definition: mitkCommon.h:179
int GetSizeX() const
get the x_size of the RendererWindow
mitk::DataStorage::Pointer m_DataStorage
int MapperSlotId
MapperSlotId defines which kind of mapper (e.g. 2D or 3D) should be used.
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:49
static BaseRendererMapType baseRendererMap
unsigned long m_CurrentWorldPlaneGeometryTransformTime
test only
vtkRenderer * m_VtkRenderer
vtkRenderWindow * m_RenderWindow
void SetCurrentWorldGeometry2D(PlaneGeometry *geometry2d)
unsigned int m_NumberOfVisibleLODEnabledMappers
virtual DataNode * PickObject(const Point2D &, Point3D &) const
Determines the object (mitk::DataNode) closest to the current position by means of picking...
itkEventMacro(ContourModelEvent, itk::AnyEvent)
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
unsigned long GetTimeStepUpdateTime()
Get timestamp of last change of current TimeStep.
DataStorage::Pointer m_DataStorage
The DataStorage that is used for rendering.
static std::string GetName(std::string fileName, std::string suffix)
ViewDirection
Possible view directions for render windows.
unsigned long GetCurrentWorldPlaneGeometryUpdateTime()
Get timestamp of last call of SetCurrentWorldPlaneGeometry.
Describes a two-dimensional, rectangular plane.
DataNode::Pointer m_CurrentWorldPlaneGeometryNode
itk::SmartPointer< CameraController > m_CameraController
CameraController for 3D rendering.
virtual DataStorage::Pointer GetDataStorage() const
MapperSlotId m_MapperID
MapperSlotId to use. Defines which kind of mapper (e.g., 2D or 3D) shoud be used. ...
SliceNavigationController::Pointer m_SliceNavigationController
BaseGeometry Describes the geometry of a data object.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
int GetSizeY() const
get the y_size of the RendererWindow
controls the camera used by the associated BaseRenderer