1 #include <tclap/CmdLine.h> 6 #include <vtkSmartPointer.h> 8 #include <vtkPointData.h> 9 #include <vtkPolyData.h> 12 #include <itkCastImageFilter.h> 14 int main(
int argc,
char **argv)
16 TCLAP::CmdLine cmd(
"Filters fibers from a vtp file using a label image and specifying with several -t and -f which labels should be touched or are forbidden for each fiber. INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
18 TCLAP::ValueArg<std::string> inArg(
"i",
"input",
"input tracks file",
true,
"",
"input tracks",cmd);
19 TCLAP::ValueArg<std::string> outArg(
"o",
"output",
"output mask image",
true,
"",
"output mask image",cmd);
20 TCLAP::ValueArg<std::string> geomArg(
"g",
"geometry",
"Geometry image",
true,
"",
"geometry image",cmd);
22 TCLAP::SwitchArg proportionArg(
"P",
"proportion",
"Output proportion of fibers going through each pixel",cmd,
false);
28 catch (TCLAP::ArgException& e)
30 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
34 typedef itk::Image <double, 3> OutputImageType;
35 OutputImageType::Pointer outputImage = anima::readImage <OutputImageType> (geomArg.getValue());
36 outputImage->FillBuffer(0.0);
42 vtkSmartPointer <vtkPolyData> tracks = trackReader.
GetOutput();
44 vtkIdType nbCells = tracks->GetNumberOfCells();
45 double incrementFactor = 1.0;
46 if (proportionArg.isSet())
47 incrementFactor /= nbCells;
50 OutputImageType::IndexType currentIndex;
51 OutputImageType::PointType currentPoint;
52 OutputImageType::RegionType region = outputImage->GetLargestPossibleRegion();
55 for (
int j = 0;j < nbCells;++j)
57 vtkCell *cell = tracks->GetCell(j);
58 vtkPoints *cellPts = cell->GetPoints();
59 vtkIdType nbPts = cellPts->GetNumberOfPoints();
62 for (
int i = 0;i < nbPts;++i)
64 cellPts->GetPoint(i,ptVals);
66 for (
unsigned int k = 0;k < 3;++k)
67 currentPoint[k] = ptVals[k];
69 outputImage->TransformPhysicalPointToIndex(currentPoint,currentIndex);
70 bool insideBuffer =
true;
71 for (
unsigned int k = 0;k < 3;++k)
73 if ((currentIndex[k] < 0)||(currentIndex[k] >= region.GetSize(k)))
83 double countIndex = outputImage->GetPixel(currentIndex) + incrementFactor;
84 outputImage->SetPixel(currentIndex, countIndex);
88 if (proportionArg.isSet())
89 anima::writeImage <OutputImageType> (outArg.getValue(),outputImage);
92 using MaskImageType = itk::Image <unsigned int, 3>;
93 using CastFilterType = itk::CastImageFilter <OutputImageType, MaskImageType>;
95 CastFilterType::Pointer castFilter = CastFilterType::New();
96 castFilter->SetInput(outputImage);
99 anima::writeImage <MaskImageType> (outArg.getValue(), castFilter->GetOutput());
int main(int argc, char **argv)
void SetFileName(std::string &name)
vtkPolyData * GetOutput()