Skip to content

Commit

Permalink
Method of finding k for knot insertion was incorrect.
Browse files Browse the repository at this point in the history
sv_knotvector.find_span() works in a special way when u_bar is near
right end of curve domain.

refs #4722.
  • Loading branch information
portnov committed Nov 4, 2022
1 parent ea6582e commit a37b6e5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions utils/curve/nurbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,12 +1182,7 @@ def insert_knot(self, u_bar, count=1, if_possible=False):
N = len(self.control_points)
u = self.get_knotvector()
s = sv_knotvector.find_multiplicity(u, u_bar)
#print(f"I: kv {len(u)}{u}, u_bar {u_bar} => s {s}")
#k = np.searchsorted(u, u_bar, side='right')-1
k = sv_knotvector.find_span(u, N, u_bar)
p = self.get_degree()
new_knotvector = sv_knotvector.insert(u, u_bar, count)
control_points = self.get_homogenous_control_points()

if (u_bar == u[0] or u_bar == u[-1]):
if s+count > p+1:
Expand All @@ -1202,6 +1197,10 @@ def insert_knot(self, u_bar, count=1, if_possible=False):
else:
raise CantInsertKnotException(f"Can't insert knot t={u_bar} for {count} times")

k = u.searchsorted(u_bar, side='right')-1
new_knotvector = sv_knotvector.insert(u, u_bar, count)
control_points = self.get_homogenous_control_points()

for r in range(1, count+1):
prev_control_points = control_points
control_points = []
Expand All @@ -1211,9 +1210,11 @@ def insert_knot(self, u_bar, count=1, if_possible=False):
point = prev_control_points[i]
#print(f"P[{r},{i}] := {i}{prev_control_points[i]}")
elif k - p + r <= i <= k - s:
if i >= len(prev_control_points):
raise CantInsertKnotException(f"Can't insert the knot t={u_bar} for {r}th time: T is too close to curve's end")
denominator = u[i+p-r+1] - u[i]
if abs(denominator) < 1e-6:
raise Exception(f"Can't insert the knot t={u_bar} for {i}th time: u[i+p-r+1]={u[i+p-r+1]}, u[i]={u[i]}, denom={denominator}")
raise Exception(f"Can't insert the knot t={u_bar} for {r}th time: u[i+p-r+1]={u[i+p-r+1]}, u[i]={u[i]}, denom={denominator}")
alpha = (u_bar - u[i]) / denominator
point = alpha * prev_control_points[i] + (1.0 - alpha) * prev_control_points[i-1]
#print(f"P[{r},{i}]: alpha {alpha}, pts {i}{prev_control_points[i]}, {i-1}{prev_control_points[i-1]} => {point}")
Expand Down

0 comments on commit a37b6e5

Please sign in to comment.