10 #ifndef OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED 11 #define OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED 24 #include <tbb/spin_mutex.h> 30 #include <type_traits> 33 class TestAttributeArray;
49 template <
typename IntegerT,
typename FloatT>
53 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
60 template <
typename FloatT,
typename IntegerT>
64 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
68 template <
typename IntegerVectorT,
typename FloatT>
72 return IntegerVectorT(
73 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
x()),
74 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
y()),
75 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.
z()));
78 template <
typename FloatVectorT,
typename IntegerT>
83 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
x()),
84 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
y()),
85 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.
z()));
105 CONSTANTSTRIDE = 0x8,
113 WRITEMEMCOMPRESS = 0x4,
121 tbb::spin_mutex::scoped_lock lock;
126 using Ptr = std::shared_ptr<AttributeArray>;
127 using ConstPtr = std::shared_ptr<const AttributeArray>;
138 if (mFlags & PARTIALREAD) mCompressedBytes = 0;
150 virtual Index size()
const = 0;
154 virtual Index stride()
const = 0;
158 virtual Index dataSize()
const = 0;
161 virtual Name valueType()
const = 0;
164 virtual Name codecType()
const = 0;
168 virtual Index valueTypeSize()
const = 0;
172 virtual Index storageTypeSize()
const = 0;
175 virtual bool valueTypeIsFloatingPoint()
const = 0;
178 virtual bool valueTypeIsClass()
const = 0;
181 virtual bool valueTypeIsVector()
const = 0;
184 virtual bool valueTypeIsQuaternion()
const = 0;
187 virtual bool valueTypeIsMatrix()
const = 0;
190 virtual size_t memUsage()
const = 0;
201 static Ptr create(
const NamePair& type, Index length, Index stride = 1,
202 bool constantStride =
true,
212 virtual const NamePair& type()
const = 0;
214 template<
typename AttributeArrayType>
215 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
218 template<
typename ValueType>
219 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
244 template<
typename IterT>
245 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
249 template<
typename IterT>
250 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
253 virtual bool isUniform()
const = 0;
256 virtual void expand(
bool fill =
true) = 0;
258 virtual void collapse() = 0;
260 virtual bool compact() = 0;
266 void setHidden(
bool state);
273 void setTransient(
bool state);
281 void setStreaming(
bool state);
289 uint8_t
flags()
const {
return mFlags; }
292 virtual void read(std::istream&) = 0;
295 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
297 virtual void write(std::ostream&)
const = 0;
300 virtual void readMetadata(std::istream&) = 0;
304 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
307 virtual void readBuffers(std::istream&) = 0;
310 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
319 virtual void loadData()
const = 0;
322 virtual bool isDataLoaded()
const = 0;
334 friend class ::TestAttributeArray;
341 virtual char* dataAsByteArray() = 0;
342 virtual const char* dataAsByteArray()
const = 0;
345 template <
typename IterT>
346 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
347 bool rangeChecking =
true);
353 void setConstantStride(
bool state);
362 static void unregisterType(
const NamePair& type,
365 bool mIsUniform =
true;
368 uint8_t mUsePagedRead = 0;
386 template <
typename T>
394 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
406 namespace attribute_traits
438 template <
typename T>
441 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
442 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
443 static const char*
name() {
return "null"; }
449 template <
typename T>
452 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
453 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
454 static const char*
name() {
return "trnc"; }
461 static const char*
name() {
return "fxpt"; }
462 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
463 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
470 static const char*
name() {
return "ufxpt"; }
471 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
472 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
476 template <
bool OneByte,
typename Range=PositionRange>
479 template <
typename T>
482 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
483 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
486 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
496 template <
typename T>
501 static const char*
name() {
return "uvec"; }
510 template<
typename ValueType_,
typename Codec_ = NullCodec>
514 using Ptr = std::shared_ptr<TypedAttributeArray>;
515 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
519 using StorageType =
typename Codec::template Storage<ValueType>::Type;
525 const ValueType& uniformValue = zeroVal<ValueType>());
550 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true,
551 const Metadata* metadata =
nullptr);
560 static const NamePair& attributeType();
565 static bool isRegistered();
567 static void registerType();
569 static void unregisterType();
576 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
580 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
597 bool valueTypeIsFloatingPoint()
const override;
600 bool valueTypeIsClass()
const override;
603 bool valueTypeIsVector()
const override;
606 bool valueTypeIsQuaternion()
const override;
609 bool valueTypeIsMatrix()
const override;
625 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
627 template<
typename T>
void get(
Index n, T& value)
const;
638 template<
typename T>
void setUnsafe(
Index n,
const T& value);
640 template<
typename T>
void set(
Index n,
const T& value);
651 void expand(
bool fill =
true)
override;
653 void collapse()
override;
655 bool compact()
override;
658 void collapse(
const ValueType& uniformValue);
669 void read(std::istream&)
override;
673 void write(std::ostream& os,
bool outputTransient)
const override;
675 void write(std::ostream&)
const override;
678 void readMetadata(std::istream&)
override;
683 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
686 void readBuffers(std::istream&)
override;
690 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
700 inline bool isOutOfCore()
const;
703 void loadData()
const override;
706 bool isDataLoaded()
const override;
719 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
722 friend class ::TestAttributeArray;
727 inline void doLoad()
const;
729 inline void doLoadUnsafe()
const;
732 inline void setOutOfCore(
const bool);
738 char* dataAsByteArray()
override;
739 const char* dataAsByteArray()
const override;
741 size_t arrayMemUsage()
const;
748 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride, metadata);
751 std::unique_ptr<StorageType[]> mData;
753 Index mStrideOrTotalSize;
762 template <
typename ValueType,
typename CodecType = UnknownCodec>
767 using Ptr = std::shared_ptr<Handle>;
776 static Ptr create(
const AttributeArray& array,
const bool collapseOnDestruction =
true);
788 bool isUniform()
const;
789 bool hasConstantStride()
const;
806 friend class ::TestAttributeArray;
808 template <
bool IsUnknownCodec>
809 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
811 template <
bool IsUnknownCodec>
812 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
814 template <
bool IsUnknownCodec>
815 typename std::enable_if<IsUnknownCodec, ValueType>::type
get(
Index index)
const;
817 template <
bool IsUnknownCodec>
818 typename std::enable_if<!IsUnknownCodec, ValueType>::type
get(
Index index)
const;
820 Index mStrideOrTotalSize;
822 bool mCollapseOnDestruction;
830 template <
typename ValueType,
typename CodecType = UnknownCodec>
835 using Ptr = std::shared_ptr<Handle>;
846 void expand(
bool fill =
true);
850 void collapse(
const ValueType& uniformValue);
857 void fill(
const ValueType& value);
859 void set(
Index n,
const ValueType& value);
860 void set(
Index n,
Index m,
const ValueType& value);
865 friend class ::TestAttributeArray;
867 template <
bool IsUnknownCodec>
868 typename std::enable_if<IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
870 template <
bool IsUnknownCodec>
871 typename std::enable_if<!IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
881 template<
typename ValueType>
883 NullCodec::decode(
const ValueType& data, ValueType& val)
889 template<
typename ValueType>
891 NullCodec::encode(
const ValueType& val, ValueType& data)
897 template<
typename StorageType,
typename ValueType>
899 TruncateCodec::decode(
const StorageType& data, ValueType& val)
901 val =
static_cast<ValueType
>(data);
905 template<
typename StorageType,
typename ValueType>
907 TruncateCodec::encode(
const ValueType& val, StorageType& data)
909 data =
static_cast<StorageType
>(val);
913 template <
bool OneByte,
typename Range>
914 template<
typename StorageType,
typename ValueType>
918 val = fixedPointToFloatingPoint<ValueType>(data);
922 val = Range::template decode<ValueType>(val);
926 template <
bool OneByte,
typename Range>
927 template<
typename StorageType,
typename ValueType>
933 const ValueType newVal = Range::template encode<ValueType>(val);
935 data = floatingPointToFixedPoint<StorageType>(newVal);
943 val = math::QuantizedUnitVec::unpack(data);
951 data = math::QuantizedUnitVec::pack(val);
959 template <
typename IterT>
960 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
972 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
973 char*
const targetBuffer = this->dataAsByteArray();
976 if (rangeChecking && this->isUniform()) {
980 const bool sourceIsUniform = sourceArray.
isUniform();
982 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
983 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
985 for (IterT it(iter); it; ++it) {
986 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
987 const Index targetIndex = it.targetIndex();
990 if (sourceIndex >= sourceDataSize) {
992 "Cannot copy array data as source index exceeds size of source array.");
994 if (targetIndex >= targetDataSize) {
996 "Cannot copy array data as target index exceeds size of target array.");
1005 const size_t targetOffset(targetIndex * bytes);
1006 const size_t sourceOffset(sourceIndex * bytes);
1008 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1012 template <
typename IterT>
1013 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1015 this->doCopyValues(sourceArray, iter,
false);
1018 template <
typename IterT>
1019 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1023 if (bytes != this->storageTypeSize()) {
1040 this->doCopyValues(sourceArray, iter,
true);
1054 template<
typename ValueType_,
typename Codec_>
1060 , mStrideOrTotalSize(strideOrTotalSize)
1062 if (constantStride) {
1064 if (strideOrTotalSize == 0) {
1066 "stride to be at least one.")
1071 if (mStrideOrTotalSize < n) {
1073 "a total size of at least the number of elements in the array.")
1077 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1078 Codec::encode(uniformValue, this->
data()[0]);
1082 template<
typename ValueType_,
typename Codec_>
1089 template<
typename ValueType_,
typename Codec_>
1091 const tbb::spin_mutex::scoped_lock& lock)
1094 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1098 std::memcpy(static_cast<void*>(this->
data()), rhs.
data(), this->arrayMemUsage());
1103 template<
typename ValueType_,
typename Codec_>
1109 tbb::spin_mutex::scoped_lock lock(
mMutex);
1110 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1117 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1122 std::memcpy(static_cast<void*>(this->
data()), rhs.
data(), this->arrayMemUsage());
1130 template<
typename ValueType_,
typename Codec_>
1135 return NamePair(typeNameAsString<ValueType>(), Codec::name());
1141 template<
typename ValueType_,
typename Codec_>
1149 template<
typename ValueType_,
typename Codec_>
1157 template<
typename ValueType_,
typename Codec_>
1165 template<
typename ValueType_,
typename Codec_>
1174 typedMetadata ? typedMetadata->
value() : zeroVal<ValueType>()));
1177 template<
typename ValueType_,
typename Codec_>
1187 template<
typename ValueType_,
typename Codec_>
1197 template<
typename ValueType_,
typename Codec_>
1205 template<
typename ValueType_,
typename Codec_>
1215 template<
typename ValueType_,
typename Codec_>
1231 template<
typename ValueType_,
typename Codec_>
1237 this->setOutOfCore(
false);
1240 if (mData) mData.reset();
1244 template<
typename ValueType_,
typename Codec_>
1250 if (std::is_same<ValueType, Quats>::value ||
1251 std::is_same<ValueType, Quatd>::value ||
1252 std::is_same<ValueType, Mat3s>::value ||
1253 std::is_same<ValueType, Mat3d>::value ||
1254 std::is_same<ValueType, Mat4s>::value ||
1255 std::is_same<ValueType, Mat4d>::value)
return true;
1260 return std::is_floating_point<ElementT>::value || std::is_same<math::half, ElementT>::value;
1264 template<
typename ValueType_,
typename Codec_>
1269 return std::is_class<ValueType>::value && !std::is_same<math::half, ValueType>::value;
1273 template<
typename ValueType_,
typename Codec_>
1281 template<
typename ValueType_,
typename Codec_>
1286 return !this->
valueType().compare(0, 4,
"quat");
1290 template<
typename ValueType_,
typename Codec_>
1295 return !this->
valueType().compare(0, 3,
"mat");
1299 template<
typename ValueType_,
typename Codec_>
1303 return sizeof(*this) + (
bool(mData) ? this->arrayMemUsage() : 0);
1307 template<
typename ValueType_,
typename Codec_>
1315 template<
typename ValueType_,
typename Codec_>
1327 template<
typename ValueType_,
typename Codec_>
1338 template<
typename ValueType_,
typename Codec_>
1339 template<
typename T>
1343 val =
static_cast<T
>(this->
getUnsafe(n));
1347 template<
typename ValueType_,
typename Codec_>
1348 template<
typename T>
1352 val =
static_cast<T
>(this->
get(n));
1356 template<
typename ValueType_,
typename Codec_>
1364 template<
typename ValueType_,
typename Codec_>
1379 template<
typename ValueType_,
typename Codec_>
1391 template<
typename ValueType_,
typename Codec_>
1392 template<
typename T>
1396 this->
setUnsafe(n, static_cast<ValueType>(val));
1400 template<
typename ValueType_,
typename Codec_>
1401 template<
typename T>
1405 this->
set(n,
static_cast<ValueType>(val));
1409 template<
typename ValueType_,
typename Codec_>
1417 template<
typename ValueType_,
typename Codec_>
1426 tbb::spin_mutex::scoped_lock lock(
mMutex);
1438 template<
typename ValueType_,
typename Codec_>
1445 const ValueType_ val = this->
get(0);
1455 template<
typename ValueType_,
typename Codec_>
1459 this->
collapse(zeroVal<ValueType>());
1463 template<
typename ValueType_,
typename Codec_>
1468 tbb::spin_mutex::scoped_lock lock(
mMutex);
1473 Codec::encode(uniformValue, this->
data()[0]);
1477 template<
typename ValueType_,
typename Codec_>
1485 template<
typename ValueType_,
typename Codec_>
1490 tbb::spin_mutex::scoped_lock lock(
mMutex);
1497 Codec::encode(value, this->
data()[i]);
1502 template<
typename ValueType_,
typename Codec_>
1510 template<
typename ValueType_,
typename Codec_>
1518 template<
typename ValueType_,
typename Codec_>
1526 template<
typename ValueType_,
typename Codec_>
1537 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1538 this->doLoadUnsafe();
1542 template<
typename ValueType_,
typename Codec_>
1550 template<
typename ValueType_,
typename Codec_>
1558 template<
typename ValueType_,
typename Codec_>
1567 template<
typename ValueType_,
typename Codec_>
1574 is.read(reinterpret_cast<char*>(&bytes),
sizeof(
Index64));
1575 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1577 uint8_t
flags = uint8_t(0);
1578 is.read(reinterpret_cast<char*>(&flags),
sizeof(uint8_t));
1581 uint8_t serializationFlags = uint8_t(0);
1582 is.read(reinterpret_cast<char*>(&serializationFlags),
sizeof(uint8_t));
1585 is.read(reinterpret_cast<char*>(&size),
sizeof(
Index));
1594 if (serializationFlags >= 0x10) {
1609 is.read(reinterpret_cast<char*>(&stride),
sizeof(
Index));
1610 mStrideOrTotalSize =
stride;
1613 mStrideOrTotalSize = 1;
1618 template<
typename ValueType_,
typename Codec_>
1627 tbb::spin_mutex::scoped_lock lock(
mMutex);
1631 uint8_t bloscCompressed(0);
1632 if (!
mIsUniform) is.read(reinterpret_cast<char*>(&bloscCompressed),
sizeof(uint8_t));
1637 mCompressedBytes = 0;
1642 if (bloscCompressed == uint8_t(1)) {
1648 if (newBuffer) buffer.reset(newBuffer.release());
1653 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1657 template<
typename ValueType_,
typename Codec_>
1666 #ifdef OPENVDB_USE_DELAYED_LOADING 1669 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is.
getInputStream());
1670 const bool delayLoad = (mappedFile.get() !=
nullptr);
1685 tbb::spin_mutex::scoped_lock lock(
mMutex);
1689 #ifdef OPENVDB_USE_DELAYED_LOADING 1690 this->setOutOfCore(delayLoad);
1694 #endif // OPENVDB_USE_DELAYED_LOADING 1696 #ifdef OPENVDB_USE_DELAYED_LOADING 1699 std::unique_ptr<char[]> buffer =
mPageHandle->read();
1700 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1702 #ifdef OPENVDB_USE_DELAYED_LOADING 1712 template<
typename ValueType_,
typename Codec_>
1716 this->
write(os,
false);
1720 template<
typename ValueType_,
typename Codec_>
1729 template<
typename ValueType_,
typename Codec_>
1733 if (!outputTransient && this->
isTransient())
return;
1740 uint8_t serializationFlags(0);
1742 Index strideOrTotalSize(mStrideOrTotalSize);
1743 bool strideOfOne(this->
stride() == 1);
1748 if (bloscCompression) this->doLoad();
1750 size_t compressedBytes = 0;
1760 if (bloscCompression && paged) serializationFlags |=
WRITEPAGED;
1762 else if (bloscCompression)
1766 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1767 const size_t inBytes = this->arrayMemUsage();
1774 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1778 os.write(reinterpret_cast<const char*>(&bytes),
sizeof(
Index64));
1779 os.write(reinterpret_cast<const char*>(&flags),
sizeof(uint8_t));
1780 os.write(reinterpret_cast<const char*>(&serializationFlags),
sizeof(uint8_t));
1781 os.write(reinterpret_cast<const char*>(&size),
sizeof(
Index));
1784 if (!strideOfOne) os.write(reinterpret_cast<const char*>(&strideOrTotalSize),
sizeof(
Index));
1788 template<
typename ValueType_,
typename Codec_>
1792 if (!outputTransient && this->
isTransient())
return;
1801 os.write(reinterpret_cast<const char*>(this->
data()),
sizeof(
StorageType));
1805 std::unique_ptr<char[]> compressedBuffer;
1806 size_t compressedBytes = 0;
1807 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1808 const size_t inBytes = this->arrayMemUsage();
1810 if (compressedBuffer) {
1811 uint8_t bloscCompressed(1);
1812 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1813 os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
1816 uint8_t bloscCompressed(0);
1817 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1818 os.write(reinterpret_cast<const char*>(this->
data()), inBytes);
1823 uint8_t bloscCompressed(0);
1824 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1825 os.write(reinterpret_cast<const char*>(this->
data()), this->arrayMemUsage());
1830 template<
typename ValueType_,
typename Codec_>
1834 if (!outputTransient && this->
isTransient())
return;
1838 if (!bloscCompression) {
1849 os.
write(reinterpret_cast<const char*>(this->
data()), this->arrayMemUsage());
1853 template<
typename ValueType_,
typename Codec_>
1866 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
1868 self->mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1870 self->mPageHandle.reset();
1874 self->mOutOfCore =
false;
1878 template<
typename ValueType_,
typename Codec_>
1893 template<
typename ValueType_,
typename Codec_>
1898 if(!otherT)
return false;
1899 if(this->mSize != otherT->mSize ||
1900 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1902 this->attributeType() != this->
attributeType())
return false;
1908 if (!target && !source)
return true;
1909 if (!target || !source)
return false;
1916 template<
typename ValueType_,
typename Codec_>
1920 return reinterpret_cast<char*
>(this->
data());
1924 template<
typename ValueType_,
typename Codec_>
1928 return reinterpret_cast<const char*
>(this->
data());
1936 template <
typename CodecType,
typename ValueType>
1957 template <
typename ValueType>
1965 return (*functor)(array, n);
1970 (*functor)(array, n, value);
1979 template <
typename ValueType,
typename CodecType>
1987 template <
typename ValueType,
typename CodecType>
1992 , mCollapseOnDestruction(collapseOnDestruction && array.
isStreaming())
1994 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2015 template <
typename ValueType,
typename CodecType>
2022 template <
typename ValueType,
typename CodecType>
2023 template <
bool IsUnknownCodec>
2024 typename std::enable_if<IsUnknownCodec, bool>::type
2032 template <
typename ValueType,
typename CodecType>
2033 template <
bool IsUnknownCodec>
2034 typename std::enable_if<!IsUnknownCodec, bool>::type
2042 template <
typename ValueType,
typename CodecType>
2049 template <
typename ValueType,
typename CodecType>
2057 template <
typename ValueType,
typename CodecType>
2060 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->
index(n, m));
2063 template <
typename ValueType,
typename CodecType>
2064 template <
bool IsUnknownCodec>
2065 typename std::enable_if<IsUnknownCodec, ValueType>::type
2073 template <
typename ValueType,
typename CodecType>
2074 template <
bool IsUnknownCodec>
2075 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2083 template <
typename ValueType,
typename CodecType>
2089 template <
typename ValueType,
typename CodecType>
2099 template <
typename ValueType,
typename CodecType>
2107 template <
typename ValueType,
typename CodecType>
2111 if (expand) array.
expand();
2114 template <
typename ValueType,
typename CodecType>
2117 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->
index(n, 0), value);
2120 template <
typename ValueType,
typename CodecType>
2123 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->
index(n, m), value);
2126 template <
typename ValueType,
typename CodecType>
2132 template <
typename ValueType,
typename CodecType>
2138 template <
typename ValueType,
typename CodecType>
2144 template <
typename ValueType,
typename CodecType>
2150 template <
typename ValueType,
typename CodecType>
2153 this->
mFiller(const_cast<AttributeArray*>(this->
mArray), value);
2156 template <
typename ValueType,
typename CodecType>
2157 template <
bool IsUnknownCodec>
2158 typename std::enable_if<IsUnknownCodec, void>::type
2166 template <
typename ValueType,
typename CodecType>
2167 template <
bool IsUnknownCodec>
2168 typename std::enable_if<!IsUnknownCodec, void>::type
2176 template <
typename ValueType,
typename CodecType>
2188 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED T & y()
Definition: Vec3.h:87
Definition: AttributeArray.h:492
GetterPtr mGetter
Definition: AttributeArray.h:800
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t *poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
Definition: pnanovdb_validate_strides.h:20
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
Base class for storing attribute data.
Definition: AttributeArray.h:93
Definition: AttributeArray.h:480
Index storageTypeSize() const override
Definition: AttributeArray.h:594
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:393
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
virtual Index stride() const =0
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:562
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
uint64_t Index64
Definition: Types.h:53
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:474
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1560
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: AttributeArray.h:119
Definition: AttributeArray.h:447
AttributeArray & array()
Definition: AttributeArray.h:2177
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:328
size_t mCompressedBytes
Definition: AttributeArray.h:373
bool hasConstantStride() const
Definition: AttributeArray.h:2090
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:207
Definition: Exceptions.h:57
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:480
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:1961
static Ptr create(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2101
std::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:369
size_t memUsageIfLoaded() const override
Definition: AttributeArray.h:1309
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:258
AttributeArray()
Definition: AttributeArray.h:133
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:219
Index size() const
Definition: AttributeArray.h:786
ValuePtr mCollapser
Definition: AttributeArray.h:802
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:462
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1143
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition: AttributeArray.h:1317
Index index(Index n, Index m) const
Definition: AttributeArray.h:2050
T Type
Definition: AttributeArray.h:439
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:289
Definition: AttributeArray.h:408
void(*)(AttributeArray *array, const Index n, const Index &value) SetterPtr
Definition: AttributeArray.h:772
const StorageType * data() const
Definition: AttributeArray.h:716
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1569
data is marked as strided when written
Definition: AttributeArray.h:112
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:268
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:514
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:215
bool mIsUniform
Definition: AttributeArray.h:365
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1329
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1544
Index32 Index
Definition: Types.h:54
T & z()
Definition: Vec3.h:88
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:1880
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:519
internal::half half
Definition: Types.h:29
Index(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:771
Definition: Compression.h:57
static const char * name()
Definition: AttributeArray.h:454
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:443
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:389
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1512
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:127
tbb::spin_mutex mMutex
Definition: AttributeArray.h:366
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1832
virtual Index storageTypeSize() const =0
Write-able version of AttributeHandle.
Definition: AttributeArray.h:831
ValuePtr mFiller
Definition: AttributeArray.h:803
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2139
bool sizeOnly() const
Definition: StreamCompression.h:218
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:2151
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true) ...
Definition: AttributeArray.h:1266
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1457
Definition: AttributeArray.h:497
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:767
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1132
Definition: Exceptions.h:65
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:382
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1790
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:587
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1159
Convenience wrappers to using Blosc and reading and writing of Paged data.
Definition: AttributeArray.h:763
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:275
uint8_t mFlags
Definition: AttributeArray.h:367
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1105
short Type
Definition: AttributeArray.h:410
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:86
SetterPtr mSetter
Definition: AttributeArray.h:397
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:719
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:450
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:463
Definition: AttributeArray.h:115
SetterPtr mSetter
Definition: AttributeArray.h:801
int16_t Int16
Definition: Types.h:55
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1440
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:1940
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1179
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1552
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2108
static const char * name()
Definition: AttributeArray.h:501
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:1988
Typed class for storing attribute data.
Definition: AttributeArray.h:511
static const char * name()
Definition: AttributeArray.h:470
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:472
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1722
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:70
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
Definition: Exceptions.h:64
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:1167
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1199
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:244
Definition: Exceptions.h:13
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:1381
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:286
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:40
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
Definition: Exceptions.h:58
Flag
Definition: AttributeArray.h:102
Definition: AttributeArray.h:450
Codec_ Codec
Definition: AttributeArray.h:518
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1419
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:372
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:391
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1283
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1246
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:173
uint16_t Type
Definition: AttributeArray.h:418
Index stride() const
Definition: AttributeArray.h:785
~TypedAttributeArray() override
Definition: AttributeArray.h:543
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:835
typename T::ValueType ElementType
Definition: Types.h:318
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1731
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:715
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
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:1055
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:1937
Definition: AttributeArray.h:477
static const char * name()
Definition: AttributeArray.h:461
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1301
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:579
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition: AttributeArray.h:129
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:647
ValueType get(Index n, Index m=0) const
Definition: AttributeArray.h:2058
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:471
streaming mode collapses attributes when first accessed
Definition: AttributeArray.h:107
void(*)(AttributeArray *array, const Index &value) ValuePtr
Definition: AttributeArray.h:773
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:1960
const AttributeArray & array() const
Definition: AttributeArray.h:2043
ValuePtr mFiller
Definition: AttributeArray.h:399
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:1939
bool isUniform() const
Definition: AttributeArray.h:2084
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1659
virtual ~AttributeArray()
Definition: AttributeArray.h:134
Definition: AttributeArray.h:111
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:80
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:256
Definition: AttributeArray.h:439
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1292
bool sizeOnly() const
Definition: StreamCompression.h:255
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:1981
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:836
Definition: AttributeArray.h:468
std::string Name
Definition: Name.h:19
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:283
Definition: AttributeArray.h:459
ValueType_ ValueType
Definition: AttributeArray.h:517
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1275
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1151
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
Definition: AttributeArray.h:97
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:768
const StorageType * constData() const
Return the raw data buffer.
Definition: AttributeArray.h:709
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2127
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:126
static const char * name()
Definition: AttributeArray.h:485
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1487
SerializationFlag
Definition: AttributeArray.h:110
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:584
std::istream & getInputStream()
Definition: StreamCompression.h:221
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:416
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
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.
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:572
Definition: AttributeArray.h:436
Definition: AttributeArray.h:433
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2133
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...
static const char * name()
Definition: AttributeArray.h:443
const char * constDataAsByteArray() const
Indirect virtual function to retrieve the data buffer cast to a char byte array.
Definition: AttributeArray.h:331
void set(Index n, const ValueType &value)
Definition: AttributeArray.h:2115
GetterPtr mGetter
Definition: AttributeArray.h:396
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition: AttributeArray.h:1366
uint16_t StorageType
Definition: AttributeArray.h:494
virtual ~AttributeHandle()
Definition: AttributeArray.h:2016
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:590
uint8_t Type
Definition: AttributeArray.h:417
uint8_t mUsePagedRead
Definition: AttributeArray.h:368
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:99
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...
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218
StorageType Type
Definition: AttributeArray.h:497
virtual Index dataSize() const =0
virtual void loadData() const =0
Ensures all data is in-core.
const AttributeArray * mArray
Definition: AttributeArray.h:798
Index stride() const override
Definition: AttributeArray.h:576
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1620
ValuePtr mCollapser
Definition: AttributeArray.h:398