18 #include "vnl/vnl_det.h"
22 m_Position(), m_Orientation(0.0, 0.0, 0.0, 1.0), m_CovErrorMatrix(),
23 m_HasPosition(true), m_HasOrientation(true), m_DataValid(false), m_IGTTimeStamp(0.0),
32 m_Position(toCopy.GetPosition()), m_Orientation(toCopy.GetOrientation()), m_CovErrorMatrix(toCopy.GetCovErrorMatrix()),
33 m_HasPosition(toCopy.GetHasPosition()), m_HasOrientation(toCopy.GetHasOrientation()), m_DataValid(toCopy.IsDataValid()), m_IGTTimeStamp(toCopy.GetIGTTimeStamp()),
48 nd =
dynamic_cast<const Self *
>( data );
52 itkExceptionMacro( <<
"mitk::NavigationData::Graft cannot cast "
53 <<
typeid(data).name() <<
" to "
54 <<
typeid(
const Self *).name() );
60 itkExceptionMacro( <<
"mitk::NavigationData::Graft cannot cast "
61 <<
typeid(data).name() <<
" to "
62 <<
typeid(
const Self *).name() );
66 this->SetPosition(nd->GetPosition());
67 this->SetOrientation(nd->GetOrientation());
68 this->SetDataValid(nd->IsDataValid());
69 this->SetIGTTimeStamp(nd->GetIGTTimeStamp());
70 this->SetHasPosition(nd->GetHasPosition());
71 this->SetHasOrientation(nd->GetHasOrientation());
72 this->SetCovErrorMatrix(nd->GetCovErrorMatrix());
73 this->SetName(nd->GetName());
85 this->Superclass::PrintSelf(os, indent);
86 os << indent <<
"data valid: " << this->IsDataValid() << std::endl;
87 os << indent <<
"Position: " << this->GetPosition() << std::endl;
88 os << indent <<
"Orientation: " << this->GetOrientation() << std::endl;
89 os << indent <<
"TimeStamp: " << this->GetIGTTimeStamp() << std::endl;
90 os << indent <<
"HasPosition: " << this->GetHasPosition() << std::endl;
91 os << indent <<
"HasOrientation: " << this->GetHasOrientation() << std::endl;
92 os << indent <<
"CovErrorMatrix: " << this->GetCovErrorMatrix() << std::endl;
98 this->Superclass::CopyInformation( data );
100 const Self * nd =
nullptr;
103 nd =
dynamic_cast<const Self*
>(data);
108 itkExceptionMacro(<<
"mitk::NavigationData::CopyInformation() cannot cast "
109 <<
typeid(data).name() <<
" to "
110 <<
typeid(Self*).name() );
115 itkExceptionMacro(<<
"mitk::NavigationData::CopyInformation() cannot cast "
116 <<
typeid(data).name() <<
" to "
117 <<
typeid(Self*).name() );
125 for (
int i = 0; i < 3; i++ )
126 for (
int j = 0; j < 3; j++ )
128 m_CovErrorMatrix[ i ][ j ] = 0;
130 m_CovErrorMatrix[ i + 3 ][ j ] = 0;
131 m_CovErrorMatrix[ i ][ j + 3 ] = 0;
133 m_CovErrorMatrix[0][0] = m_CovErrorMatrix[1][1] = m_CovErrorMatrix[2][2] = error * error;
139 for (
int i = 0; i < 3; i++ )
140 for (
int j = 0; j < 3; j++ ) {
141 m_CovErrorMatrix[ i + 3 ][ j + 3 ] = 0;
143 m_CovErrorMatrix[ i + 3 ][ j ] = 0;
144 m_CovErrorMatrix[ i ][ j + 3 ] = 0;
146 m_CovErrorMatrix[3][3] = m_CovErrorMatrix[4][4] = m_CovErrorMatrix[5][5] = error * error;
154 nd3 = getComposition(
this, n);
156 nd3 = getComposition(n,
this);
163 const bool checkForRotationMatrix) :
itk::DataObject(),
165 m_CovErrorMatrix(), m_HasPosition(true), m_HasOrientation(true), m_DataValid(true), m_IGTTimeStamp(0.0),
174 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrix = affineTransform3D->GetMatrix().GetVnlMatrix();
175 vnl_matrix_fixed<ScalarType, 3, 3> rotationMatrixTransposed = rotationMatrix.transpose();
177 if (checkForRotationMatrix)
180 if (!
Equal(1.0, vnl_det(rotationMatrix), 0.1)
181 || !((rotationMatrix*rotationMatrixTransposed).is_identity(0.1)))
183 mitkThrow() <<
"tried to initialize NavigationData with non-rotation matrix :" << rotationMatrix <<
" (Does your AffineTransform3D object include spacing? This is not supported by NavigationData objects!)";
198 affineTransform3D->SetMatrix(this->GetRotationMatrix());
203 for (
int i = 0; i < 3; ++i) {
204 vector3D[i] = m_Position[i];
206 affineTransform3D->SetOffset(vector3D);
208 return affineTransform3D;
214 vnl_matrix_fixed<ScalarType,3,3> vnl_rotation = m_Orientation.rotation_matrix_transpose().transpose();
217 for (
int i = 0; i < 3; ++i) {
218 for (
int j = 0; j < 3; ++j) {
219 mitkRotation[i][j] = vnl_rotation[i][j];
229 vnl_vector_fixed<ScalarType, 3> vnlPoint;
231 for (
int i = 0; i < 3; ++i) {
232 vnlPoint[i] = point[i];
235 Quaternion normalizedQuaternion = this->GetOrientation().normalize();
237 vnlPoint = normalizedQuaternion.rotate(vnlPoint);
241 for (
int i = 0; i < 3; ++i) {
243 resultingPoint[i] = vnlPoint[i] + this->GetPosition()[i];
246 return resultingPoint;
254 zeroQuaternion.fill(0);
255 if (
Equal(zeroQuaternion, this->GetOrientation()))
256 mitkThrow() <<
"tried to invert zero quaternion in NavigationData";
259 navigationDataInverse->SetOrientation(this->GetOrientation().inverse());
262 vnl_vector_fixed<ScalarType, 3> vnlPoint;
263 for (
int i = 0; i < 3; ++i) {
264 vnlPoint[i] = this->GetPosition()[i];
268 vnlPoint = -(navigationDataInverse->GetOrientation().rotate(vnlPoint));
271 Point3D invertedPosition = this->GetPosition();
272 for (
int i = 0; i < 3; ++i) {
273 invertedPosition[i] = vnlPoint[i];
276 navigationDataInverse->SetPosition(invertedPosition);
279 navigationDataInverse->ResetCovarianceValidity();
281 return navigationDataInverse;
285 mitk::NavigationData::ResetCovarianceValidity()
287 this->SetHasPosition(
false);
288 this->SetHasOrientation(
false);
298 nd3->SetOrientation(nd2->GetOrientation() * nd1->GetOrientation());
301 vnl_vector_fixed<ScalarType,3> b1, b2, b3;
302 for (
int i = 0; i < 3; ++i) {
303 b1[i] = nd1->GetPosition()[i];
304 b2[i] = nd2->GetPosition()[i];
308 b3 = nd2->GetOrientation().rotate(b1) + b2;
312 for (
int i = 0; i < 3; ++i) {
316 nd3->SetPosition(point);
318 nd3->ResetCovarianceValidity();
325 bool returnValue =
true;
332 MITK_INFO <<
"[( NavigationData )] Position differs.";
334 <<
"rightHandSide is " << rightHandSide.
GetPosition();
344 MITK_INFO <<
"[( NavigationData )] Orientation differs.";
355 MITK_INFO <<
"[( NavigationData )] CovErrorMatrix differs.";
362 if( std::string(rightHandSide.
GetName()) != std::string(leftHandSide.
GetName()) )
366 MITK_INFO <<
"[( NavigationData )] Name differs.";
368 <<
"rightHandSide is " << rightHandSide.
GetName();
377 MITK_INFO <<
"[( NavigationData )] IGTTimeStamp differs.";
itk::SmartPointer< Self > Pointer
void SetOrientationAccuracy(mitk::ScalarType error)
virtual void CopyInformation(const DataObject *data) override
copy meta data of a NavigationData object
virtual const char * GetName() const
returns the name of the NavigationData object
mitk::Point3D TransformPoint(const mitk::Point3D point) const
Transform by an affine transformation.
mitk::NavigationData::Pointer GetInverse() const
OrientationType m_Orientation
holds the orientation part of the tracking data
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Prints the object information to the given stream os.
mitk::Matrix3D GetRotationMatrix() const
Calculate the RotationMatrix of this transformation.
mitk::AffineTransform3D::Pointer GetAffineTransform3D() const
Calculate AffineTransform3D from the transformation held by this NavigationData. TODO: should throw a...
virtual OrientationType GetOrientation() const
returns the orientation of the NavigationData object
CovarianceMatrixType m_CovErrorMatrix
A 6x6 covariance matrix parameterizing the Gaussian error distribution of the measured position and o...
virtual CovarianceMatrixType GetCovErrorMatrix() const
gets the 6x6 Error Covariance Matrix of the NavigationData object
virtual TimeStampType GetIGTTimeStamp() const
gets the IGT timestamp of the NavigationData object
vnl_quaternion< ScalarType > Quaternion
Point< ScalarType, 3 > Point3D
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual PositionType GetPosition() const
returns position of the NavigationData object
virtual void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
virtual ~NavigationData()
void Compose(const mitk::NavigationData::Pointer n, const bool pre=false)
PositionType m_Position
holds the position part of the tracking data
MITKCORE_EXPORT const ScalarType eps
static std::string GetName(std::string fileName, std::string suffix)
void SetPositionAccuracy(mitk::ScalarType error)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.