~ubuntu-branches/ubuntu/precise/insighttoolkit/precise

« back to all changes in this revision

Viewing changes to Testing/Code/IO/itkSymmetricSecondRankTensorImageReadTest.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2008-05-31 12:07:29 UTC
  • mfrom: (3.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080531120729-7g7layn480le43ko
Tags: 3.6.0-3
* debian/patches/gccxml-workaround.patch: New.  Work around gccxml issue
  with #include_next; c.f. http://www.gccxml.org/Bug/view.php?id=7134.  
* debian/patches/gcc43.patch: include <cstring> in itkNeighbourhood.h.
  This only showed up in the tcl wrapping step.

* Above two entries fix FTBFS for GCC 4.3-based systems.
  Closes: #478500.

* debian/patches/sharedforward.patch: New.  Ensure that linux/sparc
  systems are not also configured as a SUN sparc system, which requires
  SUN header sys/isa_defs.h.  Closes: #478940, #483312.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Insight Segmentation & Registration Toolkit
 
4
  Module:    $RCSfile: itkSymmetricSecondRankTensorImageReadTest.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2008-01-27 18:31:29 $
 
7
  Version:   $Revision: 1.4 $
 
8
 
 
9
  Copyright (c) Insight Software Consortium. All rights reserved.
 
10
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
 
11
 
 
12
     This software is distributed WITHOUT ANY WARRANTY; without even 
 
13
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 
14
     PURPOSE.  See the above copyright notices for more information.
 
15
 
 
16
=========================================================================*/
 
17
#if defined(_MSC_VER)
 
18
#pragma warning ( disable : 4786 )
 
19
#endif
 
20
 
 
21
#include <fstream>
 
22
#include "itkImageFileReader.h"
 
23
#include "itkImageFileWriter.h"
 
24
#include "itkImage.h"
 
25
#include "itkSymmetricSecondRankTensor.h"
 
26
#include "itkImageRegionIterator.h"
 
27
 
 
28
 
 
29
int itkSymmetricSecondRankTensorImageReadTest( int ac, char* av[] )
 
30
{
 
31
  if(ac < 1)
 
32
    {
 
33
    std::cerr << "Usage: " << av[0] << " Input\n";
 
34
    return EXIT_FAILURE;
 
35
    }
 
36
  
 
37
  typedef itk::SymmetricSecondRankTensor<float, 3>    TensorPixelType;
 
38
  typedef itk::Image<TensorPixelType, 3>              TensorImageType;
 
39
 
 
40
  typedef itk::Matrix<float,3,3>                      MatrixPixelType;
 
41
  typedef itk::Image<MatrixPixelType, 3>              MatrixImageType;
 
42
 
 
43
  MatrixImageType::Pointer matrixImage = MatrixImageType::New();
 
44
   
 
45
  MatrixImageType::SizeType size;
 
46
  size.Fill(10);
 
47
  
 
48
  MatrixImageType::IndexType start;
 
49
  start.Fill(0);
 
50
 
 
51
  MatrixImageType::RegionType region;
 
52
  region.SetIndex( start );
 
53
  region.SetSize( size );
 
54
 
 
55
  matrixImage->SetRegions( region );
 
56
  matrixImage->Allocate();
 
57
 
 
58
  MatrixPixelType matrixPixel;
 
59
 
 
60
  matrixPixel[0][0] = 1; 
 
61
  matrixPixel[0][1] = 2; 
 
62
  matrixPixel[0][2] = 3; 
 
63
 
 
64
  matrixPixel[1][0] = 2; 
 
65
  matrixPixel[1][1] = 4; 
 
66
  matrixPixel[1][2] = 5; 
 
67
 
 
68
  matrixPixel[2][0] = 3; 
 
69
  matrixPixel[2][1] = 5; 
 
70
  matrixPixel[2][2] = 6; 
 
71
 
 
72
  itk::ImageRegionIterator< MatrixImageType > itr( matrixImage, region );
 
73
 
 
74
  itr.GoToBegin();
 
75
 
 
76
  while( !itr.IsAtEnd() )
 
77
    {
 
78
    itr.Set( matrixPixel );
 
79
    for(unsigned int i=0; i<3; i++)
 
80
      {
 
81
      for(unsigned int j=0; j<3; j++)
 
82
        {
 
83
        matrixPixel[i][j]++;
 
84
        }
 
85
      }
 
86
    ++itr;
 
87
    }
 
88
 
 
89
  typedef itk::ImageFileWriter< MatrixImageType > MatrixWriterType;
 
90
 
 
91
  MatrixWriterType::Pointer matrixWriter = MatrixWriterType::New();
 
92
 
 
93
  matrixWriter->SetInput( matrixImage );
 
94
  matrixWriter->SetFileName( av[1] );
 
95
 
 
96
  try
 
97
    {
 
98
    matrixWriter->Update();
 
99
    }
 
100
  catch( itk::ExceptionObject & excp )
 
101
    {
 
102
    std::cerr << excp << std::endl;
 
103
    return EXIT_FAILURE;
 
104
    }
 
105
 
 
106
 
 
107
  typedef itk::ImageFileReader<  TensorImageType > TensorReaderType;
 
108
 
 
109
  TensorReaderType::Pointer tensorReader = TensorReaderType::New();
 
110
 
 
111
  tensorReader->SetFileName( av[1] );
 
112
 
 
113
  try
 
114
    {
 
115
    tensorReader->Update();
 
116
    }
 
117
  catch( itk::ExceptionObject & excp )
 
118
    {
 
119
    std::cerr << excp << std::endl;
 
120
    return EXIT_FAILURE;
 
121
    }
 
122
 
 
123
  TensorImageType::ConstPointer tensorImage = tensorReader->GetOutput();
 
124
 
 
125
  // Compare the read values to the original values
 
126
  const float tolerance = 1e-5;
 
127
 
 
128
  itk::ImageRegionConstIterator< TensorImageType > tItr( tensorImage, region );
 
129
  itk::ImageRegionConstIterator< MatrixImageType > mItr( matrixImage, region );
 
130
  
 
131
  tItr.GoToBegin();
 
132
  mItr.GoToBegin();
 
133
 
 
134
  while( !mItr.IsAtEnd() )
 
135
    {
 
136
    matrixPixel = mItr.Get();
 
137
    const TensorPixelType tensorPixel = tItr.Get();
 
138
 
 
139
    for(unsigned int i=0; i<3; i++)
 
140
      {
 
141
      for(unsigned int j=0; j<3; j++)
 
142
        {
 
143
        if( vcl_abs( matrixPixel[i][j] - tensorPixel(i,j) ) > tolerance )
 
144
          {
 
145
          std::cerr << "Tensor read does not match expected values " << std::endl;
 
146
          std::cerr << "Index " << tItr.GetIndex() << std::endl;
 
147
          std::cerr << "Tensor value " << std::endl << tensorPixel << std::endl;
 
148
          std::cerr << "Matrix value " << std::endl << matrixPixel << std::endl;
 
149
          return EXIT_FAILURE;
 
150
          }
 
151
        }
 
152
      }
 
153
    ++mItr;
 
154
    ++tItr;
 
155
    }
 
156
  
 
157
 
 
158
  return EXIT_SUCCESS;
 
159
 
 
160
}