def test_export_obj_single(nurbs_surface): fname = FILE_NAME + ".obj" nurbs_surface.sample_size = SAMPLE_SIZE exchange.export_obj(nurbs_surface, fname) assert os.path.isfile(fname) assert os.path.getsize(fname) > 0 # Clean up temporary file if exists if os.path.isfile(fname): os.remove(fname)
def test_export_obj_multi(nurbs_surface_decompose): fname = FILE_NAME + ".obj" nurbs_multi = operations.decompose_surface(nurbs_surface_decompose) nurbs_multi.sample_size = SAMPLE_SIZE exchange.export_obj(nurbs_multi, fname) assert os.path.isfile(fname) assert os.path.getsize(fname) > 0 # Clean up temporary file if exists if os.path.isfile(fname): os.remove(fname)
def test_export_obj_multi(nurbs_surface_decompose): fname = FILE_NAME + ".obj" data = operations.decompose_surface(nurbs_surface_decompose) nurbs_multi = multi.SurfaceContainer(data) nurbs_multi.sample_size = SAMPLE_SIZE exchange.export_obj(nurbs_multi, fname) assert os.path.isfile(fname) assert os.path.getsize(fname) > 0 # Clean up temporary file if exists if os.path.isfile(fname): os.remove(fname)
# Set knot vectors surf.knotvector_u = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] surf.knotvector_v = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] # Set sample size surf.sample_size = 35 # Set surface tessellation component surf.tessellator = tessellate.TrimTessellate() # Set visualization component visconf = vis.VisConfig(ctrlpts=False, legend=False) surf.vis = vis.VisSurface(config=visconf) # Generate a circular trim curve tcrv = analytic.Circle(origin=(0.5, 0.5), radius=0.25) tcrv.opt = ['reversed', 1] trim_curves = [tcrv] # Set trim curves (as a list) surf.trims = trim_curves # Visualize surface # surf.render() # # Save as Wavefront OBJ file exchange.export_obj(surf, "trim_single.obj") # Good to have something here to put a breakpoint pass
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Examples for the NURBS-Python Package Released under MIT License Developed by Onur Rauf Bingol (c) 2018 Exporting a NURBS surface as .obj file """ from geomdl.shapes import surface from geomdl import exchange cylinder = surface.cylinder(radius=5.0, height=22.5) cylinder.delta = 0.05 # Export the surface as a .obj file exchange.export_obj(cylinder, "cylindrical_surface.obj") # Good to have something here to put a breakpoint pass
name="u", color="red", size=10 ), dict( points=surf_curves['v'][0].evalpts, name="v", color="black", size=10 ) ] toroid_pcl = np.array(surf.evalpts) np.savetxt("tapered_toroid_pcl.csv",toroid_pcl,delimiter = ',') toroid_cpts = np.array(surf.ctrlpts) np.savetxt("toroid_cpts.csv",toroid_cpts,delimiter = ',',fmt = "%1.3f") print(len(toroid_cpts)) # np.savetxt("cpts_bezier.dat",r,delimiter = ',') # from matplotlib import cm surf.delta = 0.03 surf.vis = vis.VisSurface() surf.render(extras=plot_extras) exchange.export_obj(surf, "tapered_toroid.obj") np.savetxt("tapered_toroid.dat",toroid_pcl,delimiter = ' ') # np.savetxt("tube_cpts.dat",tube_cpts,delimiter = ' ') plt.show()
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Examples for the NURBS-Python Package Released under MIT License Developed by Onur Rauf Bingol (c) 2018 """ import os from geomdl import exchange from geomdl.visualization import VisPlotly as vis # Fix file path os.chdir(os.path.dirname(os.path.realpath(__file__))) # Read a directory containing smesh files multi_smesh = exchange.import_smesh('data') multi_smesh.sample_size = 5 # Draw the control point grid and the evaluated surface vis_config = vis.VisConfig(ctrlpts=False, legend=False) vis_comp = vis.VisSurface(vis_config) multi_smesh.vis = vis_comp multi_smesh.render() # Save MultiSurface as a .obj file exchange.export_obj(multi_smesh, "multisurface01.obj") # Good to have something here to put a breakpoint pass
import numpy as np import matplotlib.pyplot as plt from geomdl import fitting from geomdl import convert from geomdl import construct from geomdl.visualization import VisMPL as vis import sys np.set_printoptions(threshold=sys.maxsize) from tools import preProcess from geomdl import exchange from geomdl import knotvector from geomdl import BSpline from generateHelix import helix ctrlpts = np.loadtxt("test1.txt") np.savetxt("candidate_cpts.csv", ctrlpts, delimiter=',') helix = helix() c = np.array(helix.ctrlpts) print(c) fig = plt.figure() ax = plt.axes(projection='3d') ax.scatter(c[:, 0], c[:, 1], c[:, 2]) helix.ctrlpts = ctrlpts helix.delta = 0.015 helix.vis = vis.VisSurface() helix.render() exchange.export_obj(helix, "trial0.obj")
# Set knot vectors surf.knotvector_u = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] surf.knotvector_v = [0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0, 3.0, 3.0] # Set sample size surf.sample_size = 25 # Set surface tessellation component surf.tessellator = tessellate.TrimTessellate() # Set visualization component visconf = vis.VisConfig(ctrlpts=False, legend=False) surf.vis = vis.VisSurface(config=visconf) # Generate a circular trim curve tcrv = analytic.Circle(origin=(0.5, 0.5), radius=0.25) trim_curves = [tcrv] # Set trim curves (as a list) surf.trims = trim_curves # Visualize surface surf.render(colormap=cm.copper) # Save as Wavefront OBJ file exchange.export_obj(surf, "surf-circular_trim.obj") # Good to have something here to put a breakpoint pass
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.02 surf.vis = vis.VisSurface() surf.render(extras=plot_extras) exchange.export_obj(surf, "fitted_cyl.obj") exchange.export_stl(surf, "fitted_cyl.stl") # visualize data samples, original RV data, and fitted surface eval_surf = np.array(surf.evalpts) np.savetxt("RV_cyl.dat", eval_surf, delimiter=' ') cpts = np.array(surf.ctrlpts) ########### cyl_cpts = np.array(surf.ctrlpts) # tube_cpts = np.loadtxt('cpts_tube.dat') # print(len(cyl_cpts),len(tube_cpts)) np.savetxt("cpts_cyl.dat", cyl_cpts, delimiter=' ') np.savetxt("cyl_cpts.csv", cyl_cpts, delimiter=',') fig = plt.figure() ax = plt.axes(projection="3d") ax.scatter(eval_surf[:, 0], eval_surf[:, 1], eval_surf[:, 2], 'blue')
surf = fitting.approximate_surface(pts, size_u, size_v, degree_u, degree_v) surf = convert.bspline_to_nurbs(surf) surf.delta = 0.025 surf.vis = vis.VisSurface() evalpts = np.array(surf.evalpts) ax.scatter(evalpts[:, 0], evalpts[:, 1], evalpts[:, 2], color='b') # plt.show() surf_curves = construct.extract_curves(surf) plot_extras = [ dict(points=surf_curves['u'][0].evalpts, name="u", color="red", size=5), dict(points=surf_curves['v'][0].evalpts, name="v", color="black", size=5) ] # surf.render(extras = plot_extras) exchange.export_obj(surf, "clyinder_ed.obj") # compute analytical metric tensor a_E = [] a_F = [] a_G = [] for i in range(0, len(drdt)): a_E.append(np.dot(drdz[i], drdz[i])) a_F.append(np.dot(drdz[i], drdt[i])) a_G.append(np.dot(drdt[i], drdt[i])) a_metric_tensor = np.array([a_E, a_F, a_F, a_G]).T print('analytical metric tensor = ') print(a_metric_tensor) # compute the metric tensor uv = np.linspace(0, 1, 11)
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
def main(): path = "d:/Workspace/RV-Mapping/RVshape/" rm_file = "rm_RVendo_0" std_file = "standardSample_15x25_RVendo_0" remapped_RV_file = path + rm_file standard_RV_file = path + std_file trimmed_rv_file = np.loadtxt("d:/Workspace/RV-Mapping/RVshape/transformed_RVendo_0.txt") # trimmed_rv_file = np.loadtxt("d:/Workspace/RV-Mapping.py/processed_RVendo_0.txt") std_rv_data = np.loadtxt(standard_RV_file + ".csv", delimiter=",") # std_rv_data = preProcess(std_rv_data) rm_rv_data = np.loadtxt(remapped_RV_file + ".txt", delimiter="\t") rm_rv_data = rm_rv_data[rm_rv_data[:,2] > 1] rm_rv_data = rm_rv_data[rm_rv_data[:,2] < max(rm_rv_data[:,2]) - 11] # rm_rv_data = preProcess(rm_rv_data) points = std_rv_data # np.savetxt("trimmed_" + rm_file + ".txt",rm_rv_data) N = 25 M = 15 # surf,sampled_data = fit_Remapped_RV(N,M, rm_rv_data,flag = False) surf = fit_Standard_RV(N,M, std_rv_data) fig = plt.figure() ax = plt.axes(projection="3d") # ax.scatter(trimmed_rv_file[:, 0],trimmed_rv_file[:, 1],trimmed_rv_file[:, 2]) ax.scatter(std_rv_data[:, 0],std_rv_data[:, 1],std_rv_data[:, 2], s= 50,color = 'r') # ax.scatter(points[:, 0],points[:, 1],points[:, 2]) # ax.scatter(sampled_data[:, 0],sampled_data[:, 1],sampled_data[:, 2] , color = 'r') # ax.scatter3D(0*np.ones((len(points))),0*np.ones((len(points))),points[:, 2],color = 'r') ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') plt.axis('off') plt.show() # fig = plt.figure() # ax = plt.axes(projection="3d") # ax.scatter(std_rv_data[:, 0],std_rv_data[:, 1],std_rv_data[:, 2], color = 'r') # ax.scatter(trimmed_rv_file[:, 0],trimmed_rv_file[:, 1],trimmed_rv_file[:, 2]) # plt.axis('off') # plt.show() # np.savetxt("sampled_" + str(M) + 'x' + str(N) + '_' + rm_file + ".txt",sampled_data) # 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=5), dict(points=surf_curves["v"][0].evalpts, name="v", color="black", size=5), ] surf.delta = 0.02 surf.vis = vis.VisSurface() surf.render(extras=plot_extras) # exchange.export_obj(surf, rm_file + "_fit.obj") exchange.export_obj(surf, std_file + "_fit.obj") # # visualize data samples, original RV data, and fitted surface eval_surf = np.array(surf.evalpts) np.savetxt(std_file + "_NURBS_surf_pts.csv",eval_surf,delimiter = ',') # np.savetxt(rm_file + "_NURBS_surf_pts.csv",eval_surf,delimiter = ',') # # 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(trimmed_rv_file[:, 0],trimmed_rv_file[:, 1],trimmed_rv_file[:, 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) print(len(cpts)) # np.savetxt('cpts_'+rm_file+".csv",cpts, delimiter = ',') np.savetxt('cpts_'+ std_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()
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) ] tube_pcl = np.array(surf.evalpts) tube_cpts = np.array(surf.ctrlpts) np.savetxt("cpts_tube.dat", tube_cpts, delimiter=' ') from matplotlib import cm surf.delta = 0.018 surf.vis = vis.VisSurface(ctrlpts=False) surf.render(extras=plot_extras) exchange.export_obj(surf, "fitted_helix.obj") # visualize data samples, original RV data, and fitted surface np.savetxt("RV_tube.dat", tube_pcl, delimiter=' ') fig = plt.figure() ax = plt.axes(projection="3d") ax.scatter(tube_pcl[:, 0], tube_pcl[:, 1], tube_pcl[:, 2]) ax.scatter(points[:, 0], points[:, 1], points[:, 2], color="red") plt.show()