14 #include <vnl/vnl_inverse.h> 39 vnl_matrix_fixed<mitk::ScalarType, 3, 3> rot;
53 vnl_matrix_fixed<mitk::ScalarType, 3, 3> rot;
65 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat = transform->
GetMatrix();
75 t->SetMatrix( transform );
82 t->SetMatrix( transform );
88 mitk::NavigationData::Pointer nd
93 const vnl_quaternion<mitk::ScalarType>& orientation)
103 for(
unsigned int i=0; i<3; ++i)
112 vnl_vector_fixed<mitk::ScalarType, 3> vec;
113 for(
unsigned int i=0; i<vec.size(); i++)
120 vnl_matrix_fixed<mitk::ScalarType, 3, 3> mat;
122 unsigned int row = 0;
123 unsigned int col = 0;
124 for(
unsigned int i=0; i<mat.rows()*mat.cols(); i++)
126 if( i > 0 && i % 3 == 0 )
132 mat(row,col) = array[i];
141 vnl_vector_fixed<mitk::ScalarType, 4> qvec;
153 vnl_vector_fixed<double, 3> vecDouble;
162 vnl_vector_fixed<double, 3> dTransl(transl);
163 vnl_vector_fixed<mitk::ScalarType, 3> fTransl;
173 vnl_quaternion<double> dOrientation;
182 std::ifstream csvFile (file.c_str());
186 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat;
189 int row=0,column = 0;
191 while (std::getline (csvFile, line))
193 std::istringstream linestream(line);
196 while (std::getline (linestream, item,
','))
198 std::istringstream number;
201 mat(row, column) = d;
207 transform->SetMatrix( mat );
215 std::ostringstream s; s.precision(12);
217 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat
220 for(
unsigned int j=0; j<mat.rows(); ++j )
222 for(
unsigned int k=0;
k<mat.cols(); ++
k )
237 ,
bool printLastRow)
const 239 std::ostringstream s; s.precision(12);
241 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat
244 s << varname <<
" = [";
245 for(
unsigned int j=0; j<mat.rows(); ++j )
247 if( !printLastRow && j+1 == mat.rows() )
249 for(
unsigned int k=0;
k<mat.cols(); ++
k )
251 s << mat(j,
k) <<
" ";
255 s <<
"];" << std::endl;
275 vnl_matrix_fixed<mitk::ScalarType, 4, 4> vnlMat;
276 for(
unsigned int i=0; i<4; ++i)
277 for(
unsigned int j=0; j<4; ++j)
278 vnlMat(i,j) = mat->GetElement(i, j);
285 std::ofstream csvFile;
286 csvFile.open(file.c_str());
293 ,
const std::string& varname)
const 295 std::ofstream csvFile;
296 csvFile.open(file.c_str());
317 vnl_matrix_fixed<mitk::ScalarType, 3, 3> tmp(mat);
329 for(
unsigned int i = 0; i < 3; ++i)
330 p.SetElement(i, array[i]);
337 vnl_matrix_fixed<mitk::ScalarType, 3, 3> mat;
339 for(
unsigned int i = 0; i < 3; ++i)
340 for(
unsigned int j = 0; j < 3; ++j)
341 mat(i, j) = array[i][j];
347 vnl_matrix_fixed<mitk::ScalarType, 4, 4> tmp(this->
GetMatrix());
352 const vnl_matrix_fixed<mitk::ScalarType, 4, 4>& mat)
355 vnl_vector<mitk::ScalarType> transl = mat.get_column(3);
357 for(
unsigned int i=0; i<3; ++i)
363 vnl_matrix_fixed<mitk::ScalarType, 3, 3> rotMatFixed(
375 vnl_vector<mitk::ScalarType> vec(3);
377 _VnlVectorFromCvMat.
Update();
378 this->
SetTranslation( vnl_vector_fixed<mitk::ScalarType, 3>( vec ) );
383 vnl_matrix<mitk::ScalarType> vnlMat(3, 3);
385 _VnlMatrixFromCvMat.
Update();
386 vnl_matrix_fixed<mitk::ScalarType, 3, 3> vnlMatFixed(vnlMat);
394 cv::Rodrigues( rotVec, rotMat );
396 vnl_matrix<mitk::ScalarType> vnlMat(3, 3);
398 _VnlMatrixFromCvMat.
Update();
401 vnl_matrix_fixed<mitk::ScalarType, 3, 3> vnlMatFixed(vnlMat);
429 vnl_matrix_fixed<mitk::ScalarType, 4, 4> vnlMat = this->
GetMatrix();
430 for(
unsigned int i=0; i<vnlMat.rows(); ++i)
431 for(
unsigned int j=0; j<vnlMat.cols(); ++j)
432 matrix->SetElement(i,j, vnlMat(i,j));
437 vnl_matrix<mitk::ScalarType> vnlRotation
441 vnlRotation.normalize_rows();
443 vnl_matrix<mitk::ScalarType> vnlInverseRotation(3,3);
445 vnlInverseRotation = vnl_matrix_inverse<mitk::ScalarType>(vnlRotation);
447 vnl_vector<mitk::ScalarType> vnlTranslation
450 vnlTranslation = vnlInverseRotation * vnlTranslation;
451 vnlTranslation *= -1;
456 tmp->SetTranslation( vnlTranslation );
457 tmp->SetRotation( vnlRotation );
458 tmp->GetMatrix(matrix);
464 itk::Point<mitk::ScalarType,3> pointR = (R * point);
479 _CvMatFromVnlVector.
Update();
489 _CvMatFromVnlMatrix.
Update();
496 vnl_matrix<mitk::ScalarType> vec = this->
GetMatrix().as_matrix();
498 _CvMatFromVnlMatrix.
Update();
504 cv::Mat rotVec(3,1,cv::DataType<mitk::ScalarType>::type);
512 vnl_vector_fixed<mitk::ScalarType, 3> vec(
m_NavData->GetPosition()
519 return m_NavData->GetOrientation().rotation_matrix_transpose();
524 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat = this->
GetMatrix();
526 vnl_matrix_fixed<double, 4, 4> doubleMat;
528 for(
unsigned int i=0; i<mat.rows(); ++i)
529 for(
unsigned int j=0; j<mat.cols(); ++j)
530 doubleMat(i,j) =
static_cast<double>( mat(i,j) );
541 vnl_matrix_fixed<mitk::ScalarType, 4, 4> homMat;
542 homMat.set_identity();
544 for(
unsigned int i=0; i<rot.rows(); ++i)
545 for(
unsigned int j=0; j<rot.cols(); ++j)
546 homMat(i,j) = rot(i,j);
547 for(
unsigned int i=0; i<transl.size(); ++i)
548 homMat(i,3) = transl[i];
570 std::ostringstream s; s.precision(12);
577 orientation =
m_NavData->GetOrientation();
579 s <<
"Translation: [" << position[0] <<
", " << position[1] <<
", " 580 << position[2] <<
"]";
581 s <<
", orientation: [" << orientation[0] <<
", " << orientation[1] <<
", " 582 << orientation[2] <<
", " << orientation[3] <<
"]";
583 s <<
", valid: [" << (this->
IsValid()?
"true":
"false") <<
"]";
590 std::string value = elem->ValueStr();
592 elem->SetValue(this->GetNameOfClass());
599 orientation =
m_NavData->GetOrientation();
602 matrix.SetIdentity();
605 bool hasPosition =
true;
606 hasPosition =
m_NavData->GetHasPosition();
607 bool hasOrientation =
true;
608 hasOrientation =
m_NavData->GetHasOrientation();
609 bool dataValid =
false;
613 elem->SetAttribute(
"Type",
m_Type);
614 elem->SetDoubleAttribute(
"Time", timestamp);
615 elem->SetDoubleAttribute(
"X", position[0]);
616 elem->SetDoubleAttribute(
"Y", position[1]);
617 elem->SetDoubleAttribute(
"Z", position[2]);
619 elem->SetDoubleAttribute(
"QX", orientation[0]);
620 elem->SetDoubleAttribute(
"QY", orientation[1]);
621 elem->SetDoubleAttribute(
"QZ", orientation[2]);
622 elem->SetDoubleAttribute(
"QR", orientation[3]);
624 elem->SetDoubleAttribute(
"C00", matrix[0][0]);
625 elem->SetDoubleAttribute(
"C01", matrix[0][1]);
626 elem->SetDoubleAttribute(
"C02", matrix[0][2]);
627 elem->SetDoubleAttribute(
"C03", matrix[0][3]);
628 elem->SetDoubleAttribute(
"C04", matrix[0][4]);
629 elem->SetDoubleAttribute(
"C05", matrix[0][5]);
630 elem->SetDoubleAttribute(
"C10", matrix[1][0]);
631 elem->SetDoubleAttribute(
"C11", matrix[1][1]);
632 elem->SetDoubleAttribute(
"C12", matrix[1][2]);
633 elem->SetDoubleAttribute(
"C13", matrix[1][3]);
634 elem->SetDoubleAttribute(
"C14", matrix[1][4]);
635 elem->SetDoubleAttribute(
"C15", matrix[1][5]);
638 elem->SetAttribute(
"Valid",1);
640 elem->SetAttribute(
"Valid",0);
643 elem->SetAttribute(
"hO",1);
645 elem->SetAttribute(
"hO",0);
648 elem->SetAttribute(
"hP",1);
650 elem->SetAttribute(
"hP",0);
663 bool hasPosition =
true;
664 bool hasOrientation =
true;
665 bool dataValid =
false;
668 matrix.SetIdentity();
671 elem->QueryStringAttribute(
"Type", &type);
672 elem->QueryDoubleAttribute(
"Time",×tamp);
675 if(elem->QueryDoubleAttribute(
"X", &position[0]) != TIXML_SUCCESS)
676 throw std::invalid_argument(
"No X position found in xml");
677 if(elem->QueryDoubleAttribute(
"Y", &position[1]) != TIXML_SUCCESS)
678 throw std::invalid_argument(
"No Y position found in xml");
679 if(elem->QueryDoubleAttribute(
"Z", &position[2]) != TIXML_SUCCESS)
680 throw std::invalid_argument(
"No Z position found in xml");
682 if(elem->QueryDoubleAttribute(
"QX", &orientation[0]) != TIXML_SUCCESS)
683 throw std::invalid_argument(
"No QX orientation found in xml");
684 if(elem->QueryDoubleAttribute(
"QY", &orientation[1]) != TIXML_SUCCESS)
685 throw std::invalid_argument(
"No QY orientation found in xml");
686 if(elem->QueryDoubleAttribute(
"QZ", &orientation[2]) != TIXML_SUCCESS)
687 throw std::invalid_argument(
"No QZ orientation found in xml");
688 if(elem->QueryDoubleAttribute(
"QR", &orientation[3]) != TIXML_SUCCESS)
689 throw std::invalid_argument(
"No QR orientation found in xml");
691 elem->QueryDoubleAttribute(
"C00", &matrix[0][0]);
692 elem->QueryDoubleAttribute(
"C01", &matrix[0][1]);
693 elem->QueryDoubleAttribute(
"C02", &matrix[0][2]);
694 elem->QueryDoubleAttribute(
"C03", &matrix[0][3]);
695 elem->QueryDoubleAttribute(
"C04", &matrix[0][4]);
696 elem->QueryDoubleAttribute(
"C05", &matrix[0][5]);
697 elem->QueryDoubleAttribute(
"C10", &matrix[1][0]);
698 elem->QueryDoubleAttribute(
"C11", &matrix[1][1]);
699 elem->QueryDoubleAttribute(
"C12", &matrix[1][2]);
700 elem->QueryDoubleAttribute(
"C13", &matrix[1][3]);
701 elem->QueryDoubleAttribute(
"C14", &matrix[1][4]);
702 elem->QueryDoubleAttribute(
"C15", &matrix[1][5]);
705 elem->QueryIntAttribute(
"Valid", &tmpval);
712 elem->QueryIntAttribute(
"hO", &tmpval);
714 hasOrientation =
false;
716 hasOrientation =
true;
719 elem->QueryIntAttribute(
"hP", &tmpval);
725 nd->SetIGTTimeStamp(timestamp);
726 nd->SetPosition(position);
727 nd->SetOrientation(orientation);
728 nd->SetCovErrorMatrix(matrix);
729 nd->SetDataValid(dataValid);
730 nd->SetHasOrientation(hasOrientation);
731 nd->SetHasPosition(hasPosition);
741 std::ostream&
operator<< (std::ostream& os, mitk::Transform::Pointer p)
itk::Matrix< mitk::ScalarType, 6, 6 > CovarianceMatrixType
type that holds the error characterization of the position and orientation measurements ...
DataCollection - Class to facilitate loading/accessing structured data.
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
double TimeStampType
type that holds the time at which the data was recorded in milliseconds
vnl_quaternion< ScalarType > Quaternion
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
#define endodebugvar(var)