ANIMA  4.0
animaStimulatedSpinEchoSimulator.cxx
Go to the documentation of this file.
1 #include <cmath>
2 
3 #include <tclap/CmdLine.h>
4 
5 #include <itkVectorImage.h>
6 #include <itkImageFileReader.h>
7 #include <itkImageFileWriter.h>
8 
10 
11 int main(int argc, char *argv[] )
12 {
13  TCLAP::CmdLine cmd("Simulator for stimulated spin echo T2 sequences\nINRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
14 
15  TCLAP::ValueArg<std::string> t1MapArg("","t1","Input T1 map",true,"","T1 map",cmd);
16  TCLAP::ValueArg<std::string> t2MapArg("","t2","Input T2 map",true,"","T2 map",cmd);
17  TCLAP::ValueArg<std::string> m0ImageArg("","m0","Input M0 image",true,"","M0 image",cmd);
18  TCLAP::ValueArg<std::string> b1ImageArg("","b1","Input B1 image",false,"","B1 image",cmd);
19  TCLAP::ValueArg<std::string> resArg("o","output","Output simulated image",true,"","output simulated image",cmd);
20 
21  TCLAP::ValueArg<unsigned int> neArg("n","ne","Number of echoes, default: 7",false, 7,"number of echoes",cmd);
22  TCLAP::ValueArg<double> teArg("e","te","TE echo spacing (ms), default: 10ms",false, 10,"TE value",cmd);
23  TCLAP::ValueArg<double> xfaArg("x","excite-fa","Excitation flip angle (degrees), default: 90 degrees", false, 90,"excitation flip angle value",cmd);
24  TCLAP::ValueArg<double> faArg("f","fa","Flip angle (degrees), default: 180 degrees", false, 180,"flip angle value",cmd);
25 
26  TCLAP::ValueArg<unsigned int> nbpArg("T","numberofthreads","Number of threads to run on (default : all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
27 
28  try
29  {
30  cmd.parse(argc,argv);
31  }
32  catch (TCLAP::ArgException& e)
33  {
34  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
35  return EXIT_FAILURE;
36  }
37 
38  // Parse arguments
39  std::string input1FileName = t1MapArg.getValue();
40  std::string input2FileName = t2MapArg.getValue();
41  std::string input3FileName = m0ImageArg.getValue();
42  std::string outputFileName = resArg.getValue();
43 
44  // Setup types
45  typedef itk::Image<double, 3> ImageType;
46  typedef itk::VectorImage<double, 3> OutputImageType;
48 
49  // Read T1 map
50  typedef itk::ImageFileReader<ImageType> ReaderType;
51  ReaderType::Pointer reader1 = ReaderType::New();
52  reader1->SetFileName(input1FileName);
53  reader1->Update();
54 
55  // Read T2s map
56  ReaderType::Pointer reader2 = ReaderType::New();
57  reader2->SetFileName(input2FileName);
58  reader2->Update();
59 
60  // Read M0 map
61  ReaderType::Pointer reader3 = ReaderType::New();
62  reader3->SetFileName(input3FileName);
63  reader3->Update();
64 
65  FilterType::Pointer filter = FilterType::New();
66  filter->SetInput(0,reader1->GetOutput());
67  filter->SetInput(1,reader2->GetOutput());
68  filter->SetInput(2,reader3->GetOutput());
69  filter->SetNumberOfWorkUnits(nbpArg.getValue());
70 
71  // Read B1 map
72  if (b1ImageArg.getValue() != "")
73  {
74  ReaderType::Pointer readerB1 = ReaderType::New();
75  readerB1->SetFileName(b1ImageArg.getValue().c_str());
76  readerB1->Update();
77 
78  filter->SetInput(3,readerB1->GetOutput());
79  }
80 
81  filter->SetEchoSpacing(teArg.getValue());
82  filter->SetFlipAngle(faArg.getValue() * M_PI / 180.0);
83  filter->SetNumberOfEchoes(neArg.getValue());
84  filter->SetExcitationFlipAngle(xfaArg.getValue() * M_PI / 180.0);
85 
86  filter->Update();
87 
88  // Save the output image
89  typedef itk::ImageFileWriter <FilterType::Image4DType> WriterType;
90  WriterType::Pointer writer = WriterType::New();
91  writer->SetFileName(outputFileName);
92  writer->SetInput(filter->GetOutputAs4DImage());
93  writer->Update();
94 
95  // return
96  return EXIT_SUCCESS;
97 }
98 
int main(int argc, char *argv[])