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;
823 Index mStrideOrTotalSize;
825 bool mCollapseOnDestruction;
833 template <
typename ValueType,
typename CodecType = UnknownCodec>
838 using Ptr = std::shared_ptr<Handle>;
849 void expand(
bool fill =
true);
853 void collapse(
const ValueType& uniformValue);
860 void fill(
const ValueType& value);
862 void set(
Index n,
const ValueType& value);
863 void set(
Index n,
Index m,
const ValueType& value);
868 friend class ::TestAttributeArray;
870 template <
bool IsUnknownCodec>
871 typename std::enable_if<IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
873 template <
bool IsUnknownCodec>
874 typename std::enable_if<!IsUnknownCodec, void>::type
set(
Index index,
const ValueType& value)
const;
884 template<
typename ValueType>
886 NullCodec::decode(
const ValueType& data, ValueType& val)
892 template<
typename ValueType>
894 NullCodec::encode(
const ValueType& val, ValueType& data)
900 template<
typename StorageType,
typename ValueType>
902 TruncateCodec::decode(
const StorageType& data, ValueType& val)
904 val =
static_cast<ValueType
>(data);
908 template<
typename StorageType,
typename ValueType>
910 TruncateCodec::encode(
const ValueType& val, StorageType& data)
912 data =
static_cast<StorageType
>(val);
916 template <
bool OneByte,
typename Range>
917 template<
typename StorageType,
typename ValueType>
921 val = fixedPointToFloatingPoint<ValueType>(data);
925 val = Range::template decode<ValueType>(val);
929 template <
bool OneByte,
typename Range>
930 template<
typename StorageType,
typename ValueType>
936 const ValueType newVal = Range::template encode<ValueType>(val);
938 data = floatingPointToFixedPoint<StorageType>(newVal);
946 val = math::QuantizedUnitVec::unpack(data);
954 data = math::QuantizedUnitVec::pack(val);
962 template <
typename IterT>
963 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
975 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
976 char*
const targetBuffer = this->dataAsByteArray();
979 if (rangeChecking && this->isUniform()) {
983 const bool sourceIsUniform = sourceArray.
isUniform();
985 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
986 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
988 for (IterT it(iter); it; ++it) {
989 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
990 const Index targetIndex = it.targetIndex();
993 if (sourceIndex >= sourceDataSize) {
995 "Cannot copy array data as source index exceeds size of source array.");
997 if (targetIndex >= targetDataSize) {
999 "Cannot copy array data as target index exceeds size of target array.");
1008 const size_t targetOffset(targetIndex * bytes);
1009 const size_t sourceOffset(sourceIndex * bytes);
1011 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1015 template <
typename IterT>
1016 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1018 this->doCopyValues(sourceArray, iter,
false);
1021 template <
typename IterT>
1022 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1026 if (bytes != this->storageTypeSize()) {
1043 this->doCopyValues(sourceArray, iter,
true);
1057 template<
typename ValueType_,
typename Codec_>
1063 , mStrideOrTotalSize(strideOrTotalSize)
1065 if (constantStride) {
1067 if (strideOrTotalSize == 0) {
1069 "stride to be at least one.")
1074 if (mStrideOrTotalSize < n) {
1076 "a total size of at least the number of elements in the array.")
1080 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1081 Codec::encode(uniformValue, this->
data()[0]);
1085 template<
typename ValueType_,
typename Codec_>
1092 template<
typename ValueType_,
typename Codec_>
1094 const tbb::spin_mutex::scoped_lock& lock)
1097 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1101 std::memcpy(static_cast<void*>(this->
data()), rhs.
data(), this->arrayMemUsage());
1106 template<
typename ValueType_,
typename Codec_>
1112 tbb::spin_mutex::scoped_lock lock(
mMutex);
1113 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1120 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1125 std::memcpy(static_cast<void*>(this->
data()), rhs.
data(), this->arrayMemUsage());
1133 template<
typename ValueType_,
typename Codec_>
1138 return NamePair(typeNameAsString<ValueType>(), Codec::name());
1144 template<
typename ValueType_,
typename Codec_>
1152 template<
typename ValueType_,
typename Codec_>
1160 template<
typename ValueType_,
typename Codec_>
1168 template<
typename ValueType_,
typename Codec_>
1177 typedMetadata ? typedMetadata->
value() : zeroVal<ValueType>()));
1180 template<
typename ValueType_,
typename Codec_>
1190 template<
typename ValueType_,
typename Codec_>
1200 template<
typename ValueType_,
typename Codec_>
1208 template<
typename ValueType_,
typename Codec_>
1218 template<
typename ValueType_,
typename Codec_>
1234 template<
typename ValueType_,
typename Codec_>
1240 this->setOutOfCore(
false);
1243 if (mData) mData.reset();
1247 template<
typename ValueType_,
typename Codec_>
1253 if (std::is_same<ValueType, Quats>::value ||
1254 std::is_same<ValueType, Quatd>::value ||
1255 std::is_same<ValueType, Mat3s>::value ||
1256 std::is_same<ValueType, Mat3d>::value ||
1257 std::is_same<ValueType, Mat4s>::value ||
1258 std::is_same<ValueType, Mat4d>::value)
return true;
1263 return std::is_floating_point<ElementT>::value || std::is_same<math::half, ElementT>::value;
1267 template<
typename ValueType_,
typename Codec_>
1272 return std::is_class<ValueType>::value && !std::is_same<math::half, ValueType>::value;
1276 template<
typename ValueType_,
typename Codec_>
1284 template<
typename ValueType_,
typename Codec_>
1289 return !this->
valueType().compare(0, 4,
"quat");
1293 template<
typename ValueType_,
typename Codec_>
1298 return !this->
valueType().compare(0, 3,
"mat");
1302 template<
typename ValueType_,
typename Codec_>
1306 return sizeof(*this) + (
bool(mData) ? this->arrayMemUsage() : 0);
1310 template<
typename ValueType_,
typename Codec_>
1318 template<
typename ValueType_,
typename Codec_>
1330 template<
typename ValueType_,
typename Codec_>
1341 template<
typename ValueType_,
typename Codec_>
1342 template<
typename T>
1346 val =
static_cast<T
>(this->
getUnsafe(n));
1350 template<
typename ValueType_,
typename Codec_>
1351 template<
typename T>
1355 val =
static_cast<T
>(this->
get(n));
1359 template<
typename ValueType_,
typename Codec_>
1367 template<
typename ValueType_,
typename Codec_>
1382 template<
typename ValueType_,
typename Codec_>
1394 template<
typename ValueType_,
typename Codec_>
1395 template<
typename T>
1399 this->
setUnsafe(n, static_cast<ValueType>(val));
1403 template<
typename ValueType_,
typename Codec_>
1404 template<
typename T>
1408 this->
set(n,
static_cast<ValueType>(val));
1412 template<
typename ValueType_,
typename Codec_>
1420 template<
typename ValueType_,
typename Codec_>
1429 tbb::spin_mutex::scoped_lock lock(
mMutex);
1441 template<
typename ValueType_,
typename Codec_>
1448 const ValueType_ val = this->
get(0);
1458 template<
typename ValueType_,
typename Codec_>
1462 this->
collapse(zeroVal<ValueType>());
1466 template<
typename ValueType_,
typename Codec_>
1471 tbb::spin_mutex::scoped_lock lock(
mMutex);
1476 Codec::encode(uniformValue, this->
data()[0]);
1480 template<
typename ValueType_,
typename Codec_>
1488 template<
typename ValueType_,
typename Codec_>
1493 tbb::spin_mutex::scoped_lock lock(
mMutex);
1500 Codec::encode(value, this->
data()[i]);
1505 template<
typename ValueType_,
typename Codec_>
1513 template<
typename ValueType_,
typename Codec_>
1521 template<
typename ValueType_,
typename Codec_>
1529 template<
typename ValueType_,
typename Codec_>
1540 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1541 this->doLoadUnsafe();
1545 template<
typename ValueType_,
typename Codec_>
1553 template<
typename ValueType_,
typename Codec_>
1561 template<
typename ValueType_,
typename Codec_>
1570 template<
typename ValueType_,
typename Codec_>
1577 is.read(reinterpret_cast<char*>(&bytes),
sizeof(
Index64));
1578 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1580 uint8_t
flags = uint8_t(0);
1581 is.read(reinterpret_cast<char*>(&flags),
sizeof(uint8_t));
1584 uint8_t serializationFlags = uint8_t(0);
1585 is.read(reinterpret_cast<char*>(&serializationFlags),
sizeof(uint8_t));
1588 is.read(reinterpret_cast<char*>(&size),
sizeof(
Index));
1597 if (serializationFlags >= 0x10) {
1612 is.read(reinterpret_cast<char*>(&stride),
sizeof(
Index));
1613 mStrideOrTotalSize =
stride;
1616 mStrideOrTotalSize = 1;
1621 template<
typename ValueType_,
typename Codec_>
1630 tbb::spin_mutex::scoped_lock lock(
mMutex);
1634 uint8_t bloscCompressed(0);
1635 if (!
mIsUniform) is.read(reinterpret_cast<char*>(&bloscCompressed),
sizeof(uint8_t));
1640 mCompressedBytes = 0;
1645 if (bloscCompressed == uint8_t(1)) {
1651 if (newBuffer) buffer.reset(newBuffer.release());
1656 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1660 template<
typename ValueType_,
typename Codec_>
1669 #ifdef OPENVDB_USE_DELAYED_LOADING 1672 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is.
getInputStream());
1673 const bool delayLoad = (mappedFile.get() !=
nullptr);
1688 tbb::spin_mutex::scoped_lock lock(
mMutex);
1692 #ifdef OPENVDB_USE_DELAYED_LOADING 1693 this->setOutOfCore(delayLoad);
1697 #endif // OPENVDB_USE_DELAYED_LOADING 1699 #ifdef OPENVDB_USE_DELAYED_LOADING 1702 std::unique_ptr<char[]> buffer =
mPageHandle->read();
1703 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1705 #ifdef OPENVDB_USE_DELAYED_LOADING 1715 template<
typename ValueType_,
typename Codec_>
1719 this->
write(os,
false);
1723 template<
typename ValueType_,
typename Codec_>
1732 template<
typename ValueType_,
typename Codec_>
1736 if (!outputTransient && this->
isTransient())
return;
1743 uint8_t serializationFlags(0);
1745 Index strideOrTotalSize(mStrideOrTotalSize);
1746 bool strideOfOne(this->
stride() == 1);
1751 if (bloscCompression) this->doLoad();
1753 size_t compressedBytes = 0;
1763 if (bloscCompression && paged) serializationFlags |=
WRITEPAGED;
1765 else if (bloscCompression)
1769 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1770 const size_t inBytes = this->arrayMemUsage();
1777 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1781 os.write(reinterpret_cast<const char*>(&bytes),
sizeof(
Index64));
1782 os.write(reinterpret_cast<const char*>(&flags),
sizeof(uint8_t));
1783 os.write(reinterpret_cast<const char*>(&serializationFlags),
sizeof(uint8_t));
1784 os.write(reinterpret_cast<const char*>(&size),
sizeof(
Index));
1787 if (!strideOfOne) os.write(reinterpret_cast<const char*>(&strideOrTotalSize),
sizeof(
Index));
1791 template<
typename ValueType_,
typename Codec_>
1795 if (!outputTransient && this->
isTransient())
return;
1804 os.write(reinterpret_cast<const char*>(this->
data()),
sizeof(
StorageType));
1808 std::unique_ptr<char[]> compressedBuffer;
1809 size_t compressedBytes = 0;
1810 const char* charBuffer =
reinterpret_cast<const char*
>(this->
data());
1811 const size_t inBytes = this->arrayMemUsage();
1813 if (compressedBuffer) {
1814 uint8_t bloscCompressed(1);
1815 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1816 os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
1819 uint8_t bloscCompressed(0);
1820 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1821 os.write(reinterpret_cast<const char*>(this->
data()), inBytes);
1826 uint8_t bloscCompressed(0);
1827 os.write(reinterpret_cast<const char*>(&bloscCompressed),
sizeof(uint8_t));
1828 os.write(reinterpret_cast<const char*>(this->
data()), this->arrayMemUsage());
1833 template<
typename ValueType_,
typename Codec_>
1837 if (!outputTransient && this->
isTransient())
return;
1841 if (!bloscCompression) {
1852 os.
write(reinterpret_cast<const char*>(this->
data()), this->arrayMemUsage());
1856 template<
typename ValueType_,
typename Codec_>
1869 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
1871 self->mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1873 self->mPageHandle.reset();
1877 self->mOutOfCore =
false;
1881 template<
typename ValueType_,
typename Codec_>
1896 template<
typename ValueType_,
typename Codec_>
1901 if(!otherT)
return false;
1902 if(this->mSize != otherT->mSize ||
1903 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1905 this->attributeType() != this->
attributeType())
return false;
1911 if (!target && !source)
return true;
1912 if (!target || !source)
return false;
1919 template<
typename ValueType_,
typename Codec_>
1923 return reinterpret_cast<char*
>(this->
data());
1927 template<
typename ValueType_,
typename Codec_>
1931 return reinterpret_cast<const char*
>(this->
data());
1939 template <
typename CodecType,
typename ValueType>
1960 template <
typename ValueType>
1968 return (*functor)(array, n);
1973 (*functor)(array, n, value);
1982 template <
typename ValueType,
typename CodecType>
1990 template <
typename ValueType,
typename CodecType>
1995 , mCollapseOnDestruction(collapseOnDestruction && array.
isStreaming())
1997 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2018 template <
typename ValueType,
typename CodecType>
2025 template <
typename ValueType,
typename CodecType>
2026 template <
bool IsUnknownCodec>
2027 typename std::enable_if<IsUnknownCodec, bool>::type
2035 template <
typename ValueType,
typename CodecType>
2036 template <
bool IsUnknownCodec>
2037 typename std::enable_if<!IsUnknownCodec, bool>::type
2045 template <
typename ValueType,
typename CodecType>
2052 template <
typename ValueType,
typename CodecType>
2060 template <
typename ValueType,
typename CodecType>
2063 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->
index(n, m));
2066 template <
typename ValueType,
typename CodecType>
2067 template <
bool IsUnknownCodec>
2068 typename std::enable_if<IsUnknownCodec, ValueType>::type
2076 template <
typename ValueType,
typename CodecType>
2077 template <
bool IsUnknownCodec>
2078 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2086 template <
typename ValueType,
typename CodecType>
2092 template <
typename ValueType,
typename CodecType>
2102 template <
typename ValueType,
typename CodecType>
2110 template <
typename ValueType,
typename CodecType>
2114 if (expand) array.
expand();
2117 template <
typename ValueType,
typename CodecType>
2120 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->
index(n, 0), value);
2123 template <
typename ValueType,
typename CodecType>
2126 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->
index(n, m), value);
2129 template <
typename ValueType,
typename CodecType>
2135 template <
typename ValueType,
typename CodecType>
2141 template <
typename ValueType,
typename CodecType>
2147 template <
typename ValueType,
typename CodecType>
2153 template <
typename ValueType,
typename CodecType>
2156 this->
mFiller(const_cast<AttributeArray*>(this->
mArray), value);
2159 template <
typename ValueType,
typename CodecType>
2160 template <
bool IsUnknownCodec>
2161 typename std::enable_if<IsUnknownCodec, void>::type
2169 template <
typename ValueType,
typename CodecType>
2170 template <
bool IsUnknownCodec>
2171 typename std::enable_if<!IsUnknownCodec, void>::type
2179 template <
typename ValueType,
typename CodecType>
2191 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:1883
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:443
T & y()
Definition: Vec3.h:87
Definition: AttributeArray.h:480
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:99
virtual void loadData() const =0
Ensures all data is in-core.
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1793
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:715
uint16_t StorageType
Definition: AttributeArray.h:494
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t *poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
Definition: pnanovdb_validate_strides.h:20
std::istream & getInputStream()
Definition: StreamCompression.h:221
StorageType Type
Definition: AttributeArray.h:497
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1304
virtual Index stride() const =0
AttributeArray & array()
Definition: AttributeArray.h:2180
ValuePtr mCollapser
Definition: AttributeArray.h:802
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1108
size_t mCompressedBytes
Definition: AttributeArray.h:373
bool isUniform() const
Definition: AttributeArray.h:2087
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true) ...
Definition: AttributeArray.h:1269
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:328
ValueType_ ValueType
Definition: AttributeArray.h:517
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1443
Definition: AttributeArray.h:497
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1555
Definition: Exceptions.h:57
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1182
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1490
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
static const char * name()
Definition: AttributeArray.h:485
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
Definition: AttributeArray.h:450
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
ValuePtr mCollapser
Definition: AttributeArray.h:398
uint64_t Index64
Definition: Types.h:53
Index(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:771
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1162
static Ptr create(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2104
bool sizeOnly() const
Definition: StreamCompression.h:218
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:719
static const char * name()
Definition: AttributeArray.h:470
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:289
SetterPtr mSetter
Definition: AttributeArray.h:801
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:389
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:462
std::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:369
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1202
internal::half half
Definition: Types.h:29
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1278
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:244
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition: AttributeArray.h:1369
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:768
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:268
bool sizeOnly() const
Definition: StreamCompression.h:255
typename T::ValueType ElementType
Definition: Types.h:247
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:215
Index stride() const
Definition: AttributeArray.h:785
Definition: AttributeArray.h:416
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:590
int16_t Int16
Definition: Types.h:55
bool mIsUniform
Definition: AttributeArray.h:365
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1725
Definition: AttributeArray.h:447
Definition: AttributeArray.h:763
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1286
T & z()
Definition: Vec3.h:88
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1249
static const char * name()
Definition: AttributeArray.h:454
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:463
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:1170
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:1943
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2142
Index32 Index
Definition: Types.h:54
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1384
void(*)(AttributeArray *array, const Index n, const Index &value) SetterPtr
Definition: AttributeArray.h:772
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:127
Definition: AttributeArray.h:97
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:2154
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:477
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1422
Index stride() const override
Definition: AttributeArray.h:576
tbb::spin_mutex mMutex
Definition: AttributeArray.h:366
Definition: AttributeArray.h:439
virtual Index storageTypeSize() const =0
Index index(Index n, Index m) const
Definition: AttributeArray.h:2053
Definition: Exceptions.h:65
const AttributeArray & array() const
Definition: AttributeArray.h:2046
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:258
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:1942
bool hasConstantStride() const
Definition: AttributeArray.h:2093
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:474
GetterPtr mGetter
Definition: AttributeArray.h:800
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:275
Convenience wrappers to using Blosc and reading and writing of Paged data.
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1662
ValueType get(Index n, Index m=0) const
Definition: AttributeArray.h:2061
SetterPtr mSetter
Definition: AttributeArray.h:397
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:86
ValuePtr mFiller
Definition: AttributeArray.h:803
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:1058
static const char * name()
Definition: AttributeArray.h:443
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:562
static const char * name()
Definition: AttributeArray.h:461
T Type
Definition: AttributeArray.h:439
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:579
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition: AttributeArray.h:1320
uint8_t mFlags
Definition: AttributeArray.h:367
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1563
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1295
void(*)(AttributeArray *array, const Index &value) ValuePtr
Definition: AttributeArray.h:773
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:647
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
Definition: AttributeArray.h:459
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:1963
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1572
Definition: AttributeArray.h:115
Definition: AttributeArray.h:468
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:390
const StorageType * constData() const
Return the raw data buffer.
Definition: AttributeArray.h:709
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2111
data is marked as strided when written
Definition: AttributeArray.h:112
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:450
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:70
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:286
Definition: Compression.h:57
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1146
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:382
Write-able version of AttributeHandle.
Definition: AttributeArray.h:834
ValuePtr mFiller
Definition: AttributeArray.h:399
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: Exceptions.h:13
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1515
const StorageType * data() const
Definition: AttributeArray.h:716
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:472
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1154
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1460
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1332
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:40
const AttributeArray * mArray
Definition: AttributeArray.h:798
Definition: AttributeArray.h:111
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:519
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1623
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:767
Flag
Definition: AttributeArray.h:102
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:173
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:572
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:372
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:1940
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:1991
Index size() const
Definition: AttributeArray.h:786
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:838
Index storageTypeSize() const override
Definition: AttributeArray.h:594
uint16_t Type
Definition: AttributeArray.h:418
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:391
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1135
short Type
Definition: AttributeArray.h:410
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:587
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.
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition: AttributeArray.h:129
Definition: AttributeArray.h:119
virtual ~AttributeArray()
Definition: AttributeArray.h:134
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:256
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:80
Definition: Exceptions.h:64
GetterPtr mGetter
Definition: AttributeArray.h:396
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:1984
SerializationFlag
Definition: AttributeArray.h:110
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:480
Definition: AttributeArray.h:408
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:471
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:839
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:283
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:126
Definition: Exceptions.h:58
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:207
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:393
Definition: AttributeArray.h:433
std::string Name
Definition: Name.h:19
size_t memUsageIfLoaded() const override
Definition: AttributeArray.h:1312
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2130
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2136
Definition: AttributeArray.h:436
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1547
void set(Index n, const ValueType &value)
Definition: AttributeArray.h:2118
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
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...
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
~TypedAttributeArray() override
Definition: AttributeArray.h:543
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
virtual ~AttributeHandle()
Definition: AttributeArray.h:2019
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1734
virtual Index dataSize() const =0
uint8_t Type
Definition: AttributeArray.h:417
Typed class for storing attribute data.
Definition: AttributeArray.h:511
static const char * name()
Definition: AttributeArray.h:501
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.
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1835
Codec_ Codec
Definition: AttributeArray.h:518
const char * constDataAsByteArray() const
Indirect virtual function to retrieve the data buffer cast to a char byte array.
Definition: AttributeArray.h:331
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:514
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218
Definition: AttributeArray.h:492
uint8_t mUsePagedRead
Definition: AttributeArray.h:368
streaming mode collapses attributes when first accessed
Definition: AttributeArray.h:107
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:1964
Base class for storing attribute data.
Definition: AttributeArray.h:93