ANIMA  4.0
animaSimuBlochGRE.cxx
Go to the documentation of this file.
1 #include <tclap/CmdLine.h>
2 
3 #include <itkImage.h>
4 #include <itkImageFileReader.h>
5 #include <itkImageFileWriter.h>
6 
7 #include "animaSimuBlochGRE.h"
8 
9 int main(int argc, char *argv[] )
10 {
11  TCLAP::CmdLine cmd("SimuBlochGRE: Simulator for Gradient Echo\nINRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
12 
13  TCLAP::ValueArg<std::string> t1MapArg("","t1","Input T1 map",true,"","T1 map",cmd);
14  TCLAP::ValueArg<std::string> t2sMapArg("","t2s","Input T2* map",true,"","T2* map",cmd); //changed for GRE
15  TCLAP::ValueArg<std::string> m0ImageArg("","m0","Input M0 image",true,"","M0 image",cmd);
16  TCLAP::ValueArg<std::string> resArg("o","output","Output simulated image for Gradient Echo",true,"","output simulated image",cmd);
17 
18  TCLAP::ValueArg<double> trArg("r","tr","TR value (ms), default: 120ms",false, 120,"TR value",cmd); //changed for GRE
19  TCLAP::ValueArg<double> teArg("e","te","TE value (ms), default: 8ms",false, 8,"TE value",cmd);//changed for GRE
20 
21  try
22  {
23  cmd.parse(argc,argv);
24  }
25  catch (TCLAP::ArgException& e)
26  {
27  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
28  return(1);
29  }
30 
31  // Parse arguments
32  std::string input1FileName = t1MapArg.getValue();
33  std::string input2FileName = t2sMapArg.getValue();//changed for GRE
34  std::string input3FileName = m0ImageArg.getValue();
35  std::string outputFileName = resArg.getValue();
36  double TR = trArg.getValue();
37  double TE = teArg.getValue();
38 
39  // Verify range of TR and TE
40  if ((TR < 0) || (TE < 0))
41  {
42  std::cerr << "Error: " << std::endl;
43  std::cerr << "TR(ms) < 0 or TE(ms) < 0." << std::endl;
44  std::cerr << "Please set TR(ms) >= 0 and TE(ms) >= 0." << std::endl;
45  return EXIT_FAILURE;
46  }
47 
48  // Verify TE < TR
49  if (TE >= TR)
50  {
51  std::cerr << "Error: " << std::endl;
52  std::cerr << "TE(ms) >= TR(ms)" << std::endl;
53  std::cerr << "Please set TE(ms) < TR(ms)." << std::endl;
54  return EXIT_FAILURE;
55 
56  }
57 
58  // Setup types
59  typedef itk::Image<double, 3> ImageType;
60  typedef anima::SimuBlochGRE<ImageType> FilterType;
61 
62  // Read T1 map
63  typedef itk::ImageFileReader<ImageType> ReaderType;
64  ReaderType::Pointer reader1 = ReaderType::New();
65  reader1->SetFileName(input1FileName);
66  reader1->Update();
67 
68  // Read T2s map
69  typedef itk::ImageFileReader<ImageType> ReaderType;
70  ReaderType::Pointer reader2 = ReaderType::New();
71  reader2->SetFileName(input2FileName);
72  reader2->Update();
73 
74  // Read M0 map
75  typedef itk::ImageFileReader<ImageType> ReaderType;
76  ReaderType::Pointer reader3 = ReaderType::New();
77  reader3->SetFileName(input3FileName);
78  reader3->Update();
79 
80  // Get the size of input image
81  ReaderType::SizeType size1 = reader1->GetOutput()->GetLargestPossibleRegion().GetSize();
82  ReaderType::SizeType size2 = reader2->GetOutput()->GetLargestPossibleRegion().GetSize();
83  ReaderType::SizeType size3 = reader3->GetOutput()->GetLargestPossibleRegion().GetSize();
84 
85  // Verify the dimension of the input image
86  if ( ((sizeof(size1)/sizeof(size1[0])) != (sizeof(size2)/sizeof(size2[0])))
87  || ((sizeof(size1)/sizeof(size1[0])) != (sizeof(size3)/sizeof(size3[0]))) )
88  {
89  std::cerr << "Error: " << std::endl;
90  std::cerr << "The dimensions of the input images are not the same." << std::endl;
91  std::cerr << "Please input the images with the same dimension." << std::endl;
92  return EXIT_FAILURE;
93  }
94 
95  // Verify the size of the input image
96  if (((size1[0] != size2[0]) || (size1[0] != size3[0]))
97  || ((size1[1] != size2[1]) || (size1[1] != size3[1]))
98  || ((size1[2] != size2[2]) || (size1[2] != size3[2])) )
99  {
100  std::cerr << "Error: " << std::endl;
101  std::cerr << "The sizes of the input images are not the same." << std::endl;
102  std::cerr << "Please input the images with the same size." << std::endl;
103  return EXIT_FAILURE;
104  }
105 
106  // Create the filter: estimate the sequence of Gradient Echo
107  FilterType::Pointer filter = FilterType::New();
108  filter->SetInput(0,reader1->GetOutput());
109  filter->SetInput(1,reader2->GetOutput());
110  filter->SetInput(2,reader3->GetOutput());
111  filter->SetTR(TR);
112  filter->SetTE(TE);
113  filter->Update();
114 
115  // Save the output image
116  typedef itk::ImageFileWriter< ImageType > WriterType;
117  WriterType::Pointer writer = WriterType::New();
118  writer->SetFileName(outputFileName);
119  writer->SetInput(filter->GetOutput());
120  writer->Update();
121 
122  // return
123  return EXIT_SUCCESS;
124 }
125 
int main(int argc, char *argv[])