27 #include <vtkAbstractMapper3D.h> 28 #include <vtkAbstractVolumeMapper.h> 29 #include <vtkAssembly.h> 30 #include <vtkCellArray.h> 31 #include <vtkCellData.h> 32 #include <vtkColorTransferFunction.h> 33 #include <vtkLinearTransform.h> 34 #include <vtkLookupTable.h> 35 #include <vtkPiecewiseFunction.h> 37 #include <vtkPointData.h> 38 #include <vtkProp3DCollection.h> 39 #include <vtkScalarsToColors.h> 40 #include <vtkUnstructuredGrid.h> 41 #include <vtkVolume.h> 42 #include <vtkVolumeProperty.h> 69 if (!node->GetProperty(
m_Outline,
"outline polygons"))
74 if (!node->GetProperty(
m_Color,
"color"))
99 node->GetProperty(transferFuncProp,
"TransferFunction", renderer);
100 if (transferFuncProp.IsNotNull())
105 m_ScalarsToColors =
static_cast<vtkScalarsToColors *
>(tf->GetColorTransferFunction());
122 node->GetOpacity(opacity, renderer);
141 vtkLinearTransform *inversetransform = vtktransform->GetLinearInverse();
149 if (worldPlaneGeometry.IsNotNull())
152 point = worldPlaneGeometry->GetOrigin();
153 normal = worldPlaneGeometry->GetNormal();
155 m_Plane->SetTransform((vtkAbstractTransform *)
nullptr);
164 if (worldAbstractGeometry.IsNotNull())
167 point = worldAbstractGeometry->GetParametricBoundingBox()->GetMinimum();
169 m_Plane->SetTransform(worldAbstractGeometry->GetVtkAbstractTransform()->GetInverse());
175 double vp[3], vnormal[3];
177 vnl2vtk(point.GetVnlVector(), vp);
178 vnl2vtk(normal.GetVnlVector(), vnormal);
184 inversetransform->TransformPoint(vp, vp);
185 inversetransform->TransformNormalAtPoint(vp, vnormal, vnormal);
202 vtkPolyData *contour =
m_Slicer->GetOutput();
204 vtkPoints *vpoints = contour->GetPoints();
205 vtkCellArray *vlines = contour->GetLines();
206 vtkCellArray *vpolys = contour->GetPolys();
207 vtkPointData *vpointdata = contour->GetPointData();
208 vtkDataArray *vscalars = vpointdata->GetScalars();
210 vtkCellData *vcelldata = contour->GetCellData();
211 vtkDataArray *vcellscalars = vcelldata->GetScalars();
213 const int numberOfLines = contour->GetNumberOfLines();
214 const int numberOfPolys = contour->GetNumberOfPolys();
216 const bool useCellData =
m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_DEFAULT ||
217 m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_CELL_DATA;
218 const bool usePointData =
m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_POINT_DATA;
223 vlines->InitTraversal();
224 vpolys->InitTraversal();
230 for (
int i = 0; i < numberOfLines; ++i)
232 vtkIdType *cell(
nullptr);
233 vtkIdType cellSize(0);
235 vlines->GetNextCell(cellSize, cell);
237 float rgba[4] = {outlineColor[0], outlineColor[1], outlineColor[2], 1.0f};
242 double scalar = vcellscalars->GetComponent(i, 0);
243 double rgb[3] = {1.0f, 1.0f, 1.0f};
245 rgba[0] = (float)rgb[0];
246 rgba[1] = (float)rgb[1];
247 rgba[2] = (float)rgb[2];
250 else if (usePointData)
252 double scalar = vscalars->GetComponent(i, 0);
253 double rgb[3] = {1.0f, 1.0f, 1.0f};
255 rgba[0] = (float)rgb[0];
256 rgba[1] = (float)rgb[1];
257 rgba[2] = (float)rgb[2];
264 glBegin(GL_LINE_LOOP);
265 for (
int j = 0; j < cellSize; ++j)
267 vpoints->GetPoint(cell[j], vp);
269 vtktransform->TransformPoint(vp, vp);
280 glVertex2f(p2d[0], p2d[1]);
285 bool polyOutline =
m_Outline->GetValue();
292 const int maxPolySize = 10;
293 auto *cachedPoints =
new Point2D[maxPolySize * numberOfPolys];
296 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
300 if (scalarVisibility && vcellscalars)
302 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
304 for (
int i = 0; i < numberOfPolys; ++i)
306 vtkIdType *cell(
nullptr);
307 vtkIdType cellSize(0);
309 vpolys->GetNextCell(cellSize, cell);
311 float rgba[4] = {1.0f, 1.0f, 1.0f, 0};
312 if (scalarVisibility && vcellscalars)
316 double scalar = vcellscalars->GetComponent(i + numberOfLines, 0);
317 double rgb[3] = {1.0f, 1.0f, 1.0f};
319 rgba[0] = (float)rgb[0];
320 rgba[1] = (float)rgb[1];
321 rgba[2] = (float)rgb[2];
324 else if (usePointData)
326 double scalar = vscalars->GetComponent(i, 0);
327 double rgb[3] = {1.0f, 1.0f, 1.0f};
329 rgba[0] = (float)rgb[0];
330 rgba[1] = (float)rgb[1];
331 rgba[2] = (float)rgb[2];
338 for (
int j = 0; j < cellSize; ++j)
340 vpoints->GetPoint(cell[j], vp);
342 vtktransform->TransformPoint(vp, vp);
352 cachedPoints[i * 10 + j][0] = p2d[0];
353 cachedPoints[i * 10 + j][1] = p2d[1];
356 glVertex2f(p2d[0], p2d[1]);
363 vpolys->InitTraversal();
365 glColor4f(outlineColor[0], outlineColor[1], outlineColor[2], 1.0f);
366 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
367 for (
int i = 0; i < numberOfPolys; ++i)
369 vtkIdType *cell(
nullptr);
370 vtkIdType cellSize(0);
372 vpolys->GetNextCell(cellSize, cell);
376 for (
int j = 0; j < cellSize; ++j)
379 glVertex2f(cachedPoints[i * 10 + j][0], cachedPoints[i * 10 + j][1]);
386 delete[] cachedPoints;
397 if (mitkMapper.IsNull())
402 mitkMapper->Update(renderer);
404 auto *assembly =
dynamic_cast<vtkAssembly *
>(mitkMapper->GetVtkProp(renderer));
407 vtkProp3DCollection *collection = assembly->GetParts();
408 collection->InitTraversal();
409 vtkProp3D *prop3d =
nullptr;
412 prop3d = collection->GetNextProp3D();
413 auto *actor =
dynamic_cast<vtkActor *
>(prop3d);
416 return dynamic_cast<vtkAbstractMapper3D *
>(actor->GetMapper());
419 auto *volume =
dynamic_cast<vtkVolume *
>(prop3d);
422 return dynamic_cast<vtkAbstractMapper3D *
>(volume->GetMapper());
424 }
while (prop3d != collection->GetLastProp3D());
428 auto *actor =
dynamic_cast<vtkActor *
>(mitkMapper->GetVtkProp(renderer));
431 return dynamic_cast<vtkAbstractMapper3D *
>(actor->GetMapper());
434 auto *volume =
dynamic_cast<vtkVolume *
>(mitkMapper->GetVtkProp(renderer));
437 return dynamic_cast<vtkAbstractMapper3D *
>(volume->GetMapper());
447 if (abstractMapper ==
nullptr)
456 return static_cast<vtkPointSet *>(grid->GetVtkUnstructuredGrid(time));
462 auto *mapper =
dynamic_cast<vtkMapper *
>(abstractMapper);
465 return dynamic_cast<vtkPointSet *
>(mapper->GetInput());
467 auto *volMapper =
dynamic_cast<vtkAbstractVolumeMapper *
>(abstractMapper);
470 return dynamic_cast<vtkPointSet *
>(volMapper->GetDataSetInput());
482 return mapper->GetLookupTable();
490 if (mitkMapper.IsNull())
496 mitkMapper->Update(renderer);
498 auto *volume =
dynamic_cast<vtkVolume *
>(mitkMapper->GetVtkProp(renderer));
502 return static_cast<vtkScalarsToColors *
>(volume->GetProperty()->GetRGBTransferFunction());
505 auto *assembly =
dynamic_cast<vtkAssembly *
>(mitkMapper->GetVtkProp(renderer));
510 node->GetProperty(transferFuncProp,
"TransferFunction",
nullptr);
511 if (transferFuncProp.IsNotNull())
513 MITK_INFO <<
"return colortransferfunction\n";
514 return static_cast<vtkScalarsToColors *
>(transferFuncProp->GetValue()->GetColorTransferFunction());
mitk::IntProperty::Pointer m_LineWidth
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
Base class for mapper specific rendering ressources.
void GenerateDataForRenderer(BaseRenderer *) override
Generate the data needed for rendering into renderer.
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...
virtual void SetSlicePlane(vtkPlane *)
LocalStorageHandler< BaseLocalStorage > m_LSH
Organizes the rendering process.
~UnstructuredGridMapper2D() override
mitk::BoolProperty::Pointer m_Outline
mitk::BoolProperty::Pointer m_ScalarVisibility
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
virtual vtkScalarsToColors * GetVtkLUT(BaseRenderer *renderer)
Base class of all Vtk Mappers in order to display primitives by exploiting Vtk functionality.
vtkPointSetSlicer * m_Slicer
void WorldToDisplay(const Point3D &worldIndex, Point2D &displayPoint) const
This method converts a 3D world index to the display point using the geometry of the renderWindow...
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
vtkPointSet * m_VtkPointSet
mitk::ColorProperty::Pointer m_Color
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
mitk::VtkScalarModeProperty::Pointer m_ScalarMode
virtual vtkAbstractMapper3D * GetVtkAbstractMapper3D(BaseRenderer *renderer)
void vnl2vtk(const vnl_vector< Tin > &in, Tout *out)
void ApplyColorAndOpacityProperties(mitk::BaseRenderer *renderer, vtkActor *actor=nullptr) override
Apply color and opacity properties read from the PropertyList. The actor is not used in the GLMappers...
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...
void vtk2itk(const Tin &in, Tout &out)
vtkLinearTransform * GetVtkTransform(int t=0) const
Get the transformation applied prior to displaying the data as a vtkTransform.
vtkScalarsToColors * m_ScalarsToColors
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
static vtkPointSetSlicer * New()
void UpdateGenerateDataTime()
virtual bool IsConvertibleToVtkPointSet(BaseRenderer *renderer)
int GetTimestep() const
Returns the current time step as calculated from the renderer.
virtual vtkPointSet * GetVtkPointSet(BaseRenderer *renderer, int time=0)
Class for storing unstructured grids (vtkUnstructuredGrid)
Describes a two-dimensional, rectangular plane.
vtkPiecewiseFunction * m_ScalarsToOpacity
void Paint(mitk::BaseRenderer *renderer) override
UnstructuredGridMapper2D()