Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkStaticIGTHelperFunctions.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 <itkVector.h>
19 
21  {
22  double returnValue;
23 
24  itk::Vector<double,3> point; //caution 5D-Tools: correct verctor along the tool axis is needed
25  point[0] = rotationVector[0];
26  point[1] = rotationVector[1];
27  point[2] = rotationVector[2];
28 
29  //Quaternions used for rotations should alway be normalized, so just to be safe:
30  a.normalize();
31  b.normalize();
32 
33  itk::Matrix<double,3,3> rotMatrixA;
34  for(int i=0; i<3; i++) for(int j=0; j<3; j++) rotMatrixA[i][j] = a.rotation_matrix_transpose().transpose()[i][j];
35 
36  itk::Matrix<double,3,3> rotMatrixB;
37  for(int i=0; i<3; i++) for(int j=0; j<3; j++) rotMatrixB[i][j] = b.rotation_matrix_transpose().transpose()[i][j];
38 
39  itk::Vector<double,3> pt1 = rotMatrixA * point;
40  itk::Vector<double,3> pt2 = rotMatrixB * point;
41 
42  returnValue = (pt1[0]*pt2[0]+pt1[1]*pt2[1]+pt1[2]*pt2[2]) / ( sqrt(pow(pt1[0],2.0)+pow(pt1[1],2.0)+pow(pt1[2],2.0)) * sqrt(pow(pt2[0],2.0)+pow(pt2[1],2.0)+pow(pt2[2],2.0)));
43  returnValue = acos(returnValue) * 57.296; //57,296 = 180/Pi ; conversion to degrees
44 
45  return returnValue;
46  }
47 
49 {
50  itk::Vector<double,3> rotationVector = itk::Vector<double,3>();
51  rotationVector[0] = 0;
52  rotationVector[1] = 0;
53  rotationVector[2] = 1000;
54  return GetAngleBetweenTwoQuaterions(a,b,rotationVector);
55 }
56 
57 itk::Matrix<double,3,3> mitk::StaticIGTHelperFunctions::ConvertEulerAnglesToRotationMatrix(double alpha, double beta, double gamma)
58 {
59  double PI = 3.141592653589793;
60  alpha = alpha * PI / 180;
61  beta = beta * PI / 180;
62  gamma = gamma * PI / 180;
63 
64  //convert angles to matrix:
65  itk::Matrix<double,3,3> matrix;
66 
67  /* x-Konvention (Z, X, Z)
68  matrix[0][0] = cos(alpha) * cos(gamma) - sin(alpha) * cos(beta) * sin(gamma);
69  matrix[0][1] = -cos(alpha) * sin(gamma)- sin(alpha) * cos(beta) * cos(gamma);
70  matrix[0][2] = sin(alpha) * sin(beta);
71 
72  matrix[1][0] = sin(alpha) * cos(gamma) + cos(alpha) * cos(beta) * sin(gamma);
73  matrix[1][1] = cos(alpha) * cos(beta) * cos(gamma) - sin(alpha) * sin(gamma);
74  matrix[1][2] = -cos(alpha) * sin(beta);
75 
76  matrix[2][0] = sin(beta) * sin(gamma);
77  matrix[2][1] = sin(beta) * cos(gamma);
78  matrix[2][2] = cos(beta);
79  */
80 
81  //Luftfahrtnorm (DIN 9300) (Yaw-Pitch-Roll, Z, Y, X)
82  matrix[0][0] = cos(beta) * cos(alpha);
83  matrix[0][1] = cos(beta) * sin(alpha);
84  matrix[0][2] = -sin(beta);
85 
86  matrix[1][0] = sin(gamma) * sin(beta) * cos(alpha) - cos(gamma) * sin(alpha) ;
87  matrix[1][1] = sin(gamma) * sin(beta) * sin(alpha) + cos(gamma) * cos(alpha);
88  matrix[1][2] = sin(gamma) * cos(beta);
89 
90  matrix[2][0] = cos(gamma) * sin(beta) * cos(alpha) + sin(gamma) * sin(alpha);
91  matrix[2][1] = cos(gamma) * sin(beta) * sin(alpha) - sin(gamma) * cos(alpha);
92  matrix[2][2] = cos(gamma) * cos(beta);
93 
94  return matrix;
95 }
96 
97 double mitk::StaticIGTHelperFunctions::ComputeFRE(mitk::PointSet::Pointer imageFiducials, mitk::PointSet::Pointer realWorldFiducials, vtkSmartPointer<vtkLandmarkTransform> transform)
98 {
99  if (imageFiducials->GetSize() != realWorldFiducials->GetSize()) return -1;
100  double FRE = 0;
101  for (int i = 0; i < imageFiducials->GetSize(); i++)
102  {
103  itk::Point<double> current_image_fiducial_point = imageFiducials->GetPoint(i);
104  if (transform != NULL)
105  {
106  current_image_fiducial_point = transform->TransformPoint(imageFiducials->GetPoint(i)[0], imageFiducials->GetPoint(i)[1], imageFiducials->GetPoint(i)[2]);
107  }
108  double cur_error_squared = current_image_fiducial_point.SquaredEuclideanDistanceTo(realWorldFiducials->GetPoint(i));
109  FRE += cur_error_squared;
110  }
111 
112  FRE = sqrt(FRE / (double)imageFiducials->GetSize());
113 
114  return FRE;
115 }
const mitk::ScalarType PI
vnl_quaternion< ScalarType > Quaternion
static itk::Matrix< double, 3, 3 > ConvertEulerAnglesToRotationMatrix(double alpha, double beta, double gamma)
static double GetAngleBetweenTwoQuaterions(mitk::Quaternion a, mitk::Quaternion b, itk::Vector< double, 3 > rotationVector)
static double ComputeFRE(mitk::PointSet::Pointer imageFiducials, mitk::PointSet::Pointer realWorldFiducials, vtkSmartPointer< vtkLandmarkTransform > transform=NULL)
Computes the fiducial registration error out of two sets of fiducials. The two sets must have the sam...