ANIMA  4.0
animaODFProbabilisticTractography.cxx
Go to the documentation of this file.
3 #include <itkTimeProbe.h>
4 
5 #include <tclap/CmdLine.h>
6 
9 
10 #include <itkCommand.h>
11 
12 #include <animaShapesWriter.h>
13 
14 //Update progression of the process
15 void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
16 {
17  itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
18  std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
19 }
20 
21 int main(int argc, char* argv[])
22 {
23  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
24 
25  // Mandatory arguments
26  TCLAP::ValueArg<std::string> odfArg("i","odf","Input diffusion tensor image",true,"","dti image",cmd);
27  TCLAP::ValueArg<std::string> seedMaskArg("s","seed-mask","Seed mask",true,"","seed",cmd);
28  TCLAP::ValueArg<std::string> fibersArg("o","fibers","Output fibers",true,"","fibers",cmd);
29  TCLAP::ValueArg<std::string> b0Arg("b","b0","B0 image",true,"","b0 image",cmd);
30  TCLAP::ValueArg<std::string> noiseArg("N","noise","Noise image",true,"","noise image",cmd);
31 
32  TCLAP::ValueArg<int> colinearityModeArg("","col-init-mode",
33  "Colinearity mode for initialization - 0: center, 1: outward, 2: top, 3: bottom, 4: left, 5: right, 6: front, 7: back (default: 0)",
34  false,0,"colinearity mode for initialization",cmd);
35  TCLAP::ValueArg<int> initialDirectionModeArg("","init-mode",
36  "Mode for initialization - 0: take most colinear direction, 1: take highest weighted direction (default: 1)",
37  false,1,"mode for initialization",cmd);
38 
39  // Optional mask arguments
40  TCLAP::ValueArg<std::string> cutMaskArg("c","cut-mask","Mask for cutting fibers (default: none)",false,"","cut mask",cmd);
41  TCLAP::ValueArg<std::string> forbiddenMaskArg("f","forbidden-mask","Mask for removing fibers (default: none)",false,"","remove mask",cmd);
42  TCLAP::ValueArg<std::string> filterMaskArg("","filter-mask","Mask for filtering fibers (default: none)",false,"","filter mask",cmd);
43 
44  TCLAP::ValueArg<double> gfaThrArg("","gfa-thr","GFA threshold (default: 0.2)",false,0.2,"GFA threshold",cmd);
45  TCLAP::ValueArg<double> stepLengthArg("","step-length","Length of each step (default: 1)",false,1.0,"step length",cmd);
46  TCLAP::ValueArg<int> nbFibersArg("","nb-fibers","Number of starting particle filters (n*n*n) per voxel (default: 1)",false,1,"number of seeds per voxel",cmd);
47 
48  TCLAP::ValueArg<double> minLengthArg("","min-length","Minimum length for a fiber to be considered for computation (default: 10mm)",false,10.0,"minimum length",cmd);
49  TCLAP::ValueArg<double> maxLengthArg("","max-length","Maximum length of a tract (default: 150mm)",false,150.0,"maximum length",cmd);
50 
51  TCLAP::ValueArg<unsigned int> nbParticlesArg("n","nb-particles","Number of particles per filter (default: 1000)",false,1000,"number of particles",cmd);
52  TCLAP::ValueArg<unsigned int> clusterMinSizeArg("","cluster-min-size","Minimal number of particles per cluster before split (default: 10)",false,10,"minimal cluster size",cmd);
53 
54  TCLAP::ValueArg<double> resampThrArg("r","resamp-thr","Resampling relative threshold (default: 0.8)",false,0.8,"resampling threshold",cmd);
55 
56  TCLAP::ValueArg<double> minDiffProbaArg("","mdp","Minimal diffusion probability for an ODF direction to be kept (default: 0.02",false,0.01,"Minimal diffusion probability for an ODF direction",cmd);
57  TCLAP::ValueArg<double> trashThrArg("","trash-thr","Relative threshold to keep fibers in trash (default: 0.1)",false,0.1,"trash threshold",cmd);
58  TCLAP::ValueArg<double> kappaPriorArg("k","kappa-prior","Kappa of prior distribution (default: 15)",false,15.0,"prior kappa",cmd);
59  TCLAP::ValueArg<double> curvScaleArg("","cs","Scale for ODF curvature to get vMF kappa (default: 6)",false,6.0,"scale for ODF curvature",cmd);
60 
61  TCLAP::ValueArg<double> distThrArg("","dist-thr","Hausdorff distance threshold for mergine clusters (default: 0.5)",false,0.5,"merging threshold",cmd);
62  TCLAP::ValueArg<double> kappaThrArg("","kappa-thr","Kappa threshold for splitting clusters (default: 30)",false,30.0,"splitting threshold",cmd);
63 
64  TCLAP::ValueArg<unsigned int> clusterDistArg("","cluster-dist","Distance between clusters: choices are 0 (AHD), 1 (HD, default) or 2 (MHD)",false,1,"cluster distance",cmd);
65 
66  TCLAP::SwitchArg averageClustersArg("M","average-clusters","Output only cluster mean",cmd,false);
67  TCLAP::SwitchArg addLocalDataArg("L","local-data","Add local data information to output tracks",cmd);
68 
69  TCLAP::ValueArg<unsigned int> nbThreadsArg("T","nb-threads","Number of threads to run on (default: all available)",false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),"number of threads",cmd);
70 
71  try
72  {
73  cmd.parse(argc,argv);
74  }
75  catch (TCLAP::ArgException& e)
76  {
77  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
78  return(1);
79  }
80 
82  typedef MainFilterType::InputModelImageType InputModelImageType;
83  typedef MainFilterType::MaskImageType MaskImageType;
84  typedef MainFilterType::Vector3DType Vector3DType;
85 
86  MainFilterType::Pointer odfTracker = MainFilterType::New();
87 
88  odfTracker->SetNumberOfWorkUnits(nbThreadsArg.getValue());
89  odfTracker->SetInputModelImage(anima::readImage <InputModelImageType> (odfArg.getValue()));
90 
91  odfTracker->SetInitialColinearityDirection((MainFilterType::ColinearityDirectionType)colinearityModeArg.getValue());
92  odfTracker->SetInitialDirectionMode((MainFilterType::InitialDirectionModeType)initialDirectionModeArg.getValue());
93 
94  // Load seed mask
95  odfTracker->SetSeedMask(anima::readImage <MaskImageType> (seedMaskArg.getValue()));
96 
97  // Load cut mask
98  if (cutMaskArg.getValue() != "")
99  odfTracker->SetCutMask(anima::readImage <MaskImageType> (cutMaskArg.getValue()));
100 
101  // Load forbidden mask
102  if (forbiddenMaskArg.getValue() != "")
103  odfTracker->SetForbiddenMask(anima::readImage <MaskImageType> (forbiddenMaskArg.getValue()));
104 
105  // Load filter mask
106  if (filterMaskArg.getValue() != "")
107  odfTracker->SetFilterMask(anima::readImage <MaskImageType> (filterMaskArg.getValue()));
108 
109  typedef MainFilterType::ScalarImageType ScalarImageType;
110  odfTracker->SetB0Image(anima::readImage <ScalarImageType> (b0Arg.getValue()));
111  odfTracker->SetNoiseImage(anima::readImage <ScalarImageType> (noiseArg.getValue()));
112 
113  odfTracker->SetNumberOfFibersPerPixel(nbFibersArg.getValue());
114  odfTracker->SetStepProgression(stepLengthArg.getValue());
115  odfTracker->SetGFAThreshold(gfaThrArg.getValue());
116  odfTracker->SetMinLengthFiber(minLengthArg.getValue());
117  odfTracker->SetMaxLengthFiber(maxLengthArg.getValue());
118 
119  odfTracker->SetNumberOfParticles(nbParticlesArg.getValue());
120  odfTracker->SetMinimalNumberOfParticlesPerClass(clusterMinSizeArg.getValue());
121  odfTracker->SetResamplingThreshold(resampThrArg.getValue());
122  odfTracker->SetFiberTrashThreshold(trashThrArg.getValue());
123 
124  odfTracker->SetMinimalDiffusionProbability(minDiffProbaArg.getValue());
125  odfTracker->SetKappaOfPriorDistribution(kappaPriorArg.getValue());
126 
127  odfTracker->SetPositionDistanceFuseThreshold(distThrArg.getValue());
128  odfTracker->SetKappaSplitThreshold(kappaThrArg.getValue());
129  odfTracker->SetClusterDistance(clusterDistArg.getValue());
130  odfTracker->SetCurvatureScale(curvScaleArg.getValue());
131 
132  bool computeLocalColors = (fibersArg.getValue().find(".fds") != std::string::npos) && (addLocalDataArg.isSet());
133  odfTracker->SetComputeLocalColors(computeLocalColors);
134  odfTracker->SetMAPMergeFibers(averageClustersArg.getValue());
135 
136  itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
137  callback->SetCallback(eventCallback);
138  odfTracker->AddObserver(itk::ProgressEvent(), callback);
139 
140  itk::TimeProbe tmpTime;
141  tmpTime.Start();
142 
143  odfTracker->Update();
144  odfTracker->RemoveAllObservers();
145 
146  tmpTime.Stop();
147  std::cout << "Tracking time: " << tmpTime.GetTotal() << "s" << std::endl;
148 
149  anima::ShapesWriter writer;
150  writer.SetInputData(odfTracker->GetOutput());
151  writer.SetFileName(fibersArg.getValue());
152  writer.Update();
153 
154  return EXIT_SUCCESS;
155 }
void SetInputData(vtkPolyData *data)
int main(int argc, char *argv[])
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
void SetFileName(std::string &name)