All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.imglib2.img.unsafe.UnsafeImgs Maven / Gradle / Ivy

The newest version!
/*
 * #%L
 * ImgLib2 data structures using Unsafe.
 * %%
 * Copyright (C) 2017 - 2024 Howard Hughes Medical Institute.
 * %%
 * 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.img.unsafe;

import net.imglib2.img.basictypeaccess.array.ByteArray;
import net.imglib2.img.basictypeaccess.array.DoubleArray;
import net.imglib2.img.basictypeaccess.array.FloatArray;
import net.imglib2.img.basictypeaccess.array.IntArray;
import net.imglib2.img.basictypeaccess.array.LongArray;
import net.imglib2.img.basictypeaccess.array.ShortArray;
import net.imglib2.img.basictypelongaccess.ByteLongAccess;
import net.imglib2.img.basictypelongaccess.DoubleLongAccess;
import net.imglib2.img.basictypelongaccess.FloatLongAccess;
import net.imglib2.img.basictypelongaccess.IntLongAccess;
import net.imglib2.img.basictypelongaccess.LongLongAccess;
import net.imglib2.img.basictypelongaccess.ShortLongAccess;
import net.imglib2.img.basictypelongaccess.unsafe.DoubleUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.FloatUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.owning.OwningByteUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.owning.OwningDoubleUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.owning.OwningFloatUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.owning.OwningIntUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.owning.OwningLongUnsafe;
import net.imglib2.img.basictypelongaccess.unsafe.owning.OwningShortUnsafe;
import net.imglib2.type.Type;
import net.imglib2.type.numeric.ARGBLongAccessType;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.complex.ComplexDoubleLongAccessType;
import net.imglib2.type.numeric.complex.ComplexDoubleType;
import net.imglib2.type.numeric.complex.ComplexFloatLongAccessType;
import net.imglib2.type.numeric.complex.ComplexFloatType;
import net.imglib2.type.numeric.integer.ByteLongAccessType;
import net.imglib2.type.numeric.integer.IntLongAccessType;
import net.imglib2.type.numeric.integer.IntType;
import net.imglib2.type.numeric.integer.LongLongAccessType;
import net.imglib2.type.numeric.integer.LongType;
import net.imglib2.type.numeric.integer.ShortLongAccessType;
import net.imglib2.type.numeric.integer.ShortType;
import net.imglib2.type.numeric.integer.UnsignedByteLongAccessType;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedIntLongAccessType;
import net.imglib2.type.numeric.integer.UnsignedIntType;
import net.imglib2.type.numeric.integer.UnsignedLongLongAccessType;
import net.imglib2.type.numeric.integer.UnsignedShortLongAccessType;
import net.imglib2.type.numeric.integer.UnsignedShortType;
import net.imglib2.type.numeric.real.DoubleLongAccessType;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.type.numeric.real.FloatLongAccessType;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Fraction;

/**
 * 

* Convenience factory methods for creation of {@link UnsafeImg} instances with * the most common pixel {@link Type} variants. The collection includes * factories to re-use existing primitive type arrays as data. This can be used * for in-place access to data from other libraries such as AWT or ImageJ. Keep * in mind that this cannot be a complete collection since the number of * existing pixel {@link Type}s may be extended. *

* *

* For pixel {@link Type}s T not present in this collection, use the generic * {@link UnsafeImgFactory#create(long[], net.imglib2.type.NativeLongAccessType)}, e.g. *

* *
 * img = new ArrayImgFactory< MyType >.create( new long[] { 100, 200 }, new MyType() );
 * 
* * @author Stephan Saalfeld */ final public class UnsafeImgs { private UnsafeImgs() {} /** * Create an {@link UnsafeImg}<{@link UnsignedByteType}, {@link ByteArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< UnsignedByteLongAccessType, OwningByteUnsafe > unsignedBytes( final long... dim ) { return ( UnsafeImg< UnsignedByteLongAccessType, OwningByteUnsafe > ) new UnsafeImgFactory< UnsignedByteLongAccessType >().create( dim, new UnsignedByteLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link UnsignedByteType}, {@link ByteArray}> * reusing a passed {@link ByteLongAccess}. */ final public static UnsafeImg< UnsignedByteLongAccessType, ByteLongAccess > unsignedBytes( final ByteLongAccess access, final long... dim ) { final UnsafeImg< UnsignedByteLongAccessType, ByteLongAccess > img = new UnsafeImg<>( access, dim, new Fraction() ); final UnsignedByteLongAccessType t = new UnsignedByteLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link ByteLongAccessType}, * {@link ByteArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< ByteLongAccessType, OwningByteUnsafe > bytes( final long... dim ) { return ( UnsafeImg< ByteLongAccessType, OwningByteUnsafe > ) new UnsafeImgFactory< ByteLongAccessType >().create( dim, new ByteLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link ByteLongAccessType}, * {@link ByteArray}> reusing a passed {@link ByteLongAccess}. */ final public static UnsafeImg< ByteLongAccessType, ByteLongAccess > bytes( final ByteLongAccess access, final long... dim ) { final UnsafeImg< ByteLongAccessType, ByteLongAccess > img = new UnsafeImg<>( access, dim, new Fraction() ); final ByteLongAccessType t = new ByteLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link UnsignedShortType}, * {@link ShortArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< UnsignedShortLongAccessType, OwningShortUnsafe > unsignedShorts( final long... dim ) { return ( UnsafeImg< UnsignedShortLongAccessType, OwningShortUnsafe > ) new UnsafeImgFactory< UnsignedShortLongAccessType >().create( dim, new UnsignedShortLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link UnsignedShortType}, * {@link ShortArray}> reusing a passed {@link ShortLongAccess}. */ final public static UnsafeImg< UnsignedShortLongAccessType, ShortLongAccess > unsignedShorts( final ShortLongAccess access, final long... dim ) { final UnsafeImg< UnsignedShortLongAccessType, ShortLongAccess > img = new UnsafeImg<>( access, dim, new Fraction() ); final UnsignedShortLongAccessType t = new UnsignedShortLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link ShortType}, {@link ShortArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< ShortLongAccessType, OwningShortUnsafe > shorts( final long... dim ) { return ( UnsafeImg< ShortLongAccessType, OwningShortUnsafe > ) new UnsafeImgFactory< ShortLongAccessType >().create( dim, new ShortLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link ShortType}, {@link ShortArray}> * reusing a passed {@link ShortLongAccess}. */ final public static UnsafeImg< ShortLongAccessType, ShortLongAccess > shorts( final ShortLongAccess access, final long... dim ) { final UnsafeImg< ShortLongAccessType, ShortLongAccess > img = new UnsafeImg<>( access, dim, new Fraction() ); final ShortLongAccessType t = new ShortLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link UnsignedIntType}, {@link IntArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< UnsignedIntLongAccessType, OwningIntUnsafe > unsignedInts( final long... dim ) { return ( UnsafeImg< UnsignedIntLongAccessType, OwningIntUnsafe > ) new UnsafeImgFactory< UnsignedIntLongAccessType >().create( dim, new UnsignedIntLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link UnsignedIntType}, {@link IntArray}> * reusing a passed {@link IntLongAccess}. */ final public static UnsafeImg< UnsignedIntLongAccessType, IntLongAccess > unsignedInts( final IntLongAccess access, final long... dim ) { final UnsafeImg< UnsignedIntLongAccessType, IntLongAccess > img = new UnsafeImg<>( access, dim, new Fraction() ); final UnsignedIntLongAccessType t = new UnsignedIntLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link IntType}, {@link IntArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< IntLongAccessType, IntArray > ints( final long... dim ) { return ( UnsafeImg< IntLongAccessType, IntArray > ) new UnsafeImgFactory< IntLongAccessType >().create( dim, new IntLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link IntType}, {@link IntArray}> reusing a * passed {@link IntLongAccess}. */ final public static UnsafeImg< IntLongAccessType, IntLongAccess > ints( final IntLongAccess access, final long... dim ) { final UnsafeImg< IntLongAccessType, IntLongAccess > img = new UnsafeImg<>( access, dim, new Fraction() ); final IntLongAccessType t = new IntLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link LongType}, {@link LongArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< UnsignedLongLongAccessType, OwningLongUnsafe > unsignedLongs( final long... dim ) { return ( UnsafeImg< UnsignedLongLongAccessType, OwningLongUnsafe > ) new UnsafeImgFactory< UnsignedLongLongAccessType >().create( dim, new UnsignedLongLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link LongType}, {@link LongArray}> reusing * a passed {@link LongLongAccess}. */ final public static UnsafeImg< UnsignedLongLongAccessType, LongLongAccess > unsignedLongs( final LongLongAccess access, final long... dim ) { final UnsafeImg< UnsignedLongLongAccessType, LongLongAccess > img = new UnsafeImg<>( access, dim, new Fraction() ); final UnsignedLongLongAccessType t = new UnsignedLongLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link LongType}, {@link LongArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< LongLongAccessType, OwningLongUnsafe > longs( final long... dim ) { return ( UnsafeImg< LongLongAccessType, OwningLongUnsafe > ) new UnsafeImgFactory< LongLongAccessType >().create( dim, new LongLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link LongType}, {@link LongArray}> reusing * a passed {@link LongLongAccess}. */ final public static UnsafeImg< LongLongAccessType, LongLongAccess > longs( final LongLongAccess access, final long... dim ) { final UnsafeImg< LongLongAccessType, LongLongAccess > img = new UnsafeImg<>( access, dim, new Fraction() ); final LongLongAccessType t = new LongLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link FloatType}, {@link FloatArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< FloatLongAccessType, OwningFloatUnsafe > floats( final long... dim ) { return ( UnsafeImg< FloatLongAccessType, OwningFloatUnsafe > ) new UnsafeImgFactory< FloatLongAccessType >().create( dim, new FloatLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link FloatType}, {@link FloatArray}> * reusing a passed {@link FloatUnsafe}. */ final public static UnsafeImg< FloatLongAccessType, FloatUnsafe > floats( final FloatUnsafe access, final long... dim ) { final UnsafeImg< FloatLongAccessType, FloatUnsafe > img = new UnsafeImg<>( access, dim, new Fraction() ); final FloatLongAccessType t = new FloatLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link DoubleType}, {@link DoubleArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< DoubleLongAccessType, OwningDoubleUnsafe > doubles( final long... dim ) { return ( UnsafeImg< DoubleLongAccessType, OwningDoubleUnsafe > ) new UnsafeImgFactory< DoubleLongAccessType >().create( dim, new DoubleLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link DoubleType}, {@link DoubleArray}> * reusing a passed {@link DoubleUnsafe}. */ final public static UnsafeImg< DoubleLongAccessType, DoubleUnsafe > doubles( final DoubleUnsafe access, final long... dim ) { final UnsafeImg< DoubleLongAccessType, DoubleUnsafe > img = new UnsafeImg<>( access, dim, new Fraction() ); final DoubleLongAccessType t = new DoubleLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link ARGBType}, {@link IntArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< ARGBLongAccessType, OwningIntUnsafe > argbs( final long... dim ) { return ( UnsafeImg< ARGBLongAccessType, OwningIntUnsafe > ) new UnsafeImgFactory< ARGBLongAccessType >().create( dim, new ARGBLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link ARGBLongAccessType}, {@link IntLongAccess}> reusing * a passed {@link IntLongAccess}. */ final public static UnsafeImg< ARGBLongAccessType, IntLongAccess > argbs( final IntLongAccess access, final long... dim ) { final UnsafeImg< ARGBLongAccessType, IntLongAccess > img = new UnsafeImg<>( access, dim, new Fraction() ); System.out.println( "DEBUG 1 " + ( img == null ) ); final ARGBLongAccessType t = new ARGBLongAccessType( img ); System.out.println( "DEBUG 2 " + ( t == null ) ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link ComplexFloatType}, * {@link FloatArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< ComplexFloatLongAccessType, FloatLongAccess > complexFloats( final long... dim ) { return ( UnsafeImg< ComplexFloatLongAccessType, FloatLongAccess > ) new UnsafeImgFactory< ComplexFloatLongAccessType >().create( dim, new ComplexFloatLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link FloatType}, {@link FloatArray}> * reusing a passed float[] array. */ final public static UnsafeImg< ComplexFloatLongAccessType, FloatLongAccess > complexFloats( final FloatLongAccess access, final long... dim ) { final UnsafeImg< ComplexFloatLongAccessType, FloatLongAccess > img = new UnsafeImg<>( access, dim, new Fraction( 2, 1 ) ); final ComplexFloatLongAccessType t = new ComplexFloatLongAccessType( img ); img.setLinkedType( t ); return img; } /** * Create an {@link UnsafeImg}<{@link ComplexDoubleType}, * {@link DoubleArray}>. */ @SuppressWarnings( "unchecked" ) final static public UnsafeImg< ComplexDoubleLongAccessType, DoubleLongAccess > complexDoubles( final long... dim ) { return ( UnsafeImg< ComplexDoubleLongAccessType, DoubleLongAccess > ) new UnsafeImgFactory< ComplexDoubleLongAccessType >().create( dim, new ComplexDoubleLongAccessType() ); } /** * Creates an {@link UnsafeImg}<{@link DoubleType}, {@link DoubleArray}> * reusing a passed double[] array. */ final public static UnsafeImg< ComplexDoubleLongAccessType, DoubleLongAccess > complexDoubles( final DoubleLongAccess access, final long... dim ) { final UnsafeImg< ComplexDoubleLongAccessType, DoubleLongAccess > img = new UnsafeImg<>( access, dim, new Fraction( 2, 1 ) ); final ComplexDoubleLongAccessType t = new ComplexDoubleLongAccessType( img ); img.setLinkedType( t ); return img; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy