11"""
2- InvWarpedView(img, tinv, [indices]) -> wv
2+ InvWarpedView(img, tinv, [indices]; kwargs...) -> wv
3+ InvWarpedView(inner_view, tinv) -> wv
34
45Create a view of `img` that lazily transforms any given index `I`
56passed to `wv[I]` so that `wv[I] == img[inv(tinv)(I)]`.
67
8+ Except for the lazy evaluation, the following two lines are expected to be equivalent:
9+
10+ ```julia
11+ warp(img, inv(tform), [indices]; kwargs...)
12+ invwarpedview(img, tform, [indices]; kwargs...)
13+ ```
14+
715The conceptual difference to [`WarpedView`](@ref) is that
816`InvWarpedView` is intended to be used when reasoning about the
917image is more convenient that reasoning about the indices.
1018Furthermore, `InvWarpedView` allows simple nesting of
1119transformations, in which case the transformations will be
1220composed into a single one.
1321
14- See [`invwarpedview`](@ref) for a convenient constructor of `InvWarpedView`.
15-
1622For detailed explaination of warp, associated arguments and parameters,
1723please refer to [`warp`](@ref).
1824"""
@@ -26,8 +32,9 @@ function InvWarpedView(inner::WarpedView{T,N,TA,F,I,E}) where {T,N,TA,F,I,E}
2632 InvWarpedView {T,N,TA,F,I,typeof(tinv),E} (inner, tinv)
2733end
2834
29- function InvWarpedView (A:: AbstractArray , tinv:: Transformation , inds:: Tuple = autorange (A, tinv))
30- InvWarpedView (WarpedView (A, inv (tinv), inds), tinv)
35+ function InvWarpedView (A:: AbstractArray , tinv:: Transformation , inds:: Tuple = autorange (A, tinv); kwargs... )
36+ inner = WarpedView (A, inv (tinv), inds; kwargs... )
37+ InvWarpedView (inner, tinv)
3138end
3239
3340function InvWarpedView (inner:: InvWarpedView , outer_tinv:: Transformation )
@@ -40,14 +47,11 @@ function InvWarpedView(inner::InvWarpedView, outer_tinv::Transformation, inds::T
4047 InvWarpedView (parent (inner), tinv, inds)
4148end
4249
43- Base. parent (A:: InvWarpedView ) = parent (A. inner)
50+ @inline Base. parent (A:: InvWarpedView ) = parent (A. inner)
4451@inline Base. axes (A:: InvWarpedView ) = axes (A. inner)
52+ @inline Base. size (A:: InvWarpedView ) = size (A. inner)
4553
46- IndexStyle (:: Type{T} ) where {T<: InvWarpedView } = IndexCartesian ()
47- @inline Base. getindex (A:: InvWarpedView{T,N} , I:: Vararg{Int,N} ) where {T,N} = A. inner[I... ]
48-
49- Base. size (A:: InvWarpedView ) = size (A. inner)
50- Base. size (A:: InvWarpedView , d) = size (A. inner, d)
54+ Base. @propagate_inbounds Base. getindex (A:: InvWarpedView{T,N} , I:: Vararg{Int,N} ) where {T,N} = A. inner[I... ]
5155
5256function Base. showarg (io:: IO , A:: InvWarpedView , toplevel)
5357 print (io, " InvWarpedView(" )
@@ -60,37 +64,3 @@ function Base.showarg(io::IO, A::InvWarpedView, toplevel)
6064 print (io, ' )' )
6165 end
6266end
63-
64- """
65- invwarpedview(img, tinv, [indices]; kwargs...) -> wv
66-
67- Create a view of `img` that lazily transforms any given index `I`
68- passed to `wv[I]` so that `wv[I] == img[inv(tinv)(I)]`.
69-
70- Except for the lazy evaluation, the following two lines are equivalent:
71-
72- ```julia
73- warp(img, inv(tform), [indices]; kwargs...)
74- invwarpedview(img, tform, [indices]; kwargs...)
75- ```
76-
77- For detailed explaination of warp, associated arguments and parameters,
78- please refer to [`warp`](@ref).
79- """
80- function invwarpedview (A:: AbstractArray , tinv:: Transformation , indices:: Tuple = autorange (A, tinv); kwargs... )
81- InvWarpedView (box_extrapolation (A; kwargs... ), tinv, indices)
82- end
83-
84- # For SubArray:
85- # 1. We can exceed the boundary of SubArray by using its parent and thus trick Interpolations in
86- # order to get better extrapolation result around the border. Otherwise it will just fill it.
87- # 2. For default indices, we use `IdentityUnitRange`, which guarantees `r[i] == i`, to preserve the view indices.
88- function invwarpedview (A:: SubArray , tinv:: Transformation ; kwargs... )
89- default_indices = map (IdentityUnitRange, autorange (CartesianIndices (A. indices), tinv))
90- invwarpedview (A, tinv, default_indices; kwargs... )
91- end
92- function invwarpedview (A:: SubArray , tinv:: Transformation , indices:: Tuple ; kwargs... )
93- inner = parent (A)
94- new_inner = InvWarpedView (inner, tinv, autorange (inner, tinv))
95- view (new_inner, indices... )
96- end
0 commit comments