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