Commit 271687be authored by Jørgen Lind's avatar Jørgen Lind
Browse files

VolumeDataLayer & VolumeDataLayout & VolumeDataPartition

parent e6b386e3
......@@ -5,6 +5,11 @@ set(SOURCE_FILES
IO/Win_File.cpp
IO/S3_Downloader.cpp
VDS/VolumeDataPartition.cpp
VDS/VolumeDataLayer.cpp
VDS/VolumeDataLayout.cpp
VDS/VolumeDataChunk.cpp
VDS/VolumeDataRegion.cpp
VDS/VolumeDataHash.cpp
VDS/DimensionGroup.cpp)
set (PRIVATE_HEADER_FILES
......@@ -12,7 +17,17 @@ set (PRIVATE_HEADER_FILES
IO/S3_Downloader.h
VDS/VolumeData.h
VDS/VolumeDataPartition.h
VDS/DimensionGroup.h)
VDS/VolumeDataLayer.h
VDS/VolumeDataLayout.h
VDS/VolumeDataChunk.h
VDS/VolumeDataRegion.h
VDS/VolumeDataChannelDescriptor.h
VDS/VolumeDataHash.h
VDS/VolumeDataAxisDescriptor.h
VDS/DimensionGroup.h
VDS/Hash.h
Math/Vector.h
VDS/Bitmask.h)
set (EXPORTED_HEADER_FILES
OpenVDS/OpenVDS.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.
****************************************************************************/
#ifndef RANGE_H
#define RANGE_H
namespace OpenVDS
{
template<typename T>
struct Range
{
T min;
T max;
};
template<typename T>
T rangeSize(const Range<T> &r)
{
return r.max - r.min;
}
}
#endif //RANGE_H
\ No newline at end of file
/****************************************************************************
** 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.
****************************************************************************/
#pragma once
namespace OpenVDS
{
template<typename T, size_t N>
struct Vector
{
T d[N];
inline T & operator[] (size_t n) { return d[n]; }
inline const T &operator[] (size_t n) const { return d[n]; }
};
template<typename T, size_t N>
static inline Vector<T, N> Add(const Vector<T, N> &a, const Vector<T, N> &b)
{
Vector<T,N> ret;
for (int i = 0; i < N; i++)
ret[i] = a[i] + b[i];
return ret;
}
template<typename T, size_t N>
static inline Vector<T, N> Subtract(const Vector<T, N> &a, const Vector<T, N> &b)
{
Vector<T,N> ret;
for (int i = 0; i < N; i++)
ret[i] = a[i] - b[i];
return ret;
}
template<typename T, size_t N>
static inline Vector<T, N> Multiply(const Vector<T, N> &a, const Vector<T, N> &b)
{
Vector<T,N> ret;
for (int i = 0; i < N; i++)
ret[i] = a[i] * b[i];
return ret;
}
template<typename T, size_t N>
static inline bool operator==(const Vector<T, N> &a, const Vector<T, N> &b)
{
for (int i = 0; i < N; i++)
if (a[i] != b[i])
return false;
return true;
}
template<typename T, size_t N>
bool operator!=(const Vector<T, N> &a, const Vector<T, N> &b)
{
for (int i = 0; i < N; i++)
if (a[i] == b[i])
return false;
return true;
}
template<typename T>
using Vec2 = Vector<T, 2>;
template<typename T>
using Vec3 = Vector<T, 3>;
template<typename T>
using Vec4 = Vector<T, 4>;
using FloatVec2 = Vec2<float>;
using FloatVec3 = Vec3<float>;
using FloatVec4 = Vec4<float>;
using DoubleVec2 = Vec2<double>;
using DoubleVec3 = Vec3<double>;
using DoubleVec4 = Vec4<double>;
}
/****************************************************************************
** 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.
****************************************************************************/
#ifndef BITMASK_H_INCLUDE
#define BITMASK_H_INCLUDE
#include <type_traits>
namespace OpenVDS
{
namespace Internal
{
template <typename T>
struct bit_mask {
using U = typename std::underlying_type<T>::type;
constexpr bit_mask()
: _flags()
{
}
constexpr bit_mask(const bit_mask<T> &other) = default;
template <typename... ARGS>
bit_mask(T flag, ARGS... args)
: bit_mask(args...)
{
_flags |= static_cast<U>(flag);
}
constexpr bit_mask(T flag)
: _flags(static_cast<U>(flag))
{
}
explicit constexpr bit_mask(U u)
: _flags(u)
{
}
constexpr bit_mask<T> operator~() const { return bit_mask(~_flags); }
constexpr bit_mask<T> operator|(const bit_mask<T> &other) const { return bit_mask<T>(_flags | other._flags); }
constexpr bit_mask<T> operator&(const bit_mask<T> &other) const { return bit_mask<T>(_flags & other._flags); }
constexpr bit_mask<T> operator^(const bit_mask<T> &other) const { return bit_mask<T>(_flags ^ other._flags); }
bit_mask<T>& operator|= (const bit_mask<T> &other) { _flags |= other._flags; return *this; }
bit_mask<T>& operator&= (const bit_mask<T> &other) { _flags &= other._flags; return *this; }
bit_mask<T>& operator^= (const bit_mask<T> &other) { _flags ^= other._flags; return *this; }
template<typename V>
friend constexpr bit_mask<V> operator|(V a, bit_mask<V> &b);
template<typename V>
friend constexpr bit_mask<V> operator&(V a, const bit_mask<V> &b);
template<typename V>
friend constexpr bit_mask<V> operator^(V a, const bit_mask<V> &b);
U _flags;
};
template<typename T>
constexpr bit_mask<T> operator|(T a, bit_mask<T> &b) { return bit_mask<T>(static_cast<typename std::underlying_type<T>::type>(a) | b._flags); }
template<typename T>
constexpr bit_mask<T> operator&(T a, const bit_mask<T> &b) { return bit_mask<T>(static_cast<typename std::underlying_type<T>::type>(a) & b._flags); }
template<typename T>
constexpr bit_mask<T> operator^(T a, const bit_mask<T> &b) { return bit_mask<T>(static_cast<typename std::underlying_type<T>::type>(a) ^ b._flags); }
//this is to eager
//template<typename T>
//constexpr inline bit_mask<T> operator|(T a, T b) { return bit_mask<T>(static_cast<typename std::underlying_type<T>::type>(a) | static_cast<typename std::underlying_type<T>::type>(b)); }
//template<typename T>
//constexpr inline bit_mask<T> operator&(T a, T b) { return bit_mask<T>(static_cast<typename std::underlying_type<T>::type>(a) & static_cast<typename std::underlying_type<T>::type>(b)); }
//template<typename T>
//constexpr inline bit_mask<T> operator^(T a, T b) { return bit_mask<T>(static_cast<typename std::underlying_type<T>::type>(a) ^ static_cast<typename std::underlying_type<T>::type>(b)); }
}
}
#endif // BITMASK_H_INCLUDE
......@@ -20,6 +20,7 @@
#include "VolumeData.h"
#include <cstdint>
#include <cstring>
namespace OpenVDS
{
......@@ -115,6 +116,20 @@ enum Dimensionality
Dimensionality_6,
Dimensionality_Max = Dimensionality_6
};
using IndexArray = int32_t[Dimensionality_Max];
struct NDPos
{
NDPos()
{
Clear();
}
void Clear()
{
memset(data, 0, sizeof data);
}
float data[Dimensionality_Max];
};
namespace DimensionGroupUtil
{
......
/****************************************************************************
** 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.
****************************************************************************/
#ifndef HASH_H_INCLUDE
#define HASH_H_INCLUDE
namespace OpenVDS
{
template <class T>
inline uint64_t ConvertToIntForHashing(T tValue)
{
return tValue;
}
template <>
inline uint64_t ConvertToIntForHashing(float rValue)
{
return *(uint32_t *)&rValue;
}
template <>
inline uint64_t ConvertToIntForHashing(double rValue)
{
return *(uint64_t *)&rValue;
}
template <typename T>
struct InternalHasher
{
static uint64_t CalculateHash(const T &tValue)
{
uint64_t uValue = tValue;
uValue *= 0x87c37b91114253d5ULL;
uValue = (uValue << 31) | (uValue >> (64 - 31)); // ROTL64(uValue,31);
uValue *= 0x4cf5ad432745937fULL;
return uValue;
}
};
template <>
struct InternalHasher<float>
{
static uint64_t CalculateHash(float rValue) { union { float _rValue; uint32_t _uValue; } convert; convert._rValue = rValue; return InternalHasher<uint32_t>::CalculateHash(convert._uValue); }
};
template <>
struct InternalHasher<double>
{
static uint64_t CalculateHash(double rValue) { union { double _rValue; uint64_t _uValue; } convert; convert._rValue = rValue; return InternalHasher<uint64_t>::CalculateHash(convert._uValue); }
};
template<typename T>
struct InternalHasher<Range<T>>
{
static uint64_t CalculateHash(const Range<T>& value)
{
return ConvertToIntForHashing(value.min) * 98953412543643LL +
ConvertToIntForHashing(value.max) * 45985432099125LL;
}
};
template<typename Key>
class HashTraits
{
// This will yield a substitution failure if the template parameter isn't a class (so a member function pointer type cannot be formed)
template <typename T> struct TypeCheck;
public:
static uint64_t CalculateHash(Key const &cA) { return InternalHasher<Key>::CalculateHash(cA); }
static bool
Equal(Key const &cA, Key const &cB) { return cA == cB; }
};
class HashCombiner
{
uint64_t m_combinedHash;
public:
HashCombiner()
: m_combinedHash(0xff51afd7ed558ccdULL)
{
}
template<typename T>
explicit HashCombiner(const T& tValue)
: m_combinedHash(0xff51afd7ed558ccdULL)
{
Add(tValue);
}
operator uint64_t() const
{
return m_combinedHash;
}
// Methods
uint64_t GetCombinedHash() const { return m_combinedHash; }
template<typename T>
HashCombiner& Add(const T& tValue)
{
m_combinedHash ^= HashTraits<T>::CalculateHash(tValue);
m_combinedHash = (m_combinedHash << 27) | (m_combinedHash >> (64 - 27));
m_combinedHash = m_combinedHash * 5 + 0x52dce729;
return *this;
}
template<typename T>
HashCombiner& Add(const T* atValue, int32_t nSize)
{
for (int32_t i = 0; i < nSize; ++i)
{
Add(atValue[i]);
}
return *this;
}
};
}
#endif //HASH_H_INCLUDE
......@@ -78,6 +78,17 @@ enum class VolumeDataMapping
PerTrace ///< Each trace in the volume has a specified number of values. A trace is the entire length of dimension 0
};
enum class CompressionMethod
{
None,
Wavelet,
Rle,
Zip,
WaveletNormalizeBlock,
WaveletLossless,
WaveletNormalizeBlockLossless,
Max
};
} /* namespace OpenVDS */
#endif //VOLUMEDATA_H_INCLUDED
/****************************************************************************
** 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.
****************************************************************************/
#ifndef VOLUMEDATAAXISDESCRIPTOR_H
#define VOLUMEDATAAXISDESCRIPTOR_H
#include <cmath>
namespace OpenVDS
{
class VolumeDataAxisDescriptor
{
int numSamples;
std::string pName;
std::string pUnit;
float coordinateMin;
float coordinateMax;
public:
VolumeDataAxisDescriptor() : numSamples(-1), pName(0), pUnit(0), coordinateMin(0.0f), coordinateMax(0.0f) {}
/// \param numSamples the number of samples along this axis
/// \param pName the name of this axis
/// \param pUnit the unit for this axis
/// \param coordinateMin the minumum coordinate for this axis
/// \param coordinateMax the maximum coordinate for this axis
VolumeDataAxisDescriptor(int numSamples, const std::string &pName, const std::string &pUnit, float coordinateMin, float coordinateMax)
: numSamples(numSamples), pName(pName), pUnit(pUnit), coordinateMin(coordinateMin), coordinateMax(coordinateMax) {}
int GetNumSamples() const { return numSamples; }
const std::string &GetName() const { return pName; }
const std::string &GetUnit() const { return pUnit; }
float GetCoordinateMin() const { return coordinateMin; }
float GetCoordinateMax() const { return coordinateMax; }
float GetCoordinateStep() const { return (numSamples > 1) ? ((coordinateMax - coordinateMin) / (numSamples - 1)) : 0; }
/// Convert a sample index on this axis to a coordinate value
/// \param sampleIndex the sample index to convert
/// \return the coordinate
float SampleIndexToCoordinate(int sampleIndex) { return coordinateMin + sampleIndex * GetCoordinateStep(); }
/// Convert a coordinate to a sample index (rounding to the closest index)
/// \param coordinate the coordinate to convert
/// \return the sample index
int CoordinateToSampleIndex(float coordinate) { return (coordinate == coordinateMin) ? 0 : (int)floorf(((coordinate - coordinateMin) / (coordinateMax - coordinateMin)) * (numSamples - 1) + 0.5f); }
};
}
#endif //VOLUMEDATAAXISDESCRIPTOR_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.
****************************************************************************/
#ifndef VOLUMEDATACHANNELDESCRIPTOR_H
#define VOLUMEDATACHANNELDESCRIPTOR_H
#include <string>
#include <Math/Range.h>
#include "VolumeData.h"
namespace OpenVDS
{
/// \class VolumeDataChannelDescriptor
/// \brief Describes a channel of a VDS
class VolumeDataChannelDescriptor
{
public:
/// Flags for this channel
enum Flags
{
Default = 0,
DiscreteData = (1 << 0), ///< This channel contains discrete data
NoLossyCompression = (1 << 1), ///< Do not allow lossy compression on this channel
NotRenderable = (1 << 2), ///< This channel is not renderable
NoLossyCompressionUseZip = NoLossyCompression | (1 << 3), ///< Use Zip when compressing this channel
};
enum Format
{
FormatAny = -1, ///< The DataBlock can be in any format
Format1Bit, ///< data is in packed 1-bit format
FormatU8, ///< data is in unsigned 8 bit
FormatU16, ///< data is in unsigned 16 bit
FormatR32, ///< data is in 32 bit float
FormatU32, ///< data is in unsigned 32 bit
FormatR64, ///< data is in 64 bit double
FormatU64 ///< data is in unsigned 64 bit
};
enum Components
{
Components_1 = 1,
Components_2 = 2,
Components_4 = 4,
ComponentsMax = Components_4
};
private:
Format format;
Components components;
const char *pName;
const char *pUnit;
Range<float> valueRange;
VolumeDataMapping mapping;
int mappedValueCount;
Flags flags;
bool useNoValue;
float noValue;
float integerScale;
float integerOffset;
public:
VolumeDataChannelDescriptor()
: format(FormatAny), components(Components_1), pName(nullptr), pUnit(nullptr), valueRange({0.0f,0.0f}), mapping(VolumeDataMapping::Direct), mappedValueCount(1), flags(Default), useNoValue(false), noValue(0.0f), integerScale(1.0f), integerOffset(0.0f) {}
/// The minimum constructor for a VolumeDataChannelDescriptor. This will use direct mapping, default flags, and no No Value
/// \param format the data format for this channel
/// \param components the vector count for this channel
/// \param pName the name of this channel
/// \param pUnit the unit of this channel
/// \param valueRangeMin the value range minimum of this channel
/// \param valueRangeMax the value range maximum of this channel
VolumeDataChannelDescriptor(Format format, Components components, const char *pName, const char *pUnit, float valueRangeMin, float valueRangeMax)
: format(format), components(components), pName(pName), pUnit(pUnit), valueRange({valueRangeMin, valueRangeMax}), mapping(VolumeDataMapping::Direct), mappedValueCount(1), flags(Default), useNoValue(false), noValue(0.0f), integerScale(1.0f), integerOffset(0.0f) {}
/// \param format the data format for this channel
/// \param components the vector count for this channel
/// \param pName the name of this channel
/// \param pUnit the unit of this channel
/// \param valueRangeMin the value range minimum of this channel
/// \param valueRangeMax the value range maximum of this channel
/// \param mapping the mapping for this channel
VolumeDataChannelDescriptor(Format format, Components components, const char *pName, const char *pUnit, float valueRangeMin, float valueRangeMax, enum VolumeDataMapping mapping)
: format(format), components(components), pName(pName), pUnit(pUnit), valueRange({valueRangeMin, valueRangeMax}), mapping(mapping), mappedValueCount(1), flags(Default), useNoValue(false), noValue(0.0f), integerScale(1.0f), integerOffset(0.0f) {}
/// \param format the data format for this channel
/// \param components the vector count for this channel
/// \param pName the name of this channel
/// \param pUnit the unit of this channel
/// \param valueRangeMin the value range minimum of this channel
/// \param valueRangeMax the value range maximum of this channel
/// \param flags the flags for this channel
VolumeDataChannelDescriptor(Format format, Components components, const char *pName, const char *pUnit, float valueRangeMin, float valueRangeMax, enum Flags flags)
: format(format), components(components), pName(pName), pUnit(pUnit), valueRange({valueRangeMin, valueRangeMax}), mapping(VolumeDataMapping::Direct), mappedValueCount(