------------------------------------------------------------------------------ Handles some trivial triangulation cases. Returns 0 if cannot triangulate the current polygon. 3 and 4 points are handled with special care for concave quad.
| 1383 | // Handles some trivial triangulation cases. Returns 0 if cannot triangulate |
| 1384 | // the current polygon. 3 and 4 points are handled with special care for concave quad. |
| 1385 | int SimpleTriangulation(vtkIdList* ptIds, vtkPoints* pts, double tol2, vtkIdList* tris) |
| 1386 | { |
| 1387 | int number_of_verts = ptIds->GetNumberOfIds(); |
| 1388 | // Just output the single triangle |
| 1389 | if (number_of_verts == 3) |
| 1390 | { |
| 1391 | double x0[3], x1[3], x2[3]; |
| 1392 | bool valid = true; |
| 1393 | pts->GetPoint(0, x0); |
| 1394 | pts->GetPoint(1, x1); |
| 1395 | pts->GetPoint(2, x2); |
| 1396 | if (vtkMath::Distance2BetweenPoints(x0, x1) < tol2 || |
| 1397 | vtkMath::Distance2BetweenPoints(x1, x2) < tol2 || |
| 1398 | vtkMath::Distance2BetweenPoints(x0, x2) < tol2) |
| 1399 | { |
| 1400 | valid = false; |
| 1401 | } |
| 1402 | if (valid) |
| 1403 | { |
| 1404 | tris->SetNumberOfIds(3); |
| 1405 | std::iota(tris->begin(), tris->end(), 0); |
| 1406 | return 1; |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | // Four points are split into two triangles. Watch out for the |
| 1411 | // concave case (i.e., quad looks like a arrowhead). |
| 1412 | else if (number_of_verts == 4) |
| 1413 | { |
| 1414 | // There are only two ear cutting possibility. |
| 1415 | // This boolean |
| 1416 | bool use_d1 = true; |
| 1417 | bool concave = false; |
| 1418 | // Temporary storage of the four points |
| 1419 | double x0[3], x1[3], x2[3], x3[3]; |
| 1420 | // Quad possible diagonals with d1 and d2 |
| 1421 | double d1[3], d2[3]; |
| 1422 | // complementary vector to analyse fan |
| 1423 | double v1[3], v3[3]; |
| 1424 | // face normal |
| 1425 | double normal[3]; |
| 1426 | // local tri normal |
| 1427 | double n1[3], n2[3]; |
| 1428 | double area; |
| 1429 | |
| 1430 | pts->GetPoint(0, x0); |
| 1431 | pts->GetPoint(1, x1); |
| 1432 | pts->GetPoint(2, x2); |
| 1433 | pts->GetPoint(3, x3); |
| 1434 | // Build diagonals for ear cutting |
| 1435 | d1[0] = x2[0] - x0[0]; |
| 1436 | d1[1] = x2[1] - x0[1]; |
| 1437 | d1[2] = x2[2] - x0[2]; |
| 1438 | // |
| 1439 | d2[0] = x3[0] - x1[0]; |
| 1440 | d2[1] = x3[1] - x1[1]; |
| 1441 | d2[2] = x3[2] - x1[2]; |
| 1442 |
no test coverage detected