14#include "vnl/vnl_det.h"
15#include "mitkException.h"
18m_Position(), m_Orientation(0.0, 0.0, 0.0, 1.0), m_CovErrorMatrix(),
19m_HasPosition(true), m_HasOrientation(true), m_DataValid(false), m_IGTTimeStamp(0.0),
28 m_Position(toCopy.GetPosition()), m_Orientation(toCopy.GetOrientation()), m_CovErrorMatrix(toCopy.GetCovErrorMatrix()),
29 m_HasPosition(toCopy.GetHasPosition()), m_HasOrientation(toCopy.GetHasOrientation()), m_DataValid(toCopy.IsDataValid()), m_IGTTimeStamp(toCopy.GetIGTTimeStamp()),
30 m_Name(toCopy.GetName())
44 nd =
dynamic_cast<const Self *
>( data );
48 itkExceptionMacro( <<
"mitk::NavigationData::Graft cannot cast "
49 <<
typeid(data).name() <<
" to "
50 <<
typeid(
const Self *).name() );
56 itkExceptionMacro( <<
"mitk::NavigationData::Graft cannot cast "
57 <<
typeid(data).name() <<
" to "
58 <<
typeid(
const Self *).name() );
62 this->SetPosition(nd->GetPosition());
63 this->SetOrientation(nd->GetOrientation());
64 this->SetDataValid(nd->IsDataValid());
65 this->SetIGTTimeStamp(nd->GetIGTTimeStamp());
66 this->SetHasPosition(nd->GetHasPosition());
67 this->SetHasOrientation(nd->GetHasOrientation());
68 this->SetCovErrorMatrix(nd->GetCovErrorMatrix());
69 this->SetName(nd->GetName());
81 this->Superclass::PrintSelf(os, indent);
82 os << indent <<
"data valid: " << this->IsDataValid() << std::endl;
83 os << indent <<
"Position: " << this->GetPosition() << std::endl;
84 os << indent <<
"Orientation: " << this->GetOrientation() << std::endl;
85 os << indent <<
"TimeStamp: " << this->GetIGTTimeStamp() << std::endl;
86 os << indent <<
"HasPosition: " << this->GetHasPosition() << std::endl;
87 os << indent <<
"HasOrientation: " << this->GetHasOrientation() << std::endl;
88 os << indent <<
"CovErrorMatrix: " << this->GetCovErrorMatrix() << std::endl;
94 this->Superclass::CopyInformation( data );
96 const Self * nd =
nullptr;
99 nd =
dynamic_cast<const Self*
>(data);
104 itkExceptionMacro(<<
"mitk::NavigationData::CopyInformation() cannot cast "
105 <<
typeid(data).name() <<
" to "
106 <<
typeid(Self*).name() );
111 itkExceptionMacro(<<
"mitk::NavigationData::CopyInformation() cannot cast "
112 <<
typeid(data).name() <<
" to "
113 <<
typeid(Self*).name() );
121 for (
int i = 0; i < 3; i++ )
122 for (
int j = 0; j < 3; j++ )
124 m_CovErrorMatrix[ i ][ j ] = 0;
126 m_CovErrorMatrix[ i + 3 ][ j ] = 0;
127 m_CovErrorMatrix[ i ][ j + 3 ] = 0;
129 m_CovErrorMatrix[0][0] = m_CovErrorMatrix[1][1] = m_CovErrorMatrix[2][2] = error * error;
135 for (
int i = 0; i < 3; i++ )
136 for (
int j = 0; j < 3; j++ ) {
137 m_CovErrorMatrix[ i + 3 ][ j + 3 ] = 0;
139 m_CovErrorMatrix[ i + 3 ][ j ] = 0;
140 m_CovErrorMatrix[ i ][ j + 3 ] = 0;
142 m_CovErrorMatrix[3][3] = m_CovErrorMatrix[4][4] = m_CovErrorMatrix[5][5] = error * error;
148 NavigationData::Pointer nd3;
150 nd3 = getComposition(
this, n);
152 nd3 = getComposition(n,
this);
158 mitk::AffineTransform3D::Pointer affineTransform3D,
159 const bool checkForRotationMatrix) :
itk::DataObject(),
161 m_CovErrorMatrix(), m_HasPosition(true), m_HasOrientation(true), m_DataValid(true), m_IGTTimeStamp(0.0),
164 mitk::Vector3D offset = affineTransform3D->GetOffset();
170 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrix = affineTransform3D->GetMatrix().GetVnlMatrix();
171 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrixTransposed = rotationMatrix.transpose();
173 if (checkForRotationMatrix)
176 if (!
Equal(1.0, vnl_det(rotationMatrix), 0.1)
177 || !((rotationMatrix*rotationMatrixTransposed).is_identity(0.1)))
179 mitkThrow() <<
"tried to initialize NavigationData with non-rotation matrix :" << rotationMatrix <<
" (Does your AffineTransform3D object include spacing? This is not supported by NavigationData objects!)";
188mitk::AffineTransform3D::Pointer
191 AffineTransform3D::Pointer affineTransform3D = AffineTransform3D::New();
194 affineTransform3D->SetMatrix(this->GetRotationMatrix());
199 for (
int i = 0; i < 3; ++i) {
200 vector3D[i] = m_Position[i];
202 affineTransform3D->SetOffset(vector3D);
204 return affineTransform3D;
210 vnl_matrix_fixed<ScalarType,3,3> vnl_rotation = m_Orientation.rotation_matrix_transpose().transpose();
211 Matrix3D mitkRotation;
213 for (
int i = 0; i < 3; ++i) {
214 for (
int j = 0; j < 3; ++j) {
215 mitkRotation[i][j] = vnl_rotation[i][j];
225 vnl_vector_fixed<ScalarType, 3> vnlPoint;
227 for (
int i = 0; i < 3; ++i) {
228 vnlPoint[i] = point[i];
231 Quaternion normalizedQuaternion = this->GetOrientation().normalize();
233 vnlPoint = normalizedQuaternion.rotate(vnlPoint);
235 Point3D resultingPoint;
237 for (
int i = 0; i < 3; ++i) {
239 resultingPoint[i] = vnlPoint[i] + this->GetPosition()[i];
242 return resultingPoint;
245mitk::NavigationData::Pointer
249 Quaternion zeroQuaternion;
250 zeroQuaternion.fill(0);
251 if (
Equal(zeroQuaternion, this->GetOrientation()))
252 mitkThrow() <<
"tried to invert zero quaternion in NavigationData";
254 mitk::NavigationData::Pointer navigationDataInverse = this->Clone();
255 navigationDataInverse->SetOrientation(this->GetOrientation().inverse());
258 vnl_vector_fixed<ScalarType, 3> vnlPoint;
259 for (
int i = 0; i < 3; ++i) {
260 vnlPoint[i] = this->GetPosition()[i];
264 vnlPoint = -(navigationDataInverse->GetOrientation().rotate(vnlPoint));
267 Point3D invertedPosition = this->GetPosition();
268 for (
int i = 0; i < 3; ++i) {
269 invertedPosition[i] = vnlPoint[i];
272 navigationDataInverse->SetPosition(invertedPosition);
275 navigationDataInverse->ResetCovarianceValidity();
277 return navigationDataInverse;
281mitk::NavigationData::ResetCovarianceValidity()
283 this->SetHasPosition(
false);
284 this->SetHasOrientation(
false);
287mitk::NavigationData::Pointer
288mitk::NavigationData::getComposition(
const mitk::NavigationData::Pointer nd1,
289 const mitk::NavigationData::Pointer nd2)
291 NavigationData::Pointer nd3 = nd1->Clone();
294 nd3->SetOrientation(nd2->GetOrientation() * nd1->GetOrientation());
297 vnl_vector_fixed<ScalarType,3> b1, b2, b3;
298 for (
int i = 0; i < 3; ++i) {
299 b1[i] = nd1->GetPosition()[i];
300 b2[i] = nd2->GetPosition()[i];
304 b3 = nd2->GetOrientation().rotate(b1) + b2;
308 for (
int i = 0; i < 3; ++i) {
312 nd3->SetPosition(point);
314 nd3->ResetCovarianceValidity();
321 bool returnValue =
true;
324 if( !
mitk::Equal(rightHandSide.GetPosition(), leftHandSide.GetPosition(), eps) )
328 MITK_INFO <<
"[( NavigationData )] Position differs.";
329 MITK_INFO <<
"leftHandSide is " << leftHandSide.GetPosition()
330 <<
"rightHandSide is " << rightHandSide.GetPosition();
336 if( !
mitk::Equal(rightHandSide.GetOrientation(), leftHandSide.GetOrientation(), eps) )
340 MITK_INFO <<
"[( NavigationData )] Orientation differs.";
341 MITK_INFO <<
"leftHandSide is " << leftHandSide.GetOrientation()
342 <<
"rightHandSide is " << rightHandSide.GetOrientation();
347 if( rightHandSide.GetCovErrorMatrix() != leftHandSide.GetCovErrorMatrix() )
351 MITK_INFO <<
"[( NavigationData )] CovErrorMatrix differs.";
352 MITK_INFO <<
"leftHandSide is " << leftHandSide.GetCovErrorMatrix()
353 <<
"rightHandSide is " << rightHandSide.GetCovErrorMatrix();
358 if( std::string(rightHandSide.GetName()) != std::string(leftHandSide.GetName()) )
362 MITK_INFO <<
"[( NavigationData )] Name differs.";
363 MITK_INFO <<
"leftHandSide is " << leftHandSide.GetName()
364 <<
"rightHandSide is " << rightHandSide.GetName();
369 if( rightHandSide.GetIGTTimeStamp() != leftHandSide.GetIGTTimeStamp() )
373 MITK_INFO <<
"[( NavigationData )] IGTTimeStamp differs.";
374 MITK_INFO <<
"leftHandSide is " << leftHandSide.GetIGTTimeStamp()
375 <<
"rightHandSide is " << rightHandSide.GetIGTTimeStamp();
mitk::Point3D TransformPoint(const mitk::Point3D point) const
Transform by an affine transformation.
mitk::NavigationData::Pointer GetInverse() const
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Prints the object information to the given stream os.
void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.
void SetPositionAccuracy(mitk::ScalarType error)
OrientationType m_Orientation
holds the orientation part of the tracking data
void CopyInformation(const DataObject *data) override
copy meta data of a NavigationData object
mitk::AffineTransform3D::Pointer GetAffineTransform3D() const
Calculate AffineTransform3D from the transformation held by this NavigationData. TODO: should throw a...
void SetOrientationAccuracy(mitk::ScalarType error)
~NavigationData() override
mitk::Matrix3D GetRotationMatrix() const
Calculate the RotationMatrix of this transformation.
PositionType m_Position
holds the position part of the tracking data
virtual bool IsDataValid() const
returns true if the object contains valid data
void Compose(const mitk::NavigationData::Pointer n, const bool pre=false)
CovarianceMatrixType m_CovErrorMatrix
A 6x6 covariance matrix parameterizing the Gaussian error distribution of the measured position and o...
MITKIGTBASE_EXPORT bool Equal(const mitk::NavigationData &leftHandSide, const mitk::NavigationData &rightHandSide, ScalarType eps=mitk::eps, bool verbose=false)
Equal A function comparing two navigation data objects for beeing equal in meta- and imagedata.