Go to the documentation of this file.
10 #ifndef OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
11 #define OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
23 #include <tbb/spin_mutex.h>
24 #include <tbb/atomic.h>
29 #include <type_traits>
32 class TestAttributeArray;
48 template <
typename IntegerT,
typename FloatT>
52 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
59 template <
typename FloatT,
typename IntegerT>
63 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
67 template <
typename IntegerVectorT,
typename FloatT>
71 return IntegerVectorT(
72 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
x()),
73 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
y()),
74 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
z()));
77 template <
typename FloatVectorT,
typename IntegerT>
82 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
x()),
83 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
y()),
84 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
z()));
96 template <
typename T>
struct Accessor;
104 CONSTANTSTRIDE = 0x8,
112 WRITEMEMCOMPRESS = 0x4,
120 tbb::spin_mutex::scoped_lock lock;
125 using Ptr = std::shared_ptr<AttributeArray>;
126 using ConstPtr = std::shared_ptr<const AttributeArray>;
137 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
139 #if OPENVDB_ABI_VERSION_NUMBER >= 6
171 #if OPENVDB_ABI_VERSION_NUMBER >= 6
172 virtual Name valueType()
const = 0;
209 bool constantStride =
true,
224 template<
typename AttributeArrayType>
225 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
228 template<
typename ValueType>
229 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
233 #if OPENVDB_ABI_VERSION_NUMBER >= 6
241 #if OPENVDB_ABI_VERSION_NUMBER >= 6
242 template<
typename IterT>
266 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
270 template<
typename IterT>
271 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
278 virtual void expand(
bool fill =
true) = 0;
303 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
324 uint8_t
flags()
const {
return mFlags; }
327 virtual void read(std::istream&) = 0;
330 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
332 virtual void write(std::ostream&)
const = 0;
339 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
345 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
356 #if OPENVDB_ABI_VERSION_NUMBER >= 6
357 virtual bool isDataLoaded()
const = 0;
368 friend class ::TestAttributeArray;
374 #if OPENVDB_ABI_VERSION_NUMBER >= 6
375 virtual char* dataAsByteArray() = 0;
377 virtual const char* dataAsByteArray()
const = 0;
380 template <
typename IterT>
381 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
382 bool rangeChecking =
true);
386 #if OPENVDB_ABI_VERSION_NUMBER >= 7
403 #if OPENVDB_ABI_VERSION_NUMBER < 6
405 size_t mCompressedBytes = 0;
407 uint8_t mUsePagedRead = 0;
408 tbb::atomic<Index32> mOutOfCore;
411 #else // #if OPENVDB_ABI_VERSION_NUMBER < 6
413 bool mIsUniform =
true;
416 uint8_t mUsePagedRead = 0;
436 template <
typename T>
444 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
456 namespace attribute_traits
488 template <
typename T>
491 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
492 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
493 static const char*
name() {
return "null"; }
499 template <
typename T>
502 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
503 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
504 static const char*
name() {
return "trnc"; }
511 static const char*
name() {
return "fxpt"; }
512 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
513 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
520 static const char*
name() {
return "ufxpt"; }
521 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
522 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
526 template <
bool OneByte,
typename Range=PositionRange>
529 template <
typename T>
532 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
533 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
536 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
546 template <
typename T>
551 static const char*
name() {
return "uvec"; }
560 template<
typename ValueType_,
typename Codec_ = NullCodec>
561 #if OPENVDB_ABI_VERSION_NUMBER >= 6 // for ABI=6, class is final to allow for de-virtualization
568 using Ptr = std::shared_ptr<TypedAttributeArray>;
569 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
573 using StorageType =
typename Codec::template Storage<ValueType>::Type;
579 const ValueType& uniformValue = zeroVal<ValueType>());
580 #if OPENVDB_ABI_VERSION_NUMBER >= 7
617 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true,
618 const Metadata* metadata =
nullptr);
627 static const NamePair& attributeType();
632 static bool isRegistered();
634 static void registerType();
636 static void unregisterType();
643 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
647 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
650 #if OPENVDB_ABI_VERSION_NUMBER >= 6
651 Name valueType()
const override {
return typeNameAsString<ValueType>(); }
665 bool valueTypeIsFloatingPoint()
const override;
668 bool valueTypeIsClass()
const override;
671 bool valueTypeIsVector()
const override;
674 bool valueTypeIsQuaternion()
const override;
677 bool valueTypeIsMatrix()
const override;
681 size_t memUsage()
const override;
684 ValueType getUnsafe(
Index n)
const;
686 ValueType get(
Index n)
const;
688 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
690 template<
typename T>
void get(
Index n, T& value)
const;
697 void setUnsafe(
Index n,
const ValueType& value);
699 void set(
Index n,
const ValueType& value);
701 template<
typename T>
void setUnsafe(
Index n,
const T& value);
703 template<
typename T>
void set(
Index n,
const T& value);
710 #if OPENVDB_ABI_VERSION_NUMBER >= 6
720 void expand(
bool fill =
true)
override;
722 void collapse()
override;
724 bool compact()
override;
727 void collapse(
const ValueType& uniformValue);
730 void fill(
const ValueType& value);
733 static void collapse(
AttributeArray* array,
const ValueType& value);
743 void read(std::istream&)
override;
747 void write(std::ostream& os,
bool outputTransient)
const override;
749 void write(std::ostream&)
const override;
752 void readMetadata(std::istream&)
override;
757 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
760 void readBuffers(std::istream&)
override;
764 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
774 inline bool isOutOfCore()
const;
777 void loadData()
const override;
779 #if OPENVDB_ABI_VERSION_NUMBER >= 6
780 bool isDataLoaded()
const override;
785 AccessorBasePtr getAccessor()
const override;
792 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
795 friend class ::TestAttributeArray;
797 #if OPENVDB_ABI_VERSION_NUMBER >= 7
802 inline void doLoad()
const;
805 inline void doLoadUnsafe(
const bool compression =
true)
const;
807 inline bool compressUnsafe();
810 inline void setOutOfCore(
const bool);
815 #if OPENVDB_ABI_VERSION_NUMBER >= 6
816 char* dataAsByteArray()
override;
818 const char* dataAsByteArray()
const override;
821 size_t arrayMemUsage()
const;
828 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride, metadata);
831 static std::unique_ptr<const NamePair> sTypeName;
832 std::unique_ptr<StorageType[]> mData;
834 Index mStrideOrTotalSize;
835 #if OPENVDB_ABI_VERSION_NUMBER < 6 // as of ABI=6, this data lives in the base class to reduce memory
836 bool mIsUniform =
true;
837 mutable tbb::spin_mutex mMutex;
847 template <
typename ValueType,
typename CodecType = UnknownCodec>
852 using Ptr = std::shared_ptr<Handle>;
891 friend class ::TestAttributeArray;
893 template <
bool IsUnknownCodec>
894 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
896 template <
bool IsUnknownCodec>
897 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
899 template <
bool IsUnknownCodec>
900 typename std::enable_if<IsUnknownCodec, ValueType>::type get(
Index index)
const;
902 template <
bool IsUnknownCodec>
903 typename std::enable_if<!IsUnknownCodec, ValueType>::type get(
Index index)
const;
908 Index mStrideOrTotalSize;
910 bool mCollapseOnDestruction;
918 template <
typename ValueType,
typename CodecType = UnknownCodec>
923 using Ptr = std::shared_ptr<Handle>;
945 void fill(
const ValueType& value);
953 friend class ::TestAttributeArray;
955 template <
bool IsUnknownCodec>
956 typename std::enable_if<IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
958 template <
bool IsUnknownCodec>
959 typename std::enable_if<!IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
969 template<
typename ValueType>
971 NullCodec::decode(
const ValueType& data, ValueType& val)
977 template<
typename ValueType>
979 NullCodec::encode(
const ValueType& val, ValueType& data)
985 template<
typename StorageType,
typename ValueType>
987 TruncateCodec::decode(
const StorageType& data, ValueType& val)
989 val =
static_cast<ValueType
>(data);
993 template<
typename StorageType,
typename ValueType>
995 TruncateCodec::encode(
const ValueType& val, StorageType& data)
997 data =
static_cast<StorageType
>(val);
1001 template <
bool OneByte,
typename Range>
1002 template<
typename StorageType,
typename ValueType>
1006 val = fixedPointToFloatingPoint<ValueType>(data);
1010 val = Range::template decode<ValueType>(val);
1014 template <
bool OneByte,
typename Range>
1015 template<
typename StorageType,
typename ValueType>
1021 const ValueType newVal = Range::template encode<ValueType>(val);
1023 data = floatingPointToFixedPoint<StorageType>(newVal);
1027 template<
typename T>
1031 val = math::QuantizedUnitVec::unpack(data);
1035 template<
typename T>
1039 data = math::QuantizedUnitVec::pack(val);
1047 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1049 template <
typename IterT>
1050 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1056 assert(sourceArray.
isDataLoaded() && this->isDataLoaded());
1058 assert(this->storageTypeSize()*this->stride() ==
1062 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
1063 char*
const targetBuffer = this->dataAsByteArray();
1064 assert(sourceBuffer && targetBuffer);
1066 if (rangeChecking && this->isUniform()) {
1070 const bool sourceIsUniform = sourceArray.
isUniform();
1072 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
1073 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1075 for (IterT it(iter); it; ++it) {
1076 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1077 const Index targetIndex = it.targetIndex();
1079 if (rangeChecking) {
1080 if (sourceIndex >= sourceDataSize) {
1082 "Cannot copy array data as source index exceeds size of source array.");
1084 if (targetIndex >= targetDataSize) {
1086 "Cannot copy array data as target index exceeds size of target array.");
1090 assert(sourceIndex < sourceArray.
dataSize());
1091 assert(targetIndex < this->dataSize());
1092 if (this->isUniform()) assert(targetIndex ==
Index(0));
1095 const size_t targetOffset(targetIndex * bytes);
1096 const size_t sourceOffset(sourceIndex * bytes);
1098 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1102 template <
typename IterT>
1103 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1105 this->doCopyValues(sourceArray, iter,
false);
1108 template <
typename IterT>
1109 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1113 if (bytes != this->storageTypeSize()) {
1130 this->doCopyValues(sourceArray, iter,
true);
1144 template<
typename ValueType_,
typename Codec_>
1148 template<
typename ValueType_,
typename Codec_>
1154 , mStrideOrTotalSize(strideOrTotalSize)
1156 if (constantStride) {
1158 if (strideOrTotalSize == 0) {
1160 "stride to be at least one.")
1165 if (mStrideOrTotalSize < n) {
1167 "a total size of at least the number of elements in the array.")
1171 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1172 Codec::encode(uniformValue, this->
data()[0]);
1176 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1177 template<
typename ValueType_,
typename Codec_>
1184 template<
typename ValueType_,
typename Codec_>
1186 const tbb::spin_mutex::scoped_lock& lock)
1189 template<typename ValueType_, typename Codec_>
1194 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1195 #if OPENVDB_ABI_VERSION_NUMBER < 6
1196 , mIsUniform(rhs.mIsUniform)
1201 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1206 template<
typename ValueType_,
typename Codec_>
1207 TypedAttributeArray<ValueType_, Codec_>&
1212 tbb::spin_mutex::scoped_lock lock(mMutex);
1213 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1220 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1223 if (this->validData()) {
1225 std::memcpy(
static_cast<void*
>(this->data()), rhs.
data(), this->arrayMemUsage());
1233 template<
typename ValueType_,
typename Codec_>
1237 static std::once_flag once;
1238 std::call_once(once, []()
1240 sTypeName.reset(
new NamePair(typeNameAsString<ValueType>(), Codec::name()));
1246 template<
typename ValueType_,
typename Codec_>
1254 template<
typename ValueType_,
typename Codec_>
1262 template<
typename ValueType_,
typename Codec_>
1270 template<
typename ValueType_,
typename Codec_>
1279 typedMetadata ? typedMetadata->
value() : zeroVal<ValueType>()));
1282 template<
typename ValueType_,
typename Codec_>
1292 template<
typename ValueType_,
typename Codec_>
1302 template<
typename ValueType_,
typename Codec_>
1306 #if OPENVDB_ABI_VERSION_NUMBER < 7
1307 tbb::spin_mutex::scoped_lock lock(mMutex);
1313 template<
typename ValueType_,
typename Codec_>
1317 return this->copy();
1321 template<
typename ValueType_,
typename Codec_>
1325 if (this->isOutOfCore())
return 0;
1327 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1331 template<
typename ValueType_,
typename Codec_>
1333 TypedAttributeArray<ValueType_, Codec_>::allocate()
1337 mData.reset(
new StorageType[1]);
1340 const size_t size(this->dataSize());
1342 mData.reset(
new StorageType[size]);
1347 template<
typename ValueType_,
typename Codec_>
1349 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1352 if (this->isOutOfCore()) {
1353 this->setOutOfCore(
false);
1354 this->mPageHandle.reset();
1356 if (mData) mData.reset();
1360 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1361 template<
typename ValueType_,
typename Codec_>
1367 if (std::is_same<ValueType, Quats>::value ||
1368 std::is_same<ValueType, Quatd>::value ||
1369 std::is_same<ValueType, Mat3s>::value ||
1370 std::is_same<ValueType, Mat3d>::value ||
1371 std::is_same<ValueType, Mat4s>::value ||
1372 std::is_same<ValueType, Mat4d>::value)
return true;
1377 return std::is_floating_point<ElementT>::value || std::is_same<half, ElementT>::value;
1381 template<
typename ValueType_,
typename Codec_>
1386 return std::is_class<ValueType>::value && !std::is_same<half, ValueType>::value;
1390 template<
typename ValueType_,
typename Codec_>
1398 template<
typename ValueType_,
typename Codec_>
1403 return !this->valueType().compare(0, 4,
"quat");
1407 template<
typename ValueType_,
typename Codec_>
1412 return !this->valueType().compare(0, 3,
"mat");
1417 template<
typename ValueType_,
typename Codec_>
1421 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1425 template<
typename ValueType_,
typename Codec_>
1429 assert(n < this->dataSize());
1432 Codec::decode(this->data()[mIsUniform ? 0 : n], val);
1437 template<
typename ValueType_,
typename Codec_>
1442 if (this->isOutOfCore()) this->doLoad();
1444 return this->getUnsafe(n);
1448 template<
typename ValueType_,
typename Codec_>
1449 template<
typename T>
1453 val =
static_cast<T
>(this->getUnsafe(n));
1457 template<
typename ValueType_,
typename Codec_>
1458 template<
typename T>
1462 val =
static_cast<T
>(this->get(n));
1466 template<
typename ValueType_,
typename Codec_>
1474 template<
typename ValueType_,
typename Codec_>
1478 assert(n < this->dataSize());
1479 assert(!this->isOutOfCore());
1480 assert(!this->isUniform());
1485 Codec::encode(val, this->data()[mIsUniform ? 0 : n]);
1489 template<
typename ValueType_,
typename Codec_>
1494 if (this->isOutOfCore()) this->doLoad();
1495 if (this->isUniform()) this->expand();
1497 this->setUnsafe(n, val);
1501 template<
typename ValueType_,
typename Codec_>
1502 template<
typename T>
1506 this->setUnsafe(n,
static_cast<ValueType>(val));
1510 template<
typename ValueType_,
typename Codec_>
1511 template<
typename T>
1515 this->set(n,
static_cast<ValueType>(val));
1519 template<
typename ValueType_,
typename Codec_>
1527 template<
typename ValueType_,
typename Codec_>
1534 sourceTypedArray.
get(sourceIndex, sourceValue);
1536 this->set(n, sourceValue);
1540 template<
typename ValueType_,
typename Codec_>
1544 if (!mIsUniform)
return;
1549 tbb::spin_mutex::scoped_lock lock(mMutex);
1556 for (
Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1561 template<
typename ValueType_,
typename Codec_>
1565 if (mIsUniform)
return true;
1568 const ValueType_ val = this->get(0);
1569 for (
Index i = 1; i < this->dataSize(); i++) {
1573 this->collapse(this->get(0));
1578 template<
typename ValueType_,
typename Codec_>
1582 this->collapse(zeroVal<ValueType>());
1586 template<
typename ValueType_,
typename Codec_>
1591 tbb::spin_mutex::scoped_lock lock(mMutex);
1596 Codec::encode(uniformValue, this->data()[0]);
1600 template<
typename ValueType_,
typename Codec_>
1608 template<
typename ValueType_,
typename Codec_>
1612 if (this->isOutOfCore()) {
1613 tbb::spin_mutex::scoped_lock lock(mMutex);
1618 const Index size = mIsUniform ? 1 : this->dataSize();
1619 for (
Index i = 0; i < size; ++i) {
1620 Codec::encode(value, this->data()[i]);
1625 template<
typename ValueType_,
typename Codec_>
1633 template<
typename ValueType_,
typename Codec_>
1641 template<
typename ValueType_,
typename Codec_>
1649 template<
typename ValueType_,
typename Codec_>
1657 template<
typename ValueType_,
typename Codec_>
1665 template<
typename ValueType_,
typename Codec_>
1673 template<
typename ValueType_,
typename Codec_>
1675 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1677 if (!(this->isOutOfCore()))
return;
1679 TypedAttributeArray<ValueType_, Codec_>*
self =
1680 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1684 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1685 this->doLoadUnsafe();
1689 template<
typename ValueType_,
typename Codec_>
1697 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1698 template<
typename ValueType_,
typename Codec_>
1702 return !this->isOutOfCore();
1707 template<
typename ValueType_,
typename Codec_>
1711 this->readMetadata(is);
1712 this->readBuffers(is);
1716 template<
typename ValueType_,
typename Codec_>
1723 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1724 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1726 uint8_t flags = uint8_t(0);
1727 is.read(
reinterpret_cast<char*
>(&flags),
sizeof(uint8_t));
1730 uint8_t serializationFlags = uint8_t(0);
1731 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1734 is.read(
reinterpret_cast<char*
>(&size),
sizeof(
Index));
1738 if (mFlags >= 0x20) {
1743 if (serializationFlags >= 0x10) {
1749 mIsUniform = serializationFlags & WRITEUNIFORM;
1750 mUsePagedRead = serializationFlags & WRITEPAGED;
1751 mCompressedBytes = bytes;
1752 mFlags |= PARTIALREAD;
1756 if (serializationFlags & WRITESTRIDED) {
1758 is.read(
reinterpret_cast<char*
>(&stride),
sizeof(
Index));
1759 mStrideOrTotalSize = stride;
1762 mStrideOrTotalSize = 1;
1767 template<
typename ValueType_,
typename Codec_>
1771 if (mUsePagedRead) {
1776 tbb::spin_mutex::scoped_lock lock(mMutex);
1780 uint8_t bloscCompressed(0);
1781 if (!mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1783 assert(mFlags & PARTIALREAD);
1784 std::unique_ptr<char[]> buffer(
new char[mCompressedBytes]);
1785 is.read(buffer.get(), mCompressedBytes);
1786 mCompressedBytes = 0;
1787 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1791 if (bloscCompressed == uint8_t(1)) {
1795 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1797 if (newBuffer) buffer.reset(newBuffer.release());
1802 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1806 template<
typename ValueType_,
typename Codec_>
1810 if (!mUsePagedRead) {
1818 const bool delayLoad = (mappedFile.get() !=
nullptr);
1822 size_t compressedBytes(mCompressedBytes);
1823 mCompressedBytes = 0;
1824 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1825 assert(!mPageHandle);
1830 assert(mPageHandle);
1832 tbb::spin_mutex::scoped_lock lock(mMutex);
1836 this->setOutOfCore(delayLoad);
1837 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1840 std::unique_ptr<char[]> buffer = mPageHandle->read();
1841 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1850 template<
typename ValueType_,
typename Codec_>
1854 this->write(os,
false);
1858 template<
typename ValueType_,
typename Codec_>
1862 this->writeMetadata(os, outputTransient,
false);
1863 this->writeBuffers(os, outputTransient);
1867 template<
typename ValueType_,
typename Codec_>
1871 if (!outputTransient && this->isTransient())
return;
1873 if (mFlags & PARTIALREAD) {
1877 uint8_t flags(mFlags);
1878 uint8_t serializationFlags(0);
1880 Index stride(mStrideOrTotalSize);
1881 bool strideOfOne(this->stride() == 1);
1886 if (bloscCompression) this->doLoad();
1888 size_t compressedBytes = 0;
1892 serializationFlags |= WRITESTRIDED;
1897 serializationFlags |= WRITEUNIFORM;
1898 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1900 else if (bloscCompression)
1902 if (paged) serializationFlags |= WRITEPAGED;
1904 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1905 const size_t inBytes = this->arrayMemUsage();
1912 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1916 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1917 os.write(
reinterpret_cast<const char*
>(&flags),
sizeof(uint8_t));
1918 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1919 os.write(
reinterpret_cast<const char*
>(&size),
sizeof(
Index));
1922 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&stride),
sizeof(
Index));
1926 template<
typename ValueType_,
typename Codec_>
1930 if (!outputTransient && this->isTransient())
return;
1932 if (mFlags & PARTIALREAD) {
1938 if (this->isUniform()) {
1939 os.write(
reinterpret_cast<const char*
>(this->data()),
sizeof(
StorageType));
1943 std::unique_ptr<char[]> compressedBuffer;
1944 size_t compressedBytes = 0;
1945 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1946 const size_t inBytes = this->arrayMemUsage();
1948 if (compressedBuffer) {
1949 uint8_t bloscCompressed(1);
1950 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1951 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
1954 uint8_t bloscCompressed(0);
1955 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1956 os.write(
reinterpret_cast<const char*
>(this->data()), inBytes);
1961 uint8_t bloscCompressed(0);
1962 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1963 os.write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1968 template<
typename ValueType_,
typename Codec_>
1972 if (!outputTransient && this->isTransient())
return;
1976 if (!bloscCompression) {
1981 if (mFlags & PARTIALREAD) {
1987 os.
write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1991 template<
typename ValueType_,
typename Codec_>
1995 if (!(this->isOutOfCore()))
return;
2001 assert(self->mPageHandle);
2002 assert(!(self->mFlags & PARTIALREAD));
2004 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
2006 self->mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
2008 self->mPageHandle.reset();
2012 self->mOutOfCore =
false;
2016 template<
typename ValueType_,
typename Codec_>
2031 template<
typename ValueType_,
typename Codec_>
2036 if(!otherT)
return false;
2037 if(this->mSize != otherT->mSize ||
2038 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
2040 this->attributeType() != this->attributeType())
return false;
2045 const StorageType *target = this->data(), *source = otherT->
data();
2046 if (!target && !source)
return true;
2047 if (!target || !source)
return false;
2048 Index n = this->mIsUniform ? 1 : mSize;
2054 #if OPENVDB_ABI_VERSION_NUMBER >= 6
2055 template<
typename ValueType_,
typename Codec_>
2057 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2059 return reinterpret_cast<char*
>(this->data());
2063 template<
typename ValueType_,
typename Codec_>
2065 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
2067 return reinterpret_cast<const char*
>(this->data());
2076 template <
typename CodecType,
typename ValueType>
2097 template <
typename ValueType>
2105 return (*functor)(array, n);
2110 (*functor)(array, n, value);
2119 template <
typename ValueType,
typename CodecType>
2127 template <
typename ValueType,
typename CodecType>
2130 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2131 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2132 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2134 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2155 template <
typename ValueType,
typename CodecType>
2159 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
2162 template <
typename ValueType,
typename CodecType>
2163 template <
bool IsUnknownCodec>
2164 typename std::enable_if<IsUnknownCodec, bool>::type
2169 return mArray->hasValueType<ValueType>();
2172 template <
typename ValueType,
typename CodecType>
2173 template <
bool IsUnknownCodec>
2174 typename std::enable_if<!IsUnknownCodec, bool>::type
2175 AttributeHandle<ValueType, CodecType>::compatibleType()
const
2179 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2182 template <
typename ValueType,
typename CodecType>
2189 template <
typename ValueType,
typename CodecType>
2192 Index index = n * mStrideOrTotalSize + m;
2193 assert(index < (mSize * mStrideOrTotalSize));
2197 template <
typename ValueType,
typename CodecType>
2200 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2203 template <
typename ValueType,
typename CodecType>
2204 template <
bool IsUnknownCodec>
2205 typename std::enable_if<IsUnknownCodec, ValueType>::type
2210 return (*mGetter)(mArray, index);
2213 template <
typename ValueType,
typename CodecType>
2214 template <
bool IsUnknownCodec>
2215 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2223 template <
typename ValueType,
typename CodecType>
2226 return mArray->isUniform();
2229 template <
typename ValueType,
typename CodecType>
2232 return mArray->hasConstantStride();
2239 template <
typename ValueType,
typename CodecType>
2247 template <
typename ValueType,
typename CodecType>
2254 template <
typename ValueType,
typename CodecType>
2257 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2260 template <
typename ValueType,
typename CodecType>
2263 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2266 template <
typename ValueType,
typename CodecType>
2272 template <
typename ValueType,
typename CodecType>
2278 template <
typename ValueType,
typename CodecType>
2284 template <
typename ValueType,
typename CodecType>
2287 this->mCollapser(
const_cast<AttributeArray*
>(this->mArray), uniformValue);
2290 template <
typename ValueType,
typename CodecType>
2296 template <
typename ValueType,
typename CodecType>
2297 template <
bool IsUnknownCodec>
2298 typename std::enable_if<IsUnknownCodec, void>::type
2303 (*this->mSetter)(
const_cast<AttributeArray*
>(this->mArray), index, value);
2306 template <
typename ValueType,
typename CodecType>
2307 template <
bool IsUnknownCodec>
2308 typename std::enable_if<!IsUnknownCodec, void>::type
2316 template <
typename ValueType,
typename CodecType>
2319 assert(this->mArray);
2328 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
Definition: openvdb/Exceptions.h:58
virtual ~AttributeArray()
Definition: AttributeArray.h:133
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1419
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1709
OPENVDB_DEPRECATED bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1635
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:923
static const char * name()
Definition: AttributeArray.h:511
static OPENVDB_DEPRECATED Ptr create(const NamePair &type, Index length, Index stride, bool constantStride, const ScopedRegistryLock *lock)
Index storageTypeSize() const override
Definition: AttributeArray.h:662
uint16_t Type
Definition: AttributeArray.h:468
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:83
const AttributeArray * mArray
Definition: AttributeArray.h:883
ValueType get(Index n, Index m=0) const
Definition: AttributeArray.h:2198
AttributeArray & operator=(const AttributeArray &rhs)
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:513
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
virtual Index stride() const =0
Convenience wrappers to using Blosc and reading and writing of Paged data.
Definition: AttributeArray.h:543
AttributeArray(AttributeArray &&)=delete
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:852
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1248
Definition: AttributeArray.h:438
Index(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:856
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2248
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1383
Definition: AttributeArray.h:519
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1363
OPENVDB_DEPRECATED TypedAttributeArray(const TypedAttributeArray &, bool)
Index index(Index n, Index m) const
Definition: AttributeArray.h:2190
virtual void write(std::ostream &) const =0
Write attribute metadata and buffers to a stream, don't write transient attributes.
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1563
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1409
virtual void readMetadata(std::istream &)=0
Read attribute metadata from a stream.
Index stride() const override
Definition: AttributeArray.h:643
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:303
bool isUniform() const
Definition: AttributeArray.h:2224
AttributeArray()
Definition: AttributeArray.h:132
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:209
Definition: AttributeArray.h:547
bool operator==(const AttributeArray &other) const
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1542
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:126
const StorageType * data() const
Definition: AttributeArray.h:789
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
StorageType Type
Definition: AttributeArray.h:547
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:246
void setHidden(bool state)
Specify whether this attribute should be hidden (e.g., from UI or iterators).
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1580
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:79
Index OPENVDB_DEPRECATED
Definition: AttributeArrayString.h:33
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1284
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1235
Index size() const
Definition: AttributeArray.h:871
virtual Index dataSize() const =0
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2090
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2101
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1928
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
void collapse(const ValueType &uniformValue)
Definition: AttributeArray.h:2285
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:792
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:365
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
static const char * name()
Definition: AttributeArray.h:535
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
virtual void writeBuffers(std::ostream &, bool outputTransient) const =0
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:500
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:568
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:440
Base class for storing attribute data.
Definition: AttributeArray.h:93
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:788
void set(Index n, const ValueType &value)
Definition: AttributeArray.h:2255
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:646
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2128
TypedAttributeArray & operator=(TypedAttributeArray &&)=delete
Move assignment operator disabled.
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2104
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1860
#define OPENVDB_THROW(exception, message)
Definition: openvdb/Exceptions.h:82
Index stride() const
Definition: AttributeArray.h:870
std::string Name
Definition: Name.h:17
virtual void readBuffers(std::istream &)=0
Read attribute buffers from a stream.
const AttributeArray & array() const
Definition: AttributeArray.h:2183
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition: AttributeArray.h:128
Flag
Definition: AttributeArray.h:101
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2084
TypedAttributeArray(TypedAttributeArray &&)=delete
Move constructor disabled.
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:2291
static void clearRegistry(const ScopedRegistryLock *lock=nullptr)
Clear the attribute type registry.
T & y()
Definition: Vec3.h:84
ValuePtr mFiller
Definition: AttributeArray.h:888
uint8_t mFlags
Definition: AttributeArray.h:415
void setTransient(bool state)
Specify whether this attribute should only exist in memory and not be serialized during stream output...
short Type
Definition: AttributeArray.h:460
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1718
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:1149
bool mIsUniform
Definition: AttributeArray.h:413
tbb::spin_mutex mMutex
Definition: AttributeArray.h:414
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1491
virtual AttributeArray::Ptr copy() const =0
Return a copy of this attribute.
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:420
void setStreaming(bool state)
Specify whether this attribute is to be streamed off disk, in which case, the attributes are collapse...
static const char * name()
Definition: AttributeArray.h:520
virtual void read(std::istream &)=0
Read attribute metadata and buffers from a stream.
uint64_t Index64
Definition: openvdb/Types.h:31
AttributeArray & operator=(AttributeArray &&)=delete
virtual bool valueTypeIsVector() const =0
Return true if the value type is a vector.
virtual OPENVDB_DEPRECATED bool compress()=0
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1400
bool sizeOnly() const
Definition: StreamCompression.h:256
virtual Name codecType() const =0
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2121
T & z()
Definition: Vec3.h:85
Definition: AttributeArray.h:466
static const char * name()
Definition: AttributeArray.h:504
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:318
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
Typed class for storing attribute data.
Definition: AttributeArray.h:566
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2078
virtual OPENVDB_DEPRECATED AttributeArray::Ptr copyUncompressed() const =0
Definition: AttributeArray.h:849
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:639
static const char * name()
Definition: AttributeArray.h:551
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1700
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1808
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...
OPENVDB_DEPRECATED bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1651
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1970
AttributeArray(const AttributeArray &rhs)
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:629
AttributeHandle(const AttributeHandle &)=default
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
typename T::ValueType ElementType
Definition: openvdb/Types.h:186
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
ValuePtr mCollapser
Definition: AttributeArray.h:887
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:655
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:658
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:171
ValuePtr mCollapser
Definition: AttributeArray.h:448
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:229
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:69
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:321
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
virtual Index size() const =0
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2267
Definition: AttributeArray.h:498
virtual void write(std::ostream &, bool outputTransient) const =0
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2279
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:439
virtual size_t memUsage() const =0
Return the number of bytes of memory used by this attribute.
static Ptr create(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2241
uint8_t Type
Definition: AttributeArray.h:467
Definition: openvdb/Exceptions.h:64
GetterPtr mGetter
Definition: AttributeArray.h:885
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
OPENVDB_DEPRECATED AttributeArray::Ptr copyUncompressed() const override
Definition: AttributeArray.h:1315
half Type
Definition: AttributeArray.h:459
Definition: AttributeArray.h:530
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:1272
virtual OPENVDB_DEPRECATED bool decompress()=0
AttributeArray & array()
Definition: AttributeArray.h:2317
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:924
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:324
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:225
ValueType_ ValueType
Definition: AttributeArray.h:571
tbb::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:417
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:2018
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:147
virtual void writeMetadata(std::ostream &, bool outputTransient, bool paged) const =0
static const char * name()
Definition: AttributeArray.h:493
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:920
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:432
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1392
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:522
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1208
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2273
Definition: AttributeArray.h:528
virtual void loadData() const =0
Ensures all data is in-core.
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1610
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition: AttributeArray.h:1476
virtual Index storageTypeSize() const =0
static Ptr create(const NamePair &type, Index length, Index stride=1, bool constantStride=true, const Metadata *metadata=nullptr, const ScopedRegistryLock *lock=nullptr)
@ COMPRESS_BLOSC
Definition: Compression.h:56
virtual bool valueTypeIsQuaternion() const =0
Return true if the value type is a quaternion.
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition: AttributeArray.h:1427
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:259
Definition: AttributeArray.h:483
T Type
Definition: AttributeArray.h:489
uint16_t StorageType
Definition: AttributeArray.h:544
virtual ~AttributeWriteHandle()=default
virtual void collapse()=0
Replace the existing array with a uniform zero value.
void set(Index n, Index m, const ValueType &value)
Definition: AttributeArray.h:2261
bool sizeOnly() const
Definition: StreamCompression.h:219
Definition: openvdb/Exceptions.h:57
virtual Index valueTypeSize() const =0
Codec_ Codec
Definition: AttributeArray.h:572
Definition: AttributeArray.h:487
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:530
Definition: AttributeArray.h:489
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1256
SetterPtr mSetter
Definition: AttributeArray.h:447
virtual const NamePair & type() const =0
Return the name of this attribute's type.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:95
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:310
std::istream & getInputStream()
Definition: StreamCompression.h:222
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2080
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1264
~TypedAttributeArray() override
Definition: AttributeArray.h:605
void(*)(AttributeArray *array, const Index n, const Index &value) SetterPtr
Definition: AttributeArray.h:857
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
bool hasConstantStride() const
Definition: AttributeArray.h:2230
GetterPtr mGetter
Definition: AttributeArray.h:446
Definition: AttributeArray.h:119
AttributeArray(const AttributeArray &rhs, const tbb::spin_mutex::scoped_lock &)
Definition: AttributeArray.h:510
size_t mCompressedBytes
Definition: AttributeArray.h:421
virtual ~AttributeHandle()
Definition: AttributeArray.h:2156
ValuePtr mFiller
Definition: AttributeArray.h:449
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:434
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1659
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:853
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:443
virtual bool valueTypeIsMatrix() const =0
Return true if the value type is a matrix.
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2109
SerializationFlag
Definition: AttributeArray.h:109
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:716
Definition: openvdb/Exceptions.h:65
Definition: openvdb/Exceptions.h:13
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1304
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1869
AttributeHandle & operator=(const AttributeHandle &)=default
Definition: AttributeArray.h:458
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:521
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:573
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
void(*)(AttributeArray *array, const Index &value) ValuePtr
Definition: AttributeArray.h:858
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:441
SharedPtr< MappedFile > Ptr
Definition: io.h:136
Definition: openvdb/Types.h:183
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1769
int16_t Int16
Definition: openvdb/Types.h:33
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...
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2079
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2100
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:98
Index32 Index
Definition: openvdb/Types.h:32
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:512
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1691
Definition: AttributeArray.h:500
uint8_t mUsePagedRead
Definition: AttributeArray.h:416
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1439
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
virtual bool valueTypeIsClass() const =0
Return true if the value type is a class (ie vector, matrix or quaternion return true)
SetterPtr mSetter
Definition: AttributeArray.h:886
virtual ~AccessorBase()=default
virtual OPENVDB_DEPRECATED void set(const Index n, const AttributeArray &sourceArray, const Index sourceIndex)=0
Set value at given index n from sourceIndex of another sourceArray.
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253