def main():
    args = parse_args()
    mesh = pymesh.load_mesh(args.in_mesh)
    if (args.with_rounding):
        mesh = pymesh.form_mesh(np.round(mesh.vertices, args.precision),
                                mesh.faces)
    intersecting_faces = pymesh.detect_self_intersection(mesh)

    counter = 0
    while len(intersecting_faces) > 0 and counter < args.max_iterations:
        if (args.with_rounding):
            involved_vertices = np.unique(
                mesh.faces[intersecting_faces].ravel())
            mesh.vertices_ref[involved_vertices, :] =\
                    np.round(mesh.vertices[involved_vertices, :],
                            args.precision//2)
        mesh = pymesh.resolve_self_intersection(mesh, "igl")
        mesh, __ = pymesh.remove_duplicated_faces(mesh, fins_only=True)
        if (args.with_rounding):
            mesh = pymesh.form_mesh(np.round(mesh.vertices, args.precision),
                                    mesh.faces)
        intersecting_faces = pymesh.detect_self_intersection(mesh)
        counter += 1

    if len(intersecting_faces) > 0:
        logging.warn("Resolving failed: max iteration reached!")

    pymesh.save_mesh(args.out_mesh, mesh)
Esempio n. 2
0
def main():
    args = parse_args();
    mesh = pymesh.load_mesh(args.in_mesh);
    if (args.with_rounding):
        mesh = pymesh.form_mesh(
                np.round(mesh.vertices, args.precision),
                mesh.faces);
    intersecting_faces = pymesh.detect_self_intersection(mesh);

    counter = 0;
    while len(intersecting_faces) > 0 and counter < args.max_iterations:
        if (args.with_rounding):
            involved_vertices = np.unique(mesh.faces[intersecting_faces].ravel());
            mesh.vertices_ref[involved_vertices, :] =\
                    np.round(mesh.vertices[involved_vertices, :],
                            args.precision//2);
        mesh = pymesh.resolve_self_intersection(mesh, "igl");
        mesh, __ = pymesh.remove_duplicated_faces(mesh, fins_only=True);
        if (args.with_rounding):
            mesh = pymesh.form_mesh(
                    np.round(mesh.vertices, args.precision),
                    mesh.faces);
        intersecting_faces = pymesh.detect_self_intersection(mesh);
        counter += 1;

    if len(intersecting_faces) > 0:
        logging.warn("Resolving failed: max iteration reached!");

    pymesh.save_mesh(args.out_mesh, mesh);
def main():
    args = parse_args();
    mesh = pymesh.load_mesh(args.in_mesh);
    intersecting_faces = pymesh.detect_self_intersection(mesh);

    counter = 0;
    while len(intersecting_faces) > 0 and counter < args.max_iterations:
        mesh = pymesh.resolve_self_intersection(mesh, "igl");
        mesh, __ = pymesh.remove_duplicated_faces(mesh, fins_only=True);
        intersecting_faces = pymesh.detect_self_intersection(mesh);
        counter += 1;

    if len(intersecting_faces) > 0:
        logging.warn("Resolving failed: max iteration reached!");

    pymesh.save_mesh(args.out_mesh, mesh);
Esempio n. 4
0
    def test_no_intersection(self):
        mesh_1 = generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1, 1]))
        mesh_2 = generate_box_mesh(np.array([3, 3, 3]), np.array([4, 4, 4]))
        mesh = merge_meshes((mesh_1, mesh_2))

        intersecting_faces = detect_self_intersection(mesh)
        self.assertEqual(0, len(intersecting_faces))

        output_mesh = resolve_self_intersection(mesh)
        self.assertEqual(mesh.num_vertices, output_mesh.num_vertices)
        self.assertEqual(mesh.num_faces, output_mesh.num_faces)
        self.assert_even_adj_faces(output_mesh)
def main():
    args = parse_args();
    mesh = pymesh.load_mesh(args.input_mesh);

    intersecting_faces = pymesh.detect_self_intersection(mesh);
    intersection_marker = np.zeros(mesh.num_faces);
    for i,face_pair in enumerate(intersecting_faces):
        intersection_marker[face_pair] = i+1;

    mesh.add_attribute("intersecting_faces");
    mesh.set_attribute("intersecting_faces", intersection_marker);
    pymesh.save_mesh(args.output_mesh, mesh, "intersecting_faces");
def main():
    args = parse_args()
    mesh = pymesh.load_mesh(args.input_mesh)

    intersecting_faces = pymesh.detect_self_intersection(mesh)
    intersection_marker = np.zeros(mesh.num_faces)
    for i, face_pair in enumerate(intersecting_faces):
        intersection_marker[face_pair] = i + 1

    mesh.add_attribute("intersecting_faces")
    mesh.set_attribute("intersecting_faces", intersection_marker)
    pymesh.save_mesh(args.output_mesh, mesh, "intersecting_faces")
def extract_intersecting_faces(mesh, selection):
    face_pairs = pymesh.detect_self_intersection(mesh);
    selected_faces = np.zeros(mesh.num_faces, dtype=bool);

    if selection is not None:
        selected_pairs = np.any(face_pairs == selection, axis=1);
        face_pairs = face_pairs[selected_pairs];

    selected_faces[face_pairs[:,0]] = True;
    selected_faces[face_pairs[:,1]] = True;
    faces = mesh.faces[selected_faces];
    intersecting_mesh = pymesh.form_mesh(mesh.vertices, faces);
    intersecting_mesh, __ = pymesh.remove_isolated_vertices(intersecting_mesh);
    return intersecting_mesh;
Esempio n. 8
0
    def test_no_intersection(self):
        mesh_1 = generate_box_mesh(
                np.array([0, 0, 0]), np.array([1, 1, 1]));
        mesh_2 = generate_box_mesh(
                np.array([3, 3, 3]), np.array([4, 4, 4]));
        mesh = merge_meshes((mesh_1, mesh_2));

        intersecting_faces = detect_self_intersection(mesh);
        self.assertEqual(0, len(intersecting_faces));

        output_mesh = resolve_self_intersection(mesh);
        self.assertEqual(mesh.num_vertices, output_mesh.num_vertices);
        self.assertEqual(mesh.num_faces, output_mesh.num_faces);
        self.assert_even_adj_faces(output_mesh);
def extract_intersecting_faces(mesh, selection):
    face_pairs = pymesh.detect_self_intersection(mesh)
    selected_faces = np.zeros(mesh.num_faces, dtype=bool)

    if selection is not None:
        selected_pairs = np.any(face_pairs == selection, axis=1)
        face_pairs = face_pairs[selected_pairs]

    selected_faces[face_pairs[:, 0]] = True
    selected_faces[face_pairs[:, 1]] = True
    faces = mesh.faces[selected_faces]
    intersecting_mesh = pymesh.form_mesh(mesh.vertices, faces)
    intersecting_mesh, __ = pymesh.remove_isolated_vertices(intersecting_mesh)
    return intersecting_mesh
    def execute(self, context):
        scene = context.scene
        pymesh_props = scene.pymesh

        obj_a = context.active_object
        mesh_a = import_object(context, obj_a)
        pymesh_si = pymesh.detect_self_intersection(mesh_a)
        if pymesh_si.size == 0:
            self.report({'ERROR'}, "This mesh has no self-intersections")
            return {'CANCELLED'}
        pymesh_r = pymesh.resolve_self_intersection(mesh_a)
        off_name = "Py.SI." + obj_a.name
        mesh_r = export_mesh(context, pymesh_r, off_name)
        add_to_scene(context, mesh_r)

        return {'FINISHED'}
Esempio n. 11
0
    def test_chain(self):
        input_mesh = generate_box_mesh(np.array([0, 0, 0]), np.array([1, 1,
                                                                      1]))
        path = np.array([
            [0.0, 0.0, 0.0],
            [1.0, 0.0, 0.0],
            [1.0, 1.0, 0.0],
            [0.0, 1.0, 0.0],
        ])

        output_mesh = minkowski_sum(input_mesh, path)
        self.assertTrue(output_mesh.is_closed())
        self.assertTrue(output_mesh.is_oriented())
        self.assertEqual(1, output_mesh.num_components)

        self_intersections = detect_self_intersection(output_mesh)
        self.assertEqual(0, len(self_intersections))
Esempio n. 12
0
    def test_chain(self):
        input_mesh = generate_box_mesh(
                np.array([0, 0, 0]), np.array([1, 1, 1]));
        path = np.array([
            [0.0, 0.0, 0.0],
            [1.0, 0.0, 0.0],
            [1.0, 1.0, 0.0],
            [0.0, 1.0, 0.0],
            ]);

        output_mesh = minkowski_sum(input_mesh, path);
        self.assertTrue(output_mesh.is_closed());
        self.assertTrue(output_mesh.is_oriented());
        self.assertEqual(1, output_mesh.num_components);

        self_intersections = detect_self_intersection(output_mesh);
        self.assertEqual(0, len(self_intersections));
Esempio n. 13
0
def print_self_intersection_info(mesh, info):
    if mesh.vertex_per_face == 4:
        print_red("Converting quad to tri for self-intersection check.")
        mesh = pymesh.quad_to_tri(mesh)

    if mesh.num_vertices == 0 or mesh.num_faces == 0:
        num_intersections = 0
        num_coplanar_intersecting_faces = 0
    else:
        intersecting_faces = pymesh.detect_self_intersection(mesh)
        num_intersections = len(intersecting_faces)
        intersect_and_coplanar = coplanar_analysis(mesh, intersecting_faces)
        num_coplanar_intersecting_faces = len(intersect_and_coplanar)
    info["self_intersect"] = num_intersections > 0
    info["num_self_intersections"] = num_intersections
    info["num_coplanar_intersecting_faces"] = num_coplanar_intersecting_faces
    print_property("self intersect", info["self_intersect"], False)
    if num_intersections > 0:
        print_property("num self intersections", num_intersections, 0)
        print_property("num coplanar intersecting faces",
                       num_coplanar_intersecting_faces, 0)
Esempio n. 14
0
def print_self_intersection_info(mesh, info):
    if mesh.vertex_per_face == 4:
        print_red("Converting quad to tri for self-intersection check.");
        mesh = pymesh.quad_to_tri(mesh);

    if mesh.num_vertices == 0 or mesh.num_faces == 0:
        num_intersections = 0;
        num_coplanar_intersecting_faces = 0;
    else:
        intersecting_faces = pymesh.detect_self_intersection(mesh);
        num_intersections = len(intersecting_faces);
        intersect_and_coplanar = coplanar_analysis(mesh, intersecting_faces);
        num_coplanar_intersecting_faces = len(intersect_and_coplanar);
    info["self_intersect"] = num_intersections > 0;
    info["num_self_intersections"] = num_intersections;
    info["num_coplanar_intersecting_faces"] = num_coplanar_intersecting_faces;
    print_property("self intersect", info["self_intersect"], False);
    if num_intersections > 0:
        print_property("num self intersections", num_intersections, 0);
        print_property("num coplanar intersecting faces",
                num_coplanar_intersecting_faces, 0);
Esempio n. 15
0
 def assert_self_intersect(self, mesh):
     """ Ensure there is at least 1 pair of faces are intersecting.
     """
     intersecting_faces = detect_self_intersection(mesh);
     self.assertLess(0, len(intersecting_faces));
Esempio n. 16
0
 def assert_self_intersect(self, mesh):
     """ Ensure there is at least 1 pair of faces are intersecting.
     """
     intersecting_faces = detect_self_intersection(mesh)
     self.assertLess(0, len(intersecting_faces))
Esempio n. 17
0
 def assert_no_self_intersect(self, mesh):
     """ Ensure the mesh contains no self-intersection.
     """
     intersecting_faces = detect_self_intersection(mesh)
     self.assertEqual(0, len(intersecting_faces))
Esempio n. 18
0
 def assert_no_self_intersect(self, mesh):
     """ Ensure the mesh contains no self-intersection.
     """
     intersecting_faces = detect_self_intersection(mesh);
     self.assertEqual(0, len(intersecting_faces));