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