Skip to content

Commit

Permalink
keep improving javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 12, 2023
1 parent c341b20 commit 4b811e2
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.integer.ByteType;
import net.imglib2.type.numeric.integer.IntType;
import net.imglib2.type.numeric.integer.LongType;
import net.imglib2.type.numeric.integer.ShortType;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedIntType;
import net.imglib2.type.numeric.integer.UnsignedShortType;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.type.numeric.real.FloatType;

/**
* Interface to interact with shared memory segments retrieving the underlying information
Expand Down Expand Up @@ -266,6 +275,33 @@ static String createShmName() {
else return ("/shm-" + UUID.randomUUID()).substring(0, SharedMemoryArrayMacOS.MACOS_MAX_LENGTH);
}

/**
* Get the number of bytes that is required to store the data in an nd array of a certain data type
* @param <T>
* possible ImgLib2 data types of the provided {@link RandomAccessibleInterval}
* @param shape
* shape of the array
* @param type
* ImgLib2 data type of the array
* @return the number of bytes needed to store the nd array
*/
public static <T extends RealType<T> & NativeType<T>> int getArrayByteSize(long[] shape, T type) {
int noByteSize = 1;
for (long l : shape) {noByteSize *= l;}
if (type instanceof ByteType || type instanceof UnsignedByteType) {
return noByteSize * 1;
} else if (type instanceof ShortType || type instanceof UnsignedShortType) {
return noByteSize * 2;
} else if (type instanceof IntType || type instanceof UnsignedIntType
|| type instanceof FloatType) {
return noByteSize * 4;
} else if (type instanceof LongType || type instanceof DoubleType) {
return noByteSize * 8;
} else {
throw new IllegalArgumentException("Type not supported: " + type.getClass().toString());
}
}

/**
*
* @return the unique name for the shared memory, specified as a string. When creating a new shared memory bloc.k instance
Expand Down
Loading

0 comments on commit 4b811e2

Please sign in to comment.