Medical Imaging Interaction Toolkit  2018.4.99-bd7b41ba
Medical Imaging Interaction Toolkit
mitkContourSetVtkMapper3D.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include "mitkColorProperty.h"
15 #include "mitkDataNode.h"
16 #include "mitkProperties.h"
17 #include "mitkVtkPropRenderer.h"
18 
19 #include <vtkActor.h>
20 #include <vtkActor.h>
21 #include <vtkAppendPolyData.h>
22 #include <vtkAssembly.h>
23 #include <vtkCellArray.h>
24 #include <vtkFollower.h>
25 #include <vtkLinearTransform.h>
26 #include <vtkPolyData.h>
27 #include <vtkPolyDataMapper.h>
28 #include <vtkPolygon.h>
29 #include <vtkProp3DCollection.h>
30 #include <vtkRenderer.h>
31 #include <vtkTubeFilter.h>
32 
33 #include <cstdlib>
34 #include <vtkPolyDataMapper.h>
35 #include <vtkProperty.h>
36 
38 {
39  m_VtkPolyDataMapper = vtkPolyDataMapper::New();
40  m_Actor = vtkActor::New();
41  m_Actor->SetMapper(m_VtkPolyDataMapper);
42 
43  m_ContourSet = vtkPolyData::New();
44  m_TubeFilter = vtkTubeFilter::New();
45 }
46 
48 {
50  m_VtkPolyDataMapper->Delete();
51  ;
52 
53  if (m_TubeFilter)
54  m_TubeFilter->Delete();
55  ;
56 
57  if (m_ContourSet)
58  m_ContourSet->Delete();
59  ;
60 
61  if (m_Actor)
62  m_Actor->Delete();
63  ;
64 }
65 
67 {
68  return m_Actor;
69 }
70 
72 {
73  bool visible = true;
74  GetDataNode()->GetVisibility(visible, renderer, "visible");
75 
76  if (!visible)
77  {
78  m_Actor->VisibilityOff();
79  return;
80  }
81 
82  m_Actor->VisibilityOn();
83 
85  {
86  m_ContourSet = vtkPolyData::New();
87 
88  vtkPoints *points = vtkPoints::New();
89  vtkCellArray *lines = vtkCellArray::New();
90 
91  mitk::ContourSet::Pointer input = const_cast<mitk::ContourSet *>(this->GetInput());
92  mitk::ContourSet::ContourVectorType contourVec = input->GetContours();
93  auto contourIt = contourVec.begin();
94 
95  vtkIdType firstPointIndex = 0, lastPointIndex = 0;
96 
97  vtkIdType ptIndex = 0;
98  while (contourIt != contourVec.end())
99  {
100  auto *nextContour = (mitk::Contour *)(*contourIt).second;
101  Contour::InputType idx = nextContour->GetContourPath()->StartOfInput();
102 
103  Contour::InputType end = nextContour->GetContourPath()->EndOfInput();
104  if (end > 50000)
105  end = 0;
106 
107  mitk::Contour::PointsContainerPointer contourPoints = nextContour->GetPoints();
108  mitk::Contour::PointsContainerIterator pointsIt = contourPoints->Begin();
109  unsigned int counter = 0;
110 
111  firstPointIndex = ptIndex;
112  while (pointsIt != contourPoints->End())
113  {
114  if (counter % 2 == 0)
115  {
116  Contour::BoundingBoxType::PointType point;
117  point = pointsIt.Value();
118  points->InsertPoint(ptIndex, point[0], point[1], point[2]);
119  if (ptIndex > firstPointIndex)
120  {
121  vtkIdType cell[2] = {ptIndex - 1, ptIndex};
122  lines->InsertNextCell((vtkIdType)2, cell);
123  }
124  lastPointIndex = ptIndex;
125  ptIndex++;
126  }
127  pointsIt++;
128  idx += 1;
129  }
130 
131  if (nextContour->GetClosed())
132  {
133  vtkIdType cell[2] = {lastPointIndex, firstPointIndex};
134  lines->InsertNextCell((vtkIdType)2, cell);
135  }
136  contourIt++;
137  }
138 
139  m_ContourSet->SetPoints(points);
140  m_ContourSet->SetLines(lines);
141 
142  m_TubeFilter->SetInputData(m_ContourSet);
143  m_TubeFilter->SetRadius(1);
144  m_TubeFilter->Update();
145  m_VtkPolyDataMapper->SetInputConnection(m_TubeFilter->GetOutputPort());
146 
147  double rgba[4] = {0.0f, 1.0f, 0.0f, 0.6f};
148 
149  m_Actor->GetProperty()->SetColor(rgba);
150  m_Actor->SetMapper(m_VtkPolyDataMapper);
151  }
152 }
153 
155 {
156  return static_cast<const mitk::ContourSet *>(GetDataNode()->GetData());
157 }
BoundingBoxType::PointsContainerIterator PointsContainerIterator
Definition: mitkContour.h:51
void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
Definition: mitkMapper.cpp:31
Organizes the rendering process.
virtual const mitk::ContourSet * GetInput()
Stores vertices for drawing a contour.
Definition: mitkContour.h:31
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this 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...
Definition: mitkDataNode.h:421
vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
PathType::InputType InputType
Definition: mitkContour.h:43
unsigned long GetMTime() const override
Get the modified time of the last change of the contents this data object or its geometry.
std::map< unsigned long, Contour::Pointer > ContourVectorType
BoundingBoxType::PointsContainer::Pointer PointsContainerPointer
Definition: mitkContour.h:50
unsigned long GetCurrentWorldPlaneGeometryUpdateTime()
Get timestamp of last call of SetCurrentWorldPlaneGeometry.