DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkSphereTessellator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Sphere Tessellator
4  Module: $HeadURL $
5  Language: C++
6  Date: $Date$
7  Version: $Revision$
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notices for more information.
12 
13 =========================================================================*/
14 #ifndef __itkSphereTessellator_h
15 #define __itkSphereTessellator_h
16 
17 #include <itkObject.h>
18 #include <itkObjectFactory.h>
19 #include <vnl/vnl_matrix.h>
20 #include <vnl/vnl_vector.h>
21 
22 namespace itk
23 {
24 
36 template <typename TElement = double>
37 class ITK_EXPORT SphereTessellator: public Object
38 {
39 public:
42  typedef Object Superclass;
43  typedef SmartPointer<Self> Pointer;
44  typedef SmartPointer<const Self> ConstPointer;
45 
47  itkNewMacro(Self);
48 
50  itkTypeMacro(SphereTessellator, Object);
51 
53  const static unsigned int NDimensions = 3;
54 
56  typedef vnl_matrix<TElement> PointsMatrixType;
57  typedef vnl_matrix<unsigned long> CellsMatrixType;
58 
60  void TessellateSphere();
61 
63  typedef enum {TETRAHEDRON, OCTAHEDRON, ICOSAHEDRON} BasicShapeType;
64 
65  itkGetMacro(BasicShape, BasicShapeType);
66  itkSetMacro(BasicShape, BasicShapeType);
67 
70  itkGetMacro(Order, unsigned int);
71  itkSetMacro(Order, unsigned int);
72 
74  itkGetMacro(NumberOfVertices, unsigned int);
75  itkGetMacro(NumberOfFaces, unsigned int);
76  itkGetMacro(NumberOfEdges, unsigned int);
77 
78  PointsMatrixType GetPointsMatrix()
79  {
80  return m_Points;
81  }
82 
83  PointsMatrixType GetPointsMatrixInHemisphere()
84  {
85  PointsMatrixType points(m_Points.rows()/2, 3);
86  int j=0;
87  for ( int i = 0; i < m_NumberOfVertices; i += 1 )
88  {
89  if ( points(i,2)>0
90  || (std::abs(points(i,2))<1e-20 && points(i,1)<0)
91  || (std::abs(points(i,2))<1e-20 && std::abs(points(i,1))<1e-20 && points(i,0)>0))
92  {
93  for ( int kk = 0; kk < 3; ++kk )
94  points(j,3) = m_Points(i,3);
95  j++;
96  }
97  }
98  return points;
99  }
100 
101  CellsMatrixType GetCellsMatrix()
102  {
103  return m_Cells;
104  }
105 
107  void Initialize(void);
108 
110  void Reserve(void);
111 
113  void Squeeze(void);
114 
115 protected:
117  virtual ~SphereTessellator();
118 
122  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
123 
124  void InitTetrahedron();
125  void InitOctahedron();
126  void InitIcosahedron();
127  int SearchMidpoint (int index_start, int index_end);
128  void Subdivide() ;
129  void OutputSphere();
130 
131 private:
132  SphereTessellator(const Self&); //purposely not implemented
133  void operator=(const Self&); //purposely not implemented
134 
135  unsigned int n_vertices;
136  unsigned int n_faces;
137  unsigned int n_edges;
138  double *vertices;
139  int *faces;
140 
141  unsigned int edge_walk;
142  int *start;
143  int *end;
144  int *midpoint;
145 
146  PointsMatrixType m_Points;
147  CellsMatrixType m_Cells;
148 
149  BasicShapeType m_BasicShape;
150 
151  unsigned int m_Order;
152 
153  unsigned int m_NumberOfVertices;
154  unsigned int m_NumberOfFaces;
155  unsigned int m_NumberOfEdges;
156 
157 };
158 
159 } // end namespace itk
160 
161 // Define instantiation macro for this template.
162 #define ITK_TEMPLATE_SphereTessellator(_, EXPORT, x, y) namespace itk { \
163  _(2(class EXPORT SphereTessellator< ITK_TEMPLATE_2 x >)) \
164  namespace Templates { typedef SphereTessellator< ITK_TEMPLATE_2 x > SphereTessellator##y; } \
165  }
166 
167 #if ITK_TEMPLATE_EXPLICIT
168 # include "Templates/itkSphereTessellator+-.h"
169 #endif
170 
171 #if !defined(ITK_MANUAL_INSTANTIATION) && !defined(__itkSphereTessellator_hxx)
172 # include "itkSphereTessellator.hxx"
173 #endif
174 
175 #endif
PointsMatrixType GetPointsMatrix()
vnl_matrix< unsigned long > CellsMatrixType
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
CellsMatrixType GetCellsMatrix()
T abs(const T x)
template version of the fabs function
vnl_matrix< TElement > PointsMatrixType
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
PointsMatrixType GetPointsMatrixInHemisphere()
Tesselates a sphere via subdivision of tetrahedron, octahedron, or icosahedron.