-
Notifications
You must be signed in to change notification settings - Fork 7
/
RealViews.java
224 lines (215 loc) · 9.88 KB
/
RealViews.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* #%L
* ImgLib2: a general-purpose, multidimensional image processing library.
* %%
* Copyright (C) 2009 - 2020 Tobias Pietzsch, Stephan Preibisch, Stephan Saalfeld,
* John Bogovic, Albert Cardona, Barry DeZonia, Christian Dietz, Jan Funke,
* Aivar Grislis, Jonathan Hale, Grant Harris, Stefan Helfrich, Mark Hiner,
* Martin Horn, Steffen Jaensch, Lee Kamentsky, Larry Lindsey, Melissa Linkert,
* Mark Longair, Brian Northan, Nick Perry, Curtis Rueden, Johannes Schindelin,
* Jean-Yves Tinevez and Michael Zinsmaier.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package net.imglib2.realtransform;
import net.imglib2.RandomAccess;
import net.imglib2.RandomAccessible;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessible;
/**
* Convenience factory methods for {@link RealRandomAccessible
* RealRandomAccessibles} transformed in real coordinate space by
* {@link InvertibleRealTransform InvertibleRealTransforms}.
*
* @author Stephan Saalfeld
*/
public class RealViews
{
/**
* See a {@link RealRandomAccessible} as transformed by an
* {@link InvertibleRealTransform}. The {@link InvertibleRealTransform} is
* interpreted according to the natural understanding that the source is
* transformed by it. E.g. a positive translation of dimension <em>x</em>
* would shift the source to the right. Therefore, the samples need to be
* generated by the inverse of the {@link InvertibleRealTransform}. Here,
* the inverse is realized by {@link InverseRealTransform}. That way,
* changing the state of the {@link InvertibleRealTransform} will
* immediately change the state of any new {@link RealRandomAccess}
* generated by the view.
*
* @param source
* the {@link RealRandomAccessible} to be transformed
* @param transformFromSource
* the {@link InvertibleRealTransform} transforming source
* coordinates to coordinates of the returned
* {@link RealRandomAccessible}
* @param <T> the type
*
* @return {@link RealTransformRealRandomAccessible} representing the
* transformed source
*/
public static < T > RealTransformRealRandomAccessible< T, InverseRealTransform > transformReal( final RealRandomAccessible< T > source, final InvertibleRealTransform transformFromSource )
{
return new RealTransformRealRandomAccessible< >( source, new InverseRealTransform( transformFromSource ) );
}
/**
* See a {@link RealRandomAccessible} as a {@link RandomAccessible}
* transformed by an {@link InvertibleRealTransform}. The
* {@link InvertibleRealTransform} is interpreted according to the natural
* understanding that the source is transformed by it. E.g. a positive
* translation of dimension <em>x</em> would shift the source to the right.
* Therefore, the samples need to be generated by the inverse of the
* {@link InvertibleRealTransform}. Here, the inverse is realized by
* {@link InverseRealTransform}. That way, changing the state of the
* {@link InvertibleRealTransform} will immediately change the state of any
* new {@link RandomAccess} generated by the view.
*
* @param source
* the {@link RealRandomAccessible} to be transformed
* @param transformFromSource
* the {@link InvertibleRealTransform} transforming source
* coordinates to coordinates of the returned
* {@link RealRandomAccessible}
* @param <T> the type
*
* @return {@link RealTransformRandomAccessible} representing the
* transformed source
*/
public static < T > RealTransformRandomAccessible< T, InverseRealTransform > transform( final RealRandomAccessible< T > source, final InvertibleRealTransform transformFromSource )
{
return new RealTransformRandomAccessible< >( source, new InverseRealTransform( transformFromSource ) );
}
/**
* See a {@link RealRandomAccessible} as transformed by an {@link AffineGet}
* . The {@link AffineGet} is interpreted according to the natural
* understanding that the source is transformed by it. E.g. a positive
* translation of dimension <em>x</em> would shift the source to the right.
* Therefore, the samples need to be generated by the inverse of the
* {@link AffineGet}. Here, the {@link AffineGet} is inverted using it's
* {@link AffineGet#inverse()} method that is expected to generate an
* inverse that changes with the original transformation accordingly. That
* way, changing the state of the {@link AffineGet} will immediately change
* the state of any new {@link RealRandomAccess} generated by the view.
*
* @param source
* the {@link RealRandomAccessible} to be transformed
* @param transformFromSource
* the {@link InvertibleRealTransform} transforming source
* coordinates to coordinates of the returned
* {@link RealRandomAccessible}
* @param <T> the type
*
* @return {@link AffineRealRandomAccessible} representing the transformed
* source
*/
public static < T > AffineRealRandomAccessible< T, AffineGet > affineReal( final RealRandomAccessible< T > source, final AffineGet transformFromSource )
{
return new AffineRealRandomAccessible< >( source, transformFromSource.inverse() );
}
/**
* See a {@link RealRandomAccessible} as a {@link RandomAccessible}
* transformed by an {@link AffineGet}. The {@link AffineGet} is interpreted
* according to the natural understanding that the source is transformed by
* it. E.g. a positive translation of dimension <em>x</em> would shift the
* source to the right. Therefore, the samples need to be generated by the
* inverse of the {@link AffineGet}. Here, the {@link AffineGet} is inverted
* using it's {@link AffineGet#inverse()} method that is expected to
* generate and inverse that changes with the original transformation
* accordingly. That way, changing the state of the {@link AffineGet} will
* immediately change the state of any new {@link RandomAccess} generated
* by the view.
*
* @param source
* the {@link RealRandomAccessible} to be transformed
* @param transformFromSource
* the {@link InvertibleRealTransform} transforming source
* coordinates to coordinates of the returned
* {@link RealRandomAccessible}
* @param <T> the type
*
* @return {@link AffineRandomAccessible} representing the transformed
* source
*/
public static < T > AffineRandomAccessible< T, AffineGet > affine( final RealRandomAccessible< T > source, final AffineGet transformFromSource )
{
return new AffineRandomAccessible< >( source, transformFromSource.inverse() );
}
/**
* Add a dimension to a {@link RealRandomAccessible}. The resulting
* {@link RealRandomAccessible} has samples from the original dimensions
* continuously stacked along the added dimensions.
*
* The additional dimension is the last dimension. For example, an XYZ view
* is created for an XY source. When accessing an XYZ sample in the view,
* the final coordinate is discarded and the source XY sample is accessed.
*
* @param source
* the source
* @param <T> the type
* @return the new {@link RealRandomAccessible}
*/
public static < T > RealRandomAccessible< T > addDimension( final RealRandomAccessible< T > source )
{
return new StackingRealRandomAccessible< >( source, 1 );
}
/**
*
* Simplifies all {@link RealTransform}s which are wrapped in the source
* {@link RealRandomAccessible}.
*
* NB: that the resulting {@link RandomAccessible} copies all
* {@link RealTransform}s when required. Former references on any
* {@link RealTransform}s wrapped in the {@link RealRandomAccessible} are
* invalid for the resulting {@link RandomAccessible}.
*
* @param source
* {@link RealRandomAccessible} to be simplified
* @param <T> the type
* @return potentially simplified {@link RandomAccessible}
*
*/
public static < T > RandomAccessible< T > simplify( final RealRandomAccessible< T > source )
{
return RealViewsSimplifyUtils.simplify( source );
}
/**
*
* Simplifies all {@link RealTransform}s which are wrapped in the source
* {@link RealRandomAccessible}.
*
* NB: that the resulting {@link RealRandomAccessible} copies all
* {@link RealTransform}s when required. Former references on any
* {@link RealTransform}s wrapped in the {@link RealRandomAccessible} are
* invalid for the resulting {@link RealRandomAccessible}.
*
* @param source
* {@link RealRandomAccessible} to be simplified
* @param <T> the type
* @return potentially simplified {@link RealRandomAccessible}
*
*/
public static < T > RealRandomAccessible< T > simplifyReal( final RealRandomAccessible< T > source )
{
return RealViewsSimplifyUtils.simplifyReal( source );
}
}