18 #include <vnl/vnl_inverse.h>
43 vnl_matrix_fixed<mitk::ScalarType, 3, 3> rot;
57 vnl_matrix_fixed<mitk::ScalarType, 3, 3> rot;
69 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat = transform->
GetMatrix();
79 t->SetMatrix( transform );
86 t->SetMatrix( transform );
97 const vnl_quaternion<mitk::ScalarType>& orientation)
107 for(
unsigned int i=0; i<3; ++i)
116 vnl_vector_fixed<mitk::ScalarType, 3> vec;
117 for(
unsigned int i=0; i<vec.size(); i++)
124 vnl_matrix_fixed<mitk::ScalarType, 3, 3> mat;
126 unsigned int row = 0;
127 unsigned int col = 0;
128 for(
unsigned int i=0; i<mat.rows()*mat.cols(); i++)
130 if( i > 0 && i % 3 == 0 )
136 mat(row,col) = array[i];
145 vnl_vector_fixed<mitk::ScalarType, 4> qvec;
157 vnl_vector_fixed<double, 3> vecDouble;
166 vnl_vector_fixed<double, 3> dTransl(transl);
167 vnl_vector_fixed<mitk::ScalarType, 3> fTransl;
177 vnl_quaternion<double> dOrientation;
186 std::ifstream csvFile (file.c_str());
190 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat;
193 int row=0,column = 0;
195 while (std::getline (csvFile, line))
197 std::istringstream linestream(line);
200 while (std::getline (linestream, item,
','))
202 std::istringstream number;
205 mat(row, column) = d;
211 transform->SetMatrix( mat );
219 std::ostringstream s; s.precision(12);
221 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat
224 for(
unsigned int j=0; j<mat.rows(); ++j )
226 for(
unsigned int k=0; k<mat.cols(); ++k )
241 ,
bool printLastRow)
const
243 std::ostringstream s; s.precision(12);
245 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat
248 s << varname <<
" = [";
249 for(
unsigned int j=0; j<mat.rows(); ++j )
251 if( !printLastRow && j+1 == mat.rows() )
253 for(
unsigned int k=0; k<mat.cols(); ++k )
255 s << mat(j,k) <<
" ";
259 s <<
"];" << std::endl;
279 vnl_matrix_fixed<mitk::ScalarType, 4, 4> vnlMat;
280 for(
unsigned int i=0; i<4; ++i)
281 for(
unsigned int j=0; j<4; ++j)
282 vnlMat(i,j) = mat->GetElement(i, j);
289 std::ofstream csvFile;
290 csvFile.open(file.c_str());
297 ,
const std::string& varname)
const
299 std::ofstream csvFile;
300 csvFile.open(file.c_str());
321 vnl_matrix_fixed<mitk::ScalarType, 3, 3> tmp(mat);
333 for(
unsigned int i = 0; i < 3; ++i)
334 p.SetElement(i, array[i]);
341 vnl_matrix_fixed<mitk::ScalarType, 3, 3> mat;
343 for(
unsigned int i = 0; i < 3; ++i)
344 for(
unsigned int j = 0; j < 3; ++j)
345 mat(i, j) = array[i][j];
351 vnl_matrix_fixed<mitk::ScalarType, 4, 4> tmp(this->
GetMatrix());
356 const vnl_matrix_fixed<mitk::ScalarType, 4, 4>& mat)
359 vnl_vector<mitk::ScalarType> transl = mat.get_column(3);
361 for(
unsigned int i=0; i<3; ++i)
367 vnl_matrix_fixed<mitk::ScalarType, 3, 3> rotMatFixed(
379 vnl_vector<mitk::ScalarType> vec(3);
381 _VnlVectorFromCvMat.
Update();
382 this->
SetTranslation( vnl_vector_fixed<mitk::ScalarType, 3>( vec ) );
387 vnl_matrix<mitk::ScalarType> vnlMat(3, 3);
389 _VnlMatrixFromCvMat.
Update();
390 vnl_matrix_fixed<mitk::ScalarType, 3, 3> vnlMatFixed(vnlMat);
398 cv::Rodrigues( rotVec, rotMat );
400 vnl_matrix<mitk::ScalarType> vnlMat(3, 3);
402 _VnlMatrixFromCvMat.
Update();
405 vnl_matrix_fixed<mitk::ScalarType, 3, 3> vnlMatFixed(vnlMat);
433 vnl_matrix_fixed<mitk::ScalarType, 4, 4> vnlMat = this->
GetMatrix();
434 for(
unsigned int i=0; i<vnlMat.rows(); ++i)
435 for(
unsigned int j=0; j<vnlMat.cols(); ++j)
436 matrix->SetElement(i,j, vnlMat(i,j));
441 vnl_matrix<mitk::ScalarType> vnlRotation
445 vnlRotation.normalize_rows();
447 vnl_matrix<mitk::ScalarType> vnlInverseRotation(3,3);
449 vnlInverseRotation = vnl_matrix_inverse<mitk::ScalarType>(vnlRotation);
451 vnl_vector<mitk::ScalarType> vnlTranslation
454 vnlTranslation = vnlInverseRotation * vnlTranslation;
455 vnlTranslation *= -1;
460 tmp->SetTranslation( vnlTranslation );
461 tmp->SetRotation( vnlRotation );
462 tmp->GetMatrix(matrix);
468 itk::Point<mitk::ScalarType,3> pointR = (R * point);
483 _CvMatFromVnlVector.
Update();
493 _CvMatFromVnlMatrix.
Update();
500 vnl_matrix<mitk::ScalarType> vec = this->
GetMatrix().as_matrix();
502 _CvMatFromVnlMatrix.
Update();
508 cv::Mat rotVec(3,1,cv::DataType<mitk::ScalarType>::type);
516 vnl_vector_fixed<mitk::ScalarType, 3> vec(
m_NavData->GetPosition()
523 return m_NavData->GetOrientation().rotation_matrix_transpose();
528 vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat = this->
GetMatrix();
530 vnl_matrix_fixed<double, 4, 4> doubleMat;
532 for(
unsigned int i=0; i<mat.rows(); ++i)
533 for(
unsigned int j=0; j<mat.cols(); ++j)
534 doubleMat(i,j) =
static_cast<double>( mat(i,j) );
545 vnl_matrix_fixed<mitk::ScalarType, 4, 4> homMat;
546 homMat.set_identity();
548 for(
unsigned int i=0; i<rot.rows(); ++i)
549 for(
unsigned int j=0; j<rot.cols(); ++j)
550 homMat(i,j) = rot(i,j);
551 for(
unsigned int i=0; i<transl.size(); ++i)
552 homMat(i,3) = transl[i];
574 std::ostringstream s; s.precision(12);
578 position = m_NavData->GetPosition();
581 orientation = m_NavData->GetOrientation();
583 s <<
"Translation: [" << position[0] <<
", " << position[1] <<
", "
584 << position[2] <<
"]";
585 s <<
", orientation: [" << orientation[0] <<
", " << orientation[1] <<
", "
586 << orientation[2] <<
", " << orientation[3] <<
"]";
587 s <<
", valid: [" << (this->IsValid()?
"true":
"false") <<
"]";
594 std::string value = elem->ValueStr();
596 elem->SetValue(this->GetNameOfClass());
600 position = m_NavData->GetPosition();
603 orientation = m_NavData->GetOrientation();
606 matrix.SetIdentity();
607 matrix = m_NavData->GetCovErrorMatrix();
609 bool hasPosition =
true;
610 hasPosition = m_NavData->GetHasPosition();
611 bool hasOrientation =
true;
612 hasOrientation = m_NavData->GetHasOrientation();
613 bool dataValid =
false;
614 dataValid = m_NavData->IsDataValid();
617 elem->SetAttribute(
"Type", m_Type);
618 elem->SetDoubleAttribute(
"Time", timestamp);
619 elem->SetDoubleAttribute(
"X", position[0]);
620 elem->SetDoubleAttribute(
"Y", position[1]);
621 elem->SetDoubleAttribute(
"Z", position[2]);
623 elem->SetDoubleAttribute(
"QX", orientation[0]);
624 elem->SetDoubleAttribute(
"QY", orientation[1]);
625 elem->SetDoubleAttribute(
"QZ", orientation[2]);
626 elem->SetDoubleAttribute(
"QR", orientation[3]);
628 elem->SetDoubleAttribute(
"C00", matrix[0][0]);
629 elem->SetDoubleAttribute(
"C01", matrix[0][1]);
630 elem->SetDoubleAttribute(
"C02", matrix[0][2]);
631 elem->SetDoubleAttribute(
"C03", matrix[0][3]);
632 elem->SetDoubleAttribute(
"C04", matrix[0][4]);
633 elem->SetDoubleAttribute(
"C05", matrix[0][5]);
634 elem->SetDoubleAttribute(
"C10", matrix[1][0]);
635 elem->SetDoubleAttribute(
"C11", matrix[1][1]);
636 elem->SetDoubleAttribute(
"C12", matrix[1][2]);
637 elem->SetDoubleAttribute(
"C13", matrix[1][3]);
638 elem->SetDoubleAttribute(
"C14", matrix[1][4]);
639 elem->SetDoubleAttribute(
"C15", matrix[1][5]);
642 elem->SetAttribute(
"Valid",1);
644 elem->SetAttribute(
"Valid",0);
647 elem->SetAttribute(
"hO",1);
649 elem->SetAttribute(
"hO",0);
652 elem->SetAttribute(
"hP",1);
654 elem->SetAttribute(
"hP",0);
667 bool hasPosition =
true;
668 bool hasOrientation =
true;
669 bool dataValid =
false;
672 matrix.SetIdentity();
675 elem->QueryStringAttribute(
"Type", &type);
676 elem->QueryDoubleAttribute(
"Time",×tamp);
679 if(elem->QueryDoubleAttribute(
"X", &position[0]) != TIXML_SUCCESS)
680 throw std::invalid_argument(
"No X position found in xml");
681 if(elem->QueryDoubleAttribute(
"Y", &position[1]) != TIXML_SUCCESS)
682 throw std::invalid_argument(
"No Y position found in xml");
683 if(elem->QueryDoubleAttribute(
"Z", &position[2]) != TIXML_SUCCESS)
684 throw std::invalid_argument(
"No Z position found in xml");
686 if(elem->QueryDoubleAttribute(
"QX", &orientation[0]) != TIXML_SUCCESS)
687 throw std::invalid_argument(
"No QX orientation found in xml");
688 if(elem->QueryDoubleAttribute(
"QY", &orientation[1]) != TIXML_SUCCESS)
689 throw std::invalid_argument(
"No QY orientation found in xml");
690 if(elem->QueryDoubleAttribute(
"QZ", &orientation[2]) != TIXML_SUCCESS)
691 throw std::invalid_argument(
"No QZ orientation found in xml");
692 if(elem->QueryDoubleAttribute(
"QR", &orientation[3]) != TIXML_SUCCESS)
693 throw std::invalid_argument(
"No QR orientation found in xml");
695 elem->QueryDoubleAttribute(
"C00", &matrix[0][0]);
696 elem->QueryDoubleAttribute(
"C01", &matrix[0][1]);
697 elem->QueryDoubleAttribute(
"C02", &matrix[0][2]);
698 elem->QueryDoubleAttribute(
"C03", &matrix[0][3]);
699 elem->QueryDoubleAttribute(
"C04", &matrix[0][4]);
700 elem->QueryDoubleAttribute(
"C05", &matrix[0][5]);
701 elem->QueryDoubleAttribute(
"C10", &matrix[1][0]);
702 elem->QueryDoubleAttribute(
"C11", &matrix[1][1]);
703 elem->QueryDoubleAttribute(
"C12", &matrix[1][2]);
704 elem->QueryDoubleAttribute(
"C13", &matrix[1][3]);
705 elem->QueryDoubleAttribute(
"C14", &matrix[1][4]);
706 elem->QueryDoubleAttribute(
"C15", &matrix[1][5]);
709 elem->QueryIntAttribute(
"Valid", &tmpval);
716 elem->QueryIntAttribute(
"hO", &tmpval);
718 hasOrientation =
false;
720 hasOrientation =
true;
723 elem->QueryIntAttribute(
"hP", &tmpval);
729 nd->SetIGTTimeStamp(timestamp);
730 nd->SetPosition(position);
731 nd->SetOrientation(orientation);
732 nd->SetCovErrorMatrix(matrix);
733 nd->SetDataValid(dataValid);
734 nd->SetHasOrientation(hasOrientation);
735 nd->SetHasPosition(hasPosition);
itk::SmartPointer< Self > Pointer
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
vnl_quaternion< ScalarType > Quaternion
#define endodebugvar(var)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.