| 8 | using namespace PyMesh; |
| 9 | |
| 10 | void FaceIncircleRadiusAttribute::compute_from_mesh(Mesh& mesh) { |
| 11 | const size_t num_faces = mesh.get_num_faces(); |
| 12 | const size_t num_vertex_per_face = mesh.get_vertex_per_face(); |
| 13 | if (num_vertex_per_face != 3) { |
| 14 | throw NotImplementedError("Incircle only exists for triangles."); |
| 15 | } |
| 16 | |
| 17 | if (!mesh.has_attribute("edge_length")) { |
| 18 | mesh.add_attribute("edge_length"); |
| 19 | } |
| 20 | if (!mesh.has_attribute("face_area")) { |
| 21 | mesh.add_attribute("face_area"); |
| 22 | } |
| 23 | |
| 24 | const VectorF& edge_length = mesh.get_attribute("edge_length"); |
| 25 | const VectorF& areas = mesh.get_attribute("face_area"); |
| 26 | |
| 27 | VectorF& radii = m_values; |
| 28 | radii = VectorF::Zero(num_faces); |
| 29 | |
| 30 | for (size_t i=0; i<num_faces; i++) { |
| 31 | Float circumference = edge_length.segment( |
| 32 | i*num_vertex_per_face, num_vertex_per_face).sum(); |
| 33 | Float area = areas[i]; |
| 34 | if (circumference != 0) |
| 35 | radii[i] = 2.0 * area / circumference; |
| 36 | else |
| 37 | radii[i] = 0.0; |
| 38 | } |
| 39 | } |
| 40 |
nothing calls this directly
no test coverage detected