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;
820 Index mStrideOrTotalSize;
822 bool mCollapseOnDestruction;
830template <
typename ValueType,
typename CodecType = UnknownCodec>
835 using Ptr = std::shared_ptr<Handle>;
857 void fill(
const ValueType& value);
865 friend class ::TestAttributeArray;
867 template <
bool IsUnknownCodec>
868 typename std::enable_if<IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
870 template <
bool IsUnknownCodec>
871 typename std::enable_if<!IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
881template<
typename ValueType>
889template<
typename ValueType>
897template<
typename StorageType,
typename ValueType>
901 val =
static_cast<ValueType
>(data);
905template<
typename StorageType,
typename ValueType>
909 data =
static_cast<StorageType
>(val);
913template <
bool OneByte,
typename Range>
914template<
typename StorageType,
typename ValueType>
926template <
bool OneByte,
typename Range>
927template<
typename StorageType,
typename ValueType>
959template <
typename IterT>
960void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
972 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
973 char*
const targetBuffer = this->dataAsByteArray();
976 if (rangeChecking && this->isUniform()) {
980 const bool sourceIsUniform = sourceArray.
isUniform();
982 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
983 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
985 for (IterT it(iter); it; ++it) {
986 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
987 const Index targetIndex = it.targetIndex();
990 if (sourceIndex >= sourceDataSize) {
992 "Cannot copy array data as source index exceeds size of source array.");
994 if (targetIndex >= targetDataSize) {
996 "Cannot copy array data as target index exceeds size of target array.");
1005 const size_t targetOffset(targetIndex * bytes);
1006 const size_t sourceOffset(sourceIndex * bytes);
1008 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1012template <
typename IterT>
1015 this->doCopyValues(sourceArray, iter,
false);
1018template <
typename IterT>
1040 this->doCopyValues(sourceArray, iter,
true);
1054template<
typename ValueType_,
typename Codec_>
1060 , mStrideOrTotalSize(strideOrTotalSize)
1062 if (constantStride) {
1064 if (strideOrTotalSize == 0) {
1066 "stride to be at least one.")
1071 if (mStrideOrTotalSize < n) {
1073 "a total size of at least the number of elements in the array.")
1076 mSize = std::max(
Index(1), mSize);
1077 mStrideOrTotalSize = std::max(
Index(1), mStrideOrTotalSize);
1078 Codec::encode(uniformValue, this->
data()[0]);
1082template<
typename ValueType_,
typename Codec_>
1089template<
typename ValueType_,
typename Codec_>
1091 const tbb::spin_mutex::scoped_lock& lock)
1094 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1098 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1103template<
typename ValueType_,
typename Codec_>
1104TypedAttributeArray<ValueType_, Codec_>&
1109 tbb::spin_mutex::scoped_lock lock(
mMutex);
1110 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1117 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1122 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1130template<
typename ValueType_,
typename Codec_>
1141template<
typename ValueType_,
typename Codec_>
1149template<
typename ValueType_,
typename Codec_>
1157template<
typename ValueType_,
typename Codec_>
1165template<
typename ValueType_,
typename Codec_>
1177template<
typename ValueType_,
typename Codec_>
1187template<
typename ValueType_,
typename Codec_>
1197template<
typename ValueType_,
typename Codec_>
1205template<
typename ValueType_,
typename Codec_>
1207TypedAttributeArray<ValueType_, Codec_>::arrayMemUsage()
const
1209 if (this->isOutOfCore())
return 0;
1211 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1215template<
typename ValueType_,
typename Codec_>
1217TypedAttributeArray<ValueType_, Codec_>::allocate()
1221 mData.reset(
new StorageType[1]);
1224 const size_t size(this->dataSize());
1226 mData.reset(
new StorageType[size]);
1231template<
typename ValueType_,
typename Codec_>
1233TypedAttributeArray<ValueType_, Codec_>::deallocate()
1236 if (this->isOutOfCore()) {
1237 this->setOutOfCore(
false);
1238 this->mPageHandle.reset();
1240 if (mData) mData.reset();
1244template<
typename ValueType_,
typename Codec_>
1250 if (std::is_same<ValueType, Quats>::value ||
1251 std::is_same<ValueType, Quatd>::value ||
1252 std::is_same<ValueType, Mat3s>::value ||
1253 std::is_same<ValueType, Mat3d>::value ||
1254 std::is_same<ValueType, Mat4s>::value ||
1255 std::is_same<ValueType, Mat4d>::value)
return true;
1260 return std::is_floating_point<ElementT>::value || std::is_same<math::half, ElementT>::value;
1264template<
typename ValueType_,
typename Codec_>
1269 return std::is_class<ValueType>::value && !std::is_same<math::half, ValueType>::value;
1273template<
typename ValueType_,
typename Codec_>
1281template<
typename ValueType_,
typename Codec_>
1286 return !this->
valueType().compare(0, 4,
"quat");
1290template<
typename ValueType_,
typename Codec_>
1295 return !this->
valueType().compare(0, 3,
"mat");
1299template<
typename ValueType_,
typename Codec_>
1303 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1307template<
typename ValueType_,
typename Codec_>
1315template<
typename ValueType_,
typename Codec_>
1327template<
typename ValueType_,
typename Codec_>
1338template<
typename ValueType_,
typename Codec_>
1343 val =
static_cast<T
>(this->
getUnsafe(n));
1347template<
typename ValueType_,
typename Codec_>
1352 val =
static_cast<T
>(this->
get(n));
1356template<
typename ValueType_,
typename Codec_>
1364template<
typename ValueType_,
typename Codec_>
1379template<
typename ValueType_,
typename Codec_>
1391template<
typename ValueType_,
typename Codec_>
1400template<
typename ValueType_,
typename Codec_>
1409template<
typename ValueType_,
typename Codec_>
1417template<
typename ValueType_,
typename Codec_>
1426 tbb::spin_mutex::scoped_lock lock(
mMutex);
1433 for (
Index i = 0; i < this->dataSize(); ++i) this->
data()[i] = val;
1438template<
typename ValueType_,
typename Codec_>
1445 const ValueType_ val = this->
get(0);
1446 for (
Index i = 1; i < this->dataSize(); i++) {
1455template<
typename ValueType_,
typename Codec_>
1463template<
typename ValueType_,
typename Codec_>
1468 tbb::spin_mutex::scoped_lock lock(
mMutex);
1473 Codec::encode(uniformValue, this->
data()[0]);
1477template<
typename ValueType_,
typename Codec_>
1485template<
typename ValueType_,
typename Codec_>
1490 tbb::spin_mutex::scoped_lock lock(
mMutex);
1497 Codec::encode(value, this->
data()[i]);
1502template<
typename ValueType_,
typename Codec_>
1510template<
typename ValueType_,
typename Codec_>
1518template<
typename ValueType_,
typename Codec_>
1520TypedAttributeArray<ValueType_, Codec_>::setOutOfCore(
const bool b)
1526template<
typename ValueType_,
typename Codec_>
1528TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1530 if (!(this->isOutOfCore()))
return;
1532 TypedAttributeArray<ValueType_, Codec_>* self =
1533 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1537 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1538 this->doLoadUnsafe();
1542template<
typename ValueType_,
typename Codec_>
1550template<
typename ValueType_,
typename Codec_>
1558template<
typename ValueType_,
typename Codec_>
1567template<
typename ValueType_,
typename Codec_>
1574 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1575 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1577 uint8_t
flags = uint8_t(0);
1578 is.read(
reinterpret_cast<char*
>(&
flags),
sizeof(uint8_t));
1581 uint8_t serializationFlags = uint8_t(0);
1582 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1585 is.read(
reinterpret_cast<char*
>(&
size),
sizeof(
Index));
1594 if (serializationFlags >= 0x10) {
1609 is.read(
reinterpret_cast<char*
>(&
stride),
sizeof(
Index));
1610 mStrideOrTotalSize =
stride;
1613 mStrideOrTotalSize = 1;
1618template<
typename ValueType_,
typename Codec_>
1627 tbb::spin_mutex::scoped_lock lock(
mMutex);
1631 uint8_t bloscCompressed(0);
1632 if (!
mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1642 if (bloscCompressed == uint8_t(1)) {
1646 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1648 if (newBuffer) buffer.reset(newBuffer.release());
1653 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1657template<
typename ValueType_,
typename Codec_>
1666#ifdef OPENVDB_USE_DELAYED_LOADING
1669 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is.
getInputStream());
1670 const bool delayLoad = (mappedFile.get() !=
nullptr);
1685 tbb::spin_mutex::scoped_lock lock(
mMutex);
1689#ifdef OPENVDB_USE_DELAYED_LOADING
1690 this->setOutOfCore(delayLoad);
1696#ifdef OPENVDB_USE_DELAYED_LOADING
1699 std::unique_ptr<char[]> buffer =
mPageHandle->read();
1700 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1702#ifdef OPENVDB_USE_DELAYED_LOADING
1712template<
typename ValueType_,
typename Codec_>
1716 this->
write(os,
false);
1720template<
typename ValueType_,
typename Codec_>
1729template<
typename ValueType_,
typename Codec_>
1733 if (!outputTransient && this->
isTransient())
return;
1740 uint8_t serializationFlags(0);
1742 Index strideOrTotalSize(mStrideOrTotalSize);
1743 bool strideOfOne(this->
stride() == 1);
1748 if (bloscCompression) this->doLoad();
1750 size_t compressedBytes = 0;
1760 if (bloscCompression && paged) serializationFlags |=
WRITEPAGED;
1762 else if (bloscCompression)
1766 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1767 const size_t inBytes = this->arrayMemUsage();
1774 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1778 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1779 os.write(
reinterpret_cast<const char*
>(&
flags),
sizeof(uint8_t));
1780 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1781 os.write(
reinterpret_cast<const char*
>(&
size),
sizeof(
Index));
1784 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&strideOrTotalSize),
sizeof(
Index));
1788template<
typename ValueType_,
typename Codec_>
1792 if (!outputTransient && this->
isTransient())
return;
1801 os.write(
reinterpret_cast<const char*
>(this->
data()),
sizeof(
StorageType));
1805 std::unique_ptr<char[]> compressedBuffer;
1806 size_t compressedBytes = 0;
1807 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1808 const size_t inBytes = this->arrayMemUsage();
1810 if (compressedBuffer) {
1811 uint8_t bloscCompressed(1);
1812 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1813 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
1816 uint8_t bloscCompressed(0);
1817 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1818 os.write(
reinterpret_cast<const char*
>(this->
data()), inBytes);
1823 uint8_t bloscCompressed(0);
1824 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1825 os.write(
reinterpret_cast<const char*
>(this->
data()), this->arrayMemUsage());
1830template<
typename ValueType_,
typename Codec_>
1834 if (!outputTransient && this->
isTransient())
return;
1838 if (!bloscCompression) {
1849 os.
write(
reinterpret_cast<const char*
>(this->
data()), this->arrayMemUsage());
1853template<
typename ValueType_,
typename Codec_>
1855TypedAttributeArray<ValueType_, Codec_>::doLoadUnsafe()
const
1857 if (!(this->isOutOfCore()))
return;
1866 std::unique_ptr<char[]> buffer = self->mPageHandle->read();
1868 self->mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1870 self->mPageHandle.reset();
1874 self->mOutOfCore =
false;
1878template<
typename ValueType_,
typename Codec_>
1893template<
typename ValueType_,
typename Codec_>
1895TypedAttributeArray<ValueType_, Codec_>::isEqual(
const AttributeArray& other)
const
1898 if(!otherT)
return false;
1899 if(this->mSize != otherT->mSize ||
1900 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1902 this->attributeType() != this->attributeType())
return false;
1907 const StorageType *target = this->data(), *source = otherT->
data();
1908 if (!target && !source)
return true;
1909 if (!target || !source)
return false;
1910 Index n = this->mIsUniform ? 1 : mSize;
1916template<
typename ValueType_,
typename Codec_>
1918TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
1920 return reinterpret_cast<char*
>(this->data());
1924template<
typename ValueType_,
typename Codec_>
1926TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
1928 return reinterpret_cast<const char*
>(this->data());
1936template <
typename CodecType,
typename ValueType>
1957template <
typename ValueType>
1965 return (*functor)(array, n);
1970 (*functor)(array, n, value);
1979template <
typename ValueType,
typename CodecType>
1980typename AttributeHandle<ValueType, CodecType>::Ptr
1987template <
typename ValueType,
typename CodecType>
1992 , mCollapseOnDestruction(collapseOnDestruction &&
array.isStreaming())
1994 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2015template <
typename ValueType,
typename CodecType>
2022template <
typename ValueType,
typename CodecType>
2023template <
bool IsUnknownCodec>
2024typename std::enable_if<IsUnknownCodec, bool>::type
2025AttributeHandle<ValueType, CodecType>::compatibleType()
const
2032template <
typename ValueType,
typename CodecType>
2033template <
bool IsUnknownCodec>
2034typename std::enable_if<!IsUnknownCodec, bool>::type
2035AttributeHandle<ValueType, CodecType>::compatibleType()
const
2039 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2042template <
typename ValueType,
typename CodecType>
2049template <
typename ValueType,
typename CodecType>
2057template <
typename ValueType,
typename CodecType>
2063template <
typename ValueType,
typename CodecType>
2064template <
bool IsUnknownCodec>
2065typename std::enable_if<IsUnknownCodec, ValueType>::type
2070 return (*mGetter)(mArray,
index);
2073template <
typename ValueType,
typename CodecType>
2074template <
bool IsUnknownCodec>
2075typename std::enable_if<!IsUnknownCodec, ValueType>::type
2083template <
typename ValueType,
typename CodecType>
2086 return mArray->isUniform();
2089template <
typename ValueType,
typename CodecType>
2092 return mArray->hasConstantStride();
2099template <
typename ValueType,
typename CodecType>
2107template <
typename ValueType,
typename CodecType>
2114template <
typename ValueType,
typename CodecType>
2120template <
typename ValueType,
typename CodecType>
2126template <
typename ValueType,
typename CodecType>
2132template <
typename ValueType,
typename CodecType>
2138template <
typename ValueType,
typename CodecType>
2144template <
typename ValueType,
typename CodecType>
2150template <
typename ValueType,
typename CodecType>
2156template <
typename ValueType,
typename CodecType>
2157template <
bool IsUnknownCodec>
2158typename std::enable_if<IsUnknownCodec, void>::type
2166template <
typename ValueType,
typename CodecType>
2167template <
bool IsUnknownCodec>
2168typename std::enable_if<!IsUnknownCodec, void>::type
2176template <
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:1013
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:1019
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:2016
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:1981
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition AttributeArray.h:1988
ValuePtr mFiller
Definition AttributeArray.h:803
ValueType get(Index n, Index m=0) const
Definition AttributeArray.h:2058
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:2084
std::unique_ptr< Handle > UniquePtr
Definition AttributeArray.h:768
bool hasConstantStride() const
Definition AttributeArray.h:2090
AttributeHandle & operator=(const AttributeHandle &)=default
Index index(Index n, Index m) const
Definition AttributeArray.h:2050
virtual ~AttributeWriteHandle()=default
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition AttributeArray.h:2108
std::shared_ptr< Handle > Ptr
Definition AttributeArray.h:835
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition AttributeArray.h:2139
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition AttributeArray.h:2133
void set(Index n, const ValueType &value)
Definition AttributeArray.h:2115
void expand(bool fill=true)
std::unique_ptr< Handle > ScopedPtr
Definition AttributeArray.h:836
AttributeWriteHandle< ValueType, CodecType > Handle
Definition AttributeArray.h:834
static Ptr create(AttributeArray &array, const bool expand=true)
Definition AttributeArray.h:2101
void set(Index n, Index m, const ValueType &value)
Definition AttributeArray.h:2121
void fill(const ValueType &value)
void collapse(const ValueType &uniformValue)
Definition AttributeArray.h:2145
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:1714
size_t memUsageIfLoaded() const override
Definition AttributeArray.h:1309
void getUnsafe(Index n, T &value) const
Return the value at index n (assumes in-core)
Definition AttributeArray.h:1341
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition AttributeArray.h:1317
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:1620
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:1880
void write(std::ostream &os, bool outputTransient) const override
Definition AttributeArray.h:1722
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:1301
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:1055
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition AttributeArray.h:1552
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition AttributeArray.h:1512
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:1275
bool validData() const
Definition AttributeArray.h:719
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition AttributeArray.h:1179
TypedAttributeArray & operator=(TypedAttributeArray &&)=delete
Move assignment operator disabled.
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition AttributeArray.h:1790
AttributeArray::Ptr copy() const override
Definition AttributeArray.h:1199
Index storageTypeSize() const override
Definition AttributeArray.h:594
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition AttributeArray.h:1283
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition AttributeArray.h:1659
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition AttributeArray.h:1381
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition AttributeArray.h:1105
static void registerType()
Register this attribute type along with a factory function.
Definition AttributeArray.h:1151
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition AttributeArray.h:1246
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition AttributeArray.h:1731
static void unregisterType()
Remove this attribute type from the registry.
Definition AttributeArray.h:1159
const StorageType * data() const
Definition AttributeArray.h:716
void loadData() const override
Ensures all data is in-core.
Definition AttributeArray.h:1544
void read(std::istream &) override
Read attribute data from a stream.
Definition AttributeArray.h:1560
ValueType get(Index n) const
Return the value at index n.
Definition AttributeArray.h:1329
TypedAttributeArray(TypedAttributeArray &&)=delete
Move constructor disabled.
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition AttributeArray.h:1132
TypedAttributeArray(const TypedAttributeArray &)
Definition AttributeArray.h:1083
static void fill(AttributeArray *array, const ValueType &value)
Non-member equivalent to fill() that static_casts array to this TypedAttributeArray.
Definition AttributeArray.h:1504
static void collapse(AttributeArray *array, const ValueType &value)
Non-member equivalent to collapse() that static_casts array to this TypedAttributeArray.
Definition AttributeArray.h:1479
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:1189
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition AttributeArray.h:1266
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:1457
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:1419
static bool isRegistered()
Return true if this attribute type is registered.
Definition AttributeArray.h:1143
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition AttributeArray.h:1292
StorageType * data()
Definition AttributeArray.h:715
static ValueType getUnsafe(const AttributeArray *array, const Index n)
Definition AttributeArray.h:1358
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:1465
void set(Index n, const T &value)
Set value at the given index n.
Definition AttributeArray.h:1403
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:1167
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:1832
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:1394
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition AttributeArray.h:1366
static void setUnsafe(AttributeArray *array, const Index n, const ValueType &value)
Definition AttributeArray.h:1411
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition AttributeArray.h:1569
void get(Index n, T &value) const
Return the value at index n.
Definition AttributeArray.h:1350
#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:468
internal::half half
Definition HalfDecl.h:25
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: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:1964
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition AttributeArray.h:1961
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition AttributeArray.h:1969
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:1960
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition AttributeArray.h:1938
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition AttributeArray.h:1940
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition AttributeArray.h:1944
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition AttributeArray.h:1939
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition AttributeArray.h:1950
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:929
static void decode(const StorageType &, ValueType &)
Definition AttributeArray.h:916
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:891
static const char * name()
Definition AttributeArray.h:443
static void decode(const ValueType &, ValueType &)
Definition AttributeArray.h:883
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:907
static void decode(const StorageType &, ValueType &)
Definition AttributeArray.h:899
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:941
static void encode(const math::Vec3< T > &, StorageType &)
Definition AttributeArray.h:949
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