Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkBaseRenderer.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3  The Medical Imaging Interaction Toolkit (MITK)
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics.
7  All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without
10  even the implied warranty of MERCHANTABILITY or FITNESS FOR
11  A PARTICULAR PURPOSE.
12 
13  See LICENSE.txt or http://www.mitk.org for details.
14 
15  ===================================================================*/
16 
17 #include "mitkBaseRenderer.h"
18 #include "mitkMapper.h"
20 
21 // Geometries
22 #include "mitkPlaneGeometry.h"
23 #include "mitkSlicedGeometry3D.h"
24 
25 // Controllers
26 #include "mitkCameraController.h"
29 
30 #include "mitkVtkLayerController.h"
31 
32 #include "mitkInteractionConst.h"
33 #include "mitkOverlayManager.h"
34 #include "mitkProperties.h"
36 
37 // VTK
38 #include <vtkCamera.h>
39 #include <vtkLinearTransform.h>
40 #include <vtkRenderWindow.h>
41 #include <vtkRenderer.h>
42 
43 #include <vtkActor.h>
44 #include <vtkPolyDataMapper.h>
45 #include <vtkProperty.h>
46 
48 
50 {
51  for (BaseRendererMapType::iterator mapit = baseRendererMap.begin(); mapit != baseRendererMap.end(); ++mapit)
52  {
53  if ((*mapit).first == renWin)
54  return (*mapit).second;
55  }
56  return nullptr;
57 }
58 
59 void mitk::BaseRenderer::AddInstance(vtkRenderWindow *renWin, BaseRenderer *baseRenderer)
60 {
61  if (renWin == nullptr || baseRenderer == nullptr)
62  return;
63 
64  // ensure that no BaseRenderer is managed twice
66 
67  baseRendererMap.insert(BaseRendererMapType::value_type(renWin, baseRenderer));
68 }
69 
70 void mitk::BaseRenderer::RemoveInstance(vtkRenderWindow *renWin)
71 {
72  BaseRendererMapType::iterator mapit = baseRendererMap.find(renWin);
73  if (mapit != baseRendererMap.end())
74  baseRendererMap.erase(mapit);
75 }
76 
78 {
79  for (BaseRendererMapType::iterator mapit = baseRendererMap.begin(); mapit != baseRendererMap.end(); ++mapit)
80  {
81  if ((*mapit).second->m_Name == name)
82  return (*mapit).second;
83  }
84  return nullptr;
85 }
86 
87 vtkRenderWindow *mitk::BaseRenderer::GetRenderWindowByName(const std::string &name)
88 {
89  for (BaseRendererMapType::iterator mapit = baseRendererMap.begin(); mapit != baseRendererMap.end(); ++mapit)
90  {
91  if ((*mapit).second->m_Name == name)
92  return (*mapit).first;
93  }
94  return nullptr;
95 }
96 
98  vtkRenderWindow *renWin,
100  RenderingMode::Type renderingMode)
101  : m_RenderWindow(nullptr),
102  m_VtkRenderer(nullptr),
103  m_MapperID(defaultMapper),
104  m_DataStorage(nullptr),
105  m_RenderingManager(rm),
106  m_LastUpdateTime(0),
107  m_CameraController(nullptr),
108  m_SliceNavigationController(nullptr),
109  m_CameraRotationController(nullptr),
110  m_WorldTimeGeometry(nullptr),
111  m_CurrentWorldGeometry(nullptr),
112  m_CurrentWorldPlaneGeometry(nullptr),
113  m_Slice(0),
114  m_TimeStep(),
115  m_CurrentWorldPlaneGeometryUpdateTime(),
116  m_TimeStepUpdateTime(),
117  m_KeepDisplayedRegion(true),
118  m_CurrentWorldPlaneGeometryData(nullptr),
119  m_CurrentWorldPlaneGeometryNode(nullptr),
120  m_CurrentWorldPlaneGeometryTransformTime(0),
121  m_Name(name),
122  m_EmptyWorldGeometry(true),
123  m_NumberOfVisibleLODEnabledMappers(0)
124 {
125  m_Bounds[0] = 0;
126  m_Bounds[1] = 0;
127  m_Bounds[2] = 0;
128  m_Bounds[3] = 0;
129  m_Bounds[4] = 0;
130  m_Bounds[5] = 0;
131 
132  if (name != nullptr)
133  {
134  m_Name = name;
135  }
136  else
137  {
138  m_Name = "unnamed renderer";
139  itkWarningMacro(<< "Created unnamed renderer. Bad for serialization. Please choose a name.");
140  }
141 
142  if (renWin != nullptr)
143  {
144  m_RenderWindow = renWin;
145  m_RenderWindow->Register(nullptr);
146  }
147  else
148  {
149  itkWarningMacro(<< "Created mitkBaseRenderer without vtkRenderWindow present.");
150  }
151  // instances.insert( this );
152 
153  // adding this BaseRenderer to the List of all BaseRenderer
154 
155  m_BindDispatcherInteractor = new mitk::BindDispatcherInteractor(GetName());
156 
157  WeakPointerProperty::Pointer rendererProp = WeakPointerProperty::New((itk::Object *)this);
158 
159  m_CurrentWorldPlaneGeometry = mitk::PlaneGeometry::New();
160 
162  m_CurrentWorldPlaneGeometryData->SetPlaneGeometry(m_CurrentWorldPlaneGeometry);
165  m_CurrentWorldPlaneGeometryNode->GetPropertyList()->SetProperty("renderer", rendererProp);
166  m_CurrentWorldPlaneGeometryNode->GetPropertyList()->SetProperty("layer", IntProperty::New(1000));
167 
168  m_CurrentWorldPlaneGeometryNode->SetProperty("reslice.thickslices", mitk::ResliceMethodProperty::New());
169  m_CurrentWorldPlaneGeometryNode->SetProperty("reslice.thickslices.num", mitk::IntProperty::New(1));
170 
172 
174  sliceNavigationController->SetRenderer(this);
175  sliceNavigationController->ConnectGeometrySliceEvent(this);
176  sliceNavigationController->ConnectGeometryUpdateEvent(this);
177  sliceNavigationController->ConnectGeometryTimeEvent(this, false);
178  m_SliceNavigationController = sliceNavigationController;
179 
181  m_CameraRotationController->SetRenderWindow(m_RenderWindow);
182  m_CameraRotationController->AcquireCamera();
183 
185  m_CameraController->SetRenderer(this);
186 
188 
189  if (renderingMode == RenderingMode::DepthPeeling)
190  {
191  m_VtkRenderer->SetUseDepthPeeling(1);
192  m_VtkRenderer->SetMaximumNumberOfPeels(8);
193  m_VtkRenderer->SetOcclusionRatio(0.0);
194  }
195 
197  {
199  }
201 }
202 
204 {
205  if (m_OverlayManager.IsNotNull())
206  {
207  m_OverlayManager->RemoveBaseRenderer(this);
208  }
209 
210  if (m_VtkRenderer != nullptr)
211  {
212  m_VtkRenderer->Delete();
213  m_VtkRenderer = nullptr;
214  }
215 
216  if (m_CameraController.IsNotNull())
217  m_CameraController->SetRenderer(nullptr);
218 
220 
221  RemoveAllLocalStorages();
222 
223  m_DataStorage = nullptr;
224 
225  if (m_BindDispatcherInteractor != nullptr)
226  {
227  delete m_BindDispatcherInteractor;
228  }
229 
230  if (m_RenderWindow != nullptr)
231  {
232  m_RenderWindow->Delete();
233  m_RenderWindow = nullptr;
234  }
235 }
236 
238 {
239  this->InvokeEvent(mitk::BaseRenderer::RendererResetEvent());
240 
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();
245 }
246 
248 {
249  m_RegisteredLocalStorageHandlers.push_back(lsh);
250 }
251 
253 {
254  return m_BindDispatcherInteractor->GetDispatcher();
255 }
256 
258 {
259  m_RegisteredLocalStorageHandlers.remove(lsh);
260 }
261 
263 {
264  if (storage != m_DataStorage && storage != nullptr)
265  {
266  m_DataStorage = storage;
267  m_BindDispatcherInteractor->SetDataStorage(m_DataStorage);
268  this->Modified();
269  }
270 }
271 
273 
275 {
276 }
277 
279 {
280 }
281 
282 void mitk::BaseRenderer::Resize(int w, int h)
283 {
284  this->m_RenderWindow->SetSize(w, h);
285 }
286 
287 void mitk::BaseRenderer::InitRenderer(vtkRenderWindow *renderwindow)
288 {
289  if (m_RenderWindow != renderwindow)
290  {
291  if (m_RenderWindow != nullptr)
292  {
293  m_RenderWindow->Delete();
294  }
295  m_RenderWindow = renderwindow;
296  if (m_RenderWindow != nullptr)
297  {
298  m_RenderWindow->Register(nullptr);
299  }
300  }
301  RemoveAllLocalStorages();
302 
303  if (m_CameraController.IsNotNull())
304  {
305  m_CameraController->SetRenderer(this);
306  }
307 }
308 
310 {
311  this->m_RenderWindow->SetSize(w, h);
312 }
313 
314 void mitk::BaseRenderer::SetSlice(unsigned int slice)
315 {
316  if (m_Slice != slice)
317  {
318  m_Slice = slice;
319  if (m_WorldTimeGeometry.IsNotNull())
320  {
321  // get world geometry which may be rotated, for the current time step
322  SlicedGeometry3D *slicedWorldGeometry =
323  dynamic_cast<SlicedGeometry3D *>(m_WorldTimeGeometry->GetGeometryForTimeStep(m_TimeStep).GetPointer());
324  if (slicedWorldGeometry != nullptr)
325  {
326  // if slice position is part of the world geometry...
327  if (m_Slice >= slicedWorldGeometry->GetSlices())
328  // set the current worldplanegeomety as the selected 2D slice of the world geometry
329  m_Slice = slicedWorldGeometry->GetSlices() - 1;
330  SetCurrentWorldPlaneGeometry(slicedWorldGeometry->GetPlaneGeometry(m_Slice));
331  SetCurrentWorldGeometry(slicedWorldGeometry);
332  }
333  }
334  else
335  Modified();
336  }
337 }
338 
340 {
341  if (overlayManager.IsNull())
342  return;
343 
344  if (this->m_OverlayManager.IsNotNull())
345  {
346  if (this->m_OverlayManager.GetPointer() == overlayManager.GetPointer())
347  {
348  return;
349  }
350  else
351  {
352  this->m_OverlayManager->RemoveBaseRenderer(this);
353  }
354  }
355  this->m_OverlayManager = overlayManager;
356  this->m_OverlayManager->AddBaseRenderer(this); // TODO
357 }
358 
360 {
361  if (this->m_OverlayManager.IsNull())
362  {
363  m_OverlayManager = mitk::OverlayManager::New();
364  m_OverlayManager->AddBaseRenderer(this);
365  }
366  return this->m_OverlayManager;
367 }
368 
369 void mitk::BaseRenderer::SetTimeStep(unsigned int timeStep)
370 {
371  if (m_TimeStep != timeStep)
372  {
373  m_TimeStep = timeStep;
374  m_TimeStepUpdateTime.Modified();
375 
376  if (m_WorldTimeGeometry.IsNotNull())
377  {
378  if (m_TimeStep >= m_WorldTimeGeometry->CountTimeSteps())
379  m_TimeStep = m_WorldTimeGeometry->CountTimeSteps() - 1;
380  SlicedGeometry3D *slicedWorldGeometry =
381  dynamic_cast<SlicedGeometry3D *>(m_WorldTimeGeometry->GetGeometryForTimeStep(m_TimeStep).GetPointer());
382  if (slicedWorldGeometry != nullptr)
383  {
384  SetCurrentWorldPlaneGeometry(slicedWorldGeometry->GetPlaneGeometry(m_Slice));
385  SetCurrentWorldGeometry(slicedWorldGeometry);
386  }
387  }
388  else
389  Modified();
390  }
391 }
392 
394 {
395  if ((data == nullptr) || (data->IsInitialized() == false))
396  {
397  return -1;
398  }
399  return data->GetTimeGeometry()->TimePointToTimeStep(GetTime());
400 }
401 
403 {
404  if (m_WorldTimeGeometry.IsNull())
405  {
406  return 0;
407  }
408  else
409  {
410  ScalarType timeInMS = m_WorldTimeGeometry->TimeStepToTimePoint(GetTimeStep());
411  if (timeInMS == itk::NumericTraits<mitk::ScalarType>::NonpositiveMin())
412  return 0;
413  else
414  return timeInMS;
415  }
416 }
417 
419 {
420  assert(geometry != nullptr);
421 
422  itkDebugMacro("setting WorldTimeGeometry to " << geometry);
423  if (m_WorldTimeGeometry != geometry)
424  {
425  if (geometry->GetBoundingBoxInWorld()->GetDiagonalLength2() == 0)
426  return;
427 
428  m_WorldTimeGeometry = geometry;
429  itkDebugMacro("setting WorldTimeGeometry to " << m_WorldTimeGeometry);
430 
431  if (m_TimeStep >= m_WorldTimeGeometry->CountTimeSteps())
432  m_TimeStep = m_WorldTimeGeometry->CountTimeSteps() - 1;
433 
434  BaseGeometry *geometry3d;
435  geometry3d = m_WorldTimeGeometry->GetGeometryForTimeStep(m_TimeStep);
436  SetWorldGeometry3D(geometry3d);
437  }
438 }
439 
441 {
442  itkDebugMacro("setting WorldGeometry3D to " << geometry);
443 
444  if (geometry->GetBoundingBox()->GetDiagonalLength2() == 0)
445  return;
446  SlicedGeometry3D *slicedWorldGeometry;
447  slicedWorldGeometry = dynamic_cast<SlicedGeometry3D *>(geometry);
448 
449  PlaneGeometry::Pointer geometry2d;
450  if (slicedWorldGeometry != nullptr)
451  {
452  if (m_Slice >= slicedWorldGeometry->GetSlices() && (m_Slice != 0))
453  m_Slice = slicedWorldGeometry->GetSlices() - 1;
454  geometry2d = slicedWorldGeometry->GetPlaneGeometry(m_Slice);
455  if (geometry2d.IsNull())
456  {
458  plane->InitializeStandardPlane(slicedWorldGeometry);
459  geometry2d = plane;
460  }
461  SetCurrentWorldGeometry(slicedWorldGeometry);
462  }
463  else
464  {
465  geometry2d = dynamic_cast<PlaneGeometry *>(geometry);
466  if (geometry2d.IsNull())
467  {
469  plane->InitializeStandardPlane(geometry);
470  geometry2d = plane;
471  }
472  SetCurrentWorldGeometry(geometry);
473  }
474  SetCurrentWorldPlaneGeometry(geometry2d); // calls Modified()
475 
476  if (m_CurrentWorldPlaneGeometry.IsNull())
477  itkWarningMacro("m_CurrentWorldPlaneGeometry is nullptr");
478 }
479 
481 {
482  if (m_CurrentWorldPlaneGeometry != geometry2d)
483  {
484  m_CurrentWorldPlaneGeometry = geometry2d;
485  m_CurrentWorldPlaneGeometryData->SetPlaneGeometry(m_CurrentWorldPlaneGeometry);
486  m_CurrentWorldPlaneGeometryUpdateTime.Modified();
487  Modified();
488  }
489 }
490 
492 {
493  m_CurrentWorldPlaneGeometryUpdateTime.Modified();
494 }
495 
497 {
498  return this->m_RenderWindow->GetSize();
499 }
500 
502 {
503  return this->m_VtkRenderer->GetSize();
504 }
505 
507 {
508  m_CurrentWorldGeometry = geometry;
509  if (geometry == nullptr)
510  {
511  m_Bounds[0] = 0;
512  m_Bounds[1] = 0;
513  m_Bounds[2] = 0;
514  m_Bounds[3] = 0;
515  m_Bounds[4] = 0;
516  m_Bounds[5] = 0;
517  m_EmptyWorldGeometry = true;
518  return;
519  }
520  BoundingBox::Pointer boundingBox = m_CurrentWorldGeometry->CalculateBoundingBoxRelativeToTransform(nullptr);
521  const BoundingBox::BoundsArrayType &worldBounds = boundingBox->GetBounds();
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;
530  else
531  m_EmptyWorldGeometry = false;
532 }
533 
535 {
536  if (m_OverlayManager.IsNotNull())
537  {
538  m_OverlayManager->UpdateOverlays(this);
539  }
540 }
541 
542 void mitk::BaseRenderer::SetGeometry(const itk::EventObject &geometrySendEvent)
543 {
545  dynamic_cast<const SliceNavigationController::GeometrySendEvent *>(&geometrySendEvent);
546 
547  assert(sendEvent != nullptr);
548  SetWorldTimeGeometry(sendEvent->GetTimeGeometry());
549 }
550 
551 void mitk::BaseRenderer::UpdateGeometry(const itk::EventObject &geometryUpdateEvent)
552 {
554  dynamic_cast<const SliceNavigationController::GeometryUpdateEvent *>(&geometryUpdateEvent);
555 
556  if (updateEvent == nullptr)
557  return;
558 
559  if (m_CurrentWorldGeometry.IsNotNull())
560  {
561  SlicedGeometry3D *slicedWorldGeometry = dynamic_cast<SlicedGeometry3D *>(m_CurrentWorldGeometry.GetPointer());
562  if (slicedWorldGeometry)
563  {
564  PlaneGeometry *geometry2D = slicedWorldGeometry->GetPlaneGeometry(m_Slice);
565 
566  SetCurrentWorldPlaneGeometry(geometry2D); // calls Modified()
567  }
568  }
569 }
570 
571 void mitk::BaseRenderer::SetGeometrySlice(const itk::EventObject &geometrySliceEvent)
572 {
574  dynamic_cast<const SliceNavigationController::GeometrySliceEvent *>(&geometrySliceEvent);
575 
576  assert(sliceEvent != nullptr);
577  SetSlice(sliceEvent->GetPos());
578 }
579 
580 void mitk::BaseRenderer::SetGeometryTime(const itk::EventObject &geometryTimeEvent)
581 {
583  dynamic_cast<const SliceNavigationController::GeometryTimeEvent *>(&geometryTimeEvent);
584 
585  assert(timeEvent != nullptr);
586  SetTimeStep(timeEvent->GetPos());
587 }
588 
589 const double *mitk::BaseRenderer::GetBounds() const
590 {
591  return m_Bounds;
592 }
593 
595 {
596  MITK_INFO << "BaseRenderer::DrawOverlayMouse()- should be inconcret implementation OpenGLRenderer." << std::endl;
597 }
598 
600 {
601  SetConstrainZoomingAndPanning(true);
602  m_RenderingManager->RequestUpdate(this->m_RenderWindow);
603 }
604 
606 {
607  m_RenderingManager->ForceImmediateUpdate(this->m_RenderWindow);
608 }
609 
611 {
612  return m_NumberOfVisibleLODEnabledMappers;
613 }
614 
616 {
617  return m_RenderingManager.GetPointer();
618 }
619 
624 {
625  if (SlicenavigationController == nullptr)
626  return;
627 
628  // copy worldgeometry
629  SlicenavigationController->SetInputWorldTimeGeometry(SlicenavigationController->GetCreatedWorldGeometry());
630  SlicenavigationController->Update();
631 
632  // set new
633  m_SliceNavigationController = SlicenavigationController;
634  m_SliceNavigationController->SetRenderer(this);
635 
636  if (m_SliceNavigationController.IsNotNull())
637  {
638  m_SliceNavigationController->ConnectGeometrySliceEvent(this);
639  m_SliceNavigationController->ConnectGeometryUpdateEvent(this);
640  m_SliceNavigationController->ConnectGeometryTimeEvent(this, false);
641  }
642 }
643 
644 void mitk::BaseRenderer::DisplayToWorld(const Point2D &displayPoint, Point3D &worldIndex) const
645 {
646  if (m_MapperID == BaseRenderer::Standard2D)
647  {
648  double display[3], *world;
649 
650  // For the rigth z-position in display coordinates, take the focal point, convert it to display and use it for
651  // correct depth.
652  double *displayCoord;
653  double cameraFP[4];
654  // Get camera focal point and position. Convert to display (screen)
655  // coordinates. We need a depth value for z-buffer.
656  this->GetVtkRenderer()->GetActiveCamera()->GetFocalPoint(cameraFP);
657  cameraFP[3] = 0.0;
658  this->GetVtkRenderer()->SetWorldPoint(cameraFP[0], cameraFP[1], cameraFP[2], cameraFP[3]);
659  this->GetVtkRenderer()->WorldToDisplay();
660  displayCoord = this->GetVtkRenderer()->GetDisplayPoint();
661 
662  // now convert the display point to world coordinates
663  display[0] = displayPoint[0];
664  display[1] = displayPoint[1];
665  display[2] = displayCoord[2];
666 
667  this->GetVtkRenderer()->SetDisplayPoint(display);
668  this->GetVtkRenderer()->DisplayToWorld();
669  world = this->GetVtkRenderer()->GetWorldPoint();
670 
671  for (int i = 0; i < 3; i++)
672  {
673  worldIndex[i] = world[i] / world[3];
674  }
675  }
676  else if (m_MapperID == BaseRenderer::Standard3D)
677  {
678  PickWorldPoint(
679  displayPoint,
680  worldIndex); // Seems to be the same code as above, but subclasses may contain different implementations.
681  }
682 
683  return;
684 }
685 
686 void mitk::BaseRenderer::DisplayToPlane(const Point2D &displayPoint, Point2D &planePointInMM) const
687 {
688  if (m_MapperID == BaseRenderer::Standard2D)
689  {
690  Point3D worldPoint;
691  this->DisplayToWorld(displayPoint, worldPoint);
692  this->m_CurrentWorldPlaneGeometry->Map(worldPoint, planePointInMM);
693  }
694  else if (m_MapperID == BaseRenderer::Standard3D)
695  {
696  MITK_WARN << "No conversion possible with 3D mapper.";
697  return;
698  }
699 
700  return;
701 }
702 
703 void mitk::BaseRenderer::WorldToDisplay(const Point3D &worldIndex, Point2D &displayPoint) const
704 {
705  double world[4], *display;
706 
707  world[0] = worldIndex[0];
708  world[1] = worldIndex[1];
709  world[2] = worldIndex[2];
710  world[3] = 1.0;
711 
712  this->GetVtkRenderer()->SetWorldPoint(world);
713  this->GetVtkRenderer()->WorldToDisplay();
714  display = this->GetVtkRenderer()->GetDisplayPoint();
715 
716  displayPoint[0] = display[0];
717  displayPoint[1] = display[1];
718 
719  return;
720 }
721 
722 void mitk::BaseRenderer::PlaneToDisplay(const Point2D &planePointInMM, Point2D &displayPoint) const
723 {
724  Point3D worldPoint;
725  this->m_CurrentWorldPlaneGeometry->Map(planePointInMM, worldPoint);
726  this->WorldToDisplay(worldPoint, displayPoint);
727 
728  return;
729 }
730 
732 {
733  if (this->GetMapperID() == BaseRenderer::Standard2D)
734  {
735  // GetParallelScale returns half of the height of the render window in mm.
736  // Divided by the half size of the Display size in pixel givest the mm per pixel.
737  return this->GetVtkRenderer()->GetActiveCamera()->GetParallelScale() * 2.0 / GetViewportSize()[1];
738  }
739  else
740  return 1.0;
741 }
742 
744 {
745  Point2D dispSizeInMM;
746  dispSizeInMM[0] = GetSizeX() * GetScaleFactorMMPerDisplayUnit();
747  dispSizeInMM[1] = GetSizeY() * GetScaleFactorMMPerDisplayUnit();
748  return dispSizeInMM;
749 }
750 
752 {
753  Point2D dispSizeInMM;
754  dispSizeInMM[0] = GetViewportSize()[0] * GetScaleFactorMMPerDisplayUnit();
755  dispSizeInMM[1] = GetViewportSize()[1] * GetScaleFactorMMPerDisplayUnit();
756  return dispSizeInMM;
757 }
758 
760 {
761  Point2D originPx;
762  originPx[0] = m_VtkRenderer->GetOrigin()[0];
763  originPx[1] = m_VtkRenderer->GetOrigin()[1];
764  Point2D displayGeometryOriginInMM;
765  DisplayToPlane(originPx, displayGeometryOriginInMM); // top left of the render window (Origin)
766  return displayGeometryOriginInMM;
767 }
768 
770 {
771  m_ConstrainZoomingAndPanning = constrain;
772  if (m_ConstrainZoomingAndPanning)
773  {
774  this->GetCameraController()->AdjustCameraToPlane();
775  }
776 }
777 
779 {
780  // DEPRECATED: Map2DRendererPositionTo3DWorldPosition is deprecated. use DisplayToWorldInstead
781  Point3D position;
782  DisplayToWorld(mousePosition, position);
783  return position;
784 }
785 
786 void mitk::BaseRenderer::PrintSelf(std::ostream &os, itk::Indent indent) const
787 {
788  os << indent << " MapperID: " << m_MapperID << std::endl;
789  os << indent << " Slice: " << m_Slice << std::endl;
790  os << indent << " TimeStep: " << m_TimeStep << std::endl;
791 
792  os << indent << " CurrentWorldPlaneGeometry: ";
793  if (m_CurrentWorldPlaneGeometry.IsNull())
794  os << "nullptr" << std::endl;
795  else
796  m_CurrentWorldPlaneGeometry->Print(os, indent);
797 
798  os << indent << " CurrentWorldPlaneGeometryUpdateTime: " << m_CurrentWorldPlaneGeometryUpdateTime << std::endl;
799  os << indent << " CurrentWorldPlaneGeometryTransformTime: " << m_CurrentWorldPlaneGeometryTransformTime << std::endl;
800 
801  Superclass::PrintSelf(os, indent);
802 }
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)
#define MITK_INFO
Definition: mitkLogMacros.h:22
static Pointer New()
void InsertSceneRenderer(vtkSmartPointer< vtkRenderer > renderer)
Base of all data objects.
Definition: mitkBaseData.h:39
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)
double ScalarType
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.
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.
Definition: mitkBaseData.h:52
static const MapperSlotId defaultMapper
Default mapper id to use.
Constants for most interaction classes, due to the generic StateMachines.
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 Pointer New()
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.
#define MITK_WARN
Definition: mitkLogMacros.h:23
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.
static Pointer New()
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.
static Pointer New()
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
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...
static Pointer New()
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...
static Pointer New()
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
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
static Pointer New()
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)