Skip to content

Commit

Permalink
fix some degree=0 cases
Browse files Browse the repository at this point in the history
  • Loading branch information
HoBeZwe committed May 7, 2024
1 parent ed474bb commit a1c92a9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NURBS"
uuid = "dde13934-061e-461b-aa91-2c0fad390a0d"
authors = ["Bernd Hofmann <[email protected]> and contributors"]
version = "0.6.0"
version = "0.6.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
32 changes: 26 additions & 6 deletions src/fundamentalOperations/knotInsertion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function extendKnotVector!(knotVecOrig, degree::Int, newParametricPoint::Real, m

# --- check whether resulting mulitplicity makes sense
newMult = multiplicity + oldMult
if newMult > degree
if newMult > degree + 1
@info "The multiplicity of the inserted knot is limited to $(degree)."
newMult = degree
end
Expand All @@ -258,13 +258,14 @@ function extendControlPoints!(
controlPoints, knotVecOrig, degree::Int, pos::Int, uNew::Real, multiplicity::Int, oldMult::Int, weights=[]
)

T = eltype(controlPoints[1])
degree == 0 && return extendControlPoints!(controlPoints, pos, multiplicity, oldMult) # not so nice - why does algorithm not hold for degree=0?
#T = eltype(controlPoints[1])

# --- computation including weights
if !isempty(weights)

newControlPoints = [SVector{3,T}(0.0, 0.0, 0.0) for i in 1:(degree - oldMult + multiplicity - 1)]
newWeights = [T(0.0) for i in 1:(degree - oldMult + multiplicity - 1)]
newControlPoints = similar(controlPoints, degree - oldMult + multiplicity - 1) #[SVector{3,T}(0.0, 0.0, 0.0) for i in 1:(degree - oldMult + multiplicity - 1)]
newWeights = similar(weights, degree - oldMult + multiplicity - 1) #[T(0.0) for i in 1:(degree - oldMult + multiplicity - 1)]

auxC = controlPoints[(pos - degree):(pos - oldMult)]
auxW = weights[(pos - degree):(pos - oldMult)]
Expand Down Expand Up @@ -301,7 +302,7 @@ function extendControlPoints!(
end

# --- computation when there are no weights
newControlPoints = [SVector{3,T}(0.0, 0.0, 0.0) for i in 1:(degree - oldMult + multiplicity - 1)]
newControlPoints = similar(controlPoints, degree - oldMult + multiplicity - 1) #[SVector{3,T}(0.0, 0.0, 0.0) for i in 1:(degree - oldMult + multiplicity - 1)]

aux = controlPoints[(pos - degree):(pos - oldMult)]
for r in 1:multiplicity
Expand All @@ -312,7 +313,6 @@ function extendControlPoints!(
αᵢ = (uNew - knotVecOrig[L]) / (knotVecOrig[pos + i] - knotVecOrig[L])
aux[i] = αᵢ * aux[i + 1] + (1.0 - αᵢ) * aux[i]
end

newControlPoints[r] = aux[1]
newControlPoints[end - r + 1] = aux[end - r]
end
Expand All @@ -327,3 +327,23 @@ function extendControlPoints!(

return nothing
end

"""
Lowest order polynomial degree = 0.
Can multiplicity be maximum 1 and/or oldMult maximum 0? => simplify below algorithm further.
"""
function extendControlPoints!(controlPoints, pos::Int, multiplicity::Int, oldMult::Int)

newControlPoints = similar(controlPoints, oldMult + multiplicity)

aux = controlPoints[(pos):(pos - oldMult)]
for r in 1:multiplicity
newControlPoints[r] = aux[1]
end

# splice new computed points into array (replacing the correct amount)
splice!(controlPoints, (pos + 1):(pos - oldMult - 1), newControlPoints)

return nothing
end
2 changes: 2 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ Return the Greville sites (as defined in [3]) corresponding to the given knotvec
"""
function greville(kVec, degree::Int)

degree == 0 && return unique(kVec)

N = length(kVec) - degree - 1 # number of B-splines
gSites = zeros(eltype(kVec), N)

Expand Down

0 comments on commit a1c92a9

Please sign in to comment.