MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSNavigationTargetOcclusionFilter.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13// MITK
15#include "mitkDataNode.h"
16#include "mitkSurface.h"
17
18// VTK
19#include "vtkSmartPointer.h"
20#include "vtkPointData.h"
21#include "vtkPolyData.h"
22#include "vtkOBBTree.h"
23#include "vtkFloatArray.h"
24#include "vtkTransform.h"
25#include "vtkTransformPolyDataFilter.h"
26
27
32
36
38{
39 m_TargetStructure = targetStructure;
40}
41
42void mitk::USNavigationTargetOcclusionFilter::SetObstacleStructures(DataStorage::SetOfObjects::ConstPointer obstacleStructures)
43{
44 m_ObstacleStructures = obstacleStructures;
45}
46
48{
49 m_StartPositionInput = n;
50}
51
53{
55
56 // get vtk surface an the points
57 vtkSmartPointer<vtkPolyData> targetSurfaceVtk = this->GetVtkPolyDataOfTarget();
58 if ( ! targetSurfaceVtk ) { return; } // cannot do anything without a target surface
59
60 vtkIdType numberOfPoints = targetSurfaceVtk->GetNumberOfPoints();
61
62 // create array for scalar values
65 colors->SetNumberOfComponents(1);
66 colors->SetName("USNavigation::Occlusion");
67
68 const mitk::NavigationData* nd = this->GetInput(m_StartPositionInput);
69
70 // set every value to -1 if there is no (valid) navigation data
71 if ( nd == nullptr || ! nd->IsDataValid() )
72 {
73 float intersection = -1;
74 for ( vtkIdType n = 0; n < numberOfPoints; n++ )
75 {
76 colors->InsertNextTuple1(intersection);
77 }
78
79 if ( numberOfPoints > 0 )
80 {
81 targetSurfaceVtk->GetPointData()->AddArray(colors);
82 targetSurfaceVtk->GetPointData()->Update();
83 }
84
85 return;
86 }
87
88 // initialize values with 0 (no intersection) if there is valid navigation
89 // data and there are some obstacle structures defined
90 else if ( m_ObstacleStructures.IsNull() )
91 {
92 float intersection = 0;
93 for ( vtkIdType n = 0; n < numberOfPoints; n++ )
94 {
95 colors->InsertNextTuple1(intersection);
96 }
97
98 if ( numberOfPoints > 0 )
99 {
100 targetSurfaceVtk->GetPointData()->AddArray(colors);
101 targetSurfaceVtk->GetPointData()->Update();
102 }
103
104 return;
105 }
106
107 // get the current position from the navigation data
108 mitk::Point3D position = nd->GetPosition();
109 double point1[3];
110 point1[0] = position[0]; point1[1] = position[1]; point1[2] = position[2];
111
112 // transform vtk polydata according to mitk geometry
115 transformFilter->SetInputData(0, targetSurfaceVtk);
116 transformFilter->SetTransform(m_TargetStructure->GetData()->GetGeometry()->GetVtkTransform());
117 transformFilter->Update();
118 vtkSmartPointer<vtkPolyData> targetSurfaceVtkTransformed = transformFilter->GetOutput();
119
120 std::vector<bool> occlusion(numberOfPoints, false);
121
122 // calculate occlusion for every obstacle structure
123 for (mitk::DataStorage::SetOfObjects::ConstIterator it = m_ObstacleStructures->Begin();
124 it != m_ObstacleStructures->End(); ++it)
125 {
126 vtkSmartPointer<vtkPolyData> polyData = dynamic_cast<mitk::Surface*>(it->Value()->GetData())->GetVtkPolyData();
127
128 // transform the obstacle structure according to the mitk geometry
131 transformFilter->SetInputData(0, polyData);
132 transformFilter->SetTransform(it->Value()->GetData()->GetGeometry()->GetVtkTransform());
133 transformFilter->Update();
134 polyData = transformFilter->GetOutput();
135
136 // build an obb tree locator
138 cellLocator->SetDataSet(polyData);
139 cellLocator->BuildLocator();
140
141 // test for intersection with every point on the surface
142 for ( vtkIdType n = 0; n < numberOfPoints; n++ )
143 {
145 if ( cellLocator->IntersectWithLine(point1, targetSurfaceVtkTransformed->GetPoint(n), points, nullptr) != 0 )
146 {
147 occlusion.at(n) = true;
148 }
149 }
150 }
151
152 if ( numberOfPoints > 0 )
153 {
154 // set the occlusion values as scalar array to the vtkPolyData
155 float one = 1.0f; float zero = 0.0f;
156 for ( std::vector<bool>::iterator it = occlusion.begin(); it != occlusion.end(); ++it )
157 {
158 colors->InsertNextTuple1(*it ? one : zero);
159 }
160
161 targetSurfaceVtk->GetPointData()->AddArray(colors);
162 targetSurfaceVtk->GetPointData()->Update();
163 }
164}
165
167{
168 if ( m_TargetStructure.IsNull() )
169 {
170 MITK_WARN("USNavigationTargetOcclusionFilter") << "Target structure must not be null.";
171 return nullptr;
172 }
173
174 mitk::Surface::Pointer targetSurface = dynamic_cast<mitk::Surface*>(m_TargetStructure->GetData());
175 if ( targetSurface.IsNull() )
176 {
177 MITK_WARN("USNavigationTargetOcclusionFilter") << "A mitk::Surface has to be set to the data node.";
178 return nullptr;
179 }
180
181 vtkSmartPointer<vtkPolyData> targetSurfaceVtk = targetSurface->GetVtkPolyData();
182 if( targetSurfaceVtk == nullptr )
183 {
184 MITK_WARN("USNavigationTargetOcclusionFilter") << "VtkPolyData of the mitk::Surface of the data node must not be null.";
185 return nullptr;
186 }
187
188 return targetSurfaceVtk;
189}
void GenerateData() override
Passes navigation data from all inputs to all outputs. If a subclass wants to implement its own versi...
virtual bool IsDataValid() const
returns true if the object contains valid data
void SetObstacleStructures(DataStorage::SetOfObjects::ConstPointer obstacleStructures)
Sets the obstacle structures which can occlude the target structure.
void SelectStartPositionInput(unsigned int n)
Sets the index of the input which is used for occlusion calculation. The occlusion will be calculated...
void SetTargetStructure(itk::SmartPointer< DataNode > targetStructure)
Sets the target structure for which the occluded positions should be calculated.
vtkSmartPointer< vtkPolyData > GetVtkPolyDataOfTarget()
Returns the vtk poly data of the target structure.