21 #include <vtkAppendPolyData.h> 22 #include <vtkCellArray.h> 23 #include <vtkConeSource.h> 24 #include <vtkCubeSource.h> 25 #include <vtkCylinderSource.h> 26 #include <vtkPolyDataAlgorithm.h> 27 #include <vtkPolyDataMapper.h> 28 #include <vtkPropAssembly.h> 29 #include <vtkProperty.h> 30 #include <vtkRenderer.h> 31 #include <vtkSphereSource.h> 32 #include <vtkTransform.h> 33 #include <vtkTransformPolyDataFilter.h> 34 #include <vtkTubeFilter.h> 35 #include <vtkVectorText.h> 105 bool isInputDevice =
false;
106 if (this->
GetDataNode()->GetBoolProperty(
"inputdevice", isInputDevice) && isInputDevice)
123 mitk::PointSet::DataType::Pointer itkPointSet = input->GetPointSet(timestep);
125 if (itkPointSet.GetPointer() ==
nullptr)
136 if (pointSizeProp.IsNotNull())
140 bool showLabel =
true;
142 const char *pointLabel =
nullptr;
145 if (dynamic_cast<mitk::StringProperty *>(this->
GetDataNode()->GetPropertyList()->GetProperty(
"label")) !=
nullptr)
153 int nbPoints = itkPointSet->GetPointData()->Size();
154 bool makeContour =
false;
157 bool closeContour =
false;
159 int contourPointLimit = 0;
163 contourPointLimit = nbPoints;
165 contourPointLimit = nbPoints - 1;
169 mitk::PointSet::PointsContainer::Iterator pointsIter;
174 vtkSmartPointer<vtkPoints> localPoints = vtkSmartPointer<vtkPoints>::New();
177 for (ptIdx = 0, pointsIter = itkPointSet->GetPoints()->Begin(); pointsIter != itkPointSet->GetPoints()->End();
178 pointsIter++, ptIdx++)
180 itk::Point<float> currentPoint = pointsIter->Value();
181 localPoints->InsertPoint(ptIdx, currentPoint[0], currentPoint[1], currentPoint[2]);
183 if (makeContour && ptIdx < contourPointLimit)
185 vtkIdType cell[2] = {(ptIdx + 1) % nbPoints, ptIdx};
201 bool pointDataBroken = (itkPointSet->GetPointData()->Size() != itkPointSet->GetPoints()->Size());
204 mitk::PointSet::PointDataContainer::Iterator pointDataIter = itkPointSet->GetPointData()->Begin();
205 for (ptIdx = 0; ptIdx < nbPoints; ++ptIdx)
207 double currentPoint[3];
209 vtkSmartPointer<vtkPolyDataAlgorithm> source;
214 if (itkPointSet->GetPointData()->size() == 0 || pointDataBroken)
217 pointType = pointDataIter.Value().pointSpec;
223 vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
225 sphere->SetCenter(currentPoint);
231 sphere->SetThetaResolution(10);
232 sphere->SetPhiResolution(10);
236 sphere->SetThetaResolution(20);
237 sphere->SetPhiResolution(20);
244 vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
248 cube->SetCenter(currentPoint);
254 vtkSmartPointer<vtkConeSource> cone = vtkSmartPointer<vtkConeSource>::New();
256 cone->SetCenter(currentPoint);
257 cone->SetResolution(20);
263 vtkSmartPointer<vtkCylinderSource> cylinder = vtkSmartPointer<vtkCylinderSource>::New();
265 cylinder->SetCenter(currentPoint);
266 cylinder->SetResolution(20);
272 vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
276 sphere->SetThetaResolution(20);
277 sphere->SetPhiResolution(20);
283 vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
285 sphere->SetCenter(currentPoint);
286 sphere->SetThetaResolution(20);
287 sphere->SetPhiResolution(20);
293 if (pointDataIter.Value().selected && !pointDataBroken)
306 std::string l = pointLabel;
307 if (input->GetSize() > 1)
309 sprintf(buffer,
"%d", ptIdx + 1);
313 vtkSmartPointer<vtkVectorText> label = vtkSmartPointer<vtkVectorText>::New();
314 label->SetText(l.c_str());
317 vtkSmartPointer<vtkTransform> aLabelTransform = vtkSmartPointer<vtkTransform>::New();
318 aLabelTransform->Identity();
319 aLabelTransform->Translate(currentPoint[0] + 2, currentPoint[1] + 2, currentPoint[2]);
320 aLabelTransform->Scale(5.7, 5.7, 5.7);
323 vtkSmartPointer<vtkTransformPolyDataFilter> labelTransform = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
324 labelTransform->SetTransform(aLabelTransform);
325 labelTransform->SetInputConnection(label->GetOutputPort());
340 if (pointDataIter != itkPointSet->GetPointData()->End())
386 if (!needGenerateData)
391 needGenerateData =
true;
395 if (needGenerateData)
403 bool showPoints =
true;
409 if (
false && dynamic_cast<mitk::FloatProperty *>(this->
GetDataNode()->GetProperty(
"opacity")) !=
nullptr)
413 float opacity = pointOpacity->GetValue();
419 bool showContour =
false;
445 double unselectedColor[4] = {1.0f, 1.0f, 0.0f, 1.0f};
447 double contourColor[4] = {1.0f, 0.0f, 0.0f, 1.0f};
451 double opacity = 1.0;
454 if (dynamic_cast<mitk::ColorProperty *>(
455 this->
GetDataNode()->GetPropertyList(renderer)->GetProperty(
"unselectedcolor")) !=
nullptr)
460 unselectedColor[0] = tmpColor[0];
461 unselectedColor[1] = tmpColor[1];
462 unselectedColor[2] = tmpColor[2];
463 unselectedColor[3] = 1.0f;
465 else if (dynamic_cast<mitk::ColorProperty *>(
466 this->
GetDataNode()->GetPropertyList(
nullptr)->GetProperty(
"unselectedcolor")) !=
nullptr)
471 unselectedColor[0] = tmpColor[0];
472 unselectedColor[1] = tmpColor[1];
473 unselectedColor[2] = tmpColor[2];
474 unselectedColor[3] = 1.0f;
479 float unselectedColorTMP[4] = {1.0f, 1.0f, 0.0f, 1.0f};
481 unselectedColor[0] = unselectedColorTMP[0];
482 unselectedColor[1] = unselectedColorTMP[1];
483 unselectedColor[2] = unselectedColorTMP[2];
488 if (dynamic_cast<mitk::ColorProperty *>(
489 this->
GetDataNode()->GetPropertyList(renderer)->GetProperty(
"selectedcolor")) !=
nullptr)
494 selectedColor[0] = tmpColor[0];
495 selectedColor[1] = tmpColor[1];
496 selectedColor[2] = tmpColor[2];
497 selectedColor[3] = 1.0f;
499 else if (dynamic_cast<mitk::ColorProperty *>(
500 this->
GetDataNode()->GetPropertyList(
nullptr)->GetProperty(
"selectedcolor")) !=
nullptr)
505 selectedColor[0] = tmpColor[0];
506 selectedColor[1] = tmpColor[1];
507 selectedColor[2] = tmpColor[2];
508 selectedColor[3] = 1.0f;
512 if (dynamic_cast<mitk::ColorProperty *>(
513 this->
GetDataNode()->GetPropertyList(renderer)->GetProperty(
"contourcolor")) !=
nullptr)
518 contourColor[0] = tmpColor[0];
519 contourColor[1] = tmpColor[1];
520 contourColor[2] = tmpColor[2];
521 contourColor[3] = 1.0f;
523 else if (dynamic_cast<mitk::ColorProperty *>(
524 this->
GetDataNode()->GetPropertyList(
nullptr)->GetProperty(
"contourcolor")) !=
nullptr)
529 contourColor[0] = tmpColor[0];
530 contourColor[1] = tmpColor[1];
531 contourColor[2] = tmpColor[2];
532 contourColor[3] = 1.0f;
535 if (dynamic_cast<mitk::FloatProperty *>(this->
GetDataNode()->GetPropertyList(renderer)->GetProperty(
"opacity")) !=
540 opacity = pointOpacity->GetValue();
542 else if (dynamic_cast<mitk::FloatProperty *>(this->
GetDataNode()->GetPropertyList(
nullptr)->GetProperty(
"opacity")) !=
547 opacity = pointOpacity->GetValue();
552 bool showContour =
false;
570 vtkSmartPointer<vtkAppendPolyData> vtkContourPolyData = vtkSmartPointer<vtkAppendPolyData>::New();
571 vtkSmartPointer<vtkPolyDataMapper> vtkContourPolyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
573 vtkSmartPointer<vtkPolyData> contour = vtkSmartPointer<vtkPolyData>::New();
574 contour->SetPoints(points);
575 contour->SetLines(m_PointConnections);
577 vtkSmartPointer<vtkTubeFilter> tubeFilter = vtkSmartPointer<vtkTubeFilter>::New();
578 tubeFilter->SetNumberOfSides(12);
579 tubeFilter->SetInputData(contour);
586 if (contourSizeProp.IsNotNull())
590 tubeFilter->Update();
593 vtkContourPolyData->AddInputConnection(tubeFilter->GetOutputPort());
594 vtkContourPolyDataMapper->SetInputConnection(vtkContourPolyData->GetOutputPort());
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr, bool fallBackOnDataProperties=true) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
vtkSmartPointer< vtkPropAssembly > m_PointsAssembly
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
unsigned int m_NumberOfSelectedAdded
Base class for mapper specific rendering ressources.
void ReleaseGraphicsResources(vtkWindow *renWin)
LocalStorageHandler< BaseLocalStorage > m_LSH
unsigned long GetMTime() const override
Get the timestamp of the last change of the map or the last change of one of the properties store in ...
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Mapper *mapper, mitk::DataNode *dataNode) const
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
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)
vtkSmartPointer< vtkPolyDataMapper > m_VtkUnselectedPolyDataMapper
Organizes the rendering process.
vtkSmartPointer< vtkActor > m_ContourActor
void ApplyColorAndOpacityProperties(mitk::BaseRenderer *renderer, vtkActor *actor) override
Apply color and opacity properties read from the PropertyList. Called by mapper subclasses.
virtual const mitk::PointSet * GetInput()
vtkSmartPointer< vtkAppendPolyData > m_vtkUnselectedPointList
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
vtkSmartPointer< vtkAppendPolyData > m_vtkTextList
static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
virtual void CreateVTKRenderObjects()
virtual void ApplyAllProperties(mitk::BaseRenderer *renderer, vtkActor *actor)
virtual void CreateContour(vtkPoints *points, vtkCellArray *connections)
The ColorProperty class RGB color property.
vtkSmartPointer< vtkPolyDataMapper > m_VtkSelectedPolyDataMapper
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
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 ...
vtkSmartPointer< vtkActor > m_UnselectedActor
Data structure which stores a set of points. Superclass of mitk::Mesh.
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
mitk::DataNode * m_DataNode
bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey="visible") const
Convenience access method for visibility properties (instances of BoolProperty with property-key "vis...
ScalarType m_ContourRadius
vtkLinearTransform * GetVtkTransform(int t=0) const
Get the transformation applied prior to displaying the data as a vtkTransform.
itk::TimeStamp & GetLastGenerateDataTime()
vtkSmartPointer< vtkPoints > m_WorldPositions
All point positions, already in world coordinates.
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
mitk::PropertyList * GetPropertyList(const mitk::BaseRenderer *renderer=nullptr) const
Get the PropertyList of the renderer. If renderer is nullptr, the BaseRenderer-independent PropertyLi...
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
void UpdateGenerateDataTime()
unsigned int m_NumberOfUnselectedAdded
vtkSmartPointer< vtkActor > m_SelectedActor
const float selectedColor[]
int GetTimestep() const
Returns the current time step as calculated from the renderer.
vtkSmartPointer< vtkAppendPolyData > m_vtkSelectedPointList
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
~PointSetVtkMapper3D() override
vtkSmartPointer< vtkCellArray > m_PointConnections
All connections between two points (used for contour drawing)
void UpdateVtkTransform(mitk::BaseRenderer *renderer) override
Set the vtkTransform of the m_Prop3D for the current time step of renderer.
vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
Class for nodes of the DataTree.
static void SetDefaultProperties(DataNode *node, BaseRenderer *renderer=nullptr, bool overwrite=false)
Set default values of properties used by this mapper to node.