Beispiel #1
0
def test_meshing():

    plant_number = 1
    voxels_size = 16

    dir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                            "../data")
    print(dir_path)
    voxel_grid = phm_data.voxel_grid(dir_path,
                                     plant_number=plant_number,
                                     voxels_size=voxels_size)

    image_3d = voxel_grid.to_image_3d()

    vertices, faces = phm_mesh.meshing(image_3d,
                                       smoothing_iteration=2,
                                       reduction=0.95,
                                       verbose=True)
    assert 100 <= len(vertices) <= 500, len(vertices)
    assert 200 <= len(faces) <= 1000, len(faces)

    poly_data = phm_mesh.from_vertices_faces_to_vtk_poly_data(vertices, faces)

    vtk_image_data = phm_mesh.voxelization(poly_data, voxels_size=voxels_size)
    voxels_position = phm_mesh.from_vtk_image_data_to_voxels_center(
        vtk_image_data)

    assert len(voxels_position) >= 1000
Beispiel #2
0
def test_mesh_error_2():
    voxels_size = 1
    voxels_position = list()
    voxels_position.append((0, 0, 0))

    try:
        image_3d = phm_obj.VoxelGrid(voxels_position,
                                     voxels_size).to_image_3d()
        vertices, faces = phm_mesh.meshing(image_3d)

    except Exception as e:
        assert type(e) == ValueError
    else:
        assert False
Beispiel #3
0
def test_meshing():

    plant_number = 1
    voxels_size = 16
    voxel_grid = phm_data.voxel_grid(plant_number=plant_number,
                                     voxels_size=voxels_size)

    image_3d = voxel_grid.to_image_3d()

    vertices, faces = phm_mesh.meshing(image_3d,
                                       smoothing_iteration=2,
                                       reduction=0.95,
                                       verbose=True)
    assert 100 <= len(vertices) <= 500, len(vertices)
    assert 200 <= len(faces) <= 1000, len(faces)

    poly_data = phm_mesh.from_vertices_faces_to_vtk_poly_data(vertices, faces)

    vtk_image_data = phm_mesh.voxelization(poly_data, voxels_size=voxels_size)
    voxels_position = phm_mesh.from_vtk_image_data_to_voxels_center(
        vtk_image_data)

    assert len(voxels_position) >= 1000
            image_ref=image_ref))

##### Do multi-view reconstruction
voxels_size = 16 # mm
error_tolerance = 0
voxel_grid = phm_mvr.reconstruction_3d(image_views, 
                                       voxels_size=voxels_size,
                                       error_tolerance=error_tolerance)



###### Save / Load voxel grid
voxel_grid.write("plant_{}_size_{}.npz".format(plant_number, voxels_size))
voxel_grid = phm_obj.VoxelGrid.read("plant_{}_size_{}.npz".format(plant_number, voxels_size))

##### Viewing
phm_display_notebook.show_voxel_grid(voxel_grid, size=1)


## meshing
vertices, faces = phm_mesh.meshing(voxel_grid.to_image_3d(),
                                   reduction=0.90,
                                   smoothing_iteration=5,
                                   verbose=True)

print("Number of vertices : {nb_vertices}".format(nb_vertices=len(vertices)))
print("Number of faces : {nb_faces}".format(nb_faces=len(faces)))

## viewing
phm_display_notebook.show_mesh(vertices, faces)