Return true if all faces of the cell are planar. The cell is expected to be a vtkVoxel instance.
| 65 | // Return true if all faces of the cell are planar. |
| 66 | // The cell is expected to be a vtkVoxel instance. |
| 67 | bool AreAllFacesPlanar(vtkCell* cell) |
| 68 | { |
| 69 | bool allFacesArePlanar = true; |
| 70 | |
| 71 | std::array<std::array<double, 3>, POLY_FACES_POINTS_NB> facePoints{}; |
| 72 | |
| 73 | // For each face |
| 74 | for (int faceId = 0, canonicalId = 0; faceId < ::POLY_FACES_NB; faceId++) |
| 75 | { |
| 76 | // Retrieve face points |
| 77 | for (int i = 0; i < ::POLY_FACES_POINTS_NB; i++, canonicalId++) |
| 78 | { |
| 79 | auto point = cell->GetPoints()->GetPoint(::CANONICAL_FACES[canonicalId]); |
| 80 | facePoints[i][0] = point[0]; |
| 81 | facePoints[i][1] = point[1]; |
| 82 | facePoints[i][2] = point[2]; |
| 83 | } |
| 84 | |
| 85 | // Test if 3 vectors of the face are coplanar |
| 86 | std::array<double, 3> v1{}; |
| 87 | v1[0] = facePoints[1][0] - facePoints[0][0]; |
| 88 | v1[1] = facePoints[1][1] - facePoints[0][1]; |
| 89 | v1[2] = facePoints[1][2] - facePoints[0][2]; |
| 90 | |
| 91 | std::array<double, 3> v2{}; |
| 92 | v2[0] = facePoints[2][0] - facePoints[0][0]; |
| 93 | v2[1] = facePoints[2][1] - facePoints[0][1]; |
| 94 | v2[2] = facePoints[2][2] - facePoints[0][2]; |
| 95 | |
| 96 | std::array<double, 3> v3{}; |
| 97 | v3[0] = facePoints[3][0] - facePoints[0][0]; |
| 98 | v3[1] = facePoints[3][1] - facePoints[0][1]; |
| 99 | v3[2] = facePoints[3][2] - facePoints[0][2]; |
| 100 | |
| 101 | double cross[3] = { 0. }; |
| 102 | vtkMath::Cross(v1, v2, cross); |
| 103 | |
| 104 | if (!vtkMathUtilities::FuzzyCompare(vtkMath::Dot(cross, v3), 0.)) |
| 105 | { |
| 106 | allFacesArePlanar = false; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return allFacesArePlanar; |
| 112 | } |
| 113 | |
| 114 | // Given contour values, find a "valid" epsilon value, allowing to discriminate values |
| 115 | // by fuzzy comparison. Returned espilon correspond to the min difference between contour |
no test coverage detected