| 40 | } |
| 41 | |
| 42 | void cut_face( |
| 43 | const Vector2F& bbox_min, |
| 44 | const Vector2F& bbox_max, |
| 45 | const Vector2F& p0, |
| 46 | const Vector2F& p1, |
| 47 | const Vector2F& p2, |
| 48 | MatrixFr& vertices, MatrixIr& faces) { |
| 49 | MatrixFr box_vertices(4,2); |
| 50 | box_vertices << bbox_min[0], bbox_min[1], |
| 51 | bbox_max[0], bbox_min[1], |
| 52 | bbox_max[0], bbox_max[1], |
| 53 | bbox_min[0], bbox_max[1]; |
| 54 | MatrixIr box_faces(2, 3); |
| 55 | box_faces << 0, 1, 2, |
| 56 | 0, 2, 3; |
| 57 | |
| 58 | MatrixFr tri_vertices(3, 2); |
| 59 | tri_vertices << p0.transpose(), |
| 60 | p1.transpose(), |
| 61 | p2.transpose(); |
| 62 | MatrixIr tri_faces(1, 3); |
| 63 | tri_faces << 0, 1, 2; |
| 64 | |
| 65 | BooleanEngine::Ptr boolean_engine = BooleanEngine::create("clipper"); |
| 66 | boolean_engine->set_mesh_1(tri_vertices, tri_faces); |
| 67 | boolean_engine->set_mesh_2(box_vertices, box_faces); |
| 68 | boolean_engine->compute_intersection(); |
| 69 | vertices = boolean_engine->get_vertices(); |
| 70 | faces = boolean_engine->get_faces(); |
| 71 | } |
| 72 | |
| 73 | template<typename M, typename T> |
| 74 | void append(const M& vertices, std::list<T>& flattened) { |
no test coverage detected