Skip to content

Commit 43f4b1a

Browse files
authored
Merge pull request #208 from imglib/native-bool-type
Add the infrastructure for boolean[]-backed images
2 parents f578d60 + c6e369b commit 43f4b1a

File tree

16 files changed

+1090
-1
lines changed

16 files changed

+1090
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010

1111
<artifactId>imglib2</artifactId>
12-
<version>5.5.1-SNAPSHOT</version>
12+
<version>5.6.0-SNAPSHOT</version>
1313

1414
<name>ImgLib2 Core Library</name>
1515
<description>A multidimensional, type-agnostic image processing library.</description>

src/main/java/net/imglib2/img/array/ArrayImgs.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434

3535
package net.imglib2.img.array;
3636

37+
import net.imglib2.img.basictypeaccess.BooleanAccess;
3738
import net.imglib2.img.basictypeaccess.ByteAccess;
3839
import net.imglib2.img.basictypeaccess.DoubleAccess;
3940
import net.imglib2.img.basictypeaccess.FloatAccess;
4041
import net.imglib2.img.basictypeaccess.IntAccess;
4142
import net.imglib2.img.basictypeaccess.LongAccess;
4243
import net.imglib2.img.basictypeaccess.ShortAccess;
44+
import net.imglib2.img.basictypeaccess.array.BooleanArray;
4345
import net.imglib2.img.basictypeaccess.array.ByteArray;
4446
import net.imglib2.img.basictypeaccess.array.DoubleArray;
4547
import net.imglib2.img.basictypeaccess.array.FloatArray;
@@ -48,6 +50,7 @@
4850
import net.imglib2.img.basictypeaccess.array.ShortArray;
4951
import net.imglib2.type.Type;
5052
import net.imglib2.type.logic.BitType;
53+
import net.imglib2.type.logic.NativeBoolType;
5154
import net.imglib2.type.numeric.ARGBType;
5255
import net.imglib2.type.numeric.complex.ComplexDoubleType;
5356
import net.imglib2.type.numeric.complex.ComplexFloatType;
@@ -348,6 +351,36 @@ final public static < A extends LongAccess > ArrayImg< LongType, A > longs( fina
348351
return img;
349352
}
350353

354+
/**
355+
* Create an {@link ArrayImg}&lt;{@link NativeBoolType}, {@link BooleanArray}&gt;.
356+
*/
357+
@SuppressWarnings( "unchecked" )
358+
final static public ArrayImg< NativeBoolType, BooleanArray > booleans( final long... dim )
359+
{
360+
return ( ArrayImg< NativeBoolType, BooleanArray > ) new ArrayImgFactory<>( new NativeBoolType() ).create( dim );
361+
}
362+
363+
/**
364+
* Creates an {@link ArrayImg}&lt;{@link NativeBoolType}, {@link BooleanArray}&gt;
365+
* reusing a passed byte[] array.
366+
*/
367+
final public static ArrayImg< NativeBoolType, BooleanArray > booleans( final boolean[] array, final long... dim )
368+
{
369+
return booleans( new BooleanArray( array ), dim );
370+
}
371+
372+
/**
373+
* Creates an {@link ArrayImg}&lt;{@link NativeBoolType},
374+
* {@link BooleanAccess}&gt; using a {@link BooleanAccess} passed as argument.
375+
*/
376+
final public static < A extends BooleanAccess > ArrayImg< NativeBoolType, A > booleans( final A access, final long... dim )
377+
{
378+
final ArrayImg< NativeBoolType, A > img = new ArrayImg<>( access, dim, new Fraction() );
379+
final NativeBoolType t = new NativeBoolType( img );
380+
img.setLinkedType( t );
381+
return img;
382+
}
383+
351384
/**
352385
* Create an {@link ArrayImg}&lt;{@link BitType}, {@link LongArray}&gt;.
353386
*/
@@ -357,6 +390,18 @@ final static public ArrayImg< BitType, LongArray > bits( final long... dim )
357390
return ( ArrayImg< BitType, LongArray > ) new ArrayImgFactory<>( new BitType() ).create( dim );
358391
}
359392

393+
/**
394+
* Creates an {@link ArrayImg}&lt;{@link NativeBoolType}, {@link LongAccess}&gt;
395+
* using a {@link LongAccess} passed as argument.
396+
*/
397+
final static public < A extends BooleanAccess > ArrayImg< NativeBoolType, A > bits( final A access, final long... dim )
398+
{
399+
final ArrayImg< NativeBoolType, A > img = new ArrayImg<>( access, dim, new Fraction( 1, 64 ) );
400+
final NativeBoolType t = new NativeBoolType( img );
401+
img.setLinkedType( t );
402+
return img;
403+
}
404+
360405
/**
361406
* Creates an {@link ArrayImg}&lt;{@link BitType}, {@link LongAccess}&gt;
362407
* using a {@link LongAccess} passed as argument.

src/main/java/net/imglib2/img/basictypeaccess/ArrayDataAccessFactory.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
import java.util.Set;
4040

4141
import net.imglib2.img.basictypeaccess.array.ArrayDataAccess;
42+
import net.imglib2.img.basictypeaccess.array.BooleanArray;
4243
import net.imglib2.img.basictypeaccess.array.ByteArray;
4344
import net.imglib2.img.basictypeaccess.array.CharArray;
45+
import net.imglib2.img.basictypeaccess.array.DirtyBooleanArray;
4446
import net.imglib2.img.basictypeaccess.array.DirtyByteArray;
4547
import net.imglib2.img.basictypeaccess.array.DirtyCharArray;
4648
import net.imglib2.img.basictypeaccess.array.DirtyDoubleArray;
@@ -53,13 +55,15 @@
5355
import net.imglib2.img.basictypeaccess.array.IntArray;
5456
import net.imglib2.img.basictypeaccess.array.LongArray;
5557
import net.imglib2.img.basictypeaccess.array.ShortArray;
58+
import net.imglib2.img.basictypeaccess.volatiles.array.DirtyVolatileBooleanArray;
5659
import net.imglib2.img.basictypeaccess.volatiles.array.DirtyVolatileByteArray;
5760
import net.imglib2.img.basictypeaccess.volatiles.array.DirtyVolatileCharArray;
5861
import net.imglib2.img.basictypeaccess.volatiles.array.DirtyVolatileDoubleArray;
5962
import net.imglib2.img.basictypeaccess.volatiles.array.DirtyVolatileFloatArray;
6063
import net.imglib2.img.basictypeaccess.volatiles.array.DirtyVolatileIntArray;
6164
import net.imglib2.img.basictypeaccess.volatiles.array.DirtyVolatileLongArray;
6265
import net.imglib2.img.basictypeaccess.volatiles.array.DirtyVolatileShortArray;
66+
import net.imglib2.img.basictypeaccess.volatiles.array.VolatileBooleanArray;
6367
import net.imglib2.img.basictypeaccess.volatiles.array.VolatileByteArray;
6468
import net.imglib2.img.basictypeaccess.volatiles.array.VolatileCharArray;
6569
import net.imglib2.img.basictypeaccess.volatiles.array.VolatileDoubleArray;
@@ -115,6 +119,14 @@ public static < A extends ArrayDataAccess< A > > A get(
115119
final boolean volatil = flags.contains( VOLATILE );
116120
switch ( primitiveType )
117121
{
122+
case BOOLEAN:
123+
return dirty
124+
? ( volatil
125+
? ( A ) new DirtyVolatileBooleanArray( 0, true )
126+
: ( A ) new DirtyBooleanArray( 0 ) )
127+
: ( volatil
128+
? ( A ) new VolatileBooleanArray( 0, true )
129+
: ( A ) new BooleanArray( 0 ) );
118130
case BYTE:
119131
return dirty
120132
? ( volatil
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* #%L
3+
* ImgLib2: a general-purpose, multidimensional image processing library.
4+
* %%
5+
* Copyright (C) 2009 - 2018 Tobias Pietzsch, Stephan Preibisch, Stephan Saalfeld,
6+
* John Bogovic, Albert Cardona, Barry DeZonia, Christian Dietz, Jan Funke,
7+
* Aivar Grislis, Jonathan Hale, Grant Harris, Stefan Helfrich, Mark Hiner,
8+
* Martin Horn, Steffen Jaensch, Lee Kamentsky, Larry Lindsey, Melissa Linkert,
9+
* Mark Longair, Brian Northan, Nick Perry, Curtis Rueden, Johannes Schindelin,
10+
* Jean-Yves Tinevez and Michael Zinsmaier.
11+
* %%
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright notice,
18+
* this list of conditions and the following disclaimer in the documentation
19+
* and/or other materials provided with the distribution.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
* #L%
33+
*/
34+
35+
package net.imglib2.img.basictypeaccess;
36+
37+
/**
38+
* TODO
39+
*
40+
* @author Curtis Rueden
41+
*/
42+
public interface BooleanAccess
43+
{
44+
public boolean getValue( final int index );
45+
46+
public void setValue( final int index, final boolean value );
47+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* #%L
3+
* ImgLib2: a general-purpose, multidimensional image processing library.
4+
* %%
5+
* Copyright (C) 2009 - 2018 Tobias Pietzsch, Stephan Preibisch, Stephan Saalfeld,
6+
* John Bogovic, Albert Cardona, Barry DeZonia, Christian Dietz, Jan Funke,
7+
* Aivar Grislis, Jonathan Hale, Grant Harris, Stefan Helfrich, Mark Hiner,
8+
* Martin Horn, Steffen Jaensch, Lee Kamentsky, Larry Lindsey, Melissa Linkert,
9+
* Mark Longair, Brian Northan, Nick Perry, Curtis Rueden, Johannes Schindelin,
10+
* Jean-Yves Tinevez and Michael Zinsmaier.
11+
* %%
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright notice,
18+
* this list of conditions and the following disclaimer in the documentation
19+
* and/or other materials provided with the distribution.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
* #L%
33+
*/
34+
35+
package net.imglib2.img.basictypeaccess.array;
36+
37+
import net.imglib2.img.basictypeaccess.BooleanAccess;
38+
39+
/**
40+
*
41+
* @author Curtis Rueden
42+
*/
43+
public abstract class AbstractBooleanArray< A extends AbstractBooleanArray< A > > implements BooleanAccess, ArrayDataAccess< A >
44+
{
45+
protected boolean[] data;
46+
47+
public AbstractBooleanArray( final int numEntities )
48+
{
49+
this.data = new boolean[ numEntities ];
50+
}
51+
52+
public AbstractBooleanArray( final boolean[] data )
53+
{
54+
this.data = data;
55+
}
56+
57+
@Override
58+
public boolean getValue( final int index )
59+
{
60+
return data[ index ];
61+
}
62+
63+
@Override
64+
public void setValue( final int index, final boolean value )
65+
{
66+
data[ index ] = value;
67+
}
68+
69+
@Override
70+
public boolean[] getCurrentStorageArray()
71+
{
72+
return data;
73+
}
74+
75+
@Override
76+
public int getArrayLength() {
77+
return data.length;
78+
}
79+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* #%L
3+
* ImgLib2: a general-purpose, multidimensional image processing library.
4+
* %%
5+
* Copyright (C) 2009 - 2018 Tobias Pietzsch, Stephan Preibisch, Stephan Saalfeld,
6+
* John Bogovic, Albert Cardona, Barry DeZonia, Christian Dietz, Jan Funke,
7+
* Aivar Grislis, Jonathan Hale, Grant Harris, Stefan Helfrich, Mark Hiner,
8+
* Martin Horn, Steffen Jaensch, Lee Kamentsky, Larry Lindsey, Melissa Linkert,
9+
* Mark Longair, Brian Northan, Nick Perry, Curtis Rueden, Johannes Schindelin,
10+
* Jean-Yves Tinevez and Michael Zinsmaier.
11+
* %%
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright notice,
18+
* this list of conditions and the following disclaimer in the documentation
19+
* and/or other materials provided with the distribution.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
* #L%
33+
*/
34+
35+
package net.imglib2.img.basictypeaccess.array;
36+
37+
/**
38+
*
39+
* @author Curtis Rueden
40+
*/
41+
public class BooleanArray extends AbstractBooleanArray< BooleanArray >
42+
{
43+
public BooleanArray( final int numEntities )
44+
{
45+
super( numEntities );
46+
}
47+
48+
public BooleanArray( final boolean[] data )
49+
{
50+
super( data );
51+
}
52+
53+
@Override
54+
public BooleanArray createArray( final int numEntities )
55+
{
56+
return new BooleanArray( numEntities );
57+
}
58+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* #%L
3+
* ImgLib2: a general-purpose, multidimensional image processing library.
4+
* %%
5+
* Copyright (C) 2009 - 2018 Tobias Pietzsch, Stephan Preibisch, Stephan Saalfeld,
6+
* John Bogovic, Albert Cardona, Barry DeZonia, Christian Dietz, Jan Funke,
7+
* Aivar Grislis, Jonathan Hale, Grant Harris, Stefan Helfrich, Mark Hiner,
8+
* Martin Horn, Steffen Jaensch, Lee Kamentsky, Larry Lindsey, Melissa Linkert,
9+
* Mark Longair, Brian Northan, Nick Perry, Curtis Rueden, Johannes Schindelin,
10+
* Jean-Yves Tinevez and Michael Zinsmaier.
11+
* %%
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright notice,
18+
* this list of conditions and the following disclaimer in the documentation
19+
* and/or other materials provided with the distribution.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
* #L%
33+
*/
34+
35+
package net.imglib2.img.basictypeaccess.array;
36+
37+
import net.imglib2.Dirty;
38+
39+
/**
40+
*
41+
* @author Curtis Rueden
42+
*/
43+
public class DirtyBooleanArray extends AbstractBooleanArray< DirtyBooleanArray > implements Dirty
44+
{
45+
protected boolean dirty = false;
46+
47+
public DirtyBooleanArray( final int numEntities )
48+
{
49+
super( numEntities );
50+
}
51+
52+
public DirtyBooleanArray( final boolean[] data )
53+
{
54+
super( data );
55+
}
56+
57+
@Override
58+
public void setValue( final int index, final boolean value )
59+
{
60+
dirty = true;
61+
data[ index ] = value;
62+
}
63+
64+
@Override
65+
public DirtyBooleanArray createArray( final int numEntities )
66+
{
67+
return new DirtyBooleanArray( numEntities );
68+
}
69+
70+
@Override
71+
public boolean isDirty()
72+
{
73+
return dirty;
74+
}
75+
76+
@Override
77+
public void setDirty()
78+
{
79+
dirty = true;
80+
}
81+
}

0 commit comments

Comments
 (0)