Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTransform.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 #include "mitkTransform.h"
17 #include <fstream>
18 #include <vnl/vnl_inverse.h>
20 #include <mitkVnlVectorFromCvMat.h>
21 #include <mitkVnlMatrixFromCvMat.h>
22 #include <mitkCvMatFromVnlVector.h>
23 namespace mitk
24 {
25  // DO NOT CHANGE THE VALUES OF THESE CONSTANTS!!
26  const std::string Transform::UNKNOWN_TYPE = "Unknown type";
27  const std::string Transform::ENDOSCOPE_SCOPE_TOOL = "Endoscope scope tool";
28  const std::string Transform::ENDOSCOPE_CAM_TOOL = "Endoscope camera tool";
29  const std::string Transform::CHESSBOARD_TOOL = "Chessboard tool";
30  const std::string Transform::POINTER_TOOL = "Pointer tool";
31  const std::string Transform::POINTER_TO_CHESSBOARD_ORIGIN = "Pointer to chessboard origin";
32  const std::string Transform::POINTER_TO_CHESSBOARD_X_SUPPORT_POINT = "Pointer to chessboard X support origin";
33  const std::string Transform::POINTER_TO_CHESSBOARD_Y_SUPPORT_POINT = "Pointer to chessboard Y support origin";
34  const std::string Transform::BOARD_TO_BOARD_TOOL = "Board to board tool";
35  const std::string Transform::REFERENCE_CAMERA_TRANSFORM = "Reference camera transform";
36  const std::string Transform::REFERENCE_SCOPE_TRANSFORM = "Reference scope transform";
37  const std::string Transform::EYE_TO_HAND_TRANSFORM = "Eye to hand transform";
38  const std::string Transform::CAMERA_EXTRINSICS = "Camera extrinsics";
39 
41  : m_NavData(mitk::NavigationData::New()), m_Type( UNKNOWN_TYPE )
42  {
43  vnl_matrix_fixed<mitk::ScalarType, 3, 3> rot;
44  rot.set_identity();
45  this->SetRotation( rot );
46  }
47 
49  : m_NavData(mitk::NavigationData::New()), m_Type( UNKNOWN_TYPE )
50  {
51  m_NavData->Graft(nd);
52  }
53 
54  Transform::Transform(const std::string& s)
55  : m_NavData(mitk::NavigationData::New()), m_Type( s )
56  {
57  vnl_matrix_fixed<mitk::ScalarType, 3, 3> rot;
58  rot.set_identity();
59  this->SetRotation( rot );
60  }
61 
63  {
64  (const_cast<mitk::NavigationData*>(m_NavData.GetPointer()))->Graft(nd);
65  }
66 
68  {
69  vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat = transform->GetMatrix();
70  mat = mat * this->GetMatrix(); //
71  this->SetMatrix( mat );
72 
73  }
74 
75  void Transform::Concatenate( const vnl_matrix_fixed<mitk::ScalarType, 4, 4>&
76  transform )
77  {
79  t->SetMatrix( transform );
80  this->Concatenate( t );
81  }
82 
83  void Transform::Concatenate( const vtkMatrix4x4* transform )
84  {
86  t->SetMatrix( transform );
87  this->Concatenate( t );
88  }
89 
91  {
94  this->Copy( nd );
95  }
97  const vnl_quaternion<mitk::ScalarType>& orientation)
98  {
99  m_NavData->SetOrientation(orientation);
100  this->Modified();
101  }
102 
103  void Transform::SetTranslation( const vnl_vector_fixed<mitk::ScalarType, 3>&
104  transl)
105  {
106  mitk::Point3D p;
107  for(unsigned int i=0; i<3; ++i)
108  p[i] = transl[i];
109 
110  m_NavData->SetPosition(p);
111  this->Modified();
112  }
113 
114  void Transform::SetTranslation( float* array )
115  {
116  vnl_vector_fixed<mitk::ScalarType, 3> vec;
117  for(unsigned int i=0; i<vec.size(); i++)
118  vec(i) = array[i];
119  this->SetTranslation( vec );
120  }
121 
122  void Transform::SetRotation( float* array )
123  {
124  vnl_matrix_fixed<mitk::ScalarType, 3, 3> mat;
125 
126  unsigned int row = 0;
127  unsigned int col = 0;
128  for(unsigned int i=0; i<mat.rows()*mat.cols(); i++)
129  {
130  if( i > 0 && i % 3 == 0 )
131  {
132  ++row;
133  col = 0;
134  }
135 
136  mat(row,col) = array[i];
137  ++col;
138  }
139 
140  this->SetRotation( mat );
141  }
142 
143  void Transform::SetOrientation( const vnl_quaternion<float>& orientation)
144  {
145  vnl_vector_fixed<mitk::ScalarType, 4> qvec;
146  VnlVectorFixedCaster<float, mitk::ScalarType, 4> caster( &orientation, &qvec );
147  caster.Update();
148 
149  mitk::Quaternion p( qvec );
150 
151  this->SetOrientation( p );
152  }
153 
154  vnl_vector_fixed<double, 3> Transform::GetVnlDoubleTranslation() const
155  {
156  vnl_vector_fixed<mitk::ScalarType, 3> vecFloat = this->GetVnlTranslation();
157  vnl_vector_fixed<double, 3> vecDouble;
158  VnlVectorFixedCaster<mitk::ScalarType, double, 3> caster( &vecFloat, &vecDouble );
159  caster.Update();
160 
161  return vecDouble;
162  }
163 
164  void Transform::SetTranslation( const vnl_vector<double>& transl)
165  {
166  vnl_vector_fixed<double, 3> dTransl(transl);
167  vnl_vector_fixed<mitk::ScalarType, 3> fTransl;
168  VnlVectorFixedCaster<double, mitk::ScalarType, 3> caster( &dTransl, &fTransl );
169  caster.Update();
170 
171  this->SetTranslation( fTransl );
172  }
173 
174  vnl_quaternion<double> Transform::GetVnlDoubleQuaternion() const
175  {
176  mitk::Quaternion fOrientation = this->GetOrientation();
177  vnl_quaternion<double> dOrientation;
178  VnlVectorFixedCaster<mitk::ScalarType, double, 4> caster( &fOrientation, &dOrientation );
179  caster.Update();
180 
181  return dOrientation;
182  }
183 
184  void Transform::FromCSVFile(const std::string& file)
185  {
186  std::ifstream csvFile (file.c_str());
187  endoAssert ( csvFile.fail() == false );
188 
190  vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat;
191  std::string line;
192  mitk::ScalarType d = 0.0f;
193  int row=0,column = 0;
194 
195  while (std::getline (csvFile, line))
196  {
197  std::istringstream linestream(line);
198  std::string item;
199  column = 0;
200  while (std::getline (linestream, item, ','))
201  {
202  std::istringstream number;
203  number.str(item);
204  number >> d;
205  mat(row, column) = d;
206  ++column;
207  }
208  ++row;
209  }
210  endoAssert( row == 4 && column == 4 );
211  transform->SetMatrix( mat );
212 
213  this->SetNavigationData( transform->GetNavigationData() );
214  // modified is called in SetNavigationData
215  }
216 
217  std::string Transform::ToCSVString() const
218  {
219  std::ostringstream s; s.precision(12);
220 
221  vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat
222  = this->GetMatrix();
223 
224  for( unsigned int j=0; j<mat.rows(); ++j )
225  {
226  for( unsigned int k=0; k<mat.cols(); ++k )
227  {
228  s << mat(j,k);
229  if(k+1<mat.cols())
230  s << ",";
231  }
232  if(j+1<mat.rows())
233  s << std::endl;
234  }
235 
236  return s.str();
237 
238  }
239 
240  std::string Transform::ToMatlabString(const std::string& varname
241  , bool printLastRow) const
242  {
243  std::ostringstream s; s.precision(12);
244 
245  vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat
246  = this->GetMatrix();
247 
248  s << varname << " = [";
249  for( unsigned int j=0; j<mat.rows(); ++j )
250  {
251  if( !printLastRow && j+1 == mat.rows() )
252  break;
253  for( unsigned int k=0; k<mat.cols(); ++k )
254  {
255  s << mat(j,k) << " ";
256  }
257  s << ";";
258  }
259  s << "];" << std::endl;
260 
261  return s.str();
262  }
263 
264  void Transform::Copy( const mitk::Transform* transform )
265  {
266  m_NavData->Graft(transform->GetNavigationData());
267  m_Type = transform->GetType();
268  }
269 
271  {
273  copy->Copy( this );
274  return copy;
275  }
276 
277  void Transform::SetMatrix( const vtkMatrix4x4* mat)
278  {
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);
283 
284  this->SetMatrix( vnlMat );
285  }
286 
287  void Transform::ToCSVFile(const std::string& file) const
288  {
289  std::ofstream csvFile;
290  csvFile.open(file.c_str());
291  endoAssert ( csvFile.fail() == false );
292  csvFile << this->ToCSVString();
293  csvFile.close();
294  }
295 
296  void Transform::ToMatlabFile(const std::string& file
297  , const std::string& varname) const
298  {
299  std::ofstream csvFile;
300  csvFile.open(file.c_str());
301  endoAssert ( csvFile.fail() == false );
302  csvFile << this->ToMatlabString(varname);
303  csvFile.close();
304  }
305 
307  {
308  endoAssert( naviData != nullptr );
309  m_NavData->Graft( naviData );
310  this->Modified();
311  }
312 
313  void Transform::SetRotation( vnl_matrix_fixed<mitk::ScalarType, 3, 3>& mat)
314  {
315  this->m_NavData->SetOrientation( mitk::Quaternion(mat) );
316  this->Modified();
317  }
318 
319  void Transform::SetRotation( vnl_matrix<mitk::ScalarType>& mat)
320  {
321  vnl_matrix_fixed<mitk::ScalarType, 3, 3> tmp(mat);
322  this->SetRotation( tmp );
323  }
324 
326  {
327  this->SetTranslation( transl.GetVnlVector() );
328  }
329 
330  void Transform::SetTranslation( double array[3] )
331  {
332  mitk::Point3D p;
333  for(unsigned int i = 0; i < 3; ++i)
334  p.SetElement(i, array[i]);
335  this->SetTranslation( p.GetVnlVector() );
336  }
337 
338 
339  void Transform::SetRotation( double array[3][3] )
340  {
341  vnl_matrix_fixed<mitk::ScalarType, 3, 3> mat;
342 
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];
346  this->SetRotation( mat );
347  }
348 
350  {
351  vnl_matrix_fixed<mitk::ScalarType, 4, 4> tmp(this->GetMatrix());
352  this->SetMatrix( vnl_inverse( tmp ) );
353  }
354 
356  const vnl_matrix_fixed<mitk::ScalarType, 4, 4>& mat)
357  {
358  // set translation first
359  vnl_vector<mitk::ScalarType> transl = mat.get_column(3);
360  mitk::Point3D p;
361  for(unsigned int i=0; i<3; ++i)
362  p[i] = transl[i];
363 
364  m_NavData->SetPosition(p);
365 
366  // set rotation
367  vnl_matrix_fixed<mitk::ScalarType, 3, 3> rotMatFixed(
368  mat.extract(3,3));
369  this->SetRotation(rotMatFixed);
370  }
371 
372  bool Transform::IsValid() const
373  {
374  return m_NavData->IsDataValid();
375  }
376 
377  void Transform::SetTranslation( const cv::Mat& transl)
378  {
379  vnl_vector<mitk::ScalarType> vec(3);
380  VnlVectorFromCvMat<mitk::ScalarType> _VnlVectorFromCvMat( &transl, &vec );
381  _VnlVectorFromCvMat.Update();
382  this->SetTranslation( vnl_vector_fixed<mitk::ScalarType, 3>( vec ) );
383  }
384 
385  void Transform::SetRotation( const cv::Mat& mat )
386  {
387  vnl_matrix<mitk::ScalarType> vnlMat(3, 3);
388  VnlMatrixFromCvMat<mitk::ScalarType> _VnlMatrixFromCvMat( &mat, &vnlMat );
389  _VnlMatrixFromCvMat.Update();
390  vnl_matrix_fixed<mitk::ScalarType, 3, 3> vnlMatFixed(vnlMat);
391 
392  this->SetRotation(vnlMatFixed);
393  }
394 
395  void Transform::SetRotationVector( const cv::Mat& rotVec )
396  {
397  cv::Mat rotMat;
398  cv::Rodrigues( rotVec, rotMat );
399 
400  vnl_matrix<mitk::ScalarType> vnlMat(3, 3);
401  VnlMatrixFromCvMat<mitk::ScalarType> _VnlMatrixFromCvMat( &rotMat, &vnlMat );
402  _VnlMatrixFromCvMat.Update();
403 
404 
405  vnl_matrix_fixed<mitk::ScalarType, 3, 3> vnlMatFixed(vnlMat);
406 
407  this->SetRotation( vnlMatFixed );
408  }
409 
410  //# getter
412  {
413  return m_NavData;
414  }
415 
417  {
418  return m_NavData->GetPosition();
419  }
420 
422  {
423  return m_NavData->GetPosition();
424  }
425 
427  {
428  return m_NavData->GetOrientation();
429  }
430 
431  void Transform::GetMatrix(vtkMatrix4x4* matrix) const
432  {
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));
437  }
438 
439  void Transform::GetVtkOpenGlMatrix(vtkMatrix4x4* matrix) const
440  {
441  vnl_matrix<mitk::ScalarType> vnlRotation
442  = this->GetVnlRotationMatrix().as_matrix();
443 
444  // normalize rows of rotation matrix
445  vnlRotation.normalize_rows();
446 
447  vnl_matrix<mitk::ScalarType> vnlInverseRotation(3,3);
448  // invert rotation
449  vnlInverseRotation = vnl_matrix_inverse<mitk::ScalarType>(vnlRotation);
450 
451  vnl_vector<mitk::ScalarType> vnlTranslation
452  = this->GetPosition().GetVnlVector();
453  // rotate translation vector by inverse rotation P = P'
454  vnlTranslation = vnlInverseRotation * vnlTranslation;
455  vnlTranslation *= -1; // save -P'
456 
457  // set position
459 
460  tmp->SetTranslation( vnlTranslation );
461  tmp->SetRotation( vnlRotation );
462  tmp->GetMatrix(matrix);
463  }
464 
466  {
467  itk::Matrix<mitk::ScalarType,3,3> R(GetVnlRotationMatrix());
468  itk::Point<mitk::ScalarType,3> pointR = (R * point);
469  mitk::Point3D retPoint = pointR;
470  retPoint[0] = pointR[0] + GetPosition()[0];
471  retPoint[1] = pointR[1] + GetPosition()[1];
472  retPoint[2] = pointR[2] + GetPosition()[2];
473  return retPoint;
474  }
475 
476  //# cv getter
478  {
479  cv::Mat mat;
480  vnl_vector<mitk::ScalarType> vec = this->GetVnlTranslation().as_vector();
481  endodebugvar( vec )
482  CvMatFromVnlVector<mitk::ScalarType> _CvMatFromVnlVector(&vec, &mat);
483  _CvMatFromVnlVector.Update();
484  return mat;
485  }
486 
488  {
489  cv::Mat mat;
490  vnl_matrix<mitk::ScalarType> vec = this->GetVnlRotationMatrix().as_matrix();
491  endodebugvar( vec )
492  CvMatFromVnlMatrix<mitk::ScalarType> _CvMatFromVnlMatrix(&vec, &mat);
493  _CvMatFromVnlMatrix.Update();
494  return mat;
495  }
496 
497  cv::Mat Transform::GetCvMatrix() const
498  {
499  cv::Mat mat;
500  vnl_matrix<mitk::ScalarType> vec = this->GetMatrix().as_matrix();
501  CvMatFromVnlMatrix<mitk::ScalarType> _CvMatFromVnlMatrix(&vec, &mat);
502  _CvMatFromVnlMatrix.Update();
503  return mat;
504  }
505 
507  {
508  cv::Mat rotVec(3,1,cv::DataType<mitk::ScalarType>::type);
509  cv::Rodrigues( this->GetCvRotationMatrix(), rotVec );
510  return rotVec;
511  }
512 
513  //# vnl getter
514  vnl_vector_fixed<mitk::ScalarType, 3> Transform::GetVnlTranslation() const
515  {
516  vnl_vector_fixed<mitk::ScalarType, 3> vec(m_NavData->GetPosition()
517  .GetVnlVector());
518  return vec;
519  }
520 
521  vnl_matrix_fixed<mitk::ScalarType, 3, 3> Transform::GetVnlRotationMatrix() const
522  {
523  return m_NavData->GetOrientation().rotation_matrix_transpose();
524  }
525 
526  vnl_matrix_fixed<double, 4, 4> Transform::GetVnlDoubleMatrix() const
527  {
528  vnl_matrix_fixed<mitk::ScalarType, 4, 4> mat = this->GetMatrix();
529 
530  vnl_matrix_fixed<double, 4, 4> doubleMat;
531 
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) );
535 
536  return doubleMat;
537  }
538 
539  vnl_matrix_fixed<mitk::ScalarType, 4, 4> Transform::GetMatrix()
540  const
541  {
542  vnl_vector_fixed<mitk::ScalarType, 3> transl = this->GetVnlTranslation();
543  vnl_matrix_fixed<mitk::ScalarType, 3, 3> rot = this->GetVnlRotationMatrix();
544 
545  vnl_matrix_fixed<mitk::ScalarType, 4, 4> homMat;
546  homMat.set_identity();
547  //std::cout << homMat << std::endl;
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];
553 
554  return homMat;
555  }
556 
558  {
559  vnl_matrix_fixed<mitk::ScalarType, 3, 3> rotMat = this->GetVnlRotationMatrix().transpose();
560  this->SetRotation( rotMat );
561  }
562 
563  void Transform::SetValid( bool valid )
564  {
565  if( m_NavData->IsDataValid() == valid )
566  return;
567 
568  m_NavData->SetDataValid( valid );
569  this->Modified();
570  }
571 
572  std::string mitk::Transform::ToString() const
573  {
574  std::ostringstream s; s.precision(12);
575 
577  position.Fill(0.0);
578  position = m_NavData->GetPosition();
579 
580  mitk::NavigationData::OrientationType orientation(0.0, 0.0, 0.0, 0.0);
581  orientation = m_NavData->GetOrientation();
582 
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") << "]";
588 
589  return s.str();
590  }
591 
592  void mitk::Transform::ToXML(TiXmlElement* elem) const
593  {
594  std::string value = elem->ValueStr();
595  if(value.empty())
596  elem->SetValue(this->GetNameOfClass());
597 
599  position.Fill(0.0);
600  position = m_NavData->GetPosition();
601 
602  mitk::NavigationData::OrientationType orientation(0.0, 0.0, 0.0, 0.0);
603  orientation = m_NavData->GetOrientation();
604 
606  matrix.SetIdentity();
607  matrix = m_NavData->GetCovErrorMatrix();
608 
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();
616 
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]);
622 
623  elem->SetDoubleAttribute("QX", orientation[0]);
624  elem->SetDoubleAttribute("QY", orientation[1]);
625  elem->SetDoubleAttribute("QZ", orientation[2]);
626  elem->SetDoubleAttribute("QR", orientation[3]);
627 
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]);
640 
641  if (dataValid)
642  elem->SetAttribute("Valid",1);
643  else
644  elem->SetAttribute("Valid",0);
645 
646  if (hasOrientation)
647  elem->SetAttribute("hO",1);
648  else
649  elem->SetAttribute("hO",0);
650 
651  if (hasPosition)
652  elem->SetAttribute("hP",1);
653  else
654  elem->SetAttribute("hP",0);
655  }
656 
657  void mitk::Transform::FromXML(TiXmlElement* elem)
658  {
659  assert(elem);
660 
663  mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0);
666 
667  bool hasPosition = true;
668  bool hasOrientation = true;
669  bool dataValid = false;
670 
671  position.Fill(0.0);
672  matrix.SetIdentity();
673 
674  std::string type = Transform::UNKNOWN_TYPE;
675  elem->QueryStringAttribute("Type", &type);
676  elem->QueryDoubleAttribute("Time",&timestamp);
677 
678  // position and orientation is mandatory!
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");
685 
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");
694 
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]);
707 
708  int tmpval = 0;
709  elem->QueryIntAttribute("Valid", &tmpval);
710  if (tmpval == 0)
711  dataValid = false;
712  else
713  dataValid = true;
714 
715  tmpval = 0;
716  elem->QueryIntAttribute("hO", &tmpval);
717  if (tmpval == 0)
718  hasOrientation = false;
719  else
720  hasOrientation = true;
721 
722  tmpval = 0;
723  elem->QueryIntAttribute("hP", &tmpval);
724  if (tmpval == 0)
725  hasPosition = false;
726  else
727  hasPosition = true;
728 
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);
736 
737  m_NavData = nd;
738  m_Type = type;
739 
740  this->Modified();
741  }
742 
743 } // namespace mitk
744 
745 std::ostream& operator<< (std::ostream& os, mitk::Transform::Pointer p)
746 {
747  os << p->ToString();
748  return os;
749 }
static Pointer New()
static char * line
Definition: svm.cpp:2884
cv::Mat GetCvTranslation() const
itk::SmartPointer< Self > Pointer
static const std::string BOARD_TO_BOARD_TOOL
Definition: mitkTransform.h:61
mitk::Quaternion GetOrientation() const
itk::Matrix< mitk::ScalarType, 6, 6 > CovarianceMatrixType
type that holds the error characterization of the position and orientation measurements ...
void ToMatlabFile(const std::string &file, const std::string &varname="transform") const
double ScalarType
Navigation Data.
static const std::string ENDOSCOPE_CAM_TOOL
Definition: mitkTransform.h:55
vnl_quaternion< double > GetVnlDoubleQuaternion() const
void FromXML(TiXmlElement *elem) override
static Pointer New()
DataCollection - Class to facilitate loading/accessing structured data.
mitk::Point3D GetPosition() const
virtual std::string GetType() const
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
void Concatenate(mitk::Transform *transform)
static const std::string UNKNOWN_TYPE
Definition: mitkTransform.h:53
void SetOrientation(const vnl_quaternion< mitk::ScalarType > &orientation)
mitk::NavigationData::Pointer m_NavData
void ToCSVFile(const std::string &file) const
double TimeStampType
type that holds the time at which the data was recorded
vnl_matrix_fixed< mitk::ScalarType, 3, 3 > GetVnlRotationMatrix() const
std::string m_Type
static const std::string EYE_TO_HAND_TRANSFORM
Definition: mitkTransform.h:64
static const std::string ENDOSCOPE_SCOPE_TOOL
Definition: mitkTransform.h:54
mitk::Point3D GetTranslation() const
cv::Mat GetCvMatrix() const
void SetNavigationData(const mitk::NavigationData *naviData)
vnl_vector_fixed< mitk::ScalarType, 3 > GetVnlTranslation() const
void SetTranslation(const vnl_vector_fixed< mitk::ScalarType, 3 > &transl)
static const std::string REFERENCE_CAMERA_TRANSFORM
Definition: mitkTransform.h:62
vnl_quaternion< ScalarType > Quaternion
static const std::string POINTER_TO_CHESSBOARD_ORIGIN
Definition: mitkTransform.h:58
void Copy(const mitk::Transform *transform)
vnl_matrix_fixed< double, 4, 4 > GetVnlDoubleMatrix() const
mitk::NavigationData::Pointer GetNavigationData() const
void SetMatrix(const vnl_matrix_fixed< mitk::ScalarType, 4, 4 > &mat)
class representing a transfrom in 3D
Definition: mitkTransform.h:40
static const std::string CHESSBOARD_TOOL
Definition: mitkTransform.h:56
static const std::string POINTER_TOOL
Definition: mitkTransform.h:57
static const std::string POINTER_TO_CHESSBOARD_Y_SUPPORT_POINT
Definition: mitkTransform.h:60
#define endoAssert(a)
std::string ToCSVString() const
static const std::string CAMERA_EXTRINSICS
Definition: mitkTransform.h:65
void ToXML(TiXmlElement *elem) const override
void SetRotationVector(const cv::Mat &rotVec)
std::ostream & operator<<(std::ostream &os, mitk::Transform::Pointer p)
std::string ToMatlabString(const std::string &varname="transform", bool printLastRow=true) const
mitk::Transform::Pointer Clone() const
void SetValid(bool valid)
cv::Mat GetCvRotationMatrix() const
std::string ToString() const
static const std::string REFERENCE_SCOPE_TRANSFORM
Definition: mitkTransform.h:63
void GetVtkOpenGlMatrix(vtkMatrix4x4 *matrix) const
void SetPosition(const mitk::Point3D &transl)
vnl_matrix_fixed< mitk::ScalarType, 4, 4 > GetMatrix() const
mitk::Point3D TransformPoint(mitk::Point3D point) const
cv::Mat GetCvRotationVector() const
static const std::string POINTER_TO_CHESSBOARD_X_SUPPORT_POINT
Definition: mitkTransform.h:59
vnl_vector_fixed< double, 3 > GetVnlDoubleTranslation() const
bool IsValid() const
void SetRotation(vnl_matrix_fixed< mitk::ScalarType, 3, 3 > &mat)
#define endodebugvar(var)
void FromCSVFile(const std::string &file)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.