Exemple #1
0
def sinusoidal_cylinder():

    N = 11
    M = 2
    eps = 0.1
    # eps2 = 0.1
    z = np.linspace(0, 1, N)
    theta = np.linspace(0, 1, N)

    # ED configuration
    rho_ed = 30
    h_ed = 80
    r_ed = []
    drdt_ed = []
    drdz_ed = []

    # Deformed Configuration
    rho_es = 20
    h_es = 60
    r_es = []
    drdt_es = []
    drdz_es = []
    # eps2*np.sin( 2 * np.pi * theta[j] ) )
    for i in range(0, len(z)):
        for j in range(0, len(theta)):

            cylinder_ed = Cylinder(
                rho_ed * ((1 + eps * np.sin(M * 2 * np.pi * z[i]))), h_ed,
                theta[j], z[i])
            r_ed.append(cylinder_ed.cylinder2cart())
            drdt_ed.append(cylinder_ed.partial_theta())
            drdz_ed.append(cylinder_ed.partial_z_sin(M, eps))

            cylinder_es = Cylinder(
                rho_es * ((1 + eps * np.sin(M * 2 * np.pi * z[i]))), h_es,
                theta[j], z[i])
            r_es.append(cylinder_es.cylinder2cart())
            drdt_es.append(cylinder_es.partial_theta())
            drdz_es.append(cylinder_es.partial_z_sin(M, eps))

    pts_ed = r_ed
    pts_es = r_es
    size_u = N
    size_v = N
    degree_u = 3
    degree_v = 3

    # Do global surface approximation
    surf_ed = fitting.approximate_surface(pts_ed, size_u, size_v, degree_u,
                                          degree_v)
    surf_ed = convert.bspline_to_nurbs(surf_ed)

    # Do global surface approximation
    surf_es = fitting.approximate_surface(pts_es, size_u, size_v, degree_u,
                                          degree_v)
    surf_es = convert.bspline_to_nurbs(surf_es)

    return surf_ed, surf_es, drdt_ed, drdz_ed, drdt_es, drdz_es
def test_convert_surface():
    surf_bs = BSpline.Surface()
    surf_bs.degree_u = S_DEGREE_U
    surf_bs.degree_v = S_DEGREE_V
    surf_bs.ctrlpts_size_u = 3
    surf_bs.ctrlpts_size_v = 3
    surf_bs.ctrlpts = S_CTRLPTS
    surf_bs.knotvector_u = S_KV_U
    surf_bs.knotvector_v = S_KV_V

    surf_nurbs = convert.bspline_to_nurbs(surf_bs)
    surf_nurbs.sample_size = SAMPLE_SIZE

    # Expected weights vector
    res_weights = [1.0 for _ in range(3*3)]

    # Expected output
    res = [[0.0, 0.0, 0.0], [0.0, 0.5, -0.1875], [0.0, 1.0, -0.75], [0.0, 1.5, -1.6875],
           [0.0, 2.0, -3.0], [0.5, 0.0, 2.25], [0.5, 0.5, 1.171875], [0.5, 1.0, 0.1875],
           [0.5, 1.5, -0.703125], [0.5, 2.0, -1.5], [1.0, 0.0, 3.0], [1.0, 0.5, 1.6875],
           [1.0, 1.0, 0.75], [1.0, 1.5, 0.1875], [1.0, 2.0, 0.0], [1.5, 0.0, 2.25],
           [1.5, 0.5, 1.359375], [1.5, 1.0, 0.9375], [1.5, 1.5, 0.984375], [1.5, 2.0, 1.5],
           [2.0, 0.0, 0.0], [2.0, 0.5, 0.1875], [2.0, 1.0, 0.75], [2.0, 1.5, 1.6875], [2.0, 2.0, 3.0]]

    assert not surf_bs.rational
    assert surf_nurbs.rational
    assert surf_nurbs.evalpts == res
    assert surf_nurbs.weights == res_weights
Exemple #3
0
def fit_Standard_RV(N, M, sampled_data):

    # set up the fitting parameters
    p_ctrlpts = sampled_data
    size_u = M + 1
    size_v = N + 1
    degree_u = 3
    degree_v = 3

    # Do global surface approximation
    standard_RV_NURBS_surf = fitting.interpolate_surface(
        p_ctrlpts, size_u, size_v, degree_u, degree_v)

    standard_RV_NURBS_surf = convert.bspline_to_nurbs(standard_RV_NURBS_surf)

    return standard_RV_NURBS_surf
    def set_curves(self):
        degree = 2
        num_cp = 2
        CP, U = F.curve_fit2D(self.points, np.ones((len(self.points), 1)),
                              None, None, None, num_cp, degree)

        B_cur = BSpline.Curve()
        B_cur.degree = degree
        B_cur.ctrlpts = CP
        B_cur.knotvector = U
        B_cur.evaluate()
        B_cur.delta = 0.01

        N_cur = convert.bspline_to_nurbs(B_cur)
        # Set evaluation delta
        N_cur.delta = 0.01
        N_cur.evaluate()

        return N_cur, B_cur
def test_convert_curve():
    curve_bs = BSpline.Curve()
    curve_bs.degree = C_DEGREE
    curve_bs.ctrlpts = C_CTRLPTS
    curve_bs.knotvector = C_KV
    curve_bs.sample_size = SAMPLE_SIZE

    curve_nurbs = convert.bspline_to_nurbs(curve_bs)
    curve_nurbs.sample_size = SAMPLE_SIZE

    # Expected weights vector
    res_weights = [1.0 for _ in range(len(C_CTRLPTS))]

    # Expected evaluation result
    res = [[1.0, 1.0, 0.0], [1.4375, 1.0625, -0.375], [1.75, 1.25, -0.5], [1.9375, 1.5625, -0.375], [2.0, 2.0, 0.0]]

    assert not curve_bs.rational
    assert curve_nurbs.rational
    assert curve_nurbs.evalpts == res
    assert curve_nurbs.weights == res_weights
Exemple #6
0
def nurbs_surf(spline_surf):
    surf = convert.bspline_to_nurbs(spline_surf)
    return surf
Exemple #7
0
fig = plt.figure(dpi = 175)
ax = plt.axes(projection = '3d')
plt.style.use('dark_background')
ax.scatter(toroid[:,0],toroid[:,1],toroid[:,2], color = 'blue',marker = 'o')
ax.plot(caxis[:,0],caxis[:,1],caxis[:,2],color = 'red')
ax.axis("off")
p_ctrlpts = toroid
size_u = N
size_v = N
degree_u = 3
degree_v = 3

# Do global surface approximation
surf = fitting.approximate_surface(p_ctrlpts, size_u, size_v, degree_u, degree_v)

surf = convert.bspline_to_nurbs(surf)

# Extract curves from the approximated surface
surf_curves = construct.extract_curves(surf)
plot_extras = [
    dict(
        points=surf_curves['u'][0].evalpts,
        name="u",
        color="red",
        size=10
    ),
    dict(
        points=surf_curves['v'][0].evalpts,
        name="v",
        color="black",
        size=10
Exemple #8
0
caxis = np.array(caxis)
caxis_def = np.array(caxis_def)

p_ctrlpts = toroid
size_u = N
size_v = N
degree_u = 3
degree_v = 3

# Do global surface approximation
surf = fitting.approximate_surface(p_ctrlpts, size_u, size_v, degree_u,
                                   degree_v)
surf_def = fitting.approximate_surface(toroid_def, size_u, size_v, degree_u,
                                       degree_v)

surf = convert.bspline_to_nurbs(surf)
surf_def = convert.bspline_to_nurbs(surf_def)

# toroid_pcl = np.array(surf.evalpts)
# toroid_cpts = np.array(surf.ctrlpts)

uv = np.linspace(0, 1, N)
nurbs_fit_G = compute_metric_tensor(surf, uv)
nurbs_fit_G_def = compute_metric_tensor(surf_def, uv)
E = []
F = 0 * np.ones((len(uv)))
G = []
E_def = []
G_def = []
for i in range(0, len(uv)):
    E.append((R + r * np.cos(2 * np.pi * uv[i]))**2)
Exemple #9
0
def nurbs_curve(spline_curve):
    curve = convert.bspline_to_nurbs(spline_curve)
    curve.weights = [0.5, 1.0, 0.75, 1.0, 0.25, 1.0]
    return curve
Exemple #10
0
		cylinder_es = Cylinder(R_es,h_es,theta[j],z[i])
		r_es.append(cylinder_es.cylinder2cart())
		drdt_es.append(cylinder_es.partial_theta())
		drdz_es.append(cylinder_es.partial_z())

# print(len(drdt_ed))
pts_ed = r_ed
size_u = 20
size_v = 20
degree_u = 3
degree_v = 3

# Do global surface approximation
surf_ed = fitting.approximate_surface(pts_ed, size_u, size_v, degree_u, degree_v)
surf_ed = convert.bspline_to_nurbs(surf_ed)

surf_ed.delta = 0.025
surf_ed.vis = vis.VisSurface()
evalpts_ed = np.array(surf_ed.evalpts)

pts_es = r_es

# Do global surface approximation
surf_es = fitting.approximate_surface(pts_es, size_u, size_v, degree_u, degree_v)
surf_es = convert.bspline_to_nurbs(surf_es)

surf_es.delta = 0.025
surf_es.vis = vis.VisSurface()
evalpts_es = np.array(surf_es.evalpts)
Exemple #11
0
def fit_StandardRV():
    # load data
    rm_file = "N2_RV_P4_rm"
    points = np.loadtxt(rm_file + ".csv", delimiter=',')

    # split data into slices
    N = 15
    slice(N, points)
    slices = []
    temp = []
    layers = []
    bins = slice.bins

    for j in range(0, len(slice.slices)):
        temp.append(
            cylinder(slice.slices[j][:, 0], slice.slices[j][:, 1],
                     bins[j] * np.ones(len(slice.slices[j][:, 2]))))
    temp = np.array(temp)

    # store all slices into layers array
    for i in range(0, len(temp)):
        for j in range(0, len(temp[i][0])):
            layers.append(
                [temp[:, 0][i][j], temp[:, 1][i][j], temp[:, 2][i][j]])

    # segment the layers into angled segments
    layers = np.array(layers)
    M = N
    segments = split_into_angles(M, layers)

    # find average points at each segment and slice

    temp1 = []
    data = []
    # fig = plt.figure()
    # ax = plt.axes(projection= "3d")
    segment = []

    for i in range(0, len(segments)):
        segment.append(
            np.array([segments[i][0], segments[i][1], segments[i][2]]).T)
        for j in range(0, len(bins)):
            temp1.append(segment[i][segment[i][:, 2] == bins[j]])

    chunks = np.array(temp1)

    # ax.scatter(chunks[0][:,0],chunks[0][:,1],chunks[0][:,2])
    # fig = plt.figure()
    # ax = plt.axes(projection= "3d")
    # xbar = []
    # ybar = []
    # zbar = []

    # for j in range(0,len(chunks)):
    # 	xbar.append(chunks[j][:,0].mean())
    # 	ybar.append(chunks[j][:,1].mean())
    # 	zbar.append(chunks[j][:,2].max())
    # for i in range(0,(N+1)):
    # 	xbar.append(chunks[i][:,0].mean())
    # 	ybar.append(chunks[i][:,1].mean())
    # 	zbar.append(chunks[i][:,2].max())
    # X = np.array([xbar,ybar,zbar]).T

    cylData = []
    for j in range(0, len(chunks)):
        cylData.append(
            cylinder(chunks[j][:, 0], chunks[j][:, 1], chunks[j][:, 2]))

    cartData = []
    for i in range(0, len(cylData)):
        cartData.append(
            cart(cylData[i][0].max(), cylData[i][1].max(),
                 cylData[i][2].max()))
    for i in range(0, (N + 1)):
        cartData.append(
            cart(cylData[i][0].max(), cylData[i][1].max(),
                 cylData[i][2].max()))

    X = np.array(cartData)

    test = []

    # np.savetxt("sampled_"+ rm_file + ".csv",X,delimiter = ',')

    reg_file = "N2_RV_P0"
    xyz = np.loadtxt(reg_file + ".dat")
    xyz = preProcess(xyz)

    # X = np.loadtxt('sampled_' + reg_file + ".csv",delimiter = ',')
    # X = preProcess(X)

    # this orders the points from least to greatest height (z values)
    for i in range(0, len(bins)):
        test.append(X[X[:, 2] == bins[i]])
    for j in range(0, len(test)):
        for ii in range(0, len(test[i])):
            data.append([test[j][ii][0], test[j][ii][1], test[j][ii][2]])

    data = np.array(data)
    # ax.scatter(xbar,ybar,zbar)
    print(len(X))

    # set up the fitting parameters
    p_ctrlpts = X
    size_u = N + 1
    size_v = M + 1
    degree_u = 3
    degree_v = 3

    # Do global surface approximation
    surf = fitting.interpolate_surface(p_ctrlpts, size_u, size_v, degree_u,
                                       degree_v)

    surf = convert.bspline_to_nurbs(surf)
    print("surf", type(surf))

    # Extract curves from the approximated surface
    surf_curves = construct.extract_curves(surf)
    plot_extras = [
        dict(points=surf_curves['u'][0].evalpts,
             name="u",
             color="red",
             size=10),
        dict(points=surf_curves['v'][0].evalpts,
             name="v",
             color="black",
             size=10)
    ]
    surf.delta = 0.025
    # surf.vis = vis.VisSurface()
    # surf.render(extras=plot_extras)
    # exchange.export_obj(surf, rm_file + "_fit.obj")
    # exchange.export_obj(surf, reg_file + "_fit.obj")
    # visualize data samples, original RV data, and fitted surface
    eval_surf = np.array(surf.evalpts)
    # eval_surf = preProcess(eval_surf)

    # fig = plt.figure()
    # ax = plt.axes(projection="3d")
    # ax.scatter(eval_surf[:,0],eval_surf[:,1],eval_surf[:,2], color = 'r')
    # # ax.scatter3D(points[:, 0],points[:, 1],points[:, 2])
    # ax.scatter3D(xyz[:, 0],xyz[:, 1],xyz[:, 2])
    # ax.scatter(X[:,0],X[:,1],X[:,2])

    # ax.scatter(X[:,0],X[:,1],X[:,2])
    cpts = np.array(surf.ctrlpts)
    # np.savetxt('cpts_'+rm_file,cpts, delimiter = '	')
    # np.savetxt('cpts_'+ reg_file + ".csv",cpts, delimiter = ',')

    # fig = plt.figure()
    # ax = plt.axes(projection = "3d")
    # ax.scatter(X[:,0],X[:,1],X[:,2])
    # ax.scatter(cpts[:,0],cpts[:,1],cpts[:,2])
    # plt.show()
    return surf
Exemple #12
0
# Set degree
crv2.degree = 3

# Set control points
crv2.ctrlpts = [[1, 0, 0], [1, 1, 0], [2, 1, 0], [1, 1, 0]]

# Generate a uniform knot vector
crv2.knotvector = knotvector.generate(crv2.degree, crv2.ctrlpts_size)

# Create a curve container
mcrv = multi.CurveContainer(crv1, crv2)

# Import Matplotlib visualization module
from geomdl.visualization import VisMPL

# Set the visualization component of the curve container
mcrv.vis = VisMPL.VisCurve3D()

# Plot the curves in the curve container
mcrv.render()
'''
    Convert non-rational to rational curve
    
    Generates a B-Spline (non-rational) curve and converts it 
    into a NURBS (rational) curve.
'''
from geomdl import convert  # Import convert module

# B-Spline to NURBS
crv_rat = convert.bspline_to_nurbs(crv)
Exemple #13
0
def helix():

    # create starting parameters for helix
    M = 20
    t = np.linspace(0, 2 * np.pi / 3, M)
    a = 30
    b = 30

    s = []
    C = a**2 + b**2
    for i in range(0, len(t)):
        s.append(np.sqrt(C) * t[i])

    r = []
    T = []
    N = []
    B = []

    for i in range(0, len(s)):
        # generate a helical axis first
        r.append([
            a * np.cos(s[i] / np.sqrt(C)), a * np.sin(s[i] / np.sqrt(C)),
            b * s[i] / np.sqrt(C)
        ])

        # create the tangential, normal, and binormal vectors
        T.append([
            -a / np.sqrt(C) * np.sin(s[i] / np.sqrt(C)),
            a / np.sqrt(C) * np.cos(s[i] / np.sqrt(C)), b / np.sqrt(C)
        ])
        N.append([-np.cos(s[i] / np.sqrt(C)), -np.sin(s[i] / np.sqrt(C)), 0])

    B.append(np.cross(T, N))

    # store them as numpy arrays for convenience
    r = np.array(r)
    Ts = np.array(T)
    Ns = np.array(N)
    Bs = np.array(B[0])

    # scatter the T, N, and B vectors
    fig = plt.figure()
    ax = plt.axes(projection="3d")

    # these scatter points serves as a check to make sure that the T, N , B vectors work

    # ax.plot(r[:,0],r[:,1],r[:,2],color = 'r')
    # ax.scatter(r[5,0]+Ts[5,0],r[5,1]+Ts[5,1],r[5,2]+Ts[5,2],color = 'b')
    # ax.scatter(r[5,0],r[5,1],r[5,2],color = 'k')
    # ax.scatter(r[5,0]-Ts[5,0],r[5,1]-Ts[5,1],r[5,2]-Ts[5,2],color = 'g')

    # ax.scatter(Bs[:,0],Bs[:,1],Bs[:,2],color = 'g')
    # ax.scatter(Ns[:,0],Ns[:,1],Ns[:,2],color = 'b')

    helix = []
    phi = np.linspace(0, 2 * np.pi, M)
    d = 10
    for i in range(0, len(s)):
        for j in range(0, len(phi)):
            helix.append([
                d * Bs[i, 0] * np.cos(phi[j]) + d * Ns[i, 0] * np.sin(phi[j]) +
                r[i, 0], d * Bs[i, 1] * np.cos(phi[j]) +
                d * Ns[i, 1] * np.sin(phi[j]) + r[i, 1],
                d * Bs[i, 2] * np.cos(phi[j]) + d * Ns[i, 2] * np.sin(phi[j]) +
                r[i, 2]
            ])

    helix = np.array(helix)
    np.savetxt("helical_cylinder.csv", helix, delimiter=',')

    ax.scatter(helix[:, 0], helix[:, 1], helix[:, 2])
    ax.set_title("Helical Tube Point Cloud")
    ax.set_xlabel('x')
    ax.set_ylabel('y')
    ax.set_zlabel('z')
    plt.show()
    p_ctrlpts = helix
    size_u = M
    size_v = M
    degree_u = 3
    degree_v = 3

    # Do global surface approximation
    surf = fitting.approximate_surface(p_ctrlpts, size_u, size_v, degree_u,
                                       degree_v)

    surf = convert.bspline_to_nurbs(surf)

    # Extract curves from the approximated surface
    surf_curves = construct.extract_curves(surf)
    plot_extras = [
        dict(points=surf_curves['u'][0].evalpts,
             name="u",
             color="red",
             size=10),
        dict(points=surf_curves['v'][0].evalpts,
             name="v",
             color="black",
             size=10)
    ]
    tube_pcl = np.array(surf.evalpts)
    tube_cpts = np.array(surf.ctrlpts)

    # np.savetxt("cpts_bezier.dat",r,delimiter = ',')
    # from matplotlib import cm
    surf.delta = 0.02
    surf.vis = vis.VisSurface()
    surf.render(extras=plot_extras)
    exchange.export_obj(surf, "helix.stl")
    np.savetxt("RV_tube.dat", tube_pcl, delimiter=' ')
    # np.savetxt("tube_cpts.dat",tube_cpts,delimiter = ' ')
    np.savetxt("tube_cpts.csv", tube_cpts, delimiter=',')

    # crv = BSpline.Curve()
    # crv.degree = 3
    # crv.ctrlpts = exchange.import_txt("cpts_tube.dat")
    # crv.knotvector = knotvector.generate(crv.degree, crv.ctrlpts_size)

    # # Set the visualization component of the curve
    # crv.vis = vis.VisCurve3D()

    # # Plot the curve
    # crv.render()
    return surf
Exemple #14
0
def nurbs_curve(spline_curve):
    curve = convert.bspline_to_nurbs(spline_curve)
    curve.weights = [0.5, 1.0, 0.75, 1.0, 0.25, 1.0]
    return curve