Go to the documentation of this file.
10 #ifndef OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
11 #define OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
23 #include <tbb/spin_mutex.h>
24 #include <tbb/atomic.h>
29 #include <type_traits>
32 class TestAttributeArray;
48 template <
typename IntegerT,
typename FloatT>
52 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
59 template <
typename FloatT,
typename IntegerT>
63 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
67 template <
typename IntegerVectorT,
typename FloatT>
71 return IntegerVectorT(
72 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
x()),
73 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
y()),
74 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
z()));
77 template <
typename FloatVectorT,
typename IntegerT>
82 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
x()),
83 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
y()),
84 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
z()));
105 CONSTANTSTRIDE = 0x8,
113 WRITEMEMCOMPRESS = 0x4,
121 tbb::spin_mutex::scoped_lock lock;
126 using Ptr = std::shared_ptr<AttributeArray>;
127 using ConstPtr = std::shared_ptr<const AttributeArray>;
133 #if OPENVDB_ABI_VERSION_NUMBER >= 5
142 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
144 #if OPENVDB_ABI_VERSION_NUMBER >= 6
176 #if OPENVDB_ABI_VERSION_NUMBER >= 6
177 virtual Name valueType()
const = 0;
223 template<
typename AttributeArrayType>
224 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
227 template<
typename ValueType>
228 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
232 #if OPENVDB_ABI_VERSION_NUMBER >= 6
240 #if OPENVDB_ABI_VERSION_NUMBER >= 6
241 template<
typename IterT>
265 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
269 template<
typename IterT>
270 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
277 virtual void expand(
bool fill =
true) = 0;
305 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
326 uint8_t
flags()
const {
return mFlags; }
329 virtual void read(std::istream&) = 0;
332 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
334 virtual void write(std::ostream&)
const = 0;
341 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
347 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
358 #if OPENVDB_ABI_VERSION_NUMBER >= 6
359 virtual bool isDataLoaded()
const = 0;
370 friend class ::TestAttributeArray;
376 #if OPENVDB_ABI_VERSION_NUMBER >= 6
377 virtual char* dataAsByteArray() = 0;
379 virtual const char* dataAsByteArray()
const = 0;
382 template <
typename IterT>
383 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
384 bool rangeChecking =
true);
388 #if OPENVDB_ABI_VERSION_NUMBER >= 7
405 #if OPENVDB_ABI_VERSION_NUMBER < 6
407 size_t mCompressedBytes = 0;
409 uint8_t mUsePagedRead = 0;
410 #if OPENVDB_ABI_VERSION_NUMBER >= 5
411 tbb::atomic<Index32> mOutOfCore;
415 #else // #if OPENVDB_ABI_VERSION_NUMBER < 6
417 bool mIsUniform =
true;
420 uint8_t mUsePagedRead = 0;
440 template <
typename T>
448 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
460 namespace attribute_traits
492 template <
typename T>
495 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
496 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
497 static const char*
name() {
return "null"; }
503 template <
typename T>
506 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
507 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
508 static const char*
name() {
return "trnc"; }
515 static const char*
name() {
return "fxpt"; }
516 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
517 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
524 static const char*
name() {
return "ufxpt"; }
525 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
526 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
530 template <
bool OneByte,
typename Range=PositionRange>
533 template <
typename T>
536 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
537 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
540 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
550 template <
typename T>
555 static const char*
name() {
return "uvec"; }
564 template<
typename ValueType_,
typename Codec_ = NullCodec>
565 #if OPENVDB_ABI_VERSION_NUMBER >= 6 // for ABI=6, class is final to allow for de-virtualization
572 using Ptr = std::shared_ptr<TypedAttributeArray>;
573 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
577 using StorageType =
typename Codec::template Storage<ValueType>::Type;
583 const ValueType& uniformValue = zeroVal<ValueType>());
584 #if OPENVDB_ABI_VERSION_NUMBER >= 7
620 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true);
629 static const NamePair& attributeType();
634 static bool isRegistered();
636 static void registerType();
638 static void unregisterType();
645 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
649 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
652 #if OPENVDB_ABI_VERSION_NUMBER >= 6
653 Name valueType()
const override {
return typeNameAsString<ValueType>(); }
667 bool valueTypeIsFloatingPoint()
const override;
670 bool valueTypeIsClass()
const override;
673 bool valueTypeIsVector()
const override;
676 bool valueTypeIsQuaternion()
const override;
679 bool valueTypeIsMatrix()
const override;
683 size_t memUsage()
const override;
686 ValueType getUnsafe(
Index n)
const;
688 ValueType get(
Index n)
const;
690 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
692 template<
typename T>
void get(
Index n, T& value)
const;
699 void setUnsafe(
Index n,
const ValueType& value);
701 void set(
Index n,
const ValueType& value);
703 template<
typename T>
void setUnsafe(
Index n,
const T& value);
705 template<
typename T>
void set(
Index n,
const T& value);
712 #if OPENVDB_ABI_VERSION_NUMBER >= 6
722 void expand(
bool fill =
true)
override;
724 void collapse()
override;
726 bool compact()
override;
729 void collapse(
const ValueType& uniformValue);
732 void fill(
const ValueType& value);
735 static void collapse(
AttributeArray* array,
const ValueType& value);
745 void read(std::istream&)
override;
749 void write(std::ostream& os,
bool outputTransient)
const override;
751 void write(std::ostream&)
const override;
754 void readMetadata(std::istream&)
override;
759 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
762 void readBuffers(std::istream&)
override;
766 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
776 inline bool isOutOfCore()
const;
779 void loadData()
const override;
781 #if OPENVDB_ABI_VERSION_NUMBER >= 6
782 bool isDataLoaded()
const override;
787 AccessorBasePtr getAccessor()
const override;
794 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
797 friend class ::TestAttributeArray;
799 #if OPENVDB_ABI_VERSION_NUMBER >= 7
804 inline void doLoad()
const;
807 inline void doLoadUnsafe(
const bool compression =
true)
const;
809 inline bool compressUnsafe();
812 inline void setOutOfCore(
const bool);
817 #if OPENVDB_ABI_VERSION_NUMBER >= 6
818 char* dataAsByteArray()
override;
820 const char* dataAsByteArray()
const override;
823 size_t arrayMemUsage()
const;
829 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride);
832 static std::unique_ptr<const NamePair> sTypeName;
833 std::unique_ptr<StorageType[]> mData;
835 Index mStrideOrTotalSize;
836 #if OPENVDB_ABI_VERSION_NUMBER < 6 // as of ABI=6, this data lives in the base class to reduce memory
837 bool mIsUniform =
true;
838 mutable tbb::spin_mutex mMutex;
848 template <
typename ValueType,
typename CodecType = UnknownCodec>
853 using Ptr = std::shared_ptr<Handle>;
892 friend class ::TestAttributeArray;
894 template <
bool IsUnknownCodec>
895 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
897 template <
bool IsUnknownCodec>
898 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
900 template <
bool IsUnknownCodec>
901 typename std::enable_if<IsUnknownCodec, ValueType>::type get(
Index index)
const;
903 template <
bool IsUnknownCodec>
904 typename std::enable_if<!IsUnknownCodec, ValueType>::type get(
Index index)
const;
909 Index mStrideOrTotalSize;
911 bool mCollapseOnDestruction;
919 template <
typename ValueType,
typename CodecType = UnknownCodec>
924 using Ptr = std::shared_ptr<Handle>;
946 void fill(
const ValueType& value);
954 friend class ::TestAttributeArray;
956 template <
bool IsUnknownCodec>
957 typename std::enable_if<IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
959 template <
bool IsUnknownCodec>
960 typename std::enable_if<!IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
970 template<
typename ValueType>
972 NullCodec::decode(
const ValueType& data, ValueType& val)
978 template<
typename ValueType>
980 NullCodec::encode(
const ValueType& val, ValueType& data)
986 template<
typename StorageType,
typename ValueType>
988 TruncateCodec::decode(
const StorageType& data, ValueType& val)
990 val =
static_cast<ValueType
>(data);
994 template<
typename StorageType,
typename ValueType>
996 TruncateCodec::encode(
const ValueType& val, StorageType& data)
998 data =
static_cast<StorageType
>(val);
1002 template <
bool OneByte,
typename Range>
1003 template<
typename StorageType,
typename ValueType>
1007 val = fixedPointToFloatingPoint<ValueType>(data);
1011 val = Range::template decode<ValueType>(val);
1015 template <
bool OneByte,
typename Range>
1016 template<
typename StorageType,
typename ValueType>
1022 const ValueType newVal = Range::template encode<ValueType>(val);
1024 data = floatingPointToFixedPoint<StorageType>(newVal);
1028 template<
typename T>
1032 val = math::QuantizedUnitVec::unpack(data);
1036 template<
typename T>
1040 data = math::QuantizedUnitVec::pack(val);
1048 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1050 template <
typename IterT>
1051 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1057 assert(sourceArray.
isDataLoaded() && this->isDataLoaded());
1059 assert(this->storageTypeSize()*this->stride() ==
1063 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
1064 char*
const targetBuffer = this->dataAsByteArray();
1065 assert(sourceBuffer && targetBuffer);
1067 if (rangeChecking && this->isUniform()) {
1071 const bool sourceIsUniform = sourceArray.
isUniform();
1073 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
1074 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1076 for (IterT it(iter); it; ++it) {
1077 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1078 const Index targetIndex = it.targetIndex();
1080 if (rangeChecking) {
1081 if (sourceIndex >= sourceDataSize) {
1083 "Cannot copy array data as source index exceeds size of source array.");
1085 if (targetIndex >= targetDataSize) {
1087 "Cannot copy array data as target index exceeds size of target array.");
1091 assert(sourceIndex < sourceArray.
dataSize());
1092 assert(targetIndex < this->dataSize());
1093 if (this->isUniform()) assert(targetIndex ==
Index(0));
1096 const size_t targetOffset(targetIndex * bytes);
1097 const size_t sourceOffset(sourceIndex * bytes);
1099 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1103 template <
typename IterT>
1104 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1106 this->doCopyValues(sourceArray, iter,
false);
1109 template <
typename IterT>
1110 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1114 if (bytes != this->storageTypeSize()) {
1131 this->doCopyValues(sourceArray, iter,
true);
1145 template<
typename ValueType_,
typename Codec_>
1149 template<
typename ValueType_,
typename Codec_>
1155 , mStrideOrTotalSize(strideOrTotalSize)
1157 if (constantStride) {
1159 if (strideOrTotalSize == 0) {
1161 "stride to be at least one.")
1166 if (mStrideOrTotalSize < n) {
1168 "a total size of at least the number of elements in the array.")
1172 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1173 Codec::encode(uniformValue, this->
data()[0]);
1177 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1178 template<
typename ValueType_,
typename Codec_>
1185 template<
typename ValueType_,
typename Codec_>
1187 const tbb::spin_mutex::scoped_lock& lock)
1190 template<typename ValueType_, typename Codec_>
1195 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1196 #if OPENVDB_ABI_VERSION_NUMBER < 6
1197 , mIsUniform(rhs.mIsUniform)
1202 std::memcpy(this->
data(), rhs.
data(), this->arrayMemUsage());
1207 template<
typename ValueType_,
typename Codec_>
1208 TypedAttributeArray<ValueType_, Codec_>&
1213 tbb::spin_mutex::scoped_lock lock(mMutex);
1214 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1221 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1224 if (this->validData()) {
1226 std::memcpy(this->newDataAsByteArray(), rhs.newDataAsByteArray(), this->arrayMemUsage());
1232 template<
typename ValueType_,
typename Codec_>
1236 static std::once_flag once;
1237 std::call_once(once, []()
1239 sTypeName.reset(
new NamePair(typeNameAsString<ValueType>(), Codec::name()));
1245 template<
typename ValueType_,
typename Codec_>
1253 template<
typename ValueType_,
typename Codec_>
1261 template<
typename ValueType_,
typename Codec_>
1269 template<
typename ValueType_,
typename Codec_>
1276 template<
typename ValueType_,
typename Codec_>
1286 template<
typename ValueType_,
typename Codec_>
1296 template<
typename ValueType_,
typename Codec_>
1300 #if OPENVDB_ABI_VERSION_NUMBER < 7
1301 tbb::spin_mutex::scoped_lock lock(mMutex);
1307 template<
typename ValueType_,
typename Codec_>
1311 return this->copy();
1315 template<
typename ValueType_,
typename Codec_>
1319 if (this->isOutOfCore())
return 0;
1321 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1325 template<
typename ValueType_,
typename Codec_>
1327 TypedAttributeArray<ValueType_, Codec_>::allocate()
1331 mData.reset(
new StorageType[1]);
1334 const size_t size(this->dataSize());
1336 mData.reset(
new StorageType[size]);
1341 template<
typename ValueType_,
typename Codec_>
1343 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1346 if (this->isOutOfCore()) {
1347 this->setOutOfCore(
false);
1348 this->mPageHandle.reset();
1350 if (mData) mData.reset();
1354 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1355 template<
typename ValueType_,
typename Codec_>
1361 if (std::is_same<ValueType, Quats>::value ||
1362 std::is_same<ValueType, Quatd>::value ||
1363 std::is_same<ValueType, Mat3s>::value ||
1364 std::is_same<ValueType, Mat3d>::value ||
1365 std::is_same<ValueType, Mat4s>::value ||
1366 std::is_same<ValueType, Mat4d>::value)
return true;
1371 return std::is_floating_point<ElementT>::value || std::is_same<half, ElementT>::value;
1375 template<
typename ValueType_,
typename Codec_>
1380 return std::is_class<ValueType>::value && !std::is_same<half, ValueType>::value;
1384 template<
typename ValueType_,
typename Codec_>
1392 template<
typename ValueType_,
typename Codec_>
1397 return !this->valueType().compare(0, 4,
"quat");
1401 template<
typename ValueType_,
typename Codec_>
1406 return !this->valueType().compare(0, 3,
"mat");
1411 template<
typename ValueType_,
typename Codec_>
1415 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1419 template<
typename ValueType_,
typename Codec_>
1423 assert(n < this->dataSize());
1426 Codec::decode(this->data()[mIsUniform ? 0 : n], val);
1431 template<
typename ValueType_,
typename Codec_>
1436 if (this->isOutOfCore()) this->doLoad();
1438 return this->getUnsafe(n);
1442 template<
typename ValueType_,
typename Codec_>
1443 template<
typename T>
1447 val =
static_cast<T
>(this->getUnsafe(n));
1451 template<
typename ValueType_,
typename Codec_>
1452 template<
typename T>
1456 val =
static_cast<T
>(this->get(n));
1460 template<
typename ValueType_,
typename Codec_>
1468 template<
typename ValueType_,
typename Codec_>
1472 assert(n < this->dataSize());
1473 assert(!this->isOutOfCore());
1474 assert(!this->isUniform());
1479 Codec::encode(val, this->data()[mIsUniform ? 0 : n]);
1483 template<
typename ValueType_,
typename Codec_>
1488 if (this->isOutOfCore()) this->doLoad();
1489 if (this->isUniform()) this->expand();
1491 this->setUnsafe(n, val);
1495 template<
typename ValueType_,
typename Codec_>
1496 template<
typename T>
1500 this->setUnsafe(n,
static_cast<ValueType>(val));
1504 template<
typename ValueType_,
typename Codec_>
1505 template<
typename T>
1509 this->set(n,
static_cast<ValueType>(val));
1513 template<
typename ValueType_,
typename Codec_>
1521 template<
typename ValueType_,
typename Codec_>
1528 sourceTypedArray.
get(sourceIndex, sourceValue);
1530 this->set(n, sourceValue);
1534 template<
typename ValueType_,
typename Codec_>
1538 if (!mIsUniform)
return;
1543 tbb::spin_mutex::scoped_lock lock(mMutex);
1550 for (
Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1555 template<
typename ValueType_,
typename Codec_>
1559 if (mIsUniform)
return true;
1562 const ValueType_ val = this->get(0);
1563 for (
Index i = 1; i < this->dataSize(); i++) {
1567 this->collapse(this->get(0));
1572 template<
typename ValueType_,
typename Codec_>
1576 this->collapse(zeroVal<ValueType>());
1580 template<
typename ValueType_,
typename Codec_>
1585 tbb::spin_mutex::scoped_lock lock(mMutex);
1590 Codec::encode(uniformValue, this->data()[0]);
1594 template<
typename ValueType_,
typename Codec_>
1602 template<
typename ValueType_,
typename Codec_>
1606 if (this->isOutOfCore()) {
1607 tbb::spin_mutex::scoped_lock lock(mMutex);
1612 const Index size = mIsUniform ? 1 : this->dataSize();
1613 for (
Index i = 0; i < size; ++i) {
1614 Codec::encode(value, this->data()[i]);
1619 template<
typename ValueType_,
typename Codec_>
1627 template<
typename ValueType_,
typename Codec_>
1635 template<
typename ValueType_,
typename Codec_>
1643 template<
typename ValueType_,
typename Codec_>
1651 template<
typename ValueType_,
typename Codec_>
1655 #if OPENVDB_ABI_VERSION_NUMBER >= 5
1658 return (mFlags & OUTOFCORE);
1663 template<
typename ValueType_,
typename Codec_>
1667 #if OPENVDB_ABI_VERSION_NUMBER >= 5
1670 if (b) mFlags =
static_cast<uint8_t
>(mFlags | OUTOFCORE);
1671 else mFlags =
static_cast<uint8_t
>(mFlags & ~OUTOFCORE);
1676 template<
typename ValueType_,
typename Codec_>
1678 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1680 if (!(this->isOutOfCore()))
return;
1682 TypedAttributeArray<ValueType_, Codec_>*
self =
1683 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1687 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1688 this->doLoadUnsafe();
1692 template<
typename ValueType_,
typename Codec_>
1700 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1701 template<
typename ValueType_,
typename Codec_>
1705 return !this->isOutOfCore();
1710 template<
typename ValueType_,
typename Codec_>
1714 this->readMetadata(is);
1715 this->readBuffers(is);
1719 template<
typename ValueType_,
typename Codec_>
1726 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1727 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1729 uint8_t flags = uint8_t(0);
1730 is.read(
reinterpret_cast<char*
>(&flags),
sizeof(uint8_t));
1733 uint8_t serializationFlags = uint8_t(0);
1734 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1737 is.read(
reinterpret_cast<char*
>(&size),
sizeof(
Index));
1741 if (mFlags >= 0x20) {
1746 if (serializationFlags >= 0x10) {
1752 mIsUniform = serializationFlags & WRITEUNIFORM;
1753 mUsePagedRead = serializationFlags & WRITEPAGED;
1754 mCompressedBytes = bytes;
1755 mFlags |= PARTIALREAD;
1759 if (serializationFlags & WRITESTRIDED) {
1761 is.read(
reinterpret_cast<char*
>(&stride),
sizeof(
Index));
1762 mStrideOrTotalSize = stride;
1765 mStrideOrTotalSize = 1;
1770 template<
typename ValueType_,
typename Codec_>
1774 if (mUsePagedRead) {
1779 tbb::spin_mutex::scoped_lock lock(mMutex);
1783 uint8_t bloscCompressed(0);
1784 if (!mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1786 assert(mFlags & PARTIALREAD);
1787 std::unique_ptr<char[]> buffer(
new char[mCompressedBytes]);
1788 is.read(buffer.get(), mCompressedBytes);
1789 mCompressedBytes = 0;
1790 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1794 if (bloscCompressed == uint8_t(1)) {
1798 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1800 if (newBuffer) buffer.reset(newBuffer.release());
1805 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1809 template<
typename ValueType_,
typename Codec_>
1813 if (!mUsePagedRead) {
1821 const bool delayLoad = (mappedFile.get() !=
nullptr);
1825 size_t compressedBytes(mCompressedBytes);
1826 mCompressedBytes = 0;
1827 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1828 assert(!mPageHandle);
1833 assert(mPageHandle);
1835 tbb::spin_mutex::scoped_lock lock(mMutex);
1839 this->setOutOfCore(delayLoad);
1840 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1843 std::unique_ptr<char[]> buffer = mPageHandle->read();
1844 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1853 template<
typename ValueType_,
typename Codec_>
1857 this->write(os,
false);
1861 template<
typename ValueType_,
typename Codec_>
1865 this->writeMetadata(os, outputTransient,
false);
1866 this->writeBuffers(os, outputTransient);
1870 template<
typename ValueType_,
typename Codec_>
1874 if (!outputTransient && this->isTransient())
return;
1876 if (mFlags & PARTIALREAD) {
1880 #if OPENVDB_ABI_VERSION_NUMBER >= 5
1881 uint8_t flags(mFlags);
1883 uint8_t flags(mFlags & uint8_t(~OUTOFCORE));
1885 uint8_t serializationFlags(0);
1887 Index stride(mStrideOrTotalSize);
1888 bool strideOfOne(this->stride() == 1);
1893 if (bloscCompression) this->doLoad();
1895 size_t compressedBytes = 0;
1899 serializationFlags |= WRITESTRIDED;
1904 serializationFlags |= WRITEUNIFORM;
1905 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1907 else if (bloscCompression)
1909 if (paged) serializationFlags |= WRITEPAGED;
1911 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1912 const size_t inBytes = this->arrayMemUsage();
1919 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1923 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1924 os.write(
reinterpret_cast<const char*
>(&flags),
sizeof(uint8_t));
1925 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1926 os.write(
reinterpret_cast<const char*
>(&size),
sizeof(
Index));
1929 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&stride),
sizeof(
Index));
1933 template<
typename ValueType_,
typename Codec_>
1937 if (!outputTransient && this->isTransient())
return;
1939 if (mFlags & PARTIALREAD) {
1945 if (this->isUniform()) {
1946 os.write(
reinterpret_cast<const char*
>(this->data()),
sizeof(
StorageType));
1950 std::unique_ptr<char[]> compressedBuffer;
1951 size_t compressedBytes = 0;
1952 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1953 const size_t inBytes = this->arrayMemUsage();
1955 if (compressedBuffer) {
1956 uint8_t bloscCompressed(1);
1957 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1958 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
1961 uint8_t bloscCompressed(0);
1962 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1963 os.write(
reinterpret_cast<const char*
>(this->data()), inBytes);
1968 uint8_t bloscCompressed(0);
1969 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1970 os.write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1975 template<
typename ValueType_,
typename Codec_>
1979 if (!outputTransient && this->isTransient())
return;
1983 if (!bloscCompression) {
1988 if (mFlags & PARTIALREAD) {
1994 os.
write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1998 template<
typename ValueType_,
typename Codec_>
2002 if (!(this->isOutOfCore()))
return;
2008 assert(self->mPageHandle);
2009 assert(!(self->mFlags & PARTIALREAD));
2011 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
2013 self->mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
2015 self->mPageHandle.reset();
2019 #if OPENVDB_ABI_VERSION_NUMBER >= 5
2020 self->mOutOfCore =
false;
2022 self->mFlags &= uint8_t(~OUTOFCORE);
2027 template<
typename ValueType_,
typename Codec_>
2042 template<
typename ValueType_,
typename Codec_>
2047 if(!otherT)
return false;
2048 if(this->mSize != otherT->mSize ||
2049 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
2051 this->attributeType() != this->attributeType())
return false;
2056 const StorageType *target = this->data(), *source = otherT->
data();
2057 if (!target && !source)
return true;
2058 if (!target || !source)
return false;
2059 Index n = this->mIsUniform ? 1 : mSize;
2065 #if OPENVDB_ABI_VERSION_NUMBER >= 6
2066 template<
typename ValueType_,
typename Codec_>
2068 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2070 return reinterpret_cast<char*
>(this->data());
2074 template<
typename ValueType_,
typename Codec_>
2076 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
2078 return reinterpret_cast<const char*
>(this->data());
2087 template <
typename CodecType,
typename ValueType>
2108 template <
typename ValueType>
2116 return (*functor)(array, n);
2121 (*functor)(array, n, value);
2130 template <
typename ValueType,
typename CodecType>
2138 template <
typename ValueType,
typename CodecType>
2141 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2142 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2143 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2145 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2166 template <
typename ValueType,
typename CodecType>
2170 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
2173 template <
typename ValueType,
typename CodecType>
2174 template <
bool IsUnknownCodec>
2175 typename std::enable_if<IsUnknownCodec, bool>::type
2180 return mArray->hasValueType<ValueType>();
2183 template <
typename ValueType,
typename CodecType>
2184 template <
bool IsUnknownCodec>
2185 typename std::enable_if<!IsUnknownCodec, bool>::type
2186 AttributeHandle<ValueType, CodecType>::compatibleType()
const
2190 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2193 template <
typename ValueType,
typename CodecType>
2200 template <
typename ValueType,
typename CodecType>
2203 Index index = n * mStrideOrTotalSize + m;
2204 assert(index < (mSize * mStrideOrTotalSize));
2208 template <
typename ValueType,
typename CodecType>
2211 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2214 template <
typename ValueType,
typename CodecType>
2215 template <
bool IsUnknownCodec>
2216 typename std::enable_if<IsUnknownCodec, ValueType>::type
2221 return (*mGetter)(mArray, index);
2224 template <
typename ValueType,
typename CodecType>
2225 template <
bool IsUnknownCodec>
2226 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2234 template <
typename ValueType,
typename CodecType>
2237 return mArray->isUniform();
2240 template <
typename ValueType,
typename CodecType>
2243 return mArray->hasConstantStride();
2250 template <
typename ValueType,
typename CodecType>
2258 template <
typename ValueType,
typename CodecType>
2265 template <
typename ValueType,
typename CodecType>
2268 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2271 template <
typename ValueType,
typename CodecType>
2274 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2277 template <
typename ValueType,
typename CodecType>
2283 template <
typename ValueType,
typename CodecType>
2289 template <
typename ValueType,
typename CodecType>
2295 template <
typename ValueType,
typename CodecType>
2298 this->mCollapser(
const_cast<AttributeArray*
>(this->mArray), uniformValue);
2301 template <
typename ValueType,
typename CodecType>
2307 template <
typename ValueType,
typename CodecType>
2308 template <
bool IsUnknownCodec>
2309 typename std::enable_if<IsUnknownCodec, void>::type
2314 (*this->mSetter)(
const_cast<AttributeArray*
>(this->mArray), index, value);
2317 template <
typename ValueType,
typename CodecType>
2318 template <
bool IsUnknownCodec>
2319 typename std::enable_if<!IsUnknownCodec, void>::type
2327 template <
typename ValueType,
typename CodecType>
2330 assert(this->mArray);
2339 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
virtual ~AttributeArray()
Definition: AttributeArray.h:138
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:445
OPENVDB_DEPRECATED TypedAttributeArray(const TypedAttributeArray &, bool)
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1403
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:924
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:83
Ptr(*)(Index, Index, bool) FactoryMethod
Definition: AttributeArray.h:129
AttributeArray & operator=(const AttributeArray &rhs)
Definition: AttributeArray.h:504
virtual Index stride() const =0
Convenience wrappers to using Blosc and reading and writing of Paged data.
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
Index index(Index n, Index m) const
Definition: AttributeArray.h:2201
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1536
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1433
const StorageType * data() const
Definition: AttributeArray.h:791
Definition: AttributeArray.h:470
const AttributeArray * mArray
Definition: AttributeArray.h:884
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2090
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1574
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2259
virtual void write(std::ostream &) const =0
Write attribute metadata and buffers to a stream, don't write transient attributes.
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1278
int16_t Int16
Definition: Types.h:32
virtual void readMetadata(std::istream &)=0
Read attribute metadata from a stream.
OPENVDB_DEPRECATED bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1629
Definition: AttributeArray.h:547
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:525
Index storageTypeSize() const override
Definition: AttributeArray.h:664
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:305
Base class for storing attribute data.
Definition: AttributeArray.h:93
Definition: AttributeArray.h:514
AttributeArray()
Definition: AttributeArray.h:134
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:853
StringIndexType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:857
SharedPtr< MappedFile > Ptr
Definition: io.h:136
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1935
bool operator==(const AttributeArray &other) const
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2120
Definition: AttributeArray.h:523
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:127
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
static Ptr create(Index n, Index strideOrTotalSize=1, bool constantStride=true)
Return a new attribute array of the given length n and stride with uniform value zero.
Definition: AttributeArray.h:1271
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
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.
Index size() const
Definition: AttributeArray.h:872
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1247
bool isUniform() const
Definition: AttributeArray.h:2235
void setHidden(bool state)
Specify whether this attribute should be hidden (e.g., from UI or iterators).
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1377
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1357
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:572
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1557
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
Index stride() const override
Definition: AttributeArray.h:645
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:648
virtual Index dataSize() const =0
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2111
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...
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:209
void collapse(const ValueType &uniformValue)
Definition: AttributeArray.h:2296
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:367
static const char * name()
Definition: AttributeArray.h:555
short Type
Definition: AttributeArray.h:464
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:126
virtual void writeBuffers(std::ostream &, bool outputTransient) const =0
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:444
const AttributeArray & array() const
Definition: AttributeArray.h:2194
void set(Index n, const ValueType &value)
Definition: AttributeArray.h:2266
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1234
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:526
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:1150
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1485
virtual void readBuffers(std::istream &)=0
Read attribute buffers from a stream.
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2091
Flag
Definition: AttributeArray.h:101
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:2302
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:794
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2139
static void clearRegistry(const ScopedRegistryLock *lock=nullptr)
Clear the attribute type registry.
T & y()
Definition: Vec3.h:84
Index stride() const
Definition: AttributeArray.h:871
uint8_t mFlags
Definition: AttributeArray.h:419
void setTransient(bool state)
Specify whether this attribute should only exist in memory and not be serialized during stream output...
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:790
TypedAttributeArray & operator=(TypedAttributeArray &&)=delete
Move assignment operator disabled.
virtual AttributeArray::Ptr copy() const =0
Return a copy of this attribute.
bool mIsUniform
Definition: AttributeArray.h:417
tbb::spin_mutex mMutex
Definition: AttributeArray.h:418
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1863
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1703
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1811
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:424
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
OPENVDB_DEPRECATED bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1645
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1977
ValuePtr mFiller
Definition: AttributeArray.h:889
void setStreaming(bool state)
Specify whether this attribute is to be streamed off disk, in which case, the attributes are collapse...
TypedAttributeArray(TypedAttributeArray &&)=delete
Move constructor disabled.
virtual void read(std::istream &)=0
Read attribute metadata and buffers from a stream.
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:631
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
virtual bool valueTypeIsVector() const =0
Return true if the value type is a vector.
virtual OPENVDB_DEPRECATED bool compress()=0
static const char * name()
Definition: AttributeArray.h:524
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:657
virtual Name codecType() const =0
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
T & z()
Definition: Vec3.h:85
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:320
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1721
Write-able version of AttributeHandle.
Definition: AttributeArray.h:921
T Type
Definition: AttributeArray.h:493
ValuePtr mCollapser
Definition: AttributeArray.h:888
virtual OPENVDB_DEPRECATED AttributeArray::Ptr copyUncompressed() const =0
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:443
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:171
Definition: Exceptions.h:64
AttributeArray(const AttributeArray &rhs)
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2132
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2089
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:504
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:2029
Typed class for storing attribute data.
Definition: AttributeArray.h:570
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1394
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:228
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:323
AttributeHandle(const AttributeHandle &)=default
uint16_t StorageType
Definition: AttributeArray.h:548
virtual Index size() const =0
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2278
virtual void write(std::ostream &, bool outputTransient) const =0
static const char * name()
Definition: AttributeArray.h:539
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:641
Definition: AttributeArray.h:850
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2290
virtual size_t memUsage() const =0
Return the number of bytes of memory used by this attribute.
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1604
Definition: AttributeArray.h:96
Definition: AttributeArray.h:491
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1470
static Ptr create(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2252
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:69
@ COMPRESS_BLOSC
Definition: Compression.h:56
AttributeArray & operator=(AttributeArray &&)=default
Definition: AttributeArray.h:493
AttributeArray & array()
Definition: AttributeArray.h:2328
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:925
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:326
ValuePtr mCollapser
Definition: AttributeArray.h:452
virtual OPENVDB_DEPRECATED bool decompress()=0
tbb::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:421
typename T::ValueType ElementType
Definition: Types.h:185
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:224
bool sizeOnly() const
Definition: StreamCompression.h:256
static const char * name()
Definition: AttributeArray.h:497
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:516
virtual void writeMetadata(std::ostream &, bool outputTransient, bool paged) const =0
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:660
GetterPtr mGetter
Definition: AttributeArray.h:886
AttributeArray(AttributeArray &&)=default
Definition: AttributeArray.h:120
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1255
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2112
virtual void loadData() const =0
Ensures all data is in-core.
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2284
uint8_t Type
Definition: AttributeArray.h:471
bool sizeOnly() const
Definition: StreamCompression.h:219
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1263
virtual ~AccessorBase()=default
virtual Index storageTypeSize() const =0
OPENVDB_DEPRECATED AttributeArray::Ptr copyUncompressed() const override
Definition: AttributeArray.h:1309
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:436
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:246
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2095
virtual bool valueTypeIsQuaternion() const =0
Return true if the value type is a quaternion.
ValueType_ ValueType
Definition: AttributeArray.h:575
virtual ~AttributeWriteHandle()=default
Index32 Index
Definition: Types.h:31
Definition: AttributeArray.h:502
virtual void collapse()=0
Replace the existing array with a uniform zero value.
void set(Index n, Index m, const ValueType &value)
Definition: AttributeArray.h:2272
GetterPtr mGetter
Definition: AttributeArray.h:450
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
void(*)(AttributeArray *array, const Index n, const StringIndexType &value) SetterPtr
Definition: AttributeArray.h:858
virtual Index valueTypeSize() const =0
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:79
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:718
Definition: Exceptions.h:57
std::string Name
Definition: Name.h:17
Definition: AttributeArray.h:532
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1386
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2115
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1209
Definition: AttributeArray.h:462
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:388
virtual const NamePair & type() const =0
Return the name of this attribute's type.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:854
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:312
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:577
SetterPtr mSetter
Definition: AttributeArray.h:451
Definition: AttributeArray.h:487
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1772
AttributeArray(const AttributeArray &rhs, const tbb::spin_mutex::scoped_lock &)
Definition: AttributeArray.h:534
ValueType getUnsafe(Index n) const
Return the value at index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1421
ValuePtr mFiller
Definition: AttributeArray.h:453
AttributeHandle & operator=(const AttributeHandle &)=default
size_t mCompressedBytes
Definition: AttributeArray.h:425
Definition: AttributeArray.h:551
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:447
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1694
static Ptr create(const NamePair &type, Index length, Index stride=1, bool constantStride=true, const ScopedRegistryLock *lock=nullptr)
virtual bool valueTypeIsMatrix() const =0
Return true if the value type is a matrix.
SerializationFlag
Definition: AttributeArray.h:110
std::istream & getInputStream()
Definition: StreamCompression.h:222
Definition: Exceptions.h:65
Codec_ Codec
Definition: AttributeArray.h:576
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:534
bool hasConstantStride() const
Definition: AttributeArray.h:2241
StorageType Type
Definition: AttributeArray.h:551
Definition: Exceptions.h:13
Definition: Exceptions.h:58
virtual ~AttributeHandle()
Definition: AttributeArray.h:2167
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1413
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1712
uint64_t Index64
Definition: Types.h:30
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
static const char * name()
Definition: AttributeArray.h:515
~TypedAttributeArray() override
Definition: AttributeArray.h:609
SetterPtr mSetter
Definition: AttributeArray.h:887
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2101
half Type
Definition: AttributeArray.h:463
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:259
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:98
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:517
uint8_t mUsePagedRead
Definition: AttributeArray.h:420
uint16_t Type
Definition: AttributeArray.h:472
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1653
OPENVDB_DEPRECATED bool isCompressed() const
Definition: AttributeArray.h:285
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
static const char * name()
Definition: AttributeArray.h:508
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
virtual bool valueTypeIsClass() const =0
Return true if the value type is a class (ie vector, matrix or quaternion return true)
void(*)(AttributeArray *array, const StringIndexType &value) ValuePtr
Definition: AttributeArray.h:859
ValueType get(Index n, Index m=0) const
Definition: AttributeArray.h:2209
virtual OPENVDB_DEPRECATED void set(const Index n, const AttributeArray &sourceArray, const Index sourceIndex)=0
Set value at given index n from sourceIndex of another sourceArray.
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...
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1298
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1872