37 #ifndef OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED 40 #include <openvdb/Types.h> 41 #include <openvdb/math/QuantizedUnitVec.h> 42 #include <openvdb/util/Name.h> 43 #include <openvdb/util/logging.h> 44 #include <openvdb/io/io.h> 45 #include <openvdb/io/Compression.h> 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,
138 WRITEMEMCOMPRESS = 0x4,
142 using Ptr = std::shared_ptr<AttributeArray>;
143 using ConstPtr = std::shared_ptr<const AttributeArray>;
162 virtual Index size()
const = 0;
166 virtual Index stride()
const = 0;
170 virtual Index dataSize()
const = 0;
173 virtual size_t memUsage()
const = 0;
176 static Ptr create(
const NamePair& type, Index length, Index stride = 1,
bool constantStride =
true);
178 static bool isRegistered(
const NamePair& type);
180 static void clearRegistry();
183 virtual const NamePair& type()
const = 0;
185 template<
typename AttributeArrayType>
186 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
189 template<
typename ValueType>
190 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
193 virtual void set(
const Index n,
const AttributeArray& sourceArray,
const Index sourceIndex) = 0;
196 virtual bool isUniform()
const = 0;
199 virtual void expand(
bool fill =
true) = 0;
201 virtual void collapse() = 0;
203 virtual bool compact() = 0;
208 virtual bool compress() = 0;
210 virtual bool decompress() = 0;
216 void setHidden(
bool state);
218 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
223 void setTransient(
bool state);
231 void setStreaming(
bool state);
239 uint8_t
flags()
const {
return mFlags; }
242 virtual void read(std::istream&) = 0;
245 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
247 virtual void write(std::ostream&)
const = 0;
250 virtual void readMetadata(std::istream&) = 0;
254 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
257 virtual void readBuffers(std::istream&) = 0;
260 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
269 virtual void loadData()
const = 0;
278 friend class ::TestAttributeArray;
286 void setConstantStride(
bool state);
294 static void unregisterType(
const NamePair& type);
296 size_t mCompressedBytes = 0;
298 uint8_t mSerializationFlags = 0;
300 #if OPENVDB_ABI_VERSION_NUMBER >= 5 301 tbb::atomic<Index32> mOutOfCore = 0;
317 template <
typename T>
325 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
337 namespace attribute_traits
369 template <
typename T>
372 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
373 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
374 static const char*
name() {
return "null"; }
380 template <
typename T>
383 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
384 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
385 static const char*
name() {
return "trnc"; }
392 static const char*
name() {
return "fxpt"; }
393 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
394 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
401 static const char*
name() {
return "ufxpt"; }
402 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
403 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
407 template <
bool OneByte,
typename Range=PositionRange>
410 template <
typename T>
413 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
414 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
417 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
427 template <
typename T>
432 static const char*
name() {
return "uvec"; }
440 template<
typename ValueType_,
typename Codec_ = NullCodec>
444 using Ptr = std::shared_ptr<TypedAttributeArray>;
445 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
449 using StorageType =
typename Codec::template Storage<ValueType>::Type;
455 const ValueType& uniformValue = zeroVal<ValueType>());
474 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true);
483 static const NamePair& attributeType();
488 static bool isRegistered();
490 static void registerType();
492 static void unregisterType();
499 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
503 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
507 size_t memUsage()
const override;
514 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
516 template<
typename T>
void get(
Index n, T& value)
const;
527 template<
typename T>
void setUnsafe(
Index n,
const T& value);
529 template<
typename T>
void set(
Index n,
const T& value);
543 void expand(
bool fill =
true)
override;
545 void collapse()
override;
547 bool compact()
override;
550 void collapse(
const ValueType& uniformValue);
561 bool compress()
override;
563 bool decompress()
override;
566 void read(std::istream&)
override;
570 void write(std::ostream& os,
bool outputTransient)
const override;
572 void write(std::ostream&)
const override;
575 void readMetadata(std::istream&)
override;
580 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
583 void readBuffers(std::istream&)
override;
587 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
597 inline bool isOutOfCore()
const;
600 void loadData()
const override;
607 inline void doLoad()
const;
610 inline void doLoadUnsafe(
const bool compression =
true)
const;
612 inline bool compressUnsafe();
615 inline void setOutOfCore(
const bool);
620 size_t arrayMemUsage()
const;
626 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride);
629 static tbb::atomic<const NamePair*> sTypeName;
630 std::unique_ptr<StorageType[]> mData;
632 Index mStrideOrTotalSize;
633 bool mIsUniform =
false;
634 tbb::spin_mutex mMutex;
643 template <
typename ValueType,
typename CodecType = UnknownCodec>
648 using Ptr = std::shared_ptr<Handle>;
657 static Ptr create(
const AttributeArray& array,
const bool preserveCompression =
true);
669 bool isUniform()
const;
670 bool hasConstantStride()
const;
687 friend class ::TestAttributeArray;
689 template <
bool IsUnknownCodec>
690 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
692 template <
bool IsUnknownCodec>
693 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
695 template <
bool IsUnknownCodec>
696 typename std::enable_if<IsUnknownCodec, ValueType>::type
get(
Index index)
const;
698 template <
bool IsUnknownCodec>
699 typename std::enable_if<!IsUnknownCodec, ValueType>::type
get(
Index index)
const;
704 Index mStrideOrTotalSize;
706 bool mCollapseOnDestruction;
714 template <
typename ValueType,
typename CodecType = UnknownCodec>
719 using Ptr = std::shared_ptr<Handle>;
730 void expand(
bool fill =
true);
734 void collapse(
const ValueType& uniformValue);
741 void fill(
const ValueType& value);
743 void set(
Index n,
const ValueType& value);
744 void set(
Index n,
Index m,
const ValueType& value);
749 friend class ::TestAttributeArray;
751 template <
bool IsUnknownCodec>
752 typename std::enable_if<IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
754 template <
bool IsUnknownCodec>
755 typename std::enable_if<!IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
765 template<
typename ValueType>
767 NullCodec::decode(
const ValueType& data, ValueType& val)
773 template<
typename ValueType>
775 NullCodec::encode(
const ValueType& val, ValueType& data)
781 template<
typename StorageType,
typename ValueType>
783 TruncateCodec::decode(
const StorageType& data, ValueType& val)
785 val =
static_cast<ValueType
>(data);
789 template<
typename StorageType,
typename ValueType>
791 TruncateCodec::encode(
const ValueType& val, StorageType& data)
793 data =
static_cast<StorageType
>(val);
797 template <
bool OneByte,
typename Range>
798 template<
typename StorageType,
typename ValueType>
802 val = fixedPointToFloatingPoint<ValueType>(data);
806 val = Range::template decode<ValueType>(val);
810 template <
bool OneByte,
typename Range>
811 template<
typename StorageType,
typename ValueType>
817 const ValueType newVal = Range::template encode<ValueType>(val);
819 data = floatingPointToFixedPoint<StorageType>(newVal);
827 val = math::QuantizedUnitVec::unpack(data);
835 data = math::QuantizedUnitVec::pack(val);
843 template<
typename ValueType_,
typename Codec_>
847 template<
typename ValueType_,
typename Codec_>
852 , mStrideOrTotalSize(strideOrTotalSize)
855 if (constantStride) {
857 if (strideOrTotalSize == 0) {
859 "stride to be at least one.")
864 if (mStrideOrTotalSize < n) {
866 "a total size of at least the number of elements in the array.")
871 Codec::encode(uniformValue, mData.get()[0]);
875 template<
typename ValueType_,
typename Codec_>
879 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
880 , mIsUniform(rhs.mIsUniform)
888 }
else if (mIsUniform) {
890 mData.get()[0] = rhs.mData.get()[0];
892 std::unique_ptr<char[]> buffer;
894 const char* charBuffer =
reinterpret_cast<const char*
>(rhs.mData.get());
906 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
909 std::memcpy(mData.get(), rhs.mData.get(), this->arrayMemUsage());
914 template<
typename ValueType_,
typename Codec_>
919 tbb::spin_mutex::scoped_lock lock(mMutex);
927 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
928 mIsUniform = rhs.mIsUniform;
932 }
else if (mIsUniform) {
934 mData.get()[0] = rhs.mData.get()[0];
938 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
941 std::memcpy(mData.get(), rhs.mData.get(), arrayMemUsage());
947 template<
typename ValueType_,
typename Codec_>
951 if (sTypeName ==
nullptr) {
953 if (sTypeName.compare_and_swap(s,
nullptr) !=
nullptr)
delete s;
959 template<
typename ValueType_,
typename Codec_>
967 template<
typename ValueType_,
typename Codec_>
975 template<
typename ValueType_,
typename Codec_>
983 template<
typename ValueType_,
typename Codec_>
990 template<
typename ValueType_,
typename Codec_>
1000 template<
typename ValueType_,
typename Codec_>
1010 template<
typename ValueType_,
typename Codec_>
1018 template<
typename ValueType_,
typename Codec_>
1026 template<
typename ValueType_,
typename Codec_>
1037 template<
typename ValueType_,
typename Codec_>
1053 template<
typename ValueType_,
typename Codec_>
1059 this->setOutOfCore(
false);
1062 if (mData) mData.reset();
1066 template<
typename ValueType_,
typename Codec_>
1070 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1074 template<
typename ValueType_,
typename Codec_>
1083 Codec::decode(mData.get()[mIsUniform ? 0 : n], val);
1088 template<
typename ValueType_,
typename Codec_>
1100 template<
typename ValueType_,
typename Codec_>
1101 template<
typename T>
1105 val =
static_cast<T
>(this->
getUnsafe(n));
1109 template<
typename ValueType_,
typename Codec_>
1110 template<
typename T>
1114 val =
static_cast<T
>(this->
get(n));
1118 template<
typename ValueType_,
typename Codec_>
1126 template<
typename ValueType_,
typename Codec_>
1138 Codec::encode(val, mData.get()[mIsUniform ? 0 : n]);
1142 template<
typename ValueType_,
typename Codec_>
1155 template<
typename ValueType_,
typename Codec_>
1156 template<
typename T>
1160 this->
setUnsafe(n, static_cast<ValueType>(val));
1164 template<
typename ValueType_,
typename Codec_>
1165 template<
typename T>
1169 this->
set(n,
static_cast<ValueType>(val));
1173 template<
typename ValueType_,
typename Codec_>
1181 template<
typename ValueType_,
typename Codec_>
1188 sourceTypedArray.
get(sourceIndex, sourceValue);
1190 this->
set(n, sourceValue);
1194 template<
typename ValueType_,
typename Codec_>
1198 if (!mIsUniform)
return;
1203 tbb::spin_mutex::scoped_lock lock(mMutex);
1212 for (
Index i = 0; i < this->
dataSize(); ++i) mData.get()[i] = val;
1217 template<
typename ValueType_,
typename Codec_>
1221 if (mIsUniform)
return true;
1224 const ValueType_ val = this->
get(0);
1234 template<
typename ValueType_,
typename Codec_>
1238 this->
collapse(zeroVal<ValueType>());
1242 template<
typename ValueType_,
typename Codec_>
1247 tbb::spin_mutex::scoped_lock lock(mMutex);
1252 Codec::encode(uniformValue, mData.get()[0]);
1256 template<
typename ValueType_,
typename Codec_>
1264 template<
typename ValueType_,
typename Codec_>
1269 tbb::spin_mutex::scoped_lock lock(mMutex);
1276 Codec::encode(value, mData.get()[i]);
1281 template<
typename ValueType_,
typename Codec_>
1289 template<
typename ValueType_,
typename Codec_>
1297 tbb::spin_mutex::scoped_lock lock(mMutex);
1299 this->doLoadUnsafe(
false);
1303 return this->compressUnsafe();
1310 template<
typename ValueType_,
typename Codec_>
1315 if (mIsUniform)
return false;
1320 const size_t inBytes = writeCompress ?
mCompressedBytes : this->arrayMemUsage();
1324 const char* charBuffer =
reinterpret_cast<const char*
>(mData.get());
1327 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1337 template<
typename ValueType_,
typename Codec_>
1341 tbb::spin_mutex::scoped_lock lock(mMutex);
1345 if (writeCompress) {
1346 this->doLoadUnsafe(
false);
1351 this->doLoadUnsafe();
1352 const char* charBuffer =
reinterpret_cast<const char*
>(this->mData.get());
1356 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1366 template<
typename ValueType_,
typename Codec_>
1370 #if OPENVDB_ABI_VERSION_NUMBER >= 5 1378 template<
typename ValueType_,
typename Codec_>
1382 #if OPENVDB_ABI_VERSION_NUMBER >= 5 1391 template<
typename ValueType_,
typename Codec_>
1402 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1403 this->doLoadUnsafe();
1407 template<
typename ValueType_,
typename Codec_>
1415 template<
typename ValueType_,
typename Codec_>
1424 template<
typename ValueType_,
typename Codec_>
1431 is.read(reinterpret_cast<char*>(&bytes),
sizeof(
Index64));
1432 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1434 uint8_t
flags = uint8_t(0);
1435 is.read(reinterpret_cast<char*>(&flags),
sizeof(uint8_t));
1438 uint8_t serializationFlags = uint8_t(0);
1439 is.read(reinterpret_cast<char*>(&serializationFlags),
sizeof(uint8_t));
1443 is.read(reinterpret_cast<char*>(&size),
sizeof(
Index));
1465 is.read(reinterpret_cast<char*>(&stride),
sizeof(
Index));
1466 mStrideOrTotalSize =
stride;
1469 mStrideOrTotalSize = 1;
1474 template<
typename ValueType_,
typename Codec_>
1483 tbb::spin_mutex::scoped_lock lock(mMutex);
1487 uint8_t bloscCompressed(0);
1488 if (!mIsUniform) is.read(reinterpret_cast<char*>(&bloscCompressed),
sizeof(uint8_t));
1495 mCompressedBytes =
Index64(0);
1499 mCompressedBytes =
Index64(0);
1504 if (bloscCompressed == uint8_t(1)) {
1510 if (newBuffer) buffer.reset(newBuffer.release());
1515 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1524 template<
typename ValueType_,
typename Codec_>
1536 const bool delayLoad = (mappedFile.get() !=
nullptr);
1546 tbb::spin_mutex::scoped_lock lock(mMutex);
1550 this->setOutOfCore(delayLoad);
1554 std::unique_ptr<char[]> buffer =
mPageHandle->read();
1555 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1575 template<
typename ValueType_,
typename Codec_>
1579 this->
write(os,
false);
1583 template<
typename ValueType_,
typename Codec_>
1592 template<
typename ValueType_,
typename Codec_>
1596 if (!outputTransient && this->
isTransient())
return;
1598 #if OPENVDB_ABI_VERSION_NUMBER >= 5 1603 uint8_t serializationFlags(0);
1606 bool strideOfOne(this->
stride() == 1);
1611 if (bloscCompression || this->
isCompressed()) this->doLoad();
1613 size_t compressedBytes = 0;
1623 if (bloscCompression && paged) serializationFlags |=
WRITEPAGED;
1625 else if (bloscCompression && paged)
1630 const char* charBuffer =
reinterpret_cast<const char*
>(mData.get());
1639 else if (bloscCompression)
1641 const char* charBuffer =
reinterpret_cast<const char*
>(mData.get());
1642 const size_t inBytes = this->arrayMemUsage();
1648 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1652 os.write(reinterpret_cast<const char*>(&bytes),
sizeof(
Index64));
1653 os.write(reinterpret_cast<const char*>(&flags),
sizeof(uint8_t));
1654 os.write(reinterpret_cast<const char*>(&serializationFlags),
sizeof(uint8_t));
1655 os.write(reinterpret_cast<const char*>(&size),
sizeof(
Index));
1658 if (!strideOfOne) os.write(reinterpret_cast<const char*>(&stride),
sizeof(
Index));
1662 template<
typename ValueType_,
typename Codec_>
1666 if (!outputTransient && this->
isTransient())
return;
1671 os.write(reinterpret_cast<const char*>(mData.get()),
sizeof(
StorageType));
1675 uint8_t bloscCompressed(0);
1676 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1681 std::unique_ptr<char[]> compressedBuffer;
1682 size_t compressedBytes = 0;
1683 const char* charBuffer =
reinterpret_cast<const char*
>(mData.get());
1684 const size_t inBytes = this->arrayMemUsage();
1686 if (compressedBuffer) {
1687 uint8_t bloscCompressed(1);
1688 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1689 os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
1692 uint8_t bloscCompressed(0);
1693 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1694 os.write(reinterpret_cast<const char*>(mData.get()), inBytes);
1699 uint8_t bloscCompressed(0);
1700 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1701 os.write(reinterpret_cast<const char*>(mData.get()), this->arrayMemUsage());
1706 template<
typename ValueType_,
typename Codec_>
1710 if (!outputTransient && this->
isTransient())
return;
1714 if (!bloscCompression) {
1724 std::unique_ptr<char[]> uncompressedBuffer;
1728 const char* charBuffer =
reinterpret_cast<const char*
>(this->mData.get());
1731 buffer =
reinterpret_cast<const char*
>(uncompressedBuffer.get());
1734 buffer =
reinterpret_cast<const char*
>(mData.get());
1735 bytes = this->arrayMemUsage();
1738 os.
write(buffer, bytes);
1742 template<
typename ValueType_,
typename Codec_>
1752 assert(self->mPageHandle);
1754 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
1756 self->mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1758 self->mPageHandle.reset();
1763 if (compression)
self->compressUnsafe();
1764 else self->mCompressedBytes = 0;
1769 #if OPENVDB_ABI_VERSION_NUMBER >= 5 1770 self->mOutOfCore =
false;
1778 template<
typename ValueType_,
typename Codec_>
1793 template<
typename ValueType_,
typename Codec_>
1798 if(!otherT)
return false;
1799 if(this->mSize != otherT->mSize ||
1800 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1801 this->mIsUniform != otherT->mIsUniform ||
1802 *this->sTypeName != *otherT->sTypeName)
return false;
1807 const StorageType *target = this->mData.get(), *source = otherT->mData.get();
1808 if (!target && !source)
return true;
1809 if (!target || !source)
return false;
1810 Index n = this->mIsUniform ? 1 : mSize;
1819 template <
typename CodecType,
typename ValueType>
1840 template <
typename ValueType>
1848 return (*functor)(array, n);
1853 (*functor)(array, n, value);
1862 template <
typename ValueType,
typename CodecType>
1870 template <
typename ValueType,
typename CodecType>
1875 , mCollapseOnDestruction(preserveCompression && array.
isStreaming())
1877 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
1890 if (preserveCompression && !array.
isStreaming()) {
1892 mLocalArray->decompress();
1893 mArray = mLocalArray.get();
1907 mGetter = typedAccessor->
mGetter;
1908 mSetter = typedAccessor->
mSetter;
1910 mFiller = typedAccessor->
mFiller;
1913 template <
typename ValueType,
typename CodecType>
1917 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
1920 template <
typename ValueType,
typename CodecType>
1921 template <
bool IsUnknownCodec>
1922 typename std::enable_if<IsUnknownCodec, bool>::type
1927 return mArray->hasValueType<ValueType>();
1930 template <
typename ValueType,
typename CodecType>
1931 template <
bool IsUnknownCodec>
1932 typename std::enable_if<!IsUnknownCodec, bool>::type
1940 template <
typename ValueType,
typename CodecType>
1947 template <
typename ValueType,
typename CodecType>
1950 Index index = n * mStrideOrTotalSize + m;
1951 assert(index < (mSize * mStrideOrTotalSize));
1955 template <
typename ValueType,
typename CodecType>
1958 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
1961 template <
typename ValueType,
typename CodecType>
1962 template <
bool IsUnknownCodec>
1963 typename std::enable_if<IsUnknownCodec, ValueType>::type
1968 return (*mGetter)(mArray, index);
1971 template <
typename ValueType,
typename CodecType>
1972 template <
bool IsUnknownCodec>
1973 typename std::enable_if<!IsUnknownCodec, ValueType>::type
1981 template <
typename ValueType,
typename CodecType>
1987 template <
typename ValueType,
typename CodecType>
1997 template <
typename ValueType,
typename CodecType>
2005 template <
typename ValueType,
typename CodecType>
2009 if (expand) array.
expand();
2012 template <
typename ValueType,
typename CodecType>
2015 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2018 template <
typename ValueType,
typename CodecType>
2021 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2024 template <
typename ValueType,
typename CodecType>
2030 template <
typename ValueType,
typename CodecType>
2036 template <
typename ValueType,
typename CodecType>
2042 template <
typename ValueType,
typename CodecType>
2045 this->mCollapser(const_cast<AttributeArray*>(this->mArray), uniformValue);
2048 template <
typename ValueType,
typename CodecType>
2051 this->mFiller(const_cast<AttributeArray*>(this->mArray), value);
2054 template <
typename ValueType,
typename CodecType>
2055 template <
bool IsUnknownCodec>
2056 typename std::enable_if<IsUnknownCodec, void>::type
2061 (*this->mSetter)(const_cast<AttributeArray*>(this->mArray), index, value);
2064 template <
typename ValueType,
typename CodecType>
2065 template <
bool IsUnknownCodec>
2066 typename std::enable_if<!IsUnknownCodec, void>::type
2074 template <
typename ValueType,
typename CodecType>
2077 assert(this->mArray);
2086 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED bool sizeOnly() const
Definition: StreamCompression.h:236
T & y()
Definition: Vec3.h:111
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:218
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:1820
Definition: AttributeArray.h:122
const AttributeArray * mArray
Definition: AttributeArray.h:679
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:322
Write-able version of AttributeHandle.
Definition: AttributeArray.h:715
data is marked as compressed in-memory when written
Definition: AttributeArray.h:139
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1068
Definition: AttributeArray.h:378
ValueType_ ValueType
Definition: AttributeArray.h:447
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:403
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:225
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
Flag
Definition: AttributeArray.h:127
AttributeArray::Ptr copy() const override
Return a copy of this attribute.
Definition: AttributeArray.h:1012
bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1339
ValuePtr mCollapser
Definition: AttributeArray.h:683
static const char * name()
Definition: AttributeArray.h:385
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1219
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1526
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:719
Definition: AttributeArray.h:370
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
Ptr(*)(Index, Index, bool) FactoryMethod
Definition: AttributeArray.h:145
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1708
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:105
short Type
Definition: AttributeArray.h:341
compression::PageHandle::Ptr mPageHandle
used for out-of-core, paged reading
Definition: AttributeArray.h:305
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:321
SetterPtr mSetter
Definition: AttributeArray.h:328
ValuePtr mFiller
Definition: AttributeArray.h:330
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:124
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1664
uint16_t Type
Definition: AttributeArray.h:349
std::string Name
Definition: Name.h:44
OPENVDB_API bool bloscCanCompress()
Returns true if compression is available.
SetterPtr mSetter
Definition: AttributeArray.h:682
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:402
Definition: Exceptions.h:91
Definition: AttributeArray.h:428
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK, etc.) specifying whether and how input data is compressed or output data should be compressed.
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:992
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:233
ValuePtr mFiller
Definition: AttributeArray.h:684
Definition: AttributeArray.h:347
Definition: AttributeArray.h:136
std::shared_ptr< PageHandle > Ptr
Definition: StreamCompression.h:197
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:444
Codec_ Codec
Definition: AttributeArray.h:448
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:143
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...
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1426
ValuePtr mCollapser
Definition: AttributeArray.h:329
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:381
TypedAttributeArray & operator=(const TypedAttributeArray &)
Deep copy assignment operator.
Definition: AttributeArray.h:916
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:848
AttributeArray::Ptr copyUncompressed() const override
Return an uncompressed copy of this attribute (will just return a copy if not compressed).
Definition: AttributeArray.h:1020
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1476
StorageType Type
Definition: AttributeArray.h:428
bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1291
static const char * name()
Definition: AttributeArray.h:392
static const char * name()
Definition: AttributeArray.h:416
Index size() const
Definition: AttributeArray.h:667
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.
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1090
half Type
Definition: AttributeArray.h:340
AttributeHandle(const AttributeArray &array, const bool preserveCompression=true)
Definition: AttributeArray.h:1871
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:495
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:324
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:313
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:275
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:394
GetterPtr mGetter
Definition: AttributeArray.h:681
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:720
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...
uint8_t Type
Definition: AttributeArray.h:348
Convenience wrappers to using Blosc and reading and writing of Paged data.
static Ptr create(const AttributeArray &array, const bool preserveCompression=true)
Definition: AttributeArray.h:1864
bool hasConstantStride() const
Definition: AttributeArray.h:1988
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:190
data is marked as strided when written
Definition: AttributeArray.h:137
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: Exceptions.h:92
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:280
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:239
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:648
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:1844
uint8_t mSerializationFlags
Definition: AttributeArray.h:298
bool isUniform() const
Definition: AttributeArray.h:1982
static const char * name()
Definition: AttributeArray.h:432
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:485
bool isCompressed() const
Return true if this array is compressed.
Definition: AttributeArray.h:206
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:449
int16_t Int16
Definition: Types.h:62
T Type
Definition: AttributeArray.h:370
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:110
bool sizeOnly() const
Definition: StreamCompression.h:273
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:411
static void registerType(const NamePair &type, FactoryMethod)
Register a attribute type along with a factory function.
uint8_t mFlags
Definition: AttributeArray.h:297
Definition: Exceptions.h:40
Definition: Compression.h:81
Definition: AttributeArray.h:390
data is marked as uniform when written
Definition: AttributeArray.h:138
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1417
size_t mCompressedBytes
Definition: AttributeArray.h:296
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1368
SerializationFlag
Definition: AttributeArray.h:135
Index32 Index
Definition: Types.h:61
tbb::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:301
void(*)(AttributeArray *array, const Index n, const StringIndexType &value) SetterPtr
Definition: AttributeArray.h:653
StringIndexType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:652
std::istream & getInputStream()
Definition: StreamCompression.h:239
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:393
Definition: AttributeArray.h:644
GetterPtr mGetter
Definition: AttributeArray.h:327
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1144
Base class for storing attribute data.
Definition: AttributeArray.h:118
uint64_t Index64
Definition: Types.h:60
Definition: AttributeArray.h:408
hidden from UIs or iterators
Definition: AttributeArray.h:130
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:186
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:488
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:985
Definition: AttributeArray.h:381
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1128
uint16_t StorageType
Definition: AttributeArray.h:425
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:961
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:225
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:236
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1409
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
Definition: Exceptions.h:84
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1594
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:320
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:969
ValueType getUnsafe(Index n) const
Return the value at index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1076
Definition: AttributeArray.h:411
Definition: AttributeArray.h:423
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:1780
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:949
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:1843
Definition: AttributeArray.h:364
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:1823
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:276
Definition: AttributeArray.h:367
virtual ~TypedAttributeArray()
Definition: AttributeArray.h:465
static const char * name()
Definition: AttributeArray.h:374
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:95
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1266
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:539
Definition: AttributeArray.h:339
virtual AttributeArray::Ptr copyUncompressed() const =0
Return an uncompressed copy of this attribute (will return a copy if not compressed).
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated, or a null pointer if the stream is not associated with a memory-mapped file.
Index stride() const override
Definition: AttributeArray.h:499
static void unregisterType(const NamePair &type)
Remove a attribute type from the registry.
SharedPtr< MappedFile > Ptr
Definition: io.h:152
static bool isRegistered(const NamePair &type)
Return true if the given attribute type name is registered.
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:502
static const char * name()
Definition: AttributeArray.h:401
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1196
void(*)(AttributeArray *array, const StringIndexType &value) ValuePtr
Definition: AttributeArray.h:654
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:262
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:649
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1585
OPENVDB_API size_t bloscUncompressedSize(const char *buffer)
Retrieves the uncompressed size of buffer when uncompressed.
Index stride() const
Definition: AttributeArray.h:666
Definition: Exceptions.h:85
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:1822
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:977
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1236
T & z()
Definition: Vec3.h:112
Definition: AttributeArray.h:399
Typed class for storing attribute data.
Definition: AttributeArray.h:441