37 #ifndef OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED 50 #include <tbb/spin_mutex.h> 51 #include <tbb/atomic.h> 55 #include <type_traits> 58 class TestAttributeArray;
74 template <
typename IntegerT,
typename FloatT>
78 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
85 template <
typename FloatT,
typename IntegerT>
89 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
93 template <
typename IntegerVectorT,
typename FloatT>
97 return IntegerVectorT(
98 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
x()),
99 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
y()),
100 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
z()));
103 template <
typename FloatVectorT,
typename IntegerT>
108 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
x()),
109 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
y()),
110 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
z()));
131 CONSTANTSTRIDE = 0x8,
139 WRITEMEMCOMPRESS = 0x4,
144 using Ptr = std::shared_ptr<AttributeArray>;
145 using ConstPtr = std::shared_ptr<const AttributeArray>;
156 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
158 #if OPENVDB_ABI_VERSION_NUMBER >= 6 160 : mIsUniform(rhs.mIsUniform)
162 , mSerializationFlags(rhs.mSerializationFlags)
163 , mOutOfCore(rhs.mOutOfCore)
173 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
180 else mPageHandle.reset();
198 virtual Index size()
const = 0;
202 virtual Index stride()
const = 0;
206 virtual Index dataSize()
const = 0;
208 #if OPENVDB_ABI_VERSION_NUMBER >= 6 209 virtual Name valueType()
const = 0;
213 virtual Name codecType()
const = 0;
217 virtual Index valueTypeSize()
const = 0;
221 virtual Index storageTypeSize()
const = 0;
224 virtual bool valueTypeIsFloatingPoint()
const = 0;
227 virtual bool valueTypeIsClass()
const = 0;
230 virtual bool valueTypeIsVector()
const = 0;
233 virtual bool valueTypeIsQuaternion()
const = 0;
236 virtual bool valueTypeIsMatrix()
const = 0;
240 virtual size_t memUsage()
const = 0;
243 static Ptr create(
const NamePair& type,
Index length,
Index stride = 1,
bool constantStride =
true);
245 static bool isRegistered(
const NamePair& type);
247 static void clearRegistry();
250 virtual const NamePair& type()
const = 0;
252 template<
typename AttributeArrayType>
253 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
256 template<
typename ValueType>
257 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
261 #if OPENVDB_ABI_VERSION_NUMBER >= 6 266 #if OPENVDB_ABI_VERSION_NUMBER >= 6 267 template<
typename IterT>
289 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
291 template<
typename IterT>
292 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
296 virtual bool isUniform()
const = 0;
299 virtual void expand(
bool fill =
true) = 0;
301 virtual void collapse() = 0;
303 virtual bool compact() = 0;
317 void setHidden(
bool state);
319 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
324 void setTransient(
bool state);
332 void setStreaming(
bool state);
340 uint8_t
flags()
const {
return mFlags; }
343 virtual void read(std::istream&) = 0;
346 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
348 virtual void write(std::ostream&)
const = 0;
351 virtual void readMetadata(std::istream&) = 0;
355 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
358 virtual void readBuffers(std::istream&) = 0;
361 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
370 virtual void loadData()
const = 0;
372 #if OPENVDB_ABI_VERSION_NUMBER >= 6 373 virtual bool isDataLoaded()
const = 0;
384 friend class ::TestAttributeArray;
390 #if OPENVDB_ABI_VERSION_NUMBER >= 6 391 virtual char* dataAsByteArray() = 0;
393 virtual const char* dataAsByteArray()
const = 0;
396 template <
typename IterT>
397 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
398 bool rangeChecking =
true);
403 void setConstantStride(
bool state);
411 static void unregisterType(
const NamePair& type);
413 #if OPENVDB_ABI_VERSION_NUMBER < 6 415 size_t mCompressedBytes = 0;
417 uint8_t mSerializationFlags = 0;
418 #if OPENVDB_ABI_VERSION_NUMBER >= 5 419 tbb::atomic<Index32> mOutOfCore = 0;
423 #else // #if OPENVDB_ABI_VERSION_NUMBER < 6 425 bool mIsUniform =
true;
428 uint8_t mSerializationFlags = 0;
429 tbb::atomic<Index32> mOutOfCore = 0;
448 template <
typename T>
456 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
468 namespace attribute_traits
500 template <
typename T>
503 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
504 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
505 static const char*
name() {
return "null"; }
511 template <
typename T>
514 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
515 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
516 static const char*
name() {
return "trnc"; }
523 static const char*
name() {
return "fxpt"; }
524 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
525 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
532 static const char*
name() {
return "ufxpt"; }
533 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
534 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
538 template <
bool OneByte,
typename Range=PositionRange>
541 template <
typename T>
544 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
545 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
548 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
558 template <
typename T>
563 static const char*
name() {
return "uvec"; }
572 template<
typename ValueType_,
typename Codec_ = NullCodec>
573 #if OPENVDB_ABI_VERSION_NUMBER >= 6 // for ABI=6, class is final to allow for de-virtualization 580 using Ptr = std::shared_ptr<TypedAttributeArray>;
581 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
585 using StorageType =
typename Codec::template Storage<ValueType>::Type;
591 const ValueType& uniformValue = zeroVal<ValueType>());
610 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true);
619 static const NamePair& attributeType();
624 static bool isRegistered();
626 static void registerType();
628 static void unregisterType();
635 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
639 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
642 #if OPENVDB_ABI_VERSION_NUMBER >= 6 643 Name valueType()
const override {
return typeNameAsString<ValueType>(); }
657 bool valueTypeIsFloatingPoint()
const override;
660 bool valueTypeIsClass()
const override;
663 bool valueTypeIsVector()
const override;
666 bool valueTypeIsQuaternion()
const override;
669 bool valueTypeIsMatrix()
const override;
673 size_t memUsage()
const override;
676 ValueType getUnsafe(
Index n)
const;
678 ValueType get(
Index n)
const;
680 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
682 template<
typename T>
void get(
Index n, T& value)
const;
689 void setUnsafe(
Index n,
const ValueType& value);
691 void set(
Index n,
const ValueType& value);
693 template<
typename T>
void setUnsafe(
Index n,
const T& value);
695 template<
typename T>
void set(
Index n,
const T& value);
709 void expand(
bool fill =
true)
override;
711 void collapse()
override;
713 bool compact()
override;
716 void collapse(
const ValueType& uniformValue);
719 void fill(
const ValueType& value);
722 static void collapse(
AttributeArray* array,
const ValueType& value);
732 void read(std::istream&)
override;
736 void write(std::ostream& os,
bool outputTransient)
const override;
738 void write(std::ostream&)
const override;
741 void readMetadata(std::istream&)
override;
746 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
749 void readBuffers(std::istream&)
override;
753 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
763 inline bool isOutOfCore()
const;
766 void loadData()
const override;
768 #if OPENVDB_ABI_VERSION_NUMBER >= 6 769 bool isDataLoaded()
const override;
774 AccessorBasePtr getAccessor()
const override;
781 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
784 friend class ::TestAttributeArray;
787 inline void doLoad()
const;
790 inline void doLoadUnsafe(
const bool compression =
true)
const;
792 inline bool compressUnsafe();
795 inline void setOutOfCore(
const bool);
800 #if OPENVDB_ABI_VERSION_NUMBER >= 6 801 char* dataAsByteArray()
override;
803 const char* dataAsByteArray()
const override;
806 size_t arrayMemUsage()
const;
812 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride);
815 static tbb::atomic<const NamePair*> sTypeName;
816 std::unique_ptr<StorageType[]> mData;
818 Index mStrideOrTotalSize;
819 #if OPENVDB_ABI_VERSION_NUMBER < 6 // as of ABI=6, this data lives in the base class to reduce memory 820 bool mIsUniform =
true;
821 tbb::spin_mutex mMutex;
831 template <
typename ValueType,
typename CodecType = UnknownCodec>
836 using Ptr = std::shared_ptr<Handle>;
845 static Ptr create(
const AttributeArray& array,
const bool collapseOnDestruction =
true);
857 bool isUniform()
const;
858 bool hasConstantStride()
const;
875 friend class ::TestAttributeArray;
877 template <
bool IsUnknownCodec>
878 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
880 template <
bool IsUnknownCodec>
881 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
883 template <
bool IsUnknownCodec>
884 typename std::enable_if<IsUnknownCodec, ValueType>::type get(
Index index)
const;
886 template <
bool IsUnknownCodec>
887 typename std::enable_if<!IsUnknownCodec, ValueType>::type get(
Index index)
const;
892 Index mStrideOrTotalSize;
894 bool mCollapseOnDestruction;
902 template <
typename ValueType,
typename CodecType = UnknownCodec>
907 using Ptr = std::shared_ptr<Handle>;
918 void expand(
bool fill =
true);
922 void collapse(
const ValueType& uniformValue);
929 void fill(
const ValueType& value);
931 void set(
Index n,
const ValueType& value);
932 void set(
Index n,
Index m,
const ValueType& value);
937 friend class ::TestAttributeArray;
939 template <
bool IsUnknownCodec>
940 typename std::enable_if<IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
942 template <
bool IsUnknownCodec>
943 typename std::enable_if<!IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
953 template<
typename ValueType>
955 NullCodec::decode(
const ValueType& data, ValueType& val)
961 template<
typename ValueType>
963 NullCodec::encode(
const ValueType& val, ValueType& data)
969 template<
typename StorageType,
typename ValueType>
971 TruncateCodec::decode(
const StorageType& data, ValueType& val)
973 val = static_cast<ValueType>(data);
977 template<
typename StorageType,
typename ValueType>
979 TruncateCodec::encode(
const ValueType& val, StorageType& data)
981 data = static_cast<StorageType>(val);
985 template <
bool OneByte,
typename Range>
986 template<
typename StorageType,
typename ValueType>
990 val = fixedPointToFloatingPoint<ValueType>(data);
994 val = Range::template decode<ValueType>(val);
998 template <
bool OneByte,
typename Range>
999 template<
typename StorageType,
typename ValueType>
1005 const ValueType newVal = Range::template encode<ValueType>(val);
1007 data = floatingPointToFixedPoint<StorageType>(newVal);
1011 template<
typename T>
1015 val = math::QuantizedUnitVec::unpack(data);
1019 template<
typename T>
1023 data = math::QuantizedUnitVec::pack(val);
1031 #if OPENVDB_ABI_VERSION_NUMBER >= 6 1033 template <
typename IterT>
1034 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1040 assert(sourceArray.
isDataLoaded() && this->isDataLoaded());
1042 assert(this->storageTypeSize()*this->stride() ==
1046 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
1047 char*
const targetBuffer = this->dataAsByteArray();
1048 assert(sourceBuffer && targetBuffer);
1050 if (rangeChecking && this->isUniform()) {
1054 const bool sourceIsUniform = sourceArray.
isUniform();
1056 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
1057 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1059 for (IterT it(iter); it; ++it) {
1060 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1061 const Index targetIndex = it.targetIndex();
1063 if (rangeChecking) {
1064 if (sourceIndex >= sourceDataSize) {
1066 "Cannot copy array data as source index exceeds size of source array.");
1068 if (targetIndex >= targetDataSize) {
1070 "Cannot copy array data as target index exceeds size of target array.");
1074 assert(sourceIndex < sourceArray.
dataSize());
1075 assert(targetIndex < this->dataSize());
1076 if (this->isUniform()) assert(targetIndex ==
Index(0));
1079 const size_t targetOffset(targetIndex * bytes);
1080 const size_t sourceOffset(sourceIndex * bytes);
1082 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1086 template <
typename IterT>
1087 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1089 this->doCopyValues(sourceArray, iter,
false);
1092 template <
typename IterT>
1093 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1097 if (bytes != this->storageTypeSize()) {
1108 this->doCopyValues(sourceArray, iter,
true);
1122 template<
typename ValueType_,
typename Codec_>
1126 template<
typename ValueType_,
typename Codec_>
1132 , mStrideOrTotalSize(strideOrTotalSize)
1134 if (constantStride) {
1136 if (strideOrTotalSize == 0) {
1138 "stride to be at least one.")
1143 if (mStrideOrTotalSize < n) {
1145 "a total size of at least the number of elements in the array.")
1149 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1150 Codec::encode(uniformValue, this->
data()[0]);
1154 template<
typename ValueType_,
typename Codec_>
1158 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1159 #if OPENVDB_ABI_VERSION_NUMBER < 6
1160 , mIsUniform(rhs.mIsUniform)
1165 std::memcpy(this->
data(), rhs.
data(), this->arrayMemUsage());
1170 template<
typename ValueType_,
typename Codec_>
1175 tbb::spin_mutex::scoped_lock lock(mMutex);
1182 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1185 if (this->validData()) {
1187 std::memcpy(this->newDataAsByteArray(), rhs.newDataAsByteArray(), this->arrayMemUsage());
1193 template<
typename ValueType_,
typename Codec_>
1197 if (sTypeName ==
nullptr) {
1199 if (sTypeName.compare_and_swap(s,
nullptr) !=
nullptr)
delete s;
1205 template<
typename ValueType_,
typename Codec_>
1213 template<
typename ValueType_,
typename Codec_>
1221 template<
typename ValueType_,
typename Codec_>
1229 template<
typename ValueType_,
typename Codec_>
1236 template<
typename ValueType_,
typename Codec_>
1243 return static_cast<TypedAttributeArray&>(attributeArray);
1246 template<
typename ValueType_,
typename Codec_>
1253 return static_cast<const TypedAttributeArray&>(attributeArray);
1256 template<
typename ValueType_,
typename Codec_>
1264 template<
typename ValueType_,
typename Codec_>
1272 template<
typename ValueType_,
typename Codec_>
1276 if (this->isOutOfCore())
return 0;
1278 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1282 template<
typename ValueType_,
typename Codec_>
1284 TypedAttributeArray<ValueType_, Codec_>::allocate()
1288 mData.reset(
new StorageType[1]);
1291 const size_t size(this->dataSize());
1293 mData.reset(
new StorageType[size]);
1298 template<
typename ValueType_,
typename Codec_>
1300 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1303 if (this->isOutOfCore()) {
1304 this->setOutOfCore(
false);
1305 this->mPageHandle.reset();
1307 if (mData) mData.reset();
1311 #if OPENVDB_ABI_VERSION_NUMBER >= 6 1312 template<
typename ValueType_,
typename Codec_>
1318 if (std::is_same<ValueType, Quats>::value ||
1319 std::is_same<ValueType, Quatd>::value ||
1320 std::is_same<ValueType, Mat3s>::value ||
1321 std::is_same<ValueType, Mat3d>::value ||
1322 std::is_same<ValueType, Mat4s>::value ||
1323 std::is_same<ValueType, Mat4d>::value)
return true;
1328 return std::is_floating_point<ElementT>::value || std::is_same<half, ElementT>::value;
1332 template<
typename ValueType_,
typename Codec_>
1337 return std::is_class<ValueType>::value && !std::is_same<half, ValueType>::value;
1341 template<
typename ValueType_,
typename Codec_>
1349 template<
typename ValueType_,
typename Codec_>
1354 return !this->valueType().compare(0, 4,
"quat");
1358 template<
typename ValueType_,
typename Codec_>
1363 return !this->valueType().compare(0, 3,
"mat");
1368 template<
typename ValueType_,
typename Codec_>
1372 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1376 template<
typename ValueType_,
typename Codec_>
1380 assert(n < this->dataSize());
1383 Codec::decode(this->data()[mIsUniform ? 0 : n], val);
1388 template<
typename ValueType_,
typename Codec_>
1393 if (this->isOutOfCore()) this->doLoad();
1395 return this->getUnsafe(n);
1399 template<
typename ValueType_,
typename Codec_>
1400 template<
typename T>
1404 val = static_cast<T>(this->getUnsafe(n));
1408 template<
typename ValueType_,
typename Codec_>
1409 template<
typename T>
1413 val = static_cast<T>(this->get(n));
1417 template<
typename ValueType_,
typename Codec_>
1425 template<
typename ValueType_,
typename Codec_>
1429 assert(n < this->dataSize());
1430 assert(!this->isOutOfCore());
1431 assert(!this->isUniform());
1436 Codec::encode(val, this->data()[mIsUniform ? 0 : n]);
1440 template<
typename ValueType_,
typename Codec_>
1445 if (this->isOutOfCore()) this->doLoad();
1446 if (this->isUniform()) this->expand();
1448 this->setUnsafe(n, val);
1452 template<
typename ValueType_,
typename Codec_>
1453 template<
typename T>
1457 this->setUnsafe(n, static_cast<ValueType>(val));
1461 template<
typename ValueType_,
typename Codec_>
1462 template<
typename T>
1466 this->set(n, static_cast<ValueType>(val));
1470 template<
typename ValueType_,
typename Codec_>
1478 template<
typename ValueType_,
typename Codec_>
1482 const TypedAttributeArray& sourceTypedArray = static_cast<const TypedAttributeArray&>(sourceArray);
1485 sourceTypedArray.
get(sourceIndex, sourceValue);
1487 this->set(n, sourceValue);
1491 template<
typename ValueType_,
typename Codec_>
1495 if (!mIsUniform)
return;
1500 tbb::spin_mutex::scoped_lock lock(mMutex);
1507 for (
Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1512 template<
typename ValueType_,
typename Codec_>
1516 if (mIsUniform)
return true;
1519 const ValueType_ val = this->get(0);
1520 for (
Index i = 1; i < this->dataSize(); i++) {
1524 this->collapse(this->get(0));
1529 template<
typename ValueType_,
typename Codec_>
1533 this->collapse(zeroVal<ValueType>());
1537 template<
typename ValueType_,
typename Codec_>
1542 tbb::spin_mutex::scoped_lock lock(mMutex);
1547 Codec::encode(uniformValue, this->data()[0]);
1551 template<
typename ValueType_,
typename Codec_>
1559 template<
typename ValueType_,
typename Codec_>
1563 if (this->isOutOfCore()) {
1564 tbb::spin_mutex::scoped_lock lock(mMutex);
1569 const Index size = mIsUniform ? 1 : this->dataSize();
1570 for (
Index i = 0; i < size; ++i) {
1571 Codec::encode(value, this->data()[i]);
1576 template<
typename ValueType_,
typename Codec_>
1584 template<
typename ValueType_,
typename Codec_>
1592 template<
typename ValueType_,
typename Codec_>
1600 template<
typename ValueType_,
typename Codec_>
1608 template<
typename ValueType_,
typename Codec_>
1612 #if OPENVDB_ABI_VERSION_NUMBER >= 5 1615 return (mFlags & OUTOFCORE);
1620 template<
typename ValueType_,
typename Codec_>
1624 #if OPENVDB_ABI_VERSION_NUMBER >= 5 1627 if (b) mFlags = static_cast<uint8_t>(mFlags | OUTOFCORE);
1628 else mFlags = static_cast<uint8_t>(mFlags & ~OUTOFCORE);
1633 template<
typename ValueType_,
typename Codec_>
1635 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const 1637 if (!(this->isOutOfCore()))
return;
1639 TypedAttributeArray<ValueType_, Codec_>*
self =
1640 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1644 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1645 this->doLoadUnsafe();
1649 template<
typename ValueType_,
typename Codec_>
1657 #if OPENVDB_ABI_VERSION_NUMBER >= 6 1658 template<
typename ValueType_,
typename Codec_>
1662 return !this->isOutOfCore();
1667 template<
typename ValueType_,
typename Codec_>
1671 this->readMetadata(is);
1672 this->readBuffers(is);
1676 template<
typename ValueType_,
typename Codec_>
1683 is.read(reinterpret_cast<char*>(&bytes),
sizeof(
Index64));
1684 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1686 uint8_t flags = uint8_t(0);
1687 is.read(reinterpret_cast<char*>(&flags),
sizeof(uint8_t));
1690 uint8_t serializationFlags = uint8_t(0);
1691 is.read(reinterpret_cast<char*>(&serializationFlags),
sizeof(uint8_t));
1692 mSerializationFlags = serializationFlags;
1695 is.read(reinterpret_cast<char*>(&size),
sizeof(
Index));
1699 if (mFlags >= 0x20) {
1704 if (mSerializationFlags >= 0x10) {
1710 mIsUniform = mSerializationFlags & WRITEUNIFORM;
1711 mCompressedBytes = bytes;
1712 mFlags |= PARTIALREAD;
1716 if (mSerializationFlags & WRITESTRIDED) {
1718 is.read(reinterpret_cast<char*>(&stride),
sizeof(
Index));
1719 mStrideOrTotalSize = stride;
1722 mStrideOrTotalSize = 1;
1727 template<
typename ValueType_,
typename Codec_>
1731 if ((mSerializationFlags & WRITEPAGED)) {
1736 tbb::spin_mutex::scoped_lock lock(mMutex);
1740 uint8_t bloscCompressed(0);
1741 if (!mIsUniform) is.read(reinterpret_cast<char*>(&bloscCompressed),
sizeof(uint8_t));
1743 assert(mFlags & PARTIALREAD);
1744 std::unique_ptr<char[]> buffer(
new char[mCompressedBytes]);
1745 is.read(buffer.get(), mCompressedBytes);
1746 mCompressedBytes = 0;
1747 mFlags = static_cast<uint8_t>(mFlags & ~PARTIALREAD);
1751 if (bloscCompressed == uint8_t(1)) {
1755 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1757 if (newBuffer) buffer.reset(newBuffer.release());
1762 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1766 if (mIsUniform) mSerializationFlags &= uint8_t(~WRITEUNIFORM & ~WRITEMEMCOMPRESS & ~WRITEPAGED);
1767 else mSerializationFlags &= uint8_t(~WRITEUNIFORM & ~WRITEPAGED);
1771 template<
typename ValueType_,
typename Codec_>
1775 if (!(mSerializationFlags & WRITEPAGED)) {
1783 const bool delayLoad = (mappedFile.get() !=
nullptr);
1787 size_t compressedBytes(mCompressedBytes);
1788 mCompressedBytes = 0;
1789 mFlags = static_cast<uint8_t>(mFlags & ~PARTIALREAD);
1790 assert(!mPageHandle);
1795 assert(mPageHandle);
1797 tbb::spin_mutex::scoped_lock lock(mMutex);
1801 this->setOutOfCore(delayLoad);
1802 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1805 std::unique_ptr<char[]> buffer = mPageHandle->read();
1806 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1811 if (mIsUniform) mSerializationFlags &= uint8_t(~WRITEUNIFORM & ~WRITEMEMCOMPRESS & ~WRITEPAGED);
1812 else mSerializationFlags &= uint8_t(~WRITEUNIFORM & ~WRITEPAGED);
1816 template<
typename ValueType_,
typename Codec_>
1820 this->write(os,
false);
1824 template<
typename ValueType_,
typename Codec_>
1828 this->writeMetadata(os, outputTransient,
false);
1829 this->writeBuffers(os, outputTransient);
1833 template<
typename ValueType_,
typename Codec_>
1837 if (!outputTransient && this->isTransient())
return;
1839 if (mFlags & PARTIALREAD) {
1843 #if OPENVDB_ABI_VERSION_NUMBER >= 5 1844 uint8_t flags(mFlags);
1846 uint8_t flags(mFlags & uint8_t(~OUTOFCORE));
1848 uint8_t serializationFlags(0);
1850 Index stride(mStrideOrTotalSize);
1851 bool strideOfOne(this->stride() == 1);
1856 if (bloscCompression) this->doLoad();
1858 size_t compressedBytes = 0;
1862 serializationFlags |= WRITESTRIDED;
1867 serializationFlags |= WRITEUNIFORM;
1868 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1870 else if (bloscCompression)
1872 if (paged) serializationFlags |= WRITEPAGED;
1874 const char* charBuffer = reinterpret_cast<const char*>(this->data());
1875 const size_t inBytes = this->arrayMemUsage();
1882 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1886 os.write(reinterpret_cast<const char*>(&bytes),
sizeof(
Index64));
1887 os.write(reinterpret_cast<const char*>(&flags),
sizeof(uint8_t));
1888 os.write(reinterpret_cast<const char*>(&serializationFlags),
sizeof(uint8_t));
1889 os.write(reinterpret_cast<const char*>(&size),
sizeof(
Index));
1892 if (!strideOfOne) os.write(reinterpret_cast<const char*>(&stride),
sizeof(
Index));
1896 template<
typename ValueType_,
typename Codec_>
1900 if (!outputTransient && this->isTransient())
return;
1902 if (mFlags & PARTIALREAD) {
1908 if (this->isUniform()) {
1909 os.write(reinterpret_cast<const char*>(this->data()),
sizeof(
StorageType));
1913 std::unique_ptr<char[]> compressedBuffer;
1914 size_t compressedBytes = 0;
1915 const char* charBuffer = reinterpret_cast<const char*>(this->data());
1916 const size_t inBytes = this->arrayMemUsage();
1918 if (compressedBuffer) {
1919 uint8_t bloscCompressed(1);
1920 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1921 os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
1924 uint8_t bloscCompressed(0);
1925 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1926 os.write(reinterpret_cast<const char*>(this->data()), inBytes);
1931 uint8_t bloscCompressed(0);
1932 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1933 os.write(reinterpret_cast<const char*>(this->data()), this->arrayMemUsage());
1938 template<
typename ValueType_,
typename Codec_>
1942 if (!outputTransient && this->isTransient())
return;
1946 if (!bloscCompression) {
1951 if (mFlags & PARTIALREAD) {
1957 os.
write(reinterpret_cast<const char*>(this->data()), this->arrayMemUsage());
1961 template<
typename ValueType_,
typename Codec_>
1965 if (!(this->isOutOfCore()))
return;
1971 assert(self->mPageHandle);
1973 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
1975 self->mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1977 self->mPageHandle.reset();
1981 #if OPENVDB_ABI_VERSION_NUMBER >= 5 1982 self->mOutOfCore =
false;
1984 self->mFlags &= uint8_t(~OUTOFCORE);
1986 self->mSerializationFlags &= uint8_t(~WRITEUNIFORM & ~WRITEMEMCOMPRESS & ~WRITEPAGED);
1990 template<
typename ValueType_,
typename Codec_>
2005 template<
typename ValueType_,
typename Codec_>
2010 if(!otherT)
return false;
2011 if(this->mSize != otherT->mSize ||
2012 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
2014 *this->sTypeName != *otherT->sTypeName)
return false;
2019 const StorageType *target = this->data(), *source = otherT->
data();
2020 if (!target && !source)
return true;
2021 if (!target || !source)
return false;
2022 Index n = this->mIsUniform ? 1 : mSize;
2028 #if OPENVDB_ABI_VERSION_NUMBER >= 6 2029 template<
typename ValueType_,
typename Codec_>
2031 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2033 return reinterpret_cast<char*>(this->data());
2037 template<
typename ValueType_,
typename Codec_>
2039 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const 2041 return reinterpret_cast<const char*>(this->data());
2050 template <
typename CodecType,
typename ValueType>
2071 template <
typename ValueType>
2079 return (*functor)(array, n);
2084 (*functor)(array, n, value);
2093 template <
typename ValueType,
typename CodecType>
2101 template <
typename ValueType,
typename CodecType>
2104 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2105 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2106 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2108 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2123 mGetter = typedAccessor->
mGetter;
2124 mSetter = typedAccessor->
mSetter;
2126 mFiller = typedAccessor->
mFiller;
2129 template <
typename ValueType,
typename CodecType>
2133 if (mCollapseOnDestruction) const_cast<AttributeArray*>(this->mArray)->collapse();
2136 template <
typename ValueType,
typename CodecType>
2137 template <
bool IsUnknownCodec>
2138 typename std::enable_if<IsUnknownCodec, bool>::type
2143 return mArray->hasValueType<ValueType>();
2146 template <
typename ValueType,
typename CodecType>
2147 template <
bool IsUnknownCodec>
2148 typename std::enable_if<!IsUnknownCodec, bool>::type
2149 AttributeHandle<ValueType, CodecType>::compatibleType()
const 2153 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2156 template <
typename ValueType,
typename CodecType>
2163 template <
typename ValueType,
typename CodecType>
2166 Index index = n * mStrideOrTotalSize + m;
2167 assert(index < (mSize * mStrideOrTotalSize));
2171 template <
typename ValueType,
typename CodecType>
2174 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2177 template <
typename ValueType,
typename CodecType>
2178 template <
bool IsUnknownCodec>
2179 typename std::enable_if<IsUnknownCodec, ValueType>::type
2184 return (*mGetter)(mArray, index);
2187 template <
typename ValueType,
typename CodecType>
2188 template <
bool IsUnknownCodec>
2189 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2190 AttributeHandle<ValueType, CodecType>::get(
Index index)
const 2194 return TypedAttributeArray<ValueType, CodecType>::getUnsafe(mArray, index);
2197 template <
typename ValueType,
typename CodecType>
2203 template <
typename ValueType,
typename CodecType>
2213 template <
typename ValueType,
typename CodecType>
2221 template <
typename ValueType,
typename CodecType>
2225 if (expand) array.
expand();
2228 template <
typename ValueType,
typename CodecType>
2231 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2234 template <
typename ValueType,
typename CodecType>
2237 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2240 template <
typename ValueType,
typename CodecType>
2243 const_cast<AttributeArray*>(this->mArray)->
expand(fill);
2246 template <
typename ValueType,
typename CodecType>
2249 const_cast<AttributeArray*>(this->mArray)->
collapse();
2252 template <
typename ValueType,
typename CodecType>
2255 return const_cast<AttributeArray*>(this->mArray)->
compact();
2258 template <
typename ValueType,
typename CodecType>
2261 this->mCollapser(const_cast<AttributeArray*>(this->mArray), uniformValue);
2264 template <
typename ValueType,
typename CodecType>
2267 this->mFiller(const_cast<AttributeArray*>(this->mArray), value);
2270 template <
typename ValueType,
typename CodecType>
2271 template <
bool IsUnknownCodec>
2272 typename std::enable_if<IsUnknownCodec, void>::type
2277 (*this->mSetter)(const_cast<AttributeArray*>(this->mArray), index, value);
2280 template <
typename ValueType,
typename CodecType>
2281 template <
bool IsUnknownCodec>
2282 typename std::enable_if<!IsUnknownCodec, void>::type
2283 AttributeWriteHandle<ValueType, CodecType>::set(
Index index,
const ValueType& value)
const 2287 TypedAttributeArray<ValueType, CodecType>::setUnsafe(const_cast<AttributeArray*>(this->mArray), index, value);
2290 template <
typename ValueType,
typename CodecType>
2293 assert(this->mArray);
2294 return *const_cast<AttributeArray*>(this->mArray);
2302 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED Definition: AttributeArray.h:509
virtual Index stride() const =0
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1729
static const char * name()
Definition: AttributeArray.h:532
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1334
short Type
Definition: AttributeArray.h:472
Definition: AttributeArray.h:512
static void unregisterType(const NamePair &type)
Remove a attribute type from the registry.
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1651
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1493
std::istream & getInputStream()
Definition: StreamCompression.h:249
StorageType Type
Definition: AttributeArray.h:559
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:647
SetterPtr mSetter
Definition: AttributeArray.h:459
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2253
int16_t Int16
Definition: Types.h:62
OPENVDB_DEPRECATED bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1602
bool isUniform() const
Definition: AttributeArray.h:2198
Definition: AttributeArray.h:530
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:444
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1215
Index32 Index
Definition: Types.h:61
uint64_t Index64
Definition: Types.h:60
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1223
virtual ~AttributeArray()
Definition: AttributeArray.h:152
Index storageTypeSize() const override
Definition: AttributeArray.h:654
ValuePtr mCollapser
Definition: AttributeArray.h:460
SharedPtr< MappedFile > Ptr
Definition: io.h:152
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2054
Typed class for storing attribute data.
Definition: AttributeArray.h:574
Write-able version of AttributeHandle.
Definition: AttributeArray.h:903
TypedAttributeArray & operator=(const TypedAttributeArray &)
Deep copy assignment operator.
Definition: AttributeArray.h:1172
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:235
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:334
static const char * name()
Definition: AttributeArray.h:516
static const char * name()
Definition: AttributeArray.h:563
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
uint8_t Type
Definition: AttributeArray.h:479
Index stride() const override
Definition: AttributeArray.h:635
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:534
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1207
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1351
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:907
Ptr(*)(Index, Index, bool) FactoryMethod
Definition: AttributeArray.h:147
AttributeArray & operator=(const AttributeArray &rhs)
Definition: AttributeArray.h:169
void(*)(AttributeArray *array, const Index n, const StringIndexType &value) SetterPtr
Definition: AttributeArray.h:841
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:580
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:381
AttributeArray()
Definition: AttributeArray.h:151
T Type
Definition: AttributeArray.h:501
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1390
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2074
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:631
GetterPtr mGetter
Definition: AttributeArray.h:458
GetterPtr mGetter
Definition: AttributeArray.h:869
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1826
Definition: AttributeArray.h:501
Flag
Definition: AttributeArray.h:127
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:124
bool sizeOnly() const
Definition: StreamCompression.h:283
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2247
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:452
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:451
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2051
void(*)(AttributeArray *array, const StringIndexType &value) ValuePtr
Definition: AttributeArray.h:842
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2083
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1678
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:145
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:836
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:432
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:908
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2095
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:340
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:1127
uint8_t mSerializationFlags
Definition: AttributeArray.h:428
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2075
half Type
Definition: AttributeArray.h:471
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:272
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:198
Definition: Exceptions.h:91
SetterPtr mSetter
Definition: AttributeArray.h:870
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:533
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:837
bool mIsUniform
Definition: AttributeArray.h:425
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:585
virtual Index dataSize() const =0
Convenience wrappers to using Blosc and reading and writing of Paged data.
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1660
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...
AttributeArray::Ptr copy() const override
Return a copy of this attribute.
Definition: AttributeArray.h:1258
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:488
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1773
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1427
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1940
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1531
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:621
StringIndexType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:840
ValueType getUnsafe(Index n) const
Return the value at index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1378
tbb::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:429
static const char * name()
Definition: AttributeArray.h:523
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:453
OPENVDB_DEPRECATED bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1586
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:105
uint8_t mFlags
Definition: AttributeArray.h:427
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:280
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:257
static void registerType(const NamePair &type, FactoryMethod)
Register a attribute type along with a factory function.
Definition: AttributeArray.h:122
Codec_ Codec
Definition: AttributeArray.h:584
Definition: AttributeArray.h:521
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1898
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
Definition: Compression.h:81
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:525
T & z()
Definition: Vec3.h:112
static Ptr create(Index n, Index strideOrTotalSize=1, bool constantStride=true)
Return a new attribute array of the given length n and stride with uniform value zero.
Definition: AttributeArray.h:1231
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1669
size_t mCompressedBytes
Definition: AttributeArray.h:433
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...
T & y()
Definition: Vec3.h:111
virtual Index storageTypeSize() const =0
Definition: Exceptions.h:40
AttributeArray::Ptr copyUncompressed() const override
Return an uncompressed copy of this attribute (will just return a copy if not compressed).
Definition: AttributeArray.h:1266
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:286
AttributeArray(const AttributeArray &rhs)
Definition: AttributeArray.h:159
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:777
Definition: AttributeArray.h:554
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:144
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
static const char * name()
Definition: AttributeArray.h:547
uint16_t StorageType
Definition: AttributeArray.h:556
Definition: Exceptions.h:84
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1343
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:455
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1835
Index stride() const
Definition: AttributeArray.h:854
Definition: AttributeArray.h:542
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1514
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:326
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1360
uint16_t Type
Definition: AttributeArray.h:480
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:638
Definition: AttributeArray.h:478
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:95
bool hasConstantStride() const
Definition: AttributeArray.h:2204
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1195
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2058
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
const StorageType * data() const
Definition: AttributeArray.h:778
Definition: AttributeArray.h:498
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1442
Definition: AttributeArray.h:559
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2053
Definition: AttributeArray.h:539
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:781
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1370
bool sizeOnly() const
Definition: StreamCompression.h:246
tbb::spin_mutex mMutex
Definition: AttributeArray.h:426
const AttributeArray * mArray
Definition: AttributeArray.h:867
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1238
Base class for storing attribute data.
Definition: AttributeArray.h:118
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:512
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
Definition: AttributeArray.h:832
SerializationFlag
Definition: AttributeArray.h:136
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:337
OPENVDB_DEPRECATED bool isCompressed() const
Definition: AttributeArray.h:307
ValuePtr mFiller
Definition: AttributeArray.h:872
virtual ~TypedAttributeArray()
Definition: AttributeArray.h:601
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1561
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2102
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:705
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1314
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2078
Definition: Exceptions.h:92
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2064
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:253
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:650
ValuePtr mCollapser
Definition: AttributeArray.h:871
Definition: Exceptions.h:85
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:524
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
virtual void loadData() const =0
Ensures all data is in-core.
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:542
static const char * name()
Definition: AttributeArray.h:505
std::string Name
Definition: Name.h:44
Definition: AttributeArray.h:495
ValuePtr mFiller
Definition: AttributeArray.h:461
ValueType_ ValueType
Definition: AttributeArray.h:583
Definition: AttributeArray.h:470
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:1992
static bool isRegistered(const NamePair &type)
Return true if the given attribute type name is registered.
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1610
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:319
Index size() const
Definition: AttributeArray.h:855
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2241
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:110
T ElementType
Definition: Types.h:218