Skip to content
Snippets Groups Projects
Commit 563f4f67 authored by Stephan Hilb's avatar Stephan Hilb
Browse files

implement dörfler marking

parent 84f01d31
Branches
Tags
No related merge requests found
...@@ -233,9 +233,26 @@ function refine(ctx::L1L2TVContext, marked_cells) ...@@ -233,9 +233,26 @@ function refine(ctx::L1L2TVContext, marked_cells)
return new_ctx return new_ctx
end end
function mark(ctx::L1L2TVContext; theta=0.5)
n = ncells(ctx.mesh)
esttotal = sum(ctx.est.data)
cellerrors = collect(pairs(ctx.est.data))
cellerrors_sorted = sort(cellerrors; lt = (x, y) -> x.second > y.second)
marked_cells = Int[]
estacc = 0.
for (cell, error) in cellerrors_sorted
estacc >= theta * esttotal && break
push!(marked_cells, cell)
estacc += error
end
return marked_cells
end
function save(ctx::L1L2TVContext, filename, fs...) function save(ctx::L1L2TVContext, filename, fs...)
print("save ... ") print("save \"$filename\" ... ")
vtk = vtk_mesh(filename, ctx.mesh) vtk = vtk_mesh(filename, ctx.mesh)
vtk_append!(vtk, fs...) vtk_append!(vtk, fs...)
vtk_save(vtk) vtk_save(vtk)
...@@ -318,32 +335,31 @@ function denoise(img; name, params...) ...@@ -318,32 +335,31 @@ function denoise(img; name, params...)
m = size(img) ./ 2 m = size(img) ./ 2
interpolate!(ctx.g, x -> norm(x .- m) < norm(m) / 3) interpolate!(ctx.g, x -> norm(x .- m) < norm(m) / 3)
save_denoise(i) = save_denoise(ctx, i) =
save(ctx, "$(ctx.name)_$(lpad(i, 5, '0')).vtu", save(ctx, "$(ctx.name)_$(lpad(i, 5, '0')).vtu",
ctx.g, ctx.u, ctx.p1, ctx.p2, ctx.est) ctx.g, ctx.u, ctx.p1, ctx.p2, ctx.est)
pvd = paraview_collection("$(ctx.name).pvd") pvd = paraview_collection("$(ctx.name).pvd")
pvd[0] = save_denoise(0) pvd[0] = save_denoise(ctx, 0)
for i in 1:10
step!(ctx) k = 0
estimate!(ctx) while true
pvd[i] = save_denoise(i) for i in 1:10
println() k += 1
end step!(ctx)
estmean = mean(ctx.est.data) estimate!(ctx)
marked_cells = findall(>(2*estmean), ctx.est.data) pvd[k] = save_denoise(ctx, k)
test_mesh(ctx.mesh) println()
println(marked_cells) end
ctx = refine(ctx, marked_cells) marked_cells = mark(ctx; theta = 0.7)
test_mesh(ctx.mesh) #println(marked_cells)
interpolate!(ctx.g, x -> norm(x .- m) < norm(m) / 3) println("refining ...")
for i in 6:20 ctx = refine(ctx, marked_cells)
step!(ctx) test_mesh(ctx.mesh)
estimate!(ctx) interpolate!(ctx.g, x -> norm(x .- m) < norm(m) / 3)
pvd[i] = save_denoise(i) k >= 50 && break
println()
end end
vtk_save(pvd)
return ctx return ctx
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment