Пример #1
0
def save_triangulated(filename, eptm):

    vertices, faces, _ = eptm.triangular_mesh(eptm.coords)
    write_mesh(filename,
               vertices=vertices,
               faces=faces,
               normals=None,
               texcoords=None,
               overwrite=True)
    logger.info('Saved %s as a trianglulated .OBJ file', eptm.identifier)
Пример #2
0
def save_junction_mesh(filename, eptm):

    vertices, faces, normals = eptm.vertex_mesh(eptm.coords,
                                                vertex_normals=True)

    write_mesh(filename,
               vertices=vertices,
               faces=faces,
               normals=normals,
               texcoords=None,
               overwrite=True,
               reshape_faces=False)  # GH 1155
    logger.info('Saved %s as a junction mesh .OBJ file', eptm.identifier)
Пример #3
0
def test_meshio():
    '''Test meshio i/o'''
    vertices = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.], [-.0, 1.0, 0.],
                         [1.0, 1.0, 0.]])

    faces = np.array([[0, 1, 3], [1, 2, 3]])
    fname_out = op.join(temp_dir, 'temp.vtk')
    write_mesh(fname_out,
               vertices=vertices,
               faces=faces,
               normals=None,
               texcoords=None,
               overwrite=True,
               reshape_faces=False)
    out_vertices, out_faces, _, _ = read_mesh(fname_out)

    assert np.all(np.abs(out_vertices - vertices) < 1.0e-14)
    assert np.all(out_faces == faces)
Пример #4
0
def test_wavefront_non_triangular():
    '''Test wavefront writing with non-triangular faces'''
    vertices = np.array([[0.5, 1.375, 0.], [0.5, 0.625, 0.], [3.25, 1., 0.],
                         [1., 0.375, 0.], [2., 0.375, 0.], [1.5, 0.625, 0.],
                         [1.5, 1.375, 0.], [1., 1.625, 0.], [2., 1.625, 0.]])

    faces = np.array([[1, 0, 7, 6, 5, 3], [4, 5, 6, 8, 2]])
    fname_out = op.join(temp_dir, 'temp.obj')
    write_mesh(fname_out,
               vertices=vertices,
               faces=faces,
               normals=None,
               texcoords=None,
               overwrite=True,
               reshape_faces=False)
    assert_raises(RuntimeError, read_mesh, fname_out)
    with open(fname_out, 'r+') as out_file:
        lines = out_file.readlines()
    assert lines[-1].startswith('f 5 6 7 9 3')
    assert lines[-2].startswith('f 2 1 8 7 6 4')
Пример #5
0
def test_wavefront():
    """Test wavefront reader"""
    fname_mesh = load_data_file('orig/triceratops.obj.gz')
    fname_out = op.join(temp_dir, 'temp.obj')
    mesh1 = read_mesh(fname_mesh)
    assert_raises(IOError, read_mesh, 'foo.obj')
    assert_raises(ValueError, read_mesh, op.abspath(__file__))
    assert_raises(ValueError, write_mesh, fname_out, *mesh1, format='foo')
    write_mesh(fname_out, mesh1[0], mesh1[1], mesh1[2], mesh1[3])
    assert_raises(IOError, write_mesh, fname_out, *mesh1)
    write_mesh(fname_out, *mesh1, overwrite=True)
    mesh2 = read_mesh(fname_out)
    assert_equal(len(mesh1), len(mesh2))
    for m1, m2 in zip(mesh1, mesh2):
        if m1 is None:
            assert_equal(m2, None)
        else:
            assert_allclose(m1, m2, rtol=1e-5)
    # test our efficient normal calculation routine
    assert_allclose(mesh1[2], _slow_calculate_normals(mesh1[0], mesh1[1]),
                    rtol=1e-7, atol=1e-7)
Пример #6
0
def test_wavefront():
    """Test wavefront reader"""
    fname_mesh = load_data_file('orig/triceratops.obj.gz')
    fname_out = op.join(temp_dir, 'temp.obj')
    mesh1 = read_mesh(fname_mesh)
    assert_raises(IOError, read_mesh, 'foo.obj')
    assert_raises(ValueError, read_mesh, op.abspath(__file__))
    assert_raises(ValueError, write_mesh, fname_out, *mesh1, format='foo')
    write_mesh(fname_out, mesh1[0], mesh1[1], mesh1[2], mesh1[3])
    assert_raises(IOError, write_mesh, fname_out, *mesh1)
    write_mesh(fname_out, *mesh1, overwrite=True)
    mesh2 = read_mesh(fname_out)
    assert_equal(len(mesh1), len(mesh2))
    for m1, m2 in zip(mesh1, mesh2):
        if m1 is None:
            assert_equal(m2, None)
        else:
            assert_allclose(m1, m2, rtol=1e-5)
    # test our efficient normal calculation routine
    assert_allclose(mesh1[2],
                    _slow_calculate_normals(mesh1[0], mesh1[1]),
                    rtol=1e-7,
                    atol=1e-7)
Пример #7
0
def save_splitted_cells(fname, sheet, epsilon=0.1):

    coords = sheet.coords
    up_srce = sheet.upcast_srce(sheet.vert_df[coords])
    up_trgt = sheet.upcast_trgt(sheet.vert_df[coords])
    up_face = sheet.upcast_face(sheet.face_df[coords])
    up_srce = (up_srce - up_face) * (1 - epsilon) + up_face
    up_trgt = (up_trgt - up_face) * (1 - epsilon) + up_face

    cell_faces = pd.concat([sheet.face_df[coords], up_srce, up_trgt], ignore_index=True)
    Ne, Nf = sheet.Ne, sheet.Nf

    triangles = np.vstack(
        [sheet.edge_df["face"], np.arange(Ne) + Nf, np.arange(Ne) + Ne + Nf]
    ).T
    write_mesh(
        fname,
        cell_faces.values,
        triangles,
        normals=None,
        texcoords=None,
        overwrite=True,
    )
Пример #8
0
def test_wavefront_non_triangular():
    '''Test wavefront writing with non-triangular faces'''
    vertices = np.array([[0.5, 1.375, 0.],
                         [0.5, 0.625, 0.],
                         [3.25, 1., 0.],
                         [1., 0.375, 0.],
                         [2., 0.375, 0.],
                         [1.5, 0.625, 0.],
                         [1.5, 1.375, 0.],
                         [1., 1.625, 0.],
                         [2., 1.625, 0.]])

    faces = np.array([[1, 0, 7, 6, 5, 3],
                      [4, 5, 6, 8, 2]])
    fname_out = op.join(temp_dir, 'temp.obj')
    write_mesh(fname_out, vertices=vertices,
               faces=faces, normals=None,
               texcoords=None, overwrite=True,
               reshape_faces=False)
    assert_raises(RuntimeError, read_mesh, fname_out)
    with open(fname_out, 'r+') as out_file:
        lines = out_file.readlines()
    assert lines[-1].startswith('f 5 6 7 9 3')
    assert lines[-2].startswith('f 2 1 8 7 6 4')
def update(ev):
    global t, surface1, surface2
    print("loop %d/%d" % (t, dimt))

    #cold data
    surface3.set_data(cold_data[:, :, :, t])
    if (cold_data[:, :, :, t].max() == 1):
        coldVertices, coldEdges, coldFaces = retrieveIsosurfaceData(
            surface3, dimx, dimy, dimz)
        coldMeshEdges.set_data(coldVertices, coldEdges, color=(0.6, 0.6, 1, 1))
        coldMeshFaces.set_data(coldVertices, coldFaces)
        write_mesh("cold_%d.obj" % t, coldMeshFaces.mesh_data.get_vertices(),
                   coldMeshFaces.mesh_data.get_faces(),
                   coldMeshFaces.mesh_data.get_vertex_normals(), None,
                   "hot data", "obj", True, True)
    else:
        coldMeshEdges.set_data(None, None)
        coldMeshFaces.set_data(None, None)

    #cool data
    surface2.set_data(cool_data[:, :, :, t])
    if (cool_data[:, :, :, t].max() == 1):
        coolVertices, coolEdges, coolFaces = retrieveIsosurfaceData(
            surface2, dimx, dimy, dimz)
        coolMeshEdges.set_data(coolVertices, coolEdges, color=(1, 1, 0.6, 1))
        coolMeshFaces.set_data(coolVertices, coolFaces)
        write_mesh("cool_%d.obj" % t, coolMeshFaces.mesh_data.get_vertices(),
                   coolMeshFaces.mesh_data.get_faces(),
                   coolMeshFaces.mesh_data.get_vertex_normals(), None,
                   "hot data", "obj", True, True)
    else:
        coolMeshEdges.set_data(None, None)
        coolMeshFaces.set_data(None, None)

    #hot data
    surface1.set_data(hot_data[:, :, :, t])
    if (hot_data[:, :, :, t].max() == 1):
        hotVertices, hotEdges, hotFaces = retrieveIsosurfaceData(
            surface1, dimx, dimy, dimz)
        hotMeshEdges.set_data(hotVertices, hotEdges, color=(1, 0.6, 0.6, 1))
        hotMeshFaces.set_data(hotVertices, hotFaces)
        write_mesh("hot_%d.obj" % t, hotMeshFaces.mesh_data.get_vertices(),
                   hotMeshFaces.mesh_data.get_faces(),
                   hotMeshFaces.mesh_data.get_vertex_normals(), None,
                   "hot data", "obj", True, True)
    else:
        hotMeshEdges.set_data(None, None)
        hotMeshFaces.set_data(None, None)
    print("t = %i" % t)
    t += 1
if coldEdges != None and np.shape(coldEdges)[0] != 0:
    coldMeshEdges = scene.visuals.Mesh(coldVertices,
                                       coldEdges,
                                       mode='lines',
                                       parent=view.scene)
    coldMeshFaces = scene.visuals.Mesh(coldVertices, coldFaces, parent=None)
else:
    coldMeshEdges = scene.visuals.Mesh(None,
                                       None,
                                       mode='lines',
                                       parent=view.scene)
    coldMeshFaces = scene.visuals.Mesh(None, None, parent=None)

if hotMeshFaces.mesh_data.get_vertices() != None:
    write_mesh("hot_0.obj", hotMeshFaces.mesh_data.get_vertices(),
               hotMeshFaces.mesh_data.get_faces(),
               hotMeshFaces.mesh_data.get_vertex_normals(), None, "hot data",
               "obj", True, True)
if coolMeshFaces.mesh_data.get_vertices() != None:
    write_mesh("cool_0.obj", coolMeshFaces.mesh_data.get_vertices(),
               coolMeshFaces.mesh_data.get_faces(),
               coolMeshFaces.mesh_data.get_vertex_normals(), None, "cool data",
               "obj", True, True)
if coldMeshFaces.mesh_data.get_vertices() != None:
    write_mesh("cold_0.obj", coldMeshFaces.mesh_data.get_vertices(),
               coldMeshFaces.mesh_data.get_faces(),
               coldMeshFaces.mesh_data.get_vertex_normals(), None, "hot data",
               "obj", True, True)

# Add a 3D axis to keep us oriented
axis = scene.visuals.XYZAxis(parent=view.scene)