net.imglib2.img.basictypeaccess.array.ArrayDataAccess Java Examples

The following examples show how to use net.imglib2.img.basictypeaccess.array.ArrayDataAccess. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: N5Data.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * @param reader container
 * @param dataset dataset
 * @param transform transforms voxel data into real world coordinates
 * @param priority in fetching queue
 * @param <T> data type
 * @param <V> viewer type
 * @return image data with cache invalidation
 * @throws IOException if any N5 operation throws {@link IOException}
 */
@SuppressWarnings("unchecked")
public static <T extends NativeType<T>, V extends Volatile<T> & NativeType<V>, A extends ArrayDataAccess<A>>
ImagesWithTransform<T, V> openRaw(
		final N5Reader reader,
		final String dataset,
		final AffineTransform3D transform,
		final SharedQueue queue,
		final int priority /* TODO use priority, probably in wrapAsVolatile? */) throws IOException {

	try {
		final CachedCellImg<T, ?> raw = N5Utils.openVolatile(reader, dataset);
		final TmpVolatileHelpers.RaiWithInvalidate<V> vraw = TmpVolatileHelpers.createVolatileCachedCellImgWithInvalidate(
				(CachedCellImg) raw,
				queue,
				new CacheHints(LoadingStrategy.VOLATILE, priority, true));
		return new ImagesWithTransform<>(raw, vraw.getRai(), transform, raw.getCache(), vraw.getInvalidate());
	}
	catch (final Exception e)
	{
		throw e instanceof IOException ? (IOException) e : new IOException(e);
	}
}
 
Example #2
Source File: MathNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(ops = {
	net.imagej.ops.math.ConstantToPlanarImage.SubtractLong.class,
	net.imagej.ops.math.ConstantToPlanarImage.SubtractUnsignedLong.class })
public <N extends NativeType<N>, A extends ArrayDataAccess<A>> PlanarImg<N, A>
	subtract(final PlanarImg<N, A> image, final long value)
{
	@SuppressWarnings("unchecked")
	final PlanarImg<N, A> result = (PlanarImg<N, A>) ops().run(
		Ops.Math.Subtract.NAME, image, value);
	return result;
}
 
Example #3
Source File: SCIFIOCellImgFactory.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private <A extends ArrayDataAccess<A>> SCIFIOCellLoader<T, A>
	createCellLoader(final NativeTypeFactory<T, A> typeFactory)
{
	switch (typeFactory.getPrimitiveType()) {
		case BYTE:
			return new SCIFIOCellLoader(new ByteArrayLoader(reader, subregion),
				o -> new ByteArray((byte[]) o));
		case CHAR:
			return new SCIFIOCellLoader(new CharArrayLoader(reader, subregion),
				o -> new CharArray((char[]) o));
		case DOUBLE:
			return new SCIFIOCellLoader(new DoubleArrayLoader(reader, subregion),
				o -> new DoubleArray((double[]) o));
		case FLOAT:
			return new SCIFIOCellLoader(new FloatArrayLoader(reader, subregion),
				o -> new FloatArray((float[]) o));
		case INT:
			return new SCIFIOCellLoader(new IntArrayLoader(reader, subregion),
				o -> new IntArray((int[]) o));
		case LONG:
			return new SCIFIOCellLoader(new LongArrayLoader(reader, subregion),
				o -> new LongArray((long[]) o));
		case SHORT:
			return new SCIFIOCellLoader(new ShortArrayLoader(reader, subregion),
				o -> new ShortArray((short[]) o));
		default:
			throw new IllegalArgumentException();
	}
}
 
Example #4
Source File: DefaultImgUtilityService.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Obtains planar access instance backing the given img, if any. */
@Override
@SuppressWarnings("unchecked")
public PlanarAccess<ArrayDataAccess<?>> getPlanarAccess(
	final ImgPlus<?> img)
{
	if (img.getImg() instanceof PlanarAccess) {
		return (PlanarAccess<ArrayDataAccess<?>>) img.getImg();
	}
	return null;
}
 
Example #5
Source File: ImgUtilityService.java    From scifio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Obtains planar access instance backing the given img, if any. */
PlanarAccess<ArrayDataAccess<?>> getPlanarAccess(final ImgPlus<?> img);
 
Example #6
Source File: ImgUtilityService.java    From scifio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Wraps raw primitive array in ImgLib2 Array object. */
ArrayDataAccess<?> makeArray(final Object array);
 
Example #7
Source File: SCIFIOCellImgFactory.java    From scifio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private <A extends ArrayDataAccess<A>> SCIFIOCellImg<T, ? extends A> create(
	final long[] dimensions, final T type,
	final NativeTypeFactory<T, A> typeFactory)
{
	final SCIFIOCellLoader<T, A> cellLoader = createCellLoader(typeFactory);
	cellLoader.loader.setIndex(index);

	final DiskCachedCellImgOptions.Values options = factoryOptions.values;

	final Fraction entitiesPerPixel = type.getEntitiesPerPixel();

	final CellGrid grid = createCellGrid(dimensions, entitiesPerPixel);

	final CellLoader<T> actualCellLoader = options.initializeCellsAsDirty()
		? cell -> {
			cellLoader.load(cell);
			cell.setDirty();
		} : cellLoader;
	final CacheLoader<Long, Cell<A>> backingLoader = LoadedCellCacheLoader.get(
		grid, actualCellLoader, type, options.accessFlags());

	final Path blockcache = createBlockCachePath(options);

	@SuppressWarnings({ "rawtypes", "unchecked" })
	final DiskCellCache<A> diskcache = options.dirtyAccesses()
		? new DirtyDiskCellCache(blockcache, grid, backingLoader, AccessIo.get(
			type, options.accessFlags()), entitiesPerPixel) : new DiskCellCache<>(
				blockcache, grid, backingLoader, AccessIo.get(type, options
					.accessFlags()), entitiesPerPixel);

	final IoSync<Long, Cell<A>, A> iosync = new IoSync<>(diskcache, options
		.numIoThreads(), options.maxIoQueueSize());

	LoaderRemoverCache<Long, Cell<A>, A> listenableCache;
	switch (options.cacheType()) {
		case BOUNDED:
			listenableCache = new GuardedStrongRefLoaderRemoverCache<>(options
				.maxCacheSize());
			break;
		case SOFTREF:
		default:
			listenableCache = new SoftRefLoaderRemoverCache<>();
			break;
	}

	final Cache<Long, Cell<A>> cache = listenableCache.withRemover(iosync)
		.withLoader(iosync);

	final A accessType = ArrayDataAccessFactory.get(typeFactory, options
		.accessFlags());
	final SCIFIOCellImg<T, ? extends A> img = new SCIFIOCellImg<>(this, grid,
		entitiesPerPixel, cache, accessType, iosync);
	img.setLinkedType(typeFactory.createLinkedType(img));
	return img;
}