38 #include <vtkAssemblyNode.h>
39 #include <vtkAssemblyPath.h>
40 #include <vtkCamera.h>
41 #include <vtkCellPicker.h>
42 #include <vtkInteractorStyleTrackballCamera.h>
44 #include <vtkLightKit.h>
45 #include <vtkLinearTransform.h>
46 #include <vtkMapper.h>
47 #include <vtkPointPicker.h>
49 #include <vtkRenderWindow.h>
50 #include <vtkRenderWindowInteractor.h>
51 #include <vtkRenderer.h>
52 #include <vtkRendererCollection.h>
53 #include <vtkSmartPointer.h>
54 #include <vtkTextActor.h>
55 #include <vtkTextProperty.h>
56 #include <vtkTransform.h>
57 #include <vtkWorldPointPicker.h>
60 vtkRenderWindow *renWin,
63 :
BaseRenderer(name, renWin, rm, renderingMode), m_CameraInitializedForMapperID(0)
70 m_PointPicker->SetTolerance(0.0025);
73 m_CellPicker->SetTolerance(0.0025);
76 m_CurrentWorldPlaneGeometryMapper = geometryMapper;
84 m_TextRenderer->SetRenderWindow(renWin);
85 m_TextRenderer->SetInteractive(0);
86 m_TextRenderer->SetErase(0);
100 if (m_LightKit != NULL)
101 m_LightKit->Delete();
103 if (m_VtkRenderer != NULL)
105 m_CameraController = NULL;
107 m_VtkRenderer->Delete();
109 m_VtkRenderer = NULL;
112 m_CameraController = NULL;
114 if (m_WorldPointPicker != NULL)
115 m_WorldPointPicker->Delete();
116 if (m_PointPicker != NULL)
117 m_PointPicker->Delete();
118 if (m_CellPicker != NULL)
119 m_CellPicker->Delete();
120 if (m_TextRenderer != NULL)
121 m_TextRenderer->Delete();
135 this->SetWorldGeometryToDataStorageBounds();
146 if (geometry.IsNull())
149 this->SetWorldTimeGeometry(geometry);
150 this->GetVtkRenderer()->ResetCamera();
151 this->GetCameraController()->Fit();
164 this->UpdateOverlays();
166 if (this->GetEmptyWorldGeometry())
174 this->PrepareMapperQueue();
177 for (
auto it = m_MappersMap.cbegin(); it != m_MappersMap.cend(); it++)
179 Mapper *mapper = (*it).second;
184 this->UpdateOverlays();
189 if (m_TextCollection.size() > 0)
191 m_TextRenderer->SetViewport(this->GetVtkRenderer()->GetViewport());
192 for (TextMapType::iterator it = m_TextCollection.begin(); it != m_TextCollection.end(); ++it)
193 m_TextRenderer->AddViewProp((*it).second);
194 m_TextRenderer->Render();
206 void mitk::VtkPropRenderer::PrepareMapperQueue()
209 m_NumberOfVisibleLODEnabledMappers = 0;
212 if (m_LastUpdateTime < GetMTime() || m_LastUpdateTime < this->GetCurrentWorldPlaneGeometry()->GetMTime())
216 else if (m_MapperID >= 1 && m_MapperID < 6)
220 m_TextRenderer->RemoveAllViewProps();
222 for (
unsigned int i = 0; i < m_TextCollection.size(); i++)
224 m_TextCollection[i]->Delete();
226 m_TextCollection.clear();
229 m_MappersMap.clear();
239 for (DataStorage::SetOfObjects::ConstIterator it = allObjects->Begin(); it != allObjects->End(); ++it)
250 node->GetVisibility(visible,
this,
"visible");
253 if (mapper->IsLODEnabled(
this) && visible)
255 ++m_NumberOfVisibleLODEnabledMappers;
259 node->GetIntProperty(
"layer", layer,
this);
260 int nr = (layer << 16) + mapperNo;
261 m_MappersMap.insert(std::pair<int, Mapper *>(nr, mapper));
268 if (datatreenode != NULL)
271 if (mapper.IsNotNull())
273 if (GetCurrentWorldPlaneGeometry()->IsValid())
275 mapper->Update(
this);
278 if (vtkmapper != NULL)
294 for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin(); it != all->End(); ++it)
298 m_LastUpdateTime = GetMTime();
312 renderWindow->GetInteractor()->AddObserver(vtkCommand::RenderEvent, renderCallbackCommand);
313 renderCallbackCommand->Delete();
315 if (renderWindow == NULL)
317 m_InitNeeded =
false;
318 m_ResizeNeeded =
false;
323 m_ResizeNeeded =
true;
325 m_LastUpdateTime = 0;
330 vtkRenderWindowInteractor *renderWindowInteractor =
dynamic_cast<vtkRenderWindowInteractor *
>(caller);
331 if (!renderWindowInteractor)
344 m_RenderingManager->RequestUpdate(this->GetRenderWindow());
349 m_RenderWindow->SetSize(w, h);
350 Superclass::InitSize(w, h);
353 if (m_VtkRenderer != NULL)
355 int w = vtkObject::GetGlobalWarningDisplay();
356 vtkObject::GlobalWarningDisplayOff();
357 m_VtkRenderer->ResetCamera();
358 vtkObject::SetGlobalWarningDisplay(w);
360 this->GetCameraController()->Fit();
364 std::string text,
double posX,
double posY,
double color1,
double color2,
double color3,
float opacity)
366 this->GetVtkRenderer()->ViewToDisplay();
372 textActor->SetDisplayPosition(posX, posY);
373 textActor->SetInput(text.c_str());
374 textActor->SetTextScaleModeToNone();
375 textActor->GetTextProperty()->SetColor(color1, color2, color3);
376 textActor->GetTextProperty()->SetOpacity(opacity);
377 int text_id = m_TextCollection.size();
378 m_TextCollection.insert(TextMapType::value_type(text_id, textActor));
389 if (m_MapperID != mapperId)
390 Superclass::SetMapperID(mapperId);
401 if (m_RenderWindow != NULL)
402 m_RenderWindow->MakeCurrent();
407 if (this->GetRenderWindow()->GetNeverRendered() != 0)
410 switch (m_PickingMode)
412 case (WorldPointPicking):
414 m_WorldPointPicker->Pick(displayPoint[0], displayPoint[1], 0, m_VtkRenderer);
415 vtk2itk(m_WorldPointPicker->GetPickPosition(), worldPoint);
420 m_PointPicker->Pick(displayPoint[0], displayPoint[1], 0, m_VtkRenderer);
421 vtk2itk(m_PointPicker->GetPickPosition(), worldPoint);
426 m_CellPicker->Pick(displayPoint[0], displayPoint[1], 0, m_VtkRenderer);
427 vtk2itk(m_CellPicker->GetPickPosition(), worldPoint);
437 m_CellPicker->InitializePickList();
442 for (DataStorage::SetOfObjects::ConstIterator it = allObjects->Begin(); it != allObjects->End(); ++it)
448 bool pickable =
false;
461 m_CellPicker->AddPickList(prop);
465 m_CellPicker->PickFromListOn();
466 m_CellPicker->Pick(displayPosition[0], displayPosition[1], 0.0, m_VtkRenderer);
467 m_CellPicker->PickFromListOff();
469 vtk2itk(m_CellPicker->GetPickPosition(), worldPosition);
470 vtkProp *prop = m_CellPicker->GetViewProp();
479 for (DataStorage::SetOfObjects::ConstIterator it = allObjects->Begin(); it != allObjects->End(); ++it)
494 if (vtkmapper->
HasVtkProp(prop, const_cast<mitk::VtkPropRenderer *>(
this)))
507 return this->m_TextCollection[text_id]->GetTextProperty();
515 this->m_Paths->InitTraversal();
526 if (GetMTime() > m_PathTime || (m_Paths !=
nullptr && m_Paths->GetMTime() > m_PathTime))
532 for (DataStorage::SetOfObjects::const_iterator iter = objects->begin(); iter != objects->end(); ++iter)
541 if (prop && prop->GetVisibility())
544 onePath->AddNode(prop, prop->GetMatrix());
545 m_Paths->AddItem(onePath);
551 m_PathTime.Modified();
558 return m_Paths->GetNumberOfItems();
563 return m_Paths ? m_Paths->GetNextItem() : 0;
572 for (DataStorage::SetOfObjects::const_iterator iter = allObjects->begin(); iter != allObjects->end(); ++iter)
578 Mapper *mapper = node->GetMapper(m_MapperID);
592 return m_WorldPointPicker;
597 return m_PointPicker;
615 return glWorkAroundGlobalCount > 1;
618 void mitk::VtkPropRenderer::checkState()
620 if (m_MapperID == Standard3D)
625 glWorkAroundGlobalCount++;
627 if (glWorkAroundGlobalCount == 2)
629 MITK_INFO <<
"Multiple 3D Renderwindows active...: turning Immediate Rendering ON for legacy mappers";
639 glWorkAroundGlobalCount--;
640 if (glWorkAroundGlobalCount == 1)
642 MITK_INFO <<
"Single 3D Renderwindow active...: turning Immediate Rendering OFF for legacy mappers";
652 if (this->GetMapperID() != m_CameraInitializedForMapperID)
654 Initialize2DvtkCamera();
656 GetCameraController()->AdjustCameraToPlane();
659 bool mitk::VtkPropRenderer::Initialize2DvtkCamera()
661 if (this->GetMapperID() == Standard3D)
664 this->GetVtkRenderer()->GetActiveCamera()->SetParallelProjection(
false);
665 vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
667 this->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
668 this->GetRenderWindow()->GetInteractor()->EnableRenderOff();
669 m_CameraInitializedForMapperID = Standard3D;
671 else if (this->GetMapperID() == Standard2D)
674 this->GetVtkRenderer()->GetActiveCamera()->SetParallelProjection(
true);
677 this->GetVtkRenderer()->RemoveAllLights();
680 this->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
681 this->GetRenderWindow()->GetInteractor()->EnableRenderOff();
682 m_CameraInitializedForMapperID = Standard2D;
VtkPropRenderer(const char *name="VtkPropRenderer", vtkRenderWindow *renWin=nullptr, mitk::RenderingManager *rm=nullptr, mitk::BaseRenderer::RenderingMode::Type renderingMode=mitk::BaseRenderer::RenderingMode::Standard)
vtkTextProperty * GetTextLabelProperty(int text_id)
CGetTextLabelProperty an be used in order to get a vtkTextProperty for a specific text_id...
static int glWorkAroundGlobalCount
virtual mitk::DataNode * PickObject(const Point2D &displayPosition, Point3D &worldPosition) const override
Determines the object (mitk::DataNode) closest to the current position by means of picking...
std::map< int, Mapper * > MappersMapType
Data management class that handles 'was created by' relations.
virtual ~VtkPropRenderer()
Destructs the VtkPropRenderer.
virtual bool SetWorldGeometryToDataStorageBounds() override
const vtkCellPicker * GetCellPicker() const
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
virtual bool HasVtkProp(const vtkProp *prop, BaseRenderer *renderer)
Returns true if this mapper owns the specified vtkProp for the given BaseRenderer.
virtual void MakeCurrent()
Activates the current renderwindow.
virtual void SetDataStorage(mitk::DataStorage *storage) override
set the datastorage that will be used for rendering
virtual void SetDataStorage(DataStorage *storage)
set the datastorage that will be used for rendering
virtual void Resize(int w, int h)
Called to inform the renderer that the RenderWindow has been resized.
virtual void InitSize(int w, int h) override
Set the initial size. Called by RenderWindow after it has become visible for the first time...
Organizes the rendering process.
int WriteSimpleText(std::string text, double posX, double posY, double color1=0.0, double color2=1.0, double color3=0.0, float opacity=1.0)
WriteSimpleText Write a text in a renderwindow.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
virtual void InitRenderer(vtkRenderWindow *renderwindow) override
This method is called from the two Constructors.
static void Update(vtkPolyData *)
virtual void PickWorldPoint(const Point2D &displayPoint, Point3D &worldPoint) const override
Perform a picking: find the x,y,z world coordinate of a display x,y coordinate.
int Render(RenderType type)
Called by the vtkMitkRenderProp in order to start MITK rendering process.
const vtkWorldPointPicker * GetWorldPointPicker() const
Base class of all Vtk Mappers in order to display primitives by exploiting Vtk functionality.
Base class of all mappers, Vtk as well as OpenGL mappers.
MappersMapType GetMappersMap() const
itk::SmartPointer< const Self > ConstPointer
itk::SmartPointer< Self > Pointer
mitk::DataStorage::Pointer m_DataStorage
int MapperSlotId
MapperSlotId defines which kind of mapper (e.g., 2D or 3D) shoud be used.
Manager for coordinating the rendering process.
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer)=0
const vtkPointPicker * GetPointPicker() const
void InitPathTraversal()
Used by vtkPointPicker/vtkPicker. This will query a list of all objects in MITK and provide every vtk...
vtkRenderer * m_VtkRenderer
void vtk2itk(const Tin &in, Tout &out)
virtual void UpdateVtkTransform(mitk::BaseRenderer *renderer)
Set the vtkTransform of the m_Prop3D for the current time step of renderer.
static void RenderingCallback(vtkObject *caller, unsigned long eid, void *clientdata, void *calldata)
Vtk-based mapper to display a PlaneGeometry in a 3D windowUses a PlaneGeometryDataToSurfaceFilter obj...
virtual void PrepareRender()
This methods contains all method neceassary before a VTK Render() call.
virtual void MitkRender(mitk::BaseRenderer *renderer, mitk::VtkPropRenderer::RenderType type)=0
Responsible for calling the appropriate render functions. To be implemented in sub-classes.
static bool useImmediateModeRendering()
mitk::Mapper * GetMapper(MapperSlotId id) const
virtual void ReleaseGraphicsResources(mitk::BaseRenderer *)
Release vtk-based graphics resources that are being consumed by this mapper.
virtual void ReleaseGraphicsResources(vtkWindow *renWin)
Release vtk-based graphics resources. Called by vtkMitkRenderProp::ReleaseGraphicsResources.
virtual void SetMapperID(const MapperSlotId mapperId) override
Set the MapperSlotId to use.
virtual void Update() override
Call update of all mappers. To be implemented in subclasses.
virtual void Resize(int w, int h) override
Resize the OpenGL Window.
DataNode::Pointer m_CurrentWorldPlaneGeometryNode
virtual void UpdatePaths()
virtual void InitRenderer(vtkRenderWindow *renderwindow)
Initialize the renderer with a RenderWindow (renderwindow).
vtkAssemblyPath * GetNextPath()
Used by vtkPointPicker/vtkPicker. This will query a list of all objects in MITK and provide every vtk...
Class for nodes of the DataTree.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.