ANIMA  4.0
animaCreateImage.cxx
Go to the documentation of this file.
1 #include <tclap/CmdLine.h>
2 #include <iostream>
3 #include <string>
4 
5 #include <itkImage.h>
6 #include <itkVectorImage.h>
7 #include <itkImageRegionIterator.h>
8 
10 
11 int main(int argc, char **argv)
12 {
13  TCLAP::CmdLine cmd("INRIA / IRISA - VisAGeS/Empenn Team", ' ',ANIMA_VERSION);
14 
15  TCLAP::ValueArg<std::string> geomArg("g","geometryfile","Geometry image",true,"","Geometry image",cmd);
16  TCLAP::ValueArg<std::string> outArg("o","outputfile","output image",true,"","output image",cmd);
17  TCLAP::ValueArg<unsigned int> vdimArg("v","vdim","Force vdim to this value",false,1,"Force vdim",cmd);
18  TCLAP::ValueArg<unsigned int> valueArg("b","buffervalue","Value to fill buffer",false,0,"Value to fill buffer",cmd);
19 
20  TCLAP::SwitchArg vecArg("V","isvec","Input image is a vector / tensor image",cmd,false);
21 
22  try
23  {
24  cmd.parse(argc,argv);
25  }
26  catch (TCLAP::ArgException& e)
27  {
28  std::cerr << "Error: " << e.error() << "for argument " << e.argId() << std::endl;
29  return EXIT_FAILURE;
30  }
31 
32  typedef itk::Image <double,3> ImageType;
33  typedef itk::VectorImage <double,3> VectorImageType;
34 
35  bool isVect = vecArg.isSet();
36  unsigned int fvdim = vdimArg.getValue();
37  if (fvdim > 1)
38  isVect = true;
39 
40  if (!isVect)
41  {
42  ImageType::Pointer geomImage = anima::readImage <ImageType> (geomArg.getValue());
43 
44  ImageType::Pointer resImage = ImageType::New();
45  resImage->Initialize();
46  resImage->SetRegions(geomImage->GetLargestPossibleRegion());
47  resImage->SetSpacing(geomImage->GetSpacing());
48  resImage->SetOrigin(geomImage->GetOrigin());
49  resImage->SetDirection(geomImage->GetDirection());
50 
51  resImage->Allocate();
52  resImage->FillBuffer(valueArg.getValue());
53 
54  anima::writeImage <ImageType> (outArg.getValue(),resImage);
55  }
56  else
57  {
58  VectorImageType::Pointer geomImage = anima::readImage <VectorImageType> (geomArg.getValue());
59 
60  VectorImageType::Pointer resImage = VectorImageType::New();
61  resImage->Initialize();
62  resImage->SetRegions(geomImage->GetLargestPossibleRegion());
63  resImage->SetSpacing(geomImage->GetSpacing());
64  resImage->SetOrigin(geomImage->GetOrigin());
65  resImage->SetDirection(geomImage->GetDirection());
66 
67  itk::VariableLengthVector <double> tmpData;
68  unsigned int vdim = geomImage->GetNumberOfComponentsPerPixel();
69  if (fvdim > 1)
70  vdim = fvdim;
71 
72  resImage->SetNumberOfComponentsPerPixel(vdim);
73  resImage->Allocate();
74 
75  tmpData.SetSize(vdim);
76  for (unsigned int i = 0;i < vdim;++i)
77  tmpData[i] = valueArg.getValue();
78 
79  itk::ImageRegionIterator <VectorImageType> tmpIt(resImage,resImage->GetLargestPossibleRegion());
80 
81  while(!tmpIt.IsAtEnd())
82  {
83  tmpIt.Set(tmpData);
84  ++tmpIt;
85  }
86 
87  anima::writeImage <VectorImageType> (outArg.getValue(),resImage);
88  }
89 
90  return EXIT_SUCCESS;
91 }
int main(int argc, char **argv)