Skip to content

Commit

Permalink
code cleaness
Browse files Browse the repository at this point in the history
  • Loading branch information
StRigaud committed Oct 17, 2024
1 parent 69cd9aa commit 627c11c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 50 deletions.
62 changes: 12 additions & 50 deletions src/main/java/net/clesperanto/CLIJ3.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ImagePlus pull(Object image) {
return convert(image, ImagePlus.class);
}

public RandomAccessibleInterval pullRAI(Object image) {
public RandomAccessibleInterval<?> pullRAI(Object image) {
return convert(image, RandomAccessibleInterval.class);
}

Expand All @@ -64,13 +64,11 @@ public <S, T> T convert(S source, Class<T> targetClass) {
synchronized (this) {
// if source is an ImagePlus and targetClass is ArrayJ
if (source instanceof ImagePlus && targetClass == ArrayJ.class) {

return (T) ImageJConverters.copyImagePlus2ToArrayJ((ImagePlus) source, device, MemoryType.BUFFER);
}
// if source is an ImgLib2 Img<> and targetClass is ArrayJ
if (source instanceof RandomAccessibleInterval && targetClass == ArrayJ.class) {
return (T) ImgLib2Converters.copyImgLib2ToArrayJ((RandomAccessibleInterval) source, device,
MemoryType.BUFFER);
return (T) ImgLib2Converters.copyImgLib2ToArrayJ((RandomAccessibleInterval) source, device, MemoryType.BUFFER);
}
// if source is an ArrayJ and targetClass is ImagePlus
if (source instanceof ArrayJ && targetClass == ImagePlus.class) {
Expand All @@ -86,89 +84,53 @@ public <S, T> T convert(S source, Class<T> targetClass) {
}

public void imshow(Object gpu_image) {
ImagePlus image = pull(gpu_image);
ImagePlus image = this.pull(gpu_image);
image.resetDisplayRange();
image.show();
}

public ArrayJ create(long width, long height, long depth) {
return device.createArray(DataType.FLOAT32, MemoryType.BUFFER,
new long[] { width, height, depth });
// return MemoryJ.makeFloatBuffer(this.device, new long[] { width, height, depth
// }, "buffer");
return device.createArray(DataType.FLOAT32, MemoryType.BUFFER, new long[] { width, height, depth });
}

public ArrayJ create(long width, long height, long depth, String data_type) {
switch (data_type) {
case "float":
return device.createArray(DataType.FLOAT32, MemoryType.BUFFER, new long[] { width, height, depth });
// return MemoryJ.makeFloatBuffer(this.device, new long[] { width, height, depth
// }, "buffer");
case "int":
return device.createArray(DataType.INT32, MemoryType.BUFFER, new long[] { width, height, depth });
// return MemoryJ.makeIntBuffer(this.device, new long[] { width, height, depth
// }, "buffer");
case "short":
return device.createArray(DataType.INT16, MemoryType.BUFFER, new long[] { width, height, depth });
// return MemoryJ.makeShortBuffer(this.device, new long[] { width, height, depth
// }, "buffer");
case "char":
return device.createArray(DataType.INT8, MemoryType.BUFFER, new long[] { width, height, depth });
// return MemoryJ.makeByteBuffer(this.device, new long[] { width, height, depth
// }, "buffer");
case "uint":
return device.createArray(DataType.UINT32, MemoryType.BUFFER, new long[] { width, height, depth });
// return MemoryJ.makeUIntBuffer(this.device, new long[] { width, height, depth
// }, "buffer");
case "ushort":
return device.createArray(DataType.UINT16, MemoryType.BUFFER, new long[] { width, height, depth });
// return MemoryJ.makeUShortBuffer(this.device, new long[] { width, height,
// depth }, "buffer");
case "uchar":
return device.createArray(DataType.UINT8, MemoryType.BUFFER, new long[] { width, height, depth });
// return MemoryJ.makeUByteBuffer(this.device, new long[] { width, height, depth
// }, "buffer");
default:
throw new IllegalArgumentException("Data type " + data_type + " not supported.");
}
}

public ArrayJ create_like(ArrayJ source) {
// source.dataType()
DataType data_type = source.dataType();
switch (data_type) {
case FLOAT32:
return device.createArray(data_type, source.memoryType(),
new long[] { source.width(), source.height(), source.depth() });
// return MemoryJ.makeFloatBuffer(this.device, source.getDimensions(),
// "buffer");
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(), source.depth() });
case INT32:
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(),
source.depth() });
// return MemoryJ.makeIntBuffer(this.device, source.getDimensions(), "buffer");
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(), source.depth() });
case INT16:
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(),
source.depth() });
// return MemoryJ.makeShortBuffer(this.device, source.getDimensions(),
// "buffer");
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(), source.depth() });
case INT8:
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(),
source.depth() });
// return MemoryJ.makeByteBuffer(this.device, source.getDimensions(), "buffer");
case UINT32:
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(),
source.depth() });
// return MemoryJ.makeUIntBuffer(this.device, source.getDimensions(), "buffer");
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(), source.depth() });
case UINT32:
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(), source.depth() });
case UINT16:
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(),
source.depth() });
// return MemoryJ.makeUShortBuffer(this.device, source.getDimensions(),
// "buffer");
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(), source.depth() });
case UINT8:
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(),
source.depth() });
// return MemoryJ.makeUByteBuffer(this.device, source.getDimensions(),
// "buffer");
return device.createArray(data_type, source.memoryType(), new long[] { source.width(), source.height(), source.depth() });
default:
throw new IllegalArgumentException("Data type " + data_type + " not supported.");
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/clesperanto/test/YetAnotherPlayground.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,19 @@ public static void main(String[] args) {
ArrayJ labels = cle.connected_components_labeling(binary, null, "box");

cle.imshow(labels);
ImagePlus result = cle.pull(labels);

// now print information about the result in ImageJ console
IJ.log("ImagePlus object: " + result);
IJ.log("Image dimensions: " + result.getWidth() + "x" + result.getHeight() + "x" + result.getNSlices());
IJ.log("Image type: " + result.getType());
IJ.log("Image title: " + result.getTitle());


// now print information about the result in ImageJ console
IJ.log("ArrayJ object: " + labels);
IJ.log("ArrayJ dimensions: " + labels.width() + "x" + labels.height() + "x" + labels.depth());
IJ.log("ArrayJ type: " + labels.dataType());

}
}

0 comments on commit 627c11c

Please sign in to comment.