Commit 0a82f5fe authored by Jørgen Lind's avatar Jørgen Lind
Browse files

Merge branch wip/julien.lacoste/requestShortBuffer with refs/heads/master into...

Merge branch wip/julien.lacoste/requestShortBuffer with refs/heads/master into refs/merge-requests/472/train
parents d484897e 12ef9317
Pipeline #70075 passed with stages
in 19 minutes and 7 seconds
......@@ -240,6 +240,8 @@ public abstract class BufferUtils {
return outBuf.capacity() * Integer.BYTES;
else if (outBuf instanceof ByteBuffer)
return outBuf.capacity() * Byte.BYTES;
else if (outBuf instanceof ShortBuffer)
return outBuf.capacity() * Short.BYTES;
throw new IllegalArgumentException();
}
}
......@@ -323,6 +323,17 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion {
box.getMin(), box.getMax(), FORMAT_U32.getCode());
}
public long requestVolumeSubset(ShortBuffer outBuf,
DimensionsND dimensionsND, int lod, int channel,
NDBox box) {
B.checkDirectBuffer(outBuf);
if (B.getCapacityInBytes(outBuf) < getVolumeSubsetBufferSize(box, FORMAT_U16, lod, channel))
throwBufferTooSmallException();
return cpRequestVolumeSubset(_handle, outBuf, B.getCapacityInBytes(outBuf),
dimensionsND.ordinal(), lod, channel,
box.getMin(), box.getMax(), FORMAT_U16.getCode());
}
/**
* Request a subset of the input VDS.
*
......@@ -385,6 +396,18 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion {
box.getMin(), box.getMax(), FORMAT_U32.getCode(), replacementNoValue);
}
public long requestVolumeSubset(ShortBuffer outBuf,
DimensionsND dimensionsND, int lod, int channel,
NDBox box,
float replacementNoValue) {
B.checkDirectBuffer(outBuf);
if (B.getCapacityInBytes(outBuf) < getVolumeSubsetBufferSize(box, FORMAT_U16, lod, channel))
throwBufferTooSmallException();
return cpRequestVolumeSubsetR(_handle, outBuf, B.getCapacityInBytes(outBuf),
dimensionsND.ordinal(), lod, channel,
box.getMin(), box.getMax(), FORMAT_U16.getCode(), replacementNoValue);
}
/**
* Compute the buffer size (in bytes) for a projected volume subset request.
*
......
......@@ -23,6 +23,7 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.LinkedList;
import java.util.Random;
import java.util.concurrent.ExecutionException;
......@@ -669,6 +670,44 @@ public class MemoryVdsGeneratorTest {
assertTrue(generator.isNull());
}
@Test
void testVolumeSubsetRequestShort() throws IOException {
int nXSamples = 60, nYSamples = 60, nZSamples = 60;
VolumeDataChannelDescriptor.Format format = FORMAT_U16;
MemoryVdsGenerator generator = new MemoryVdsGenerator(nZSamples, nYSamples, nXSamples, format);
assertTrue(!generator.isNull());
assertTrue(generator.ownHandle());
final VolumeDataLayout layout = generator.getLayout();
assertTrue(!layout.isNull());
final VolumeDataAccessManager accessManager = generator.getAccessManager();
assertTrue(!accessManager.isNull());
NDBox box = new NDBox(0, 0, 0, 0, 0, 0, nZSamples, nYSamples, 1, 0, 0, 0);
final ShortBuffer shortBuffer1 = B.createShortBuffer(nZSamples * nYSamples);
final long requestSubsetId = accessManager.requestVolumeSubset(shortBuffer1, DimensionsND.DIMENSIONS_012, 0, 0, box);
accessManager.waitForCompletion(requestSubsetId);
final ShortBuffer shortBuffer0 = B.createShortBuffer(nZSamples * nYSamples);
final float channelNoValue = layout.getChannelNoValue(0);
final long requestID0 = accessManager.requestVolumeSubset(shortBuffer0, DimensionsND.DIMENSIONS_012, 0, 0,
box, channelNoValue);
accessManager.waitForCompletion(requestID0);
for (int i = 0; i < nZSamples * nYSamples; i++) {
final short f1 = shortBuffer0.get(i);
final short f2 = shortBuffer1.get(i);
assertEquals(0, Short.compare(f1, f2), " value " + i + " is different");
}
B.release(shortBuffer0, shortBuffer1);
generator.close();
assertTrue(generator.isNull());
}
@Test
void testSampleRequest() throws IOException {
int nXSamples = 60, nYSamples = 60, nZSamples = 60;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment