File: itkQuadEdgeMeshToQuadEdgeMeshFilter.h

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 80,652 kB
  • sloc: cpp: 458,133; ansic: 196,223; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 430; csh: 220; perl: 193; xml: 20
file content (297 lines) | stat: -rw-r--r-- 11,312 bytes parent folder | download | duplicates (2)
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkQuadEdgeMeshToQuadEdgeMeshFilter.h
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  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 __itkQuadEdgeMeshToQuadEdgeMeshFilter_h
#define __itkQuadEdgeMeshToQuadEdgeMeshFilter_h

#include "itkMeshToMeshFilter.h"

namespace itk
{
/** \class QuadEdgeMeshToQuadEdgeMeshFilter
 *  \brief Duplicates the content of a Mesh.
 *
 * \author Alexandre Gouaillard, Leonardo Florez-Valencia, Eric Boix
 *
 * This implementation was contributed as a paper to the Insight Journal
 * http://insight-journal.org/midas/handle.php?handle=1926/306
 *
 */
template< typename TInputMesh, typename TOutputMesh >
class QuadEdgeMeshToQuadEdgeMeshFilter
  : public MeshToMeshFilter< TInputMesh, TOutputMesh >
{
public:
  /** Basic types. */
  typedef QuadEdgeMeshToQuadEdgeMeshFilter            Self;
  typedef MeshToMeshFilter< TInputMesh, TOutputMesh > Superclass;
  typedef SmartPointer< Self >                        Pointer;
  typedef SmartPointer< const Self >                  ConstPointer;

  /** Input types. */
  typedef TInputMesh                              InputMeshType;
  typedef typename InputMeshType::Pointer         InputMeshPointer;
  typedef typename InputMeshType::ConstPointer    InputMeshConstPointer;
  typedef typename InputMeshType::CoordRepType    InputCoordRepType;
  typedef typename InputMeshType::PointType       InputPointType;
  typedef typename InputMeshType::PointIdentifier InputPointIdentifier;
  typedef typename InputMeshType::QEPrimal        InputQEPrimal;
  typedef typename InputMeshType::VectorType      InputVectorType;

  typedef typename InputMeshType::PointDataContainer   InputPointDataContainer;
  typedef typename InputMeshType::CellDataContainer    InputCellDataContainer;

  typedef typename InputPointDataContainer::ConstPointer 
    InputPointDataContainerConstPointer; 
  typedef typename InputMeshType::PointsContainerConstIterator
    InputPointsContainerConstIterator;
  typedef typename InputMeshType::PointsContainerConstPointer
    InputPointsContainerConstPointer;
  typedef typename InputMeshType::CellsContainerConstIterator
    InputCellsContainerConstIterator;
  typedef typename InputMeshType::CellsContainerConstPointer
    InputCellsContainerConstPointer; 

  typedef typename InputMeshType::EdgeCellType    InputEdgeCellType;
  typedef typename InputMeshType::PolygonCellType InputPolygonCellType;
  typedef typename InputMeshType::PointIdList     InputPointIdList;
  typedef typename InputMeshType::CellTraits      InputCellTraits;
  typedef typename InputCellTraits::PointIdInternalIterator
                                                  InputPointsIdInternalIterator;

  typedef typename InputQEPrimal::IteratorGeom    InputQEIterator;

  /** Output types. */
  typedef TOutputMesh                               OutputMeshType;
  typedef typename OutputMeshType::Pointer          OutputMeshPointer;
  typedef typename OutputMeshType::ConstPointer     OutputMeshConstPointer;
  typedef typename OutputMeshType::CoordRepType     OutputCoordRepType;
  typedef typename OutputMeshType::PointType        OutputPointType;
  typedef typename OutputMeshType::PointIdentifier  OutputPointIdentifier;
  typedef typename OutputMeshType::QEPrimal         OutputQEPrimal;
  typedef typename OutputMeshType::VectorType       OutputVectorType;
  typedef typename OutputQEPrimal::IteratorGeom     OutputQEIterator;
  typedef typename OutputMeshType::PointsContainerIterator
      OutputPointsContainerIterator;
  typedef typename OutputMeshType::PointsContainerPointer
      OutputPointsContainerPointer;
  typedef typename OutputMeshType::PointsContainerConstPointer
      OutputPointsContainerConstPointer;

  typedef typename OutputMeshType::PointDataContainer  OutputPointDataContainer;
  typedef typename OutputMeshType::CellDataContainer   OutputCellDataContainer;

public:
  itkNewMacro( Self );
  itkTypeMacro( QuadEdgeMeshToQuadEdgeMeshFilter, MeshToMeshFilter );

protected:
  QuadEdgeMeshToQuadEdgeMeshFilter();
  virtual ~QuadEdgeMeshToQuadEdgeMeshFilter() { }

  virtual void CopyMeshToMesh(const TInputMesh * in, TOutputMesh * out);
  virtual void CopyInputMeshToOutputMesh();
  virtual void CopyInputMeshToOutputMeshGeometry();
  virtual void CopyInputMeshToOutputMeshPoints();
  virtual void CopyInputMeshToOutputMeshCells();
  virtual void CopyInputMeshToOutputMeshEdgeCells();
  virtual void CopyInputMeshToOutputMeshFieldData();
  virtual void CopyInputMeshToOutputMeshPointData();
  virtual void CopyInputMeshToOutputMeshCellData(); 

private:
  QuadEdgeMeshToQuadEdgeMeshFilter( const Self& ); // Not impl.
  void operator=( const Self& );  // Not impl.
};

//
// Helper functions that copy selected pieces of a Mesh.
// These functions should be templated here in order to 
// facilitate their reuse in multiple scenarios.
//

// ---------------------------------------------------------------------
template< class TInputMesh, class TOutputMesh >
void CopyMeshToMeshCellData( const TInputMesh * in, TOutputMesh * out )
{

  typedef typename TInputMesh::CellDataContainer         InputCellDataContainer;
  typedef typename TOutputMesh::CellDataContainer        OutputCellDataContainer;
  typedef typename InputCellDataContainer::ConstPointer  InputCellDataContainerConstPointer;
  typedef typename OutputCellDataContainer::Pointer      OutputCellDataContainerPointer;

  InputCellDataContainerConstPointer inputCellData = in->GetCellData();

  if( inputCellData.IsNull() )
    {
    // There is nothing to copy
    return;
    }

  OutputCellDataContainerPointer outputCellData = OutputCellDataContainer::New();
  outputCellData->Reserve( inputCellData->Size() );

  // Copy point data
  typedef typename InputCellDataContainer::ConstIterator  InputCellDataContainerConstIterator;
  InputCellDataContainerConstIterator inIt = inputCellData->Begin();
  while( inIt != inputCellData->End() )
    {
    outputCellData->SetElement( inIt.Index(), inIt.Value() );
    inIt++;
    } 

  out->SetCellData( outputCellData );
}


// ---------------------------------------------------------------------
template< class TInputMesh, class TOutputMesh >
void CopyMeshToMeshPointData( const TInputMesh * in, TOutputMesh * out )
{

  typedef typename TOutputMesh::PointDataContainer        OutputPointDataContainer;
  typedef typename OutputPointDataContainer::Pointer      OutputPointDataContainerPointer;
  typedef typename TInputMesh::PointDataContainer         InputPointDataContainer;

  const InputPointDataContainer * inputPointData = in->GetPointData();

  if( inputPointData == NULL )
    {
    // There is nothing to copy
    return;
    }

  OutputPointDataContainerPointer outputPointData = OutputPointDataContainer::New();
  outputPointData->Reserve( inputPointData->Size() );

  // Copy point data
  typedef typename InputPointDataContainer::ConstIterator  InputPointDataContainerConstIterator;
  InputPointDataContainerConstIterator inIt = inputPointData->Begin();
  while( inIt != inputPointData->End() )
    {
    outputPointData->SetElement( inIt.Index(), inIt.Value() );
    inIt++;
    } 

  out->SetPointData( outputPointData );
}


// ---------------------------------------------------------------------
template< class TInputMesh, class TOutputMesh >
void CopyMeshToMeshCells( const TInputMesh * in, TOutputMesh * out )
{
  // Copy cells
  typedef typename TInputMesh::CellsContainer           InputCellsContainer;
  typedef typename InputCellsContainer::ConstPointer    InputCellsContainerConstPointer;
  typedef typename InputCellsContainer::ConstIterator   InputCellsContainerConstIterator;
  typedef typename TInputMesh::PolygonCellType          InputPolygonCellType;
  typedef typename TInputMesh::PointIdList              InputPointIdList;
  typedef typename TInputMesh::CellTraits               InputCellTraits;
  typedef typename InputCellTraits::PointIdInternalIterator
                                                        InputPointsIdInternalIterator;

  out->SetCellsAllocationMethod( TOutputMesh::CellsAllocatedDynamicallyCellByCell );

  InputCellsContainerConstPointer inCells = in->GetCells();

  if( inCells )
    {
    InputCellsContainerConstIterator cIt = inCells->Begin();
    while( cIt != inCells->End() )
      {
      InputPolygonCellType * pe = dynamic_cast< InputPolygonCellType* >( cIt.Value());
      if( pe )
        {
        InputPointIdList points;
        InputPointsIdInternalIterator pit = pe->InternalPointIdsBegin();
        while( pit != pe->InternalPointIdsEnd( ) )
          {
          points.push_back( ( *pit ) );
          ++pit;
          }
        out->AddFaceWithSecurePointList( points, false );
        }
      cIt++;
      }
    }
}


// ---------------------------------------------------------------------
template< class TInputMesh, class TOutputMesh >
void CopyMeshToMeshEdgeCells( const TInputMesh * in, TOutputMesh * out )
{
  // Copy Edge Cells
  typedef typename TInputMesh::CellsContainer           InputCellsContainer;
  typedef typename InputCellsContainer::ConstPointer    InputCellsContainerConstPointer;
  typedef typename InputCellsContainer::ConstIterator   InputCellsContainerConstIterator;
  typedef typename TInputMesh::EdgeCellType             InputEdgeCellType;

  InputCellsContainerConstPointer inEdgeCells = in->GetEdgeCells();

  if( inEdgeCells )
    {
    InputCellsContainerConstIterator ecIt = inEdgeCells->Begin();
    while( ecIt != inEdgeCells->End() )
      {
      InputEdgeCellType* pe = dynamic_cast< InputEdgeCellType* >( ecIt.Value());
      if( pe )
        {
        out->AddEdgeWithSecurePointList( pe->GetQEGeom()->GetOrigin(),
                                         pe->GetQEGeom()->GetDestination() );
        }
      ecIt++;
      }
    }
}


// ---------------------------------------------------------------------
template< class TInputMesh, class TOutputMesh >
void CopyMeshToMeshPoints( const TInputMesh * in, TOutputMesh * out )
{
  // Copy points
  typedef typename TInputMesh::PointsContainer          InputPointsContainer;
  typedef typename InputPointsContainer::ConstPointer   InputPointsContainerConstPointer;
  typedef typename InputPointsContainer::ConstIterator  InputPointsContainerConstIterator;
  typedef typename TOutputMesh::PointType               OutputPointType;

  InputPointsContainerConstPointer inPoints = in->GetPoints();

  if( inPoints )
    {
    InputPointsContainerConstIterator inIt = inPoints->Begin();
    OutputPointType pOut;

    while( inIt != inPoints->End() )
      {
      pOut.CastFrom( inIt.Value() );
      out->SetPoint( inIt.Index(), pOut );
      inIt++;
      } 
    }
}


} // end namespace itk

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

#endif