def extrude_to_point(self, point): my_control_points = self.get_control_points() n = len(my_control_points) other_control_points = np.empty((n, 3)) other_control_points[:] = point control_points = np.stack((my_control_points, other_control_points)) control_points = np.transpose(control_points, axes=(1, 0, 2)) my_weights = self.get_weights() other_weights = my_weights #other_weights = np.ones((n,)) weights = np.stack((my_weights, other_weights)).T knotvector_u = self.get_knotvector() knotvector_v = sv_knotvector.generate(1, 2, clamped=True) degree_u = self.get_degree() degree_v = 1 surface = SvNurbsMaths.build_surface(self.get_nurbs_implementation(), degree_u, degree_v, knotvector_u, knotvector_v, control_points, weights) return surface
def build(cls, implementation, degree_u, degree_v, knotvector_u, knotvector_v, control_points, weights=None, normalize_knots=False): return SvNurbsMaths.build_surface(implementation, degree_u, degree_v, knotvector_u, knotvector_v, control_points, weights, normalize_knots)
def to_nurbs(self, implementation = SvNurbsMaths.NATIVE): u_min, u_max = self.u_bounds v_min, v_max = self.v_bounds pt1 = self.evaluate(u_min, v_min) pt2 = self.evaluate(u_min, v_max) pt3 = self.evaluate(u_max, v_min) pt4 = self.evaluate(u_max, v_max) control_points = np.array([[pt1, pt2], [pt3, pt4]]) weights = np.array([[1,1], [1, 1]]) degree_u = degree_v = 1 knotvector_u = knotvector_v = sv_knotvector.generate(1, 2) return SvNurbsMaths.build_surface(implementation, degree_u, degree_v, knotvector_u, knotvector_v, control_points, weights)
def make_ruled_surface(self, curve2, vmin, vmax): curve = self curve2 = SvNurbsCurve.to_nurbs(curve2) if curve2 is None: raise UnsupportedCurveTypeException("second curve is not NURBS") curve, curve2 = unify_curves_degree([curve, curve2]) if curve.get_degree() != curve2.get_degree(): raise UnsupportedCurveTypeException( f"curves have different degrees: {curve.get_degree()} != {curve2.get_degree()}" ) #print(f"kv1: {curve.get_knotvector().shape}, kv2: {curve2.get_knotvector().shape}") kv1, kv2 = curve.get_knotvector(), curve2.get_knotvector() if kv1.shape != kv2.shape or (kv1 != kv2).any(): curve, curve2 = unify_two_curves(curve, curve2) #raise UnsupportedCurveTypeException("curves have different knot vectors") my_control_points = curve.get_control_points() other_control_points = curve2.get_control_points() if len(my_control_points) != len(other_control_points): raise UnsupportedCurveTypeException( "curves have different number of control points") if vmin != 0: my_control_points = ( 1 - vmin) * my_control_points + vmin * other_control_points if vmax != 0: other_control_points = ( 1 - vmax) * my_control_points + vmax * other_control_points control_points = np.stack((my_control_points, other_control_points)) control_points = np.transpose(control_points, axes=(1, 0, 2)) weights = np.stack((curve.get_weights(), curve2.get_weights())).T knotvector_v = sv_knotvector.generate(1, 2, clamped=True) surface = SvNurbsMaths.build_surface( self.get_nurbs_implementation(), degree_u=curve.get_degree(), degree_v=1, knotvector_u=curve.get_knotvector(), knotvector_v=knotvector_v, control_points=control_points, weights=weights) return surface
def surface_to_freecad(sv_surface, make_face=False): """ Convert SvSurface into FreeCAD's Surface. The surface must be presentable as NURBS. input: * sv_surface: SvSurface * make_face: if True, create a Part.Face out of the surface and assign it to the `face` property of the resulting surface output: SvFreeCadNurbsSurface """ nurbs = SvNurbsSurface.get(sv_surface) if nurbs is None: raise TypeError(f"{sv_surface} is not a NURBS surface") sv_fc_nurbs = SvNurbsMaths.build_surface(SvNurbsMaths.FREECAD, nurbs.get_degree_u(), nurbs.get_degree_v(), nurbs.get_knotvector_u(), nurbs.get_knotvector_v(), nurbs.get_control_points(), nurbs.get_weights()) if make_face: sv_fc_nurbs.face = Part.Face(sv_fc_nurbs.surface) return sv_fc_nurbs