def draw_curve(self, curve): # Try to load the visualization module try: render_curve = True from geomdl.visualization import VisMPL except ImportError: render_curve = False # Draw the control point polygon and the evaluated curve if render_curve: vis_comp = VisMPL.VisCurve3D() curve.vis = vis_comp curve.render()
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_fig_save(bspline_curve3d): conf = VisMPL.VisConfig() vis = VisMPL.VisCurve3D(config=conf) fname = "test-curve.png" bspline_curve3d.vis = vis bspline_curve3d.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_fig_nowindow(bspline_curve2d): conf = VisMPL.VisConfig() vis = VisMPL.VisCurve3D(config=conf) fname = conf.figure_image_filename bspline_curve2d.vis = vis bspline_curve2d.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" 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 draw_curves(self, curvespts): # Try to load the visualization module try: render_curve = True from geomdl.visualization import VisMPL except ImportError: render_curve = False # Plot the curves using the curve container curves = Multi.MultiCurve() curves.delta = 0.01 for curve in curvespts: curves.add(curve) if render_curve: vis_comp = VisMPL.VisCurve3D() curves.vis = vis_comp curves.render()
def build_vis(obj, **kwargs): """ Prepares visualization module for the input spline geometry. :param obj: input spline geometry object :return: spline geometry object updated with a visualization module """ vis_config = VisMPL.VisConfig(**kwargs) if isinstance(obj, (NURBS.Curve, multi.CurveContainer)): if obj.dimension == 2: obj.vis = VisMPL.VisCurve2D(vis_config) elif obj.dimension == 3: obj.vis = VisMPL.VisCurve3D(vis_config) else: raise RuntimeError("Can only plot 2- or 3-dimensional curves") if isinstance(obj, (NURBS.Surface, multi.SurfaceContainer)): obj.vis = VisMPL.VisSurface(vis_config) if isinstance(obj, (NURBS.Volume, multi.VolumeContainer)): obj.vis = VisMPL.VisVolume(vis_config) return obj
for j in range(curve_geometry.NbPoles): data = model_part.GetNode(j + 1).X, model_part.GetNode( j + 1).Y, model_part.GetNode(j + 1).Z ctlpts_list.write( str(model_part.GetNode(j + 1).X) + ',' + str(model_part.GetNode(j + 1).Y) + ',' + str(model_part.GetNode(j + 1).Z) + '\n') ctlpts_list.close() plot_curve.ctrlpts = exchange.import_txt( "C:\_Masterarbeit\BeamValidation\python_base\Balken\ctlpts_list.txt") plot_curve.knotvector = utilities.generate_knot_vector( plot_curve.degree, len(plot_curve.ctrlpts)) # Set evaluation delta # plot_curve.delta = 0.001 # plot_curve.evaluate # add to mulit_curve multi_curve.add(plot_curve) # Set evaluation delta multi_curve.delta = 0.001 # multi_curve.evaluate # plot the controlpoint polygon and the evaluated curve vis_comp = VisMPL.VisCurve3D() multi_curve.vis = vis_comp multi_curve multi_curve.render(cpcolor='black', evalcolor='red') # multi_curve.render() pass
def vis_spline_curve(self, crv): crv.vis = VisMPL.VisCurve3D() crv.render()
import numpy as np import matplotlib.pyplot as plt from geomdl import fitting from geomdl import exchange from geomdl.visualization import VisMPL as vis ''' todo: fit 3d curves to central axes of the toroid experiments ''' con_toroid = exchange.import_csv("con_toroid_caxis.csv",delimiter = ',') print(len(con_toroid)) toroid = exchange.import_csv("toroid_caxis.csv",delimiter = ',') print(toroid) curve = fitting.approximate_curve(toroid,degree = 2,ctrlpts_size = 10) curve1 = fitting.approximate_curve(con_toroid,degree = 2,ctrlpts_size = 10-) # Plot the interpolated curve curve.delta = 0.005 curve.vis = vis.VisCurve3D(vis.VisConfig(ctrlpts=False)) curve.render() # Plot the interpolated curve curve1.delta = 0.005 curve1.vis = vis.VisCurve3D(vis.VisConfig(ctrlpts=False)) curve1.render()
# Fix file path os.chdir(os.path.dirname(os.path.realpath(__file__))) # Create a NURBS curve instance (full circle) curve = NURBS.Curve() # Set evaluation delta curve.delta = 0.01 # Set up curve curve.read_ctrlpts_from_txt("ex_curve04.cptw") curve.degree = 2 # Use a specialized knot vector curve.knotvector = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1] # Convert to a 3D curve curve3d = curve.add_dimension() # Translate curve to z = 5 curve3d.translate((0, 0, 5)) # Draw the control point polygon and the evaluated curve if render_curve: vis_config = VisMPL.VisConfig(ctrlpts=True) vis_comp = VisMPL.VisCurve3D(vis_config) curve3d.vis = vis_comp curve3d.render() # Good to have something here to put a breakpoint pass
# 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)