MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSNavigationTargetIntersectionFilter.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
14#include "mitkSurface.h"
15#include "mitkPointSet.h"
16
17#include "vtkSmartPointer.h"
18#include "vtkOBBTree.h"
19#include "vtkTransformPolyDataFilter.h"
20#include "vtkLinearTransform.h"
21#include "vtkIdList.h"
22#include "vtkMath.h"
23
27
31
33{
34 if ( line.IsNull() || line->GetSize() != 2 )
35 {
36 mitkThrow() << "Line must consist of exact two points.";
37 }
38
39 // copy points from the PointSet to arrays
40 m_LinePoint1[0] = line->GetPoint(0)[0];
41 m_LinePoint1[1] = line->GetPoint(0)[1];
42 m_LinePoint1[2] = line->GetPoint(0)[2];
43 m_LinePoint2[0] = line->GetPoint(1)[0];
44 m_LinePoint2[1] = line->GetPoint(1)[1];
45 m_LinePoint2[2] = line->GetPoint(1)[2];
46}
47
49{
50 // copy the values for returning a Point3D
51 mitk::Point3D intersectionPoint;
52 intersectionPoint[0] = m_IntersectionPoint[0];
53 intersectionPoint[1] = m_IntersectionPoint[1];
54 intersectionPoint[2] = m_IntersectionPoint[2];
55 return intersectionPoint;
56}
57
59{
60 // cell id was saved on intersection calculation and can be used now
62 m_TargetSurfaceVtk->GetCellPoints(m_IntersectionCellId, pointIds);
63
64 return pointIds->GetId(0);
65}
66
68{
69 return sqrt(vtkMath::Distance2BetweenPoints(m_LinePoint1, m_IntersectionPoint));
70}
71
73{
74 if ( m_TargetSurface.IsNull() )
75 {
76 mitkThrow() << "Target surface must not be null.";
77 }
78
79 m_TargetSurfaceVtk = m_TargetSurface->GetVtkPolyData();
80
81 // transform vtk polydata according to mitk geometry
84 transformFilter->SetInputData(0, m_TargetSurfaceVtk);
85 transformFilter->SetTransform(m_TargetSurface->GetGeometry()->GetVtkTransform());
86 transformFilter->Update();
87 m_TargetSurfaceVtk = transformFilter->GetOutput();
88
89 // build a obb tree locator for the target surface
91 cellLocator->SetDataSet(m_TargetSurfaceVtk);
92 cellLocator->BuildLocator();
93
96 if ( cellLocator->IntersectWithLine(m_LinePoint1, m_LinePoint2, points, cellIds) != 0 )
97 {
98 m_IsIntersecting = true;
99
100 points->GetPoint(0, m_IntersectionPoint);
101 m_IntersectionCellId = cellIds->GetId(0);
102 }
103 else
104 {
105 m_IsIntersecting = false;
106 }
107}
void CalculateIntersection()
Does the intersection calculation. SetTargetSurface() and SetLine() have to be called before.