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>
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()));
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;
155 virtual Index size()
const = 0;
159 virtual Index stride()
const = 0;
163 virtual Index dataSize()
const = 0;
166 virtual Name valueType()
const = 0;
169 virtual Name codecType()
const = 0;
173 virtual Index valueTypeSize()
const = 0;
177 virtual Index storageTypeSize()
const = 0;
180 virtual bool valueTypeIsFloatingPoint()
const = 0;
183 virtual bool valueTypeIsClass()
const = 0;
186 virtual bool valueTypeIsVector()
const = 0;
189 virtual bool valueTypeIsQuaternion()
const = 0;
192 virtual bool valueTypeIsMatrix()
const = 0;
195 virtual size_t memUsage()
const = 0;
201 bool constantStride =
true,
203 const ScopedRegistryLock* lock =
nullptr);
206 static bool isRegistered(
const NamePair& type,
const ScopedRegistryLock* lock =
nullptr);
208 static void clearRegistry(
const ScopedRegistryLock* lock =
nullptr);
211 virtual const NamePair& type()
const = 0;
213 template<
typename AttributeArrayType>
214 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
217 template<
typename ValueType>
218 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
250 template<
typename IterT>
251 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
255 template<
typename IterT>
256 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
259 virtual bool isUniform()
const = 0;
262 virtual void expand(
bool fill =
true) = 0;
264 virtual void collapse() = 0;
266 virtual bool compact() = 0;
272 virtual bool compress() = 0;
277 virtual bool decompress() = 0;
283 void setHidden(
bool state);
285 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
290 void setTransient(
bool state);
298 void setStreaming(
bool state);
306 uint8_t
flags()
const {
return mFlags; }
309 virtual void read(std::istream&) = 0;
312 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
314 virtual void write(std::ostream&)
const = 0;
317 virtual void readMetadata(std::istream&) = 0;
321 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
324 virtual void readBuffers(std::istream&) = 0;
327 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
336 virtual void loadData()
const = 0;
339 virtual bool isDataLoaded()
const = 0;
348 friend class ::TestAttributeArray;
355 virtual char* dataAsByteArray() = 0;
356 virtual const char* dataAsByteArray()
const = 0;
359 template <
typename IterT>
360 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
361 bool rangeChecking =
true);
364 #if OPENVDB_ABI_VERSION_NUMBER >= 7
369 void setConstantStride(
bool state);
378 static void unregisterType(
const NamePair& type,
381 bool mIsUniform =
true;
384 uint8_t mUsePagedRead = 0;
402 template <
typename T>
410 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
422 namespace attribute_traits
454 template <
typename T>
457 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
458 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
459 static const char*
name() {
return "null"; }
465 template <
typename T>
468 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
469 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
470 static const char*
name() {
return "trnc"; }
477 static const char*
name() {
return "fxpt"; }
478 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
479 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
486 static const char*
name() {
return "ufxpt"; }
487 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
488 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
492 template <
bool OneByte,
typename Range=PositionRange>
495 template <
typename T>
498 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
499 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
502 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
512 template <
typename T>
517 static const char*
name() {
return "uvec"; }
526 template<
typename ValueType_,
typename Codec_ = NullCodec>
530 using Ptr = std::shared_ptr<TypedAttributeArray>;
531 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
535 using StorageType =
typename Codec::template Storage<ValueType>::Type;
541 const ValueType& uniformValue = zeroVal<ValueType>());
542 #if OPENVDB_ABI_VERSION_NUMBER >= 7
579 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride = true,
580 const
Metadata* metadata =
nullptr);
589 static const
NamePair& attributeType();
591 const
NamePair& type()
const override {
return attributeType(); }
594 static bool isRegistered();
596 static void registerType();
598 static void unregisterType();
605 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
609 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
626 bool valueTypeIsFloatingPoint()
const override;
629 bool valueTypeIsClass()
const override;
632 bool valueTypeIsVector()
const override;
635 bool valueTypeIsQuaternion()
const override;
638 bool valueTypeIsMatrix()
const override;
644 ValueType getUnsafe(
Index n)
const;
646 ValueType get(
Index n)
const;
648 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
650 template<
typename T>
void get(
Index n, T& value)
const;
657 void setUnsafe(
Index n,
const ValueType& value);
659 void set(
Index n,
const ValueType& value);
661 template<
typename T>
void setUnsafe(
Index n,
const T& value);
663 template<
typename T>
void set(
Index n,
const T& value);
674 bool isUniform()
const override {
return mIsUniform; }
678 void expand(
bool fill =
true)
override;
680 void collapse()
override;
682 bool compact()
override;
685 void collapse(
const ValueType& uniformValue);
688 void fill(
const ValueType& value);
691 static void collapse(
AttributeArray* array,
const ValueType& value);
697 bool compress() override;
700 bool decompress() override;
703 void read(
std::istream&) override;
707 void write(
std::ostream& os,
bool outputTransient) const override;
709 void write(
std::ostream&) const override;
712 void readMetadata(
std::istream&) override;
717 void writeMetadata(
std::ostream& os,
bool outputTransient,
bool paged) const override;
720 void readBuffers(
std::istream&) override;
724 void writeBuffers(
std::ostream& os,
bool outputTransient) const override;
727 void readPagedBuffers(compression::PagedInputStream&) override;
731 void writePagedBuffers(compression::PagedOutputStream& os,
bool outputTransient) const override;
734 inline
bool isOutOfCore() const;
737 void loadData() const override;
740 bool isDataLoaded() const override;
743 AccessorBasePtr getAccessor() const override;
746 inline
StorageType* data() { assert(validData());
return mData.get(); }
750 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
753 friend class ::TestAttributeArray;
755 #if OPENVDB_ABI_VERSION_NUMBER >= 7
760 inline void doLoad()
const;
763 inline void doLoadUnsafe(
const bool compression =
true)
const;
765 inline bool compressUnsafe();
768 inline void setOutOfCore(
const bool);
774 char* dataAsByteArray()
override;
775 const char* dataAsByteArray()
const override;
777 size_t arrayMemUsage()
const;
784 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride, metadata);
787 static std::unique_ptr<const NamePair> sTypeName;
788 std::unique_ptr<StorageType[]> mData;
790 Index mStrideOrTotalSize;
799 template <
typename ValueType,
typename CodecType = UnknownCodec>
804 using Ptr = std::shared_ptr<Handle>;
813 static Ptr create(
const AttributeArray& array,
const bool collapseOnDestruction =
true);
825 bool isUniform()
const;
826 bool hasConstantStride()
const;
843 friend class ::TestAttributeArray;
845 template <
bool IsUnknownCodec>
846 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
848 template <
bool IsUnknownCodec>
849 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
851 template <
bool IsUnknownCodec>
852 typename std::enable_if<IsUnknownCodec, ValueType>::type get(
Index index)
const;
854 template <
bool IsUnknownCodec>
855 typename std::enable_if<!IsUnknownCodec, ValueType>::type get(
Index index)
const;
860 Index mStrideOrTotalSize;
862 bool mCollapseOnDestruction;
870 template <
typename ValueType,
typename CodecType = UnknownCodec>
875 using Ptr = std::shared_ptr<Handle>;
886 void expand(
bool fill =
true);
890 void collapse(
const ValueType& uniformValue);
897 void fill(
const ValueType& value);
899 void set(
Index n,
const ValueType& value);
900 void set(
Index n,
Index m,
const ValueType& value);
905 friend class ::TestAttributeArray;
907 template <
bool IsUnknownCodec>
908 typename std::enable_if<IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
910 template <
bool IsUnknownCodec>
911 typename std::enable_if<!IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
921 template<
typename ValueType>
923 NullCodec::decode(
const ValueType& data, ValueType& val)
929 template<
typename ValueType>
931 NullCodec::encode(
const ValueType& val, ValueType& data)
937 template<
typename StorageType,
typename ValueType>
939 TruncateCodec::decode(
const StorageType& data, ValueType& val)
941 val =
static_cast<ValueType
>(data);
945 template<
typename StorageType,
typename ValueType>
947 TruncateCodec::encode(
const ValueType& val, StorageType& data)
949 data =
static_cast<StorageType
>(val);
953 template <
bool OneByte,
typename Range>
954 template<
typename StorageType,
typename ValueType>
958 val = fixedPointToFloatingPoint<ValueType>(data);
962 val = Range::template decode<ValueType>(val);
966 template <
bool OneByte,
typename Range>
967 template<
typename StorageType,
typename ValueType>
973 const ValueType newVal = Range::template encode<ValueType>(val);
975 data = floatingPointToFixedPoint<StorageType>(newVal);
983 val = math::QuantizedUnitVec::unpack(data);
991 data = math::QuantizedUnitVec::pack(val);
999 template <
typename IterT>
1000 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1006 assert(sourceArray.
isDataLoaded() && this->isDataLoaded());
1008 assert(this->storageTypeSize()*this->stride() ==
1012 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
1013 char*
const targetBuffer = this->dataAsByteArray();
1014 assert(sourceBuffer && targetBuffer);
1016 if (rangeChecking && this->isUniform()) {
1020 const bool sourceIsUniform = sourceArray.
isUniform();
1022 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
1023 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1025 for (IterT it(iter); it; ++it) {
1026 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1027 const Index targetIndex = it.targetIndex();
1029 if (rangeChecking) {
1030 if (sourceIndex >= sourceDataSize) {
1032 "Cannot copy array data as source index exceeds size of source array.");
1034 if (targetIndex >= targetDataSize) {
1036 "Cannot copy array data as target index exceeds size of target array.");
1040 assert(sourceIndex < sourceArray.
dataSize());
1041 assert(targetIndex < this->dataSize());
1042 if (this->isUniform()) assert(targetIndex ==
Index(0));
1045 const size_t targetOffset(targetIndex * bytes);
1046 const size_t sourceOffset(sourceIndex * bytes);
1048 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1052 template <
typename IterT>
1053 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1055 this->doCopyValues(sourceArray, iter,
false);
1058 template <
typename IterT>
1059 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1063 if (bytes != this->storageTypeSize()) {
1080 this->doCopyValues(sourceArray, iter,
true);
1093 template<
typename ValueType_,
typename Codec_>
1097 template<
typename ValueType_,
typename Codec_>
1103 , mStrideOrTotalSize(strideOrTotalSize)
1105 if (constantStride) {
1107 if (strideOrTotalSize == 0) {
1109 "stride to be at least one.")
1114 if (mStrideOrTotalSize < n) {
1116 "a total size of at least the number of elements in the array.")
1120 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1121 Codec::encode(uniformValue, this->
data()[0]);
1125 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1126 template<
typename ValueType_,
typename Codec_>
1133 template<
typename ValueType_,
typename Codec_>
1135 const tbb::spin_mutex::scoped_lock& lock)
1138 template<typename ValueType_, typename Codec_>
1143 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1147 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1152 template<
typename ValueType_,
typename Codec_>
1153 TypedAttributeArray<ValueType_, Codec_>&
1158 tbb::spin_mutex::scoped_lock lock(mMutex);
1159 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1166 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1169 if (this->validData()) {
1171 std::memcpy(
static_cast<void*
>(this->data()), rhs.
data(), this->arrayMemUsage());
1179 template<
typename ValueType_,
typename Codec_>
1183 static std::once_flag once;
1184 std::call_once(once, []()
1186 sTypeName.reset(
new NamePair(typeNameAsString<ValueType>(), Codec::name()));
1192 template<
typename ValueType_,
typename Codec_>
1200 template<
typename ValueType_,
typename Codec_>
1208 template<
typename ValueType_,
typename Codec_>
1216 template<
typename ValueType_,
typename Codec_>
1225 typedMetadata ? typedMetadata->
value() : zeroVal<ValueType>()));
1228 template<
typename ValueType_,
typename Codec_>
1238 template<
typename ValueType_,
typename Codec_>
1248 template<
typename ValueType_,
typename Codec_>
1252 #if OPENVDB_ABI_VERSION_NUMBER < 7
1253 tbb::spin_mutex::scoped_lock lock(mMutex);
1259 template<
typename ValueType_,
typename Codec_>
1263 return this->copy();
1267 template<
typename ValueType_,
typename Codec_>
1271 if (this->isOutOfCore())
return 0;
1273 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1277 template<
typename ValueType_,
typename Codec_>
1279 TypedAttributeArray<ValueType_, Codec_>::allocate()
1283 mData.reset(
new StorageType[1]);
1286 const size_t size(this->dataSize());
1288 mData.reset(
new StorageType[size]);
1293 template<
typename ValueType_,
typename Codec_>
1295 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1298 if (this->isOutOfCore()) {
1299 this->setOutOfCore(
false);
1300 this->mPageHandle.reset();
1302 if (mData) mData.reset();
1306 template<
typename ValueType_,
typename Codec_>
1312 if (std::is_same<ValueType, Quats>::value ||
1313 std::is_same<ValueType, Quatd>::value ||
1314 std::is_same<ValueType, Mat3s>::value ||
1315 std::is_same<ValueType, Mat3d>::value ||
1316 std::is_same<ValueType, Mat4s>::value ||
1317 std::is_same<ValueType, Mat4d>::value)
return true;
1322 return std::is_floating_point<ElementT>::value || std::is_same<math::half, ElementT>::value;
1326 template<
typename ValueType_,
typename Codec_>
1331 return std::is_class<ValueType>::value && !std::is_same<math::half, ValueType>::value;
1335 template<
typename ValueType_,
typename Codec_>
1343 template<
typename ValueType_,
typename Codec_>
1348 return !this->valueType().compare(0, 4,
"quat");
1352 template<
typename ValueType_,
typename Codec_>
1357 return !this->valueType().compare(0, 3,
"mat");
1361 template<
typename ValueType_,
typename Codec_>
1365 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1369 template<
typename ValueType_,
typename Codec_>
1373 assert(n < this->dataSize());
1376 Codec::decode(this->data()[mIsUniform ? 0 : n], val);
1381 template<
typename ValueType_,
typename Codec_>
1386 if (this->isOutOfCore()) this->doLoad();
1388 return this->getUnsafe(n);
1392 template<
typename ValueType_,
typename Codec_>
1393 template<
typename T>
1397 val =
static_cast<T
>(this->getUnsafe(n));
1401 template<
typename ValueType_,
typename Codec_>
1402 template<
typename T>
1406 val =
static_cast<T
>(this->get(n));
1410 template<
typename ValueType_,
typename Codec_>
1418 template<
typename ValueType_,
typename Codec_>
1422 assert(n < this->dataSize());
1423 assert(!this->isOutOfCore());
1424 assert(!this->isUniform());
1429 Codec::encode(val, this->data()[mIsUniform ? 0 : n]);
1433 template<
typename ValueType_,
typename Codec_>
1438 if (this->isOutOfCore()) this->doLoad();
1439 if (this->isUniform()) this->expand();
1441 this->setUnsafe(n, val);
1445 template<
typename ValueType_,
typename Codec_>
1446 template<
typename T>
1450 this->setUnsafe(n,
static_cast<ValueType>(val));
1454 template<
typename ValueType_,
typename Codec_>
1455 template<
typename T>
1459 this->set(n,
static_cast<ValueType>(val));
1463 template<
typename ValueType_,
typename Codec_>
1471 template<
typename ValueType_,
typename Codec_>
1478 sourceTypedArray.
get(sourceIndex, sourceValue);
1480 this->set(n, sourceValue);
1484 template<
typename ValueType_,
typename Codec_>
1488 if (!mIsUniform)
return;
1493 tbb::spin_mutex::scoped_lock lock(mMutex);
1500 for (
Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1505 template<
typename ValueType_,
typename Codec_>
1509 if (mIsUniform)
return true;
1512 const ValueType_ val = this->get(0);
1513 for (
Index i = 1; i < this->dataSize(); i++) {
1517 this->collapse(this->get(0));
1522 template<
typename ValueType_,
typename Codec_>
1526 this->collapse(zeroVal<ValueType>());
1530 template<
typename ValueType_,
typename Codec_>
1535 tbb::spin_mutex::scoped_lock lock(mMutex);
1540 Codec::encode(uniformValue, this->data()[0]);
1544 template<
typename ValueType_,
typename Codec_>
1552 template<
typename ValueType_,
typename Codec_>
1556 if (this->isOutOfCore()) {
1557 tbb::spin_mutex::scoped_lock lock(mMutex);
1562 const Index size = mIsUniform ? 1 : this->dataSize();
1563 for (
Index i = 0; i < size; ++i) {
1564 Codec::encode(value, this->data()[i]);
1569 template<
typename ValueType_,
typename Codec_>
1577 template<
typename ValueType_,
typename Codec_>
1585 template<
typename ValueType_,
typename Codec_>
1593 template<
typename ValueType_,
typename Codec_>
1601 template<
typename ValueType_,
typename Codec_>
1609 template<
typename ValueType_,
typename Codec_>
1617 template<
typename ValueType_,
typename Codec_>
1619 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1621 if (!(this->isOutOfCore()))
return;
1623 TypedAttributeArray<ValueType_, Codec_>*
self =
1624 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1628 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1629 this->doLoadUnsafe();
1633 template<
typename ValueType_,
typename Codec_>
1641 template<
typename ValueType_,
typename Codec_>
1645 return !this->isOutOfCore();
1649 template<
typename ValueType_,
typename Codec_>
1653 this->readMetadata(is);
1654 this->readBuffers(is);
1658 template<
typename ValueType_,
typename Codec_>
1665 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1666 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1668 uint8_t flags = uint8_t(0);
1669 is.read(
reinterpret_cast<char*
>(&flags),
sizeof(uint8_t));
1672 uint8_t serializationFlags = uint8_t(0);
1673 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1676 is.read(
reinterpret_cast<char*
>(&size),
sizeof(
Index));
1680 if (mFlags >= 0x20) {
1685 if (serializationFlags >= 0x10) {
1691 mIsUniform = serializationFlags & WRITEUNIFORM;
1692 mUsePagedRead = serializationFlags & WRITEPAGED;
1693 mCompressedBytes = bytes;
1694 mFlags |= PARTIALREAD;
1698 if (serializationFlags & WRITESTRIDED) {
1700 is.read(
reinterpret_cast<char*
>(&stride),
sizeof(
Index));
1701 mStrideOrTotalSize = stride;
1704 mStrideOrTotalSize = 1;
1709 template<
typename ValueType_,
typename Codec_>
1713 if (mUsePagedRead) {
1718 tbb::spin_mutex::scoped_lock lock(mMutex);
1722 uint8_t bloscCompressed(0);
1723 if (!mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1725 assert(mFlags & PARTIALREAD);
1726 std::unique_ptr<char[]> buffer(
new char[mCompressedBytes]);
1727 is.read(buffer.get(), mCompressedBytes);
1728 mCompressedBytes = 0;
1729 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1733 if (bloscCompressed == uint8_t(1)) {
1737 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1739 if (newBuffer) buffer.reset(newBuffer.release());
1744 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1748 template<
typename ValueType_,
typename Codec_>
1752 if (!mUsePagedRead) {
1760 const bool delayLoad = (mappedFile.get() !=
nullptr);
1764 size_t compressedBytes(mCompressedBytes);
1765 mCompressedBytes = 0;
1766 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1767 assert(!mPageHandle);
1772 assert(mPageHandle);
1774 tbb::spin_mutex::scoped_lock lock(mMutex);
1778 this->setOutOfCore(delayLoad);
1779 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1782 std::unique_ptr<char[]> buffer = mPageHandle->read();
1783 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1784 mPageHandle.reset();
1793 template<
typename ValueType_,
typename Codec_>
1797 this->write(os,
false);
1801 template<
typename ValueType_,
typename Codec_>
1805 this->writeMetadata(os, outputTransient,
false);
1806 this->writeBuffers(os, outputTransient);
1810 template<
typename ValueType_,
typename Codec_>
1814 if (!outputTransient && this->isTransient())
return;
1816 if (mFlags & PARTIALREAD) {
1820 uint8_t flags(mFlags);
1821 uint8_t serializationFlags(0);
1823 Index stride(mStrideOrTotalSize);
1824 bool strideOfOne(this->stride() == 1);
1829 if (bloscCompression) this->doLoad();
1831 size_t compressedBytes = 0;
1835 serializationFlags |= WRITESTRIDED;
1840 serializationFlags |= WRITEUNIFORM;
1841 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1843 else if (bloscCompression)
1845 if (paged) serializationFlags |= WRITEPAGED;
1847 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1848 const size_t inBytes = this->arrayMemUsage();
1855 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1859 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1860 os.write(
reinterpret_cast<const char*
>(&flags),
sizeof(uint8_t));
1861 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1862 os.write(
reinterpret_cast<const char*
>(&size),
sizeof(
Index));
1865 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&stride),
sizeof(
Index));
1869 template<
typename ValueType_,
typename Codec_>
1873 if (!outputTransient && this->isTransient())
return;
1875 if (mFlags & PARTIALREAD) {
1881 if (this->isUniform()) {
1882 os.write(
reinterpret_cast<const char*
>(this->data()),
sizeof(
StorageType));
1886 std::unique_ptr<char[]> compressedBuffer;
1887 size_t compressedBytes = 0;
1888 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1889 const size_t inBytes = this->arrayMemUsage();
1891 if (compressedBuffer) {
1892 uint8_t bloscCompressed(1);
1893 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1894 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
1897 uint8_t bloscCompressed(0);
1898 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1899 os.write(
reinterpret_cast<const char*
>(this->data()), inBytes);
1904 uint8_t bloscCompressed(0);
1905 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1906 os.write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1911 template<
typename ValueType_,
typename Codec_>
1915 if (!outputTransient && this->isTransient())
return;
1919 if (!bloscCompression) {
1924 if (mFlags & PARTIALREAD) {
1930 os.
write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1934 template<
typename ValueType_,
typename Codec_>
1938 if (!(this->isOutOfCore()))
return;
1944 assert(self->mPageHandle);
1945 assert(!(self->mFlags & PARTIALREAD));
1947 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
1949 self->mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1951 self->mPageHandle.reset();
1955 self->mOutOfCore =
false;
1959 template<
typename ValueType_,
typename Codec_>
1974 template<
typename ValueType_,
typename Codec_>
1979 if(!otherT)
return false;
1980 if(this->mSize != otherT->mSize ||
1981 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1983 this->attributeType() != this->attributeType())
return false;
1988 const StorageType *target = this->data(), *source = otherT->
data();
1989 if (!target && !source)
return true;
1990 if (!target || !source)
return false;
1991 Index n = this->mIsUniform ? 1 : mSize;
1997 template<
typename ValueType_,
typename Codec_>
1999 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2001 return reinterpret_cast<char*
>(this->data());
2005 template<
typename ValueType_,
typename Codec_>
2007 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
2009 return reinterpret_cast<const char*
>(this->data());
2017 template <
typename CodecType,
typename ValueType>
2038 template <
typename ValueType>
2046 return (*functor)(array, n);
2051 (*functor)(array, n, value);
2060 template <
typename ValueType,
typename CodecType>
2068 template <
typename ValueType,
typename CodecType>
2071 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2072 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2073 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2075 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2090 mGetter = typedAccessor->
mGetter;
2091 mSetter = typedAccessor->
mSetter;
2093 mFiller = typedAccessor->
mFiller;
2096 template <
typename ValueType,
typename CodecType>
2100 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
2103 template <
typename ValueType,
typename CodecType>
2104 template <
bool IsUnknownCodec>
2105 typename std::enable_if<IsUnknownCodec, bool>::type
2110 return mArray->hasValueType<ValueType>();
2113 template <
typename ValueType,
typename CodecType>
2114 template <
bool IsUnknownCodec>
2115 typename std::enable_if<!IsUnknownCodec, bool>::type
2116 AttributeHandle<ValueType, CodecType>::compatibleType()
const
2120 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2123 template <
typename ValueType,
typename CodecType>
2130 template <
typename ValueType,
typename CodecType>
2133 Index index = n * mStrideOrTotalSize + m;
2134 assert(index < (mSize * mStrideOrTotalSize));
2138 template <
typename ValueType,
typename CodecType>
2141 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2144 template <
typename ValueType,
typename CodecType>
2145 template <
bool IsUnknownCodec>
2146 typename std::enable_if<IsUnknownCodec, ValueType>::type
2151 return (*mGetter)(mArray, index);
2154 template <
typename ValueType,
typename CodecType>
2155 template <
bool IsUnknownCodec>
2156 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2157 AttributeHandle<ValueType, CodecType>::get(
Index index)
const
2161 return TypedAttributeArray<ValueType, CodecType>::getUnsafe(mArray, index);
2164 template <
typename ValueType,
typename CodecType>
2170 template <
typename ValueType,
typename CodecType>
2180 template <
typename ValueType,
typename CodecType>
2188 template <
typename ValueType,
typename CodecType>
2192 if (expand) array.
expand();
2195 template <
typename ValueType,
typename CodecType>
2198 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2201 template <
typename ValueType,
typename CodecType>
2204 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2207 template <
typename ValueType,
typename CodecType>
2213 template <
typename ValueType,
typename CodecType>
2219 template <
typename ValueType,
typename CodecType>
2225 template <
typename ValueType,
typename CodecType>
2228 this->mCollapser(
const_cast<AttributeArray*
>(this->mArray), uniformValue);
2231 template <
typename ValueType,
typename CodecType>
2237 template <
typename ValueType,
typename CodecType>
2238 template <
bool IsUnknownCodec>
2239 typename std::enable_if<IsUnknownCodec, void>::type
2244 (*this->mSetter)(
const_cast<AttributeArray*
>(this->mArray), index, value);
2247 template <
typename ValueType,
typename CodecType>
2248 template <
bool IsUnknownCodec>
2249 typename std::enable_if<!IsUnknownCodec, void>::type
2250 AttributeWriteHandle<ValueType, CodecType>::set(
Index index,
const ValueType& value)
const
2254 TypedAttributeArray<ValueType, CodecType>::setUnsafe(
const_cast<AttributeArray*
>(this->mArray), index, value);
2257 template <
typename ValueType,
typename CodecType>
2260 assert(this->mArray);
2269 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:477
ValuePtr mFiller
Definition: AttributeArray.h:415
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1660
static const char * name()
Definition: AttributeArray.h:470
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:292
ValuePtr mFiller
Definition: AttributeArray.h:840
uint8_t mFlags
Definition: AttributeArray.h:383
Write-able version of AttributeHandle.
Definition: AttributeArray.h:871
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.
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1554
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:406
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1210
Convenience wrappers to using Blosc and reading and writing of Paged data.
SetterPtr mSetter
Definition: AttributeArray.h:413
Definition: AttributeArray.h:800
T Type
Definition: AttributeArray.h:455
Definition: AttributeArray.h:475
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:488
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1181
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:241
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
virtual Index stride() const =0
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:178
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1337
SharedPtr< MappedFile > Ptr
Definition: io.h:136
uint8_t mUsePagedRead
Definition: AttributeArray.h:384
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:79
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:444
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:496
AttributeArray::Ptr copyUncompressed() const override
Definition: AttributeArray.h:1261
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2018
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition: AttributeArray.h:1420
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
Definition: AttributeArray.h:96
void(*)(AttributeArray *array, const Index n, const Index &value) SetterPtr
Definition: AttributeArray.h:809
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2069
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 compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1507
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1345
std::istream & getInputStream()
Definition: StreamCompression.h:218
int16_t Int16
Definition: openvdb/Types.h:51
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:479
uint16_t StorageType
Definition: AttributeArray.h:510
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:619
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1871
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1603
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
Codec_ Codec
Definition: AttributeArray.h:534
std::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:385
Definition: AttributeArray.h:118
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:601
virtual ~AttributeArray()
Definition: AttributeArray.h:133
typename T::ValueType ElementType
Definition: openvdb/Types.h:204
const AttributeArray * mArray
Definition: AttributeArray.h:835
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1250
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1194
static const char * name()
Definition: AttributeArray.h:501
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:804
static const char * name()
Definition: AttributeArray.h:477
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
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:805
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:1218
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...
Definition: openvdb/Exceptions.h:58
Definition: AttributeArray.h:513
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:398
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:487
tbb::spin_mutex mMutex
Definition: AttributeArray.h:382
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:214
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:746
bool sizeOnly() const
Definition: StreamCompression.h:215
Index(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:808
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1486
const StorageType * data() const
Definition: AttributeArray.h:747
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:218
static const char * name()
Definition: AttributeArray.h:459
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:69
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1651
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:535
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:345
Definition: AttributeArray.h:493
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2041
ValueType_ ValueType
Definition: AttributeArray.h:533
Index32 Index
Definition: openvdb/Types.h:50
Index storageTypeSize() const override
Definition: AttributeArray.h:623
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:478
@ COMPRESS_BLOSC
Definition: Compression.h:56
virtual Index storageTypeSize() const =0
bool sizeOnly() const
Definition: StreamCompression.h:252
Base class for storing attribute data.
Definition: AttributeArray.h:92
Definition: AttributeArray.h:496
Typed class for storing attribute data.
Definition: AttributeArray.h:527
Definition: AttributeArray.h:508
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1750
bool mIsUniform
Definition: AttributeArray.h:381
Definition: AttributeArray.h:449
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1154
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
virtual Index dataSize() const =0
uint16_t Type
Definition: AttributeArray.h:434
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1711
Definition: openvdb/Exceptions.h:65
virtual void loadData() const =0
Ensures all data is in-core.
bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1579
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:616
Index stride() const override
Definition: AttributeArray.h:605
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2021
bool isUniform() const
Definition: AttributeArray.h:2165
Index size() const
Definition: AttributeArray.h:823
Definition: AttributeArray.h:424
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:89
Definition: AttributeArray.h:463
SerializationFlag
Definition: AttributeArray.h:109
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1913
Definition: openvdb/Types.h:200
static const char * name()
Definition: AttributeArray.h:517
Definition: AttributeArray.h:484
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2045
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition: AttributeArray.h:128
Flag
Definition: AttributeArray.h:101
StorageType Type
Definition: AttributeArray.h:513
bool hasConstantStride() const
Definition: AttributeArray.h:2171
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:405
Index stride() const
Definition: AttributeArray.h:822
uint64_t Index64
Definition: openvdb/Types.h:49
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:204
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1363
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
void(*)(AttributeArray *array, const Index &value) ValuePtr
Definition: AttributeArray.h:810
Definition: AttributeArray.h:466
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1328
Definition: AttributeArray.h:455
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1354
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:530
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:876
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:388
ValuePtr mCollapser
Definition: AttributeArray.h:414
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2050
short Type
Definition: AttributeArray.h:426
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:409
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:1098
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1435
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1383
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1803
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1643
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:466
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...
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:285
SetterPtr mSetter
Definition: AttributeArray.h:838
AttributeArray()
Definition: AttributeArray.h:132
Definition: openvdb/Exceptions.h:64
uint8_t Type
Definition: AttributeArray.h:433
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:170
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1812
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:1961
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2031
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1308
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
GetterPtr mGetter
Definition: AttributeArray.h:837
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:608
static const char * name()
Definition: AttributeArray.h:486
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition: AttributeArray.h:1371
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:306
T & y()
Definition: Vec3.h:90
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1202
std::string Name
Definition: Name.h:17
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:750
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:407
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:98
GetterPtr mGetter
Definition: AttributeArray.h:412
Definition: AttributeArray.h:432
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
Definition: openvdb/Exceptions.h:13
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2020
internal::half half
Definition: openvdb/Types.h:25
ValuePtr mCollapser
Definition: AttributeArray.h:839
size_t mCompressedBytes
Definition: AttributeArray.h:389
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2042
Definition: openvdb/Exceptions.h:57
T & z()
Definition: Vec3.h:91
bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1595
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1524
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2062
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:875
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:255
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:126
Name valueType() const override
Return the name of the value type of a single element in this array (e.g., "float" or "vec3d").
Definition: AttributeArray.h:613
~TypedAttributeArray() override
Definition: AttributeArray.h:567
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:303
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1230
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2025
Definition: AttributeArray.h:452
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:300
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1635