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

« back to all changes in this revision

Viewing changes to Testing/Code/Common/itkOrientedImage2DTest.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: itkOrientedImage2DTest.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2007-12-20 18:37:03 $
 
7
  Version:   $Revision: 1.5 $
 
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 "itkImageFileReader.h"
 
22
#include "itkOrientedImage.h"
 
23
#include "itkCentralDifferenceImageFunction.h"
 
24
 
 
25
int itkOrientedImage2DTest( int ac, char * av[] )
 
26
{
 
27
 
 
28
  if( ac < 12 )
 
29
    {
 
30
    std::cerr << "Usage: " << av[0] 
 
31
    << " InputImage  "
 
32
    << "corner1x corner1y "
 
33
    << "corner2x corner2y "
 
34
    << "corner3x corner3y "
 
35
    << "derivative1x derivative1y "
 
36
    << "derivative2x derivative2y "
 
37
    << std::endl;
 
38
    return EXIT_FAILURE;
 
39
    }
 
40
  
 
41
  const unsigned int Dimension = 2;
 
42
  typedef unsigned char PixelType;
 
43
 
 
44
  typedef itk::OrientedImage<PixelType, Dimension>    ImageType;
 
45
  typedef itk::ImageFileReader< ImageType >           ReaderType;
 
46
 
 
47
  typedef ImageType::IndexType                        IndexType;
 
48
  typedef ImageType::PointType                        PointType;
 
49
  typedef IndexType::IndexValueType                   IndexValueType;
 
50
 
 
51
  ReaderType::Pointer reader = ReaderType::New();
 
52
  
 
53
  reader->SetFileName( av[1] );
 
54
 
 
55
  try
 
56
    {
 
57
    reader->Update();
 
58
    }
 
59
  catch (itk::ExceptionObject & e)
 
60
    {
 
61
    std::cerr << e << std::endl;
 
62
    return EXIT_FAILURE;
 
63
    }
 
64
  
 
65
  ImageType::ConstPointer image = reader->GetOutput();
 
66
   
 
67
  ImageType::DirectionType directionCosines = image->GetDirection();
 
68
 
 
69
  std::cout << directionCosines << std::endl;
 
70
 
 
71
  unsigned int element = 2;
 
72
  const double tolerance = 1e-3;
 
73
 
 
74
  ImageType::RegionType region = image->GetLargestPossibleRegion();
 
75
  ImageType::SizeType   size   = region.GetSize();
 
76
 
 
77
  const int numberOfPointsToTest = 3;
 
78
 
 
79
  IndexType index[numberOfPointsToTest];
 
80
  PointType physicalPoint;
 
81
 
 
82
  index[0][0] = 0;
 
83
  index[0][1] = 0;
 
84
 
 
85
  index[1][0] = size[0];
 
86
  index[1][1] = 0;
 
87
 
 
88
  index[2][0] = 0;
 
89
  index[2][1] = size[1];
 
90
 
 
91
  image->Print( std::cout );
 
92
  std::cout << std::endl;
 
93
  std::cout << std::endl;
 
94
 
 
95
  for( int pointId=0; pointId < numberOfPointsToTest; ++pointId )
 
96
    {
 
97
 
 
98
    image->TransformIndexToPhysicalPoint( index[pointId], physicalPoint );
 
99
 
 
100
    std::cout << index[pointId] << " : " << physicalPoint << std::endl;
 
101
 
 
102
    for( unsigned int dim=0; dim < Dimension; ++dim )
 
103
      {
 
104
      const double expectedValue = atof( av[ element++ ] );
 
105
      const double currentValue = physicalPoint[dim];
 
106
      const double difference = currentValue - expectedValue;
 
107
      if( vnl_math_abs( difference ) > tolerance )
 
108
        {
 
109
        std::cerr << "Error: " << std::endl;
 
110
        std::cerr << "in Point # " << pointId << std::endl;
 
111
        std::cerr << "Expected      = " << expectedValue << std::endl;
 
112
        std::cerr << "Read          = " << currentValue << std::endl;
 
113
        std::cerr << "Index         = " << index[pointId] << std::endl;
 
114
        std::cerr << "PhysicalPoint = " << physicalPoint << std::endl;
 
115
        return EXIT_FAILURE;
 
116
        }
 
117
      }
 
118
    }
 
119
 
 
120
  //
 
121
  // Select a point in the middle of the image and compute its
 
122
  // derivative using the image orientation.
 
123
  //
 
124
  IndexType centralIndex;
 
125
  centralIndex[0] = static_cast< IndexValueType >( size[0] / 2.0 );
 
126
  centralIndex[1] = static_cast< IndexValueType >( size[1] / 2.0 );
 
127
 
 
128
  typedef itk::CentralDifferenceImageFunction< ImageType, double >   CentralDifferenceImageFunctionType;
 
129
 
 
130
  CentralDifferenceImageFunctionType::Pointer gradientHelper1 = CentralDifferenceImageFunctionType::New();
 
131
  gradientHelper1->SetInputImage( image );
 
132
 
 
133
  std::cout << std::endl;
 
134
  std::cout << std::endl;
 
135
  std::cout << "Image Direction" << std::endl;
 
136
  std::cout << image->GetDirection() << std::endl;
 
137
 
 
138
  { // Compute gradient value without taking image direction into account
 
139
  gradientHelper1->UseImageDirectionOff();
 
140
  CentralDifferenceImageFunctionType::OutputType gradient1a = gradientHelper1->EvaluateAtIndex( centralIndex ); 
 
141
 
 
142
  std::cout << "Gradient without Direction" << std::endl;
 
143
  std::cout << gradient1a << std::endl;
 
144
 
 
145
  for( unsigned int dim=0; dim < Dimension; ++dim )
 
146
    {
 
147
    const double expectedValue = atof( av[ element++ ] );
 
148
    const double currentValue = gradient1a[dim];
 
149
    const double difference = currentValue - expectedValue;
 
150
    if( vnl_math_abs( difference ) > tolerance )
 
151
      {
 
152
      std::cerr << "Error: " << std::endl;
 
153
 
 
154
      std::cerr << "Expected      = " << expectedValue << std::endl;
 
155
      std::cerr << "Read          = " << currentValue << std::endl;
 
156
      return EXIT_FAILURE;
 
157
      }
 
158
    }
 
159
  }
 
160
 
 
161
 
 
162
  { // Compute gradient value taking image direction into account
 
163
  gradientHelper1->UseImageDirectionOn();
 
164
  CentralDifferenceImageFunctionType::OutputType gradient1b = gradientHelper1->EvaluateAtIndex( centralIndex ); 
 
165
 
 
166
  std::cout << std::endl;
 
167
  std::cout << "Gradient with Direction" << std::endl;
 
168
  std::cout << gradient1b << std::endl;
 
169
 
 
170
  for( unsigned int dim=0; dim < Dimension; ++dim )
 
171
    {
 
172
    const double expectedValue = atof( av[ element++ ] );
 
173
    const double currentValue = gradient1b[dim];
 
174
    const double difference = currentValue - expectedValue;
 
175
    if( vnl_math_abs( difference ) > tolerance )
 
176
      {
 
177
      std::cerr << "Error: " << std::endl;
 
178
      std::cerr << "Expected      = " << expectedValue << std::endl;
 
179
      std::cerr << "Read          = " << currentValue << std::endl;
 
180
      return EXIT_FAILURE;
 
181
      }
 
182
    }
 
183
  }
 
184
 
 
185
  return EXIT_SUCCESS;
 
186
}