Browse Source

Added more unit tests for mesh boolean.

Former-commit-id: 7a5b2605954a9113c074bb7628e54c2c43f3a7a5
Qingnan Zhou 9 years ago
parent
commit
497ff5bbc1

+ 56 - 0
tests/data/boolean_minus_test_cube.obj

@@ -0,0 +1,56 @@
+# Alias OBJ Model File
+# Exported from SketchUp, (c) 2000-2012 Trimble Navigation Limited
+# File units = inches
+
+mtllib orig.mtl
+
+g Mesh1 Model
+
+usemtl FrontColor
+v 1 0 -0
+vt -1 0
+vn 0 -1 -0
+v 0 0 1
+vt 0 -1
+v 0 0 -0
+vt 0 0
+f 1/1/1 2/2/1 3/3/1
+
+v 1 0 1
+vt -1 -1
+f 2/2/1 1/1/1 4/4/1
+
+vn 1 0 -0
+v 1 1 1
+vt -1 1
+f 1/3/2 5/5/2 4/1/2
+
+v 1 1 -0
+vt 0 1
+f 5/5/2 1/3/2 6/6/2
+
+vn 0 0 -1
+v 0 1 -0
+f 1/1/3 7/6/3 6/5/3
+
+f 7/6/3 1/1/3 3/3/3
+
+vt 1 0
+vn -1 0 -0
+f 2/7/4 7/6/4 3/3/4
+
+v 0 1 1
+vt 1 1
+f 7/6/4 2/7/4 8/8/4
+
+vn 0 0 1
+f 2/3/5 5/8/5 8/6/5
+
+f 5/8/5 2/3/5 4/7/5
+
+vt 1 -1
+vn 0 1 -0
+f 5/9/6 7/3/6 8/2/6
+
+f 7/3/6 5/9/6 6/7/6
+

+ 67 - 0
tests/data/boolean_minus_test_green.obj

@@ -0,0 +1,67 @@
+# Alias OBJ Model File
+# Exported from SketchUp, (c) 2000-2012 Trimble Navigation Limited
+# File units = inches
+
+mtllib 1_2ex.mtl
+
+g Mesh1 Model
+
+usemtl FrontColor
+v 0 0.625 0.375
+vt 0.375 0.625
+vn -1 0 -0
+v 0 0.375 0.625
+vt 0.625 0.375
+v 0 0.625 0.625
+vt 0.625 0.625
+f 1/1/1 2/2/1 3/3/1
+
+v 0 0.375 0.375
+vt 0.375 0.375
+f 2/2/1 1/1/1 4/4/1
+
+vt 0 0.625
+vn 0 0 -1
+v 2 0.375 0.375
+vt -2 0.375
+vt 0 0.375
+f 1/5/2 5/6/2 4/7/2
+
+v 2 0.625 0.375
+vt -2 0.625
+f 5/6/2 1/5/2 6/8/2
+
+vt 0 -0.375
+vn 0 1 -0
+v 2 0.625 0.625
+vt 2 -0.625
+vt 2 -0.375
+f 1/9/3 7/10/3 6/11/3
+
+vt 0 -0.625
+f 7/10/3 1/9/3 3/12/3
+
+vn 0 0 1
+vt 2 0.625
+f 2/7/4 7/13/4 3/5/4
+
+v 2 0.375 0.625
+vt 2 0.375
+f 7/13/4 2/7/4 8/14/4
+
+vn 0 -1 -0
+vt -2 -0.375
+vt -2 -0.625
+f 2/12/5 5/15/5 8/16/5
+
+f 5/15/5 2/12/5 4/9/5
+
+vt -0.375 0.375
+vn 1 0 -0
+vt -0.625 0.625
+vt -0.625 0.375
+f 5/17/6 7/18/6 8/19/6
+
+vt -0.375 0.625
+f 7/18/6 5/17/6 6/20/6
+

+ 78 - 3
tests/include/igl/boolean/mesh_boolean.cpp

@@ -1,8 +1,52 @@
 #include <test_common.h>
 
+#include <vector>
+
 #include <igl/boolean/mesh_boolean.h>
 #include <igl/boolean/MeshBooleanType.h>
 #include <igl/exterior_edges.h>
+#include <igl/is_vertex_manifold.h>
+
+namespace mesh_boolean_test {
+
+    template<typename DerivedF>
+    void assert_no_exterior_edges(
+            const Eigen::PlainObjectBase<DerivedF>& F) {
+        Eigen::MatrixXi Eb;
+        igl::exterior_edges(F, Eb);
+
+        ASSERT_EQ(0, Eb.rows());
+    }
+
+    template<typename DerivedV, typename DerivedF>
+    void assert_is_manifold(
+            const Eigen::PlainObjectBase<DerivedV>& V,
+            const Eigen::PlainObjectBase<DerivedF>& F) {
+        Eigen::MatrixXi B;
+        ASSERT_TRUE(igl::is_vertex_manifold(F, B));
+        ASSERT_TRUE(igl::is_edge_manifold(V, F));
+    }
+
+    template<typename DerivedV, typename DerivedF>
+    void assert_genus_eq(
+            const Eigen::PlainObjectBase<DerivedV>& V,
+            const Eigen::PlainObjectBase<DerivedF>& F,
+            const int genus) {
+        const int num_vertices = V.rows();
+        const int num_faces = F.rows();
+
+        Eigen::Matrix<
+            typename DerivedF::Scalar,
+            Eigen::Dynamic,
+            Eigen::Dynamic>
+            E, uE, EMAP;
+        std::vector<std::vector<size_t> > uE2E;
+        igl::unique_edge_map(F, E, uE, EMAP, uE2E);
+
+        const int num_edges = uE.rows();
+        const int euler = num_vertices - num_edges + num_faces;
+        ASSERT_EQ(euler, 2 - 2 * genus);
+    }
 
 TEST(MeshBoolean, TwoCubes) {
     Eigen::MatrixXd V1;
@@ -19,8 +63,39 @@ TEST(MeshBoolean, TwoCubes) {
             igl::boolean::MESH_BOOLEAN_TYPE_UNION,
             Vo, Fo);
 
-    Eigen::MatrixXi Eb;
-    igl::exterior_edges(Fo, Eb);
+    assert_no_exterior_edges(Fo);
+    assert_is_manifold(Vo, Fo);
+    assert_genus_eq(Vo, Fo, 0);
+}
+
+TEST(MeshBoolean, MinusTest) {
+    // Many thanks to Eric Yao for submitting this test case.
+    Eigen::MatrixXd V1, V2, Vo;
+    Eigen::MatrixXi F1, F2, Fo;
+    test_common::load_mesh("boolean_minus_test_cube.obj", V1, F1);
+    test_common::load_mesh("boolean_minus_test_green.obj", V2, F2);
+
+    igl::boolean::mesh_boolean(V1, F1, V2, F2,
+            igl::boolean::MESH_BOOLEAN_TYPE_MINUS,
+            Vo, Fo);
+
+    assert_no_exterior_edges(Fo);
+    assert_is_manifold(Vo, Fo);
+    assert_genus_eq(Vo, Fo, 1);
+}
+
+TEST(MeshBoolean, IntersectWithSelf) {
+    Eigen::MatrixXd V1, Vo;
+    Eigen::MatrixXi F1, Fo;
+    test_common::load_mesh("cube.obj", V1, F1);
+
+    igl::boolean::mesh_boolean(V1, F1, V1, F1,
+            igl::boolean::MESH_BOOLEAN_TYPE_INTERSECT,
+            Vo, Fo);
+
+    assert_no_exterior_edges(Fo);
+    assert_is_manifold(Vo, Fo);
+    assert_genus_eq(Vo, Fo, 0);
+}
 
-    ASSERT_EQ(0, Eb.rows());
 }