def test_insert(self): b, b2, xx = self.b, self.b2, self.xx j = b.t.size // 2 tn = 0.5 * (b.t[j] + b.t[j + 1]) bn, tck_n = insert(tn, b), insert(tn, (b.t, b.c, b.k)) assert_allclose(splev(xx, bn), splev(xx, tck_n), atol=1e-15) assert_(isinstance(bn, BSpline)) assert_(isinstance(tck_n, tuple)) # back-compat: tck in, tck out # for n-D array of coefficients, BSpline.c needs to be transposed # after that, the results are equivalent. sh = tuple(range(b2.c.ndim)) c_ = b2.c.transpose(sh[1:] + (0, )) tck_n2 = insert(tn, (b2.t, c_, b2.k)) bn2 = insert(tn, b2) # need a transpose for comparing the results, cf test_splev assert_allclose(np.asarray(splev(xx, tck_n2)).transpose(2, 0, 1), bn2(xx), atol=1e-15) assert_(isinstance(bn2, BSpline)) assert_(isinstance(tck_n2, tuple)) # back-compat: tck in, tck out
def test_insert(self): b, b2, xx = self.b, self.b2, self.xx j = b.t.size // 2 tn = 0.5*(b.t[j] + b.t[j+1]) bn, tck_n = insert(tn, b), insert(tn, (b.t, b.c, b.k)) assert_allclose(splev(xx, bn), splev(xx, tck_n), atol=1e-15) assert_(isinstance(bn, BSpline)) assert_(isinstance(tck_n, tuple)) # back-compat: tck in, tck out # for n-D array of coefficients, BSpline.c needs to be transposed # after that, the results are equivalent. sh = tuple(range(b2.c.ndim)) c_ = b2.c.transpose(sh[1:] + (0,)) tck_n2 = insert(tn, (b2.t, c_, b2.k)) bn2 = insert(tn, b2) # need a transpose for comparing the results, cf test_splev assert_allclose(np.asarray(splev(xx, tck_n2)).transpose(2, 0, 1), bn2(xx), atol=1e-15) assert_(isinstance(bn2, BSpline)) assert_(isinstance(tck_n2, tuple)) # back-compat: tck in, tck out
def skinning_curves(ctx,spls): ts = [t for t,c,k in spls] ks = [k for t,c,k in spls] n_curves = len(spls) k = ks[0] for j in ks: if j != k: return False knot_set = set() for t in ts: knot_set = knot_set.union(t) nurbs_surface = bpy.data.curves.new(name="leap_surface_nurbs",type="SURFACE") nurbs_surface.dimensions = "3D" object_surf_data = bpy.data.objects.new("leap_surface_nurbs_object",nurbs_surface) object_surf_data.location = (0,0,0) ctx.scene.objects.link(object_surf_data) for i in range(n_curves): knots = set(ts[i]) tck = spls[i] nP = len(tck[1][0]) knot_diff = knot_set - knots for new_k in knot_diff: tck = inter.insert(new_k,tck) nP +=1 cX,cY,cZ = tck[1] cX = cX[:nP] cY = cY[:nP] nurbs_curve = bpy.data.curves.new(name="leap_curve_nurbs",type="CURVE") nurbs_curve.dimensions = "2D" object_curve_data = bpy.data.objects.new("leap_curve_nurbs_object",nurbs_curve) object_curve_data.location = (0,0,0.5*i) ctx.scene.objects.link(object_curve_data) polyline_curve = nurbs_curve.splines.new("NURBS") polyline_curve.points.add(nP-1) for p,x,y in zip(polyline_curve.points,cX,cY): p.co = (x,y,0.0,1.0) polyline_curve.order_u = k+1 polyline_surf = nurbs_surface.splines.new("NURBS") polyline_surf.points.add(nP-1) for p,x,y in zip(polyline_surf.points,cX,cY): p.co = Vector((x,y,0.5*i,1.0)) p.select = True polyline_surf.order_u = k+1 ctx.scene.objects.active = object_surf_data bpy.ops.object.mode_set(mode='EDIT') bpy.ops.curve.make_segment() bpy.ops.object.mode_set(mode='OBJECT') nurbs_surface.splines[0].order_u = nurbs_surface.splines[0].order_u