ANIMA  4.0
animaSimuBlochSP-GRE.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 "animaSimuBlochSP-GRE.h"
8 
9 int main(int argc, char *argv[] )
10 {
11  TCLAP::CmdLine cmd("SimuBlochSP-GRE: Simulator for Spoiled Gradient Echo ( SPGR, FLASH, or T1-FFE )\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 SP-GRE
15  TCLAP::ValueArg<std::string> m0ImageArg("","m0","Input M0 image",true,"","M0 image",cmd);
16  TCLAP::ValueArg<std::string> b1ImageArg("","b1","Input B1 image",false,"","B1 image",cmd);
17  TCLAP::ValueArg<std::string> resArg("o","output","Output simulated image for Spoiled Gradient Echo",true,"","output simulated image",cmd);
18 
19  TCLAP::ValueArg<double> trArg("r","tr","TR value (ms), default: 35ms",false, 35,"TR value",cmd);//changed for SP-GRE
20  TCLAP::ValueArg<double> teArg("e","te","TE value (ms), default: 6ms",false, 6,"TE value",cmd);//changed for SP-GRE
21  TCLAP::ValueArg<double> faArg("f","fa","Flip Angle (degree), default: 40degree", false, 40,"FA value",cmd);//changed for SP-GRE
22 
23  try
24  {
25  cmd.parse(argc,argv);
26  }
27  catch (TCLAP::ArgException& e)
28  {
29  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
30  return EXIT_FAILURE;//changed for SP-GRE
31  }
32 
33  // Parse arguments
34  std::string input1FileName = t1MapArg.getValue();
35  std::string input2FileName = t2sMapArg.getValue();//changed for SP-GRE
36  std::string input3FileName = m0ImageArg.getValue();
37  std::string outputFileName = resArg.getValue();
38  double TR = trArg.getValue();
39  double TE = teArg.getValue();
40  double FA = faArg.getValue();//changed for SP-GRE
41 
42  // Verify range of TR, TE
43  if ((TR < 0) || (TE < 0))
44  {
45  std::cerr << "Error: " << std::endl;
46  std::cerr << "TR(ms) < 0 or TE(ms)" << std::endl;
47  std::cerr << "Please set TR(ms) >= 0 and TE(ms) >= 0." << std::endl;
48  return EXIT_FAILURE;
49  }
50 
51  // Verify TE < TR
52  if (TE >= TR)
53  {
54  std::cerr << "Error: " << std::endl;
55  std::cerr << "TE(ms) >= TR(ms)" << std::endl;
56  std::cerr << "Please set TE and TR values which satisfy TE(ms) < TR(ms)." << std::endl;
57  return EXIT_FAILURE;
58 
59  }
60 
61  // Verify range of FA
62  if ((FA > 180) || (FA < 0))
63  {
64  std::cerr << "Error: " << std::endl;
65  std::cerr << "FA(degree) < 0 or FA(degree) > 180" << std::endl;
66  std::cerr << "Please set FA(degree) in the range of [0, 180]." << std::endl;
67  return EXIT_FAILURE;
68  }
69 
70  // Setup types
71  typedef itk::Image<double, 3> ImageType;
72  typedef anima::SimuBlochSPGRE<ImageType> FilterType;
73 
74  // Read T1 map
75  typedef itk::ImageFileReader<ImageType> ReaderType;
76  ReaderType::Pointer reader1 = ReaderType::New();
77  reader1->SetFileName(input1FileName);
78  reader1->Update();
79 
80  // Read T2s map
81  ReaderType::Pointer reader2 = ReaderType::New();
82  reader2->SetFileName(input2FileName);
83  reader2->Update();
84 
85  // Read M0 map
86  ReaderType::Pointer reader3 = ReaderType::New();
87  reader3->SetFileName(input3FileName);
88  reader3->Update();
89 
90  // Get the size of input image
91  ReaderType::SizeType size1 = reader1->GetOutput()->GetLargestPossibleRegion().GetSize();
92  ReaderType::SizeType size2 = reader2->GetOutput()->GetLargestPossibleRegion().GetSize();
93  ReaderType::SizeType size3 = reader3->GetOutput()->GetLargestPossibleRegion().GetSize();
94 
95  // Verify the dimension of the input image
96  if ( ((sizeof(size1)/sizeof(size1[0])) != (sizeof(size2)/sizeof(size2[0])))
97  || ((sizeof(size1)/sizeof(size1[0])) != (sizeof(size3)/sizeof(size3[0]))) )
98  {
99  std::cerr << "Error: " << std::endl;
100  std::cerr << "The dimensions of the input images are not the same." << std::endl;
101  std::cerr << "Please input the images with the same dimension." << std::endl;
102  return EXIT_FAILURE;
103  }
104 
105  // Verify the size of the input image
106  if (((size1[0] != size2[0]) || (size1[0] != size3[0]))
107  || ((size1[1] != size2[1]) || (size1[1] != size3[1]))
108  || ((size1[2] != size2[2]) || (size1[2] != size3[2])) )
109  {
110  std::cerr << "Error: " << std::endl;
111  std::cerr << "The sizes of the input images are not the same." << std::endl;
112  std::cerr << "Please input the images with the same size." << std::endl;
113  return EXIT_FAILURE;
114  }
115 
116  // Create the filter: estimate the sequence of SP-GRE
117  FilterType::Pointer filter = FilterType::New();
118  filter->SetInput(0,reader1->GetOutput());
119  filter->SetInput(1,reader2->GetOutput());
120  filter->SetInput(2,reader3->GetOutput());
121 
122  // Read B1 map
123  if (b1ImageArg.getValue() != "")
124  {
125  ReaderType::Pointer readerB1 = ReaderType::New();
126  readerB1->SetFileName(b1ImageArg.getValue().c_str());
127  readerB1->Update();
128 
129  filter->SetInput(3,readerB1->GetOutput());
130  }
131 
132  filter->SetTR(TR);
133  filter->SetTE(TE);
134  filter->SetFA(FA);//changed for SP-GRE
135  filter->Update();
136 
137  // Save the output image
138  typedef itk::ImageFileWriter< ImageType > WriterType;
139  WriterType::Pointer writer = WriterType::New();
140  writer->SetFileName(outputFileName);
141  writer->SetInput(filter->GetOutput());
142  writer->Update();
143 
144  // return
145  return EXIT_SUCCESS;
146 }
147 
int main(int argc, char *argv[])