Пример #1
0
    def test_gauss_curvature_2(self):
        weights = [[1, 1, 1, 1], [1, 2, 3, 1], [1, 3, 4, 1], [1, 4, 5, 1],
                   [1, 1, 1, 1]]
        #us, vs = self.us, self.vs

        us = np.linspace(0.0, 1.0, num=10)
        vs = np.linspace(0.0, 1.0, num=20)
        us, vs = np.meshgrid(us, vs)
        us = us.flatten()
        vs = vs.flatten()

        geomdl_surface = SvGeomdlSurface.build_geomdl(
            self.degree_u, self.degree_v, self.knotvector_u, self.knotvector_v,
            self.control_points, weights)
        native_surface = SvNativeNurbsSurface(self.degree_u, self.degree_v,
                                              self.knotvector_u,
                                              self.knotvector_v,
                                              self.control_points, weights)
        c1 = geomdl_surface.curvature_calculator(us, vs)
        c2 = native_surface.curvature_calculator(us, vs)
        self.assert_numpy_arrays_equal(c1.fu, c2.fu, precision=8)
        self.assert_numpy_arrays_equal(c1.fv, c2.fv, precision=8)
        self.assert_numpy_arrays_equal(c1.duu, c2.duu, precision=8)
        self.assert_numpy_arrays_equal(c1.dvv, c2.dvv, precision=8)
        self.assert_numpy_arrays_equal(c1.duv, c2.duv, precision=8)
        self.assert_numpy_arrays_equal(c1.nuu,
                                       c2.nuu,
                                       precision=8,
                                       fail_fast=False)
        self.assert_numpy_arrays_equal(c1.nvv, c2.nvv, precision=8)
        self.assert_numpy_arrays_equal(c1.nuv, c2.nuv, precision=8)
        vs1 = geomdl_surface.gauss_curvature_array(self.us, self.vs)
        vs2 = native_surface.gauss_curvature_array(self.us, self.vs)
        self.assert_numpy_arrays_equal(vs1, vs2, precision=8, fail_fast=False)
Пример #2
0
 def test_gauss_curvature(self):
     geomdl_surface = SvGeomdlSurface.build_geomdl(
         self.degree_u, self.degree_v, self.knotvector_u, self.knotvector_v,
         self.control_points, self.weights)
     native_surface = SvNativeNurbsSurface(self.degree_u, self.degree_v,
                                           self.knotvector_u,
                                           self.knotvector_v,
                                           self.control_points,
                                           self.weights)
     vs1 = geomdl_surface.gauss_curvature_array(self.us, self.vs)
     vs2 = native_surface.gauss_curvature_array(self.us, self.vs)
     self.assert_sverchok_data_equal(vs1, vs2, precision=8)
Пример #3
0
 def test_normal(self):
     geomdl_surface = SvGeomdlSurface.build_geomdl(
         self.degree_u, self.degree_v, self.knotvector_u, self.knotvector_v,
         self.control_points, self.weights)
     native_surface = SvNativeNurbsSurface(self.degree_u, self.degree_v,
                                           self.knotvector_u,
                                           self.knotvector_v,
                                           self.control_points,
                                           self.weights)
     vs1 = geomdl_surface.normal_array(self.us, self.vs)
     vs2 = native_surface.normal_array(self.us, self.vs)
     self.assert_numpy_arrays_equal(vs1, vs2, precision=8)
Пример #4
0
    def test_eval_2(self):
        weights = [[1, 1, 1, 1], [1, 2, 3, 1], [1, 3, 4, 1], [1, 4, 5, 1],
                   [1, 1, 1, 1]]

        geomdl_surface = SvGeomdlSurface.build_geomdl(
            self.degree_u, self.degree_v, self.knotvector_u, self.knotvector_v,
            self.control_points, weights)
        native_surface = SvNativeNurbsSurface(self.degree_u, self.degree_v,
                                              self.knotvector_u,
                                              self.knotvector_v,
                                              self.control_points, weights)
        vs1 = geomdl_surface.evaluate_array(self.us, self.vs)
        vs2 = native_surface.evaluate_array(self.us, self.vs)
        self.assert_numpy_arrays_equal(vs1, vs2, precision=8, fail_fast=False)
Пример #5
0
    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")
        if curve.get_degree() != curve2.get_degree():
            raise UnsupportedCurveTypeException("curves have different degrees")

        #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_curves(curve, curve2)
            #raise UnsupportedCurveTypeException("curves have different knot vectors")

        my_control_points = curve.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.weights, curve2.get_weights())).T
        knotvector_v = sv_knotvector.generate(1, 2, clamped=True)

        surface = SvNativeNurbsSurface(degree_u = curve.degree, degree_v = 1,
                        knotvector_u = curve.knotvector, knotvector_v = knotvector_v,
                        control_points = control_points,
                        weights = weights)
        return surface
Пример #6
0
 def extrude_along_vector(self, vector):
     vector = np.array(vector)
     other_control_points = self.control_points + vector
     control_points = np.stack((self.control_points, other_control_points))
     control_points = np.transpose(control_points, axes=(1,0,2))
     weights = np.stack((self.weights, self.weights)).T
     knotvector_v = sv_knotvector.generate(1, 2, clamped=True)
     surface = SvNativeNurbsSurface(degree_u = self.degree, degree_v = 1,
                     knotvector_u = self.knotvector, knotvector_v = knotvector_v,
                     control_points = control_points,
                     weights = weights)
     return surface