def gen_kern_seq(num_spline_dots=12, kernel_size=(19, 38)): curve_degree = num_spline_dots - 1 curve = BSpline.Curve() small_kernel_size = (int(np.round(kernel_size[0] / 1.5)) - 1, int(np.round(kernel_size[1] / 1.5)) - 1) phi = np.random.rand() * 2 * np.pi knot_dots = [[ small_kernel_size[0] * np.cos(phi), small_kernel_size[1] * np.sin(phi) ]] for i in range(1, num_spline_dots - 1): knot_dots += [[ np.random.randint(0, small_kernel_size[0]), np.random.randint(0, small_kernel_size[1]) ]] phi = np.random.rand() * 2 * np.pi knot_dots += [[ small_kernel_size[0] * np.cos(phi), small_kernel_size[1] * np.sin(phi) ]] curve.degree = curve_degree curve.ctrlpts = knot_dots curve.knotvector = generate_knot_vector(curve.degree, len(curve.ctrlpts)) curve1, curve2 = split_curve(curve, np.random.rand() * 0.2 + 0.4) curve1.delta = 0.005 curve2.delta = 0.005 curve1.evaluate() curve2.evaluate() pts_1 = np.array(curve1.evalpts) pts_1[:, 0] -= (pts_1[:, 0].min() - 2) pts_1[:, 1] -= (pts_1[:, 1].min() - 2) pts_2 = np.array(curve2.evalpts) pts_2[:, 0] -= (pts_2[:, 0].min() - 2) pts_2[:, 1] -= (pts_2[:, 1].min() - 2) k_dim = int(max(np.ceil(pts_1.max()), np.ceil(pts_2.max()))) + 2 k1 = kern_from_grid(pts_1, k_dim + 1) k2 = kern_from_grid(pts_2, k_dim + 1) cm_k1 = np.round(calculate_center_mass(k1), 0).astype(int) dim_k1_c = 2 * max(list(np.array(k1.shape) - cm_k1) + list(cm_k1)) cm_k2 = np.round(calculate_center_mass(k2), 0).astype(int) dim_k2_c = 2 * max(list(np.array(k2.shape) - cm_k2) + list(cm_k2)) dim_final = max(dim_k1_c, dim_k2_c) if dim_final % 2 == 0: dim_final += 1 k1 = expand(k1, (dim_final, dim_final)) k2 = expand(k2, (dim_final, dim_final)) k1 /= k1.sum() k2 /= k2.sum() return k1, k2
# Fix file path os.chdir(os.path.dirname(os.path.realpath(__file__))) # Create a BSpline (NUBS) curve instance curve = BSpline.Curve() # Set up the curve curve.degree = 3 curve.ctrlpts = exchange.import_txt("ex_curve02.cpt") # Auto-generate knot vector curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts)) # Split the curve curve1, curve2 = operations.split_curve(curve, 0.2) # Move the 1st curve a little bit far away from the 2nd curve c2tan = curve2.tangent(0.0, normalize=True) c2tanvec = [-1 * p for p in c2tan[1]] operations.translate(curve1, c2tanvec, inplace=True) # Plot the curves using the curve container curves = multi.CurveContainer() curves.sample_size = 40 curves.add(curve1) curves.add(curve2) vis_comp = VisMPL.VisCurve2D() curves.vis = vis_comp curves.render()
# 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)) # Split the curve curves = operations.split_curve(curve, 0.6) # Move the 1st curve a little bit far away from the 2nd curve c2tan = curves[1].tangent(0.0, normalize=True) c2tanvec = [-3 * p for p in c2tan[1]] operations.translate(curves[0], c2tanvec, inplace=True) # Plot the curves using the curve container curves.sample_size = 40 # Plot the curve vis_comp = VisMPL.VisCurve2D() curves.vis = vis_comp curves.render() # Good to have something here to put a breakpoint
# 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)) # Split the curve curve_list = operations.split_curve(curve, 0.6) curves = multi.CurveContainer(curve_list) # Move the 1st curve a little bit far away from the 2nd curve c2tan = curves[1].tangent(0.0, normalize=True) c2tanvec = [-3 * p for p in c2tan[1]] operations.translate(curves[0], c2tanvec, inplace=True) # Plot the curves using the curve container curves.sample_size = 40 # Plot the curve vis_comp = VisMPL.VisCurve2D() curves.vis = vis_comp curves.render()