Skip to content

Commit 4f81a78

Browse files
committed
Opify fill package
1 parent b036d87 commit 4f81a78

File tree

1 file changed

+149
-4
lines changed

1 file changed

+149
-4
lines changed

src/main/java/net/imglib2/algorithm/fill/FloodFill.java

Lines changed: 149 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@
3434

3535
package net.imglib2.algorithm.fill;
3636

37+
import java.util.concurrent.ExecutorService;
3738
import java.util.function.BiPredicate;
3839
import java.util.function.Consumer;
3940

4041
import gnu.trove.list.TLongList;
4142
import gnu.trove.list.array.TLongArrayList;
42-
import net.imglib2.Cursor;
43-
import net.imglib2.Localizable;
44-
import net.imglib2.RandomAccess;
45-
import net.imglib2.RandomAccessible;
43+
import net.imglib2.*;
4644
import net.imglib2.algorithm.neighborhood.Neighborhood;
4745
import net.imglib2.algorithm.neighborhood.Shape;
4846
import net.imglib2.type.Type;
@@ -105,6 +103,53 @@ public static < T extends Type< T >, U extends Type< U > > void fill(
105103
fill( source, target, seed, fillLabel, shape, filter );
106104
}
107105

106+
/**
107+
* Iterative n-dimensional flood fill for arbitrary neighborhoods: Starting
108+
* at seed location, write fillLabel into target at current location and
109+
* continue for each pixel in neighborhood defined by shape if neighborhood
110+
* pixel is in the same connected component and fillLabel has not been
111+
* written into that location yet.
112+
*
113+
* Convenience call to
114+
* {@link #fill(RandomAccessible, RandomAccessible, Localizable, Type, Shape, BiPredicate)}.
115+
* seedLabel is extracted from source at seed location.
116+
* <p>
117+
* This method differs from
118+
* {@link #fill(RandomAccessible, RandomAccessible, Localizable, Type, Shape)}
119+
* only in that its parameter order is tailored to an Op. The output comes
120+
* last, and the primary input (the input image) comes first.
121+
* </p>
122+
*
123+
* @implNote op name='floodFill', type='org.scijava.function.Computers.Arity4'
124+
* @param source
125+
* input
126+
* @param seed
127+
* Start flood fill at this location.
128+
* @param fillLabel
129+
* Immutable. Value to be written into valid flood fill
130+
* locations.
131+
* @param shape
132+
* Defines neighborhood that is considered for connected
133+
* components, e.g.
134+
* {@link net.imglib2.algorithm.neighborhood.DiamondShape}
135+
* @param target
136+
* {@link RandomAccessible} to be written into. May be the same
137+
* as input.
138+
* @param <T>
139+
* input pixel type
140+
* @param <U>
141+
* fill label type
142+
*/
143+
public static < T extends Type< T >, U extends Type< U > > void fill(
144+
final RandomAccessible< T > source,
145+
final Localizable seed,
146+
final U fillLabel,
147+
final Shape shape,
148+
final RandomAccessible< U > target)
149+
{
150+
fill(source, target, seed, fillLabel, shape);
151+
}
152+
108153
/**
109154
* Iterative n-dimensional flood fill for arbitrary neighborhoods: Starting
110155
* at seed location, write fillLabel into target at current location and
@@ -150,6 +195,58 @@ public static < T, U extends Type< U > > void fill(
150195
fill( source, target, seed, shape, filter, targetPixel -> targetPixel.set( fillLabel ) );
151196
}
152197

198+
/**
199+
* Iterative n-dimensional flood fill for arbitrary neighborhoods: Starting
200+
* at seed location, write fillLabel into target at current location and
201+
* continue for each pixel in neighborhood defined by shape if neighborhood
202+
* pixel is in the same connected component and fillLabel has not been
203+
* written into that location yet.
204+
*
205+
* Convenience call to
206+
* {@link FloodFill#fill(RandomAccessible, RandomAccessible, Localizable, Shape, BiPredicate, Consumer)}
207+
* with {@link Type#set} as writer.
208+
* <p>
209+
* This method differs from
210+
* {@link #fill(RandomAccessible, RandomAccessible, Localizable, Type, Shape, BiPredicate)}
211+
* only in that its parameter order is tailored to an Op. The output comes
212+
* last, and the primary input (the input image) comes first.
213+
* </p>
214+
*
215+
* @implNote op name='floodFill', type='org.scijava.function.Computers.Arity5'
216+
* @param source
217+
* input
218+
* @param seed
219+
* Start flood fill at this location.
220+
* @param fillLabel
221+
* Immutable. Value to be written into valid flood fill
222+
* locations.
223+
* @param shape
224+
* Defines neighborhood that is considered for connected
225+
* components, e.g.
226+
* {@link net.imglib2.algorithm.neighborhood.DiamondShape}
227+
* @param filter
228+
* Returns true if pixel has not been visited yet and should be
229+
* written into. Returns false if target pixel has been visited
230+
* or source pixel is not part of the same connected component.
231+
* @param target
232+
* {@link RandomAccessible} to be written into. May be the same
233+
* as input.
234+
* @param <T>
235+
* input pixel type
236+
* @param <U>
237+
* fill label type
238+
*/
239+
public static < T, U extends Type< U > > void fill(
240+
final RandomAccessible< T > source,
241+
final Localizable seed,
242+
final U fillLabel,
243+
final Shape shape,
244+
final BiPredicate< T, U > filter,
245+
final RandomAccessible< U > target)
246+
{
247+
fill( source, target, seed, shape, filter, targetPixel -> targetPixel.set( fillLabel ) );
248+
}
249+
153250
/**
154251
*
155252
* Iterative n-dimensional flood fill for arbitrary neighborhoods: Starting
@@ -236,6 +333,54 @@ public static < T, U > void fill(
236333
}
237334

238335
}
336+
/**
337+
*
338+
* Iterative n-dimensional flood fill for arbitrary neighborhoods: Starting
339+
* at seed location, write fillLabel into target at current location and
340+
* continue for each pixel in neighborhood defined by shape if neighborhood
341+
* pixel is in the same connected component and fillLabel has not been
342+
* written into that location yet.
343+
* <p>
344+
* This method differs from
345+
* {@link #fill(RandomAccessible, RandomAccessible, Localizable, Shape, BiPredicate, Consumer)}
346+
* only in that its parameter order is tailored to an Op. The output comes
347+
* last, and the primary input (the input image) comes first.
348+
* </p>
349+
*
350+
* @implNote op name='floodFill', type='org.scijava.function.Computers.Arity5'
351+
* @param source
352+
* input
353+
* @param seed
354+
* Start flood fill at this location.
355+
* @param shape
356+
* Defines neighborhood that is considered for connected
357+
* components, e.g.
358+
* {@link net.imglib2.algorithm.neighborhood.DiamondShape}
359+
* @param filter
360+
* Returns true if pixel has not been visited yet and should be
361+
* written into. Returns false if target pixel has been visited
362+
* or source pixel is not part of the same connected component.
363+
* @param writer
364+
* Defines how fill label is written into target at current
365+
* location.
366+
* @param target
367+
* {@link RandomAccessible} to be written into. May be the same
368+
* as input.
369+
* @param <T>
370+
* input pixel type
371+
* @param <U>
372+
* fill label type
373+
*/
374+
public static < T, U > void fill(
375+
final RandomAccessible< T > source,
376+
final Localizable seed,
377+
final Shape shape,
378+
final BiPredicate< T, U > filter,
379+
final Consumer< U > writer,
380+
final RandomAccessible< U > target )
381+
{
382+
fill(source, target, seed, shape, filter, writer);
383+
}
239384

240385
/**
241386
* Iterative n-dimensional flood fill for arbitrary neighborhoods: Starting

0 commit comments

Comments
 (0)