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

Implemented VolumeDataChannelMapping properly.

parent dd093b3f
......@@ -7,6 +7,7 @@ set(SOURCE_FILES
IO/IOManager.cpp
IO/IOManagerAWS.cpp
VDS/VolumeDataPartition.cpp
VDS/VolumeDataChannelMapping.cpp
VDS/VolumeDataLayer.cpp
VDS/VolumeDataLayout.cpp
VDS/VolumeDataRegion.cpp
......@@ -33,6 +34,7 @@ set (PRIVATE_HEADER_FILES
IO/IOManager.h
IO/IOManagerAWS.h
VDS/VolumeDataPartition.h
VDS/VolumeDataChannelMapping.h
VDS/VolumeDataLayer.h
VDS/VolumeDataLayout.h
VDS/VolumeDataChunk.h
......@@ -69,7 +71,6 @@ set (EXPORTED_HEADER_FILES
OpenVDS/Metadata.h
OpenVDS/VolumeData.h
OpenVDS/VolumeDataLayoutDescriptor.h
OpenVDS/VolumeDataChannelMapping.h
OpenVDS/VolumeDataChannelDescriptor.h
OpenVDS/VolumeDataAxisDescriptor.h
OpenVDS/VolumeDataAccess.h
......
/****************************************************************************
** Copyright 2019 The Open Group
** Copyright 2019 Bluware, Inc.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
****************************************************************************/
#include "VolumeDataChannelMapping.h"
#include "VolumeDataPartition.h"
#include <assert.h>
namespace OpenVDS
{
class TraceVolumeDataChannelMapping : public VolumeDataChannelMapping
{
TraceVolumeDataChannelMapping() {}
~TraceVolumeDataChannelMapping() {}
public:
DimensionGroup
getMappedChunkDimensionGroup(VolumeDataPartition const &primaryPartition, int32_t mappedValues) const override;
int32_t getMappedPositiveMargin(VolumeDataPartition const &primaryPartition, int32_t dimension) const override;
int32_t getMappedNegativeMargin(VolumeDataPartition const &primaryPartition, int32_t dimension) const override;
int32_t getMappedPositiveBorder(VolumeDataPartition const &primaryPartition, int32_t dimension) const override;
int32_t getMappedNegativeBorder(VolumeDataPartition const &primaryPartition, int32_t dimension) const override;
int32_t getMappedDimensionFirstSample(int32_t dimension, int32_t dimensionFirstSample, int32_t mappedValues) const override;
int32_t getMappedDimensionNumSamples(int32_t dimension, int32_t dimensionNumSamples, int32_t mappedValues) const override;
int32_t getMappedBrickSize(VolumeDataPartition const &primaryPartition, int32_t dimension, int32_t mappedValues) const override;
int64_t getMappedChunkIndex(VolumeDataPartition const &primaryPartition, int64_t chunkIndex) const override;
int32_t getMappedChunkIndexFromVoxel(VolumeDataPartition const &primaryPartition, int32_t voxel, int32_t dimension) const override;
void getLayoutMinMax(VolumeDataPartition const &primaryPartition, int64_t mappedChunkIndex, int32_t *min, int32_t *max, bool isIncludeMargin) const override;
int64_t getPrimaryChunkIndex(VolumeDataPartition const &primaryPartition, int64_t mappedChunkIndex) const override;
static const TraceVolumeDataChannelMapping &
getInstance();
};
DimensionGroup
TraceVolumeDataChannelMapping::getMappedChunkDimensionGroup(VolumeDataPartition const &primaryPartition, int32_t mappedValues) const
{
int32_t dimensionCount = 0;
int32_t dimensions[Dimensionality_Max];
// If there are more than 1 mapped values, we need to include dimension 0
if(mappedValues > 1)
{
dimensions[dimensionCount++] = 0;
}
// Add any dimensions other than 0 to the dimensions for the metadata layer
DimensionGroup dimensionGroup = primaryPartition.getOriginalDimensionGroup();
for(int32_t dimension = 1; dimension < Dimensionality_Max; dimension++)
{
if(DimensionGroupUtil::isDimensionInGroup(dimensionGroup, dimension))
{
dimensions[dimensionCount++] = dimension;
}
}
while(dimensionCount < Dimensionality_Max)
{
dimensions[dimensionCount++] = -1;
}
return DimensionGroupUtil::getDimensionGroupFromDimensionIndices(dimensions[0], dimensions[1], dimensions[2], dimensions[3], dimensions[4], dimensions[5]);
}
int
TraceVolumeDataChannelMapping::getMappedPositiveMargin(VolumeDataPartition const &primaryPartition, int32_t dimension) const
{
if(dimension == 0)
{
return 0;
}
else
{
return primaryPartition.getPositiveMargin(dimension);
}
}
int
TraceVolumeDataChannelMapping::getMappedNegativeMargin(VolumeDataPartition const &primaryPartition, int32_t dimension) const
{
if(dimension == 0)
{
return 0;
}
else
{
return primaryPartition.getNegativeMargin(dimension);
}
}
int
TraceVolumeDataChannelMapping::getMappedPositiveBorder(VolumeDataPartition const &primaryPartition, int32_t dimension) const
{
if(dimension == 0)
{
return 0;
}
else
{
return primaryPartition.getPositiveBorder(dimension);
}
}
int
TraceVolumeDataChannelMapping::getMappedNegativeBorder(VolumeDataPartition const &primaryPartition, int32_t dimension)const
{
if(dimension == 0)
{
return 0;
}
else
{
return primaryPartition.getNegativeBorder(dimension);
}
}
int
TraceVolumeDataChannelMapping::getMappedDimensionFirstSample(int32_t dimension, int32_t dimensionFirstSample, int32_t mappedValues) const
{
if(dimension == 0)
{
return 0;
}
else
{
return dimensionFirstSample;
}
}
int
TraceVolumeDataChannelMapping::getMappedDimensionNumSamples(int32_t dimension, int32_t dimensionNumSamples, int32_t mappedValues) const
{
assert(mappedValues > 0);
if(dimension == 0)
{
return mappedValues;
}
else
{
return dimensionNumSamples;
}
}
int
TraceVolumeDataChannelMapping::getMappedBrickSize(VolumeDataPartition const &primaryPartition, int32_t dimension, int32_t mappedValues) const
{
assert(mappedValues > 0);
if(dimension == 0)
{
return mappedValues;
}
else
{
return primaryPartition.getBrickSize(dimension);
}
}
int64_t
TraceVolumeDataChannelMapping::getMappedChunkIndex(VolumeDataPartition const &primaryPartition, int64_t chunkIndex) const
{
assert(chunkIndex >= 0 && chunkIndex < primaryPartition.getTotalChunkCount());
return chunkIndex / primaryPartition.getNumChunksInDimension(0);
}
int
TraceVolumeDataChannelMapping::getMappedChunkIndexFromVoxel(VolumeDataPartition const &primaryPartition, int32_t voxel, int32_t dimension) const
{
if(dimension == 0) return 0;
else return primaryPartition.voxelToIndex(voxel, dimension);
}
void
TraceVolumeDataChannelMapping::getLayoutMinMax(VolumeDataPartition const &primaryPartition, int64_t mappedChunkIndex, int32_t *min, int32_t *max, bool isIncludeMargin) const
{
int64_t
startChunk = mappedChunkIndex * primaryPartition.getNumChunksInDimension(0),
endChunk = startChunk + primaryPartition.getNumChunksInDimension(0) - 1;
int32_t
startMax[Dimensionality_Max],
endMin[Dimensionality_Max];
primaryPartition.getChunkMinMax(startChunk, min, startMax, false);
primaryPartition.getChunkMinMax(endChunk, endMin, max, false);
}
int64_t
TraceVolumeDataChannelMapping::getPrimaryChunkIndex(VolumeDataPartition const &primaryPartition, int64_t mappedChunkIndex) const
{
return mappedChunkIndex * primaryPartition.getNumChunksInDimension(0);
}
const TraceVolumeDataChannelMapping &
TraceVolumeDataChannelMapping::getInstance()
{
static TraceVolumeDataChannelMapping
instance;
return instance;
}
const VolumeDataChannelMapping *
VolumeDataChannelMapping::getVolumeDataChannelMapping(VolumeDataMapping volumeDataMapping)
{
switch(volumeDataMapping)
{
case VolumeDataMapping::Direct: return nullptr;
case VolumeDataMapping::PerTrace: return &TraceVolumeDataChannelMapping::getInstance();
default: assert(0 && "Illegal volume data mapping"); return nullptr;
}
}
}
......@@ -15,20 +15,20 @@
** limitations under the License.
****************************************************************************/
#ifndef VOLUMEDATACHANNELMAPPING_H
#define VOLUMEDATACHANNELMAPPING_H
#include "VolumeDataPartition.h"
#include <cstdint>
#include <OpenVDS/openvds_export.h>
#include <VDS/DimensionGroup.h>
namespace OpenVDS
{
class VolumeDataPartition;
class VolumeDataChannelMapping
{
public:
protected:
virtual ~VolumeDataChannelMapping() {}
public:
virtual DimensionGroup getMappedChunkDimensionGroup(VolumeDataPartition const &primaryPartition, int32_t mappedValues) const = 0;
virtual int32_t getMappedPositiveMargin(VolumeDataPartition const &primaryPartition, int32_t dimension) const = 0;
virtual int32_t getMappedNegativeMargin(VolumeDataPartition const &primaryPartition, int32_t dimension) const = 0;
......@@ -42,5 +42,12 @@ public:
virtual int32_t getMappedChunkIndexFromVoxel(VolumeDataPartition const &primaryPartition, int32_t voxel, int32_t dimension) const = 0;
virtual void getLayoutMinMax(VolumeDataPartition const &primaryPartition, int64_t mappedChunkIndex, int32_t *min, int32_t *max, bool isIncludeMargin) const = 0;
virtual int64_t getPrimaryChunkIndex(VolumeDataPartition const &primaryPartition, int64_t mappedChunkIndex) const = 0;
static const VolumeDataChannelMapping *
getVolumeDataChannelMapping(VolumeDataMapping volumeDataMapping);
static VolumeDataPartition
staticMapPartition(VolumeDataPartition const &primaryPartition, const VolumeDataChannelMapping *volumeDataChannelMapping, int32_t mappedValues);
};
}
#endif //VOLUMEDATACHANNELMAPPING_H
......@@ -83,7 +83,7 @@ const VolumeDataChannelMapping* VolumeDataLayer::getVolumeDataChannelMapping() c
int32_t VolumeDataLayer::getMappedValueCount() const
{
return m_volumeDataLayout->getMappedValueCount(m_channel);
return m_volumeDataLayout->getChannelMappedValueCount(m_channel);
}
void VolumeDataLayer::getChunkIndexArrayFromVoxel(const IndexArray& voxel, IndexArray& chunk) const
......
......@@ -18,6 +18,7 @@
#include <OpenVDS/VolumeDataLayoutDescriptor.h>
#include "VolumeDataLayout.h"
#include "VolumeDataChannelMapping.h"
#include "DimensionGroup.h"
#include "Bitmask.h"
......@@ -107,11 +108,19 @@ VolumeDataLayer* VolumeDataLayout::getBaseLayer(DimensionGroup dimensionGroup, i
FloatRange const& VolumeDataLayout::getChannelActualValueRange(int32_t channel) const
{
assert(channel >= 0 && channel < getChannelCount());
return (channel == m_actualValueRangeChannel) ? m_actualValueRange : m_volumeDataChannelDescriptor[channel].getValueRange();
}
int32_t VolumeDataLayout::getMappedValueCount(int32_t channel) const
VolumeDataMapping VolumeDataLayout::getChannelMapping(int32_t channel) const
{
assert(channel >= 0 && channel < getChannelCount());
return m_volumeDataChannelDescriptor[channel].getMapping();
}
int32_t VolumeDataLayout::getChannelMappedValueCount(int32_t channel) const
{
assert(channel >= 0 && channel < getChannelCount());
return m_volumeDataChannelDescriptor[channel].getMappedValueCount();
}
......@@ -121,26 +130,11 @@ FloatRange const& VolumeDataLayout::getDimensionRange(int32_t dimension) const
return m_dimensionRange[dimension];
}
//const VolumeDataChannelMapping* VolumeDataLayout::GetVolumeDataChannelMapping(int32_t channel) const
//{
// assert(channel >= 0 && channel < m_volumeDataChannelDescriptor.size());
//
// VolumeDataChannelDescriptor *volumeDataChannelDescriptor = m_volumeDataChannelDescriptor[channel];
//
// if(volumeDataChannelDescriptor->GetChannelMapping() == OBJ_NONE)
// {
// return NULL;
// }
// else if(pcVolumeDataChannelDescriptor->GetChannelMapping() == TraceVolumeDataChannelMapping_c::GetInstance().GetObjID())
// {
// return &TraceVolumeDataChannelMapping_c::GetInstance();
// }
// else
// {
// DEBUG_ERROR(("Unknown channel mapping"));
// return NULL;
// }
//}
const VolumeDataChannelMapping* VolumeDataLayout::getVolumeDataChannelMapping(int32_t channel) const
{
assert(channel >= 0 && channel < m_volumeDataChannelDescriptor.size());
return VolumeDataChannelMapping::getVolumeDataChannelMapping(m_volumeDataChannelDescriptor[channel].getMapping());
}
VolumeDataLayer *VolumeDataLayout::getVolumeDataLayerFromID(VolumeDataLayer::VolumeDataLayerID volumeDataLayerID) const
{
......@@ -267,31 +261,9 @@ VolumeDataAxisDescriptor VolumeDataLayout::getAxisDescriptor(int32_t dimension)
{
assert(dimension >= 0 && dimension < m_dimensionality);
return VolumeDataAxisDescriptor(getDimensionNumSamples(dimension),
getDimensionName(dimension),
getDimensionUnit(dimension),
getDimensionRange(dimension));
}
VolumeDataMapping VolumeDataLayout::getChannelMapping(int32_t channel) const
{
assert(channel >= 0 && channel < getChannelCount());
assert(0);
// const VolumeDataChannelDescriptor &volumeDataChannelDescriptor = m_volumeDataChannelDescriptor[channel];
//
// if (volumeDataChannelDescriptor.GetChannelMapping() == nullptr)
// {
// return VOLUMEDATAMAPPING_DIRECT;
// }
// else if (pcVolumeDataChannelDescriptor->GetChannelMapping() == TraceVolumeDataChannelMapping_c::GetInstance().GetObjID())
// {
// return VOLUMEDATAMAPPING_PER_TRACE;
// }
// else
// {
// DEBUG_ERROR(("Unknown channel mapping"));
// return ::SpaceLib::VOLUMEDATAMAPPING_DIRECT;
// }
return VolumeDataMapping::Direct;
getDimensionName(dimension),
getDimensionUnit(dimension),
getDimensionRange(dimension));
}
int VolumeDataLayout::getDimensionNumSamples(int32_t dimension) const
......@@ -368,9 +340,9 @@ void VolumeDataLayout::createRenderLayers(DimensionGroup dimensionGroup, int32_t
layerType = VolumeDataLayer::Auxiliary;
}
VolumeDataChannelMapping const *volumeDataChannelMapping = nullptr;// = GetVolumeDataChannelMapping(channel);
VolumeDataChannelMapping const *volumeDataChannelMapping = getVolumeDataChannelMapping(channel);
VolumeDataLayer *volumeDataLayer = new VolumeDataLayer(VolumeDataPartition::staticMapPartition(primaryPartition, volumeDataChannelMapping, getMappedValueCount(channel)),
VolumeDataLayer *volumeDataLayer = new VolumeDataLayer(VolumeDataPartition::staticMapPartition(primaryPartition, volumeDataChannelMapping, getChannelMappedValueCount(channel)),
this, channel,primaryChannelLayer, lowerLOD[channel], layerType, volumeDataChannelMapping);
if(channel == 0)
......
......@@ -81,8 +81,10 @@ public:
FloatRange const &getChannelActualValueRange(int32_t channel) const;
//TODO SHOULD THIS BE REMOVED
int32_t getMappedValueCount(int32_t channel) const;
const VolumeDataChannelMapping *
getVolumeDataChannelMapping(int32_t channel) const;
int32_t getChannelMappedValueCount(int32_t channel) const;
FloatRange const &getDimensionRange(int32_t dimension) const;
......@@ -137,7 +139,6 @@ public:
virtual bool isChannelAllowingLossyCompression(int32_t channel) const { assert(channel >= 0 && channel < getChannelCount()); return m_volumeDataChannelDescriptor[channel].isAllowLossyCompression(); }
virtual bool isChannelUseZipForLosslessCompression(int32_t channel) const { assert(channel >= 0 && channel < getChannelCount()); return m_volumeDataChannelDescriptor[channel].isUseZipForLosslessCompression(); }
// REMOVE ?
virtual VolumeDataMapping getChannelMapping(int32_t channel) const;
// These convenience functions provide access to the individual elements of the axis descriptors
......
......@@ -16,6 +16,7 @@
****************************************************************************/
#include "VolumeDataPartition.h"
#include "VolumeDataChannelMapping.h"
#include <algorithm>
#include <cstring>
......
......@@ -15,9 +15,12 @@
** limitations under the License.
****************************************************************************/
#ifndef VOLUMEDATAPARTITION
#define VOLUMEDATAPARTITION
#include <OpenVDS/openvds_export.h>
#include <OpenVDS/VolumeData.h>
#include <OpenVDS/VolumeDataChannelMapping.h>
#include "DimensionGroup.h"
#include <assert.h>
......@@ -25,6 +28,7 @@
namespace OpenVDS
{
class VolumeDataChannelMapping;
template<typename T, size_t N>
constexpr size_t array_size(const T (&)[N])
......@@ -141,3 +145,4 @@ public:
static VolumeDataPartition staticFindSuperPartition(VolumeDataPartition const &partitionA, VolumeDataPartition const &partitionB);
};
}
#endif //VOLUMEDATAPARTITION
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