Skip to content

Commit 6cd01a1

Browse files
refactored weight matrix
1 parent 5f625b2 commit 6cd01a1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pygem/cffd.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CFFD(FFD):
6060
>>> new_mesh_points = cffd(original_mesh_points)
6161
>>> assert np.isclose(np.linalg.norm(fun(new_mesh_points)-b),np.array([0.]))
6262
"""
63-
def __init__(self, n_control_points=None, fun=None, fixval=None, M=None, mask=None ):
63+
def __init__(self, n_control_points=None, fun=None, fixval=None, weight_matrix=None, mask=None ):
6464
super().__init__(n_control_points)
6565

6666
if mask==None:
@@ -79,15 +79,15 @@ def __init__(self, n_control_points=None, fun=None, fixval=None, M=None, mask=No
7979
else:
8080
self.fun=fun
8181

82-
if M==None:
83-
self.M=np.eye(np.sum(self.mask.astype(int)))
82+
if weight_matrix==None:
83+
self.weight_matrix=np.eye(np.sum(self.mask.astype(int)))
8484

8585
def __call__(self, src_pts):
8686
saved_parameters = self._save_parameters()
8787
indices=np.arange(np.prod(self.n_control_points)*3)[self.mask.reshape(-1)]
8888
A, b = self._compute_linear_map(src_pts, saved_parameters.copy(),indices)
8989
d = A @ saved_parameters[indices] + b
90-
invM=np.linalg.inv(self.M)
90+
invM=np.linalg.inv(self.weight_matrix)
9191
deltax = np.linalg.multi_dot([invM , A.T , np.linalg.inv(np.linalg.multi_dot([A, invM, A.T])) , (self.fixval - d)])
9292
saved_parameters[indices] = saved_parameters[indices] + deltax
9393
self._load_parameters(saved_parameters)
@@ -131,7 +131,7 @@ def _load_parameters(self, tmp):
131131
def read_parameters(self,filename='parameters.prm'):
132132
super().read_parameters(filename)
133133
self.mask=np.full((*self.n_control_points,3), True, dtype=bool)
134-
self.M=np.eye(np.sum(self.mask.astype(int)))
134+
self.weight_matrix=np.eye(np.sum(self.mask.astype(int)))
135135

136136
# I see that a similar function already exists in pygem.utils, but it does not work for inputs and outputs of different dimensions
137137

pygem/vffd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __call__(self, src_pts):
7878
for i in range(3):
7979
self.mask=np.full((*self.n_control_points,3), False, dtype=bool)
8080
self.mask[:,:,:,i]=mask_bak[:,:,:,i].copy()
81-
self.M = np.eye(np.sum(self.mask.astype(int)))
81+
self.weight_matrix = np.eye(np.sum(self.mask.astype(int)))
8282
self.fixval = self.fun(
8383
self.ffd(src_pts)) + self.vweight[i] * (diffvolume)
8484
_ = super().__call__(src_pts)

0 commit comments

Comments
 (0)