def kntins(self, uknots, vknots=None): """Insert new knots into the surface uknots - knots to be inserted along u direction vknots - knots to be inserted along v direction NOTE: No knot multiplicity will be increased beyond the order of the spline""" if len(vknots): # Force the v knot sequence to be a vector in ascending order vknots = numerix.sort(numerix.asarray(vknots, numerix.Float)) if numerix.any(vknots < 0.) or numerix.any(vknots > 1.): raise NURBSError, 'Illegal vknots sequence' coefs = numerix.resize( self.cntrl, (4 * self.cntrl.shape[1], self.cntrl.shape[2])) coefs, self.vknots = bspkntins(self.degree[1], coefs, self.vknots, vknots) self.cntrl = numerix.resize( coefs, (4, self.cntrl.shape[1], coefs.shape[1])) if len(uknots): # Force the u knot sequence to be a vector in ascending order uknots = numerix.sort(numerix.asarray(uknots, numerix.Float)) if numerix.any(uknots < 0.) or numerix.any(uknots > 1.): raise NURBSError, 'Illegal uknots sequence' coefs = numerix.transpose(self.cntrl, (0, 2, 1)) coefs = numerix.resize( coefs, (4 * self.cntrl.shape[2], self.cntrl.shape[1])) coefs, self.uknots = bspkntins(self.degree[0], coefs, self.uknots, uknots) coefs = numerix.resize(coefs, (4, self.cntrl.shape[2], coefs.shape[1])) self.cntrl = numerix.transpose(coefs, (0, 2, 1))
def extractU(self, v): "Extract curve in u-direction at parameter v." if numerix.any(v < 0.) or numerix.any(v > 1.): raise NURBSError, 'Out of parameter range [0,1]' if v == 0.: cntrl = self.cntrl[:, :, 0] knots = self.uknots[:] elif v == 1.: cntrl = self.cntrl[:, :, -1] knots = self.uknots[:] else: vknots = numerix.repeat( numerix.asarray([v], numerix.Float), [self.degree[0] * (self.cntrl.shape[1] + 1)]) coefs = numerix.resize( self.cntrl, (4 * self.cntrl.shape[1], self.cntrl.shape[2])) coefs, knots = bspkntins(self.degree[1], coefs, self.vknots, vknots) cntrl = numerix.resize(coefs, (4, self.cntrl.shape[1], coefs.shape[1])) i = 0 j = knots[0] for k in knots[1:]: if k == v: break elif k != j: i += 1 j = k return Crv.Crv(cntrl[:, :, i], self.uknots[:])
def extractV(self, u): "Extract curve in v-direction at parameter u." if numerix.any(u < 0.) or numerix.any(u > 1.): raise NURBSError, 'Out of parameter range [0,1]' if u == 0.: cntrl = self.cntrl[:, 0, :] knots = self.vknots[:] elif u == 1.: cntrl = self.cntrl[:, -1, :] knots = self.vknots[:] else: uknots = numerix.repeat( numerix.asarray([u], numerix.Float), [self.degree[1] * (self.cntrl.shape[2] + 1)]) coefs = numerix.transpose(self.cntrl, (0, 2, 1)) coefs = numerix.resize( coefs, (4 * self.cntrl.shape[2], self.cntrl.shape[1])) coefs, knots = bspkntins(self.degree[0], coefs, self.uknots, uknots) coefs = numerix.resize(coefs, (4, self.cntrl.shape[2], coefs.shape[1])) cntrl = numerix.transpose(coefs, (0, 2, 1)) i = 0 j = knots[0] for k in knots[1:]: if k == u: break elif k != j: i += 1 j = k return Crv.Crv(cntrl[:, i, :], self.vknots[:])
def extractV(self, u): "Extract curve in v-direction at parameter u." # if np.less(u, 0.) or np.greater(u, 1.): # raise NURBSError, 'Out of parameter range [0,1]' if u == 0.: cntrl = self.cntrl[:,0,:] knots = self.vknots[:] elif u == 1.: cntrl = self.cntrl[:,-1,:] knots = self.vknots[:] else: uknots = np.repeat(np.asarray([u], np.float),[self.degree[1]*(self.cntrl.shape[2] + 1)]) coefs = np.transpose(self.cntrl,(0, 2, 1)) coefs = np.resize(coefs,(4*self.cntrl.shape[2], self.cntrl.shape[1])) coefs, knots = bspkntins(self.degree[0], coefs, self.uknots, uknots) coefs = np.resize(coefs, (4, self.cntrl.shape[2], coefs.shape[1])) cntrl = np.transpose(coefs,(0,2,1)) i = 0 j = knots[0] for k in knots[1:]: if k == u: break elif k != j: i += 1 j = k return Crv.Crv(cntrl[:,i,:], self.vknots[:])
def kntins(self, uknots): """Insert new knots into the curve NOTE: No knot multiplicity will be increased beyond the order of the spline""" if len(uknots): uknots = numerix.sort(numerix.asarray(uknots, numerix.Float)) if numerix.any(uknots < 0.) or numerix.any(uknots > 1.): raise NURBSError, 'NURBS curve parameter out of range [0,1]' self.cntrl, self.uknots = bspkntins(self.degree, self.cntrl, self.uknots, uknots)
def kntins(self, uknots): """Insert new knots into the curve NOTE: No knot multiplicity will be increased beyond the order of the spline""" if len(uknots): uknots = np.sort(np.asarray(uknots, np.float)) if np.less(uknots, 0.) or np.greater(uknots, 1.): raise NURBSError, 'NURBS curve parameter out of range [0,1]' self.cntrl, self.uknots = bspkntins(self.degree, self.cntrl, self.uknots, uknots)
def kntins(self, uknots, vknots = None): """Insert new knots into the surface uknots - knots to be inserted along u direction vknots - knots to be inserted along v direction NOTE: No knot multiplicity will be increased beyond the order of the spline""" if len(vknots): # Force the v knot sequence to be a vector in ascending order vknots = np.sort(np.asarray(vknots, np.float)) # if np.less(vknots, 0.) or np.greater(vknots, 1.): # raise NURBSError, 'Illegal vknots sequence' coefs = np.resize(self.cntrl,(4*self.cntrl.shape[1], self.cntrl.shape[2])) coefs, self.vknots = bspkntins(self.degree[1], coefs, self.vknots, vknots) self.cntrl = np.resize(coefs, (4, self.cntrl.shape[1], coefs.shape[1])) if len(uknots): # Force the u knot sequence to be a vector in ascending order uknots = np.sort(np.asarray(uknots, np.float)) # if np.less(uknots, 0.) or np.greater(uknots, 1.): # raise NURBSError, 'Illegal uknots sequence' coefs = np.transpose(self.cntrl,(0, 2, 1)) coefs = np.resize(coefs,(4*self.cntrl.shape[2], self.cntrl.shape[1])) coefs, self.uknots = bspkntins(self.degree[0], coefs, self.uknots, uknots) coefs = np.resize(coefs, (4, self.cntrl.shape[2], coefs.shape[1])) self.cntrl = np.transpose(coefs,(0,2,1))
def extractU(self, v): "Extract curve in u-direction at parameter v." # if np.less(v, 0.) or np.greater(v, 1.): # raise NURBSError, 'Out of parameter range [0,1]' if v == 0.: cntrl = self.cntrl[:,:,0] knots = self.uknots[:] elif v == 1.: cntrl = self.cntrl[:,:,-1] knots = self.uknots[:] else: vknots = np.repeat(np.asarray([v], np.float),[self.degree[0]*(self.cntrl.shape[1] + 1)]) coefs = np.resize(self.cntrl,(4*self.cntrl.shape[1], self.cntrl.shape[2])) coefs, knots = bspkntins(self.degree[1], coefs, self.vknots, vknots) cntrl = np.resize(coefs, (4, self.cntrl.shape[1], coefs.shape[1])) i = 0 j = knots[0] for k in knots[1:]: if k == v: break elif k != j: i += 1 j = k return Crv.Crv(cntrl[:,:,i], self.uknots[:])