ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkAutomaticTopologyMeshSource.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 __itkAutomaticTopologyMeshSource_h
19 #define __itkAutomaticTopologyMeshSource_h
20 
21 #include "itkArray.h"
23 #include "itksys/hash_map.hxx"
24 #include "itkHexahedronCell.h"
25 #include "itkIntTypes.h"
26 #include "itkMesh.h"
27 #include "itkMeshSource.h"
28 #include "itkStructHashFunction.h"
29 #include "itkTetrahedronCell.h"
30 #include "itkVertexCell.h"
31 
32 namespace itk
33 {
110 template< class TOutputMesh >
111 class ITK_EXPORT AutomaticTopologyMeshSource:public MeshSource< TOutputMesh >
112 {
113 public:
119 
121  typedef TOutputMesh MeshType;
122  typedef typename MeshType::PointHashType PointHashType;
123  typedef typename MeshType::PointType PointType;
124  typedef typename MeshType::CellType CellType;
125  typedef typename MeshType::Pointer MeshPointer;
126  typedef typename PointType::CoordRepType CoordinateType;
127  typedef typename CellType::CellAutoPointer CellAutoPointer;
128 
130  typedef::itk::VertexCell< CellType > VertexCell;
131  typedef::itk::LineCell< CellType > LineCell;
132  typedef::itk::TriangleCell< CellType > TriangleCell;
133  typedef::itk::QuadrilateralCell< CellType > QuadrilateralCell;
134  typedef::itk::TetrahedronCell< CellType > TetrahedronCell;
135  typedef::itk::HexahedronCell< CellType > HexahedronCell;
136 
140 
143 
146  typedef itksys::hash_map<
147  PointType,
150 
152  itkStaticConstMacro(PointDimension, unsigned int,
153  MeshType::PointDimension);
154  itkStaticConstMacro(MaxTopologicalDimension, unsigned int,
155  MeshType::MaxTopologicalDimension);
157 
159  itkNewMacro(Self);
160 
163 
165  IdentifierType AddPoint(const PointType & p0);
166 
167  IdentifierType AddPoint(const CoordinateType *p0);
168 
174  IdentifierType AddPoint(CoordinateType x0 = 0, CoordinateType x1 = 0,
175  CoordinateType x2 = 0, CoordinateType x3 = 0,
176  CoordinateType x4 = 0, CoordinateType x5 = 0);
177 
179  IdentifierType AddVertex(const IdentifierArrayType & pointIds);
180 
181  IdentifierType AddVertex(IdentifierType pointId0);
182 
183  IdentifierType AddVertex(const PointType & p0);
184 
185  IdentifierType AddVertex(const CoordinateType *p0);
186 
191  IdentifierType AddLine(const IdentifierArrayType & pointIds);
192 
193  IdentifierType AddLine(
194  IdentifierType pointId0, IdentifierType pointId1);
195 
196  IdentifierType AddLine(const PointType & p0, const PointType & p1);
197 
198  IdentifierType AddLine(const CoordinateType *p0,
199  const CoordinateType *p1);
200 
211  IdentifierType AddTriangle(const IdentifierArrayType & pointIds);
212 
213  IdentifierType AddTriangle(
214  IdentifierType pointId0, IdentifierType pointId1,
215  IdentifierType pointId2);
216 
217  IdentifierType AddTriangle(const PointType & p0, const PointType & p1,
218  const PointType & p2);
219 
220  IdentifierType AddTriangle(const CoordinateType *p0,
221  const CoordinateType *p1,
222  const CoordinateType *p2);
223 
244  IdentifierType AddQuadrilateral(const IdentifierArrayType & pointIds);
245 
246  IdentifierType AddQuadrilateral(
247  IdentifierType pointId0, IdentifierType pointId1,
248  IdentifierType pointId2, IdentifierType pointId3);
249 
250  IdentifierType AddQuadrilateral(const PointType & p0, const PointType & p1,
251  const PointType & p2, const PointType & p3);
252 
253  IdentifierType AddQuadrilateral(const CoordinateType *p0,
254  const CoordinateType *p1,
255  const CoordinateType *p2,
256  const CoordinateType *p3);
257 
270  IdentifierType AddTetrahedron(const IdentifierArrayType & pointIds);
271 
272  IdentifierType AddTetrahedron(
273  IdentifierType pointId0, IdentifierType pointId1,
274  IdentifierType pointId2, IdentifierType pointId3);
275 
276  IdentifierType AddTetrahedron(const PointType & p0, const PointType & p1,
277  const PointType & p2, const PointType & p3);
278 
279  IdentifierType AddTetrahedron(const CoordinateType *p0,
280  const CoordinateType *p1,
281  const CoordinateType *p2,
282  const CoordinateType *p3);
283 
312  IdentifierType AddHexahedron(const IdentifierArrayType & pointIds);
313 
314  IdentifierType AddHexahedron(
315  IdentifierType pointId0, IdentifierType pointId1,
316  IdentifierType pointId2, IdentifierType pointId3,
317  IdentifierType pointId4, IdentifierType pointId5,
318  IdentifierType pointId6, IdentifierType pointId7);
319 
320  IdentifierType AddHexahedron(
321  const PointType & p0, const PointType & p1, const PointType & p2,
322  const PointType & p3, const PointType & p4, const PointType & p5,
323  const PointType & p6, const PointType & p7
324  );
325 
326  IdentifierType AddHexahedron(const CoordinateType *p0,
327  const CoordinateType *p1,
328  const CoordinateType *p2,
329  const CoordinateType *p3,
330  const CoordinateType *p4,
331  const CoordinateType *p5,
332  const CoordinateType *p6,
333  const CoordinateType *p7);
334 
336  {
337 public:
338  IdentifierType operator()(Array< IdentifierType > identifierArray) const
339  {
340  typedef IdentifierType IdType;
341 
342  IdType size = identifierArray.Size();
343 
344  std::sort( identifierArray.begin(), identifierArray.end() );
345 
346  IdType hash = 0;
347  IdType *id = &identifierArray[0];
348 
349  while ( size-- )
350  {
351  hash += *id++;
352  hash = ( hash << 7 ) | ( hash >> 25 ); // Rotate left by 7.
353  }
354 
355  return hash;
356  }
357  };
358 
360  {
361 public:
362  bool operator()(
363  Array< IdentifierType > identifierArray1,
364  Array< IdentifierType > identifierArray2
365  ) const
366  {
367  typedef IdentifierType IdType;
368 
369  IdType size1 = identifierArray1.Size();
370  IdType size2 = identifierArray2.Size();
371 
372  if ( size1 != size2 )
373  {
374  return false;
375  }
376 
377  std::sort( identifierArray1.begin(), identifierArray1.end() );
378  std::sort( identifierArray2.begin(), identifierArray2.end() );
379 
380  return ( identifierArray1 == identifierArray2 );
381  }
382  };
383 
384 protected:
387 
388  void GenerateData() {} // GenerateData is a no-op, since the entries
389  // are controlled manually
390 
391 private:
392  AutomaticTopologyMeshSource(const Self &); //purposely not implemented
393  void operator=(const Self &); //purposely not implemented
394 
395  typedef itksys::hash_map<
398  IdentifierArrayHashFunction,
400 
403  MeshPointer m_OutputMesh; // Retained for convenience.
404 };
405 } // end namespace itk
406 
407 #ifndef ITK_MANUAL_INSTANTIATION
408 #include "itkAutomaticTopologyMeshSource.hxx"
409 #endif
410 
411 #endif // __itkAutomaticTopologyMeshSource_h
412