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

« back to all changes in this revision

Viewing changes to Testing/Code/Review/itkMapMaskedRankImageFilterTest.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2008-12-19 20:16:49 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081219201649-drt97guwl2ryt0cn

* New upstream version.
  - patches/nifti-versioning.patch: Remove.  Applied upstream.
  - control:
  - rules: Update version numbers, package names.

* control: Build-depend on uuid-dev (gdcm uses it).

* copyright: Update download URL.

* rules: Adhere to parallel=N in DEB_BUILD_OPTIONS by setting MAKEFLAGS.

* compat: Set to 7.
* control: Update build-dep on debhelper to version >= 7.

* CMakeCache.txt.debian: Set CMAKE_BUILD_TYPE to "RELEASE" so that we
  build with -O3 (not -O2), necessary to optimize the templated code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Insight Segmentation & Registration Toolkit
 
4
  Module:    $RCSfile: itkMapMaskedRankImageFilterTest.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2008-08-08 11:41:11 $
 
7
  Version:   $Revision: 1.2 $
 
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 "itkMaskedRankImageFilter.h"
 
23
#include "itkImageFileReader.h"
 
24
#include "itkImageFileWriter.h"
 
25
#include "itkTextOutput.h"
 
26
#include "itkNumericTraits.h"
 
27
#include "itkFilterWatcher.h"
 
28
 
 
29
int itkMapMaskedRankImageFilterTest(int ac, char* av[] )
 
30
{
 
31
  // Comment the following if you want to use the itk text output window
 
32
  itk::OutputWindow::SetInstance(itk::TextOutput::New());
 
33
 
 
34
  if(ac < 5)
 
35
    {
 
36
    std::cerr << "Usage: " << av[0] << " InputImage maskImage BaselineImage radius" << std::endl;
 
37
    return -1;
 
38
    }
 
39
 
 
40
  typedef itk::Image<unsigned short, 2> ImageType;
 
41
  
 
42
  typedef itk::ImageFileReader<ImageType> ReaderType;
 
43
  ReaderType::Pointer input  = ReaderType::New();
 
44
  input->SetFileName(av[1]);
 
45
  
 
46
  ReaderType::Pointer input2  = ReaderType::New();
 
47
  input2->SetFileName(av[2]);
 
48
  
 
49
  // Create a filter
 
50
  typedef itk::FlatStructuringElement<2> SEType;
 
51
  typedef itk::MaskedRankImageFilter<ImageType,ImageType,ImageType,SEType> FilterType;
 
52
  FilterType::Pointer filter = FilterType::New();
 
53
  FilterWatcher filterWatch(filter);
 
54
 
 
55
  typedef FilterType::RadiusType RadiusType;
 
56
 
 
57
  // test default values
 
58
  RadiusType r1;
 
59
  r1.Fill( 1 );
 
60
  if ( filter->GetRadius() != r1 )
 
61
    {
 
62
    std::cerr << "Wrong default Radius." << std::endl;
 
63
    return EXIT_FAILURE;
 
64
    }
 
65
  if ( filter->GetRank() != 0.5 )
 
66
    {
 
67
    std::cerr << "Wrong default Rank." << std::endl;
 
68
    return EXIT_FAILURE;
 
69
    }
 
70
  if ( filter->GetMaskValue() != 65535 )
 
71
    {
 
72
    std::cerr << "Wrong default mask value." << std::endl;
 
73
    return EXIT_FAILURE;
 
74
    }
 
75
  if ( filter->GetFillValue() != 0 )
 
76
    {
 
77
    std::cerr << "Wrong default fill value." << std::endl;
 
78
    return EXIT_FAILURE;
 
79
    }
 
80
  if ( filter->GetBackgroundMaskValue() != 0 )
 
81
    {
 
82
    std::cerr << "Wrong default background mask value." << std::endl;
 
83
    return EXIT_FAILURE;
 
84
    }
 
85
    
 
86
  // set radius with a radius type
 
87
  RadiusType r5;
 
88
  r5.Fill( 5 );
 
89
  filter->SetRadius( r5 );
 
90
  if ( filter->GetRadius() != r5 )
 
91
    {
 
92
    std::cerr << "Radius value is not the expected one:�r5." << std::endl;
 
93
    return EXIT_FAILURE;
 
94
    }
 
95
 
 
96
  // set radius with an integer
 
97
  filter->SetRadius( 1 );
 
98
  if ( filter->GetRadius() != r1 )
 
99
    {
 
100
    std::cerr << "Radius value is not the expected one:�r1." << std::endl;
 
101
    return EXIT_FAILURE;
 
102
    }
 
103
 
 
104
  filter->SetRank( 0.25 );
 
105
  if ( filter->GetRank() != 0.25 )
 
106
    {
 
107
    std::cerr << "Rank value is not the expected one: " << filter->GetRank() << std::endl;
 
108
    return EXIT_FAILURE;
 
109
    }
 
110
 
 
111
  filter->SetMaskValue( 1 );
 
112
  if ( filter->GetMaskValue() != 1 )
 
113
    {
 
114
    std::cerr << "Mask value value is not the expected one: " << filter->GetMaskValue() << std::endl;
 
115
    return EXIT_FAILURE;
 
116
    }
 
117
 
 
118
  filter->SetFillValue( 1 );
 
119
  if ( filter->GetFillValue() != 1 )
 
120
    {
 
121
    std::cerr << "Fill value value is not the expected one: " << filter->GetFillValue() << std::endl;
 
122
    return EXIT_FAILURE;
 
123
    }
 
124
 
 
125
  filter->SetBackgroundMaskValue( 1 );
 
126
  if ( filter->GetBackgroundMaskValue() != 1 )
 
127
    {
 
128
    std::cerr << "Background mask value value is not the expected one: " << filter->GetBackgroundMaskValue() << std::endl;
 
129
    return EXIT_FAILURE;
 
130
    }
 
131
 
 
132
  try
 
133
    {
 
134
    int r = atoi( av[4] );
 
135
    filter->SetInput(input->GetOutput());
 
136
    filter->SetMaskImage(input2->GetOutput());
 
137
    filter->SetRadius( r );
 
138
    filter->SetRank( 0.5 );
 
139
    filter->SetMaskValue( 255 );
 
140
    filter->SetFillValue( 1 );
 
141
    filter->SetBackgroundMaskValue( 0 );
 
142
    filter->Update();
 
143
    }
 
144
  catch (itk::ExceptionObject& e)
 
145
    {
 
146
    std::cerr << "Exception detected: "  << e.GetDescription();
 
147
    return EXIT_FAILURE;
 
148
    }
 
149
 
 
150
  // Generate test image
 
151
  typedef itk::ImageFileWriter<ImageType> WriterType;
 
152
  WriterType::Pointer writer = WriterType::New();
 
153
  writer->SetInput( filter->GetOutput() );
 
154
  writer->SetFileName( av[3] );
 
155
  writer->Update();
 
156
 
 
157
  return EXIT_SUCCESS;
 
158
}