From 478fff1ea1e514c5eb50d51a5505a15d0b157cf5 Mon Sep 17 00:00:00 2001 From: Nicola Demo Date: Thu, 12 Nov 2020 18:04:55 +0100 Subject: [PATCH] Add flag for non in-place `reflect` --- pygem/ffd.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pygem/ffd.py b/pygem/ffd.py index d1995a0..ab98870 100644 --- a/pygem/ffd.py +++ b/pygem/ffd.py @@ -45,6 +45,7 @@ except ImportError: import ConfigParser as configparser import os +import copy import numpy as np from scipy import special @@ -477,7 +478,7 @@ def control_points(self, deformed=True): return box_points.T - def reflect(self, axis=0): + def reflect(self, axis=0, in_place=True): """ Reflect the lattice of control points along the direction defined by `axis`. In particular the origin point of the lattice is preserved. @@ -492,6 +493,17 @@ def reflect(self, axis=0): :param int axis: axis along which the reflection is performed. Default is 0. Possible values are 0, 1, or 2, corresponding to x, y, and z respectively. + :param bool in_place: if True, the object attributes are modified in + place; if False, a new object is return with the reflected lattice. + Default is True. + :return: a new object with the same parameters and the reflected + lattice if `in_place` is False, otherwise NoneType. + + :Example: + + >>> ffd.reflect(axis=0, in_place=True) # irreversible + >>> # or ... + >>> refle_ffd = ffd.reflect(axis=0, in_place=False) """ # check axis value if axis not in (0, 1, 2): @@ -508,6 +520,9 @@ def reflect(self, axis=0): "points in the symmetry plane along that axis." ) + if in_place is False: + self = copy.deepcopy(self) + # double the control points in the given axis -1 (the symmetry plane) self.n_control_points[axis] = 2 * self.n_control_points[axis] - 1 # double the box length @@ -536,6 +551,10 @@ def reflect(self, axis=0): reflection[2] * np.flip(self.array_mu_z, axis)[indeces], axis=axis) + if in_place is False: + return self + + def __call__(self, src_pts): """