Commit e47910d8 authored by Morten Ofstad's avatar Morten Ofstad
Browse files

Added GetVolumeSubsetBufferSize() API to calculate required size of a buffer...

Added GetVolumeSubsetBufferSize() API to calculate required size of a buffer for a call to RequestVolumeSubset.
parent de060b4a
......@@ -163,6 +163,29 @@ public:
virtual VolumeDataReadAccessor<FloatVector4, float > *Create4DInterpolatingVolumeDataAccessorR32(VolumeDataPageAccessor* volumeDataPageAccessor, float replacementNoValue, InterpolationMethod interpolationMethod) = 0;
virtual VolumeDataReadAccessor<FloatVector4, double> *Create4DInterpolatingVolumeDataAccessorR64(VolumeDataPageAccessor* volumeDataPageAccessor, float replacementNoValue, InterpolationMethod interpolationMethod) = 0;
/// <summary>
/// Compute the buffer size for a volume subset request.
/// </summary>
/// <param name="pVolumeDataLayout">
/// The VolumeDataLayout object associated with the input VDS.
/// </param>
/// <param name="MinVoxelCoordinates">
/// The minimum voxel coordinates to request in each dimension (inclusive).
/// </param>
/// <param name="MaxVoxelCoordinates">
/// The maximum voxel coordinates to request in each dimension (exclusive).
/// </param>
/// <param name="eFormat">
/// Voxel format the final buffer should be in.
/// </param>
/// <param name="lod">
/// The lod level the requested data is read from.
/// </param>
/// <returns>
/// The buffer size needed
/// </returns>
virtual int64_t GetVolumeSubsetBufferSize(VolumeDataLayout const *volumeDataLayout, const int (&minVoxelCoordinates)[Dimensionality_Max], const int (&maxVoxelCoordinates)[Dimensionality_Max], VolumeDataChannelDescriptor::Format format, int lod = 0) = 0;
/// <summary>
/// Request a subset of the input VDS.
/// </summary>
......
......@@ -215,6 +215,7 @@ public:
VolumeDataReadAccessor<FloatVector4, float > *Create4DInterpolatingVolumeDataAccessorR32(VolumeDataPageAccessor* volumeDataPageAccessor, float replacementNoValue, InterpolationMethod interpolationMethod) override;
VolumeDataReadAccessor<FloatVector4, double> *Create4DInterpolatingVolumeDataAccessorR64(VolumeDataPageAccessor* volumeDataPageAccessor, float replacementNoValue, InterpolationMethod interpolationMethod) override;
int64_t GetVolumeSubsetBufferSize(VolumeDataLayout const *volumeDataLayout, const int (&minVoxelCoordinates)[Dimensionality_Max], const int (&maxVoxelCoordinates)[Dimensionality_Max], VolumeDataChannelDescriptor::Format format, int lod);
int64_t RequestVolumeSubset(void *buffer, VolumeDataLayout const *volumeDataLayout, DimensionsND dimensionsND, int lod, int channel, const int (&minVoxelCoordinates)[Dimensionality_Max], const int (&maxVoxelCoordinates)[Dimensionality_Max], VolumeDataChannelDescriptor::Format format) override;
int64_t RequestVolumeSubset(void *buffer, VolumeDataLayout const *volumeDataLayout, DimensionsND dimensionsND, int lOD, int channel, const int (&minVoxelCoordinates)[Dimensionality_Max], const int (&maxVoxelCoordinates)[Dimensionality_Max], VolumeDataChannelDescriptor::Format format, float replacementNoValue) override;
int64_t RequestProjectedVolumeSubset(void *buffer, VolumeDataLayout const *volumeDataLayout, DimensionsND dimensionsND, int lod, int channel, const int (&minVoxelCoordinates)[Dimensionality_Max], const int (&maxVoxelCoordinates)[Dimensionality_Max], FloatVector4 const &voxelPlane, DimensionsND projectedDimensions, VolumeDataChannelDescriptor::Format format, InterpolationMethod interpolationMethod) override;
......
......@@ -450,37 +450,6 @@ VolumeDataReadAccessor<FloatVector4, double>* VolumeDataAccessManagerImpl::Creat
return VolumeDataAccess_CreateInterpolatingVolumeDataAccessor<FloatVector4, double>(volumeDataPageAccessor, replacementNoValue, interpolationMethod);
}
static int64_t GetVoxelCount(const int32_t(&min)[Dimensionality_Max], const int32_t (&max)[Dimensionality_Max], int32_t lod, int32_t dimensionality)
{
int64_t voxel = 1;
for (int32_t iCount = 0; iCount < dimensionality; iCount++)
{
int32_t iMin = min[iCount];
int32_t iMax = max[iCount];
int64_t nSize = int64_t(iMax) - iMin;
assert(nSize == 1 || (nSize % (int64_t(1) << int64_t(lod)) == 0));
nSize >>= lod;
if (nSize <= 0)
{
if (min[iCount] >= max[iCount])
{
return 0;
}
}
else
{
voxel *= nSize;
}
}
return voxel;
}
static int32_t CombineAndReduceDimensions (int32_t (&sourceSize )[DataStoreDimensionality_Max],
int32_t (&sourceOffset)[DataStoreDimensionality_Max],
int32_t (&targetSize )[DataStoreDimensionality_Max],
......@@ -822,15 +791,6 @@ static int64_t StaticRequestVolumeSubset(VolumeDataRequestProcessor &request_pro
boxRequested.max[iDimension] = 1;
}
int64_t voxelCount = GetVoxelCount(boxRequested.min, boxRequested.max, lod, volumeDataLayer->GetLayout()->GetDimensionality());
int64_t requestByteSize = voxelCount * GetElementSize(format, VolumeDataChannelDescriptor::Components_1);
if (requestByteSize > VDS_MAX_REQUEST_VOLUME_SUBSET_BYTESIZE)
{
fprintf(stderr, "Requested volume subset is larger than 2GB %" PRId64 "\n", requestByteSize);
abort();
}
std::vector<VolumeDataChunk> chunksInRegion;
volumeDataLayer->GetChunksInRegion(boxRequested.min, boxRequested.max, &chunksInRegion);
......@@ -1865,6 +1825,43 @@ static int64_t StaticRequestVolumeTraces(VolumeDataRequestProcessor &request_pro
});
}
int64_t VolumeDataAccessManagerImpl::GetVolumeSubsetBufferSize(VolumeDataLayout const *volumeDataLayout, const int (&minVoxelCoordinates)[Dimensionality_Max], const int (&maxVoxelCoordinates)[Dimensionality_Max], VolumeDataChannelDescriptor::Format format, int lod = 0)
{
const int dimensionality = volumeDataLayout->GetDimensionality();
for (int32_t dimension = 0; dimension < dimensionality; dimension++)
{
if(minVoxelCoordinates[dimension] < 0 || minVoxelCoordinates[dimension] >= maxVoxelCoordinates[dimension])
{
fmt::print(stderr, "Illegal volume subset, dimension {} min = {}, max = {}", dimension, minVoxelCoordinates[dimension], maxVoxelCoordinates[dimension]);
abort();
}
}
int64_t voxelCount = 1;
for (int dimension = 0; dimension < dimensionality; dimension++)
{
if (static_cast<const VolumeDataLayoutImpl *>(volumeDataLayout)->IsDimensionLODDecimated(dimension))
{
voxelCount *= GetLODSize(minVoxelCoordinates[dimension], maxVoxelCoordinates[dimension], lod);
}
else
{
voxelCount *= maxVoxelCoordinates[dimension] - minVoxelCoordinates[dimension];
}
}
if(format == VolumeDataChannelDescriptor::Format_1Bit)
{
return (voxelCount + 7) / 8;
}
else
{
return voxelCount * GetVoxelFormatByteSize(format);
}
}
int64_t VolumeDataAccessManagerImpl::RequestVolumeSubset(void* buffer, VolumeDataLayout const* volumeDataLayout, DimensionsND dimensionsND, int lod, int channel, const int(&minVoxelCoordinates)[Dimensionality_Max], const int(&maxVoxelCoordinates)[Dimensionality_Max], VolumeDataChannelDescriptor::Format format)
{
return StaticRequestVolumeSubset(m_requestProcessor, buffer, GetLayer(volumeDataLayout, dimensionsND, lod, channel), minVoxelCoordinates, maxVoxelCoordinates, lod, format, false, 0.0f);
......
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