File: itkSymmetricEigenSystemTest.cxx

package info (click to toggle)
insighttoolkit 3.6.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 94,956 kB
  • ctags: 74,981
  • sloc: cpp: 355,621; ansic: 195,070; fortran: 28,713; python: 3,802; tcl: 1,996; sh: 1,175; java: 583; makefile: 415; csh: 184; perl: 175
file content (92 lines) | stat: -rwxr-xr-x 2,834 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*=========================================================================

Program:   Insight Segmentation & Registration Toolkit
Module:    $RCSfile: itkSymmetricEigenSystemTest.cxx,v $
Language:  C++
Date:      $Date: 2005-02-08 04:20:01 $
Version:   $Revision: 1.6 $

Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

This software is distributed WITHOUT ANY WARRANTY; without even 
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include "itkWin32Header.h"
#include <fstream>

#include "itkSymmetricEigenSystem.h"

int itkSymmetricEigenSystemTest(int , char* [] )
{
  typedef itk::SymmetricEigenSystem< double, 2 > EigenSystemType ;
  
  EigenSystemType::Pointer eigen = EigenSystemType::New() ;

  EigenSystemType::MatrixType mat ;
  mat.GetVnlMatrix().put(0, 0, 814.95741) ;
  mat.GetVnlMatrix().put(0, 1, 38.40308) ;
  mat.GetVnlMatrix().put(1, 0, 38.40308) ;
  mat.GetVnlMatrix().put(1, 1, 817.64446) ;
  EigenSystemType::EigenValueArrayType eigenValues ;
  eigenValues[0] = 854.7275 ;
  eigenValues[1] = 777.8744 ;

  EigenSystemType::EigenVectorArrayType eigenVectors ;
  eigenVectors[0][0] = 0.6946354 ;
  eigenVectors[0][1] = 0.7193620 ;
  eigenVectors[1][0] = 0.7193620 ;
  eigenVectors[1][1] = -0.6946354 ;

  double precision = 0.0000001 ;

  eigen->SetMatrix(&mat) ;
  eigen->Update() ;

  std::cout << "Matrix: " << mat << std::endl ;
  double temp ;
  std::cout.setf(std::ios::scientific, std::ios::floatfield) ;
  
  for ( unsigned int i = 0 ; i < 2 ; i++ )
    {
      temp = (*(eigen->GetEigenValues()))[i]  ;
      std::cout << "eigen value = " << temp << std::endl;
      if ( vnl_math_abs(1 - vnl_math_abs(temp / eigenValues[i])) > precision )
        {
          std::cout << "wrong eigen value " 
                    << vnl_math_abs(1 - (temp / eigenValues[i])) 
                    << std::endl ; 
          return EXIT_FAILURE;
        }
    }

  for ( unsigned int i = 0 ; i < 2 ; i++ )
    {
      std::cout << "eigen vector = " ; 
      double dotProduct = 0.0 ;
      for ( unsigned int j = 0 ; j < 2 ; j++ )
        {
          temp = (*(eigen->GetEigenVectors()))[i][j] ;
          std::cout << temp << " " ;

          dotProduct += temp * eigenVectors[i][j] ;
        }

      if ( vnl_math_abs(vnl_math_abs(dotProduct) - 1 ) > precision )
        {
          std::cout << "wrong eigen vector " << dotProduct << std::endl ; 
          return EXIT_FAILURE;
        }

      std::cout << std::endl ;
    }

  std::cout << "Test succeeded." << std::endl;
  return EXIT_SUCCESS ;
}