Skip to content

Commit bdf74cb

Browse files
outer and inner function merged: test passing
1 parent c69b7cd commit bdf74cb

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

pygem/cffd.py

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,6 @@ def __init__(self,
7979
self.fun_mask = np.full((self.num_cons, 3), True, dtype=bool)
8080
else:
8181
self.fun_mask = fun_mask
82-
def _adjust_control_points_inner(self, src_pts,i):
83-
'''
84-
Solves the constrained optimization problem of axis i
85-
86-
:param np.ndarray src_pts: the points whose deformation we want to be
87-
constrained.
88-
:param int i: the axis we are considering.
89-
:rtype: None.
90-
'''
91-
92-
saved_parameters = self._save_parameters()
93-
indices = np.arange(np.prod(self.n_control_points) *
94-
3)[self.ffd_mask.reshape(-1)]
95-
A, b = self._compute_linear_map(src_pts, saved_parameters.copy(),
96-
indices)
97-
A=A[self.fun_mask[:,i].reshape(-1),:]
98-
b=b[self.fun_mask[:,i].reshape(-1)]
99-
d = A @ saved_parameters[indices] + b
100-
fixval=self.fixval[self.fun_mask[:,i].reshape(-1)]
101-
deltax = np.linalg.multi_dot([
102-
A.T,
103-
np.linalg.inv(np.linalg.multi_dot([A, A.T])),
104-
(fixval - d)
105-
])
106-
saved_parameters[indices] = saved_parameters[indices] + deltax
107-
self._load_parameters(saved_parameters)
108-
return np.linalg.norm(deltax.reshape(-1))
109-
110-
111-
11282
def adjust_control_points(self,src_pts):
11383
'''
11484
Adjust the FFD control points such that fun(ffd(src_pts))=fixval
@@ -127,7 +97,24 @@ def adjust_control_points(self,src_pts):
12797
self.fixval = self.fun(self.ffd(src_pts)) + vweight[:,i] * (
12898
diffvolume
12999
)
130-
self._adjust_control_points_inner(src_pts,i)
100+
saved_parameters = self._save_parameters()
101+
indices = np.arange(np.prod(self.n_control_points) *
102+
3)[self.ffd_mask.reshape(-1)]
103+
A, b = self._compute_linear_map(src_pts, saved_parameters.copy(),
104+
indices)
105+
A=A[self.fun_mask[:,i].reshape(-1),:]
106+
b=b[self.fun_mask[:,i].reshape(-1)]
107+
d = A @ saved_parameters[indices] + b
108+
fixval=self.fixval[self.fun_mask[:,i].reshape(-1)]
109+
deltax = np.linalg.multi_dot([
110+
A.T,
111+
np.linalg.inv(np.linalg.multi_dot([A, A.T])),
112+
(fixval - d)
113+
])
114+
saved_parameters[indices] = saved_parameters[indices] + deltax
115+
self._load_parameters(saved_parameters)
116+
self.ffd_mask = mask_bak.copy()
117+
131118

132119

133120
def ffd(self, src_pts):

0 commit comments

Comments
 (0)