Ejemplo n.º 1
0
def unif_resample(x,n,tol=1,deg=3):    
    x = np.atleast_2d(x)
    x = mu.remove_duplicate_rows(x)
    dl = mu.norms(x[1:] - x[:-1],1)
    l = np.cumsum(np.r_[0,dl])
    (tck,_) = si.splprep(x.T,k=deg,s = tol**2*len(x),u=l)
    
    newu = np.linspace(0,l[-1],n)
    return np.array(si.splev(newu,tck)).T
Ejemplo n.º 2
0
def unif_resample(x,n,tol=0,deg=None):    
    if deg is None: deg = min(3, len(x) - 1)

    x = np.atleast_2d(x)
    x = math_utils.remove_duplicate_rows(x)
    dl = math_utils.norms(x[1:] - x[:-1],1)
    l = np.cumsum(np.r_[0,dl])
    
    (tck,_) = si.splprep(x.T,k=deg,s = tol**2*len(x),u=l)

    newu = np.linspace(0,l[-1],n)
    return np.array(si.splev(newu,tck)).T    
Ejemplo n.º 3
0
def unif_resample(x,n,weights,tol=.001,deg=3):    
    x = np.atleast_2d(x)
    weights = np.atleast_2d(weights)
    x = mu.remove_duplicate_rows(x)
    x_scaled = x * weights
    dl = mu.norms(x_scaled[1:] - x_scaled[:-1],1)
    l = np.cumsum(np.r_[0,dl])
    (tck,_) = si.splprep(x_scaled.T,k=deg,s = tol**2*len(x),u=l)
    
    newu = np.linspace(0,l[-1],n)
    out_scaled = np.array(si.splev(newu,tck)).T
    out = out_scaled/weights
    return out
Ejemplo n.º 4
0
def find_path_through_point_cloud(xyzs, plotting = False):
    xyzs = np.asarray(xyzs).reshape(-1,3)
    S = skeletonize_point_cloud(xyzs)
    segs = get_segments(S)

    if plotting: 
        from mayavi import mlab
        mlab.figure(1); mlab.clf()
        plot_graph_3d(S)

    S,segs = prune_skeleton(S, segs)

    if plotting: 
        from mayavi import mlab
        mlab.figure(3); mlab.clf()
        plot_graph_3d(S)


    segs3d = [np.array([S.node[i]["xyz"] for i in seg]) for seg in segs]

    if plotting: plot_paths_2d(segs3d)

    C = make_cost_matrix(segs3d)
    PG = make_path_graph(C, [len(path) for path in segs3d])

    (score, nodes) = longest_path_through_segment_graph(PG)
    print nodes

    total_path = []
    for node in nodes[::2]:
        if node%2 == 0: total_path.extend(segs[node//2])
        else: total_path.extend(segs[node//2][::-1])

    total_path_3d = math_utils.remove_duplicate_rows(np.array([S.node[i]["xyz"] for i in total_path]))
    total_path_3d = unif_resample(total_path_3d, n = 100, tol=.01) # tolerance of 1mm


    if plotting:
        mlab.figure(2); mlab.clf()
        for seg in segs3d:
            x,y,z = np.array(seg).T
            mlab.plot3d(x,y,z,color=(0,1,0),tube_radius=.001)
        x,y,z = np.array(total_path_3d).T
        mlab.plot3d(x,y,z,color=(1,0,0),tube_radius=.01,opacity=.2)      
        
        x,y,z = np.array(xyzs).reshape(-1,3).T
        mlab.points3d(x,y,z,scale_factor=.01,opacity=.1,color=(0,0,1))


    return total_path_3d