114{
115 vtkPointSet *input = static_cast<vtkPointSet*>(dataSetInput);
116 vtkIdType numCells = input->GetNumberOfCells();
117 vtkGenericCell *cell;
118 vtkIdType newCellId, j;
119 int k;
120 vtkCellData *inCD=input->GetCellData();
121 vtkCellData *outCD=output->GetCellData();
122 vtkPoints *cellPts;
123 vtkIdList *cellPtIds;
124 vtkIdType ptId, numTets, ncells;
125 int numPts, type;
126 int numSimplices, dim;
127 vtkIdType pts[4];
128 double x[3];
129
130 if (numCells == 0)
131 {
132 return;
133 }
134
135
136 vtkUnsignedCharArray* cellTypes = dataSetInput->GetCellTypesArray();
137 if (cellTypes)
138 {
139 int allsimplices = 1;
140 for (vtkIdType cellId = 0; cellId < cellTypes->GetSize() && allsimplices; cellId++)
141 {
142 switch (cellTypes->GetValue(cellId))
143 {
144 case VTK_TETRA:
145 break;
146 case VTK_VERTEX:
147 case VTK_LINE:
148 case VTK_TRIANGLE:
150 {
151 allsimplices = 0;
152 }
153 break;
154 default:
155 allsimplices = 0;
156 break;
157 }
158 }
159 if (allsimplices)
160 {
161 output->ShallowCopy(input);
162 return;
163 }
164 }
165
166 cell = vtkGenericCell::New();
167 cellPts = vtkPoints::New();
168 cellPtIds = vtkIdList::New();
169
170
171 vtkCellData *tempCD = vtkCellData::New();
172 tempCD->ShallowCopy(inCD);
173 tempCD->SetActiveGlobalIds(NULL);
174
175 outCD->CopyAllocate(tempCD, input->GetNumberOfCells()*5);
176 output->Allocate(input->GetNumberOfCells()*5);
177
178
179 output->SetPoints(input->GetPoints());
180 output->GetPointData()->PassData(input->GetPointData());
181
182 for (vtkIdType cellId=0; cellId < numCells; cellId++)
183 {
184 input->GetCell(cellId, cell);
185 dim = cell->GetCellDimension();
186
187 if ( dim != 3 )
188 {
189 continue;
190 }
191
192 numPts = cell->GetNumberOfPoints();
193 double *p, *pPtr=cell->GetParametricCoords();
194 this->
Triangulator->InitTriangulation(0.0,1.0, 0.0,1.0, 0.0,1.0, numPts);
195 for (p=pPtr, j=0; j<numPts; j++, p+=3)
196 {
197 ptId = cell->PointIds->GetId(j);
198 cell->Points->GetPoint(j, x);
200 }
201 if ( cell->IsPrimaryCell() )
202 {
203 int numEdges=cell->GetNumberOfEdges();
204 this->
Triangulator->TemplateTriangulate(cell->GetCellType(),
205 numPts,numEdges);
206 }
207 else
208 {
210 }
211
212 ncells = output->GetNumberOfCells();
214
215 for (j=0; j < numTets; j++)
216 {
217 outCD->CopyData(tempCD, cellId, ncells+j);
218 }
219 }
220
222 {
223 output->BuildLinks();
224
225 for (vtkIdType cellId=0; cellId < numCells; cellId++)
226 {
227 input->GetCell(cellId, cell);
228 dim = cell->GetCellDimension();
229
230 if (dim != 2)
231 {
232 continue;
233 }
234
235 dim++;
236
237 if (cell->GetCellType() == VTK_QUAD)
238 {
240 }
241 else
242 {
243 cell->Triangulate(0, cellPtIds, cellPts);
244 }
245
246 numPts = cellPtIds->GetNumberOfIds();
247
248 numSimplices = numPts / dim;
249 type = 0;
250 switch (dim)
251 {
252 case 1:
253 type = VTK_VERTEX; break;
254 case 2:
255 type = VTK_LINE; break;
256 case 3:
257 type = VTK_TRIANGLE; break;
258 }
259
260 for ( j=0; j < numSimplices; j++ )
261 {
262 for (k=0; k<dim; k++)
263 {
264 pts[k] = cellPtIds->GetId(dim*j+k);
265 }
266 newCellId = output->InsertNextCell(type, dim, pts);
267 outCD->CopyData(tempCD, cellId, newCellId);
268 }
269 }
270
271
272 }
273
274 output->Squeeze();
275
276 tempCD->Delete();
277
278 cellPts->Delete();
279 cellPtIds->Delete();
280 cell->Delete();
281}
int TriangulateQuad(vtkUnstructuredGrid *output, vtkIdList *quadPtIds, vtkIdList *ptIds)