Beispiel #1
0
def test_radius_sphere_into_ellipse():
    """See if we can turn a sphere into an ellipse by changing the radius of
    vertices
    
    The point cloud (ellipse) should have more points than the initial mesh.
    When the intial mesh is coarse the resulting mesh will also be heavily faceted, but this will avoid the big holes, and large changes in depth
    """

    # define the sphere
    vs, fs = wavefront.ellipsoid_mesh(1, 1, 1, density=10, subdivisions=0)
    ve, fe = wavefront.ellipsoid_mesh(2, 3, 4, density=10, subdivisions=2)

    mfig = graphics.mayavi_figure()
    mesh = graphics.mayavi_addMesh(mfig, vs, fs)
    ms = mesh.mlab_source
    # in a loop add each vertex of the ellipse into the sphere mesh
    for pt in ve:
        vs, fs = wavefront.radius_mesh_incremental_update(pt, vs, fs)
        ms.reset(x=vs[:, 0], y=vs[:, 1], z=vs[:, 2], triangles=fs)

    input('Enter for mesh subdivision')
    vs, fs = wavefront.mesh_subdivide(vs, fs, 1)
    ms.reset(x=vs[:, 0], y=vs[:, 1], z=vs[:, 2], triangles=fs)

    input('Enter for second round of updating')
    ve, fe = wavefront.ellipsoid_mesh(2, 3, 4, density=20, subdivisions=2)
    for pt in ve:
        vs, fs = wavefront.radius_mesh_incremental_update(pt, vs, fs)
        ms.reset(x=vs[:, 0], y=vs[:, 1], z=vs[:, 2], triangles=fs)

    return vs, fs
Beispiel #2
0
def cube_into_sphere(img_path):
    """Transform a cube into a sphere
    """
    vc, fc = wavefront.read_obj('./integration/cube.obj')
    vs, fs = wavefront.ellipsoid_mesh(2, 2, 2, density=10, subdivisions=0)

    mfig = graphics.mayavi_figure(offscreen=True)
    mesh = graphics.mayavi_addMesh(mfig, vc, fc)
    ms = mesh.mlab_source
    index = 0
    for ii in range(5):
        for jj, pt in enumerate(vs):
            index += 1
            filename = os.path.join(
                img_path, 'cube_sphere_' + str(index).zfill(6) + '.jpg')
            graphics.mlab.savefig(filename, magnification=4)
            mesh_param = wavefront.polyhedron_parameters(vc, fc)
            vc, fc = wavefront.radius_mesh_incremental_update(
                pt, vc, fc, mesh_param, max_angle=np.deg2rad(5))
            ms.reset(x=vc[:, 0], y=vc[:, 1], z=vc[:, 2], triangles=fc)
            graphics.mayavi_addPoint(mfig, pt)

        vc, fc = wavefront.mesh_subdivide(vc, fc, 1)
        ms.reset(x=vc[:, 0], y=vc[:, 1], z=vc[:, 2], triangles=fc)

    return 0
Beispiel #3
0
def sphere_into_ellipsoid(img_path):
    """See if we can turn a sphere into an ellipse by changing the radius of
    vertices
    
    The point cloud (ellipse) should have more points than the initial mesh.
    When the intial mesh is coarse the resulting mesh will also be heavily faceted, but this will avoid the big holes, and large changes in depth
    """

    # define the sphere
    vs, fs = wavefront.ellipsoid_mesh(1, 1, 1, density=20, subdivisions=1)
    ve, fe = wavefront.ellipsoid_mesh(2, 3, 4, density=20, subdivisions=1)

    mfig = graphics.mayavi_figure(offscreen=True)
    mesh = graphics.mayavi_addMesh(mfig, vs, fs)
    ms = mesh.mlab_source
    index = 0
    # in a loop add each vertex of the ellipse into the sphere mesh
    for jj in range(2):
        for ii, pt in enumerate(ve):
            index += 1
            filename = os.path.join(
                img_path, 'sphere_ellipsoid_' + str(index).zfill(6) + '.jpg')
            graphics.mlab.savefig(filename, magnification=4)
            mesh_param = wavefront.polyhedron_parameters(vs, fs)
            vs, fs = wavefront.radius_mesh_incremental_update(
                pt, vs, fs, mesh_param, max_angle=np.deg2rad(10))
            ms.reset(x=vs[:, 0], y=vs[:, 1], z=vs[:, 2], triangles=fs)
            graphics.mayavi_addPoint(mfig, pt)

        vs, fs = wavefront.mesh_subdivide(vs, fs, 1)
        ms.reset(x=vs[:, 0], y=vs[:, 1], z=vs[:, 2], triangles=fs)

    return 0
Beispiel #4
0
def test_radius_cube_into_sphere():
    """Transform a cube into a sphere
    """
    vc, fc = wavefront.read_obj('./integration/cube.obj')
    vs, fs = wavefront.ellipsoid_mesh(2, 2, 2, density=10, subdivisions=0)

    mfig = graphics.mayavi_figure()
    mesh = graphics.mayavi_addMesh(mfig, vc, fc)
    graphics.mayavi_points3d(mfig, vc, color=(0, 1, 0))
    ms = mesh.mlab_source
    for ii in range(5):
        for pt in vs:
            mesh_param = wavefront.polyhedron_parameters(vc, fc)
            vc, fc = wavefront.radius_mesh_incremental_update(
                pt, vc, fc, mesh_param, max_angle=np.deg2rad(45))
            ms.reset(x=vc[:, 0], y=vc[:, 1], z=vc[:, 2], triangles=fc)
            graphics.mayavi_addPoint(mfig, pt)

        input('Mesh subdivison')
        vc, fc = wavefront.mesh_subdivide(vc, fc, 1)
        ms.reset(x=vc[:, 0], y=vc[:, 1], z=vc[:, 2], triangles=fc)
 def test_mesh_subdivision_butterfly(self):
     v, f = wavefront.mesh_subdivide(self.v, self.f, 1, 'butterfly')
     np.testing.assert_allclose(v.shape[0], 1146)
     np.testing.assert_allclose(f.shape[0], self.f.shape[0] * 4)