File: itkDirectFourierReconstructionImageToImageFilterTest.cxx

package info (click to toggle)
insighttoolkit 3.18.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 110,432 kB
  • ctags: 74,559
  • sloc: cpp: 412,627; ansic: 196,210; fortran: 28,000; python: 3,852; tcl: 2,005; sh: 1,186; java: 583; makefile: 458; csh: 220; perl: 193; xml: 20
file content (180 lines) | stat: -rw-r--r-- 5,535 bytes parent folder | download
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkDirectFourierReconstructionImageToImageFilterTest.cxx,v $
  Language:  C++
  Date:      $Date: 2009-05-01 17:35:49 $
  Version:   $Revision: 1.2 $

  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 "itkImage.h"
#include "itkImageFileReader.h"
#include "itkRecursiveGaussianImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkRegionOfInterestImageFilter.h"
#include "itkImageFileWriter.h"
#include "itkCommand.h"

#include "itkDirectFourierReconstructionImageToImageFilter.h"

typedef double    InternalPixelType;
typedef short int OutputPixelType;

typedef itk::Image< OutputPixelType, 3 > OutputImageType;
typedef itk::DirectFourierReconstructionImageToImageFilter< InternalPixelType, InternalPixelType > ReconstructionFilterType;
typedef ReconstructionFilterType::OutputImageType InternalImageType;

typedef itk::RecursiveGaussianImageFilter< InternalImageType, InternalImageType > SmootherType;
typedef itk::RescaleIntensityImageFilter< InternalImageType, OutputImageType >    RescalerType;
typedef itk::RegionOfInterestImageFilter< OutputImageType, OutputImageType >      ROIFilterType;
typedef itk::ImageFileReader< InternalImageType >                                 ReaderType;
typedef itk::ImageFileWriter< OutputImageType >                                   WriterType;


class CommandProgressUpdate : public itk::Command
{
public:
  typedef CommandProgressUpdate Self;
  typedef itk::Command          Superclass;
  
  typedef itk::SmartPointer< Self > Pointer;
  
  itkNewMacro( Self );
  
protected:
  CommandProgressUpdate() {}; // purposely not implemented
 
  typedef const ReconstructionFilterType * ReconstructionFilterPointer;
 
  void Execute(itk::Object * caller, const itk::EventObject & event )
    {
    Execute( ( const itk::Object * )caller, event);
    }
  
  void Execute( const itk::Object * caller, const itk::EventObject & event )
    {
    ReconstructionFilterPointer reconstructor = dynamic_cast< ReconstructionFilterPointer >( caller );
   
    if ( ! itk::ProgressEvent().CheckEvent( &event ) )
      {
      return;
      }
   
    std::cout << (int)( 100 * reconstructor->GetProgress() ) << "%" << std::endl;
    }
};


int itkDirectFourierReconstructionImageToImageFilterTest (int argc, char * argv[] )
{

  if ( argc != 18)
    {
    std::cerr << "Wrong number of input arguments" << std::endl;
    std::cerr << "Usage : " << std::endl << "\t";
    std::cerr << argv[0] << " input output r_dir z_dir alpha_dir nz ng fc nb alpha_range x y z sx sy sz sigma" << std::endl;
    return 1;
    }

  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );
 
 
  SmootherType::Pointer smoother = SmootherType::New();
  smoother->SetInput( reader->GetOutput() );
  smoother->SetSigma( atof( argv[17] ) );
  smoother->SetDirection( atoi( argv[3] ) );
 
 
  ReconstructionFilterType::Pointer reconstruct = ReconstructionFilterType::New();
  if ( atof( argv[17] ) == 0 ) 
    {
    reconstruct->SetInput( reader->GetOutput() );
    }
  else 
    {
    reconstruct->SetInput( smoother->GetOutput() );
    }
  reconstruct->SetRDirection( atoi( argv[3] ) );
  reconstruct->SetZDirection( atoi( argv[4] ) );
  reconstruct->SetAlphaDirection( atoi( argv[5] ) );
  reconstruct->SetZeroPadding( atoi( argv[6] ) );
  reconstruct->SetOverSampling( atoi( argv[7] ) );
  reconstruct->SetCutoff( atof( argv[8] ) );
  reconstruct->SetRadialSplineOrder( atoi( argv[9] ) );
  reconstruct->SetAlphaRange( atoi( argv[10] ) );

  CommandProgressUpdate::Pointer observer = CommandProgressUpdate::New();
  reconstruct->AddObserver( itk::ProgressEvent(), observer ); 
 
 
 
  RescalerType::Pointer rescaler = RescalerType::New();
  rescaler->SetInput( reconstruct->GetOutput() );
  rescaler->SetOutputMinimum( itk::NumericTraits< OutputPixelType >::min() );
  rescaler->SetOutputMaximum( itk::NumericTraits< OutputPixelType >::max() );
 
 
 
  ROIFilterType::Pointer ROIFilter = ROIFilterType::New();
  ROIFilter->SetInput( rescaler->GetOutput() );
 
  ROIFilterType::IndexType start;
  ROIFilterType::SizeType size;
 
  start[0] = atoi( argv[11] );
  start[1] = atoi( argv[12] );
  start[2] = atoi( argv[13] );
 
  size[0] = atoi( argv[14] );
  size[1] = atoi( argv[15] );
  size[2] = atoi( argv[16] );

  ROIFilterType::RegionType requestedRegion;  
  requestedRegion.SetIndex( start );
  requestedRegion.SetSize( size );
 
  ROIFilter->SetRegionOfInterest( requestedRegion );
 
 
 
 
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName( argv[2] );
  writer->UseCompressionOn(  );
  writer->SetInput( ROIFilter->GetOutput() );

 
 
 
 
 
  try 
    {
    writer->Update(); 
    } 
  catch ( itk::ExceptionObject err )
    {
    std::cerr << "An error occurred somewhere:" << std::endl;
    std::cerr << err << std::endl;
    return 2;
    }

  std::cout << "Done" << std::endl;
 
  std::cout << reconstruct << std::endl;

  return 0;

} // main