Exemplo n.º 1
0
class test_load_ply:
    from cp.tools.io import load_ply
    v, f = load_ply(
        os.path.join(
            os.path.split(os.path.abspath(__file__))[0], "data",
            "Armadillo_ascii_converted_using_meshlab.ply"))
    npt.assert_equal(f.max(), len(v) - 1)
    npt.assert_equal(np.setdiff1d(f.ravel(), np.arange(len(v))), np.array([]))

    v2, f2 = load_ply(
        os.path.join(
            os.path.split(os.path.abspath(__file__))[0], "data",
            "Armadillo.ply"))
    # big absolute tolerance because meshlab lost many digits when
    # converting to ascii
    npt.assert_allclose(v2, v, atol=1e-4)
    npt.assert_allclose(f2, f)
Exemplo n.º 2
0
    def __init__(self, ff=None):
        '''
        Constructor
        '''
        if ff is None:
            ff = open('Armadillo.ply')
        v, f = load_ply(ff)
        ma = v.max()
        mi = v.min()
        med = (ma + mi) / 2
        v -= med
        v /= (ma - mi) / (2 * 1.7)

        self.v = v
        self.f = f
        self.meshcp = MeshCP(v, f)
Exemplo n.º 3
0
 def __init__(self,ff = None):
     '''
     Constructor
     '''
     if ff is None:
         ff = open('Armadillo.ply')
     v,f = load_ply(ff)
     ma = v.max()
     mi = v.min()
     med = (ma+mi)/2
     v -= med
     v /= (ma-mi)/(2*1.7)
     
     
     self.v = v
     self.f = f
     self.meshcp = MeshCP(v,f)
from cp.surfaces import Mesh
# Since our mesh is a sphere, we'll take advantage of its
# parametric_plot method
from cp.surfaces import Sphere
from cp.tools.io import load_ply
from cp.build_matrices import build_interp_matrix, build_diff_matrix
# TODO: move coordinate_transform out of cp.surfaces (maybe to
# cp.tools?)
from cp.surfaces.coordinate_transform import cart2sph


PLOT = True

# Load vertices and faces, and instatiate surface
v, f = load_ply('cp/tests/data/sphere_refined.ply')
m = Mesh(v, f)

p = 3
diff_stencil_arm = 1
dim = 3

index, distance, grid, dx = m.grid(num_blocks_per_dim=41,
                                   levels=1,
                                   p=p,
                                   diff_stencil_arm=diff_stencil_arm)
cp, dist, _, _ = m.closest_point(grid, index)

# The points in `grid` can be thought to be a subset of a virtual grid
# (for instance, the result of meshgrid). `ll` is the lower left
# corner of such virtual grid, and `ur` the upper right corner. The
Exemplo n.º 5
0
    Output
    ------
    cp : array of shape (npoints, 4)
         Coordinates of the closest points, and squareddistance from
         its original point.
         cp[:, 0] is the squared distance (redundant information)
         cp[:, 1:] are the coordinates of the closest points
    """
    N = len(index_cp)
    cp = np.empty((N, 4), dtype=np.float64)
    for i, (index_of_cp, point) in enumerate(izip(index_cp, grid_fine)):
        face_indices_that_share_that_vertex = vertex2faces[index_of_cp]
        # Much faster using np.take than fancy indexing
        possible_faces = np.take(faces,
                                 face_indices_that_share_that_vertex,
                                 axis=0)
        # Cythonize this and it gets way faster
        cp[i] = FindClosestPointToTriSet(point[0], point[1], point[2],
                                         possible_faces, vertices)
    return cp


if __name__ == '__main__':
    v, f = load_ply('cp/tests/data/Armadillo.ply')
    m = Mesh(v, f)

    v2, f2 = load_ply('cp/tests/data/eight_refined.ply')
    m2 = Mesh(v2, f2)
    index, grid, distance, dx = m2.grid(num_blocks=10, levels=4)
    cp, dist, _, _ = m2.closest_point(index, grid)
Exemplo n.º 6
0
                   Given by build_vertices2faces
    vertices, faces : arrays, given by load_ply

    Output
    ------
    cp : array of shape (npoints, 4)
         Coordinates of the closest points, and squareddistance from
         its original point.
         cp[:, 0] is the squared distance (redundant information)
         cp[:, 1:] are the coordinates of the closest points
    """
    N = len(index_cp)
    cp = np.empty((N, 4), dtype=np.float64)
    for i, (index_of_cp, point) in enumerate(izip(index_cp, grid_fine)):
        face_indices_that_share_that_vertex = vertex2faces[index_of_cp]
        # Much faster using np.take than fancy indexing
        possible_faces = np.take(faces, face_indices_that_share_that_vertex, axis=0)
        # Cythonize this and it gets way faster
        cp[i] = FindClosestPointToTriSet(point[0], point[1], point[2], possible_faces, vertices)
    return cp


if __name__ == "__main__":
    v, f = load_ply("cp/tests/data/Armadillo.ply")
    m = Mesh(v, f)

    v2, f2 = load_ply("cp/tests/data/eight_refined.ply")
    m2 = Mesh(v2, f2)
    index, grid, distance, dx = m2.grid(num_blocks=10, levels=4)
    cp, dist, _, _ = m2.closest_point(index, grid)