def test_edge_surfaces(self): # test 3D surface vs 2D rational surface # more or less random 3D surface with p=[2,2] and n=[3,4] controlpoints = [[0, 0, 1], [-1, 1, 1], [0, 2, 1], [1, -1, 1], [1, 0, .5], [1, 1, 1], [2, 1, 1], [2, 2, .5], [2, 3, 1], [3, 0, 1], [4, 1, 1], [3, 2, 1]] basis1 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis2 = BSplineBasis(3, [0, 0, 0, .64, 2, 2, 2]) top = Surface(basis1, basis2, controlpoints) # more or less random 2D rational surface with p=[1,2] and n=[3,4] controlpoints = [[0, 0, 1], [-1, 1, .96], [0, 2, 1], [1, -1, 1], [1, 0, .8], [1, 1, 1], [2, 1, .89], [2, 2, .9], [2, 3, 1], [3, 0, 1], [4, 1, 1], [3, 2, 1]] basis1 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis2 = BSplineBasis(2, [0, 0, .4, .44, 1, 1]) bottom = Surface(basis1, basis2, controlpoints, True) vol = VolumeFactory.edge_surfaces(bottom, top) # set parametric domain to [0,1]^2 for easier comparison top.reparam() bottom.reparam() # verify on 7x7x2 evaluation grid for u in np.linspace(0, 1, 7): for v in np.linspace(0, 1, 7): for w in np.linspace(0, 1, 2): # rational basis, not linear in w-direction self.assertAlmostEqual( vol(u, v, w)[0], bottom(u, v)[0] * (1 - w) + top(u, v)[0] * w) # x-coordinate self.assertAlmostEqual( vol(u, v, w)[1], bottom(u, v)[1] * (1 - w) + top(u, v)[1] * w) # y-coordinate self.assertAlmostEqual( vol(u, v, w)[2], 0 * (1 - w) + top(u, v)[2] * w) # z-coordinate # test 3D surface vs 2D surface controlpoints = [[0, 0], [-1, 1], [0, 2], [1, -1], [1, 0], [1, 1], [2, 1], [2, 2], [2, 3], [3, 0], [4, 1], [3, 2]] basis1 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis2 = BSplineBasis(2, [0, 0, .4, .44, 1, 1]) bottom = Surface(basis1, basis2, controlpoints) # non-rational! vol = VolumeFactory.edge_surfaces(bottom, top) # also non-rational! # verify on 5x5x7 evaluation grid for u in np.linspace(0, 1, 5): for v in np.linspace(0, 1, 5): for w in np.linspace(0, 1, 7): # include inner evaluation points self.assertAlmostEqual( vol(u, v, w)[0], bottom(u, v)[0] * (1 - w) + top(u, v)[0] * w) # x-coordinate self.assertAlmostEqual( vol(u, v, w)[1], bottom(u, v)[1] * (1 - w) + top(u, v)[1] * w) # y-coordinate self.assertAlmostEqual( vol(u, v, w)[2], 0 * (1 - w) + top(u, v)[2] * w) # z-coordinate
def test_edge_surfaces(self): # test 3D surface vs 2D rational surface # more or less random 3D surface with p=[2,2] and n=[3,4] controlpoints = [[0, 0, 1], [-1, 1, 1], [0, 2, 1], [1, -1, 1], [1, 0, .5], [1, 1, 1], [2, 1, 1], [2, 2, .5], [2, 3, 1], [3, 0, 1], [4, 1, 1], [3, 2, 1]] basis1 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis2 = BSplineBasis(3, [0, 0, 0, .64, 2, 2, 2]) top = Surface(basis1, basis2, controlpoints) # more or less random 2D rational surface with p=[1,2] and n=[3,4] controlpoints = [[0, 0, 1], [-1, 1, .96], [0, 2, 1], [1, -1, 1], [1, 0, .8], [1, 1, 1], [2, 1, .89], [2, 2, .9], [2, 3, 1], [3, 0, 1], [4, 1, 1], [3, 2, 1]] basis1 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis2 = BSplineBasis(2, [0, 0, .4, .44, 1, 1]) bottom = Surface(basis1, basis2, controlpoints, True) vol = vf.edge_surfaces(bottom, top) # set parametric domain to [0,1]^2 for easier comparison top.reparam() bottom.reparam() # verify on 7x7x2 evaluation grid for u in np.linspace(0, 1, 7): for v in np.linspace(0, 1, 7): for w in np.linspace(0, 1, 2): # rational basis, not linear in w-direction self.assertAlmostEqual( vol(u, v, w)[0], bottom(u, v)[0] * (1 - w) + top(u, v)[0] * w) # x-coordinate self.assertAlmostEqual( vol(u, v, w)[1], bottom(u, v)[1] * (1 - w) + top(u, v)[1] * w) # y-coordinate self.assertAlmostEqual( vol(u, v, w)[2], 0 * (1 - w) + top(u, v)[2] * w) # z-coordinate # test 3D surface vs 2D surface controlpoints = [[0, 0], [-1, 1], [0, 2], [1, -1], [1, 0], [1, 1], [2, 1], [2, 2], [2, 3], [3, 0], [4, 1], [3, 2]] basis1 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis2 = BSplineBasis(2, [0, 0, .4, .44, 1, 1]) bottom = Surface(basis1, basis2, controlpoints) # non-rational! vol = vf.edge_surfaces(bottom, top) # also non-rational! # verify on 5x5x7 evaluation grid for u in np.linspace(0, 1, 5): for v in np.linspace(0, 1, 5): for w in np.linspace(0, 1, 7): # include inner evaluation points self.assertAlmostEqual( vol(u, v, w)[0], bottom(u, v)[0] * (1 - w) + top(u, v)[0] * w) # x-coordinate self.assertAlmostEqual( vol(u, v, w)[1], bottom(u, v)[1] * (1 - w) + top(u, v)[1] * w) # y-coordinate self.assertAlmostEqual( vol(u, v, w)[2], 0 * (1 - w) + top(u, v)[2] * w) # z-coordinate
def plane(self): dim = int( self.read_next_non_whitespace().strip()) center = np.array(next(self.fstream).split(), dtype=float) normal = np.array(next(self.fstream).split(), dtype=float) x_axis = np.array(next(self.fstream).split(), dtype=float) finite = next(self.fstream).strip() != '0' if finite: param_u= np.array(next(self.fstream).split(), dtype=float) param_v= np.array(next(self.fstream).split(), dtype=float) else: param_u= [-state.unlimited, +state.unlimited] param_v= [-state.unlimited, +state.unlimited] swap = next(self.fstream).strip() != '0' result = Surface() * [param_u[1]-param_u[0], param_v[1]-param_v[0]] + [param_u[0],param_v[0]] result.rotate(rotate_local_x_axis(x_axis, normal)) result = flip_and_move_plane_geometry(result,center,normal) result.reparam(param_u, param_v) if(swap): result.swap() return result
def test_reparam(self): # identity mapping, control points generated from knot vector basis1 = BSplineBasis(4, [2, 2, 2, 2, 3, 6, 7, 7, 7, 7]) basis2 = BSplineBasis(3, [-3, -3, -3, 20, 30, 31, 31, 31]) surf = Surface(basis1, basis2) self.assertAlmostEqual(surf.start(0), 2) self.assertAlmostEqual(surf.end(0), 7) self.assertAlmostEqual(surf.start(1), -3) self.assertAlmostEqual(surf.end(1), 31) surf.reparam((4, 10), (0, 9)) self.assertAlmostEqual(surf.start(0), 4) self.assertAlmostEqual(surf.end(0), 10) self.assertAlmostEqual(surf.start(1), 0) self.assertAlmostEqual(surf.end(1), 9) surf.reparam((5, 11), direction=0) self.assertAlmostEqual(surf.start(0), 5) self.assertAlmostEqual(surf.end(0), 11) self.assertAlmostEqual(surf.start(1), 0) self.assertAlmostEqual(surf.end(1), 9) surf.reparam((5, 11), direction='v') self.assertAlmostEqual(surf.start(0), 5) self.assertAlmostEqual(surf.end(0), 11) self.assertAlmostEqual(surf.start(1), 5) self.assertAlmostEqual(surf.end(1), 11) surf.reparam((-9, 9)) self.assertAlmostEqual(surf.start(0), -9) self.assertAlmostEqual(surf.end(0), 9) self.assertAlmostEqual(surf.start(1), 0) self.assertAlmostEqual(surf.end(1), 1) surf.reparam() self.assertAlmostEqual(surf.start(0), 0) self.assertAlmostEqual(surf.end(0), 1) self.assertAlmostEqual(surf.start(1), 0) self.assertAlmostEqual(surf.end(1), 1) surf.reparam((4, 10), (0, 9)) surf.reparam(direction=1) self.assertAlmostEqual(surf.start(0), 4) self.assertAlmostEqual(surf.end(0), 10) self.assertAlmostEqual(surf.start(1), 0) self.assertAlmostEqual(surf.end(1), 1)