Esempio n. 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
Esempio n. 2
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
Esempio n. 3
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
    def test_face_insertion(self):
        """Point is out of view of any vertices. Need to modify the edge
        """
        pt = np.array([1, 0.1, 0])
        mesh_parameters = wavefront.polyhedron_parameters(self.v, self.f)
        nv, nf = wavefront.radius_mesh_incremental_update(pt, self.v, self.f,
                                                          mesh_parameters,
                                                          max_angle=np.deg2rad(5))
        nv_exp = self.v.copy()
        nv_exp = np.concatenate((nv_exp, pt[np.newaxis]))
        nf_exp = np.array([[0, 6, 4],
                           [0, 2, 6],
                           [0, 3, 2],
                           [0, 1, 3],
                           [2, 7, 6],
                           [2, 3, 7],
                           [4, 7, 5],
                           [0, 4, 5],
                           [0, 5, 1],
                           [1, 5, 7],
                           [1, 7, 3],
                           [4, 6, 8],
                           [6, 7, 8],
                           [7, 4, 8]])

        np.testing.assert_allclose(nv, nv_exp)
        np.testing.assert_allclose(nf, nf_exp)
    def test_edge_insertion(self):
        """Point is out of view of any vertices. Need to modify the edge
        """
        pt = np.array([1, 0, 0])
        mesh_parameters = wavefront.polyhedron_parameters(self.v, self.f)
        nv, nf = wavefront.radius_mesh_incremental_update(pt, self.v, self.f,
                                                          mesh_parameters,
                                                          max_angle=np.deg2rad(5))
        nv_exp = np.array([[-0.5, -0.5, -0.5],
                           [-0.5, -0.5,  0.5],
                           [-0.5,  0.5, -0.5],
                           [-0.5,  0.5,  0.5],
                           [0.5, -0.5, -0.5],
                           [0.5, -0.5,  0.5],
                           [0.5,  0.5, -0.5],
                           [0.5,  0.5,  0.5],
                           [1.,  0.,  0.]])
        nf_exp = np.array([[0, 6, 4],
                           [0, 2, 6],
                           [0, 3, 2],
                           [0, 1, 3],
                           [2, 7, 6],
                           [2, 3, 7],
                           [0, 4, 5],
                           [0, 5, 1],
                           [1, 5, 7],
                           [1, 7, 3],
                           [4, 6, 8],
                           [8, 6, 7],
                           [4, 8, 5],
                           [8, 7, 5]])

        np.testing.assert_allclose(nv, nv_exp)
        np.testing.assert_allclose(nf, nf_exp)
 def test_vertex_radial_change(self):
     pt = np.array([1, 1, 1])
     mesh_parameters = wavefront.polyhedron_parameters(self.v, self.f)
     nv, nf = wavefront.radius_mesh_incremental_update(pt, self.v, self.f,
                                                       mesh_parameters,
                                                       max_angle=np.deg2rad(5))
     nv_exp = self.v.copy()
     nv_exp[-1, :] = pt
     np.testing.assert_allclose(nv, nv_exp)
     np.testing.assert_allclose(nf, self.f)
Esempio n. 7
0
def test_radius_mesh_update_cube(pt=np.array([1, 0, 0])):
    """Update the mesh by modifying the radius of the closest point
    """
    # load the cube
    v, f = wavefront.read_obj('./integration/cube.obj')
    mesh_parameters = wavefront.polyhedron_parameters(v, f)
    # pick a point
    nv, nf = wavefront.radius_mesh_incremental_update(pt,
                                                      v,
                                                      f,
                                                      mesh_parameters,
                                                      max_angle=np.deg2rad(10))

    # plot the new mesh
    mfig = graphics.mayavi_figure()
    graphics.mayavi_addMesh(mfig, nv, nf)
    graphics.mayavi_addPoint(mfig, pt)
    graphics.mayavi_points3d(mfig, v, color=(0, 1, 0))

    return nv, nf
Esempio n. 8
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)