ANIMA  4.0
animaTotalLesionLoad.cxx
Go to the documentation of this file.
1 #include <tclap/CmdLine.h>
2 
3 #include <itkTimeProbe.h>
6 
7 int main(int argc, const char** argv)
8 {
9  const unsigned int Dimension = 3;
10  typedef itk::Image <unsigned char,Dimension> ImageType;
11  typedef itk::ImageRegionConstIterator <ImageType> ImageIterator;
12 
13  // Parsing arguments
14  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
15 
16  // Input filenames
17  TCLAP::ValueArg<std::string> inArg("i", "inputfile", "Input image", true, "", "input image", cmd);
18  // Output filenames
19  TCLAP::ValueArg<std::string> outArg("o", "outputfile", "Output TLL score", false, "", "output image", cmd);
20 
21  try
22  {
23  cmd.parse(argc,argv);
24  }
25  catch (TCLAP::ArgException& e)
26  {
27  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
28  return EXIT_FAILURE;
29  }
30 
31  ImageType::Pointer inputImage = anima::readImage <ImageType> (inArg.getValue());
32 
33  ImageIterator inputIt(inputImage,inputImage->GetLargestPossibleRegion());
34 
35  unsigned int cpt=0;
36  while(!inputIt.IsAtEnd())
37  {
38  if(inputIt.Get() != 0)
39  ++cpt;
40 
41  ++inputIt;
42  }
43 
44  ImageType::SpacingType spacing = inputImage->GetSpacing();
45  ImageType::SpacingValueType spacingTot = spacing[0];
46  for (unsigned int i = 1; i < 3;++i)
47  spacingTot *= spacing[i];
48 
49  std::ofstream oFileOut;
50  if (outArg.getValue() != "")
51  {
52  oFileOut.open(outArg.getValue(), std::ios::out | std::ios::trunc);
53  if (!oFileOut.is_open())
54  {
55  std::cerr << "Can not open file: " << outArg.getValue() << "to store TLL value" << std::endl;
56  }
57  }
58 
59  if (oFileOut.is_open())
60  {
61  oFileOut << cpt * spacingTot;
62  }
63  else
64  {
65  std::cout << cpt * spacingTot << std::endl;
66  }
67 
68  oFileOut.close();
69 
70  return EXIT_SUCCESS;
71 }
int main(int argc, const char **argv)