def render_spline(ctrl_pts, rows, cols): ctrl_pts = ctrl_pts.reshape(-1, 3).detach().cpu().numpy().tolist() pts_h = rows pts_v = cols surf = BSpline.Surface() surf.degree_u = 3 surf.degree_v = 3 surf.set_ctrlpts(ctrl_pts, pts_h, pts_v) surf.knotvector_u = knotvector.generate(3, pts_h, clamped=True) surf.knotvector_v = knotvector.generate(3, pts_v, clamped=True) surf.delta = 0.025 surf.evaluate() surf.vis = VisPlotly.VisSurface() surf.render(colormap=cm.cool)
surf.degree_u = 3 surf.degree_v = 3 # Get the control points from the generated grid surf.ctrlpts2d = surfgrid.grid() # Set knot vectors surf.knotvector_u = utilities.generate_knot_vector(surf.degree_u, surf.ctrlpts_size_u) surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, surf.ctrlpts_size_v) # Split the surface at v = 0.35 split_surf = surf.split_v(0.35) # Set sample size of the split surface split_surf.sample_size = 25 # Generate the visualization component and its configuration vis_config = VisPlotly.VisConfig(ctrlpts=False, legend=False) vis_comp = VisPlotly.VisSurface(vis_config) # Set visualization component of the split surface split_surf.vis = vis_comp # Plot the split surface split_surf.render() # Good to have something here to put a breakpoint pass
# Fix file path os.chdir(os.path.dirname(os.path.realpath(__file__))) # Create a BSpline curve instance curve = BSpline.Curve() # Set degree curve.degree = 3 # Read control points from a file curve.ctrlpts = exchange.import_txt("ex_curve03.cpt") # Set knot vector curve.knotvector = [0, 0, 0, 0, 0.25, 0.25, 0.5, 0.75, 0.75, 1, 1, 1, 1] # Decompose the curve curve_list = operations.decompose_curve(curve) curve_decomposed = multi.CurveContainer(curve_list) # Set sample size for the decomposed curve curve_decomposed.sample_size = 25 # Plot the decomposed curve vis_comp = vis.VisCurve2D() curve_decomposed.vis = vis_comp curve_decomposed.render() # Good to have something here to put a breakpoint pass
os.chdir(os.path.dirname(os.path.realpath(__file__))) # Create a BSpline surface instance surf = BSpline.Surface() # Set degrees surf.degree_u = 3 surf.degree_v = 3 # Set control points surf.set_ctrlpts( *exchange.import_txt("ex_surface01.cpt", two_dimensional=True)) # 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 evaluation delta surf.delta = 0.025 # Evaluate surface points surf.evaluate() # Plot the control point grid and the evaluated surface vis_comp = VisPlotly.VisSurface() surf.vis = vis_comp surf.render() # 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 """ 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
# Set up the curve curve.degree = 3 curve.ctrlpts = exchange.import_txt("ex_curve03.cpt") # Auto-generate knot vector curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts)) # Set evaluation delta curve.delta = 0.01 # Evaulate curve curve.evaluate() # Draw the control point polygon and the evaluated curve vis_comp = VisPlotly.VisCurve2D() curve.vis = vis_comp curve.render() # Evaluate curve tangent at u = 0.0 curvetan1 = operations.tangent(curve, 0.0, normalize=True) # Evaluate curve tangent at u = 0.2 curvetan2 = operations.tangent(curve, 0.2, normalize=True) # Evaluate curve tangent at u = 0.5 curvetan3 = operations.tangent(curve, 0.5, normalize=True) # Evaluate curve tangent at u = 0.6 curvetan4 = operations.tangent(curve, 0.6, normalize=True)
from geomdl.visualization import VisPlotly as plotter # Fix file path os.chdir(os.path.dirname(os.path.realpath(__file__))) # Create a BSpline curve instance curve = BSpline.Curve() # Set degree curve.degree = 3 # Read control points from a file curve.ctrlpts = exchange.import_txt("ex_curve03.cpt") # Set knot vector curve.knotvector = [0, 0, 0, 0, 0.25, 0.25, 0.5, 0.75, 0.75, 1, 1, 1, 1] # Decompose the curve curve_decomposed = operations.decompose_curve(curve) # Set sample size for the decomposed curve curve_decomposed.sample_size = 25 # Plot the decomposed curve vis_comp = plotter.VisCurve2D() curve_decomposed.vis = vis_comp curve_decomposed.render() # Good to have something here to put a breakpoint pass
[surface0, surface1] = geomdl.operations.split_surface_u(surface_full, 0.4) [surface, surface2] = geomdl.operations.split_surface_u(surface1, 0.5555) # save surface to a pickle file pickle_filename = output_pickle_filename print("Write pickle file \"{}\"".format(pickle_filename)) with open(pickle_filename,"wb") as f: pickle.dump(surface,f) # here we have the surface, either loaded from an existing pickle file or newly created # triangulate the surface for output for surf in [surface]: surf.sample_size = 100 surf.evaluate() # plot the result if False: surface_full.vis = VisPlotly.VisSurface() surface_full.render() surface.vis = VisPlotly.VisSurface() #surface.vis = VisMPL.VisSurfWireframe() surface.render() # export as STL file print("write stl file \"{}\"".format(output_stl_filename)) geomdl.exchange.export_stl(surface, output_stl_filename) print("File \"{}\" written.".format(output_stl_filename))
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) # exchange.export_obj(surf_ed,"clyinder_ed.obj") # exchange.export_obj(surf_es,"clyinder_es.obj")
ax = plt.axes(projection='3d') ax.scatter(r[:, 0], r[:, 1], r[:, 2], s=50, color='r') pts = r size_u = 20 size_v = 20 degree_u = 3 degree_v = 3 # Do global surface approximation 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 = []