Exemple #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)
Exemple #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)
Exemple #3
0
 def __init__(self,
              original_control_points=None,
              deformed_control_points=None,
              func='gaussian_spline',
              radius=0.5,
              extra_parameter=None,
              u_knots_to_add=0,
              v_knots_to_add=0,
              t_knots_to_add=0,
              tolerance=1e-4):
     OriginalRBF.__init__(self, 
                          original_control_points=original_control_points, 
                          deformed_control_points=deformed_control_points,
                          func=func,
                          radius=radius,
                          extra_parameter=extra_parameter)
     CADDeformation.__init__(self,
                             u_knots_to_add=u_knots_to_add,
                             v_knots_to_add=v_knots_to_add,
                             t_knots_to_add=t_knots_to_add,
                             tolerance=tolerance)
Exemple #4
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')
Exemple #5
0
 def test_read_parameters_radius(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_default.prm')
     assert rbf.radius == 0.5
Exemple #6
0
 def test_class_members_default_n_control_points(self):
     rbf = RBF()
     assert rbf.n_control_points == 8
Exemple #7
0
 def test_class_members_default_deformed_control_points(self):
     rbf = RBF()
     np.testing.assert_array_equal(rbf.deformed_control_points, unit_cube)
Exemple #8
0
 def test_print_info(self):
     rbf = RBF()
     print(rbf)
Exemple #9
0
 def test_class_members_default_radius(self):
     rbf = RBF()
     assert rbf.radius == 0.5
Exemple #10
0
 def test_read_parameters_failing_filename_type(self):
     params = RBF()
     with self.assertRaises(TypeError):
         params.read_parameters(3)
Exemple #11
0
 def test_class_members_default_extra(self):
     rbf = RBF()
     assert rbf.extra == {}
Exemple #12
0
 def test_print_info(self):
     params = RBF()
     print(params)
Exemple #13
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)
Exemple #14
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])
Exemple #15
0
 def test_read_extra_parameters(self):
     rbf = RBF()
     rbf.read_parameters('tests/test_datasets/parameters_rbf_extra.prm')
     assert rbf.extra == {'k': 4}
Exemple #16
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')
Exemple #17
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
# 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))
Exemple #19
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)
Exemple #20
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])
Exemple #21
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')
Exemple #22
0
 def test_wrong_basis(self):
     rbf = RBF()
     with self.assertRaises(NameError):
         rbf.read_parameters(
                 'tests/test_datasets/parameters_rbf_bugged_02.prm')
Exemple #23
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)
Exemple #24
0
 def test_class_members_default_basis(self):
     rbf = RBF()