def create_loop(z_value, spline_surface, v_curve, n_points, loop): """ Sample the spline surface at a given z level, result is a loop as list of points :param z_value: z level of all extracted points :param spline_surface: the spline surface as Surface object of geomdl :param v_curve: a b-spline curve in z direction, created by construct.extract_curves(spline_surface)["v"][0] :param n_points: number of points that will be sampled :param loop: this is the output, this list will contain points """ # get the v value for the plane of the curve in z direction v = get_u_by_z_value(v_curve, z_value) # extract u curve in surface at that v value try: if v <= 1e-5: v = 1e-5 if v >= 1 - 1e-5: v = 1 - 1e-5 [s0, s1] = operations.split_surface_v(spline_surface, v) extracted_curves = construct.extract_curves(s1) curve = extracted_curves["u"][0] except Exception as e: print("Error in extracting u curve in surface at a v value") print("v: {}".format(v)) raise e curve.delta = 0.01 curve_length = operations.length_curve(curve) #curve_length = get_arc_length(curve, 1.0) u_init = 1e-5 for s in np.linspace(0, curve_length, n_points + 1)[:-1]: u_init = get_u_by_arclength(curve, s, u_init) point = curve.evaluate_single(u_init) point[2] = z_value loop.append(point)
# Set degrees 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 = operations.split_surface_v(surf, 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
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] # Split the surface in V-direction surfaces = operations.split_surface_v(surf, t=0.5) # Translate one of the surfaces by a vector operations.translate(surfaces[0], (0, -2.5, 0), inplace=True) # Set number of samples for all split surfaces surfaces.sample_size = 20 # Plot the control point grid and the evaluated surface vis_comp = VisMPL.VisSurface() surfaces.vis = vis_comp surfaces.render() # Good to have something here to put a breakpoint pass
def create_ring_section(spline_surface, start_point, end_point, z_value, n_points, debugging_points=[]): """ Sample points on a curve in the intersection of the x-y-plane z=z_value und the surface mesh, given by spline_surface, from nearest point to start_point to nearest point to end_point. The direction is such that the length of the curve is minimal (there are 2 possible orientations cw/ccw). :param spline_surface: a spline surface of the geomdl package :param start_point: the line starts at the point on the surface with given z_value, that is the nearest to start_point :param end_point: the line ends at the point on the surface with given z_value, that is the nearest to end_point :param z_value: the z level of the line on the surface :param n_points: number of points on the boundary """ debug = False # get curve in z direction v_curve = construct.extract_curves(spline_surface)["v"][0] # get the v value for the plane of the curve in z direction v = get_u_by_z_value(v_curve, z_value) if debug: print("create_ring_section z_value={}, n_points={}, v: {}".format( z_value, n_points, v)) # extract u curve in surface at that v value if v <= 1e-5: v = 1e-5 if v >= 1 - 1e-5: v = 1 - 1e-5 [s0, s1] = operations.split_surface_v(spline_surface, v) extracted_curves = construct.extract_curves(s1) curve = extracted_curves["u"][0] curve_length = operations.length_curve(curve) # find u value at start_point and end_point u_start = get_u_by_xy_value(curve, start_point[0:2]) u_end = get_u_by_xy_value(curve, end_point[0:2]) if debug: print("u in [{}, {}], curve_length: {}".format(u_start, u_end, curve_length)) # sample curve in between s_start = get_arc_length(curve, u_start) s_end = get_arc_length(curve, u_end) length_forwards = s_end - s_start if length_forwards < 0: length_forwards += curve_length length_backwards = s_start - s_end if length_backwards < 0: length_backwards += curve_length if debug: print("length forwards: {}, backwards: {}".format( length_forwards, length_backwards)) # if backwards is shorter, change start and end point if length_backwards < length_forwards: s_start, s_end = s_end, s_start if debug: print("go backwards, s in [{},{}]".format(s_start, s_end)) else: if debug: print("go forwards, s in [{},{}]".format(s_start, s_end)) # forward direction points = [] u = u_start # if passing boundary at u=1, u=0 is involved if s_end < s_start: if debug: print("passing boundary") section_length = curve_length - s_start + s_end interval_length = section_length / (n_points - 1) if debug: print("curve_length: {}, section_length: {}, interval_length: {}". format(curve_length, section_length, interval_length)) if debugging_points is not None: point = curve.evaluate_single(0.0) point[2] = z_value debugging_points.append(point) point = curve.evaluate_single(1.0) point[2] = z_value debugging_points.append(point) s = s_start for i in range(n_points): if abs(s - s_end) < 1e-7: if debug: print("reached s_end={}".format(s_end)) s = s_end # collect point u = get_u_by_arclength(curve, s, u) if debug: print("collect point {} for s={}, u={}".format(i, s, u)) point = curve.evaluate_single(u) point[2] = z_value points.append(point) # proceed s to next point s += interval_length if s > curve_length: s -= curve_length else: for s in np.linspace(s_start, s_end, n_points): u = get_u_by_arclength(curve, s, u) if debug: print("collect point for s={}, u={}".format(s, u)) point = curve.evaluate_single(u) point[2] = z_value points.append(point) # if start and end points were reversed, reverse back if length_backwards < length_forwards: points = list(reversed(points)) return points
# 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] # Split the surface surface_list1 = operations.split_surface_u(surf, param=0.25) surfaces1 = multi.SurfaceContainer(surface_list1) # Translate one of the split surfaces operations.translate(surfaces1[0], (0, 0, 5), inplace=True) # Split the other split surface surface_list2 = operations.split_surface_v(surfaces1[1], param=0.75) surfaces = multi.SurfaceContainer(surface_list2) surfaces.add(surfaces1[0]) # Set number of samples for all split surfaces surfaces.sample_size = 20 # Plot the control point grid and the evaluated surface vis_comp = VisMPL.VisSurfTriangle() surfaces.vis = vis_comp surfaces.render() # Good to have something here to put a breakpoint pass
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] # Split the surface surfaces1 = operations.split_surface_u(surf, t=0.25) # Translate one of the split surfaces operations.translate(surfaces1[0], (0, 0, 5), inplace=True) # Split the other split surface surfaces = operations.split_surface_v(surfaces1[1], t=0.75) surfaces.add(surfaces1[0]) # Set number of samples for all split surfaces surfaces.sample_size = 20 # Plot the control point grid and the evaluated surface vis_comp = VisMPL.VisSurfTriangle() surfaces.vis = vis_comp surfaces.render() # Good to have something here to put a breakpoint pass
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] # Split the surface on the v-direction surf_list = operations.split_surface_v(surf, param=0.5) surfaces = multi.SurfaceContainer(surf_list) # Translate one of the surfaces by a vector operations.translate(surfaces[0], (0, -2.5, 0), inplace=True) # Set number of samples for all split surfaces surfaces.sample_size = 20 # Plot the control point grid and the evaluated surface vis_comp = VisMPL.VisSurface() surfaces.vis = vis_comp surfaces.render() # Good to have something here to put a breakpoint pass