def test_edge_surfaces_six_sides_issue_141(self): # create the unit cube vol = Volume() # modify slightly one edge: umin(w=0) is now a parabola instead of a line vol.raise_order(0,1,0) vol.controlpoints[-1, 1, 0, 0] += 1 faces = vol.faces() # edge_surface should give back the same modified unit cube vol2 = vf.edge_surfaces(faces) # check discretization self.assertEqual(vol2.order(0),2) self.assertEqual(vol2.order(1),3) self.assertEqual(vol2.order(2),2) self.assertEqual(len(vol2.knots(0)),2) # [0, 1] self.assertEqual(len(vol2.knots(1)),2) self.assertEqual(len(vol2.knots(2)),2) # check a 5x5x5 evaluation grid u = np.linspace(0,1,5) v = np.linspace(0,1,5) w = np.linspace(0,1,5) pt = vol( u,v,w) pt2 = vol2(u,v,w) self.assertTrue(np.allclose(pt, pt2))
def test_edge_surfaces_six_sides(self): # create the unit cube vol = Volume() vol.raise_order(2,2,2) vol.refine(3) edges = vol.faces() # edge_surface should give back the same unit cube vol2 = VolumeFactory.edge_surfaces(edges) # check discretization self.assertEqual(vol2.order(0), 4) self.assertEqual(vol2.order(1), 4) self.assertEqual(vol2.order(2), 4) self.assertEqual(len(vol2.knots(0)), 5) # [0,.25,.5,.75,1] self.assertEqual(len(vol2.knots(1)), 5) self.assertEqual(len(vol2.knots(2)), 5) # check a 5x5x5 evaluation grid u = np.linspace(0,1,5) v = np.linspace(0,1,5) w = np.linspace(0,1,5) pt = vol( u,v,w) pt2 = vol2(u,v,w) self.assertAlmostEqual(np.linalg.norm(pt-pt2), 0.0)
def test_edge_surfaces_six_sides(self): # create the unit cube vol = Volume() vol.raise_order(2,2,2) vol.refine(3) edges = vol.faces() # edge_surface should give back the same unit cube vol2 = vf.edge_surfaces(edges) # check discretization self.assertEqual(vol2.order(0), 4) self.assertEqual(vol2.order(1), 4) self.assertEqual(vol2.order(2), 4) self.assertEqual(len(vol2.knots(0)), 5) # [0,.25,.5,.75,1] self.assertEqual(len(vol2.knots(1)), 5) self.assertEqual(len(vol2.knots(2)), 5) # check a 5x5x5 evaluation grid u = np.linspace(0,1,5) v = np.linspace(0,1,5) w = np.linspace(0,1,5) pt = vol( u,v,w) pt2 = vol2(u,v,w) self.assertAlmostEqual(np.linalg.norm(pt-pt2), 0.0)
def test_raise_order(self): # more or less random 3D volume with p=[2,2,1] and n=[4,3,2] controlpoints = [[0, 0, 0], [-1, 1, 0], [0, 2, 0], [1, -1, 0], [1, 0, 0], [1, 1, 0], [2, 1, 0], [2, 2, 0], [2, 3, 0], [3, 0, 0], [4, 1, 0], [3, 2, 0], [0, 0, 1], [-1, 1, 1], [0, 2, 1], [1, -1, 2], [1, 0, 2], [1, 1, 2], [2, 1, 2], [2, 2, 2], [2, 3, 2], [3, 0, 1], [4, 1, 1], [3, 2, 1]] basis1 = BSplineBasis(3, [0, 0, 0, .4, 1, 1, 1]) basis2 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis3 = BSplineBasis(2, [0, 0, 1, 1]) vol = Volume(basis1, basis2, basis3, controlpoints) self.assertEqual(vol.order(), (3, 3, 2)) evaluation_point1 = vol( 0.23, 0.37, 0.44) # pick some evaluation point (could be anything) vol.raise_order(1, 2, 4) self.assertEqual(vol.order(), (4, 5, 6)) evaluation_point2 = vol(0.23, 0.37, 0.44) # evaluation before and after RaiseOrder should remain unchanged self.assertAlmostEqual(evaluation_point1[0], evaluation_point2[0]) self.assertAlmostEqual(evaluation_point1[1], evaluation_point2[1]) self.assertAlmostEqual(evaluation_point1[2], evaluation_point2[2]) # test a rational 3D volume controlpoints = [[0, 0, 1, 1], [-1, 1, .96, 1], [0, 2, 1, 1], [1, -1, 1, 1], [1, 0, .8, 1], [1, 1, 1, 1], [2, 1, .89, 1], [2, 2, .9, 1], [2, 3, 1, 1], [3, 0, 1, 1], [4, 1, 1, 1], [3, 2, 1, 1], [0, 0, 1, 2], [-1, 1, .7, 2], [0, 2, 1.3, 2], [1, -1, 1, 2], [1, 0, .77, 2], [1, 1, 1, 2], [2, 1, .89, 1], [2, 2, .8, 4], [2, 3, 1, 1], [3, 0, 1, 1], [4, 1, 1, 1], [3, 2, 1, 1]] basis1 = BSplineBasis(3, [0, 0, 0, .4, 1, 1, 1]) basis2 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis3 = BSplineBasis(2, [0, 0, 1, 1]) vol = Volume(basis1, basis2, basis3, controlpoints, True) self.assertEqual(vol.order()[0], 3) self.assertEqual(vol.order()[1], 3) evaluation_point1 = vol(0.23, 0.37, 0.44) vol.raise_order(1, 2, 1) self.assertEqual(vol.order(), (4, 5, 3)) evaluation_point2 = vol(0.23, 0.37, 0.44) # evaluation before and after RaiseOrder should remain unchanged self.assertAlmostEqual(evaluation_point1[0], evaluation_point2[0]) self.assertAlmostEqual(evaluation_point1[1], evaluation_point2[1]) self.assertAlmostEqual(evaluation_point1[2], evaluation_point2[2])
def test_raise_order(self): # more or less random 3D volume with p=[2,2,1] and n=[4,3,2] controlpoints = [[0, 0, 0], [-1, 1, 0], [0, 2, 0], [1, -1, 0], [1, 0, 0], [1, 1, 0], [2, 1, 0], [2, 2, 0], [2, 3, 0], [3, 0, 0], [4, 1, 0], [3, 2, 0], [0, 0, 1], [-1, 1, 1], [0, 2, 1], [1, -1, 2], [1, 0, 2], [1, 1, 2], [2, 1, 2], [2, 2, 2], [2, 3, 2], [3, 0, 1], [4, 1, 1], [3, 2, 1]] basis1 = BSplineBasis(3, [0, 0, 0, .4, 1, 1, 1]) basis2 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis3 = BSplineBasis(2, [0, 0, 1, 1]) vol = Volume(basis1, basis2, basis3, controlpoints) self.assertEqual(vol.order(), (3, 3, 2)) evaluation_point1 = vol(0.23, 0.37, 0.44) # pick some evaluation point (could be anything) vol.raise_order(1, 2, 4) self.assertEqual(vol.order(), (4, 5, 6)) evaluation_point2 = vol(0.23, 0.37, 0.44) # evaluation before and after RaiseOrder should remain unchanged self.assertAlmostEqual(evaluation_point1[0], evaluation_point2[0]) self.assertAlmostEqual(evaluation_point1[1], evaluation_point2[1]) self.assertAlmostEqual(evaluation_point1[2], evaluation_point2[2]) # test a rational 3D volume controlpoints = [[0, 0, 1, 1], [-1, 1, .96, 1], [0, 2, 1, 1], [1, -1, 1, 1], [1, 0, .8, 1], [1, 1, 1, 1], [2, 1, .89, 1], [2, 2, .9, 1], [2, 3, 1, 1], [3, 0, 1, 1], [4, 1, 1, 1], [3, 2, 1, 1], [0, 0, 1, 2], [-1, 1, .7, 2], [0, 2, 1.3, 2], [1, -1, 1, 2], [1, 0, .77, 2], [1, 1, 1, 2], [2, 1, .89, 1], [2, 2, .8, 4], [2, 3, 1, 1], [3, 0, 1, 1], [4, 1, 1, 1], [3, 2, 1, 1]] basis1 = BSplineBasis(3, [0, 0, 0, .4, 1, 1, 1]) basis2 = BSplineBasis(3, [0, 0, 0, 1, 1, 1]) basis3 = BSplineBasis(2, [0, 0, 1, 1]) vol = Volume(basis1, basis2, basis3, controlpoints, True) self.assertEqual(vol.order()[0], 3) self.assertEqual(vol.order()[1], 3) evaluation_point1 = vol(0.23, 0.37, 0.44) vol.raise_order(1, 2, 1) self.assertEqual(vol.order(), (4, 5, 3)) evaluation_point2 = vol(0.23, 0.37, 0.44) # evaluation before and after RaiseOrder should remain unchanged self.assertAlmostEqual(evaluation_point1[0], evaluation_point2[0]) self.assertAlmostEqual(evaluation_point1[1], evaluation_point2[1]) self.assertAlmostEqual(evaluation_point1[2], evaluation_point2[2])
def test_operators(self): v = Volume() v.raise_order(1, 1, 2) v.refine(3, 2, 1) # test translation operator v2 = v + [1, 0, 0] v3 = [1, 0, 0] + v v += [1, 0, 0] self.assertTrue(np.allclose(v2.controlpoints, v3.controlpoints)) self.assertTrue(np.allclose(v.controlpoints, v3.controlpoints)) # test scaling operator v2 = v * 3 v3 = 3 * v v *= 3 self.assertTrue(np.allclose(v2.controlpoints, v3.controlpoints)) self.assertTrue(np.allclose(v.controlpoints, v3.controlpoints))
def test_operators(self): v = Volume() v.raise_order(1,1,2) v.refine(3,2,1) # test translation operator v2 = v + [1,0,0] v3 = [1,0,0] + v v += [1,0,0] self.assertTrue(np.allclose(v2.controlpoints, v3.controlpoints)) self.assertTrue(np.allclose(v.controlpoints, v3.controlpoints)) # test scaling operator v2 = v * 3 v3 = 3 * v v *= 3 self.assertTrue(np.allclose(v2.controlpoints, v3.controlpoints)) self.assertTrue(np.allclose(v.controlpoints, v3.controlpoints))