14 #include "vnl/vnl_det.h" 18 m_Position(), m_Orientation(0.0, 0.0, 0.0, 1.0), m_CovErrorMatrix(),
19 m_HasPosition(true), m_HasOrientation(true), m_DataValid(false), m_IGTTimeStamp(0.0),
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() );
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;
86 os << indent <<
"HasPosition: " << this->
GetHasPosition() << 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++ )
135 for (
int i = 0; i < 3; i++ )
136 for (
int j = 0; j < 3; j++ ) {
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(),
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!)";
188 mitk::AffineTransform3D::Pointer
191 AffineTransform3D::Pointer affineTransform3D = AffineTransform3D::New();
199 for (
int i = 0; i < 3; ++i) {
202 affineTransform3D->SetOffset(vector3D);
204 return affineTransform3D;
210 vnl_matrix_fixed<ScalarType,3,3> vnl_rotation =
m_Orientation.rotation_matrix_transpose().transpose();
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];
233 vnlPoint = normalizedQuaternion.rotate(vnlPoint);
237 for (
int i = 0; i < 3; ++i) {
239 resultingPoint[i] = vnlPoint[i] + this->
GetPosition()[i];
242 return resultingPoint;
245 mitk::NavigationData::Pointer
250 zeroQuaternion.fill(0);
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) {
264 vnlPoint = -(navigationDataInverse->GetOrientation().rotate(vnlPoint));
268 for (
int i = 0; i < 3; ++i) {
269 invertedPosition[i] = vnlPoint[i];
272 navigationDataInverse->SetPosition(invertedPosition);
275 navigationDataInverse->ResetCovarianceValidity();
277 return navigationDataInverse;
281 mitk::NavigationData::ResetCovarianceValidity()
287 mitk::NavigationData::Pointer
288 mitk::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;
328 MITK_INFO <<
"[( NavigationData )] Position differs.";
330 <<
"rightHandSide is " << rightHandSide.
GetPosition();
340 MITK_INFO <<
"[( NavigationData )] Orientation differs.";
351 MITK_INFO <<
"[( NavigationData )] CovErrorMatrix differs.";
358 if( std::string(rightHandSide.
GetName()) != std::string(leftHandSide.
GetName()) )
362 MITK_INFO <<
"[( NavigationData )] Name differs.";
364 <<
"rightHandSide is " << rightHandSide.
GetName();
373 MITK_INFO <<
"[( NavigationData )] IGTTimeStamp differs.";
void SetOrientationAccuracy(mitk::ScalarType error)
void CopyInformation(const DataObject *data) override
copy meta data of a NavigationData object
bool m_HasPosition
defines if position part of m_CovErrorMatrix is valid
bool m_HasOrientation
defines if orientation part of m_CovErrorMatrix is valid
virtual void SetCovErrorMatrix(CovarianceMatrixType _arg)
sets the 6x6 Error Covariance Matrix of the NavigationData object
OrientationType m_Orientation
holds the orientation part of the tracking data
virtual void SetName(const char *_arg)
set the name of the NavigationData object
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Prints the object information to the given stream os.
mitk::AffineTransform3D::Pointer GetAffineTransform3D() const
Calculate AffineTransform3D from the transformation held by this NavigationData. TODO: should throw a...
virtual void SetDataValid(bool _arg)
sets the dataValid flag of the NavigationData object indicating if the object contains valid data ...
virtual void SetIGTTimeStamp(TimeStampType _arg)
sets the IGT timestamp of the NavigationData object in milliseconds
virtual const char * GetName() const
returns the name of the NavigationData object
CovarianceMatrixType m_CovErrorMatrix
A 6x6 covariance matrix parameterizing the Gaussian error distribution of the measured position and o...
virtual PositionType GetPosition() const
returns position of the NavigationData object
virtual void SetHasPosition(bool _arg)
sets the HasPosition flag of the NavigationData object
~NavigationData() override
virtual TimeStampType GetIGTTimeStamp() const
gets the IGT timestamp of the NavigationData object in milliseconds Please note, that there is also t...
virtual void SetHasOrientation(bool _arg)
sets the HasOrientation flag of the NavigationData object
mitk::NavigationData::Pointer GetInverse() const
virtual void SetOrientation(OrientationType _arg)
sets the orientation of the NavigationData object
std::string m_Name
name of the navigation data
vnl_quaternion< ScalarType > Quaternion
virtual bool GetHasPosition() const
gets the HasPosition flag of the NavigationData object
virtual void SetPosition(PositionType _arg)
sets the position of the NavigationData object
mitk::Point3D TransformPoint(const mitk::Point3D point) const
Transform by an affine transformation.
TimeStampType m_IGTTimeStamp
contains the time at which the tracking data was recorded
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 bool GetHasOrientation() const
gets the HasOrientation flag of the NavigationData object
void Compose(const mitk::NavigationData::Pointer n, const bool pre=false)
mitk::Matrix3D GetRotationMatrix() const
Calculate the RotationMatrix of this transformation.
PositionType m_Position
holds the position part of the tracking data
MITKCORE_EXPORT const ScalarType eps
bool m_DataValid
defines if the object contains valid values
virtual CovarianceMatrixType GetCovErrorMatrix() const
gets the 6x6 Error Covariance Matrix of the NavigationData object
virtual OrientationType GetOrientation() const
returns the orientation of the NavigationData object
virtual bool IsDataValid() const
returns true if the object contains valid data
void SetPositionAccuracy(mitk::ScalarType error)