Skip to content

Commit 2a79e6b

Browse files
deleted call function to CFFD to highlight the working principle
1 parent 6cd01a1 commit 2a79e6b

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

pygem/cffd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(self, n_control_points=None, fun=None, fixval=None, weight_matrix=N
8282
if weight_matrix==None:
8383
self.weight_matrix=np.eye(np.sum(self.mask.astype(int)))
8484

85-
def __call__(self, src_pts):
85+
def adjust_control_points(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)
@@ -91,7 +91,6 @@ def __call__(self, src_pts):
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)
94-
return self.ffd(src_pts)
9594

9695
def ffd(self, src_pts):
9796
'''

pygem/vffd.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def volume(x):
7171

7272
self.fun = volume
7373

74-
def __call__(self, src_pts):
74+
def adjust_control_points(self, src_pts):
7575
self.vweight = np.abs(self.vweight) / np.sum(np.abs(self.vweight))
7676
mask_bak=self.mask.copy()
7777
diffvolume = self.fixval - self.fun(self.ffd(src_pts))
@@ -81,7 +81,5 @@ def __call__(self, src_pts):
8181
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)
84-
_ = super().__call__(src_pts)
85-
tmp = super().__call__(src_pts)
86-
self.mask = mask_bak
87-
return tmp
84+
super().adjust_control_points(src_pts)
85+

tests/test_bffd.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def test_nothing_happens(self):
1414
A = np.random.rand(3, original_mesh_points.reshape(-1).shape[0])
1515
b = cffd.fun(original_mesh_points)
1616
cffd.fixval = b
17-
new_mesh_points = cffd(original_mesh_points)
17+
cffd.adjust_control_points(original_mesh_points)
18+
new_mesh_points = cffd.ffd(original_mesh_points)
1819
assert np.array_equal(original_mesh_points, new_mesh_points)
1920

2021
def test_constraint(self):
@@ -26,6 +27,7 @@ def test_constraint(self):
2627
"tests/test_datasets/meshpoints_sphere_orig.npy")
2728
b = cffd.fun(original_mesh_points)
2829
cffd.fixval = b
29-
new_mesh_points = cffd(original_mesh_points)
30+
cffd.adjust_control_points(original_mesh_points)
31+
new_mesh_points = cffd.ffd(original_mesh_points)
3032
assert np.isclose(np.linalg.norm(cffd.fun(new_mesh_points) - b),
3133
np.array([0.0]))

tests/test_cffd.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def fun(x):
3434
b = fun(original_mesh_points)
3535
cffd.fun = fun
3636
cffd.fixval = b
37-
new_mesh_points = cffd(original_mesh_points)
37+
cffd.adjust_control_points(original_mesh_points)
38+
new_mesh_points = cffd.ffd(original_mesh_points)
3839
assert np.array_equal(original_mesh_points, new_mesh_points)
3940

4041
def test_constraint(self):
@@ -53,7 +54,8 @@ def fun(x):
5354
b = fun(original_mesh_points)
5455
cffd.fun = fun
5556
cffd.fixval = b
56-
new_mesh_points = cffd(original_mesh_points)
57+
cffd.adjust_control_points(original_mesh_points)
58+
new_mesh_points = cffd.ffd(original_mesh_points)
5759
assert np.isclose(np.linalg.norm(fun(new_mesh_points) - b),
5860
np.array([0.0]),atol=1e-7)
5961

tests/test_vffd.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def test_nothing_happens(self):
3838
cffd.vweight = np.array([1 / 3, 1 / 3, 1 / 3])
3939
b = cffd.fun(points)
4040
cffd.fixval = np.array([b])
41-
new_mesh_points = cffd(points)
41+
cffd.adjust_control_points(points)
42+
new_mesh_points = cffd.ffd(points)
4243
assert np.allclose(np.linalg.norm(points - new_mesh_points), 0.0)
4344

4445
def test_constraint(self):
@@ -74,6 +75,7 @@ def test_constraint(self):
7475
cffd.read_parameters(
7576
"tests/test_datasets/parameters_test_ffd_sphere.prm")
7677
cffd.fixval = np.array([b])
77-
new_mesh_points = cffd(points)
78+
cffd.adjust_control_points(points)
79+
new_mesh_points = cffd.ffd(points)
7880
assert np.isclose(np.linalg.norm(cffd.fun(new_mesh_points) - b),
7981
np.array([0.0]))

0 commit comments

Comments
 (0)