-
Notifications
You must be signed in to change notification settings - Fork 5
/
itkTriangleCellSubdivisionQuadEdgeMeshFilter.hxx
295 lines (261 loc) · 10.1 KB
/
itkTriangleCellSubdivisionQuadEdgeMeshFilter.hxx
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
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkTriangleCellSubdivisionQuadEdgeMeshFilter_hxx
#define itkTriangleCellSubdivisionQuadEdgeMeshFilter_hxx
namespace itk
{
template <typename TInputMesh, typename TOutputMesh>
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::TriangleCellSubdivisionQuadEdgeMeshFilter()
{
this->m_Uniform = true;
}
template <typename TInputMesh, typename TOutputMesh>
void
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::SetCellsToBeSubdivided(
const SubdivisionCellContainer & cellIdList)
{
this->m_CellsToBeSubdivided = cellIdList;
this->Modified();
}
template <typename TInputMesh, typename TOutputMesh>
void
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::AddSubdividedCellId(OutputCellIdentifier cellId)
{
this->m_CellsToBeSubdivided.push_back(cellId);
this->Modified();
}
template <typename TInputMesh, typename TOutputMesh>
void
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::GenerateOutputPoints()
{
this->CopyInputMeshToOutputMeshPoints();
this->m_EdgesPointIdentifier->Initialize();
this->m_Uniform = this->m_CellsToBeSubdivided.empty();
const InputCellsContainer * cells = this->GetInput()->GetCells();
if (this->m_Uniform)
{
InputCellsContainerConstIterator cellIt = cells->Begin();
while (cellIt != cells->End())
{
this->AddNewCellPoints(cellIt->Value());
++cellIt;
}
}
else
{
SubdivisionCellContainerConstIterator it = this->m_CellsToBeSubdivided.begin();
SubdivisionCellContainerConstIterator end = this->m_CellsToBeSubdivided.end();
while (it != end)
{
InputCellType * cell = cells->GetElement(static_cast<InputCellIdentifier>(*it));
if (cell)
{
this->AddNewCellPoints(cell);
}
++it;
}
}
}
template <typename TInputMesh, typename TOutputMesh>
void
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::GenerateOutputCells()
{
InputMeshConstPointer input = this->GetInput();
OutputMeshPointer output = this->GetOutput();
this->m_CellsToBeSubdivided.clear();
const InputCellsContainer * cells = input->GetCells();
InputCellsContainerConstIterator cellIt = cells->Begin();
while (cellIt != cells->End())
{
InputCellType * cell = cellIt->Value();
if (!cell || cell->GetType() != CellGeometryEnum::POLYGON_CELL || cell->GetNumberOfPoints() != 3)
{
continue;
}
InputPointIdentifier inputPointIdArray[3];
OutputPointIdentifier trianglePointIds[3];
OutputPointIdentifier edgePointIds[3];
InputPointIdIterator it = cell->PointIdsBegin();
unsigned int n = 0;
while (it != cell->PointIdsEnd())
{
inputPointIdArray[n] = *it;
trianglePointIds[n] = static_cast<OutputPointIdentifier>(inputPointIdArray[n]);
++it;
++n;
}
unsigned int splitEdges[3];
n = 0;
InputQEType * edge;
for (unsigned int ii = 0; ii < 3; ++ii)
{
unsigned int jj = (ii + 1) % 3;
edge = input->FindEdge(inputPointIdArray[ii], inputPointIdArray[jj]);
if (this->m_EdgesPointIdentifier->IndexExists(edge))
{
edgePointIds[ii] = this->m_EdgesPointIdentifier->GetElement(edge);
splitEdges[n] = ii;
++n;
}
}
if (n == 0)
{
// this face has no subdivided face as neighbor, copy it
const auto qeprimal = output->AddFaceTriangle(trianglePointIds[0], trianglePointIds[1], trianglePointIds[2]);
this->PassCellData(cellIt.Index(), qeprimal);
}
else if (n == 1)
{
SplitTriangleFromOneEdge(output, trianglePointIds, edgePointIds, splitEdges, cellIt.Index());
}
else if (n == 2)
{
SplitTriangleFromTwoEdges(output, trianglePointIds, edgePointIds, splitEdges, cellIt.Index());
}
else if (n == 3)
{
// this face was not supposed to be subdivided but all neighbors are
SplitTriangleFromThreeEdges(output, trianglePointIds, edgePointIds, cellIt.Index());
}
++cellIt;
}
}
template <typename TInputMesh, typename TOutputMesh>
void
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::SplitTriangleFromOneEdge(
OutputMeshType * output,
const OutputPointIdentifier * trianglePointIds,
const OutputPointIdentifier * edgePointIds,
const unsigned int * splitEdges,
const InputCellIdentifier id)
{
unsigned int ii = splitEdges[0];
unsigned int jj = (ii + 1) % 3;
unsigned int kk = (ii + 2) % 3;
const auto qeprimal0 = output->AddFaceTriangle(edgePointIds[ii], trianglePointIds[jj], trianglePointIds[kk]);
this->PassCellData(id, qeprimal0);
const auto qeprimal1 = output->AddFaceTriangle(edgePointIds[ii], trianglePointIds[kk], trianglePointIds[ii]);
this->PassCellData(id, qeprimal1);
}
template <typename TInputMesh, typename TOutputMesh>
void
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::SplitTriangleFromTwoEdges(
OutputMeshType * output,
const OutputPointIdentifier * trianglePointIds,
const OutputPointIdentifier * edgePointIds,
const unsigned int * splitEdges,
const InputCellIdentifier id)
{
unsigned int ii = splitEdges[0];
unsigned int jj = splitEdges[1];
if (ii == 0 && jj == 1)
{
// ii = 0, jj = 1
const auto qeprimal0 = output->AddFaceTriangle(trianglePointIds[2], trianglePointIds[0], edgePointIds[0]);
this->PassCellData(id, qeprimal0);
const auto qeprimal1 = output->AddFaceTriangle(trianglePointIds[2], edgePointIds[0], edgePointIds[1]);
this->PassCellData(id, qeprimal1);
const auto qeprimal2 = output->AddFaceTriangle(edgePointIds[0], trianglePointIds[1], edgePointIds[1]);
this->PassCellData(id, qeprimal2);
}
else if (ii == 0 && jj == 2)
{
// ii = 0, jj = 2
const auto qeprimal0 = output->AddFaceTriangle(trianglePointIds[1], trianglePointIds[2], edgePointIds[0]);
this->PassCellData(id, qeprimal0);
const auto qeprimal1 = output->AddFaceTriangle(trianglePointIds[2], edgePointIds[2], edgePointIds[0]);
this->PassCellData(id, qeprimal1);
const auto qeprimal2 = output->AddFaceTriangle(edgePointIds[2], trianglePointIds[0], edgePointIds[0]);
this->PassCellData(id, qeprimal2);
}
else if (ii == 1 && jj == 2)
{
// ii = 1, jj = 2
const auto qeprimal0 = output->AddFaceTriangle(trianglePointIds[0], trianglePointIds[1], edgePointIds[1]);
this->PassCellData(id, qeprimal0);
const auto qeprimal1 = output->AddFaceTriangle(trianglePointIds[0], edgePointIds[1], edgePointIds[2]);
this->PassCellData(id, qeprimal1);
const auto qeprimal2 = output->AddFaceTriangle(edgePointIds[1], trianglePointIds[2], edgePointIds[2]);
this->PassCellData(id, qeprimal2);
}
}
template <typename TInputMesh, typename TOutputMesh>
void
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::SplitTriangleFromThreeEdges(
OutputMeshType * output,
const OutputPointIdentifier * trianglePointIds,
const OutputPointIdentifier * edgePointIds,
const InputCellIdentifier id)
{
// this face was not supposed to be subdivided but all neighbors are
if (this->m_Uniform)
{
const auto qeprimal0 = output->AddFaceTriangle(trianglePointIds[0], edgePointIds[0], edgePointIds[2]);
this->PassCellData(id, qeprimal0);
const auto qeprimal1 = output->AddFaceTriangle(edgePointIds[0], trianglePointIds[1], edgePointIds[1]);
this->PassCellData(id, qeprimal1);
const auto qeprimal2 = output->AddFaceTriangle(edgePointIds[1], trianglePointIds[2], edgePointIds[2]);
this->PassCellData(id, qeprimal2);
const auto qeprimal3 = output->AddFaceTriangle(edgePointIds[0], edgePointIds[1], edgePointIds[2]);
this->PassCellData(id, qeprimal3);
}
else
{
OutputQEType * newTriangleEdge = output->AddFaceTriangle(trianglePointIds[0], edgePointIds[0], edgePointIds[2]);
this->PassCellData(id, newTriangleEdge);
this->m_CellsToBeSubdivided.push_back(newTriangleEdge->GetLeft());
newTriangleEdge = output->AddFaceTriangle(edgePointIds[0], trianglePointIds[1], edgePointIds[1]);
this->PassCellData(id, newTriangleEdge);
this->m_CellsToBeSubdivided.push_back(newTriangleEdge->GetLeft());
newTriangleEdge = output->AddFaceTriangle(edgePointIds[1], trianglePointIds[2], edgePointIds[2]);
this->PassCellData(id, newTriangleEdge);
this->m_CellsToBeSubdivided.push_back(newTriangleEdge->GetLeft());
newTriangleEdge = output->AddFaceTriangle(edgePointIds[0], edgePointIds[1], edgePointIds[2]);
this->PassCellData(id, newTriangleEdge);
this->m_CellsToBeSubdivided.push_back(newTriangleEdge->GetLeft());
}
}
template <typename TInputMesh, typename TOutputMesh>
void
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::PassCellData(const InputCellIdentifier inputId,
const OutputQEType * outputEdge)
{
if (nullptr == outputEdge)
{
return;
}
if (nullptr == this->GetInput()->GetCellData())
{
return;
}
if (!this->GetInput()->GetCellData()->IndexExists(inputId))
{
return;
}
const auto data = this->GetInput()->GetCellData()->ElementAt(inputId);
this->GetOutput()->SetCellData(outputEdge->GetLeft(), data);
}
template <typename TInputMesh, typename TOutputMesh>
void
TriangleCellSubdivisionQuadEdgeMeshFilter<TInputMesh, TOutputMesh>::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Is Uniform Subdivision: " << m_Uniform << std::endl;
}
} // namespace itk
#endif