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(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(this->newDataAsByteArray(), rhs.newDataAsByteArray(), this->arrayMemUsage());
1231 template<
typename ValueType_,
typename Codec_>
1235 static std::once_flag once;
1236 std::call_once(once, []()
1238 sTypeName.reset(
new NamePair(typeNameAsString<ValueType>(), Codec::name()));
1244 template<
typename ValueType_,
typename Codec_>
1252 template<
typename ValueType_,
typename Codec_>
1260 template<
typename ValueType_,
typename Codec_>
1268 template<
typename ValueType_,
typename Codec_>
1277 typedMetadata ? typedMetadata->
value() : zeroVal<ValueType>()));
1280 template<
typename ValueType_,
typename Codec_>
1290 template<
typename ValueType_,
typename Codec_>
1300 template<
typename ValueType_,
typename Codec_>
1304 #if OPENVDB_ABI_VERSION_NUMBER < 7
1305 tbb::spin_mutex::scoped_lock lock(mMutex);
1311 template<
typename ValueType_,
typename Codec_>
1315 return this->copy();
1319 template<
typename ValueType_,
typename Codec_>
1323 if (this->isOutOfCore())
return 0;
1325 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1329 template<
typename ValueType_,
typename Codec_>
1331 TypedAttributeArray<ValueType_, Codec_>::allocate()
1335 mData.reset(
new StorageType[1]);
1338 const size_t size(this->dataSize());
1340 mData.reset(
new StorageType[size]);
1345 template<
typename ValueType_,
typename Codec_>
1347 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1350 if (this->isOutOfCore()) {
1351 this->setOutOfCore(
false);
1352 this->mPageHandle.reset();
1354 if (mData) mData.reset();
1358 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1359 template<
typename ValueType_,
typename Codec_>
1365 if (std::is_same<ValueType, Quats>::value ||
1366 std::is_same<ValueType, Quatd>::value ||
1367 std::is_same<ValueType, Mat3s>::value ||
1368 std::is_same<ValueType, Mat3d>::value ||
1369 std::is_same<ValueType, Mat4s>::value ||
1370 std::is_same<ValueType, Mat4d>::value)
return true;
1375 return std::is_floating_point<ElementT>::value || std::is_same<half, ElementT>::value;
1379 template<
typename ValueType_,
typename Codec_>
1384 return std::is_class<ValueType>::value && !std::is_same<half, ValueType>::value;
1388 template<
typename ValueType_,
typename Codec_>
1396 template<
typename ValueType_,
typename Codec_>
1401 return !this->valueType().compare(0, 4,
"quat");
1405 template<
typename ValueType_,
typename Codec_>
1410 return !this->valueType().compare(0, 3,
"mat");
1415 template<
typename ValueType_,
typename Codec_>
1419 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1423 template<
typename ValueType_,
typename Codec_>
1427 assert(n < this->dataSize());
1430 Codec::decode(this->data()[mIsUniform ? 0 : n], val);
1435 template<
typename ValueType_,
typename Codec_>
1440 if (this->isOutOfCore()) this->doLoad();
1442 return this->getUnsafe(n);
1446 template<
typename ValueType_,
typename Codec_>
1447 template<
typename T>
1451 val =
static_cast<T
>(this->getUnsafe(n));
1455 template<
typename ValueType_,
typename Codec_>
1456 template<
typename T>
1460 val =
static_cast<T
>(this->get(n));
1464 template<
typename ValueType_,
typename Codec_>
1472 template<
typename ValueType_,
typename Codec_>
1476 assert(n < this->dataSize());
1477 assert(!this->isOutOfCore());
1478 assert(!this->isUniform());
1483 Codec::encode(val, this->data()[mIsUniform ? 0 : n]);
1487 template<
typename ValueType_,
typename Codec_>
1492 if (this->isOutOfCore()) this->doLoad();
1493 if (this->isUniform()) this->expand();
1495 this->setUnsafe(n, val);
1499 template<
typename ValueType_,
typename Codec_>
1500 template<
typename T>
1504 this->setUnsafe(n,
static_cast<ValueType>(val));
1508 template<
typename ValueType_,
typename Codec_>
1509 template<
typename T>
1513 this->set(n,
static_cast<ValueType>(val));
1517 template<
typename ValueType_,
typename Codec_>
1525 template<
typename ValueType_,
typename Codec_>
1532 sourceTypedArray.
get(sourceIndex, sourceValue);
1534 this->set(n, sourceValue);
1538 template<
typename ValueType_,
typename Codec_>
1542 if (!mIsUniform)
return;
1547 tbb::spin_mutex::scoped_lock lock(mMutex);
1554 for (
Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1559 template<
typename ValueType_,
typename Codec_>
1563 if (mIsUniform)
return true;
1566 const ValueType_ val = this->get(0);
1567 for (
Index i = 1; i < this->dataSize(); i++) {
1571 this->collapse(this->get(0));
1576 template<
typename ValueType_,
typename Codec_>
1580 this->collapse(zeroVal<ValueType>());
1584 template<
typename ValueType_,
typename Codec_>
1589 tbb::spin_mutex::scoped_lock lock(mMutex);
1594 Codec::encode(uniformValue, this->data()[0]);
1598 template<
typename ValueType_,
typename Codec_>
1606 template<
typename ValueType_,
typename Codec_>
1610 if (this->isOutOfCore()) {
1611 tbb::spin_mutex::scoped_lock lock(mMutex);
1616 const Index size = mIsUniform ? 1 : this->dataSize();
1617 for (
Index i = 0; i < size; ++i) {
1618 Codec::encode(value, this->data()[i]);
1623 template<
typename ValueType_,
typename Codec_>
1631 template<
typename ValueType_,
typename Codec_>
1639 template<
typename ValueType_,
typename Codec_>
1647 template<
typename ValueType_,
typename Codec_>
1655 template<
typename ValueType_,
typename Codec_>
1663 template<
typename ValueType_,
typename Codec_>
1671 template<
typename ValueType_,
typename Codec_>
1673 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1675 if (!(this->isOutOfCore()))
return;
1677 TypedAttributeArray<ValueType_, Codec_>*
self =
1678 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1682 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1683 this->doLoadUnsafe();
1687 template<
typename ValueType_,
typename Codec_>
1695 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1696 template<
typename ValueType_,
typename Codec_>
1700 return !this->isOutOfCore();
1705 template<
typename ValueType_,
typename Codec_>
1709 this->readMetadata(is);
1710 this->readBuffers(is);
1714 template<
typename ValueType_,
typename Codec_>
1721 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1722 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1724 uint8_t flags = uint8_t(0);
1725 is.read(
reinterpret_cast<char*
>(&flags),
sizeof(uint8_t));
1728 uint8_t serializationFlags = uint8_t(0);
1729 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1732 is.read(
reinterpret_cast<char*
>(&size),
sizeof(
Index));
1736 if (mFlags >= 0x20) {
1741 if (serializationFlags >= 0x10) {
1747 mIsUniform = serializationFlags & WRITEUNIFORM;
1748 mUsePagedRead = serializationFlags & WRITEPAGED;
1749 mCompressedBytes = bytes;
1750 mFlags |= PARTIALREAD;
1754 if (serializationFlags & WRITESTRIDED) {
1756 is.read(
reinterpret_cast<char*
>(&stride),
sizeof(
Index));
1757 mStrideOrTotalSize = stride;
1760 mStrideOrTotalSize = 1;
1765 template<
typename ValueType_,
typename Codec_>
1769 if (mUsePagedRead) {
1774 tbb::spin_mutex::scoped_lock lock(mMutex);
1778 uint8_t bloscCompressed(0);
1779 if (!mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1781 assert(mFlags & PARTIALREAD);
1782 std::unique_ptr<char[]> buffer(
new char[mCompressedBytes]);
1783 is.read(buffer.get(), mCompressedBytes);
1784 mCompressedBytes = 0;
1785 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1789 if (bloscCompressed == uint8_t(1)) {
1793 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1795 if (newBuffer) buffer.reset(newBuffer.release());
1800 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1804 template<
typename ValueType_,
typename Codec_>
1808 if (!mUsePagedRead) {
1816 const bool delayLoad = (mappedFile.get() !=
nullptr);
1820 size_t compressedBytes(mCompressedBytes);
1821 mCompressedBytes = 0;
1822 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1823 assert(!mPageHandle);
1828 assert(mPageHandle);
1830 tbb::spin_mutex::scoped_lock lock(mMutex);
1834 this->setOutOfCore(delayLoad);
1835 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1838 std::unique_ptr<char[]> buffer = mPageHandle->read();
1839 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1848 template<
typename ValueType_,
typename Codec_>
1852 this->write(os,
false);
1856 template<
typename ValueType_,
typename Codec_>
1860 this->writeMetadata(os, outputTransient,
false);
1861 this->writeBuffers(os, outputTransient);
1865 template<
typename ValueType_,
typename Codec_>
1869 if (!outputTransient && this->isTransient())
return;
1871 if (mFlags & PARTIALREAD) {
1875 uint8_t flags(mFlags);
1876 uint8_t serializationFlags(0);
1878 Index stride(mStrideOrTotalSize);
1879 bool strideOfOne(this->stride() == 1);
1884 if (bloscCompression) this->doLoad();
1886 size_t compressedBytes = 0;
1890 serializationFlags |= WRITESTRIDED;
1895 serializationFlags |= WRITEUNIFORM;
1896 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1898 else if (bloscCompression)
1900 if (paged) serializationFlags |= WRITEPAGED;
1902 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1903 const size_t inBytes = this->arrayMemUsage();
1910 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1914 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1915 os.write(
reinterpret_cast<const char*
>(&flags),
sizeof(uint8_t));
1916 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1917 os.write(
reinterpret_cast<const char*
>(&size),
sizeof(
Index));
1920 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&stride),
sizeof(
Index));
1924 template<
typename ValueType_,
typename Codec_>
1928 if (!outputTransient && this->isTransient())
return;
1930 if (mFlags & PARTIALREAD) {
1936 if (this->isUniform()) {
1937 os.write(
reinterpret_cast<const char*
>(this->data()),
sizeof(
StorageType));
1941 std::unique_ptr<char[]> compressedBuffer;
1942 size_t compressedBytes = 0;
1943 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1944 const size_t inBytes = this->arrayMemUsage();
1946 if (compressedBuffer) {
1947 uint8_t bloscCompressed(1);
1948 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1949 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
1952 uint8_t bloscCompressed(0);
1953 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1954 os.write(
reinterpret_cast<const char*
>(this->data()), inBytes);
1959 uint8_t bloscCompressed(0);
1960 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1961 os.write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1966 template<
typename ValueType_,
typename Codec_>
1970 if (!outputTransient && this->isTransient())
return;
1974 if (!bloscCompression) {
1979 if (mFlags & PARTIALREAD) {
1985 os.
write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1989 template<
typename ValueType_,
typename Codec_>
1993 if (!(this->isOutOfCore()))
return;
1999 assert(self->mPageHandle);
2000 assert(!(self->mFlags & PARTIALREAD));
2002 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
2004 self->mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
2006 self->mPageHandle.reset();
2010 self->mOutOfCore =
false;
2014 template<
typename ValueType_,
typename Codec_>
2029 template<
typename ValueType_,
typename Codec_>
2034 if(!otherT)
return false;
2035 if(this->mSize != otherT->mSize ||
2036 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
2038 this->attributeType() != this->attributeType())
return false;
2043 const StorageType *target = this->data(), *source = otherT->
data();
2044 if (!target && !source)
return true;
2045 if (!target || !source)
return false;
2046 Index n = this->mIsUniform ? 1 : mSize;
2052 #if OPENVDB_ABI_VERSION_NUMBER >= 6
2053 template<
typename ValueType_,
typename Codec_>
2055 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2057 return reinterpret_cast<char*
>(this->data());
2061 template<
typename ValueType_,
typename Codec_>
2063 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
2065 return reinterpret_cast<const char*
>(this->data());
2074 template <
typename CodecType,
typename ValueType>
2095 template <
typename ValueType>
2103 return (*functor)(array, n);
2108 (*functor)(array, n, value);
2117 template <
typename ValueType,
typename CodecType>
2125 template <
typename ValueType,
typename CodecType>
2128 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2129 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2130 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2132 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2153 template <
typename ValueType,
typename CodecType>
2157 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
2160 template <
typename ValueType,
typename CodecType>
2161 template <
bool IsUnknownCodec>
2162 typename std::enable_if<IsUnknownCodec, bool>::type
2167 return mArray->hasValueType<ValueType>();
2170 template <
typename ValueType,
typename CodecType>
2171 template <
bool IsUnknownCodec>
2172 typename std::enable_if<!IsUnknownCodec, bool>::type
2173 AttributeHandle<ValueType, CodecType>::compatibleType()
const
2177 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2180 template <
typename ValueType,
typename CodecType>
2187 template <
typename ValueType,
typename CodecType>
2190 Index index = n * mStrideOrTotalSize + m;
2191 assert(index < (mSize * mStrideOrTotalSize));
2195 template <
typename ValueType,
typename CodecType>
2198 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2201 template <
typename ValueType,
typename CodecType>
2202 template <
bool IsUnknownCodec>
2203 typename std::enable_if<IsUnknownCodec, ValueType>::type
2208 return (*mGetter)(mArray, index);
2211 template <
typename ValueType,
typename CodecType>
2212 template <
bool IsUnknownCodec>
2213 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2221 template <
typename ValueType,
typename CodecType>
2224 return mArray->isUniform();
2227 template <
typename ValueType,
typename CodecType>
2230 return mArray->hasConstantStride();
2237 template <
typename ValueType,
typename CodecType>
2245 template <
typename ValueType,
typename CodecType>
2252 template <
typename ValueType,
typename CodecType>
2255 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2258 template <
typename ValueType,
typename CodecType>
2261 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2264 template <
typename ValueType,
typename CodecType>
2270 template <
typename ValueType,
typename CodecType>
2276 template <
typename ValueType,
typename CodecType>
2282 template <
typename ValueType,
typename CodecType>
2285 this->mCollapser(
const_cast<AttributeArray*
>(this->mArray), uniformValue);
2288 template <
typename ValueType,
typename CodecType>
2294 template <
typename ValueType,
typename CodecType>
2295 template <
bool IsUnknownCodec>
2296 typename std::enable_if<IsUnknownCodec, void>::type
2301 (*this->mSetter)(
const_cast<AttributeArray*
>(this->mArray), index, value);
2304 template <
typename ValueType,
typename CodecType>
2305 template <
bool IsUnknownCodec>
2306 typename std::enable_if<!IsUnknownCodec, void>::type
2314 template <
typename ValueType,
typename CodecType>
2317 assert(this->mArray);
2326 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
bool sizeOnly() const
Definition: StreamCompression.h:256
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:629
virtual ~AttributeArray()
Definition: AttributeArray.h:133
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:923
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:2016
static OPENVDB_DEPRECATED Ptr create(const NamePair &type, Index length, Index stride, bool constantStride, const ScopedRegistryLock *lock)
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:83
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1398
AttributeArray & operator=(const AttributeArray &rhs)
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:500
Convenience wrappers to using Blosc and reading and writing of Paged data.
virtual Index stride() const =0
Definition: AttributeArray.h:489
const AttributeArray * mArray
Definition: AttributeArray.h:883
ValueType get(Index n, Index m=0) const
Definition: AttributeArray.h:2196
Index(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:856
Definition: AttributeArray.h:849
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:639
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1608
AttributeArray(AttributeArray &&)=delete
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition: AttributeArray.h:1474
Index index(Index n, Index m) const
Definition: AttributeArray.h:2188
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2246
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:1270
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:852
virtual void write(std::ostream &) const =0
Write attribute metadata and buffers to a stream, don't write transient attributes.
virtual void readMetadata(std::istream &)=0
Read attribute metadata from a stream.
Definition: AttributeArray.h:543
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:303
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2107
AttributeArray()
Definition: AttributeArray.h:132
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:658
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:79
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:521
SharedPtr< MappedFile > Ptr
Definition: io.h:136
bool operator==(const AttributeArray &other) const
bool sizeOnly() const
Definition: StreamCompression.h:219
Definition: AttributeArray.h:510
bool isUniform() const
Definition: AttributeArray.h:2222
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:126
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
uint8_t Type
Definition: AttributeArray.h:467
Index32 Index
Definition: Types.h:31
void setHidden(bool state)
Specify whether this attribute should be hidden (e.g., from UI or iterators).
Index OPENVDB_DEPRECATED
Definition: AttributeArrayString.h:33
Index size() const
Definition: AttributeArray.h:871
std::string Name
Definition: Name.h:17
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2098
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
ValueType_ ValueType
Definition: AttributeArray.h:571
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:512
virtual Index dataSize() const =0
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:716
void collapse(const ValueType &uniformValue)
Definition: AttributeArray.h:2283
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1390
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:69
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1208
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1254
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:365
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1262
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
OPENVDB_DEPRECATED AttributeArray::Ptr copyUncompressed() const override
Definition: AttributeArray.h:1313
virtual void writeBuffers(std::ostream &, bool outputTransient) const =0
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1767
Write-able version of AttributeHandle.
Definition: AttributeArray.h:920
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2126
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:522
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:440
Index stride() const
Definition: AttributeArray.h:870
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:513
typename T::ValueType ElementType
Definition: Types.h:185
Definition: AttributeArray.h:547
void set(Index n, const ValueType &value)
Definition: AttributeArray.h:2253
const AttributeArray & array() const
Definition: AttributeArray.h:2181
uint64_t Index64
Definition: Types.h:30
virtual void readBuffers(std::istream &)=0
Read attribute buffers from a stream.
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition: AttributeArray.h:128
Flag
Definition: AttributeArray.h:101
Definition: Exceptions.h:58
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:2289
static void clearRegistry(const ScopedRegistryLock *lock=nullptr)
Clear the attribute type registry.
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:573
static const char * name()
Definition: AttributeArray.h:511
T & y()
Definition: Vec3.h:84
~TypedAttributeArray() override
Definition: AttributeArray.h:605
half Type
Definition: AttributeArray.h:459
uint16_t StorageType
Definition: AttributeArray.h:544
uint8_t mFlags
Definition: AttributeArray.h:415
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition: AttributeArray.h:1425
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:171
void setTransient(bool state)
Specify whether this attribute should only exist in memory and not be serialized during stream output...
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1689
bool mIsUniform
Definition: AttributeArray.h:413
static const char * name()
Definition: AttributeArray.h:504
ValuePtr mFiller
Definition: AttributeArray.h:888
tbb::spin_mutex mMutex
Definition: AttributeArray.h:414
virtual AttributeArray::Ptr copy() const =0
Return a copy of this attribute.
Codec_ Codec
Definition: AttributeArray.h:572
Definition: AttributeArray.h:530
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:420
Definition: AttributeArray.h:528
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
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1417
virtual void read(std::istream &)=0
Read attribute metadata and buffers from a stream.
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1707
OPENVDB_DEPRECATED TypedAttributeArray(const TypedAttributeArray &, bool)
AttributeArray & operator=(AttributeArray &&)=delete
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2119
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:408
virtual bool valueTypeIsVector() const =0
Return true if the value type is a vector.
virtual OPENVDB_DEPRECATED bool compress()=0
static const char * name()
Definition: AttributeArray.h:551
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...
virtual ~AccessorBase()=default
T & z()
Definition: Vec3.h:85
virtual Name codecType() const =0
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
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.
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1657
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:259
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1437
virtual OPENVDB_DEPRECATED AttributeArray::Ptr copyUncompressed() const =0
T Type
Definition: AttributeArray.h:489
int16_t Int16
Definition: Types.h:32
Typed class for storing attribute data.
Definition: AttributeArray.h:566
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1302
AttributeArray(const AttributeArray &rhs)
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1578
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1867
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2076
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1282
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2078
OPENVDB_DEPRECATED bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1633
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1407
Index storageTypeSize() const override
Definition: AttributeArray.h:662
AttributeHandle(const AttributeHandle &)=default
ValuePtr mCollapser
Definition: AttributeArray.h:448
Definition: AttributeArray.h:458
static const char * name()
Definition: AttributeArray.h:493
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:229
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:321
ValuePtr mCollapser
Definition: AttributeArray.h:887
virtual Index size() const =0
std::istream & getInputStream()
Definition: StreamCompression.h:222
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1540
GetterPtr mGetter
Definition: AttributeArray.h:885
Definition: AttributeArray.h:519
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2277
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:439
virtual void write(std::ostream &, bool outputTransient) const =0
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2265
const StorageType * data() const
Definition: AttributeArray.h:789
static Ptr create(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2239
virtual size_t memUsage() const =0
Return the number of bytes of memory used by this attribute.
StorageType Type
Definition: AttributeArray.h:547
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:924
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:324
virtual OPENVDB_DEPRECATED bool decompress()=0
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:225
AttributeArray & array()
Definition: AttributeArray.h:2315
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1561
tbb::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:417
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:646
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2102
Definition: AttributeArray.h:438
virtual void writeMetadata(std::ostream &, bool outputTransient, bool paged) const =0
@ COMPRESS_BLOSC
Definition: Compression.h:56
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1926
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:209
static const char * name()
Definition: AttributeArray.h:535
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:432
virtual void loadData() const =0
Ensures all data is in-core.
Base class for storing attribute data.
Definition: AttributeArray.h:93
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2088
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2271
short Type
Definition: AttributeArray.h:460
virtual Index storageTypeSize() const =0
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1246
static Ptr create(const NamePair &type, Index length, Index stride=1, bool constantStride=true, const Metadata *metadata=nullptr, const ScopedRegistryLock *lock=nullptr)
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1381
virtual bool valueTypeIsQuaternion() const =0
Return true if the value type is a quaternion.
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1361
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:568
virtual ~AttributeWriteHandle()=default
Index stride() const override
Definition: AttributeArray.h:643
virtual void collapse()=0
Replace the existing array with a uniform zero value.
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:500
Definition: Exceptions.h:57
virtual Index valueTypeSize() const =0
void set(Index n, Index m, const ValueType &value)
Definition: AttributeArray.h:2259
Definition: AttributeArray.h:498
SetterPtr mSetter
Definition: AttributeArray.h:447
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:792
virtual const NamePair & type() const =0
Return the name of this attribute's type.
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:310
virtual ~AttributeHandle()
Definition: AttributeArray.h:2154
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
Definition: AttributeArray.h:483
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:119
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:853
AttributeArray(const AttributeArray &rhs, const tbb::spin_mutex::scoped_lock &)
GetterPtr mGetter
Definition: AttributeArray.h:446
size_t mCompressedBytes
Definition: AttributeArray.h:421
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
void(*)(AttributeArray *array, const Index n, const Index &value) SetterPtr
Definition: AttributeArray.h:857
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1233
bool hasConstantStride() const
Definition: AttributeArray.h:2228
Definition: AttributeArray.h:466
TypedAttributeArray & operator=(TypedAttributeArray &&)=delete
Move assignment operator disabled.
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
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.
ValuePtr mFiller
Definition: AttributeArray.h:449
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
Definition: Exceptions.h:65
SerializationFlag
Definition: AttributeArray.h:109
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1489
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2077
AttributeHandle & operator=(const AttributeHandle &)=default
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:530
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1698
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1806
Definition: Exceptions.h:13
TypedAttributeArray(TypedAttributeArray &&)=delete
Move constructor disabled.
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:441
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:655
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:98
void(*)(AttributeArray *array, const Index &value) ValuePtr
Definition: AttributeArray.h:858
SetterPtr mSetter
Definition: AttributeArray.h:886
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:788
uint16_t Type
Definition: AttributeArray.h:468
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2082
uint8_t mUsePagedRead
Definition: AttributeArray.h:416
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1716
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:246
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2099
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...
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1858
virtual bool valueTypeIsClass() const =0
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:487
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.
Definition: Exceptions.h:64
OPENVDB_DEPRECATED bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1649
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1968
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253