コード例 #1
0
    def fix_mesh(self, wiggle_vertices=False, verbose=False):
        """ Executes rudimentary fixing function from pymeshfix

        Good for closing holes

        :param wiggle_vertices: bool
            adds robustness for smaller components
        :param verbose: bool
        """
        if self.body_count > 1:
            tin = _meshfix.PyTMesh(verbose)
            tin.LoadArray(self.vertices, self.faces)
            tin.RemoveSmallestComponents()

            # Check if volume is 0 after isolated components have been removed
            self.vertices, self.faces = tin.ReturnArrays()

            self.fix_normals()

        if self.volume == 0:
            return

        if wiggle_vertices:
            wiggle = np.random.randn(self.n_vertices * 3).reshape(-1, 3) * 10
            self.vertices += wiggle

        self.vertices, self.faces = _meshfix.CleanFromVF(self.vertices,
                                                         self.faces,
                                                         verbose=verbose)

        self.fix_normals()
コード例 #2
0
def test_fill_small_boundaries():
    meshfix = _meshfix.PyTMesh()
    meshfix.load_file(examples.bunny_scan)
    ninit_boundaries = meshfix.boundaries()

    meshfix.fill_small_boundaries(refine=False)
    assert meshfix.boundaries() < ninit_boundaries
コード例 #3
0
def clean_from_arrays_celii(v,
                            f,
                            verbose=False,
                            joincomp=False,
                            remove_smallest_components=True,
                            clean=True):
    """
    Performs default cleaning procedure on vertex and face arrays
    Returns cleaned vertex and face arrays
    
    Parameters
    ----------
    v : numpy.ndarray
        Numpy n x 3 array of vertices
    f : numpy.ndarray
        Numpy n x 3 array of faces.
    verbose : bool, optional
        Prints progress to stdout.  Default True.
    joincomp : bool, optional
        Attempts to join nearby open components.  Default False
    remove_smallest_components : bool, optional
        Remove all but the largest isolated component from the mesh
        before beginning the repair process.  Default True.
    Examples
    --------
    >>>
    >>> CleanFromFile('inmesh.ply', 'outmesh.ply')
    """
    # Create mesh object and load from file
    tin = _meshfix.PyTMesh(verbose)
    tin.load_array(v, f)

    # repari and return vertex and face arrays
    repair_celii(tin, verbose, joincomp, remove_smallest_components, clean)
    return tin.return_arrays()
コード例 #4
0
def test_clean():
    meshfix = _meshfix.PyTMesh()
    meshfix.load_file(examples.bunny_scan)
    # v, f = meshfix.return_arrays()
    # assert f.shape[0] == bunny.n_faces

    assert meshfix.boundaries()

    meshfix.clean()
    assert not meshfix.boundaries()
コード例 #5
0
def test_load_array():
    meshfix = _meshfix.PyTMesh()
    v = bunny.points
    with pytest.raises(Exception):
        meshfix.load_array(v, bunny.faces)

    f = bunny.faces.reshape(-1, 4)[:, 1:]
    meshfix.load_array(v, f)
    v, f = meshfix.return_arrays()
    assert f.shape[0] == bunny.n_faces

    with pytest.raises(Exception):
        meshfix.load_array(v, f)
コード例 #6
0
def test_load_and_save_file(tmpdir):
    meshfix = _meshfix.PyTMesh()
    meshfix.load_file(examples.bunny_scan)

    with pytest.raises(Exception):
        meshfix.load_file(examples.bunny_scan)

    v, f = meshfix.return_arrays()
    assert f.shape[0] == bunny.n_faces

    # test saving
    filename = str(tmpdir.mkdir("tmpdir").join('tmp.ply'))
    meshfix.save_file(filename)
    new_bunny = pv.PolyData(filename)
    assert new_bunny.points.shape == v.shape
コード例 #7
0
def fix_polydata(polydata):
    vertices, faces = polydata_to_numpy(polydata)
    #  meshfix = pymeshfix.MeshFix(vertices, faces[:, 1:])
    #  meshfix.repair()
    tin = _meshfix.PyTMesh()
    tin.load_array(vertices, faces[:, 1:])

    tin.fill_small_boundaries()
    print('There are {:d} boundaries'.format(tin.boundaries()))


    # Clean (removes self intersections)
    # tin.clean(max_iters=10, inner_loops=3)
    # Check mesh for holes again
    # print('There are {:d} boundaries'.format(tin.boundaries()))

    clean_vertices, clean_faces = tin.return_arrays()
    fixed_polydata = numpy_to_polydata(clean_vertices, clean_faces)
    return fixed_polydata
コード例 #8
0
def cleanMesh(inputMesh, savePath):
    tin = _meshfix.PyTMesh()
    tin.load_file(inputMesh)
    tin.clean(max_iters=10, inner_loops=3)
    tin.select_intersecting_triangles()
    tin.save_file(savePath)
コード例 #9
0
def test_select_intersecting_triangles():
    meshfix = _meshfix.PyTMesh(quiet=0)
    meshfix.load_file(examples.bunny_scan)
    faces = meshfix.select_intersecting_triangles()
    assert faces.any()
コード例 #10
0
def test_remove_components():
    meshfix = _meshfix.PyTMesh()
    meshfix.load_file(examples.bunny_scan)
    assert meshfix.remove_smallest_components()
コード例 #11
0
        if i == 0:
            outresolution = f.shape[0]

        print("@ Save subdivided object and renew")
        finit_obj = args.dresult + '/init_subd.obj'

        if args.data[-1] == "C":
            util_mesh.subdivide_save(finit_obj, v, f, lv, lf)

        # else:
        util_mesh.save_mesh(finit_obj, v, f, lv, lf)

        if args.data[-1] == "A":
            start = time.time()
            tin = _meshfix.PyTMesh()
            tin.load_file(finit_obj)
            _meshfix.clean_from_file(finit_obj, finit_obj)
            tin.clean(max_iters=10, inner_loops=3)
            tin.save_file(finit_obj)

            # if i == 0:
            p1 = subprocess.Popen(
                ["./manifold", finit_obj, finit_obj,
                 str(outresolution)])
            p1.communicate()

            elpased_time = time.time() - start
            f = open(f"{args.dresult}/log.txt", "a")
            f.write(f"~ refine_time: {elpased_time:.4f}\n")
            f.close()