Medical Imaging Interaction Toolkit  2026.06.00
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 #ifdef __GNUC__
41 #pragma GCC visibility push(default)
42 #endif
43  itkEventMacroDeclaration(RendererResetEvent, itk::AnyEvent);
44 #ifdef __GNUC__
45 #pragma GCC visibility pop
46 #endif
47 
66  class MITKCORE_EXPORT BaseRenderer : public itk::Object
67  {
68  public:
69 
71  typedef std::map<vtkRenderWindow*, BaseRenderer*> BaseRendererMapType;
72 
75 
80  {
81  Standard2D = 1,
82  Standard3D = 2
83  };
84 
90  static BaseRenderer* GetInstance(vtkRenderWindow* renderWindow);
91 
100  static void AddInstance(vtkRenderWindow* renderWindow, BaseRenderer* baseRenderer);
101 
106  static void RemoveInstance(vtkRenderWindow* renderWindow);
107 
113  static BaseRenderer* GetByName(const std::string& name);
114 
120  static vtkRenderWindow* GetRenderWindowByName(const std::string& name);
121 
128 
134 
140 
142 
148  BaseRenderer(const char* name = nullptr, vtkRenderWindow* renderWindow = nullptr);
149 
154 
160 
166 
175  virtual void SetDataStorage(DataStorage* storage);
176 
181  virtual DataStorage::Pointer GetDataStorage() const
182  {
183  return m_DataStorage.GetPointer();
184  }
185 
190  vtkRenderWindow* GetRenderWindow() const
191  {
192  return m_RenderWindow;
193  }
194 
199  vtkRenderer* GetVtkRenderer() const
200  {
201  return m_VtkRenderer;
202  }
203 
207  Dispatcher::Pointer GetDispatcher() const;
208 
214  virtual void Resize(int w, int h);
215 
224  virtual void InitRenderer(vtkRenderWindow* renderwindow);
225 
231  virtual void InitSize(int w, int h);
232 
238  virtual void DrawOverlayMouse(Point2D&)
239  {
240  MITK_INFO << "BaseRenderer::DrawOverlayMouse() should be in concret implementation OpenGLRenderer." << std::endl;
241  }
242 
249  virtual void SetWorldTimeGeometry(const TimeGeometry* geometry);
250  itkGetConstObjectMacro(WorldTimeGeometry, TimeGeometry);
251 
264  virtual void SetInteractionReferenceGeometry(const TimeGeometry* geometry);
265 
269  itkGetConstObjectMacro(InteractionReferenceGeometry, TimeGeometry);
270 
276  itkGetMacro(ReferenceGeometryAligned, bool);
277 
281  itkGetConstObjectMacro(CurrentWorldGeometry, BaseGeometry);
282 
286  itkGetConstObjectMacro(CurrentWorldPlaneGeometry, PlaneGeometry);
287 
294  {
295  return false;
296  }
297 
305  virtual void SetSlice(unsigned int slice);
306 
307  itkGetConstMacro(Slice, unsigned int);
308 
316  virtual void SetTimeStep(unsigned int timeStep);
317 
318  itkGetConstMacro(TimeStep, unsigned int);
319 
326  TimeStepType GetTimeStep(const BaseData* data) const;
327 
332 
338  virtual void SetGeometry(const itk::EventObject& geometrySliceEvent);
339 
345  virtual void UpdateGeometry(const itk::EventObject& geometrySliceEvent);
346 
353  virtual void SetGeometrySlice(const itk::EventObject& geometrySliceEvent);
354 
361  virtual void SetGeometryTime(const itk::EventObject& geometryTimeEvent);
362 
363  itkGetObjectMacro(CurrentWorldPlaneGeometryNode, DataNode);
364 
369 
373  itkGetMacro(CurrentWorldPlaneGeometryUpdateTime, unsigned long);
374 
378  itkGetMacro(TimeStepUpdateTime, unsigned long);
379 
385  virtual void PickWorldPoint(const Point2D& diplayPosition, Point3D& worldPosition) const = 0;
386 
394  virtual DataNode* PickObject(const Point2D& /*displayPosition*/, Point3D& /*worldPosition*/) const
395  {
396  return nullptr;
397  }
398 
402  itkGetMacro(MapperID, MapperSlotId);
403  itkGetConstMacro(MapperID, MapperSlotId);
404 
408  virtual void SetMapperID(MapperSlotId id);
409 
414  virtual int* GetSize() const;
415 
421  virtual int* GetViewportSize() const;
422 
431  void SetSliceNavigationController(SliceNavigationController* SlicenavigationController);
432 
434  itkGetObjectMacro(CameraController, CameraController);
435 
438 
441 
443  itkGetMacro(EmptyWorldGeometry, bool);
444 
449  itkGetMacro(KeepDisplayedRegion, bool);
450  itkSetMacro(KeepDisplayedRegion, bool);
451 
455  const char* GetName() const
456  {
457  return m_Name.c_str();
458  }
459 
463  int GetSizeX() const
464  {
465  return this->GetSize()[0];
466  }
467 
471  int GetSizeY() const
472  {
473  return this->GetSize()[1];
474  }
475 
482  const double* GetBounds() const;
483 
490 
495 
501 
511  void DisplayToWorld(const Point2D& displayPoint, Point3D& worldIndex) const;
512 
521  void DisplayToPlane(const Point2D& displayPoint, Point2D& planePointInMM) const;
522 
528  void WorldToDisplay(const Point3D& worldIndex, Point2D& displayPoint) const;
529 
538  void WorldToView(const Point3D& worldIndex, Point2D& viewPoint) const;
539 
545  void PlaneToDisplay(const Point2D& planePointInMM, Point2D& displayPoint) const;
546 
552  void PlaneToView(const Point2D& planePointInMM, Point2D& viewPoint) const;
553 
563 
569 
575 
581 
583  itkGetConstMacro(ConstrainZoomingAndPanning, bool)
584 
585 
592  virtual void SetConstrainZoomingAndPanning(bool constrain);
593 
594  protected:
595 
596  ~BaseRenderer() override;
597 
598  virtual void Update() = 0;
599 
600  vtkRenderWindow* m_RenderWindow;
601  vtkRenderer* m_VtkRenderer;
602 
603  MapperSlotId m_MapperID;
604  DataStorage::Pointer m_DataStorage;
605  unsigned long m_LastUpdateTime;
606 
607  CameraController::Pointer m_CameraController;
608  CameraRotationController::Pointer m_CameraRotationController;
609  SliceNavigationController::Pointer m_SliceNavigationController;
610 
611  void UpdateCurrentGeometries();
612  virtual void SetCurrentWorldPlaneGeometry(const PlaneGeometry* geometry2d);
613  virtual void SetCurrentWorldGeometry(const BaseGeometry *geometry);
614 
615  private:
616 
626  TimeGeometry::ConstPointer m_WorldTimeGeometry;
627 
635  TimeGeometry::ConstPointer m_InteractionReferenceGeometry;
636 
644  BaseGeometry::ConstPointer m_CurrentWorldGeometry;
645 
653  PlaneGeometry::Pointer m_CurrentWorldPlaneGeometry;
654 
655  unsigned int m_Slice;
656  unsigned int m_TimeStep;
657 
658  itk::TimeStamp m_CurrentWorldPlaneGeometryUpdateTime;
659  itk::TimeStamp m_TimeStepUpdateTime;
660 
661  BindDispatcherInteractor* m_BindDispatcherInteractor;
662 
663  bool m_KeepDisplayedRegion;
664  bool m_ReferenceGeometryAligned;
665 
666  protected:
667 
668  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
669 
670  PlaneGeometryData::Pointer m_CurrentWorldPlaneGeometryData;
671  DataNode::Pointer m_CurrentWorldPlaneGeometryNode;
672  unsigned long m_CurrentWorldPlaneGeometryTransformTime;
673 
674  std::string m_Name;
675 
676  double m_Bounds[6];
677 
678  bool m_EmptyWorldGeometry;
679 
680  typedef std::set<Mapper*> LODEnabledMappersType;
681 
682  unsigned int m_NumberOfVisibleLODEnabledMappers;
683 
684  std::list<BaseLocalStorageHandler*> m_RegisteredLocalStorageHandlers;
685 
686  bool m_ConstrainZoomingAndPanning;
687  };
688 } // namespace mitk
689 
690 #endif
#define MITKCORE_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
Abstract base class describing the geometry of a data object.
Interface for accessing (templated) LocalStorageHandler instances.
Organizes the rendering process.
void PlaneToDisplay(const Point2D &planePointInMM, Point2D &displayPoint) const
Convert a 2D plane coordinate in millimeters to a 2D display point.
static BaseRendererMapType GetAll2DRenderWindows()
Convenience function: Get a map of all 2D RenderWindows.
static BaseRendererMapType baseRendererMap
Static map holding all registered BaseRenderer instances, keyed by their vtkRenderWindow.
static void AddInstance(vtkRenderWindow *renderWindow, BaseRenderer *baseRenderer)
Register a BaseRenderer instance for the given vtkRenderWindow.
std::map< vtkRenderWindow *, BaseRenderer * > BaseRendererMapType
Map type associating vtkRenderWindow pointers with BaseRenderer pointers.
virtual void SetDataStorage(DataStorage *storage)
Set the DataStorage used by this renderer.
void RemoveAllLocalStorages()
Remove all registered local storages and notify observers via RendererResetEvent.
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)
Replace the current SliceNavigationController.
void UnregisterLocalStorageHandler(BaseLocalStorageHandler *lsh)
Unregister a previously registered local storage handler.
void DisplayToPlane(const Point2D &displayPoint, Point2D &planePointInMM) const
Convert a display point to a 2D plane coordinate in millimeters.
virtual void SetSlice(unsigned int slice)
Set the slice that should be used for geometry extraction.
vtkRenderer * GetVtkRenderer() const
Get the underlying vtkRenderer used for VTK rendering.
BaseRenderer(const char *name=nullptr, vtkRenderWindow *renderWindow=nullptr)
Construct a BaseRenderer with an optional name and vtkRenderWindow.
const char * GetName() const
Return the name of the base renderer.
virtual DataStorage::Pointer GetDataStorage() const
Get the DataStorage used by this renderer.
void WorldToDisplay(const Point3D &worldIndex, Point2D &displayPoint) const
Convert a 3D world coordinate to a 2D display point.
void WorldToView(const Point3D &worldIndex, Point2D &viewPoint) const
Convert a 3D world coordinate to a 2D viewport point.
static BaseRenderer * GetByName(const std::string &name)
Find a BaseRenderer by its name.
virtual bool SetWorldGeometryToDataStorageBounds()
Set the world geometry so that it encompasses all objects in the DataStorage.
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.
void SendUpdateSlice()
Modify the update time of the current world plane geometry and force reslicing.
Point2D GetOriginInMM() const
Get the origin of the viewport in plane coordinates (millimeters).
static BaseRenderer * GetInstance(vtkRenderWindow *renderWindow)
Get the BaseRenderer instance associated with the given vtkRenderWindow.
Point2D GetDisplaySizeInMM() const
Get the size of the render window in millimeters.
vtkRenderWindow * GetRenderWindow() const
Get the vtkRenderWindow associated with this renderer.
virtual void SetTimeStep(unsigned int timeStep)
Set the timestep that should be used for geometry extraction.
static void RemoveInstance(vtkRenderWindow *renderWindow)
Remove the BaseRenderer registration for the given vtkRenderWindow.
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
Get the scale factor relating millimeters to display pixels.
void PlaneToView(const Point2D &planePointInMM, Point2D &viewPoint) const
Convert a 2D plane coordinate in millimeters to a 2D viewport point.
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()
Force an immediate synchronous rendering update for this render window.
virtual int * GetViewportSize() const
Get the size of the VTK viewport in pixels.
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
Get the size of the VTK viewport in millimeters.
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
Get the size of the render window in pixels.
mitkClassMacroItkParent(BaseRenderer, itk::Object)
virtual void DrawOverlayMouse(Point2D &)
Draw an overlay mouse cursor at the given position.
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)
Register a local storage handler with this renderer.
void DisplayToWorld(const Point2D &displayPoint, Point3D &worldIndex) const
Convert a display point to a 3D world coordinate.
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)
Find a vtkRenderWindow by the name of its associated BaseRenderer.
static BaseRendererMapType GetSpecificRenderWindows(MapperSlotId mapper)
Get a map of all BaseRenderers that use the specified mapper type.
virtual void SetInteractionReferenceGeometry(const TimeGeometry *geometry)
Set the interaction reference world time geometry using the given TimeGeometry.
void RequestUpdate()
Request an asynchronous rendering update for this render window via the RenderingManager.
Connects a DataStorage with a Dispatcher for interaction event routing.
Controls the camera used by the associated BaseRenderer.
Controls azimuthal camera rotation driven by a Stepper.
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
Abstract data management class that organizes DataNode objects in a directed acyclic graph.
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:56
Data class containing PlaneGeometry objects.
Describes the geometry of a plane object.
Controls the selection of the slice the associated BaseRenderer will display.
unsigned int MapperSlotId
Definition: mitkCommon.h:23
#define MITK_INFO
Log an informational message.
Definition: mitkLog.h:358
Find image slices visible on a given plane.
std::size_t TimeStepType
Type for time step indices (non-negative integers starting from 0).
double ScalarType
Scalar type used throughout MITK for geometric computations.
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)