DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
SphereTessellator.cxx
Go to the documentation of this file.
1 
17 #include <SphereTessellatorCLP.h>
18 #include "utl.h"
19 
20 #include "itkSphereTessellator.h"
21 
22 
23 int
24 main (int argc, char *argv[])
25 {
26  PARSE_ARGS;
27 
28  typedef double TElement;
29  typedef itk::SphereTessellator<TElement> TessellatorType;
30  typedef itk::SphereTessellator<TElement>::Pointer TessellatorPointer;
31 
32  TessellatorPointer tessellator = TessellatorType::New();
33 
34  if ( _BasicShape == "TETRAHEDRON" )
35  tessellator->SetBasicShape(TessellatorType::TETRAHEDRON);
36  if ( _BasicShape == "OCTAHEDRON" )
37  tessellator->SetBasicShape(TessellatorType::OCTAHEDRON);
38  if ( _BasicShape == "ICOSAHEDRON" )
39  tessellator->SetBasicShape(TessellatorType::ICOSAHEDRON);
40 
41  tessellator->SetOrder(_Order);
42  tessellator->TessellateSphere();
43 
44  unsigned int numberOfVertices = tessellator->GetNumberOfVertices();
45  unsigned int numberOfFaces = tessellator->GetNumberOfFaces();
46  unsigned int numberOfEdges = tessellator->GetNumberOfEdges();
47 
48  std::ofstream ofs; // create ofstream object
49 
50  ofs.open ( _OutputFile.c_str() ); // open ofstream
51  utlAssert (ofs, "\nERROR : failed to open output file " << _OutputFile );
52 
53  TessellatorType::PointsMatrixType points = tessellator->GetPointsMatrix();
54  TessellatorType::CellsMatrixType cells = tessellator->GetCellsMatrix();
55 
56  // if (_OutInOderrArg.isSet())
57  // {
58  // TessellatorType::PointsMatrixType points_back = points;
59  // TessellatorType::CellsMatrixType cells_back = cells;
60  // std::vector<bool> used(points.rows(),false);
61  // int count=0;
62  // for ( int i = 0; i < cells.rows(); i += 1 )
63  // {
64  // for ( int j = 0; j < cells.columns(); j += 1 )
65  // {
66  // if (used[cells_back(i,j)])
67  // continue;
68 
69  // used[cells_back(i,j)] = true;
70  // points.set_row(count, points_back.get_row(cells_back(i,j)));
71  // for ( int ii = 0; ii < cells.rows(); ii += 1 )
72  // for ( int jj = 0; jj < cells.columns(); jj += 1 )
73  // {
74  // if (cells_back(ii,jj)==cells_back(i,j))
75  // cells(ii,jj) = count;
76  // }
77  // count++;
78  // }
79  // }
80  // }
81 
82  ofs.precision(10);
83  if (_NumberOfDirectionsArg.isSet() && !_HemisphereArg.isSet())
84  ofs << numberOfVertices << " " << numberOfFaces << " " << numberOfEdges << "\n";
85  if (_NumberOfDirectionsArg.isSet() && _HemisphereArg.isSet())
86  ofs << numberOfVertices/2 << "\n";
87 
88  if (!_HemisphereArg.isSet())
89  {
90  for ( int i = 0; i < numberOfVertices; i += 1 )
91  ofs << points(i,0) << " " << points(i,1) << " " << points(i,2) << "\n";
92  }
93  else
94  {
95  for ( int i = 0; i < numberOfVertices; i += 1 )
96  {
97  if ( points(i,2)>0
98  || (std::abs(points(i,2))<1e-20 && points(i,1)<0)
99  || (std::abs(points(i,2))<1e-20 && std::abs(points(i,1))<1e-20 && points(i,0)>0))
100  ofs << points(i,0) << " " << points(i,1) << " " << points(i,2) << "\n";
101  }
102  }
103 
104  if (_CellArg.isSet() && !_HemisphereArg.isSet())
105  {
106  for ( int i = 0; i <numberOfFaces; i += 1 )
107  ofs << cells(i,0) << " " << cells(i,1) << " " << cells(i,2) << "\n";
108  }
109 
110  ofs.close();
111 
112  return EXIT_SUCCESS;
113 }
helper functions specifically used in dmritool
T abs(const T x)
template version of the fabs function
#define utlAssert(cond, expout)
Definition: utlCoreMacro.h:550
SmartPointer< Self > Pointer
Tesselates a sphere via subdivision of tetrahedron, octahedron, or icosahedron.
int main(int argc, char *argv[])