ANIMA  4.0
animaPatientToGroupODFComparison.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <tclap/CmdLine.h>
3 
6 
7 #include <animaODFFunctions.h>
8 
9 //Update progression of the process
10 void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
11 {
12  itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
13  std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
14 }
15 
16 int main(int argc, char **argv)
17 {
18  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
19 
20  TCLAP::ValueArg<std::string> refODFArg("i","inputodf","ODF Test Image",true,"","ODF test image",cmd);
21 
22  TCLAP::ValueArg<std::string> dataODFArg("I","databaseodf","ODF Database Image List",true,"","ODF database image list",cmd);
23 
24  TCLAP::ValueArg<std::string> maskArg("m","maskname","Computation mask",true,"","computation mask",cmd);
25  TCLAP::ValueArg<std::string> resArg("o","outputname","Z-Score output image",true,"","Z-Score output image",cmd);
26  TCLAP::ValueArg<std::string> resPValArg("O","outpvalname","P-value output image",true,"","P-Value output image",cmd);
27 
28  TCLAP::ValueArg<std::string> statTestArg("t","stat-test","Statistical test to use ([fisher],chi)",false,"fisher","statistical test",cmd);
29  TCLAP::ValueArg<double> expVarArg("e","expvar","PCA threshold: threshold on eigenvalues to compute the new basis (default: 0.5)",false,0.5,"PCA threshold",cmd);
30  TCLAP::ValueArg<unsigned int> numEigenArg("E","numeigenpca","Number of eigenvalues to keep (default: 6)",false,6,"Number of PCA eigen values",cmd);
31 
32  TCLAP::ValueArg<unsigned int> nbpArg("p","numberofthreads","Number of threads to run on (default: all cores)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
33 
34  TCLAP::ValueArg<unsigned int> nbThetaArg("T","theta","Number of theta values (theta varies between 0 and pi/2",false,0,"number of theta values",cmd);
35  TCLAP::ValueArg<unsigned int> nbPhiArg("P","phi","Number of phi values (theta varies between 0 and 2 pi",false,0,"number of phi values",cmd);
36 
37  TCLAP::ValueArg<std::string> samplesFileNameArg("d","sampledirectionsfile","Samples directions in a text file",false,"","Samples directions file",cmd);
38 
39  try
40  {
41  cmd.parse(argc,argv);
42  }
43  catch (TCLAP::ArgException& e)
44  {
45  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
46  return EXIT_FAILURE;
47  }
48 
49  typedef itk::VectorImage<double,3> ODFImageType;
50  typedef anima::PatientToGroupODFComparisonImageFilter<double> MAOZScoreImageFilterType;
51 
52  itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
53  callback->SetCallback(eventCallback);
54 
55  MAOZScoreImageFilterType::Pointer mainFilter = MAOZScoreImageFilterType::New();
56  mainFilter->SetComputationMask(anima::readImage < itk::Image <unsigned char,3> > (maskArg.getValue()));
57  mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
58 
59  mainFilter->SetInput(anima::readImage <ODFImageType> (refODFArg.getValue()));
60  mainFilter->SetExplainedRatio(expVarArg.getValue());
61  mainFilter->SetNumEigenValuesPCA(numEigenArg.getValue());
62 
63  std::vector < std::vector <double> > sampleDirections = anima::InitializeSampleDirections(nbThetaArg.getValue(),nbPhiArg.getValue(),
64  samplesFileNameArg.getValue());
65 
66  mainFilter->SetSampleDirections(sampleDirections);
67 
68  if (statTestArg.getValue() == "chi")
69  mainFilter->SetStatisticalTestType(MAOZScoreImageFilterType::CHI_SQUARE);
70  else
71  mainFilter->SetStatisticalTestType(MAOZScoreImageFilterType::FISHER);
72 
73  std::ifstream fileIn(dataODFArg.getValue());
74  if (!fileIn.is_open())
75  {
76  std::cerr << "Could not open ODF data file (" << dataODFArg.getValue() << ")" << std::endl;
77  return EXIT_FAILURE;
78  }
79 
80  while (!fileIn.eof())
81  {
82  char tmpStr[2048];
83  fileIn.getline(tmpStr,2048);
84 
85  if (strcmp(tmpStr,"") == 0)
86  continue;
87 
88  std::cout << "Loading ODF image " << tmpStr << "..." << std::endl;
89  mainFilter->AddDatabaseInput(anima::readImage <ODFImageType> (tmpStr));
90  }
91  fileIn.close();
92 
93  mainFilter->AddObserver(itk::ProgressEvent(), callback);
94 
95  try
96  {
97  mainFilter->Update();
98  }
99  catch(itk::ExceptionObject &e)
100  {
101  std::cerr << e << std::endl;
102  return EXIT_FAILURE;
103  }
104 
105  anima::writeImage < itk::Image <double, 3> > (resArg.getValue(),mainFilter->GetOutput(0));
106  anima::writeImage < itk::Image <double, 3> > (resPValArg.getValue(),mainFilter->GetOutput(1));
107 
108  return EXIT_SUCCESS;
109 }
int main(int argc, char **argv)
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
std::vector< std::vector< double > > InitializeSampleDirections(unsigned int nbTheta, unsigned int nbPhi, std::string sampleDirFileName)
itk::SmartPointer< ImageType > readImage(std::string filename)