print " usage : tp8.py [torus,cylinder,grid,terrain] [subdivision_depth=1]" print " example : python tp8.py torus 3" else: # init Viewer viewer = Viewer("TP8 : Uniform B-spline SubSurf[" + dataname + "]", [1200, 800]) # open the datafile datafile = open(filename, 'r') # read control points and u_closed, v_closed M, u_closed, v_closed = ReadPoints(datafile) # add wireframe : control net viewer.add_patch(M[0, :, :], M[1, :, :], M[2, :, :], wireframe=True) # iterative subdivision for d in range(depth): # M = Sub(M,u_closed,v_closed) M = Subdivide( M, u_closed, v_closed) # if not algo_cc else Sub_C_C(M,u_closed,v_closed) # u_closed : make rows periodic if u_closed: rows = np.append(np.arange(M.shape[1]), 0) M = M[:, rows, :] # v_closed : make cols periodic if v_closed:
# get first line = number of patches numpatch = np.fromstring(datafile.readline(), sep=' ', dtype=int)[0] # init Viewer viewer = Viewer("TP6 : Bezier surfaces [" + dataname + "]", [1200, 800]) # read and compute each patch for p in range(numpatch): # print patch id print(" patch", p + 1, "/", numpatch) # read Bezier control points Mx, My, Mz = ReadBezierMesh(datafile) # compute surface points Sx = BezierSurf(Mx, density) Sy = BezierSurf(My, density) Sz = BezierSurf(Mz, density) # add patch to the Viewer viewer.add_patch(Sx, Sy, Sz) # print final message print(" done.") # display the viewer viewer.render()
viewer = Viewer("TP7 : B-spline surfaces [" + dataname + "]", [1200, 800]) # open the datafile datafile = open(filename, 'r') # read control points and knot sequences M, U, V = ReadBSplineMeshWithKnots(datafile, nurbs) # coordinate matrices Mx = M[0, :, :] My = M[1, :, :] Mz = M[2, :, :] # add wireframe : control net viewer.add_patch(Mx, My, Mz, wireframe=True) # NURBS weights : Multiply Mx, My, Mz by Mw if nurbs: Mw = M[3, :, :] Mx = np.multiply(Mx, Mw) My = np.multiply(My, Mw) Mz = np.multiply(Mz, Mw) # add control net wireframe to the viewer viewer.add_patch(Mx, My, Mz, wireframe=True) m = Mx.shape[0] - 1 # m+1 points in u-direction n = Mx.shape[1] - 1 # n+1 points in v-direction k = U.shape[0] - 1 # k+1 knots in u-direction