Skip to content

Commit

Permalink
"Unify nurbs surfaces" API.
Browse files Browse the repository at this point in the history
  • Loading branch information
portnov committed Jun 23, 2021
1 parent 5cd3e32 commit 3b1b550
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions utils/surface/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from sverchok.utils.curve.core import SvFlipCurve, UnsupportedCurveTypeException
from sverchok.utils.curve.primitives import SvCircle
from sverchok.utils.curve import knotvector as sv_knotvector
from sverchok.utils.curve.algorithms import (
SvNormalTrack, curve_frame_on_surface_array,
MathutilsRotationCalculator, DifferentialRotationCalculator,
Expand Down Expand Up @@ -1072,3 +1073,61 @@ def nurbs_revolution_surface(curve, origin, axis, v_min=0, v_max=2*pi, global_or
curve.get_knotvector(), circle_knotvector,
control_points, weights)

def unify_nurbs_surfaces(surfaces):
# Unify surface degrees

degrees_u = [surface.get_degree_u() for surface in surfaces]
degrees_v = [surface.get_degree_v() for surface in surfaces]

degree_u = max(degrees_u)
degree_v = max(degrees_v)

surfaces = [surface.elevate_degree(SvNurbsSurface.U, target=degree_u) for surface in surfaces]
surfaces = [surface.elevate_degree(SvNurbsSurface.V, target=degree_v) for surface in surfaces]

# Unify surface knotvectors

dst_knots_u = defaultdict(int)
dst_knots_v = defaultdict(int)
for surface in surfaces:
m_u = sv_knotvector.to_multiplicity(surface.get_knotvector_u())
m_v = sv_knotvector.to_multiplicity(surface.get_knotvector_v())

for u, count in m_u:
u = round(u, 6)
dst_knots_u[u] = max(dst_knots_u[u], count)

for v, count in m_v:
v = round(v, 6)
dst_knots_v[v] = max(dst_knots_v[v], count)

result = []
for surface in surfaces:
diffs_u = []
kv_u = np.round(surface.get_knotvector_u(), 6)
ms_u = dict(sv_knotvector.to_multiplicity(kv_u))
for dst_u, dst_multiplicity in dst_knots_u.items():
src_multiplicity = ms_u.get(dst_u, 0)
diff = dst_multiplicity - src_multiplicity
diffs_u.append((dst_u, diff))

for u, diff in diffs_u:
if diff > 0:
surface = surface.insert_knot(SvNurbsSurface.U, u, diff)

diffs_v = []
kv_v = np.round(surface.get_knotvector_v(), 6)
ms_v = dict(sv_knotvector.to_multiplicity(kv_v))
for dst_v, dst_multiplicity in dst_knots_v.items():
src_multiplicity = ms_v.get(dst_v, 0)
diff = dst_multiplicity - src_multiplicity
diffs_v.append((dst_v, diff))

for v, diff in diffs_v:
if diff > 0:
surface = surface.insert_knot(SvNurbsSurface.V, v, diff)

result.append(surface)

return result

0 comments on commit 3b1b550

Please sign in to comment.