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,
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;
313 template <
typename T>
321 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
333 namespace attribute_traits
365 template <
typename T>
368 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
369 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
370 static const char*
name() {
return "null"; }
376 template <
typename T>
379 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
380 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
381 static const char*
name() {
return "trnc"; }
388 static const char*
name() {
return "fxpt"; }
389 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
390 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
397 static const char*
name() {
return "ufxpt"; }
398 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
399 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
403 template <
bool OneByte,
typename Range=PositionRange>
406 template <
typename T>
409 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
410 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
413 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
423 template <
typename T>
428 static const char*
name() {
return "uvec"; }
436 template<
typename ValueType_,
typename Codec_ = NullCodec>
440 using Ptr = std::shared_ptr<TypedAttributeArray>;
441 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
445 using StorageType =
typename Codec::template Storage<ValueType>::Type;
451 const ValueType& uniformValue = zeroVal<ValueType>());
470 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true);
479 static const NamePair& attributeType();
484 static bool isRegistered();
486 static void registerType();
488 static void unregisterType();
495 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
499 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
503 size_t memUsage()
const override;
510 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
512 template<
typename T>
void get(
Index n, T& value)
const;
523 template<
typename T>
void setUnsafe(
Index n,
const T& value);
525 template<
typename T>
void set(
Index n,
const T& value);
539 void expand(
bool fill =
true)
override;
541 void collapse()
override;
543 bool compact()
override;
546 void collapse(
const ValueType& uniformValue);
557 bool compress()
override;
559 bool decompress()
override;
562 void read(std::istream&)
override;
566 void write(std::ostream& os,
bool outputTransient)
const override;
568 void write(std::ostream&)
const override;
571 void readMetadata(std::istream&)
override;
576 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
579 void readBuffers(std::istream&)
override;
583 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
593 inline bool isOutOfCore()
const;
596 void loadData()
const override;
603 inline void doLoad()
const;
606 inline void doLoadUnsafe(
const bool compression =
true)
const;
608 inline bool compressUnsafe();
611 inline void setOutOfCore(
const bool);
616 size_t arrayMemUsage()
const;
622 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride);
625 static tbb::atomic<const NamePair*> sTypeName;
626 std::unique_ptr<StorageType[]> mData;
628 Index mStrideOrTotalSize;
629 bool mIsUniform =
false;
630 tbb::spin_mutex mMutex;
639 template <
typename ValueType,
typename CodecType = UnknownCodec>
644 using Ptr = std::shared_ptr<Handle>;
653 static Ptr create(
const AttributeArray& array,
const bool preserveCompression =
true);
665 bool isUniform()
const;
666 bool hasConstantStride()
const;
681 friend class ::TestAttributeArray;
683 template <
bool IsUnknownCodec>
684 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
686 template <
bool IsUnknownCodec>
687 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
689 template <
bool IsUnknownCodec>
690 typename std::enable_if<IsUnknownCodec, ValueType>::type
get(
Index index)
const;
692 template <
bool IsUnknownCodec>
693 typename std::enable_if<!IsUnknownCodec, ValueType>::type
get(
Index index)
const;
698 Index mStrideOrTotalSize;
700 bool mCollapseOnDestruction;
708 template <
typename ValueType,
typename CodecType = UnknownCodec>
713 using Ptr = std::shared_ptr<Handle>;
724 void expand(
bool fill =
true);
728 void collapse(
const ValueType& uniformValue);
735 void fill(
const ValueType& value);
737 void set(
Index n,
const ValueType& value);
738 void set(
Index n,
Index m,
const ValueType& value);
741 friend class ::TestAttributeArray;
743 template <
bool IsUnknownCodec>
744 typename std::enable_if<IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
746 template <
bool IsUnknownCodec>
747 typename std::enable_if<!IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
757 template<
typename ValueType>
759 NullCodec::decode(
const ValueType&
data, ValueType& val)
765 template<
typename ValueType>
767 NullCodec::encode(
const ValueType& val, ValueType&
data)
773 template<
typename StorageType,
typename ValueType>
775 TruncateCodec::decode(
const StorageType&
data, ValueType& val)
777 val =
static_cast<ValueType
>(
data);
781 template<
typename StorageType,
typename ValueType>
783 TruncateCodec::encode(
const ValueType& val, StorageType&
data)
785 data =
static_cast<StorageType
>(val);
789 template <
bool OneByte,
typename Range>
790 template<
typename StorageType,
typename ValueType>
794 val = fixedPointToFloatingPoint<ValueType>(
data);
798 val = Range::template decode<ValueType>(val);
802 template <
bool OneByte,
typename Range>
803 template<
typename StorageType,
typename ValueType>
809 const ValueType newVal = Range::template encode<ValueType>(val);
811 data = floatingPointToFixedPoint<StorageType>(newVal);
819 val = math::QuantizedUnitVec::unpack(data);
827 data = math::QuantizedUnitVec::pack(val);
835 template<
typename ValueType_,
typename Codec_>
839 template<
typename ValueType_,
typename Codec_>
844 , mStrideOrTotalSize(strideOrTotalSize)
847 if (constantStride) {
849 if (strideOrTotalSize == 0) {
851 "stride to be at least one.")
856 if (mStrideOrTotalSize < n) {
858 "a total size of at least the number of elements in the array.")
863 Codec::encode(uniformValue, mData.get()[0]);
867 template<
typename ValueType_,
typename Codec_>
871 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
872 , mIsUniform(rhs.mIsUniform)
880 }
else if (mIsUniform) {
882 mData.get()[0] = rhs.mData.get()[0];
884 std::unique_ptr<char[]> buffer;
886 const char* charBuffer =
reinterpret_cast<const char*
>(rhs.mData.get());
898 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
901 std::memcpy(mData.get(), rhs.mData.get(), this->arrayMemUsage());
906 template<
typename ValueType_,
typename Codec_>
911 tbb::spin_mutex::scoped_lock lock(mMutex);
919 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
920 mIsUniform = rhs.mIsUniform;
924 }
else if (mIsUniform) {
926 mData.get()[0] = rhs.mData.get()[0];
930 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
933 std::memcpy(mData.get(), rhs.mData.get(), arrayMemUsage());
939 template<
typename ValueType_,
typename Codec_>
943 if (sTypeName ==
nullptr) {
945 if (sTypeName.compare_and_swap(s,
nullptr) !=
nullptr)
delete s;
951 template<
typename ValueType_,
typename Codec_>
959 template<
typename ValueType_,
typename Codec_>
967 template<
typename ValueType_,
typename Codec_>
975 template<
typename ValueType_,
typename Codec_>
982 template<
typename ValueType_,
typename Codec_>
992 template<
typename ValueType_,
typename Codec_>
1002 template<
typename ValueType_,
typename Codec_>
1010 template<
typename ValueType_,
typename Codec_>
1018 template<
typename ValueType_,
typename Codec_>
1029 template<
typename ValueType_,
typename Codec_>
1045 template<
typename ValueType_,
typename Codec_>
1051 this->setOutOfCore(
false);
1054 if (mData) mData.reset();
1058 template<
typename ValueType_,
typename Codec_>
1062 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1066 template<
typename ValueType_,
typename Codec_>
1075 Codec::decode(mData.get()[mIsUniform ? 0 : n], val);
1080 template<
typename ValueType_,
typename Codec_>
1092 template<
typename ValueType_,
typename Codec_>
1093 template<
typename T>
1097 val =
static_cast<T
>(this->
getUnsafe(n));
1101 template<
typename ValueType_,
typename Codec_>
1102 template<
typename T>
1106 val =
static_cast<T
>(this->
get(n));
1110 template<
typename ValueType_,
typename Codec_>
1118 template<
typename ValueType_,
typename Codec_>
1130 Codec::encode(val, mData.get()[mIsUniform ? 0 : n]);
1134 template<
typename ValueType_,
typename Codec_>
1147 template<
typename ValueType_,
typename Codec_>
1148 template<
typename T>
1152 this->
setUnsafe(n, static_cast<ValueType>(val));
1156 template<
typename ValueType_,
typename Codec_>
1157 template<
typename T>
1161 this->
set(n,
static_cast<ValueType>(val));
1165 template<
typename ValueType_,
typename Codec_>
1173 template<
typename ValueType_,
typename Codec_>
1180 sourceTypedArray.
get(sourceIndex, sourceValue);
1182 this->
set(n, sourceValue);
1186 template<
typename ValueType_,
typename Codec_>
1190 if (!mIsUniform)
return;
1195 tbb::spin_mutex::scoped_lock lock(mMutex);
1209 template<
typename ValueType_,
typename Codec_>
1213 if (mIsUniform)
return true;
1216 const ValueType_ val = this->
get(0);
1226 template<
typename ValueType_,
typename Codec_>
1230 this->
collapse(zeroVal<ValueType>());
1234 template<
typename ValueType_,
typename Codec_>
1239 tbb::spin_mutex::scoped_lock lock(mMutex);
1244 Codec::encode(uniformValue, mData.get()[0]);
1248 template<
typename ValueType_,
typename Codec_>
1256 template<
typename ValueType_,
typename Codec_>
1261 tbb::spin_mutex::scoped_lock lock(mMutex);
1268 Codec::encode(value, mData.get()[
i]);
1273 template<
typename ValueType_,
typename Codec_>
1281 template<
typename ValueType_,
typename Codec_>
1289 tbb::spin_mutex::scoped_lock lock(mMutex);
1291 this->doLoadUnsafe(
false);
1295 return this->compressUnsafe();
1302 template<
typename ValueType_,
typename Codec_>
1307 if (mIsUniform)
return false;
1312 const size_t inBytes = writeCompress ?
mCompressedBytes : this->arrayMemUsage();
1316 const char* charBuffer =
reinterpret_cast<const char*
>(mData.get());
1319 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1329 template<
typename ValueType_,
typename Codec_>
1333 tbb::spin_mutex::scoped_lock lock(mMutex);
1337 if (writeCompress) {
1338 this->doLoadUnsafe(
false);
1343 this->doLoadUnsafe();
1344 const char* charBuffer =
reinterpret_cast<const char*
>(this->mData.get());
1348 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1358 template<
typename ValueType_,
typename Codec_>
1366 template<
typename ValueType_,
typename Codec_>
1375 template<
typename ValueType_,
typename Codec_>
1386 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1387 this->doLoadUnsafe();
1391 template<
typename ValueType_,
typename Codec_>
1399 template<
typename ValueType_,
typename Codec_>
1408 template<
typename ValueType_,
typename Codec_>
1415 is.read(reinterpret_cast<char*>(&bytes),
sizeof(
Index64));
1416 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1418 uint8_t
flags = uint8_t(0);
1419 is.read(reinterpret_cast<char*>(&flags),
sizeof(uint8_t));
1422 uint8_t serializationFlags = uint8_t(0);
1423 is.read(reinterpret_cast<char*>(&serializationFlags),
sizeof(uint8_t));
1427 is.read(reinterpret_cast<char*>(&size),
sizeof(
Index));
1449 is.read(reinterpret_cast<char*>(&stride),
sizeof(
Index));
1450 mStrideOrTotalSize =
stride;
1453 mStrideOrTotalSize = 1;
1458 template<
typename ValueType_,
typename Codec_>
1467 tbb::spin_mutex::scoped_lock lock(mMutex);
1471 uint8_t bloscCompressed(0);
1472 if (!mIsUniform) is.read(reinterpret_cast<char*>(&bloscCompressed),
sizeof(uint8_t));
1479 mCompressedBytes =
Index64(0);
1483 mCompressedBytes =
Index64(0);
1488 if (bloscCompressed == uint8_t(1)) {
1494 if (newBuffer) buffer.reset(newBuffer.release());
1499 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1508 template<
typename ValueType_,
typename Codec_>
1520 const bool delayLoad = (mappedFile.get() !=
nullptr);
1530 tbb::spin_mutex::scoped_lock lock(mMutex);
1534 this->setOutOfCore(delayLoad);
1538 std::unique_ptr<char[]> buffer =
mPageHandle->read();
1539 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1559 template<
typename ValueType_,
typename Codec_>
1563 this->
write(os,
false);
1567 template<
typename ValueType_,
typename Codec_>
1576 template<
typename ValueType_,
typename Codec_>
1580 if (!outputTransient && this->
isTransient())
return;
1583 uint8_t serializationFlags(0);
1586 bool strideOfOne(this->
stride() == 1);
1591 if (bloscCompression || this->
isCompressed()) this->doLoad();
1593 size_t compressedBytes = 0;
1603 if (bloscCompression && paged) serializationFlags |=
WRITEPAGED;
1605 else if (bloscCompression && paged)
1610 const char* charBuffer =
reinterpret_cast<const char*
>(mData.get());
1619 else if (bloscCompression)
1621 const char* charBuffer =
reinterpret_cast<const char*
>(mData.get());
1622 const size_t inBytes = this->arrayMemUsage();
1628 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1632 os.write(reinterpret_cast<const char*>(&bytes),
sizeof(
Index64));
1633 os.write(reinterpret_cast<const char*>(&flags),
sizeof(uint8_t));
1634 os.write(reinterpret_cast<const char*>(&serializationFlags),
sizeof(uint8_t));
1635 os.write(reinterpret_cast<const char*>(&size),
sizeof(
Index));
1638 if (!strideOfOne) os.write(reinterpret_cast<const char*>(&stride),
sizeof(
Index));
1642 template<
typename ValueType_,
typename Codec_>
1646 if (!outputTransient && this->
isTransient())
return;
1651 os.write(reinterpret_cast<const char*>(mData.get()),
sizeof(
StorageType));
1655 uint8_t bloscCompressed(0);
1656 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1661 std::unique_ptr<char[]> compressedBuffer;
1662 size_t compressedBytes = 0;
1663 const char* charBuffer =
reinterpret_cast<const char*
>(mData.get());
1664 const size_t inBytes = this->arrayMemUsage();
1666 if (compressedBuffer) {
1667 uint8_t bloscCompressed(1);
1668 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1669 os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
1672 uint8_t bloscCompressed(0);
1673 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1674 os.write(reinterpret_cast<const char*>(mData.get()), inBytes);
1679 uint8_t bloscCompressed(0);
1680 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1681 os.write(reinterpret_cast<const char*>(mData.get()), this->arrayMemUsage());
1686 template<
typename ValueType_,
typename Codec_>
1690 if (!outputTransient && this->
isTransient())
return;
1694 if (!bloscCompression) {
1704 std::unique_ptr<char[]> uncompressedBuffer;
1708 const char* charBuffer =
reinterpret_cast<const char*
>(this->mData.get());
1711 buffer =
reinterpret_cast<const char*
>(uncompressedBuffer.get());
1714 buffer =
reinterpret_cast<const char*
>(mData.get());
1715 bytes = this->arrayMemUsage();
1718 os.
write(buffer, bytes);
1722 template<
typename ValueType_,
typename Codec_>
1732 assert(self->mPageHandle);
1734 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
1736 self->mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1738 self->mPageHandle.reset();
1743 if (compression)
self->compressUnsafe();
1744 else self->mCompressedBytes = 0;
1754 template<
typename ValueType_,
typename Codec_>
1769 template<
typename ValueType_,
typename Codec_>
1774 if(!otherT)
return false;
1775 if(this->mSize != otherT->mSize ||
1776 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1777 this->mIsUniform != otherT->mIsUniform ||
1778 *this->sTypeName != *otherT->sTypeName)
return false;
1783 const StorageType *target = this->mData.get(), *source = otherT->mData.get();
1784 if (!target && !source)
return true;
1785 if (!target || !source)
return false;
1786 Index n = this->mIsUniform ? 1 : mSize;
1795 template <
typename CodecType,
typename ValueType>
1816 template <
typename ValueType>
1824 return (*functor)(array, n);
1829 (*functor)(array, n, value);
1838 template <
typename ValueType,
typename CodecType>
1846 template <
typename ValueType,
typename CodecType>
1851 , mCollapseOnDestruction(preserveCompression && array.
isStreaming())
1853 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
1866 if (preserveCompression && !array.
isStreaming()) {
1868 mLocalArray->decompress();
1869 mArray = mLocalArray.get();
1883 mGetter = typedAccessor->
mGetter;
1884 mSetter = typedAccessor->
mSetter;
1886 mFiller = typedAccessor->
mFiller;
1889 template <
typename ValueType,
typename CodecType>
1893 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
1896 template <
typename ValueType,
typename CodecType>
1897 template <
bool IsUnknownCodec>
1898 typename std::enable_if<IsUnknownCodec, bool>::type
1903 return mArray->hasValueType<ValueType>();
1906 template <
typename ValueType,
typename CodecType>
1907 template <
bool IsUnknownCodec>
1908 typename std::enable_if<!IsUnknownCodec, bool>::type
1916 template <
typename ValueType,
typename CodecType>
1919 Index index = n * mStrideOrTotalSize + m;
1920 assert(index < (mSize * mStrideOrTotalSize));
1924 template <
typename ValueType,
typename CodecType>
1927 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
1930 template <
typename ValueType,
typename CodecType>
1931 template <
bool IsUnknownCodec>
1932 typename std::enable_if<IsUnknownCodec, ValueType>::type
1937 return (*mGetter)(mArray, index);
1940 template <
typename ValueType,
typename CodecType>
1941 template <
bool IsUnknownCodec>
1942 typename std::enable_if<!IsUnknownCodec, ValueType>::type
1950 template <
typename ValueType,
typename CodecType>
1956 template <
typename ValueType,
typename CodecType>
1966 template <
typename ValueType,
typename CodecType>
1974 template <
typename ValueType,
typename CodecType>
1978 if (expand) array.
expand();
1981 template <
typename ValueType,
typename CodecType>
1984 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
1987 template <
typename ValueType,
typename CodecType>
1990 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
1993 template <
typename ValueType,
typename CodecType>
1999 template <
typename ValueType,
typename CodecType>
2005 template <
typename ValueType,
typename CodecType>
2011 template <
typename ValueType,
typename CodecType>
2014 this->mCollapser(const_cast<AttributeArray*>(this->mArray), uniformValue);
2017 template <
typename ValueType,
typename CodecType>
2020 this->mFiller(const_cast<AttributeArray*>(this->mArray), value);
2023 template <
typename ValueType,
typename CodecType>
2024 template <
bool IsUnknownCodec>
2025 typename std::enable_if<IsUnknownCodec, void>::type
2030 (*this->mSetter)(const_cast<AttributeArray*>(this->mArray), index, value);
2033 template <
typename ValueType,
typename CodecType>
2034 template <
bool IsUnknownCodec>
2035 typename std::enable_if<!IsUnknownCodec, void>::type
2048 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED Definition: AttributeArray.h:363
ValueType_ ValueType
Definition: AttributeArray.h:443
AttributeArray::Ptr copy() const override
Return a copy of this attribute.
Definition: AttributeArray.h:1004
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:316
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:377
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:713
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:105
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:1799
bool sizeOnly() const
Definition: StreamCompression.h:236
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:233
Index stride() const override
Definition: AttributeArray.h:495
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.
TypedAttributeArray & operator=(const TypedAttributeArray &)
Deep copy assignment operator.
Definition: AttributeArray.h:908
OPENVDB_API void bloscDecompress(char *uncompressedBuffer, const size_t expectedBytes, const size_t bufferBytes, const char *compressedBuffer)
Decompress into the supplied buffer. Will throw if decompression fails or uncompressed buffer has ins...
Definition: AttributeArray.h:335
Definition: Compression.h:81
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:961
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:225
Definition: Exceptions.h:85
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:190
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1228
Definition: AttributeArray.h:122
ValuePtr mFiller
Definition: AttributeArray.h:678
uint16_t Type
Definition: AttributeArray.h:345
SetterPtr mSetter
Definition: AttributeArray.h:676
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:984
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:275
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1578
Flag
Definition: AttributeArray.h:127
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1211
Index stride() const
Definition: AttributeArray.h:662
uint16_t StorageType
Definition: AttributeArray.h:421
std::shared_ptr< PageHandle > Ptr
Definition: StreamCompression.h:197
T & z()
Definition: Vec3.h:111
void(*)(AttributeArray *array, const StringIndexType &value) ValuePtr
Definition: AttributeArray.h:650
StorageType Type
Definition: AttributeArray.h:424
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:318
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:391
Definition: AttributeArray.h:395
size_t mCompressedBytes
Definition: AttributeArray.h:296
Definition: AttributeArray.h:360
const AttributeArray * mArray
Definition: AttributeArray.h:673
tbb::atomic< Index32 > i
Definition: LeafBuffer.h:71
Definition: AttributeArray.h:407
OPENVDB_API size_t bloscUncompressedSize(const char *buffer)
Retrieves the uncompressed size of buffer when uncompressed.
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
compression::PageHandle::Ptr mPageHandle
used for out-of-core, paged reading
Definition: AttributeArray.h:301
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:239
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
AttributeArray::Ptr copyUncompressed() const override
Return an uncompressed copy of this attribute (will just return a copy if not compressed).
Definition: AttributeArray.h:1012
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...
SerializationFlag
Definition: AttributeArray.h:135
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:95
T * data
Definition: LeafBuffer.h:71
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:1796
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:491
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1393
Definition: AttributeArray.h:136
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:714
static void unregisterType(const NamePair &type)
Remove a attribute type from the registry.
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:407
Index32 Index
Definition: Types.h:57
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:389
bool isCompressed() const
Return true if this array is compressed.
Definition: AttributeArray.h:206
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:969
static bool isRegistered(const NamePair &type)
Return true if the given attribute type name is registered.
bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1283
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:309
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1401
virtual ~TypedAttributeArray()
Definition: AttributeArray.h:461
half Type
Definition: AttributeArray.h:336
ValueType getUnsafe(Index n) const
Return the value at index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1068
ValuePtr mCollapser
Definition: AttributeArray.h:325
std::istream & getInputStream()
Definition: StreamCompression.h:239
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes uncompressed and in-core)
Definition: AttributeArray.h:1120
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:1756
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:276
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:498
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:645
static Ptr create(const AttributeArray &array, const bool preserveCompression=true)
Definition: AttributeArray.h:1840
bool hasConstantStride() const
Definition: AttributeArray.h:1957
uint64_t Index64
Definition: Types.h:56
Convenience wrappers to using Blosc and reading and writing of Paged data.
uint8_t Type
Definition: AttributeArray.h:344
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:941
std::string Name
Definition: Name.h:44
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:317
#define OPENVDB_VERSION_NAME
Definition: version.h:43
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1569
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:535
int16_t Int16
Definition: Types.h:58
virtual AttributeArray::Ptr copyUncompressed() const =0
Return an uncompressed copy of this attribute (will return a copy if not compressed).
AttributeHandle(const AttributeArray &array, const bool preserveCompression=true)
Definition: AttributeArray.h:1847
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:279
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:262
StringIndexType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:648
Index size() const
Definition: AttributeArray.h:663
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:143
OPENVDB_API bool bloscCanCompress()
Returns true if compression is available.
Definition: AttributeArray.h:343
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:236
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1258
Definition: AttributeArray.h:377
bool sizeOnly() const
Definition: StreamCompression.h:273
Definition: Exceptions.h:39
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1688
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:487
Definition: AttributeArray.h:366
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:390
Definition: AttributeArray.h:424
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:109
Typed class for storing attribute data.
Definition: AttributeArray.h:437
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:124
T & y()
Definition: Vec3.h:110
short Type
Definition: AttributeArray.h:337
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:218
static const char * name()
Definition: AttributeArray.h:412
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
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:840
data is marked as uniform when written
Definition: AttributeArray.h:138
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1136
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1460
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:1820
GetterPtr mGetter
Definition: AttributeArray.h:675
uint8_t mSerializationFlags
Definition: AttributeArray.h:298
Definition: AttributeArray.h:640
Definition: Exceptions.h:92
SharedPtr< MappedFile > Ptr
Definition: io.h:152
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1082
static void registerType(const NamePair &type, FactoryMethod)
Register a attribute type along with a factory function.
void(*)(AttributeArray *array, const Index n, const StringIndexType &value) SetterPtr
Definition: AttributeArray.h:649
static const char * name()
Definition: AttributeArray.h:428
data is marked as compressed in-memory when written
Definition: AttributeArray.h:139
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1188
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:977
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:1819
ValuePtr mCollapser
Definition: AttributeArray.h:677
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:644
Ptr(*)(Index, Index, bool) FactoryMethod
Definition: AttributeArray.h:145
static const char * name()
Definition: AttributeArray.h:397
Base class for storing attribute data.
Definition: AttributeArray.h:118
SetterPtr mSetter
Definition: AttributeArray.h:324
uint8_t mFlags
Definition: AttributeArray.h:297
bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1331
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1510
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1360
Definition: Exceptions.h:84
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:481
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
Definition: Exceptions.h:91
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:1798
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:399
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:225
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:953
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
data is marked as strided when written
Definition: AttributeArray.h:137
Definition: AttributeArray.h:386
Definition: AttributeArray.h:374
T Type
Definition: AttributeArray.h:366
bool isUniform() const
Definition: AttributeArray.h:1951
Definition: AttributeArray.h:404
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:186
static const char * name()
Definition: AttributeArray.h:370
static constexpr size_t size
The size of a LeafBuffer when LeafBuffer::mOutOfCore is atomic.
Definition: LeafBuffer.h:85
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:398
static const char * name()
Definition: AttributeArray.h:388
ValuePtr mFiller
Definition: AttributeArray.h:326
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1060
Definition: AttributeArray.h:419
hidden from UIs or iterators
Definition: AttributeArray.h:130
Codec_ Codec
Definition: AttributeArray.h:444
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:320
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:445
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:440
Write-able version of AttributeHandle.
Definition: AttributeArray.h:709
static const char * name()
Definition: AttributeArray.h:381
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1410
GetterPtr mGetter
Definition: AttributeArray.h:323
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1644
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.