def test_read_parameters_rotation_matrix(self): params = FFD(n_control_points=[3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') rotation_matrix_exact = np.array( [[0.98162718, 0., 0.190809], [0.06619844, 0.93788893, -0.34056147], [-0.17895765, 0.34693565, 0.92065727]]) np.testing.assert_array_almost_equal(params.rotation_matrix, rotation_matrix_exact)
def test_read_parameters_array_mu_z(self): params = FFD(n_control_points=[3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') array_mu_z_exact = np.array( [0., -0.2, 0., -0.45622985, 0., 0., 0., 0., -1.22, 0., -1., 0.]).reshape((3, 2, 2)) np.testing.assert_array_almost_equal(params.array_mu_z, array_mu_z_exact)
def test_write_parameters_filename_default(self): params = FFD(n_control_points=[3, 2, 2]) params.write_parameters() outfilename = 'parameters.prm' outfilename_expected = 'tests/test_datasets/parameters_default.prm' self.assertTrue(filecmp.cmp(outfilename, outfilename_expected)) os.remove(outfilename)
def test_reflect_wrong_symmetry_plane_3(self): params = FFD([3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') params.array_mu_z = np.array( [0.2, 0., 0., 0., 0.5, 0., 0., 0., 1., 0., 0.3, 0.1]).reshape( (3, 2, 2)) with self.assertRaises(RuntimeError): params.reflect(axis=2)
def test_write_parameters(self): params = FFD(n_control_points=[3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') outfilename = 'tests/test_datasets/parameters_sphere_out.prm' outfilename_expected = 'tests/test_datasets/parameters_sphere_out_true.prm' params.write_parameters(outfilename) self.assertTrue(filecmp.cmp(outfilename, outfilename_expected)) os.remove(outfilename)
def test_set_modification_parameters_to_zero(self): params = FFD([5, 5, 5]) params.reset_weights() np.testing.assert_almost_equal(params.array_mu_x, np.zeros(shape=(5, 5, 5))) np.testing.assert_almost_equal(params.array_mu_y, np.zeros(shape=(5, 5, 5))) np.testing.assert_almost_equal(params.array_mu_z, np.zeros(shape=(5, 5, 5)))
def test_ffd_sphere_mod(self): ffd = FFD() ffd.read_parameters( filename='tests/test_datasets/parameters_test_ffd_sphere.prm') mesh_points = np.load('tests/test_datasets/meshpoints_sphere_orig.npy') mesh_points_ref = np.load( 'tests/test_datasets/meshpoints_sphere_mod.npy') mesh_points_test = ffd(mesh_points) np.testing.assert_array_almost_equal(mesh_points_test, mesh_points_ref)
def test_read_parameters_position_vertex_0(self): params = FFD(n_control_points=[3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') position_vertices = np.array( [[-20.0, -55.0, -45.0], [24.17322326, -52.02107006, -53.05309404], [-20., 29.41000412, -13.77579136], [-2.82719042, -85.65053198, 37.85915459]]) np.testing.assert_array_almost_equal(params.position_vertices, position_vertices)
def test_set_position_of_vertices(self): expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) tops = np.array([1., 1., 1.]) params = FFD() params.box_origin = expected_matrix[0] params.box_length = tops - expected_matrix[0] np.testing.assert_almost_equal(params.position_vertices, expected_matrix, decimal=5)
def test_reflect_axis_2(self): params = FFD([3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') params.array_mu_z = np.array( [0.2, 0., 0., 0., 0.5, 0., 0., 0., 0., 0., 0., 0.]).reshape( (3, 2, 2)) params.reflect(axis=2) array_mu_z_exact = np.array([ 0.2, 0., -0.2, 0., 0., 0., 0.5, 0., -0.5, 0., 0., -0., 0., 0., -0., 0., 0., -0. ]).reshape((3, 2, 3)) np.testing.assert_array_almost_equal(params.array_mu_z, array_mu_z_exact)
def test_class_members_default_n_control_points(self): params = FFD() assert np.array_equal(params.n_control_points, [2, 2, 2])
def test_class_members_generic_array_mu_z(self): params = FFD([2, 3, 5]) np.testing.assert_array_almost_equal(params.array_mu_z, np.zeros((2, 3, 5)))
def test_reflect_n_control_points_3(self): params = FFD([2, 3, 5]) params.reflect(axis=2) assert np.array_equal(params.n_control_points, [2, 3, 9])
def test_class_members_default_position_vertices(self): params = FFD() expected_matrix = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) np.testing.assert_array_almost_equal(params.position_vertices, expected_matrix)
def test_class_members_generic_n_control_points(self): params = FFD([2, 3, 5]) assert np.array_equal(params.n_control_points, [2, 3, 5])
def test_class_members_default_array_mu_z(self): params = FFD() np.testing.assert_array_almost_equal(params.array_mu_z, np.zeros((2, 2, 2)))
def test_class_members_default_rotation_matrix(self): params = FFD() np.testing.assert_array_almost_equal(params.rotation_matrix, np.eye(3))
def test_read_parameters_position_vertex_0_origin(self): params = FFD(n_control_points=[3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') np.testing.assert_array_almost_equal(params.position_vertices[0], params.box_origin)
def test_read_parameters_box_origin(self): params = FFD(n_control_points=[3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') box_origin_exact = np.array([-20.0, -55.0, -45.0]) np.testing.assert_array_almost_equal(params.box_origin, box_origin_exact)
def test_reflect_box_length_3(self): params = FFD([2, 3, 5]) params.reflect(axis=2) assert params.box_length[2] == 2
def test_read_parameters_rot_angle_x(self): params = FFD(n_control_points=[3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') assert np.array_equal(params.rot_angle, [20.3, 11.0, 0.])
phi = np.arccos(1 - 2 * indices / num_pts) theta = np.pi * (1 + 5**0.5) * indices return np.array([ np.cos(theta) * np.sin(phi), np.sin(theta) * np.sin(phi), np.cos(phi) ]).T mesh = mesh_points() plt.figure(figsize=(8, 8)).add_subplot(111, projection='3d').scatter(*mesh.T) plt.show() ffd = FFD([2, 2, 2]) print(ffd) print('Movements of point[{}, {}, {}] along x: {}'.format( 1, 1, 1, ffd.array_mu_x[1, 1, 1])) print('Movements of point[{}, {}, {}] along z: {}'.format( 1, 1, 1, ffd.array_mu_z[1, 1, 1])) ffd.array_mu_x[1, 1, 1] = 2 ffd.array_mu_z[1, 1, 1] = 0.8 print() print('Movements of point[{}, {}, {}] along x: {}'.format( 1, 1, 1, ffd.array_mu_x[1, 1, 1])) print('Movements of point[{}, {}, {}] along z: {}'.format( 1, 1, 1, ffd.array_mu_z[1, 1, 1]))
def test_read_parameters_box_length_x(self): params = FFD(n_control_points=[3, 2, 2]) params.read_parameters('tests/test_datasets/parameters_sphere.prm') assert np.array_equal(params.box_length, [45.0, 90.0, 90.0])
def test_write_parameters_filename_default_existance(self): params = FFD(n_control_points=[3, 2, 2]) params.write_parameters() outfilename = 'parameters.prm' assert os.path.isfile(outfilename) os.remove(outfilename)
def test_write_parameters_failing_filename_type(self): params = FFD(n_control_points=[3, 2, 2]) with self.assertRaises(TypeError): params.write_parameters(5)
def test_class_members_default_rot_angle(self): params = FFD() assert np.array_equal(params.rot_angle, np.zeros(3))
# メッシュにテクスチャーを設定 mesh.textures = texture #================================ # PyGeM での FFD #================================ # FFD 変形用パラメーターファイルの読み込み if (args.ffd_param_file != ""): from pygem import FFDParameters ffd_params = FFDParameters() ffd_params.read_parameters(filename=args.ffd_param_file) # FFD(n_control_points) # n_control_points (list) : number of control points in the x, y, and z direction. Default is [2, 2, 2]. if (args.ffd_param_file == ""): ffd = FFD([2, 2, 2]) else: ffd = FFD(ffd_params) # 制御点の変位を制御するために、`array_mu_x`, `array_mu_y`, `array_mu_z` の値を変えれば良い if (args.ffd_param_file == ""): x_min = torch.min( mesh.verts_packed().squeeze()[:, 0]).detach().cpu().numpy() x_max = torch.max( mesh.verts_packed().squeeze()[:, 0]).detach().cpu().numpy() y_min = torch.min( mesh.verts_packed().squeeze()[:, 1]).detach().cpu().numpy() y_max = torch.max( mesh.verts_packed().squeeze()[:, 1]).detach().cpu().numpy() z_min = torch.min( mesh.verts_packed().squeeze()[:, 2]).detach().cpu().numpy()
def test_class_members_default_box_origin(self): params = FFD() assert np.array_equal(params.box_origin, np.zeros(3))
from pygem import FFDParameters, FFD, StlHandler params = FFDParameters() params.read_parameters( filename='PyGem/tests/test_datasets/parameters_test_ffd_sphere.prm') stl_handler = StlHandler() mesh_points = stl_handler.parse('PyGem/tests/test_datasets/test_sphere.stl') fig = stl_handler.plot(plot_file='PyGem/tests/test_datasets/test_sphere.stl') free_form = FFD(params, mesh_points) free_form.perform() new_mesh_points = free_form.modified_mesh_points stl_handler.write(new_mesh_points, 'test_sphere_mod.stl') fig = stl_handler.plot(plot_file='test_sphere_mod.stl')
def test_print(self): params = FFD(n_control_points=[3, 2, 2]) print(params)