OpenVDB  7.2.1
AttributeArray.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
9 
10 #ifndef OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
11 #define OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
12 
13 #include <openvdb/Types.h>
15 #include <openvdb/util/Name.h>
16 #include <openvdb/util/logging.h>
17 #include <openvdb/io/io.h> // MappedFile
18 #include <openvdb/io/Compression.h> // COMPRESS_BLOSC
19 
20 #include "IndexIterator.h"
21 #include "StreamCompression.h"
22 
23 #include <tbb/spin_mutex.h>
24 #include <tbb/atomic.h>
25 
26 #include <memory>
27 #include <mutex>
28 #include <string>
29 #include <type_traits>
30 
31 
32 class TestAttributeArray;
33 
34 namespace openvdb {
36 namespace OPENVDB_VERSION_NAME {
37 
38 
39 using NamePair = std::pair<Name, Name>;
40 
41 namespace points {
42 
43 
45 
46 // Utility methods
47 
48 template <typename IntegerT, typename FloatT>
49 inline IntegerT
51 {
52  static_assert(std::is_unsigned<IntegerT>::value, "IntegerT must be unsigned");
53  if (FloatT(0.0) > s) return std::numeric_limits<IntegerT>::min();
54  else if (FloatT(1.0) <= s) return std::numeric_limits<IntegerT>::max();
55  return IntegerT(s * FloatT(std::numeric_limits<IntegerT>::max()));
56 }
57 
58 
59 template <typename FloatT, typename IntegerT>
60 inline FloatT
61 fixedPointToFloatingPoint(const IntegerT s)
62 {
63  static_assert(std::is_unsigned<IntegerT>::value, "IntegerT must be unsigned");
64  return FloatT(s) / FloatT((std::numeric_limits<IntegerT>::max()));
65 }
66 
67 template <typename IntegerVectorT, typename FloatT>
68 inline IntegerVectorT
70 {
71  return IntegerVectorT(
72  floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.x()),
73  floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.y()),
74  floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.z()));
75 }
76 
77 template <typename FloatVectorT, typename IntegerT>
78 inline FloatVectorT
80 {
81  return FloatVectorT(
82  fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.x()),
83  fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.y()),
84  fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.z()));
85 }
86 
87 
89 
90 
93 {
94 protected:
95  struct AccessorBase;
96  template <typename T> struct Accessor;
97 
98  using AccessorBasePtr = std::shared_ptr<AccessorBase>;
99 
100 public:
101  enum Flag {
102  TRANSIENT = 0x1,
103  HIDDEN = 0x2,
104  CONSTANTSTRIDE = 0x8,
105  STREAMING = 0x10,
106  PARTIALREAD = 0x20
107  };
108 
110  WRITESTRIDED = 0x1,
111  WRITEUNIFORM = 0x2,
112  WRITEMEMCOMPRESS = 0x4,
113  WRITEPAGED = 0x8
115  };
116 
117  // Scoped Lock wrapper class that locks the AttributeArray registry mutex
119  {
120  tbb::spin_mutex::scoped_lock lock;
121  public:
123  }; // class ScopedRegistryLock
124 
125  using Ptr = std::shared_ptr<AttributeArray>;
126  using ConstPtr = std::shared_ptr<const AttributeArray>;
127 
128  using FactoryMethod = Ptr (*)(Index, Index, bool, const Metadata*);
129 
130  template <typename ValueType, typename CodecType> friend class AttributeHandle;
131 
132  AttributeArray(): mPageHandle() { mOutOfCore = 0; }
133  virtual ~AttributeArray()
134  {
135  // if this AttributeArray has been partially read, zero the compressed bytes,
136  // so the page handle won't attempt to clean up invalid memory
137  if (mFlags & PARTIALREAD) mCompressedBytes = 0;
138  }
139 #if OPENVDB_ABI_VERSION_NUMBER >= 6
142 #else
143  AttributeArray(const AttributeArray&) = default;
144  AttributeArray& operator=(const AttributeArray&) = default;
145 #endif
148 
150  virtual AttributeArray::Ptr copy() const = 0;
151 
154 #ifndef _MSC_VER
156 #endif
158 
161  virtual Index size() const = 0;
162 
165  virtual Index stride() const = 0;
166 
169  virtual Index dataSize() const = 0;
170 
171 #if OPENVDB_ABI_VERSION_NUMBER >= 6
172  virtual Name valueType() const = 0;
174 
176  virtual Name codecType() const = 0;
177 
180  virtual Index valueTypeSize() const = 0;
181 
184  virtual Index storageTypeSize() const = 0;
185 
187  virtual bool valueTypeIsFloatingPoint() const = 0;
188 
190  virtual bool valueTypeIsClass() const = 0;
191 
193  virtual bool valueTypeIsVector() const = 0;
194 
196  virtual bool valueTypeIsQuaternion() const = 0;
197 
199  virtual bool valueTypeIsMatrix() const = 0;
200 #endif
201 
203  virtual size_t memUsage() const = 0;
204 
208  static Ptr create(const NamePair& type, Index length, Index stride = 1,
209  bool constantStride = true,
210  const Metadata* metadata = nullptr,
211  const ScopedRegistryLock* lock = nullptr);
212 
213  static OPENVDB_DEPRECATED Ptr create(const NamePair& type, Index length,
214  Index stride, bool constantStride, const ScopedRegistryLock* lock);
215 
217  static bool isRegistered(const NamePair& type, const ScopedRegistryLock* lock = nullptr);
219  static void clearRegistry(const ScopedRegistryLock* lock = nullptr);
220 
222  virtual const NamePair& type() const = 0;
224  template<typename AttributeArrayType>
225  bool isType() const { return this->type() == AttributeArrayType::attributeType(); }
226 
228  template<typename ValueType>
229  bool hasValueType() const { return this->type().first == typeNameAsString<ValueType>(); }
230 
233 #if OPENVDB_ABI_VERSION_NUMBER >= 6
234  // Windows does not allow base classes to be easily deprecated.
235 #ifndef _MSC_VER
237 #endif
238 #endif
239  virtual void set(const Index n, const AttributeArray& sourceArray, const Index sourceIndex) = 0;
240 
241 #if OPENVDB_ABI_VERSION_NUMBER >= 6
242  template<typename IterT>
266  void copyValuesUnsafe(const AttributeArray& sourceArray, const IterT& iter);
270  template<typename IterT>
271  void copyValues(const AttributeArray& sourceArray, const IterT& iter, bool compact = true);
272 #endif
273 
275  virtual bool isUniform() const = 0;
278  virtual void expand(bool fill = true) = 0;
280  virtual void collapse() = 0;
282  virtual bool compact() = 0;
283 
285  // Windows does not allow base classes to be deprecated
286 #ifndef _MSC_VER
288 #endif
289  virtual bool compress() = 0;
291  // Windows does not allow base classes to be deprecated
292 #ifndef _MSC_VER
294 #endif
295  virtual bool decompress() = 0;
296 
301  void setHidden(bool state);
303  bool isHidden() const { return bool(mFlags & HIDDEN); }
304 
308  void setTransient(bool state);
310  bool isTransient() const { return bool(mFlags & TRANSIENT); }
311 
316  void setStreaming(bool state);
318  bool isStreaming() const { return bool(mFlags & STREAMING); }
319 
321  bool hasConstantStride() const { return bool(mFlags & CONSTANTSTRIDE); }
322 
324  uint8_t flags() const { return mFlags; }
325 
327  virtual void read(std::istream&) = 0;
330  virtual void write(std::ostream&, bool outputTransient) const = 0;
332  virtual void write(std::ostream&) const = 0;
333 
335  virtual void readMetadata(std::istream&) = 0;
339  virtual void writeMetadata(std::ostream&, bool outputTransient, bool paged) const = 0;
340 
342  virtual void readBuffers(std::istream&) = 0;
345  virtual void writeBuffers(std::ostream&, bool outputTransient) const = 0;
346 
351  virtual void writePagedBuffers(compression::PagedOutputStream&, bool outputTransient) const = 0;
352 
354  virtual void loadData() const = 0;
355 
356 #if OPENVDB_ABI_VERSION_NUMBER >= 6
357  virtual bool isDataLoaded() const = 0;
359 #endif
360 
364  bool operator==(const AttributeArray& other) const;
365  bool operator!=(const AttributeArray& other) const { return !this->operator==(other); }
366 
367 private:
368  friend class ::TestAttributeArray;
369 
372  virtual bool isEqual(const AttributeArray& other) const = 0;
373 
374 #if OPENVDB_ABI_VERSION_NUMBER >= 6
375  virtual char* dataAsByteArray() = 0;
377  virtual const char* dataAsByteArray() const = 0;
378 
380  template <typename IterT>
381  void doCopyValues(const AttributeArray& sourceArray, const IterT& iter,
382  bool rangeChecking = true);
383 #endif
384 
385 protected:
386 #if OPENVDB_ABI_VERSION_NUMBER >= 7
387  AttributeArray(const AttributeArray& rhs, const tbb::spin_mutex::scoped_lock&);
388 #endif
389 
391  void setConstantStride(bool state);
392 
394  virtual AccessorBasePtr getAccessor() const = 0;
395 
397  static void registerType(const NamePair& type, FactoryMethod,
398  const ScopedRegistryLock* lock = nullptr);
400  static void unregisterType(const NamePair& type,
401  const ScopedRegistryLock* lock = nullptr);
402 
403 #if OPENVDB_ABI_VERSION_NUMBER < 6
404 
405  size_t mCompressedBytes = 0;
406  uint8_t mFlags = 0;
407  uint8_t mUsePagedRead = 0;
408  tbb::atomic<Index32> mOutOfCore; // interpreted as bool
409  compression::PageHandle::Ptr mPageHandle;
410 
411 #else // #if OPENVDB_ABI_VERSION_NUMBER < 6
412 
413  bool mIsUniform = true;
414  mutable tbb::spin_mutex mMutex;
415  uint8_t mFlags = 0;
416  uint8_t mUsePagedRead = 0;
417  tbb::atomic<Index32> mOutOfCore; // interpreted as bool
419  union {
421  size_t mCompressedBytes; // as of ABI=6, this data is packed together to save memory
422  };
423 
424 #endif
425 }; // class AttributeArray
426 
427 
429 
430 
432 struct AttributeArray::AccessorBase { virtual ~AccessorBase() = default; };
433 
436 template <typename T>
438 {
439  using GetterPtr = T (*)(const AttributeArray* array, const Index n);
440  using SetterPtr = void (*)(AttributeArray* array, const Index n, const T& value);
441  using ValuePtr = void (*)(AttributeArray* array, const T& value);
442 
443  Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler) :
444  mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
445 
450 }; // struct AttributeArray::Accessor
451 
452 
454 
455 
456 namespace attribute_traits
457 {
458  template <typename T> struct TruncateTrait { };
459  template <> struct TruncateTrait<float> { using Type = half; };
460  template <> struct TruncateTrait<int> { using Type = short; };
461 
462  template <typename T> struct TruncateTrait<math::Vec3<T>> {
464  };
465 
466  template <bool OneByte, typename T> struct UIntTypeTrait { };
467  template<typename T> struct UIntTypeTrait</*OneByte=*/true, T> { using Type = uint8_t; };
468  template<typename T> struct UIntTypeTrait</*OneByte=*/false, T> { using Type = uint16_t; };
469  template<typename T> struct UIntTypeTrait</*OneByte=*/true, math::Vec3<T>> {
471  };
472  template<typename T> struct UIntTypeTrait</*OneByte=*/false, math::Vec3<T>> {
474  };
475 }
476 
477 
479 
480 
481 // Attribute codec schemes
482 
483 struct UnknownCodec { };
484 
485 
486 struct NullCodec
487 {
488  template <typename T>
489  struct Storage { using Type = T; };
490 
491  template<typename ValueType> static void decode(const ValueType&, ValueType&);
492  template<typename ValueType> static void encode(const ValueType&, ValueType&);
493  static const char* name() { return "null"; }
494 };
495 
496 
498 {
499  template <typename T>
501 
502  template<typename StorageType, typename ValueType> static void decode(const StorageType&, ValueType&);
503  template<typename StorageType, typename ValueType> static void encode(const ValueType&, StorageType&);
504  static const char* name() { return "trnc"; }
505 };
506 
507 
508 // Fixed-point codec range for voxel-space positions [-0.5,0.5]
510 {
511  static const char* name() { return "fxpt"; }
512  template <typename ValueType> static ValueType encode(const ValueType& value) { return value + ValueType(0.5); }
513  template <typename ValueType> static ValueType decode(const ValueType& value) { return value - ValueType(0.5); }
514 };
515 
516 
517 // Fixed-point codec range for unsigned values in the unit range [0.0,1.0]
518 struct UnitRange
519 {
520  static const char* name() { return "ufxpt"; }
521  template <typename ValueType> static ValueType encode(const ValueType& value) { return value; }
522  template <typename ValueType> static ValueType decode(const ValueType& value) { return value; }
523 };
524 
525 
526 template <bool OneByte, typename Range=PositionRange>
528 {
529  template <typename T>
531 
532  template<typename StorageType, typename ValueType> static void decode(const StorageType&, ValueType&);
533  template<typename StorageType, typename ValueType> static void encode(const ValueType&, StorageType&);
534 
535  static const char* name() {
536  static const std::string Name = std::string(Range::name()) + (OneByte ? "8" : "16");
537  return Name.c_str();
538  }
539 };
540 
541 
543 {
544  using StorageType = uint16_t;
545 
546  template <typename T>
547  struct Storage { using Type = StorageType; };
548 
549  template<typename T> static void decode(const StorageType&, math::Vec3<T>&);
550  template<typename T> static void encode(const math::Vec3<T>&, StorageType&);
551  static const char* name() { return "uvec"; }
552 };
553 
554 
556 
557 
559 
560 template<typename ValueType_, typename Codec_ = NullCodec>
561 #if OPENVDB_ABI_VERSION_NUMBER >= 6 // for ABI=6, class is final to allow for de-virtualization
563 #else
565 #endif
566 {
567 public:
568  using Ptr = std::shared_ptr<TypedAttributeArray>;
569  using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
570 
571  using ValueType = ValueType_;
572  using Codec = Codec_;
573  using StorageType = typename Codec::template Storage<ValueType>::Type;
574 
576 
578  explicit TypedAttributeArray(Index n = 1, Index strideOrTotalSize = 1, bool constantStride = true,
579  const ValueType& uniformValue = zeroVal<ValueType>());
580 #if OPENVDB_ABI_VERSION_NUMBER >= 7
591 #else
592  TypedAttributeArray(const TypedAttributeArray&, bool uncompress = false);
596 #endif
597  TypedAttributeArray& operator=(const TypedAttributeArray&);
604 
605  ~TypedAttributeArray() override { this->deallocate(); }
606 
609  AttributeArray::Ptr copy() const override;
610 
614  OPENVDB_DEPRECATED AttributeArray::Ptr copyUncompressed() const override;
615 
617  static Ptr create(Index n, Index strideOrTotalSize = 1, bool constantStride = true,
618  const Metadata* metadata = nullptr);
619 
621  static TypedAttributeArray& cast(AttributeArray& attributeArray);
622 
624  static const TypedAttributeArray& cast(const AttributeArray& attributeArray);
625 
627  static const NamePair& attributeType();
629  const NamePair& type() const override { return attributeType(); }
630 
632  static bool isRegistered();
634  static void registerType();
636  static void unregisterType();
637 
639  Index size() const override { return mSize; }
640 
643  Index stride() const override { return hasConstantStride() ? mStrideOrTotalSize : 0; }
644 
646  Index dataSize() const override {
647  return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
648  }
649 
650 #if OPENVDB_ABI_VERSION_NUMBER >= 6
651  Name valueType() const override { return typeNameAsString<ValueType>(); }
653 
655  Name codecType() const override { return Codec::name(); }
656 
658  Index valueTypeSize() const override { return sizeof(ValueType); }
659 
662  Index storageTypeSize() const override { return sizeof(StorageType); }
663 
665  bool valueTypeIsFloatingPoint() const override;
666 
668  bool valueTypeIsClass() const override;
669 
671  bool valueTypeIsVector() const override;
672 
674  bool valueTypeIsQuaternion() const override;
675 
677  bool valueTypeIsMatrix() const override;
678 #endif
679 
681  size_t memUsage() const override;
682 
684  ValueType getUnsafe(Index n) const;
686  ValueType get(Index n) const;
688  template<typename T> void getUnsafe(Index n, T& value) const;
690  template<typename T> void get(Index n, T& value) const;
691 
694  static ValueType getUnsafe(const AttributeArray* array, const Index n);
695 
697  void setUnsafe(Index n, const ValueType& value);
699  void set(Index n, const ValueType& value);
701  template<typename T> void setUnsafe(Index n, const T& value);
703  template<typename T> void set(Index n, const T& value);
704 
707  static void setUnsafe(AttributeArray* array, const Index n, const ValueType& value);
708 
710 #if OPENVDB_ABI_VERSION_NUMBER >= 6
712 #endif
713  void set(const Index n, const AttributeArray& sourceArray, const Index sourceIndex) override;
714 
716  bool isUniform() const override { return mIsUniform; }
720  void expand(bool fill = true) override;
722  void collapse() override;
724  bool compact() override;
725 
727  void collapse(const ValueType& uniformValue);
730  void fill(const ValueType& value);
731 
733  static void collapse(AttributeArray* array, const ValueType& value);
735  static void fill(AttributeArray* array, const ValueType& value);
736 
738  OPENVDB_DEPRECATED bool compress() override;
740  OPENVDB_DEPRECATED bool decompress() override;
741 
743  void read(std::istream&) override;
747  void write(std::ostream& os, bool outputTransient) const override;
749  void write(std::ostream&) const override;
750 
752  void readMetadata(std::istream&) override;
757  void writeMetadata(std::ostream& os, bool outputTransient, bool paged) const override;
758 
760  void readBuffers(std::istream&) override;
764  void writeBuffers(std::ostream& os, bool outputTransient) const override;
765 
767  void readPagedBuffers(compression::PagedInputStream&) override;
771  void writePagedBuffers(compression::PagedOutputStream& os, bool outputTransient) const override;
772 
774  inline bool isOutOfCore() const;
775 
777  void loadData() const override;
778 
779 #if OPENVDB_ABI_VERSION_NUMBER >= 6
780  bool isDataLoaded() const override;
782 #endif
783 
784 protected:
785  AccessorBasePtr getAccessor() const override;
786 
788  inline StorageType* data() { assert(validData()); return mData.get(); }
789  inline const StorageType* data() const { assert(validData()); return mData.get(); }
790 
792  inline bool validData() const { return !(isOutOfCore() || (flags() & PARTIALREAD)); }
793 
794 private:
795  friend class ::TestAttributeArray;
796 
797 #if OPENVDB_ABI_VERSION_NUMBER >= 7
798  TypedAttributeArray(const TypedAttributeArray&, const tbb::spin_mutex::scoped_lock&);
799 #endif
800 
802  inline void doLoad() const;
805  inline void doLoadUnsafe(const bool compression = true) const;
807  inline bool compressUnsafe();
808 
810  inline void setOutOfCore(const bool);
811 
813  bool isEqual(const AttributeArray& other) const override;
814 
815 #if OPENVDB_ABI_VERSION_NUMBER >= 6
816  char* dataAsByteArray() override;
818  const char* dataAsByteArray() const override;
819 #endif
820 
821  size_t arrayMemUsage() const;
822  void allocate();
823  void deallocate();
824 
826  static AttributeArray::Ptr factory(Index n, Index strideOrTotalSize, bool constantStride,
827  const Metadata* metadata) {
828  return TypedAttributeArray::create(n, strideOrTotalSize, constantStride, metadata);
829  }
830 
831  static std::unique_ptr<const NamePair> sTypeName;
832  std::unique_ptr<StorageType[]> mData;
833  Index mSize;
834  Index mStrideOrTotalSize;
835 #if OPENVDB_ABI_VERSION_NUMBER < 6 // as of ABI=6, this data lives in the base class to reduce memory
836  bool mIsUniform = true;
837  mutable tbb::spin_mutex mMutex;
838 #endif
839 }; // class TypedAttributeArray
840 
841 
843 
844 
847 template <typename ValueType, typename CodecType = UnknownCodec>
849 {
850 public:
852  using Ptr = std::shared_ptr<Handle>;
853  using UniquePtr = std::unique_ptr<Handle>;
854 
855 protected:
856  using GetterPtr = ValueType (*)(const AttributeArray* array, const Index n);
857  using SetterPtr = void (*)(AttributeArray* array, const Index n, const ValueType& value);
858  using ValuePtr = void (*)(AttributeArray* array, const ValueType& value);
859 
860 public:
861  static Ptr create(const AttributeArray& array, const bool collapseOnDestruction = true);
862 
863  AttributeHandle(const AttributeArray& array, const bool collapseOnDestruction = true);
864 
865  AttributeHandle(const AttributeHandle&) = default;
867 
868  virtual ~AttributeHandle();
869 
870  Index stride() const { return mStrideOrTotalSize; }
871  Index size() const { return mSize; }
872 
873  bool isUniform() const;
874  bool hasConstantStride() const;
875 
876  ValueType get(Index n, Index m = 0) const;
877 
878  const AttributeArray& array() const;
879 
880 protected:
881  Index index(Index n, Index m) const;
882 
884 
889 
890 private:
891  friend class ::TestAttributeArray;
892 
893  template <bool IsUnknownCodec>
894  typename std::enable_if<IsUnknownCodec, bool>::type compatibleType() const;
895 
896  template <bool IsUnknownCodec>
897  typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType() const;
898 
899  template <bool IsUnknownCodec>
900  typename std::enable_if<IsUnknownCodec, ValueType>::type get(Index index) const;
901 
902  template <bool IsUnknownCodec>
903  typename std::enable_if<!IsUnknownCodec, ValueType>::type get(Index index) const;
904 
905  // local copy of AttributeArray (to preserve compression)
906  AttributeArray::Ptr mLocalArray;
907 
908  Index mStrideOrTotalSize;
909  Index mSize;
910  bool mCollapseOnDestruction;
911 }; // class AttributeHandle
912 
913 
915 
916 
918 template <typename ValueType, typename CodecType = UnknownCodec>
919 class AttributeWriteHandle : public AttributeHandle<ValueType, CodecType>
920 {
921 public:
923  using Ptr = std::shared_ptr<Handle>;
924  using ScopedPtr = std::unique_ptr<Handle>;
925 
926  static Ptr create(AttributeArray& array, const bool expand = true);
927 
928  AttributeWriteHandle(AttributeArray& array, const bool expand = true);
929 
930  virtual ~AttributeWriteHandle() = default;
931 
934  void expand(bool fill = true);
935 
937  void collapse();
938  void collapse(const ValueType& uniformValue);
939 
941  bool compact();
942 
945  void fill(const ValueType& value);
946 
947  void set(Index n, const ValueType& value);
948  void set(Index n, Index m, const ValueType& value);
949 
951 
952 private:
953  friend class ::TestAttributeArray;
954 
955  template <bool IsUnknownCodec>
956  typename std::enable_if<IsUnknownCodec, void>::type set(Index index, const ValueType& value) const;
957 
958  template <bool IsUnknownCodec>
959  typename std::enable_if<!IsUnknownCodec, void>::type set(Index index, const ValueType& value) const;
960 }; // class AttributeWriteHandle
961 
962 
964 
965 
966 // Attribute codec implementation
967 
968 
969 template<typename ValueType>
970 inline void
971 NullCodec::decode(const ValueType& data, ValueType& val)
972 {
973  val = data;
974 }
975 
976 
977 template<typename ValueType>
978 inline void
979 NullCodec::encode(const ValueType& val, ValueType& data)
980 {
981  data = val;
982 }
983 
984 
985 template<typename StorageType, typename ValueType>
986 inline void
987 TruncateCodec::decode(const StorageType& data, ValueType& val)
988 {
989  val = static_cast<ValueType>(data);
990 }
991 
992 
993 template<typename StorageType, typename ValueType>
994 inline void
995 TruncateCodec::encode(const ValueType& val, StorageType& data)
996 {
997  data = static_cast<StorageType>(val);
998 }
999 
1000 
1001 template <bool OneByte, typename Range>
1002 template<typename StorageType, typename ValueType>
1003 inline void
1004 FixedPointCodec<OneByte, Range>::decode(const StorageType& data, ValueType& val)
1005 {
1006  val = fixedPointToFloatingPoint<ValueType>(data);
1007 
1008  // shift value range to be -0.5 => 0.5 (as this is most commonly used for position)
1009 
1010  val = Range::template decode<ValueType>(val);
1011 }
1012 
1013 
1014 template <bool OneByte, typename Range>
1015 template<typename StorageType, typename ValueType>
1016 inline void
1017 FixedPointCodec<OneByte, Range>::encode(const ValueType& val, StorageType& data)
1018 {
1019  // shift value range to be -0.5 => 0.5 (as this is most commonly used for position)
1020 
1021  const ValueType newVal = Range::template encode<ValueType>(val);
1022 
1023  data = floatingPointToFixedPoint<StorageType>(newVal);
1024 }
1025 
1026 
1027 template<typename T>
1028 inline void
1029 UnitVecCodec::decode(const StorageType& data, math::Vec3<T>& val)
1030 {
1031  val = math::QuantizedUnitVec::unpack(data);
1032 }
1033 
1034 
1035 template<typename T>
1036 inline void
1037 UnitVecCodec::encode(const math::Vec3<T>& val, StorageType& data)
1038 {
1039  data = math::QuantizedUnitVec::pack(val);
1040 }
1041 
1042 
1044 
1045 // AttributeArray implementation
1046 
1047 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1048 
1049 template <typename IterT>
1050 void AttributeArray::doCopyValues(const AttributeArray& sourceArray, const IterT& iter,
1051  bool rangeChecking/*=true*/)
1052 {
1053  // ensure both arrays have float-float or integer-integer value types
1054  assert(sourceArray.valueTypeIsFloatingPoint() == this->valueTypeIsFloatingPoint());
1055  // ensure both arrays have been loaded from disk (if delay-loaded)
1056  assert(sourceArray.isDataLoaded() && this->isDataLoaded());
1057  // ensure storage size * stride matches on both arrays
1058  assert(this->storageTypeSize()*this->stride() ==
1059  sourceArray.storageTypeSize()*sourceArray.stride());
1060 
1061  const size_t bytes(sourceArray.storageTypeSize()*sourceArray.stride());
1062  const char* const sourceBuffer = sourceArray.dataAsByteArray();
1063  char* const targetBuffer = this->dataAsByteArray();
1064  assert(sourceBuffer && targetBuffer);
1065 
1066  if (rangeChecking && this->isUniform()) {
1067  OPENVDB_THROW(IndexError, "Cannot copy array data as target array is uniform.");
1068  }
1069 
1070  const bool sourceIsUniform = sourceArray.isUniform();
1071 
1072  const Index sourceDataSize = rangeChecking ? sourceArray.dataSize() : 0;
1073  const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1074 
1075  for (IterT it(iter); it; ++it) {
1076  const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1077  const Index targetIndex = it.targetIndex();
1078 
1079  if (rangeChecking) {
1080  if (sourceIndex >= sourceDataSize) {
1082  "Cannot copy array data as source index exceeds size of source array.");
1083  }
1084  if (targetIndex >= targetDataSize) {
1086  "Cannot copy array data as target index exceeds size of target array.");
1087  }
1088  } else {
1089  // range-checking asserts
1090  assert(sourceIndex < sourceArray.dataSize());
1091  assert(targetIndex < this->dataSize());
1092  if (this->isUniform()) assert(targetIndex == Index(0));
1093  }
1094 
1095  const size_t targetOffset(targetIndex * bytes);
1096  const size_t sourceOffset(sourceIndex * bytes);
1097 
1098  std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1099  }
1100 }
1101 
1102 template <typename IterT>
1103 void AttributeArray::copyValuesUnsafe(const AttributeArray& sourceArray, const IterT& iter)
1104 {
1105  this->doCopyValues(sourceArray, iter, /*range-checking=*/false);
1106 }
1107 
1108 template <typename IterT>
1109 void AttributeArray::copyValues(const AttributeArray& sourceArray, const IterT& iter,
1110  bool compact/* = true*/)
1111 {
1112  const Index bytes = sourceArray.storageTypeSize();
1113  if (bytes != this->storageTypeSize()) {
1114  OPENVDB_THROW(TypeError, "Cannot copy array data due to mis-match in storage type sizes.");
1115  }
1116 
1117  // ensure both arrays have been loaded from disk
1118  sourceArray.loadData();
1119  this->loadData();
1120 
1121  // if the target array is uniform, expand it first
1122  this->expand();
1123 
1124  // TODO: Acquire mutex locks for source and target arrays to ensure that
1125  // value copying is always thread-safe. Note that the unsafe method will be
1126  // faster, but can only be used if neither the source or target arrays are
1127  // modified during copying. Note that this will require a new private
1128  // virtual method with ABI=7 to access the mutex from the derived class.
1129 
1130  this->doCopyValues(sourceArray, iter, true);
1131 
1132  // attempt to compact target array
1133  if (compact) {
1134  this->compact();
1135  }
1136 }
1137 #endif
1138 
1139 
1141 
1142 // TypedAttributeArray implementation
1143 
1144 template<typename ValueType_, typename Codec_>
1145 std::unique_ptr<const NamePair> TypedAttributeArray<ValueType_, Codec_>::sTypeName;
1146 
1147 
1148 template<typename ValueType_, typename Codec_>
1150  Index n, Index strideOrTotalSize, bool constantStride, const ValueType& uniformValue)
1151  : AttributeArray()
1152  , mData(new StorageType[1])
1153  , mSize(n)
1154  , mStrideOrTotalSize(strideOrTotalSize)
1155 {
1156  if (constantStride) {
1157  this->setConstantStride(true);
1158  if (strideOrTotalSize == 0) {
1159  OPENVDB_THROW(ValueError, "Creating a TypedAttributeArray with a constant stride requires that " \
1160  "stride to be at least one.")
1161  }
1162  }
1163  else {
1164  this->setConstantStride(false);
1165  if (mStrideOrTotalSize < n) {
1166  OPENVDB_THROW(ValueError, "Creating a TypedAttributeArray with a non-constant stride must have " \
1167  "a total size of at least the number of elements in the array.")
1168  }
1169  }
1170  mSize = std::max(Index(1), mSize);
1171  mStrideOrTotalSize = std::max(Index(1), mStrideOrTotalSize);
1172  Codec::encode(uniformValue, this->data()[0]);
1173 }
1174 
1175 
1176 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1177 template<typename ValueType_, typename Codec_>
1179  : TypedAttributeArray(rhs, tbb::spin_mutex::scoped_lock(rhs.mMutex))
1180 {
1181 }
1182 
1183 
1184 template<typename ValueType_, typename Codec_>
1186  const tbb::spin_mutex::scoped_lock& lock)
1187  : AttributeArray(rhs, lock)
1188 #else
1189 template<typename ValueType_, typename Codec_>
1190 TypedAttributeArray<ValueType_, Codec_>::TypedAttributeArray(const TypedAttributeArray& rhs, bool)
1191  : AttributeArray(rhs)
1192 #endif
1193  , mSize(rhs.mSize)
1194  , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1195 #if OPENVDB_ABI_VERSION_NUMBER < 6
1196  , mIsUniform(rhs.mIsUniform)
1197 #endif
1198 {
1199  if (this->validData()) {
1200  this->allocate();
1201  std::memcpy(static_cast<void*>(this->data()), rhs.data(), this->arrayMemUsage());
1202  }
1203 }
1204 
1205 
1206 template<typename ValueType_, typename Codec_>
1207 TypedAttributeArray<ValueType_, Codec_>&
1209 {
1210  if (&rhs != this) {
1211  // lock both the source and target arrays to ensure thread-safety
1212  tbb::spin_mutex::scoped_lock lock(mMutex);
1213  tbb::spin_mutex::scoped_lock rhsLock(rhs.mMutex);
1214 
1215  this->deallocate();
1216 
1217  mFlags = rhs.mFlags;
1218  mUsePagedRead = rhs.mUsePagedRead;
1219  mSize = rhs.mSize;
1220  mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1221  mIsUniform = rhs.mIsUniform;
1222 
1223  if (this->validData()) {
1224  this->allocate();
1225  std::memcpy(static_cast<void*>(this->data()), rhs.data(), this->arrayMemUsage());
1226  }
1227  }
1228 
1229  return *this;
1230 }
1231 
1232 
1233 template<typename ValueType_, typename Codec_>
1234 inline const NamePair&
1236 {
1237  static std::once_flag once;
1238  std::call_once(once, []()
1239  {
1240  sTypeName.reset(new NamePair(typeNameAsString<ValueType>(), Codec::name()));
1241  });
1242  return *sTypeName;
1243 }
1244 
1245 
1246 template<typename ValueType_, typename Codec_>
1247 inline bool
1249 {
1251 }
1252 
1253 
1254 template<typename ValueType_, typename Codec_>
1255 inline void
1257 {
1258  AttributeArray::registerType(TypedAttributeArray::attributeType(), TypedAttributeArray::factory);
1259 }
1260 
1261 
1262 template<typename ValueType_, typename Codec_>
1263 inline void
1265 {
1267 }
1268 
1269 
1270 template<typename ValueType_, typename Codec_>
1273  const Metadata* metadata)
1274 {
1275  const TypedMetadata<ValueType>* typedMetadata = metadata ?
1276  dynamic_cast<const TypedMetadata<ValueType>*>(metadata) : nullptr;
1277 
1278  return Ptr(new TypedAttributeArray(n, stride, constantStride,
1279  typedMetadata ? typedMetadata->value() : zeroVal<ValueType>()));
1280 }
1281 
1282 template<typename ValueType_, typename Codec_>
1285 {
1286  if (!attributeArray.isType<TypedAttributeArray>()) {
1287  OPENVDB_THROW(TypeError, "Invalid Attribute Type");
1288  }
1289  return static_cast<TypedAttributeArray&>(attributeArray);
1290 }
1291 
1292 template<typename ValueType_, typename Codec_>
1295 {
1296  if (!attributeArray.isType<TypedAttributeArray>()) {
1297  OPENVDB_THROW(TypeError, "Invalid Attribute Type");
1298  }
1299  return static_cast<const TypedAttributeArray&>(attributeArray);
1300 }
1301 
1302 template<typename ValueType_, typename Codec_>
1305 {
1306 #if OPENVDB_ABI_VERSION_NUMBER < 7
1307  tbb::spin_mutex::scoped_lock lock(mMutex);
1308 #endif
1310 }
1311 
1312 
1313 template<typename ValueType_, typename Codec_>
1316 {
1317  return this->copy();
1318 }
1319 
1320 
1321 template<typename ValueType_, typename Codec_>
1322 size_t
1324 {
1325  if (this->isOutOfCore()) return 0;
1326 
1327  return (mIsUniform ? 1 : this->dataSize()) * sizeof(StorageType);
1328 }
1329 
1330 
1331 template<typename ValueType_, typename Codec_>
1332 void
1333 TypedAttributeArray<ValueType_, Codec_>::allocate()
1334 {
1335  assert(!mData);
1336  if (mIsUniform) {
1337  mData.reset(new StorageType[1]);
1338  }
1339  else {
1340  const size_t size(this->dataSize());
1341  assert(size > 0);
1342  mData.reset(new StorageType[size]);
1343  }
1344 }
1345 
1346 
1347 template<typename ValueType_, typename Codec_>
1348 void
1349 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1350 {
1351  // detach from file if delay-loaded
1352  if (this->isOutOfCore()) {
1353  this->setOutOfCore(false);
1354  this->mPageHandle.reset();
1355  }
1356  if (mData) mData.reset();
1357 }
1358 
1359 
1360 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1361 template<typename ValueType_, typename Codec_>
1362 bool
1364 {
1365  // TODO: Update to use Traits that correctly handle matrices and quaternions.
1366 
1367  if (std::is_same<ValueType, Quats>::value ||
1368  std::is_same<ValueType, Quatd>::value ||
1369  std::is_same<ValueType, Mat3s>::value ||
1370  std::is_same<ValueType, Mat3d>::value ||
1371  std::is_same<ValueType, Mat4s>::value ||
1372  std::is_same<ValueType, Mat4d>::value) return true;
1373 
1374  using ElementT = typename VecTraits<ValueType>::ElementType;
1375 
1376  // half is not defined as float point as expected, so explicitly handle it
1377  return std::is_floating_point<ElementT>::value || std::is_same<half, ElementT>::value;
1378 }
1379 
1380 
1381 template<typename ValueType_, typename Codec_>
1382 bool
1384 {
1385  // half is not defined as a non-class type as expected, so explicitly exclude it
1386  return std::is_class<ValueType>::value && !std::is_same<half, ValueType>::value;
1387 }
1388 
1389 
1390 template<typename ValueType_, typename Codec_>
1391 bool
1393 {
1395 }
1396 
1397 
1398 template<typename ValueType_, typename Codec_>
1399 bool
1401 {
1402  // TODO: improve performance by making this a compile-time check using type traits
1403  return !this->valueType().compare(0, 4, "quat");
1404 }
1405 
1406 
1407 template<typename ValueType_, typename Codec_>
1408 bool
1410 {
1411  // TODO: improve performance by making this a compile-time check using type traits
1412  return !this->valueType().compare(0, 3, "mat");
1413 }
1414 #endif
1415 
1416 
1417 template<typename ValueType_, typename Codec_>
1418 size_t
1420 {
1421  return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1422 }
1423 
1424 
1425 template<typename ValueType_, typename Codec_>
1428 {
1429  assert(n < this->dataSize());
1430 
1431  ValueType val;
1432  Codec::decode(/*in=*/this->data()[mIsUniform ? 0 : n], /*out=*/val);
1433  return val;
1434 }
1435 
1436 
1437 template<typename ValueType_, typename Codec_>
1440 {
1441  if (n >= this->dataSize()) OPENVDB_THROW(IndexError, "Out-of-range access.");
1442  if (this->isOutOfCore()) this->doLoad();
1443 
1444  return this->getUnsafe(n);
1445 }
1446 
1447 
1448 template<typename ValueType_, typename Codec_>
1449 template<typename T>
1450 void
1452 {
1453  val = static_cast<T>(this->getUnsafe(n));
1454 }
1455 
1456 
1457 template<typename ValueType_, typename Codec_>
1458 template<typename T>
1459 void
1461 {
1462  val = static_cast<T>(this->get(n));
1463 }
1464 
1465 
1466 template<typename ValueType_, typename Codec_>
1469 {
1470  return static_cast<const TypedAttributeArray<ValueType, Codec>*>(array)->getUnsafe(n);
1471 }
1472 
1473 
1474 template<typename ValueType_, typename Codec_>
1475 void
1477 {
1478  assert(n < this->dataSize());
1479  assert(!this->isOutOfCore());
1480  assert(!this->isUniform());
1481 
1482  // this unsafe method assumes the data is not uniform, however if it is, this redirects the index
1483  // to zero, which is marginally less efficient but ensures not writing to an illegal address
1484 
1485  Codec::encode(/*in=*/val, /*out=*/this->data()[mIsUniform ? 0 : n]);
1486 }
1487 
1488 
1489 template<typename ValueType_, typename Codec_>
1490 void
1492 {
1493  if (n >= this->dataSize()) OPENVDB_THROW(IndexError, "Out-of-range access.");
1494  if (this->isOutOfCore()) this->doLoad();
1495  if (this->isUniform()) this->expand();
1496 
1497  this->setUnsafe(n, val);
1498 }
1499 
1500 
1501 template<typename ValueType_, typename Codec_>
1502 template<typename T>
1503 void
1505 {
1506  this->setUnsafe(n, static_cast<ValueType>(val));
1507 }
1508 
1509 
1510 template<typename ValueType_, typename Codec_>
1511 template<typename T>
1512 void
1514 {
1515  this->set(n, static_cast<ValueType>(val));
1516 }
1517 
1518 
1519 template<typename ValueType_, typename Codec_>
1520 void
1522 {
1523  static_cast<TypedAttributeArray<ValueType, Codec>*>(array)->setUnsafe(n, value);
1524 }
1525 
1526 
1527 template<typename ValueType_, typename Codec_>
1528 void
1530 {
1531  const TypedAttributeArray& sourceTypedArray = static_cast<const TypedAttributeArray&>(sourceArray);
1532 
1533  ValueType sourceValue;
1534  sourceTypedArray.get(sourceIndex, sourceValue);
1535 
1536  this->set(n, sourceValue);
1537 }
1538 
1539 
1540 template<typename ValueType_, typename Codec_>
1541 void
1543 {
1544  if (!mIsUniform) return;
1545 
1546  const StorageType val = this->data()[0];
1547 
1548  {
1549  tbb::spin_mutex::scoped_lock lock(mMutex);
1550  this->deallocate();
1551  mIsUniform = false;
1552  this->allocate();
1553  }
1554 
1555  if (fill) {
1556  for (Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1557  }
1558 }
1559 
1560 
1561 template<typename ValueType_, typename Codec_>
1562 bool
1564 {
1565  if (mIsUniform) return true;
1566 
1567  // compaction is not possible if any values are different
1568  const ValueType_ val = this->get(0);
1569  for (Index i = 1; i < this->dataSize(); i++) {
1570  if (!math::isExactlyEqual(this->get(i), val)) return false;
1571  }
1572 
1573  this->collapse(this->get(0));
1574  return true;
1575 }
1576 
1577 
1578 template<typename ValueType_, typename Codec_>
1579 void
1581 {
1582  this->collapse(zeroVal<ValueType>());
1583 }
1584 
1585 
1586 template<typename ValueType_, typename Codec_>
1587 void
1589 {
1590  if (!mIsUniform) {
1591  tbb::spin_mutex::scoped_lock lock(mMutex);
1592  this->deallocate();
1593  mIsUniform = true;
1594  this->allocate();
1595  }
1596  Codec::encode(uniformValue, this->data()[0]);
1597 }
1598 
1599 
1600 template<typename ValueType_, typename Codec_>
1601 void
1603 {
1604  static_cast<TypedAttributeArray<ValueType, Codec>*>(array)->collapse(value);
1605 }
1606 
1607 
1608 template<typename ValueType_, typename Codec_>
1609 void
1611 {
1612  if (this->isOutOfCore()) {
1613  tbb::spin_mutex::scoped_lock lock(mMutex);
1614  this->deallocate();
1615  this->allocate();
1616  }
1617 
1618  const Index size = mIsUniform ? 1 : this->dataSize();
1619  for (Index i = 0; i < size; ++i) {
1620  Codec::encode(value, this->data()[i]);
1621  }
1622 }
1623 
1624 
1625 template<typename ValueType_, typename Codec_>
1626 void
1628 {
1629  static_cast<TypedAttributeArray<ValueType, Codec>*>(array)->fill(value);
1630 }
1631 
1632 
1633 template<typename ValueType_, typename Codec_>
1634 inline bool
1636 {
1637  return false;
1638 }
1639 
1640 
1641 template<typename ValueType_, typename Codec_>
1642 inline bool
1644 {
1645  return false;
1646 }
1647 
1648 
1649 template<typename ValueType_, typename Codec_>
1650 inline bool
1652 {
1653  return false;
1654 }
1655 
1656 
1657 template<typename ValueType_, typename Codec_>
1658 bool
1660 {
1661  return mOutOfCore;
1662 }
1663 
1664 
1665 template<typename ValueType_, typename Codec_>
1666 void
1668 {
1669  mOutOfCore = b;
1670 }
1671 
1672 
1673 template<typename ValueType_, typename Codec_>
1674 void
1675 TypedAttributeArray<ValueType_, Codec_>::doLoad() const
1676 {
1677  if (!(this->isOutOfCore())) return;
1678 
1679  TypedAttributeArray<ValueType_, Codec_>* self =
1680  const_cast<TypedAttributeArray<ValueType_, Codec_>*>(this);
1681 
1682  // This lock will be contended at most once, after which this buffer
1683  // will no longer be out-of-core.
1684  tbb::spin_mutex::scoped_lock lock(self->mMutex);
1685  this->doLoadUnsafe();
1686 }
1687 
1688 
1689 template<typename ValueType_, typename Codec_>
1690 void
1692 {
1693  this->doLoad();
1694 }
1695 
1696 
1697 #if OPENVDB_ABI_VERSION_NUMBER >= 6
1698 template<typename ValueType_, typename Codec_>
1699 bool
1701 {
1702  return !this->isOutOfCore();
1703 }
1704 #endif
1705 
1706 
1707 template<typename ValueType_, typename Codec_>
1708 void
1710 {
1711  this->readMetadata(is);
1712  this->readBuffers(is);
1713 }
1714 
1715 
1716 template<typename ValueType_, typename Codec_>
1717 void
1719 {
1720  // read data
1721 
1722  Index64 bytes = Index64(0);
1723  is.read(reinterpret_cast<char*>(&bytes), sizeof(Index64));
1724  bytes = bytes - /*flags*/sizeof(Int16) - /*size*/sizeof(Index);
1725 
1726  uint8_t flags = uint8_t(0);
1727  is.read(reinterpret_cast<char*>(&flags), sizeof(uint8_t));
1728  mFlags = flags;
1729 
1730  uint8_t serializationFlags = uint8_t(0);
1731  is.read(reinterpret_cast<char*>(&serializationFlags), sizeof(uint8_t));
1732 
1733  Index size = Index(0);
1734  is.read(reinterpret_cast<char*>(&size), sizeof(Index));
1735  mSize = size;
1736 
1737  // warn if an unknown flag has been set
1738  if (mFlags >= 0x20) {
1739  OPENVDB_LOG_WARN("Unknown attribute flags for VDB file format.");
1740  }
1741  // error if an unknown serialization flag has been set,
1742  // as this will adjust the layout of the data and corrupt the ability to read
1743  if (serializationFlags >= 0x10) {
1744  OPENVDB_THROW(IoError, "Unknown attribute serialization flags for VDB file format.");
1745  }
1746 
1747  // set uniform, compressed and page read state
1748 
1749  mIsUniform = serializationFlags & WRITEUNIFORM;
1750  mUsePagedRead = serializationFlags & WRITEPAGED;
1751  mCompressedBytes = bytes;
1752  mFlags |= PARTIALREAD; // mark data as having been partially read
1753 
1754  // read strided value (set to 1 if array is not strided)
1755 
1756  if (serializationFlags & WRITESTRIDED) {
1757  Index stride = Index(0);
1758  is.read(reinterpret_cast<char*>(&stride), sizeof(Index));
1759  mStrideOrTotalSize = stride;
1760  }
1761  else {
1762  mStrideOrTotalSize = 1;
1763  }
1764 }
1765 
1766 
1767 template<typename ValueType_, typename Codec_>
1768 void
1770 {
1771  if (mUsePagedRead) {
1772  // use readBuffers(PagedInputStream&) for paged buffers
1773  OPENVDB_THROW(IoError, "Cannot read paged AttributeArray buffers.");
1774  }
1775 
1776  tbb::spin_mutex::scoped_lock lock(mMutex);
1777 
1778  this->deallocate();
1779 
1780  uint8_t bloscCompressed(0);
1781  if (!mIsUniform) is.read(reinterpret_cast<char*>(&bloscCompressed), sizeof(uint8_t));
1782 
1783  assert(mFlags & PARTIALREAD);
1784  std::unique_ptr<char[]> buffer(new char[mCompressedBytes]);
1785  is.read(buffer.get(), mCompressedBytes);
1786  mCompressedBytes = 0;
1787  mFlags = static_cast<uint8_t>(mFlags & ~PARTIALREAD); // mark data read as having completed
1788 
1789  // compressed on-disk
1790 
1791  if (bloscCompressed == uint8_t(1)) {
1792 
1793  // decompress buffer
1794 
1795  const size_t inBytes = this->dataSize() * sizeof(StorageType);
1796  std::unique_ptr<char[]> newBuffer = compression::bloscDecompress(buffer.get(), inBytes);
1797  if (newBuffer) buffer.reset(newBuffer.release());
1798  }
1799 
1800  // set data to buffer
1801 
1802  mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1803 }
1804 
1805 
1806 template<typename ValueType_, typename Codec_>
1807 void
1809 {
1810  if (!mUsePagedRead) {
1811  if (!is.sizeOnly()) this->readBuffers(is.getInputStream());
1812  return;
1813  }
1814 
1815  // If this array is being read from a memory-mapped file, delay loading of its data
1816  // until the data is actually accessed.
1818  const bool delayLoad = (mappedFile.get() != nullptr);
1819 
1820  if (is.sizeOnly())
1821  {
1822  size_t compressedBytes(mCompressedBytes);
1823  mCompressedBytes = 0; // if not set to zero, mPageHandle will attempt to destroy invalid memory
1824  mFlags = static_cast<uint8_t>(mFlags & ~PARTIALREAD); // mark data read as having completed
1825  assert(!mPageHandle);
1826  mPageHandle = is.createHandle(compressedBytes);
1827  return;
1828  }
1829 
1830  assert(mPageHandle);
1831 
1832  tbb::spin_mutex::scoped_lock lock(mMutex);
1833 
1834  this->deallocate();
1835 
1836  this->setOutOfCore(delayLoad);
1837  is.read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1838 
1839  if (!delayLoad) {
1840  std::unique_ptr<char[]> buffer = mPageHandle->read();
1841  mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1842  }
1843 
1844  // clear page state
1845 
1846  mUsePagedRead = 0;
1847 }
1848 
1849 
1850 template<typename ValueType_, typename Codec_>
1851 void
1853 {
1854  this->write(os, /*outputTransient=*/false);
1855 }
1856 
1857 
1858 template<typename ValueType_, typename Codec_>
1859 void
1860 TypedAttributeArray<ValueType_, Codec_>::write(std::ostream& os, bool outputTransient) const
1861 {
1862  this->writeMetadata(os, outputTransient, /*paged=*/false);
1863  this->writeBuffers(os, outputTransient);
1864 }
1865 
1866 
1867 template<typename ValueType_, typename Codec_>
1868 void
1869 TypedAttributeArray<ValueType_, Codec_>::writeMetadata(std::ostream& os, bool outputTransient, bool paged) const
1870 {
1871  if (!outputTransient && this->isTransient()) return;
1872 
1873  if (mFlags & PARTIALREAD) {
1874  OPENVDB_THROW(IoError, "Cannot write out a partially-read AttributeArray.");
1875  }
1876 
1877  uint8_t flags(mFlags);
1878  uint8_t serializationFlags(0);
1879  Index size(mSize);
1880  Index stride(mStrideOrTotalSize);
1881  bool strideOfOne(this->stride() == 1);
1882 
1883  bool bloscCompression = io::getDataCompression(os) & io::COMPRESS_BLOSC;
1884 
1885  // any compressed data needs to be loaded if out-of-core
1886  if (bloscCompression) this->doLoad();
1887 
1888  size_t compressedBytes = 0;
1889 
1890  if (!strideOfOne)
1891  {
1892  serializationFlags |= WRITESTRIDED;
1893  }
1894 
1895  if (mIsUniform)
1896  {
1897  serializationFlags |= WRITEUNIFORM;
1898  if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1899  }
1900  else if (bloscCompression)
1901  {
1902  if (paged) serializationFlags |= WRITEPAGED;
1903  else {
1904  const char* charBuffer = reinterpret_cast<const char*>(this->data());
1905  const size_t inBytes = this->arrayMemUsage();
1906  compressedBytes = compression::bloscCompressedSize(charBuffer, inBytes);
1907  }
1908  }
1909 
1910  Index64 bytes = /*flags*/ sizeof(Int16) + /*size*/ sizeof(Index);
1911 
1912  bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1913 
1914  // write data
1915 
1916  os.write(reinterpret_cast<const char*>(&bytes), sizeof(Index64));
1917  os.write(reinterpret_cast<const char*>(&flags), sizeof(uint8_t));
1918  os.write(reinterpret_cast<const char*>(&serializationFlags), sizeof(uint8_t));
1919  os.write(reinterpret_cast<const char*>(&size), sizeof(Index));
1920 
1921  // write strided
1922  if (!strideOfOne) os.write(reinterpret_cast<const char*>(&stride), sizeof(Index));
1923 }
1924 
1925 
1926 template<typename ValueType_, typename Codec_>
1927 void
1928 TypedAttributeArray<ValueType_, Codec_>::writeBuffers(std::ostream& os, bool outputTransient) const
1929 {
1930  if (!outputTransient && this->isTransient()) return;
1931 
1932  if (mFlags & PARTIALREAD) {
1933  OPENVDB_THROW(IoError, "Cannot write out a partially-read AttributeArray.");
1934  }
1935 
1936  this->doLoad();
1937 
1938  if (this->isUniform()) {
1939  os.write(reinterpret_cast<const char*>(this->data()), sizeof(StorageType));
1940  }
1942  {
1943  std::unique_ptr<char[]> compressedBuffer;
1944  size_t compressedBytes = 0;
1945  const char* charBuffer = reinterpret_cast<const char*>(this->data());
1946  const size_t inBytes = this->arrayMemUsage();
1947  compressedBuffer = compression::bloscCompress(charBuffer, inBytes, compressedBytes);
1948  if (compressedBuffer) {
1949  uint8_t bloscCompressed(1);
1950  os.write(reinterpret_cast<const char*>(&bloscCompressed), sizeof(uint8_t));
1951  os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
1952  }
1953  else {
1954  uint8_t bloscCompressed(0);
1955  os.write(reinterpret_cast<const char*>(&bloscCompressed), sizeof(uint8_t));
1956  os.write(reinterpret_cast<const char*>(this->data()), inBytes);
1957  }
1958  }
1959  else
1960  {
1961  uint8_t bloscCompressed(0);
1962  os.write(reinterpret_cast<const char*>(&bloscCompressed), sizeof(uint8_t));
1963  os.write(reinterpret_cast<const char*>(this->data()), this->arrayMemUsage());
1964  }
1965 }
1966 
1967 
1968 template<typename ValueType_, typename Codec_>
1969 void
1971 {
1972  if (!outputTransient && this->isTransient()) return;
1973 
1974  // paged compression only available when Blosc is enabled
1975  bool bloscCompression = io::getDataCompression(os.getOutputStream()) & io::COMPRESS_BLOSC;
1976  if (!bloscCompression) {
1977  if (!os.sizeOnly()) this->writeBuffers(os.getOutputStream(), outputTransient);
1978  return;
1979  }
1980 
1981  if (mFlags & PARTIALREAD) {
1982  OPENVDB_THROW(IoError, "Cannot write out a partially-read AttributeArray.");
1983  }
1984 
1985  this->doLoad();
1986 
1987  os.write(reinterpret_cast<const char*>(this->data()), this->arrayMemUsage());
1988 }
1989 
1990 
1991 template<typename ValueType_, typename Codec_>
1992 void
1993 TypedAttributeArray<ValueType_, Codec_>::doLoadUnsafe(const bool /*compression*/) const
1994 {
1995  if (!(this->isOutOfCore())) return;
1996 
1997  // this function expects the mutex to already be locked
1998 
1999  auto* self = const_cast<TypedAttributeArray<ValueType_, Codec_>*>(this);
2000 
2001  assert(self->mPageHandle);
2002  assert(!(self->mFlags & PARTIALREAD));
2003 
2004  std::unique_ptr<char[]> buffer = self->mPageHandle->read();
2005 
2006  self->mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
2007 
2008  self->mPageHandle.reset();
2009 
2010  // clear all write and out-of-core flags
2011 
2012  self->mOutOfCore = false;
2013 }
2014 
2015 
2016 template<typename ValueType_, typename Codec_>
2019 {
2020  // use the faster 'unsafe' get and set methods as attribute handles
2021  // ensure data is in-core when constructed
2022 
2028 }
2029 
2030 
2031 template<typename ValueType_, typename Codec_>
2032 bool
2034 {
2035  const TypedAttributeArray<ValueType_, Codec_>* const otherT = dynamic_cast<const TypedAttributeArray<ValueType_, Codec_>* >(&other);
2036  if(!otherT) return false;
2037  if(this->mSize != otherT->mSize ||
2038  this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
2039  this->mIsUniform != otherT->mIsUniform ||
2040  this->attributeType() != this->attributeType()) return false;
2041 
2042  this->doLoad();
2043  otherT->doLoad();
2044 
2045  const StorageType *target = this->data(), *source = otherT->data();
2046  if (!target && !source) return true;
2047  if (!target || !source) return false;
2048  Index n = this->mIsUniform ? 1 : mSize;
2049  while (n && math::isExactlyEqual(*target++, *source++)) --n;
2050  return n == 0;
2051 }
2052 
2053 
2054 #if OPENVDB_ABI_VERSION_NUMBER >= 6
2055 template<typename ValueType_, typename Codec_>
2056 char*
2057 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2058 {
2059  return reinterpret_cast<char*>(this->data());
2060 }
2061 
2062 
2063 template<typename ValueType_, typename Codec_>
2064 const char*
2065 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray() const
2066 {
2067  return reinterpret_cast<const char*>(this->data());
2068 }
2069 #endif
2070 
2071 
2073 
2074 
2076 template <typename CodecType, typename ValueType>
2078 {
2079  using GetterPtr = ValueType (*)(const AttributeArray* array, const Index n);
2080  using SetterPtr = void (*)(AttributeArray* array, const Index n, const ValueType& value);
2081 
2084  static ValueType get(GetterPtr /*functor*/, const AttributeArray* array, const Index n) {
2086  }
2087 
2090  static void set(SetterPtr /*functor*/, AttributeArray* array, const Index n, const ValueType& value) {
2092  }
2093 };
2094 
2095 
2097 template <typename ValueType>
2098 struct AccessorEval<UnknownCodec, ValueType>
2099 {
2100  using GetterPtr = ValueType (*)(const AttributeArray* array, const Index n);
2101  using SetterPtr = void (*)(AttributeArray* array, const Index n, const ValueType& value);
2102 
2104  static ValueType get(GetterPtr functor, const AttributeArray* array, const Index n) {
2105  return (*functor)(array, n);
2106  }
2107 
2109  static void set(SetterPtr functor, AttributeArray* array, const Index n, const ValueType& value) {
2110  (*functor)(array, n, value);
2111  }
2112 };
2113 
2114 
2116 
2117 // AttributeHandle implementation
2118 
2119 template <typename ValueType, typename CodecType>
2121 AttributeHandle<ValueType, CodecType>::create(const AttributeArray& array, const bool collapseOnDestruction)
2122 {
2124  new AttributeHandle<ValueType, CodecType>(array, collapseOnDestruction));
2125 }
2126 
2127 template <typename ValueType, typename CodecType>
2128 AttributeHandle<ValueType, CodecType>::AttributeHandle(const AttributeArray& array, const bool collapseOnDestruction)
2129  : mArray(&array)
2130  , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2131  , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2132  , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2133 {
2134  if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2135  OPENVDB_THROW(TypeError, "Cannot bind handle due to incompatible type of AttributeArray.");
2136  }
2137 
2138  // load data if delay-loaded
2139 
2140  mArray->loadData();
2141 
2142  // bind getter and setter methods
2143 
2145  assert(accessor);
2146 
2147  AttributeArray::Accessor<ValueType>* typedAccessor = static_cast<AttributeArray::Accessor<ValueType>*>(accessor.get());
2148 
2149  mGetter = typedAccessor->mGetter;
2150  mSetter = typedAccessor->mSetter;
2151  mCollapser = typedAccessor->mCollapser;
2152  mFiller = typedAccessor->mFiller;
2153 }
2154 
2155 template <typename ValueType, typename CodecType>
2157 {
2158  // if enabled, attribute is collapsed on destruction of the handle to save memory
2159  if (mCollapseOnDestruction) const_cast<AttributeArray*>(this->mArray)->collapse();
2160 }
2161 
2162 template <typename ValueType, typename CodecType>
2163 template <bool IsUnknownCodec>
2164 typename std::enable_if<IsUnknownCodec, bool>::type
2166 {
2167  // if codec is unknown, just check the value type
2168 
2169  return mArray->hasValueType<ValueType>();
2170 }
2171 
2172 template <typename ValueType, typename CodecType>
2173 template <bool IsUnknownCodec>
2174 typename std::enable_if<!IsUnknownCodec, bool>::type
2175 AttributeHandle<ValueType, CodecType>::compatibleType() const
2176 {
2177  // if the codec is known, check the value type and codec
2178 
2179  return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2180 }
2181 
2182 template <typename ValueType, typename CodecType>
2184 {
2185  assert(mArray);
2186  return *mArray;
2187 }
2188 
2189 template <typename ValueType, typename CodecType>
2191 {
2192  Index index = n * mStrideOrTotalSize + m;
2193  assert(index < (mSize * mStrideOrTotalSize));
2194  return index;
2195 }
2196 
2197 template <typename ValueType, typename CodecType>
2199 {
2200  return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2201 }
2202 
2203 template <typename ValueType, typename CodecType>
2204 template <bool IsUnknownCodec>
2205 typename std::enable_if<IsUnknownCodec, ValueType>::type
2207 {
2208  // if the codec is unknown, use the getter functor
2209 
2210  return (*mGetter)(mArray, index);
2211 }
2212 
2213 template <typename ValueType, typename CodecType>
2214 template <bool IsUnknownCodec>
2215 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2217 {
2218  // if the codec is known, call the method on the attribute array directly
2219 
2221 }
2222 
2223 template <typename ValueType, typename CodecType>
2225 {
2226  return mArray->isUniform();
2227 }
2228 
2229 template <typename ValueType, typename CodecType>
2231 {
2232  return mArray->hasConstantStride();
2233 }
2234 
2236 
2237 // AttributeWriteHandle implementation
2238 
2239 template <typename ValueType, typename CodecType>
2242 {
2244  new AttributeWriteHandle<ValueType, CodecType>(array, expand));
2245 }
2246 
2247 template <typename ValueType, typename CodecType>
2249  : AttributeHandle<ValueType, CodecType>(array, /*collapseOnDestruction=*/false)
2250 {
2251  if (expand) array.expand();
2252 }
2253 
2254 template <typename ValueType, typename CodecType>
2256 {
2257  this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2258 }
2259 
2260 template <typename ValueType, typename CodecType>
2262 {
2263  this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2264 }
2265 
2266 template <typename ValueType, typename CodecType>
2268 {
2269  const_cast<AttributeArray*>(this->mArray)->expand(fill);
2270 }
2271 
2272 template <typename ValueType, typename CodecType>
2274 {
2275  const_cast<AttributeArray*>(this->mArray)->collapse();
2276 }
2277 
2278 template <typename ValueType, typename CodecType>
2280 {
2281  return const_cast<AttributeArray*>(this->mArray)->compact();
2282 }
2283 
2284 template <typename ValueType, typename CodecType>
2285 void AttributeWriteHandle<ValueType, CodecType>::collapse(const ValueType& uniformValue)
2286 {
2287  this->mCollapser(const_cast<AttributeArray*>(this->mArray), uniformValue);
2288 }
2289 
2290 template <typename ValueType, typename CodecType>
2292 {
2293  this->mFiller(const_cast<AttributeArray*>(this->mArray), value);
2294 }
2295 
2296 template <typename ValueType, typename CodecType>
2297 template <bool IsUnknownCodec>
2298 typename std::enable_if<IsUnknownCodec, void>::type
2299 AttributeWriteHandle<ValueType, CodecType>::set(Index index, const ValueType& value) const
2300 {
2301  // if the codec is unknown, use the setter functor
2302 
2303  (*this->mSetter)(const_cast<AttributeArray*>(this->mArray), index, value);
2304 }
2305 
2306 template <typename ValueType, typename CodecType>
2307 template <bool IsUnknownCodec>
2308 typename std::enable_if<!IsUnknownCodec, void>::type
2309 AttributeWriteHandle<ValueType, CodecType>::set(Index index, const ValueType& value) const
2310 {
2311  // if the codec is known, call the method on the attribute array directly
2312 
2313  TypedAttributeArray<ValueType, CodecType>::setUnsafe(const_cast<AttributeArray*>(this->mArray), index, value);
2314 }
2315 
2316 template <typename ValueType, typename CodecType>
2318 {
2319  assert(this->mArray);
2320  return *const_cast<AttributeArray*>(this->mArray);
2321 }
2322 
2323 
2324 } // namespace points
2325 } // namespace OPENVDB_VERSION_NAME
2326 } // namespace openvdb
2327 
2328 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
openvdb::v7_2::IoError
Definition: openvdb/Exceptions.h:58
Types.h
openvdb::v7_2::points::AttributeArray::~AttributeArray
virtual ~AttributeArray()
Definition: AttributeArray.h:133
openvdb::v7_2::points::TypedAttributeArray::memUsage
size_t memUsage() const override
Return the number of bytes of memory used by this attribute.
Definition: AttributeArray.h:1419
openvdb::v7_2::points::TypedAttributeArray::read
void read(std::istream &) override
Read attribute data from a stream.
Definition: AttributeArray.h:1709
openvdb::v7_2::points::TypedAttributeArray::compress
OPENVDB_DEPRECATED bool compress() override
Compress the attribute array.
Definition: AttributeArray.h:1635
Compression.h
openvdb::v7_2::points::AttributeWriteHandle::Ptr
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:923
openvdb::v7_2::points::PositionRange::name
static const char * name()
Definition: AttributeArray.h:511
openvdb::v7_2::points::AttributeArray::create
static OPENVDB_DEPRECATED Ptr create(const NamePair &type, Index length, Index stride, bool constantStride, const ScopedRegistryLock *lock)
openvdb::v7_2::points::TypedAttributeArray::storageTypeSize
Index storageTypeSize() const override
Definition: AttributeArray.h:662
openvdb::v7_2::points::attribute_traits::UIntTypeTrait< false, T >::Type
uint16_t Type
Definition: AttributeArray.h:468
openvdb::v7_2::math::Vec3::x
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:83
openvdb::v7_2::points::AttributeHandle::mArray
const AttributeArray * mArray
Definition: AttributeArray.h:883
openvdb::v7_2::points::AttributeHandle::get
ValueType get(Index n, Index m=0) const
Definition: AttributeArray.h:2198
openvdb::v7_2::points::AttributeArray::operator=
AttributeArray & operator=(const AttributeArray &rhs)
openvdb::v7_2::points::PositionRange::decode
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:513
openvdb::v7_2::points::AttributeArray::readPagedBuffers
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
openvdb::v7_2::points::AttributeArray::stride
virtual Index stride() const =0
StreamCompression.h
Convenience wrappers to using Blosc and reading and writing of Paged data.
openvdb::v7_2::TypedMetadata::value
T & value()
Return this metadata's value.
Definition: Metadata.h:249
openvdb::v7_2::points::UnitVecCodec
Definition: AttributeArray.h:543
openvdb::v7_2::points::AttributeArray::AttributeArray
AttributeArray(AttributeArray &&)=delete
openvdb::v7_2::points::AttributeHandle< Index, openvdb::v7_2::points::StringCodec< false > >::Ptr
std::shared_ptr< Handle > Ptr
Definition: AttributeArray.h:852
openvdb::v7_2::points::TypedAttributeArray::isRegistered
static bool isRegistered()
Return true if this attribute type is registered.
Definition: AttributeArray.h:1248
openvdb::v7_2::points::AttributeArray::Accessor
Definition: AttributeArray.h:438
openvdb::v7_2::points::AttributeHandle< Index, openvdb::v7_2::points::StringCodec< false > >::GetterPtr
Index(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:856
openvdb::v7_2::points::AttributeWriteHandle::AttributeWriteHandle
AttributeWriteHandle(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2248
openvdb::v7_2::points::TypedAttributeArray::valueTypeIsClass
bool valueTypeIsClass() const override
Return true if the value type is a class (ie vector, matrix or quaternion return true)
Definition: AttributeArray.h:1383
openvdb::v7_2::points::UnitRange
Definition: AttributeArray.h:519
openvdb::v7_2::points::TypedAttributeArray::valueTypeIsFloatingPoint
bool valueTypeIsFloatingPoint() const override
Return true if the value type is floating point.
Definition: AttributeArray.h:1363
openvdb::v7_2::points::TypedAttributeArray::TypedAttributeArray
OPENVDB_DEPRECATED TypedAttributeArray(const TypedAttributeArray &, bool)
openvdb::v7_2::points::AttributeHandle::index
Index index(Index n, Index m) const
Definition: AttributeArray.h:2190
openvdb::v7_2::points::AttributeArray::write
virtual void write(std::ostream &) const =0
Write attribute metadata and buffers to a stream, don't write transient attributes.
openvdb::v7_2::points::TypedAttributeArray::compact
bool compact() override
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:1563
openvdb::v7_2::points::TypedAttributeArray::valueTypeIsMatrix
bool valueTypeIsMatrix() const override
Return true if the value type is a matrix.
Definition: AttributeArray.h:1409
openvdb::v7_2::points::AttributeArray::readMetadata
virtual void readMetadata(std::istream &)=0
Read attribute metadata from a stream.
openvdb::v7_2::points::TypedAttributeArray::stride
Index stride() const override
Definition: AttributeArray.h:643
openvdb::v7_2::points::AttributeArray::isHidden
bool isHidden() const
Return true if this attribute is hidden (e.g., from UI or iterators).
Definition: AttributeArray.h:303
openvdb::v7_2::points::AttributeHandle::isUniform
bool isUniform() const
Definition: AttributeArray.h:2224
openvdb::v7_2::points::AttributeArray::AttributeArray
AttributeArray()
Definition: AttributeArray.h:132
openvdb::v7_2::compression::PagedInputStream
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:209
openvdb::v7_2::points::UnitVecCodec::Storage
Definition: AttributeArray.h:547
openvdb::v7_2::points::AttributeArray::operator==
bool operator==(const AttributeArray &other) const
openvdb::v7_2::points::TypedAttributeArray::expand
void expand(bool fill=true) override
Replace the single value storage with an array of length size().
Definition: AttributeArray.h:1542
openvdb::v7_2::points::AttributeArray::valueTypeIsFloatingPoint
virtual bool valueTypeIsFloatingPoint() const =0
Return true if the value type is floating point.
openvdb::v7_2::points::AttributeArray::ConstPtr
std::shared_ptr< const AttributeArray > ConstPtr
Definition: AttributeArray.h:126
openvdb::v7_2::points::TypedAttributeArray::data
const StorageType * data() const
Definition: AttributeArray.h:789
openvdb::v7_2::points::AttributeArray::getAccessor
virtual AccessorBasePtr getAccessor() const =0
Obtain an Accessor that stores getter and setter functors.
openvdb::v7_2::points::UnitVecCodec::Storage::Type
StorageType Type
Definition: AttributeArray.h:547
openvdb::v7_2::compression::PagedOutputStream
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:246
openvdb::v7_2::points::AttributeArray::setHidden
void setHidden(bool state)
Specify whether this attribute should be hidden (e.g., from UI or iterators).
openvdb::v7_2::points::TypedAttributeArray::collapse
void collapse() override
Replace the existing array with a uniform zero value.
Definition: AttributeArray.h:1580
openvdb::v7_2::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:103
openvdb::v7_2::points::fixedPointToFloatingPoint
FloatVectorT fixedPointToFloatingPoint(const math::Vec3< IntegerT > &v)
Definition: AttributeArray.h:79
openvdb::v7_2::points::OPENVDB_DEPRECATED
Index OPENVDB_DEPRECATED
Definition: AttributeArrayString.h:33
openvdb::v7_2::points::TypedAttributeArray::cast
static TypedAttributeArray & cast(AttributeArray &attributeArray)
Cast an AttributeArray to TypedAttributeArray<T>
Definition: AttributeArray.h:1284
openvdb::v7_2::points::AttributeArray::isRegistered
static bool isRegistered(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Return true if the given attribute type name is registered.
QuantizedUnitVec.h
openvdb::v7_2::points::TypedAttributeArray::attributeType
static const NamePair & attributeType()
Return the name of this attribute's type (includes codec)
Definition: AttributeArray.h:1235
tbb
Definition: Coord.h:16
openvdb::v7_2::points::AttributeHandle::size
Index size() const
Definition: AttributeArray.h:871
openvdb::v7_2::points::AttributeArray::dataSize
virtual Index dataSize() const =0
openvdb::v7_2::points::AccessorEval::set
static void set(SetterPtr, AttributeArray *array, const Index n, const ValueType &value)
Definition: AttributeArray.h:2090
openvdb::v7_2::points::AccessorEval< UnknownCodec, ValueType >::SetterPtr
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2101
openvdb::v7_2::points::TypedAttributeArray::writeBuffers
void writeBuffers(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1928
openvdb::v7_2::compression::PagedInputStream::createHandle
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
openvdb::v7_2::points::AttributeWriteHandle::collapse
void collapse(const ValueType &uniformValue)
Definition: AttributeArray.h:2285
openvdb::v7_2::points::TypedAttributeArray::validData
bool validData() const
Verify that data is not out-of-core or in a partially-read state.
Definition: AttributeArray.h:792
openvdb::v7_2::points::AttributeArray::operator!=
bool operator!=(const AttributeArray &other) const
Definition: AttributeArray.h:365
openvdb::v7_2::io::getDataCompression
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
openvdb::v7_2::points::AttributeArray::Ptr
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
openvdb::v7_2::points::FixedPointCodec::name
static const char * name()
Definition: AttributeArray.h:535
openvdb::v7_2::compression::bloscCompress
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::v7_2::points::AttributeArray::writeBuffers
virtual void writeBuffers(std::ostream &, bool outputTransient) const =0
openvdb::v7_2::points::TruncateCodec::Storage::Type
typename attribute_traits::TruncateTrait< T >::Type Type
Definition: AttributeArray.h:500
openvdb::v7_2::points::TypedAttributeArray::Ptr
std::shared_ptr< TypedAttributeArray > Ptr
Definition: AttributeArray.h:568
openvdb::v7_2::points::AttributeArray::Accessor::SetterPtr
void(*)(AttributeArray *array, const Index n, const T &value) SetterPtr
Definition: AttributeArray.h:440
openvdb::v7_2::points::AttributeArray
Base class for storing attribute data.
Definition: AttributeArray.h:93
openvdb::v7_2::points::TypedAttributeArray::data
StorageType * data()
Return the raw data buffer.
Definition: AttributeArray.h:788
openvdb::v7_2::points::AttributeWriteHandle::set
void set(Index n, const ValueType &value)
Definition: AttributeArray.h:2255
openvdb::v7_2::points::TypedAttributeArray::dataSize
Index dataSize() const override
Return the size of the data in this array.
Definition: AttributeArray.h:646
openvdb::v7_2::points::AttributeHandle::AttributeHandle
AttributeHandle(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2128
openvdb::v7_2::points::TypedAttributeArray::operator=
TypedAttributeArray & operator=(TypedAttributeArray &&)=delete
Move assignment operator disabled.
openvdb::v7_2::points::AccessorEval< UnknownCodec, ValueType >::get
static ValueType get(GetterPtr functor, const AttributeArray *array, const Index n)
Getter that calls the supplied functor.
Definition: AttributeArray.h:2104
openvdb::v7_2::compression::PagedOutputStream::write
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
openvdb::v7_2::points::TypedAttributeArray::write
void write(std::ostream &os, bool outputTransient) const override
Definition: AttributeArray.h:1860
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: openvdb/Exceptions.h:82
openvdb::v7_2::points::AttributeHandle::stride
Index stride() const
Definition: AttributeArray.h:870
openvdb::v7_2::Name
std::string Name
Definition: Name.h:17
Name.h
openvdb::v7_2::points::AttributeArray::readBuffers
virtual void readBuffers(std::istream &)=0
Read attribute buffers from a stream.
openvdb::v7_2::points::AttributeHandle::array
const AttributeArray & array() const
Definition: AttributeArray.h:2183
openvdb::v7_2::points::AttributeArray::FactoryMethod
Ptr(*)(Index, Index, bool, const Metadata *) FactoryMethod
Definition: AttributeArray.h:128
openvdb::v7_2::points::AttributeArray::Flag
Flag
Definition: AttributeArray.h:101
openvdb::v7_2::points::AccessorEval::get
static ValueType get(GetterPtr, const AttributeArray *array, const Index n)
Definition: AttributeArray.h:2084
openvdb::v7_2::points::TypedAttributeArray::TypedAttributeArray
TypedAttributeArray(TypedAttributeArray &&)=delete
Move constructor disabled.
openvdb::v7_2::points::AttributeWriteHandle::fill
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:2291
openvdb::v7_2::tools::composite::max
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:107
openvdb::v7_2::points::AttributeArray::clearRegistry
static void clearRegistry(const ScopedRegistryLock *lock=nullptr)
Clear the attribute type registry.
openvdb::v7_2::math::Vec3::y
T & y()
Definition: Vec3.h:84
openvdb::v7_2::points::AttributeHandle::mFiller
ValuePtr mFiller
Definition: AttributeArray.h:888
openvdb::v7_2::points::AttributeArray::mFlags
uint8_t mFlags
Definition: AttributeArray.h:415
openvdb::v7_2::points::AttributeArray::setTransient
void setTransient(bool state)
Specify whether this attribute should only exist in memory and not be serialized during stream output...
openvdb::v7_2::points::attribute_traits::TruncateTrait< int >::Type
short Type
Definition: AttributeArray.h:460
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:221
openvdb::v7_2::points::TypedAttributeArray::readMetadata
void readMetadata(std::istream &) override
Read attribute metadata from a stream.
Definition: AttributeArray.h:1718
openvdb::v7_2::points::TypedAttributeArray::TypedAttributeArray
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:1149
openvdb::v7_2::points::AttributeArray::mIsUniform
bool mIsUniform
Definition: AttributeArray.h:413
openvdb::v7_2::points::AttributeArray::mMutex
tbb::spin_mutex mMutex
Definition: AttributeArray.h:414
openvdb::v7_2::points::TypedAttributeArray::set
void set(Index n, const ValueType &value)
Set value at the given index n.
Definition: AttributeArray.h:1491
openvdb::v7_2::points::AttributeArray::copy
virtual AttributeArray::Ptr copy() const =0
Return a copy of this attribute.
openvdb::v7_2::points::AttributeArray::mPageHandle
compression::PageHandle::Ptr mPageHandle
Definition: AttributeArray.h:420
openvdb::v7_2::points::AttributeArray::setStreaming
void setStreaming(bool state)
Specify whether this attribute is to be streamed off disk, in which case, the attributes are collapse...
openvdb::v7_2::points::UnitRange::name
static const char * name()
Definition: AttributeArray.h:520
openvdb::v7_2::points::AttributeArray::read
virtual void read(std::istream &)=0
Read attribute metadata and buffers from a stream.
openvdb::v7_2::Index64
uint64_t Index64
Definition: openvdb/Types.h:31
openvdb::v7_2::points::AttributeArray::operator=
AttributeArray & operator=(AttributeArray &&)=delete
openvdb::v7_2::points::AttributeArray::valueTypeIsVector
virtual bool valueTypeIsVector() const =0
Return true if the value type is a vector.
openvdb::v7_2::points::AttributeArray::compress
virtual OPENVDB_DEPRECATED bool compress()=0
openvdb::v7_2::points::TypedAttributeArray::valueTypeIsQuaternion
bool valueTypeIsQuaternion() const override
Return true if the value type is a quaternion.
Definition: AttributeArray.h:1400
openvdb::v7_2::compression::PagedOutputStream::sizeOnly
bool sizeOnly() const
Definition: StreamCompression.h:256
openvdb::v7_2::points::AttributeArray::codecType
virtual Name codecType() const =0
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
openvdb::v7_2::points::AttributeHandle::create
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2121
openvdb::v7_2::math::Vec3::z
T & z()
Definition: Vec3.h:85
openvdb::v7_2::points::attribute_traits::UIntTypeTrait
Definition: AttributeArray.h:466
openvdb::v7_2::points::TruncateCodec::name
static const char * name()
Definition: AttributeArray.h:504
openvdb::v7_2::points::AttributeArray::isStreaming
bool isStreaming() const
Return true if this attribute is in streaming mode.
Definition: AttributeArray.h:318
openvdb::v7_2::points::AttributeArray::setConstantStride
void setConstantStride(bool state)
Specify whether this attribute has a constant stride or not.
openvdb::v7_2::points::TypedAttributeArray
Typed class for storing attribute data.
Definition: AttributeArray.h:566
openvdb::v7_2::points::AccessorEval
Accessor to call unsafe get and set methods based on templated Codec and Value.
Definition: AttributeArray.h:2078
openvdb::v7_2::points::AttributeArray::copyUncompressed
virtual OPENVDB_DEPRECATED AttributeArray::Ptr copyUncompressed() const =0
openvdb::v7_2::points::AttributeHandle
Definition: AttributeArray.h:849
openvdb::v7_2::points::TypedAttributeArray::size
Index size() const override
Return the number of elements in this array.
Definition: AttributeArray.h:639
openvdb::v7_2::points::UnitVecCodec::name
static const char * name()
Definition: AttributeArray.h:551
openvdb::v7_2::points::TypedAttributeArray::isDataLoaded
bool isDataLoaded() const override
Return true if all data has been loaded.
Definition: AttributeArray.h:1700
openvdb::v7_2::points::TypedAttributeArray::readPagedBuffers
void readPagedBuffers(compression::PagedInputStream &) override
Read attribute buffers from a paged stream.
Definition: AttributeArray.h:1808
openvdb::v7_2::compression::bloscDecompress
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::v7_2::points::TypedAttributeArray::decompress
OPENVDB_DEPRECATED bool decompress() override
Uncompress the attribute array.
Definition: AttributeArray.h:1651
openvdb::v7_2::points::TypedAttributeArray::writePagedBuffers
void writePagedBuffers(compression::PagedOutputStream &os, bool outputTransient) const override
Definition: AttributeArray.h:1970
openvdb::v7_2::points::AttributeArray::AttributeArray
AttributeArray(const AttributeArray &rhs)
IndexIterator.h
Index Iterators.
openvdb::v7_2::points::TypedAttributeArray::type
const NamePair & type() const override
Return the name of this attribute's type.
Definition: AttributeArray.h:629
openvdb::v7_2::points::AttributeHandle::AttributeHandle
AttributeHandle(const AttributeHandle &)=default
openvdb::v7_2::points::AttributeArray::compact
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
openvdb::v7_2::points::AttributeArray::ScopedRegistryLock::ScopedRegistryLock
ScopedRegistryLock()
openvdb::v7_2::VecTraits::ElementType
typename T::ValueType ElementType
Definition: openvdb/Types.h:186
openvdb::v7_2::math::operator==
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
openvdb::v7_2::points::AttributeHandle::mCollapser
ValuePtr mCollapser
Definition: AttributeArray.h:887
openvdb::v7_2::points::TypedAttributeArray::codecType
Name codecType() const override
Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
Definition: AttributeArray.h:655
openvdb::v7_2::points::TypedAttributeArray::valueTypeSize
Index valueTypeSize() const override
Return the size in bytes of the value type of a single element in this array.
Definition: AttributeArray.h:658
openvdb::v7_2::compression::PageHandle::Ptr
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:171
openvdb::v7_2::points::AttributeArray::Accessor::mCollapser
ValuePtr mCollapser
Definition: AttributeArray.h:448
openvdb::v7_2::points::AttributeArray::hasValueType
bool hasValueType() const
Return true if this attribute has a value type the same as the template parameter.
Definition: AttributeArray.h:229
openvdb::v7_2::points::floatingPointToFixedPoint
IntegerVectorT floatingPointToFixedPoint(const math::Vec3< FloatT > &v)
Definition: AttributeArray.h:69
openvdb::v7_2::points::AttributeArray::hasConstantStride
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:321
openvdb::v7_2::io::getMappedFilePtr
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
openvdb::v7_2::points::AttributeArray::size
virtual Index size() const =0
openvdb::v7_2::points::AttributeWriteHandle::expand
void expand(bool fill=true)
If this array is uniform, replace it with an array of length size().
Definition: AttributeArray.h:2267
openvdb::v7_2::points::TruncateCodec
Definition: AttributeArray.h:498
openvdb::v7_2::points::AttributeArray::write
virtual void write(std::ostream &, bool outputTransient) const =0
openvdb::v7_2::points::AttributeWriteHandle::compact
bool compact()
Compact the existing array to become uniform if all values are identical.
Definition: AttributeArray.h:2279
openvdb::v7_2::points::AttributeArray::Accessor::GetterPtr
T(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:439
openvdb::v7_2::points::AttributeArray::memUsage
virtual size_t memUsage() const =0
Return the number of bytes of memory used by this attribute.
openvdb::v7_2::points::AttributeWriteHandle::create
static Ptr create(AttributeArray &array, const bool expand=true)
Definition: AttributeArray.h:2241
openvdb::v7_2::points::attribute_traits::UIntTypeTrait< true, T >::Type
uint8_t Type
Definition: AttributeArray.h:467
openvdb::v7_2::TypeError
Definition: openvdb/Exceptions.h:64
openvdb::v7_2::points::AttributeHandle::mGetter
GetterPtr mGetter
Definition: AttributeArray.h:885
openvdb::v7_2::NamePair
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
openvdb::v7_2::compression::bloscCompressedSize
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
openvdb::v7_2::TypedMetadata
Templated metadata class to hold specific types.
Definition: Metadata.h:122
openvdb::v7_2::points::TypedAttributeArray::copyUncompressed
OPENVDB_DEPRECATED AttributeArray::Ptr copyUncompressed() const override
Definition: AttributeArray.h:1315
openvdb::v7_2::points::attribute_traits::TruncateTrait< float >::Type
half Type
Definition: AttributeArray.h:459
openvdb::v7_2::Metadata
Base class for storing metadata information in a grid.
Definition: Metadata.h:24
openvdb::v7_2::points::FixedPointCodec::Storage
Definition: AttributeArray.h:530
openvdb::v7_2::points::TypedAttributeArray::create
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:1272
openvdb::v7_2::points::AttributeArray::decompress
virtual OPENVDB_DEPRECATED bool decompress()=0
openvdb::v7_2::points::AttributeWriteHandle::array
AttributeArray & array()
Definition: AttributeArray.h:2317
openvdb::v7_2::points::AttributeWriteHandle< Index, openvdb::v7_2::points::StringCodec< false > >::ScopedPtr
std::unique_ptr< Handle > ScopedPtr
Definition: AttributeArray.h:924
openvdb::v7_2::points::AttributeArray::flags
uint8_t flags() const
Retrieve the attribute array flags.
Definition: AttributeArray.h:324
openvdb::v7_2::points::AttributeArray::isType
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:225
openvdb::v7_2::points::TypedAttributeArray::ValueType
ValueType_ ValueType
Definition: AttributeArray.h:571
openvdb::v7_2::points::AttributeArray::mOutOfCore
tbb::atomic< Index32 > mOutOfCore
Definition: AttributeArray.h:417
openvdb::v7_2::points::TypedAttributeArray::getAccessor
AccessorBasePtr getAccessor() const override
Obtain an Accessor that stores getter and setter functors.
Definition: AttributeArray.h:2018
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:147
openvdb::v7_2::points::AttributeArray::writeMetadata
virtual void writeMetadata(std::ostream &, bool outputTransient, bool paged) const =0
openvdb::v7_2::points::NullCodec::name
static const char * name()
Definition: AttributeArray.h:493
openvdb::v7_2::points::AttributeArray::registerType
static void registerType(const NamePair &type, FactoryMethod, const ScopedRegistryLock *lock=nullptr)
Register a attribute type along with a factory function.
openvdb::v7_2::points::AttributeWriteHandle
Write-able version of AttributeHandle.
Definition: AttributeArray.h:920
openvdb::v7_2::points::AttributeArray::AccessorBase
Accessor base class for AttributeArray storage where type is not available.
Definition: AttributeArray.h:432
openvdb::v7_2::points::TypedAttributeArray::valueTypeIsVector
bool valueTypeIsVector() const override
Return true if the value type is a vector.
Definition: AttributeArray.h:1392
openvdb::v7_2::points::UnitRange::decode
static ValueType decode(const ValueType &value)
Definition: AttributeArray.h:522
openvdb::v7_2::points::AttributeArray::isUniform
virtual bool isUniform() const =0
Return true if this array is stored as a single uniform value.
openvdb::v7_2::points::TypedAttributeArray::operator=
TypedAttributeArray & operator=(const TypedAttributeArray &)
Definition: AttributeArray.h:1208
openvdb::v7_2::points::AttributeWriteHandle::collapse
void collapse()
Replace the existing array with a uniform value (zero if none provided).
Definition: AttributeArray.h:2273
openvdb::v7_2::points::FixedPointCodec
Definition: AttributeArray.h:528
openvdb::v7_2::points::AttributeArray::loadData
virtual void loadData() const =0
Ensures all data is in-core.
openvdb::v7_2::points::TypedAttributeArray::fill
void fill(const ValueType &value)
Fill the existing array with the given value.
Definition: AttributeArray.h:1610
openvdb::v7_2::points::TypedAttributeArray::setUnsafe
void setUnsafe(Index n, const ValueType &value)
Set value at the given index n (assumes in-core)
Definition: AttributeArray.h:1476
openvdb::v7_2::points::AttributeArray::storageTypeSize
virtual Index storageTypeSize() const =0
openvdb::v7_2::points::AttributeArray::create
static Ptr create(const NamePair &type, Index length, Index stride=1, bool constantStride=true, const Metadata *metadata=nullptr, const ScopedRegistryLock *lock=nullptr)
openvdb::v7_2::io::COMPRESS_BLOSC
@ COMPRESS_BLOSC
Definition: Compression.h:56
openvdb::v7_2::points::AttributeArray::valueTypeIsQuaternion
virtual bool valueTypeIsQuaternion() const =0
Return true if the value type is a quaternion.
openvdb::v7_2::points::TypedAttributeArray::getUnsafe
ValueType getUnsafe(Index n) const
Return the value at index n (assumes in-core)
Definition: AttributeArray.h:1427
openvdb::v7_2::compression::PagedOutputStream::getOutputStream
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:259
openvdb::v7_2::points::UnknownCodec
Definition: AttributeArray.h:483
openvdb::v7_2::points::NullCodec::Storage::Type
T Type
Definition: AttributeArray.h:489
openvdb::v7_2::points::UnitVecCodec::StorageType
uint16_t StorageType
Definition: AttributeArray.h:544
openvdb::v7_2::points::AttributeWriteHandle::~AttributeWriteHandle
virtual ~AttributeWriteHandle()=default
openvdb::v7_2::points::AttributeArray::collapse
virtual void collapse()=0
Replace the existing array with a uniform zero value.
logging.h
openvdb::v7_2::points::AttributeWriteHandle::set
void set(Index n, Index m, const ValueType &value)
Definition: AttributeArray.h:2261
io.h
openvdb::v7_2::compression::PagedInputStream::sizeOnly
bool sizeOnly() const
Definition: StreamCompression.h:219
openvdb::v7_2::math::Vec3
Definition: Vec3.h:24
openvdb::v7_2::IndexError
Definition: openvdb/Exceptions.h:57
openvdb::v7_2::points::AttributeArray::valueTypeSize
virtual Index valueTypeSize() const =0
openvdb::v7_2::points::TypedAttributeArray::Codec
Codec_ Codec
Definition: AttributeArray.h:572
openvdb::v7_2::points::NullCodec
Definition: AttributeArray.h:487
openvdb::v7_2::points::FixedPointCodec::Storage::Type
typename attribute_traits::UIntTypeTrait< OneByte, T >::Type Type
Definition: AttributeArray.h:530
openvdb::v7_2::points::NullCodec::Storage
Definition: AttributeArray.h:489
openvdb::v7_2::points::TypedAttributeArray::registerType
static void registerType()
Register this attribute type along with a factory function.
Definition: AttributeArray.h:1256
openvdb::v7_2::points::AttributeArray::Accessor::mSetter
SetterPtr mSetter
Definition: AttributeArray.h:447
openvdb::v7_2::points::AttributeArray::type
virtual const NamePair & type() const =0
Return the name of this attribute's type.
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:95
openvdb::v7_2::points::AttributeArray::isTransient
bool isTransient() const
Return true if this attribute is not serialized during stream output.
Definition: AttributeArray.h:310
openvdb::v7_2::compression::PagedInputStream::getInputStream
std::istream & getInputStream()
Definition: StreamCompression.h:222
openvdb::v7_2::points::AccessorEval::SetterPtr
void(*)(AttributeArray *array, const Index n, const ValueType &value) SetterPtr
Definition: AttributeArray.h:2080
openvdb::v7_2::points::TypedAttributeArray::unregisterType
static void unregisterType()
Remove this attribute type from the registry.
Definition: AttributeArray.h:1264
openvdb::v7_2::points::TypedAttributeArray::~TypedAttributeArray
~TypedAttributeArray() override
Definition: AttributeArray.h:605
openvdb::v7_2::points::AttributeHandle< Index, openvdb::v7_2::points::StringCodec< false > >::SetterPtr
void(*)(AttributeArray *array, const Index n, const Index &value) SetterPtr
Definition: AttributeArray.h:857
openvdb::v7_2::points::AttributeArray::expand
virtual void expand(bool fill=true)=0
If this array is uniform, replace it with an array of length size().
openvdb::v7_2::points::AttributeHandle::hasConstantStride
bool hasConstantStride() const
Definition: AttributeArray.h:2230
openvdb::v7_2::points::AttributeArray::Accessor::mGetter
GetterPtr mGetter
Definition: AttributeArray.h:446
openvdb::v7_2::points::AttributeArray::ScopedRegistryLock
Definition: AttributeArray.h:119
openvdb::v7_2::points::AttributeArray::AttributeArray
AttributeArray(const AttributeArray &rhs, const tbb::spin_mutex::scoped_lock &)
openvdb::v7_2::points::PositionRange
Definition: AttributeArray.h:510
openvdb::v7_2::points::AttributeArray::mCompressedBytes
size_t mCompressedBytes
Definition: AttributeArray.h:421
openvdb::v7_2::points::AttributeHandle::~AttributeHandle
virtual ~AttributeHandle()
Definition: AttributeArray.h:2156
openvdb::v7_2::points::AttributeArray::Accessor::mFiller
ValuePtr mFiller
Definition: AttributeArray.h:449
openvdb::v7_2::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:434
openvdb::v7_2::points::TypedAttributeArray::isOutOfCore
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: AttributeArray.h:1659
openvdb::v7_2::points::AttributeHandle< Index, openvdb::v7_2::points::StringCodec< false > >::UniquePtr
std::unique_ptr< Handle > UniquePtr
Definition: AttributeArray.h:853
openvdb::v7_2::points::AttributeArray::Accessor::Accessor
Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler)
Definition: AttributeArray.h:443
openvdb::v7_2::points::AttributeArray::valueTypeIsMatrix
virtual bool valueTypeIsMatrix() const =0
Return true if the value type is a matrix.
openvdb::v7_2::points::AccessorEval< UnknownCodec, ValueType >::set
static void set(SetterPtr functor, AttributeArray *array, const Index n, const ValueType &value)
Setter that calls the supplied functor.
Definition: AttributeArray.h:2109
openvdb::v7_2::points::AttributeArray::SerializationFlag
SerializationFlag
Definition: AttributeArray.h:109
openvdb::v7_2::points::TypedAttributeArray::isUniform
bool isUniform() const override
Return true if this array is stored as a single uniform value.
Definition: AttributeArray.h:716
openvdb::v7_2::ValueError
Definition: openvdb/Exceptions.h:65
openvdb
Definition: openvdb/Exceptions.h:13
openvdb::v7_2::points::TypedAttributeArray::copy
AttributeArray::Ptr copy() const override
Definition: AttributeArray.h:1304
openvdb::v7_2::points::TypedAttributeArray::writeMetadata
void writeMetadata(std::ostream &os, bool outputTransient, bool paged) const override
Definition: AttributeArray.h:1869
openvdb::v7_2::points::AttributeHandle::operator=
AttributeHandle & operator=(const AttributeHandle &)=default
openvdb::v7_2::points::attribute_traits::TruncateTrait
Definition: AttributeArray.h:458
openvdb::v7_2::points::UnitRange::encode
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:521
openvdb::v7_2::points::TypedAttributeArray::StorageType
typename Codec::template Storage< ValueType >::Type StorageType
Definition: AttributeArray.h:573
openvdb::v7_2::points::AttributeArray::writePagedBuffers
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
openvdb::v7_2::points::AttributeHandle< Index, openvdb::v7_2::points::StringCodec< false > >::ValuePtr
void(*)(AttributeArray *array, const Index &value) ValuePtr
Definition: AttributeArray.h:858
openvdb::v7_2::points::AttributeArray::Accessor::ValuePtr
void(*)(AttributeArray *array, const T &value) ValuePtr
Definition: AttributeArray.h:441
openvdb::v7_2::io::MappedFile::Ptr
SharedPtr< MappedFile > Ptr
Definition: io.h:136
openvdb::v7_2::VecTraits
Definition: openvdb/Types.h:183
openvdb::v7_2::points::TypedAttributeArray::readBuffers
void readBuffers(std::istream &) override
Read attribute buffers from a stream.
Definition: AttributeArray.h:1769
openvdb::v7_2::Int16
int16_t Int16
Definition: openvdb/Types.h:33
openvdb::v7_2::compression::PagedInputStream::read
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::v7_2::points::AccessorEval::GetterPtr
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2079
openvdb::v7_2::points::AttributeArray::isDataLoaded
virtual bool isDataLoaded() const =0
Return true if all data has been loaded.
openvdb::v7_2::points::AccessorEval< UnknownCodec, ValueType >::GetterPtr
ValueType(*)(const AttributeArray *array, const Index n) GetterPtr
Definition: AttributeArray.h:2100
openvdb::v7_2::points::AttributeArray::AccessorBasePtr
std::shared_ptr< AccessorBase > AccessorBasePtr
Definition: AttributeArray.h:98
openvdb::v7_2::Index
Index32 Index
Definition: openvdb/Types.h:32
openvdb::v7_2::points::PositionRange::encode
static ValueType encode(const ValueType &value)
Definition: AttributeArray.h:512
openvdb::v7_2::points::TypedAttributeArray::loadData
void loadData() const override
Ensures all data is in-core.
Definition: AttributeArray.h:1691
openvdb::v7_2::points::TruncateCodec::Storage
Definition: AttributeArray.h:500
openvdb::v7_2::points::AttributeArray::mUsePagedRead
uint8_t mUsePagedRead
Definition: AttributeArray.h:416
openvdb::v7_2::points::TypedAttributeArray::get
ValueType get(Index n) const
Return the value at index n.
Definition: AttributeArray.h:1439
openvdb::v7_2::points::AttributeArray::unregisterType
static void unregisterType(const NamePair &type, const ScopedRegistryLock *lock=nullptr)
Remove a attribute type from the registry.
openvdb::v7_2::points::AttributeArray::valueTypeIsClass
virtual bool valueTypeIsClass() const =0
Return true if the value type is a class (ie vector, matrix or quaternion return true)
openvdb::v7_2::points::AttributeHandle::mSetter
SetterPtr mSetter
Definition: AttributeArray.h:886
openvdb::v7_2::points::AttributeArray::AccessorBase::~AccessorBase
virtual ~AccessorBase()=default
openvdb::v7_2::points::AttributeArray::set
virtual OPENVDB_DEPRECATED void set(const Index n, const AttributeArray &sourceArray, const Index sourceIndex)=0
Set value at given index n from sourceIndex of another sourceArray.
OPENVDB_LOG_WARN
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253