109{
110 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
111 vtkInformation *outInfo = outputVector->GetInformationObject(0);
112
113 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
114 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
115
116 vtkPoints* inputPoints = input->GetPoints();
117
119 {
120 vtkErrorMacro("WarpVectors array name not specified.");
121 return 1;
122 }
123
125 {
126 vtkErrorMacro("CellEntityIds array name not specified.");
127 return 1;
128 }
129
130 if (!input->GetPointData()->GetArray(this->WarpVectorsArrayName))
131 {
132 vtkErrorMacro(<< "WarpVectors array with name specified does not exist!");
133 return 1;
134 }
135
137
139 {
141 {
142 vtkErrorMacro("LayerThickness array name not specified.");
143 return 1;
144 }
145
146 if (!input->GetPointData()->GetArray(this->LayerThicknessArrayName))
147 {
148 vtkErrorMacro(<< "LayerThickness array with name specified does not exist!");
149 return 1;
150 }
151
153 }
154
155 vtkIdType i;
156
157 vtkPoints* outputPoints = vtkPoints::New();
158 vtkPoints* warpedPoints = vtkPoints::New();
159
160 vtkCellArray* boundaryLayerCellArray = vtkCellArray::New();
161 vtkIdList* boundaryLayerCellTypes = vtkIdList::New();
162
163 vtkIntArray* cellEntityIdsArray = vtkIntArray::New();
165
166 vtkIntArray* innerSurfaceCellEntityIdsArray = vtkIntArray::New();
168
169 vtkUnsignedCharArray* checkArray = vtkUnsignedCharArray::New();
170 checkArray->SetNumberOfTuples(input->GetNumberOfCells());
171 checkArray->FillComponent(0,1);
172
173 vtkIdType numberOfInputPoints = inputPoints->GetNumberOfPoints();
174 vtkIdType numberOfInputCells = input->GetNumberOfCells();
175
176 int cellType;
177 cellType = input->GetCellType(0);
178 bool warpQuadratic = false;
179 if (cellType == VTK_QUADRATIC_TRIANGLE)
180 {
181 warpQuadratic = true;
182 }
183
184 vtkIdType numberOfLayerPoints = numberOfInputPoints;
185 if (warpQuadratic)
186 {
187 numberOfLayerPoints = 2 * numberOfInputPoints;
188 }
189
190 vtkIdType numberOfOutputPoints = numberOfInputPoints + numberOfLayerPoints * this->
NumberOfSubLayers;
191 outputPoints->SetNumberOfPoints(numberOfOutputPoints);
192
193 double point[3];
194 for (i=0; i<numberOfInputPoints; i++)
195 {
196 inputPoints->GetPoint(i,point);
197 outputPoints->SetPoint(i,point);
198 }
199
200 vtkIdType npts;
201 const vtkIdType *pts;
202 vtkIdType *surfacePts;
203
205 {
206 for (i=0; i<numberOfInputCells; i++)
207 {
208 input->GetCellPoints(i,npts,pts);
209 cellType = input->GetCellType(i);
210 surfacePts = new vtkIdType[npts];
211 switch(cellType)
212 {
213 case VTK_TRIANGLE:
214 boundaryLayerCellTypes->InsertNextId(VTK_TRIANGLE);
215 surfacePts[0] = pts[0];
216 surfacePts[1] = pts[1];
217 surfacePts[2] = pts[2];
218 break;
219 case VTK_QUAD:
220 boundaryLayerCellTypes->InsertNextId(VTK_QUAD);
221 surfacePts[0] = pts[0];
222 surfacePts[1] = pts[1];
223 surfacePts[2] = pts[2];
224 surfacePts[3] = pts[3];
225 break;
226 case VTK_QUADRATIC_TRIANGLE:
227 boundaryLayerCellTypes->InsertNextId(VTK_QUADRATIC_TRIANGLE);
228 surfacePts[0] = pts[0];
229 surfacePts[1] = pts[1];
230 surfacePts[2] = pts[2];
231 surfacePts[3] = pts[3];
232 surfacePts[4] = pts[4];
233 surfacePts[5] = pts[5];
234 break;
235 default:
236 vtkErrorMacro(<<"Unsupported surface element.");
237 return 1;
238 break;
239 }
240 boundaryLayerCellArray->InsertNextCell(npts,surfacePts);
242 delete[] surfacePts;
243 }
244 }
245
246 vtkIdList* edgePointIds = vtkIdList::New();
247 vtkIdList* edgeNeighborCellIds = vtkIdList::New();
248
252 int finalNumberOfSubsteps = this->
NumberOfSubsteps - initialNumberOfSubsteps - intermediateNumberOfSubsteps;
253
256
257 int iteration = 0;
259 if (tangled > 0)
260 {
261 std::cout << "untangle procedure.. " << tangled << " tangled cells" << std::endl;
262 }
263
264
265
266
267
268
269
271 int fewestTangled = tangled;
272 int roundsWithoutImprovement = 0;
273 while (tangled > 0 && iteration < maximumNumberOfIterations)
274 {
278 iteration += 1;
279 if (tangled == 0)
280 {
281 std::cout << "untangle iteration " << iteration << ": untangled, sweeping the rest" << std::endl;
284 }
285 std::cout << "untangle iteration " << iteration << ": " << tangled << " tangled cells" << std::endl;
286 if (tangled < fewestTangled)
287 {
288 fewestTangled = tangled;
289 roundsWithoutImprovement = 0;
290 }
292 {
293 std::cout << "untangle procedure stopped: " << tangled << " cells are still tangled after "
294 << roundsWithoutImprovement << " rounds without improvement" << std::endl;
295 break;
296 }
297 }
299
300 int k;
302 {
303 warpedPoints->Initialize();
304 this->
WarpPoints(inputPoints,warpedPoints,k,warpQuadratic);
305
306 for (i=0; i<numberOfLayerPoints; i++)
307 {
308 warpedPoints->GetPoint(i,point);
309 outputPoints->SetPoint(i + numberOfInputPoints + k*numberOfLayerPoints,point);
310 }
311
312 vtkIdType prismNPts, *prismPts;
313 vtkIdType quadNPts, *quadPts;
314 for (i=0; i<numberOfInputCells; i++)
315 {
316 input->GetCellPoints(i,npts,pts);
317 cellType = input->GetCellType(i);
318 if (cellType == VTK_TRIANGLE || cellType == VTK_QUAD)
319 {
320 prismNPts = npts * 2;
321 prismPts = new vtkIdType[prismNPts];
322 quadNPts = 4;
323 quadPts = new vtkIdType[quadNPts];
324 int j;
325 for (j=0; j<npts; j++)
326 {
327 prismPts[j] = pts[j] + k*numberOfLayerPoints;
328 }
329 for (j=0; j<npts; j++)
330 {
331 prismPts[j+npts] = pts[j] + (k+1)*numberOfLayerPoints;
332 }
333 boundaryLayerCellArray->InsertNextCell(prismNPts,prismPts);
335
336 if (cellType == VTK_TRIANGLE)
337 {
338 boundaryLayerCellTypes->InsertNextId(VTK_WEDGE);
339 }
340 else if (cellType == VTK_QUAD)
341 {
342 boundaryLayerCellTypes->InsertNextId(VTK_HEXAHEDRON);
343 }
344
346 {
347 for (j=0; j<npts; j++)
348 {
349 vtkIdType jnext = (j+1) % npts;
350 edgePointIds->Initialize();
351 edgePointIds->SetNumberOfIds(2);
352 edgePointIds->SetId(0,pts[j]);
353 edgePointIds->SetId(1,pts[jnext]);
354 input->GetCellNeighbors(i,edgePointIds,edgeNeighborCellIds);
355
356 if (edgeNeighborCellIds->GetNumberOfIds() > 0)
357 {
358 continue;
359 }
360
361 quadPts[0] = prismPts[j];
362 quadPts[1] = prismPts[jnext];
363 quadPts[2] = prismPts[jnext+npts];
364 quadPts[3] = prismPts[j+npts];
365
366 boundaryLayerCellArray->InsertNextCell(quadNPts,quadPts);
367 boundaryLayerCellTypes->InsertNextId(VTK_QUAD);
369 }
370 }
371
372 delete[] prismPts;
373 delete[] quadPts;
374 }
375 else if (cellType == VTK_QUADRATIC_TRIANGLE)
376 {
377 prismNPts = npts * 3 - 3;
378 prismPts = new vtkIdType[prismNPts];
379 quadNPts = 8;
380 quadPts = new vtkIdType[quadNPts];
381
382 boundaryLayerCellTypes->InsertNextId(VTK_QUADRATIC_WEDGE);
383
384 prismPts[0] = pts[0] + k*numberOfLayerPoints;
385 prismPts[1] = pts[1] + k*numberOfLayerPoints;
386 prismPts[2] = pts[2] + k*numberOfLayerPoints;
387
388 prismPts[3] = pts[0] + k*numberOfLayerPoints + numberOfLayerPoints;
389 prismPts[4] = pts[1] + k*numberOfLayerPoints + numberOfLayerPoints;
390 prismPts[5] = pts[2] + k*numberOfLayerPoints + numberOfLayerPoints;
391
392 prismPts[6] = pts[3] + k*numberOfLayerPoints;
393 prismPts[7] = pts[4] + k*numberOfLayerPoints;
394 prismPts[8] = pts[5] + k*numberOfLayerPoints;
395
396 prismPts[9] = pts[3] + k*numberOfLayerPoints + numberOfLayerPoints;
397 prismPts[10] = pts[4] + k*numberOfLayerPoints + numberOfLayerPoints;
398 prismPts[11] = pts[5] + k*numberOfLayerPoints + numberOfLayerPoints;
399
400 prismPts[12] = pts[0] + k*numberOfLayerPoints + numberOfLayerPoints/2;
401 prismPts[13] = pts[1] + k*numberOfLayerPoints + numberOfLayerPoints/2;
402 prismPts[14] = pts[2] + k*numberOfLayerPoints + numberOfLayerPoints/2;
403
404 boundaryLayerCellArray->InsertNextCell(prismNPts,prismPts);
406
408 {
409 for (int j=0; j<npts/2; j++)
410 {
411 vtkIdType jnext = (j+1) % npts;
412 edgePointIds->Initialize();
413 edgePointIds->SetNumberOfIds(2);
414 edgePointIds->SetId(0,pts[j]);
415 edgePointIds->SetId(1,pts[jnext]);
416 input->GetCellNeighbors(i,edgePointIds,edgeNeighborCellIds);
417
418 if (edgeNeighborCellIds->GetNumberOfIds() > 0)
419 {
420 continue;
421 }
422
423 quadPts[0] = prismPts[j];
424 quadPts[1] = prismPts[jnext];
425 quadPts[2] = prismPts[jnext+npts/2];
426 quadPts[3] = prismPts[j+npts/2];
427
428 quadPts[4] = prismPts[j+npts];
429 quadPts[5] = prismPts[jnext+2*npts];
430 quadPts[6] = prismPts[j+npts+npts/2];
431 quadPts[7] = prismPts[j+2*npts];
432
433 boundaryLayerCellArray->InsertNextCell(quadNPts,quadPts);
434 boundaryLayerCellTypes->InsertNextId(VTK_QUAD);
436 }
437 }
438
439 delete[] prismPts;
440 delete[] quadPts;
441 }
442 else
443 {
444 vtkErrorMacro(<<"Unsupported surface element.");
445 return 1;
446 }
447 }
448
450 {
452 {
453 for (i=0; i<numberOfInputCells; i++)
454 {
455 input->GetCellPoints(i,npts,pts);
456 cellType = input->GetCellType(i);
457 surfacePts = new vtkIdType[npts];
458 switch(cellType)
459 {
460 case VTK_TRIANGLE:
461 boundaryLayerCellTypes->InsertNextId(VTK_TRIANGLE);
462 surfacePts[0] = pts[0] + k*numberOfLayerPoints + numberOfLayerPoints;
463 surfacePts[1] = pts[1] + k*numberOfLayerPoints + numberOfLayerPoints;
464 surfacePts[2] = pts[2] + k*numberOfLayerPoints + numberOfLayerPoints;
465 break;
466 case VTK_QUAD:
467 boundaryLayerCellTypes->InsertNextId(VTK_QUAD);
468 surfacePts[0] = pts[0] + k*numberOfLayerPoints + numberOfLayerPoints;
469 surfacePts[1] = pts[1] + k*numberOfLayerPoints + numberOfLayerPoints;
470 surfacePts[2] = pts[2] + k*numberOfLayerPoints + numberOfLayerPoints;
471 surfacePts[3] = pts[3] + k*numberOfLayerPoints + numberOfLayerPoints;
472 break;
473 case VTK_QUADRATIC_TRIANGLE:
474 boundaryLayerCellTypes->InsertNextId(VTK_QUADRATIC_TRIANGLE);
475 surfacePts[0] = pts[0] + k*numberOfLayerPoints + numberOfLayerPoints;
476 surfacePts[1] = pts[1] + k*numberOfLayerPoints + numberOfLayerPoints;
477 surfacePts[2] = pts[2] + k*numberOfLayerPoints + numberOfLayerPoints;
478 surfacePts[3] = pts[3] + k*numberOfLayerPoints + numberOfLayerPoints;
479 surfacePts[4] = pts[4] + k*numberOfLayerPoints + numberOfLayerPoints;
480 surfacePts[5] = pts[5] + k*numberOfLayerPoints + numberOfLayerPoints;
481 break;
482 default:
483 vtkErrorMacro(<<"Unsupported surface element.");
484 return 1;
485 break;
486 }
487 boundaryLayerCellArray->InsertNextCell(npts,surfacePts);
489 delete[] surfacePts;
490 }
491 }
492 }
493 }
494
495 output->SetPoints(outputPoints);
496
497 int* boundaryLayerCellTypesInt = new int[boundaryLayerCellTypes->GetNumberOfIds()];
498 for (i=0; i<boundaryLayerCellTypes->GetNumberOfIds(); i++)
499 {
500 boundaryLayerCellTypesInt[i] = boundaryLayerCellTypes->GetId(i);
501 }
502
503 output->SetCells(boundaryLayerCellTypesInt,boundaryLayerCellArray);
504
505 delete[] boundaryLayerCellTypesInt;
506
507 output->GetCellData()->AddArray(cellEntityIdsArray);
508
510 {
513 }
514
517
518 vtkPoints* innerSurfacePoints = vtkPoints::New();
519 innerSurfacePoints->SetNumberOfPoints(numberOfInputPoints);
520 for (i=0; i<numberOfInputPoints; i++)
521 {
523 innerSurfacePoints->SetPoint(i,point);
524 }
525
526 this->
InnerSurface->GetPoints()->DeepCopy(innerSurfacePoints);
527 innerSurfaceCellEntityIdsArray->SetNumberOfTuples(this->
InnerSurface->GetNumberOfCells());
529 this->
InnerSurface->GetCellData()->AddArray(innerSurfaceCellEntityIdsArray);
530
531 edgePointIds->Delete();
532 edgeNeighborCellIds->Delete();
533
534 outputPoints->Delete();
535 warpedPoints->Delete();
536 boundaryLayerCellArray->Delete();
537 boundaryLayerCellTypes->Delete();
538 innerSurfacePoints->Delete();
539
540 cellEntityIdsArray->Delete();
541 innerSurfaceCellEntityIdsArray->Delete();
542 checkArray->Delete();
543
544 return 1;
545}
void WarpPoints(vtkPoints *inputPoints, vtkPoints *warpedPoints, int subLayerId, bool quadratic)
void LocalUntangle(vtkUnstructuredGrid *input, vtkUnsignedCharArray *checkArray, double alpha)
int CheckTangle(vtkUnstructuredGrid *input, vtkUnsignedCharArray *checkArray)
void BuildWarpVectors(vtkUnstructuredGrid *input)
void IncrementalWarpVectors(vtkUnstructuredGrid *input, int numberOfSubsteps, double relaxation)