1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 #include "clitkMatrix.h"
22 //--------------------------------------------------------------------
25 //-------------------------------------------------------------------
27 Get4x4MatrixDoubleAsString(vtkMatrix4x4 *matrix,
30 std::ostringstream strmatrix;
32 // Figure out the number of digits of the integer part of the largest absolute value
35 for (unsigned int j = 0; j < 4; j++){
37 for (unsigned int i = 0; i < 4; i++)
38 absmax = std::max(absmax, vnl_math_abs(matrix->GetElement(i, j)));
39 unsigned ndigits = (unsigned)std::max(0.,std::log10(absmax))+1;
40 width[j] = precision+ndigits+3;
43 // Output with correct width, aligned to the right
44 for (unsigned int i = 0; i < 4; i++) {
45 for (unsigned int j = 0; j < 4; j++) {
46 strmatrix.setf(ios::fixed,ios::floatfield);
47 strmatrix.precision(precision);
49 strmatrix.width(width[j]);
50 strmatrix << std::right << matrix->GetElement(i, j);
52 strmatrix << std::endl;
54 std::string result = strmatrix.str().c_str();
57 //-------------------------------------------------------------------
59 //-------------------------------------------------------------------
61 Get4x4MatrixDoubleAsString(itk::Matrix<double, 4, 4> m,
64 vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
65 for (unsigned int j = 0; j < 4; j++)
66 for (unsigned int i = 0; i < 4; i++)
67 matrix->SetElement(j,i,m[j][i]);
68 return Get4x4MatrixDoubleAsString(matrix, precision);
70 //-------------------------------------------------------------------
72 //-------------------------------------------------------------------