22 #include <vtkCellArray.h>
23 #include <vtkIdList.h>
24 #include <vtkPoints.h>
25 #include <vtkPolyData.h>
26 #include <vtkPolyDataMapper.h>
27 #include <vtkPolyLine.h>
28 #include <vtkPolygon.h>
30 mitk::PlanarFigureVtkMapper3D::LocalStorage::LocalStorage() : m_Actor(vtkSmartPointer<vtkActor>::
New()), m_LastMTime(0)
34 mitk::PlanarFigureVtkMapper3D::LocalStorage::~LocalStorage()
44 mitk::PlanarFigureVtkMapper3D::PlanarFigureVtkMapper3D() : m_FillPf(false)
48 mitk::PlanarFigureVtkMapper3D::~PlanarFigureVtkMapper3D()
62 bool selected =
false;
66 dataNode->
GetColor(color, renderer, selected ?
"planarfigure.selected.line.color" :
"color");
71 vtkProperty *
property = actor->GetProperty();
72 property->SetColor(color[0], color[1], color[2]);
73 property->SetOpacity(opacity);
89 actor->SetVisibility(render);
91 float lineWidth = 1.0f;
94 vtkProperty *
property = actor->GetProperty();
95 property->SetLineWidth(lineWidth);
98 void mitk::PlanarFigureVtkMapper3D::GenerateDataForRenderer(
BaseRenderer *renderer)
102 const DataNode *node = this->GetDataNode();
109 if (planarFigure == NULL || !planarFigure->
IsPlaced())
112 LocalStorage *localStorage = m_LocalStorageHandler.GetLocalStorage(renderer);
113 unsigned long mTime = planarFigure->
GetMTime();
116 bool refresh =
false;
118 if (m_FillPf != fillPf)
124 if (mTime > localStorage->m_LastMTime || refresh)
126 localStorage->m_LastMTime = mTime;
128 const PlaneGeometry *planeGeometry =
dynamic_cast<const PlaneGeometry *
>(planarFigure->
GetPlaneGeometry());
129 const AbstractTransformGeometry *abstractTransformGeometry =
130 dynamic_cast<const AbstractTransformGeometry *
>(planarFigure->
GetPlaneGeometry());
132 if (planeGeometry == NULL && abstractTransformGeometry == NULL)
137 if (numPolyLines == 0)
143 vtkIdType baseIndex = 0;
145 for (
size_t i = 0; i < numPolyLines; ++i)
147 const PolyLine polyLine = planarFigure->
GetPolyLine(i);
148 const vtkIdType numPoints = polyLine.size();
155 PolyLine::const_iterator polyLineEnd = polyLine.cend();
157 for (PolyLine::const_iterator polyLineIt = polyLine.cbegin(); polyLineIt != polyLineEnd; ++polyLineIt)
160 planeGeometry->Map(*polyLineIt, point);
161 points->InsertNextPoint(point.GetDataPointer());
163 const vtkIdType
id = polygon->GetPoints()->InsertNextPoint(point[0], point[1], point[2]);
164 polygon->GetPointIds()->InsertNextId(
id);
169 vtkIdList *pointIds = line->GetPointIds();
171 if (planarFigure->
IsClosed() && numPoints > 2)
173 polygons->InsertNextCell(polygon);
174 pointIds->SetNumberOfIds(numPoints + 1);
175 pointIds->SetId(numPoints, baseIndex);
179 pointIds->SetNumberOfIds(numPoints);
182 for (vtkIdType j = 0; j < numPoints; ++j)
183 pointIds->SetId(j, baseIndex + j);
185 cells->InsertNextCell(line);
187 baseIndex += points->GetNumberOfPoints();
191 polyData->SetPoints(points);
192 polyData->SetLines(cells);
194 polyData->SetPolys(polygons);
197 mapper->SetInputData(polyData);
199 localStorage->m_Actor->SetMapper(mapper);
202 this->ApplyColorAndOpacityProperties(renderer, localStorage->m_Actor);
203 this->ApplyPlanarFigureProperties(renderer, localStorage->m_Actor);
208 return m_LocalStorageHandler.GetLocalStorage(renderer)->m_Actor;
Organizes the rendering process.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
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 ...
bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
bool GetFloatProperty(const char *propertyKey, float &floatValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for float properties (instances of FloatProperty)
virtual unsigned long GetMTime() const override
Get the modified time of the last change of the contents this data object or its geometry.
Point< ScalarType, 3 > Point3D
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
Class for nodes of the DataTree.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.