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

implement dörfler marking

parent 84f01d31
No related branches found
No related tags found
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)
k = 0
while true
for i in 1:10 for i in 1:10
k += 1
step!(ctx) step!(ctx)
estimate!(ctx) estimate!(ctx)
pvd[i] = save_denoise(i) pvd[k] = save_denoise(ctx, k)
println() println()
end end
estmean = mean(ctx.est.data) marked_cells = mark(ctx; theta = 0.7)
marked_cells = findall(>(2*estmean), ctx.est.data) #println(marked_cells)
test_mesh(ctx.mesh) println("refining ...")
println(marked_cells)
ctx = refine(ctx, marked_cells) ctx = refine(ctx, marked_cells)
test_mesh(ctx.mesh) test_mesh(ctx.mesh)
interpolate!(ctx.g, x -> norm(x .- m) < norm(m) / 3) interpolate!(ctx.g, x -> norm(x .- m) < norm(m) / 3)
for i in 6:20 k >= 50 && break
step!(ctx)
estimate!(ctx)
pvd[i] = save_denoise(i)
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