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>
52 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
59 template <
typename FloatT,
typename IntegerT>
63 static_assert(std::is_unsigned<IntegerT>::value,
"IntegerT must be unsigned");
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()));
96 template <
typename T>
struct Accessor;
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;
147 #if OPENVDB_ABI_VERSION_NUMBER < 10
199 #if OPENVDB_ABI_VERSION_NUMBER >= 10
211 bool constantStride =
true,
223 template<
typename AttributeArrayType>
224 bool isType()
const {
return this->type() == AttributeArrayType::attributeType(); }
227 template<
typename ValueType>
228 bool hasValueType()
const {
return this->type().first == typeNameAsString<ValueType>(); }
230 #if OPENVDB_ABI_VERSION_NUMBER < 10
262 template<
typename IterT>
263 void copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter);
267 template<
typename IterT>
268 void copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
bool compact =
true);
274 virtual void expand(
bool fill =
true) = 0;
280 #if OPENVDB_ABI_VERSION_NUMBER < 10
285 virtual bool compress() = 0;
290 virtual bool decompress() = 0;
299 bool isHidden()
const {
return bool(mFlags & HIDDEN); }
320 uint8_t
flags()
const {
return mFlags; }
323 virtual void read(std::istream&) = 0;
326 virtual void write(std::ostream&,
bool outputTransient)
const = 0;
328 virtual void write(std::ostream&)
const = 0;
335 virtual void writeMetadata(std::ostream&,
bool outputTransient,
bool paged)
const = 0;
341 virtual void writeBuffers(std::ostream&,
bool outputTransient)
const = 0;
361 #if OPENVDB_ABI_VERSION_NUMBER >= 9
367 friend class ::TestAttributeArray;
374 virtual char* dataAsByteArray() = 0;
375 virtual const char* dataAsByteArray()
const = 0;
378 template <
typename IterT>
379 void doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
380 bool rangeChecking =
true);
398 bool mIsUniform =
true;
401 uint8_t mUsePagedRead = 0;
419 template <
typename T>
427 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
439 namespace attribute_traits
471 template <
typename T>
474 template<
typename ValueType>
static void decode(
const ValueType&, ValueType&);
475 template<
typename ValueType>
static void encode(
const ValueType&, ValueType&);
476 static const char*
name() {
return "null"; }
482 template <
typename T>
485 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
486 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
487 static const char*
name() {
return "trnc"; }
494 static const char*
name() {
return "fxpt"; }
495 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value + ValueType(0.5); }
496 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value - ValueType(0.5); }
503 static const char*
name() {
return "ufxpt"; }
504 template <
typename ValueType>
static ValueType
encode(
const ValueType& value) {
return value; }
505 template <
typename ValueType>
static ValueType
decode(
const ValueType& value) {
return value; }
509 template <
bool OneByte,
typename Range=PositionRange>
512 template <
typename T>
515 template<
typename StorageType,
typename ValueType>
static void decode(
const StorageType&, ValueType&);
516 template<
typename StorageType,
typename ValueType>
static void encode(
const ValueType&, StorageType&);
519 static const std::string
Name = std::string(Range::name()) + (OneByte ?
"8" :
"16");
529 template <
typename T>
534 static const char*
name() {
return "uvec"; }
543 template<
typename ValueType_,
typename Codec_ = NullCodec>
547 using Ptr = std::shared_ptr<TypedAttributeArray>;
548 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
552 using StorageType =
typename Codec::template Storage<ValueType>::Type;
558 const ValueType& uniformValue = zeroVal<ValueType>());
567 #if OPENVDB_ABI_VERSION_NUMBER < 10
587 #if OPENVDB_ABI_VERSION_NUMBER < 10
595 static Ptr create(
Index n,
Index strideOrTotalSize = 1,
bool constantStride =
true,
596 const Metadata* metadata =
nullptr);
605 static const NamePair& attributeType();
610 static bool isRegistered();
612 static void registerType();
614 static void unregisterType();
621 Index stride()
const override {
return hasConstantStride() ? mStrideOrTotalSize : 0; }
625 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
642 bool valueTypeIsFloatingPoint()
const override;
645 bool valueTypeIsClass()
const override;
648 bool valueTypeIsVector()
const override;
651 bool valueTypeIsQuaternion()
const override;
654 bool valueTypeIsMatrix()
const override;
659 #if OPENVDB_ABI_VERSION_NUMBER >= 10
668 ValueType getUnsafe(
Index n)
const;
670 ValueType get(
Index n)
const;
672 template<
typename T>
void getUnsafe(
Index n, T& value)
const;
674 template<
typename T>
void get(
Index n, T& value)
const;
681 void setUnsafe(
Index n,
const ValueType& value);
683 void set(
Index n,
const ValueType& value);
685 template<
typename T>
void setUnsafe(
Index n,
const T& value);
687 template<
typename T>
void set(
Index n,
const T& value);
693 #if OPENVDB_ABI_VERSION_NUMBER < 10
704 void expand(
bool fill =
true)
override;
706 void collapse()
override;
708 bool compact()
override;
711 void collapse(
const ValueType& uniformValue);
714 void fill(
const ValueType& value);
717 static void collapse(
AttributeArray* array,
const ValueType& value);
721 #if OPENVDB_ABI_VERSION_NUMBER < 10
724 bool compress() override;
727 bool decompress() override;
731 void read(std::istream&)
override;
735 void write(std::ostream& os,
bool outputTransient)
const override;
737 void write(std::ostream&)
const override;
740 void readMetadata(std::istream&)
override;
745 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
748 void readBuffers(std::istream&)
override;
752 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
762 inline bool isOutOfCore()
const;
765 void loadData()
const override;
768 bool isDataLoaded()
const override;
774 AccessorBasePtr getAccessor()
const override;
781 inline bool validData()
const {
return !(isOutOfCore() || (flags() & PARTIALREAD)); }
784 friend class ::TestAttributeArray;
789 inline void doLoad()
const;
791 #if OPENVDB_ABI_VERSION_NUMBER >= 10
792 inline void doLoadUnsafe()
const;
795 inline void doLoadUnsafe(
const bool compression =
true)
const;
797 inline bool compressUnsafe();
801 inline void setOutOfCore(
const bool);
807 char* dataAsByteArray()
override;
808 const char* dataAsByteArray()
const override;
810 size_t arrayMemUsage()
const;
817 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride, metadata);
820 std::unique_ptr<StorageType[]> mData;
822 Index mStrideOrTotalSize;
831 template <
typename ValueType,
typename CodecType = UnknownCodec>
836 using Ptr = std::shared_ptr<Handle>;
875 friend class ::TestAttributeArray;
877 template <
bool IsUnknownCodec>
878 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType()
const;
880 template <
bool IsUnknownCodec>
881 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType()
const;
883 template <
bool IsUnknownCodec>
884 typename std::enable_if<IsUnknownCodec, ValueType>::type get(
Index index)
const;
886 template <
bool IsUnknownCodec>
887 typename std::enable_if<!IsUnknownCodec, ValueType>::type get(
Index index)
const;
892 Index mStrideOrTotalSize;
894 bool mCollapseOnDestruction;
902 template <
typename ValueType,
typename CodecType = UnknownCodec>
907 using Ptr = std::shared_ptr<Handle>;
929 void fill(
const ValueType& value);
937 friend class ::TestAttributeArray;
939 template <
bool IsUnknownCodec>
940 typename std::enable_if<IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
942 template <
bool IsUnknownCodec>
943 typename std::enable_if<!IsUnknownCodec, void>::type set(
Index index,
const ValueType& value)
const;
953 template<
typename ValueType>
955 NullCodec::decode(
const ValueType& data, ValueType& val)
961 template<
typename ValueType>
963 NullCodec::encode(
const ValueType& val, ValueType& data)
969 template<
typename StorageType,
typename ValueType>
971 TruncateCodec::decode(
const StorageType& data, ValueType& val)
973 val =
static_cast<ValueType
>(data);
977 template<
typename StorageType,
typename ValueType>
979 TruncateCodec::encode(
const ValueType& val, StorageType& data)
981 data =
static_cast<StorageType
>(val);
985 template <
bool OneByte,
typename Range>
986 template<
typename StorageType,
typename ValueType>
990 val = fixedPointToFloatingPoint<ValueType>(data);
994 val = Range::template decode<ValueType>(val);
998 template <
bool OneByte,
typename Range>
999 template<
typename StorageType,
typename ValueType>
1005 const ValueType newVal = Range::template encode<ValueType>(val);
1007 data = floatingPointToFixedPoint<StorageType>(newVal);
1011 template<
typename T>
1015 val = math::QuantizedUnitVec::unpack(data);
1019 template<
typename T>
1023 data = math::QuantizedUnitVec::pack(val);
1031 template <
typename IterT>
1032 void AttributeArray::doCopyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1038 assert(sourceArray.
isDataLoaded() && this->isDataLoaded());
1040 assert(this->storageTypeSize()*this->stride() ==
1044 const char*
const sourceBuffer = sourceArray.dataAsByteArray();
1045 char*
const targetBuffer = this->dataAsByteArray();
1046 assert(sourceBuffer && targetBuffer);
1048 if (rangeChecking && this->isUniform()) {
1052 const bool sourceIsUniform = sourceArray.
isUniform();
1054 const Index sourceDataSize = rangeChecking ? sourceArray.
dataSize() : 0;
1055 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1057 for (IterT it(iter); it; ++it) {
1058 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1059 const Index targetIndex = it.targetIndex();
1061 if (rangeChecking) {
1062 if (sourceIndex >= sourceDataSize) {
1064 "Cannot copy array data as source index exceeds size of source array.");
1066 if (targetIndex >= targetDataSize) {
1068 "Cannot copy array data as target index exceeds size of target array.");
1072 assert(sourceIndex < sourceArray.
dataSize());
1073 assert(targetIndex < this->dataSize());
1074 if (this->isUniform()) assert(targetIndex ==
Index(0));
1077 const size_t targetOffset(targetIndex * bytes);
1078 const size_t sourceOffset(sourceIndex * bytes);
1080 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1084 template <
typename IterT>
1085 void AttributeArray::copyValuesUnsafe(
const AttributeArray& sourceArray,
const IterT& iter)
1087 this->doCopyValues(sourceArray, iter,
false);
1090 template <
typename IterT>
1091 void AttributeArray::copyValues(
const AttributeArray& sourceArray,
const IterT& iter,
1095 if (bytes != this->storageTypeSize()) {
1112 this->doCopyValues(sourceArray, iter,
true);
1126 template<
typename ValueType_,
typename Codec_>
1132 , mStrideOrTotalSize(strideOrTotalSize)
1134 if (constantStride) {
1136 if (strideOrTotalSize == 0) {
1138 "stride to be at least one.")
1143 if (mStrideOrTotalSize < n) {
1145 "a total size of at least the number of elements in the array.")
1149 mStrideOrTotalSize =
std::max(
Index(1), mStrideOrTotalSize);
1150 Codec::encode(uniformValue, this->
data()[0]);
1154 template<
typename ValueType_,
typename Codec_>
1161 template<
typename ValueType_,
typename Codec_>
1163 const tbb::spin_mutex::scoped_lock& lock)
1166 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1170 std::memcpy(
static_cast<void*
>(this->
data()), rhs.
data(), this->arrayMemUsage());
1175 template<
typename ValueType_,
typename Codec_>
1176 TypedAttributeArray<ValueType_, Codec_>&
1181 tbb::spin_mutex::scoped_lock lock(mMutex);
1182 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1189 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1192 if (this->validData()) {
1194 std::memcpy(
static_cast<void*
>(this->data()), rhs.
data(), this->arrayMemUsage());
1202 template<
typename ValueType_,
typename Codec_>
1207 return NamePair(typeNameAsString<ValueType>(), Codec::name());
1213 template<
typename ValueType_,
typename Codec_>
1221 template<
typename ValueType_,
typename Codec_>
1229 template<
typename ValueType_,
typename Codec_>
1237 template<
typename ValueType_,
typename Codec_>
1246 typedMetadata ? typedMetadata->
value() : zeroVal<ValueType>()));
1249 template<
typename ValueType_,
typename Codec_>
1259 template<
typename ValueType_,
typename Codec_>
1269 template<
typename ValueType_,
typename Codec_>
1277 #if OPENVDB_ABI_VERSION_NUMBER < 10
1278 template<
typename ValueType_,
typename Codec_>
1282 return this->copy();
1286 template<
typename ValueType_,
typename Codec_>
1288 TypedAttributeArray<ValueType_, Codec_>::arrayMemUsage()
const
1290 if (this->isOutOfCore())
return 0;
1292 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1296 template<
typename ValueType_,
typename Codec_>
1298 TypedAttributeArray<ValueType_, Codec_>::allocate()
1302 mData.reset(
new StorageType[1]);
1305 const size_t size(this->dataSize());
1307 mData.reset(
new StorageType[size]);
1312 template<
typename ValueType_,
typename Codec_>
1314 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1317 if (this->isOutOfCore()) {
1318 this->setOutOfCore(
false);
1319 this->mPageHandle.reset();
1321 if (mData) mData.reset();
1325 template<
typename ValueType_,
typename Codec_>
1331 if (std::is_same<ValueType, Quats>::value ||
1332 std::is_same<ValueType, Quatd>::value ||
1333 std::is_same<ValueType, Mat3s>::value ||
1334 std::is_same<ValueType, Mat3d>::value ||
1335 std::is_same<ValueType, Mat4s>::value ||
1336 std::is_same<ValueType, Mat4d>::value)
return true;
1341 return std::is_floating_point<ElementT>::value || std::is_same<math::half, ElementT>::value;
1345 template<
typename ValueType_,
typename Codec_>
1350 return std::is_class<ValueType>::value && !std::is_same<math::half, ValueType>::value;
1354 template<
typename ValueType_,
typename Codec_>
1362 template<
typename ValueType_,
typename Codec_>
1367 return !this->valueType().compare(0, 4,
"quat");
1371 template<
typename ValueType_,
typename Codec_>
1376 return !this->valueType().compare(0, 3,
"mat");
1380 template<
typename ValueType_,
typename Codec_>
1384 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1387 #if OPENVDB_ABI_VERSION_NUMBER >= 10
1388 template<
typename ValueType_,
typename Codec_>
1392 return sizeof(*this) + (mIsUniform ? 1 : this->dataSize()) *
sizeof(
StorageType);
1397 template<
typename ValueType_,
typename Codec_>
1401 assert(n < this->dataSize());
1404 Codec::decode(this->data()[mIsUniform ? 0 : n], val);
1409 template<
typename ValueType_,
typename Codec_>
1414 if (this->isOutOfCore()) this->doLoad();
1416 return this->getUnsafe(n);
1420 template<
typename ValueType_,
typename Codec_>
1421 template<
typename T>
1425 val =
static_cast<T
>(this->getUnsafe(n));
1429 template<
typename ValueType_,
typename Codec_>
1430 template<
typename T>
1434 val =
static_cast<T
>(this->get(n));
1438 template<
typename ValueType_,
typename Codec_>
1446 template<
typename ValueType_,
typename Codec_>
1450 assert(n < this->dataSize());
1451 assert(!this->isOutOfCore());
1452 assert(!this->isUniform());
1457 Codec::encode(val, this->data()[mIsUniform ? 0 : n]);
1461 template<
typename ValueType_,
typename Codec_>
1466 if (this->isOutOfCore()) this->doLoad();
1467 if (this->isUniform()) this->expand();
1469 this->setUnsafe(n, val);
1473 template<
typename ValueType_,
typename Codec_>
1474 template<
typename T>
1478 this->setUnsafe(n,
static_cast<ValueType>(val));
1482 template<
typename ValueType_,
typename Codec_>
1483 template<
typename T>
1487 this->set(n,
static_cast<ValueType>(val));
1491 template<
typename ValueType_,
typename Codec_>
1499 #if OPENVDB_ABI_VERSION_NUMBER < 10
1500 template<
typename ValueType_,
typename Codec_>
1506 ValueType sourceValue;
1507 sourceTypedArray.
get(sourceIndex, sourceValue);
1509 this->set(n, sourceValue);
1514 template<
typename ValueType_,
typename Codec_>
1518 if (!mIsUniform)
return;
1523 tbb::spin_mutex::scoped_lock lock(mMutex);
1530 for (
Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1535 template<
typename ValueType_,
typename Codec_>
1539 if (mIsUniform)
return true;
1542 const ValueType_ val = this->get(0);
1543 for (
Index i = 1; i < this->dataSize(); i++) {
1547 this->collapse(this->get(0));
1552 template<
typename ValueType_,
typename Codec_>
1556 this->collapse(zeroVal<ValueType>());
1560 template<
typename ValueType_,
typename Codec_>
1565 tbb::spin_mutex::scoped_lock lock(mMutex);
1570 Codec::encode(uniformValue, this->data()[0]);
1574 template<
typename ValueType_,
typename Codec_>
1582 template<
typename ValueType_,
typename Codec_>
1586 if (this->isOutOfCore()) {
1587 tbb::spin_mutex::scoped_lock lock(mMutex);
1592 const Index size = mIsUniform ? 1 : this->dataSize();
1593 for (
Index i = 0; i < size; ++i) {
1594 Codec::encode(value, this->data()[i]);
1599 template<
typename ValueType_,
typename Codec_>
1607 #if OPENVDB_ABI_VERSION_NUMBER < 10
1608 template<
typename ValueType_,
typename Codec_>
1616 template<
typename ValueType_,
typename Codec_>
1618 TypedAttributeArray<ValueType_, Codec_>::compressUnsafe()
1624 template<
typename ValueType_,
typename Codec_>
1626 TypedAttributeArray<ValueType_, Codec_>::decompress()
1633 template<
typename ValueType_,
typename Codec_>
1641 template<
typename ValueType_,
typename Codec_>
1649 template<
typename ValueType_,
typename Codec_>
1651 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1653 if (!(this->isOutOfCore()))
return;
1655 TypedAttributeArray<ValueType_, Codec_>*
self =
1656 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1660 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1661 this->doLoadUnsafe();
1665 template<
typename ValueType_,
typename Codec_>
1673 template<
typename ValueType_,
typename Codec_>
1677 return !this->isOutOfCore();
1681 template<
typename ValueType_,
typename Codec_>
1685 this->readMetadata(is);
1686 this->readBuffers(is);
1690 template<
typename ValueType_,
typename Codec_>
1697 is.read(
reinterpret_cast<char*
>(&bytes),
sizeof(
Index64));
1698 bytes = bytes -
sizeof(
Int16) -
sizeof(
Index);
1700 uint8_t flags = uint8_t(0);
1701 is.read(
reinterpret_cast<char*
>(&flags),
sizeof(uint8_t));
1704 uint8_t serializationFlags = uint8_t(0);
1705 is.read(
reinterpret_cast<char*
>(&serializationFlags),
sizeof(uint8_t));
1708 is.read(
reinterpret_cast<char*
>(&size),
sizeof(
Index));
1712 if (mFlags >= 0x20) {
1717 if (serializationFlags >= 0x10) {
1723 mIsUniform = serializationFlags & WRITEUNIFORM;
1724 mUsePagedRead = serializationFlags & WRITEPAGED;
1725 mCompressedBytes = bytes;
1726 mFlags |= PARTIALREAD;
1730 if (serializationFlags & WRITESTRIDED) {
1732 is.read(
reinterpret_cast<char*
>(&stride),
sizeof(
Index));
1733 mStrideOrTotalSize = stride;
1736 mStrideOrTotalSize = 1;
1741 template<
typename ValueType_,
typename Codec_>
1745 if (mUsePagedRead) {
1750 tbb::spin_mutex::scoped_lock lock(mMutex);
1754 uint8_t bloscCompressed(0);
1755 if (!mIsUniform) is.read(
reinterpret_cast<char*
>(&bloscCompressed),
sizeof(uint8_t));
1757 assert(mFlags & PARTIALREAD);
1758 std::unique_ptr<char[]> buffer(
new char[mCompressedBytes]);
1759 is.read(buffer.get(), mCompressedBytes);
1760 mCompressedBytes = 0;
1761 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1765 if (bloscCompressed == uint8_t(1)) {
1769 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1771 if (newBuffer) buffer.reset(newBuffer.release());
1776 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1780 template<
typename ValueType_,
typename Codec_>
1784 if (!mUsePagedRead) {
1789 #ifdef OPENVDB_USE_DELAYED_LOADING
1792 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is.
getInputStream());
1793 const bool delayLoad = (mappedFile.get() !=
nullptr);
1798 size_t compressedBytes(mCompressedBytes);
1799 mCompressedBytes = 0;
1800 mFlags =
static_cast<uint8_t
>(mFlags & ~PARTIALREAD);
1801 assert(!mPageHandle);
1806 assert(mPageHandle);
1808 tbb::spin_mutex::scoped_lock lock(mMutex);
1812 #ifdef OPENVDB_USE_DELAYED_LOADING
1813 this->setOutOfCore(delayLoad);
1814 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1816 is.
read(mPageHandle, std::streamsize(mPageHandle->size()),
false);
1819 #ifdef OPENVDB_USE_DELAYED_LOADING
1822 std::unique_ptr<char[]> buffer = mPageHandle->read();
1823 mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1824 mPageHandle.reset();
1825 #ifdef OPENVDB_USE_DELAYED_LOADING
1835 template<
typename ValueType_,
typename Codec_>
1839 this->
write(os,
false);
1843 template<
typename ValueType_,
typename Codec_>
1847 this->writeMetadata(os, outputTransient,
false);
1848 this->writeBuffers(os, outputTransient);
1852 template<
typename ValueType_,
typename Codec_>
1856 if (!outputTransient && this->isTransient())
return;
1858 if (mFlags & PARTIALREAD) {
1862 uint8_t flags(mFlags);
1863 uint8_t serializationFlags(0);
1865 Index strideOrTotalSize(mStrideOrTotalSize);
1866 bool strideOfOne(this->stride() == 1);
1871 if (bloscCompression) this->doLoad();
1873 size_t compressedBytes = 0;
1877 serializationFlags |= WRITESTRIDED;
1882 serializationFlags |= WRITEUNIFORM;
1883 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1885 else if (bloscCompression)
1887 if (paged) serializationFlags |= WRITEPAGED;
1889 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1890 const size_t inBytes = this->arrayMemUsage();
1897 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1901 os.write(
reinterpret_cast<const char*
>(&bytes),
sizeof(
Index64));
1902 os.write(
reinterpret_cast<const char*
>(&flags),
sizeof(uint8_t));
1903 os.write(
reinterpret_cast<const char*
>(&serializationFlags),
sizeof(uint8_t));
1904 os.write(
reinterpret_cast<const char*
>(&size),
sizeof(
Index));
1907 if (!strideOfOne) os.write(
reinterpret_cast<const char*
>(&strideOrTotalSize),
sizeof(
Index));
1911 template<
typename ValueType_,
typename Codec_>
1915 if (!outputTransient && this->isTransient())
return;
1917 if (mFlags & PARTIALREAD) {
1923 if (this->isUniform()) {
1924 os.write(
reinterpret_cast<const char*
>(this->data()),
sizeof(
StorageType));
1928 std::unique_ptr<char[]> compressedBuffer;
1929 size_t compressedBytes = 0;
1930 const char* charBuffer =
reinterpret_cast<const char*
>(this->data());
1931 const size_t inBytes = this->arrayMemUsage();
1933 if (compressedBuffer) {
1934 uint8_t bloscCompressed(1);
1935 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1936 os.write(
reinterpret_cast<const char*
>(compressedBuffer.get()), compressedBytes);
1939 uint8_t bloscCompressed(0);
1940 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1941 os.write(
reinterpret_cast<const char*
>(this->data()), inBytes);
1946 uint8_t bloscCompressed(0);
1947 os.write(
reinterpret_cast<const char*
>(&bloscCompressed),
sizeof(uint8_t));
1948 os.write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1953 template<
typename ValueType_,
typename Codec_>
1957 if (!outputTransient && this->isTransient())
return;
1961 if (!bloscCompression) {
1966 if (mFlags & PARTIALREAD) {
1972 os.
write(
reinterpret_cast<const char*
>(this->data()), this->arrayMemUsage());
1976 template<
typename ValueType_,
typename Codec_>
1978 #if OPENVDB_ABI_VERSION_NUMBER >= 10
1984 if (!(this->isOutOfCore()))
return;
1990 assert(self->mPageHandle);
1991 assert(!(self->mFlags & PARTIALREAD));
1993 std::unique_ptr<char[]> buffer =
self->mPageHandle->read();
1995 self->mData.reset(
reinterpret_cast<StorageType*
>(buffer.release()));
1997 self->mPageHandle.reset();
2001 self->mOutOfCore =
false;
2005 template<
typename ValueType_,
typename Codec_>
2020 template<
typename ValueType_,
typename Codec_>
2025 if(!otherT)
return false;
2026 if(this->mSize != otherT->mSize ||
2027 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
2029 this->attributeType() != this->attributeType())
return false;
2034 const StorageType *target = this->data(), *source = otherT->
data();
2035 if (!target && !source)
return true;
2036 if (!target || !source)
return false;
2037 Index n = this->mIsUniform ? 1 : mSize;
2043 template<
typename ValueType_,
typename Codec_>
2045 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2047 return reinterpret_cast<char*
>(this->data());
2051 template<
typename ValueType_,
typename Codec_>
2053 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
2055 return reinterpret_cast<const char*
>(this->data());
2063 template <
typename CodecType,
typename ValueType>
2084 template <
typename ValueType>
2092 return (*functor)(array, n);
2097 (*functor)(array, n, value);
2106 template <
typename ValueType,
typename CodecType>
2114 template <
typename ValueType,
typename CodecType>
2117 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2118 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2119 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2121 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2142 template <
typename ValueType,
typename CodecType>
2146 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
2149 template <
typename ValueType,
typename CodecType>
2150 template <
bool IsUnknownCodec>
2151 typename std::enable_if<IsUnknownCodec, bool>::type
2156 return mArray->hasValueType<ValueType>();
2159 template <
typename ValueType,
typename CodecType>
2160 template <
bool IsUnknownCodec>
2161 typename std::enable_if<!IsUnknownCodec, bool>::type
2162 AttributeHandle<ValueType, CodecType>::compatibleType()
const
2166 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2169 template <
typename ValueType,
typename CodecType>
2176 template <
typename ValueType,
typename CodecType>
2179 Index index = n * mStrideOrTotalSize + m;
2180 assert(index < (mSize * mStrideOrTotalSize));
2184 template <
typename ValueType,
typename CodecType>
2187 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2190 template <
typename ValueType,
typename CodecType>
2191 template <
bool IsUnknownCodec>
2192 typename std::enable_if<IsUnknownCodec, ValueType>::type
2197 return (*mGetter)(mArray, index);
2200 template <
typename ValueType,
typename CodecType>
2201 template <
bool IsUnknownCodec>
2202 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2210 template <
typename ValueType,
typename CodecType>
2213 return mArray->isUniform();
2216 template <
typename ValueType,
typename CodecType>
2219 return mArray->hasConstantStride();
2226 template <
typename ValueType,
typename CodecType>
2234 template <
typename ValueType,
typename CodecType>
2241 template <
typename ValueType,
typename CodecType>
2244 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2247 template <
typename ValueType,
typename CodecType>
2250 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2253 template <
typename ValueType,
typename CodecType>
2259 template <
typename ValueType,
typename CodecType>
2265 template <
typename ValueType,
typename CodecType>
2271 template <
typename ValueType,
typename CodecType>
2274 this->mCollapser(
const_cast<AttributeArray*
>(this->mArray), uniformValue);
2277 template <
typename ValueType,
typename CodecType>
2283 template <
typename ValueType,
typename CodecType>
2284 template <
bool IsUnknownCodec>
2285 typename std::enable_if<IsUnknownCodec, void>::type
2290 (*this->mSetter)(
const_cast<AttributeArray*
>(this->mArray), index, value);
2293 template <
typename ValueType,
typename CodecType>
2294 template <
bool IsUnknownCodec>
2295 typename std::enable_if<!IsUnknownCodec, void>::type
2303 template <
typename ValueType,
typename CodecType>
2306 assert(this->mArray);
Convenience wrappers to using Blosc and reading and writing of Paged data.
Definition: Exceptions.h:57
Definition: Exceptions.h:58
Definition: Exceptions.h:64
Definition: Exceptions.h:65
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:172
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:207
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
bool sizeOnly() const
Definition: StreamCompression.h:217
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...
std::istream & getInputStream()
Definition: StreamCompression.h:220
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:244
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:257
bool sizeOnly() const
Definition: StreamCompression.h:254
T & y()
Definition: Vec3.h:86
T & z()
Definition: Vec3.h:87
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:85
Definition: AttributeArray.h:119
Base class for storing attribute data.
Definition: AttributeArray.h:93
virtual Name valueType() const =0
Return the name of the value type of a single element in this array (e.g., "float" or "vec3d").
AttributeArray(const AttributeArray &rhs, const tbb::spin_mutex::scoped_lock &)
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
static Ptr create(const NamePair &type, Index length, Index stride=1, bool constantStride=true, const Metadata *metadata=nullptr, const ScopedRegistryLock *lock=nullptr)
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:306
SerializationFlag
Definition: AttributeArray.h:109
virtual Index dataSize() const =0
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
virtual void readBuffers(std::istream &)=0
Read attribute buffers from a stream.
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
const char * constDataAsByteArray() const
Indirect virtual function to retrieve the data buffer cast to a char byte array.
Definition: AttributeArray.h:363
virtual ~AttributeArray()
Definition: AttributeArray.h:133
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:405
AttributeArray & operator=(const AttributeArray &rhs)
Flag
Definition: AttributeArray.h:101
AttributeArray()
Definition: AttributeArray.h:132
virtual Index stride() const =0
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:299
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:224
virtual const NamePair & type() const =0
Return the name of this attribute's type.
virtual bool valueTypeIsQuaternion() const =0
Return true if the value type is a quaternion.
virtual bool valueTypeIsVector() const =0
Return true if the value type is a vector.
uint8_t mFlags
Definition: AttributeArray.h:400
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
void setStreaming(bool state)
Specify whether this attribute is to be streamed off disk, in which case, the attributes are collapse...
AttributeArray(const AttributeArray &rhs)
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:320
AttributeArray & operator=(AttributeArray &&)=delete
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:228
std::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:402
virtual void writeBuffers(std::ostream &, bool outputTransient) const =0
static void clearRegistry(const ScopedRegistryLock *lock=nullptr)
Clear the attribute type registry.
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:98
virtual Index size() const =0
void setTransient(bool state)
Specify whether this attribute should only exist in memory and not be serialized during stream output...
virtual void read(std::istream &)=0
Read attribute metadata and buffers from a stream.
void setHidden(bool state)
Specify whether this attribute should be hidden (e.g., from UI or iterators).
virtual void write(std::ostream &, bool outputTransient) const =0
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
virtual bool valueTypeIsClass() const =0
Return true if the value type is a class (ie vector, matrix or quaternion return true)
virtual void loadData() const =0
Ensures all data is in-core.
uint8_t mUsePagedRead
Definition: AttributeArray.h:401
virtual bool valueTypeIsMatrix() const =0
Return true if the value type is a matrix.
bool operator==(const AttributeArray &other) const
tbb::spin_mutex mMutex
Definition: AttributeArray.h:399
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:359
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:314
virtual void writeMetadata(std::ostream &, bool outputTransient, bool paged) const =0
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition: AttributeArray.h:128
virtual Name codecType() const =0
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
virtual size_t memUsageIfLoaded() const =0
virtual void readMetadata(std::istream &)=0
Read attribute metadata from a stream.
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:126
virtual void collapse()=0
Replace the existing array with a uniform zero value.
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
virtual Index storageTypeSize() const =0
virtual void write(std::ostream &) const =0
Write attribute metadata and buffers to a stream, don't write transient attributes.
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
virtual AttributeArray::Ptr copy() const =0
Return a copy of this attribute.
virtual Index valueTypeSize() const =0
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:317
size_t mCompressedBytes
Definition: AttributeArray.h:406
bool mIsUniform
Definition: AttributeArray.h:398
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
virtual size_t memUsage() const =0
Return the number of bytes of memory used by this attribute.
AttributeArray(AttributeArray &&)=delete
Definition: AttributeArray.h:833
virtual ~AttributeHandle()
Definition: AttributeArray.h:2143
Index size() const
Definition: AttributeArray.h:855
void(*)(AttributeArray *array, const ValueType &value) ValuePtr
Definition: AttributeArray.h:842
SetterPtr mSetter
Definition: AttributeArray.h:870
Index stride() const
Definition: AttributeArray.h:854
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:836
GetterPtr mGetter
Definition: AttributeArray.h:869
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:841
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2108
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2115
AttributeHandle & operator=(const AttributeHandle &)=default
ValuePtr mFiller
Definition: AttributeArray.h:872
ValueType get(Index n, Index m=0) const
Definition: AttributeArray.h:2185
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:840
AttributeHandle(const AttributeHandle &)=default
ValuePtr mCollapser
Definition: AttributeArray.h:871
const AttributeArray & array() const
Definition: AttributeArray.h:2170
const AttributeArray * mArray
Definition: AttributeArray.h:867
bool isUniform() const
Definition: AttributeArray.h:2211
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:837
bool hasConstantStride() const
Definition: AttributeArray.h:2217
Index index(Index n, Index m) const
Definition: AttributeArray.h:2177
Write-able version of AttributeHandle.
Definition: AttributeArray.h:904
virtual ~AttributeWriteHandle()=default
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2235
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:907
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2266
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2260
void set(Index n, const ValueType &value)
Definition: AttributeArray.h:2242
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2254
AttributeArray & array()
Definition: AttributeArray.h:2304
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:908
static Ptr create(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2228
void set(Index n, Index m, const ValueType &value)
Definition: AttributeArray.h:2248
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:2278
void collapse(const ValueType &uniformValue)
Definition: AttributeArray.h:2272
Typed class for storing attribute data.
Definition: AttributeArray.h:545
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:635
size_t memUsageIfLoaded() const override
Definition: AttributeArray.h:1390
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition: AttributeArray.h:1399
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:700
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1743
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:547
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:2007
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1845
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:552
const StorageType * constData() const
Return the raw data buffer.
Definition: AttributeArray.h:771
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1382
const StorageType * data() const
Definition: AttributeArray.h:778
ValueType_ ValueType
Definition: AttributeArray.h:550
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:1127
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1675
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1635
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1356
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:781
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1537
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1251
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:607
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1913
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1271
Index storageTypeSize() const override
Definition: AttributeArray.h:639
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1364
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1782
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1463
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1177
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1223
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1327
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1854
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1231
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1667
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1683
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1411
TypedAttributeArray(TypedAttributeArray &&)=delete
Move constructor disabled.
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1204
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1347
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:617
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1554
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:624
Codec_ Codec
Definition: AttributeArray.h:551
~TypedAttributeArray() override
Definition: AttributeArray.h:581
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1516
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1215
TypedAttributeArray & operator=(TypedAttributeArray &&)=delete
Move assignment operator disabled.
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1373
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1584
Index stride() const override
Definition: AttributeArray.h:621
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:777
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:1239
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:632
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1955
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:629
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition: AttributeArray.h:1448
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1692
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:256
static fileSize_t write(std::ostream &os, const GridHandle< BufferT > &handle, Codec codec, uint32_t n)
static void read(std::istream &is, BufferT &buffer, Codec codec)
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.
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...
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
@ COMPRESS_BLOSC
Definition: Compression.h:56
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:443
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:473
internal::half half
Definition: Types.h:29
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:79
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:69
std::string Name
Definition: Name.h:19
Index32 Index
Definition: Types.h:54
int16_t Int16
Definition: Types.h:55
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
uint64_t Index64
Definition: Types.h:53
Definition: Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t *poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
Definition: pnanovdb_validate_strides.h:20
typename T::ValueType ElementType
Definition: Types.h:247
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2091
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2088
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2096
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2087
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2065
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2067
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2071
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2066
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2077
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:415
virtual ~AccessorBase()=default
Definition: AttributeArray.h:421
SetterPtr mSetter
Definition: AttributeArray.h:430
GetterPtr mGetter
Definition: AttributeArray.h:429
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:424
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:422
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:423
ValuePtr mFiller
Definition: AttributeArray.h:432
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:426
ValuePtr mCollapser
Definition: AttributeArray.h:431
Definition: AttributeArray.h:513
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:513
Definition: AttributeArray.h:511
static const char * name()
Definition: AttributeArray.h:518
Definition: AttributeArray.h:472
T Type
Definition: AttributeArray.h:472
Definition: AttributeArray.h:470
static const char * name()
Definition: AttributeArray.h:476
Definition: AttributeArray.h:493
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:496
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:495
static const char * name()
Definition: AttributeArray.h:494
Definition: AttributeArray.h:483
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:483
Definition: AttributeArray.h:481
static const char * name()
Definition: AttributeArray.h:487
Definition: AttributeArray.h:502
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:505
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:504
static const char * name()
Definition: AttributeArray.h:503
Definition: AttributeArray.h:530
StorageType Type
Definition: AttributeArray.h:530
Definition: AttributeArray.h:526
uint16_t StorageType
Definition: AttributeArray.h:527
static const char * name()
Definition: AttributeArray.h:534
Definition: AttributeArray.h:466
short Type
Definition: AttributeArray.h:443
Definition: AttributeArray.h:441
uint16_t Type
Definition: AttributeArray.h:451
uint8_t Type
Definition: AttributeArray.h:450
Definition: AttributeArray.h:449
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212