Skip to content

Commit

Permalink
implement coarsen and JacobiDet functions
Browse files Browse the repository at this point in the history
  • Loading branch information
HoBeZwe committed Jun 18, 2024
1 parent 75d2315 commit d279136
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ext/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function NURBS.plotPatches(Patches; plotControlPoints=true, enforceRatio=true, r
traces = PlotlyJS.GenericTrace[]
maxvec = Float64[]

col = 1:size(Patches, 1)
col = 1 .+ rand(length(Patches))#1:size(Patches, 1)

for (ind, patch) in enumerate(Patches)

Expand Down
2 changes: 1 addition & 1 deletion src/NURBS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export evalNaive, evalNaiveDerivative
export Jacobian, JacobiDet

export insertKnot!, insertKnot
export refine # NOTE: split is an extension of Base.split, i.e., it is publicly available without export
export coarsen, refine # NOTE: split is an extension of Base.split, i.e., it is publicly available without export
export removeKnot!, removeKnot, removeKnotU, removeKnotV

export readMultipatch, readStep
Expand Down
25 changes: 24 additions & 1 deletion src/fundamentalOperations/knotRemoval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ function removeKnotV(S::Surface, pointToRemove::Real, multiplicity::Int)
end


"""
coarsen(knotVec, controlPoints, degree::Int, pointsToRemove::Vector, weights=[])
Coarsen a curve by removing parametric points from a curve's knot vector.
NOTE: There are more efficient ways to do this.
"""
function coarsen(knotVec, controlPoints, degree::Int, pointsToRemove::Vector, weights=[])

# --- make copies
knotVecMod = deepcopy(knotVec)
controlPointsMod = deepcopy(controlPoints)
weightsMod = deepcopy(weights)

# --- modify copies
for (i, remPoint) in enumerate(pointsToRemove)
checkRange(remPoint)
removeKnot!(knotVecMod, controlPointsMod, degree, remPoint, 1, weightsMod)
end

return knotVecMod, controlPointsMod, weightsMod
end


"""
removeKnot(knotVec, controlPoints, degree::Int, pointToRemove::Real, multiplicity::Int, weights)
Expand Down Expand Up @@ -249,7 +273,6 @@ function trimControlPoints!(cPts, kVecOri, degree::Int, pos::Int, pointToRemove:

# --- can knot be removed? Two different cases to be covered
if j - i < t

temp[ii] temp[jj + 2] && (removable = true)
wemp[ii] wemp[jj + 2] && (removableW = true)
else
Expand Down
13 changes: 13 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ function JacobiDet(Ju, Jv)
return dJ
end

function JacobiDet(Ju::SVector{3,T}, Jv::SVector{3,T}) where {T}

xu = Ju[1]
yu = Ju[2]
zu = Ju[3]

xv = Jv[1]
yv = Jv[2]
zv = Jv[3]

return sqrt((yu * zv - zu * yv)^2 + (zu * xv - xu * zv)^2 + (xu * yv - yu * xv)^2)
end


"""
spanRanges(Bspl::Bspline, points)
Expand Down
4 changes: 4 additions & 0 deletions test/fundamentalOperations/knotRemoval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
BC = BsplineCurve(Bspline(p, kVec), cP)

RC = removeKnot(BC, 0.5, 3)
kVecMod, cPmod, wMod = coarsen(kVec, cP, p, [0.5, 0.5, 0.5])

@test RC.basis.knotVec == kVecMod
@test RC.controlPoints == cPmod

cPR = RC.controlPoints

Expand Down
4 changes: 4 additions & 0 deletions test/surfaces_nurbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
@test S[2, 1][1, 1] SVector(4.4444444444, 0.0, 0.0)
@test S[2, 2][1, 1] SVector(-3.950617283, 0.0, 0.0)

a = SVector(2.1, 0.0, 1.0)
b = SVector(0.0, 0.0, 3.4)
@test JacobiDet(a, b) == norm(a × b) # area of parallelogram spanned by a and b

@test_nowarn Jacobian(Patch, uEvalpoints, vEvalpoints)


Expand Down

0 comments on commit d279136

Please sign in to comment.