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>
60 template <
typename FloatT,
typename IntegerT>
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;
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;
202 bool constantStride =
true,
204 const ScopedRegistryLock* lock =
nullptr);
207 static bool isRegistered(
const NamePair&
type,
const ScopedRegistryLock* lock =
nullptr);
209 static void clearRegistry(
const ScopedRegistryLock* lock =
nullptr);
214 template<
typename AttributeArrayType>
215 bool isType()
const {
return this->
type() == AttributeArrayType::attributeType(); }
218 template<
typename 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);
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);
365 bool mIsUniform =
true;
368 uint8_t mUsePagedRead = 0;
386 template <
typename T>
406 namespace attribute_traits
438 template <
typename T>
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"; }
470 static const char*
name() {
return "ufxpt"; }
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>;
525 const ValueType& uniformValue = zeroVal<ValueType>());
551 const Metadata* metadata =
nullptr);
669 void read(std::istream&)
override;
673 void write(std::ostream& os,
bool outputTransient)
const override;
675 void write(std::ostream&)
const override;
683 void writeMetadata(std::ostream& os,
bool outputTransient,
bool paged)
const override;
690 void writeBuffers(std::ostream& os,
bool outputTransient)
const override;
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;
751 std::unique_ptr<StorageType[]> mData;
753 Index mStrideOrTotalSize;
762 template <
typename ValueType,
typename CodecType = UnknownCodec>
767 using Ptr = std::shared_ptr<Handle>;
806 friend class ::TestAttributeArray;
808 template <
bool IsUnknownCodec>
811 template <
bool IsUnknownCodec>
814 template <
bool IsUnknownCodec>
817 template <
bool IsUnknownCodec>
823 Index mStrideOrTotalSize;
825 bool mCollapseOnDestruction;
833 template <
typename ValueType,
typename CodecType = UnknownCodec>
838 using Ptr = std::shared_ptr<Handle>;
868 friend class ::TestAttributeArray;
870 template <
bool IsUnknownCodec>
873 template <
bool IsUnknownCodec>
884 template<
typename ValueType>
892 template<
typename ValueType>
900 template<
typename StorageType,
typename ValueType>
908 template<
typename StorageType,
typename ValueType>
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);
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()) {
980 OPENVDB_THROW(IndexError,
"Cannot copy array data as target array is uniform.");
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>
1018 this->doCopyValues(sourceArray, iter,
false);
1021 template <
typename IterT>
1027 OPENVDB_THROW(TypeError,
"Cannot copy array data due to mis-match in storage type sizes.");
1043 this->doCopyValues(sourceArray, iter,
true);
1057 template<
typename ValueType_,
typename Codec_>
1063 , mStrideOrTotalSize(strideOrTotalSize)
1065 if (constantStride) {
1067 if (strideOrTotalSize == 0) {
1068 OPENVDB_THROW(ValueError,
"Creating a TypedAttributeArray with a constant stride requires that " \
1069 "stride to be at least one.")
1074 if (mStrideOrTotalSize < n) {
1075 OPENVDB_THROW(ValueError,
"Creating a TypedAttributeArray with a non-constant stride must have " \
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_>
1107 TypedAttributeArray<ValueType_, Codec_>&
1112 tbb::spin_mutex::scoped_lock lock(mMutex);
1113 tbb::spin_mutex::scoped_lock rhsLock(rhs.
mMutex);
1120 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1123 if (this->validData()) {
1125 std::memcpy(static_cast<void*>(this->
data()), rhs.
data(), this->arrayMemUsage());
1133 template<
typename ValueType_,
typename Codec_>
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_>
1212 if (this->isOutOfCore())
return 0;
1214 return (mIsUniform ? 1 : this->dataSize()) *
sizeof(StorageType);
1218 template<
typename ValueType_,
typename Codec_>
1220 TypedAttributeArray<ValueType_, Codec_>::allocate()
1224 mData.reset(
new StorageType[1]);
1227 const size_t size(this->dataSize());
1229 mData.reset(
new StorageType[
size]);
1234 template<
typename ValueType_,
typename Codec_>
1236 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1239 if (this->isOutOfCore()) {
1240 this->setOutOfCore(
false);
1241 this->mPageHandle.reset();
1243 if (mData) mData.reset();
1247 template<
typename ValueType_,
typename Codec_>
1267 template<
typename ValueType_,
typename Codec_>
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_>
1314 return sizeof(*this) + (mIsUniform ? 1 : this->dataSize()) *
sizeof(
StorageType);
1318 template<
typename ValueType_,
typename Codec_>
1325 Codec::decode(this->
data()[mIsUniform ? 0 : n], val);
1330 template<
typename ValueType_,
typename Codec_>
1334 if (n >= this->dataSize())
OPENVDB_THROW(IndexError,
"Out-of-range access.");
1335 if (this->isOutOfCore()) this->doLoad();
1337 return this->getUnsafe(n);
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_>
1378 Codec::encode(val, this->
data()[mIsUniform ? 0 : n]);
1382 template<
typename ValueType_,
typename Codec_>
1386 if (n >= this->dataSize())
OPENVDB_THROW(IndexError,
"Out-of-range access.");
1387 if (this->isOutOfCore()) this->doLoad();
1388 if (this->isUniform()) this->expand();
1390 this->setUnsafe(n, val);
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_>
1424 if (!mIsUniform)
return;
1429 tbb::spin_mutex::scoped_lock lock(mMutex);
1436 for (
Index i = 0; i < this->dataSize(); ++i) this->
data()[i] =
val;
1441 template<
typename ValueType_,
typename Codec_>
1445 if (mIsUniform)
return true;
1448 const ValueType_
val = this->
get(0);
1449 for (
Index i = 1; i < this->dataSize(); i++) {
1453 this->collapse(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_>
1492 if (this->isOutOfCore()) {
1493 tbb::spin_mutex::scoped_lock lock(mMutex);
1498 const Index size = mIsUniform ? 1 : this->dataSize();
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_>
1531 TypedAttributeArray<ValueType_, Codec_>::doLoad()
const
1533 if (!(this->isOutOfCore()))
return;
1535 TypedAttributeArray<ValueType_, Codec_>*
self =
1536 const_cast<TypedAttributeArray<ValueType_, Codec_>*
>(
this);
1540 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1541 this->doLoadUnsafe();
1545 template<
typename ValueType_,
typename Codec_>
1553 template<
typename ValueType_,
typename Codec_>
1557 return !this->isOutOfCore();
1561 template<
typename ValueType_,
typename Codec_>
1565 this->readMetadata(is);
1566 this->readBuffers(is);
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) {
1598 OPENVDB_THROW(IoError,
"Unknown attribute serialization flags for VDB file format.");
1603 mIsUniform = serializationFlags & WRITEUNIFORM;
1604 mUsePagedRead = serializationFlags & WRITEPAGED;
1605 mCompressedBytes = bytes;
1610 if (serializationFlags & WRITESTRIDED) {
1612 is.read(reinterpret_cast<char*>(&stride),
sizeof(
Index));
1613 mStrideOrTotalSize =
stride;
1616 mStrideOrTotalSize = 1;
1621 template<
typename ValueType_,
typename Codec_>
1625 if (mUsePagedRead) {
1627 OPENVDB_THROW(IoError,
"Cannot read paged AttributeArray buffers.");
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));
1638 std::unique_ptr<char[]>
buffer(
new char[mCompressedBytes]);
1639 is.read(buffer.get(), mCompressedBytes);
1640 mCompressedBytes = 0;
1645 if (bloscCompressed == uint8_t(1)) {
1649 const size_t inBytes = this->dataSize() *
sizeof(
StorageType);
1651 if (newBuffer) buffer.reset(newBuffer.release());
1656 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1660 template<
typename ValueType_,
typename Codec_>
1664 if (!mUsePagedRead) {
1669 #ifdef OPENVDB_USE_DELAYED_LOADING
1672 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is.
getInputStream());
1673 const bool delayLoad = (mappedFile.get() !=
nullptr);
1678 size_t compressedBytes(mCompressedBytes);
1679 mCompressedBytes = 0;
1688 tbb::spin_mutex::scoped_lock lock(mMutex);
1692 #ifdef OPENVDB_USE_DELAYED_LOADING
1693 this->setOutOfCore(delayLoad);
1694 is.
read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1696 is.
read(mPageHandle, std::streamsize(mPageHandle->size()),
false);
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()));
1704 mPageHandle.reset();
1705 #ifdef OPENVDB_USE_DELAYED_LOADING
1715 template<
typename ValueType_,
typename Codec_>
1719 this->write(os,
false);
1723 template<
typename ValueType_,
typename Codec_>
1727 this->writeMetadata(os, outputTransient,
false);
1728 this->writeBuffers(os, outputTransient);
1732 template<
typename ValueType_,
typename Codec_>
1736 if (!outputTransient && this->isTransient())
return;
1738 if (
mFlags & PARTIALREAD) {
1739 OPENVDB_THROW(IoError,
"Cannot write out a partially-read AttributeArray.");
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;
1757 serializationFlags |= WRITESTRIDED;
1762 serializationFlags |= WRITEUNIFORM;
1763 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1765 else if (bloscCompression)
1767 if (paged) serializationFlags |= WRITEPAGED;
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;
1797 if (
mFlags & PARTIALREAD) {
1798 OPENVDB_THROW(IoError,
"Cannot write out a partially-read AttributeArray.");
1803 if (this->isUniform()) {
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) {
1846 if (
mFlags & PARTIALREAD) {
1847 OPENVDB_THROW(IoError,
"Cannot write out a partially-read AttributeArray.");
1852 os.
write(reinterpret_cast<const char*>(this->
data()), this->arrayMemUsage());
1856 template<
typename ValueType_,
typename Codec_>
1860 if (!(this->isOutOfCore()))
return;
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;
1913 Index n = this->mIsUniform ? 1 : mSize;
1919 template<
typename ValueType_,
typename Codec_>
1921 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
1923 return reinterpret_cast<char*
>(this->
data());
1927 template<
typename ValueType_,
typename Codec_>
1929 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
const
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>
1983 typename AttributeHandle<ValueType, CodecType>::Ptr
1990 template <
typename ValueType,
typename CodecType>
1993 , mStrideOrTotalSize(array.hasConstantStride() ? array.
stride() : 1)
1994 , mSize(array.hasConstantStride() ? array.
size() : array.dataSize())
1995 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
1998 OPENVDB_THROW(TypeError,
"Cannot bind handle due to incompatible type of AttributeArray.");
2018 template <
typename ValueType,
typename CodecType>
2022 if (mCollapseOnDestruction)
const_cast<AttributeArray*
>(this->mArray)->collapse();
2025 template <
typename ValueType,
typename CodecType>
2026 template <
bool IsUnknownCodec>
2032 return mArray->hasValueType<
ValueType>();
2035 template <
typename ValueType,
typename CodecType>
2036 template <
bool IsUnknownCodec>
2038 AttributeHandle<ValueType, CodecType>::compatibleType()
const
2042 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2045 template <
typename ValueType,
typename CodecType>
2052 template <
typename ValueType,
typename CodecType>
2060 template <
typename ValueType,
typename CodecType>
2066 template <
typename ValueType,
typename CodecType>
2067 template <
bool IsUnknownCodec>
2073 return (*mGetter)(mArray, index);
2076 template <
typename ValueType,
typename CodecType>
2077 template <
bool IsUnknownCodec>
2086 template <
typename ValueType,
typename CodecType>
2089 return mArray->isUniform();
2092 template <
typename ValueType,
typename CodecType>
2095 return mArray->hasConstantStride();
2102 template <
typename ValueType,
typename CodecType>
2110 template <
typename ValueType,
typename CodecType>
2114 if (expand) array.
expand();
2117 template <
typename ValueType,
typename CodecType>
2123 template <
typename ValueType,
typename CodecType>
2129 template <
typename ValueType,
typename CodecType>
2135 template <
typename ValueType,
typename CodecType>
2141 template <
typename ValueType,
typename CodecType>
2147 template <
typename ValueType,
typename CodecType>
2150 this->mCollapser(const_cast<AttributeArray*>(this->mArray), uniformValue);
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>
2166 (*this->mSetter)(const_cast<AttributeArray*>(this->mArray), index,
value);
2169 template <
typename ValueType,
typename CodecType>
2170 template <
bool IsUnknownCodec>
2179 template <
typename ValueType,
typename CodecType>
2191 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
bool isUniform() const override
Return true if this array is stored as a single uniform value.
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
static void unregisterType()
Remove this attribute type from the registry.
std::unique_ptr< Handle > UniquePtr
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
void loadData() const override
Ensures all data is in-core.
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
~TypedAttributeArray() override
virtual Index storageTypeSize() const =0
std::unique_ptr< PageHandle > Ptr
GLdouble GLdouble GLint GLint const GLdouble * points
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Index stride() const override
Write-able version of AttributeHandle.
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
std::unique_ptr< Handle > ScopedPtr
bool hasConstantStride() const
virtual Index stride() const =0
bool isStreaming() const
Return true if this attribute is in streaming mode.
static const char * name()
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
bool compact()
Compact the existing array to become uniform if all values are identical.
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
typename T::ValueType ElementType
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
typename attribute_traits::TruncateTrait< T >::Type Type
GLsizei const GLfloat * value
std::shared_ptr< AccessorBase > AccessorBasePtr
static void decode(const StorageType &, ValueType &)
virtual ~AttributeHandle()
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 collapse() override
Replace the existing array with a uniform zero value.
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
#define OPENVDB_LOG_WARN(mesg)
IntegerT floatingPointToFixedPoint(const FloatT s)
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
ValueType get(Index n) const
Return the value at index n.
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
GLuint GLsizei GLsizei * length
#define OPENVDB_USE_VERSION_NAMESPACE
static ValueType encode(const ValueType &value)
StorageType * data()
Return the raw data buffer.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
**But if you need a or simply need to know when the task has note that the like this
bool hasConstantStride() const
Return true if this attribute has a constant stride.
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
bool compact() override
Compact the existing array to become uniform if all values are identical.
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
static void encode(const ValueType &, StorageType &)
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
static const char * name()
void copyValues(const AttributeArray &sourceArray, const IterT &iter, bool compact=true)
Like copyValuesUnsafe(), but if compact is true, attempt to collapse this array.
const AttributeArray * mArray
std::ostream & getOutputStream()
Set and get the output stream.
const NamePair & type() const override
Return the name of this attribute's type.
static void encode(const math::Vec3< T > &, StorageType &)
void collapse()
Replace the existing array with a uniform value (zero if none provided).
void(*)(AttributeArray *array, const Index n, const Index &value) SetterPtr
TypedAttributeArray & operator=(const TypedAttributeArray &)
static Ptr create(AttributeArray &array, const bool expand=true)
static void decode(const StorageType &, ValueType &)
void(*)(AttributeArray *array, const Index &value) ValuePtr
AttributeArray::Ptr copy() const override
TypedAttributeArray(Index n=1, Index strideOrTotalSize=1, bool constantStride=true, const ValueType &uniformValue=zeroVal< ValueType >())
Default constructor, always constructs a uniform attribute.
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
std::shared_ptr< Handle > Ptr
#define OPENVDB_ASSERT(X)
static const char * name()
void(*)(AttributeArray *array, const T &value) ValuePtr
static const char * name()
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
bool operator!=(const AttributeArray &other) const
GLint GLint GLsizei GLint GLenum GLenum type
virtual Index dataSize() const =0
Base class for storing attribute data.
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
const StorageType * data() const
void writeBuffers(std::ostream &os, bool outputTransient) const override
Index storageTypeSize() const override
FloatT fixedPointToFloatingPoint(const IntegerT s)
Index size() const override
Return the number of elements in this array.
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
constexpr auto set(type rhs) -> int
Accessor to call unsafe get and set methods based on templated Codec and Value.
static uint16_t pack(const Vec3< T > &vec)
Index index(Index n, Index m) const
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
virtual void loadData() const =0
Ensures all data is in-core.
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
GLsizei GLsizei GLchar * source
GLint GLenum GLboolean GLsizei stride
const StorageType * constData() const
Return the raw data 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...
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
std::shared_ptr< AttributeArray > Ptr
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
std::shared_ptr< Handle > Ptr
Convenience wrappers to using Blosc and reading and writing of Paged data.
const char * constDataAsByteArray() const
Indirect virtual function to retrieve the data buffer cast to a char byte array.
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
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...
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
std::istream & getInputStream()
GLuint const GLchar * name
std::pair< Name, Name > NamePair
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
bool isTransient() const
Return true if this attribute is not serialized during stream output.
static ValueType encode(const ValueType &value)
GLboolean GLboolean GLboolean b
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
static ValueType decode(const ValueType &value)
std::shared_ptr< const AttributeArray > ConstPtr
static bool isRegistered()
Return true if this attribute type is registered.
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
AttributeHandle & operator=(const AttributeHandle &)=default
static ValueType decode(const ValueType &value)
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
virtual ~AttributeArray()
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
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.
static void decode(const StorageType &, math::Vec3< T > &)
IMATH_NAMESPACE::V2f IMATH_NAMESPACE::Box2i std::string this attribute is obsolete as of OpenEXR v3 float
void copyValuesUnsafe(const AttributeArray &sourceArray, const IterT &iter)
Copy values into this array from a source array to a target array as referenced by an iterator...
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
uint8_t flags() const
Retrieve the attribute array flags.
Name valueType() const override
Return the name of the value type of a single element in this array (e.g., "float" or "vec3d")...
const AttributeArray & array() const
void set(Index n, const ValueType &value)
Set value at the given index n.
Typed class for storing attribute data.
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
LeafData & operator=(const LeafData &)=delete
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
bool isDataLoaded() const override
Return true if all data has been loaded.
void fill(const ValueType &value)
Fill the existing array with the given value.
virtual ~AccessorBase()=default
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void write(std::ostream &os, bool outputTransient) const override
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
static const char * name()
static const char * name()
std::shared_ptr< TypedAttributeArray > Ptr
bool valueTypeIsVector() const override
Return true if the value type is a vector.
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
typename Codec::template Storage< ValueType >::Type StorageType
void set(Index n, const ValueType &value)
void read(std::istream &) override
Read attribute data from a stream.
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
static void encode(const ValueType &, StorageType &)
static Vec3s unpack(const uint16_t data)
Accessor base class for AttributeArray storage where type is not available.
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
static void decode(const ValueType &, ValueType &)
compression::PageHandle::Ptr mPageHandle
T(*)(const AttributeArray *array, const Index n) GetterPtr
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
streaming mode collapses attributes when first accessed
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
void fill(const ValueType &value)
Fill the existing array with the given value.
size_t memUsageIfLoaded() const override
bool isType() const
Return true if this attribute is of the same type as the template parameter.
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.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
static void registerType()
Register this attribute type along with a factory function.
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true) ...
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
ValueType get(Index n, Index m=0) const
static void encode(const ValueType &, ValueType &)
Index dataSize() const override
Return the size of the data in this array.
Index(*)(const AttributeArray *array, const Index n) GetterPtr
#define OPENVDB_THROW(exception, message)
std::atomic< Index32 > mOutOfCore
virtual ~AttributeWriteHandle()=default