18 #include <vtkCellArray.h> 19 #include <vtkIdList.h> 20 #include <vtkPoints.h> 21 #include <vtkPolyData.h> 22 #include <vtkPolyDataMapper.h> 23 #include <vtkPolyLine.h> 24 #include <vtkPolygon.h> 26 mitk::PlanarFigureVtkMapper3D::LocalStorage::LocalStorage() : m_Actor(vtkSmartPointer<vtkActor>::New()), m_LastMTime(0)
30 mitk::PlanarFigureVtkMapper3D::LocalStorage::~LocalStorage()
40 mitk::PlanarFigureVtkMapper3D::PlanarFigureVtkMapper3D() : m_FillPf(
false)
44 mitk::PlanarFigureVtkMapper3D::~PlanarFigureVtkMapper3D()
55 if (dataNode ==
nullptr)
58 bool selected =
false;
62 dataNode->
GetColor(color, renderer, selected ?
"planarfigure.selected.line.color" :
"color");
67 vtkProperty *
property = actor->GetProperty();
68 property->SetColor(color[0], color[1], color[2]);
69 property->SetOpacity(opacity);
79 if (dataNode ==
nullptr)
85 actor->SetVisibility(render);
87 float lineWidth = 1.0f;
90 vtkProperty *
property = actor->GetProperty();
91 property->SetLineWidth(lineWidth);
94 void mitk::PlanarFigureVtkMapper3D::GenerateDataForRenderer(
BaseRenderer *renderer)
98 const DataNode *node = this->GetDataNode();
105 if (planarFigure ==
nullptr || !planarFigure->IsPlaced())
108 LocalStorage *localStorage = m_LocalStorageHandler.GetLocalStorage(renderer);
109 unsigned long mTime = planarFigure->
GetMTime();
112 bool refresh =
false;
114 if (m_FillPf != fillPf)
120 if (mTime > localStorage->m_LastMTime || refresh)
122 localStorage->m_LastMTime = mTime;
124 const auto *planeGeometry =
dynamic_cast<const PlaneGeometry *
>(planarFigure->GetPlaneGeometry());
125 const auto *abstractTransformGeometry =
128 if (planeGeometry ==
nullptr && abstractTransformGeometry ==
nullptr)
131 const size_t numPolyLines = planarFigure->GetPolyLinesSize();
133 if (numPolyLines == 0)
136 const vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
137 const vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
138 const vtkSmartPointer<vtkCellArray> polygons = vtkSmartPointer<vtkCellArray>::New();
139 vtkIdType baseIndex = 0;
141 for (
size_t i = 0; i < numPolyLines; ++i)
143 const PolyLine polyLine = planarFigure->GetPolyLine(i);
144 const vtkIdType numPoints = polyLine.size();
146 vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New();
151 auto polyLineEnd = polyLine.cend();
153 for (
auto polyLineIt = polyLine.cbegin(); polyLineIt != polyLineEnd; ++polyLineIt)
156 planeGeometry->Map(*polyLineIt, point);
157 points->InsertNextPoint(point.GetDataPointer());
159 const vtkIdType
id = polygon->GetPoints()->InsertNextPoint(point[0], point[1], point[2]);
160 polygon->GetPointIds()->InsertNextId(
id);
163 vtkSmartPointer<vtkPolyLine>
line = vtkSmartPointer<vtkPolyLine>::New();
165 vtkIdList *pointIds = line->GetPointIds();
167 if (planarFigure->IsClosed() && numPoints > 2)
169 polygons->InsertNextCell(polygon);
170 pointIds->SetNumberOfIds(numPoints + 1);
171 pointIds->SetId(numPoints, baseIndex);
175 pointIds->SetNumberOfIds(numPoints);
178 for (vtkIdType j = 0; j < numPoints; ++j)
179 pointIds->SetId(j, baseIndex + j);
181 cells->InsertNextCell(line);
183 baseIndex += points->GetNumberOfPoints();
186 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
187 polyData->SetPoints(points);
188 polyData->SetLines(cells);
190 polyData->SetPolys(polygons);
192 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
193 mapper->SetInputData(polyData);
195 localStorage->m_Actor->SetMapper(mapper);
198 this->ApplyColorAndOpacityProperties(renderer, localStorage->m_Actor);
199 this->ApplyPlanarFigureProperties(renderer, localStorage->m_Actor);
204 return m_LocalStorageHandler.GetLocalStorage(renderer)->m_Actor;
bool GetFloatProperty(const char *propertyKey, float &floatValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for float properties (instances of FloatProperty)
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)
bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
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 GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
unsigned long GetMTime() const override
Get the modified time of the last change of the contents this data object or its geometry.
Describes a two-dimensional, rectangular plane.
Class for nodes of the DataTree.