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