| 7 | using namespace PyMesh; |
| 8 | |
| 9 | MatrixFr EdgeThicknessParameterDerivative::compute() { |
| 10 | WireNetwork::Ptr wire_network = m_parameter->get_wire_network(); |
| 11 | |
| 12 | const size_t dim = m_mesh->get_dim(); |
| 13 | const size_t num_mesh_vertices = m_mesh->get_num_vertices(); |
| 14 | const size_t num_mesh_faces = m_mesh->get_num_faces(); |
| 15 | const size_t num_wire_edges = wire_network->get_num_edges(); |
| 16 | |
| 17 | assert(dim == wire_network->get_dim()); |
| 18 | |
| 19 | std::vector<bool> in_roi(num_wire_edges, false); |
| 20 | VectorI roi = m_parameter->get_roi(); |
| 21 | const size_t roi_size = roi.size(); |
| 22 | for (size_t i=0; i<roi_size; i++) { |
| 23 | in_roi[roi[i]] = true; |
| 24 | } |
| 25 | |
| 26 | MatrixFr derivative_v = MatrixFr::Zero(num_mesh_vertices, dim); |
| 27 | VectorF weights = VectorF::Zero(num_mesh_vertices); |
| 28 | |
| 29 | for (size_t i=0; i<num_mesh_faces; i++) { |
| 30 | const VectorI face = m_mesh->get_face(i); |
| 31 | const VectorF& normal = m_face_normals.row(i); |
| 32 | int source = m_face_source[i]; |
| 33 | if (source < 0) { |
| 34 | // Source is edge |
| 35 | size_t edge_idx = -source - 1; |
| 36 | assert(edge_idx >= 0 && edge_idx < num_wire_edges); |
| 37 | if (in_roi[edge_idx]) { |
| 38 | Float w0 = m_face_voronoi_areas(i, 0); |
| 39 | Float w1 = m_face_voronoi_areas(i, 1); |
| 40 | Float w2 = m_face_voronoi_areas(i, 2); |
| 41 | |
| 42 | derivative_v.row(face[0]) += w0 * normal.transpose(); |
| 43 | derivative_v.row(face[1]) += w1 * normal.transpose(); |
| 44 | derivative_v.row(face[2]) += w2 * normal.transpose(); |
| 45 | |
| 46 | weights[face[0]] += w0; |
| 47 | weights[face[1]] += w1; |
| 48 | weights[face[2]] += w2; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | for (size_t i=0; i<num_mesh_vertices; i++) { |
| 54 | if (weights[i] > 0) |
| 55 | derivative_v.row(i) /= weights[i]; |
| 56 | } |
| 57 | return derivative_v; |
| 58 | } |
nothing calls this directly
no test coverage detected