10#ifndef OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
11#define OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
24#include <tbb/spin_mutex.h>
33class TestAttributeArray;
49template <
typename IntegerT,
typename FloatT>
53 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
54 if (FloatT(0.0) > s)
return std::numeric_limits<IntegerT>::min();
55 else if (FloatT(1.0) <= s)
return std::numeric_limits<IntegerT>::max();
56 return IntegerT(s * FloatT(std::numeric_limits<IntegerT>::max()));
60template <
typename FloatT,
typename IntegerT>
64 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
65 return FloatT(s) / FloatT((std::numeric_limits<IntegerT>::max()));
68template <
typename IntegerVectorT,
typename FloatT>
72 return IntegerVectorT(
78template <
typename FloatVectorT,
typename IntegerT>
97 template <
typename T>
struct Accessor;
121 tbb::spin_mutex::scoped_lock lock;
126 using Ptr = std::shared_ptr<AttributeArray>;
127 using ConstPtr = std::shared_ptr<const AttributeArray>;
202 bool constantStride =
true,
214 template<
typename AttributeArrayType>
215 bool isType()
const {
return this->
type() == AttributeArrayType::attributeType(); }
218 template<
typename ValueType>
244 template<
typename IterT>
249 template<
typename IterT>
256 virtual void expand(
bool fill =
true) = 0;
292 virtual void read(std::istream&) = 0;
295 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
297 virtual void write(std::ostream&)
const = 0;
304 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
310 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
334 friend class ::TestAttributeArray;
341 virtual char* dataAsByteArray() = 0;
342 virtual const char* dataAsByteArray()
const = 0;
345 template <
typename IterT>
346 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
347 bool rangeChecking =
true);
438 template <
typename T>
441 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
442 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
443 static const char*
name() {
return "null"; }
449 template <
typename T>
452 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
453 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
454 static const char*
name() {
return "trnc"; }
461 static const char*
name() {
return "fxpt"; }
462 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
463 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
470 static const char*
name() {
return "ufxpt"; }
471 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
472 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
476template <
bool OneByte,
typename Range=PositionRange>
479 template <
typename T>
482 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
483 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
486 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
496 template <
typename T>
501 static const char*
name() {
return "uvec"; }
510template<
typename ValueType_,
typename Codec_ = NullCodec>
514 using Ptr = std::shared_ptr<TypedAttributeArray>;
515 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
519 using StorageType =
typename Codec::template Storage<ValueType>::Type;
551 const Metadata* metadata =
nullptr);
627 template<
typename T>
void get(
Index n, T& value)
const;
640 template<
typename T>
void set(
Index n,
const T& value);
669 void read(std::istream&)
override;
673 void write(std::ostream& os,
bool outputTransient)
const override;
675 void write(std::ostream&)
const override;
683 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
690 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
722 friend class ::TestAttributeArray;
727 inline void doLoad()
const;
729 inline void doLoadUnsafe()
const;
732 inline void setOutOfCore(
const bool);
738 char* dataAsByteArray()
override;
739 const char* dataAsByteArray()
const override;
741 size_t arrayMemUsage()
const;
751 std::unique_ptr<StorageType[]> mData;
753 Index mStrideOrTotalSize;
762template <
typename ValueType,
typename CodecType = UnknownCodec>
767 using Ptr = std::shared_ptr<Handle>;
806 friend class ::TestAttributeArray;
808 template <
bool IsUnknownCodec>
809 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
811 template <
bool IsUnknownCodec>
812 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
814 template <
bool IsUnknownCodec>
815 typename std::enable_if<IsUnknownCodec, ValueType>::type
get(
Index index)
const;
817 template <
bool IsUnknownCodec>
818 typename std::enable_if<!IsUnknownCodec, ValueType>::type
get(
Index index)
const;
823 Index mStrideOrTotalSize;
825 bool mCollapseOnDestruction;
833template <
typename ValueType,
typename CodecType = UnknownCodec>
838 using Ptr = std::shared_ptr<Handle>;
860 void fill(
const ValueType& value);
868 friend class ::TestAttributeArray;
870 template <
bool IsUnknownCodec>
871 typename std::enable_if<IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
873 template <
bool IsUnknownCodec>
874 typename std::enable_if<!IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
884template<
typename ValueType>
892template<
typename ValueType>
900template<
typename StorageType,
typename ValueType>
904 val =
static_cast<ValueType
>(data);
908template<
typename StorageType,
typename ValueType>
912 data =
static_cast<StorageType
>(val);
916template <
bool OneByte,
typename Range>
917template<
typename StorageType,
typename ValueType>
929template <
bool OneByte,
typename Range>
930template<
typename StorageType,
typename ValueType>
962template <
typename IterT>
963void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
975 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
976 char*
const targetBuffer = this->dataAsByteArray();
979 if (rangeChecking && this->isUniform()) {
983 const bool sourceIsUniform = sourceArray.
isUniform();
985 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
986 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
988 for (IterT it(iter); it; ++it) {
989 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
990 const Index targetIndex = it.targetIndex();
993 if (sourceIndex >= sourceDataSize) {
995 "Cannot copy array data as source index exceeds size of source array.");
997 if (targetIndex >= targetDataSize) {
999 "Cannot copy array data as target index exceeds size of target array.");
1008 const size_t targetOffset(targetIndex * bytes);
1009 const size_t sourceOffset(sourceIndex * bytes);
1011 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1015template <
typename IterT>
1018 this->doCopyValues(sourceArray, iter,
false);
1021template <
typename IterT>
1043 this->doCopyValues(sourceArray, iter,
true);
1057template<
typename ValueType_,
typename Codec_>
1063 , mStrideOrTotalSize(strideOrTotalSize)
1065 if (constantStride) {
1067 if (strideOrTotalSize == 0) {
1069 "stride to be at least one.")
1074 if (mStrideOrTotalSize < n) {
1076 "a total size of at least the number of elements in the array.")
1079 mSize = std::max(
Index(1), mSize);
1080 mStrideOrTotalSize = std::max(
Index(1), mStrideOrTotalSize);
1081 Codec::encode(uniformValue, this->
data()[0]);
1085template<
typename ValueType_,
typename Codec_>
1092template<
typename ValueType_,
typename Codec_>
1094 const tbb::spin_mutex::scoped_lock& lock)
1097 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1101 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1106template<
typename ValueType_,
typename Codec_>
1107TypedAttributeArray<ValueType_, Codec_>&
1112 tbb::spin_mutex::scoped_lock lock(
mMutex);
1113 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1120 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1125 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1133template<
typename ValueType_,
typename Codec_>
1144template<
typename ValueType_,
typename Codec_>
1152template<
typename ValueType_,
typename Codec_>
1160template<
typename ValueType_,
typename Codec_>
1168template<
typename ValueType_,
typename Codec_>
1180template<
typename ValueType_,
typename Codec_>
1190template<
typename ValueType_,
typename Codec_>
1200template<
typename ValueType_,
typename Codec_>
1208template<
typename ValueType_,
typename Codec_>
1210TypedAttributeArray<ValueType_, Codec_>::arrayMemUsage()
const
1212 if (this->isOutOfCore())
return 0;
1214 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1218template<
typename ValueType_,
typename Codec_>
1220TypedAttributeArray<ValueType_, Codec_>::allocate()
1224 mData.reset(
new StorageType[1]);
1227 const size_t size(this->dataSize());
1229 mData.reset(
new StorageType[size]);
1234template<
typename ValueType_,
typename Codec_>
1236TypedAttributeArray<ValueType_, Codec_>::deallocate()
1239 if (this->isOutOfCore()) {
1240 this->setOutOfCore(
false);
1241 this->mPageHandle.reset();
1243 if (mData) mData.reset();
1247template<
typename ValueType_,
typename Codec_>
1253 if (std::is_same<ValueType, Quats>::value ||
1254 std::is_same<ValueType, Quatd>::value ||
1255 std::is_same<ValueType, Mat3s>::value ||
1256 std::is_same<ValueType, Mat3d>::value ||
1257 std::is_same<ValueType, Mat4s>::value ||
1258 std::is_same<ValueType, Mat4d>::value)
return true;
1263 return std::is_floating_point<ElementT>::value || std::is_same<math::half, ElementT>::value;
1267template<
typename ValueType_,
typename Codec_>
1272 return std::is_class<ValueType>::value && !std::is_same<math::half, ValueType>::value;
1276template<
typename ValueType_,
typename Codec_>
1284template<
typename ValueType_,
typename Codec_>
1289 return !this->
valueType().compare(0, 4,
"quat");
1293template<
typename ValueType_,
typename Codec_>
1298 return !this->
valueType().compare(0, 3,
"mat");
1302template<
typename ValueType_,
typename Codec_>
1306 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1310template<
typename ValueType_,
typename Codec_>
1318template<
typename ValueType_,
typename Codec_>
1330template<
typename ValueType_,
typename Codec_>
1341template<
typename ValueType_,
typename Codec_>
1346 val =
static_cast<T
>(this->
getUnsafe(n));
1350template<
typename ValueType_,
typename Codec_>
1355 val =
static_cast<T
>(this->
get(n));
1359template<
typename ValueType_,
typename Codec_>
1367template<
typename ValueType_,
typename Codec_>
1382template<
typename ValueType_,
typename Codec_>
1394template<
typename ValueType_,
typename Codec_>
1403template<
typename ValueType_,
typename Codec_>
1412template<
typename ValueType_,
typename Codec_>
1420template<
typename ValueType_,
typename Codec_>
1429 tbb::spin_mutex::scoped_lock lock(
mMutex);
1436 for (
Index i = 0; i < this->dataSize(); ++i) this->
data()[i] = val;
1441template<
typename ValueType_,
typename Codec_>
1448 const ValueType_ val = this->
get(0);
1449 for (
Index i = 1; i < this->dataSize(); i++) {
1458template<
typename ValueType_,
typename Codec_>
1466template<
typename ValueType_,
typename Codec_>
1471 tbb::spin_mutex::scoped_lock lock(
mMutex);
1476 Codec::encode(uniformValue, this->
data()[0]);
1480template<
typename ValueType_,
typename Codec_>
1488template<
typename ValueType_,
typename Codec_>
1493 tbb::spin_mutex::scoped_lock lock(
mMutex);
1500 Codec::encode(value, this->
data()[i]);
1505template<
typename ValueType_,
typename Codec_>
1513template<
typename ValueType_,
typename Codec_>
1521template<
typename ValueType_,
typename Codec_>
1523TypedAttributeArray<ValueType_, Codec_>::setOutOfCore(
const bool b)
1529template<
typename ValueType_,
typename Codec_>
1531TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1533 if (!(this->isOutOfCore()))
return;
1535 TypedAttributeArray<ValueType_, Codec_>* self =
1536 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1540 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1541 this->doLoadUnsafe();
1545template<
typename ValueType_,
typename Codec_>
1553template<
typename ValueType_,
typename Codec_>
1561template<
typename ValueType_,
typename Codec_>
1570template<
typename ValueType_,
typename Codec_>
1577 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1578 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1580 uint8_t
flags = uint8_t(0);
1581 is.read(
reinterpret_cast<char*
>(&
flags),
sizeof(uint8_t));
1584 uint8_t serializationFlags = uint8_t(0);
1585 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1588 is.read(
reinterpret_cast<char*
>(&
size),
sizeof(
Index));
1597 if (serializationFlags >= 0x10) {
1612 is.read(
reinterpret_cast<char*
>(&
stride),
sizeof(
Index));
1613 mStrideOrTotalSize =
stride;
1616 mStrideOrTotalSize = 1;
1621template<
typename ValueType_,
typename Codec_>
1630 tbb::spin_mutex::scoped_lock lock(
mMutex);
1634 uint8_t bloscCompressed(0);
1635 if (!
mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1645 if (bloscCompressed == uint8_t(1)) {
1649 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1651 if (newBuffer) buffer.reset(newBuffer.release());
1656 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1660template<
typename ValueType_,
typename Codec_>
1669#ifdef OPENVDB_USE_DELAYED_LOADING
1672 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is.
getInputStream());
1673 const bool delayLoad = (mappedFile.get() !=
nullptr);
1688 tbb::spin_mutex::scoped_lock lock(
mMutex);
1692#ifdef OPENVDB_USE_DELAYED_LOADING
1693 this->setOutOfCore(delayLoad);
1699#ifdef OPENVDB_USE_DELAYED_LOADING
1702 std::unique_ptr<char[]> buffer =
mPageHandle->read();
1703 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1705#ifdef OPENVDB_USE_DELAYED_LOADING
1715template<
typename ValueType_,
typename Codec_>
1719 this->
write(os,
false);
1723template<
typename ValueType_,
typename Codec_>
1732template<
typename ValueType_,
typename Codec_>
1736 if (!outputTransient && this->
isTransient())
return;
1743 uint8_t serializationFlags(0);
1745 Index strideOrTotalSize(mStrideOrTotalSize);
1746 bool strideOfOne(this->
stride() == 1);
1751 if (bloscCompression) this->doLoad();
1753 size_t compressedBytes = 0;
1763 if (bloscCompression && paged) serializationFlags |=
WRITEPAGED;
1765 else if (bloscCompression)
1769 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1770 const size_t inBytes = this->arrayMemUsage();
1777 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1781 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1782 os.write(
reinterpret_cast<const char*
>(&
flags),
sizeof(uint8_t));
1783 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1784 os.write(
reinterpret_cast<const char*
>(&
size),
sizeof(
Index));
1787 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&strideOrTotalSize),
sizeof(
Index));
1791template<
typename ValueType_,
typename Codec_>
1795 if (!outputTransient && this->
isTransient())
return;
1804 os.write(
reinterpret_cast<const char*
>(this->
data()),
sizeof(
StorageType));
1808 std::unique_ptr<char[]> compressedBuffer;
1809 size_t compressedBytes = 0;
1810 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1811 const size_t inBytes = this->arrayMemUsage();
1813 if (compressedBuffer) {
1814 uint8_t bloscCompressed(1);
1815 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1816 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
1819 uint8_t bloscCompressed(0);
1820 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1821 os.write(
reinterpret_cast<const char*
>(this->
data()), inBytes);
1826 uint8_t bloscCompressed(0);
1827 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1828 os.write(
reinterpret_cast<const char*
>(this->
data()), this->arrayMemUsage());
1833template<
typename ValueType_,
typename Codec_>
1837 if (!outputTransient && this->
isTransient())
return;
1841 if (!bloscCompression) {
1852 os.
write(
reinterpret_cast<const char*
>(this->
data()), this->arrayMemUsage());
1856template<
typename ValueType_,
typename Codec_>
1858TypedAttributeArray<ValueType_, Codec_>::doLoadUnsafe()
const
1860 if (!(this->isOutOfCore()))
return;
1869 std::unique_ptr<char[]> buffer = self->mPageHandle->read();
1871 self->mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1873 self->mPageHandle.reset();
1877 self->mOutOfCore =
false;
1881template<
typename ValueType_,
typename Codec_>
1896template<
typename ValueType_,
typename Codec_>
1898TypedAttributeArray<ValueType_, Codec_>::isEqual(
const AttributeArray& other)
const
1901 if(!otherT)
return false;
1902 if(this->mSize != otherT->mSize ||
1903 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1905 this->attributeType() != this->attributeType())
return false;
1910 const StorageType *target = this->data(), *source = otherT->
data();
1911 if (!target && !source)
return true;
1912 if (!target || !source)
return false;
1913 Index n = this->mIsUniform ? 1 : mSize;
1919template<
typename ValueType_,
typename Codec_>
1921TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
1923 return reinterpret_cast<char*
>(this->data());
1927template<
typename ValueType_,
typename Codec_>
1929TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
1931 return reinterpret_cast<const char*
>(this->data());
1939template <
typename CodecType,
typename ValueType>
1960template <
typename ValueType>
1968 return (*functor)(array, n);
1973 (*functor)(array, n, value);
1982template <
typename ValueType,
typename CodecType>
1983typename AttributeHandle<ValueType, CodecType>::Ptr
1990template <
typename ValueType,
typename CodecType>
1995 , mCollapseOnDestruction(collapseOnDestruction &&
array.isStreaming())
1997 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2018template <
typename ValueType,
typename CodecType>
2025template <
typename ValueType,
typename CodecType>
2026template <
bool IsUnknownCodec>
2027typename std::enable_if<IsUnknownCodec, bool>::type
2028AttributeHandle<ValueType, CodecType>::compatibleType()
const
2035template <
typename ValueType,
typename CodecType>
2036template <
bool IsUnknownCodec>
2037typename std::enable_if<!IsUnknownCodec, bool>::type
2038AttributeHandle<ValueType, CodecType>::compatibleType()
const
2042 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2045template <
typename ValueType,
typename CodecType>
2052template <
typename ValueType,
typename CodecType>
2060template <
typename ValueType,
typename CodecType>
2066template <
typename ValueType,
typename CodecType>
2067template <
bool IsUnknownCodec>
2068typename std::enable_if<IsUnknownCodec, ValueType>::type
2073 return (*mGetter)(mArray,
index);
2076template <
typename ValueType,
typename CodecType>
2077template <
bool IsUnknownCodec>
2078typename std::enable_if<!IsUnknownCodec, ValueType>::type
2086template <
typename ValueType,
typename CodecType>
2089 return mArray->isUniform();
2092template <
typename ValueType,
typename CodecType>
2095 return mArray->hasConstantStride();
2102template <
typename ValueType,
typename CodecType>
2110template <
typename ValueType,
typename CodecType>
2117template <
typename ValueType,
typename CodecType>
2123template <
typename ValueType,
typename CodecType>
2129template <
typename ValueType,
typename CodecType>
2135template <
typename ValueType,
typename CodecType>
2141template <
typename ValueType,
typename CodecType>
2147template <
typename ValueType,
typename CodecType>
2153template <
typename ValueType,
typename CodecType>
2159template <
typename ValueType,
typename CodecType>
2160template <
bool IsUnknownCodec>
2161typename std::enable_if<IsUnknownCodec, void>::type
2169template <
typename ValueType,
typename CodecType>
2170template <
bool IsUnknownCodec>
2171typename std::enable_if<!IsUnknownCodec, void>::type
2179template <
typename ValueType,
typename CodecType>
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Convenience wrappers to using Blosc and reading and writing of Paged data.
Definition Exceptions.h:57
Definition Exceptions.h:58
Definition Exceptions.h:64
Definition Exceptions.h:65
std::unique_ptr< PageHandle > Ptr
Definition StreamCompression.h:173
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition StreamCompression.h:208
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
bool sizeOnly() const
Definition StreamCompression.h:218
void read(PageHandle::Ptr &pageHandle, std::streamsize n, bool delayed=true)
Takes a pageHandle and updates the referenced page with the current stream pointer position and if de...
std::istream & getInputStream()
Definition StreamCompression.h:221
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition StreamCompression.h:245
std::ostream & getOutputStream()
Set and get the output stream.
Definition StreamCompression.h:258
bool sizeOnly() const
Definition StreamCompression.h:255
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
static Vec3s unpack(const uint16_t data)
Definition QuantizedUnitVec.h:86
static uint16_t pack(const Vec3< T > &vec)
Definition QuantizedUnitVec.h:48
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition Vec3.h:86
T & y()
Definition Vec3.h:87
T & z()
Definition Vec3.h:88
Definition AttributeArray.h:120
Base class for storing attribute data.
Definition AttributeArray.h:94
virtual Name valueType() const =0
Return the name of the value type of a single element in this array (e.g., "float" or "vec3d").
const char * constDataAsByteArray() const
Indirect virtual function to retrieve the data buffer cast to a char byte array.
Definition AttributeArray.h:331
AttributeArray(const AttributeArray &rhs, const tbb::spin_mutex::scoped_lock &)
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
static Ptr create(const NamePair &type, Index length, Index stride=1, bool constantStride=true, const Metadata *metadata=nullptr, const ScopedRegistryLock *lock=nullptr)
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition AttributeArray.h:275
SerializationFlag
Definition AttributeArray.h:110
@ WRITESTRIDED
Definition AttributeArray.h:111
@ WRITEUNIFORM
data is marked as strided when written
Definition AttributeArray.h:112
@ WRITEPAGED
Definition AttributeArray.h:115
@ WRITEMEMCOMPRESS
data is marked as uniform when written
Definition AttributeArray.h:113
AttributeArray & operator=(const AttributeArray &rhs)
virtual Index dataSize() const =0
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
virtual void readBuffers(std::istream &)=0
Read attribute buffers from a stream.
std::shared_ptr< AttributeArray > Ptr
Definition AttributeArray.h:126
virtual ~AttributeArray()
Definition AttributeArray.h:134
compression::PageHandle::Ptr mPageHandle
Definition AttributeArray.h:372
Flag
Definition AttributeArray.h:102
@ TRANSIENT
Definition AttributeArray.h:103
@ PARTIALREAD
streaming mode collapses attributes when first accessed
Definition AttributeArray.h:107
@ HIDDEN
by default not written to disk
Definition AttributeArray.h:104
@ CONSTANTSTRIDE
hidden from UIs or iterators
Definition AttributeArray.h:105
@ STREAMING
stride size does not vary in the array
Definition AttributeArray.h:106
AttributeArray()
Definition AttributeArray.h:133
virtual Index stride() const =0
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition AttributeArray.h:268
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition AttributeArray.h:215
virtual bool valueTypeIsQuaternion() const =0
Return true if the value type is a quaternion.
virtual bool valueTypeIsVector() const =0
Return true if the value type is a vector.
void copyValuesUnsafe(const AttributeArray &sourceArray, const IterT &iter)
Copy values into this array from a source array to a target array as referenced by an iterator.
Definition AttributeArray.h:1016
uint8_t mFlags
Definition AttributeArray.h:367
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
void setStreaming(bool state)
Specify whether this attribute is to be streamed off disk, in which case, the attributes are collapse...
AttributeArray(const AttributeArray &rhs)
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
uint8_t flags() const
Retrieve the attribute array flags.
Definition AttributeArray.h:289
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition AttributeArray.h:219
std::atomic< Index32 > mOutOfCore
Definition AttributeArray.h:369
virtual void writeBuffers(std::ostream &, bool outputTransient) const =0
static void clearRegistry(const ScopedRegistryLock *lock=nullptr)
Clear the attribute type registry.
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition AttributeArray.h:99
virtual Index size() const =0
void setTransient(bool state)
Specify whether this attribute should only exist in memory and not be serialized during stream output...
virtual void read(std::istream &)=0
Read attribute metadata and buffers from a stream.
void copyValues(const AttributeArray &sourceArray, const IterT &iter, bool compact=true)
Like copyValuesUnsafe(), but if compact is true, attempt to collapse this array.
Definition AttributeArray.h:1022
void setHidden(bool state)
Specify whether this attribute should be hidden (e.g., from UI or iterators).
virtual void write(std::ostream &, bool outputTransient) const =0
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
virtual bool valueTypeIsClass() const =0
Return true if the value type is a class (ie vector, matrix or quaternion return true)
virtual void loadData() const =0
Ensures all data is in-core.
uint8_t mUsePagedRead
Definition AttributeArray.h:368
virtual bool valueTypeIsMatrix() const =0
Return true if the value type is a matrix.
bool operator==(const AttributeArray &other) const
tbb::spin_mutex mMutex
Definition AttributeArray.h:366
bool operator!=(const AttributeArray &other) const
Definition AttributeArray.h:328
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition AttributeArray.h:283
virtual void writeMetadata(std::ostream &, bool outputTransient, bool paged) const =0
AttributeArray & operator=(AttributeArray &&)=delete
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition AttributeArray.h:129
virtual Name codecType() const =0
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
virtual size_t memUsageIfLoaded() const =0
friend class AttributeHandle
Definition AttributeArray.h:131
virtual void readMetadata(std::istream &)=0
Read attribute metadata from a stream.
std::shared_ptr< const AttributeArray > ConstPtr
Definition AttributeArray.h:127
virtual void collapse()=0
Replace the existing array with a uniform zero value.
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
virtual Index storageTypeSize() const =0
virtual void write(std::ostream &) const =0
Write attribute metadata and buffers to a stream, don't write transient attributes.
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
virtual AttributeArray::Ptr copy() const =0
Return a copy of this attribute.
virtual Index valueTypeSize() const =0
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition AttributeArray.h:286
virtual const NamePair & type() const =0
Return the name of this attribute's type.
size_t mCompressedBytes
Definition AttributeArray.h:373
bool mIsUniform
Definition AttributeArray.h:365
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
virtual size_t memUsage() const =0
Return the number of bytes of memory used by this attribute.
AttributeArray(AttributeArray &&)=delete
virtual ~AttributeHandle()
Definition AttributeArray.h:2019
Index size() const
Definition AttributeArray.h:786
void(*)(AttributeArray *array, const ValueType &value) ValuePtr
Definition AttributeArray.h:773
SetterPtr mSetter
Definition AttributeArray.h:801
Index stride() const
Definition AttributeArray.h:785
std::shared_ptr< Handle > Ptr
Definition AttributeArray.h:767
GetterPtr mGetter
Definition AttributeArray.h:800
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition AttributeArray.h:772
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition AttributeArray.h:1984
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition AttributeArray.h:1991
ValuePtr mFiller
Definition AttributeArray.h:803
ValueType get(Index n, Index m=0) const
Definition AttributeArray.h:2061
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:771
AttributeHandle(const AttributeHandle &)=default
AttributeHandle< ValueType, CodecType > Handle
Definition AttributeArray.h:766
ValuePtr mCollapser
Definition AttributeArray.h:802
const AttributeArray & array() const
const AttributeArray * mArray
Definition AttributeArray.h:798
bool isUniform() const
Definition AttributeArray.h:2087
std::unique_ptr< Handle > UniquePtr
Definition AttributeArray.h:768
bool hasConstantStride() const
Definition AttributeArray.h:2093
AttributeHandle & operator=(const AttributeHandle &)=default
Index index(Index n, Index m) const
Definition AttributeArray.h:2053
virtual ~AttributeWriteHandle()=default
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition AttributeArray.h:2111
std::shared_ptr< Handle > Ptr
Definition AttributeArray.h:838
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition AttributeArray.h:2142
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition AttributeArray.h:2136
void set(Index n, const ValueType &value)
Definition AttributeArray.h:2118
void expand(bool fill=true)
std::unique_ptr< Handle > ScopedPtr
Definition AttributeArray.h:839
AttributeWriteHandle< ValueType, CodecType > Handle
Definition AttributeArray.h:837
static Ptr create(AttributeArray &array, const bool expand=true)
Definition AttributeArray.h:2104
void set(Index n, Index m, const ValueType &value)
Definition AttributeArray.h:2124
void fill(const ValueType &value)
void collapse(const ValueType &uniformValue)
Definition AttributeArray.h:2148
Typed class for storing attribute data.
Definition AttributeArray.h:512
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition AttributeArray.h:590
void write(std::ostream &) const override
Write attribute data to a stream, don't write transient attributes.
Definition AttributeArray.h:1717
size_t memUsageIfLoaded() const override
Definition AttributeArray.h:1312
void getUnsafe(Index n, T &value) const
Return the value at index n (assumes in-core)
Definition AttributeArray.h:1344
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition AttributeArray.h:1320
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition AttributeArray.h:647
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition AttributeArray.h:1623
std::shared_ptr< TypedAttributeArray > Ptr
Definition AttributeArray.h:514
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition AttributeArray.h:1883
void write(std::ostream &os, bool outputTransient) const override
Definition AttributeArray.h:1725
typename Codec::template Storage< ValueType >::Type StorageType
Definition AttributeArray.h:519
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition AttributeArray.h:1304
ValueType_ ValueType
Definition AttributeArray.h:517
TypedAttributeArray(Index n=1, Index strideOrTotalSize=1, bool constantStride=true, const ValueType &uniformValue=zeroVal< ValueType >())
Default constructor, always constructs a uniform attribute.
Definition AttributeArray.h:1058
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition AttributeArray.h:1555
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition AttributeArray.h:1515
std::shared_ptr< const TypedAttributeArray > ConstPtr
Definition AttributeArray.h:515
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition AttributeArray.h:1278
bool validData() const
Definition AttributeArray.h:719
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition AttributeArray.h:1182
TypedAttributeArray & operator=(TypedAttributeArray &&)=delete
Move assignment operator disabled.
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition AttributeArray.h:1793
AttributeArray::Ptr copy() const override
Definition AttributeArray.h:1202
Index storageTypeSize() const override
Definition AttributeArray.h:594
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition AttributeArray.h:1286
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition AttributeArray.h:1662
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition AttributeArray.h:1384
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition AttributeArray.h:1108
static void registerType()
Register this attribute type along with a factory function.
Definition AttributeArray.h:1154
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition AttributeArray.h:1249
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition AttributeArray.h:1734
static void unregisterType()
Remove this attribute type from the registry.
Definition AttributeArray.h:1162
const StorageType * data() const
Definition AttributeArray.h:716
void loadData() const override
Ensures all data is in-core.
Definition AttributeArray.h:1547
void read(std::istream &) override
Read attribute data from a stream.
Definition AttributeArray.h:1563
ValueType get(Index n) const
Return the value at index n.
Definition AttributeArray.h:1332
TypedAttributeArray(TypedAttributeArray &&)=delete
Move constructor disabled.
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition AttributeArray.h:1135
TypedAttributeArray(const TypedAttributeArray &)
Definition AttributeArray.h:1086
static void fill(AttributeArray *array, const ValueType &value)
Non-member equivalent to fill() that static_casts array to this TypedAttributeArray.
Definition AttributeArray.h:1507
static void collapse(AttributeArray *array, const ValueType &value)
Non-member equivalent to collapse() that static_casts array to this TypedAttributeArray.
Definition AttributeArray.h:1482
const NamePair & type() const override
Return the name of this attribute's type.
Definition AttributeArray.h:562
static const TypedAttributeArray & cast(const AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition AttributeArray.h:1192
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition AttributeArray.h:1269
Index size() const override
Return the number of elements in this array.
Definition AttributeArray.h:572
void collapse() override
Replace the existing array with a uniform zero value.
Definition AttributeArray.h:1460
Index dataSize() const override
Return the size of the data in this array.
Definition AttributeArray.h:579
Codec_ Codec
Definition AttributeArray.h:518
~TypedAttributeArray() override
Definition AttributeArray.h:543
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition AttributeArray.h:1422
static bool isRegistered()
Return true if this attribute type is registered.
Definition AttributeArray.h:1146
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition AttributeArray.h:1295
StorageType * data()
Definition AttributeArray.h:715
static ValueType getUnsafe(const AttributeArray *array, const Index n)
Definition AttributeArray.h:1361
const StorageType * constData() const
Return the raw data buffer.
Definition AttributeArray.h:709
void fill(const ValueType &value)
void collapse(const ValueType &uniformValue)
Replace the existing array with the given uniform value.
Definition AttributeArray.h:1468
void set(Index n, const T &value)
Set value at the given index n.
Definition AttributeArray.h:1406
Index stride() const override
Definition AttributeArray.h:576
static Ptr create(Index n, Index strideOrTotalSize=1, bool constantStride=true, const Metadata *metadata=nullptr)
Return a new attribute array of the given length n and stride with uniform value zero.
Definition AttributeArray.h:1170
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition AttributeArray.h:587
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition AttributeArray.h:1835
Name valueType() const override
Return the name of the value type of a single element in this array (e.g., "float" or "vec3d").
Definition AttributeArray.h:584
void setUnsafe(Index n, const T &value)
Set value at the given index n (assumes in-core)
Definition AttributeArray.h:1397
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition AttributeArray.h:1369
static void setUnsafe(AttributeArray *array, const Index n, const ValueType &value)
Definition AttributeArray.h:1414
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition AttributeArray.h:1572
void get(Index n, T &value) const
Return the value at index n.
Definition AttributeArray.h:1353
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition logging.h:256
OPENVDB_API void bloscDecompress(char *uncompressedBuffer, const size_t expectedBytes, const size_t bufferBytes, const char *compressedBuffer)
Decompress into the supplied buffer. Will throw if decompression fails or uncompressed buffer has ins...
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
@ COMPRESS_BLOSC
Definition Compression.h:57
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:443
internal::half half
Definition Types.h:29
Definition AttributeArray.h:407
Definition IndexIterator.h:35
Definition AttributeArray.h:42
FloatT fixedPointToFloatingPoint(const IntegerT s)
Definition AttributeArray.h:62
IntegerT floatingPointToFixedPoint(const FloatT s)
Definition AttributeArray.h:51
std::string Name
Definition Name.h:19
Index32 Index
Definition Types.h:54
int16_t Int16
Definition Types.h:55
std::pair< Name, Name > NamePair
Definition AttributeArray.h:40
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:70
uint64_t Index64
Definition Types.h:53
const char * typeNameAsString()
Definition Types.h:516
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t *poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
Definition pnanovdb_validate_strides.h:20
static const bool IsVec
Definition Types.h:245
typename T::ValueType ElementType
Definition Types.h:247
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition AttributeArray.h:1967
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition AttributeArray.h:1964
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition AttributeArray.h:1972
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:1963
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition AttributeArray.h:1941
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition AttributeArray.h:1943
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition AttributeArray.h:1947
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:1942
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition AttributeArray.h:1953
Accessor base class for AttributeArray storage where type is not available.
Definition AttributeArray.h:382
virtual ~AccessorBase()=default
Definition AttributeArray.h:388
SetterPtr mSetter
Definition AttributeArray.h:397
GetterPtr mGetter
Definition AttributeArray.h:396
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition AttributeArray.h:391
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:389
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition AttributeArray.h:390
ValuePtr mFiller
Definition AttributeArray.h:399
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition AttributeArray.h:393
ValuePtr mCollapser
Definition AttributeArray.h:398
Definition AttributeArray.h:480
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition AttributeArray.h:480
Definition AttributeArray.h:478
static void encode(const ValueType &, StorageType &)
Definition AttributeArray.h:932
static void decode(const StorageType &, ValueType &)
Definition AttributeArray.h:919
static const char * name()
Definition AttributeArray.h:485
Definition AttributeArray.h:439
T Type
Definition AttributeArray.h:439
Definition AttributeArray.h:437
static void encode(const ValueType &, ValueType &)
Definition AttributeArray.h:894
static const char * name()
Definition AttributeArray.h:443
static void decode(const ValueType &, ValueType &)
Definition AttributeArray.h:886
Definition AttributeArray.h:460
static ValueType decode(const ValueType &value)
Definition AttributeArray.h:463
static ValueType encode(const ValueType &value)
Definition AttributeArray.h:462
static const char * name()
Definition AttributeArray.h:461
static const char * name()
Definition AttributeArrayString.h:45
Definition AttributeArray.h:450
typename attribute_traits::TruncateTrait< T >::Type Type
Definition AttributeArray.h:450
Definition AttributeArray.h:448
static void encode(const ValueType &, StorageType &)
Definition AttributeArray.h:910
static void decode(const StorageType &, ValueType &)
Definition AttributeArray.h:902
static const char * name()
Definition AttributeArray.h:454
Definition AttributeArray.h:469
static ValueType decode(const ValueType &value)
Definition AttributeArray.h:472
static ValueType encode(const ValueType &value)
Definition AttributeArray.h:471
static const char * name()
Definition AttributeArray.h:470
Definition AttributeArray.h:497
StorageType Type
Definition AttributeArray.h:497
Definition AttributeArray.h:493
uint16_t StorageType
Definition AttributeArray.h:494
static void decode(const StorageType &, math::Vec3< T > &)
Definition AttributeArray.h:944
static void encode(const math::Vec3< T > &, StorageType &)
Definition AttributeArray.h:952
static const char * name()
Definition AttributeArray.h:501
Definition AttributeArray.h:433
math::half Type
Definition AttributeArray.h:409
short Type
Definition AttributeArray.h:410
math::Vec3< typename TruncateTrait< T >::Type > Type
Definition AttributeArray.h:413
Definition AttributeArray.h:408
uint16_t Type
Definition AttributeArray.h:418
math::Vec3< uint16_t > Type
Definition AttributeArray.h:423
uint8_t Type
Definition AttributeArray.h:417
math::Vec3< uint8_t > Type
Definition AttributeArray.h:420
Definition AttributeArray.h:416
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218