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"
21 //--------------------------------------------------------------------
24 //-------------------------------------------------------------------
26 Get4x4MatrixDoubleAsString(vtkMatrix4x4 *matrix,
29 std::ostringstream strmatrix;
31 // Figure out the number of digits of the integer part of the largest absolute value
34 for (unsigned int j = 0; j < 4; j++){
36 for (unsigned int i = 0; i < 4; i++)
37 absmax = std::max(absmax, vnl_math_abs(matrix->GetElement(i, j)));
38 unsigned ndigits = (unsigned)std::max(0.,std::log10(absmax))+1;
39 width[j] = precision+ndigits+3;
42 // Output with correct width, aligned to the right
43 for (unsigned int i = 0; i < 4; i++) {
44 for (unsigned int j = 0; j < 4; j++) {
45 strmatrix.setf(ios::fixed,ios::floatfield);
46 strmatrix.precision(precision);
48 strmatrix.width(width[j]);
49 strmatrix << std::right << matrix->GetElement(i, j);
51 strmatrix << std::endl;
53 std::string result = strmatrix.str().c_str();
56 //-------------------------------------------------------------------
58 //-------------------------------------------------------------------
60 Get4x4MatrixDoubleAsString(itk::Matrix<double, 4, 4> m,
63 vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
64 for (unsigned int j = 0; j < 4; j++)
65 for (unsigned int i = 0; i < 4; i++)
66 matrix->SetElement(j,i,m[j][i]);
67 return Get4x4MatrixDoubleAsString(matrix, precision);
69 //-------------------------------------------------------------------
71 //-------------------------------------------------------------------