25 #include <vtkAppendPolyData.h>
26 #include <vtkCellArray.h>
27 #include <vtkConeSource.h>
28 #include <vtkCubeSource.h>
29 #include <vtkCylinderSource.h>
30 #include <vtkPolyDataAlgorithm.h>
31 #include <vtkPolyDataMapper.h>
32 #include <vtkPropAssembly.h>
33 #include <vtkProperty.h>
34 #include <vtkRenderer.h>
35 #include <vtkSphereSource.h>
36 #include <vtkTransform.h>
37 #include <vtkTransformPolyDataFilter.h>
38 #include <vtkTubeFilter.h>
39 #include <vtkVectorText.h>
53 : m_vtkSelectedPointList(NULL),
54 m_vtkUnselectedPointList(NULL),
55 m_VtkSelectedPolyDataMapper(NULL),
56 m_VtkUnselectedPolyDataMapper(NULL),
58 m_NumberOfSelectedAdded(0),
59 m_NumberOfUnselectedAdded(0),
62 m_VertexRendering(false)
79 m_PointsAssembly->ReleaseGraphicsResources(renWin);
81 m_SelectedActor->ReleaseGraphicsResources(renWin);
82 m_UnselectedActor->ReleaseGraphicsResources(renWin);
83 m_ContourActor->ReleaseGraphicsResources(renWin);
88 m_PointsAssembly->ReleaseGraphicsResources(renderer->
GetRenderWindow());
91 m_UnselectedActor->ReleaseGraphicsResources(renderer->
GetRenderWindow());
100 m_PointsAssembly->VisibilityOn();
102 if (m_PointsAssembly->GetParts()->IsItemPresent(m_SelectedActor))
103 m_PointsAssembly->RemovePart(m_SelectedActor);
104 if (m_PointsAssembly->GetParts()->IsItemPresent(m_UnselectedActor))
105 m_PointsAssembly->RemovePart(m_UnselectedActor);
106 if (m_PointsAssembly->GetParts()->IsItemPresent(m_ContourActor))
107 m_PointsAssembly->RemovePart(m_ContourActor);
111 bool isInputDevice =
false;
112 if (this->GetDataNode()->GetBoolProperty(
"inputdevice", isInputDevice) && isInputDevice)
123 this->GetDataNode()->GetBoolProperty(
"updateDataOnRender", update);
127 int timestep = this->GetTimestep();
131 if (itkPointSet.GetPointer() == NULL)
133 m_PointsAssembly->VisibilityOff();
142 if (pointSizeProp.IsNotNull())
143 m_PointSize = pointSizeProp->GetValue();
146 bool showLabel =
true;
147 this->GetDataNode()->GetBoolProperty(
"show label", showLabel);
148 const char *pointLabel = NULL;
151 if (dynamic_cast<mitk::StringProperty *>(this->GetDataNode()->GetPropertyList()->GetProperty(
"label")) != NULL)
153 dynamic_cast<mitk::StringProperty *
>(this->GetDataNode()->GetPropertyList()->GetProperty(
"label"))->GetValue();
159 int nbPoints = itkPointSet->GetPointData()->Size();
160 bool makeContour =
false;
161 this->GetDataNode()->GetBoolProperty(
"show contour", makeContour);
163 bool closeContour =
false;
164 this->GetDataNode()->GetBoolProperty(
"close contour", closeContour);
165 int contourPointLimit = 0;
169 contourPointLimit = nbPoints;
171 contourPointLimit = nbPoints - 1;
175 mitk::PointSet::PointsContainer::Iterator pointsIter;
178 m_NumberOfSelectedAdded = 0;
179 m_NumberOfUnselectedAdded = 0;
183 for (ptIdx = 0, pointsIter = itkPointSet->GetPoints()->Begin(); pointsIter != itkPointSet->GetPoints()->End();
184 pointsIter++, ptIdx++)
186 itk::Point<float> currentPoint = pointsIter->Value();
187 localPoints->InsertPoint(ptIdx, currentPoint[0], currentPoint[1], currentPoint[2]);
189 if (makeContour && ptIdx < contourPointLimit)
191 vtkIdType cell[2] = {(ptIdx + 1) % nbPoints, ptIdx};
192 m_PointConnections->InsertNextCell(2, cell);
196 vtkSmartPointer<vtkLinearTransform> vtktransform = this->GetDataNode()->GetVtkTransform(this->GetTimestep());
197 vtktransform->TransformPoints(localPoints, m_WorldPositions);
202 this->CreateContour(m_WorldPositions, m_PointConnections);
207 bool pointDataBroken = (itkPointSet->GetPointData()->Size() != itkPointSet->GetPoints()->Size());
210 mitk::PointSet::PointDataContainer::Iterator pointDataIter = itkPointSet->GetPointData()->Begin();
211 for (ptIdx = 0; ptIdx < nbPoints; ++ptIdx)
213 double currentPoint[3];
214 m_WorldPositions->GetPoint(ptIdx, currentPoint);
215 vtkSmartPointer<vtkPolyDataAlgorithm> source;
220 if (itkPointSet->GetPointData()->size() == 0 || pointDataBroken)
223 pointType = pointDataIter.Value().pointSpec;
230 sphere->SetRadius(m_PointSize / 2.0f);
231 sphere->SetCenter(currentPoint);
237 sphere->SetThetaResolution(10);
238 sphere->SetPhiResolution(10);
242 sphere->SetThetaResolution(20);
243 sphere->SetPhiResolution(20);
251 cube->SetXLength(m_PointSize / 2);
252 cube->SetYLength(m_PointSize / 2);
253 cube->SetZLength(m_PointSize / 2);
254 cube->SetCenter(currentPoint);
261 cone->SetRadius(m_PointSize / 2.0f);
262 cone->SetCenter(currentPoint);
263 cone->SetResolution(20);
270 cylinder->SetRadius(m_PointSize / 2.0f);
271 cylinder->SetCenter(currentPoint);
272 cylinder->SetResolution(20);
279 sphere->SetRadius(m_PointSize / 2.0f);
282 sphere->SetThetaResolution(20);
283 sphere->SetPhiResolution(20);
290 sphere->SetRadius(m_PointSize / 2.0f);
291 sphere->SetCenter(currentPoint);
292 sphere->SetThetaResolution(20);
293 sphere->SetPhiResolution(20);
299 if (pointDataIter.Value().selected && !pointDataBroken)
301 m_vtkSelectedPointList->AddInputConnection(source->GetOutputPort());
302 ++m_NumberOfSelectedAdded;
306 m_vtkUnselectedPointList->AddInputConnection(source->GetOutputPort());
307 ++m_NumberOfUnselectedAdded;
312 std::string l = pointLabel;
313 if (input->GetSize() > 1)
315 sprintf(buffer,
"%d", ptIdx + 1);
320 label->SetText(l.c_str());
324 aLabelTransform->Identity();
325 aLabelTransform->Translate(currentPoint[0] + 2, currentPoint[1] + 2, currentPoint[2]);
326 aLabelTransform->Scale(5.7, 5.7, 5.7);
330 labelTransform->SetTransform(aLabelTransform);
331 labelTransform->SetInputConnection(label->GetOutputPort());
336 m_vtkSelectedPointList->AddInputConnection(labelTransform->GetOutputPort());
337 ++m_NumberOfSelectedAdded;
341 m_vtkUnselectedPointList->AddInputConnection(labelTransform->GetOutputPort());
342 ++m_NumberOfUnselectedAdded;
346 if (pointDataIter != itkPointSet->GetPointData()->End())
351 if (m_NumberOfSelectedAdded > 0)
354 m_VtkSelectedPolyDataMapper->SetInputConnection(m_vtkSelectedPointList->GetOutputPort());
359 m_SelectedActor->SetMapper(m_VtkSelectedPolyDataMapper);
360 m_PointsAssembly->AddPart(m_SelectedActor);
363 if (m_NumberOfUnselectedAdded > 0)
366 m_VtkUnselectedPolyDataMapper->SetInputConnection(m_vtkUnselectedPointList->GetOutputPort());
371 m_UnselectedActor->SetMapper(m_VtkUnselectedPolyDataMapper);
372 m_PointsAssembly->AddPart(m_UnselectedActor);
383 this->GetDataNode()->GetBoolProperty(
"updateDataOnRender", update);
386 int timestep = this->GetTimestep();
391 m_UnselectedActor->VisibilityOff();
392 m_SelectedActor->VisibilityOff();
398 if (pointSizeProp.IsNotNull())
399 m_PointSize = pointSizeProp->GetValue();
401 double *color = m_UnselectedActor->GetProperty()->GetColor();
402 double opacity = m_UnselectedActor->GetProperty()->GetOpacity();
404 glClearColor(0.0, 0.0, 0.0, 0.0);
405 glDisable(GL_COLOR_MATERIAL);
406 glDisable(GL_LIGHTING);
407 glEnable(GL_POINT_SMOOTH);
409 glPointSize(m_PointSize);
412 glColor4d(color[0], color[1], color[2], opacity);
414 for (
auto pointsIter = itkPointSet->GetPoints()->Begin(); pointsIter != itkPointSet->GetPoints()->End(); pointsIter++)
416 const itk::Point<mitk::ScalarType> &point = pointsIter->Value();
417 glVertex3d(point[0], point[1], point[2]);
424 glDisable(GL_POINT_SMOOTH);
425 glEnable(GL_COLOR_MATERIAL);
426 glEnable(GL_LIGHTING);
432 GetDataNode()->GetVisibility(visible, renderer,
"visible");
435 m_UnselectedActor->VisibilityOff();
436 m_SelectedActor->VisibilityOff();
437 m_ContourActor->VisibilityOff();
443 SetVtkMapperImmediateModeRendering(m_VtkSelectedPolyDataMapper);
444 SetVtkMapperImmediateModeRendering(m_VtkUnselectedPolyDataMapper);
449 if (!needGenerateData)
456 bool useVertexRendering =
false;
457 this->GetDataNode()->GetBoolProperty(
"Vertex Rendering", useVertexRendering);
460 if (pointSizeProp && m_PointSize != pointSizeProp->
GetValue())
461 needGenerateData =
true;
462 if (contourSizeProp && m_ContourRadius != contourSizeProp->
GetValue())
463 needGenerateData =
true;
467 if (useVertexRendering && m_VertexRendering != useVertexRendering)
469 needGenerateData =
false;
470 m_VertexRendering =
true;
472 else if (!useVertexRendering && m_VertexRendering)
474 m_VertexRendering =
false;
475 needGenerateData =
true;
479 if (needGenerateData)
481 this->CreateVTKRenderObjects();
485 this->ApplyAllProperties(renderer, m_ContourActor);
487 bool showPoints =
true;
488 this->GetDataNode()->GetBoolProperty(
"show points", showPoints);
490 m_UnselectedActor->SetVisibility(showPoints && !m_VertexRendering);
491 m_SelectedActor->SetVisibility(showPoints && !m_VertexRendering);
493 if (
false && dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty(
"opacity")) != NULL)
497 float opacity = pointOpacity->GetValue();
498 m_ContourActor->GetProperty()->SetOpacity(opacity);
499 m_UnselectedActor->GetProperty()->SetOpacity(opacity);
500 m_SelectedActor->GetProperty()->SetOpacity(opacity);
503 bool showContour =
false;
504 this->GetDataNode()->GetBoolProperty(
"show contour", showContour);
505 m_ContourActor->SetVisibility(showContour);
508 if (m_VertexRendering)
517 m_PointsAssembly->VisibilityOff();
522 return m_PointsAssembly;
531 Superclass::ApplyColorAndOpacityProperties(renderer, actor);
536 double unselectedColor[4] = {1.0f, 1.0f, 0.0f, 1.0f};
538 double contourColor[4] = {1.0f, 0.0f, 0.0f, 1.0f};
542 double opacity = 1.0;
545 if (dynamic_cast<mitk::ColorProperty *>(
546 this->GetDataNode()->GetPropertyList(renderer)->GetProperty(
"unselectedcolor")) != NULL)
549 this->GetDataNode()->GetPropertyList(renderer)->GetProperty(
"unselectedcolor"))
551 unselectedColor[0] = tmpColor[0];
552 unselectedColor[1] = tmpColor[1];
553 unselectedColor[2] = tmpColor[2];
554 unselectedColor[3] = 1.0f;
556 else if (dynamic_cast<mitk::ColorProperty *>(
557 this->GetDataNode()->GetPropertyList(NULL)->GetProperty(
"unselectedcolor")) != NULL)
560 dynamic_cast<mitk::ColorProperty *
>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty(
"unselectedcolor"))
562 unselectedColor[0] = tmpColor[0];
563 unselectedColor[1] = tmpColor[1];
564 unselectedColor[2] = tmpColor[2];
565 unselectedColor[3] = 1.0f;
570 float unselectedColorTMP[4] = {1.0f, 1.0f, 0.0f, 1.0f};
571 m_DataNode->
GetColor(unselectedColorTMP, NULL);
572 unselectedColor[0] = unselectedColorTMP[0];
573 unselectedColor[1] = unselectedColorTMP[1];
574 unselectedColor[2] = unselectedColorTMP[2];
579 if (dynamic_cast<mitk::ColorProperty *>(
580 this->GetDataNode()->GetPropertyList(renderer)->GetProperty(
"selectedcolor")) != NULL)
583 dynamic_cast<mitk::ColorProperty *
>(this->GetDataNode()->GetPropertyList(renderer)->GetProperty(
"selectedcolor"))
585 selectedColor[0] = tmpColor[0];
586 selectedColor[1] = tmpColor[1];
587 selectedColor[2] = tmpColor[2];
588 selectedColor[3] = 1.0f;
590 else if (dynamic_cast<mitk::ColorProperty *>(
591 this->GetDataNode()->GetPropertyList(NULL)->GetProperty(
"selectedcolor")) != NULL)
594 dynamic_cast<mitk::ColorProperty *
>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty(
"selectedcolor"))
596 selectedColor[0] = tmpColor[0];
597 selectedColor[1] = tmpColor[1];
598 selectedColor[2] = tmpColor[2];
599 selectedColor[3] = 1.0f;
603 if (dynamic_cast<mitk::ColorProperty *>(
604 this->GetDataNode()->GetPropertyList(renderer)->GetProperty(
"contourcolor")) != NULL)
607 dynamic_cast<mitk::ColorProperty *
>(this->GetDataNode()->GetPropertyList(renderer)->GetProperty(
"contourcolor"))
609 contourColor[0] = tmpColor[0];
610 contourColor[1] = tmpColor[1];
611 contourColor[2] = tmpColor[2];
612 contourColor[3] = 1.0f;
614 else if (dynamic_cast<mitk::ColorProperty *>(
615 this->GetDataNode()->GetPropertyList(NULL)->GetProperty(
"contourcolor")) != NULL)
618 dynamic_cast<mitk::ColorProperty *
>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty(
"contourcolor"))
620 contourColor[0] = tmpColor[0];
621 contourColor[1] = tmpColor[1];
622 contourColor[2] = tmpColor[2];
623 contourColor[3] = 1.0f;
626 if (dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetPropertyList(renderer)->GetProperty(
"opacity")) !=
630 dynamic_cast<mitk::FloatProperty *
>(this->GetDataNode()->GetPropertyList(renderer)->GetProperty(
"opacity"));
631 opacity = pointOpacity->GetValue();
633 else if (dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty(
"opacity")) !=
637 dynamic_cast<mitk::FloatProperty *
>(this->GetDataNode()->GetPropertyList(NULL)->GetProperty(
"opacity"));
638 opacity = pointOpacity->GetValue();
643 bool showContour =
false;
644 this->GetDataNode()->GetBoolProperty(
"show contour", showContour, renderer);
645 if (showContour && (m_ContourActor != NULL))
647 this->CreateContour(m_WorldPositions, m_PointConnections);
648 m_ContourActor->GetProperty()->SetColor(contourColor);
649 m_ContourActor->GetProperty()->SetOpacity(opacity);
652 m_SelectedActor->GetProperty()->SetColor(selectedColor);
653 m_SelectedActor->GetProperty()->SetOpacity(opacity);
655 m_UnselectedActor->GetProperty()->SetColor(unselectedColor);
656 m_UnselectedActor->GetProperty()->SetOpacity(opacity);
665 contour->SetPoints(points);
666 contour->SetLines(m_PointConnections);
669 tubeFilter->SetNumberOfSides(12);
670 tubeFilter->SetInputData(contour);
673 m_ContourRadius = 0.5;
677 if (contourSizeProp.IsNotNull())
678 m_ContourRadius = contourSizeProp->GetValue();
680 tubeFilter->SetRadius(m_ContourRadius);
681 tubeFilter->Update();
684 vtkContourPolyData->AddInputConnection(tubeFilter->GetOutputPort());
685 vtkContourPolyDataMapper->SetInputConnection(vtkContourPolyData->GetOutputPort());
687 m_ContourActor->SetMapper(vtkContourPolyDataMapper);
688 m_PointsAssembly->AddPart(m_ContourActor);
705 Superclass::SetDefaultProperties(node, renderer, overwrite);
vtkSmartPointer< vtkPropAssembly > m_PointsAssembly
itk::SmartPointer< Self > Pointer
Base class for mapper specific rendering ressources.
void ReleaseGraphicsResources(vtkWindow *renWin)
virtual void ResetMapper(BaseRenderer *renderer) override
Reset the mapper (i.e., make sure that nothing is displayed) if no valid data is present. In most cases the reimplemented function disables the according actors (toggling visibility off)
Organizes the rendering process.
vtkSmartPointer< vtkActor > m_ContourActor
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual const mitk::PointSet * GetInput()
virtual void CreateVTKRenderObjects()
virtual void ApplyAllProperties(mitk::BaseRenderer *renderer, vtkActor *actor)
virtual void CreateContour(vtkPoints *points, vtkCellArray *connections)
The ColorProperty class RGB color property.
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Mapper *mapper, mitk::DataNode *dataNode) const
vtkSmartPointer< vtkActor > m_UnselectedActor
Data structure which stores a set of points. Superclass of mitk::Mesh.
virtual void VertexRendering()
virtual ~PointSetVtkMapper3D()
const mitk::Color & GetColor() const
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer=NULL, bool overwrite=false)
void UpdateGenerateDataTime()
vtkSmartPointer< vtkActor > m_SelectedActor
const float selectedColor[]
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
virtual void UpdateVtkTransform(mitk::BaseRenderer *renderer) override
Set the vtkTransform of the m_Prop3D for the current time step of renderer.
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
Class for nodes of the DataTree.
virtual T GetValue() const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.