Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "mitkColorProperty.h"
19 #include "mitkDataNode.h"
20 #include "mitkProperties.h"
21 #include "mitkVtkPropRenderer.h"
22 
23 #include <vtkActor.h>
24 #include <vtkActor.h>
25 #include <vtkAppendPolyData.h>
26 #include <vtkAssembly.h>
27 #include <vtkCellArray.h>
28 #include <vtkFollower.h>
29 #include <vtkLinearTransform.h>
30 #include <vtkPolyData.h>
31 #include <vtkPolyDataMapper.h>
32 #include <vtkPolygon.h>
33 #include <vtkProp3DCollection.h>
34 #include <vtkRenderer.h>
35 #include <vtkTubeFilter.h>
36 
37 #include <stdlib.h>
38 #include <vtkPolyDataMapper.h>
39 #include <vtkProperty.h>
40 
42 {
45  m_Actor->SetMapper(m_VtkPolyDataMapper);
46 
49 }
50 
52 {
53  if (m_VtkPolyDataMapper)
54  m_VtkPolyDataMapper->Delete();
55  ;
56 
57  if (m_TubeFilter)
58  m_TubeFilter->Delete();
59  ;
60 
61  if (m_ContourSet)
62  m_ContourSet->Delete();
63  ;
64 
65  if (m_Actor)
66  m_Actor->Delete();
67  ;
68 }
69 
71 {
72  return m_Actor;
73 }
74 
76 {
77  bool visible = true;
78  GetDataNode()->GetVisibility(visible, renderer, "visible");
79 
80  if (!visible)
81  {
82  m_Actor->VisibilityOff();
83  return;
84  }
85 
86  m_Actor->VisibilityOn();
87 
88  if (renderer->GetCurrentWorldPlaneGeometryUpdateTime() > 0 < this->GetInput()->GetMTime())
89  {
90  m_ContourSet = vtkPolyData::New();
91 
92  vtkPoints *points = vtkPoints::New();
93  vtkCellArray *lines = vtkCellArray::New();
94 
95  mitk::ContourSet::Pointer input = const_cast<mitk::ContourSet *>(this->GetInput());
96  mitk::ContourSet::ContourVectorType contourVec = input->GetContours();
97  mitk::ContourSet::ContourIterator contourIt = contourVec.begin();
98 
99  vtkIdType firstPointIndex = 0, lastPointIndex = 0;
100 
101  vtkIdType ptIndex = 0;
102  while (contourIt != contourVec.end())
103  {
104  mitk::Contour *nextContour = (mitk::Contour *)(*contourIt).second;
105  Contour::InputType idx = nextContour->GetContourPath()->StartOfInput();
106 
107  Contour::InputType end = nextContour->GetContourPath()->EndOfInput();
108  if (end > 50000)
109  end = 0;
110 
111  mitk::Contour::PointsContainerPointer contourPoints = nextContour->GetPoints();
112  mitk::Contour::PointsContainerIterator pointsIt = contourPoints->Begin();
113  unsigned int counter = 0;
114 
115  firstPointIndex = ptIndex;
116  while (pointsIt != contourPoints->End())
117  {
118  if (counter % 2 == 0)
119  {
121  point = pointsIt.Value();
122  points->InsertPoint(ptIndex, point[0], point[1], point[2]);
123  if (ptIndex > firstPointIndex)
124  {
125  vtkIdType cell[2] = {ptIndex - 1, ptIndex};
126  lines->InsertNextCell((vtkIdType)2, cell);
127  }
128  lastPointIndex = ptIndex;
129  ptIndex++;
130  }
131  pointsIt++;
132  idx += 1;
133  }
134 
135  if (nextContour->GetClosed())
136  {
137  vtkIdType cell[2] = {lastPointIndex, firstPointIndex};
138  lines->InsertNextCell((vtkIdType)2, cell);
139  }
140  contourIt++;
141  }
142 
143  m_ContourSet->SetPoints(points);
144  m_ContourSet->SetLines(lines);
145 
146  m_TubeFilter->SetInputData(m_ContourSet);
147  m_TubeFilter->SetRadius(1);
148  m_TubeFilter->Update();
149  m_VtkPolyDataMapper->SetInputConnection(m_TubeFilter->GetOutputPort());
150 
151  double rgba[4] = {0.0f, 1.0f, 0.0f, 0.6f};
152 
153  m_Actor->GetProperty()->SetColor(rgba);
154  m_Actor->SetMapper(m_VtkPolyDataMapper);
155  }
156 
157  SetVtkMapperImmediateModeRendering(m_VtkPolyDataMapper);
158 }
159 
161 {
162  return static_cast<const mitk::ContourSet *>(GetDataNode()->GetData());
163 }
mitk::Point3D PointType
BoundingBoxType::PointsContainerIterator PointsContainerIterator
Definition: mitkContour.h:53
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
virtual bool GetClosed()
PathPointer GetContourPath() const
ContourVectorType::iterator ContourIterator
Organizes the rendering process.
virtual const mitk::ContourSet * GetInput()
Stores vertices for drawing a contour.
Definition: mitkContour.h:35
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
PathType::InputType InputType
Definition: mitkContour.h:45
PointsContainerPointer GetPoints() const
std::map< unsigned long, Contour::Pointer > ContourVectorType
BoundingBoxType::PointsContainer::Pointer PointsContainerPointer
Definition: mitkContour.h:52
unsigned long GetCurrentWorldPlaneGeometryUpdateTime()
Get timestamp of last call of SetCurrentWorldPlaneGeometry.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.