76 vtkInformation *vtkNotUsed(request),
77 vtkInformationVector **inputVector,
78 vtkInformationVector *outputVector)
80 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
81 vtkInformation *outInfo = outputVector->GetInformationObject(0);
83 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
84 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
86 vtkIntArray* cellEntityIdsArray = vtkIntArray::New();
91 if (input->GetCellData()->GetArray(this->CellEntityIdsArrayName) == NULL)
93 vtkErrorMacro(<<
"Error: CellEntityIdsArray with name specified does not exist");
96 cellEntityIdsArray->DeepCopy(input->GetCellData()->GetArray(this->CellEntityIdsArrayName));
100 vtkPoints* outputPoints = vtkPoints::New();
102 int numberOfInputPoints = input->GetNumberOfPoints();
104 vtkEdgeTable* edgeTable = vtkEdgeTable::New();
105 edgeTable->InitEdgeInsertion(numberOfInputPoints,1);
107 vtkEdgeTable* faceTable = vtkEdgeTable::New();
108 faceTable->InitEdgeInsertion(numberOfInputPoints,1);
110 vtkPointData* inputPointData = input->GetPointData();
111 vtkPointData* outputPointData = output->GetPointData();
112 outputPointData->InterpolateAllocate(inputPointData,5*numberOfInputPoints);
114 vtkCellData* inputCellData = input->GetCellData();
115 vtkCellData* outputCellData = output->GetCellData();
116 outputCellData->CopyAllocate(inputCellData,numberOfInputPoints);
119 for (i=0; i<numberOfInputPoints; i++)
121 outputPoints->InsertNextPoint(input->GetPoint(i));
122 outputPointData->CopyData(inputPointData,i,i);
125 vtkGenericCell* cell = vtkGenericCell::New();
127 vtkIdTypeArray* tetraIds = vtkIdTypeArray::New();
128 input->GetIdsOfCellsOfType(VTK_TETRA,tetraIds);
130 int numberOfInputTetras = tetraIds->GetNumberOfTuples();
132 vtkIdTypeArray* triangleIds = vtkIdTypeArray::New();
133 input->GetIdsOfCellsOfType(VTK_TRIANGLE,triangleIds);
135 int numberOfInputTriangles = triangleIds->GetNumberOfTuples();
137 vtkIdTypeArray* wedgeIds = vtkIdTypeArray::New();
138 input->GetIdsOfCellsOfType(VTK_WEDGE,wedgeIds);
140 int numberOfInputWedges = wedgeIds->GetNumberOfTuples();
142 vtkIdTypeArray* hexahedraIds = vtkIdTypeArray::New();
143 input->GetIdsOfCellsOfType(VTK_HEXAHEDRON,hexahedraIds);
145 int numberOfInputHexahedra = hexahedraIds->GetNumberOfTuples();
147 vtkIdTypeArray* quadIds = vtkIdTypeArray::New();
148 input->GetIdsOfCellsOfType(VTK_QUAD,quadIds);
150 int numberOfInputQuads = quadIds->GetNumberOfTuples();
152 int numberOfInputCells = numberOfInputTetras + numberOfInputTriangles + numberOfInputWedges + numberOfInputHexahedra + numberOfInputQuads;
154 output->SetPoints(outputPoints);
155 output->Allocate(numberOfInputCells);
157 int numberOfCells = input->GetNumberOfCells();
158 vtkIdList* inputToOutputCellIds = vtkIdList::New();
159 inputToOutputCellIds->SetNumberOfIds(numberOfInputCells);
161 for (i=0; i<numberOfCells; i++)
163 inputToOutputCellIds->SetId(i,-1);
167 double point0[3], point1[3], point2[3], point3[3], point4[3], point5[3], point6[3], point7[3];
168 vtkIdType pointId0, pointId1, pointId2, pointId3, pointId4, pointId5, pointId6, pointId7;
170 vtkIdType edgePointId01, edgePointId02, edgePointId03, edgePointId12, edgePointId13, edgePointId23;
171 vtkIdType edgePointId14, edgePointId34, edgePointId45, edgePointId35, edgePointId25, edgePointId37;
172 vtkIdType edgePointId56, edgePointId67, edgePointId74, edgePointId04, edgePointId15, edgePointId26;
173 vtkIdType facePointId0143, facePointId1254, facePointId2035;
174 vtkIdType facePointId3047, facePointId1265, facePointId0154, facePointId2376, facePointId0123, facePointId4567;
175 vtkIdType midVolumePoint;
176 facePointId0143 = facePointId1254 = facePointId2035 = -1;
177 facePointId3047 = facePointId1265 = facePointId0154 = facePointId2376 = facePointId0123 = facePointId4567 = -1;
179 vtkIdType neighborCellId;
182 double weightsVolume[8];
183 weights[0] = weights[1] = weights[2] = weights[3] = 0.25;
184 weightsVolume[0] = weightsVolume[1] = weightsVolume[2] = weightsVolume[3] = weightsVolume[4] = weightsVolume[5] = weightsVolume[6] = weightsVolume[7] = 0.125;
186 vtkIdList* facePointIds = vtkIdList::New();
187 vtkIdList* cellNeighbors = vtkIdList::New();
189 for (i=0; i<numberOfInputWedges; i++)
191 cellId = wedgeIds->GetValue(i);
192 input->GetCell(cellId,cell);
194 cell->Points->GetPoint(0,point0);
195 cell->Points->GetPoint(1,point1);
196 cell->Points->GetPoint(2,point2);
197 cell->Points->GetPoint(3,point3);
198 cell->Points->GetPoint(4,point4);
199 cell->Points->GetPoint(5,point5);
201 pointId0 = cell->PointIds->GetId(0);
202 pointId1 = cell->PointIds->GetId(1);
203 pointId2 = cell->PointIds->GetId(2);
204 pointId3 = cell->PointIds->GetId(3);
205 pointId4 = cell->PointIds->GetId(4);
206 pointId5 = cell->PointIds->GetId(5);
208 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
209 if (edgePointId01 == -1)
213 point[j] = 0.5 * (point0[j] + point1[j]);
215 edgePointId01 = outputPoints->InsertNextPoint(point);
216 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
217 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
220 edgePointId02 = edgeTable->IsEdge(pointId0,pointId2);
221 if (edgePointId02 == -1)
225 point[j] = 0.5 * (point0[j] + point2[j]);
227 edgePointId02 = outputPoints->InsertNextPoint(point);
228 outputPointData->InterpolateEdge(inputPointData,edgePointId02,pointId0,pointId2,0.5);
229 edgeTable->InsertEdge(pointId0,pointId2,edgePointId02);
232 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
233 if (edgePointId12 == -1)
237 point[j] = 0.5 * (point1[j] + point2[j]);
239 edgePointId12 = outputPoints->InsertNextPoint(point);
240 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
241 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
244 edgePointId34 = edgeTable->IsEdge(pointId3,pointId4);
245 if (edgePointId34 == -1)
249 point[j] = 0.5 * (point3[j] + point4[j]);
251 edgePointId34 = outputPoints->InsertNextPoint(point);
252 outputPointData->InterpolateEdge(inputPointData,edgePointId34,pointId3,pointId4,0.5);
253 edgeTable->InsertEdge(pointId3,pointId4,edgePointId34);
256 edgePointId35 = edgeTable->IsEdge(pointId3,pointId5);
257 if (edgePointId35 == -1)
261 point[j] = 0.5 * (point3[j] + point5[j]);
263 edgePointId35 = outputPoints->InsertNextPoint(point);
264 outputPointData->InterpolateEdge(inputPointData,edgePointId35,pointId3,pointId5,0.5);
265 edgeTable->InsertEdge(pointId3,pointId5,edgePointId35);
268 edgePointId45 = edgeTable->IsEdge(pointId4,pointId5);
269 if (edgePointId45 == -1)
273 point[j] = 0.5 * (point4[j] + point5[j]);
275 edgePointId45 = outputPoints->InsertNextPoint(point);
276 outputPointData->InterpolateEdge(inputPointData,edgePointId45,pointId4,pointId5,0.5);
277 edgeTable->InsertEdge(pointId4,pointId5,edgePointId45);
280 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
281 if (edgePointId03 == -1)
285 point[j] = 0.5 * (point0[j] + point3[j]);
287 edgePointId03 = outputPoints->InsertNextPoint(point);
288 outputPointData->InterpolateEdge(inputPointData,edgePointId03,pointId0,pointId3,0.5);
289 edgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
292 edgePointId14 = edgeTable->IsEdge(pointId1,pointId4);
293 if (edgePointId14 == -1)
297 point[j] = 0.5 * (point1[j] + point4[j]);
299 edgePointId14 = outputPoints->InsertNextPoint(point);
300 outputPointData->InterpolateEdge(inputPointData,edgePointId14,pointId1,pointId4,0.5);
301 edgeTable->InsertEdge(pointId1,pointId4,edgePointId14);
304 edgePointId25 = edgeTable->IsEdge(pointId2,pointId5);
305 if (edgePointId25 == -1)
309 point[j] = 0.5 * (point2[j] + point5[j]);
311 edgePointId25 = outputPoints->InsertNextPoint(point);
312 outputPointData->InterpolateEdge(inputPointData,edgePointId25,pointId2,pointId5,0.5);
313 edgeTable->InsertEdge(pointId2,pointId5,edgePointId25);
318 facePointIds->Initialize();
319 facePointIds->InsertNextId(pointId0);
320 facePointIds->InsertNextId(pointId1);
321 facePointIds->InsertNextId(pointId4);
322 facePointIds->InsertNextId(pointId3);
323 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
325 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
327 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_WEDGE)
329 neighborCellId = cellNeighbors->GetId(j);
333 if (neighborCellId != -1)
335 facePointId0143 = faceTable->IsEdge(cellId,neighborCellId);
336 if (facePointId0143 == -1)
340 point[j] = 0.25 * (point0[j] + point1[j] + point4[j] + point3[j]);
342 facePointId0143 = outputPoints->InsertNextPoint(point);
343 outputPointData->InterpolatePoint(inputPointData,facePointId0143,facePointIds,weights);
344 faceTable->InsertEdge(cellId,neighborCellId,facePointId0143);
348 facePointIds->Initialize();
349 facePointIds->InsertNextId(pointId1);
350 facePointIds->InsertNextId(pointId2);
351 facePointIds->InsertNextId(pointId5);
352 facePointIds->InsertNextId(pointId4);
353 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
355 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
357 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_WEDGE)
359 neighborCellId = cellNeighbors->GetId(j);
363 if (neighborCellId != -1)
365 facePointId1254 = faceTable->IsEdge(cellId,neighborCellId);
366 if (facePointId1254 == -1)
370 point[j] = 0.25 * (point1[j] + point2[j] + point5[j] + point4[j]);
372 facePointId1254 = outputPoints->InsertNextPoint(point);
373 outputPointData->InterpolatePoint(inputPointData,facePointId1254,facePointIds,weights);
374 faceTable->InsertEdge(cellId,neighborCellId,facePointId1254);
378 facePointIds->Initialize();
379 facePointIds->InsertNextId(pointId2);
380 facePointIds->InsertNextId(pointId0);
381 facePointIds->InsertNextId(pointId3);
382 facePointIds->InsertNextId(pointId5);
383 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
385 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
387 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_WEDGE)
389 neighborCellId = cellNeighbors->GetId(j);
393 if (neighborCellId != -1)
395 facePointId2035 = faceTable->IsEdge(cellId,neighborCellId);
396 if (facePointId2035 == -1)
400 point[j] = 0.25 * (point2[j] + point0[j] + point3[j] + point5[j]);
402 facePointId2035 = outputPoints->InsertNextPoint(point);
403 outputPointData->InterpolatePoint(inputPointData,facePointId2035,facePointIds,weights);
404 faceTable->InsertEdge(cellId,neighborCellId,facePointId2035);
416 pts[6] = edgePointId01;
417 pts[7] = edgePointId12;
418 pts[8] = edgePointId02;
419 pts[9] = edgePointId34;
420 pts[10] = edgePointId45;
421 pts[11] = edgePointId35;
422 pts[12] = edgePointId03;
423 pts[13] = edgePointId14;
424 pts[14] = edgePointId25;
425 pts[15] = facePointId0143;
426 pts[16] = facePointId1254;
427 pts[17] = facePointId2035;
433 newCellId = output->InsertNextCell(VTK_BIQUADRATIC_QUADRATIC_WEDGE, 18, pts);
437 newCellId = output->InsertNextCell(VTK_QUADRATIC_WEDGE, 15, pts);
440 inputToOutputCellIds->SetId(cellId,newCellId);
441 outputCellData->CopyData(inputCellData,cellId,newCellId);
444 for (i=0; i<numberOfInputTetras; i++)
446 cellId = tetraIds->GetValue(i);
447 input->GetCell(cellId,cell);
449 cell->Points->GetPoint(0,point0);
450 cell->Points->GetPoint(1,point1);
451 cell->Points->GetPoint(2,point2);
452 cell->Points->GetPoint(3,point3);
454 pointId0 = cell->PointIds->GetId(0);
455 pointId1 = cell->PointIds->GetId(1);
456 pointId2 = cell->PointIds->GetId(2);
457 pointId3 = cell->PointIds->GetId(3);
459 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
460 if (edgePointId01 == -1)
464 point[j] = 0.5 * (point0[j] + point1[j]);
466 edgePointId01 = outputPoints->InsertNextPoint(point);
467 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
468 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
471 edgePointId02 = edgeTable->IsEdge(pointId0,pointId2);
472 if (edgePointId02 == -1)
476 point[j] = 0.5 * (point0[j] + point2[j]);
478 edgePointId02 = outputPoints->InsertNextPoint(point);
479 outputPointData->InterpolateEdge(inputPointData,edgePointId02,pointId0,pointId2,0.5);
480 edgeTable->InsertEdge(pointId0,pointId2,edgePointId02);
483 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
484 if (edgePointId03 == -1)
488 point[j] = 0.5 * (point0[j] + point3[j]);
490 edgePointId03 = outputPoints->InsertNextPoint(point);
491 outputPointData->InterpolateEdge(inputPointData,edgePointId03,pointId0,pointId3,0.5);
492 edgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
495 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
496 if (edgePointId12 == -1)
500 point[j] = 0.5 * (point1[j] + point2[j]);
502 edgePointId12 = outputPoints->InsertNextPoint(point);
503 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
504 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
507 edgePointId13 = edgeTable->IsEdge(pointId1,pointId3);
508 if (edgePointId13 == -1)
512 point[j] = 0.5 * (point1[j] + point3[j]);
514 edgePointId13 = outputPoints->InsertNextPoint(point);
515 outputPointData->InterpolateEdge(inputPointData,edgePointId13,pointId1,pointId3,0.5);
516 edgeTable->InsertEdge(pointId1,pointId3,edgePointId13);
519 edgePointId23 = edgeTable->IsEdge(pointId2,pointId3);
520 if (edgePointId23 == -1)
524 point[j] = 0.5 * (point2[j] + point3[j]);
526 edgePointId23 = outputPoints->InsertNextPoint(point);
527 outputPointData->InterpolateEdge(inputPointData,edgePointId23,pointId2,pointId3,0.5);
528 edgeTable->InsertEdge(pointId2,pointId3,edgePointId23);
535 pts[4] = edgePointId01;
536 pts[5] = edgePointId12;
537 pts[6] = edgePointId02;
538 pts[7] = edgePointId03;
539 pts[8] = edgePointId13;
540 pts[9] = edgePointId23;
542 vtkIdType newCellId = output->InsertNextCell(VTK_QUADRATIC_TETRA, 10, pts);
544 inputToOutputCellIds->SetId(cellId,newCellId);
545 outputCellData->CopyData(inputCellData,cellId,newCellId);
548 for (i=0; i<numberOfInputHexahedra; i++)
550 cellId = hexahedraIds->GetValue(i);
551 input->GetCell(cellId,cell);
553 cell->Points->GetPoint(0,point0);
554 cell->Points->GetPoint(1,point1);
555 cell->Points->GetPoint(2,point2);
556 cell->Points->GetPoint(3,point3);
557 cell->Points->GetPoint(4,point4);
558 cell->Points->GetPoint(5,point5);
559 cell->Points->GetPoint(6,point6);
560 cell->Points->GetPoint(7,point7);
562 pointId0 = cell->PointIds->GetId(0);
563 pointId1 = cell->PointIds->GetId(1);
564 pointId2 = cell->PointIds->GetId(2);
565 pointId3 = cell->PointIds->GetId(3);
566 pointId4 = cell->PointIds->GetId(4);
567 pointId5 = cell->PointIds->GetId(5);
568 pointId6 = cell->PointIds->GetId(6);
569 pointId7 = cell->PointIds->GetId(7);
571 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
572 if (edgePointId01 == -1)
576 point[j] = 0.5 * (point0[j] + point1[j]);
578 edgePointId01 = outputPoints->InsertNextPoint(point);
579 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
580 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
583 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
584 if (edgePointId12 == -1)
588 point[j] = 0.5 * (point1[j] + point2[j]);
590 edgePointId12 = outputPoints->InsertNextPoint(point);
591 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
592 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
595 edgePointId23 = edgeTable->IsEdge(pointId2,pointId3);
596 if (edgePointId23 == -1)
600 point[j] = 0.5 * (point2[j] + point3[j]);
602 edgePointId23 = outputPoints->InsertNextPoint(point);
603 outputPointData->InterpolateEdge(inputPointData,edgePointId23,pointId2,pointId3,0.5);
604 edgeTable->InsertEdge(pointId2,pointId3,edgePointId23);
607 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
608 if (edgePointId03 == -1)
612 point[j] = 0.5 * (point0[j] + point3[j]);
614 edgePointId03 = outputPoints->InsertNextPoint(point);
615 outputPointData->InterpolateEdge(inputPointData,edgePointId03,pointId0,pointId3,0.5);
616 edgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
619 edgePointId04 = edgeTable->IsEdge(pointId0,pointId4);
620 if (edgePointId04 == -1)
624 point[j] = 0.5 * (point0[j] + point4[j]);
626 edgePointId04 = outputPoints->InsertNextPoint(point);
627 outputPointData->InterpolateEdge(inputPointData,edgePointId04,pointId0,pointId4,0.5);
628 edgeTable->InsertEdge(pointId0,pointId4,edgePointId04);
631 edgePointId15 = edgeTable->IsEdge(pointId1,pointId5);
632 if (edgePointId15 == -1)
636 point[j] = 0.5 * (point1[j] + point5[j]);
638 edgePointId15 = outputPoints->InsertNextPoint(point);
639 outputPointData->InterpolateEdge(inputPointData,edgePointId15,pointId1,pointId5,0.5);
640 edgeTable->InsertEdge(pointId1,pointId5,edgePointId15);
643 edgePointId26 = edgeTable->IsEdge(pointId2,pointId6);
644 if (edgePointId26 == -1)
648 point[j] = 0.5 * (point2[j] + point6[j]);
650 edgePointId26 = outputPoints->InsertNextPoint(point);
651 outputPointData->InterpolateEdge(inputPointData,edgePointId26,pointId2,pointId6,0.5);
652 edgeTable->InsertEdge(pointId2,pointId6,edgePointId26);
655 edgePointId37 = edgeTable->IsEdge(pointId3,pointId7);
656 if (edgePointId37 == -1)
660 point[j] = 0.5 * (point3[j] + point7[j]);
662 edgePointId37 = outputPoints->InsertNextPoint(point);
663 outputPointData->InterpolateEdge(inputPointData,edgePointId37,pointId3,pointId7,0.5);
664 edgeTable->InsertEdge(pointId3,pointId7,edgePointId37);
667 edgePointId45 = edgeTable->IsEdge(pointId4,pointId5);
668 if (edgePointId45 == -1)
672 point[j] = 0.5 * (point4[j] + point5[j]);
674 edgePointId45 = outputPoints->InsertNextPoint(point);
675 outputPointData->InterpolateEdge(inputPointData,edgePointId45,pointId4,pointId5,0.5);
676 edgeTable->InsertEdge(pointId4,pointId5,edgePointId45);
679 edgePointId56 = edgeTable->IsEdge(pointId5,pointId6);
680 if (edgePointId56 == -1)
684 point[j] = 0.5 * (point5[j] + point6[j]);
686 edgePointId56 = outputPoints->InsertNextPoint(point);
687 outputPointData->InterpolateEdge(inputPointData,edgePointId56,pointId5,pointId6,0.5);
688 edgeTable->InsertEdge(pointId5,pointId6,edgePointId56);
691 edgePointId67 = edgeTable->IsEdge(pointId6,pointId7);
692 if (edgePointId67 == -1)
696 point[j] = 0.5 * (point6[j] + point7[j]);
698 edgePointId67 = outputPoints->InsertNextPoint(point);
699 outputPointData->InterpolateEdge(inputPointData,edgePointId67,pointId6,pointId7,0.5);
700 edgeTable->InsertEdge(pointId6,pointId7,edgePointId67);
703 edgePointId74 = edgeTable->IsEdge(pointId4,pointId7);
704 if (edgePointId74 == -1)
708 point[j] = 0.5 * (point4[j] + point7[j]);
710 edgePointId74 = outputPoints->InsertNextPoint(point);
711 outputPointData->InterpolateEdge(inputPointData,edgePointId74,pointId4,pointId7,0.5);
712 edgeTable->InsertEdge(pointId4,pointId7,edgePointId74);
718 facePointIds->Initialize();
719 facePointIds->InsertNextId(pointId0);
720 facePointIds->InsertNextId(pointId1);
721 facePointIds->InsertNextId(pointId5);
722 facePointIds->InsertNextId(pointId4);
723 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
724 facePointId0154 = -1;
725 if (cellNeighbors->GetNumberOfIds() == 0)
727 neighborCellId = numberOfInputCells + 1;
733 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
735 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
736 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
737 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
738 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
740 neighborCellId = cellNeighbors->GetId(j);
744 if (neighborCellId != -1)
746 facePointId0154 = faceTable->IsEdge(cellId,neighborCellId);
747 if (facePointId0154 == -1)
751 point[j] = 0.25 * (point0[j] + point1[j] + point5[j] + point4[j]);
753 facePointId0154 = outputPoints->InsertNextPoint(point);
754 outputPointData->InterpolatePoint(inputPointData,facePointId0154,facePointIds,weights);
755 faceTable->InsertEdge(cellId,neighborCellId,facePointId0154);
759 facePointIds->Initialize();
760 facePointIds->InsertNextId(pointId1);
761 facePointIds->InsertNextId(pointId2);
762 facePointIds->InsertNextId(pointId6);
763 facePointIds->InsertNextId(pointId5);
764 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
765 facePointId1265 = -1;
766 if (cellNeighbors->GetNumberOfIds() == 0)
768 neighborCellId = numberOfInputCells + 2;
774 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
776 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
777 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
778 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
779 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
781 neighborCellId = cellNeighbors->GetId(j);
785 if (neighborCellId != -1)
787 facePointId1265 = faceTable->IsEdge(cellId,neighborCellId);
788 if (facePointId1265 == -1)
792 point[j] = 0.25 * (point1[j] + point2[j] + point6[j] + point5[j]);
794 facePointId1265 = outputPoints->InsertNextPoint(point);
795 outputPointData->InterpolatePoint(inputPointData,facePointId1265,facePointIds,weights);
796 faceTable->InsertEdge(cellId,neighborCellId,facePointId1265);
800 facePointIds->Initialize();
801 facePointIds->InsertNextId(pointId2);
802 facePointIds->InsertNextId(pointId3);
803 facePointIds->InsertNextId(pointId7);
804 facePointIds->InsertNextId(pointId6);
805 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
806 facePointId2376 = -1;
807 if (cellNeighbors->GetNumberOfIds() == 0)
809 neighborCellId = numberOfInputCells + 3;
815 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
817 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
818 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
819 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
820 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
822 neighborCellId = cellNeighbors->GetId(j);
826 if (neighborCellId != -1)
828 facePointId2376 = faceTable->IsEdge(cellId,neighborCellId);
829 if (facePointId2376 == -1)
833 point[j] = 0.25 * (point2[j] + point3[j] + point7[j] + point6[j]);
835 facePointId2376 = outputPoints->InsertNextPoint(point);
836 outputPointData->InterpolatePoint(inputPointData,facePointId2376,facePointIds,weights);
837 faceTable->InsertEdge(cellId,neighborCellId,facePointId2376);
841 facePointIds->Initialize();
842 facePointIds->InsertNextId(pointId3);
843 facePointIds->InsertNextId(pointId0);
844 facePointIds->InsertNextId(pointId4);
845 facePointIds->InsertNextId(pointId7);
846 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
847 facePointId3047 = -1;
848 if (cellNeighbors->GetNumberOfIds() == 0)
850 neighborCellId = numberOfInputCells + 4;
856 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
858 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
859 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
860 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
861 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
863 neighborCellId = cellNeighbors->GetId(j);
867 if (neighborCellId != -1)
869 facePointId3047 = faceTable->IsEdge(cellId,neighborCellId);
870 if (facePointId3047 == -1)
874 point[j] = 0.25 * (point3[j] + point0[j] + point4[j] + point7[j]);
876 facePointId3047 = outputPoints->InsertNextPoint(point);
877 outputPointData->InterpolatePoint(inputPointData,facePointId3047,facePointIds,weights);
878 faceTable->InsertEdge(cellId,neighborCellId,facePointId3047);
885 facePointIds->Initialize();
886 facePointIds->InsertNextId(pointId0);
887 facePointIds->InsertNextId(pointId1);
888 facePointIds->InsertNextId(pointId2);
889 facePointIds->InsertNextId(pointId3);
890 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
891 facePointId0123 = -1;
892 if (cellNeighbors->GetNumberOfIds() == 0)
894 neighborCellId = numberOfInputCells + 5;
900 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
902 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
903 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
904 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
905 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
907 neighborCellId = cellNeighbors->GetId(j);
911 if (neighborCellId != -1)
913 facePointId0123 = faceTable->IsEdge(cellId,neighborCellId);
914 if (facePointId0123 == -1)
918 point[j] = 0.25 * (point0[j] + point1[j] + point2[j] + point3[j]);
920 facePointId0123 = outputPoints->InsertNextPoint(point);
921 outputPointData->InterpolatePoint(inputPointData,facePointId0123,facePointIds,weights);
922 faceTable->InsertEdge(cellId,neighborCellId,facePointId0123);
926 facePointIds->Initialize();
927 facePointIds->InsertNextId(pointId4);
928 facePointIds->InsertNextId(pointId5);
929 facePointIds->InsertNextId(pointId6);
930 facePointIds->InsertNextId(pointId7);
931 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
932 facePointId4567 = -1;
933 if (cellNeighbors->GetNumberOfIds() == 0)
935 neighborCellId = numberOfInputCells + 6;
941 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
943 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON ||
944 input->GetCellType(cellNeighbors->GetId(j)) == VTK_QUAD ||
945 input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
946 input->GetCellType(cellNeighbors->GetId(j)) == VTK_BIQUADRATIC_QUAD)
948 neighborCellId = cellNeighbors->GetId(j);
952 if (neighborCellId != -1)
954 facePointId4567 = faceTable->IsEdge(cellId,neighborCellId);
955 if (facePointId4567 == -1)
959 point[j] = 0.25 * (point4[j] + point5[j] + point6[j] + point7[j]);
961 facePointId4567 = outputPoints->InsertNextPoint(point);
962 outputPointData->InterpolatePoint(inputPointData,facePointId4567,facePointIds,weights);
963 faceTable->InsertEdge(cellId,neighborCellId,facePointId4567);
967 facePointIds->Initialize();
968 facePointIds->InsertNextId(pointId0);
969 facePointIds->InsertNextId(pointId1);
970 facePointIds->InsertNextId(pointId2);
971 facePointIds->InsertNextId(pointId3);
972 facePointIds->InsertNextId(pointId4);
973 facePointIds->InsertNextId(pointId5);
974 facePointIds->InsertNextId(pointId6);
975 facePointIds->InsertNextId(pointId7);
978 point[j] = 0.125 * (point0[j] + point1[j] + point2[j] + point3[j] + point4[j] + point5[j] + point6[j] + point7[j]);
980 midVolumePoint = outputPoints->InsertNextPoint(point);
981 outputPointData->InterpolatePoint(inputPointData,midVolumePoint,facePointIds,weightsVolume);
993 pts[8] = edgePointId01;
994 pts[9] = edgePointId12;
995 pts[10] = edgePointId23;
996 pts[11] = edgePointId03;
997 pts[12] = edgePointId45;
998 pts[13] = edgePointId56;
999 pts[14] = edgePointId67;
1000 pts[15] = edgePointId74;
1001 pts[16] = edgePointId04;
1002 pts[17] = edgePointId15;
1003 pts[18] = edgePointId26;
1004 pts[19] = edgePointId37;
1008 pts[20] = facePointId3047;
1009 pts[21] = facePointId1265;
1010 pts[22] = facePointId0154;
1011 pts[23] = facePointId2376;
1014 pts[24] = facePointId0123;
1015 pts[25] = facePointId4567;
1016 pts[26] = midVolumePoint;
1020 vtkIdType newCellId;
1026 newCellId = output->InsertNextCell(VTK_QUADRATIC_HEXAHEDRON, 20, pts);
1031 newCellId = output->InsertNextCell(VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON, 24, pts);
1036 newCellId = output->InsertNextCell(VTK_TRIQUADRATIC_HEXAHEDRON, 27, pts);
1041 newCellId = output->InsertNextCell(VTK_HEXAHEDRON, 8, pts);
1042 vtkErrorMacro(<<
"Invalid number of nodes for a quadratic hexahedral mesh- choose 20, 24, or 27.");
1047 inputToOutputCellIds->SetId(cellId,newCellId);
1048 outputCellData->CopyData(inputCellData,cellId,newCellId);
1051 vtkCellLocator* locator = NULL;
1054 locator = vtkCellLocator::New();
1056 locator->BuildLocator();
1059 double projectedPoint[3];
1060 vtkIdType referenceCellId;
1064 vtkEdgeTable* surfaceEdgeTable = vtkEdgeTable::New();
1065 vtkEdgeTable* surfaceFaceTable = vtkEdgeTable::New();
1066 surfaceEdgeTable->InitEdgeInsertion(numberOfInputPoints,1);
1067 surfaceFaceTable->InitEdgeInsertion(numberOfInputPoints,1);
1069 for (i=0; i<numberOfInputTriangles; i++)
1071 cellId = triangleIds->GetValue(i);
1072 input->GetCell(cellId,cell);
1074 bool project =
true;
1079 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1086 cell->Points->GetPoint(0,point0);
1087 cell->Points->GetPoint(1,point1);
1088 cell->Points->GetPoint(2,point2);
1090 pointId0 = cell->PointIds->GetId(0);
1091 pointId1 = cell->PointIds->GetId(1);
1092 pointId2 = cell->PointIds->GetId(2);
1094 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
1095 if (edgePointId01 == -1)
1099 point[j] = 0.5 * (point0[j] + point1[j]);
1101 edgePointId01 = outputPoints->InsertNextPoint(point);
1102 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
1103 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
1106 edgePointId02 = edgeTable->IsEdge(pointId0,pointId2);
1107 if (edgePointId02 == -1)
1111 point[j] = 0.5 * (point0[j] + point2[j]);
1113 edgePointId02 = outputPoints->InsertNextPoint(point);
1114 outputPointData->InterpolateEdge(inputPointData,edgePointId02,pointId0,pointId2,0.5);
1115 edgeTable->InsertEdge(pointId0,pointId2,edgePointId02);
1118 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
1119 if (edgePointId12 == -1)
1123 point[j] = 0.5 * (point1[j] + point2[j]);
1125 edgePointId12 = outputPoints->InsertNextPoint(point);
1126 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
1127 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
1132 surfaceEdgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
1133 surfaceEdgeTable->InsertEdge(pointId0,pointId2,edgePointId02);
1134 surfaceEdgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
1140 pts[3] = edgePointId01;
1141 pts[4] = edgePointId12;
1142 pts[5] = edgePointId02;
1144 vtkIdType newCellId = output->InsertNextCell(VTK_QUADRATIC_TRIANGLE, 6, pts);
1146 inputToOutputCellIds->SetId(cellId,newCellId);
1147 outputCellData->CopyData(inputCellData,cellId,newCellId);
1149 if (locator && project)
1151 double point01[3], point12[3], point02[3];
1152 outputPoints->GetPoint(edgePointId01,point01);
1153 locator->FindClosestPoint(point01,projectedPoint,referenceCellId,subId,dist2);
1154 outputPoints->SetPoint(edgePointId01,projectedPoint);
1155 outputPoints->GetPoint(edgePointId12,point12);
1156 locator->FindClosestPoint(point12,projectedPoint,referenceCellId,subId,dist2);
1157 outputPoints->SetPoint(edgePointId12,projectedPoint);
1158 outputPoints->GetPoint(edgePointId02,point02);
1159 locator->FindClosestPoint(point02,projectedPoint,referenceCellId,subId,dist2);
1160 outputPoints->SetPoint(edgePointId02,projectedPoint);
1164 for (i=0; i<numberOfInputQuads; i++)
1166 cellId = quadIds->GetValue(i);
1167 input->GetCell(cellId,cell);
1169 bool project =
true;
1174 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1181 cell->Points->GetPoint(0,point0);
1182 cell->Points->GetPoint(1,point1);
1183 cell->Points->GetPoint(2,point2);
1184 cell->Points->GetPoint(3,point3);
1186 pointId0 = cell->PointIds->GetId(0);
1187 pointId1 = cell->PointIds->GetId(1);
1188 pointId2 = cell->PointIds->GetId(2);
1189 pointId3 = cell->PointIds->GetId(3);
1191 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
1192 if (edgePointId01 == -1)
1196 point[j] = 0.5 * (point0[j] + point1[j]);
1198 edgePointId01 = outputPoints->InsertNextPoint(point);
1199 outputPointData->InterpolateEdge(inputPointData,edgePointId01,pointId0,pointId1,0.5);
1200 edgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
1203 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
1204 if (edgePointId12 == -1)
1208 point[j] = 0.5 * (point1[j] + point2[j]);
1210 edgePointId12 = outputPoints->InsertNextPoint(point);
1211 outputPointData->InterpolateEdge(inputPointData,edgePointId12,pointId1,pointId2,0.5);
1212 edgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
1215 edgePointId23 = edgeTable->IsEdge(pointId2,pointId3);
1216 if (edgePointId23 == -1)
1220 point[j] = 0.5 * (point2[j] + point3[j]);
1222 edgePointId23 = outputPoints->InsertNextPoint(point);
1223 outputPointData->InterpolateEdge(inputPointData,edgePointId23,pointId2,pointId3,0.5);
1224 edgeTable->InsertEdge(pointId2,pointId3,edgePointId23);
1227 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
1228 if (edgePointId03 == -1)
1232 point[j] = 0.5 * (point0[j] + point3[j]);
1234 edgePointId03 = outputPoints->InsertNextPoint(point);
1235 outputPointData->InterpolateEdge(inputPointData,edgePointId03,pointId0,pointId3,0.5);
1236 edgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
1241 surfaceEdgeTable->InsertEdge(pointId0,pointId1,edgePointId01);
1242 surfaceEdgeTable->InsertEdge(pointId1,pointId2,edgePointId12);
1243 surfaceEdgeTable->InsertEdge(pointId2,pointId3,edgePointId23);
1244 surfaceEdgeTable->InsertEdge(pointId0,pointId3,edgePointId03);
1251 pts[4] = edgePointId01;
1252 pts[5] = edgePointId12;
1253 pts[6] = edgePointId23;
1254 pts[7] = edgePointId03;
1258 facePointIds->Initialize();
1259 facePointIds->InsertNextId(pointId0);
1260 facePointIds->InsertNextId(pointId1);
1261 facePointIds->InsertNextId(pointId2);
1262 facePointIds->InsertNextId(pointId3);
1263 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
1264 neighborCellId = -1;
1265 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
1267 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
1268 input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON)
1270 neighborCellId = cellNeighbors->GetId(j);
1271 facePointId0123 = faceTable->IsEdge(cellId,neighborCellId);
1275 if (neighborCellId != -1)
1277 pts[8] = facePointId0123;
1280 surfaceFaceTable->InsertEdge(cellId,neighborCellId,facePointId0123);
1285 vtkIdType newCellId;
1290 newCellId = output->InsertNextCell(VTK_QUADRATIC_QUAD, 8, pts);
1295 newCellId = output->InsertNextCell(VTK_BIQUADRATIC_QUAD, 9, pts);
1300 newCellId = output->InsertNextCell(VTK_QUAD, 4, pts);
1301 vtkErrorMacro(<<
"Invalid number of nodes (" << this->
NumberOfNodesHexahedra <<
") for a hexahedral mesh with quadratic quad surface- choose 20 or 27.\n");
1306 inputToOutputCellIds->SetId(cellId,newCellId);
1307 outputCellData->CopyData(inputCellData,cellId,newCellId);
1309 if (locator && project)
1311 double point01[3], point12[3], point23[3], point03[3], facePoint[3];
1312 outputPoints->GetPoint(edgePointId01,point01);
1313 locator->FindClosestPoint(point01,projectedPoint,referenceCellId,subId,dist2);
1314 outputPoints->SetPoint(edgePointId01,projectedPoint);
1315 outputPoints->GetPoint(edgePointId12,point12);
1316 locator->FindClosestPoint(point12,projectedPoint,referenceCellId,subId,dist2);
1317 outputPoints->SetPoint(edgePointId12,projectedPoint);
1318 outputPoints->GetPoint(edgePointId23,point23);
1319 locator->FindClosestPoint(point23,projectedPoint,referenceCellId,subId,dist2);
1320 outputPoints->SetPoint(edgePointId23,projectedPoint);
1321 outputPoints->GetPoint(edgePointId03,point03);
1322 locator->FindClosestPoint(point03,projectedPoint,referenceCellId,subId,dist2);
1323 outputPoints->SetPoint(edgePointId03,projectedPoint);
1326 outputPoints->GetPoint(facePointId0123,facePoint);
1327 locator->FindClosestPoint(facePoint,projectedPoint,referenceCellId,subId,dist2);
1328 outputPoints->SetPoint(facePointId0123,projectedPoint);
1334#ifdef LEGACY_RELAXATION
1335 int numberOfRelaxationSteps = 10;
1336 int maxSignChangeIterations = 20;
1337 int signChangeCounter = 0;
1338 bool anySignChange =
true;
1339 while (anySignChange)
1341 if (signChangeCounter >= maxSignChangeIterations)
1345 signChangeCounter++;
1346 anySignChange =
false;
1347 for (i=0; i<numberOfInputTriangles; i++)
1349 cellId = triangleIds->GetValue(i);
1350 input->GetCell(cellId,cell);
1352 cell->Points->GetPoint(0,point0);
1353 cell->Points->GetPoint(1,point1);
1354 cell->Points->GetPoint(2,point2);
1356 pointId0 = cell->PointIds->GetId(0);
1357 pointId1 = cell->PointIds->GetId(1);
1358 pointId2 = cell->PointIds->GetId(2);
1360 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
1361 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
1362 edgePointId02 = edgeTable->IsEdge(pointId0,pointId2);
1366 bool project =
true;
1369 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1377 vtkIdType volumeCellId = -1;
1378 vtkIdList* volumeCellIds = vtkIdList::New();
1379 output->GetCellNeighbors(cellId,cell->PointIds,volumeCellIds);
1380 if (volumeCellIds->GetNumberOfIds() == 0)
1382 vtkWarningMacro(<<
"Warning: surface element "<<cellId<<
" does not have a volume element attached.");
1383 volumeCellIds->Delete();
1386 if (volumeCellIds->GetNumberOfIds() > 1)
1388 vtkWarningMacro(<<
"Warning: surface element "<<cellId<<
" has more than one volume element attached.");
1389 volumeCellIds->Delete();
1392 volumeCellId = volumeCellIds->GetId(0);
1393 vtkCell* linearVolumeCell = input->GetCell(volumeCellId);
1394 vtkCell* quadraticVolumeCell = output->GetCell(volumeCellId);
1395 double point01[3], point12[3], point02[3];
1396 double projectedPoint01[3], projectedPoint12[3], projectedPoint02[3];
1397 outputPoints->GetPoint(edgePointId01,projectedPoint01);
1398 outputPoints->GetPoint(edgePointId12,projectedPoint12);
1399 outputPoints->GetPoint(edgePointId02,projectedPoint02);
1401 for (s=0; s<numberOfRelaxationSteps; s++)
1407 anySignChange =
true;
1408 vtkWarningMacro(<<
"Warning: projection causes element "<<volumeCellId<<
" to have a negative Jacobian somewhere. Relaxing projection for this element.");
1409 double relaxation = (double)(s+1)/(double)numberOfRelaxationSteps;
1412 point01[j] = (1.0 - relaxation) * projectedPoint01[j] + relaxation * (0.5 * (point0[j] + point1[j]));
1413 point12[j] = (1.0 - relaxation) * projectedPoint12[j] + relaxation * (0.5 * (point1[j] + point2[j]));
1414 point02[j] = (1.0 - relaxation) * projectedPoint02[j] + relaxation * (0.5 * (point0[j] + point2[j]));
1416 outputPoints->SetPoint(edgePointId01,point01);
1417 outputPoints->SetPoint(edgePointId12,point12);
1418 outputPoints->SetPoint(edgePointId02,point02);
1419 quadraticVolumeCell = output->GetCell(volumeCellId);
1421 volumeCellIds->Delete();
1426 for (i=0; i<numberOfInputQuads; i++)
1428 cellId = quadIds->GetValue(i);
1429 input->GetCell(cellId,cell);
1431 cell->Points->GetPoint(0,point0);
1432 cell->Points->GetPoint(1,point1);
1433 cell->Points->GetPoint(2,point2);
1434 cell->Points->GetPoint(3,point3);
1436 pointId0 = cell->PointIds->GetId(0);
1437 pointId1 = cell->PointIds->GetId(1);
1438 pointId2 = cell->PointIds->GetId(2);
1439 pointId3 = cell->PointIds->GetId(3);
1441 edgePointId01 = edgeTable->IsEdge(pointId0,pointId1);
1442 edgePointId12 = edgeTable->IsEdge(pointId1,pointId2);
1443 edgePointId23 = edgeTable->IsEdge(pointId2,pointId3);
1444 edgePointId03 = edgeTable->IsEdge(pointId0,pointId3);
1448 bool project =
true;
1451 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1458 vtkIdType volumeCellId = 0;
1459 vtkIdList* volumeCellIds = vtkIdList::New();
1460 output->GetCellNeighbors(cellId,cell->PointIds,volumeCellIds);
1461 if (volumeCellIds->GetNumberOfIds() == 0)
1463 vtkWarningMacro(<<
"Warning: surface element "<<cellId<<
" does not have a volume element attached.");
1464 volumeCellIds->Delete();
1467 if (volumeCellIds->GetNumberOfIds() > 1)
1469 vtkWarningMacro(<<
"Warning: surface element "<<cellId<<
" has more than one volume element attached.");
1470 volumeCellIds->Delete();
1473 volumeCellId = volumeCellIds->GetId(0);
1474 vtkCell* linearVolumeCell = input->GetCell(volumeCellId);
1475 vtkCell* quadraticVolumeCell = output->GetCell(volumeCellId);
1476 double point01[3], point12[3], point23[3], point03[3];
1477 double projectedPoint01[3], projectedPoint12[3], projectedPoint23[3], projectedPoint03[3];
1478 outputPoints->GetPoint(edgePointId01,projectedPoint01);
1479 outputPoints->GetPoint(edgePointId12,projectedPoint12);
1480 outputPoints->GetPoint(edgePointId23,projectedPoint23);
1481 outputPoints->GetPoint(edgePointId03,projectedPoint03);
1484 for (s=0; s<numberOfRelaxationSteps; s++)
1490 anySignChange =
true;
1491 vtkWarningMacro(<<
"Warning: projection causes element "<<volumeCellId<<
" to have a negative Jacobian somewhere. Relaxing projection for this element.");
1492 double relaxation = (double)(s+1)/(double)numberOfRelaxationSteps;
1495 point01[j] = (1.0 - relaxation) * projectedPoint01[j] + relaxation * (0.5 * (point0[j] + point1[j]));
1496 point12[j] = (1.0 - relaxation) * projectedPoint12[j] + relaxation * (0.5 * (point1[j] + point2[j]));
1497 point23[j] = (1.0 - relaxation) * projectedPoint23[j] + relaxation * (0.5 * (point2[j] + point3[j]));
1498 point03[j] = (1.0 - relaxation) * projectedPoint03[j] + relaxation * (0.5 * (point0[j] + point3[j]));
1500 outputPoints->SetPoint(edgePointId01,point01);
1501 outputPoints->SetPoint(edgePointId12,point12);
1502 outputPoints->SetPoint(edgePointId23,point23);
1503 outputPoints->SetPoint(edgePointId03,point03);
1504 quadraticVolumeCell = output->GetCell(volumeCellId);
1506 volumeCellIds->Delete();
1512 int numberOfRelaxationSteps = 10;
1513 int maxSignChangeIterations = 20;
1514 int signChangeCounter = 0;
1515 bool anySignChange =
true;
1518 anySignChange =
false;
1520 while (anySignChange)
1522 if (signChangeCounter >= maxSignChangeIterations)
1526 signChangeCounter++;
1527 anySignChange =
false;
1529 surfaceEdgeTable->InitTraversal();
1530 vtkIdType edgePointId = surfaceEdgeTable->GetNextEdge(pointId0,pointId1);
1531 vtkIdList* edgePointIds = vtkIdList::New();
1532 vtkIdList* cellEdgeNeighbors = vtkIdList::New();
1533 while (edgePointId >= 0)
1535 edgePointIds->Initialize();
1536 edgePointIds->InsertNextId(pointId0);
1537 edgePointIds->InsertNextId(pointId1);
1538 input->GetCellNeighbors(-1,edgePointIds,cellEdgeNeighbors);
1539 int numberOfCellEdgeNeighbors = cellEdgeNeighbors->GetNumberOfIds();
1540 for (i=0; i<numberOfCellEdgeNeighbors; i++)
1542 vtkIdType volumeCellId = cellEdgeNeighbors->GetId(i);
1543 if (input->GetCell(volumeCellId)->GetCellDimension() != 3)
1547 vtkCell* linearVolumeCell = input->GetCell(volumeCellId);
1548 vtkIdType outputCellId = inputToOutputCellIds->GetId(volumeCellId);
1549 if (outputCellId == -1)
1553 vtkCell* quadraticVolumeCell = output->GetCell(outputCellId);
1556 for (s=0; s<numberOfRelaxationSteps; s++)
1562 anySignChange =
true;
1563 vtkWarningMacro(<<
"Warning: projection causes element "<<volumeCellId<<
" to have a negative Jacobian somewhere. Relaxing projection for this element.");
1564 double relaxation = (double)(s+1)/(double)numberOfRelaxationSteps;
1565 int numberOfEdges = linearVolumeCell->GetNumberOfEdges();
1567 for (e=0; e<numberOfEdges; e++)
1569 vtkCell* edge = linearVolumeCell->GetEdge(e);
1570 vtkIdType pointId0 = edge->GetPointId(0);
1571 vtkIdType pointId1 = edge->GetPointId(1);
1572 vtkIdType edgePointId = surfaceEdgeTable->IsEdge(pointId0,pointId1);
1573 if (edgePointId == -1)
1577 double edgePoint[3], relaxedEdgePoint[3];
1578 input->GetPoint(pointId0,point0);
1579 input->GetPoint(pointId1,point1);
1580 output->GetPoint(edgePointId,edgePoint);
1583 relaxedEdgePoint[j] = (1.0 - relaxation) * edgePoint[j] + relaxation * (0.5 * (point0[j] + point1[j]));
1585 outputPoints->SetPoint(edgePointId,relaxedEdgePoint);
1587 quadraticVolumeCell = output->GetCell(outputCellId);
1590 edgePointId = surfaceEdgeTable->GetNextEdge(pointId0,pointId1);
1592 edgePointIds->Delete();
1593 cellEdgeNeighbors->Delete();
1600 int numberOfRelaxationSteps = 10;
1601 int maxSignChangeIterations = 20;
1602 int signChangeCounter = 0;
1603 bool anySignChange =
true;
1604 while (anySignChange)
1606 if (signChangeCounter >= maxSignChangeIterations)
1610 signChangeCounter++;
1611 anySignChange =
false;
1613 for (i=0; i<numberOfInputQuads; i++)
1615 cellId = quadIds->GetValue(i);
1616 input->GetCell(cellId,cell);
1618 cell->Points->GetPoint(0,point0);
1619 cell->Points->GetPoint(1,point1);
1620 cell->Points->GetPoint(2,point2);
1621 cell->Points->GetPoint(3,point3);
1623 pointId0 = cell->PointIds->GetId(0);
1624 pointId1 = cell->PointIds->GetId(1);
1625 pointId2 = cell->PointIds->GetId(2);
1626 pointId3 = cell->PointIds->GetId(3);
1628 facePointIds->Initialize();
1629 facePointIds->InsertNextId(pointId0);
1630 facePointIds->InsertNextId(pointId1);
1631 facePointIds->InsertNextId(pointId2);
1632 facePointIds->InsertNextId(pointId3);
1633 input->GetCellNeighbors(cellId,facePointIds,cellNeighbors);
1634 neighborCellId = -1;
1635 facePointId0123 = -1;
1636 for (j=0; j<cellNeighbors->GetNumberOfIds(); j++)
1638 if (input->GetCellType(cellNeighbors->GetId(j)) == VTK_TRIQUADRATIC_HEXAHEDRON ||
1639 input->GetCellType(cellNeighbors->GetId(j)) == VTK_HEXAHEDRON)
1641 neighborCellId = cellNeighbors->GetId(j);
1642 facePointId0123 = faceTable->IsEdge(cellId,neighborCellId);
1648 bool project =
true;
1651 if (cellEntityIdsArray->GetValue(cellId) != this->ProjectedCellEntityId)
1658 vtkIdType volumeCellId = 0;
1659 vtkIdList* volumeCellIds = vtkIdList::New();
1660 output->GetCellNeighbors(cellId,cell->PointIds,volumeCellIds);
1661 if (volumeCellIds->GetNumberOfIds() == 0)
1663 vtkWarningMacro(<<
"Warning: surface element "<<cellId<<
" does not have a volume element attached.");
1664 volumeCellIds->Delete();
1667 if (volumeCellIds->GetNumberOfIds() > 1)
1669 vtkWarningMacro(<<
"Warning: surface element "<<cellId<<
" has more than one volume element attached.");
1670 volumeCellIds->Delete();
1673 volumeCellId = volumeCellIds->GetId(0);
1674 vtkCell* linearVolumeCell = input->GetCell(volumeCellId);
1675 vtkCell* quadraticVolumeCell = output->GetCell(volumeCellId);
1676 double facePoint[3];
1677 double projectedFacePoint0123[3];
1679 outputPoints->GetPoint(facePointId0123,projectedFacePoint0123);
1681 for (s=0; s<numberOfRelaxationSteps; s++)
1687 anySignChange =
true;
1688 vtkWarningMacro(<<
"Warning: projection causes element "<<volumeCellId<<
" to have a negative Jacobian somewhere. Relaxing projection for this element.");
1689 double relaxation = (double)(s+1)/(double)numberOfRelaxationSteps;
1692 facePoint[j] = (1.0 - relaxation) * projectedFacePoint0123[j] + relaxation * (0.25 * (point0[j] + point1[j] + point2[j] + point3[j]));
1694 outputPoints->SetPoint(facePointId0123,facePoint);
1695 quadraticVolumeCell = output->GetCell(volumeCellId);
1697 volumeCellIds->Delete();
1706 for (i=0; i<numberOfCells; i++)
1708 vtkCell* linearVolumeCell = input->GetCell(i);
1709 if (linearVolumeCell->GetCellDimension() != 3)
1713 vtkIdType outputCellId = inputToOutputCellIds->GetId(i);
1714 if (outputCellId == -1)
1718 vtkCell* quadraticVolumeCell = output->GetCell(outputCellId);
1722 vtkErrorMacro(
"Error: negative Jacobian detected in cell "<<outputCellId<<
" even after relaxation. Output quadratic mesh will have negative Jacobians.");
1727 surfaceEdgeTable->Delete();
1728 surfaceFaceTable->Delete();
1730 outputPoints->Delete();
1731 edgeTable->Delete();
1732 faceTable->Delete();
1734 triangleIds->Delete();
1737 hexahedraIds->Delete();
1739 facePointIds->Delete();
1740 cellNeighbors->Delete();
1748 cellEntityIdsArray->Delete();
1750 inputToOutputCellIds->Delete();