Пример #1
0
 def test_rbf_cube_mod(self):
     mesh_points_ref = np.load(
         'tests/test_datasets/meshpoints_cube_mod_rbf.npy')
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_cube.prm')
     rbf.radius = 0.5
     deformed_mesh = rbf(self.get_cube_mesh_points())
     np.testing.assert_array_almost_equal(deformed_mesh, mesh_points_ref)
Пример #2
0
 def test_write_parameters_filename_default_existance(self):
     params = RBF()
     params.basis = 'inv_multi_quadratic_biharmonic_spline'
     params.radius = 0.1
     params.original_control_points = np.array(
         [0., 0., 0., 0., 0., 1., 0., 1., 0.]).reshape((3, 3))
     params.deformed_control_points = np.array(
         [0., 0., 0., 0., 0., 1., 0., 1., 0.]).reshape((3, 3))
     params.write_parameters()
     outfilename = 'parameters_rbf.prm'
     assert os.path.isfile(outfilename)
     os.remove(outfilename)
Пример #3
0
 def test_class_members_default_deformed_control_points(self):
     rbf = RBF()
     np.testing.assert_array_equal(rbf.deformed_control_points, unit_cube)
Пример #4
0
 def test_class_members_default_n_control_points(self):
     rbf = RBF()
     assert rbf.n_control_points == 8
Пример #5
0
 def test_class_members_default_radius(self):
     rbf = RBF()
     assert rbf.radius == 0.5
Пример #6
0
 def test_call_dummy_transformation(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_default.prm')
     mesh = self.get_cube_mesh_points()
     new = rbf(mesh)
     np.testing.assert_array_almost_equal(new[17], mesh[17])
# First of all we import the required **PyGeM** class, we import numpy and we set matplotlib for the notebook.

# In[1]:

get_ipython().run_line_magic('matplotlib', 'inline')
from pygem import RBF
import numpy as np
import matplotlib.pyplot as plt

# Using RBF, we can control the deformation by arranging some control points around the object to deform, then moving these latter to induce the morphing. Within **PyGeM**, the setting of such parameters can be done by parsing an input text file or manually touching the `RBF` attributes.
#
# Let's try togheter by using an input file: the first step is the creation of the new object. After this, we can use the `read_parameters` to set the parameters.

# In[2]:

rbf = RBF()
rbf.read_parameters(filename='../tests/test_datasets/parameters_rbf_cube.prm')

# The following is the parameters file for this particular case. The Radial Basis Functions section describes the basis functions to use. Here we use Gaussian splines with the distance parameter equal to 0.5 (see the documentation of the [RBF](http://mathlab.github.io/PyGeM/rbf.html) class for more details). As control points we consider the 8 vertices of the cube (the first one is not exactly the vertex), and we move 3 of them. In the Control points section there are all the coordinates of the control points.

# In[3]:

get_ipython().run_line_magic('cat',
                             '../tests/test_datasets/parameters_rbf_cube.prm')

# Here we create a $10 \times10 \times 10$ lattice to mimic a cube.

# In[4]:

nx, ny, nz = (10, 10, 10)
mesh = np.zeros((nx * ny * nz, 3))
Пример #8
0
 def test_read_parameters_failing_filename_type(self):
     params = RBF()
     with self.assertRaises(TypeError):
         params.read_parameters(3)
Пример #9
0
 def test_read_parameters_n_control_points(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_default.prm')
     assert rbf.n_control_points == 8
Пример #10
0
 def test_print_info(self):
     params = RBF()
     print(params)
Пример #11
0
 def test_read_extra_parameters(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_extra.prm')
     assert rbf.extra == {'k': 4}
Пример #12
0
 def test_read_parameters_basis2(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_extra.prm')
     assert rbf.basis == RBFFactory('polyharmonic_spline')
Пример #13
0
 def test_class_members_default_extra(self):
     rbf = RBF()
     assert rbf.extra == {}
Пример #14
0
 def test_call(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_extra.prm')
     mesh = self.get_cube_mesh_points()
     new = rbf(mesh)
     np.testing.assert_array_almost_equal(new[17], [8.947368e-01, 5.353524e-17, 8.845331e-03])
Пример #15
0
 def test_read_parameters_basis(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_default.prm')
     assert rbf.basis == RBFFactory('gaussian_spline')
Пример #16
0
 def test_read_parameters_radius(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_default.prm')
     assert rbf.radius == 0.5
Пример #17
0
 def test_rbf_weights_member(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_cube.prm')
     rbf.compute_weights()
     weights_true = np.load('tests/test_datasets/weights_rbf_cube.npy')
     np.testing.assert_array_almost_equal(rbf.weights, weights_true)
Пример #18
0
 def test_read_parameters_deformed_control_points(self):
     params = RBF()
     params.read_parameters('tests/test_datasets/parameters_rbf_default.prm')
     np.testing.assert_array_almost_equal(params.deformed_control_points,
                                          unit_cube)
Пример #19
0
 def test_wrong_basis(self):
     rbf = RBF()
     with self.assertRaises(NameError):
         rbf.read_parameters(
                 'tests/test_datasets/parameters_rbf_bugged_02.prm')
Пример #20
0
 def test_read_parameters_failing_number_deformed_control_points(self):
     params = RBF()
     with self.assertRaises(TypeError):
         params.read_parameters(
             'tests/test_datasets/parameters_rbf_bugged_01.prm')
Пример #21
0
 def test_class_members_default_basis(self):
     rbf = RBF()
Пример #22
0
print("GENERATING MORPHED VTK");



cwd = os.getcwd()
full_path = os.path.realpath(__file__)
path, filename = os.path.split(full_path)


# In[2]:


params = RBFParameters()
params.read_parameters(parameter_file_path)


# In[2]:


vtk_handler = VtkHandler()
mesh = vtk_handler.parse(mesh_file_path)


# In[4]:


rbf = RBF(params, mesh)
rbf.perform()
new_mesh_points = rbf.modified_mesh_points
vtk_handler.write(new_mesh_points, output_morphed_vtk_path)
Пример #23
0
 def test_print_info(self):
     rbf = RBF()
     print(rbf)