139 vtkInformation *vtkNotUsed(request),
140 vtkInformationVector **inputVector,
141 vtkInformationVector *outputVector)
143 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
144 vtkInformation *outInfo = outputVector->GetInformationObject(0);
146 vtkPolyData *input = vtkPolyData::SafeDownCast(
147 inInfo->Get(vtkDataObject::DATA_OBJECT()));
148 vtkPolyData *output = vtkPolyData::SafeDownCast(
149 outInfo->Get(vtkDataObject::DATA_OBJECT()));
155 vtkErrorMacro(<<
"TargetAreaArrayName not specified");
161 vtkErrorMacro(<<
"TargetAreaArray with name specified does not exist");
176 if (!cellEntityIdsArray)
178 vtkErrorMacro(<<
"CellEntityIdsArray with name specified does not exist");
191 this->
Mesh->Delete();
195 vtkPolyDataNormals* normals = vtkPolyDataNormals::New();
196 normals->SetInputData(input);
197 normals->ComputePointNormalsOff();
198 normals->ComputeCellNormalsOn();
199 normals->AutoOrientNormalsOn();
200 normals->ConsistencyOn();
201 normals->SplittingOff();
204 vtkDataArray* cellNormals = normals->GetOutput()->GetCellData()->GetNormals();
206 this->
Mesh = vtkPolyData::New();
207 vtkPoints* workingPoints = vtkPoints::New();
208 vtkCellArray* workingCells = vtkCellArray::New();
209 workingPoints->DeepCopy(input->GetPoints());
211 double point1[3], point2[3], point3[3];
212 double cellNormal[3], orientedCellNormal[3];
213 for (
int i=0; i<input->GetNumberOfCells(); i++)
215 if (input->GetCellType(i) != VTK_TRIANGLE)
219 vtkCell* cell = input->GetCell(i);
220 cell->GetPoints()->GetPoint(0,point1);
221 cell->GetPoints()->GetPoint(1,point2);
222 cell->GetPoints()->GetPoint(2,point3);
223 vtkTriangle::ComputeNormal(point1,point2,point3,cellNormal);
224 cellNormals->GetTuple(i,orientedCellNormal);
225 workingCells->InsertNextCell(3);
226 if (vtkMath::Dot(cellNormal,orientedCellNormal) > 0.0)
228 workingCells->InsertCellPoint(cell->GetPointId(0));
229 workingCells->InsertCellPoint(cell->GetPointId(1));
230 workingCells->InsertCellPoint(cell->GetPointId(2));
234 workingCells->InsertCellPoint(cell->GetPointId(1));
235 workingCells->InsertCellPoint(cell->GetPointId(0));
236 workingCells->InsertCellPoint(cell->GetPointId(2));
240 this->
Mesh->SetPoints(workingPoints);
241 this->
Mesh->SetPolys(workingCells);
243 workingPoints->Delete();
244 workingCells->Delete();
247 this->
Mesh->BuildCells();
248#if VTK_MAJOR_VERSION > 9 || (VTK_MAJOR_VERSION == 9 && VTK_MINOR_VERSION >= 4)
254 this->
Mesh->SetEditable(
true);
256 this->
Mesh->BuildLinks();
264 this->
Locator = vtkCellLocator::New();
265 this->
Locator->SetDataSet(input);
266 this->
Locator->SetNumberOfCellsPerBucket(5);
267 this->
Locator->CacheCellBoundsOn();
277 boundaryExtractor->SetInputData(input);
278 boundaryExtractor->Update();
281 this->
InputBoundary->DeepCopy(boundaryExtractor->GetOutput());
283 boundaryExtractor->Delete();
323 std::cout<<
"Iteration "<<n+1<<
"/"<<this->NumberOfIterations<<endl;
341 std::cout<<
"Final mesh improvement"<<endl;
342 bool projectToSurface =
false;
343 for (
int i=0; i<this->NumberOfIterations; i++)
345 if (i == this->NumberOfIterations/2)
347 projectToSurface =
true;
363 vtkPoints* newPoints = vtkPoints::New();
364 vtkCellArray* newCells = vtkCellArray::New();
365 vtkIntArray* newCellEntityIdsArray = vtkIntArray::New();
368 newPoints->DeepCopy(this->
Mesh->GetPoints());
370 int numberOfFinalCells = this->
Mesh->GetNumberOfCells();
371 for (
int i=0; i<numberOfFinalCells; i++)
373 if (this->
Mesh->GetCellType(i) == VTK_EMPTY_CELL)
381 newCells->InsertNextCell(this->
Mesh->GetCell(i));
385 output->SetPoints(newPoints);
386 output->SetPolys(newCells);
387 output->GetCellData()->AddArray(newCellEntityIdsArray);
391 newCellEntityIdsArray->Delete();
398 vtkPoints* entityBoundaryPoints = vtkPoints::New();
399 vtkCellArray* entityBoundaryCells = vtkCellArray::New();
400 vtkIdList* cellIds = vtkIdList::New();
401 vtkIdType numberOfCells = input->GetNumberOfCells();
403 const vtkIdType *pts;
404 for (
int i=0; i<numberOfCells; i++)
406 if (input->GetCellType(i) != VTK_TRIANGLE)
410 input->GetCellPoints(i,npts,pts);
412 for (
int j=0; j<npts; j++)
414 cellIds->Initialize();
415 vtkIdType pt1 = pts[j];
416 vtkIdType pt2 = pts[(j+1)%npts];
417 input->GetCellEdgeNeighbors(i,pt1,pt2,cellIds);
418 bool entityBoundaryEdge =
false;
419 for (
int k=0; k<cellIds->GetNumberOfIds(); k++)
423 entityBoundaryEdge =
true;
427 if (entityBoundaryEdge)
429 vtkIdType pt1Id = entityBoundaryPoints->InsertNextPoint(input->GetPoint(pt1));
430 vtkIdType pt2Id = entityBoundaryPoints->InsertNextPoint(input->GetPoint(pt2));
431 entityBoundaryCells->InsertNextCell(2);
432 entityBoundaryCells->InsertCellPoint(pt1Id);
433 entityBoundaryCells->InsertCellPoint(pt2Id);
438 entityBoundary->SetPoints(entityBoundaryPoints);
439 entityBoundary->SetLines(entityBoundaryCells);
442 entityBoundaryPoints->Delete();
443 entityBoundaryCells->Delete();
472 this->
Mesh->GetPointCells(pointId,ncells,cells);
473 vtkIdList* cellEdgeNeighbors = vtkIdList::New();
474 for (vtkIdType i=0; i<ncells; i++)
477 const vtkIdType *pts;
478 this->
Mesh->GetCellPoints(cells[i],npts,pts);
479 for (
int j=0; j<npts; j++)
481 if (pts[j] == pointId)
485 if (this->
Mesh->IsEdge(pts[j],pointId))
487 this->
Mesh->GetCellEdgeNeighbors(cells[i],pts[j],pointId,cellEdgeNeighbors);
488 if (cellEdgeNeighbors->GetNumberOfIds() == 0)
490 cellEdgeNeighbors->Delete();
496 cellEdgeNeighbors->Delete();
702 vtkIdList* cellIds = vtkIdList::New();
703 this->
Mesh->GetPointCells(pointId,cellIds);
705 vtkIdType numberOfCells = cellIds->GetNumberOfIds();
706 if (numberOfCells < 1)
712 vtkIdList* ptIds = vtkIdList::New();
713 this->
Mesh->GetCellPoints(cellIds->GetId(0),ptIds);
719 p2 = ptIds->GetId(0);
722 p2 = ptIds->GetId(i);
728 neighborIds->InsertNextId(p2);
730 this->
Mesh->GetCellEdgeNeighbors(-1,pointId,p2,cellIds);
733 vtkIdType nextCell = cellIds->GetId(0);
734 if (cellIds->GetNumberOfIds() == 1)
740 startCell = cellIds->GetId(1);
747 vtkCell* cell = NULL;
748 for (j=0; j<numberOfCells; j++)
750 cell = this->
Mesh->GetCell(nextCell);
754 p1 = cell->GetPointId(i);
755 if (p1 != pointId && p1 != p2)
762 neighborIds->InsertNextId(p2);
763 this->
Mesh->GetCellEdgeNeighbors(nextCell,pointId,p2,cellIds);
764 if (cellIds->GetNumberOfIds() != 1)
770 nextCell = cellIds->GetId(0);
775 nextCell = startCell;
777 for (; j<numberOfCells && startCell!=-1; j++)
779 cell = this->
Mesh->GetCell(nextCell);
783 p1 = cell->GetPointId(i);
784 if (p1 != pointId && p1 != p2)
790 neighborIds->InsertNextId(p2);
791 this->
Mesh->GetCellEdgeNeighbors(nextCell,pointId,p2,cellIds);
792 if (cellIds->GetNumberOfIds() != 1)
797 nextCell = cellIds->GetId(0);
803 vtkIdType
id = neighborIds->IsId(bp2);
804 for (i=0; i<=
id/2; i++)
806 p1 = neighborIds->GetId(i);
807 p2 = neighborIds->GetId(
id-i);
808 neighborIds->SetId(i,p2);
809 neighborIds->SetId(
id-i,p1);
815 neighborIds->SetNumberOfIds(neighborIds->GetNumberOfIds()-1);
821 return pointLocation;
826 vtkIdList* cellIds = vtkIdList::New();
827 this->
Mesh->GetPointCells(pointId,cellIds);
828 int pointOnExcludedEntity = 0;
829 for (
int i=0; i<cellIds->GetNumberOfIds(); i++)
833 pointOnExcludedEntity = 1;
838 if (pointOnExcludedEntity)
844 vtkIdList* neighborIds = vtkIdList::New();
860 double targetPoint[3];
861 targetPoint[0] = targetPoint[1] = targetPoint[2] = 0.0;
863 int numberOfNeighbors = neighborIds->GetNumberOfIds();
864 double stencilWeight = 1.0 / numberOfNeighbors;
865 for (
int i=0; i<numberOfNeighbors; i++)
867 double stencilPoint[3];
868 this->
Mesh->GetPoint(neighborIds->GetId(i),stencilPoint);
869 targetPoint[0] += stencilWeight * stencilPoint[0];
870 targetPoint[1] += stencilWeight * stencilPoint[1];
871 targetPoint[2] += stencilWeight * stencilPoint[2];
876 double stencilPoint[3];
878 double stencilWeight = stencil->
GetWeight(i);
879 targetPoint[0] += stencilWeight * stencilPoint[0];
880 targetPoint[1] += stencilWeight * stencilPoint[1];
881 targetPoint[2] += stencilWeight * stencilPoint[2];
885 this->
Mesh->GetPoint(pointId,point);
887 double relocatedPoint[3];
888 relocatedPoint[0] = point[0] + this->
Relaxation * (targetPoint[0] - point[0]);
889 relocatedPoint[1] = point[1] + this->
Relaxation * (targetPoint[1] - point[1]);
890 relocatedPoint[2] = point[2] + this->
Relaxation * (targetPoint[2] - point[2]);
892 double projectedRelocatedPoint[3];
898 this->
EntityBoundaryLocator->FindClosestPoint(relocatedPoint,projectedRelocatedPoint,cellId,subId,dist2);
902 if (projectToSurface)
904 this->
Locator->FindClosestPoint(relocatedPoint,projectedRelocatedPoint,cellId,subId,dist2);
908 projectedRelocatedPoint[0] = relocatedPoint[0];
909 projectedRelocatedPoint[1] = relocatedPoint[1];
910 projectedRelocatedPoint[2] = relocatedPoint[2];
913 this->
Mesh->GetPoints()->SetPoint(pointId,projectedRelocatedPoint);
917 double targetPoint[3];
918 targetPoint[0] = targetPoint[1] = targetPoint[2] = 0.0;
920 double stencilPoint[3];
922 this->
Mesh->GetPoint(neighborIds->GetId(0),stencilPoint);
926 double stencilWeight = 0.5;
927 targetPoint[0] += stencilWeight * stencilPoint[0];
928 targetPoint[1] += stencilWeight * stencilPoint[1];
929 targetPoint[2] += stencilWeight * stencilPoint[2];
931 this->
Mesh->GetPoint(neighborIds->GetId(neighborIds->GetNumberOfIds()-1),stencilPoint);
935 targetPoint[0] += stencilWeight * stencilPoint[0];
936 targetPoint[1] += stencilWeight * stencilPoint[1];
937 targetPoint[2] += stencilWeight * stencilPoint[2];
940 this->
Mesh->GetPoint(pointId,point);
942 double relocatedPoint[3];
943 relocatedPoint[0] = point[0] + this->
Relaxation * (targetPoint[0] - point[0]);
944 relocatedPoint[1] = point[1] + this->
Relaxation * (targetPoint[1] - point[1]);
945 relocatedPoint[2] = point[2] + this->
Relaxation * (targetPoint[2] - point[2]);
947 double projectedRelocatedPoint[3];
953 this->
BoundaryLocator->FindClosestPoint(relocatedPoint,projectedRelocatedPoint,cellId,subId,dist2);
958 projectedRelocatedPoint[0] = relocatedPoint[0];
959 projectedRelocatedPoint[1] = relocatedPoint[1];
960 projectedRelocatedPoint[2] = relocatedPoint[2];
964 this->
Mesh->GetPoints()->SetPoint(pointId,projectedRelocatedPoint);
967 neighborIds->Delete();
979 if (!this->
Mesh->IsEdge(pt1,pt2))
984 vtkIdList* cellIds = vtkIdList::New();
985 this->
Mesh->GetCellEdgeNeighbors(-1,pt1,pt2,cellIds);
987 int numberOfCellEdgeNeighbors = cellIds->GetNumberOfIds();
988 int numberOfNeighborTriangles = 0;
990 for (
int i=0; i<numberOfCellEdgeNeighbors; i++)
992 vtkIdType cellId = cellIds->GetId(i);
993 if (this->
Mesh->GetCellType(cellId) == VTK_TRIANGLE)
995 if (numberOfNeighborTriangles==0)
999 else if (numberOfNeighborTriangles==1)
1003 numberOfNeighborTriangles++;
1009 if (numberOfNeighborTriangles == 0)
1013 else if (numberOfNeighborTriangles == 1)
1016 const vtkIdType *pts;
1017 this->
Mesh->GetCellPoints(cell1,npts,pts);
1018 for (
int i=0; i<3; i++)
1020 if ((pts[i]==pt1 && pts[(i+1)%3]==pt2) || (pts[i]==pt2 && pts[(i+1)%3]==pt1))
1028 else if (numberOfNeighborTriangles > 2)
1033 vtkIdType pt3tmp = -1;
1034 vtkIdType pt4tmp = -1;
1035 bool reverse =
false;
1037 const vtkIdType *pts;
1038 this->
Mesh->GetCellPoints(cell1,npts,pts);
1039 for (
int i=0; i<3; i++)
1041 if ((pts[i]==pt1 && pts[(i+1)%3]==pt2) || (pts[i]==pt2 && pts[(i+1)%3]==pt1))
1043 pt3tmp = pts[(i+2)%3];
1044 if (pts[i]==pt2 && pts[(i+1)%3]==pt1)
1052 this->
Mesh->GetCellPoints(cell2,npts,pts);
1053 for (
int i=0; i<3; i++)
1055 if ((pts[i]==pt1 && pts[(i+1)%3]==pt2) || (pts[i]==pt2 && pts[(i+1)%3]==pt1))
1057 pt4tmp = pts[(i+2)%3];
1062 if (pt3tmp==-1 || pt4tmp==-1)
1081 if (this->
CellEntityIdsArray->GetValue(cell1) != this->CellEntityIdsArray->GetValue(cell2))
1091 if (this->
Mesh->GetCellType(cellId) != VTK_TRIANGLE)
1102 const vtkIdType *pts;
1103 this->
Mesh->GetCellPoints(cellId,npts,pts);
1104 vtkIdType pt1 = pts[0];
1105 vtkIdType pt2 = pts[1];
1106 vtkIdType pt3 = pts[2];
1110 double point1[3], point2[3], point3[3], newPoint[3];
1111 this->
Mesh->GetPoint(pt1,point1);
1112 this->
Mesh->GetPoint(pt2,point2);
1113 this->
Mesh->GetPoint(pt3,point3);
1114 vtkTriangle::TriangleCenter(point1,point2,point3,newPoint);
1116 double projectedNewPoint[3];
1117 vtkIdType closestCellId;
1120 this->
Locator->FindClosestPoint(newPoint,projectedNewPoint,closestCellId,subId,dist2);
1122 vtkIdType newpt = this->
Mesh->InsertNextLinkedPoint(projectedNewPoint,1);
1124 this->
Mesh->ReplaceCellPoint(cellId,pt3,newpt);
1125 this->
Mesh->RemoveReferenceToCell(pt3,cellId);
1126 this->
Mesh->AddReferenceToCell(newpt,cellId);
1132 vtkIdType cell1 = this->
Mesh->InsertNextLinkedCell(VTK_TRIANGLE,3,tri);
1138 vtkIdType cell2 = this->
Mesh->InsertNextLinkedCell(VTK_TRIANGLE,3,tri);
1154 vtkIdType cell1, cell2, pt3, pt4;
1162 bool proceed =
false;
1184 double point1[3], point2[3];
1185 this->
Mesh->GetPoint(pt1,point1);
1186 this->
Mesh->GetPoint(pt2,point2);
1189 newPoint[0] = 0.5 * (point1[0] + point2[0]);
1190 newPoint[1] = 0.5 * (point1[1] + point2[1]);
1191 newPoint[2] = 0.5 * (point1[2] + point2[2]);
1195 double projectedNewPoint[3];
1206 this->
Locator->FindClosestPoint(newPoint,projectedNewPoint,cellId,subId,dist2);
1208 vtkIdType newpt = this->
Mesh->InsertNextLinkedPoint(projectedNewPoint,2);
1210 this->
Mesh->ReplaceCellPoint(cell1,pt2,newpt);
1211 this->
Mesh->ReplaceCellPoint(cell2,pt2,newpt);
1213 this->
Mesh->RemoveReferenceToCell(pt2,cell1);
1214 this->
Mesh->RemoveReferenceToCell(pt2,cell2);
1216 this->
Mesh->AddReferenceToCell(newpt,cell1);
1217 this->
Mesh->AddReferenceToCell(newpt,cell2);
1223 vtkIdType cell3 = this->
Mesh->InsertNextLinkedCell(VTK_TRIANGLE,3,tri);
1229 vtkIdType cell4 = this->
Mesh->InsertNextLinkedCell(VTK_TRIANGLE,3,tri);
1234 double projectedNewPoint[3];
1241 this->
BoundaryLocator->FindClosestPoint(newPoint,projectedNewPoint,cellId,subId,dist2);
1245 vtkErrorMacro(<<
"Something's wrong: point on boundary but no BoundaryLocator is allocated.");
1246 projectedNewPoint[0] = newPoint[0];
1247 projectedNewPoint[1] = newPoint[1];
1248 projectedNewPoint[2] = newPoint[2];
1250 vtkIdType newpt = this->
Mesh->InsertNextLinkedPoint(projectedNewPoint,2);
1252 this->
Mesh->ReplaceCellPoint(cell1,pt2,newpt);
1253 this->
Mesh->RemoveReferenceToCell(pt2,cell1);
1254 this->
Mesh->AddReferenceToCell(newpt,cell1);
1260 vtkIdType cell3 = this->
Mesh->InsertNextLinkedCell(VTK_TRIANGLE,3,tri);
1269 vtkIdType cell1, cell2, pt3, pt4;
1277 bool proceed =
false;
1301 bool swappedForBoundary =
false;
1304 if (!pt1OnBoundary && pt2OnBoundary)
1306 vtkIdType tmp = pt1;
1309 swappedForBoundary =
true;
1314 if (!pt1OnEntityBoundary && pt2OnEntityBoundary)
1316 if (swappedForBoundary)
1320 vtkIdType tmp = pt1;
1325 vtkIdList* pt2Cells = vtkIdList::New();
1326 this->
Mesh->GetPointCells(pt2,pt2Cells);
1327 vtkIdType npt2Cells = pt2Cells->GetNumberOfIds();
1329 this->
Mesh->RemoveReferenceToCell(pt1,cell1);
1330 this->
Mesh->RemoveReferenceToCell(pt1,cell2);
1331 this->
Mesh->RemoveReferenceToCell(pt3,cell1);
1332 this->
Mesh->RemoveReferenceToCell(pt4,cell2);
1333 this->
Mesh->DeletePoint(pt2);
1334 this->
Mesh->DeleteCell(cell1);
1336 this->
Mesh->DeleteCell(cell2);
1339 this->
Mesh->ResizeCellList(pt1,npt2Cells-2);
1341 for (
int i=0; i<npt2Cells; i++)
1343 vtkIdType pt2Cell = pt2Cells->GetId(i);
1344 if (pt2Cell == cell1 || pt2Cell == cell2)
1348 this->
Mesh->AddReferenceToCell(pt1,pt2Cell);
1349 this->
Mesh->ReplaceCellPoint(pt2Cell,pt2,pt1);
1356 vtkIdList* pt2Cells = vtkIdList::New();
1357 this->
Mesh->GetPointCells(pt2,pt2Cells);
1358 vtkIdType npt2Cells = pt2Cells->GetNumberOfIds();
1360 this->
Mesh->RemoveReferenceToCell(pt1,cell1);
1361 this->
Mesh->RemoveReferenceToCell(pt3,cell1);
1362 this->
Mesh->DeletePoint(pt2);
1363 this->
Mesh->DeleteCell(cell1);
1366 this->
Mesh->ResizeCellList(pt1,npt2Cells-1);
1368 for (
int i=0; i<npt2Cells; i++)
1370 vtkIdType pt2Cell = pt2Cells->GetId(i);
1371 if (pt2Cell == cell1)
1375 this->
Mesh->AddReferenceToCell(pt1,pt2Cell);
1376 this->
Mesh->ReplaceCellPoint(pt2Cell,pt2,pt1);
1387 vtkIdType cell1, cell2, pt3, pt4;
1400 this->
Mesh->RemoveCellReference(cell1);
1401 this->
Mesh->RemoveCellReference(cell2);
1402 this->
Mesh->DeleteCell(cell1);
1405 this->
Mesh->DeleteCell(cell2);
1413 vtkIdType cell1b = this->
Mesh->InsertNextLinkedCell(VTK_TRIANGLE,3,tri);
1418 vtkIdType cell2b = this->
Mesh->InsertNextLinkedCell(VTK_TRIANGLE,3,tri);
1421 vtkIdType pt3b, pt4b;
1424 this->
Mesh->RemoveCellReference(cell1b);
1425 this->
Mesh->RemoveCellReference(cell2b);
1426 this->
Mesh->DeleteCell(cell1b);
1428 this->
Mesh->DeleteCell(cell2b);
1433 vtkIdType cell1c = this->
Mesh->InsertNextLinkedCell(VTK_TRIANGLE,3,tri);
1438 vtkIdType cell2c = this->
Mesh->InsertNextLinkedCell(VTK_TRIANGLE,3,tri);
1447 vtkIdType tri[4][3];
1464 double point1[3], point2[3], point3[3];
1466 double normal1[3], normal2[3], normal3[3], normal4[3];
1467 this->
Mesh->GetPoint(tri[0][0],point1);
1468 this->
Mesh->GetPoint(tri[0][1],point2);
1469 this->
Mesh->GetPoint(tri[0][2],point3);
1470 vtkTriangle::ComputeNormal(point1,point2,point3,normal1);
1471 this->
Mesh->GetPoint(tri[1][0],point1);
1472 this->
Mesh->GetPoint(tri[1][1],point2);
1473 this->
Mesh->GetPoint(tri[1][2],point3);
1474 vtkTriangle::ComputeNormal(point1,point2,point3,normal2);
1475 this->
Mesh->GetPoint(tri[2][0],point1);
1476 this->
Mesh->GetPoint(tri[2][1],point2);
1477 this->
Mesh->GetPoint(tri[2][2],point3);
1478 vtkTriangle::ComputeNormal(point1,point2,point3,normal3);
1479 this->
Mesh->GetPoint(tri[3][0],point1);
1480 this->
Mesh->GetPoint(tri[3][1],point2);
1481 this->
Mesh->GetPoint(tri[3][2],point3);
1482 vtkTriangle::ComputeNormal(point1,point2,point3,normal4);
1484 if (vtkMath::Dot(normal3,normal1)<0.0 || vtkMath::Dot(normal4,normal1)<0.0 || vtkMath::Dot(normal3,normal2)<0.0 || vtkMath::Dot(normal4,normal2)<0.0)
1489 if (fabs(acos(vtkMath::Dot(normal3,normal4)) - acos(vtkMath::Dot(normal1,normal2))) > this->
NormalAngleTolerance)
1499 vtkIdType cell1, cell2, pt3, pt4;
1512 vtkIdType ncells1, ncells2, ncells3, ncells4;
1514 this->
Mesh->GetPointCells(pt1,ncells1,cells);
1515 this->
Mesh->GetPointCells(pt2,ncells2,cells);
1516 this->
Mesh->GetPointCells(pt3,ncells3,cells);
1517 this->
Mesh->GetPointCells(pt4,ncells4,cells);
1519 int targetValence = 6;
1523 int currentCost = (ncells1-targetValence)*(ncells1-targetValence) + (ncells2-targetValence)*(ncells2-targetValence) + (ncells3-targetValence)*(ncells3-targetValence) + (ncells4-targetValence)*(ncells4-targetValence);
1524 int flippedCost = (ncells1-1-targetValence)*(ncells1-1-targetValence) + (ncells2-1-targetValence)*(ncells2-1-targetValence) + (ncells3+1-targetValence)*(ncells3+1-targetValence) + (ncells4+1-targetValence)*(ncells4+1-targetValence);
1526 if (flippedCost >= currentCost)
1536 vtkIdType cell1, cell2, pt3, pt4;
1549 vtkIdType tri[4][3];
1566 double point1[3], point2[3], point3[3];
1567 double direction1[3], direction2[3];
1569 double maxAngle01 = 0.0;
1570 double maxAngle23 = 0.0;
1572 for (
int n=0; n<4; n++)
1574 for (
int i=0; i<3; i++)
1576 this->
Mesh->GetPoint(tri[n][i],point1);
1577 this->
Mesh->GetPoint(tri[n][(i+1)%3],point2);
1578 this->
Mesh->GetPoint(tri[n][(i+2)%3],point3);
1579 direction1[0] = point2[0] - point1[0];
1580 direction1[1] = point2[1] - point1[1];
1581 direction1[2] = point2[2] - point1[2];
1582 vtkMath::Normalize(direction1);
1583 direction2[0] = point3[0] - point1[0];
1584 direction2[1] = point3[1] - point1[1];
1585 direction2[2] = point3[2] - point1[2];
1586 vtkMath::Normalize(direction2);
1587 double angle = acos(vtkMath::Dot(direction1,direction2));
1588 if ((n==0 || n==1) && (angle > maxAngle01))
1592 else if ((n==2 || n==3) && (angle > maxAngle23))
1609 double targetArea = 0.0;
1617 const vtkIdType *pts;
1618 this->
Mesh->GetCellPoints(cellId,npts,pts);
1619 double point1[3], point2[3], point3[3];
1620 this->
Mesh->GetPoint(pts[0],point1);
1621 this->
Mesh->GetPoint(pts[1],point2);
1622 this->
Mesh->GetPoint(pts[2],point3);
1624 vtkTriangle::TriangleCenter(point1,point2,point3,center);
1625 double projectedCenter[3];
1626 vtkIdType centerCellId;
1629 this->
Locator->FindClosestPoint(center,projectedCenter,centerCellId,subId,dist2);
1630 vtkTriangle* centerCell = vtkTriangle::SafeDownCast(vtkPolyData::SafeDownCast(this->
Locator->GetDataSet())->GetCell(centerCellId));
1631 double pcoords[3], weights[3];
1632 centerCell->EvaluatePosition(projectedCenter,NULL,subId,pcoords,dist2,weights);
1633 for (
int i=0; i<3; i++)
1635 targetArea += weights[i] * this->
TargetAreaArray->GetTuple1(centerCell->GetPointId(i));
1641 vtkErrorMacro(<<
"ElementSizeMode specified is unknown");
1644 if (targetArea > this->
MaxArea)
1648 if (targetArea < this->
MinArea)
1650 targetArea = this->MinArea;
1691 const vtkIdType *pts;
1692 this->
Mesh->GetCellPoints(cellId,npts,pts);
1699 double point1[3], point2[3], point3[3];
1700 this->
Mesh->GetPoint(tri[0],point1);
1701 this->
Mesh->GetPoint(tri[1],point2);
1702 this->
Mesh->GetPoint(tri[2],point3);
1704 double area = vtkTriangle::TriangleArea(point1,point2,point3);
1708 if (area > targetArea)
1713 double side1Squared = vtkMath::Distance2BetweenPoints(point1,point2);
1714 double side2Squared = vtkMath::Distance2BetweenPoints(point2,point3);
1715 double side3Squared = vtkMath::Distance2BetweenPoints(point3,point1);
1717 double frobeniusAspectRatio = (side1Squared + side2Squared + side3Squared) / (4.0 * sqrt(3.0) * area);
1724 if (side1Squared < side2Squared && side1Squared < side3Squared)
1729 else if (side2Squared < side1Squared && side2Squared < side3Squared)
1740 vtkIdType cell1, cell2, pt3, pt4;
1748 bool proceed =
false;
1770 vtkIdType ncells3, ncells4;
1771 ncells3 = ncells4 = 0;
1773 this->
Mesh->GetPointCells(pt3,ncells3,cells);
1776 this->
Mesh->GetPointCells(pt4,ncells4,cells);
1778 if (ncells3==3 || ncells4==3)
1784 this->
Mesh->GetPointCells(pt2,ncells2,cells);
1785 for (
int i=0; i<ncells2; i++)
1787 if (cells[i] == cell1 || cells[i] == cell2)
1791 this->
Mesh->GetCellPoints(cells[i],npts,pts);
1793 double normal1[3], normal2[3];
1794 this->
Mesh->GetPoint(pts[0],point1);
1795 this->
Mesh->GetPoint(pts[1],point2);
1796 this->
Mesh->GetPoint(pts[2],point3);
1797 vtkTriangle::ComputeNormal(point1,point2,point3,normal1);
1799 for (
int j=0; j<3; j++)
1810 this->
Mesh->GetPoint(tri[0],point1);
1811 this->
Mesh->GetPoint(tri[1],point2);
1812 this->
Mesh->GetPoint(tri[2],point3);
1813 vtkTriangle::ComputeNormal(point1,point2,point3,normal2);
1815 if (vtkMath::Dot(normal1,normal2) < 0.0)
1835 const vtkIdType *pts;
1836 this->
Mesh->GetCellPoints(cellId,npts,pts);
1843 double point1[3], point2[3], point3[3];
1844 this->
Mesh->GetPoint(tri[0],point1);
1845 this->
Mesh->GetPoint(tri[1],point2);
1846 this->
Mesh->GetPoint(tri[2],point3);
1848 double area = vtkTriangle::TriangleArea(point1,point2,point3);
1850 double side1Squared = vtkMath::Distance2BetweenPoints(point1,point2);
1851 double side2Squared = vtkMath::Distance2BetweenPoints(point2,point3);
1852 double side3Squared = vtkMath::Distance2BetweenPoints(point3,point1);
1856 if (area < targetArea)
1861 if (side1Squared >= side2Squared && side1Squared >= side3Squared)
1866 else if (side2Squared >= side1Squared && side2Squared >= side3Squared)
1871 else if (side3Squared >= side1Squared && side3Squared >= side1Squared)
1877 vtkIdType cell1, cell2, pt3, pt4;
1880 bool proceed =
false;