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>;
192#if OPENVDB_ABI_VERSION_NUMBER < 14
193 OPENVDB_DEPRECATED_MESSAGE(
"Use memUsage() instead. This method is deprecated and will be removed. Delayed loading is no longer supported.")
194 virtual
size_t memUsageIfLoaded() const = 0;
201 bool constantStride =
true,
213 template<
typename AttributeArrayType>
214 bool isType()
const {
return this->
type() == AttributeArrayType::attributeType(); }
217 template<
typename ValueType>
243 template<
typename IterT>
248 template<
typename IterT>
255 virtual void expand(
bool fill =
true) = 0;
291 virtual void read(std::istream&) = 0;
294 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
296 virtual void write(std::ostream&)
const = 0;
303 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
309 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
320#if OPENVDB_ABI_VERSION_NUMBER < 14
322 virtual
void loadData() const = 0;
325 virtual
bool isDataLoaded() const = 0;
338 friend class ::TestAttributeArray;
345 virtual char* dataAsByteArray() = 0;
346 virtual const char* dataAsByteArray()
const = 0;
349 template <
typename IterT>
350 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
351 bool rangeChecking =
true);
373#if OPENVDB_ABI_VERSION_NUMBER < 14
374 std::atomic<Index32> mOutOfCore{0};
444 template <
typename T>
447 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
448 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
449 static const char*
name() {
return "null"; }
455 template <
typename T>
458 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
459 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
460 static const char*
name() {
return "trnc"; }
467 static const char*
name() {
return "fxpt"; }
468 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
469 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
476 static const char*
name() {
return "ufxpt"; }
477 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
478 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
482template <
bool OneByte,
typename Range=PositionRange>
485 template <
typename T>
488 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
489 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
492 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
502 template <
typename T>
507 static const char*
name() {
return "uvec"; }
516template<
typename ValueType_,
typename Codec_ = NullCodec>
520 using Ptr = std::shared_ptr<TypedAttributeArray>;
521 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
525 using StorageType =
typename Codec::template Storage<ValueType>::Type;
557 const Metadata* metadata =
nullptr);
620#if OPENVDB_ABI_VERSION_NUMBER < 14
621 OPENVDB_DEPRECATED_MESSAGE(
"Use memUsage() instead. This method is deprecated and will be removed. Delayed loading is no longer supported.")
622 size_t memUsageIfLoaded()
const override {
return memUsage(); }
632 template<
typename T>
void get(
Index n, T& value)
const;
645 template<
typename T>
void set(
Index n,
const T& value);
674 void read(std::istream&)
override;
678 void write(std::ostream& os,
bool outputTransient)
const override;
680 void write(std::ostream&)
const override;
688 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
695 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
704#if OPENVDB_ABI_VERSION_NUMBER < 14
706 void loadData()
const override { }
708 OPENVDB_DEPRECATED_MESSAGE(
"Always returns true. This method is deprecated and will be removed. Delayed loading is no longer supported.")
709 bool isDataLoaded()
const override {
return true; }
726 friend class ::TestAttributeArray;
731 inline void setOutOfCore(
const bool);
737 char* dataAsByteArray()
override;
738 const char* dataAsByteArray()
const override;
740 size_t arrayMemUsage()
const;
750 std::unique_ptr<StorageType[]> mData;
752 Index mStrideOrTotalSize;
761template <
typename ValueType,
typename CodecType = UnknownCodec>
766 using Ptr = std::shared_ptr<Handle>;
805 friend class ::TestAttributeArray;
807 template <
bool IsUnknownCodec>
808 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
810 template <
bool IsUnknownCodec>
811 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
813 template <
bool IsUnknownCodec>
814 typename std::enable_if<IsUnknownCodec, ValueType>::type
get(
Index index)
const;
816 template <
bool IsUnknownCodec>
817 typename std::enable_if<!IsUnknownCodec, ValueType>::type
get(
Index index)
const;
819 Index mStrideOrTotalSize;
821 bool mCollapseOnDestruction;
829template <
typename ValueType,
typename CodecType = UnknownCodec>
834 using Ptr = std::shared_ptr<Handle>;
856 void fill(
const ValueType& value);
864 friend class ::TestAttributeArray;
866 template <
bool IsUnknownCodec>
867 typename std::enable_if<IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
869 template <
bool IsUnknownCodec>
870 typename std::enable_if<!IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
880template<
typename ValueType>
888template<
typename ValueType>
896template<
typename StorageType,
typename ValueType>
900 val =
static_cast<ValueType
>(data);
904template<
typename StorageType,
typename ValueType>
908 data =
static_cast<StorageType
>(val);
912template <
bool OneByte,
typename Range>
913template<
typename StorageType,
typename ValueType>
925template <
bool OneByte,
typename Range>
926template<
typename StorageType,
typename ValueType>
958template <
typename IterT>
959void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
969 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
970 char*
const targetBuffer = this->dataAsByteArray();
973 if (rangeChecking && this->isUniform()) {
977 const bool sourceIsUniform = sourceArray.
isUniform();
979 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
980 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
982 for (IterT it(iter); it; ++it) {
983 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
984 const Index targetIndex = it.targetIndex();
987 if (sourceIndex >= sourceDataSize) {
989 "Cannot copy array data as source index exceeds size of source array.");
991 if (targetIndex >= targetDataSize) {
993 "Cannot copy array data as target index exceeds size of target array.");
1002 const size_t targetOffset(targetIndex * bytes);
1003 const size_t sourceOffset(sourceIndex * bytes);
1005 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1009template <
typename IterT>
1012 this->doCopyValues(sourceArray, iter,
false);
1015template <
typename IterT>
1033 this->doCopyValues(sourceArray, iter,
true);
1047template<
typename ValueType_,
typename Codec_>
1053 , mStrideOrTotalSize(strideOrTotalSize)
1055 if (constantStride) {
1057 if (strideOrTotalSize == 0) {
1059 "stride to be at least one.")
1064 if (mStrideOrTotalSize < n) {
1066 "a total size of at least the number of elements in the array.")
1069 mSize = std::max(
Index(1), mSize);
1070 mStrideOrTotalSize = std::max(
Index(1), mStrideOrTotalSize);
1071 Codec::encode(uniformValue, this->
data()[0]);
1075template<
typename ValueType_,
typename Codec_>
1082template<
typename ValueType_,
typename Codec_>
1084 const tbb::spin_mutex::scoped_lock& lock)
1087 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1091 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1096template<
typename ValueType_,
typename Codec_>
1097TypedAttributeArray<ValueType_, Codec_>&
1102 tbb::spin_mutex::scoped_lock lock(
mMutex);
1103 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1110 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1115 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1123template<
typename ValueType_,
typename Codec_>
1134template<
typename ValueType_,
typename Codec_>
1142template<
typename ValueType_,
typename Codec_>
1150template<
typename ValueType_,
typename Codec_>
1158template<
typename ValueType_,
typename Codec_>
1170template<
typename ValueType_,
typename Codec_>
1180template<
typename ValueType_,
typename Codec_>
1190template<
typename ValueType_,
typename Codec_>
1198template<
typename ValueType_,
typename Codec_>
1200TypedAttributeArray<ValueType_, Codec_>::arrayMemUsage()
const
1202 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1206template<
typename ValueType_,
typename Codec_>
1208TypedAttributeArray<ValueType_, Codec_>::allocate()
1212 mData.reset(
new StorageType[1]);
1215 const size_t size(this->dataSize());
1217 mData.reset(
new StorageType[size]);
1222template<
typename ValueType_,
typename Codec_>
1224TypedAttributeArray<ValueType_, Codec_>::deallocate()
1226 if (mData) mData.reset();
1230template<
typename ValueType_,
typename Codec_>
1236 if (std::is_same<ValueType, Quats>::value ||
1237 std::is_same<ValueType, Quatd>::value ||
1238 std::is_same<ValueType, Mat3s>::value ||
1239 std::is_same<ValueType, Mat3d>::value ||
1240 std::is_same<ValueType, Mat4s>::value ||
1241 std::is_same<ValueType, Mat4d>::value)
return true;
1246 return std::is_floating_point<ElementT>::value || std::is_same<math::half, ElementT>::value;
1250template<
typename ValueType_,
typename Codec_>
1255 return std::is_class<ValueType>::value && !std::is_same<math::half, ValueType>::value;
1259template<
typename ValueType_,
typename Codec_>
1267template<
typename ValueType_,
typename Codec_>
1272 return !this->
valueType().compare(0, 4,
"quat");
1276template<
typename ValueType_,
typename Codec_>
1281 return !this->
valueType().compare(0, 3,
"mat");
1285template<
typename ValueType_,
typename Codec_>
1289 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1293template<
typename ValueType_,
typename Codec_>
1305template<
typename ValueType_,
typename Codec_>
1315template<
typename ValueType_,
typename Codec_>
1320 val =
static_cast<T
>(this->
getUnsafe(n));
1324template<
typename ValueType_,
typename Codec_>
1329 val =
static_cast<T
>(this->
get(n));
1333template<
typename ValueType_,
typename Codec_>
1341template<
typename ValueType_,
typename Codec_>
1355template<
typename ValueType_,
typename Codec_>
1366template<
typename ValueType_,
typename Codec_>
1375template<
typename ValueType_,
typename Codec_>
1384template<
typename ValueType_,
typename Codec_>
1392template<
typename ValueType_,
typename Codec_>
1401 tbb::spin_mutex::scoped_lock lock(
mMutex);
1408 for (
Index i = 0; i < this->dataSize(); ++i) this->
data()[i] = val;
1413template<
typename ValueType_,
typename Codec_>
1420 const ValueType_ val = this->
get(0);
1421 for (
Index i = 1; i < this->dataSize(); i++) {
1430template<
typename ValueType_,
typename Codec_>
1438template<
typename ValueType_,
typename Codec_>
1443 tbb::spin_mutex::scoped_lock lock(
mMutex);
1448 Codec::encode(uniformValue, this->
data()[0]);
1452template<
typename ValueType_,
typename Codec_>
1460template<
typename ValueType_,
typename Codec_>
1466 Codec::encode(value, this->
data()[i]);
1471template<
typename ValueType_,
typename Codec_>
1479template<
typename ValueType_,
typename Codec_>
1488template<
typename ValueType_,
typename Codec_>
1495 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1499 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1501 uint8_t
flags = uint8_t(0);
1502 is.read(
reinterpret_cast<char*
>(&
flags),
sizeof(uint8_t));
1505 uint8_t serializationFlags = uint8_t(0);
1506 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1509 is.read(
reinterpret_cast<char*
>(&
size),
sizeof(
Index));
1518 if (serializationFlags >= 0x10) {
1533 is.read(
reinterpret_cast<char*
>(&
stride),
sizeof(
Index));
1534 mStrideOrTotalSize =
stride;
1537 mStrideOrTotalSize = 1;
1546 if (mStrideOrTotalSize == 0 ||
1551 else if (mStrideOrTotalSize < mSize) {
1557template<
typename ValueType_,
typename Codec_>
1568 uint8_t bloscCompressed(0);
1569 if (!
mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1576 if (bloscCompressed != uint8_t(1) && mCompressedBytes < this->arrayMemUsage()) {
1588 if (bloscCompressed == uint8_t(1)) {
1593 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1595 if (newBuffer) buffer.reset(newBuffer.release());
1600 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1604template<
typename ValueType_,
typename Codec_>
1616 if (mCompressedBytes < this->arrayMemUsage()) {
1632 std::unique_ptr<char[]> buffer =
mPageHandle->read();
1633 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1649 uint8_t bloscCompressed(0);
1650 if (!
mIsUniform) inputStream.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1652 if (meta && meta->seekable()) {
1685template<
typename ValueType_,
typename Codec_>
1689 this->
write(os,
false);
1693template<
typename ValueType_,
typename Codec_>
1702template<
typename ValueType_,
typename Codec_>
1706 if (!outputTransient && this->
isTransient())
return;
1713 uint8_t serializationFlags(0);
1715 Index strideOrTotalSize(mStrideOrTotalSize);
1716 bool strideOfOne(this->
stride() == 1);
1720 size_t compressedBytes = 0;
1730 if (bloscCompression && paged) serializationFlags |=
WRITEPAGED;
1732 else if (bloscCompression)
1736 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1737 const size_t inBytes = this->arrayMemUsage();
1744 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1748 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1749 os.write(
reinterpret_cast<const char*
>(&
flags),
sizeof(uint8_t));
1750 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1751 os.write(
reinterpret_cast<const char*
>(&
size),
sizeof(
Index));
1754 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&strideOrTotalSize),
sizeof(
Index));
1758template<
typename ValueType_,
typename Codec_>
1762 if (!outputTransient && this->
isTransient())
return;
1769 os.write(
reinterpret_cast<const char*
>(this->
data()),
sizeof(
StorageType));
1773 std::unique_ptr<char[]> compressedBuffer;
1774 size_t compressedBytes = 0;
1775 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1776 const size_t inBytes = this->arrayMemUsage();
1778 if (compressedBuffer) {
1779 uint8_t bloscCompressed(1);
1780 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1781 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
1784 uint8_t bloscCompressed(0);
1785 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1786 os.write(
reinterpret_cast<const char*
>(this->
data()), inBytes);
1791 uint8_t bloscCompressed(0);
1792 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1793 os.write(
reinterpret_cast<const char*
>(this->
data()), this->arrayMemUsage());
1798template<
typename ValueType_,
typename Codec_>
1802 if (!outputTransient && this->
isTransient())
return;
1806 if (!bloscCompression) {
1815 os.
write(
reinterpret_cast<const char*
>(this->
data()), this->arrayMemUsage());
1819template<
typename ValueType_,
typename Codec_>
1834template<
typename ValueType_,
typename Codec_>
1836TypedAttributeArray<ValueType_, Codec_>::isEqual(
const AttributeArray& other)
const
1839 if(!otherT)
return false;
1840 if(this->mSize != otherT->mSize ||
1841 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1843 this->attributeType() != this->attributeType())
return false;
1845 const StorageType *target = this->data(), *source = otherT->
data();
1846 if (!target && !source)
return true;
1847 if (!target || !source)
return false;
1848 Index n = this->mIsUniform ? 1 : mSize;
1854template<
typename ValueType_,
typename Codec_>
1856TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
1858 return reinterpret_cast<char*
>(this->data());
1862template<
typename ValueType_,
typename Codec_>
1864TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
1866 return reinterpret_cast<const char*
>(this->data());
1874template <
typename CodecType,
typename ValueType>
1895template <
typename ValueType>
1903 return (*functor)(array, n);
1908 (*functor)(array, n, value);
1917template <
typename ValueType,
typename CodecType>
1918typename AttributeHandle<ValueType, CodecType>::Ptr
1925template <
typename ValueType,
typename CodecType>
1930 , mCollapseOnDestruction(collapseOnDestruction &&
array.isStreaming())
1932 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
1949template <
typename ValueType,
typename CodecType>
1956template <
typename ValueType,
typename CodecType>
1957template <
bool IsUnknownCodec>
1958typename std::enable_if<IsUnknownCodec, bool>::type
1959AttributeHandle<ValueType, CodecType>::compatibleType()
const
1966template <
typename ValueType,
typename CodecType>
1967template <
bool IsUnknownCodec>
1968typename std::enable_if<!IsUnknownCodec, bool>::type
1969AttributeHandle<ValueType, CodecType>::compatibleType()
const
1973 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
1976template <
typename ValueType,
typename CodecType>
1983template <
typename ValueType,
typename CodecType>
1991template <
typename ValueType,
typename CodecType>
1997template <
typename ValueType,
typename CodecType>
1998template <
bool IsUnknownCodec>
1999typename std::enable_if<IsUnknownCodec, ValueType>::type
2004 return (*mGetter)(mArray,
index);
2007template <
typename ValueType,
typename CodecType>
2008template <
bool IsUnknownCodec>
2009typename std::enable_if<!IsUnknownCodec, ValueType>::type
2017template <
typename ValueType,
typename CodecType>
2020 return mArray->isUniform();
2023template <
typename ValueType,
typename CodecType>
2026 return mArray->hasConstantStride();
2033template <
typename ValueType,
typename CodecType>
2041template <
typename ValueType,
typename CodecType>
2048template <
typename ValueType,
typename CodecType>
2054template <
typename ValueType,
typename CodecType>
2060template <
typename ValueType,
typename CodecType>
2066template <
typename ValueType,
typename CodecType>
2072template <
typename ValueType,
typename CodecType>
2078template <
typename ValueType,
typename CodecType>
2084template <
typename ValueType,
typename CodecType>
2090template <
typename ValueType,
typename CodecType>
2091template <
bool IsUnknownCodec>
2092typename std::enable_if<IsUnknownCodec, void>::type
2100template <
typename ValueType,
typename CodecType>
2101template <
bool IsUnknownCodec>
2102typename std::enable_if<!IsUnknownCodec, void>::type
2110template <
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
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.
void skip(PageHandle::Ptr &pageHandle, std::streamsize n)
Skip past the page data referenced by pageHandle without reading or decompressing it.
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:249
std::ostream & getOutputStream()
Set and get the output stream.
Definition StreamCompression.h:262
bool sizeOnly() const
Definition StreamCompression.h:259
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:335
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:274
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
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:267
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition AttributeArray.h:214
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:1010
uint8_t mFlags
Definition AttributeArray.h:371
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)
uint8_t flags() const
Retrieve the attribute array flags.
Definition AttributeArray.h:288
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition AttributeArray.h:218
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:1016
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.
void skipPagedBuffers(compression::PagedInputStream &)
Definition AttributeArray.h:1643
virtual bool valueTypeIsClass() const =0
Return true if the value type is a class (ie vector, matrix or quaternion return true)
uint8_t mUsePagedRead
Definition AttributeArray.h:372
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:370
bool operator!=(const AttributeArray &other) const
Definition AttributeArray.h:332
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition AttributeArray.h:282
std::unique_ptr< compression::PageHandle > mPageHandle
Definition AttributeArray.h:378
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").
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:285
virtual const NamePair & type() const =0
Return the name of this attribute's type.
size_t mCompressedBytes
Definition AttributeArray.h:379
bool mIsUniform
Definition AttributeArray.h:369
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:1950
Index size() const
Definition AttributeArray.h:785
void(*)(AttributeArray *array, const ValueType &value) ValuePtr
Definition AttributeArray.h:772
SetterPtr mSetter
Definition AttributeArray.h:800
Index stride() const
Definition AttributeArray.h:784
std::shared_ptr< Handle > Ptr
Definition AttributeArray.h:766
GetterPtr mGetter
Definition AttributeArray.h:799
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition AttributeArray.h:771
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition AttributeArray.h:1919
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition AttributeArray.h:1926
ValuePtr mFiller
Definition AttributeArray.h:802
ValueType get(Index n, Index m=0) const
Definition AttributeArray.h:1992
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:770
AttributeHandle(const AttributeHandle &)=default
AttributeHandle< ValueType, CodecType > Handle
Definition AttributeArray.h:765
ValuePtr mCollapser
Definition AttributeArray.h:801
const AttributeArray & array() const
const AttributeArray * mArray
Definition AttributeArray.h:797
bool isUniform() const
Definition AttributeArray.h:2018
std::unique_ptr< Handle > UniquePtr
Definition AttributeArray.h:767
bool hasConstantStride() const
Definition AttributeArray.h:2024
AttributeHandle & operator=(const AttributeHandle &)=default
Index index(Index n, Index m) const
Definition AttributeArray.h:1984
virtual ~AttributeWriteHandle()=default
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition AttributeArray.h:2042
std::shared_ptr< Handle > Ptr
Definition AttributeArray.h:834
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition AttributeArray.h:2073
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition AttributeArray.h:2067
void set(Index n, const ValueType &value)
Definition AttributeArray.h:2049
void expand(bool fill=true)
std::unique_ptr< Handle > ScopedPtr
Definition AttributeArray.h:835
AttributeWriteHandle< ValueType, CodecType > Handle
Definition AttributeArray.h:833
static Ptr create(AttributeArray &array, const bool expand=true)
Definition AttributeArray.h:2035
void set(Index n, Index m, const ValueType &value)
Definition AttributeArray.h:2055
void fill(const ValueType &value)
void collapse(const ValueType &uniformValue)
Definition AttributeArray.h:2079
Typed class for storing attribute data.
Definition AttributeArray.h:518
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition AttributeArray.h:596
void write(std::ostream &) const override
Write attribute data to a stream, don't write transient attributes.
Definition AttributeArray.h:1687
void getUnsafe(Index n, T &value) const
Return the value at index n (assumes in-core)
Definition AttributeArray.h:1318
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition AttributeArray.h:1295
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition AttributeArray.h:652
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition AttributeArray.h:1559
std::shared_ptr< TypedAttributeArray > Ptr
Definition AttributeArray.h:520
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition AttributeArray.h:1821
void write(std::ostream &os, bool outputTransient) const override
Definition AttributeArray.h:1695
typename Codec::template Storage< ValueType >::Type StorageType
Definition AttributeArray.h:525
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition AttributeArray.h:1287
ValueType_ ValueType
Definition AttributeArray.h:523
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:1048
std::shared_ptr< const TypedAttributeArray > ConstPtr
Definition AttributeArray.h:521
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition AttributeArray.h:1261
bool validData() const
Definition AttributeArray.h:723
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition AttributeArray.h:1172
TypedAttributeArray & operator=(TypedAttributeArray &&)=delete
Move assignment operator disabled.
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition AttributeArray.h:1760
AttributeArray::Ptr copy() const override
Definition AttributeArray.h:1192
Index storageTypeSize() const override
Definition AttributeArray.h:600
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition AttributeArray.h:1269
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition AttributeArray.h:1606
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition AttributeArray.h:1357
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition AttributeArray.h:1098
static void registerType()
Register this attribute type along with a factory function.
Definition AttributeArray.h:1144
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition AttributeArray.h:1232
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition AttributeArray.h:1704
static void unregisterType()
Remove this attribute type from the registry.
Definition AttributeArray.h:1152
const StorageType * data() const
Definition AttributeArray.h:720
void read(std::istream &) override
Read attribute data from a stream.
Definition AttributeArray.h:1481
ValueType get(Index n) const
Return the value at index n.
Definition AttributeArray.h:1307
TypedAttributeArray(TypedAttributeArray &&)=delete
Move constructor disabled.
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition AttributeArray.h:1125
TypedAttributeArray(const TypedAttributeArray &)
Definition AttributeArray.h:1076
static void fill(AttributeArray *array, const ValueType &value)
Non-member equivalent to fill() that static_casts array to this TypedAttributeArray.
Definition AttributeArray.h:1473
static void collapse(AttributeArray *array, const ValueType &value)
Non-member equivalent to collapse() that static_casts array to this TypedAttributeArray.
Definition AttributeArray.h:1454
const NamePair & type() const override
Return the name of this attribute's type.
Definition AttributeArray.h:568
static const TypedAttributeArray & cast(const AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition AttributeArray.h:1182
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition AttributeArray.h:1252
Index size() const override
Return the number of elements in this array.
Definition AttributeArray.h:578
void collapse() override
Replace the existing array with a uniform zero value.
Definition AttributeArray.h:1432
Index dataSize() const override
Return the size of the data in this array.
Definition AttributeArray.h:585
Codec_ Codec
Definition AttributeArray.h:524
~TypedAttributeArray() override
Definition AttributeArray.h:549
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition AttributeArray.h:1394
static bool isRegistered()
Return true if this attribute type is registered.
Definition AttributeArray.h:1136
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition AttributeArray.h:1278
StorageType * data()
Definition AttributeArray.h:719
static ValueType getUnsafe(const AttributeArray *array, const Index n)
Definition AttributeArray.h:1335
const StorageType * constData() const
Return the raw data buffer.
Definition AttributeArray.h:713
void fill(const ValueType &value)
void collapse(const ValueType &uniformValue)
Replace the existing array with the given uniform value.
Definition AttributeArray.h:1440
void set(Index n, const T &value)
Set value at the given index n.
Definition AttributeArray.h:1378
Index stride() const override
Definition AttributeArray.h:582
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:1160
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition AttributeArray.h:593
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition AttributeArray.h:1800
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:590
void setUnsafe(Index n, const T &value)
Set value at the given index n (assumes in-core)
Definition AttributeArray.h:1369
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition AttributeArray.h:1343
static void setUnsafe(AttributeArray *array, const Index n, const ValueType &value)
Definition AttributeArray.h:1386
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition AttributeArray.h:1490
void get(Index n, T &value) const
Return the value at index n.
Definition AttributeArray.h:1327
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition logging.h:163
size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
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...
void bloscValidateCompressedBytes(const char *buffer, const size_t bufferBytes)
Throws an IoError if the Blosc header of buffer does not fit in bufferBytes or reports more compresse...
@ COMPRESS_BLOSC
Definition Compression.h:56
uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:465
internal::half half
Definition HalfDecl.h:25
Definition AttributeArray.h:413
Definition IndexIterator.h:35
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:34
int16_t Int16
Definition Types.h:35
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:71
uint64_t Index64
Definition Types.h:33
const char * typeNameAsString()
Definition Types.h:587
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
static const bool IsVec
Definition Types.h:297
typename T::ValueType ElementType
Definition Types.h:299
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition AttributeArray.h:1902
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition AttributeArray.h:1899
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition AttributeArray.h:1907
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:1898
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition AttributeArray.h:1876
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition AttributeArray.h:1878
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition AttributeArray.h:1882
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:1877
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition AttributeArray.h:1888
Accessor base class for AttributeArray storage where type is not available.
Definition AttributeArray.h:388
virtual ~AccessorBase()=default
Definition AttributeArray.h:394
SetterPtr mSetter
Definition AttributeArray.h:403
GetterPtr mGetter
Definition AttributeArray.h:402
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition AttributeArray.h:397
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:395
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition AttributeArray.h:396
ValuePtr mFiller
Definition AttributeArray.h:405
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition AttributeArray.h:399
ValuePtr mCollapser
Definition AttributeArray.h:404
Definition AttributeArray.h:486
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition AttributeArray.h:486
Definition AttributeArray.h:484
static void encode(const ValueType &, StorageType &)
Definition AttributeArray.h:928
static void decode(const StorageType &, ValueType &)
Definition AttributeArray.h:915
static const char * name()
Definition AttributeArray.h:491
Definition AttributeArray.h:445
T Type
Definition AttributeArray.h:445
Definition AttributeArray.h:443
static void encode(const ValueType &, ValueType &)
Definition AttributeArray.h:890
static const char * name()
Definition AttributeArray.h:449
static void decode(const ValueType &, ValueType &)
Definition AttributeArray.h:882
Definition AttributeArray.h:466
static ValueType decode(const ValueType &value)
Definition AttributeArray.h:469
static ValueType encode(const ValueType &value)
Definition AttributeArray.h:468
static const char * name()
Definition AttributeArray.h:467
static const char * name()
Definition AttributeArrayString.h:45
Definition AttributeArray.h:456
typename attribute_traits::TruncateTrait< T >::Type Type
Definition AttributeArray.h:456
Definition AttributeArray.h:454
static void encode(const ValueType &, StorageType &)
Definition AttributeArray.h:906
static void decode(const StorageType &, ValueType &)
Definition AttributeArray.h:898
static const char * name()
Definition AttributeArray.h:460
Definition AttributeArray.h:475
static ValueType decode(const ValueType &value)
Definition AttributeArray.h:478
static ValueType encode(const ValueType &value)
Definition AttributeArray.h:477
static const char * name()
Definition AttributeArray.h:476
Definition AttributeArray.h:503
StorageType Type
Definition AttributeArray.h:503
Definition AttributeArray.h:499
uint16_t StorageType
Definition AttributeArray.h:500
static void decode(const StorageType &, math::Vec3< T > &)
Definition AttributeArray.h:940
static void encode(const math::Vec3< T > &, StorageType &)
Definition AttributeArray.h:948
static const char * name()
Definition AttributeArray.h:507
Definition AttributeArray.h:439
math::half Type
Definition AttributeArray.h:415
short Type
Definition AttributeArray.h:416
math::Vec3< typename TruncateTrait< T >::Type > Type
Definition AttributeArray.h:419
Definition AttributeArray.h:414
uint16_t Type
Definition AttributeArray.h:424
math::Vec3< uint16_t > Type
Definition AttributeArray.h:429
uint8_t Type
Definition AttributeArray.h:423
math::Vec3< uint8_t > Type
Definition AttributeArray.h:426
Definition AttributeArray.h:422
#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:291