File: itkMeshToMeshFilter.txx

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 80,672 kB
  • ctags: 85,253
  • sloc: cpp: 458,133; ansic: 196,222; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 428; csh: 220; perl: 193; xml: 20
file content (273 lines) | stat: -rw-r--r-- 8,029 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
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkMeshToMeshFilter.txx
  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.

  Portions of this code are covered under the VTK copyright.
  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.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 __itkMeshToMeshFilter_txx
#define __itkMeshToMeshFilter_txx

#include "itkMeshToMeshFilter.h"


namespace itk
{
  
/**
 *
 */
template <class TInputMesh, class TOutputMesh>
MeshToMeshFilter<TInputMesh,TOutputMesh>
::MeshToMeshFilter()
{
  // Modify superclass default values, can be overridden by subclasses
  this->SetNumberOfRequiredInputs(1);

}


/**
 *
 */
template <class TInputMesh, class TOutputMesh>
void 
MeshToMeshFilter<TInputMesh,TOutputMesh>
::SetInput(const TInputMesh *input)
{
  // Process object is not const-correct so the const_cast is required here
  this->ProcessObject::SetNthInput(0,
                                   const_cast< TInputMesh * >( input ) );
}


/**
 *
 */
template <class TInputMesh, class TOutputMesh>
const typename MeshToMeshFilter<TInputMesh,TOutputMesh>::InputMeshType *
MeshToMeshFilter<TInputMesh,TOutputMesh>
::GetInput() const
{
  if (this->GetNumberOfInputs() < 1)
    {
    return 0;
    }
  
  return static_cast< const TInputMesh * >
    (this->ProcessObject::GetInput(0));
}

  
/**
 *
 */
template <class TInputMesh, class TOutputMesh>
const typename MeshToMeshFilter<TInputMesh,TOutputMesh>::InputMeshType *
MeshToMeshFilter<TInputMesh,TOutputMesh>
::GetInput(unsigned int idx) const
{
  return dynamic_cast<const TInputMesh*>
    (this->ProcessObject::GetInput(idx));
}

 
template <class TInputMesh, class TOutputMesh>
void 
MeshToMeshFilter<TInputMesh,TOutputMesh>
::CopyInputMeshToOutputMeshPoints(void) 
{
  const InputMeshType * inputMesh   =  this->GetInput();
  OutputMeshPointer    outputMesh   =  this->GetOutput();

  typedef typename TOutputMesh::PointsContainer OutputPointsContainer;
  typedef typename TInputMesh::PointsContainer  InputPointsContainer;

  typename OutputPointsContainer::Pointer outputPoints = OutputPointsContainer::New();
  const InputPointsContainer * inputPoints = inputMesh->GetPoints();

  if( inputPoints )
    {
    outputPoints->Reserve( inputPoints->Size() );

    typename InputPointsContainer::ConstIterator inputItr = inputPoints->Begin();
    typename InputPointsContainer::ConstIterator inputEnd = inputPoints->End();

    typename OutputPointsContainer::Iterator outputItr = outputPoints->Begin();

    while( inputItr != inputEnd )
      {
      outputItr.Value() = inputItr.Value();
      ++inputItr;
      ++outputItr;
      }

    outputMesh->SetPoints( outputPoints );
    }
}


template <class TInputMesh, class TOutputMesh>
void 
MeshToMeshFilter<TInputMesh,TOutputMesh>
::CopyInputMeshToOutputMeshPointData(void) 
{
  const InputMeshType * inputMesh   =  this->GetInput();
  OutputMeshPointer    outputMesh   =  this->GetOutput();

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

  typename OutputPointDataContainer::Pointer outputPointData = OutputPointDataContainer::New();
  const InputPointDataContainer * inputPointData = inputMesh->GetPointData();

  if( inputPointData )
    {
    outputPointData->Reserve( inputPointData->Size() );

    typename InputPointDataContainer::ConstIterator inputItr = inputPointData->Begin();
    typename InputPointDataContainer::ConstIterator inputEnd = inputPointData->End();

    typename OutputPointDataContainer::Iterator outputItr = outputPointData->Begin();

    while( inputItr != inputEnd )
      {
      outputItr.Value() = inputItr.Value();
      ++inputItr;
      ++outputItr;
      }

    outputMesh->SetPointData( outputPointData );
    }
}

 
template <class TInputMesh, class TOutputMesh>
void 
MeshToMeshFilter<TInputMesh,TOutputMesh>
::CopyInputMeshToOutputMeshCellLinks(void) 
{
  const InputMeshType * inputMesh   =  this->GetInput();
  OutputMeshPointer    outputMesh   =  this->GetOutput();

  typedef typename TOutputMesh::CellLinksContainer OutputCellLinksContainer;
  typedef typename TInputMesh::CellLinksContainer  InputCellLinksContainer;

  typename OutputCellLinksContainer::Pointer outputCellLinks = OutputCellLinksContainer::New();
  const InputCellLinksContainer * inputCellLinks = inputMesh->GetCellLinks();

  if( inputCellLinks )
    {
    outputCellLinks->Reserve( inputCellLinks->Size() );

    typename InputCellLinksContainer::ConstIterator inputItr = inputCellLinks->Begin();
    typename InputCellLinksContainer::ConstIterator inputEnd = inputCellLinks->End();

    typename OutputCellLinksContainer::Iterator outputItr = outputCellLinks->Begin();

    while( inputItr != inputEnd )
      {
      outputItr.Value() = inputItr.Value();
      ++inputItr;
      ++outputItr;
      }

    outputMesh->SetCellLinks( outputCellLinks );
    }
}

 
template <class TInputMesh, class TOutputMesh>
void 
MeshToMeshFilter<TInputMesh,TOutputMesh>
::CopyInputMeshToOutputMeshCells(void) 
{
  const InputMeshType * inputMesh   =  this->GetInput();
  OutputMeshPointer    outputMesh   =  this->GetOutput();

  typedef typename TOutputMesh::CellsContainer   OutputCellsContainer;
  typedef typename TInputMesh::CellsContainer    InputCellsContainer;
  typedef typename TOutputMesh::CellAutoPointer  CellAutoPointer;

  outputMesh->SetCellsAllocationMethod( OutputMeshType::CellsAllocatedDynamicallyCellByCell );

  typename OutputCellsContainer::Pointer outputCells = OutputCellsContainer::New();
  const InputCellsContainer * inputCells = inputMesh->GetCells();

  if( inputCells )
    {
    outputCells->Reserve( inputCells->Size() );

    typename InputCellsContainer::ConstIterator inputItr = inputCells->Begin();
    typename InputCellsContainer::ConstIterator inputEnd = inputCells->End();

    typename OutputCellsContainer::Iterator outputItr = outputCells->Begin();

    CellAutoPointer clone;

    while( inputItr != inputEnd )
      {
//      outputItr.Value() = inputItr.Value();
      // BUG: FIXME: Here we are copying a pointer, which is a mistake. What we should do is to clone the cell.
      inputItr.Value()->MakeCopy( clone );
      outputItr.Value() = clone.ReleaseOwnership();

      ++inputItr;
      ++outputItr;
      }

    outputMesh->SetCells( outputCells );
    }
}

 
template <class TInputMesh, class TOutputMesh>
void 
MeshToMeshFilter<TInputMesh,TOutputMesh>
::CopyInputMeshToOutputMeshCellData(void) 
{
  const InputMeshType * inputMesh   =  this->GetInput();
  OutputMeshPointer    outputMesh   =  this->GetOutput();

  typedef typename TOutputMesh::CellDataContainer OutputCellDataContainer;
  typedef typename TInputMesh::CellDataContainer  InputCellDataContainer;

  typename OutputCellDataContainer::Pointer outputCellData = OutputCellDataContainer::New();
  const InputCellDataContainer * inputCellData = inputMesh->GetCellData();

  if( inputCellData )
    {
    outputCellData->Reserve( inputCellData->Size() );

    typename InputCellDataContainer::ConstIterator inputItr = inputCellData->Begin();
    typename InputCellDataContainer::ConstIterator inputEnd = inputCellData->End();

    typename OutputCellDataContainer::Iterator outputItr = outputCellData->Begin();

    while( inputItr != inputEnd )
      {
      outputItr.Value() = inputItr.Value();
      ++inputItr;
      ++outputItr;
      }

    outputMesh->SetCellData( outputCellData );
    }
}


} // end namespace itk

#endif