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,
147 tbb::spin_mutex::scoped_lock lock;
152 using Ptr = std::shared_ptr<AttributeArray>;
153 using ConstPtr = std::shared_ptr<const AttributeArray>;
159 #if OPENVDB_ABI_VERSION_NUMBER >= 5
168 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
170 #if OPENVDB_ABI_VERSION_NUMBER >= 6
172 : mIsUniform(rhs.mIsUniform)
174 , mUsePagedRead(rhs.mUsePagedRead)
175 , mOutOfCore(rhs.mOutOfCore)
185 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
192 else mPageHandle.reset();
212 virtual Index size()
const = 0;
216 virtual Index stride()
const = 0;
220 virtual Index dataSize()
const = 0;
222 #if OPENVDB_ABI_VERSION_NUMBER >= 6
223 virtual Name valueType()
const = 0;
227 virtual Name codecType()
const = 0;
231 virtual Index valueTypeSize()
const = 0;
235 virtual Index storageTypeSize()
const = 0;
238 virtual bool valueTypeIsFloatingPoint()
const = 0;
241 virtual bool valueTypeIsClass()
const = 0;
244 virtual bool valueTypeIsVector()
const = 0;
247 virtual bool valueTypeIsQuaternion()
const = 0;
250 virtual bool valueTypeIsMatrix()
const = 0;
254 virtual size_t memUsage()
const = 0;
260 bool constantStride =
true,
const ScopedRegistryLock* lock =
nullptr);
262 static bool isRegistered(
const NamePair& type,
const ScopedRegistryLock* lock =
nullptr);
264 static void clearRegistry(
const ScopedRegistryLock* lock =
nullptr);
267 virtual const NamePair& type()
const = 0;
269 template<
typename AttributeArrayType>
270 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
273 template<
typename ValueType>
274 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
278 #if OPENVDB_ABI_VERSION_NUMBER >= 6
286 #if OPENVDB_ABI_VERSION_NUMBER >= 6
287 template<
typename IterT>
311 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
315 template<
typename IterT>
316 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
320 virtual bool isUniform()
const = 0;
323 virtual void expand(
bool fill =
true) = 0;
325 virtual void collapse() = 0;
327 virtual bool compact() = 0;
337 virtual bool compress() = 0;
343 virtual bool decompress() = 0;
349 void setHidden(
bool state);
351 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
356 void setTransient(
bool state);
364 void setStreaming(
bool state);
372 uint8_t
flags()
const {
return mFlags; }
375 virtual void read(std::istream&) = 0;
378 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
380 virtual void write(std::ostream&)
const = 0;
383 virtual void readMetadata(std::istream&) = 0;
387 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
390 virtual void readBuffers(std::istream&) = 0;
393 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
402 virtual void loadData()
const = 0;
404 #if OPENVDB_ABI_VERSION_NUMBER >= 6
405 virtual bool isDataLoaded()
const = 0;
416 friend class ::TestAttributeArray;
422 #if OPENVDB_ABI_VERSION_NUMBER >= 6
423 virtual char* dataAsByteArray() = 0;
425 virtual const char* dataAsByteArray()
const = 0;
428 template <
typename IterT>
429 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
430 bool rangeChecking =
true);
435 void setConstantStride(
bool state);
444 static void unregisterType(
const NamePair& type,
447 #if OPENVDB_ABI_VERSION_NUMBER < 6
449 size_t mCompressedBytes = 0;
451 uint8_t mUsePagedRead = 0;
452 #if OPENVDB_ABI_VERSION_NUMBER >= 5
453 tbb::atomic<Index32> mOutOfCore;
457 #else // #if OPENVDB_ABI_VERSION_NUMBER < 6
459 bool mIsUniform =
true;
462 uint8_t mUsePagedRead = 0;
482 template <
typename T>
490 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
502 namespace attribute_traits
534 template <
typename T>
537 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
538 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
539 static const char*
name() {
return "null"; }
545 template <
typename T>
548 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
549 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
550 static const char*
name() {
return "trnc"; }
557 static const char*
name() {
return "fxpt"; }
558 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
559 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
566 static const char*
name() {
return "ufxpt"; }
567 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
568 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
572 template <
bool OneByte,
typename Range=PositionRange>
575 template <
typename T>
578 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
579 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
582 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
592 template <
typename T>
597 static const char*
name() {
return "uvec"; }
606 template<
typename ValueType_,
typename Codec_ = NullCodec>
607 #if OPENVDB_ABI_VERSION_NUMBER >= 6 // for ABI=6, class is final to allow for de-virtualization
614 using Ptr = std::shared_ptr<TypedAttributeArray>;
615 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
619 using StorageType =
typename Codec::template Storage<ValueType>::Type;
625 const ValueType& uniformValue = zeroVal<ValueType>());
648 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true);
657 static const NamePair& attributeType();
662 static bool isRegistered();
664 static void registerType();
666 static void unregisterType();
673 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
677 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
680 #if OPENVDB_ABI_VERSION_NUMBER >= 6
681 Name valueType()
const override {
return typeNameAsString<ValueType>(); }
695 bool valueTypeIsFloatingPoint()
const override;
698 bool valueTypeIsClass()
const override;
701 bool valueTypeIsVector()
const override;
704 bool valueTypeIsQuaternion()
const override;
707 bool valueTypeIsMatrix()
const override;
711 size_t memUsage()
const override;
714 ValueType getUnsafe(
Index n)
const;
716 ValueType get(
Index n)
const;
718 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
720 template<
typename T>
void get(
Index n, T& value)
const;
727 void setUnsafe(
Index n,
const ValueType& value);
729 void set(
Index n,
const ValueType& value);
731 template<
typename T>
void setUnsafe(
Index n,
const T& value);
733 template<
typename T>
void set(
Index n,
const T& value);
740 #if OPENVDB_ABI_VERSION_NUMBER >= 6
750 void expand(
bool fill =
true)
override;
752 void collapse()
override;
754 bool compact()
override;
757 void collapse(
const ValueType& uniformValue);
760 void fill(
const ValueType& value);
763 static void collapse(
AttributeArray* array,
const ValueType& value);
773 void read(std::istream&)
override;
777 void write(std::ostream& os,
bool outputTransient)
const override;
779 void write(std::ostream&)
const override;
782 void readMetadata(std::istream&)
override;
787 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
790 void readBuffers(std::istream&)
override;
794 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
804 inline bool isOutOfCore()
const;
807 void loadData()
const override;
809 #if OPENVDB_ABI_VERSION_NUMBER >= 6
810 bool isDataLoaded()
const override;
815 AccessorBasePtr getAccessor()
const override;
822 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
825 friend class ::TestAttributeArray;
828 inline void doLoad()
const;
831 inline void doLoadUnsafe(
const bool compression =
true)
const;
833 inline bool compressUnsafe();
836 inline void setOutOfCore(
const bool);
841 #if OPENVDB_ABI_VERSION_NUMBER >= 6
842 char* dataAsByteArray()
override;
844 const char* dataAsByteArray()
const override;
847 size_t arrayMemUsage()
const;
853 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride);
856 static tbb::atomic<const NamePair*> sTypeName;
857 std::unique_ptr<StorageType[]> mData;
859 Index mStrideOrTotalSize;
860 #if OPENVDB_ABI_VERSION_NUMBER < 6 // as of ABI=6, this data lives in the base class to reduce memory
861 bool mIsUniform =
true;
862 mutable tbb::spin_mutex mMutex;
872 template <
typename ValueType,
typename CodecType = UnknownCodec>
877 using Ptr = std::shared_ptr<Handle>;
886 static Ptr create(
const AttributeArray& array,
const bool collapseOnDestruction =
true);
898 bool isUniform()
const;
899 bool hasConstantStride()
const;
916 friend class ::TestAttributeArray;
918 template <
bool IsUnknownCodec>
919 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
921 template <
bool IsUnknownCodec>
922 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
924 template <
bool IsUnknownCodec>
925 typename std::enable_if<IsUnknownCodec, ValueType>::type get(
Index index)
const;
927 template <
bool IsUnknownCodec>
928 typename std::enable_if<!IsUnknownCodec, ValueType>::type get(
Index index)
const;
933 Index mStrideOrTotalSize;
935 bool mCollapseOnDestruction;
943 template <
typename ValueType,
typename CodecType = UnknownCodec>
948 using Ptr = std::shared_ptr<Handle>;
959 void expand(
bool fill =
true);
963 void collapse(
const ValueType& uniformValue);
970 void fill(
const ValueType& value);
972 void set(
Index n,
const ValueType& value);
973 void set(
Index n,
Index m,
const ValueType& value);
978 friend class ::TestAttributeArray;
980 template <
bool IsUnknownCodec>
981 typename std::enable_if<IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
983 template <
bool IsUnknownCodec>
984 typename std::enable_if<!IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
994 template<
typename ValueType>
996 NullCodec::decode(
const ValueType& data, ValueType& val)
1002 template<
typename ValueType>
1004 NullCodec::encode(
const ValueType& val, ValueType& data)
1010 template<
typename StorageType,
typename ValueType>
1012 TruncateCodec::decode(
const StorageType& data, ValueType& val)
1014 val =
static_cast<ValueType
>(data);
1018 template<
typename StorageType,
typename ValueType>
1020 TruncateCodec::encode(
const ValueType& val, StorageType& data)
1022 data =
static_cast<StorageType
>(val);
1026 template <
bool OneByte,
typename Range>
1027 template<
typename StorageType,
typename ValueType>
1031 val = fixedPointToFloatingPoint<ValueType>(data);
1035 val = Range::template decode<ValueType>(val);
1039 template <
bool OneByte,
typename Range>
1040 template<
typename StorageType,
typename ValueType>
1046 const ValueType newVal = Range::template encode<ValueType>(val);
1048 data = floatingPointToFixedPoint<StorageType>(newVal);
1052 template<
typename T>
1056 val = math::QuantizedUnitVec::unpack(data);
1060 template<
typename T>
1064 data = math::QuantizedUnitVec::pack(val);
1072 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1074 template <
typename IterT>
1075 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1081 assert(sourceArray.
isDataLoaded() && this->isDataLoaded());
1083 assert(this->storageTypeSize()*this->stride() ==
1087 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
1088 char*
const targetBuffer = this->dataAsByteArray();
1089 assert(sourceBuffer && targetBuffer);
1091 if (rangeChecking && this->isUniform()) {
1095 const bool sourceIsUniform = sourceArray.
isUniform();
1097 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
1098 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1100 for (IterT it(iter); it; ++it) {
1101 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1102 const Index targetIndex = it.targetIndex();
1104 if (rangeChecking) {
1105 if (sourceIndex >= sourceDataSize) {
1107 "Cannot copy array data as source index exceeds size of source array.");
1109 if (targetIndex >= targetDataSize) {
1111 "Cannot copy array data as target index exceeds size of target array.");
1115 assert(sourceIndex < sourceArray.
dataSize());
1116 assert(targetIndex < this->dataSize());
1117 if (this->isUniform()) assert(targetIndex ==
Index(0));
1120 const size_t targetOffset(targetIndex * bytes);
1121 const size_t sourceOffset(sourceIndex * bytes);
1123 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1127 template <
typename IterT>
1128 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1130 this->doCopyValues(sourceArray, iter,
false);
1133 template <
typename IterT>
1134 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1138 if (bytes != this->storageTypeSize()) {
1155 this->doCopyValues(sourceArray, iter,
true);
1169 template<
typename ValueType_,
typename Codec_>
1173 template<
typename ValueType_,
typename Codec_>
1179 , mStrideOrTotalSize(strideOrTotalSize)
1181 if (constantStride) {
1183 if (strideOrTotalSize == 0) {
1185 "stride to be at least one.")
1190 if (mStrideOrTotalSize < n) {
1192 "a total size of at least the number of elements in the array.")
1196 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1197 Codec::encode(uniformValue, this->
data()[0]);
1201 template<
typename ValueType_,
typename Codec_>
1205 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1206 #if OPENVDB_ABI_VERSION_NUMBER < 6
1207 , mIsUniform(rhs.mIsUniform)
1212 std::memcpy(this->
data(), rhs.
data(), this->arrayMemUsage());
1217 template<
typename ValueType_,
typename Codec_>
1223 tbb::spin_mutex::scoped_lock lock(mMutex);
1224 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1231 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1234 if (this->validData()) {
1236 std::memcpy(this->newDataAsByteArray(), rhs.newDataAsByteArray(), this->arrayMemUsage());
1242 template<
typename ValueType_,
typename Codec_>
1246 if (sTypeName ==
nullptr) {
1248 if (sTypeName.compare_and_swap(s,
nullptr) !=
nullptr)
delete s;
1254 template<
typename ValueType_,
typename Codec_>
1262 template<
typename ValueType_,
typename Codec_>
1270 template<
typename ValueType_,
typename Codec_>
1278 template<
typename ValueType_,
typename Codec_>
1285 template<
typename ValueType_,
typename Codec_>
1295 template<
typename ValueType_,
typename Codec_>
1305 template<
typename ValueType_,
typename Codec_>
1309 tbb::spin_mutex::scoped_lock lock(mMutex);
1314 template<
typename ValueType_,
typename Codec_>
1318 tbb::spin_mutex::scoped_lock lock(mMutex);
1323 template<
typename ValueType_,
typename Codec_>
1327 if (this->isOutOfCore())
return 0;
1329 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1333 template<
typename ValueType_,
typename Codec_>
1335 TypedAttributeArray<ValueType_, Codec_>::allocate()
1339 mData.reset(
new StorageType[1]);
1342 const size_t size(this->dataSize());
1344 mData.reset(
new StorageType[size]);
1349 template<
typename ValueType_,
typename Codec_>
1351 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1354 if (this->isOutOfCore()) {
1355 this->setOutOfCore(
false);
1356 this->mPageHandle.reset();
1358 if (mData) mData.reset();
1362 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1363 template<
typename ValueType_,
typename Codec_>
1369 if (std::is_same<ValueType, Quats>::value ||
1370 std::is_same<ValueType, Quatd>::value ||
1371 std::is_same<ValueType, Mat3s>::value ||
1372 std::is_same<ValueType, Mat3d>::value ||
1373 std::is_same<ValueType, Mat4s>::value ||
1374 std::is_same<ValueType, Mat4d>::value)
return true;
1379 return std::is_floating_point<ElementT>::value || std::is_same<half, ElementT>::value;
1383 template<
typename ValueType_,
typename Codec_>
1388 return std::is_class<ValueType>::value && !std::is_same<half, ValueType>::value;
1392 template<
typename ValueType_,
typename Codec_>
1400 template<
typename ValueType_,
typename Codec_>
1405 return !this->valueType().compare(0, 4,
"quat");
1409 template<
typename ValueType_,
typename Codec_>
1414 return !this->valueType().compare(0, 3,
"mat");
1419 template<
typename ValueType_,
typename Codec_>
1423 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1427 template<
typename ValueType_,
typename Codec_>
1431 assert(n < this->dataSize());
1434 Codec::decode(this->data()[mIsUniform ? 0 : n], val);
1439 template<
typename ValueType_,
typename Codec_>
1444 if (this->isOutOfCore()) this->doLoad();
1446 return this->getUnsafe(n);
1450 template<
typename ValueType_,
typename Codec_>
1451 template<
typename T>
1455 val =
static_cast<T
>(this->getUnsafe(n));
1459 template<
typename ValueType_,
typename Codec_>
1460 template<
typename T>
1464 val =
static_cast<T
>(this->get(n));
1468 template<
typename ValueType_,
typename Codec_>
1476 template<
typename ValueType_,
typename Codec_>
1480 assert(n < this->dataSize());
1481 assert(!this->isOutOfCore());
1482 assert(!this->isUniform());
1487 Codec::encode(val, this->data()[mIsUniform ? 0 : n]);
1491 template<
typename ValueType_,
typename Codec_>
1496 if (this->isOutOfCore()) this->doLoad();
1497 if (this->isUniform()) this->expand();
1499 this->setUnsafe(n, val);
1503 template<
typename ValueType_,
typename Codec_>
1504 template<
typename T>
1508 this->setUnsafe(n,
static_cast<ValueType>(val));
1512 template<
typename ValueType_,
typename Codec_>
1513 template<
typename T>
1517 this->set(n,
static_cast<ValueType>(val));
1521 template<
typename ValueType_,
typename Codec_>
1529 template<
typename ValueType_,
typename Codec_>
1536 sourceTypedArray.
get(sourceIndex, sourceValue);
1538 this->set(n, sourceValue);
1542 template<
typename ValueType_,
typename Codec_>
1546 if (!mIsUniform)
return;
1551 tbb::spin_mutex::scoped_lock lock(mMutex);
1558 for (
Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1563 template<
typename ValueType_,
typename Codec_>
1567 if (mIsUniform)
return true;
1570 const ValueType_ val = this->get(0);
1571 for (
Index i = 1; i < this->dataSize(); i++) {
1575 this->collapse(this->get(0));
1580 template<
typename ValueType_,
typename Codec_>
1584 this->collapse(zeroVal<ValueType>());
1588 template<
typename ValueType_,
typename Codec_>
1593 tbb::spin_mutex::scoped_lock lock(mMutex);
1598 Codec::encode(uniformValue, this->data()[0]);
1602 template<
typename ValueType_,
typename Codec_>
1610 template<
typename ValueType_,
typename Codec_>
1614 if (this->isOutOfCore()) {
1615 tbb::spin_mutex::scoped_lock lock(mMutex);
1620 const Index size = mIsUniform ? 1 : this->dataSize();
1621 for (
Index i = 0; i < size; ++i) {
1622 Codec::encode(value, this->data()[i]);
1627 template<
typename ValueType_,
typename Codec_>
1635 template<
typename ValueType_,
typename Codec_>
1643 template<
typename ValueType_,
typename Codec_>
1651 template<
typename ValueType_,
typename Codec_>
1659 template<
typename ValueType_,
typename Codec_>
1663 #if OPENVDB_ABI_VERSION_NUMBER >= 5
1666 return (mFlags & OUTOFCORE);
1671 template<
typename ValueType_,
typename Codec_>
1675 #if OPENVDB_ABI_VERSION_NUMBER >= 5
1678 if (b) mFlags =
static_cast<uint8_t
>(mFlags | OUTOFCORE);
1679 else mFlags =
static_cast<uint8_t
>(mFlags & ~OUTOFCORE);
1684 template<
typename ValueType_,
typename Codec_>
1686 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1688 if (!(this->isOutOfCore()))
return;
1690 TypedAttributeArray<ValueType_, Codec_>*
self =
1691 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1695 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1696 this->doLoadUnsafe();
1700 template<
typename ValueType_,
typename Codec_>
1708 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1709 template<
typename ValueType_,
typename Codec_>
1713 return !this->isOutOfCore();
1718 template<
typename ValueType_,
typename Codec_>
1722 this->readMetadata(is);
1723 this->readBuffers(is);
1727 template<
typename ValueType_,
typename Codec_>
1734 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1735 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1737 uint8_t flags = uint8_t(0);
1738 is.read(
reinterpret_cast<char*
>(&flags),
sizeof(uint8_t));
1741 uint8_t serializationFlags = uint8_t(0);
1742 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1745 is.read(
reinterpret_cast<char*
>(&size),
sizeof(
Index));
1749 if (mFlags >= 0x20) {
1754 if (serializationFlags >= 0x10) {
1760 mIsUniform = serializationFlags & WRITEUNIFORM;
1761 mUsePagedRead = serializationFlags & WRITEPAGED;
1762 mCompressedBytes = bytes;
1763 mFlags |= PARTIALREAD;
1767 if (serializationFlags & WRITESTRIDED) {
1769 is.read(
reinterpret_cast<char*
>(&stride),
sizeof(
Index));
1770 mStrideOrTotalSize = stride;
1773 mStrideOrTotalSize = 1;
1778 template<
typename ValueType_,
typename Codec_>
1782 if (mUsePagedRead) {
1787 tbb::spin_mutex::scoped_lock lock(mMutex);
1791 uint8_t bloscCompressed(0);
1792 if (!mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1794 assert(mFlags & PARTIALREAD);
1795 std::unique_ptr<char[]> buffer(
new char[mCompressedBytes]);
1796 is.read(buffer.get(), mCompressedBytes);
1797 mCompressedBytes = 0;
1798 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1802 if (bloscCompressed == uint8_t(1)) {
1806 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1808 if (newBuffer) buffer.reset(newBuffer.release());
1813 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1817 template<
typename ValueType_,
typename Codec_>
1821 if (!mUsePagedRead) {
1829 const bool delayLoad = (mappedFile.get() !=
nullptr);
1833 size_t compressedBytes(mCompressedBytes);
1834 mCompressedBytes = 0;
1835 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1836 assert(!mPageHandle);
1841 assert(mPageHandle);
1843 tbb::spin_mutex::scoped_lock lock(mMutex);
1847 this->setOutOfCore(delayLoad);
1848 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1851 std::unique_ptr<char[]> buffer = mPageHandle->read();
1852 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1861 template<
typename ValueType_,
typename Codec_>
1865 this->write(os,
false);
1869 template<
typename ValueType_,
typename Codec_>
1873 this->writeMetadata(os, outputTransient,
false);
1874 this->writeBuffers(os, outputTransient);
1878 template<
typename ValueType_,
typename Codec_>
1882 if (!outputTransient && this->isTransient())
return;
1884 if (mFlags & PARTIALREAD) {
1888 #if OPENVDB_ABI_VERSION_NUMBER >= 5
1889 uint8_t flags(mFlags);
1891 uint8_t flags(mFlags & uint8_t(~OUTOFCORE));
1893 uint8_t serializationFlags(0);
1895 Index stride(mStrideOrTotalSize);
1896 bool strideOfOne(this->stride() == 1);
1901 if (bloscCompression) this->doLoad();
1903 size_t compressedBytes = 0;
1907 serializationFlags |= WRITESTRIDED;
1912 serializationFlags |= WRITEUNIFORM;
1913 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1915 else if (bloscCompression)
1917 if (paged) serializationFlags |= WRITEPAGED;
1919 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1920 const size_t inBytes = this->arrayMemUsage();
1927 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1931 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1932 os.write(
reinterpret_cast<const char*
>(&flags),
sizeof(uint8_t));
1933 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1934 os.write(
reinterpret_cast<const char*
>(&size),
sizeof(
Index));
1937 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&stride),
sizeof(
Index));
1941 template<
typename ValueType_,
typename Codec_>
1945 if (!outputTransient && this->isTransient())
return;
1947 if (mFlags & PARTIALREAD) {
1953 if (this->isUniform()) {
1954 os.write(
reinterpret_cast<const char*
>(this->data()),
sizeof(
StorageType));
1958 std::unique_ptr<char[]> compressedBuffer;
1959 size_t compressedBytes = 0;
1960 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1961 const size_t inBytes = this->arrayMemUsage();
1963 if (compressedBuffer) {
1964 uint8_t bloscCompressed(1);
1965 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1966 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
1969 uint8_t bloscCompressed(0);
1970 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1971 os.write(
reinterpret_cast<const char*
>(this->data()), inBytes);
1976 uint8_t bloscCompressed(0);
1977 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1978 os.write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1983 template<
typename ValueType_,
typename Codec_>
1987 if (!outputTransient && this->isTransient())
return;
1991 if (!bloscCompression) {
1996 if (mFlags & PARTIALREAD) {
2002 os.
write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
2006 template<
typename ValueType_,
typename Codec_>
2010 if (!(this->isOutOfCore()))
return;
2016 assert(self->mPageHandle);
2017 assert(!(self->mFlags & PARTIALREAD));
2019 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
2021 self->mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
2023 self->mPageHandle.reset();
2027 #if OPENVDB_ABI_VERSION_NUMBER >= 5
2028 self->mOutOfCore =
false;
2030 self->mFlags &= uint8_t(~OUTOFCORE);
2035 template<
typename ValueType_,
typename Codec_>
2050 template<
typename ValueType_,
typename Codec_>
2055 if(!otherT)
return false;
2056 if(this->mSize != otherT->mSize ||
2057 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
2059 this->attributeType() != this->attributeType())
return false;
2064 const StorageType *target = this->data(), *source = otherT->
data();
2065 if (!target && !source)
return true;
2066 if (!target || !source)
return false;
2067 Index n = this->mIsUniform ? 1 : mSize;
2073 #if OPENVDB_ABI_VERSION_NUMBER >= 6
2074 template<
typename ValueType_,
typename Codec_>
2076 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2078 return reinterpret_cast<char*
>(this->data());
2082 template<
typename ValueType_,
typename Codec_>
2084 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
2086 return reinterpret_cast<const char*
>(this->data());
2095 template <
typename CodecType,
typename ValueType>
2116 template <
typename ValueType>
2124 return (*functor)(array, n);
2129 (*functor)(array, n, value);
2138 template <
typename ValueType,
typename CodecType>
2146 template <
typename ValueType,
typename CodecType>
2149 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2150 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2151 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2153 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2168 mGetter = typedAccessor->
mGetter;
2169 mSetter = typedAccessor->
mSetter;
2171 mFiller = typedAccessor->
mFiller;
2174 template <
typename ValueType,
typename CodecType>
2178 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
2181 template <
typename ValueType,
typename CodecType>
2182 template <
bool IsUnknownCodec>
2183 typename std::enable_if<IsUnknownCodec, bool>::type
2188 return mArray->hasValueType<ValueType>();
2191 template <
typename ValueType,
typename CodecType>
2192 template <
bool IsUnknownCodec>
2193 typename std::enable_if<!IsUnknownCodec, bool>::type
2194 AttributeHandle<ValueType, CodecType>::compatibleType()
const
2198 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2201 template <
typename ValueType,
typename CodecType>
2208 template <
typename ValueType,
typename CodecType>
2211 Index index = n * mStrideOrTotalSize + m;
2212 assert(index < (mSize * mStrideOrTotalSize));
2216 template <
typename ValueType,
typename CodecType>
2219 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2222 template <
typename ValueType,
typename CodecType>
2223 template <
bool IsUnknownCodec>
2224 typename std::enable_if<IsUnknownCodec, ValueType>::type
2229 return (*mGetter)(mArray, index);
2232 template <
typename ValueType,
typename CodecType>
2233 template <
bool IsUnknownCodec>
2234 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2235 AttributeHandle<ValueType, CodecType>::get(
Index index)
const
2239 return TypedAttributeArray<ValueType, CodecType>::getUnsafe(mArray, index);
2242 template <
typename ValueType,
typename CodecType>
2248 template <
typename ValueType,
typename CodecType>
2258 template <
typename ValueType,
typename CodecType>
2266 template <
typename ValueType,
typename CodecType>
2270 if (expand) array.
expand();
2273 template <
typename ValueType,
typename CodecType>
2276 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2279 template <
typename ValueType,
typename CodecType>
2282 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2285 template <
typename ValueType,
typename CodecType>
2291 template <
typename ValueType,
typename CodecType>
2297 template <
typename ValueType,
typename CodecType>
2303 template <
typename ValueType,
typename CodecType>
2306 this->mCollapser(
const_cast<AttributeArray*
>(this->mArray), uniformValue);
2309 template <
typename ValueType,
typename CodecType>
2315 template <
typename ValueType,
typename CodecType>
2316 template <
bool IsUnknownCodec>
2317 typename std::enable_if<IsUnknownCodec, void>::type
2322 (*this->mSetter)(
const_cast<AttributeArray*
>(this->mArray), index, value);
2325 template <
typename ValueType,
typename CodecType>
2326 template <
bool IsUnknownCodec>
2327 typename std::enable_if<!IsUnknownCodec, void>::type
2328 AttributeWriteHandle<ValueType, CodecType>::set(
Index index,
const ValueType& value)
const
2332 TypedAttributeArray<ValueType, CodecType>::setUnsafe(
const_cast<AttributeArray*
>(this->mArray), index, value);
2335 template <
typename ValueType,
typename CodecType>
2338 assert(this->mArray);
2347 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:818
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1394
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:270
Definition: Exceptions.h:85
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1219
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:489
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:669
Definition: AttributeArray.h:504
std::istream & getInputStream()
Definition: StreamCompression.h:249
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1819
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:274
T & z()
Definition: Vec3.h:112
OPENVDB_DEPRECATED bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1653
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1985
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:366
Convenience wrappers to using Blosc and reading and writing of Paged data.
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:659
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
tbb::spin_mutex mMutex
Definition: AttributeArray.h:460
std::string Name
Definition: Name.h:44
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...
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:685
AttributeArray(const AttributeArray &rhs)
Definition: AttributeArray.h:171
bool isUniform() const
Definition: AttributeArray.h:2243
Definition: AttributeArray.h:543
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:415
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1264
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:286
Definition: AttributeArray.h:564
T & y()
Definition: Vec3.h:111
GetterPtr mGetter
Definition: AttributeArray.h:910
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:637
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:576
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
Write-able version of AttributeHandle.
Definition: AttributeArray.h:944
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...
StorageType Type
Definition: AttributeArray.h:593
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.
static const char * name()
Definition: AttributeArray.h:557
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:2037
virtual void loadData() const =0
Ensures all data is in-core.
ValueType_ ValueType
Definition: AttributeArray.h:617
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:358
ValuePtr mCollapser
Definition: AttributeArray.h:912
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
static const char * name()
Definition: AttributeArray.h:539
Definition: AttributeArray.h:555
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:949
size_t mCompressedBytes
Definition: AttributeArray.h:467
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:546
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1478
Definition: Exceptions.h:91
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1612
Definition: Exceptions.h:84
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:369
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:272
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:688
Index stride() const
Definition: AttributeArray.h:895
Index size() const
Definition: AttributeArray.h:896
Codec_ Codec
Definition: AttributeArray.h:618
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:372
Index32 Index
Definition: Types.h:61
tbb::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:463
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1272
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1421
bool hasConstantStride() const
Definition: AttributeArray.h:2249
OPENVDB_DEPRECATED bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1637
@ COMPRESS_BLOSC
Definition: Compression.h:83
Index storageTypeSize() const override
Definition: AttributeArray.h:692
static const char * name()
Definition: AttributeArray.h:581
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:486
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1661
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:558
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2128
virtual Index storageTypeSize() const =0
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:746
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:198
Definition: AttributeArray.h:145
AttributeArray & operator=(const AttributeArray &rhs)
Definition: AttributeArray.h:181
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1307
static const char * name()
Definition: AttributeArray.h:597
short Type
Definition: AttributeArray.h:506
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1385
uint8_t mUsePagedRead
Definition: AttributeArray.h:462
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1880
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
SerializationFlag
Definition: AttributeArray.h:136
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1565
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:567
ValuePtr mCollapser
Definition: AttributeArray.h:494
ValuePtr mFiller
Definition: AttributeArray.h:913
Definition: Exceptions.h:92
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1780
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:95
ValueType getUnsafe(Index n) const
Return the value at index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1429
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2109
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1702
Definition: AttributeArray.h:512
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1441
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:351
SetterPtr mSetter
Definition: AttributeArray.h:911
uint8_t Type
Definition: AttributeArray.h:513
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:105
Definition: AttributeArray.h:873
half Type
Definition: AttributeArray.h:505
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1720
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1244
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2103
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1943
typename T::ValueType ElementType
Definition: Types.h:235
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2140
bool sizeOnly() const
Definition: StreamCompression.h:246
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:485
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
int16_t Int16
Definition: Types.h:62
virtual Index dataSize() const =0
Definition: AttributeArray.h:576
GetterPtr mGetter
Definition: AttributeArray.h:492
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:124
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1256
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:877
virtual Index stride() const =0
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:619
T Type
Definition: AttributeArray.h:535
Index stride() const override
Definition: AttributeArray.h:673
OPENVDB_DEPRECATED bool isCompressed() const
Definition: AttributeArray.h:331
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:478
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:568
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2099
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1544
virtual ~AttributeArray()
Definition: AttributeArray.h:164
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:948
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2096
Ptr(*)(Index, Index, bool) FactoryMethod
Definition: AttributeArray.h:155
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:110
AttributeArray()
Definition: AttributeArray.h:160
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1582
StringIndexType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:881
Definition: AttributeArray.h:573
Definition: AttributeArray.h:529
Flag
Definition: AttributeArray.h:127
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2098
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2119
uint64_t Index64
Definition: Types.h:60
Definition: AttributeArray.h:588
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2123
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2120
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1493
Definition: AttributeArray.h:593
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:1280
uint8_t mFlags
Definition: AttributeArray.h:461
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:822
Base class for storing attribute data.
Definition: AttributeArray.h:118
SetterPtr mSetter
Definition: AttributeArray.h:493
void(*)(AttributeArray *array, const Index n, const StringIndexType &value) SetterPtr
Definition: AttributeArray.h:882
bool mIsUniform
Definition: AttributeArray.h:459
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1365
Definition: AttributeArray.h:532
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1411
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:614
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:676
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:153
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:559
#define OPENVDB_VERSION_NAME
Definition: version.h:134
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1871
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2147
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:152
Typed class for storing attribute data.
Definition: AttributeArray.h:608
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1711
bool sizeOnly() const
Definition: StreamCompression.h:283
const StorageType * data() const
Definition: AttributeArray.h:819
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
uint16_t Type
Definition: AttributeArray.h:514
uint16_t StorageType
Definition: AttributeArray.h:590
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1287
Definition: Exceptions.h:40
ValuePtr mFiller
Definition: AttributeArray.h:495
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1729
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:413
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:498
Definition: AttributeArray.h:546
Definition: AttributeArray.h:122
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:878
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:1174
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
SharedPtr< MappedFile > Ptr
Definition: io.h:163
AttributeArray::Ptr copyUncompressed() const override
Definition: AttributeArray.h:1316
Definition: AttributeArray.h:535
void(*)(AttributeArray *array, const StringIndexType &value) ValuePtr
Definition: AttributeArray.h:883
static const char * name()
Definition: AttributeArray.h:566
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:466
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:487
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1402
const AttributeArray * mArray
Definition: AttributeArray.h:908
static const char * name()
Definition: AttributeArray.h:550
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:280