Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 mitkBaseRenderer_h
14 #define mitkBaseRenderer_h
15 
16 #include <mitkDataStorage.h>
17 #include <mitkPlaneGeometry.h>
18 #include <mitkPlaneGeometryData.h>
19 #include <mitkTimeGeometry.h>
20 
21 #include <mitkCameraController.h>
25 
27 #include <mitkDispatcher.h>
28 
29 #include <vtkRenderWindow.h>
30 #include <vtkRenderer.h>
31 
32 #include <map>
33 #include <set>
34 
35 namespace mitk
36 {
37  class Mapper;
38  class BaseLocalStorageHandler;
39 
40 #pragma GCC visibility push(default)
41  itkEventMacroDeclaration(RendererResetEvent, itk::AnyEvent);
42 #pragma GCC visibility pop
43 
44  /*
45  * \brief Organizes the rendering process
46  *
47  * A BaseRenderer contains a reference to a given vtkRenderWindow
48  * and a corresponding vtkRenderer.
49  * The BaseRenderer defines which mapper should be used (2D / 3D)
50  * and which view direction should be rendered.
51  *
52  * All existing BaseRenderer are stored in a static variable
53  * that can be accessed / modified via the static functions.
54  * VtkPropRenderer is a concrete implementation of a BaseRenderer.
55  */
56  class MITKCORE_EXPORT BaseRenderer : public itk::Object
57  {
58  public:
59 
60  typedef std::map<vtkRenderWindow*, BaseRenderer*> BaseRendererMapType;
62 
67  {
68  Standard2D = 1,
69  Standard3D = 2
70  };
71 
72  static BaseRenderer* GetInstance(vtkRenderWindow* renderWindow);
73  static void AddInstance(vtkRenderWindow* renderWindow, BaseRenderer* baseRenderer);
74  static void RemoveInstance(vtkRenderWindow* renderWindow);
75 
76  static BaseRenderer* GetByName(const std::string& name);
77  static vtkRenderWindow* GetRenderWindowByName(const std::string& name);
78 
82  static BaseRendererMapType GetSpecificRenderWindows(MapperSlotId mapper);
83 
87  static BaseRendererMapType GetAll2DRenderWindows();
88 
92  static BaseRendererMapType GetAll3DRenderWindows();
93 
95 
96  BaseRenderer(const char* name = nullptr, vtkRenderWindow* renderWindow = nullptr);
97 
98  void RemoveAllLocalStorages();
99  void RegisterLocalStorageHandler(BaseLocalStorageHandler* lsh);
100  void UnregisterLocalStorageHandler(BaseLocalStorageHandler* lsh);
101 
102  virtual void SetDataStorage(DataStorage* storage);
103 
105  {
106  return m_DataStorage.GetPointer();
107  }
108 
109  vtkRenderWindow* GetRenderWindow() const
110  {
111  return m_RenderWindow;
112  }
113 
114  vtkRenderer* GetVtkRenderer() const
115  {
116  return m_VtkRenderer;
117  }
118 
122  Dispatcher::Pointer GetDispatcher() const;
123 
127  virtual void Resize(int w, int h);
128 
133  virtual void InitRenderer(vtkRenderWindow* renderwindow);
134 
138  virtual void InitSize(int w, int h);
139 
140  virtual void DrawOverlayMouse(Point2D&)
141  {
142  MITK_INFO << "BaseRenderer::DrawOverlayMouse() should be in concret implementation OpenGLRenderer." << std::endl;
143  }
144 
151  virtual void SetWorldTimeGeometry(const TimeGeometry* geometry);
152  itkGetConstObjectMacro(WorldTimeGeometry, TimeGeometry);
153 
166  virtual void SetInteractionReferenceGeometry(const TimeGeometry* geometry);
167 
171  itkGetConstObjectMacro(InteractionReferenceGeometry, TimeGeometry);
172 
178  itkGetMacro(ReferenceGeometryAligned, bool);
179 
183  itkGetConstObjectMacro(CurrentWorldGeometry, BaseGeometry);
184 
188  itkGetConstObjectMacro(CurrentWorldPlaneGeometry, PlaneGeometry);
189 
191  {
192  return false;
193  }
194 
202  virtual void SetSlice(unsigned int slice);
203 
204  itkGetConstMacro(Slice, unsigned int);
205 
213  virtual void SetTimeStep(unsigned int timeStep);
214 
215  itkGetConstMacro(TimeStep, unsigned int);
216 
223  TimeStepType GetTimeStep(const BaseData* data) const;
224 
228  ScalarType GetTime() const;
229 
235  virtual void SetGeometry(const itk::EventObject& geometrySliceEvent);
236 
242  virtual void UpdateGeometry(const itk::EventObject& geometrySliceEvent);
243 
250  virtual void SetGeometrySlice(const itk::EventObject& geometrySliceEvent);
251 
258  virtual void SetGeometryTime(const itk::EventObject& geometryTimeEvent);
259 
260  itkGetObjectMacro(CurrentWorldPlaneGeometryNode, DataNode);
261 
265  void SendUpdateSlice();
266 
270  itkGetMacro(CurrentWorldPlaneGeometryUpdateTime, unsigned long);
271 
275  itkGetMacro(TimeStepUpdateTime, unsigned long);
276 
282  virtual void PickWorldPoint(const Point2D& diplayPosition, Point3D& worldPosition) const = 0;
283 
291  virtual DataNode* PickObject(const Point2D& /*displayPosition*/, Point3D& /*worldPosition*/) const
292  {
293  return nullptr;
294  }
295 
299  itkGetMacro(MapperID, MapperSlotId);
300  itkGetConstMacro(MapperID, MapperSlotId);
301 
305  virtual void SetMapperID(MapperSlotId id);
306 
307  virtual int* GetSize() const;
308  virtual int* GetViewportSize() const;
309 
310  void SetSliceNavigationController(SliceNavigationController* SlicenavigationController);
311  itkGetObjectMacro(CameraController, CameraController);
314  itkGetMacro(EmptyWorldGeometry, bool);
315 
320  itkGetMacro(KeepDisplayedRegion, bool);
321  itkSetMacro(KeepDisplayedRegion, bool);
322 
326  const char* GetName() const
327  {
328  return m_Name.c_str();
329  }
330 
334  int GetSizeX() const
335  {
336  return this->GetSize()[0];
337  }
338 
342  int GetSizeY() const
343  {
344  return this->GetSize()[1];
345  }
346 
353  const double* GetBounds() const;
354 
355  void RequestUpdate();
356  void ForceImmediateUpdate();
357 
362  unsigned int GetNumberOfVisibleLODEnabledMappers() const;
363 
368  void DisplayToWorld(const Point2D& displayPoint, Point3D& worldIndex) const;
369 
374  void DisplayToPlane(const Point2D& displayPoint, Point2D& planePointInMM) const;
375 
380  void WorldToDisplay(const Point3D& worldIndex, Point2D& displayPoint) const;
381 
386  void WorldToView(const Point3D& worldIndex, Point2D& viewPoint) const;
387 
392  void PlaneToDisplay(const Point2D& planePointInMM, Point2D& displayPoint) const;
393 
398  void PlaneToView(const Point2D& planePointInMM, Point2D& viewPoint) const;
399 
400  double GetScaleFactorMMPerDisplayUnit() const;
401 
402  Point2D GetDisplaySizeInMM() const;
403  Point2D GetViewportSizeInMM() const;
404 
405  Point2D GetOriginInMM() const;
406 
407  itkGetConstMacro(ConstrainZoomingAndPanning, bool)
408  virtual void SetConstrainZoomingAndPanning(bool constrain);
409 
410  protected:
411 
412  ~BaseRenderer() override;
413 
414  virtual void Update() = 0;
415 
416  vtkRenderWindow* m_RenderWindow;
417  vtkRenderer* m_VtkRenderer;
418 
421  unsigned long m_LastUpdateTime;
422 
426 
427  void UpdateCurrentGeometries();
428  virtual void SetCurrentWorldPlaneGeometry(const PlaneGeometry* geometry2d);
429  virtual void SetCurrentWorldGeometry(const BaseGeometry *geometry);
430 
431  private:
432 
442  TimeGeometry::ConstPointer m_WorldTimeGeometry;
443 
451  TimeGeometry::ConstPointer m_InteractionReferenceGeometry;
452 
460  BaseGeometry::ConstPointer m_CurrentWorldGeometry;
461 
469  PlaneGeometry::Pointer m_CurrentWorldPlaneGeometry;
470 
471  unsigned int m_Slice;
472  unsigned int m_TimeStep;
473 
474  itk::TimeStamp m_CurrentWorldPlaneGeometryUpdateTime;
475  itk::TimeStamp m_TimeStepUpdateTime;
476 
477  BindDispatcherInteractor* m_BindDispatcherInteractor;
478 
479  bool m_KeepDisplayedRegion;
480  bool m_ReferenceGeometryAligned;
481 
482  protected:
483 
484  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
485 
489 
490  std::string m_Name;
491 
492  double m_Bounds[6];
493 
495 
496  typedef std::set<Mapper*> LODEnabledMappersType;
497 
499 
500  std::list<BaseLocalStorageHandler*> m_RegisteredLocalStorageHandlers;
501 
503  };
504 } // namespace mitk
505 
506 #endif
mitk::BaseRenderer::GetSizeY
int GetSizeY() const
Return the size in y-direction of the base renderer.
Definition: mitkBaseRenderer.h:342
mitk::BaseRenderer::m_CameraRotationController
CameraRotationController::Pointer m_CameraRotationController
Definition: mitkBaseRenderer.h:424
mitkDispatcher.h
mitk::TimeGeometry
Definition: mitkTimeGeometry.h:43
MITK_INFO
#define MITK_INFO
Definition: mitkLog.h:209
mitk::BaseRenderer::BaseRendererMapType
std::map< vtkRenderWindow *, BaseRenderer * > BaseRendererMapType
Definition: mitkBaseRenderer.h:60
mitk::BaseRenderer::SetWorldGeometryToDataStorageBounds
virtual bool SetWorldGeometryToDataStorageBounds()
Definition: mitkBaseRenderer.h:190
mitk::BaseRenderer::m_VtkRenderer
vtkRenderer * m_VtkRenderer
Definition: mitkBaseRenderer.h:417
mitk::PlaneGeometry
Describes a two-dimensional, rectangular plane.
Definition: mitkPlaneGeometry.h:78
mitkDataStorage.h
mitkPlaneGeometryData.h
mitk::BaseRenderer::LODEnabledMappersType
std::set< Mapper * > LODEnabledMappersType
Definition: mitkBaseRenderer.h:496
mitk::BaseRenderer::m_CameraController
CameraController::Pointer m_CameraController
Definition: mitkBaseRenderer.h:423
mitk::BaseRenderer::GetSizeX
int GetSizeX() const
Return the size in x-direction of the base renderer.
Definition: mitkBaseRenderer.h:334
mitk::BaseRenderer::GetRenderWindow
vtkRenderWindow * GetRenderWindow() const
Definition: mitkBaseRenderer.h:109
mitk::BaseRenderer::m_RenderWindow
vtkRenderWindow * m_RenderWindow
Definition: mitkBaseRenderer.h:416
itk::SmartPointer< Self >
mitkTimeGeometry.h
mitk::BaseRenderer::m_CurrentWorldPlaneGeometryData
PlaneGeometryData::Pointer m_CurrentWorldPlaneGeometryData
Definition: mitkBaseRenderer.h:486
mitkClassMacroItkParent
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:45
mitk::BaseRenderer::m_LastUpdateTime
unsigned long m_LastUpdateTime
Definition: mitkBaseRenderer.h:421
mitk::SliceNavigationController
Controls the selection of the slice the associated BaseRenderer will display.
Definition: mitkSliceNavigationController.h:130
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitkCameraController.h
mitk::BaseRenderer::StandardMapperSlot
StandardMapperSlot
Defines which kind of mapper (e.g. 2D or 3D) should be used.
Definition: mitkBaseRenderer.h:66
mitk::BaseLocalStorageHandler
Interface for accessing (templated) LocalStorageHandler instances.
Definition: mitkLocalStorageHandler.h:32
mitk::BaseRenderer::m_CurrentWorldPlaneGeometryNode
DataNode::Pointer m_CurrentWorldPlaneGeometryNode
Definition: mitkBaseRenderer.h:487
mitk::BaseRenderer::GetName
const char * GetName() const
Return the name of the base renderer.
Definition: mitkBaseRenderer.h:326
mitkCameraRotationController.h
mitk::BaseGeometry
BaseGeometry Describes the geometry of a data object.
Definition: mitkBaseGeometry.h:94
mitk::BaseRenderer::m_DataStorage
DataStorage::Pointer m_DataStorage
Definition: mitkBaseRenderer.h:420
mitk::BaseRenderer::GetVtkRenderer
vtkRenderer * GetVtkRenderer() const
Definition: mitkBaseRenderer.h:114
mitk::BaseRenderer::baseRendererMap
static BaseRendererMapType baseRendererMap
Definition: mitkBaseRenderer.h:61
mitk::Point< ScalarType, 2 >
mitk::BindDispatcherInteractor
This Class is used to connect a DataStorage with the Dispatcher.
Definition: mitkBindDispatcherInteractor.h:35
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitkBindDispatcherInteractor.h
mitk::BaseRenderer::m_ConstrainZoomingAndPanning
bool m_ConstrainZoomingAndPanning
Definition: mitkBaseRenderer.h:502
mitk::BaseRenderer::GetDataStorage
virtual DataStorage::Pointer GetDataStorage() const
Definition: mitkBaseRenderer.h:104
mitk::DataStorage
Data management class that handles 'was created by' relations.
Definition: mitkDataStorage.h:43
mitk::BaseRenderer::m_SliceNavigationController
SliceNavigationController::Pointer m_SliceNavigationController
Definition: mitkBaseRenderer.h:425
mitkTimeNavigationController.h
mitk::BaseRenderer::PickObject
virtual DataNode * PickObject(const Point2D &, Point3D &) const
Determines the object (mitk::DataNode) closest to the current position by means of picking.
Definition: mitkBaseRenderer.h:291
mitk::CameraRotationController
Definition: mitkCameraRotationController.h:24
mitk::TimeStepType
std::size_t TimeStepType
Definition: mitkTimeGeometry.h:27
mitk::CameraController
controls the camera used by the associated BaseRenderer
Definition: mitkCameraController.h:29
mitkSliceNavigationController.h
mitk::BaseRenderer::DrawOverlayMouse
virtual void DrawOverlayMouse(Point2D &)
Definition: mitkBaseRenderer.h:140
mitk::BaseRenderer
Definition: mitkBaseRenderer.h:56
MapperSlotId
unsigned int MapperSlotId
Definition: mitkCommon.h:29
mitk::BaseRenderer::m_NumberOfVisibleLODEnabledMappers
unsigned int m_NumberOfVisibleLODEnabledMappers
Definition: mitkBaseRenderer.h:498
mitk::BaseRenderer::m_MapperID
MapperSlotId m_MapperID
Definition: mitkBaseRenderer.h:419
mitk::BaseRenderer::m_EmptyWorldGeometry
bool m_EmptyWorldGeometry
Definition: mitkBaseRenderer.h:494
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63
mitk::BaseRenderer::m_RegisteredLocalStorageHandlers
std::list< BaseLocalStorageHandler * > m_RegisteredLocalStorageHandlers
Definition: mitkBaseRenderer.h:500
mitk::BaseRenderer::m_Name
std::string m_Name
Definition: mitkBaseRenderer.h:490
mitk::BaseRenderer::m_CurrentWorldPlaneGeometryTransformTime
unsigned long m_CurrentWorldPlaneGeometryTransformTime
Definition: mitkBaseRenderer.h:488
mitk::itkEventMacroDeclaration
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)
mitk::ScalarType
double ScalarType
Definition: mitkNumericConstants.h:20
mitkPlaneGeometry.h