def test_curve3d_multi_fig_nowindow(bspline_curve3d): conf = VisMPL.VisConfig() vis = VisMPL.VisCurve3D(config=conf) multi = operations.decompose_curve(bspline_curve3d) multi.vis = vis multi.render(plot=False) assert os.path.isfile(conf.figure_image_filename) assert os.path.getsize(conf.figure_image_filename) > 0 # Clean up temporary file if exists if os.path.isfile(conf.figure_image_filename): os.remove(conf.figure_image_filename)
def test_curve3d_multi_fig_nowindow(bspline_curve3d): conf = VisMPL.VisConfig() vis = VisMPL.VisCurve3D(config=conf) data = operations.decompose_curve(bspline_curve3d) multi_shape = multi.CurveContainer(data) multi_shape.vis = vis multi_shape.render(plot=False) assert os.path.isfile(conf.figure_image_filename) assert os.path.getsize(conf.figure_image_filename) > 0 # Clean up temporary file if exists if os.path.isfile(conf.figure_image_filename): os.remove(conf.figure_image_filename)
def test_curve3d_multi_fig_save(bspline_curve3d): conf = VisMPL.VisConfig() vis = VisMPL.VisCurve3D(config=conf) fname = "test-multi_curve.png" multi = operations.decompose_curve(bspline_curve3d) multi.vis = vis multi.render(filename=fname, plot=False) 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_curve2d_multi_fig_nowindow(bspline_curve2d): conf = VisMPL.VisConfig() vis = VisMPL.VisCurve2D(config=conf) fname = conf.figure_image_filename data = operations.decompose_curve(bspline_curve2d) multi_shape = multi.CurveContainer(data) multi_shape.vis = vis multi_shape.render(plot=False) assert os.path.isfile(fname) assert os.path.getsize(fname) > 0 # Clean up temporary file if exists if os.path.isfile(conf.figure_image_filename): os.remove(conf.figure_image_filename)
def test_curve3d_multi_fig_save(bspline_curve3d): conf = VisMPL.VisConfig() vis = VisMPL.VisCurve3D(config=conf) fname = "test-multi_curve.png" data = operations.decompose_curve(bspline_curve3d) multi_shape = multi.CurveContainer(data) multi_shape.vis = vis multi_shape.render(filename=fname, plot=False) 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)
# 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
from geomdl import operations from geomdl import multi from geomdl.visualization import VisMPL # Fix file path os.chdir(os.path.dirname(os.path.realpath(__file__))) # Create a B-Spline curve instance curve = BSpline.Curve() # Set up the curve curve.degree = 4 curve.ctrlpts = exchange.import_txt("ex_curve01.cpt") # Auto-generate knot vector curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts)) # Decompose the curve into Bezier curve segments bezier_curves = operations.decompose_curve(curve) bezier = multi.CurveContainer(bezier_curves) # Plot the curves using the curve container bezier.sample_size = 40 vis_comp = VisMPL.VisCurve2D() bezier.vis = vis_comp bezier.render() # Good to have something here to put a breakpoint pass
knots = list(tck[0]) coeff = list(tck[1]) deg = tck[2] assert deg == 3 pts_int = [[x, y] for x, y in zip(coeff[0], coeff[1])] xi, yi = interpolate.splev(np.linspace(0, 1, 1000), tck) c = NURBS.Curve() c.degree = 3 c.ctrlpts = pts_int c.knotvector = knots '''c.vis = VisMPL.VisCurve2D(axes=False, labels=False, ctrlpts=False, legend=True) c.render()''' curves_0 = operations.decompose_curve(c) base_pts = [(p[0], p[1]) for c in curves_0 for p in c.ctrlpts] x, y, r = make_circle(base_pts) # O(n) center = (x, y) radius = r pts_pr = [] for c in curves_0: pts_pr.append(project_to_circle(c.ctrlpts[0], center, radius)) curves_1 = [] for i in range(len(pts_pr) - 1): c = NURBS.Curve() c.degree = 3 c.ctrlpts = [ pts_pr[i],
# Set up the visualisation settings vis_config = VisMPL.VisConfig( legend=False, ctrlpts=True) # Set ctrlpts=True to plot control points with the curves vis_comp = VisMPL.VisCurve2D(vis_config) # # Create the decomposed heart # # Generate the heart heart = generate_heart() # Decompose the B-Spline into Bezier curves heart_bezier = operations.decompose_curve(heart) # Set evaluation delta heart_bezier.delta = 0.001 # Print output information print( "Displaying the decomposed heart. Note that each set of control points for each Bezier curve is given a different colour, but that colour does not necessarily match up with the relevant Bezier curve. Each different coloured segment represents a different Bezier curve." ) # Draw the control point polygon and the bezier curves from the decomposition heart_bezier.vis = vis_comp heart_bezier.render() """ Question 2b: Describe any extra geometrical property is required to maintain for supporting proper shape editing of the heart-shaped object through the decomposed Bezier curves. Show how such property is applied.
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
from geomdl.shapes import curve2d from geomdl import operations from geomdl import multi from geomdl.visualization import VisMPL # Generate a NURBS full circle from 7 control points circle = curve2d.full_circle2(radius=5.0) circle.sample_size = 75 # Render the circle and the control points polygon vis_config = VisMPL.VisConfig(ctrlpts=True, figure_size=[9, 8]) vis_comp = VisMPL.VisCurve2D(config=vis_config) circle.vis = vis_comp circle.render() # Decompose the circle into Bezier curve segments segments = operations.decompose_curve(circle) bezier_segments = multi.CurveContainer(segments) # Set sample size (delta) bezier_segments.sample_size = 25 # Render the Bezier curve segments and their control points polygons vis_config = VisMPL.VisConfig(ctrlpts=True, figure_size=[9, 8]) vis_comp = VisMPL.VisCurve2D(config=vis_config) bezier_segments.vis = vis_comp bezier_segments.render() # Good to have something here to put a breakpoint pass