File: itkTriangleMeshToSimplexMeshFilter.h

package info (click to toggle)
insighttoolkit 3.6.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 94,956 kB
  • ctags: 74,981
  • sloc: cpp: 355,621; ansic: 195,070; fortran: 28,713; python: 3,802; tcl: 1,996; sh: 1,175; java: 583; makefile: 415; csh: 184; perl: 175
file content (231 lines) | stat: -rw-r--r-- 7,658 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*=========================================================================

Program:   Insight Segmentation & Registration Toolkit
Module:    $RCSfile: itkTriangleMeshToSimplexMeshFilter.h,v $
Language:  C++
Date:      $Date: 2007-12-29 17:51:23 $
Version:   $Revision: 1.5 $

Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

This software is distributed WITHOUT ANY WARRANTY; without even 
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkTriangleMeshToSimplexMeshFilter_h
#define __itkTriangleMeshToSimplexMeshFilter_h

#include <itkMesh.h>
#include <itkLineCell.h>
#include <itkVertexCell.h>
#include <itkMapContainer.h>
#include "itkSimplexMesh.h"
#include "itkSimplexMeshGeometry.h"
#include "itkMeshToMeshFilter.h"
#include "itkVectorContainer.h"
#include "itkNumericTraits.h"

#include <itkPolygonCell.h>
namespace itk
{
/**
 * \class TriangleMeshToSimplexMeshFilter
 * \brief This filter converts a triangle mesh into a 2-simplex mesh.
 * 
 * The triangle cell centers build the points of the dual simplex mesh
 * each center is connected with the center of each neighboring triangle.
 * This creates the simplex structure. 
 *
 * Finally the neighbors of the points are reordered counter-clockwise
 * for geometry computation.
 *
 * \author Thomas Boettger. Division Medical and Biological Informatics, German Cancer Research Center, Heidelberg.
 * 
 */
template <class TInputMesh, class TOutputMesh>
class TriangleMeshToSimplexMeshFilter : public MeshToMeshFilter<TInputMesh, TOutputMesh>
{
public:
  /** Standard "Self" typedef. */
  typedef TriangleMeshToSimplexMeshFilter  Self;

  /** Standard "Superclass" typedef. */
  typedef MeshToMeshFilter<TInputMesh, TOutputMesh> Superclass;

  /** Smart pointer typedef support */
  typedef SmartPointer<Self>        Pointer;
  typedef SmartPointer<const Self>  ConstPointer;

  /** Method of creation through the object factory. */
  itkNewMacro(Self);

  /** Run-time type information (and related methods). */
  itkTypeMacro(TriangleMeshToSimplexMeshFilter,MeshToMeshFilter);

  typedef TInputMesh                     InputMeshType;
  typedef typename TInputMesh::Pointer   InputMeshPointer;
  typedef typename TInputMesh::PointType InputPointType;

  typedef typename TInputMesh::BoundaryAssignmentsContainerPointer InputBoundaryAssignmentsContainerPointer;

  typedef typename TInputMesh::PointsContainer    InputPointsContainer;
  typedef typename InputPointsContainer::Pointer  InputPointsContainerPointer;
  typedef typename InputPointsContainer::Iterator InputPointsContainerIterator;

  typedef typename TOutputMesh::Pointer                   OutputMeshPointer;
  typedef typename TOutputMesh::PointType                 OutputPointType;
  typedef typename TOutputMesh::PixelType                 OutputPixelType;
  typedef typename TOutputMesh::PointsContainer           OutputPointsContainer;
  typedef typename OutputPointsContainer::Pointer         OutputPointsContainerPointer;
  typedef typename TOutputMesh::PointsContainer::Iterator OutputPointsContainerIterator;

  typedef typename TInputMesh::BoundaryAssignmentIdentifier InputBoundnaryAssignmentIdentifier;

  typedef typename TInputMesh::CellType             InputCellType;
  typedef typename InputCellType::CellAutoPointer   InputCellAutoPointer;
  typedef typename TInputMesh::CellAutoPointer      CellAutoPointer;
  typedef          itk::LineCell<InputCellType>     LineType;
  typedef          itk::PolygonCell<InputCellType>  PolygonType;
  typedef          itk::TriangleCell<InputCellType> TriangleType;
  typedef          itk::VertexCell<InputCellType>   VertexType;

  typedef          std::pair<unsigned long,unsigned long> EdgeIdentifierType;
  typedef          std::set<unsigned long>                IndexSetType;

  typedef          itk::MapContainer<unsigned long, EdgeIdentifierType> EdgeNeighborListType;
  typedef          itk::MapContainer<EdgeIdentifierType, unsigned long> LineCellIndexType;

  typedef          itk::MapContainer<unsigned long, IndexSetType>       VertexNeighborListType;
    typedef          itk::MapContainer<EdgeIdentifierType,unsigned long>  EdgeMapType;
  typedef typename EdgeMapType::Pointer                                 EdgeMapPointer;

  typedef          itk::VectorContainer<unsigned long,unsigned long>    IdVectorType;
  typedef typename IdVectorType::Pointer                                IdVectorPointer;

  typedef typename TOutputMesh::CellType             OutputCellType;
  typedef typename TOutputMesh::CellAutoPointer      OutputCellAutoPointer;
  typedef          itk::LineCell<OutputCellType>     OutputLineType;
  typedef          itk::PolygonCell<OutputCellType>  OutputPolygonType;

protected:

  TriangleMeshToSimplexMeshFilter();
  ~TriangleMeshToSimplexMeshFilter();
  TriangleMeshToSimplexMeshFilter(const Self&) {}

  void operator=(const Self&) {}

  void PrintSelf(std::ostream& os, Indent indent) const;

  /** 
   * Override from ProcessObject
   */
  virtual void GenerateData();

  /** 
   * Initializes all necessary datastructures
   */
  void Initialize();

  /** 
   * Method inserts the new computed simplex points into the output mesh
   */
  void CreateSimplexPoints();

  /** 
   * Method creates a new edge, which from the centers of 
   * two neighboring triangles of the input mesh over the 
   * edge the both triangles have in common.
   */
  void CreateEdgeForTrianglePair( unsigned long pointIndex, unsigned long boundaryId);

  /** 
   * Constructs the neighborhood relations for all simplex mesh points
   * It also reorders the neighbors for easy normals computation
   */
  void CreateSimplexNeighbors();

  /**
   * This method creates all the cells of the dual simplex mesh
   */
  void CreateCells();

  /**
   * \brief add edge cells to the input mesh
   */
  void CreateNewEdge(unsigned long currentCellId, unsigned int featureId, 
    unsigned long startPointId, unsigned long endPointId);

  /**
   *  Computes the center of a face
   */
  InputPointType ComputeFaceCenter(unsigned long faceId);

  /**
   * \brief stores all faces (triangles) of the input mesh
   */
  IndexSetType* m_FaceSet;

  /**
   * \brief stores all edges of the input mesh. 
   * 
   * the key is the index of the edge cell, and the element is the 
   * index pair of the two points of the edge.
   */
  EdgeMapPointer m_Edges;

  /**
   * \brief stores the two neighboring cells (faces) of an edge
   */
  EdgeNeighborListType::Pointer m_EdgeNeighborList;

  /**
   * \brief stores all edges starting from a vertex
   */
  VertexNeighborListType::Pointer m_VertexNeighborList;

  /**
   * stores line indices for conversion algorithm
   */
  LineCellIndexType::Pointer m_LineCellIndices;

  /**
   * offset for ids of new simplex polygon cells
   */
  unsigned long m_CellIdxOffset;

  /**
   * offset for point ids
   */
  unsigned long m_IdOffset;

  /**
   * offset for edge cell ids
   */
  unsigned long m_EdgeCellId;

  /**
   * stores algorithmic data
   */
  IdVectorPointer m_HandledEdgeIds;

  /** 
   * autopointer definition for creation of new cells in the input mesh
   */
  InputCellAutoPointer m_NewInputMeshCellPointer;

  /** 
   * autopointer definition for creation of new simplex cells
   */
  OutputCellAutoPointer  m_NewSimplexCellPointer;
};

} //end of namespace

#ifndef ITK_MANUAL_INSTANTIATION
#include "itkTriangleMeshToSimplexMeshFilter.txx"
#endif

#endif