Skip to content

Commit d6073e1

Browse files
committed
enhance: add fit_to_points method to automatically position FFD box based on input points
1 parent b3d83c7 commit d6073e1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pygem/ffd.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,26 @@ def reset_weights(self):
235235
self.array_mu_x.fill(0.0)
236236
self.array_mu_y.fill(0.0)
237237
self.array_mu_z.fill(0.0)
238+
239+
def fit_to_points(self, points, padding_factor=0.05):
240+
"""
241+
Automatically set the FFD box_origin and box_length based on the input points.
242+
243+
The method computes the axis-aligned bounding box of the input points, adds a small padding, and sets the FFD lattice to exactly
244+
enclose the points. This provides a convenient default for the morphing setup.
245+
246+
:param numpy.ndarray points: The original mesh points (N x 3).
247+
:param float padding_factor: Additional space around the object as a fraction of its size. Default is 0.05 (5%).
248+
"""
249+
points = np.asarray(points)
250+
min_coords = np.min(points, axis=0)
251+
max_coords = np.max(points, axis=0)
252+
253+
side_lengths = max_coords - min_coords
254+
padding = side_lengths * padding_factor
255+
self.box_length = side_lengths + 2 * padding
256+
self.box_origin = min_coords - padding
257+
238258

239259
def read_parameters(self, filename='parameters.prm'):
240260
"""

0 commit comments

Comments
 (0)