| 24 | } |
| 25 | |
| 26 | VectorF FaceVoronoiAreaAttribute::compute_triangle_voronoi_area( |
| 27 | Mesh& mesh, size_t face_idx) { |
| 28 | size_t dim = mesh.get_dim(); |
| 29 | VectorI face = mesh.get_face(face_idx); |
| 30 | |
| 31 | Vector3F v0 = Vector3F::Zero(); |
| 32 | Vector3F v1 = Vector3F::Zero(); |
| 33 | Vector3F v2 = Vector3F::Zero(); |
| 34 | |
| 35 | v0.segment(0, dim) = mesh.get_vertex(face[0]); |
| 36 | v1.segment(0, dim) = mesh.get_vertex(face[1]); |
| 37 | v2.segment(0, dim) = mesh.get_vertex(face[2]); |
| 38 | |
| 39 | Vector3F e0 = v2 - v1; |
| 40 | Vector3F e1 = v0 - v2; |
| 41 | Vector3F e2 = v1 - v0; |
| 42 | |
| 43 | Float double_area = e2.cross(-e1).norm(); |
| 44 | |
| 45 | Float cot_0 = e2.dot(-e1) / e2.cross(-e1).norm(); |
| 46 | Float cot_1 = e0.dot(-e2) / e0.cross(-e2).norm(); |
| 47 | Float cot_2 = e1.dot(-e0) / e1.cross(-e0).norm(); |
| 48 | |
| 49 | // Handle obtuse triangles. |
| 50 | if (cot_0 < 0.0) { |
| 51 | return Vector3F(0.5, 0.25, 0.25) * double_area * 0.5; |
| 52 | } else if (cot_1 < 0.0) { |
| 53 | return Vector3F(0.25, 0.5, 0.25) * double_area * 0.5; |
| 54 | } else if (cot_2 < 0.0) { |
| 55 | return Vector3F(0.25, 0.25, 0.5) * double_area * 0.5; |
| 56 | } |
| 57 | |
| 58 | Float sq_l0 = e0.squaredNorm(); |
| 59 | Float sq_l1 = e1.squaredNorm(); |
| 60 | Float sq_l2 = e2.squaredNorm(); |
| 61 | |
| 62 | return Vector3F( |
| 63 | sq_l1 * cot_1 + sq_l2 * cot_2, |
| 64 | sq_l0 * cot_0 + sq_l2 * cot_2, |
| 65 | sq_l1 * cot_1 + sq_l0 * cot_0) / 8.0; |
| 66 | } |
nothing calls this directly
no test coverage detected