2323import static net .imglib2 .algorithm .math .ImgMath .OR ;
2424import static net .imglib2 .algorithm .math .ImgMath .XOR ;
2525import static net .imglib2 .algorithm .math .ImgMath .NOT ;
26+ import static net .imglib2 .algorithm .math .ImgMath .block ;
27+ import static net .imglib2 .algorithm .math .ImgMath .gen ;
2628
2729
2830import static org .junit .Assert .assertTrue ;
3638import java .nio .ByteBuffer ;
3739import java .nio .channels .Channels ;
3840import java .nio .channels .ReadableByteChannel ;
41+ import java .util .ArrayList ;
3942
4043import javax .imageio .ImageIO ;
4144
4245import org .junit .Test ;
4346
4447import net .imglib2 .Cursor ;
4548import net .imglib2 .IterableInterval ;
49+ import net .imglib2 .KDTree ;
50+ import net .imglib2 .Point ;
4651import net .imglib2 .RandomAccess ;
4752import net .imglib2 .RandomAccessibleInterval ;
53+ import net .imglib2 .algorithm .integral .IntegralImg ;
4854import net .imglib2 .algorithm .math .abstractions .IFunction ;
4955import net .imglib2 .algorithm .math .abstractions .Util ;
56+ import net .imglib2 .converter .Converter ;
5057import net .imglib2 .converter .Converters ;
5158import net .imglib2 .img .Img ;
5259import net .imglib2 .img .array .ArrayImg ;
5966import net .imglib2 .type .numeric .RealType ;
6067import net .imglib2 .type .numeric .integer .LongType ;
6168import net .imglib2 .type .numeric .integer .UnsignedByteType ;
69+ import net .imglib2 .type .numeric .integer .UnsignedLongType ;
6270import net .imglib2 .type .numeric .integer .UnsignedShortType ;
6371import net .imglib2 .type .numeric .real .DoubleType ;
6472import net .imglib2 .type .numeric .real .FloatType ;
@@ -803,6 +811,7 @@ static private final < T extends RealType< T > > boolean same( final Img< T > im
803811 return true ;
804812 }
805813
814+ @ SuppressWarnings ("unchecked" )
806815 @ Test
807816 public void test10Logical () {
808817 System .out .println ("test10Logical" );
@@ -833,16 +842,16 @@ public void test10Logical() {
833842 img4 = into4x4Img ( pixels4 );
834843
835844 // AND
836- assertTrue ( same ( img1 , (Img < UnsignedByteType >) compute (AND (img1 , img2 )).intoArrayImg () ) );
845+ assertTrue ( same ( img1 , ( Img < UnsignedByteType > ) compute (AND (img1 , img2 )).intoArrayImg () ) );
837846 // OR
838- assertTrue ( same ( img2 , (Img < UnsignedByteType >) compute (OR (img1 , img2 )).intoArrayImg () ) );
847+ assertTrue ( same ( img2 , ( Img < UnsignedByteType > ) compute (OR (img1 , img2 )).intoArrayImg () ) );
839848 // XOR
840- assertTrue ( same ( img3 , (Img < UnsignedByteType >) compute (XOR (img1 , img2 )).intoArrayImg () ) );
849+ assertTrue ( same ( img3 , ( Img < UnsignedByteType > ) compute (XOR (img1 , img2 )).intoArrayImg () ) );
841850 // NOT
842- assertTrue ( same ( img4 , (Img < UnsignedByteType >) compute (NOT (img1 )).intoArrayImg () ) );
851+ assertTrue ( same ( img4 , ( Img < UnsignedByteType > ) compute (NOT (img1 )).intoArrayImg () ) );
843852
844853 // Test LogicalAndBoolean
845- final Img < UnsignedByteType > imgIFAND = (Img < UnsignedByteType >) compute (IF (AND (LT (img1 , 1 ), LT (img2 , 1 )),
854+ final Img < UnsignedByteType > imgIFAND = ( Img < UnsignedByteType > ) compute (IF (AND (LT (img1 , 1 ), LT (img2 , 1 )),
846855 THEN (1 ),
847856 ELSE (0 ))).intoArrayImg ();
848857
@@ -853,6 +862,49 @@ public void test10Logical() {
853862 assertTrue ( same (imgTEST , imgIFAND ) );
854863 }
855864
865+ @ Test
866+ public void test11IntegralBlockReading () {
867+ System .out .println ("test11IntegralBlockReading" );
868+ final Img < UnsignedByteType > img = ArrayImgs .unsignedBytes ( 3 , 3 );
869+ for ( final UnsignedByteType t : img )
870+ t .setOne ();
871+ final IntegralImg < UnsignedByteType , UnsignedLongType > ii = new IntegralImg < UnsignedByteType , UnsignedLongType >( img , new UnsignedLongType (),
872+ new Converter < UnsignedByteType , UnsignedLongType >() {
873+ @ Override
874+ public void convert ( final UnsignedByteType input , final UnsignedLongType output ) {
875+ output .setInteger ( input .getIntegerLong () );
876+ }
877+ });
878+ ii .process ();
879+ final Img < UnsignedLongType > integralImg = ii .getResult ();
880+ final RandomAccessibleInterval < UnsignedLongType > view = block ( Views .extendBorder ( integralImg ), 3 ).view ( new UnsignedLongType () );
881+ final RandomAccess < UnsignedLongType > ra = view .randomAccess ();
882+ ra .setPosition ( new long []{ 1 , 1 } );
883+ assertTrue ( 9 == ra .get ().get () );
884+ }
885+
886+ @ Test
887+ public void test12KDTreeGen ()
888+ {
889+ System .out .println ("test12KDTreeGen" );
890+ final ArrayList < UnsignedByteType > values = new ArrayList <>();
891+ values .add ( new UnsignedByteType ( 1 ) );
892+ values .add ( new UnsignedByteType ( 2 ) );
893+ final ArrayList < Point > positions = new ArrayList <>();
894+ positions .add ( Point .wrap ( new long []{ 25 , 25 } ) );
895+ positions .add ( Point .wrap ( new long []{ 200 , 400 } ) );
896+ final KDTree < UnsignedByteType > kdtree = new KDTree <>( values , positions );
897+ final RandomAccess < UnsignedByteType > ra = gen ( kdtree , 5 ).view ( new UnsignedByteType () ).randomAccess ();
898+ ra .setPosition ( new long []{ 20 , 20 } );
899+ assertTrue ( 0 == ra .get ().get () );
900+ ra .setPosition ( new long []{ 23 , 29 } );
901+ assertTrue ( 1 == ra .get ().get () );
902+ ra .setPosition ( new long []{ 200 , 400 } );
903+ assertTrue ( 2 == ra .get ().get () );
904+ ra .setPosition ( new long []{ -200 , -400 } );
905+ assertTrue ( 0 == ra .get ().get () );
906+ }
907+
856908 static public void main (String [] args ) {
857909 new ImgMathTest ().test1 ();
858910 }
0 commit comments