Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SemiSmoothNewton.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephan Hilb
SemiSmoothNewton.jl
Commits
8916fc05
Commit
8916fc05
authored
Jun 29, 2021
by
Stephan Hilb
Browse files
Options
Downloads
Patches
Plain Diff
add basic image warping
parent
3e30404e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/SemiSmoothNewton.jl
+72
-0
72 additions, 0 deletions
src/SemiSmoothNewton.jl
src/image.jl
+27
-0
27 additions, 0 deletions
src/image.jl
src/mesh.jl
+26
-0
26 additions, 0 deletions
src/mesh.jl
with
125 additions
and
0 deletions
src/SemiSmoothNewton.jl
0 → 100644
+
72
−
0
View file @
8916fc05
module
SemiSmoothNewton
include
(
"image.jl"
)
include
(
"mesh.jl"
)
function
run
()
end
function
clip_line
(
r0
,
r1
,
l0
,
l1
)
d_l
=
-
(
l1
[
1
]
-
l0
[
1
])
d_r
=
+
(
l1
[
1
]
-
l0
[
1
])
d_b
=
-
(
l1
[
2
]
-
l0
[
2
])
d_t
=
+
(
l1
[
2
]
-
l0
[
2
])
t_l
=
-
(
r0
[
1
]
-
l0
[
1
])
/
d_l
t_r
=
+
(
r1
[
1
]
-
l0
[
1
])
/
d_r
t_b
=
-
(
r0
[
2
]
-
l0
[
2
])
/
d_b
t_t
=
+
(
r1
[
2
]
-
l0
[
2
])
/
d_t
t0
=
max
(
d_l
<=
0
?
t_l
:
0.
,
d_r
<=
0
?
t_r
:
0.
,
d_b
<=
0
?
t_b
:
0.
,
d_t
<=
0
?
t_t
:
0.
)
t1
=
min
(
d_l
>=
0
?
t_l
:
1.
,
d_r
>=
0
?
t_r
:
1.
,
d_b
>=
0
?
t_b
:
1.
,
d_t
>=
0
?
t_t
:
1.
)
# tolerance on non-intersection
t1
<
t0
+
eps
()
&&
return
false
c0
=
l0
+
t0
*
(
l1
-
l0
)
c1
=
l0
+
t1
*
(
l1
-
l0
)
return
c0
,
c1
end
# meshfunction
# mesh
# mesh
# vertices: idx -> vertex
# cells: idx -> cell
"project array data onto a grid function"
function
project_array!
(
u
,
img
::
Array
)
vertices
=
u
.
mesh
.
vertices
mesh_box
=
(
reduce
((
a
,
b
)
->
min
.
(
a
,
b
),
vertices
),
reduce
((
a
,
b
)
->
max
.
(
a
,
b
),
vertices
))
for
cell
in
u
.
mesh
.
cells
cell_box
=
(
reduce
((
a
,
b
)
->
min
.
(
a
,
b
),
cell
.
vertices
),
reduce
((
a
,
b
)
->
max
.
(
a
,
b
),
cell
.
vertices
))
u
[
cell
]
end
end
end
# module
This diff is collapsed.
Click to expand it.
src/image.jl
0 → 100644
+
27
−
0
View file @
8916fc05
eval_neumann
(
img
,
x
)
=
img
[
clamp
.
(
Tuple
(
x
),
axes
(
img
))
...
]
function
interpolate_bilinear
(
img
,
x
)
x0
=
floor
.
(
Int
,
x
)
x1
=
x0
.+
1
val
=
zero
(
eltype
(
img
))
for
idx
in
CartesianIndices
(
ntuple
(
_
->
0
:
1
,
ndims
(
img
)))
cornerbool
=
Bool
.
(
Tuple
(
idx
))
λ
=
ifelse
.
(
cornerbool
,
x
.-
x0
,
x1
.-
x
)
corner
=
ifelse
.
(
cornerbool
,
x1
,
x0
)
val
+=
prod
(
λ
)
*
eval_neumann
(
img
,
CartesianIndex
(
corner
))
end
return
val
end
function
warp_backwards
(
img
,
u
)
axes
(
img
)
==
axes
(
u
)[
2
:
end
]
||
throw
(
ArgumentError
(
"invalid dimensions"
))
res
=
similar
(
img
)
for
I
in
CartesianIndices
(
img
)
x
=
Tuple
(
I
)
.+
u
[
:
,
I
]
res
[
I
]
=
interpolate_bilinear
(
img
,
(
x
...
,))
end
return
res
end
This diff is collapsed.
Click to expand it.
src/mesh.jl
0 → 100644
+
26
−
0
View file @
8916fc05
using
WriteVTK
# 2d, simplex grid
struct
Mesh
vertices
::
Array
{
Float64
,
2
}
cells
::
Array
{
NTuple
{
3
,
Int64
}}
end
#function append_data!(vtkfile, f::GlobalMeshFunction{<:TriangleGrid, n}) where n
# fgrid = mesh(f)
# fdata = Array{Float64, 2}(undef, n, size(fgrid.vertices, 2))
# for i in axes(fdata, 2)
# fdata[:, i] .= f.f(fgrid.vertices[:, i])
# end
# vtk_point_data(vtkfile, fdata, "f")
#end
#
#cells = [MeshCell(VTKCellTypes.VTK_TRIANGLE, grid.cells[:, i]) for i in axes(grid.cells, 2)]
#vtkfile = vtk_grid(filename, grid.vertices, cells)
#for (i, f) in enumerate(fs)
# append_data!(vtkfile, f)
#end
#vtk_save(vtkfile)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment