Go to the documentation of this file.
37 #ifndef OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
38 #define OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
50 #include <tbb/spin_mutex.h>
51 #include <tbb/atomic.h>
55 #include <type_traits>
58 class TestAttributeArray;
74 template <
typename IntegerT,
typename FloatT>
78 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
85 template <
typename FloatT,
typename IntegerT>
89 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
93 template <
typename IntegerVectorT,
typename FloatT>
97 return IntegerVectorT(
98 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
x()),
99 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
y()),
100 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
z()));
103 template <
typename FloatVectorT,
typename IntegerT>
108 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
x()),
109 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
y()),
110 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
z()));
131 CONSTANTSTRIDE = 0x8,
139 WRITEMEMCOMPRESS = 0x4,
144 using Ptr = std::shared_ptr<AttributeArray>;
145 using ConstPtr = std::shared_ptr<const AttributeArray>;
151 #if OPENVDB_ABI_VERSION_NUMBER >= 5
160 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
162 #if OPENVDB_ABI_VERSION_NUMBER >= 6
164 : mIsUniform(rhs.mIsUniform)
166 , mUsePagedRead(rhs.mUsePagedRead)
167 , mOutOfCore(rhs.mOutOfCore)
177 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
184 else mPageHandle.reset();
204 virtual Index size()
const = 0;
208 virtual Index stride()
const = 0;
212 virtual Index dataSize()
const = 0;
214 #if OPENVDB_ABI_VERSION_NUMBER >= 6
215 virtual Name valueType()
const = 0;
219 virtual Name codecType()
const = 0;
223 virtual Index valueTypeSize()
const = 0;
227 virtual Index storageTypeSize()
const = 0;
230 virtual bool valueTypeIsFloatingPoint()
const = 0;
233 virtual bool valueTypeIsClass()
const = 0;
236 virtual bool valueTypeIsVector()
const = 0;
239 virtual bool valueTypeIsQuaternion()
const = 0;
242 virtual bool valueTypeIsMatrix()
const = 0;
246 virtual size_t memUsage()
const = 0;
249 static Ptr create(
const NamePair& type,
Index length,
Index stride = 1,
bool constantStride =
true);
251 static bool isRegistered(
const NamePair& type);
253 static void clearRegistry();
256 virtual const NamePair& type()
const = 0;
258 template<
typename AttributeArrayType>
259 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
262 template<
typename ValueType>
263 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
267 #if OPENVDB_ABI_VERSION_NUMBER >= 6
272 #if OPENVDB_ABI_VERSION_NUMBER >= 6
273 template<
typename IterT>
297 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
301 template<
typename IterT>
302 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
306 virtual bool isUniform()
const = 0;
309 virtual void expand(
bool fill =
true) = 0;
311 virtual void collapse() = 0;
313 virtual bool compact() = 0;
327 void setHidden(
bool state);
329 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
334 void setTransient(
bool state);
342 void setStreaming(
bool state);
350 uint8_t
flags()
const {
return mFlags; }
353 virtual void read(std::istream&) = 0;
356 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
358 virtual void write(std::ostream&)
const = 0;
361 virtual void readMetadata(std::istream&) = 0;
365 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
368 virtual void readBuffers(std::istream&) = 0;
371 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
380 virtual void loadData()
const = 0;
382 #if OPENVDB_ABI_VERSION_NUMBER >= 6
383 virtual bool isDataLoaded()
const = 0;
394 friend class ::TestAttributeArray;
400 #if OPENVDB_ABI_VERSION_NUMBER >= 6
401 virtual char* dataAsByteArray() = 0;
403 virtual const char* dataAsByteArray()
const = 0;
406 template <
typename IterT>
407 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
408 bool rangeChecking =
true);
413 void setConstantStride(
bool state);
421 static void unregisterType(
const NamePair& type);
423 #if OPENVDB_ABI_VERSION_NUMBER < 6
425 size_t mCompressedBytes = 0;
427 uint8_t mUsePagedRead = 0;
428 #if OPENVDB_ABI_VERSION_NUMBER >= 5
429 tbb::atomic<Index32> mOutOfCore;
433 #else // #if OPENVDB_ABI_VERSION_NUMBER < 6
435 bool mIsUniform =
true;
438 uint8_t mUsePagedRead = 0;
458 template <
typename T>
466 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
478 namespace attribute_traits
510 template <
typename T>
513 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
514 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
515 static const char*
name() {
return "null"; }
521 template <
typename T>
524 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
525 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
526 static const char*
name() {
return "trnc"; }
533 static const char*
name() {
return "fxpt"; }
534 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
535 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
542 static const char*
name() {
return "ufxpt"; }
543 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
544 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
548 template <
bool OneByte,
typename Range=PositionRange>
551 template <
typename T>
554 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
555 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
558 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
568 template <
typename T>
573 static const char*
name() {
return "uvec"; }
582 template<
typename ValueType_,
typename Codec_ = NullCodec>
583 #if OPENVDB_ABI_VERSION_NUMBER >= 6 // for ABI=6, class is final to allow for de-virtualization
590 using Ptr = std::shared_ptr<TypedAttributeArray>;
591 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
595 using StorageType =
typename Codec::template Storage<ValueType>::Type;
601 const ValueType& uniformValue = zeroVal<ValueType>());
624 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true);
633 static const NamePair& attributeType();
638 static bool isRegistered();
640 static void registerType();
642 static void unregisterType();
649 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
653 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
656 #if OPENVDB_ABI_VERSION_NUMBER >= 6
657 Name valueType()
const override {
return typeNameAsString<ValueType>(); }
671 bool valueTypeIsFloatingPoint()
const override;
674 bool valueTypeIsClass()
const override;
677 bool valueTypeIsVector()
const override;
680 bool valueTypeIsQuaternion()
const override;
683 bool valueTypeIsMatrix()
const override;
687 size_t memUsage()
const override;
690 ValueType getUnsafe(
Index n)
const;
692 ValueType get(
Index n)
const;
694 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
696 template<
typename T>
void get(
Index n, T& value)
const;
703 void setUnsafe(
Index n,
const ValueType& value);
705 void set(
Index n,
const ValueType& value);
707 template<
typename T>
void setUnsafe(
Index n,
const T& value);
709 template<
typename T>
void set(
Index n,
const T& value);
723 void expand(
bool fill =
true)
override;
725 void collapse()
override;
727 bool compact()
override;
730 void collapse(
const ValueType& uniformValue);
733 void fill(
const ValueType& value);
736 static void collapse(
AttributeArray* array,
const ValueType& value);
746 void read(std::istream&)
override;
750 void write(std::ostream& os,
bool outputTransient)
const override;
752 void write(std::ostream&)
const override;
755 void readMetadata(std::istream&)
override;
760 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
763 void readBuffers(std::istream&)
override;
767 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
777 inline bool isOutOfCore()
const;
780 void loadData()
const override;
782 #if OPENVDB_ABI_VERSION_NUMBER >= 6
783 bool isDataLoaded()
const override;
788 AccessorBasePtr getAccessor()
const override;
795 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
798 friend class ::TestAttributeArray;
801 inline void doLoad()
const;
804 inline void doLoadUnsafe(
const bool compression =
true)
const;
806 inline bool compressUnsafe();
809 inline void setOutOfCore(
const bool);
814 #if OPENVDB_ABI_VERSION_NUMBER >= 6
815 char* dataAsByteArray()
override;
817 const char* dataAsByteArray()
const override;
820 size_t arrayMemUsage()
const;
826 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride);
829 static tbb::atomic<const NamePair*> sTypeName;
830 std::unique_ptr<StorageType[]> mData;
832 Index mStrideOrTotalSize;
833 #if OPENVDB_ABI_VERSION_NUMBER < 6 // as of ABI=6, this data lives in the base class to reduce memory
834 bool mIsUniform =
true;
835 mutable tbb::spin_mutex mMutex;
845 template <
typename ValueType,
typename CodecType = UnknownCodec>
850 using Ptr = std::shared_ptr<Handle>;
859 static Ptr create(
const AttributeArray& array,
const bool collapseOnDestruction =
true);
871 bool isUniform()
const;
872 bool hasConstantStride()
const;
889 friend class ::TestAttributeArray;
891 template <
bool IsUnknownCodec>
892 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
894 template <
bool IsUnknownCodec>
895 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
897 template <
bool IsUnknownCodec>
898 typename std::enable_if<IsUnknownCodec, ValueType>::type get(
Index index)
const;
900 template <
bool IsUnknownCodec>
901 typename std::enable_if<!IsUnknownCodec, ValueType>::type get(
Index index)
const;
906 Index mStrideOrTotalSize;
908 bool mCollapseOnDestruction;
916 template <
typename ValueType,
typename CodecType = UnknownCodec>
921 using Ptr = std::shared_ptr<Handle>;
932 void expand(
bool fill =
true);
936 void collapse(
const ValueType& uniformValue);
943 void fill(
const ValueType& value);
945 void set(
Index n,
const ValueType& value);
946 void set(
Index n,
Index m,
const ValueType& value);
951 friend class ::TestAttributeArray;
953 template <
bool IsUnknownCodec>
954 typename std::enable_if<IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
956 template <
bool IsUnknownCodec>
957 typename std::enable_if<!IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
967 template<
typename ValueType>
969 NullCodec::decode(
const ValueType& data, ValueType& val)
975 template<
typename ValueType>
977 NullCodec::encode(
const ValueType& val, ValueType& data)
983 template<
typename StorageType,
typename ValueType>
985 TruncateCodec::decode(
const StorageType& data, ValueType& val)
987 val = static_cast<ValueType>(data);
991 template<
typename StorageType,
typename ValueType>
993 TruncateCodec::encode(
const ValueType& val, StorageType& data)
995 data = static_cast<StorageType>(val);
999 template <
bool OneByte,
typename Range>
1000 template<
typename StorageType,
typename ValueType>
1004 val = fixedPointToFloatingPoint<ValueType>(data);
1008 val = Range::template decode<ValueType>(val);
1012 template <
bool OneByte,
typename Range>
1013 template<
typename StorageType,
typename ValueType>
1019 const ValueType newVal = Range::template encode<ValueType>(val);
1021 data = floatingPointToFixedPoint<StorageType>(newVal);
1025 template<
typename T>
1029 val = math::QuantizedUnitVec::unpack(data);
1033 template<
typename T>
1037 data = math::QuantizedUnitVec::pack(val);
1045 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1047 template <
typename IterT>
1048 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1054 assert(sourceArray.
isDataLoaded() && this->isDataLoaded());
1056 assert(this->storageTypeSize()*this->stride() ==
1060 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
1061 char*
const targetBuffer = this->dataAsByteArray();
1062 assert(sourceBuffer && targetBuffer);
1064 if (rangeChecking && this->isUniform()) {
1068 const bool sourceIsUniform = sourceArray.
isUniform();
1070 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
1071 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1073 for (IterT it(iter); it; ++it) {
1074 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1075 const Index targetIndex = it.targetIndex();
1077 if (rangeChecking) {
1078 if (sourceIndex >= sourceDataSize) {
1080 "Cannot copy array data as source index exceeds size of source array.");
1082 if (targetIndex >= targetDataSize) {
1084 "Cannot copy array data as target index exceeds size of target array.");
1088 assert(sourceIndex < sourceArray.
dataSize());
1089 assert(targetIndex < this->dataSize());
1090 if (this->isUniform()) assert(targetIndex ==
Index(0));
1093 const size_t targetOffset(targetIndex * bytes);
1094 const size_t sourceOffset(sourceIndex * bytes);
1096 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1100 template <
typename IterT>
1101 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1103 this->doCopyValues(sourceArray, iter,
false);
1106 template <
typename IterT>
1107 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1111 if (bytes != this->storageTypeSize()) {
1128 this->doCopyValues(sourceArray, iter,
true);
1142 template<
typename ValueType_,
typename Codec_>
1146 template<
typename ValueType_,
typename Codec_>
1152 , mStrideOrTotalSize(strideOrTotalSize)
1154 if (constantStride) {
1156 if (strideOrTotalSize == 0) {
1158 "stride to be at least one.")
1163 if (mStrideOrTotalSize < n) {
1165 "a total size of at least the number of elements in the array.")
1169 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1170 Codec::encode(uniformValue, this->
data()[0]);
1174 template<
typename ValueType_,
typename Codec_>
1178 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1179 #if OPENVDB_ABI_VERSION_NUMBER < 6
1180 , mIsUniform(rhs.mIsUniform)
1185 std::memcpy(this->
data(), rhs.
data(), this->arrayMemUsage());
1190 template<
typename ValueType_,
typename Codec_>
1196 tbb::spin_mutex::scoped_lock lock(mMutex);
1197 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1204 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1207 if (this->validData()) {
1209 std::memcpy(this->newDataAsByteArray(), rhs.newDataAsByteArray(), this->arrayMemUsage());
1215 template<
typename ValueType_,
typename Codec_>
1219 if (sTypeName ==
nullptr) {
1221 if (sTypeName.compare_and_swap(s,
nullptr) !=
nullptr)
delete s;
1227 template<
typename ValueType_,
typename Codec_>
1235 template<
typename ValueType_,
typename Codec_>
1243 template<
typename ValueType_,
typename Codec_>
1251 template<
typename ValueType_,
typename Codec_>
1258 template<
typename ValueType_,
typename Codec_>
1265 return static_cast<TypedAttributeArray&>(attributeArray);
1268 template<
typename ValueType_,
typename Codec_>
1275 return static_cast<const TypedAttributeArray&>(attributeArray);
1278 template<
typename ValueType_,
typename Codec_>
1282 tbb::spin_mutex::scoped_lock lock(mMutex);
1287 template<
typename ValueType_,
typename Codec_>
1291 tbb::spin_mutex::scoped_lock lock(mMutex);
1296 template<
typename ValueType_,
typename Codec_>
1300 if (this->isOutOfCore())
return 0;
1302 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1306 template<
typename ValueType_,
typename Codec_>
1308 TypedAttributeArray<ValueType_, Codec_>::allocate()
1312 mData.reset(
new StorageType[1]);
1315 const size_t size(this->dataSize());
1317 mData.reset(
new StorageType[size]);
1322 template<
typename ValueType_,
typename Codec_>
1324 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1327 if (this->isOutOfCore()) {
1328 this->setOutOfCore(
false);
1329 this->mPageHandle.reset();
1331 if (mData) mData.reset();
1335 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1336 template<
typename ValueType_,
typename Codec_>
1342 if (std::is_same<ValueType, Quats>::value ||
1343 std::is_same<ValueType, Quatd>::value ||
1344 std::is_same<ValueType, Mat3s>::value ||
1345 std::is_same<ValueType, Mat3d>::value ||
1346 std::is_same<ValueType, Mat4s>::value ||
1347 std::is_same<ValueType, Mat4d>::value)
return true;
1352 return std::is_floating_point<ElementT>::value || std::is_same<half, ElementT>::value;
1356 template<
typename ValueType_,
typename Codec_>
1361 return std::is_class<ValueType>::value && !std::is_same<half, ValueType>::value;
1365 template<
typename ValueType_,
typename Codec_>
1373 template<
typename ValueType_,
typename Codec_>
1378 return !this->valueType().compare(0, 4,
"quat");
1382 template<
typename ValueType_,
typename Codec_>
1387 return !this->valueType().compare(0, 3,
"mat");
1392 template<
typename ValueType_,
typename Codec_>
1396 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1400 template<
typename ValueType_,
typename Codec_>
1404 assert(n < this->dataSize());
1407 Codec::decode(this->data()[mIsUniform ? 0 : n], val);
1412 template<
typename ValueType_,
typename Codec_>
1417 if (this->isOutOfCore()) this->doLoad();
1419 return this->getUnsafe(n);
1423 template<
typename ValueType_,
typename Codec_>
1424 template<
typename T>
1428 val = static_cast<T>(this->getUnsafe(n));
1432 template<
typename ValueType_,
typename Codec_>
1433 template<
typename T>
1437 val = static_cast<T>(this->get(n));
1441 template<
typename ValueType_,
typename Codec_>
1449 template<
typename ValueType_,
typename Codec_>
1453 assert(n < this->dataSize());
1454 assert(!this->isOutOfCore());
1455 assert(!this->isUniform());
1460 Codec::encode(val, this->data()[mIsUniform ? 0 : n]);
1464 template<
typename ValueType_,
typename Codec_>
1469 if (this->isOutOfCore()) this->doLoad();
1470 if (this->isUniform()) this->expand();
1472 this->setUnsafe(n, val);
1476 template<
typename ValueType_,
typename Codec_>
1477 template<
typename T>
1481 this->setUnsafe(n, static_cast<ValueType>(val));
1485 template<
typename ValueType_,
typename Codec_>
1486 template<
typename T>
1490 this->set(n, static_cast<ValueType>(val));
1494 template<
typename ValueType_,
typename Codec_>
1502 template<
typename ValueType_,
typename Codec_>
1506 const TypedAttributeArray& sourceTypedArray = static_cast<const TypedAttributeArray&>(sourceArray);
1509 sourceTypedArray.
get(sourceIndex, sourceValue);
1511 this->set(n, sourceValue);
1515 template<
typename ValueType_,
typename Codec_>
1519 if (!mIsUniform)
return;
1524 tbb::spin_mutex::scoped_lock lock(mMutex);
1531 for (
Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1536 template<
typename ValueType_,
typename Codec_>
1540 if (mIsUniform)
return true;
1543 const ValueType_ val = this->get(0);
1544 for (
Index i = 1; i < this->dataSize(); i++) {
1548 this->collapse(this->get(0));
1553 template<
typename ValueType_,
typename Codec_>
1557 this->collapse(zeroVal<ValueType>());
1561 template<
typename ValueType_,
typename Codec_>
1566 tbb::spin_mutex::scoped_lock lock(mMutex);
1571 Codec::encode(uniformValue, this->data()[0]);
1575 template<
typename ValueType_,
typename Codec_>
1583 template<
typename ValueType_,
typename Codec_>
1587 if (this->isOutOfCore()) {
1588 tbb::spin_mutex::scoped_lock lock(mMutex);
1593 const Index size = mIsUniform ? 1 : this->dataSize();
1594 for (
Index i = 0; i < size; ++i) {
1595 Codec::encode(value, this->data()[i]);
1600 template<
typename ValueType_,
typename Codec_>
1608 template<
typename ValueType_,
typename Codec_>
1616 template<
typename ValueType_,
typename Codec_>
1624 template<
typename ValueType_,
typename Codec_>
1632 template<
typename ValueType_,
typename Codec_>
1636 #if OPENVDB_ABI_VERSION_NUMBER >= 5
1639 return (mFlags & OUTOFCORE);
1644 template<
typename ValueType_,
typename Codec_>
1648 #if OPENVDB_ABI_VERSION_NUMBER >= 5
1651 if (b) mFlags = static_cast<uint8_t>(mFlags | OUTOFCORE);
1652 else mFlags = static_cast<uint8_t>(mFlags & ~OUTOFCORE);
1657 template<
typename ValueType_,
typename Codec_>
1659 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1661 if (!(this->isOutOfCore()))
return;
1663 TypedAttributeArray<ValueType_, Codec_>*
self =
1664 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1668 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1669 this->doLoadUnsafe();
1673 template<
typename ValueType_,
typename Codec_>
1681 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1682 template<
typename ValueType_,
typename Codec_>
1686 return !this->isOutOfCore();
1691 template<
typename ValueType_,
typename Codec_>
1695 this->readMetadata(is);
1696 this->readBuffers(is);
1700 template<
typename ValueType_,
typename Codec_>
1707 is.read(reinterpret_cast<char*>(&bytes),
sizeof(
Index64));
1708 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1710 uint8_t flags = uint8_t(0);
1711 is.read(reinterpret_cast<char*>(&flags),
sizeof(uint8_t));
1714 uint8_t serializationFlags = uint8_t(0);
1715 is.read(reinterpret_cast<char*>(&serializationFlags),
sizeof(uint8_t));
1718 is.read(reinterpret_cast<char*>(&size),
sizeof(
Index));
1722 if (mFlags >= 0x20) {
1727 if (serializationFlags >= 0x10) {
1733 mIsUniform = serializationFlags & WRITEUNIFORM;
1734 mUsePagedRead = serializationFlags & WRITEPAGED;
1735 mCompressedBytes = bytes;
1736 mFlags |= PARTIALREAD;
1740 if (serializationFlags & WRITESTRIDED) {
1742 is.read(reinterpret_cast<char*>(&stride),
sizeof(
Index));
1743 mStrideOrTotalSize = stride;
1746 mStrideOrTotalSize = 1;
1751 template<
typename ValueType_,
typename Codec_>
1755 if (mUsePagedRead) {
1760 tbb::spin_mutex::scoped_lock lock(mMutex);
1764 uint8_t bloscCompressed(0);
1765 if (!mIsUniform) is.read(reinterpret_cast<char*>(&bloscCompressed),
sizeof(uint8_t));
1767 assert(mFlags & PARTIALREAD);
1768 std::unique_ptr<char[]> buffer(
new char[mCompressedBytes]);
1769 is.read(buffer.get(), mCompressedBytes);
1770 mCompressedBytes = 0;
1771 mFlags = static_cast<uint8_t>(mFlags & ~PARTIALREAD);
1775 if (bloscCompressed == uint8_t(1)) {
1779 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1781 if (newBuffer) buffer.reset(newBuffer.release());
1786 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1790 template<
typename ValueType_,
typename Codec_>
1794 if (!mUsePagedRead) {
1802 const bool delayLoad = (mappedFile.get() !=
nullptr);
1806 size_t compressedBytes(mCompressedBytes);
1807 mCompressedBytes = 0;
1808 mFlags = static_cast<uint8_t>(mFlags & ~PARTIALREAD);
1809 assert(!mPageHandle);
1814 assert(mPageHandle);
1816 tbb::spin_mutex::scoped_lock lock(mMutex);
1820 this->setOutOfCore(delayLoad);
1821 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1824 std::unique_ptr<char[]> buffer = mPageHandle->read();
1825 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1834 template<
typename ValueType_,
typename Codec_>
1838 this->write(os,
false);
1842 template<
typename ValueType_,
typename Codec_>
1846 this->writeMetadata(os, outputTransient,
false);
1847 this->writeBuffers(os, outputTransient);
1851 template<
typename ValueType_,
typename Codec_>
1855 if (!outputTransient && this->isTransient())
return;
1857 if (mFlags & PARTIALREAD) {
1861 #if OPENVDB_ABI_VERSION_NUMBER >= 5
1862 uint8_t flags(mFlags);
1864 uint8_t flags(mFlags & uint8_t(~OUTOFCORE));
1866 uint8_t serializationFlags(0);
1868 Index stride(mStrideOrTotalSize);
1869 bool strideOfOne(this->stride() == 1);
1874 if (bloscCompression) this->doLoad();
1876 size_t compressedBytes = 0;
1880 serializationFlags |= WRITESTRIDED;
1885 serializationFlags |= WRITEUNIFORM;
1886 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1888 else if (bloscCompression)
1890 if (paged) serializationFlags |= WRITEPAGED;
1892 const char* charBuffer = reinterpret_cast<const char*>(this->data());
1893 const size_t inBytes = this->arrayMemUsage();
1900 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1904 os.write(reinterpret_cast<const char*>(&bytes),
sizeof(
Index64));
1905 os.write(reinterpret_cast<const char*>(&flags),
sizeof(uint8_t));
1906 os.write(reinterpret_cast<const char*>(&serializationFlags),
sizeof(uint8_t));
1907 os.write(reinterpret_cast<const char*>(&size),
sizeof(
Index));
1910 if (!strideOfOne) os.write(reinterpret_cast<const char*>(&stride),
sizeof(
Index));
1914 template<
typename ValueType_,
typename Codec_>
1918 if (!outputTransient && this->isTransient())
return;
1920 if (mFlags & PARTIALREAD) {
1926 if (this->isUniform()) {
1927 os.write(reinterpret_cast<const char*>(this->data()),
sizeof(
StorageType));
1931 std::unique_ptr<char[]> compressedBuffer;
1932 size_t compressedBytes = 0;
1933 const char* charBuffer = reinterpret_cast<const char*>(this->data());
1934 const size_t inBytes = this->arrayMemUsage();
1936 if (compressedBuffer) {
1937 uint8_t bloscCompressed(1);
1938 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1939 os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
1942 uint8_t bloscCompressed(0);
1943 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1944 os.write(reinterpret_cast<const char*>(this->data()), inBytes);
1949 uint8_t bloscCompressed(0);
1950 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1951 os.write(reinterpret_cast<const char*>(this->data()), this->arrayMemUsage());
1956 template<
typename ValueType_,
typename Codec_>
1960 if (!outputTransient && this->isTransient())
return;
1964 if (!bloscCompression) {
1969 if (mFlags & PARTIALREAD) {
1975 os.
write(reinterpret_cast<const char*>(this->data()), this->arrayMemUsage());
1979 template<
typename ValueType_,
typename Codec_>
1983 if (!(this->isOutOfCore()))
return;
1989 assert(self->mPageHandle);
1990 assert(!(self->mFlags & PARTIALREAD));
1992 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
1994 self->mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1996 self->mPageHandle.reset();
2000 #if OPENVDB_ABI_VERSION_NUMBER >= 5
2001 self->mOutOfCore =
false;
2003 self->mFlags &= uint8_t(~OUTOFCORE);
2008 template<
typename ValueType_,
typename Codec_>
2023 template<
typename ValueType_,
typename Codec_>
2028 if(!otherT)
return false;
2029 if(this->mSize != otherT->mSize ||
2030 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
2032 this->attributeType() != this->attributeType())
return false;
2037 const StorageType *target = this->data(), *source = otherT->
data();
2038 if (!target && !source)
return true;
2039 if (!target || !source)
return false;
2040 Index n = this->mIsUniform ? 1 : mSize;
2046 #if OPENVDB_ABI_VERSION_NUMBER >= 6
2047 template<
typename ValueType_,
typename Codec_>
2049 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2051 return reinterpret_cast<char*>(this->data());
2055 template<
typename ValueType_,
typename Codec_>
2057 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
2059 return reinterpret_cast<const char*>(this->data());
2068 template <
typename CodecType,
typename ValueType>
2089 template <
typename ValueType>
2097 return (*functor)(array, n);
2102 (*functor)(array, n, value);
2111 template <
typename ValueType,
typename CodecType>
2119 template <
typename ValueType,
typename CodecType>
2122 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2123 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2124 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2126 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2141 mGetter = typedAccessor->
mGetter;
2142 mSetter = typedAccessor->
mSetter;
2144 mFiller = typedAccessor->
mFiller;
2147 template <
typename ValueType,
typename CodecType>
2151 if (mCollapseOnDestruction) const_cast<AttributeArray*>(this->mArray)->collapse();
2154 template <
typename ValueType,
typename CodecType>
2155 template <
bool IsUnknownCodec>
2156 typename std::enable_if<IsUnknownCodec, bool>::type
2161 return mArray->hasValueType<ValueType>();
2164 template <
typename ValueType,
typename CodecType>
2165 template <
bool IsUnknownCodec>
2166 typename std::enable_if<!IsUnknownCodec, bool>::type
2167 AttributeHandle<ValueType, CodecType>::compatibleType()
const
2171 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2174 template <
typename ValueType,
typename CodecType>
2181 template <
typename ValueType,
typename CodecType>
2184 Index index = n * mStrideOrTotalSize + m;
2185 assert(index < (mSize * mStrideOrTotalSize));
2189 template <
typename ValueType,
typename CodecType>
2192 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2195 template <
typename ValueType,
typename CodecType>
2196 template <
bool IsUnknownCodec>
2197 typename std::enable_if<IsUnknownCodec, ValueType>::type
2202 return (*mGetter)(mArray, index);
2205 template <
typename ValueType,
typename CodecType>
2206 template <
bool IsUnknownCodec>
2207 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2208 AttributeHandle<ValueType, CodecType>::get(
Index index)
const
2212 return TypedAttributeArray<ValueType, CodecType>::getUnsafe(mArray, index);
2215 template <
typename ValueType,
typename CodecType>
2221 template <
typename ValueType,
typename CodecType>
2231 template <
typename ValueType,
typename CodecType>
2239 template <
typename ValueType,
typename CodecType>
2243 if (expand) array.
expand();
2246 template <
typename ValueType,
typename CodecType>
2249 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2252 template <
typename ValueType,
typename CodecType>
2255 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2258 template <
typename ValueType,
typename CodecType>
2261 const_cast<AttributeArray*>(this->mArray)->
expand(fill);
2264 template <
typename ValueType,
typename CodecType>
2267 const_cast<AttributeArray*>(this->mArray)->
collapse();
2270 template <
typename ValueType,
typename CodecType>
2273 return const_cast<AttributeArray*>(this->mArray)->
compact();
2276 template <
typename ValueType,
typename CodecType>
2279 this->mCollapser(const_cast<AttributeArray*>(this->mArray), uniformValue);
2282 template <
typename ValueType,
typename CodecType>
2285 this->mFiller(const_cast<AttributeArray*>(this->mArray), value);
2288 template <
typename ValueType,
typename CodecType>
2289 template <
bool IsUnknownCodec>
2290 typename std::enable_if<IsUnknownCodec, void>::type
2295 (*this->mSetter)(const_cast<AttributeArray*>(this->mArray), index, value);
2298 template <
typename ValueType,
typename CodecType>
2299 template <
bool IsUnknownCodec>
2300 typename std::enable_if<!IsUnknownCodec, void>::type
2301 AttributeWriteHandle<ValueType, CodecType>::set(
Index index,
const ValueType& value)
const
2305 TypedAttributeArray<ValueType, CodecType>::setUnsafe(const_cast<AttributeArray*>(this->mArray), index, value);
2308 template <
typename ValueType,
typename CodecType>
2311 assert(this->mArray);
2312 return *const_cast<AttributeArray*>(this->mArray);
2320 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1634
Definition: AttributeArray.h:522
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:259
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:498
const AttributeArray * mArray
Definition: AttributeArray.h:881
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1414
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:465
uint8_t Type
Definition: AttributeArray.h:489
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1280
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:272
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1555
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:263
T & z()
Definition: Vec3.h:112
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:344
Convenience wrappers to using Blosc and reading and writing of Paged data.
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1358
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1853
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:595
Definition: AttributeArray.h:846
tbb::spin_mutex mMutex
Definition: AttributeArray.h:436
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2265
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2096
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:535
static void registerType(const NamePair &type, FactoryMethod)
Register a attribute type along with a factory function.
ValueType getUnsafe(Index n) const
Return the value at index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1402
AttributeArray(const AttributeArray &rhs)
Definition: AttributeArray.h:163
GetterPtr mGetter
Definition: AttributeArray.h:883
static const char * name()
Definition: AttributeArray.h:515
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1517
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...
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:1253
T & y()
Definition: Vec3.h:111
bool isUniform() const
Definition: AttributeArray.h:2216
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2076
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2271
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:652
int16_t Int16
Definition: Types.h:62
virtual void loadData() const =0
Ensures all data is in-core.
SharedPtr< MappedFile > Ptr
Definition: io.h:153
Base class for storing attribute data.
Definition: AttributeArray.h:118
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1217
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:336
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...
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1466
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1684
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:922
ValuePtr mCollapser
Definition: AttributeArray.h:885
size_t mCompressedBytes
Definition: AttributeArray.h:443
static bool isRegistered(const NamePair &type)
Return true if the given attribute type name is registered.
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
Definition: AttributeArray.h:511
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
Definition: Exceptions.h:84
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:552
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1229
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:544
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:347
Index stride() const
Definition: AttributeArray.h:868
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1260
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
Index stride() const override
Definition: AttributeArray.h:649
half Type
Definition: AttributeArray.h:481
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1384
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:590
Index size() const
Definition: AttributeArray.h:869
Definition: Compression.h:81
Definition: AttributeArray.h:519
typename T::ValueType ElementType
Definition: Types.h:235
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:350
const StorageType * data() const
Definition: AttributeArray.h:792
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:795
tbb::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:439
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:462
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:105
bool hasConstantStride() const
Definition: AttributeArray.h:2222
static const char * name()
Definition: AttributeArray.h:573
bool sizeOnly() const
Definition: StreamCompression.h:283
T Type
Definition: AttributeArray.h:511
Definition: Exceptions.h:85
Definition: AttributeArray.h:552
virtual Index storageTypeSize() const =0
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:1147
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2072
AttributeArray & operator=(const AttributeArray &rhs)
Definition: AttributeArray.h:173
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1792
uint8_t mUsePagedRead
Definition: AttributeArray.h:438
Definition: Exceptions.h:92
SerializationFlag
Definition: AttributeArray.h:136
ValuePtr mCollapser
Definition: AttributeArray.h:470
Definition: AttributeArray.h:549
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1338
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:661
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1702
ValuePtr mFiller
Definition: AttributeArray.h:886
SetterPtr mSetter
Definition: AttributeArray.h:884
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1844
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2093
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:198
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:329
static void unregisterType(const NamePair &type)
Remove a attribute type from the registry.
OPENVDB_DEPRECATED bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1626
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1958
static const char * name()
Definition: AttributeArray.h:533
Definition: AttributeArray.h:531
Definition: AttributeArray.h:122
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:635
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:2010
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
uint16_t StorageType
Definition: AttributeArray.h:566
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2113
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1375
Index32 Index
Definition: Types.h:61
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:95
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:461
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1367
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1192
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1237
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1451
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:645
Definition: Exceptions.h:91
virtual Index dataSize() const =0
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1585
uint64_t Index64
Definition: Types.h:60
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:124
GetterPtr mGetter
Definition: AttributeArray.h:468
AttributeArray::Ptr copyUncompressed() const override
Definition: AttributeArray.h:1289
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
virtual Index stride() const =0
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
OPENVDB_DEPRECATED bool isCompressed() const
Definition: AttributeArray.h:317
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:850
StorageType Type
Definition: AttributeArray.h:569
Definition: AttributeArray.h:540
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2101
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:534
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:791
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2071
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:454
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:543
virtual ~AttributeArray()
Definition: AttributeArray.h:156
StringIndexType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:854
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:921
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:177
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:110
Ptr(*)(Index, Index, bool) FactoryMethod
Definition: AttributeArray.h:147
AttributeArray()
Definition: AttributeArray.h:152
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:235
~TypedAttributeArray() override
Definition: AttributeArray.h:613
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:522
Flag
Definition: AttributeArray.h:127
short Type
Definition: AttributeArray.h:482
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2069
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.
Definition: AttributeArray.h:480
ValueType_ ValueType
Definition: AttributeArray.h:593
Write-able version of AttributeHandle.
Definition: AttributeArray.h:917
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:719
static const char * name()
Definition: AttributeArray.h:557
uint8_t mFlags
Definition: AttributeArray.h:437
Definition: AttributeArray.h:564
SetterPtr mSetter
Definition: AttributeArray.h:469
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1245
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1394
bool mIsUniform
Definition: AttributeArray.h:435
Definition: AttributeArray.h:505
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1753
void(*)(AttributeArray *array, const Index n, const StringIndexType &value) SetterPtr
Definition: AttributeArray.h:855
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2120
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:145
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:125
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:664
uint16_t Type
Definition: AttributeArray.h:490
std::istream & getInputStream()
Definition: StreamCompression.h:249
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:144
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
Definition: AttributeArray.h:488
Typed class for storing attribute data.
Definition: AttributeArray.h:584
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:286
OPENVDB_DEPRECATED bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1610
Index storageTypeSize() const override
Definition: AttributeArray.h:668
Definition: Exceptions.h:40
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:851
Definition: AttributeArray.h:569
ValuePtr mFiller
Definition: AttributeArray.h:471
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1675
static const char * name()
Definition: AttributeArray.h:526
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:391
Codec_ Codec
Definition: AttributeArray.h:594
bool sizeOnly() const
Definition: StreamCompression.h:246
std::string Name
Definition: Name.h:44
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2082
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
static const char * name()
Definition: AttributeArray.h:542
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2259
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1693
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1538
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:463
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2092
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:442
void(*)(AttributeArray *array, const StringIndexType &value) ValuePtr
Definition: AttributeArray.h:856
Definition: AttributeArray.h:508
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:280
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1916