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()));
96 template <
typename T>
struct Accessor;
104 CONSTANTSTRIDE = 0x8,
112 WRITEMEMCOMPRESS = 0x4,
120 tbb::spin_mutex::scoped_lock lock;
125 using Ptr = std::shared_ptr<AttributeArray>;
126 using ConstPtr = std::shared_ptr<const AttributeArray>;
137 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
139 #if OPENVDB_ABI_VERSION_NUMBER >= 6
154 [[deprecated(
"In-memory compression no longer supported, use AttributeArray::copy() instead")]]
170 #if OPENVDB_ABI_VERSION_NUMBER >= 6
171 virtual Name valueType()
const = 0;
208 bool constantStride =
true,
220 template<
typename AttributeArrayType>
221 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
224 template<
typename ValueType>
225 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
228 #if OPENVDB_ABI_VERSION_NUMBER >= 6
231 [[deprecated(
"From ABI 6 on, use copyValues() with source-target index pairs")]]
236 #if OPENVDB_ABI_VERSION_NUMBER >= 6
237 template<
typename IterT>
261 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
265 template<
typename IterT>
266 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
273 virtual void expand(
bool fill =
true) = 0;
281 [[deprecated(
"Previously this compressed the attribute array, now it does nothing")]]
286 [[deprecated(
"Previously this uncompressed the attribute array, now it does nothing")]]
296 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
317 uint8_t
flags()
const {
return mFlags; }
320 virtual void read(std::istream&) = 0;
323 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
325 virtual void write(std::ostream&)
const = 0;
332 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
338 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
349 #if OPENVDB_ABI_VERSION_NUMBER >= 6
350 virtual bool isDataLoaded()
const = 0;
361 friend class ::TestAttributeArray;
367 #if OPENVDB_ABI_VERSION_NUMBER >= 6
368 virtual char* dataAsByteArray() = 0;
370 virtual const char* dataAsByteArray()
const = 0;
373 template <
typename IterT>
374 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
375 bool rangeChecking =
true);
379 #if OPENVDB_ABI_VERSION_NUMBER >= 7
396 #if OPENVDB_ABI_VERSION_NUMBER < 6
398 size_t mCompressedBytes = 0;
400 uint8_t mUsePagedRead = 0;
401 tbb::atomic<Index32> mOutOfCore;
404 #else // #if OPENVDB_ABI_VERSION_NUMBER < 6
406 bool mIsUniform =
true;
409 uint8_t mUsePagedRead = 0;
429 template <
typename T>
437 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
449 namespace attribute_traits
481 template <
typename T>
484 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
485 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
486 static const char*
name() {
return "null"; }
492 template <
typename T>
495 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
496 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
497 static const char*
name() {
return "trnc"; }
504 static const char*
name() {
return "fxpt"; }
505 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
506 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
513 static const char*
name() {
return "ufxpt"; }
514 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
515 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
519 template <
bool OneByte,
typename Range=PositionRange>
522 template <
typename T>
525 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
526 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
529 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
539 template <
typename T>
544 static const char*
name() {
return "uvec"; }
553 template<
typename ValueType_,
typename Codec_ = NullCodec>
554 #if OPENVDB_ABI_VERSION_NUMBER >= 6 // for ABI=6, class is final to allow for de-virtualization
561 using Ptr = std::shared_ptr<TypedAttributeArray>;
562 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
566 using StorageType =
typename Codec::template Storage<ValueType>::Type;
572 const ValueType& uniformValue = zeroVal<ValueType>());
573 #if OPENVDB_ABI_VERSION_NUMBER >= 7
582 [[deprecated(
"Use copy-constructor without unused bool parameter")]]
606 [[deprecated(
"In-memory compression no longer supported, use AttributeArray::copy() instead")]]
610 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true,
611 const Metadata* metadata =
nullptr);
620 static const NamePair& attributeType();
625 static bool isRegistered();
627 static void registerType();
629 static void unregisterType();
636 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
640 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
643 #if OPENVDB_ABI_VERSION_NUMBER >= 6
644 Name valueType()
const override {
return typeNameAsString<ValueType>(); }
658 bool valueTypeIsFloatingPoint()
const override;
661 bool valueTypeIsClass()
const override;
664 bool valueTypeIsVector()
const override;
667 bool valueTypeIsQuaternion()
const override;
670 bool valueTypeIsMatrix()
const override;
674 size_t memUsage()
const override;
677 ValueType getUnsafe(
Index n)
const;
679 ValueType get(
Index n)
const;
681 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
683 template<
typename T>
void get(
Index n, T& value)
const;
690 void setUnsafe(
Index n,
const ValueType& value);
692 void set(
Index n,
const ValueType& value);
694 template<
typename T>
void setUnsafe(
Index n,
const T& value);
696 template<
typename T>
void set(
Index n,
const T& value);
703 #if OPENVDB_ABI_VERSION_NUMBER >= 6
704 [[deprecated(
"From ABI 6 on, use copyValues() with source-target index pairs")]]
713 void expand(
bool fill =
true)
override;
715 void collapse()
override;
717 bool compact()
override;
720 void collapse(
const ValueType& uniformValue);
723 void fill(
const ValueType& value);
726 static void collapse(
AttributeArray* array,
const ValueType& value);
731 [[deprecated(
"Previously this compressed the attribute array, now it does nothing")]]
732 bool compress()
override;
734 [[deprecated(
"Previously this uncompressed the attribute array, now it does nothing")]]
735 bool decompress()
override;
738 void read(std::istream&)
override;
742 void write(std::ostream& os,
bool outputTransient)
const override;
744 void write(std::ostream&)
const override;
747 void readMetadata(std::istream&)
override;
752 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
755 void readBuffers(std::istream&)
override;
759 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
769 inline bool isOutOfCore()
const;
772 void loadData()
const override;
774 #if OPENVDB_ABI_VERSION_NUMBER >= 6
775 bool isDataLoaded()
const override;
780 AccessorBasePtr getAccessor()
const override;
787 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
790 friend class ::TestAttributeArray;
792 #if OPENVDB_ABI_VERSION_NUMBER >= 7
797 inline void doLoad()
const;
800 inline void doLoadUnsafe(
const bool compression =
true)
const;
802 inline bool compressUnsafe();
805 inline void setOutOfCore(
const bool);
810 #if OPENVDB_ABI_VERSION_NUMBER >= 6
811 char* dataAsByteArray()
override;
813 const char* dataAsByteArray()
const override;
816 size_t arrayMemUsage()
const;
823 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride, metadata);
826 static std::unique_ptr<const NamePair> sTypeName;
827 std::unique_ptr<StorageType[]> mData;
829 Index mStrideOrTotalSize;
830 #if OPENVDB_ABI_VERSION_NUMBER < 6 // as of ABI=6, this data lives in the base class to reduce memory
831 bool mIsUniform =
true;
832 mutable tbb::spin_mutex mMutex;
842 template <
typename ValueType,
typename CodecType = UnknownCodec>
847 using Ptr = std::shared_ptr<Handle>;
886 friend class ::TestAttributeArray;
888 template <
bool IsUnknownCodec>
889 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
891 template <
bool IsUnknownCodec>
892 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
894 template <
bool IsUnknownCodec>
895 typename std::enable_if<IsUnknownCodec, ValueType>::type get(
Index index)
const;
897 template <
bool IsUnknownCodec>
898 typename std::enable_if<!IsUnknownCodec, ValueType>::type get(
Index index)
const;
903 Index mStrideOrTotalSize;
905 bool mCollapseOnDestruction;
913 template <
typename ValueType,
typename CodecType = UnknownCodec>
918 using Ptr = std::shared_ptr<Handle>;
940 void fill(
const ValueType& value);
948 friend class ::TestAttributeArray;
950 template <
bool IsUnknownCodec>
951 typename std::enable_if<IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
953 template <
bool IsUnknownCodec>
954 typename std::enable_if<!IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
964 template<
typename ValueType>
966 NullCodec::decode(
const ValueType& data, ValueType& val)
972 template<
typename ValueType>
974 NullCodec::encode(
const ValueType& val, ValueType& data)
980 template<
typename StorageType,
typename ValueType>
982 TruncateCodec::decode(
const StorageType& data, ValueType& val)
984 val =
static_cast<ValueType
>(data);
988 template<
typename StorageType,
typename ValueType>
990 TruncateCodec::encode(
const ValueType& val, StorageType& data)
992 data =
static_cast<StorageType
>(val);
996 template <
bool OneByte,
typename Range>
997 template<
typename StorageType,
typename ValueType>
1001 val = fixedPointToFloatingPoint<ValueType>(data);
1005 val = Range::template decode<ValueType>(val);
1009 template <
bool OneByte,
typename Range>
1010 template<
typename StorageType,
typename ValueType>
1016 const ValueType newVal = Range::template encode<ValueType>(val);
1018 data = floatingPointToFixedPoint<StorageType>(newVal);
1022 template<
typename T>
1026 val = math::QuantizedUnitVec::unpack(data);
1030 template<
typename T>
1034 data = math::QuantizedUnitVec::pack(val);
1042 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1044 template <
typename IterT>
1045 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1051 assert(sourceArray.
isDataLoaded() && this->isDataLoaded());
1053 assert(this->storageTypeSize()*this->stride() ==
1057 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
1058 char*
const targetBuffer = this->dataAsByteArray();
1059 assert(sourceBuffer && targetBuffer);
1061 if (rangeChecking && this->isUniform()) {
1065 const bool sourceIsUniform = sourceArray.
isUniform();
1067 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
1068 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1070 for (IterT it(iter); it; ++it) {
1071 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1072 const Index targetIndex = it.targetIndex();
1074 if (rangeChecking) {
1075 if (sourceIndex >= sourceDataSize) {
1077 "Cannot copy array data as source index exceeds size of source array.");
1079 if (targetIndex >= targetDataSize) {
1081 "Cannot copy array data as target index exceeds size of target array.");
1085 assert(sourceIndex < sourceArray.
dataSize());
1086 assert(targetIndex < this->dataSize());
1087 if (this->isUniform()) assert(targetIndex ==
Index(0));
1090 const size_t targetOffset(targetIndex * bytes);
1091 const size_t sourceOffset(sourceIndex * bytes);
1093 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1097 template <
typename IterT>
1098 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1100 this->doCopyValues(sourceArray, iter,
false);
1103 template <
typename IterT>
1104 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1108 if (bytes != this->storageTypeSize()) {
1125 this->doCopyValues(sourceArray, iter,
true);
1139 template<
typename ValueType_,
typename Codec_>
1143 template<
typename ValueType_,
typename Codec_>
1149 , mStrideOrTotalSize(strideOrTotalSize)
1151 if (constantStride) {
1153 if (strideOrTotalSize == 0) {
1155 "stride to be at least one.")
1160 if (mStrideOrTotalSize < n) {
1162 "a total size of at least the number of elements in the array.")
1166 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1167 Codec::encode(uniformValue, this->
data()[0]);
1171 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1172 template<
typename ValueType_,
typename Codec_>
1179 template<
typename ValueType_,
typename Codec_>
1181 const tbb::spin_mutex::scoped_lock& lock)
1184 template<typename ValueType_, typename Codec_>
1189 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1190 #if OPENVDB_ABI_VERSION_NUMBER < 6
1191 , mIsUniform(rhs.mIsUniform)
1196 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1201 template<
typename ValueType_,
typename Codec_>
1202 TypedAttributeArray<ValueType_, Codec_>&
1207 tbb::spin_mutex::scoped_lock lock(mMutex);
1208 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1215 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1218 if (this->validData()) {
1220 std::memcpy(
static_cast<void*
>(this->data()), rhs.
data(), this->arrayMemUsage());
1228 template<
typename ValueType_,
typename Codec_>
1232 static std::once_flag once;
1233 std::call_once(once, []()
1235 sTypeName.reset(
new NamePair(typeNameAsString<ValueType>(), Codec::name()));
1241 template<
typename ValueType_,
typename Codec_>
1249 template<
typename ValueType_,
typename Codec_>
1257 template<
typename ValueType_,
typename Codec_>
1265 template<
typename ValueType_,
typename Codec_>
1274 typedMetadata ? typedMetadata->
value() : zeroVal<ValueType>()));
1277 template<
typename ValueType_,
typename Codec_>
1287 template<
typename ValueType_,
typename Codec_>
1297 template<
typename ValueType_,
typename Codec_>
1301 #if OPENVDB_ABI_VERSION_NUMBER < 7
1302 tbb::spin_mutex::scoped_lock lock(mMutex);
1308 template<
typename ValueType_,
typename Codec_>
1312 return this->copy();
1316 template<
typename ValueType_,
typename Codec_>
1320 if (this->isOutOfCore())
return 0;
1322 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1326 template<
typename ValueType_,
typename Codec_>
1328 TypedAttributeArray<ValueType_, Codec_>::allocate()
1332 mData.reset(
new StorageType[1]);
1335 const size_t size(this->dataSize());
1337 mData.reset(
new StorageType[size]);
1342 template<
typename ValueType_,
typename Codec_>
1344 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1347 if (this->isOutOfCore()) {
1348 this->setOutOfCore(
false);
1349 this->mPageHandle.reset();
1351 if (mData) mData.reset();
1355 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1356 template<
typename ValueType_,
typename Codec_>
1362 if (std::is_same<ValueType, Quats>::value ||
1363 std::is_same<ValueType, Quatd>::value ||
1364 std::is_same<ValueType, Mat3s>::value ||
1365 std::is_same<ValueType, Mat3d>::value ||
1366 std::is_same<ValueType, Mat4s>::value ||
1367 std::is_same<ValueType, Mat4d>::value)
return true;
1372 return std::is_floating_point<ElementT>::value || std::is_same<half, ElementT>::value;
1376 template<
typename ValueType_,
typename Codec_>
1381 return std::is_class<ValueType>::value && !std::is_same<half, ValueType>::value;
1385 template<
typename ValueType_,
typename Codec_>
1393 template<
typename ValueType_,
typename Codec_>
1398 return !this->valueType().compare(0, 4,
"quat");
1402 template<
typename ValueType_,
typename Codec_>
1407 return !this->valueType().compare(0, 3,
"mat");
1412 template<
typename ValueType_,
typename Codec_>
1416 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1420 template<
typename ValueType_,
typename Codec_>
1424 assert(n < this->dataSize());
1427 Codec::decode(this->data()[mIsUniform ? 0 : n], val);
1432 template<
typename ValueType_,
typename Codec_>
1437 if (this->isOutOfCore()) this->doLoad();
1439 return this->getUnsafe(n);
1443 template<
typename ValueType_,
typename Codec_>
1444 template<
typename T>
1448 val =
static_cast<T
>(this->getUnsafe(n));
1452 template<
typename ValueType_,
typename Codec_>
1453 template<
typename T>
1457 val =
static_cast<T
>(this->get(n));
1461 template<
typename ValueType_,
typename Codec_>
1469 template<
typename ValueType_,
typename Codec_>
1473 assert(n < this->dataSize());
1474 assert(!this->isOutOfCore());
1475 assert(!this->isUniform());
1480 Codec::encode(val, this->data()[mIsUniform ? 0 : n]);
1484 template<
typename ValueType_,
typename Codec_>
1489 if (this->isOutOfCore()) this->doLoad();
1490 if (this->isUniform()) this->expand();
1492 this->setUnsafe(n, val);
1496 template<
typename ValueType_,
typename Codec_>
1497 template<
typename T>
1501 this->setUnsafe(n,
static_cast<ValueType>(val));
1505 template<
typename ValueType_,
typename Codec_>
1506 template<
typename T>
1510 this->set(n,
static_cast<ValueType>(val));
1514 template<
typename ValueType_,
typename Codec_>
1522 template<
typename ValueType_,
typename Codec_>
1529 sourceTypedArray.
get(sourceIndex, sourceValue);
1531 this->set(n, sourceValue);
1535 template<
typename ValueType_,
typename Codec_>
1539 if (!mIsUniform)
return;
1544 tbb::spin_mutex::scoped_lock lock(mMutex);
1551 for (
Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1556 template<
typename ValueType_,
typename Codec_>
1560 if (mIsUniform)
return true;
1563 const ValueType_ val = this->get(0);
1564 for (
Index i = 1; i < this->dataSize(); i++) {
1568 this->collapse(this->get(0));
1573 template<
typename ValueType_,
typename Codec_>
1577 this->collapse(zeroVal<ValueType>());
1581 template<
typename ValueType_,
typename Codec_>
1586 tbb::spin_mutex::scoped_lock lock(mMutex);
1591 Codec::encode(uniformValue, this->data()[0]);
1595 template<
typename ValueType_,
typename Codec_>
1603 template<
typename ValueType_,
typename Codec_>
1607 if (this->isOutOfCore()) {
1608 tbb::spin_mutex::scoped_lock lock(mMutex);
1613 const Index size = mIsUniform ? 1 : this->dataSize();
1614 for (
Index i = 0; i < size; ++i) {
1615 Codec::encode(value, this->data()[i]);
1620 template<
typename ValueType_,
typename Codec_>
1628 template<
typename ValueType_,
typename Codec_>
1636 template<
typename ValueType_,
typename Codec_>
1644 template<
typename ValueType_,
typename Codec_>
1652 template<
typename ValueType_,
typename Codec_>
1660 template<
typename ValueType_,
typename Codec_>
1668 template<
typename ValueType_,
typename Codec_>
1670 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1672 if (!(this->isOutOfCore()))
return;
1674 TypedAttributeArray<ValueType_, Codec_>*
self =
1675 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1679 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1680 this->doLoadUnsafe();
1684 template<
typename ValueType_,
typename Codec_>
1692 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1693 template<
typename ValueType_,
typename Codec_>
1697 return !this->isOutOfCore();
1702 template<
typename ValueType_,
typename Codec_>
1706 this->readMetadata(is);
1707 this->readBuffers(is);
1711 template<
typename ValueType_,
typename Codec_>
1718 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1719 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1721 uint8_t flags = uint8_t(0);
1722 is.read(
reinterpret_cast<char*
>(&flags),
sizeof(uint8_t));
1725 uint8_t serializationFlags = uint8_t(0);
1726 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1729 is.read(
reinterpret_cast<char*
>(&size),
sizeof(
Index));
1733 if (mFlags >= 0x20) {
1738 if (serializationFlags >= 0x10) {
1744 mIsUniform = serializationFlags & WRITEUNIFORM;
1745 mUsePagedRead = serializationFlags & WRITEPAGED;
1746 mCompressedBytes = bytes;
1747 mFlags |= PARTIALREAD;
1751 if (serializationFlags & WRITESTRIDED) {
1753 is.read(
reinterpret_cast<char*
>(&stride),
sizeof(
Index));
1754 mStrideOrTotalSize = stride;
1757 mStrideOrTotalSize = 1;
1762 template<
typename ValueType_,
typename Codec_>
1766 if (mUsePagedRead) {
1771 tbb::spin_mutex::scoped_lock lock(mMutex);
1775 uint8_t bloscCompressed(0);
1776 if (!mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1778 assert(mFlags & PARTIALREAD);
1779 std::unique_ptr<char[]> buffer(
new char[mCompressedBytes]);
1780 is.read(buffer.get(), mCompressedBytes);
1781 mCompressedBytes = 0;
1782 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1786 if (bloscCompressed == uint8_t(1)) {
1790 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1792 if (newBuffer) buffer.reset(newBuffer.release());
1797 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1801 template<
typename ValueType_,
typename Codec_>
1805 if (!mUsePagedRead) {
1813 const bool delayLoad = (mappedFile.get() !=
nullptr);
1817 size_t compressedBytes(mCompressedBytes);
1818 mCompressedBytes = 0;
1819 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1820 assert(!mPageHandle);
1825 assert(mPageHandle);
1827 tbb::spin_mutex::scoped_lock lock(mMutex);
1831 this->setOutOfCore(delayLoad);
1832 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1835 std::unique_ptr<char[]> buffer = mPageHandle->read();
1836 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1845 template<
typename ValueType_,
typename Codec_>
1849 this->write(os,
false);
1853 template<
typename ValueType_,
typename Codec_>
1857 this->writeMetadata(os, outputTransient,
false);
1858 this->writeBuffers(os, outputTransient);
1862 template<
typename ValueType_,
typename Codec_>
1866 if (!outputTransient && this->isTransient())
return;
1868 if (mFlags & PARTIALREAD) {
1872 uint8_t flags(mFlags);
1873 uint8_t serializationFlags(0);
1875 Index stride(mStrideOrTotalSize);
1876 bool strideOfOne(this->stride() == 1);
1881 if (bloscCompression) this->doLoad();
1883 size_t compressedBytes = 0;
1887 serializationFlags |= WRITESTRIDED;
1892 serializationFlags |= WRITEUNIFORM;
1893 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1895 else if (bloscCompression)
1897 if (paged) serializationFlags |= WRITEPAGED;
1899 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1900 const size_t inBytes = this->arrayMemUsage();
1907 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1911 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1912 os.write(
reinterpret_cast<const char*
>(&flags),
sizeof(uint8_t));
1913 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1914 os.write(
reinterpret_cast<const char*
>(&size),
sizeof(
Index));
1917 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&stride),
sizeof(
Index));
1921 template<
typename ValueType_,
typename Codec_>
1925 if (!outputTransient && this->isTransient())
return;
1927 if (mFlags & PARTIALREAD) {
1933 if (this->isUniform()) {
1934 os.write(
reinterpret_cast<const char*
>(this->data()),
sizeof(
StorageType));
1938 std::unique_ptr<char[]> compressedBuffer;
1939 size_t compressedBytes = 0;
1940 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1941 const size_t inBytes = this->arrayMemUsage();
1943 if (compressedBuffer) {
1944 uint8_t bloscCompressed(1);
1945 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1946 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
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()), inBytes);
1956 uint8_t bloscCompressed(0);
1957 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1958 os.write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1963 template<
typename ValueType_,
typename Codec_>
1967 if (!outputTransient && this->isTransient())
return;
1971 if (!bloscCompression) {
1976 if (mFlags & PARTIALREAD) {
1982 os.
write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1986 template<
typename ValueType_,
typename Codec_>
1990 if (!(this->isOutOfCore()))
return;
1996 assert(self->mPageHandle);
1997 assert(!(self->mFlags & PARTIALREAD));
1999 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
2001 self->mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
2003 self->mPageHandle.reset();
2007 self->mOutOfCore =
false;
2011 template<
typename ValueType_,
typename Codec_>
2026 template<
typename ValueType_,
typename Codec_>
2031 if(!otherT)
return false;
2032 if(this->mSize != otherT->mSize ||
2033 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
2035 this->attributeType() != this->attributeType())
return false;
2040 const StorageType *target = this->data(), *source = otherT->
data();
2041 if (!target && !source)
return true;
2042 if (!target || !source)
return false;
2043 Index n = this->mIsUniform ? 1 : mSize;
2049 #if OPENVDB_ABI_VERSION_NUMBER >= 6
2050 template<
typename ValueType_,
typename Codec_>
2052 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2054 return reinterpret_cast<char*
>(this->data());
2058 template<
typename ValueType_,
typename Codec_>
2060 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
2062 return reinterpret_cast<const char*
>(this->data());
2071 template <
typename CodecType,
typename ValueType>
2092 template <
typename ValueType>
2100 return (*functor)(array, n);
2105 (*functor)(array, n, value);
2114 template <
typename ValueType,
typename CodecType>
2122 template <
typename ValueType,
typename CodecType>
2125 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2126 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2127 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2129 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2150 template <
typename ValueType,
typename CodecType>
2154 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
2157 template <
typename ValueType,
typename CodecType>
2158 template <
bool IsUnknownCodec>
2159 typename std::enable_if<IsUnknownCodec, bool>::type
2164 return mArray->hasValueType<ValueType>();
2167 template <
typename ValueType,
typename CodecType>
2168 template <
bool IsUnknownCodec>
2169 typename std::enable_if<!IsUnknownCodec, bool>::type
2170 AttributeHandle<ValueType, CodecType>::compatibleType()
const
2174 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2177 template <
typename ValueType,
typename CodecType>
2184 template <
typename ValueType,
typename CodecType>
2187 Index index = n * mStrideOrTotalSize + m;
2188 assert(index < (mSize * mStrideOrTotalSize));
2192 template <
typename ValueType,
typename CodecType>
2195 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2198 template <
typename ValueType,
typename CodecType>
2199 template <
bool IsUnknownCodec>
2200 typename std::enable_if<IsUnknownCodec, ValueType>::type
2205 return (*mGetter)(mArray, index);
2208 template <
typename ValueType,
typename CodecType>
2209 template <
bool IsUnknownCodec>
2210 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2218 template <
typename ValueType,
typename CodecType>
2221 return mArray->isUniform();
2224 template <
typename ValueType,
typename CodecType>
2227 return mArray->hasConstantStride();
2234 template <
typename ValueType,
typename CodecType>
2242 template <
typename ValueType,
typename CodecType>
2249 template <
typename ValueType,
typename CodecType>
2252 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2255 template <
typename ValueType,
typename CodecType>
2258 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2261 template <
typename ValueType,
typename CodecType>
2267 template <
typename ValueType,
typename CodecType>
2273 template <
typename ValueType,
typename CodecType>
2279 template <
typename ValueType,
typename CodecType>
2282 this->mCollapser(
const_cast<AttributeArray*
>(this->mArray), uniformValue);
2285 template <
typename ValueType,
typename CodecType>
2291 template <
typename ValueType,
typename CodecType>
2292 template <
bool IsUnknownCodec>
2293 typename std::enable_if<IsUnknownCodec, void>::type
2298 (*this->mSetter)(
const_cast<AttributeArray*
>(this->mArray), index, value);
2301 template <
typename ValueType,
typename CodecType>
2302 template <
bool IsUnknownCodec>
2303 typename std::enable_if<!IsUnknownCodec, void>::type
2311 template <
typename ValueType,
typename CodecType>
2314 assert(this->mArray);
2323 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2085
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:303
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1803
uint8_t mFlags
Definition: AttributeArray.h:408
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1203
Index32 Index
Definition: openvdb/Types.h:32
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1965
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2116
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:433
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
Definition: AttributeArray.h:503
Convenience wrappers to using Blosc and reading and writing of Paged data.
ValuePtr mFiller
Definition: AttributeArray.h:883
Definition: openvdb/Types.h:183
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1764
T Type
Definition: AttributeArray.h:482
bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1630
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:648
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
SetterPtr mSetter
Definition: AttributeArray.h:440
virtual bool decompress()=0
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:515
Definition: AttributeArray.h:459
virtual Index stride() const =0
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:69
uint8_t mUsePagedRead
Definition: AttributeArray.h:409
SharedPtr< MappedFile > Ptr
Definition: io.h:136
bool sizeOnly() const
Definition: StreamCompression.h:256
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2074
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.
virtual ~AttributeHandle()
Definition: AttributeArray.h:2151
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:523
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1414
Definition: AttributeArray.h:119
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1378
static Ptr create(const NamePair &type, Index length, Index stride=1, bool constantStride=true, const Metadata *metadata=nullptr, const ScopedRegistryLock *lock=nullptr)
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:477
void(*)(AttributeArray *array, const Index n, const Index &value) SetterPtr
Definition: AttributeArray.h:852
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:444
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1404
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:561
virtual bool valueTypeIsQuaternion() const =0
Return true if the value type is a quaternion.
Definition: AttributeArray.h:512
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: AttributeArray.h:431
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:1144
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1486
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1855
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2073
AttributeHandle & operator=(const AttributeHandle &)=default
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1864
@ COMPRESS_BLOSC
Definition: Compression.h:56
virtual bool compress()=0
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:209
virtual bool valueTypeIsMatrix() const =0
Return true if the value type is a matrix.
static const char * name()
Definition: AttributeArray.h:528
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1358
void set(Index n, const ValueType &value)
Definition: AttributeArray.h:2250
void setStreaming(bool state)
Specify whether this attribute is to be streamed off disk, in which case, the attributes are collapse...
Write-able version of AttributeHandle.
Definition: AttributeArray.h:915
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition: AttributeArray.h:1422
uint64_t Index64
Definition: openvdb/Types.h:31
short Type
Definition: AttributeArray.h:453
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
Definition: AttributeArray.h:482
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1434
Index index(Index n, Index m) const
Definition: AttributeArray.h:2185
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1695
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1251
virtual ~AttributeArray()
Definition: AttributeArray.h:133
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:2286
virtual const NamePair & type() const =0
Return the name of this attribute's type.
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:848
Definition: openvdb/Exceptions.h:64
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2123
AttributeArray & operator=(AttributeArray &&)=delete
uint8_t Type
Definition: AttributeArray.h:460
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
TypedAttributeArray(TypedAttributeArray &&)=delete
Move constructor disabled.
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2075
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
#define OPENVDB_THROW(exception, message)
Definition: openvdb/Exceptions.h:74
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:514
const AttributeArray * mArray
Definition: AttributeArray.h:878
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:2013
half Type
Definition: AttributeArray.h:452
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:847
TypedAttributeArray(const TypedAttributeArray &, bool)
Deep copy constructor.
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:639
static Ptr create(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2236
tbb::spin_mutex mMutex
Definition: AttributeArray.h:407
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:221
AttributeHandle(const AttributeHandle &)=default
void setHidden(bool state)
Specify whether this attribute should be hidden (e.g., from UI or iterators).
tbb::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:410
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:425
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:259
virtual void set(const Index n, const AttributeArray &sourceArray, const Index sourceIndex)=0
Set value at given index n from sourceIndex of another sourceArray.
static const char * name()
Definition: AttributeArray.h:544
bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1646
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:225
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:787
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:622
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:358
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
std::string Name
Definition: Name.h:17
bool operator==(const AttributeArray &other) const
Index(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:851
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1686
virtual Index storageTypeSize() const =0
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2095
Definition: AttributeArray.h:536
static const char * name()
Definition: AttributeArray.h:486
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:79
Definition: AttributeArray.h:476
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...
uint16_t StorageType
Definition: AttributeArray.h:537
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
bool mIsUniform
Definition: AttributeArray.h:406
Typed class for storing attribute data.
Definition: AttributeArray.h:559
virtual void readBuffers(std::istream &)=0
Read attribute buffers from a stream.
virtual void collapse()=0
Replace the existing array with a uniform zero value.
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1259
virtual Index dataSize() const =0
void set(Index n, Index m, const ValueType &value)
Definition: AttributeArray.h:2256
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1575
uint16_t Type
Definition: AttributeArray.h:461
~TypedAttributeArray() override
Definition: AttributeArray.h:598
virtual void loadData() const =0
Ensures all data is in-core.
std::istream & getInputStream()
Definition: StreamCompression.h:222
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1279
Definition: openvdb/Exceptions.h:65
Index size() const
Definition: AttributeArray.h:866
void collapse(const ValueType &uniformValue)
Definition: AttributeArray.h:2280
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:493
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1230
Definition: AttributeArray.h:491
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1713
static const char * name()
Definition: AttributeArray.h:497
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:432
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:89
SerializationFlag
Definition: AttributeArray.h:109
bool isUniform() const
Definition: AttributeArray.h:2219
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1605
AttributeArray::Ptr copyUncompressed() const override
Definition: AttributeArray.h:1310
virtual ~AttributeWriteHandle()=default
Definition: AttributeArray.h:844
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition: AttributeArray.h:128
Flag
Definition: AttributeArray.h:101
Definition: AttributeArray.h:480
TypedAttributeArray & operator=(TypedAttributeArray &&)=delete
Move assignment operator disabled.
virtual ~AccessorBase()=default
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1387
virtual bool valueTypeIsVector() const =0
Return true if the value type is a vector.
typename T::ValueType ElementType
Definition: openvdb/Types.h:186
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2096
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2262
const AttributeArray & array() const
Definition: AttributeArray.h:2178
bool hasConstantStride() const
Definition: AttributeArray.h:2225
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
virtual bool valueTypeIsClass() const =0
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:493
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:413
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:919
void(*)(AttributeArray *array, const Index &value) ValuePtr
Definition: AttributeArray.h:853
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:436
virtual Index valueTypeSize() const =0
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2243
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1923
SetterPtr mSetter
Definition: AttributeArray.h:881
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1654
virtual void write(std::ostream &) const =0
Write attribute metadata and buffers to a stream, don't write transient attributes.
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:709
Codec_ Codec
Definition: AttributeArray.h:565
AttributeArray & operator=(const AttributeArray &rhs)
ValueType get(Index n, Index m=0) const
Definition: AttributeArray.h:2193
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2099
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2104
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:296
Index stride() const
Definition: AttributeArray.h:865
AttributeArray()
Definition: AttributeArray.h:132
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition: AttributeArray.h:1471
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2079
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1299
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1243
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 setTransient(bool state)
Specify whether this attribute should only exist in memory and not be serialized during stream output...
Definition: AttributeArray.h:451
AttributeArray(const AttributeArray &rhs, const tbb::spin_mutex::scoped_lock &)
static Ptr create(Index n, Index strideOrTotalSize=1, bool constantStride=true, const Metadata *metadata=nullptr)
Return a new attribute array of the given length n and stride with uniform value zero.
Definition: AttributeArray.h:1267
Definition: AttributeArray.h:521
ValuePtr mCollapser
Definition: AttributeArray.h:441
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
virtual AttributeArray::Ptr copy() const =0
Return a copy of this attribute.
AttributeArray(AttributeArray &&)=delete
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1558
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1395
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:317
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:651
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:101
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:783
GetterPtr mGetter
Definition: AttributeArray.h:439
T & y()
Definition: Vec3.h:90
ValuePtr mCollapser
Definition: AttributeArray.h:882
static const char * name()
Definition: AttributeArray.h:513
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1537
const StorageType * data() const
Definition: AttributeArray.h:784
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:632
int16_t Int16
Definition: openvdb/Types.h:33
virtual Name codecType() const =0
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Base class for storing attribute data.
Definition: AttributeArray.h:93
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1704
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:566
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:246
static const char * name()
Definition: AttributeArray.h:504
Definition: AttributeArray.h:523
static void clearRegistry(const ScopedRegistryLock *lock=nullptr)
Clear the attribute type registry.
GetterPtr mGetter
Definition: AttributeArray.h:880
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:98
StorageType Type
Definition: AttributeArray.h:540
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2274
Definition: openvdb/Exceptions.h:58
virtual AttributeArray::Ptr copyUncompressed() const =0
Return a copy of this attribute.
Definition: openvdb/Exceptions.h:13
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:505
virtual Index size() const =0
Definition: AttributeArray.h:540
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:506
virtual void write(std::ostream &, bool outputTransient) const =0
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:171
size_t mCompressedBytes
Definition: AttributeArray.h:414
AttributeArray & array()
Definition: AttributeArray.h:2312
bool sizeOnly() const
Definition: StreamCompression.h:219
T & z()
Definition: Vec3.h:91
Definition: openvdb/Exceptions.h:57
virtual void read(std::istream &)=0
Read attribute metadata and buffers from a stream.
virtual void writeMetadata(std::ostream &, bool outputTransient, bool paged) const =0
AttributeArray(const AttributeArray &rhs)
virtual void readMetadata(std::istream &)=0
Read attribute metadata from a stream.
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:126
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:918
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:314
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:434
ValueType_ ValueType
Definition: AttributeArray.h:564
Index stride() const override
Definition: AttributeArray.h:636
Index storageTypeSize() const override
Definition: AttributeArray.h:655
virtual void writeBuffers(std::ostream &, bool outputTransient) const =0
ValuePtr mFiller
Definition: AttributeArray.h:442
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2268
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:311
virtual size_t memUsage() const =0
Return the number of bytes of memory used by this attribute.
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253