10 #ifndef OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED 11 #define OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED 23 #include <tbb/spin_mutex.h> 29 #include <type_traits> 32 class TestAttributeArray;
48 template <
typename IntegerT,
typename FloatT>
59 template <
typename FloatT,
typename IntegerT>
67 template <
typename IntegerVectorT,
typename FloatT>
71 return IntegerVectorT(
72 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
x()),
73 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
y()),
74 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
z()));
77 template <
typename FloatVectorT,
typename IntegerT>
82 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
x()),
83 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
y()),
84 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
z()));
104 CONSTANTSTRIDE = 0x8,
112 WRITEMEMCOMPRESS = 0x4,
120 tbb::spin_mutex::scoped_lock lock;
125 using Ptr = std::shared_ptr<AttributeArray>;
126 using ConstPtr = std::shared_ptr<const AttributeArray>;
137 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
155 virtual Index size()
const = 0;
159 virtual Index stride()
const = 0;
163 virtual Index dataSize()
const = 0;
166 virtual Name valueType()
const = 0;
169 virtual Name codecType()
const = 0;
173 virtual Index valueTypeSize()
const = 0;
177 virtual Index storageTypeSize()
const = 0;
180 virtual bool valueTypeIsFloatingPoint()
const = 0;
183 virtual bool valueTypeIsClass()
const = 0;
186 virtual bool valueTypeIsVector()
const = 0;
189 virtual bool valueTypeIsQuaternion()
const = 0;
192 virtual bool valueTypeIsMatrix()
const = 0;
195 virtual size_t memUsage()
const = 0;
200 static Ptr create(
const NamePair& type, Index length, Index stride = 1,
201 bool constantStride =
true,
211 virtual const NamePair& type()
const = 0;
213 template<
typename AttributeArrayType>
214 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
217 template<
typename ValueType>
218 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
225 virtual void set(
const Index n,
const AttributeArray& sourceArray,
const Index sourceIndex) = 0;
250 template<
typename IterT>
251 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
255 template<
typename IterT>
256 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
259 virtual bool isUniform()
const = 0;
262 virtual void expand(
bool fill =
true) = 0;
264 virtual void collapse() = 0;
266 virtual bool compact() = 0;
272 virtual bool compress() = 0;
277 virtual bool decompress() = 0;
283 void setHidden(
bool state);
285 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
290 void setTransient(
bool state);
298 void setStreaming(
bool state);
306 uint8_t
flags()
const {
return mFlags; }
309 virtual void read(std::istream&) = 0;
312 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
314 virtual void write(std::ostream&)
const = 0;
317 virtual void readMetadata(std::istream&) = 0;
321 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
324 virtual void readBuffers(std::istream&) = 0;
327 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
336 virtual void loadData()
const = 0;
339 virtual bool isDataLoaded()
const = 0;
347 #if OPENVDB_ABI_VERSION_NUMBER >= 9 353 friend class ::TestAttributeArray;
360 virtual char* dataAsByteArray() = 0;
361 virtual const char* dataAsByteArray()
const = 0;
364 template <
typename IterT>
365 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
366 bool rangeChecking =
true);
369 #if OPENVDB_ABI_VERSION_NUMBER >= 7 374 void setConstantStride(
bool state);
383 static void unregisterType(
const NamePair& type,
386 bool mIsUniform =
true;
389 uint8_t mUsePagedRead = 0;
407 template <
typename T>
415 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
427 namespace attribute_traits
459 template <
typename T>
462 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
463 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
464 static const char*
name() {
return "null"; }
470 template <
typename T>
473 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
474 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
475 static const char*
name() {
return "trnc"; }
482 static const char*
name() {
return "fxpt"; }
483 template <
typename ValueType>
static ValueType
encode(
const ValueType&
value) {
return value + ValueType(0.5); }
484 template <
typename ValueType>
static ValueType
decode(
const ValueType&
value) {
return value - ValueType(0.5); }
491 static const char*
name() {
return "ufxpt"; }
492 template <
typename ValueType>
static ValueType
encode(
const ValueType&
value) {
return value; }
493 template <
typename ValueType>
static ValueType
decode(
const ValueType&
value) {
return value; }
497 template <
bool OneByte,
typename Range=PositionRange>
500 template <
typename T>
503 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
504 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
507 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
517 template <
typename T>
522 static const char*
name() {
return "uvec"; }
531 template<
typename ValueType_,
typename Codec_ = NullCodec>
535 using Ptr = std::shared_ptr<TypedAttributeArray>;
536 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
540 using StorageType =
typename Codec::template Storage<ValueType>::Type;
546 const ValueType& uniformValue = zeroVal<ValueType>());
547 #if OPENVDB_ABI_VERSION_NUMBER >= 7 562 TypedAttributeArray(
const TypedAttributeArray&,
bool uncompress =
false);
566 TypedAttributeArray& operator=(
const TypedAttributeArray&);
568 TypedAttributeArray(TypedAttributeArray&&) =
delete;
570 TypedAttributeArray& operator=(TypedAttributeArray&&) =
delete;
584 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true,
585 const Metadata* metadata =
nullptr);
591 static const TypedAttributeArray& cast(
const AttributeArray& attributeArray);
594 static const NamePair& attributeType();
599 static bool isRegistered();
601 static void registerType();
603 static void unregisterType();
610 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
614 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
631 bool valueTypeIsFloatingPoint()
const override;
634 bool valueTypeIsClass()
const override;
637 bool valueTypeIsVector()
const override;
640 bool valueTypeIsQuaternion()
const override;
643 bool valueTypeIsMatrix()
const override;
653 template<
typename T>
void getUnsafe(
Index n, T&
value)
const;
655 template<
typename T>
void get(
Index n, T&
value)
const;
666 template<
typename T>
void setUnsafe(
Index n,
const T& value);
668 template<
typename T>
void set(
Index n,
const T&
value);
683 void expand(
bool fill =
true)
override;
685 void collapse()
override;
687 bool compact()
override;
690 void collapse(
const ValueType& uniformValue);
702 bool compress()
override;
705 bool decompress()
override;
708 void read(std::istream&)
override;
712 void write(std::ostream& os,
bool outputTransient)
const override;
714 void write(std::ostream&)
const override;
717 void readMetadata(std::istream&)
override;
722 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
725 void readBuffers(std::istream&)
override;
729 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
739 inline bool isOutOfCore()
const;
742 void loadData()
const override;
745 bool isDataLoaded()
const override;
747 #if OPENVDB_ABI_VERSION_NUMBER >= 9 760 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
763 friend class ::TestAttributeArray;
765 #if OPENVDB_ABI_VERSION_NUMBER >= 7 766 TypedAttributeArray(
const TypedAttributeArray&,
const tbb::spin_mutex::scoped_lock&);
770 inline void doLoad()
const;
773 inline void doLoadUnsafe(
const bool compression =
true)
const;
775 inline bool compressUnsafe();
778 inline void setOutOfCore(
const bool);
784 char* dataAsByteArray()
override;
785 const char* dataAsByteArray()
const override;
787 size_t arrayMemUsage()
const;
794 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride, metadata);
797 static std::unique_ptr<const NamePair> sTypeName;
798 std::unique_ptr<StorageType[]> mData;
800 Index mStrideOrTotalSize;
809 template <
typename ValueType,
typename CodecType = UnknownCodec>
814 using Ptr = std::shared_ptr<Handle>;
823 static Ptr create(
const AttributeArray& array,
const bool collapseOnDestruction =
true);
835 bool isUniform()
const;
836 bool hasConstantStride()
const;
853 friend class ::TestAttributeArray;
855 template <
bool IsUnknownCodec>
856 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
858 template <
bool IsUnknownCodec>
859 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
861 template <
bool IsUnknownCodec>
862 typename std::enable_if<IsUnknownCodec, ValueType>::type
get(
Index index)
const;
864 template <
bool IsUnknownCodec>
865 typename std::enable_if<!IsUnknownCodec, ValueType>::type
get(
Index index)
const;
870 Index mStrideOrTotalSize;
872 bool mCollapseOnDestruction;
880 template <
typename ValueType,
typename CodecType = UnknownCodec>
885 using Ptr = std::shared_ptr<Handle>;
896 void expand(
bool fill =
true);
900 void collapse(
const ValueType& uniformValue);
907 void fill(
const ValueType&
value);
915 friend class ::TestAttributeArray;
917 template <
bool IsUnknownCodec>
918 typename std::enable_if<IsUnknownCodec, void>::type
set(
Index index,
const ValueType&
value)
const;
920 template <
bool IsUnknownCodec>
921 typename std::enable_if<!IsUnknownCodec, void>::type
set(
Index index,
const ValueType&
value)
const;
931 template<
typename ValueType>
933 NullCodec::decode(
const ValueType& data, ValueType& val)
939 template<
typename ValueType>
941 NullCodec::encode(
const ValueType& val, ValueType& data)
947 template<
typename StorageType,
typename ValueType>
949 TruncateCodec::decode(
const StorageType& data, ValueType& val)
951 val =
static_cast<ValueType
>(data);
955 template<
typename StorageType,
typename ValueType>
957 TruncateCodec::encode(
const ValueType& val, StorageType& data)
959 data =
static_cast<StorageType
>(val);
963 template <
bool OneByte,
typename Range>
964 template<
typename StorageType,
typename ValueType>
968 val = fixedPointToFloatingPoint<ValueType>(data);
972 val = Range::template decode<ValueType>(val);
976 template <
bool OneByte,
typename Range>
977 template<
typename StorageType,
typename ValueType>
983 const ValueType newVal = Range::template encode<ValueType>(val);
985 data = floatingPointToFixedPoint<StorageType>(newVal);
993 val = math::QuantizedUnitVec::unpack(data);
1001 data = math::QuantizedUnitVec::pack(val);
1009 template <
typename IterT>
1010 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1016 assert(sourceArray.
isDataLoaded() && this->isDataLoaded());
1018 assert(this->storageTypeSize()*this->stride() ==
1022 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
1023 char*
const targetBuffer = this->dataAsByteArray();
1024 assert(sourceBuffer && targetBuffer);
1026 if (rangeChecking && this->isUniform()) {
1030 const bool sourceIsUniform = sourceArray.
isUniform();
1032 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
1033 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1035 for (IterT it(iter); it; ++it) {
1036 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1037 const Index targetIndex = it.targetIndex();
1039 if (rangeChecking) {
1040 if (sourceIndex >= sourceDataSize) {
1042 "Cannot copy array data as source index exceeds size of source array.");
1044 if (targetIndex >= targetDataSize) {
1046 "Cannot copy array data as target index exceeds size of target array.");
1050 assert(sourceIndex < sourceArray.
dataSize());
1051 assert(targetIndex < this->dataSize());
1052 if (this->isUniform()) assert(targetIndex ==
Index(0));
1055 const size_t targetOffset(targetIndex * bytes);
1056 const size_t sourceOffset(sourceIndex * bytes);
1058 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1062 template <
typename IterT>
1063 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1065 this->doCopyValues(sourceArray, iter,
false);
1068 template <
typename IterT>
1069 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1073 if (bytes != this->storageTypeSize()) {
1090 this->doCopyValues(sourceArray, iter,
true);
1103 template<
typename ValueType_,
typename Codec_>
1107 template<
typename ValueType_,
typename Codec_>
1113 , mStrideOrTotalSize(strideOrTotalSize)
1115 if (constantStride) {
1117 if (strideOrTotalSize == 0) {
1119 "stride to be at least one.")
1124 if (mStrideOrTotalSize < n) {
1126 "a total size of at least the number of elements in the array.")
1130 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1131 Codec::encode(uniformValue, this->
data()[0]);
1135 #if OPENVDB_ABI_VERSION_NUMBER >= 7 1136 template<
typename ValueType_,
typename Codec_>
1143 template<
typename ValueType_,
typename Codec_>
1145 const tbb::spin_mutex::scoped_lock& lock)
1148 template<
typename ValueType_,
typename Codec_>
1153 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1157 std::memcpy(static_cast<void*>(this->
data()), rhs.
data(), this->arrayMemUsage());
1162 template<
typename ValueType_,
typename Codec_>
1168 tbb::spin_mutex::scoped_lock lock(
mMutex);
1169 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1176 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1181 std::memcpy(static_cast<void*>(this->
data()), rhs.
data(), this->arrayMemUsage());
1189 template<
typename ValueType_,
typename Codec_>
1193 static std::once_flag once;
1194 std::call_once(once, []()
1196 sTypeName.reset(
new NamePair(typeNameAsString<ValueType>(), Codec::name()));
1202 template<
typename ValueType_,
typename Codec_>
1210 template<
typename ValueType_,
typename Codec_>
1218 template<
typename ValueType_,
typename Codec_>
1226 template<
typename ValueType_,
typename Codec_>
1235 typedMetadata ? typedMetadata->
value() : zeroVal<ValueType>()));
1238 template<
typename ValueType_,
typename Codec_>
1248 template<
typename ValueType_,
typename Codec_>
1258 template<
typename ValueType_,
typename Codec_>
1262 #if OPENVDB_ABI_VERSION_NUMBER < 7 1263 tbb::spin_mutex::scoped_lock lock(
mMutex);
1269 template<
typename ValueType_,
typename Codec_>
1273 return this->
copy();
1277 template<
typename ValueType_,
typename Codec_>
1287 template<
typename ValueType_,
typename Codec_>
1303 template<
typename ValueType_,
typename Codec_>
1309 this->setOutOfCore(
false);
1312 if (mData) mData.reset();
1316 template<
typename ValueType_,
typename Codec_>
1336 template<
typename ValueType_,
typename Codec_>
1345 template<
typename ValueType_,
typename Codec_>
1353 template<
typename ValueType_,
typename Codec_>
1358 return !this->
valueType().compare(0, 4,
"quat");
1362 template<
typename ValueType_,
typename Codec_>
1367 return !this->
valueType().compare(0, 3,
"mat");
1371 template<
typename ValueType_,
typename Codec_>
1375 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1379 template<
typename ValueType_,
typename Codec_>
1391 template<
typename ValueType_,
typename Codec_>
1402 template<
typename ValueType_,
typename Codec_>
1403 template<
typename T>
1407 val =
static_cast<T
>(this->
getUnsafe(n));
1411 template<
typename ValueType_,
typename Codec_>
1412 template<
typename T>
1416 val =
static_cast<T
>(this->
get(n));
1420 template<
typename ValueType_,
typename Codec_>
1428 template<
typename ValueType_,
typename Codec_>
1443 template<
typename ValueType_,
typename Codec_>
1455 template<
typename ValueType_,
typename Codec_>
1456 template<
typename T>
1460 this->
setUnsafe(n, static_cast<ValueType>(val));
1464 template<
typename ValueType_,
typename Codec_>
1465 template<
typename T>
1469 this->
set(n,
static_cast<ValueType>(val));
1473 template<
typename ValueType_,
typename Codec_>
1481 template<
typename ValueType_,
typename Codec_>
1488 sourceTypedArray.
get(sourceIndex, sourceValue);
1490 this->
set(n, sourceValue);
1494 template<
typename ValueType_,
typename Codec_>
1503 tbb::spin_mutex::scoped_lock lock(
mMutex);
1515 template<
typename ValueType_,
typename Codec_>
1522 const ValueType_ val = this->
get(0);
1532 template<
typename ValueType_,
typename Codec_>
1536 this->
collapse(zeroVal<ValueType>());
1540 template<
typename ValueType_,
typename Codec_>
1545 tbb::spin_mutex::scoped_lock lock(
mMutex);
1550 Codec::encode(uniformValue, this->
data()[0]);
1554 template<
typename ValueType_,
typename Codec_>
1562 template<
typename ValueType_,
typename Codec_>
1567 tbb::spin_mutex::scoped_lock lock(
mMutex);
1574 Codec::encode(value, this->
data()[i]);
1579 template<
typename ValueType_,
typename Codec_>
1587 template<
typename ValueType_,
typename Codec_>
1595 template<
typename ValueType_,
typename Codec_>
1603 template<
typename ValueType_,
typename Codec_>
1611 template<
typename ValueType_,
typename Codec_>
1619 template<
typename ValueType_,
typename Codec_>
1627 template<
typename ValueType_,
typename Codec_>
1638 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1639 this->doLoadUnsafe();
1643 template<
typename ValueType_,
typename Codec_>
1651 template<
typename ValueType_,
typename Codec_>
1659 template<
typename ValueType_,
typename Codec_>
1668 template<
typename ValueType_,
typename Codec_>
1675 is.read(reinterpret_cast<char*>(&bytes),
sizeof(
Index64));
1676 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1678 uint8_t
flags = uint8_t(0);
1679 is.read(reinterpret_cast<char*>(&flags),
sizeof(uint8_t));
1682 uint8_t serializationFlags = uint8_t(0);
1683 is.read(reinterpret_cast<char*>(&serializationFlags),
sizeof(uint8_t));
1686 is.read(reinterpret_cast<char*>(&size),
sizeof(
Index));
1695 if (serializationFlags >= 0x10) {
1710 is.read(reinterpret_cast<char*>(&stride),
sizeof(
Index));
1711 mStrideOrTotalSize =
stride;
1714 mStrideOrTotalSize = 1;
1719 template<
typename ValueType_,
typename Codec_>
1728 tbb::spin_mutex::scoped_lock lock(
mMutex);
1732 uint8_t bloscCompressed(0);
1733 if (!
mIsUniform) is.read(reinterpret_cast<char*>(&bloscCompressed),
sizeof(uint8_t));
1738 mCompressedBytes = 0;
1743 if (bloscCompressed == uint8_t(1)) {
1749 if (newBuffer) buffer.reset(newBuffer.release());
1754 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1758 template<
typename ValueType_,
typename Codec_>
1770 const bool delayLoad = (mappedFile.get() !=
nullptr);
1784 tbb::spin_mutex::scoped_lock lock(
mMutex);
1788 this->setOutOfCore(delayLoad);
1792 std::unique_ptr<char[]> buffer =
mPageHandle->read();
1793 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1803 template<
typename ValueType_,
typename Codec_>
1807 this->
write(os,
false);
1811 template<
typename ValueType_,
typename Codec_>
1820 template<
typename ValueType_,
typename Codec_>
1824 if (!outputTransient && this->
isTransient())
return;
1831 uint8_t serializationFlags(0);
1834 bool strideOfOne(this->
stride() == 1);
1839 if (bloscCompression) this->doLoad();
1841 size_t compressedBytes = 0;
1851 if (bloscCompression && paged) serializationFlags |=
WRITEPAGED;
1853 else if (bloscCompression)
1857 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1858 const size_t inBytes = this->arrayMemUsage();
1865 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1869 os.write(reinterpret_cast<const char*>(&bytes),
sizeof(
Index64));
1870 os.write(reinterpret_cast<const char*>(&flags),
sizeof(uint8_t));
1871 os.write(reinterpret_cast<const char*>(&serializationFlags),
sizeof(uint8_t));
1872 os.write(reinterpret_cast<const char*>(&size),
sizeof(
Index));
1875 if (!strideOfOne) os.write(reinterpret_cast<const char*>(&stride),
sizeof(
Index));
1879 template<
typename ValueType_,
typename Codec_>
1883 if (!outputTransient && this->
isTransient())
return;
1892 os.write(reinterpret_cast<const char*>(this->
data()),
sizeof(
StorageType));
1896 std::unique_ptr<char[]> compressedBuffer;
1897 size_t compressedBytes = 0;
1898 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1899 const size_t inBytes = this->arrayMemUsage();
1901 if (compressedBuffer) {
1902 uint8_t bloscCompressed(1);
1903 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1904 os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
1907 uint8_t bloscCompressed(0);
1908 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1909 os.write(reinterpret_cast<const char*>(this->
data()), inBytes);
1914 uint8_t bloscCompressed(0);
1915 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1916 os.write(reinterpret_cast<const char*>(this->
data()), this->arrayMemUsage());
1921 template<
typename ValueType_,
typename Codec_>
1925 if (!outputTransient && this->
isTransient())
return;
1929 if (!bloscCompression) {
1940 os.
write(reinterpret_cast<const char*>(this->
data()), this->arrayMemUsage());
1944 template<
typename ValueType_,
typename Codec_>
1954 assert(self->mPageHandle);
1957 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
1959 self->mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1961 self->mPageHandle.reset();
1965 self->mOutOfCore =
false;
1969 template<
typename ValueType_,
typename Codec_>
1984 template<
typename ValueType_,
typename Codec_>
1989 if(!otherT)
return false;
1990 if(this->mSize != otherT->mSize ||
1991 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1993 this->attributeType() != this->
attributeType())
return false;
1999 if (!target && !source)
return true;
2000 if (!target || !source)
return false;
2007 template<
typename ValueType_,
typename Codec_>
2011 return reinterpret_cast<char*
>(this->
data());
2015 template<
typename ValueType_,
typename Codec_>
2019 return reinterpret_cast<const char*
>(this->
data());
2027 template <
typename CodecType,
typename ValueType>
2048 template <
typename ValueType>
2056 return (*functor)(array, n);
2061 (*functor)(array, n,
value);
2070 template <
typename ValueType,
typename CodecType>
2078 template <
typename ValueType,
typename CodecType>
2083 , mCollapseOnDestruction(collapseOnDestruction && array.
isStreaming())
2106 template <
typename ValueType,
typename CodecType>
2113 template <
typename ValueType,
typename CodecType>
2114 template <
bool IsUnknownCodec>
2115 typename std::enable_if<IsUnknownCodec, bool>::type
2123 template <
typename ValueType,
typename CodecType>
2124 template <
bool IsUnknownCodec>
2125 typename std::enable_if<!IsUnknownCodec, bool>::type
2133 template <
typename ValueType,
typename CodecType>
2140 template <
typename ValueType,
typename CodecType>
2144 assert(index < (mSize * mStrideOrTotalSize));
2148 template <
typename ValueType,
typename CodecType>
2154 template <
typename ValueType,
typename CodecType>
2155 template <
bool IsUnknownCodec>
2156 typename std::enable_if<IsUnknownCodec, ValueType>::type
2164 template <
typename ValueType,
typename CodecType>
2165 template <
bool IsUnknownCodec>
2166 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2174 template <
typename ValueType,
typename CodecType>
2180 template <
typename ValueType,
typename CodecType>
2190 template <
typename ValueType,
typename CodecType>
2198 template <
typename ValueType,
typename CodecType>
2202 if (expand) array.
expand();
2205 template <
typename ValueType,
typename CodecType>
2211 template <
typename ValueType,
typename CodecType>
2217 template <
typename ValueType,
typename CodecType>
2223 template <
typename ValueType,
typename CodecType>
2229 template <
typename ValueType,
typename CodecType>
2235 template <
typename ValueType,
typename CodecType>
2241 template <
typename ValueType,
typename CodecType>
2244 this->
mFiller(const_cast<AttributeArray*>(this->
mArray), value);
2247 template <
typename ValueType,
typename CodecType>
2248 template <
bool IsUnknownCodec>
2249 typename std::enable_if<IsUnknownCodec, void>::type
2257 template <
typename ValueType,
typename CodecType>
2258 template <
bool IsUnknownCodec>
2259 typename std::enable_if<!IsUnknownCodec, void>::type
2267 template <
typename ValueType,
typename CodecType>
2279 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:98
SetterPtr mSetter
Definition: AttributeArray.h:418
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:815
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2030
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
bool mIsUniform
Definition: AttributeArray.h:386
short Type
Definition: AttributeArray.h:431
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t *poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
Definition: pnanovdb_validate_strides.h:20
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1881
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:444
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:345
bool isUniform() const
Definition: AttributeArray.h:2175
static Ptr create(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2192
Definition: AttributeArray.h:489
StorageType Type
Definition: AttributeArray.h:518
streaming mode collapses attributes when first accessed
Definition: AttributeArray.h:106
static const char * name()
Definition: AttributeArray.h:491
bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1589
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:69
Definition: AttributeArray.h:468
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:292
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:126
Definition: AttributeArray.h:454
tbb::spin_mutex mMutex
Definition: AttributeArray.h:387
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true) ...
Definition: AttributeArray.h:1338
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1373
static const char * name()
Definition: AttributeArray.h:506
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:613
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
static Ptr create(Index n, Index strideOrTotalSize=1, bool constantStride=true, const Metadata *metadata=nullptr)
Return a new attribute array of the given length n and stride with uniform value zero.
Definition: AttributeArray.h:1228
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1661
OPENVDB_API void bloscDecompress(char *uncompressedBuffer, const size_t expectedBytes, const size_t bufferBytes, const char *compressedBuffer)
Decompress into the supplied buffer. Will throw if decompression fails or uncompressed buffer has ins...
virtual Index stride() const =0
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1355
ValuePtr mFiller
Definition: AttributeArray.h:850
ValuePtr mCollapser
Definition: AttributeArray.h:419
Definition: AttributeArray.h:110
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:300
Definition: AttributeArray.h:114
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:204
T & z()
Definition: Vec3.h:91
Definition: AttributeArray.h:460
size_t mCompressedBytes
Definition: AttributeArray.h:394
virtual ~AttributeHandle()
Definition: AttributeArray.h:2107
SharedPtr< MappedFile > Ptr
Definition: io.h:136
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2051
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:90
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:255
AttributeArray::Ptr copyUncompressed() const override
Definition: AttributeArray.h:1271
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition: AttributeArray.h:1430
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1318
const AttributeArray * mArray
Definition: AttributeArray.h:845
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:403
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2218
static const char * name()
Definition: AttributeArray.h:475
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1534
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2031
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2028
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1613
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1191
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:483
Definition: Exceptions.h:65
bool sizeOnly() const
Definition: StreamCompression.h:252
Base class for storing attribute data.
Definition: AttributeArray.h:92
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:492
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:303
static fileSize_t write(std::ostream &os, const GridHandle< BufferT > &handle, Codec codec)
Definition: AttributeArray.h:118
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1212
SetterPtr mSetter
Definition: AttributeArray.h:848
GetterPtr mGetter
Definition: AttributeArray.h:847
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:760
virtual Index storageTypeSize() const =0
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2230
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:412
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:2242
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
data is marked as strided when written
Definition: AttributeArray.h:111
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:756
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1813
static const char * name()
Definition: AttributeArray.h:522
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:411
static void read(std::istream &is, GridHandle< BufferT > &handle, Codec codec)
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:241
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1564
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
typename T::ValueType ElementType
Definition: Types.h:208
GetterPtr mGetter
Definition: AttributeArray.h:417
Convenience wrappers to using Blosc and reading and writing of Paged data.
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:814
SerializationFlag
Definition: AttributeArray.h:109
virtual Index dataSize() const =0
uint16_t StorageType
Definition: AttributeArray.h:515
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1204
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:501
Index stride() const
Definition: AttributeArray.h:832
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1496
virtual ~AttributeArray()
Definition: AttributeArray.h:133
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1260
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition: AttributeArray.h:1381
std::string Name
Definition: Name.h:17
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:410
AttributeArray()
Definition: AttributeArray.h:132
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition: AttributeArray.h:128
void set(Index n, const ValueType &value)
Definition: AttributeArray.h:2206
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1220
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1240
Flag
Definition: AttributeArray.h:101
uint8_t Type
Definition: AttributeArray.h:438
const AttributeArray & array() const
Definition: AttributeArray.h:2134
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
int16_t Int16
Definition: Types.h:55
ValueType_ ValueType
Definition: AttributeArray.h:538
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:285
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1645
uint64_t Index64
Definition: Types.h:53
Index stride() const override
Definition: AttributeArray.h:610
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:214
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:885
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:606
Index(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:818
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:1971
std::istream & getInputStream()
Definition: StreamCompression.h:218
Definition: Exceptions.h:13
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:414
std::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:390
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:1108
Index storageTypeSize() const override
Definition: AttributeArray.h:628
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2052
ValueT value
Definition: GridBuilder.h:1287
Definition: AttributeArray.h:518
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:393
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:886
Name valueType() const override
Return the name of the value type of a single element in this array (e.g., "float" or "vec3d")...
Definition: AttributeArray.h:618
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1721
virtual void loadData() const =0
Ensures all data is in-core.
Index32 Index
Definition: Types.h:54
Definition: AttributeArray.h:513
const char * constDataAsByteArray() const
Indirect virtual function to retrieve the data buffer cast to a char byte array.
Definition: AttributeArray.h:349
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1923
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:621
Definition: Compression.h:56
bool sizeOnly() const
Definition: StreamCompression.h:215
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:679
uint8_t mUsePagedRead
Definition: AttributeArray.h:389
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1393
bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1605
Index size() const
Definition: AttributeArray.h:833
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1760
Write-able version of AttributeHandle.
Definition: AttributeArray.h:881
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1822
Definition: AttributeArray.h:457
uint16_t Type
Definition: AttributeArray.h:439
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:218
Definition: AttributeArray.h:480
void(*)(AttributeArray *array, const Index n, const Index &value) SetterPtr
Definition: AttributeArray.h:819
Definition: AttributeArray.h:437
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:89
Codec_ Codec
Definition: AttributeArray.h:539
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1670
Definition: AttributeArray.h:498
AttributeArray & array()
Definition: AttributeArray.h:2268
uint8_t mFlags
Definition: AttributeArray.h:388
Definition: AttributeArray.h:810
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1653
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1347
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1164
Definition: AttributeArray.h:96
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2199
Definition: Exceptions.h:64
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:256
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
Definition: AttributeArray.h:501
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:540
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:535
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:493
const StorageType * constData() const
Return the raw data buffer.
Definition: AttributeArray.h:749
void(*)(AttributeArray *array, const Index &value) ValuePtr
Definition: AttributeArray.h:820
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:596
Definition: AttributeArray.h:429
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:306
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.
Definition: Exceptions.h:58
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:170
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1517
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:471
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2079
static const char * name()
Definition: AttributeArray.h:482
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:79
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:624
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:477
Typed class for storing attribute data.
Definition: AttributeArray.h:532
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1364
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1445
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:484
ValuePtr mCollapser
Definition: AttributeArray.h:849
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2224
internal::half half
Definition: Types.h:29
static const char * name()
Definition: AttributeArray.h:464
Definition: AttributeArray.h:471
Definition: Exceptions.h:57
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2072
~TypedAttributeArray() override
Definition: AttributeArray.h:572
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202
bool hasConstantStride() const
Definition: AttributeArray.h:2181
ValuePtr mFiller
Definition: AttributeArray.h:420
const StorageType * data() const
Definition: AttributeArray.h:757
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.
T Type
Definition: AttributeArray.h:460
ValueType get(Index n, Index m=0) const
Definition: AttributeArray.h:2149
Index index(Index n, Index m) const
Definition: AttributeArray.h:2141