38 #include <vtkCamera.h>
39 #include <vtkLinearTransform.h>
40 #include <vtkRenderWindow.h>
41 #include <vtkRenderer.h>
44 #include <vtkPolyDataMapper.h>
45 #include <vtkProperty.h>
53 if ((*mapit).first == renWin)
54 return (*mapit).second;
61 if (renWin ==
nullptr || baseRenderer ==
nullptr)
67 baseRendererMap.insert(BaseRendererMapType::value_type(renWin, baseRenderer));
72 BaseRendererMapType::iterator mapit = baseRendererMap.find(renWin);
73 if (mapit != baseRendererMap.end())
74 baseRendererMap.erase(mapit);
79 for (BaseRendererMapType::iterator mapit = baseRendererMap.begin(); mapit != baseRendererMap.end(); ++mapit)
81 if ((*mapit).second->m_Name == name)
82 return (*mapit).second;
89 for (BaseRendererMapType::iterator mapit = baseRendererMap.begin(); mapit != baseRendererMap.end(); ++mapit)
91 if ((*mapit).second->m_Name == name)
92 return (*mapit).first;
98 vtkRenderWindow *renWin,
101 : m_RenderWindow(nullptr),
102 m_VtkRenderer(nullptr),
103 m_MapperID(defaultMapper),
105 m_RenderingManager(rm),
107 m_CameraController(nullptr),
108 m_SliceNavigationController(nullptr),
109 m_CameraRotationController(nullptr),
110 m_WorldTimeGeometry(nullptr),
111 m_CurrentWorldGeometry(nullptr),
112 m_CurrentWorldPlaneGeometry(nullptr),
115 m_CurrentWorldPlaneGeometryUpdateTime(),
116 m_TimeStepUpdateTime(),
117 m_KeepDisplayedRegion(true),
118 m_CurrentWorldPlaneGeometryData(nullptr),
119 m_CurrentWorldPlaneGeometryNode(nullptr),
120 m_CurrentWorldPlaneGeometryTransformTime(0),
122 m_EmptyWorldGeometry(true),
123 m_NumberOfVisibleLODEnabledMappers(0)
138 m_Name =
"unnamed renderer";
139 itkWarningMacro(<<
"Created unnamed renderer. Bad for serialization. Please choose a name.");
142 if (renWin !=
nullptr)
149 itkWarningMacro(<<
"Created mitkBaseRenderer without vtkRenderWindow present.");
174 sliceNavigationController->SetRenderer(
this);
175 sliceNavigationController->ConnectGeometrySliceEvent(
this);
176 sliceNavigationController->ConnectGeometryUpdateEvent(
this);
177 sliceNavigationController->ConnectGeometryTimeEvent(
this,
false);
205 if (m_OverlayManager.IsNotNull())
207 m_OverlayManager->RemoveBaseRenderer(
this);
210 if (m_VtkRenderer !=
nullptr)
212 m_VtkRenderer->Delete();
213 m_VtkRenderer =
nullptr;
216 if (m_CameraController.IsNotNull())
217 m_CameraController->SetRenderer(
nullptr);
221 RemoveAllLocalStorages();
225 if (m_BindDispatcherInteractor !=
nullptr)
227 delete m_BindDispatcherInteractor;
230 if (m_RenderWindow !=
nullptr)
232 m_RenderWindow->Delete();
233 m_RenderWindow =
nullptr;
239 this->InvokeEvent(mitk::BaseRenderer::RendererResetEvent());
241 std::list<mitk::BaseLocalStorageHandler *>::iterator it;
242 for (it = m_RegisteredLocalStorageHandlers.begin(); it != m_RegisteredLocalStorageHandlers.end(); ++it)
243 (*it)->ClearLocalStorage(
this,
false);
244 m_RegisteredLocalStorageHandlers.clear();
249 m_RegisteredLocalStorageHandlers.push_back(lsh);
254 return m_BindDispatcherInteractor->GetDispatcher();
259 m_RegisteredLocalStorageHandlers.remove(lsh);
284 this->m_RenderWindow->SetSize(w, h);
289 if (m_RenderWindow != renderwindow)
291 if (m_RenderWindow !=
nullptr)
293 m_RenderWindow->Delete();
295 m_RenderWindow = renderwindow;
296 if (m_RenderWindow !=
nullptr)
298 m_RenderWindow->Register(
nullptr);
301 RemoveAllLocalStorages();
303 if (m_CameraController.IsNotNull())
305 m_CameraController->SetRenderer(
this);
311 this->m_RenderWindow->SetSize(w, h);
316 if (m_Slice != slice)
319 if (m_WorldTimeGeometry.IsNotNull())
323 dynamic_cast<SlicedGeometry3D *
>(m_WorldTimeGeometry->GetGeometryForTimeStep(m_TimeStep).GetPointer());
324 if (slicedWorldGeometry !=
nullptr)
327 if (m_Slice >= slicedWorldGeometry->
GetSlices())
329 m_Slice = slicedWorldGeometry->
GetSlices() - 1;
330 SetCurrentWorldPlaneGeometry(slicedWorldGeometry->
GetPlaneGeometry(m_Slice));
331 SetCurrentWorldGeometry(slicedWorldGeometry);
341 if (overlayManager.IsNull())
344 if (this->m_OverlayManager.IsNotNull())
346 if (this->m_OverlayManager.GetPointer() == overlayManager.GetPointer())
352 this->m_OverlayManager->RemoveBaseRenderer(
this);
355 this->m_OverlayManager = overlayManager;
356 this->m_OverlayManager->AddBaseRenderer(
this);
361 if (this->m_OverlayManager.IsNull())
364 m_OverlayManager->AddBaseRenderer(
this);
366 return this->m_OverlayManager;
371 if (m_TimeStep != timeStep)
373 m_TimeStep = timeStep;
374 m_TimeStepUpdateTime.Modified();
376 if (m_WorldTimeGeometry.IsNotNull())
378 if (m_TimeStep >= m_WorldTimeGeometry->CountTimeSteps())
379 m_TimeStep = m_WorldTimeGeometry->CountTimeSteps() - 1;
381 dynamic_cast<SlicedGeometry3D *
>(m_WorldTimeGeometry->GetGeometryForTimeStep(m_TimeStep).GetPointer());
382 if (slicedWorldGeometry !=
nullptr)
384 SetCurrentWorldPlaneGeometry(slicedWorldGeometry->
GetPlaneGeometry(m_Slice));
385 SetCurrentWorldGeometry(slicedWorldGeometry);
404 if (m_WorldTimeGeometry.IsNull())
410 ScalarType timeInMS = m_WorldTimeGeometry->TimeStepToTimePoint(GetTimeStep());
411 if (timeInMS == itk::NumericTraits<mitk::ScalarType>::NonpositiveMin())
420 assert(geometry !=
nullptr);
422 itkDebugMacro(
"setting WorldTimeGeometry to " << geometry);
423 if (m_WorldTimeGeometry != geometry)
428 m_WorldTimeGeometry = geometry;
429 itkDebugMacro(
"setting WorldTimeGeometry to " << m_WorldTimeGeometry);
431 if (m_TimeStep >= m_WorldTimeGeometry->CountTimeSteps())
432 m_TimeStep = m_WorldTimeGeometry->CountTimeSteps() - 1;
435 geometry3d = m_WorldTimeGeometry->GetGeometryForTimeStep(m_TimeStep);
436 SetWorldGeometry3D(geometry3d);
442 itkDebugMacro(
"setting WorldGeometry3D to " << geometry);
450 if (slicedWorldGeometry !=
nullptr)
452 if (m_Slice >= slicedWorldGeometry->
GetSlices() && (m_Slice != 0))
453 m_Slice = slicedWorldGeometry->
GetSlices() - 1;
455 if (geometry2d.IsNull())
458 plane->InitializeStandardPlane(slicedWorldGeometry);
461 SetCurrentWorldGeometry(slicedWorldGeometry);
466 if (geometry2d.IsNull())
469 plane->InitializeStandardPlane(geometry);
472 SetCurrentWorldGeometry(geometry);
474 SetCurrentWorldPlaneGeometry(geometry2d);
476 if (m_CurrentWorldPlaneGeometry.IsNull())
477 itkWarningMacro(
"m_CurrentWorldPlaneGeometry is nullptr");
482 if (m_CurrentWorldPlaneGeometry != geometry2d)
484 m_CurrentWorldPlaneGeometry = geometry2d;
485 m_CurrentWorldPlaneGeometryData->SetPlaneGeometry(m_CurrentWorldPlaneGeometry);
486 m_CurrentWorldPlaneGeometryUpdateTime.
Modified();
493 m_CurrentWorldPlaneGeometryUpdateTime.Modified();
498 return this->m_RenderWindow->GetSize();
503 return this->m_VtkRenderer->GetSize();
508 m_CurrentWorldGeometry = geometry;
509 if (geometry ==
nullptr)
517 m_EmptyWorldGeometry =
true;
520 BoundingBox::Pointer boundingBox = m_CurrentWorldGeometry->CalculateBoundingBoxRelativeToTransform(
nullptr);
522 m_Bounds[0] = worldBounds[0];
523 m_Bounds[1] = worldBounds[1];
524 m_Bounds[2] = worldBounds[2];
525 m_Bounds[3] = worldBounds[3];
526 m_Bounds[4] = worldBounds[4];
527 m_Bounds[5] = worldBounds[5];
528 if (boundingBox->GetDiagonalLength2() <=
mitk::eps)
529 m_EmptyWorldGeometry =
true;
531 m_EmptyWorldGeometry =
false;
536 if (m_OverlayManager.IsNotNull())
538 m_OverlayManager->UpdateOverlays(
this);
547 assert(sendEvent !=
nullptr);
556 if (updateEvent ==
nullptr)
559 if (m_CurrentWorldGeometry.IsNotNull())
562 if (slicedWorldGeometry)
566 SetCurrentWorldPlaneGeometry(geometry2D);
576 assert(sliceEvent !=
nullptr);
577 SetSlice(sliceEvent->
GetPos());
585 assert(timeEvent !=
nullptr);
586 SetTimeStep(timeEvent->
GetPos());
596 MITK_INFO <<
"BaseRenderer::DrawOverlayMouse()- should be inconcret implementation OpenGLRenderer." << std::endl;
601 SetConstrainZoomingAndPanning(
true);
602 m_RenderingManager->RequestUpdate(this->m_RenderWindow);
607 m_RenderingManager->ForceImmediateUpdate(this->m_RenderWindow);
612 return m_NumberOfVisibleLODEnabledMappers;
617 return m_RenderingManager.GetPointer();
625 if (SlicenavigationController ==
nullptr)
630 SlicenavigationController->
Update();
633 m_SliceNavigationController = SlicenavigationController;
636 if (m_SliceNavigationController.IsNotNull())
638 m_SliceNavigationController->ConnectGeometrySliceEvent(
this);
639 m_SliceNavigationController->ConnectGeometryUpdateEvent(
this);
640 m_SliceNavigationController->ConnectGeometryTimeEvent(
this,
false);
648 double display[3], *world;
652 double *displayCoord;
656 this->GetVtkRenderer()->GetActiveCamera()->GetFocalPoint(cameraFP);
658 this->GetVtkRenderer()->SetWorldPoint(cameraFP[0], cameraFP[1], cameraFP[2], cameraFP[3]);
659 this->GetVtkRenderer()->WorldToDisplay();
660 displayCoord = this->GetVtkRenderer()->GetDisplayPoint();
663 display[0] = displayPoint[0];
664 display[1] = displayPoint[1];
665 display[2] = displayCoord[2];
667 this->GetVtkRenderer()->SetDisplayPoint(display);
668 this->GetVtkRenderer()->DisplayToWorld();
669 world = this->GetVtkRenderer()->GetWorldPoint();
671 for (
int i = 0; i < 3; i++)
673 worldIndex[i] = world[i] / world[3];
691 this->DisplayToWorld(displayPoint, worldPoint);
692 this->m_CurrentWorldPlaneGeometry->Map(worldPoint, planePointInMM);
696 MITK_WARN <<
"No conversion possible with 3D mapper.";
705 double world[4], *display;
707 world[0] = worldIndex[0];
708 world[1] = worldIndex[1];
709 world[2] = worldIndex[2];
712 this->GetVtkRenderer()->SetWorldPoint(world);
713 this->GetVtkRenderer()->WorldToDisplay();
714 display = this->GetVtkRenderer()->GetDisplayPoint();
716 displayPoint[0] = display[0];
717 displayPoint[1] = display[1];
725 this->m_CurrentWorldPlaneGeometry->Map(planePointInMM, worldPoint);
726 this->WorldToDisplay(worldPoint, displayPoint);
737 return this->GetVtkRenderer()->GetActiveCamera()->GetParallelScale() * 2.0 / GetViewportSize()[1];
746 dispSizeInMM[0] = GetSizeX() * GetScaleFactorMMPerDisplayUnit();
747 dispSizeInMM[1] = GetSizeY() * GetScaleFactorMMPerDisplayUnit();
754 dispSizeInMM[0] = GetViewportSize()[0] * GetScaleFactorMMPerDisplayUnit();
755 dispSizeInMM[1] = GetViewportSize()[1] * GetScaleFactorMMPerDisplayUnit();
762 originPx[0] = m_VtkRenderer->GetOrigin()[0];
763 originPx[1] = m_VtkRenderer->GetOrigin()[1];
764 Point2D displayGeometryOriginInMM;
765 DisplayToPlane(originPx, displayGeometryOriginInMM);
766 return displayGeometryOriginInMM;
771 m_ConstrainZoomingAndPanning = constrain;
772 if (m_ConstrainZoomingAndPanning)
774 this->GetCameraController()->AdjustCameraToPlane();
782 DisplayToWorld(mousePosition, position);
788 os << indent <<
" MapperID: " << m_MapperID << std::endl;
789 os << indent <<
" Slice: " << m_Slice << std::endl;
790 os << indent <<
" TimeStep: " << m_TimeStep << std::endl;
792 os << indent <<
" CurrentWorldPlaneGeometry: ";
793 if (m_CurrentWorldPlaneGeometry.IsNull())
794 os <<
"nullptr" << std::endl;
796 m_CurrentWorldPlaneGeometry->Print(os, indent);
798 os << indent <<
" CurrentWorldPlaneGeometryUpdateTime: " << m_CurrentWorldPlaneGeometryUpdateTime << std::endl;
799 os << indent <<
" CurrentWorldPlaneGeometryTransformTime: " << m_CurrentWorldPlaneGeometryTransformTime << std::endl;
801 Superclass::PrintSelf(os, indent);
std::map< vtkRenderWindow *, BaseRenderer * > BaseRendererMapType
PlaneGeometryData::Pointer m_CurrentWorldPlaneGeometryData
virtual const mitk::TimeGeometry * GetCreatedWorldGeometry()
Access the created geometry.
void UpdateOverlays()
This method is called during the rendering process to update or render the Overlays which are stored ...
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
double GetScaleFactorMMPerDisplayUnit() const
This Class is used to connect a DataStorage with the Dispatcher.
void SetSliceNavigationController(SliceNavigationController *SlicenavigationController)
virtual Point3D Map2DRendererPositionTo3DWorldPosition(const Point2D &mousePosition) const
Provides (1) world coordinates for a given mouse position and (2) translates mousePosition to Display...
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
static vtkRenderWindow * GetRenderWindowByName(const std::string &name)
void InsertSceneRenderer(vtkSmartPointer< vtkRenderer > renderer)
Base of all data objects.
BoundingBox * GetBoundingBoxInWorld() const
Returns a bounding box that covers all time steps.
unsigned int GetNumberOfVisibleLODEnabledMappers() const
void SetInputWorldTimeGeometry(const mitk::TimeGeometry *geometry)
virtual void SetConstrainZoomingAndPanning(bool constrain)
virtual void SetDataStorage(DataStorage *storage)
set the datastorage that will be used for rendering
void SetOverlayManager(itk::SmartPointer< OverlayManager > overlayManager)
Sets an OverlayManager which is used to add various Overlays to this renderer. If an OverlayManager w...
virtual void Resize(int w, int h)
Called to inform the renderer that the RenderWindow has been resized.
Organizes the rendering process.
virtual void SetCurrentWorldPlaneGeometry(PlaneGeometry *geometry2d)
Sets m_CurrentWorldPlaneGeometry.
void ForceImmediateUpdate()
ScalarType GetTime() const
Get the time in ms of the currently displayed content.
virtual void SetTimeStep(unsigned int timeStep)
Set/Get m_TimeStep which defines together with m_Slice the 2D geometry stored in m_WorldTimeGeometry ...
Interface for accessing (templated) LocalStorageHandler instances.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
static const MapperSlotId defaultMapper
Default mapper id to use.
Constants for most interaction classes, due to the generic StateMachines.
TimeGeometry * GetTimeGeometry() const
Point2D GetDisplaySizeInMM() const
CameraRotationController::Pointer m_CameraRotationController
Controls the selection of the slice the associated BaseRenderer will display.
BaseRenderer(const char *name=nullptr, vtkRenderWindow *renWin=nullptr, mitk::RenderingManager *rm=nullptr, RenderingMode::Type mode=RenderingMode::Standard)
static void AddInstance(vtkSmartPointer< vtkRenderWindow > renWin, vtkSmartPointer< vtkRenderer > mitkSceneRenderer)
virtual void SetGeometrySlice(const itk::EventObject &geometrySliceEvent)
SetSlice is called according to the geometrySliceEvent, which is supposed to be a SliceNavigationCont...
virtual void UpdateGeometry(const itk::EventObject &geometrySliceEvent)
UpdateWorldGeometry is called to re-read the 2D geometry from the slice navigation controller...
static VtkLayerController * GetInstance(vtkSmartPointer< vtkRenderWindow > renWin)
virtual void SetWorldGeometry3D(BaseGeometry *geometry)
Set/Get the WorldGeometry (m_WorldGeometry) for 3D and 2D rendering, that describing the (maximal) ar...
void WorldToDisplay(const Point3D &worldIndex, Point2D &displayPoint) const
This method converts a 3D world index to the display point using the geometry of the renderWindow...
virtual void SetCurrentWorldGeometry(BaseGeometry *geometry)
Sets m_CurrentWorldGeometry.
mitk::DataStorage::Pointer m_DataStorage
virtual void SetSlice(unsigned int slice)
Set/Get m_Slice which defines together with m_TimeStep the 2D geometry stored in m_WorldTimeGeometry ...
virtual mitk::RenderingManager * GetRenderingManager() const
Setter for the RenderingManager that handles this instance of BaseRenderer.
int MapperSlotId
MapperSlotId defines which kind of mapper (e.g., 2D or 3D) shoud be used.
Manager for coordinating the rendering process.
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const =0
Converts a time point to the corresponding time step.
static BaseRendererMapType baseRendererMap
virtual void InitSize(int w, int h)
Set the initial size. Called by RenderWindow after it has become visible for the first time...
unsigned long m_CurrentWorldPlaneGeometryTransformTime
test only
void Modified() const override
Overload of function Modified() to prohibit several calls of Modified() using the ModifiedLock class...
virtual mitk::PlaneGeometry * GetPlaneGeometry(int s) const
Returns the PlaneGeometry of the slice (s).
void SetRenderer(BaseRenderer *renderer)
Sets the BaseRenderer associated with this SNC (if any). While the BaseRenderer is not directly used ...
Point2D GetViewportSizeInMM() const
vtkRenderer * m_VtkRenderer
Dispatcher::Pointer GetDispatcher() const
Returns the Dispatcher which handles Events for this BaseRenderer.
vtkRenderWindow * m_RenderWindow
virtual void SetGeometry(const itk::EventObject &geometrySliceEvent)
SetWorldGeometry is called according to the geometrySliceEvent, which is supposed to be a SliceNaviga...
virtual void Paint()
Do the rendering and flush the result.
virtual void SetWorldTimeGeometry(mitk::TimeGeometry *geometry)
void DisplayToPlane(const Point2D &displayPoint, Point2D &planePointInMM) const
This method converts a display point to the 2D world index, mapped onto the display plane using the g...
virtual int * GetViewportSize() const
unsigned int GetPos() const
Point2D GetOriginInMM() const
virtual unsigned int GetSlices() const
Get the number of slices.
Describes the geometry of a data object consisting of slices.
virtual unsigned int GetTimeStep() const
itk::SmartPointer< OverlayManager > GetOverlayManager()
Get the OverlayManager registered with this renderer if none was set, it will be created at this poin...
const char * GetName() const
get the name of the Renderer
const double * GetBounds() const
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override
virtual void SetGeometryTime(const itk::EventObject &geometryTimeEvent)
SetTimeStep is called according to the geometrySliceEvent, which is supposed to be a SliceNavigationC...
void RegisterLocalStorageHandler(mitk::BaseLocalStorageHandler *lsh)
virtual void Initialize()
Initialize the RenderWindow. Should only be called from RenderWindow.
static BaseRenderer * GetByName(const std::string &name)
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
MITKCORE_EXPORT const ScalarType eps
void RemoveAllLocalStorages()
virtual int * GetSize() const
Describes a two-dimensional, rectangular plane.
DataNode::Pointer m_CurrentWorldPlaneGeometryNode
static void RemoveInstance(vtkRenderWindow *renWin)
itk::SmartPointer< CameraController > m_CameraController
CameraController for 3D rendering.
void PlaneToDisplay(const Point2D &planePointInMM, Point2D &displayPoint) const
This method converts a 2D plane coordinate to the display point using the geometry of the renderWindo...
virtual void Update()
Do the actual creation and send it to the connected observers (renderers)
void DisplayToWorld(const Point2D &displayPoint, Point3D &worldIndex) const
This method converts a display point to the 3D world index using the geometry of the renderWindow...
SliceNavigationController::Pointer m_SliceNavigationController
void SendUpdateSlice()
Sets timestamp of CurrentWorldPlaneGeometry and forces so reslicing in that renderwindow.
static void AddInstance(vtkRenderWindow *renWin, BaseRenderer *baseRenderer)
virtual void InitRenderer(vtkRenderWindow *renderwindow)
Initialize the renderer with a RenderWindow (renderwindow).
BaseGeometry Describes the geometry of a data object.
static void RemoveInstance(vtkSmartPointer< vtkRenderWindow > renWin)
BoundingBoxType::BoundsArrayType BoundsArrayType
virtual void DrawOverlayMouse(Point2D &p2d)
Draws a point on the widget. Should be used during conferences to show the position of the remote mou...
virtual const BoundingBoxType * GetBoundingBox()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.
void UnregisterLocalStorageHandler(mitk::BaseLocalStorageHandler *lsh)