34 #include <vtkAssemblyNode.h> 35 #include <vtkAssemblyPath.h> 36 #include <vtkCamera.h> 37 #include <vtkCellPicker.h> 38 #include <vtkInteractorStyleTrackballCamera.h> 39 #include <vtkInformation.h> 41 #include <vtkLightKit.h> 42 #include <vtkLinearTransform.h> 43 #include <vtkMapper.h> 44 #include <vtkPointPicker.h> 46 #include <vtkRenderWindow.h> 47 #include <vtkRenderWindowInteractor.h> 48 #include <vtkRenderer.h> 49 #include <vtkRendererCollection.h> 50 #include <vtkSmartPointer.h> 51 #include <vtkTextActor.h> 52 #include <vtkTextProperty.h> 53 #include <vtkTransform.h> 54 #include <vtkWorldPointPicker.h> 58 m_CameraInitializedForMapperID(0)
62 m_WorldPointPicker = vtkWorldPointPicker::New();
64 m_PointPicker = vtkPointPicker::New();
65 m_PointPicker->SetTolerance(0.0025);
67 m_CellPicker = vtkCellPicker::New();
68 m_CellPicker->SetTolerance(0.0025);
71 m_CurrentWorldPlaneGeometryMapper = geometryMapper;
74 m_LightKit = vtkLightKit::New();
78 m_TextRenderer = vtkRenderer::New();
79 m_TextRenderer->SetRenderWindow(renWin);
80 m_TextRenderer->SetInteractive(0);
81 m_TextRenderer->SetErase(0);
95 if (m_LightKit !=
nullptr)
109 if (m_WorldPointPicker !=
nullptr)
110 m_WorldPointPicker->Delete();
111 if (m_PointPicker !=
nullptr)
112 m_PointPicker->Delete();
113 if (m_CellPicker !=
nullptr)
114 m_CellPicker->Delete();
115 if (m_TextRenderer !=
nullptr)
116 m_TextRenderer->Delete();
139 auto geometry =
m_DataStorage->ComputeVisibleBoundingGeometry3D(
nullptr,
"includeInBoundingBox");
141 if (geometry.IsNull())
168 this->PrepareMapperQueue();
170 this->PropagateRenderInfoToMappers();
174 for (
auto it = m_MappersMap.cbegin(); it != m_MappersMap.cend(); it++)
176 Mapper *mapper = (*it).second;
183 if (m_TextCollection.size() > 0)
185 m_TextRenderer->SetViewport(this->
GetVtkRenderer()->GetViewport());
186 for (
auto it = m_TextCollection.begin(); it != m_TextCollection.end(); ++it)
187 m_TextRenderer->AddViewProp((*it).second);
188 m_TextRenderer->Render();
200 void mitk::VtkPropRenderer::PrepareMapperQueue()
214 m_TextRenderer->RemoveAllViewProps();
216 for (
unsigned int i = 0; i < m_TextCollection.size(); i++)
218 m_TextCollection[i]->Delete();
220 m_TextCollection.clear();
223 m_MappersMap.clear();
231 DataStorage::SetOfObjects::ConstPointer allObjects =
m_DataStorage->GetAll();
233 for (DataStorage::SetOfObjects::ConstIterator it = allObjects->Begin(); it != allObjects->End(); ++it)
244 node->GetVisibility(visible,
this,
"visible");
247 if (mapper->IsLODEnabled(
this) && visible)
253 node->GetIntProperty(
"layer", layer,
this);
254 int nr = (layer << 16) + mapperNo;
255 m_MappersMap.insert(std::pair<int, Mapper *>(nr, mapper));
262 if (info == m_VtkRenderInfo)
265 m_VtkRenderInfo =
info;
266 this->PropagateRenderInfoToMappers();
269 void mitk::VtkPropRenderer::PropagateRenderInfoToMappers()
271 if (m_VtkRenderInfo ==
nullptr)
274 for (
const auto &mapEntry : m_MappersMap)
278 if (
nullptr != vtkMapper)
283 prop->SetPropertyKeys(m_VtkRenderInfo);
290 if (datatreenode !=
nullptr)
293 if (mapper.IsNotNull())
297 mapper->Update(
this);
299 auto *vtkmapper =
dynamic_cast<VtkMapper *
>(mapper.GetPointer());
300 if (vtkmapper !=
nullptr)
315 mitk::DataStorage::SetOfObjects::ConstPointer all =
m_DataStorage->GetAll();
316 for (mitk::DataStorage::SetOfObjects::ConstIterator it = all->Begin(); it != all->End(); ++it)
332 vtkCallbackCommand *renderCallbackCommand = vtkCallbackCommand::New();
334 renderWindow->GetInteractor()->AddObserver(vtkCommand::RenderEvent, renderCallbackCommand);
335 renderCallbackCommand->Delete();
337 if (renderWindow ==
nullptr)
339 m_InitNeeded =
false;
340 m_ResizeNeeded =
false;
345 m_ResizeNeeded =
true;
352 auto *renderWindowInteractor =
dynamic_cast<vtkRenderWindowInteractor *
>(caller);
353 if (!renderWindowInteractor)
377 int w = vtkObject::GetGlobalWarningDisplay();
378 vtkObject::GlobalWarningDisplayOff();
380 vtkObject::SetGlobalWarningDisplay(w);
386 std::string text,
double posX,
double posY,
double color1,
double color2,
double color3,
float opacity)
392 vtkTextActor *textActor = vtkTextActor::New();
394 textActor->SetDisplayPosition(posX, posY);
395 textActor->SetInput(text.c_str());
396 textActor->SetTextScaleModeToNone();
397 textActor->GetTextProperty()->SetColor(color1, color2, color3);
398 textActor->GetTextProperty()->SetOpacity(opacity);
399 int text_id = m_TextCollection.size();
400 m_TextCollection.insert(TextMapType::value_type(text_id, textActor));
432 switch (m_PickingMode)
436 m_WorldPointPicker->Pick(displayPoint[0], displayPoint[1], 0,
m_VtkRenderer);
437 vtk2itk(m_WorldPointPicker->GetPickPosition(), worldPoint);
442 m_PointPicker->Pick(displayPoint[0], displayPoint[1], 0,
m_VtkRenderer);
443 vtk2itk(m_PointPicker->GetPickPosition(), worldPoint);
448 m_CellPicker->Pick(displayPoint[0], displayPoint[1], 0,
m_VtkRenderer);
449 vtk2itk(m_CellPicker->GetPickPosition(), worldPoint);
459 m_CellPicker->InitializePickList();
463 DataStorage::SetOfObjects::ConstPointer allObjects =
m_DataStorage->GetAll();
464 for (DataStorage::SetOfObjects::ConstIterator it = allObjects->Begin(); it != allObjects->End(); ++it)
470 bool pickable =
false;
476 if (mapper ==
nullptr)
483 m_CellPicker->AddPickList(prop);
487 m_CellPicker->PickFromListOn();
488 m_CellPicker->Pick(displayPosition[0], displayPosition[1], 0.0,
m_VtkRenderer);
489 m_CellPicker->PickFromListOff();
491 vtk2itk(m_CellPicker->GetPickPosition(), worldPosition);
492 vtkProp *prop = m_CellPicker->GetViewProp();
501 for (DataStorage::SetOfObjects::ConstIterator it = allObjects->Begin(); it != allObjects->End(); ++it)
508 if (mapper ==
nullptr)
511 auto *vtkmapper =
dynamic_cast<VtkMapper *
>(mapper);
516 if (vtkmapper->HasVtkProp(prop, const_cast<mitk::VtkPropRenderer *>(
this)))
529 return this->m_TextCollection[text_id]->GetTextProperty();
537 this->m_Paths->InitTraversal();
548 if (GetMTime() > m_PathTime || (m_Paths !=
nullptr && m_Paths->GetMTime() > m_PathTime))
551 m_Paths = vtkSmartPointer<vtkAssemblyPaths>::New();
553 DataStorage::SetOfObjects::ConstPointer objects =
m_DataStorage->GetAll();
554 for (
auto iter = objects->begin(); iter != objects->end(); ++iter)
556 vtkSmartPointer<vtkAssemblyPath> onePath = vtkSmartPointer<vtkAssemblyPath>::New();
560 auto *vtkmapper =
dynamic_cast<VtkMapper *
>(mapper);
562 if (
nullptr != vtkmapper)
565 if (prop && prop->GetVisibility())
568 onePath->AddNode(prop, prop->GetMatrix());
569 m_Paths->AddItem(onePath);
575 m_PathTime.Modified();
582 return m_Paths->GetNumberOfItems();
587 return m_Paths ? m_Paths->GetNextItem() :
nullptr;
595 DataStorage::SetOfObjects::ConstPointer allObjects =
m_DataStorage->GetAll();
596 for (
auto iter = allObjects->begin(); iter != allObjects->end(); ++iter)
606 auto *vtkmapper =
dynamic_cast<VtkMapper *
>(mapper);
616 return m_WorldPointPicker;
621 return m_PointPicker;
642 void mitk::VtkPropRenderer::checkState()
653 MITK_INFO <<
"Multiple 3D Renderwindows active...: turning Immediate Rendering ON for legacy mappers";
666 MITK_INFO <<
"Single 3D Renderwindow active...: turning Immediate Rendering OFF for legacy mappers";
676 if (this->
GetMapperID() != m_CameraInitializedForMapperID)
678 Initialize2DvtkCamera();
683 bool mitk::VtkPropRenderer::Initialize2DvtkCamera()
688 this->
GetVtkRenderer()->GetActiveCamera()->SetParallelProjection(
false);
689 vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
690 vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
698 this->
GetVtkRenderer()->GetActiveCamera()->SetParallelProjection(
true);
703 vtkSmartPointer<mitkVtkInteractorStyle> style = vtkSmartPointer<mitkVtkInteractorStyle>::New();
vtkTextProperty * GetTextLabelProperty(int text_id)
CGetTextLabelProperty an be used in order to get a vtkTextProperty for a specific text_id...
static int glWorkAroundGlobalCount
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.
bool SetWorldGeometryToDataStorageBounds() override
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
virtual void MakeCurrent()
Activates the current renderwindow.
vtkRenderer * GetVtkRenderer() const
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.
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.
~VtkPropRenderer() override
Destructs the VtkPropRenderer.
void InitRenderer(vtkRenderWindow *renderwindow) override
This method is called from the two Constructors.
virtual void SetWorldTimeGeometry(const mitk::TimeGeometry *geometry)
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.
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
Base class of all Vtk Mappers in order to display primitives by exploiting Vtk functionality.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
unsigned long m_LastUpdateTime
Timestamp of last call of Update().
Base class of all mappers, Vtk as well as OpenGL mappers.
static void info(const char *fmt,...)
int MapperSlotId
MapperSlotId defines which kind of mapper (e.g. 2D or 3D) should be used.
static RenderingManager * GetInstance()
void SetPropertyKeys(vtkInformation *info)
Store/propagate vtkInformation during rendering.
virtual CameraController * GetCameraController()
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer)=0
virtual void InitSize(int w, int h)
Set the initial size. Called by RenderWindow after it has become visible for the first time...
virtual MapperSlotId GetMapperID()
Get the MapperSlotId to use.
virtual void SetMapperID(MapperSlotId _arg)
Set the MapperSlotId to use.
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)
vtkRenderWindow * m_RenderWindow
virtual bool GetEmptyWorldGeometry()
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)
unsigned int m_NumberOfVisibleLODEnabledMappers
Vtk-based mapper to display a PlaneGeometry in a 3D windowUses a PlaneGeometryDataToSurfaceFilter obj...
virtual bool IsValid() const
Is this BaseGeometry in a state that is valid?
void RequestUpdate(vtkRenderWindow *renderWindow)
mitk::Mapper * GetMapper(MapperSlotId id) const
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
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()
DataStorage::Pointer m_DataStorage
The DataStorage that is used for rendering.
const vtkPointPicker * GetPointPicker() 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.
void SetMapperID(const MapperSlotId mapperId) override
Set the MapperSlotId to use.
void Update() override
Call update of all mappers. To be implemented in subclasses.
void Resize(int w, int h) override
Resize the OpenGL Window.
DataNode::Pointer m_CurrentWorldPlaneGeometryNode
VtkPropRenderer(const char *name="VtkPropRenderer", vtkRenderWindow *renWin=nullptr)
itk::SmartPointer< CameraController > m_CameraController
CameraController for 3D rendering.
void AdjustCameraToPlane()
AdjustCameraToPlane Moves the camera of a 2D Renderwindow without panning or zooming, eg. only rotate the camera.
void Fit()
Fit Adjust the camera, so that the world bounding box is fully visible.
MapperSlotId m_MapperID
MapperSlotId to use. Defines which kind of mapper (e.g., 2D or 3D) shoud be used. ...
MappersMapType GetMappersMap() const
virtual void UpdatePaths()
const vtkWorldPointPicker * GetWorldPointPicker() const
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.
const vtkCellPicker * GetCellPicker() const