31 #include <vtkAbstractMapper3D.h>
32 #include <vtkAbstractVolumeMapper.h>
33 #include <vtkAssembly.h>
34 #include <vtkCellArray.h>
35 #include <vtkCellData.h>
36 #include <vtkColorTransferFunction.h>
37 #include <vtkLinearTransform.h>
38 #include <vtkLookupTable.h>
39 #include <vtkPiecewiseFunction.h>
41 #include <vtkPointData.h>
42 #include <vtkProp3DCollection.h>
43 #include <vtkScalarsToColors.h>
44 #include <vtkUnstructuredGrid.h>
45 #include <vtkVolume.h>
46 #include <vtkVolumeProperty.h>
73 if (!node->GetProperty(
m_Outline,
"outline polygons"))
78 if (!node->GetProperty(
m_Color,
"color"))
103 node->GetProperty(transferFuncProp,
"TransferFunction", renderer);
104 if (transferFuncProp.IsNotNull())
109 m_ScalarsToColors =
static_cast<vtkScalarsToColors *
>(tf->GetColorTransferFunction());
126 node->GetOpacity(opacity, renderer);
140 GetDataNode()->GetVisibility(visible, renderer,
"visible");
144 vtkLinearTransform *vtktransform = GetDataNode()->GetVtkTransform();
145 vtkLinearTransform *inversetransform = vtktransform->GetLinearInverse();
153 if (worldPlaneGeometry.IsNotNull())
156 point = worldPlaneGeometry->GetOrigin();
157 normal = worldPlaneGeometry->GetNormal();
159 m_Plane->SetTransform((vtkAbstractTransform *)NULL);
168 if (worldAbstractGeometry.IsNotNull())
171 point =
const_cast<mitk::BoundingBox *
>(worldAbstractGeometry->GetParametricBoundingBox())->GetMinimum();
173 m_Plane->SetTransform(worldAbstractGeometry->GetVtkAbstractTransform()->GetInverse());
179 double vp[3], vnormal[3];
181 vnl2vtk(point.GetVnlVector(), vp);
182 vnl2vtk(normal.GetVnlVector(), vnormal);
188 inversetransform->TransformPoint(vp, vp);
189 inversetransform->TransformNormalAtPoint(vp, vnormal, vnormal);
191 m_Plane->SetOrigin(vp);
192 m_Plane->SetNormal(vnormal);
195 m_Slicer->SetInputData(m_VtkPointSet);
203 ApplyColorAndOpacityProperties(renderer);
206 vtkPolyData *contour = m_Slicer->GetOutput();
208 vtkPoints *vpoints = contour->GetPoints();
209 vtkCellArray *vlines = contour->GetLines();
210 vtkCellArray *vpolys = contour->GetPolys();
211 vtkPointData *vpointdata = contour->GetPointData();
212 vtkDataArray *vscalars = vpointdata->GetScalars();
214 vtkCellData *vcelldata = contour->GetCellData();
215 vtkDataArray *vcellscalars = vcelldata->GetScalars();
217 const int numberOfLines = contour->GetNumberOfLines();
218 const int numberOfPolys = contour->GetNumberOfPolys();
220 const bool useCellData = m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_DEFAULT ||
221 m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_CELL_DATA;
222 const bool usePointData = m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_POINT_DATA;
227 vlines->InitTraversal();
228 vpolys->InitTraversal();
232 glLineWidth((
float)m_LineWidth->GetValue());
234 for (
int i = 0; i < numberOfLines; ++i)
237 vtkIdType cellSize(0);
239 vlines->GetNextCell(cellSize, cell);
241 float rgba[4] = {outlineColor[0], outlineColor[1], outlineColor[2], 1.0f};
242 if (m_ScalarVisibility->GetValue() && vcellscalars)
246 double scalar = vcellscalars->GetComponent(i, 0);
247 double rgb[3] = {1.0f, 1.0f, 1.0f};
248 m_ScalarsToColors->GetColor(scalar, rgb);
249 rgba[0] = (float)rgb[0];
250 rgba[1] = (float)rgb[1];
251 rgba[2] = (float)rgb[2];
252 rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
254 else if (usePointData)
256 double scalar = vscalars->GetComponent(i, 0);
257 double rgb[3] = {1.0f, 1.0f, 1.0f};
258 m_ScalarsToColors->GetColor(scalar, rgb);
259 rgba[0] = (float)rgb[0];
260 rgba[1] = (float)rgb[1];
261 rgba[2] = (float)rgb[2];
262 rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
268 glBegin(GL_LINE_LOOP);
269 for (
int j = 0; j < cellSize; ++j)
271 vpoints->GetPoint(cell[j], vp);
273 vtktransform->TransformPoint(vp, vp);
284 glVertex2f(p2d[0], p2d[1]);
289 bool polyOutline = m_Outline->GetValue();
290 bool scalarVisibility = m_ScalarVisibility->GetValue();
296 const int maxPolySize = 10;
300 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
304 if (scalarVisibility && vcellscalars)
306 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
308 for (
int i = 0; i < numberOfPolys; ++i)
311 vtkIdType cellSize(0);
313 vpolys->GetNextCell(cellSize, cell);
315 float rgba[4] = {1.0f, 1.0f, 1.0f, 0};
316 if (scalarVisibility && vcellscalars)
320 double scalar = vcellscalars->GetComponent(i + numberOfLines, 0);
321 double rgb[3] = {1.0f, 1.0f, 1.0f};
322 m_ScalarsToColors->GetColor(scalar, rgb);
323 rgba[0] = (float)rgb[0];
324 rgba[1] = (float)rgb[1];
325 rgba[2] = (float)rgb[2];
326 rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
328 else if (usePointData)
330 double scalar = vscalars->GetComponent(i, 0);
331 double rgb[3] = {1.0f, 1.0f, 1.0f};
332 m_ScalarsToColors->GetColor(scalar, rgb);
333 rgba[0] = (float)rgb[0];
334 rgba[1] = (float)rgb[1];
335 rgba[2] = (float)rgb[2];
336 rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
342 for (
int j = 0; j < cellSize; ++j)
344 vpoints->GetPoint(cell[j], vp);
346 vtktransform->TransformPoint(vp, vp);
356 cachedPoints[i * 10 + j][0] = p2d[0];
357 cachedPoints[i * 10 + j][1] = p2d[1];
360 glVertex2f(p2d[0], p2d[1]);
367 vpolys->InitTraversal();
369 glColor4f(outlineColor[0], outlineColor[1], outlineColor[2], 1.0f);
370 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
371 for (
int i = 0; i < numberOfPolys; ++i)
374 vtkIdType cellSize(0);
376 vpolys->GetNextCell(cellSize, cell);
380 for (
int j = 0; j < cellSize; ++j)
383 glVertex2f(cachedPoints[i * 10 + j][0], cachedPoints[i * 10 + j][1]);
390 delete[] cachedPoints;
401 if (mitkMapper.IsNull())
406 mitkMapper->Update(renderer);
408 vtkAssembly *assembly =
dynamic_cast<vtkAssembly *
>(mitkMapper->GetVtkProp(renderer));
411 vtkProp3DCollection *collection = assembly->GetParts();
412 collection->InitTraversal();
413 vtkProp3D *prop3d = 0;
416 prop3d = collection->GetNextProp3D();
417 vtkActor *actor =
dynamic_cast<vtkActor *
>(prop3d);
420 return dynamic_cast<vtkAbstractMapper3D *
>(actor->GetMapper());
423 vtkVolume *volume =
dynamic_cast<vtkVolume *
>(prop3d);
426 return dynamic_cast<vtkAbstractMapper3D *
>(volume->GetMapper());
428 }
while (prop3d != collection->GetLastProp3D());
432 vtkActor *actor =
dynamic_cast<vtkActor *
>(mitkMapper->GetVtkProp(renderer));
435 return dynamic_cast<vtkAbstractMapper3D *
>(actor->GetMapper());
438 vtkVolume *volume =
dynamic_cast<vtkVolume *
>(mitkMapper->GetVtkProp(renderer));
441 return dynamic_cast<vtkAbstractMapper3D *
>(volume->GetMapper());
450 vtkAbstractMapper3D *abstractMapper = GetVtkAbstractMapper3D(renderer);
451 if (abstractMapper == 0)
460 return static_cast<vtkPointSet *>(grid->GetVtkUnstructuredGrid(time));
466 vtkMapper *mapper =
dynamic_cast<vtkMapper *
>(abstractMapper);
469 return dynamic_cast<vtkPointSet *
>(mapper->GetInput());
471 vtkAbstractVolumeMapper *volMapper =
dynamic_cast<vtkAbstractVolumeMapper *
>(abstractMapper);
474 return dynamic_cast<vtkPointSet *
>(volMapper->GetDataSetInput());
484 vtkMapper *mapper =
dynamic_cast<vtkMapper *
>(GetVtkAbstractMapper3D(renderer));
486 return mapper->GetLookupTable();
494 if (mitkMapper.IsNull())
500 mitkMapper->Update(renderer);
502 vtkVolume *volume =
dynamic_cast<vtkVolume *
>(mitkMapper->GetVtkProp(renderer));
506 return static_cast<vtkScalarsToColors *
>(volume->GetProperty()->GetRGBTransferFunction());
509 vtkAssembly *assembly =
dynamic_cast<vtkAssembly *
>(mitkMapper->GetVtkProp(renderer));
514 node->GetProperty(transferFuncProp,
"TransferFunction", 0);
515 if (transferFuncProp.IsNotNull())
517 MITK_INFO <<
"return colortransferfunction\n";
518 return static_cast<vtkScalarsToColors *
>(transferFuncProp->GetValue()->GetColorTransferFunction());
527 return (GetVtkPointSet(renderer, this->GetTimestep()) != 0);
535 m_Slicer->SetSlicePlane(m_Plane);
537 m_ScalarsToColors = 0;
538 m_ScalarsToOpacity = 0;
553 if (m_ScalarsToOpacity != 0)
554 m_ScalarsToOpacity->UnRegister(0);
555 if (m_ScalarsToColors != 0)
556 m_ScalarsToColors->UnRegister(0);
557 if (m_VtkPointSet != 0)
558 m_VtkPointSet->UnRegister(0);
itk::BoundingBox< unsigned long, 3, ScalarType > BoundingBox
Standard 3D-BoundingBox typedef.
mitk::IntProperty::Pointer m_LineWidth
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
Base class for mapper specific rendering ressources.
virtual void GenerateDataForRenderer(BaseRenderer *) override
Generate the data needed for rendering into renderer.
Base of all data objects.
LocalStorageHandler< BaseLocalStorage > m_LSH
Organizes the rendering process.
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.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual ~UnstructuredGridMapper2D()
virtual vtkScalarsToColors * GetVtkLUT(BaseRenderer *renderer)
Base class of all Vtk Mappers in order to display primitives by exploiting Vtk functionality.
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
int GetTimestep() const
Returns the current time step as calculated from the renderer.
vtkPointSet * m_VtkPointSet
mitk::ColorProperty::Pointer m_Color
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...
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Mapper *mapper, mitk::DataNode *dataNode) const
mitk::VtkScalarModeProperty::Pointer m_ScalarMode
virtual vtkAbstractMapper3D * GetVtkAbstractMapper3D(BaseRenderer *renderer)
void vnl2vtk(const vnl_vector< Tin > &in, Tout *out)
void vtk2itk(const Tin &in, Tout &out)
vtkScalarsToColors * m_ScalarsToColors
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
static vtkPointSetSlicer * New()
void UpdateGenerateDataTime()
virtual bool IsConvertibleToVtkPointSet(BaseRenderer *renderer)
virtual vtkPointSet * GetVtkPointSet(BaseRenderer *renderer, int time=0)
Class for storing unstructured grids (vtkUnstructuredGrid)
Describes a two-dimensional, rectangular plane.
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
vtkPiecewiseFunction * m_ScalarsToOpacity
virtual void Paint(mitk::BaseRenderer *renderer) override
UnstructuredGridMapper2D()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.