Medical Imaging Interaction Toolkit  2025.12.02
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 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 
83 
88 
93 
95 
96  BaseRenderer(const char* name = nullptr, vtkRenderWindow* renderWindow = nullptr);
97 
101 
102  virtual void SetDataStorage(DataStorage* storage);
103 
104  virtual DataStorage::Pointer GetDataStorage() const
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 
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 
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 
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 
357 
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 
401 
404 
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 
419  MapperSlotId m_MapperID;
420  DataStorage::Pointer m_DataStorage;
421  unsigned long m_LastUpdateTime;
422 
423  CameraController::Pointer m_CameraController;
424  CameraRotationController::Pointer m_CameraRotationController;
425  SliceNavigationController::Pointer m_SliceNavigationController;
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 
486  PlaneGeometryData::Pointer m_CurrentWorldPlaneGeometryData;
487  DataNode::Pointer m_CurrentWorldPlaneGeometryNode;
488  unsigned long m_CurrentWorldPlaneGeometryTransformTime;
489 
490  std::string m_Name;
491 
492  double m_Bounds[6];
493 
494  bool m_EmptyWorldGeometry;
495 
496  typedef std::set<Mapper*> LODEnabledMappersType;
497 
498  unsigned int m_NumberOfVisibleLODEnabledMappers;
499 
500  std::list<BaseLocalStorageHandler*> m_RegisteredLocalStorageHandlers;
501 
502  bool m_ConstrainZoomingAndPanning;
503  };
504 } // namespace mitk
505 
506 #endif
#define MITKCORE_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
BaseGeometry Describes the geometry of a data object.
Interface for accessing (templated) LocalStorageHandler instances.
void PlaneToDisplay(const Point2D &planePointInMM, Point2D &displayPoint) const
Convert a 2D plane coordinate to the display point using the geometry of the renderWindow.
static BaseRendererMapType GetAll2DRenderWindows()
Convenience function: Get a map of all 2D RenderWindows.
static BaseRendererMapType baseRendererMap
static void AddInstance(vtkRenderWindow *renderWindow, BaseRenderer *baseRenderer)
std::map< vtkRenderWindow *, BaseRenderer * > BaseRendererMapType
virtual void SetDataStorage(DataStorage *storage)
void RemoveAllLocalStorages()
virtual void PickWorldPoint(const Point2D &diplayPosition, Point3D &worldPosition) const =0
Pick a world coordinate (x,y,z) given a display coordinate (x,y).
Dispatcher::Pointer GetDispatcher() const
Get the dispatcher, which handles events for this base renderer.
void SetSliceNavigationController(SliceNavigationController *SlicenavigationController)
void UnregisterLocalStorageHandler(BaseLocalStorageHandler *lsh)
void DisplayToPlane(const Point2D &displayPoint, Point2D &planePointInMM) const
Convert a display point to the 2D world index, mapped onto the display plane using the geometry of th...
virtual void SetSlice(unsigned int slice)
Set the slice that should be used for geometry extraction.
vtkRenderer * GetVtkRenderer() const
BaseRenderer(const char *name=nullptr, vtkRenderWindow *renderWindow=nullptr)
const char * GetName() const
Return the name of the base renderer.
virtual DataStorage::Pointer GetDataStorage() const
void WorldToDisplay(const Point3D &worldIndex, Point2D &displayPoint) const
Convert a 3D world index to the display point using the geometry of the renderWindow.
void WorldToView(const Point3D &worldIndex, Point2D &viewPoint) const
Convert a 3D world index to the point on the viewport using the geometry of the renderWindow.
static BaseRenderer * GetByName(const std::string &name)
virtual bool SetWorldGeometryToDataStorageBounds()
virtual void SetGeometry(const itk::EventObject &geometrySliceEvent)
Set the world time geometry using the geometry of the given event.
virtual void InitRenderer(vtkRenderWindow *renderwindow)
Initialize the base renderer with a vtk render window. Set the new renderer for the camera controller...
void SendUpdateSlice()
Modify the update time of the current world plane geometry and force reslicing.
Point2D GetOriginInMM() const
static BaseRenderer * GetInstance(vtkRenderWindow *renderWindow)
Point2D GetDisplaySizeInMM() const
vtkRenderWindow * GetRenderWindow() const
virtual void SetTimeStep(unsigned int timeStep)
Set the timestep that should be used for geometry extraction.
static void RemoveInstance(vtkRenderWindow *renderWindow)
unsigned int GetNumberOfVisibleLODEnabledMappers() const
Return the number of mappers which are visible and have level-of-detail rendering enabled.
StandardMapperSlot
Defines which kind of mapper (e.g. 2D or 3D) should be used.
double GetScaleFactorMMPerDisplayUnit() const
void PlaneToView(const Point2D &planePointInMM, Point2D &viewPoint) const
Convert a 2D plane coordinate to the point on the viewport using the geometry of the renderWindow.
virtual DataNode * PickObject(const Point2D &, Point3D &) const
Determines the object (mitk::DataNode) closest to the current position by means of picking.
virtual void UpdateGeometry(const itk::EventObject &geometrySliceEvent)
Set the current world plane geometry using the existing current world geometry.
virtual void InitSize(int w, int h)
Set the initial size for the render window.
void ForceImmediateUpdate()
virtual int * GetViewportSize() const
const double * GetBounds() const
Return the bounds of the bounding box of the current world geometry (time-extracted 3D-geometry).
std::set< Mapper * > LODEnabledMappersType
Point2D GetViewportSizeInMM() const
virtual void SetMapperID(MapperSlotId id)
Set the used mapperID.
virtual void SetGeometryTime(const itk::EventObject &geometryTimeEvent)
Set the current time using "SetTimeStep" and update the current world geometry and the current world ...
static BaseRendererMapType GetAll3DRenderWindows()
Convenience function: Get a map of all 3D RenderWindows.
virtual void Resize(int w, int h)
Set a new size for the render window.
ScalarType GetTime() const
Get the time in ms of the currently display content (geometry).
virtual int * GetSize() const
mitkClassMacroItkParent(BaseRenderer, itk::Object)
virtual void DrawOverlayMouse(Point2D &)
virtual void SetGeometrySlice(const itk::EventObject &geometrySliceEvent)
Set the current slice using "SetSlice" and update the current world geometry and the current world pl...
TimeStepType GetTimeStep(const BaseData *data) const
Get the timestep of a BaseData object which exists at the time of the currently displayed content.
void RegisterLocalStorageHandler(BaseLocalStorageHandler *lsh)
void DisplayToWorld(const Point2D &displayPoint, Point3D &worldIndex) const
Convert a display point to the 3D world index using the geometry of the renderWindow.
virtual void SetWorldTimeGeometry(const TimeGeometry *geometry)
Set the world time geometry using the given TimeGeometry.
int GetSizeX() const
Return the size in x-direction of the base renderer.
int GetSizeY() const
Return the size in y-direction of the base renderer.
static vtkRenderWindow * GetRenderWindowByName(const std::string &name)
static BaseRendererMapType GetSpecificRenderWindows(MapperSlotId mapper)
Get a map of specific RenderWindows.
virtual void SetInteractionReferenceGeometry(const TimeGeometry *geometry)
Set the interaction reference world time geometry using the given TimeGeometry.
This Class is used to connect a DataStorage with the Dispatcher.
controls the camera used by the associated BaseRenderer
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Data management class that handles 'was created by' relations.
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:47
Data class containing PlaneGeometry objects.
Describes a two-dimensional, rectangular plane.
Controls the selection of the slice the associated BaseRenderer will display.
unsigned int MapperSlotId
Definition: mitkCommon.h:29
#define MITK_INFO
Definition: mitkLog.h:209
Find image slices visible on a given plane.
std::size_t TimeStepType
double ScalarType
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)