Commit 831ec6ce authored by Morten Ofstad's avatar Morten Ofstad
Browse files

Changed the isReadWrite parameter to createVolumeDataPageAccessor to be an...

Changed the isReadWrite parameter to createVolumeDataPageAccessor to be an AccessModeEnum with an AccessMode_Create option so we can handle ProduceStatus better (passing this accessmode changes the produceStatus of the target layer to ProduceStatus_Normal).
parent 54388b47
......@@ -114,9 +114,9 @@ void createVolumeDataLayout(VDSHandle &handle)
false,
0));
for(int32_t iDimensionGroup = 0; iDimensionGroup < DimensionGroup_3D_Max; iDimensionGroup++)
for(int32_t dimensionGroupIndex = 0; dimensionGroupIndex < DimensionGroup_3D_Max; dimensionGroupIndex++)
{
DimensionGroup dimensionGroup = (DimensionGroup)iDimensionGroup;
DimensionGroup dimensionGroup = (DimensionGroup)dimensionGroupIndex;
int32_t nChunkDimensionality = DimensionGroupUtil::getDimensionality(dimensionGroup);
......@@ -132,7 +132,7 @@ void createVolumeDataLayout(VDSHandle &handle)
int32_t physicalLODLevels = (nChunkDimensionality == 3 || handle.layoutDescriptor.isCreate2DLODs()) ? getLODCount(handle.layoutDescriptor) : 1;
int32_t brickSize = getInternalCubeSizeLOD0(handle.layoutDescriptor) * (nChunkDimensionality == 2 ? handle.layoutDescriptor.getBrickSizeMultiplier2D() : 1);
handle.volumeDataLayout->createRenderLayers(dimensionGroup, brickSize, physicalLODLevels);
handle.volumeDataLayout->createLayers(dimensionGroup, brickSize, physicalLODLevels, handle.produceStatuses[DimensionGroupUtil::getDimensionsNDFromDimensionGroup(dimensionGroup)]);
}
}
......@@ -169,6 +169,9 @@ VDSHandle* create(const OpenOptions& options, VolumeDataLayoutDescriptor const &
handle->metadataContainer = metadataContainer;
handle->produceStatuses.clear();
handle->produceStatuses.resize(int(Dimensions_45) + 1, VolumeDataLayer::ProduceStatus_Unavailable);
createVolumeDataLayout(*handle);
if (error.code)
......
......@@ -73,6 +73,13 @@ protected:
VolumeDataAccessManager() {}
virtual ~VolumeDataAccessManager() {}
public:
enum AccessMode
{
AccessMode_ReadOnly,
AccessMode_ReadWrite,
AccessMode_Create
};
/// <summary>
/// Get the VolumeDataLayout object for a VDS.
/// </summary>
......@@ -102,13 +109,13 @@ public:
/// <param name="nMaxPages">
/// The maximum number of pages that the volume data page accessor will cache.
/// </param>
/// <param name="isReadWrite">
/// Set to true to make a read/write accessor. Read/write accessors can only be made for VDSDirect.
/// <param name="accessMode">
/// This specifies the access mode (ReadOnly/ReadWrite/Create) of the volume data page accessor.
/// </param>
/// <returns>
/// A VolumeDataPageAccessor object for the VDS associated with the given VolumeDataLayout object.
/// </returns>
virtual VolumeDataPageAccessor *createVolumeDataPageAccessor(VolumeDataLayout const *volumeDataLayout, DimensionsND dimensionsND, int lod, int channel, int maxPages, bool isReadWrite) = 0;
virtual VolumeDataPageAccessor *createVolumeDataPageAccessor(VolumeDataLayout const *volumeDataLayout, DimensionsND dimensionsND, int lod, int channel, int maxPages, AccessMode accessMode) = 0;
/// <summary>
/// Destroy a volume data page accessor object.
......
......@@ -741,9 +741,9 @@ main(int argc, char *argv[])
auto accessManager = OpenVDS::getDataAccessManager(vds);
auto layout = accessManager->getVolumeDataLayout();
auto amplitudeAccessor = accessManager->createVolumeDataPageAccessor(accessManager->getVolumeDataLayout(), OpenVDS::DimensionsND::Dimensions_012, 0, 0, 8, true);
auto traceFlagAccessor = accessManager->createVolumeDataPageAccessor(accessManager->getVolumeDataLayout(), OpenVDS::DimensionsND::Dimensions_012, 0, 1, 8, true);
auto segyTraceHeaderAccessor = accessManager->createVolumeDataPageAccessor(accessManager->getVolumeDataLayout(), OpenVDS::DimensionsND::Dimensions_012, 0, 2, 8, true);
auto amplitudeAccessor = accessManager->createVolumeDataPageAccessor(accessManager->getVolumeDataLayout(), OpenVDS::DimensionsND::Dimensions_012, 0, 0, 8, OpenVDS::VolumeDataAccessManager::AccessMode_Create);
auto traceFlagAccessor = accessManager->createVolumeDataPageAccessor(accessManager->getVolumeDataLayout(), OpenVDS::DimensionsND::Dimensions_012, 0, 1, 8, OpenVDS::VolumeDataAccessManager::AccessMode_Create);
auto segyTraceHeaderAccessor = accessManager->createVolumeDataPageAccessor(accessManager->getVolumeDataLayout(), OpenVDS::DimensionsND::Dimensions_012, 0, 2, 8, OpenVDS::VolumeDataAccessManager::AccessMode_Create);
int64_t traceByteSize = fileInfo.traceByteSize();
......
......@@ -67,7 +67,7 @@ static ParsedMetadata parseMetadata(int metadataByteSize, unsigned char const *m
}
else
{
fprintf(stderr, "%s%s\n", std::string(" Unsupported chunkMetadataByteSize: ").c_str(), std::to_string(metadataByteSize).c_str());
throw std::runtime_error(std::string(" Unsupported chunkMetadataByteSize: ") + std::to_string(metadataByteSize));
}
return parsedMetadata;
......@@ -180,13 +180,13 @@ static VolumeDataLayer *getVolumeDataLayer(VolumeDataLayout const *layout, Dimen
{
if(!layout)
{
fprintf(stderr, "Volume data layout is NULL, this is usually because the VDS setup is invalid");
throw std::runtime_error("Volume data layout is NULL, this is usually because the VDS setup is invalid");
return nullptr;
}
if(channel > layout->getChannelCount())
{
fprintf(stderr, "Specified channel doesn't exist");
throw std::runtime_error("Specified channel doesn't exist");
return nullptr;
}
......@@ -194,7 +194,7 @@ static VolumeDataLayer *getVolumeDataLayer(VolumeDataLayout const *layout, Dimen
if(!layer && !isAllowFailure)
{
fprintf(stderr, "Specified dimension group doesn't exist");
throw std::runtime_error("Specified dimension group doesn't exist");
return nullptr;
}
......@@ -205,7 +205,7 @@ static VolumeDataLayer *getVolumeDataLayer(VolumeDataLayout const *layout, Dimen
if((!layer || layer->getLayerType() == VolumeDataLayer::Virtual) && !isAllowFailure)
{
fprintf(stderr, "Specified LOD doesn't exist");
throw std::runtime_error("Specified LOD doesn't exist");
}
assert(layer || isAllowFailure);
......@@ -224,14 +224,24 @@ VolumeDataLayout const* VolumeDataAccessManagerImpl::getVolumeDataLayout() const
return m_layout;
}
VolumeDataPageAccessor* VolumeDataAccessManagerImpl::createVolumeDataPageAccessor(VolumeDataLayout const* volumeDataLayout, DimensionsND dimensionsND, int lod, int channel, int maxPages, bool isReadWrite)
VolumeDataPageAccessor* VolumeDataAccessManagerImpl::createVolumeDataPageAccessor(VolumeDataLayout const* volumeDataLayout, DimensionsND dimensionsND, int lod, int channel, int maxPages, AccessMode accessMode)
{
std::unique_lock<std::mutex> lock(m_mutex);
VolumeDataLayer *layer = getVolumeDataLayer(volumeDataLayout, dimensionsND, channel, lod, true);
if (!layer)
return nullptr;
VolumeDataPageAccessorImpl *accessor = new VolumeDataPageAccessorImpl(this,layer,maxPages, isReadWrite);
if(accessMode == VolumeDataAccessManager::AccessMode_Create)
{
layer->setProduceStatus(VolumeDataLayer::ProduceStatus_Normal);
}
else if (layer->getProduceStatus() == VolumeDataLayer::ProduceStatus_Unavailable)
{
throw std::runtime_error("The accessed dimension group or channel is unavailable (check produce status on VDS before accessing data)");
}
VolumeDataPageAccessorImpl *accessor = new VolumeDataPageAccessorImpl(this, layer, maxPages, accessMode != VolumeDataAccessManager::AccessMode_ReadOnly);
m_volumeDataPageAccessorList.insertLast(accessor);
return accessor;
}
......
......@@ -124,7 +124,7 @@ class VolumeDataAccessManagerImpl : public VolumeDataAccessManager
public:
VolumeDataAccessManagerImpl(VDSHandle *handle);
VolumeDataLayout const *getVolumeDataLayout() const override;
VolumeDataPageAccessor *createVolumeDataPageAccessor(VolumeDataLayout const *volumeDataLayout, DimensionsND dimensionsND, int lod, int channel, int maxPages, bool isReadWrite) override;
VolumeDataPageAccessor *createVolumeDataPageAccessor(VolumeDataLayout const *volumeDataLayout, DimensionsND dimensionsND, int lod, int channel, int maxPages, AccessMode accessMode) override;
void destroyVolumeDataPageAccessor(VolumeDataPageAccessor *volumeDataPageAccessor) override;
void destroyVolumeDataAccessor(VolumeDataAccessor *accessor) override;
......
......@@ -337,7 +337,7 @@ void VolumeDataLayout::setActualValueRange(int32_t actualValueRangeChannel, Floa
}
void VolumeDataLayout::createRenderLayers(DimensionGroup dimensionGroup, int32_t brickSize, int32_t physicalLODLevels)
void VolumeDataLayout::createLayers(DimensionGroup dimensionGroup, int32_t brickSize, int32_t physicalLODLevels, VolumeDataLayer::ProduceStatus produceStatus)
{
assert(physicalLODLevels > 0);
......@@ -417,7 +417,7 @@ void VolumeDataLayout::createRenderLayers(DimensionGroup dimensionGroup, int32_t
{
if(volumeDataLayer->getLayerType() != VolumeDataLayer::Virtual)
{
volumeDataLayer->setProduceStatus(VolumeDataLayer::ProduceStatus_Normal);
volumeDataLayer->setProduceStatus(produceStatus);
}
}
}
......
......@@ -168,7 +168,7 @@ public:
void setContentsHash(VolumeDataHash const &contentsHash);
void setActualValueRange(int32_t actualValueRangeChannel, FloatRange const &actualValueRange); // This should probably be implemented with VDSMetadata
void createRenderLayers(DimensionGroup dimensions, int32_t brickSize, int32_t physicalLODLevels); //-> TODO: rename at some point
void createLayers(DimensionGroup dimensionGroup, int32_t brickSize, int32_t physicalLODLevels, VolumeDataLayer::ProduceStatus produceStatus);
bool isDimensionLODDecimated(int32_t dimension) const { return dimension != m_fullResolutionDimension; }
int32_t getFullResolutionDimension() const { return m_fullResolutionDimension; }
......
......@@ -52,7 +52,7 @@ int64_t VolumeDataRequestProcessor::addJob(std::vector<VolumeDataChunk>& chunks,
auto page_accessor_it = m_page_accessors.find(key);
if (page_accessor_it == m_page_accessors.end())
{
auto pa = static_cast<VolumeDataPageAccessorImpl *>(m_manager.createVolumeDataPageAccessor(layout, dimensions, lod, channel, 100, false));
auto pa = static_cast<VolumeDataPageAccessorImpl *>(m_manager.createVolumeDataPageAccessor(layout, dimensions, lod, channel, 100, OpenVDS::VolumeDataAccessManager::AccessMode_ReadOnly));
auto insert_result = m_page_accessors.insert({key, pa});
assert(insert_result.second);
page_accessor_it = insert_result.first;
......
......@@ -45,7 +45,7 @@ GTEST_TEST(OpenVDS_integration, SimpleVolumeDataPageRead)
OpenVDS::VolumeDataLayout *layout = OpenVDS::getLayout(handle);
OpenVDS::VolumeDataPageAccessor *pageAccessor = dataAccessManager->createVolumeDataPageAccessor(layout, OpenVDS::Dimensions_012, 0, 0, 10, false);
OpenVDS::VolumeDataPageAccessor *pageAccessor = dataAccessManager->createVolumeDataPageAccessor(layout, OpenVDS::Dimensions_012, 0, 0, 10, OpenVDS::VolumeDataAccessManager::AccessMode_ReadOnly);
ASSERT_TRUE(pageAccessor);
int pos[OpenVDS::Dimensionality_Max] = {layout->getDimensionNumSamples(0) / 2, layout->getDimensionNumSamples(1) /2, layout->getDimensionNumSamples(2) / 2};
......
Supports Markdown
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