示例#1
0
class TestDistanceToMeshCubeFace():

    v, f = wavefront.read_obj('./integration/cube.obj')
    mesh_parameters = wavefront.polyhedron_parameters(v, f)
    pt = np.array([1, 0.2, 0])
    D, P, V, E, F, primitive = wavefront.distance_to_mesh(
        pt, v, f, mesh_parameters)

    D_exp = 0.5
    P_exp = np.array([0.5, 0.2, 0])
    V_exp = np.array([4, 6, 7])
    E_exp = np.array([[6, 4], [7, 6], [4, 7]])
    F_exp = np.array(6)
    primitive_exp = 'face'

    def test_distance(self):
        np.testing.assert_allclose(self.D, self.D_exp)

    def test_point(self):
        np.testing.assert_array_almost_equal(self.P, self.P_exp)

    def test_vertex(self):
        np.testing.assert_allclose(self.V, self.V_exp)

    def test_edge(self):
        np.testing.assert_allclose(self.E, self.E_exp)

    def test_face(self):
        np.testing.assert_allclose(self.F, self.F_exp)

    def test_primitive(self):
        np.testing.assert_string_equal(self.primitive, self.primitive_exp)
示例#2
0
def test_face_insertion(pt=np.array([1, 0.1, 0])):
    v, f = wavefront.read_obj('./integration/cube.obj')
    mesh_parameters = wavefront.polyhedron_parameters(v, f)
    D, P, V, E, F, primitive = wavefront.distance_to_mesh(
        pt, v, f, mesh_parameters)
    nv, nf = wavefront.face_insertion(pt, v, f, D, P, V, E, F)
    mfig = graphics.mayavi_figure()
    graphics.mayavi_addMesh(mfig, nv, nf)
示例#3
0
def test_distance_to_mesh(pt=np.random.uniform(0.8, 1.5) * sphere.rand(2)):
    """Test out the point processing function
    """
    v, f = wavefront.read_obj('./integration/cube.obj')
    mesh_parameters = wavefront.polyhedron_parameters(v, f)
    D, P, V, E, F, primitive = wavefront.distance_to_mesh(
        pt, v, f, mesh_parameters)
    plot_data(pt, v, f, D, P, V, E, F, 'Min Primitive: ' + primitive)

    return D, P, V, E, F, primitive
class TestFaceInsertion():
    v, f = wavefront.read_obj('./integration/cube.obj')
    pt = np.array([1, 0.1, 0])
    mesh_parameters = wavefront.polyhedron_parameters(v, f)
    D, P, V, E, F, primitive = wavefront.distance_to_mesh(
        pt, v, f, mesh_parameters)
    nv, nf = wavefront.face_insertion(pt, v, f, D, P, V, E, F)

    # expected solutions
    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.1,  0.]])

    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]])

    def test_vertices(self):
        np.testing.assert_allclose(self.nv, self.nv_exp)

    def test_faces(self):
        np.testing.assert_allclose(self.nf, self.nf_exp)

    def test_vertices_shape(self):
        np.testing.assert_allclose(self.nv.shape, (self.v.shape[0] + 1, 3))
示例#5
0
def test_point_insertion_random():

    num_points = 100
    nv, nf = wavefront.read_obj('./integration/cube.obj')

    # loop over random points and add them to the cube
    for ii in range(num_points):

        pt = np.random.uniform(0.6, 0.7) * sphere.rand(2)
        mesh_parameters = wavefront.polyhedron_parameters(nv, nf)
        D, P, V, E, F, primitive = wavefront.distance_to_mesh(
            pt, nv, nf, mesh_parameters)
        if primitive == 'vertex':
            nv, nf = wavefront.vertex_insertion(pt, nv, nf, D, P, V, E, F)
        elif primitive == 'edge':
            nv, nf = wavefront.edge_insertion(pt, nv, nf, D, P, V, E, F)
        elif primitive == 'face':
            nv, nf = wavefront.face_insertion(pt, nv, nf, D, P, V, E, F)

    mfig = graphics.mayavi_figure()
    mesh = graphics.mayavi_addMesh(mfig, nv, nf)