Ejemplo n.º 1
0
    def test_split_5(self):
        points = np.array([[0, 0, 0], [0, 1, 0], [1, 2, 0], [2, 2, 0],
                           [3, 1, 0], [3, 0, 0]])
        weights = [1, 1, 1, 1, 1, 1]
        degree = 3
        knotvector = np.array([0, 0, 0, 0, 0.25, 0.75, 1, 1, 1, 1])
        #print("KV", knotvector)
        curve = SvNativeNurbsCurve(degree, knotvector, points, weights)

        t0 = knotvector[4]  # 0.25
        curve1, curve2 = curve.split_at(t0)
        expected_kv1 = np.array([0, 0, 0, 0, 0.25, 0.25, 0.25, 0.25])
        expected_kv2 = np.array([0.25, 0.25, 0.25, 0.25, 0.75, 1, 1, 1, 1])

        self.assert_numpy_arrays_equal(curve1.get_knotvector(),
                                       expected_kv1,
                                       precision=8)
        self.assert_numpy_arrays_equal(curve2.get_knotvector(),
                                       expected_kv2,
                                       precision=8)

        result = curve1.concatenate(curve2, remove_knots=True)
        expected_result_kv = knotvector
        self.assert_numpy_arrays_equal(result.get_knotvector(),
                                       expected_result_kv,
                                       precision=8)
Ejemplo n.º 2
0
    def test_remove_2(self):
        points = np.array(
            [[0, 0, 0], [0, 1, 0], [1, 2, 0], [2, 2, 0], [3, 1, 0], [3, 0, 0]],
            dtype=np.float64)
        degree = 3
        kv = np.array([0, 0, 0, 0, 0.25, 0.75, 1, 1, 1, 1])
        weights = [1, 1, 1, 1, 1, 1]
        curve = SvNativeNurbsCurve(degree, kv, points, weights)
        kv_err = sv_knotvector.check(degree, kv, len(points))
        if kv_err is not None:
            raise Exception(kv_err)
        knot = 0.1
        inserted = curve.insert_knot(knot, 1)

        self.assertEquals(len(inserted.get_control_points()), len(points) + 1)

        expected_inserted_kv = np.array(
            [0, 0, 0, 0, 0.1, 0.25, 0.75, 1, 1, 1, 1])
        self.assert_numpy_arrays_equal(inserted.get_knotvector(),
                                       expected_inserted_kv,
                                       precision=8)

        inserted_kv = inserted.get_knotvector()
        k = np.searchsorted(inserted_kv, knot, side='right') - 1
        s = sv_knotvector.find_multiplicity(inserted_kv, knot)
        print("K:", k, "S:", s)
        removed = inserted.remove_knot(knot, 1)
        self.assert_numpy_arrays_equal(removed.get_knotvector(),
                                       kv,
                                       precision=8)
Ejemplo n.º 3
0
    def test_split_2(self):
        points = np.array([[0, 0, 0], [1, 1, 0], [2, 0, 0]])
        kv = sv_knotvector.generate(2, 3)
        weights = [1, 1, 1]
        curve = SvNativeNurbsCurve(2, kv, points, weights)

        curve1, curve2 = curve.split_at(0.5)

        expected_kv1 = np.array([0, 0, 0, 0.5, 0.5, 0.5])
        kv1 = curve1.get_knotvector()
        self.assert_numpy_arrays_equal(kv1, expected_kv1, precision=8)

        expected_kv2 = np.array([0.5, 0.5, 0.5, 1, 1, 1])
        kv2 = curve2.get_knotvector()
        self.assert_numpy_arrays_equal(kv2, expected_kv2, precision=8)

        expected_pts1 = np.array([[0, 0, 0], [0.5, 0.5, 0], [1, 0.5, 0]])
        pts1 = curve1.get_control_points()
        #print("Pts1", pts1)
        self.assert_numpy_arrays_equal(pts1, expected_pts1, precision=8)

        expected_pts2 = np.array([[1, 0.5, 0], [1.5, 0.5, 0], [2, 0, 0]])
        pts2 = curve2.get_control_points()
        #print("Pts2", pts2)
        self.assert_numpy_arrays_equal(pts2, expected_pts2, precision=8)
Ejemplo n.º 4
0
    def test_ruled_surface_1(self):
        """
        Test that
        1) SvCurveLerpSurface.build gives a NURBS surface for two NURBS curves;
        2) the resulting surface is identical to generic ruled surface.
        """
        control_points1 = np.array([[0, 0, 0], [0.5, 0, 0.5], [1, 0, 0]])
        control_points2 = np.array([[0, 2, 0], [0.5, 3, 0.5], [1, 2, 0]])
        # With non-trivial weights, this test will fail,
        # because the resulting surface will have different parametrization
        # comparing to generic ruled surface; however, the shape of the surface
        # will be correct anyway.
        weights1 = [1, 1, 1]
        weights2 = [1, 1, 1]

        knotvector = sv_knotvector.generate(degree=2, num_ctrlpts=3)
        curve1 = SvNativeNurbsCurve(2, knotvector, control_points1, weights1)
        curve2 = SvNativeNurbsCurve(2, knotvector, control_points2, weights2)

        surf1 = SvCurveLerpSurface(curve1, curve2)
        surf2 = SvCurveLerpSurface.build(curve1, curve2)

        self.assertTrue(isinstance(surf2, SvNativeNurbsSurface))

        us = np.array([0, 0, 0.5, 0.5, 1, 1])
        vs = np.array([0, 0.5, 0.5, 1, 0.5, 1])

        pts1 = surf1.evaluate_array(us, vs)
        pts2 = surf2.evaluate_array(us, vs)

        self.assert_numpy_arrays_equal(pts1,
                                       pts2,
                                       precision=8,
                                       fail_fast=False)
Ejemplo n.º 5
0
    def test_remove_1(self):
        points = np.array([[0, 0, 0], [1, 1, 0], [2, 1, 0], [3, 0, 0]])
        degree = 3
        kv = np.array([0, 0, 0, 0, 1, 1, 1, 1], dtype=np.float64)
        weights = [1, 1, 1, 1]
        ts = np.linspace(0.0, 1.0, num=5)
        curve = SvNativeNurbsCurve(degree, kv, points, weights)
        orig_pts = curve.evaluate_array(ts)
        kv_err = sv_knotvector.check(degree, kv, len(points))
        if kv_err is not None:
            raise Exception(kv_err)
        knot = 0.5
        inserted = curve.insert_knot(knot, 2)
        self.assertEquals(len(inserted.get_control_points()), len(points) + 2)
        self.assert_numpy_arrays_equal(inserted.evaluate_array(ts),
                                       orig_pts,
                                       precision=8)

        expected_inserted_kv = np.array([0, 0, 0, 0, 0.5, 0.5, 1, 1, 1, 1])
        inserted_kv = inserted.get_knotvector()
        self.assert_numpy_arrays_equal(inserted_kv,
                                       expected_inserted_kv,
                                       precision=8)

        removed = inserted.remove_knot(knot, 2)
        expected_removed_kv = kv
        self.assert_numpy_arrays_equal(removed.get_knotvector(),
                                       expected_removed_kv,
                                       precision=8)
        self.assert_numpy_arrays_equal(removed.evaluate_array(ts),
                                       orig_pts,
                                       precision=8)
Ejemplo n.º 6
0
 def test_curve_tangent(self):
     geomdl_curve = SvGeomdlCurve.build(self.degree, self.knotvector,
                                        self.control_points, self.weights)
     t1s = geomdl_curve.tangent_array(self.ts)
     native_curve = SvNativeNurbsCurve(self.degree, self.knotvector,
                                       self.control_points, self.weights)
     t2s = native_curve.tangent_array(self.ts)
     self.assert_numpy_arrays_equal(t1s, t2s, precision=8)
Ejemplo n.º 7
0
 def test_curve_eval_2(self):
     weights = [1.0, 2.0, 3.0, 1.0]
     geomdl_curve = SvGeomdlCurve.build_geomdl(self.degree, self.knotvector,
                                               self.control_points, weights)
     t1s = geomdl_curve.evaluate_array(self.ts)
     native_curve = SvNativeNurbsCurve(self.degree, self.knotvector,
                                       self.control_points, weights)
     t2s = native_curve.evaluate_array(self.ts)
     self.assert_numpy_arrays_equal(t1s, t2s, precision=8)
Ejemplo n.º 8
0
 def test_single_1(self):
     points = np.array([[0, 0, 0], [1, 1, 0], [2, 0, 0]])
     kv = sv_knotvector.generate(2, 3)
     weights = [1, 1, 1]
     curve = SvNativeNurbsCurve(2, kv, points, weights)
     t = 0.5
     result = curve.evaluate(t)
     #print(result)
     expected = np.array([1, 0.5, 0])
     self.assert_numpy_arrays_equal(result, expected, precision=6)
Ejemplo n.º 9
0
 def test_insert_2(self):
     points = np.array([[0, 0, 0], [1, 1, 0], [2, 0, 0]])
     degree = 2
     kv = sv_knotvector.generate(degree, 3)
     weights = [1, 1, 1]
     curve = SvNativeNurbsCurve(degree, kv, points, weights)
     inserted = curve.insert_knot(0.5, 2)
     ts = np.array([0, 0.25, 0.5, 0.75, 1.0])
     expected = curve.evaluate_array(ts)
     result = inserted.evaluate_array(ts)
     self.assert_numpy_arrays_equal(result, expected, precision=8)
Ejemplo n.º 10
0
 def test_curve_3436_2(self):
     points = [(0, 0, 0), (0.5, 0, 0.5), (1, 0, 0)]
     ts = np.array([0, 0.5, 1])
     degree = 2
     knotvector = [0, 0, 0, 1, 1, 1]
     weights = [1, 1, 1]
     geomdl_curve = SvGeomdlCurve.build(degree, knotvector, points, weights)
     native_curve = SvNativeNurbsCurve(degree, knotvector, points, weights)
     p1s = geomdl_curve.third_derivative_array(ts)
     p2s = native_curve.third_derivative_array(ts)
     self.assert_numpy_arrays_equal(p1s, p2s, precision=8)
Ejemplo n.º 11
0
    def test_insert_1(self):
        points = np.array([[0, 0, 0], [1, 0, 0]])
        kv = sv_knotvector.generate(1, 2)
        weights = [1, 1]
        curve = SvNativeNurbsCurve(1, kv, points, weights)
        curve = curve.insert_knot(0.5)

        ts = np.array([0, 0.25, 0.5, 0.75, 1.0])
        expected = np.array([[0, 0, 0], [0.25, 0, 0], [0.5, 0, 0],
                             [0.75, 0, 0], [1, 0, 0]])
        result = curve.evaluate_array(ts)
        self.assert_numpy_arrays_equal(result, expected, precision=8)
Ejemplo n.º 12
0
    def test_insert_3(self):
        points = np.array([[0, 0, 0], [1, 1, 0], [2, 1, 0], [3, 0, 0]])
        degree = 2
        kv = sv_knotvector.generate(degree, 4)
        weights = [1, 1, 1, 1]

        #print("test_insert_3: Kv:", kv)
        curve = SvNativeNurbsCurve(degree, kv, points, weights)
        inserted = curve.insert_knot(0.5)

        #print("Ins.kv:", inserted.knotvector)
        #print("Ins.cp:", inserted.control_points)

        ts = np.array([0, 0.25, 0.5, 0.75, 1.0])
        expected = curve.evaluate_array(ts)
        result = inserted.evaluate_array(ts)
        self.assert_numpy_arrays_equal(result, expected, precision=8)
Ejemplo n.º 13
0
    def test_split_3(self):
        points = np.array([[0, 0, 0], [1, 1, 0], [2, 1, 0], [3, 0, 0]])
        weights = [1, 1, 1, 1]
        degree = 2
        knotvector = sv_knotvector.generate(degree, 4)
        curve = SvNativeNurbsCurve(degree, knotvector, points, weights)

        t0 = 0.5
        curve1, curve2 = curve.split_at(t0)
        #print("Kv1:", curve1.get_knotvector())
        #print("Kv2:", curve2.get_knotvector())

        pt1 = curve1.evaluate(0.25)
        expected_pt1 = curve.evaluate(0.25)
        self.assert_numpy_arrays_equal(pt1, expected_pt1, precision=4)

        pt2 = curve2.evaluate(0.75)
        expected_pt2 = curve.evaluate(0.75)
        self.assert_numpy_arrays_equal(pt2, expected_pt2, precision=4)
Ejemplo n.º 14
0
    def test_split_4(self):
        points = np.array([[0, 0, 0], [1, 1, 0], [2, 0, 0], [3, 1, 0],
                           [4, 0, 0]])
        degree = 3
        knotvector = sv_knotvector.generate(degree, 5)
        weights = [0.25, 1, 4.9, 2.35, 1]
        #weights = [1, 1, 1, 1, 1]
        curve = SvNativeNurbsCurve(degree, knotvector, points, weights)

        curve1, curve2 = curve.split_at(0.501)
        #print("Kv1:", curve1.get_knotvector())
        #print("Kv2:", curve2.get_knotvector())

        pt1 = curve1.evaluate(0.25)
        expected_pt1 = curve.evaluate(0.25)
        self.assert_numpy_arrays_equal(pt1, expected_pt1, precision=4)

        pt2 = curve2.evaluate(0.75)
        expected_pt2 = curve.evaluate(0.75)
        self.assert_numpy_arrays_equal(pt2, expected_pt2, precision=4)
Ejemplo n.º 15
0
 def make(vertices):
     metric = 'CENTRIPETAL' if self.centripetal else 'DISTANCE'
     vertices = np.array(vertices)
     if geomdl is not None and self.nurbs_implementation == SvNurbsCurve.GEOMDL:
         curve = SvGeomdlCurve.interpolate(degree,
                                           vertices,
                                           metric=metric)
     else:
         curve = SvNativeNurbsCurve.interpolate(degree,
                                                vertices,
                                                metric=metric)
     return curve
Ejemplo n.º 16
0
    def test_split_1(self):
        points = np.array([[0, 0, 0], [1, 0, 0]])
        kv = sv_knotvector.generate(1, 2)
        weights = [1, 1]
        curve = SvNativeNurbsCurve(1, kv, points, weights)

        curve1, curve2 = curve.split_at(0.5)

        expected_pts1 = np.array([[0, 0, 0], [0.5, 0, 0]])
        pts1 = curve1.get_control_points()
        self.assert_numpy_arrays_equal(pts1, expected_pts1)

        expected_pts2 = np.array([[0.5, 0, 0.0], [1, 0, 0]])
        pts2 = curve2.get_control_points()
        self.assert_numpy_arrays_equal(pts2, expected_pts2)

        expected_kv1 = np.array([0, 0, 0.5, 0.5])
        kv1 = curve1.get_knotvector()
        self.assert_numpy_arrays_equal(kv1, expected_kv1)

        expected_kv2 = np.array([0.5, 0.5, 1, 1])
        kv2 = curve2.get_knotvector()
        self.assert_numpy_arrays_equal(kv2, expected_kv2)