fix(ui): smooth B-spline section/waterline curves + 3D ready-signal sync
- viewer_3d.py: add `ready` Signal emitted once QtInteractor finishes init - main_window.py: connect ready signal to sync active hull into 3D viewer on startup - viewer_lines.py: add _smooth_pts helper; replace straight polylines in BodyPlanViewer and PlanViewer CAPA 3 with B-spline interpolated curves (80 sample points) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -365,6 +365,25 @@ def _draw_cnet_planview(p: QPainter, ot, w2s_fn) -> None:
|
||||
p.drawPath(path)
|
||||
|
||||
|
||||
def _smooth_pts(pts_2d: np.ndarray, n: int = 60) -> np.ndarray:
|
||||
"""Muestrea n puntos de una B-spline interpolada a través de pts_2d.
|
||||
|
||||
pts_2d : shape (m, 2)
|
||||
Returns shape (n, 2). Si hay < 4 puntos o falla el spline,
|
||||
devuelve los puntos originales sin modificar.
|
||||
"""
|
||||
from arshipdesign.geometry.nurbs_curve import BSplineCurve
|
||||
m = len(pts_2d)
|
||||
if m < 4:
|
||||
return pts_2d
|
||||
try:
|
||||
k = min(3, m - 1)
|
||||
curve = BSplineCurve(pts_2d, degree=k)
|
||||
return curve.sample(n) # shape (n, 2)
|
||||
except Exception:
|
||||
return pts_2d
|
||||
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# 1. Body Plan — secciones transversales
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
@@ -475,14 +494,20 @@ class BodyPlanViewer(_BaseViewer):
|
||||
z_arr = ot.z_waterlines
|
||||
sign = 1.0 if is_fwd else -1.0
|
||||
|
||||
# Smooth B-spline through the section data points
|
||||
raw = np.column_stack([y_arr * sign, z_arr])
|
||||
# Close to keel: append (0, 0) as the last interpolation point
|
||||
keel_row = np.array([[0.0, 0.0]])
|
||||
raw_closed = np.vstack([raw, keel_row])
|
||||
smooth = _smooth_pts(raw_closed, n=80)
|
||||
|
||||
path = QPainterPath()
|
||||
for k, (y, z) in enumerate(zip(y_arr, z_arr)):
|
||||
pt = self._w2s(sign * y, z)
|
||||
if k == 0:
|
||||
for k_pt in range(len(smooth)):
|
||||
pt = self._w2s(smooth[k_pt, 0], smooth[k_pt, 1])
|
||||
if k_pt == 0:
|
||||
path.moveTo(pt)
|
||||
else:
|
||||
path.lineTo(pt)
|
||||
path.lineTo(self._w2s(0.0, 0.0))
|
||||
p.drawPath(path)
|
||||
|
||||
# Flotación de diseño (encima de todo lo anterior)
|
||||
@@ -691,15 +716,20 @@ class PlanViewer(_BaseViewer):
|
||||
width = 2.2
|
||||
else:
|
||||
color = QColor(_WATERLINE)
|
||||
color.setAlphaF(0.40 + 0.50 * frac)
|
||||
width = 1.1
|
||||
color.setAlphaF(0.45 + 0.45 * frac)
|
||||
width = 1.2
|
||||
|
||||
p.setPen(QPen(color, width))
|
||||
p.setBrush(Qt.BrushStyle.NoBrush)
|
||||
|
||||
# Smooth B-spline through the waterline data points
|
||||
raw = np.column_stack([ot.x_stations, ot.data[:, j]])
|
||||
smooth = _smooth_pts(raw, n=80)
|
||||
|
||||
path = QPainterPath()
|
||||
for i, (x, y) in enumerate(zip(ot.x_stations, ot.data[:, j])):
|
||||
pt = self._w2s(x, y)
|
||||
if i == 0:
|
||||
for k_pt in range(len(smooth)):
|
||||
pt = self._w2s(smooth[k_pt, 0], smooth[k_pt, 1])
|
||||
if k_pt == 0:
|
||||
path.moveTo(pt)
|
||||
else:
|
||||
path.lineTo(pt)
|
||||
|
||||
Reference in New Issue
Block a user