Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkRenderingManager.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 mitkRenderingManager_h
14 #define mitkRenderingManager_h
15 
16 #include <MitkCoreExports.h>
17 
18 #include <vtkCallbackCommand.h>
19 
20 #include <itkObject.h>
21 #include <itkObjectFactory.h>
22 
23 #include <mitkProperties.h>
24 #include <mitkPropertyList.h>
25 #include <mitkTimeGeometry.h>
26 #include <mitkAntiAliasing.h>
27 
28 class vtkRenderWindow;
29 class vtkObject;
30 
31 namespace mitk
32 {
33  class RenderingManagerFactory;
34  class BaseGeometry;
35  class TimeNavigationController;
36  class BaseRenderer;
37  class DataStorage;
38 
74  class MITKCORE_EXPORT RenderingManager : public itk::Object
75  {
76  public:
78 
79  typedef std::vector<vtkRenderWindow *> RenderWindowVector;
80  typedef std::vector<float> FloatVector;
81  typedef std::vector<bool> BoolVector;
82 
84 
89  {
90  REQUEST_UPDATE_ALL = 0,
92  REQUEST_UPDATE_3DWINDOWS
93  };
94 
99  static Pointer New();
100 
105  static void SetFactory(RenderingManagerFactory *factory);
106 
112 
117  static bool HasFactory();
118 
127 
132  static bool IsInstantiated();
133 
142  void AddRenderWindow(vtkRenderWindow *renderWindow);
143 
148  void RemoveRenderWindow(vtkRenderWindow *renderWindow);
149 
155 
164  void RequestUpdate(vtkRenderWindow *renderWindow);
165 
170  void ForceImmediateUpdate(vtkRenderWindow *renderWindow);
171 
176  void RequestUpdateAll(RequestType type = REQUEST_UPDATE_ALL);
177 
182  void ForceImmediateUpdateAll(RequestType type = REQUEST_UPDATE_ALL);
183 
190  virtual void InitializeViewsByBoundingObjects(const DataStorage* dataStorage);
191 
204  virtual void InitializeViewByBoundingObjects(vtkRenderWindow* renderWindow,
205  const DataStorage* dataStorage,
206  bool resetCamera = true);
207 
227  virtual bool InitializeViews(const BaseGeometry *geometry,
228  RequestType type = REQUEST_UPDATE_ALL,
229  bool resetCamera = true);
230 
250  virtual bool InitializeViews(const TimeGeometry *geometry,
251  RequestType type = REQUEST_UPDATE_ALL,
252  bool resetCamera = true);
253 
266  virtual bool InitializeViews(RequestType type = REQUEST_UPDATE_ALL);
267 
281  virtual bool InitializeView(vtkRenderWindow *renderWindow,
282  const BaseGeometry *geometry,
283  bool resetCamera = true);
284 
298  virtual bool InitializeView(vtkRenderWindow *renderWindow,
299  const TimeGeometry *geometry,
300  bool resetCamera = true);
301 
308  virtual bool InitializeView(vtkRenderWindow *renderWindow);
309 
313 
317 
319  ~RenderingManager() override;
320 
327  virtual void ExecutePendingRequests();
328 
333  bool IsRendering() const;
334 
339 
341  itkSetMacro(LODIncreaseBlocked, bool);
343  itkGetMacro(LODIncreaseBlocked, bool);
345  itkBooleanMacro(LODIncreaseBlocked);
346 
348  itkSetMacro(LODAbortMechanismEnabled, bool);
350  itkGetMacro(LODAbortMechanismEnabled, bool);
352  itkBooleanMacro(LODAbortMechanismEnabled);
353 
355  virtual void StartOrResetTimer(){};
356 
359 
361  virtual void DoStartRendering(){};
363  virtual void DoMonitorRendering(){};
365  virtual void DoFinishAbortRendering(){};
366 
372  int GetNextLOD(BaseRenderer *renderer);
373 
378  void SetMaximumLOD(unsigned int max);
379 
385  void SetShading(bool state, unsigned int lod);
386 
392  bool GetShading(unsigned int lod);
393 
398  void SetClippingPlaneStatus(bool status);
399 
405 
413  void SetShadingValues(float ambient, float diffuse, float specular, float specpower);
414 
420 
425  PropertyList::Pointer GetPropertyList() const;
426 
432  BaseProperty *GetProperty(const char *propertyKey) const;
433 
439  void SetProperty(const char *propertyKey, BaseProperty *propertyValue);
440 
451  void SetDataStorage(DataStorage *storage);
452 
459  itkGetMacro(DataStorage, DataStorage*);
460  itkGetConstMacro(DataStorage, DataStorage*);
461 
466  void SetRenderWindowFocus(vtkRenderWindow *focusWindow);
467  itkGetMacro(FocusedRenderWindow, vtkRenderWindow *);
468 
469  void SetConstrainedPanningZooming(bool constrain);
470  itkGetConstMacro(ConstrainedPanningZooming, bool);
471 
472  void SetAntiAliasing(AntiAliasing antiAliasing);
473  itkGetConstMacro(AntiAliasing, AntiAliasing);
474 
475  protected:
476  enum
477  {
478  RENDERING_INACTIVE = 0,
480  RENDERING_INPROGRESS
481  };
482 
484 
487  virtual void GenerateRenderingRequestEvent() = 0;
488 
489  virtual void InitializePropertyList();
490 
492 
493  typedef std::map<BaseRenderer *, unsigned int> RendererIntMap;
494  typedef std::map<BaseRenderer *, bool> RendererBoolMap;
495 
497 
499 
500  unsigned int m_MaxLOD;
501 
503 
505 
507 
509 
511 
512  static void RenderingStartCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata);
513  static void RenderingProgressCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata);
514  static void RenderingEndCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata);
515 
516  typedef std::map<vtkRenderWindow *, int> RenderWindowList;
517 
520 
522  {
523  vtkCallbackCommand *commands[3u];
524  };
525 
526  typedef std::map<vtkRenderWindow *, RenderWindowCallbacks> RenderWindowCallbacksList;
527 
529 
531 
532  static RenderingManager::Pointer s_Instance;
534 
535  PropertyList::Pointer m_PropertyList;
536 
538 
540 
541  private:
542 
561  void InternalViewInitialization(BaseRenderer *baseRenderer,
562  const TimeGeometry *geometry,
563  bool boundingBoxInitialized,
564  int mapperID,
565  bool resetCamera);
566 
574  bool ExtendGeometryForBoundingBox(const TimeGeometry* originalGeometry, TimeGeometry::Pointer& modifiedGeometry);
575 
576  vtkRenderWindow *m_FocusedRenderWindow;
577  AntiAliasing m_AntiAliasing;
578  };
579 
580 #ifdef __GNUC__
581 #pragma GCC visibility push(default)
582 #endif
583 
584  itkEventMacroDeclaration(RenderingManagerEvent, itk::AnyEvent);
585  itkEventMacroDeclaration(RenderingManagerViewsInitializedEvent, RenderingManagerEvent);
586 
587 #ifdef __GNUC__
588 #pragma GCC visibility pop
589 #endif
590 
591  itkEventMacroDeclaration(FocusChangedEvent, itk::AnyEvent);
592 
601  {
602  public:
604  itkFactorylessNewMacro(Self);
605  itkCloneMacro(Self);
606 
607  protected:
608 
609  void GenerateRenderingRequestEvent() override {};
610  };
611 
612 } // namespace mitk
613 
614 #endif
#define MITKCORE_EXPORT
Abstract base class describing the geometry of a data object.
Abstract base class for properties.
Organizes the rendering process.
Abstract data management class that organizes DataNode objects in a directed acyclic graph.
Factory interface for facilitating the usage of a platform-specific mitk::RenderingManager instance.
Manager for coordinating the rendering process.
void SetShadingValues(float ambient, float diffuse, float specular, float specpower)
Set the shading values for rendering.
itk::SmartPointer< DataStorage > DataStoragePointer
void SetMaximumLOD(unsigned int max)
Set the maximum LOD level.
static Pointer New()
Create a new RenderingManager instance via the registered factory.
void SetAntiAliasing(AntiAliasing antiAliasing)
virtual void DoMonitorRendering()
Hook called to monitor rendering progress. Override in subclasses.
virtual void ExecutePendingRequests()
Execute all pending rendering requests.
BaseProperty * GetProperty(const char *propertyKey) const
Get a property from the internal property list.
itk::SmartPointer< TimeNavigationController > m_TimeNavigationController
void ExecutePendingHighResRenderingRequest()
Execute any pending high-resolution rendering requests. Called from a timer callback in subclasses.
void SetClippingPlaneStatus(bool status)
Enable or disable the clipping plane.
PropertyList::Pointer m_PropertyList
void RequestUpdate(vtkRenderWindow *renderWindow)
Request a deferred update for the specified render window.
virtual void InitializeViewByBoundingObjects(vtkRenderWindow *renderWindow, const DataStorage *dataStorage, bool resetCamera=true)
Initialize the given render window by the aggregated geometry of all objects that are held in the dat...
virtual bool InitializeViews(const BaseGeometry *geometry, RequestType type=REQUEST_UPDATE_ALL, bool resetCamera=true)
Initialize the render windows specified by "type" to the given geometry.
virtual void StartOrResetTimer()
Start or reset a timer for a pending high-resolution rendering request. Subclasses should override.
RenderWindowList m_RenderWindowList
bool GetClippingPlaneStatus()
Get the clipping plane status.
TimeNavigationController * GetTimeNavigationController()
mitkClassMacroItkParent(RenderingManager, itk::Object)
virtual bool InitializeViews(RequestType type=REQUEST_UPDATE_ALL)
Initialize the render windows specified by "type" to the default viewing direction without updating t...
static RenderingManagerFactory * s_RenderingManagerFactory
static bool IsInstantiated()
Check whether the singleton instance already exists.
DataStoragePointer m_DataStorage
const RenderWindowVector & GetAllRegisteredRenderWindows()
Get all registered vtkRenderWindows.
RendererBoolMap m_RenderingAbortedMap
virtual void GenerateRenderingRequestEvent()=0
std::vector< float > FloatVector
bool IsRendering() const
Check whether any registered render window is currently rendering.
virtual void InitializeViewsByBoundingObjects(const DataStorage *dataStorage)
Initialize the render windows by the aggregated geometry of all objects that are held in the data sto...
bool GetShading(unsigned int lod)
Get the shading state for a specific LOD level.
void AbortRendering()
Abort all in-progress renderings by setting the abort flag on active render windows.
const TimeNavigationController * GetTimeNavigationController() const
RenderWindowVector m_AllRenderWindows
void RemoveRenderWindow(vtkRenderWindow *renderWindow)
Unregister a vtkRenderWindow from this RenderingManager.
static void RenderingProgressCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
virtual void DoFinishAbortRendering()
Hook called when rendering abort is finished. Override in subclasses.
static RenderingManager * GetInstance()
Get the RenderingManager singleton instance.
void SetRenderWindowFocus(vtkRenderWindow *focusWindow)
Sets a flag to the given renderwindow to indicated that it has the focus e.g. has been clicked recent...
std::vector< vtkRenderWindow * > RenderWindowVector
RequestType
Enumeration of update request types.
@ REQUEST_UPDATE_2DWINDOWS
Update only 2D render windows.
std::map< vtkRenderWindow *, RenderWindowCallbacks > RenderWindowCallbacksList
virtual bool InitializeViews(const TimeGeometry *geometry, RequestType type=REQUEST_UPDATE_ALL, bool resetCamera=true)
Initialize the render windows specified by "type" to the given geometry.
static const RenderingManagerFactory * GetFactory()
Get the factory that produces platform-specific RenderingManager instances.
void SetShading(bool state, unsigned int lod)
Enable or disable shading for a specific LOD level.
void ForceImmediateUpdate(vtkRenderWindow *renderWindow)
Immediately execute a synchronous update of the specified render window.
void SetProperty(const char *propertyKey, BaseProperty *propertyValue)
Set or add a property in the internal property list.
static void RenderingEndCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
RenderWindowCallbacksList m_RenderWindowCallbacksList
PropertyList::Pointer GetPropertyList() const
Get the internal property list used for global rendering settings.
virtual bool InitializeView(vtkRenderWindow *renderWindow, const BaseGeometry *geometry, bool resetCamera=true)
Initialize the specified render window to the given geometry.
void AddRenderWindow(vtkRenderWindow *renderWindow)
Register a vtkRenderWindow with this RenderingManager.
void ForceImmediateUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Immediately execute a synchronous update for all registered render windows.
~RenderingManager() override
Destructor. Unregisters all render windows and removes callbacks.
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Request a deferred update for all registered render windows.
static bool HasFactory()
Check whether a factory has already been set.
void SetDataStorage(DataStorage *storage)
Setter for internal DataStorage.
virtual bool InitializeView(vtkRenderWindow *renderWindow)
Initialize the specified render window to the default viewing direction without updating the geometry...
FloatVector & GetShadingValues()
Get the current shading values.
static void RenderingStartCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
void SetConstrainedPanningZooming(bool constrain)
std::map< BaseRenderer *, bool > RendererBoolMap
std::vector< bool > BoolVector
virtual bool InitializeView(vtkRenderWindow *renderWindow, const TimeGeometry *geometry, bool resetCamera=true)
Initialize the specified render window to the given geometry.
std::map< BaseRenderer *, unsigned int > RendererIntMap
virtual void DoStartRendering()
Hook called when rendering starts. Override in subclasses.
static RenderingManager::Pointer s_Instance
std::map< vtkRenderWindow *, int > RenderWindowList
int GetNextLOD(BaseRenderer *renderer)
Get the next LOD level for the given renderer.
virtual void InitializePropertyList()
static void SetFactory(RenderingManagerFactory *factory)
Set the factory that produces platform-specific RenderingManager instances.
mitkClassMacro(TestingRenderingManager, RenderingManager)
Controls the time-related properties of the time stepper, according to the given input world time geo...
AntiAliasing
Anti-aliasing methods for rendering.
Declares commonly used GenericProperty specializations for MITK.
Find image slices visible on a given plane.
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)