11"""
2- Utilities for reading and writing parameters files to perform the Free Form Deformation (FFD)
2+ Utilities for reading and writing parameters files to perform the desired geometrical morphing.
33"""
44import os
55import ConfigParser
@@ -268,13 +268,11 @@ def print_info(self):
268268 """
269269 print 'conversion_unit = ' + str (self .conversion_unit ) + '\n '
270270 print '(lenght_box_x, lenght_box_y, lenght_box_z) = (' + str (self .lenght_box_x ) + \
271- ', ' + str (self .lenght_box_y ) + ', ' + \
272- str (self .lenght_box_z ) + ')'
271+ ', ' + str (self .lenght_box_y ) + ', ' + str (self .lenght_box_z ) + ')'
273272 print 'origin_box = ' + str (self .origin_box )
274273 print 'n_control_points = ' + str (self .n_control_points )
275274 print '(rot_angle_x, rot_angle_y, rot_angle_z) = (' + str (self .rot_angle_x ) + \
276- ', ' + str (self .rot_angle_y ) + ', ' + \
277- str (self .rot_angle_z ) + ')'
275+ ', ' + str (self .rot_angle_y ) + ', ' + str (self .rot_angle_z ) + ')'
278276 print '\n array_mu_x ='
279277 print self .array_mu_x
280278 print '\n array_mu_y ='
@@ -297,3 +295,94 @@ def print_info(self):
297295 print self .position_vertex_3
298296
299297
298+
299+ class RBFParameters (object ):
300+ """
301+ Class that handles the Radial Basis Functions parameters in terms of RBF control points and
302+ basis functions.
303+
304+ :cvar string basis: name of the basis functions to use in the transformation. The functions
305+ implemented so far are: gaussian spline, multi quadratic biharmonic spline,
306+ inv multi quadratic biharmonic spline, thin plate spline, beckert wendland c2 basis.
307+ For a comprehensive list with details see the class :class:`~pygem.radialbasis.RBF`.
308+ The default value is None.
309+ :cvar float radius: is the scaling parameter r that affects the shape of the basis functions.
310+ For details see the class :class:`~pygem.radialbasis.RBF`. The default value is None.
311+ :cvar int n_control_points: total number of control points.
312+ :cvar numpy.ndarray original_control_points: it is an `n_control_points`-by-3 array with the
313+ coordinates of the original interpolation control points before the deformation. The
314+ default value is None.
315+ :cvar numpy.ndarray deformed_control_points: it is an `n_control_points`-by-3 array with the
316+ coordinates of the interpolation control points after the deformation. The default value
317+ is None.
318+ """
319+ def __init__ (self ):
320+ self .basis = None
321+ self .radius = None
322+ self .n_control_points = None
323+ self .original_control_points = None
324+ self .deformed_control_points = None
325+
326+
327+ def read_parameters (self , filename = 'parameters.prm' ):
328+ """
329+ Reads in the parameters file and fill the self structure.
330+
331+ :param string filename: parameters file to be read in.
332+ """
333+ if not isinstance (filename , basestring ):
334+ raise TypeError ('filename must be a string' )
335+
336+ # Checks if the parameters file exists. If not it writes the default class into filename.
337+ # It consists in the vetices of a cube of side one with a vertex in (0, 0, 0) and opposite one
338+ # in (1, 1, 1).
339+ if not os .path .isfile (filename ):
340+ self .basis = 'gaussian_spline'
341+ self .radius = 0.5
342+ self .n_control_points = 8
343+ self .original_control_points = np .array ([0. , 0. , 0. , 0. , 0. , 1. , 0. , 1. , 0. , 1. , 0. , 0. , \
344+ 0. , 1. , 1. , 1. , 0. , 1. , 1. , 1. , 0. , 1. , 1. , 1. ]).reshape ((8 , 3 ))
345+ self .deformed_control_points = np .array ([0. , 0. , 0. , 0. , 0. , 1. , 0. , 1. , 0. , 1. , 0. , 0. , \
346+ 0. , 1. , 1. , 1. , 0. , 1. , 1. , 1. , 0. , 1. , 1. , 1. ]).reshape ((8 , 3 ))
347+ #self.write_parameters(filename)
348+ return
349+
350+ config = ConfigParser .RawConfigParser ()
351+ config .read (filename )
352+
353+ self .basis = config .get ('Radial Basis Functions' , 'basis function' )
354+ self .radius = config .getfloat ('Radial Basis Functions' , 'radius' )
355+
356+ ctrl_points = config .get ('Control points' , 'original control points' )
357+ lines = ctrl_points .split ('\n ' )
358+ self .n_control_points = len (lines )
359+ self .original_control_points = np .zeros ((self .n_control_points , 3 ))
360+ for line , i in zip (lines , range (0 , self .n_control_points )):
361+ values = line .split ()
362+ self .original_control_points [i ] = np .array ([float (values [0 ]), float (values [1 ]), float (values [2 ])])
363+
364+ mod_points = config .get ('Control points' , 'deformed control points' )
365+ lines = mod_points .split ('\n ' )
366+
367+ if len (lines ) != self .n_control_points :
368+ raise TypeError ("The number of control points must be equal both in the 'original control points'" + \
369+ " and in the 'deformed control points' section of the parameters file ({0!s})" .format (filename ))
370+
371+ self .deformed_control_points = np .zeros ((self .n_control_points , 3 ))
372+ for line , i in zip (lines , range (0 , self .n_control_points )):
373+ values = line .split ()
374+ self .deformed_control_points [i ] = np .array ([float (values [0 ]), float (values [1 ]), float (values [2 ])])
375+
376+
377+ def print_info (self ):
378+ """
379+ This method prints all the RBF parameters on the screen. Its purpose is for debugging.
380+ """
381+ print 'basis function = ' + str (self .basis )
382+ print 'radius = ' + str (self .radius )
383+ print 'n_control_points = ' + str (self .n_control_points )
384+ print '\n original_control_points ='
385+ print self .original_control_points
386+ print '\n deformed_control_points ='
387+ print self .deformed_control_points
388+
0 commit comments