Skip to content

Commit 49cf844

Browse files
committed
RealRandomAccessible extending RandomAccessible
1 parent fd081a3 commit 49cf844

File tree

3 files changed

+166
-249
lines changed

3 files changed

+166
-249
lines changed

src/main/java/net/imglib2/RealRandomAccessible.java

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
*
5858
* @author Stephan Saalfeld
5959
*/
60-
public interface RealRandomAccessible< T > extends EuclideanSpace, Typed< T >
60+
public interface RealRandomAccessible< T > extends RandomAccessible<T>
6161
{
6262
/**
6363
* Create a random access sampler for real coordinates.
@@ -144,6 +144,167 @@ default RealRandomAccessibleView< T > realView()
144144
return RealRandomAccessibleView.wrap( this );
145145
}
146146

147+
/* RandomAccessible overrides*/
148+
149+
@Override
150+
default RandomAccess< T > randomAccess() {
151+
return randomAccess(null);
152+
}
153+
154+
@Override
155+
default RandomAccess< T > randomAccess(final Interval interval) {
156+
final RealRandomAccess<T> sourceAccess = interval == null ? realRandomAccess() : realRandomAccess(interval);
157+
final int n = numDimensions();
158+
return new RandomAccess<T>() {
159+
160+
@Override
161+
public void localize( final int[] position )
162+
{
163+
for ( int d = 0; d < n; ++d )
164+
position[ d ] = ( int ) Math.round( sourceAccess.getDoublePosition( d ) );
165+
}
166+
167+
@Override
168+
public void localize( final long[] position )
169+
{
170+
for ( int d = 0; d < n; ++d )
171+
position[ d ] = Math.round( sourceAccess.getDoublePosition( d ) );
172+
}
173+
174+
@Override
175+
public int getIntPosition( final int d )
176+
{
177+
return ( int ) Math.round( sourceAccess.getDoublePosition( d ) );
178+
}
179+
180+
@Override
181+
public long getLongPosition( final int d )
182+
{
183+
return Math.round( sourceAccess.getDoublePosition( d ) );
184+
}
185+
186+
@Override
187+
public void localize( final float[] position )
188+
{
189+
sourceAccess.localize( position );
190+
}
191+
192+
@Override
193+
public void localize( final double[] position )
194+
{
195+
sourceAccess.localize( position );
196+
}
197+
198+
@Override
199+
public float getFloatPosition( final int d )
200+
{
201+
return sourceAccess.getFloatPosition( d );
202+
}
203+
204+
@Override
205+
public double getDoublePosition( final int d )
206+
{
207+
return sourceAccess.getDoublePosition( d );
208+
}
209+
210+
@Override
211+
public void fwd( final int d )
212+
{
213+
sourceAccess.fwd( d );
214+
}
215+
216+
@Override
217+
public void bck( final int d )
218+
{
219+
sourceAccess.bck( d );
220+
}
221+
222+
@Override
223+
public void move( final int distance, final int d )
224+
{
225+
sourceAccess.move( distance, d );
226+
}
227+
228+
@Override
229+
public void move( final long distance, final int d )
230+
{
231+
sourceAccess.move( distance, d );
232+
}
233+
234+
@Override
235+
public void move( final Localizable localizable )
236+
{
237+
sourceAccess.move( localizable );
238+
}
239+
240+
@Override
241+
public void move( final int[] distance )
242+
{
243+
sourceAccess.move( distance );
244+
}
245+
246+
@Override
247+
public void move( final long[] distance )
248+
{
249+
sourceAccess.move( distance );
250+
}
251+
252+
@Override
253+
public void setPosition( final Localizable localizable )
254+
{
255+
sourceAccess.setPosition( localizable );
256+
}
257+
258+
@Override
259+
public void setPosition( final int[] position )
260+
{
261+
sourceAccess.setPosition( position );
262+
}
263+
264+
@Override
265+
public void setPosition( final long[] position )
266+
{
267+
sourceAccess.setPosition( position );
268+
}
269+
270+
@Override
271+
public void setPosition( final int position, final int d )
272+
{
273+
sourceAccess.setPosition( position, d );
274+
}
275+
276+
@Override
277+
public void setPosition( final long position, final int d )
278+
{
279+
sourceAccess.setPosition( position, d );
280+
}
281+
282+
@Override
283+
public T get()
284+
{
285+
return sourceAccess.get();
286+
}
287+
288+
@Override
289+
public T getType()
290+
{
291+
return sourceAccess.getType();
292+
}
293+
294+
@Override
295+
public RandomAccess<T> copy()
296+
{
297+
return randomAccess();
298+
}
299+
300+
@Override
301+
public int numDimensions()
302+
{
303+
return n;
304+
}
305+
};
306+
}
307+
147308
/*
148309
* NB: We cannot have a default implementation here because of
149310
* https://bugs.openjdk.org/browse/JDK-7120669
@@ -154,3 +315,4 @@ default RealRandomAccessibleView< T > realView()
154315
// return realRandomAccess().get();
155316
// }
156317
}
318+

0 commit comments

Comments
 (0)