ANIMA  4.0
animaDWISimulatorFromDTI.cxx
Go to the documentation of this file.
2 
3 #include <itkTimeProbe.h>
4 
7 
8 #include <tclap/CmdLine.h>
9 
10 int main(int argc, char **argv)
11 {
12  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
13 
14  TCLAP::ValueArg<std::string> inArg("i","inputdti","DTI volume",true,"","DTI volume",cmd);
15  TCLAP::ValueArg<std::string> resArg("o","output","Result DWI image",true,"","result DWI image",cmd);
16  TCLAP::ValueArg<std::string> s0ValueArg("s","s0","S0 of DWI (constant value or image)",false,"200","S0 of DWI",cmd);
17 
18  TCLAP::ValueArg<std::string> gradsArg("g","grad","Input gradients",true,"","Input gradients",cmd);
19  TCLAP::ValueArg<std::string> bvalArg("b","bval","Input b-values",true,"","Input b-values",cmd);
20 
21  TCLAP::ValueArg<unsigned int> nbpArg("p","numberofthreads","Number of threads to run on (default: all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
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;
31  }
32 
34  typedef FilterType::InputImageType InputImageType;
35  typedef FilterType::Image4DType Image4DType;
36 
37  FilterType::Pointer mainFilter = FilterType::New();
38 
39  typedef anima::GradientFileReader < std::vector <double>, double > GFReaderType;
40  GFReaderType gfReader;
41  gfReader.SetGradientFileName(gradsArg.getValue());
42  gfReader.SetBValueBaseString(bvalArg.getValue());
43  gfReader.SetGradientIndependentNormalization(false);
44  gfReader.Update();
45 
46  std::vector< std::vector<double> > directions = gfReader.GetGradients();
47 
48  for(unsigned int i = 0;i < directions.size();++i)
49  mainFilter->AddGradientDirection(i,directions[i]);
50 
51  std::vector <double> mb = gfReader.GetBValues();
52  mainFilter->SetBValuesList(mb);
53 
54  typedef itk::ImageFileReader <FilterType::S0ImageType> S0ImageReaderType;
55  FilterType::S0ImageType::Pointer s0Image;
56  try
57  {
58  s0Image = anima::readImage <FilterType::S0ImageType> (s0ValueArg.getValue());
59  mainFilter->SetS0Image(s0Image);
60  }
61  catch(itk::ExceptionObject &e)
62  {
63  mainFilter->SetS0Value(std::stod(s0ValueArg.getValue()));
64  }
65 
66  mainFilter->SetInput(anima::readImage <InputImageType> (inArg.getValue()));
67  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
68 
69  itk::TimeProbe tmpTimer;
70  tmpTimer.Start();
71 
72  try
73  {
74  mainFilter->Update();
75  }
76  catch (itk::ExceptionObject &e)
77  {
78  std::cerr << e << std::endl;
79  return EXIT_FAILURE;
80  }
81 
82  tmpTimer.Stop();
83 
84  std::cout << "Simulation done in " << tmpTimer.GetTotal() << " s" << std::endl;
85  std::cout << "Writing result to : " << resArg.getValue() << std::endl;
86 
87  anima::writeImage <Image4DType> (resArg.getValue(), mainFilter->GetOutputAs4DImage());
88 
89  return EXIT_SUCCESS;
90 }
void SetGradientFileName(std::string fName)
int main(int argc, char **argv)