def run_test(mesh, callback=None, stride=2):
    # Create Pseudo 3D Surface Mesh using Delaunay Triangulation and Polylidar
    polylidar_kwargs = dict(alpha=0.0,
                            lmax=0.15,
                            min_triangles=100,
                            z_thresh=0.20,
                            norm_thresh=0.95,
                            norm_thresh_min=0.90,
                            min_hole_vertices=6)
    # Create Polylidar TriMesh
    tri_mesh = open_3d_mesh_to_trimesh(mesh)
    # bilateral_filter_normals(tri_mesh, 3, 0.1, 0.1)
    vertices = np.asarray(tri_mesh.vertices)
    normals_smooth = np.asarray(tri_mesh.triangle_normals)
    mesh.triangle_normals = o3d.utility.Vector3dVector(normals_smooth)
    o3d.visualization.draw_geometries([mesh], width=600, height=500)

    planes, tri_set, all_poly_lines, polylidar_time = extract_all_dominant_planes(
        tri_mesh, vertices, polylidar_kwargs)
    time_polylidar3D = polylidar_time
    polylidar_3d_alg_name = 'Polylidar3D with Provided Mesh'

    # planes_tri_set = [np.argwhere(np.asarray(tri_set) == i)  for i in range(1, 3)]
    # # import ipdb; ipdb.set_trace()
    # mesh_tri_set = paint_planes(mesh, planes_tri_set)
    # callback(polylidar_3d_alg_name, time_polylidar3D, mesh_tri_set)

    # mesh_segment = paint_planes(mesh, planes)
    # callback(polylidar_3d_alg_name, time_polylidar3D, mesh_segment)

    mesh_3d_polylidar = []
    mesh_3d_polylidar.extend(
        flatten([line_mesh.cylinder_segments for line_mesh in all_poly_lines]))
    mesh_3d_polylidar.append(mesh)
    callback(polylidar_3d_alg_name, time_polylidar3D, mesh_3d_polylidar)
Exemplo n.º 2
0
def run_test(mesh, callback=None, polylidar_kwargs=None, config_pp=None):
    tri_mesh = open_3d_mesh_to_trimesh(mesh)
    # bilateral_filter_normals(tri_mesh, 3, 0.1, 0.1)
    vertices = np.asarray(tri_mesh.vertices)
    normals_smooth = np.asarray(tri_mesh.triangle_normals)
    mesh.triangle_normals = o3d.utility.Vector3dVector(normals_smooth)

    planes, tri_set, all_poly_lines, timings = extract_all_dominant_planes(
        tri_mesh, vertices, polylidar_kwargs, config_pp)
    time_polylidar3D = timings['t_polylidar_planepoly']
    polylidar_3d_alg_name = 'Polylidar3D with Provided Mesh'

    mesh_3d_polylidar = []
    mesh_3d_polylidar.extend(flatten([line_mesh.cylinder_segments for line_mesh in all_poly_lines]))
    mesh_3d_polylidar.append(mesh)
    callback(polylidar_3d_alg_name, time_polylidar3D, mesh_3d_polylidar)
Exemplo n.º 3
0
def run_test(pcd, rgbd, intrinsics, extrinsics, bp_alg=dict(radii=[0.02, 0.02]), poisson=dict(depth=8), callback=None, stride=2):
    """Demonstrate Polygon Extraction on both unorganized and organized point cloud

    Args:
        pcd (o3d.geometry.PointCloud): Open3D point cloud
        rgbd (np.ndarray): MXN Numpy array
        intrinsics (np.ndarray): 3X3 numpy array of camera intrinsics (assume pin hole model)
        extrinsics (np.ndarray): 4X4 numpy array of extrinsics of camera
        bp_alg (dict, optional): Arguments to Open3D ball pivot alg. Defaults to dict(radii=[0.02, 0.02]).
        poisson (dict, optional): Arguments to Open3D Poisson surface reconstruction. Defaults to dict(depth=8).
        callback (function, optional): Callback function for visualization. Defaults to None.
        stride (int, optional): Skip rows/columns in rgbd. Defaults to 2.

    """
    points = np.asarray(pcd.points)
    polylidar_kwargs = dict(alpha=0.0, lmax=0.10, min_triangles=100,
                            z_thresh=0.04, norm_thresh=0.90, norm_thresh_min=0.90, min_hole_vertices=6)
    pl = Polylidar3D(**polylidar_kwargs)

    ################################################################################
    ##### Treat data as an unorganized point clouds
    ##### Create Surface Mesh using 2.5 Delaunay Triangulation and extract Polygons
    ################################################################################
    points_mat = MatrixDouble(points)
    t1 = time.perf_counter()
    mesh, planes, polygons = pl.extract_planes_and_polygons(points_mat)
    t2 = time.perf_counter()

    # Visualization of mesh and polygons
    all_poly_lines = filter_and_create_open3d_polygons(points, polygons)
    triangles = np.asarray(mesh.triangles)
    mesh_2d_polylidar = extract_mesh_planes(points, triangles, planes, mesh.counter_clock_wise, COLOR_PALETTE[0])
    mesh_2d_polylidar.extend(flatten([line_mesh.cylinder_segments for line_mesh in all_poly_lines]))
    time_mesh_2d_polylidar = (t2 - t1) * 1000
    polylidar_alg_name = 'Treated as **Unorganized** Point Cloud - 2.5D Delaunay Triangulation with Polygon Extraction'
    callback(polylidar_alg_name, time_mesh_2d_polylidar, pcd, mesh_2d_polylidar)

    ################################################################################
    ###### Treat data as an **Organized** 3D Point Cloud #########
    ###### Creates a true 3D mesh and is much master using organized structure of point cloud 
    ################################################################################
    tri_mesh, t_mesh_creation = make_uniform_grid_mesh(np.asarray(
        rgbd.depth), np.ascontiguousarray(intrinsics.intrinsic_matrix), extrinsics, stride=stride)

    # Visualization of only the mesh
    tri_mesh_o3d = create_open_3d_mesh_from_tri_mesh(tri_mesh)
    uniform_alg_name = 'Treated as **Organized** Point Cloud - Right-Cut Triangulation/Uniform Mesh (Mesh only)'
    callback(uniform_alg_name, t_mesh_creation, pcd, tri_mesh_o3d)

    # Exctact Polygons with Polylidar3D using the Uniform Mesh. Dominant Plane normal is 0,0,1.
    t1 = time.perf_counter()
    planes, polygons = pl.extract_planes_and_polygons(tri_mesh)
    t2 = time.perf_counter()

    # Visualization of mesh and polygons
    vertices_np = np.asarray(tri_mesh.vertices)
    triangles_np = np.asarray(tri_mesh.triangles)

    all_poly_lines = filter_and_create_open3d_polygons(vertices_np, polygons)
    mesh_3d_polylidar = extract_mesh_planes(vertices_np, triangles_np, planes, tri_mesh.counter_clock_wise)
    mesh_3d_polylidar.extend(flatten([line_mesh.cylinder_segments for line_mesh in all_poly_lines]))
    time_polylidar3D = (t2 - t1) * 1000
    polylidar_3d_alg_name = 'Polygon Extraction on Uniform Mesh (only one dominant plane normal)'
    callback(polylidar_3d_alg_name, time_polylidar3D,
             create_open3d_pc(vertices_np), mesh_3d_polylidar)