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