ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkQuadEdgeMeshEulerOperatorsTestHelper.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkQuadEdgeMeshEulerOperatorsTestHelper_h
19 #define __itkQuadEdgeMeshEulerOperatorsTestHelper_h
20 
23 
24 typedef unsigned long IdentifierType;
25 
26 template<class TMesh >
27 bool AssertTopologicalInvariants( TMesh *mesh,
28  IdentifierType NumVertices,
29  IdentifierType NumFaces,
30  IdentifierType NumEdges,
31  IdentifierType NumBorders,
32  IdentifierType Genus)
33 {
35  typename CheckerType::Pointer check = CheckerType::New();
36  check->SetMesh( mesh );
37  check->SetExpectedNumberOfPoints( NumVertices );
38  check->SetExpectedNumberOfEdges( NumFaces );
39  check->SetExpectedNumberOfFaces( NumEdges );
40  check->SetExpectedNumberOfBoundaries( NumBorders );
41  check->SetExpectedGenus( Genus );
42  return( check->ValidateEulerCharacteristic( ) );
43 }
44 
45 //----------------------------------------------------------------------------
46 template< class TMesh >
47 std::vector< typename TMesh::PointType >
48 GeneratePointCoordinates( const unsigned int& iN )
49 {
50  typedef typename TMesh::PointType PointType;
51  typedef typename PointType::CoordRepType CoordRepType;
52  std::vector< PointType > oPt( iN * iN );
53 
54  for( unsigned int i = 0; i < iN; i++ )
55  {
56  for( unsigned int j = 0; j < iN; j++ )
57  {
58  oPt[ i * iN + j ][0] = static_cast< CoordRepType >( j );
59  oPt[ i * iN + j ][1] = static_cast< CoordRepType >( i );
60  oPt[ i * iN + j ][2] = static_cast< CoordRepType >( 0. );
61  }
62  }
63 
64  return oPt;
65 }
66 
67 //----------------------------------------------------------------------------
68 template< class TMesh >
69 void CreateSquareQuadMesh( typename TMesh::Pointer mesh )
70 {
71  typedef TMesh MeshType;
72  typedef typename MeshType::CellType CellType;
73 
74  typedef itk::QuadEdgeMeshPolygonCell< CellType > QEPolygonCellType;
75 
76  if( mesh->GetNumberOfPoints( ) )
77  {
78  mesh->Clear( );
79  mesh->ClearFreePointAndCellIndexesLists();
80  }
81 
83  int expectedNumPts = 25;
84  int expectedNumCells = 16;
85  int simpleSquareCells[64] =
86  { 0, 1, 6, 5,
87  1, 2, 7, 6,
88  2, 3, 8, 7,
89  3, 4, 9, 8,
90  5, 6, 11, 10,
91  6, 7, 12, 11,
92  7, 8, 13, 12,
93  8, 9, 14, 13,
94  10, 11, 16, 15,
95  11, 12, 17, 16,
96  12, 13, 18, 17,
97  13, 14, 19, 18,
98  15, 16, 21, 20,
99  16, 17, 22, 21,
100  17, 18, 23, 22,
101  18, 19, 24, 23 };
102 
103  typedef typename MeshType::PointType PointType;
104 
105  std::vector< PointType > pts = GeneratePointCoordinates< MeshType >( 5 );
106 
107  for(int i=0; i<expectedNumPts; i++)
108  {
109  mesh->SetPoint( i, pts[i] );
110  }
111 
112  typename CellType::CellAutoPointer cellpointer;
113  QEPolygonCellType *poly;
114 
115  for(int i=0; i<expectedNumCells; i++)
116  {
117  poly = new QEPolygonCellType( 4 );
118  cellpointer.TakeOwnership( poly );
119  cellpointer->SetPointId( 0, simpleSquareCells[4*i] );
120  cellpointer->SetPointId( 1, simpleSquareCells[4*i+1] );
121  cellpointer->SetPointId( 2, simpleSquareCells[4*i+2] );
122  cellpointer->SetPointId( 3, simpleSquareCells[4*i+3] );
123  mesh->SetCell( i, cellpointer );
124  }
125 }
126 
127 //----------------------------------------------------------------------------
128 template< class TMesh >
129 void CreateSquareTriangularMesh( typename TMesh::Pointer mesh )
130 {
131  typedef TMesh MeshType;
132  typedef typename MeshType::CellType CellType;
133 
134  typedef itk::QuadEdgeMeshPolygonCell< CellType > QEPolygonCellType;
135 
136  if( mesh->GetNumberOfPoints( ) )
137  {
138  mesh->Clear( );
139  mesh->ClearFreePointAndCellIndexesLists();
140  }
141 
143  int expectedNumPts = 25;
144  int expectedNumCells = 32;
145  int simpleSquareCells[96] =
146  { 0, 1, 6,
147  0, 6, 5,
148  1, 2, 7,
149  1, 7, 6,
150  2, 3, 8,
151  2, 8, 7,
152  3, 4, 9,
153  3, 9, 8,
154  5, 6, 11,
155  5, 11, 10,
156  6, 7, 12,
157  6, 12, 11,
158  7, 8, 13,
159  7, 13, 12,
160  8, 9, 14,
161  8, 14, 13,
162  10, 11, 16,
163  10, 16, 15,
164  11, 12, 17,
165  11, 17, 16,
166  12, 13, 18,
167  12, 18, 17,
168  13, 14, 19,
169  13, 19, 18,
170  15, 16, 21,
171  15, 21, 20,
172  16, 17, 22,
173  16, 22, 21,
174  17, 18, 23,
175  17, 23, 22,
176  18, 19, 24,
177  18, 24, 23 };
178 
179  typedef typename TMesh::PointType PointType;
180  std::vector< PointType > pts = GeneratePointCoordinates< TMesh >( 5 );
181 
182  for(int i=0; i<expectedNumPts; i++)
183  {
184  mesh->SetPoint( i, pts[i] );
185  }
186 
187  typename CellType::CellAutoPointer cellpointer;
188  QEPolygonCellType *poly;
189 
190  for(int i=0; i<expectedNumCells; i++)
191  {
192  poly = new QEPolygonCellType( 3 );
193  cellpointer.TakeOwnership( poly );
194  cellpointer->SetPointId( 0, simpleSquareCells[3*i] );
195  cellpointer->SetPointId( 1, simpleSquareCells[3*i+1] );
196  cellpointer->SetPointId( 2, simpleSquareCells[3*i+2] );
197  mesh->SetCell( i, cellpointer );
198  }
199 }
200 
201 //----------------------------------------------------------------------------
202 template< class TMesh >
203 void CreateTetraedronMesh( typename TMesh::Pointer mesh )
204 {
205  typedef TMesh MeshType;
206  typedef typename MeshType::CellType CellType;
207 
208  typedef itk::QuadEdgeMeshPolygonCell< CellType > QEPolygonCellType;
209 
210  if( mesh->GetNumberOfPoints( ) )
211  {
212  mesh->Clear( );
213  mesh->ClearFreePointAndCellIndexesLists();
214  }
215 
217  int expectedNumPts = 4;
218  int expectedNumCells = 4;
219  int simpleSquareCells[12] =
220  { 0, 1, 2,
221  1, 0, 3,
222  1, 3, 2,
223  2, 3, 0 };
224 
225  typedef typename TMesh::PointType PointType;
226  std::vector< PointType > pts( 4 );
227  int i(0);
228  pts[i][0] = 0.; pts[i][1] = 1.; pts[i++][2] = 0.;
229  pts[i][0] = 0.; pts[i][1] = -1.; pts[i++][2] = 0.;
230  pts[i][0] = -1.; pts[i][1] = 0.; pts[i++][2] = 0.;
231  pts[i][0] = 0.; pts[i][1] = 0.; pts[i++][2] = 1.;
232 
233  for( i=0; i<expectedNumPts; i++)
234  {
235  mesh->SetPoint( i, pts[i] );
236  }
237 
238  typename CellType::CellAutoPointer cellpointer;
239  QEPolygonCellType *poly;
240 
241  for( i=0; i<expectedNumCells; i++)
242  {
243  poly = new QEPolygonCellType( 3 );
244  cellpointer.TakeOwnership( poly );
245  cellpointer->SetPointId( 0, simpleSquareCells[3*i] );
246  cellpointer->SetPointId( 1, simpleSquareCells[3*i+1] );
247  cellpointer->SetPointId( 2, simpleSquareCells[3*i+2] );
248  mesh->SetCell( i, cellpointer );
249  }
250 }
251 
252 
253 //----------------------------------------------------------------------------
254 template< class TMesh >
255 void CreateSamosa( typename TMesh::Pointer mesh )
256 {
257  typedef TMesh MeshType;
258  typedef typename MeshType::CellType CellType;
259 
260  typedef itk::QuadEdgeMeshPolygonCell< CellType > QEPolygonCellType;
261 
262  if( mesh->GetNumberOfPoints( ) )
263  {
264  mesh->Clear( );
265  mesh->ClearFreePointAndCellIndexesLists();
266  }
267 
269  int expectedNumPts = 3;
270  int expectedNumCells = 2;
271  int simpleSquareCells[6] =
272  { 0, 1, 2,
273  1, 0, 2 };
274 
275  typedef typename TMesh::PointType PointType;
276  std::vector< PointType > pts( 3 );
277  int i(0);
278  pts[i][0] = 0.; pts[i][1] = 1.; pts[i++][2] = 0.;
279  pts[i][0] = 0.; pts[i][1] = -1.; pts[i++][2] = 0.;
280  pts[i][0] = -1.; pts[i][1] = 0.; pts[i++][2] = 0.;
281 
282  for( i=0; i<expectedNumPts; i++)
283  {
284  mesh->SetPoint( i, pts[i] );
285  }
286 
287  typename CellType::CellAutoPointer cellpointer;
288  QEPolygonCellType *poly;
289 
290  for( i=0; i<expectedNumCells; i++)
291  {
292  poly = new QEPolygonCellType( 3 );
293  cellpointer.TakeOwnership( poly );
294  cellpointer->SetPointId( 0, simpleSquareCells[3*i] );
295  cellpointer->SetPointId( 1, simpleSquareCells[3*i+1] );
296  cellpointer->SetPointId( 2, simpleSquareCells[3*i+2] );
297  mesh->SetCell( i, cellpointer );
298  }
299 }
300 
301 
302 #endif
303