GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/points/AttributeArray.h
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 490 510 96.1%
Functions: 1568 2792 56.2%
Branches: 1214 2264 53.6%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 /// @file points/AttributeArray.h
5 ///
6 /// @authors Dan Bailey, Mihai Alden, Nick Avramoussis, James Bird, Khang Ngo
7 ///
8 /// @brief Attribute Array storage templated on type and compression codec.
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>
14 #include <openvdb/math/QuantizedUnitVec.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 <atomic>
25
26 #include <memory>
27 #include <mutex>
28 #include <string>
29 #include <type_traits>
30
31
32 class TestAttributeArray;
33
34 namespace openvdb {
35 OPENVDB_USE_VERSION_NAMESPACE
36 namespace OPENVDB_VERSION_NAME {
37
38
39 using NamePair = std::pair<Name, Name>;
40
41 namespace points {
42
43
44 ////////////////////////////////////////
45
46 // Utility methods
47
48 template <typename IntegerT, typename FloatT>
49 inline IntegerT
50 floatingPointToFixedPoint(const FloatT s)
51 {
52 static_assert(std::is_unsigned<IntegerT>::value, "IntegerT must be unsigned");
53
10/12
✓ Branch 0 taken 663 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 669 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 671 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 653 times.
✓ Branch 7 taken 8 times.
✓ Branch 8 taken 658 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 660 times.
✗ Branch 11 not taken.
3974 if (FloatT(0.0) > s) return std::numeric_limits<IntegerT>::min();
54
38/48
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 7 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 5 times.
✓ Branch 11 taken 6 times.
✓ Branch 12 taken 658 times.
✓ Branch 13 taken 6 times.
✓ Branch 14 taken 660 times.
✓ Branch 15 taken 6 times.
✓ Branch 16 taken 661 times.
✓ Branch 17 taken 3 times.
✓ Branch 18 taken 657 times.
✓ Branch 19 taken 3 times.
✓ Branch 20 taken 650 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 658 times.
✓ Branch 23 taken 2 times.
✓ Branch 24 taken 4 times.
✓ Branch 25 taken 29999997 times.
✓ Branch 26 taken 4 times.
✓ Branch 27 taken 29999997 times.
✓ Branch 28 taken 3 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 3 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 3 times.
✓ Branch 33 taken 2 times.
✓ Branch 34 taken 323 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 332 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 3 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 1 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 1 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
60004700 else if (FloatT(1.0) <= s) return std::numeric_limits<IntegerT>::max();
55 4665 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
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
124 return FloatT(s) / FloatT((std::numeric_limits<IntegerT>::max()));
65 }
66
67 template <typename IntegerVectorT, typename FloatT>
68 inline IntegerVectorT
69
2/2
✓ Branch 0 taken 1315 times.
✓ Branch 1 taken 16 times.
2655 floatingPointToFixedPoint(const math::Vec3<FloatT>& v)
70 {
71 return IntegerVectorT(
72 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.x()),
73 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.y()),
74 2655 floatingPointToFixedPoint<typename IntegerVectorT::ValueType>(v.z()));
75 }
76
77 template <typename FloatVectorT, typename IntegerT>
78 inline FloatVectorT
79 fixedPointToFloatingPoint(const math::Vec3<IntegerT>& v)
80 {
81 return FloatVectorT(
82 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.x()),
83 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.y()),
84 24 fixedPointToFloatingPoint<typename FloatVectorT::ValueType>(v.z()));
85 }
86
87
88 ////////////////////////////////////////
89
90
91 /// Base class for storing attribute data
92 class OPENVDB_API AttributeArray
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, /// by default not written to disk
103 HIDDEN = 0x2, /// hidden from UIs or iterators
104 CONSTANTSTRIDE = 0x8, /// stride size does not vary in the array
105 STREAMING = 0x10, /// streaming mode collapses attributes when first accessed
106 PARTIALREAD = 0x20 /// data has been partially read (compressed bytes is used)
107 };
108
109 enum SerializationFlag {
110 WRITESTRIDED = 0x1, /// data is marked as strided when written
111 WRITEUNIFORM = 0x2, /// data is marked as uniform when written
112 WRITEMEMCOMPRESS = 0x4, /// data is marked as compressed in-memory when written
113 /// (deprecated flag as of ABI=6)
114 WRITEPAGED = 0x8 /// data is written out in pages
115 };
116
117 // Scoped Lock wrapper class that locks the AttributeArray registry mutex
118
4/20
✓ Branch 0 taken 711 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7103 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
11942 class OPENVDB_API ScopedRegistryLock
119 {
120 tbb::spin_mutex::scoped_lock lock;
121 public:
122 ScopedRegistryLock();
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 123437 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 AttributeArray(const AttributeArray& rhs);
140 AttributeArray& operator=(const AttributeArray& rhs);
141 AttributeArray(AttributeArray&&) = delete;
142 AttributeArray& operator=(AttributeArray&&) = delete;
143
144 /// Return a copy of this attribute.
145 virtual AttributeArray::Ptr copy() const = 0;
146
147 /// Return a copy of this attribute.
148 #ifndef _MSC_VER
149 OPENVDB_DEPRECATED_MESSAGE("In-memory compression no longer supported, use AttributeArray::copy() instead")
150 #endif
151 virtual AttributeArray::Ptr copyUncompressed() const = 0;
152
153 /// Return the number of elements in this array.
154 /// @note This does not count each data element in a strided array
155 virtual Index size() const = 0;
156
157 /// Return the stride of this array.
158 /// @note a return value of zero means a non-constant stride
159 virtual Index stride() const = 0;
160
161 /// Return the total number of data elements in this array.
162 /// @note This counts each data element in a strided array
163 virtual Index dataSize() const = 0;
164
165 /// Return the name of the value type of a single element in this array (e.g., "float" or "vec3d").
166 virtual Name valueType() const = 0;
167
168 /// Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
169 virtual Name codecType() const = 0;
170
171 /// Return the size in bytes of the value type of a single element in this array.
172 /// (e.g. "float" -> 4 bytes, "vec3d" -> 24 bytes").
173 virtual Index valueTypeSize() const = 0;
174
175 /// Return the size in bytes of the storage type of a single element of this array.
176 /// @note If the Codec is a NullCodec, valueSize() == storageSize()
177 virtual Index storageTypeSize() const = 0;
178
179 /// Return @c true if the value type is floating point
180 virtual bool valueTypeIsFloatingPoint() const = 0;
181
182 /// Return @c true if the value type is a class (ie vector, matrix or quaternion return true)
183 virtual bool valueTypeIsClass() const = 0;
184
185 /// Return @c true if the value type is a vector
186 virtual bool valueTypeIsVector() const = 0;
187
188 /// Return @c true if the value type is a quaternion
189 virtual bool valueTypeIsQuaternion() const = 0;
190
191 /// Return @c true if the value type is a matrix
192 virtual bool valueTypeIsMatrix() const = 0;
193
194 /// Return the number of bytes of memory used by this attribute.
195 virtual size_t memUsage() const = 0;
196
197 #if OPENVDB_ABI_VERSION_NUMBER >= 10
198 /// Return the number of bytes of memory used by this attribute array once it
199 /// has been deserialized (this may be different to memUsage() if delay-loading
200 /// is in use). Note that this method does NOT consider the fact that a
201 /// uniform attribute could be expanded and only deals with delay-loading.
202 virtual size_t memUsageIfLoaded() const = 0;
203 #endif
204
205 /// Create a new attribute array of the given (registered) type, length and stride.
206 /// @details If @a lock is non-null, the AttributeArray registry mutex
207 /// has already been locked
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 /// Return @c true if the given attribute type name is registered.
214 static bool isRegistered(const NamePair& type, const ScopedRegistryLock* lock = nullptr);
215 /// Clear the attribute type registry.
216 static void clearRegistry(const ScopedRegistryLock* lock = nullptr);
217
218 /// Return the name of this attribute's type.
219 virtual const NamePair& type() const = 0;
220 /// Return @c true if this attribute is of the same type as the template parameter.
221 template<typename AttributeArrayType>
222 263063 bool isType() const { return this->type() == AttributeArrayType::attributeType(); }
223
224 /// Return @c true if this attribute has a value type the same as the template parameter
225 template<typename ValueType>
226 259346 bool hasValueType() const { return this->type().first == typeNameAsString<ValueType>(); }
227
228 /// @brief Set value at given index @a n from @a sourceIndex of another @a sourceArray.
229 // Windows does not allow base classes to be easily deprecated.
230 #ifndef _MSC_VER
231 OPENVDB_DEPRECATED_MESSAGE("Use copyValues() with source-target index pairs")
232 #endif
233 virtual void set(const Index n, const AttributeArray& sourceArray, const Index sourceIndex) = 0;
234
235 /// @brief Copy values into this array from a source array to a target array
236 /// as referenced by an iterator.
237 /// @details Iterators must adhere to the ForwardIterator interface described
238 /// in the example below:
239 /// @code
240 /// struct MyIterator
241 /// {
242 /// // returns true if the iterator is referencing valid copying indices
243 /// operator bool() const;
244 /// // increments the iterator
245 /// MyIterator& operator++();
246 /// // returns the source index that the iterator is referencing for copying
247 /// Index sourceIndex() const;
248 /// // returns the target index that the iterator is referencing for copying
249 /// Index targetIndex() const;
250 /// };
251 /// @endcode
252 /// @note It is assumed that the strided storage sizes match, the arrays are both in-core,
253 /// and both value types are floating-point or both integer.
254 /// @note It is possible to use this method to write to a uniform target array
255 /// if the iterator does not have non-zero target indices.
256 /// @note This method is not thread-safe, it must be guaranteed that this array is not
257 /// concurrently modified by another thread and that the source array is also not modified.
258 template<typename IterT>
259 void copyValuesUnsafe(const AttributeArray& sourceArray, const IterT& iter);
260 /// @brief Like copyValuesUnsafe(), but if @a compact is true, attempt to collapse this array.
261 /// @note This method is not thread-safe, it must be guaranteed that this array is not
262 /// concurrently modified by another thread and that the source array is also not modified.
263 template<typename IterT>
264 void copyValues(const AttributeArray& sourceArray, const IterT& iter, bool compact = true);
265
266 /// Return @c true if this array is stored as a single uniform value.
267 virtual bool isUniform() const = 0;
268 /// @brief If this array is uniform, replace it with an array of length size().
269 /// @param fill if true, assign the uniform value to each element of the array.
270 virtual void expand(bool fill = true) = 0;
271 /// Replace the existing array with a uniform zero value.
272 virtual void collapse() = 0;
273 /// Compact the existing array to become uniform if all values are identical
274 virtual bool compact() = 0;
275
276 // Windows does not allow base classes to be deprecated
277 #ifndef _MSC_VER
278 OPENVDB_DEPRECATED_MESSAGE("Previously this compressed the attribute array, now it does nothing")
279 #endif
280 virtual bool compress() = 0;
281 // Windows does not allow base classes to be deprecated
282 #ifndef _MSC_VER
283 OPENVDB_DEPRECATED_MESSAGE("Previously this uncompressed the attribute array, now it does nothing")
284 #endif
285 virtual bool decompress() = 0;
286
287 /// @brief Specify whether this attribute should be hidden (e.g., from UI or iterators).
288 /// @details This is useful if the attribute is used for blind data or as scratch space
289 /// for a calculation.
290 /// @note Attributes are not hidden by default.
291 void setHidden(bool state);
292 /// Return @c true if this attribute is hidden (e.g., from UI or iterators).
293
12/18
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5050 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
5070 bool isHidden() const { return bool(mFlags & HIDDEN); }
294
295 /// @brief Specify whether this attribute should only exist in memory
296 /// and not be serialized during stream output.
297 /// @note Attributes are not transient by default.
298 void setTransient(bool state);
299 /// Return @c true if this attribute is not serialized during stream output.
300
13/18
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5043 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
5094 bool isTransient() const { return bool(mFlags & TRANSIENT); }
301
302 /// @brief Specify whether this attribute is to be streamed off disk, in which
303 /// case, the attributes are collapsed after being first loaded leaving them
304 /// in a destroyed state.
305 /// @note This operation is not thread-safe.
306 void setStreaming(bool state);
307 /// Return @c true if this attribute is in streaming mode.
308 115731 bool isStreaming() const { return bool(mFlags & STREAMING); }
309
310 /// Return @c true if this attribute has a constant stride
311
21/44
✓ Branch 0 taken 61260 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1037 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 75423 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 270 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1161 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 24681 times.
✓ Branch 11 taken 3 times.
✓ Branch 12 taken 23664 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 338 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 368 times.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 244 times.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 248 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 248 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 712 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 184 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 424 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 788 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
15988830 bool hasConstantStride() const { return bool(mFlags & CONSTANTSTRIDE); }
312
313 /// @brief Retrieve the attribute array flags
314
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
13213907 uint8_t flags() const { return mFlags; }
315
316 /// Read attribute metadata and buffers from a stream.
317 virtual void read(std::istream&) = 0;
318 /// Write attribute metadata and buffers to a stream.
319 /// @param outputTransient if true, write out transient attributes
320 virtual void write(std::ostream&, bool outputTransient) const = 0;
321 /// Write attribute metadata and buffers to a stream, don't write transient attributes.
322 virtual void write(std::ostream&) const = 0;
323
324 /// Read attribute metadata from a stream.
325 virtual void readMetadata(std::istream&) = 0;
326 /// Write attribute metadata to a stream.
327 /// @param outputTransient if true, write out transient attributes
328 /// @param paged if true, data is written out in pages
329 virtual void writeMetadata(std::ostream&, bool outputTransient, bool paged) const = 0;
330
331 /// Read attribute buffers from a stream.
332 virtual void readBuffers(std::istream&) = 0;
333 /// Write attribute buffers to a stream.
334 /// @param outputTransient if true, write out transient attributes
335 virtual void writeBuffers(std::ostream&, bool outputTransient) const = 0;
336
337 /// Read attribute buffers from a paged stream.
338 virtual void readPagedBuffers(compression::PagedInputStream&) = 0;
339 /// Write attribute buffers to a paged stream.
340 /// @param outputTransient if true, write out transient attributes
341 virtual void writePagedBuffers(compression::PagedOutputStream&, bool outputTransient) const = 0;
342
343 /// Ensures all data is in-core
344 virtual void loadData() const = 0;
345
346 /// Return @c true if all data has been loaded
347 virtual bool isDataLoaded() const = 0;
348
349 /// Check the compressed bytes and flags. If they are equal, perform a deeper
350 /// comparison check necessary on the inherited types (TypedAttributeArray)
351 /// Requires non operator implementation due to inheritance
352 bool operator==(const AttributeArray& other) const;
353
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
23 bool operator!=(const AttributeArray& other) const { return !this->operator==(other); }
354
355 #if OPENVDB_ABI_VERSION_NUMBER >= 9
356 /// Indirect virtual function to retrieve the data buffer cast to a char byte array
357 9766 const char* constDataAsByteArray() const { return this->dataAsByteArray(); }
358 #endif
359
360 private:
361 friend class ::TestAttributeArray;
362
363 /// Virtual function used by the comparison operator to perform
364 /// comparisons on inherited types
365 virtual bool isEqual(const AttributeArray& other) const = 0;
366
367 /// Virtual function to retrieve the data buffer cast to a char byte array
368 virtual char* dataAsByteArray() = 0;
369 virtual const char* dataAsByteArray() const = 0;
370
371 /// Private implementation for copyValues/copyValuesUnsafe
372 template <typename IterT>
373 void doCopyValues(const AttributeArray& sourceArray, const IterT& iter,
374 bool rangeChecking = true);
375
376 protected:
377 AttributeArray(const AttributeArray& rhs, const tbb::spin_mutex::scoped_lock&);
378
379 /// @brief Specify whether this attribute has a constant stride or not.
380 void setConstantStride(bool state);
381
382 /// Obtain an Accessor that stores getter and setter functors.
383 virtual AccessorBasePtr getAccessor() const = 0;
384
385 /// Register a attribute type along with a factory function.
386 static void registerType(const NamePair& type, FactoryMethod,
387 const ScopedRegistryLock* lock = nullptr);
388 /// Remove a attribute type from the registry.
389 static void unregisterType(const NamePair& type,
390 const ScopedRegistryLock* lock = nullptr);
391
392 bool mIsUniform = true;
393 mutable tbb::spin_mutex mMutex;
394 uint8_t mFlags = 0;
395 uint8_t mUsePagedRead = 0;
396 std::atomic<Index32> mOutOfCore; // interpreted as bool
397 /// used for out-of-core, paged reading
398 union {
399 compression::PageHandle::Ptr mPageHandle;
400 size_t mCompressedBytes;
401 };
402 }; // class AttributeArray
403
404
405 ////////////////////////////////////////
406
407
408 /// Accessor base class for AttributeArray storage where type is not available
409 struct AttributeArray::AccessorBase { virtual ~AccessorBase() = default; };
410
411 /// Templated Accessor stores typed function pointers used in binding
412 /// AttributeHandles
413 template <typename T>
414 struct AttributeArray::Accessor : public AttributeArray::AccessorBase
415 {
416 using GetterPtr = T (*)(const AttributeArray* array, const Index n);
417 using SetterPtr = void (*)(AttributeArray* array, const Index n, const T& value);
418 using ValuePtr = void (*)(AttributeArray* array, const T& value);
419
420 185981 Accessor(GetterPtr getter, SetterPtr setter, ValuePtr collapser, ValuePtr filler) :
421 185981 mGetter(getter), mSetter(setter), mCollapser(collapser), mFiller(filler) { }
422
423 GetterPtr mGetter;
424 SetterPtr mSetter;
425 ValuePtr mCollapser;
426 ValuePtr mFiller;
427 }; // struct AttributeArray::Accessor
428
429
430 ////////////////////////////////////////
431
432
433 namespace attribute_traits
434 {
435 template <typename T> struct TruncateTrait { };
436 template <> struct TruncateTrait<float> { using Type = math::half; };
437 template <> struct TruncateTrait<int> { using Type = short; };
438
439 template <typename T> struct TruncateTrait<math::Vec3<T>> {
440 using Type = math::Vec3<typename TruncateTrait<T>::Type>;
441 };
442
443 template <bool OneByte, typename T> struct UIntTypeTrait { };
444 template<typename T> struct UIntTypeTrait</*OneByte=*/true, T> { using Type = uint8_t; };
445 template<typename T> struct UIntTypeTrait</*OneByte=*/false, T> { using Type = uint16_t; };
446 template<typename T> struct UIntTypeTrait</*OneByte=*/true, math::Vec3<T>> {
447 using Type = math::Vec3<uint8_t>;
448 };
449 template<typename T> struct UIntTypeTrait</*OneByte=*/false, math::Vec3<T>> {
450 using Type = math::Vec3<uint16_t>;
451 };
452 }
453
454
455 ////////////////////////////////////////
456
457
458 // Attribute codec schemes
459
460 struct UnknownCodec { };
461
462
463 struct NullCodec
464 {
465 template <typename T>
466 struct Storage { using Type = T; };
467
468 template<typename ValueType> static void decode(const ValueType&, ValueType&);
469 template<typename ValueType> static void encode(const ValueType&, ValueType&);
470 static const char* name() { return "null"; }
471 };
472
473
474 struct TruncateCodec
475 {
476 template <typename T>
477 struct Storage { using Type = typename attribute_traits::TruncateTrait<T>::Type; };
478
479 template<typename StorageType, typename ValueType> static void decode(const StorageType&, ValueType&);
480 template<typename StorageType, typename ValueType> static void encode(const ValueType&, StorageType&);
481 static const char* name() { return "trnc"; }
482 };
483
484
485 // Fixed-point codec range for voxel-space positions [-0.5,0.5]
486 struct PositionRange
487 {
488 static const char* name() { return "fxpt"; }
489
8/12
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
42 template <typename ValueType> static ValueType encode(const ValueType& value) { return value + ValueType(0.5); }
490
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
60000039 template <typename ValueType> static ValueType decode(const ValueType& value) { return value - ValueType(0.5); }
491 };
492
493
494 // Fixed-point codec range for unsigned values in the unit range [0.0,1.0]
495 struct UnitRange
496 {
497 static const char* name() { return "ufxpt"; }
498
6/8
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 324 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 333 times.
✗ Branch 7 not taken.
689 template <typename ValueType> static ValueType encode(const ValueType& value) { return value; }
499 24 template <typename ValueType> static ValueType decode(const ValueType& value) { return value; }
500 };
501
502
503 template <bool OneByte, typename Range=PositionRange>
504 struct FixedPointCodec
505 {
506 template <typename T>
507 struct Storage { using Type = typename attribute_traits::UIntTypeTrait<OneByte, T>::Type; };
508
509 template<typename StorageType, typename ValueType> static void decode(const StorageType&, ValueType&);
510 template<typename StorageType, typename ValueType> static void encode(const ValueType&, StorageType&);
511
512 57 static const char* name() {
513
5/8
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 18 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
73 static const std::string Name = std::string(Range::name()) + (OneByte ? "8" : "16");
514 57 return Name.c_str();
515 }
516 };
517
518
519 struct UnitVecCodec
520 {
521 using StorageType = uint16_t;
522
523 template <typename T>
524 struct Storage { using Type = StorageType; };
525
526 template<typename T> static void decode(const StorageType&, math::Vec3<T>&);
527 template<typename T> static void encode(const math::Vec3<T>&, StorageType&);
528 static const char* name() { return "uvec"; }
529 };
530
531
532 ////////////////////////////////////////
533
534
535 /// Typed class for storing attribute data
536
537 template<typename ValueType_, typename Codec_ = NullCodec>
538 class TypedAttributeArray final: public AttributeArray
539 {
540 public:
541 using Ptr = std::shared_ptr<TypedAttributeArray>;
542 using ConstPtr = std::shared_ptr<const TypedAttributeArray>;
543
544 using ValueType = ValueType_;
545 using Codec = Codec_;
546 using StorageType = typename Codec::template Storage<ValueType>::Type;
547
548 //////////
549
550 /// Default constructor, always constructs a uniform attribute.
551 explicit TypedAttributeArray(Index n = 1, Index strideOrTotalSize = 1, bool constantStride = true,
552
12/24
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
11 const ValueType& uniformValue = zeroVal<ValueType>());
553
554 /// Deep copy constructor.
555 /// @note This method is thread-safe (as of ABI=7) for concurrently reading from the
556 /// source attribute array while being deep-copied. Specifically, this means that the
557 /// attribute array being deep-copied can be out-of-core and safely loaded in one thread
558 /// while being copied using this copy-constructor in another thread.
559 /// It is not thread-safe for write.
560 TypedAttributeArray(const TypedAttributeArray&);
561 /// Deep copy constructor.
562 OPENVDB_DEPRECATED_MESSAGE("Use copy-constructor without unused bool parameter")
563 TypedAttributeArray(const TypedAttributeArray&, bool /*unused*/);
564
565 /// Deep copy assignment operator.
566 /// @note this operator is thread-safe.
567 TypedAttributeArray& operator=(const TypedAttributeArray&);
568 /// Move constructor disabled.
569 TypedAttributeArray(TypedAttributeArray&&) = delete;
570 /// Move assignment operator disabled.
571 TypedAttributeArray& operator=(TypedAttributeArray&&) = delete;
572
573 405233 ~TypedAttributeArray() override { this->deallocate(); }
574
575 /// Return a copy of this attribute.
576 /// @note This method is thread-safe.
577 AttributeArray::Ptr copy() const override;
578
579 /// Return a copy of this attribute.
580 /// @note This method is thread-safe.
581 OPENVDB_DEPRECATED_MESSAGE("In-memory compression no longer supported, use AttributeArray::copy() instead")
582 AttributeArray::Ptr copyUncompressed() const override;
583
584 /// Return a new attribute array of the given length @a n and @a stride with uniform value zero.
585 static Ptr create(Index n, Index strideOrTotalSize = 1, bool constantStride = true,
586 const Metadata* metadata = nullptr);
587
588 /// Cast an AttributeArray to TypedAttributeArray<T>
589 static TypedAttributeArray& cast(AttributeArray& attributeArray);
590
591 /// Cast an AttributeArray to TypedAttributeArray<T>
592 static const TypedAttributeArray& cast(const AttributeArray& attributeArray);
593
594 /// Return the name of this attribute's type (includes codec)
595 static const NamePair& attributeType();
596 /// Return the name of this attribute's type.
597 1261620 const NamePair& type() const override { return attributeType(); }
598
599 /// Return @c true if this attribute type is registered.
600 static bool isRegistered();
601 /// Register this attribute type along with a factory function.
602 static void registerType();
603 /// Remove this attribute type from the registry.
604 static void unregisterType();
605
606 /// Return the number of elements in this array.
607
21/30
✓ Branch 0 taken 10003115 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 10000000 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 10000002 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 10000000 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 10000000 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 10000002 times.
✓ Branch 11 taken 1 times.
✓ Branch 13 taken 3 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
60451465 Index size() const override { return mSize; }
608
609 /// Return the stride of this array.
610 /// @note A return value of zero means a variable stride
611
6/10
✓ Branch 0 taken 256108 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
518026 Index stride() const override { return hasConstantStride() ? mStrideOrTotalSize : 0; }
612
613 /// Return the size of the data in this array.
614 37314190 Index dataSize() const override {
615
98/324
✓ Branch 0 taken 18657087 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 4502 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4310 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 455 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3121 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3349 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1024485 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 1026876 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 11462 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 528 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 528 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 544 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 963 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 2 times.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✓ Branch 46 taken 972 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✓ Branch 52 taken 972 times.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✓ Branch 58 taken 1536 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 10 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 1774 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 1188 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 2349 times.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✓ Branch 70 taken 1234 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✓ Branch 78 taken 1 times.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✓ Branch 86 taken 316 times.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✓ Branch 90 taken 1848 times.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✓ Branch 94 taken 44434 times.
✗ Branch 95 not taken.
✓ Branch 96 taken 49432 times.
✗ Branch 97 not taken.
✓ Branch 98 taken 585 times.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✓ Branch 102 taken 2995 times.
✗ Branch 103 not taken.
✓ Branch 104 taken 980 times.
✗ Branch 105 not taken.
✓ Branch 106 taken 1000949 times.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✓ Branch 110 taken 3 times.
✗ Branch 111 not taken.
✓ Branch 112 taken 552 times.
✗ Branch 113 not taken.
✓ Branch 114 taken 3 times.
✗ Branch 115 not taken.
✓ Branch 116 taken 62 times.
✗ Branch 117 not taken.
✓ Branch 118 taken 5 times.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✓ Branch 122 taken 1 times.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✓ Branch 126 taken 3 times.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✓ Branch 134 taken 480 times.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✓ Branch 138 taken 512 times.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✓ Branch 142 taken 489 times.
✗ Branch 143 not taken.
✓ Branch 144 taken 27 times.
✗ Branch 145 not taken.
✓ Branch 146 taken 512 times.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✓ Branch 154 taken 2 times.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✓ Branch 158 taken 2472 times.
✗ Branch 159 not taken.
✓ Branch 160 taken 14 times.
✗ Branch 161 not taken.
✗ Branch 162 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✓ Branch 172 taken 794 times.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✓ Branch 178 taken 3993 times.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✓ Branch 182 taken 3 times.
✗ Branch 183 not taken.
✓ Branch 184 taken 5283 times.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✓ Branch 190 taken 9 times.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✓ Branch 196 taken 45 times.
✗ Branch 197 not taken.
✓ Branch 198 taken 11223266 times.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
✓ Branch 204 taken 11 times.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✗ Branch 207 not taken.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✓ Branch 214 taken 719 times.
✗ Branch 215 not taken.
✓ Branch 216 taken 3 times.
✗ Branch 217 not taken.
✓ Branch 218 taken 3 times.
✗ Branch 219 not taken.
✓ Branch 220 taken 4176 times.
✗ Branch 221 not taken.
✓ Branch 222 taken 1 times.
✗ Branch 223 not taken.
✓ Branch 224 taken 116 times.
✗ Branch 225 not taken.
✓ Branch 226 taken 1784 times.
✗ Branch 227 not taken.
✓ Branch 228 taken 30000003 times.
✗ Branch 229 not taken.
✓ Branch 230 taken 30000003 times.
✗ Branch 231 not taken.
✓ Branch 232 taken 1314 times.
✗ Branch 233 not taken.
✓ Branch 234 taken 8351 times.
✗ Branch 235 not taken.
✓ Branch 236 taken 6583 times.
✗ Branch 237 not taken.
✓ Branch 238 taken 4617 times.
✗ Branch 239 not taken.
✓ Branch 240 taken 1 times.
✓ Branch 241 taken 1 times.
✓ Branch 242 taken 51 times.
✗ Branch 243 not taken.
✓ Branch 244 taken 13861 times.
✓ Branch 245 taken 2 times.
✓ Branch 246 taken 11538 times.
✓ Branch 247 taken 2 times.
✓ Branch 248 taken 102 times.
✗ Branch 249 not taken.
✓ Branch 250 taken 8 times.
✗ Branch 251 not taken.
✓ Branch 252 taken 26 times.
✗ Branch 253 not taken.
✓ Branch 254 taken 509 times.
✗ Branch 255 not taken.
✓ Branch 256 taken 36189011 times.
✗ Branch 257 not taken.
✓ Branch 258 taken 3 times.
✗ Branch 259 not taken.
✓ Branch 260 taken 6915138 times.
✓ Branch 261 taken 109 times.
✓ Branch 262 taken 9126 times.
✗ Branch 263 not taken.
✓ Branch 264 taken 1 times.
✗ Branch 265 not taken.
✓ Branch 266 taken 1 times.
✗ Branch 267 not taken.
✓ Branch 268 taken 3 times.
✓ Branch 269 taken 1 times.
✗ Branch 270 not taken.
✓ Branch 271 taken 1 times.
✗ Branch 272 not taken.
✗ Branch 273 not taken.
✓ Branch 274 taken 3 times.
✗ Branch 275 not taken.
✗ Branch 276 not taken.
✗ Branch 277 not taken.
✗ Branch 278 not taken.
✗ Branch 279 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 282 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 285 not taken.
✓ Branch 286 taken 1080 times.
✗ Branch 287 not taken.
✗ Branch 288 not taken.
✗ Branch 289 not taken.
✗ Branch 290 not taken.
✗ Branch 291 not taken.
✓ Branch 292 taken 1152 times.
✗ Branch 293 not taken.
✗ Branch 294 not taken.
✗ Branch 295 not taken.
✗ Branch 296 not taken.
✗ Branch 297 not taken.
✓ Branch 298 taken 1080 times.
✗ Branch 299 not taken.
✗ Branch 300 not taken.
✗ Branch 301 not taken.
✗ Branch 302 not taken.
✗ Branch 303 not taken.
✓ Branch 304 taken 1152 times.
✗ Branch 305 not taken.
✗ Branch 306 not taken.
✗ Branch 307 not taken.
✗ Branch 308 not taken.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✗ Branch 315 not taken.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 321 not taken.
✓ Branch 322 taken 5562 times.
✗ Branch 323 not taken.
481138408 return hasConstantStride() ? mSize * mStrideOrTotalSize : mStrideOrTotalSize;
616 }
617
618 /// Return the name of the value type of a single element in this array (e.g., "float" or "vec3d").
619 19632 Name valueType() const override { return typeNameAsString<ValueType>(); }
620
621 /// Return the name of the codec used by this array (e.g., "trnc" or "fxpt").
622
2/4
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
19568 Name codecType() const override { return Codec::name(); }
623
624 /// Return the size in bytes of the value type of a single element in this array.
625 36 Index valueTypeSize() const override { return sizeof(ValueType); }
626
627 /// Return the size in bytes of the storage type of a single element of this array.
628 /// @note If the Codec is a NullCodec, valueSize() == storageSize()
629 88654 Index storageTypeSize() const override { return sizeof(StorageType); }
630
631 /// Return @c true if the value type is floating point
632 bool valueTypeIsFloatingPoint() const override;
633
634 /// Return @c true if the value type is a class (ie vector, matrix or quaternion return true)
635 bool valueTypeIsClass() const override;
636
637 /// Return @c true if the value type is a vector
638 bool valueTypeIsVector() const override;
639
640 /// Return @c true if the value type is a quaternion
641 bool valueTypeIsQuaternion() const override;
642
643 /// Return @c true if the value type is a matrix
644 bool valueTypeIsMatrix() const override;
645
646 /// Return the number of bytes of memory used by this attribute.
647 size_t memUsage() const override;
648
649 #if OPENVDB_ABI_VERSION_NUMBER >= 10
650 /// Return the number of bytes of memory used by this attribute array once it
651 /// has been deserialized (this may be different to memUsage() if delay-loading
652 /// is in use). Note that this method does NOT consider the fact that a
653 /// uniform attribute could be expanded and only deals with delay-loading.
654 size_t memUsageIfLoaded() const override;
655 #endif
656
657 /// Return the value at index @a n (assumes in-core)
658 ValueType getUnsafe(Index n) const;
659 /// Return the value at index @a n
660 ValueType get(Index n) const;
661 /// Return the @a value at index @a n (assumes in-core)
662 template<typename T> void getUnsafe(Index n, T& value) const;
663 /// Return the @a value at index @a n
664 template<typename T> void get(Index n, T& value) const;
665
666 /// Non-member equivalent to getUnsafe() that static_casts array to this TypedAttributeArray
667 /// (assumes in-core)
668 static ValueType getUnsafe(const AttributeArray* array, const Index n);
669
670 /// Set @a value at the given index @a n (assumes in-core)
671 void setUnsafe(Index n, const ValueType& value);
672 /// Set @a value at the given index @a n
673 void set(Index n, const ValueType& value);
674 /// Set @a value at the given index @a n (assumes in-core)
675 template<typename T> void setUnsafe(Index n, const T& value);
676 /// Set @a value at the given index @a n
677 template<typename T> void set(Index n, const T& value);
678
679 /// Non-member equivalent to setUnsafe() that static_casts array to this TypedAttributeArray
680 /// (assumes in-core)
681 static void setUnsafe(AttributeArray* array, const Index n, const ValueType& value);
682
683 /// Set value at given index @a n from @a sourceIndex of another @a sourceArray
684 OPENVDB_DEPRECATED_MESSAGE("Use copyValues() with source-target index pairs")
685 void set(const Index n, const AttributeArray& sourceArray, const Index sourceIndex) override;
686
687 /// Return @c true if this array is stored as a single uniform value.
688
32/56
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 2899 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 2866 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 2 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 2 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 2 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 2 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 1 times.
✗ Branch 40 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 47 taken 1 times.
✗ Branch 48 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 51 taken 1 times.
✗ Branch 52 not taken.
✓ Branch 53 taken 1 times.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
18760573 bool isUniform() const override { return mIsUniform; }
689 /// @brief Replace the single value storage with an array of length size().
690 /// @note Non-uniform attributes are unchanged.
691 /// @param fill toggle to initialize the array elements with the pre-expanded value.
692 void expand(bool fill = true) override;
693 /// Replace the existing array with a uniform zero value.
694 void collapse() override;
695 /// Compact the existing array to become uniform if all values are identical
696 bool compact() override;
697
698 /// Replace the existing array with the given uniform value.
699 void collapse(const ValueType& uniformValue);
700 /// @brief Fill the existing array with the given value.
701 /// @note Identical to collapse() except a non-uniform array will not become uniform.
702 void fill(const ValueType& value);
703
704 /// Non-member equivalent to collapse() that static_casts array to this TypedAttributeArray
705 static void collapse(AttributeArray* array, const ValueType& value);
706 /// Non-member equivalent to fill() that static_casts array to this TypedAttributeArray
707 static void fill(AttributeArray* array, const ValueType& value);
708
709 /// Compress the attribute array.
710 OPENVDB_DEPRECATED_MESSAGE("Previously this compressed the attribute array, now it does nothing")
711 bool compress() override;
712 /// Uncompress the attribute array.
713 OPENVDB_DEPRECATED_MESSAGE("Previously this uncompressed the attribute array, now it does nothing")
714 bool decompress() override;
715
716 /// Read attribute data from a stream.
717 void read(std::istream&) override;
718 /// Write attribute data to a stream.
719 /// @param os the output stream
720 /// @param outputTransient if true, write out transient attributes
721 void write(std::ostream& os, bool outputTransient) const override;
722 /// Write attribute data to a stream, don't write transient attributes.
723 void write(std::ostream&) const override;
724
725 /// Read attribute metadata from a stream.
726 void readMetadata(std::istream&) override;
727 /// Write attribute metadata to a stream.
728 /// @param os the output stream
729 /// @param outputTransient if true, write out transient attributes
730 /// @param paged if true, data is written out in pages
731 void writeMetadata(std::ostream& os, bool outputTransient, bool paged) const override;
732
733 /// Read attribute buffers from a stream.
734 void readBuffers(std::istream&) override;
735 /// Write attribute buffers to a stream.
736 /// @param os the output stream
737 /// @param outputTransient if true, write out transient attributes
738 void writeBuffers(std::ostream& os, bool outputTransient) const override;
739
740 /// Read attribute buffers from a paged stream.
741 void readPagedBuffers(compression::PagedInputStream&) override;
742 /// Write attribute buffers to a paged stream.
743 /// @param os the output stream
744 /// @param outputTransient if true, write out transient attributes
745 void writePagedBuffers(compression::PagedOutputStream& os, bool outputTransient) const override;
746
747 /// Return @c true if this buffer's values have not yet been read from disk.
748 inline bool isOutOfCore() const;
749
750 /// Ensures all data is in-core
751 void loadData() const override;
752
753 /// Return @c true if all data has been loaded
754 bool isDataLoaded() const override;
755
756 #if OPENVDB_ABI_VERSION_NUMBER >= 9
757 /// Return the raw data buffer
758 inline const StorageType* constData() const { return this->data(); }
759 #endif
760
761 protected:
762 AccessorBasePtr getAccessor() const override;
763
764 /// Return the raw data buffer
765
1/2
✓ Branch 0 taken 225224122 times.
✗ Branch 1 not taken.
900892606 inline StorageType* data() { assert(validData()); return mData.get(); }
766
1/2
✓ Branch 0 taken 214080643 times.
✗ Branch 1 not taken.
856321498 inline const StorageType* data() const { assert(validData()); return mData.get(); }
767
768 /// Verify that data is not out-of-core or in a partially-read state
769
155/324
✓ Branch 0 taken 1688 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1688 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 539 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 539 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9556456 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 9556456 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 7 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 7 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 9 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 9 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 3572804 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 3572804 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 197 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 197 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 197 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 197 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 197 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 197 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 261 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 261 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 265 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 265 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 277 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 277 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 2990 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 2990 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 1954 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 1954 times.
✗ Branch 55 not taken.
✓ Branch 56 taken 1958 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 1958 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 6019 times.
✓ Branch 61 taken 3129 times.
✓ Branch 62 taken 6019 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 1614 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 1614 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 1601 times.
✗ Branch 69 not taken.
✓ Branch 70 taken 1601 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 1 times.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✓ Branch 88 taken 4329 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 4329 times.
✗ Branch 91 not taken.
✓ Branch 92 taken 3 times.
✗ Branch 93 not taken.
✓ Branch 94 taken 3 times.
✗ Branch 95 not taken.
✓ Branch 96 taken 1 times.
✗ Branch 97 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 100 taken 14 times.
✗ Branch 101 not taken.
✓ Branch 102 taken 14 times.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✓ Branch 116 taken 24345230 times.
✗ Branch 117 not taken.
✓ Branch 118 taken 24345230 times.
✗ Branch 119 not taken.
✓ Branch 120 taken 30001594 times.
✗ Branch 121 not taken.
✓ Branch 122 taken 30001594 times.
✗ Branch 123 not taken.
✓ Branch 124 taken 30000007 times.
✗ Branch 125 not taken.
✓ Branch 126 taken 30000007 times.
✗ Branch 127 not taken.
✓ Branch 128 taken 4 times.
✗ Branch 129 not taken.
✓ Branch 130 taken 4 times.
✗ Branch 131 not taken.
✓ Branch 132 taken 4 times.
✗ Branch 133 not taken.
✓ Branch 134 taken 4 times.
✗ Branch 135 not taken.
✓ Branch 136 taken 93324048 times.
✗ Branch 137 not taken.
✓ Branch 138 taken 93324048 times.
✗ Branch 139 not taken.
✓ Branch 140 taken 192 times.
✗ Branch 141 not taken.
✓ Branch 142 taken 192 times.
✗ Branch 143 not taken.
✓ Branch 144 taken 1230 times.
✗ Branch 145 not taken.
✓ Branch 146 taken 1230 times.
✗ Branch 147 not taken.
✓ Branch 148 taken 419 times.
✗ Branch 149 not taken.
✓ Branch 150 taken 419 times.
✗ Branch 151 not taken.
✓ Branch 152 taken 310 times.
✗ Branch 153 not taken.
✓ Branch 154 taken 310 times.
✗ Branch 155 not taken.
✓ Branch 156 taken 60001618 times.
✗ Branch 157 not taken.
✓ Branch 158 taken 60001618 times.
✗ Branch 159 not taken.
✓ Branch 160 taken 60000528 times.
✗ Branch 161 not taken.
✓ Branch 162 taken 60000528 times.
✗ Branch 163 not taken.
✓ Branch 164 taken 353 times.
✗ Branch 165 not taken.
✓ Branch 166 taken 353 times.
✗ Branch 167 not taken.
✓ Branch 168 taken 19 times.
✓ Branch 169 taken 3131 times.
✓ Branch 170 taken 19 times.
✗ Branch 171 not taken.
✓ Branch 172 taken 43745114 times.
✗ Branch 173 not taken.
✓ Branch 174 taken 43745114 times.
✗ Branch 175 not taken.
✓ Branch 176 taken 385 times.
✗ Branch 177 not taken.
✓ Branch 178 taken 385 times.
✗ Branch 179 not taken.
✓ Branch 180 taken 22 times.
✓ Branch 181 taken 6 times.
✓ Branch 182 taken 20 times.
✓ Branch 183 taken 2 times.
✓ Branch 184 taken 7434471 times.
✗ Branch 185 not taken.
✓ Branch 186 taken 7434471 times.
✗ Branch 187 not taken.
✓ Branch 188 taken 572 times.
✗ Branch 189 not taken.
✓ Branch 190 taken 572 times.
✗ Branch 191 not taken.
✓ Branch 192 taken 745 times.
✗ Branch 193 not taken.
✓ Branch 194 taken 745 times.
✗ Branch 195 not taken.
✓ Branch 196 taken 1138 times.
✗ Branch 197 not taken.
✓ Branch 198 taken 1138 times.
✗ Branch 199 not taken.
✓ Branch 200 taken 604 times.
✗ Branch 201 not taken.
✓ Branch 202 taken 604 times.
✗ Branch 203 not taken.
✓ Branch 204 taken 339 times.
✗ Branch 205 not taken.
✓ Branch 206 taken 339 times.
✗ Branch 207 not taken.
✓ Branch 208 taken 323 times.
✗ Branch 209 not taken.
✓ Branch 210 taken 323 times.
✗ Branch 211 not taken.
✓ Branch 212 taken 2150 times.
✗ Branch 213 not taken.
✓ Branch 214 taken 2150 times.
✗ Branch 215 not taken.
✓ Branch 216 taken 9581 times.
✗ Branch 217 not taken.
✓ Branch 218 taken 9581 times.
✗ Branch 219 not taken.
✓ Branch 220 taken 1429 times.
✗ Branch 221 not taken.
✓ Branch 222 taken 1429 times.
✗ Branch 223 not taken.
✓ Branch 224 taken 390 times.
✗ Branch 225 not taken.
✓ Branch 226 taken 390 times.
✗ Branch 227 not taken.
✓ Branch 228 taken 10012460 times.
✗ Branch 229 not taken.
✓ Branch 230 taken 10012460 times.
✗ Branch 231 not taken.
✓ Branch 232 taken 324 times.
✗ Branch 233 not taken.
✓ Branch 234 taken 324 times.
✗ Branch 235 not taken.
✓ Branch 236 taken 2215 times.
✗ Branch 237 not taken.
✓ Branch 238 taken 2215 times.
✗ Branch 239 not taken.
✓ Branch 240 taken 2420 times.
✗ Branch 241 not taken.
✓ Branch 242 taken 2420 times.
✗ Branch 243 not taken.
✓ Branch 244 taken 67218247 times.
✗ Branch 245 not taken.
✓ Branch 246 taken 67218247 times.
✗ Branch 247 not taken.
✓ Branch 248 taken 1885 times.
✗ Branch 249 not taken.
✓ Branch 250 taken 1885 times.
✗ Branch 251 not taken.
✓ Branch 252 taken 4567 times.
✗ Branch 253 not taken.
✓ Branch 254 taken 4567 times.
✗ Branch 255 not taken.
✓ Branch 256 taken 328 times.
✗ Branch 257 not taken.
✓ Branch 258 taken 328 times.
✗ Branch 259 not taken.
✓ Branch 260 taken 1335 times.
✗ Branch 261 not taken.
✓ Branch 262 taken 1335 times.
✗ Branch 263 not taken.
✓ Branch 264 taken 345 times.
✗ Branch 265 not taken.
✓ Branch 266 taken 345 times.
✗ Branch 267 not taken.
✓ Branch 268 taken 337 times.
✗ Branch 269 not taken.
✓ Branch 270 taken 337 times.
✗ Branch 271 not taken.
✓ Branch 272 taken 334 times.
✗ Branch 273 not taken.
✓ Branch 274 taken 333 times.
✓ Branch 275 taken 1 times.
✓ Branch 276 taken 3173 times.
✗ Branch 277 not taken.
✓ Branch 278 taken 3173 times.
✗ Branch 279 not taken.
✓ Branch 280 taken 7988 times.
✗ Branch 281 not taken.
✓ Branch 282 taken 7988 times.
✗ Branch 283 not taken.
✓ Branch 284 taken 2195 times.
✗ Branch 285 not taken.
✓ Branch 286 taken 2195 times.
✗ Branch 287 not taken.
✓ Branch 288 taken 2960 times.
✗ Branch 289 not taken.
✓ Branch 290 taken 2960 times.
✗ Branch 291 not taken.
✓ Branch 292 taken 6842 times.
✗ Branch 293 not taken.
✓ Branch 294 taken 6842 times.
✗ Branch 295 not taken.
✓ Branch 296 taken 1169 times.
✗ Branch 297 not taken.
✓ Branch 298 taken 1169 times.
✗ Branch 299 not taken.
✓ Branch 300 taken 1 times.
✗ Branch 301 not taken.
✓ Branch 302 taken 1 times.
✗ Branch 303 not taken.
✓ Branch 304 taken 1 times.
✗ Branch 305 not taken.
✓ Branch 306 taken 1 times.
✗ Branch 307 not taken.
✓ Branch 308 taken 1 times.
✗ Branch 309 not taken.
✓ Branch 310 taken 1 times.
✗ Branch 311 not taken.
✓ Branch 312 taken 14 times.
✗ Branch 313 not taken.
✓ Branch 314 taken 14 times.
✗ Branch 315 not taken.
✓ Branch 316 taken 8378 times.
✗ Branch 317 not taken.
✓ Branch 318 taken 8378 times.
✗ Branch 319 not taken.
✓ Branch 320 taken 6462 times.
✗ Branch 321 not taken.
✓ Branch 322 taken 6462 times.
✗ Branch 323 not taken.
439316447 inline bool validData() const { return !(isOutOfCore() || (flags() & PARTIALREAD)); }
770
771 private:
772 friend class ::TestAttributeArray;
773
774 TypedAttributeArray(const TypedAttributeArray&, const tbb::spin_mutex::scoped_lock&);
775
776 /// Load data from memory-mapped file.
777 inline void doLoad() const;
778 /// Load data from memory-mapped file (unsafe as this function is not protected by a mutex).
779 /// @param compression parameter no longer used
780 inline void doLoadUnsafe(const bool compression = true) const;
781 /// Compress in-core data assuming mutex is locked
782 inline bool compressUnsafe();
783
784 /// Toggle out-of-core state
785 inline void setOutOfCore(const bool);
786
787 /// Compare the this data to another attribute array. Used by the base class comparison operator
788 bool isEqual(const AttributeArray& other) const override;
789
790 /// Virtual function to retrieve the data buffer from the derived class cast to a char byte array
791 char* dataAsByteArray() override;
792 const char* dataAsByteArray() const override;
793
794 size_t arrayMemUsage() const;
795 void allocate();
796 void deallocate();
797
798 /// Helper function for use with registerType()
799 246297 static AttributeArray::Ptr factory(Index n, Index strideOrTotalSize, bool constantStride,
800 const Metadata* metadata) {
801 246297 return TypedAttributeArray::create(n, strideOrTotalSize, constantStride, metadata);
802 }
803
804 static std::unique_ptr<const NamePair> sTypeName;
805 std::unique_ptr<StorageType[]> mData;
806 Index mSize;
807 Index mStrideOrTotalSize;
808 }; // class TypedAttributeArray
809
810
811 ////////////////////////////////////////
812
813
814 /// AttributeHandles provide access to specific TypedAttributeArray methods without needing
815 /// to know the compression codec, however these methods also incur the cost of a function pointer
816 template <typename ValueType, typename CodecType = UnknownCodec>
817 7 class AttributeHandle
818 {
819 public:
820 using Handle = AttributeHandle<ValueType, CodecType>;
821 using Ptr = std::shared_ptr<Handle>;
822 using UniquePtr = std::unique_ptr<Handle>;
823
824 protected:
825 using GetterPtr = ValueType (*)(const AttributeArray* array, const Index n);
826 using SetterPtr = void (*)(AttributeArray* array, const Index n, const ValueType& value);
827 using ValuePtr = void (*)(AttributeArray* array, const ValueType& value);
828
829 public:
830 static Ptr create(const AttributeArray& array, const bool collapseOnDestruction = true);
831
832 AttributeHandle(const AttributeArray& array, const bool collapseOnDestruction = true);
833
834 14 AttributeHandle(const AttributeHandle&) = default;
835 AttributeHandle& operator=(const AttributeHandle&) = default;
836
837 virtual ~AttributeHandle();
838
839
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
6 Index stride() const { return mStrideOrTotalSize; }
840
22/42
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 34 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 16 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 28 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 8 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 8 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 13 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 6 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 9 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 6 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 3 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 48 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 16 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 24 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 10 times.
✗ Branch 40 not taken.
✓ Branch 41 taken 8 times.
372 Index size() const { return mSize; }
841
842 bool isUniform() const;
843 bool hasConstantStride() const;
844
845 ValueType get(Index n, Index m = 0) const;
846
847 const AttributeArray& array() const;
848
849 protected:
850 Index index(Index n, Index m) const;
851
852 const AttributeArray* mArray;
853
854 GetterPtr mGetter;
855 SetterPtr mSetter;
856 ValuePtr mCollapser;
857 ValuePtr mFiller;
858
859 private:
860 friend class ::TestAttributeArray;
861
862 template <bool IsUnknownCodec>
863 typename std::enable_if<IsUnknownCodec, bool>::type compatibleType() const;
864
865 template <bool IsUnknownCodec>
866 typename std::enable_if<!IsUnknownCodec, bool>::type compatibleType() const;
867
868 template <bool IsUnknownCodec>
869 typename std::enable_if<IsUnknownCodec, ValueType>::type get(Index index) const;
870
871 template <bool IsUnknownCodec>
872 typename std::enable_if<!IsUnknownCodec, ValueType>::type get(Index index) const;
873
874 // local copy of AttributeArray (to preserve compression)
875 AttributeArray::Ptr mLocalArray;
876
877 Index mStrideOrTotalSize;
878 Index mSize;
879 bool mCollapseOnDestruction;
880 }; // class AttributeHandle
881
882
883 ////////////////////////////////////////
884
885
886 /// Write-able version of AttributeHandle
887 template <typename ValueType, typename CodecType = UnknownCodec>
888 class AttributeWriteHandle : public AttributeHandle<ValueType, CodecType>
889 {
890 public:
891 using Handle = AttributeWriteHandle<ValueType, CodecType>;
892 using Ptr = std::shared_ptr<Handle>;
893 using ScopedPtr = std::unique_ptr<Handle>;
894
895 static Ptr create(AttributeArray& array, const bool expand = true);
896
897 AttributeWriteHandle(AttributeArray& array, const bool expand = true);
898
899
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
107870 virtual ~AttributeWriteHandle() = default;
900
901 /// @brief If this array is uniform, replace it with an array of length size().
902 /// @param fill if true, assign the uniform value to each element of the array.
903 void expand(bool fill = true);
904
905 /// Replace the existing array with a uniform value (zero if none provided).
906 void collapse();
907 void collapse(const ValueType& uniformValue);
908
909 /// Compact the existing array to become uniform if all values are identical
910 bool compact();
911
912 /// @brief Fill the existing array with the given value.
913 /// @note Identical to collapse() except a non-uniform array will not become uniform.
914 void fill(const ValueType& value);
915
916 void set(Index n, const ValueType& value);
917 void set(Index n, Index m, const ValueType& value);
918
919 AttributeArray& array();
920
921 private:
922 friend class ::TestAttributeArray;
923
924 template <bool IsUnknownCodec>
925 typename std::enable_if<IsUnknownCodec, void>::type set(Index index, const ValueType& value) const;
926
927 template <bool IsUnknownCodec>
928 typename std::enable_if<!IsUnknownCodec, void>::type set(Index index, const ValueType& value) const;
929 }; // class AttributeWriteHandle
930
931
932 ////////////////////////////////////////
933
934
935 // Attribute codec implementation
936
937
938 template<typename ValueType>
939 inline void
940 NullCodec::decode(const ValueType& data, ValueType& val)
941 {
942 144470223 val = data;
943 }
944
945
946 template<typename ValueType>
947 inline void
948 NullCodec::encode(const ValueType& val, ValueType& data)
949 {
950 47253177 data = val;
951 }
952
953
954 template<typename StorageType, typename ValueType>
955 inline void
956 TruncateCodec::decode(const StorageType& data, ValueType& val)
957 {
958 26 val = static_cast<ValueType>(data);
959 }
960
961
962 template<typename StorageType, typename ValueType>
963 inline void
964 TruncateCodec::encode(const ValueType& val, StorageType& data)
965 {
966
9/14
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 327 times.
✓ Branch 3 taken 325 times.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 12 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
688 data = static_cast<StorageType>(val);
967 }
968
969
970 template <bool OneByte, typename Range>
971 template<typename StorageType, typename ValueType>
972 inline void
973 118 FixedPointCodec<OneByte, Range>::decode(const StorageType& data, ValueType& val)
974 {
975
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
60000102 val = fixedPointToFloatingPoint<ValueType>(data);
976
977 // shift value range to be -0.5 => 0.5 (as this is most commonly used for position)
978
979
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
148 val = Range::template decode<ValueType>(val);
980 118 }
981
982
983 template <bool OneByte, typename Range>
984 template<typename StorageType, typename ValueType>
985 inline void
986 1338 FixedPointCodec<OneByte, Range>::encode(const ValueType& val, StorageType& data)
987 {
988 // shift value range to be -0.5 => 0.5 (as this is most commonly used for position)
989
990 1996 const ValueType newVal = Range::template encode<ValueType>(val);
991
992
4/8
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 15 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 15 times.
✗ Branch 12 not taken.
60002740 data = floatingPointToFixedPoint<StorageType>(newVal);
993 1338 }
994
995
996 template<typename T>
997 inline void
998 UnitVecCodec::decode(const StorageType& data, math::Vec3<T>& val)
999 {
1000 9 val = math::QuantizedUnitVec::unpack(data);
1001 }
1002
1003
1004 template<typename T>
1005 inline void
1006 UnitVecCodec::encode(const math::Vec3<T>& val, StorageType& data)
1007 {
1008 327 data = math::QuantizedUnitVec::pack(val);
1009 }
1010
1011
1012 ////////////////////////////////////////
1013
1014 // AttributeArray implementation
1015
1016 template <typename IterT>
1017 29482 void AttributeArray::doCopyValues(const AttributeArray& sourceArray, const IterT& iter,
1018 bool rangeChecking/*=true*/)
1019 {
1020 // ensure both arrays have float-float or integer-integer value types
1021
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 14753 times.
29482 assert(sourceArray.valueTypeIsFloatingPoint() == this->valueTypeIsFloatingPoint());
1022 // ensure both arrays have been loaded from disk (if delay-loaded)
1023
2/4
✓ Branch 1 taken 14753 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14753 times.
29482 assert(sourceArray.isDataLoaded() && this->isDataLoaded());
1024 // ensure storage size * stride matches on both arrays
1025
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 14753 times.
29482 assert(this->storageTypeSize()*this->stride() ==
1026 sourceArray.storageTypeSize()*sourceArray.stride());
1027
1028 29482 const size_t bytes(sourceArray.storageTypeSize()*sourceArray.stride());
1029 29482 const char* const sourceBuffer = sourceArray.dataAsByteArray();
1030 29482 char* const targetBuffer = this->dataAsByteArray();
1031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14753 times.
29482 assert(sourceBuffer && targetBuffer);
1032
1033
3/4
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 14730 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 23 times.
29482 if (rangeChecking && this->isUniform()) {
1034 OPENVDB_THROW(IndexError, "Cannot copy array data as target array is uniform.");
1035 }
1036
1037 29482 const bool sourceIsUniform = sourceArray.isUniform();
1038
1039
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 14730 times.
29482 const Index sourceDataSize = rangeChecking ? sourceArray.dataSize() : 0;
1040
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 14730 times.
29482 const Index targetDataSize = rangeChecking ? this->dataSize() : 0;
1041
1042
2/2
✓ Branch 0 taken 9328863 times.
✓ Branch 1 taken 14751 times.
18686861 for (IterT it(iter); it; ++it) {
1043
2/2
✓ Branch 0 taken 9328645 times.
✓ Branch 1 taken 218 times.
18657381 const Index sourceIndex = sourceIsUniform ? 0 : it.sourceIndex();
1044 18657381 const Index targetIndex = it.targetIndex();
1045
1046
2/2
✓ Branch 0 taken 343 times.
✓ Branch 1 taken 9328520 times.
18657381 if (rangeChecking) {
1047
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 342 times.
343 if (sourceIndex >= sourceDataSize) {
1048
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
4 OPENVDB_THROW(IndexError,
1049 "Cannot copy array data as source index exceeds size of source array.");
1050 }
1051
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 341 times.
342 if (targetIndex >= targetDataSize) {
1052
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
4 OPENVDB_THROW(IndexError,
1053 "Cannot copy array data as target index exceeds size of target array.");
1054 }
1055 } else {
1056 // range-checking asserts
1057
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9328520 times.
18657038 assert(sourceIndex < sourceArray.dataSize());
1058
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9328520 times.
18657038 assert(targetIndex < this->dataSize());
1059
3/4
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 9328518 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
18657038 if (this->isUniform()) assert(targetIndex == Index(0));
1060 }
1061
1062 18657379 const size_t targetOffset(targetIndex * bytes);
1063 18657379 const size_t sourceOffset(sourceIndex * bytes);
1064
1065 18657379 std::memcpy(targetBuffer + targetOffset, sourceBuffer + sourceOffset, bytes);
1066 }
1067 29480 }
1068
1069 template <typename IterT>
1070 29459 void AttributeArray::copyValuesUnsafe(const AttributeArray& sourceArray, const IterT& iter)
1071 {
1072 29459 this->doCopyValues(sourceArray, iter, /*range-checking=*/false);
1073 29459 }
1074
1075 template <typename IterT>
1076 25 void AttributeArray::copyValues(const AttributeArray& sourceArray, const IterT& iter,
1077 bool compact/* = true*/)
1078 {
1079 25 const Index bytes = sourceArray.storageTypeSize();
1080
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 23 times.
25 if (bytes != this->storageTypeSize()) {
1081
2/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
8 OPENVDB_THROW(TypeError, "Cannot copy array data due to mis-match in storage type sizes.");
1082 }
1083
1084 // ensure both arrays have been loaded from disk
1085 23 sourceArray.loadData();
1086 23 this->loadData();
1087
1088 // if the target array is uniform, expand it first
1089 23 this->expand();
1090
1091 // TODO: Acquire mutex locks for source and target arrays to ensure that
1092 // value copying is always thread-safe. Note that the unsafe method will be
1093 // faster, but can only be used if neither the source or target arrays are
1094 // modified during copying. Note that this will require a new private
1095 // virtual method with ABI=7 to access the mutex from the derived class.
1096
1097 23 this->doCopyValues(sourceArray, iter, true);
1098
1099 // attempt to compact target array
1100
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 times.
21 if (compact) {
1101 20 this->compact();
1102 }
1103 21 }
1104
1105
1106 ////////////////////////////////////////
1107
1108 // TypedAttributeArray implementation
1109
1110 template<typename ValueType_, typename Codec_>
1111 std::unique_ptr<const NamePair> TypedAttributeArray<ValueType_, Codec_>::sTypeName;
1112
1113
1114 template<typename ValueType_, typename Codec_>
1115 246824 TypedAttributeArray<ValueType_, Codec_>::TypedAttributeArray(
1116 Index n, Index strideOrTotalSize, bool constantStride, const ValueType& uniformValue)
1117 : AttributeArray()
1118
2/2
✓ Branch 1 taken 68922 times.
✓ Branch 2 taken 68922 times.
384664 , mData(new StorageType[1])
1119 , mSize(n)
1120 246824 , mStrideOrTotalSize(strideOrTotalSize)
1121 {
1122
2/2
✓ Branch 0 taken 114681 times.
✓ Branch 1 taken 8756 times.
246824 if (constantStride) {
1123
1/2
✓ Branch 1 taken 114681 times.
✗ Branch 2 not taken.
229315 this->setConstantStride(true);
1124
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 114680 times.
229315 if (strideOrTotalSize == 0) {
1125
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
8 OPENVDB_THROW(ValueError, "Creating a TypedAttributeArray with a constant stride requires that " \
1126 "stride to be at least one.")
1127 }
1128 }
1129 else {
1130
1/2
✓ Branch 1 taken 8756 times.
✗ Branch 2 not taken.
17509 this->setConstantStride(false);
1131
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8754 times.
17509 if (mStrideOrTotalSize < n) {
1132
2/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
16 OPENVDB_THROW(ValueError, "Creating a TypedAttributeArray with a non-constant stride must have " \
1133 "a total size of at least the number of elements in the array.")
1134 }
1135 }
1136
2/2
✓ Branch 0 taken 64405 times.
✓ Branch 1 taken 59029 times.
246818 mSize = std::max(Index(1), mSize);
1137
2/2
✓ Branch 0 taken 2726 times.
✓ Branch 1 taken 120708 times.
246818 mStrideOrTotalSize = std::max(Index(1), mStrideOrTotalSize);
1138 246818 Codec::encode(uniformValue, this->data()[0]);
1139 246818 }
1140
1141
1142 template<typename ValueType_, typename Codec_>
1143 23358 TypedAttributeArray<ValueType_, Codec_>::TypedAttributeArray(const TypedAttributeArray& rhs)
1144
1/2
✓ Branch 2 taken 11679 times.
✗ Branch 3 not taken.
23358 : TypedAttributeArray(rhs, tbb::spin_mutex::scoped_lock(rhs.mMutex))
1145 {
1146 }
1147
1148
1149 template<typename ValueType_, typename Codec_>
1150 23358 TypedAttributeArray<ValueType_, Codec_>::TypedAttributeArray(const TypedAttributeArray& rhs,
1151 const tbb::spin_mutex::scoped_lock& lock)
1152 : AttributeArray(rhs, lock)
1153
2/2
✓ Branch 0 taken 5413 times.
✓ Branch 1 taken 6266 times.
23358 , mSize(rhs.mSize)
1154
2/2
✓ Branch 1 taken 5413 times.
✓ Branch 2 taken 6266 times.
23358 , mStrideOrTotalSize(rhs.mStrideOrTotalSize)
1155 {
1156 if (this->validData()) {
1157
1/2
✓ Branch 1 taken 5411 times.
✗ Branch 2 not taken.
10822 this->allocate();
1158 10822 std::memcpy(static_cast<void*>(this->data()), rhs.data(), this->arrayMemUsage());
1159 }
1160 }
1161
1162
1163 template<typename ValueType_, typename Codec_>
1164 TypedAttributeArray<ValueType_, Codec_>&
1165 1 TypedAttributeArray<ValueType_, Codec_>::operator=(const TypedAttributeArray& rhs)
1166 {
1167
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (&rhs != this) {
1168 // lock both the source and target arrays to ensure thread-safety
1169 1 tbb::spin_mutex::scoped_lock lock(mMutex);
1170 1 tbb::spin_mutex::scoped_lock rhsLock(rhs.mMutex);
1171
1172 1 this->deallocate();
1173
1174 1 mFlags = rhs.mFlags;
1175 1 mUsePagedRead = rhs.mUsePagedRead;
1176 1 mSize = rhs.mSize;
1177 1 mStrideOrTotalSize = rhs.mStrideOrTotalSize;
1178
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 mIsUniform = rhs.mIsUniform;
1179
1180 if (this->validData()) {
1181
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 this->allocate();
1182 1 std::memcpy(static_cast<void*>(this->data()), rhs.data(), this->arrayMemUsage());
1183 }
1184 }
1185
1186 1 return *this;
1187 }
1188
1189
1190 template<typename ValueType_, typename Codec_>
1191 inline const NamePair&
1192 TypedAttributeArray<ValueType_, Codec_>::attributeType()
1193 {
1194 static std::once_flag once;
1195
316/518
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1160 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 486 times.
✓ Branch 8 taken 733 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 57 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 9 times.
✓ Branch 14 taken 9 times.
✓ Branch 15 taken 3 times.
✓ Branch 16 taken 19 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 11 times.
✓ Branch 19 taken 11 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
✓ Branch 22 taken 5 times.
✓ Branch 23 taken 18 times.
✓ Branch 24 taken 2 times.
✓ Branch 25 taken 4 times.
✓ Branch 26 taken 19 times.
✓ Branch 27 taken 3 times.
✓ Branch 28 taken 4 times.
✓ Branch 29 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 3 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 1 times.
✓ Branch 34 taken 4 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 1 times.
✓ Branch 37 taken 7 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 7 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✓ Branch 43 taken 4 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 1 times.
✓ Branch 46 taken 4 times.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 4 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✓ Branch 52 taken 4 times.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✓ Branch 55 taken 4 times.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✓ Branch 58 taken 4 times.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 4 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 4 times.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✓ Branch 67 taken 4 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 4 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✓ Branch 73 taken 2 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 1 times.
✓ Branch 79 taken 2 times.
✗ Branch 80 not taken.
✓ Branch 81 taken 1 times.
✓ Branch 82 taken 2 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 1 times.
✓ Branch 85 taken 2 times.
✗ Branch 86 not taken.
✓ Branch 87 taken 1 times.
✓ Branch 88 taken 2 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 11 times.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 93 taken 1 times.
✓ Branch 94 taken 1 times.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✓ Branch 97 taken 2 times.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 100 taken 2 times.
✓ Branch 101 taken 1 times.
✗ Branch 102 not taken.
✓ Branch 103 taken 9 times.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✓ Branch 106 taken 10 times.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✓ Branch 109 taken 3 times.
✗ Branch 110 not taken.
✓ Branch 112 taken 3 times.
✗ Branch 113 not taken.
✓ Branch 115 taken 2 times.
✗ Branch 116 not taken.
✓ Branch 117 taken 1 times.
✓ Branch 118 taken 1 times.
✗ Branch 119 not taken.
✓ Branch 120 taken 1 times.
✓ Branch 121 taken 1 times.
✓ Branch 122 taken 1 times.
✓ Branch 123 taken 1 times.
✓ Branch 124 taken 1 times.
✓ Branch 125 taken 1 times.
✓ Branch 126 taken 1 times.
✓ Branch 127 taken 1 times.
✓ Branch 128 taken 1 times.
✓ Branch 129 taken 1 times.
✓ Branch 130 taken 1 times.
✓ Branch 131 taken 1 times.
✓ Branch 132 taken 1 times.
✓ Branch 133 taken 1 times.
✓ Branch 134 taken 2 times.
✓ Branch 135 taken 1 times.
✓ Branch 136 taken 1 times.
✓ Branch 137 taken 2 times.
✓ Branch 138 taken 1 times.
✓ Branch 139 taken 1 times.
✓ Branch 140 taken 2 times.
✓ Branch 141 taken 1 times.
✓ Branch 142 taken 2 times.
✓ Branch 143 taken 1 times.
✓ Branch 144 taken 1 times.
✓ Branch 145 taken 2 times.
✓ Branch 146 taken 1 times.
✓ Branch 147 taken 1 times.
✓ Branch 148 taken 2 times.
✓ Branch 149 taken 1 times.
✓ Branch 150 taken 1 times.
✓ Branch 151 taken 1 times.
✓ Branch 152 taken 2 times.
✓ Branch 153 taken 1 times.
✓ Branch 154 taken 1 times.
✓ Branch 155 taken 2 times.
✓ Branch 156 taken 1 times.
✓ Branch 157 taken 1 times.
✓ Branch 158 taken 2 times.
✓ Branch 159 taken 1 times.
✓ Branch 160 taken 1 times.
✓ Branch 161 taken 2 times.
✓ Branch 162 taken 1 times.
✓ Branch 163 taken 1 times.
✓ Branch 164 taken 2 times.
✓ Branch 165 taken 1 times.
✓ Branch 166 taken 1 times.
✓ Branch 167 taken 2 times.
✓ Branch 168 taken 1 times.
✓ Branch 169 taken 1 times.
✓ Branch 170 taken 2 times.
✓ Branch 171 taken 5 times.
✓ Branch 172 taken 1 times.
✓ Branch 173 taken 1 times.
✓ Branch 174 taken 5 times.
✓ Branch 175 taken 1 times.
✓ Branch 176 taken 2 times.
✗ Branch 177 not taken.
✓ Branch 178 taken 1 times.
✓ Branch 179 taken 1 times.
✓ Branch 180 taken 1 times.
✓ Branch 181 taken 1 times.
✓ Branch 182 taken 2 times.
✗ Branch 183 not taken.
✓ Branch 184 taken 1 times.
✓ Branch 185 taken 1 times.
✓ Branch 186 taken 1 times.
✓ Branch 187 taken 1 times.
✓ Branch 188 taken 1 times.
✗ Branch 189 not taken.
✓ Branch 190 taken 1 times.
✓ Branch 191 taken 1 times.
✗ Branch 192 not taken.
✓ Branch 193 taken 1 times.
✓ Branch 194 taken 1 times.
✗ Branch 195 not taken.
✓ Branch 196 taken 1 times.
✓ Branch 197 taken 1 times.
✗ Branch 198 not taken.
✓ Branch 199 taken 1 times.
✓ Branch 200 taken 1 times.
✗ Branch 201 not taken.
✓ Branch 202 taken 1 times.
✓ Branch 203 taken 1 times.
✗ Branch 204 not taken.
✓ Branch 205 taken 1 times.
✓ Branch 206 taken 1 times.
✗ Branch 207 not taken.
✓ Branch 208 taken 1 times.
✓ Branch 209 taken 1 times.
✗ Branch 210 not taken.
✓ Branch 211 taken 1 times.
✓ Branch 212 taken 1 times.
✗ Branch 213 not taken.
✓ Branch 214 taken 1 times.
✓ Branch 215 taken 1 times.
✗ Branch 216 not taken.
✓ Branch 217 taken 1 times.
✓ Branch 218 taken 1 times.
✗ Branch 219 not taken.
✓ Branch 220 taken 1 times.
✓ Branch 221 taken 1 times.
✗ Branch 222 not taken.
✓ Branch 223 taken 1 times.
✓ Branch 224 taken 1 times.
✗ Branch 225 not taken.
✓ Branch 226 taken 1 times.
✓ Branch 227 taken 1 times.
✗ Branch 228 not taken.
✓ Branch 229 taken 1 times.
✓ Branch 230 taken 1 times.
✗ Branch 231 not taken.
✓ Branch 232 taken 1 times.
✓ Branch 233 taken 1 times.
✗ Branch 234 not taken.
✓ Branch 235 taken 1 times.
✓ Branch 236 taken 1 times.
✗ Branch 237 not taken.
✓ Branch 238 taken 1 times.
✓ Branch 239 taken 1 times.
✗ Branch 240 not taken.
✓ Branch 241 taken 1 times.
✓ Branch 242 taken 1 times.
✗ Branch 243 not taken.
✓ Branch 244 taken 1 times.
✓ Branch 245 taken 1 times.
✗ Branch 246 not taken.
✓ Branch 247 taken 1 times.
✓ Branch 248 taken 1 times.
✗ Branch 249 not taken.
✓ Branch 250 taken 1 times.
✓ Branch 251 taken 1 times.
✗ Branch 252 not taken.
✓ Branch 253 taken 1 times.
✓ Branch 254 taken 1 times.
✗ Branch 255 not taken.
✓ Branch 256 taken 1 times.
✓ Branch 257 taken 1 times.
✗ Branch 258 not taken.
✓ Branch 259 taken 1 times.
✓ Branch 260 taken 1 times.
✗ Branch 261 not taken.
✓ Branch 262 taken 1 times.
✓ Branch 263 taken 1 times.
✗ Branch 264 not taken.
✓ Branch 265 taken 1 times.
✓ Branch 266 taken 1 times.
✗ Branch 267 not taken.
✓ Branch 268 taken 1 times.
✓ Branch 269 taken 1 times.
✗ Branch 270 not taken.
✓ Branch 271 taken 1 times.
✗ Branch 272 not taken.
✓ Branch 274 taken 1 times.
✗ Branch 275 not taken.
✓ Branch 277 taken 1 times.
✗ Branch 278 not taken.
✓ Branch 280 taken 1 times.
✗ Branch 281 not taken.
✓ Branch 283 taken 1 times.
✗ Branch 284 not taken.
✓ Branch 286 taken 1 times.
✗ Branch 287 not taken.
✓ Branch 289 taken 1 times.
✗ Branch 290 not taken.
✓ Branch 292 taken 1 times.
✗ Branch 293 not taken.
✓ Branch 295 taken 1 times.
✗ Branch 296 not taken.
✓ Branch 298 taken 1 times.
✗ Branch 299 not taken.
✓ Branch 301 taken 1 times.
✗ Branch 302 not taken.
✓ Branch 304 taken 1 times.
✗ Branch 305 not taken.
✓ Branch 307 taken 1 times.
✗ Branch 308 not taken.
✓ Branch 310 taken 1 times.
✗ Branch 311 not taken.
✓ Branch 313 taken 1 times.
✗ Branch 314 not taken.
✓ Branch 316 taken 1 times.
✗ Branch 317 not taken.
✓ Branch 319 taken 1 times.
✗ Branch 320 not taken.
✓ Branch 322 taken 1 times.
✗ Branch 323 not taken.
✓ Branch 325 taken 1 times.
✗ Branch 326 not taken.
✓ Branch 328 taken 1 times.
✗ Branch 329 not taken.
✓ Branch 331 taken 1 times.
✗ Branch 332 not taken.
✓ Branch 334 taken 1 times.
✗ Branch 335 not taken.
✓ Branch 337 taken 1 times.
✗ Branch 338 not taken.
✓ Branch 340 taken 1 times.
✗ Branch 341 not taken.
✓ Branch 343 taken 1 times.
✗ Branch 344 not taken.
✓ Branch 346 taken 1 times.
✗ Branch 347 not taken.
✓ Branch 349 taken 1 times.
✗ Branch 350 not taken.
✓ Branch 352 taken 1 times.
✗ Branch 353 not taken.
✓ Branch 355 taken 1 times.
✗ Branch 356 not taken.
✓ Branch 358 taken 1 times.
✗ Branch 359 not taken.
✓ Branch 361 taken 1 times.
✗ Branch 362 not taken.
✓ Branch 364 taken 1 times.
✗ Branch 365 not taken.
✓ Branch 367 taken 1 times.
✗ Branch 368 not taken.
✓ Branch 370 taken 1 times.
✗ Branch 371 not taken.
✓ Branch 373 taken 1 times.
✗ Branch 374 not taken.
✓ Branch 376 taken 1 times.
✗ Branch 377 not taken.
✓ Branch 379 taken 1 times.
✗ Branch 380 not taken.
✓ Branch 382 taken 1 times.
✗ Branch 383 not taken.
✓ Branch 385 taken 1 times.
✗ Branch 386 not taken.
✓ Branch 388 taken 1 times.
✗ Branch 389 not taken.
✓ Branch 391 taken 1 times.
✗ Branch 392 not taken.
✓ Branch 394 taken 1 times.
✗ Branch 395 not taken.
✓ Branch 397 taken 1 times.
✗ Branch 398 not taken.
✓ Branch 400 taken 1 times.
✗ Branch 401 not taken.
✓ Branch 403 taken 1 times.
✗ Branch 404 not taken.
✓ Branch 406 taken 1 times.
✗ Branch 407 not taken.
✓ Branch 409 taken 1 times.
✗ Branch 410 not taken.
✓ Branch 412 taken 1 times.
✗ Branch 413 not taken.
✓ Branch 415 taken 1 times.
✗ Branch 416 not taken.
✓ Branch 418 taken 1 times.
✗ Branch 419 not taken.
✓ Branch 421 taken 1 times.
✗ Branch 422 not taken.
✓ Branch 424 taken 1 times.
✗ Branch 425 not taken.
✓ Branch 427 taken 1 times.
✗ Branch 428 not taken.
✓ Branch 430 taken 1 times.
✗ Branch 431 not taken.
✓ Branch 433 taken 1 times.
✗ Branch 434 not taken.
✓ Branch 436 taken 1 times.
✗ Branch 437 not taken.
✓ Branch 439 taken 1 times.
✗ Branch 440 not taken.
✓ Branch 442 taken 1 times.
✗ Branch 443 not taken.
✓ Branch 445 taken 1 times.
✗ Branch 446 not taken.
✓ Branch 448 taken 1 times.
✗ Branch 449 not taken.
✓ Branch 451 taken 1 times.
✗ Branch 452 not taken.
✓ Branch 454 taken 1 times.
✗ Branch 455 not taken.
✓ Branch 457 taken 1 times.
✗ Branch 458 not taken.
✓ Branch 460 taken 1 times.
✗ Branch 461 not taken.
✓ Branch 463 taken 1 times.
✗ Branch 464 not taken.
✓ Branch 466 taken 1 times.
✗ Branch 467 not taken.
✓ Branch 469 taken 1 times.
✗ Branch 470 not taken.
✓ Branch 472 taken 1 times.
✗ Branch 473 not taken.
✓ Branch 475 taken 1 times.
✗ Branch 476 not taken.
✓ Branch 478 taken 1 times.
✗ Branch 479 not taken.
✓ Branch 481 taken 1 times.
✗ Branch 482 not taken.
✓ Branch 484 taken 1 times.
✗ Branch 485 not taken.
✓ Branch 489 taken 1 times.
✗ Branch 490 not taken.
✓ Branch 492 taken 1 times.
✗ Branch 493 not taken.
✓ Branch 497 taken 1 times.
✗ Branch 498 not taken.
✓ Branch 500 taken 1 times.
✗ Branch 501 not taken.
✓ Branch 503 taken 1 times.
✗ Branch 504 not taken.
✓ Branch 506 taken 1 times.
✗ Branch 507 not taken.
✓ Branch 509 taken 1 times.
✗ Branch 510 not taken.
✓ Branch 512 taken 1 times.
✗ Branch 513 not taken.
✓ Branch 515 taken 1 times.
✗ Branch 516 not taken.
✓ Branch 518 taken 1 times.
✗ Branch 519 not taken.
✓ Branch 521 taken 1 times.
✗ Branch 522 not taken.
✓ Branch 524 taken 1 times.
✗ Branch 525 not taken.
✓ Branch 527 taken 1 times.
✗ Branch 528 not taken.
✓ Branch 530 taken 1 times.
✗ Branch 531 not taken.
✓ Branch 533 taken 1 times.
✗ Branch 534 not taken.
✓ Branch 536 taken 1 times.
✗ Branch 537 not taken.
✓ Branch 539 taken 1 times.
✗ Branch 540 not taken.
✓ Branch 542 taken 1 times.
✗ Branch 543 not taken.
✓ Branch 545 taken 1 times.
✗ Branch 546 not taken.
✓ Branch 548 taken 1 times.
✗ Branch 549 not taken.
✓ Branch 551 taken 1 times.
✗ Branch 552 not taken.
✓ Branch 554 taken 1 times.
✗ Branch 555 not taken.
✓ Branch 557 taken 1 times.
✗ Branch 558 not taken.
✓ Branch 560 taken 1 times.
✗ Branch 561 not taken.
✓ Branch 563 taken 1 times.
✗ Branch 564 not taken.
✓ Branch 566 taken 1 times.
✗ Branch 567 not taken.
✓ Branch 569 taken 1 times.
✗ Branch 570 not taken.
✓ Branch 572 taken 1 times.
✗ Branch 573 not taken.
✓ Branch 575 taken 1 times.
✗ Branch 576 not taken.
✓ Branch 578 taken 1 times.
✗ Branch 579 not taken.
✓ Branch 581 taken 1 times.
✗ Branch 582 not taken.
✓ Branch 584 taken 1 times.
✗ Branch 585 not taken.
✓ Branch 587 taken 1 times.
✗ Branch 588 not taken.
✓ Branch 590 taken 1 times.
✗ Branch 591 not taken.
✓ Branch 593 taken 1 times.
✗ Branch 594 not taken.
✓ Branch 596 taken 1 times.
✗ Branch 597 not taken.
✓ Branch 599 taken 1 times.
✗ Branch 600 not taken.
✓ Branch 602 taken 1 times.
✗ Branch 603 not taken.
✓ Branch 605 taken 1 times.
✗ Branch 606 not taken.
✓ Branch 608 taken 1 times.
✗ Branch 609 not taken.
✓ Branch 611 taken 1 times.
✗ Branch 612 not taken.
✓ Branch 614 taken 1 times.
✗ Branch 615 not taken.
✓ Branch 617 taken 1 times.
✗ Branch 618 not taken.
✓ Branch 620 taken 1 times.
✗ Branch 621 not taken.
✓ Branch 623 taken 1 times.
✗ Branch 624 not taken.
✓ Branch 626 taken 1 times.
✗ Branch 627 not taken.
✓ Branch 629 taken 1 times.
✗ Branch 630 not taken.
✓ Branch 632 taken 1 times.
✗ Branch 633 not taken.
✓ Branch 635 taken 1 times.
✗ Branch 636 not taken.
✓ Branch 638 taken 1 times.
✗ Branch 639 not taken.
✓ Branch 641 taken 1 times.
✗ Branch 642 not taken.
✓ Branch 644 taken 1 times.
✗ Branch 645 not taken.
✓ Branch 647 taken 1 times.
✗ Branch 648 not taken.
✓ Branch 650 taken 1 times.
✗ Branch 651 not taken.
511549 std::call_once(once, []()
1196 {
1197
79/163
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 3 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 2 times.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 2 times.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✓ Branch 28 taken 1 times.
✓ Branch 29 taken 1 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 2 times.
✓ Branch 33 taken 2 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 times.
✓ Branch 36 taken 2 times.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 2 times.
✓ Branch 41 taken 2 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 1 times.
✓ Branch 44 taken 2 times.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 2 times.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 51 taken 1 times.
✓ Branch 52 taken 1 times.
✓ Branch 53 taken 1 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 2 times.
✓ Branch 57 taken 2 times.
✗ Branch 58 not taken.
✓ Branch 59 taken 1 times.
✓ Branch 60 taken 2 times.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✓ Branch 65 taken 2 times.
✗ Branch 66 not taken.
✓ Branch 67 taken 2 times.
✓ Branch 68 taken 2 times.
✓ Branch 69 taken 1 times.
✗ Branch 70 not taken.
✓ Branch 72 taken 1 times.
✓ Branch 73 taken 1 times.
✓ Branch 74 taken 2 times.
✗ Branch 75 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✓ Branch 81 taken 2 times.
✗ Branch 82 not taken.
✓ Branch 84 taken 1 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 88 taken 1 times.
✓ Branch 89 taken 2 times.
✗ Branch 90 not taken.
✓ Branch 92 taken 1 times.
✓ Branch 93 taken 1 times.
✗ Branch 94 not taken.
✓ Branch 96 taken 2 times.
✓ Branch 97 taken 1 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 1 times.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✓ Branch 103 taken 1 times.
✗ Branch 104 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 2 times.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✓ Branch 119 taken 1 times.
✗ Branch 120 not taken.
✓ Branch 121 taken 1 times.
✗ Branch 122 not taken.
✓ Branch 124 taken 2 times.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✓ Branch 127 taken 1 times.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✓ Branch 132 taken 1 times.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✓ Branch 135 taken 1 times.
✗ Branch 136 not taken.
✓ Branch 137 taken 1 times.
✗ Branch 138 not taken.
✓ Branch 140 taken 2 times.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✓ Branch 143 taken 1 times.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✓ Branch 148 taken 1 times.
✓ Branch 149 taken 1 times.
✗ Branch 150 not taken.
✓ Branch 151 taken 1 times.
✓ Branch 152 taken 1 times.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✓ Branch 156 taken 1 times.
✗ Branch 157 not taken.
✓ Branch 159 taken 2 times.
✗ Branch 160 not taken.
✓ Branch 161 taken 1 times.
✗ Branch 162 not taken.
✓ Branch 164 taken 2 times.
✗ Branch 165 not taken.
✓ Branch 166 taken 1 times.
✓ Branch 167 taken 1 times.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✗ Branch 206 not taken.
✗ Branch 207 not taken.
66 sTypeName.reset(new NamePair(typeNameAsString<ValueType>(), Codec::name()));
1198 });
1199 return *sTypeName;
1200 }
1201
1202
1203 template<typename ValueType_, typename Codec_>
1204 inline bool
1205 39 TypedAttributeArray<ValueType_, Codec_>::isRegistered()
1206 {
1207 39 return AttributeArray::isRegistered(TypedAttributeArray::attributeType());
1208 }
1209
1210
1211 template<typename ValueType_, typename Codec_>
1212 inline void
1213 17485 TypedAttributeArray<ValueType_, Codec_>::registerType()
1214 {
1215 17485 AttributeArray::registerType(TypedAttributeArray::attributeType(), TypedAttributeArray::factory);
1216 17485 }
1217
1218
1219 template<typename ValueType_, typename Codec_>
1220 inline void
1221 TypedAttributeArray<ValueType_, Codec_>::unregisterType()
1222 {
1223 AttributeArray::unregisterType(TypedAttributeArray::attributeType());
1224 }
1225
1226
1227 template<typename ValueType_, typename Codec_>
1228 inline typename TypedAttributeArray<ValueType_, Codec_>::Ptr
1229 246316 TypedAttributeArray<ValueType_, Codec_>::create(Index n, Index stride, bool constantStride,
1230 const Metadata* metadata)
1231 {
1232
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 123312 times.
246316 const TypedMetadata<ValueType>* typedMetadata = metadata ?
1233 26 dynamic_cast<const TypedMetadata<ValueType>*>(metadata) : nullptr;
1234
1235
2/3
✓ Branch 1 taken 54422 times.
✓ Branch 2 taken 68903 times.
✗ Branch 3 not taken.
246316 return Ptr(new TypedAttributeArray(n, stride, constantStride,
1236
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
483338 typedMetadata ? typedMetadata->value() : zeroVal<ValueType>()));
1237 }
1238
1239 template<typename ValueType_, typename Codec_>
1240 inline TypedAttributeArray<ValueType_, Codec_>&
1241 3367 TypedAttributeArray<ValueType_, Codec_>::cast(AttributeArray& attributeArray)
1242 {
1243
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3354 times.
3367 if (!attributeArray.isType<TypedAttributeArray>()) {
1244
2/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
12 OPENVDB_THROW(TypeError, "Invalid Attribute Type");
1245 }
1246 3364 return static_cast<TypedAttributeArray&>(attributeArray);
1247 }
1248
1249 template<typename ValueType_, typename Codec_>
1250 inline const TypedAttributeArray<ValueType_, Codec_>&
1251 34662 TypedAttributeArray<ValueType_, Codec_>::cast(const AttributeArray& attributeArray)
1252 {
1253
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 34650 times.
34662 if (!attributeArray.isType<TypedAttributeArray>()) {
1254
2/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
12 OPENVDB_THROW(TypeError, "Invalid Attribute Type");
1255 }
1256 34659 return static_cast<const TypedAttributeArray&>(attributeArray);
1257 }
1258
1259 template<typename ValueType_, typename Codec_>
1260 AttributeArray::Ptr
1261 23330 TypedAttributeArray<ValueType_, Codec_>::copy() const
1262 {
1263
1/2
✓ Branch 2 taken 11665 times.
✗ Branch 3 not taken.
46660 return AttributeArray::Ptr(new TypedAttributeArray<ValueType, Codec>(*this));
1264 }
1265
1266
1267 template<typename ValueType_, typename Codec_>
1268 AttributeArray::Ptr
1269 TypedAttributeArray<ValueType_, Codec_>::copyUncompressed() const
1270 {
1271 return this->copy();
1272 }
1273
1274
1275 template<typename ValueType_, typename Codec_>
1276 size_t
1277
1/2
✓ Branch 0 taken 111582 times.
✗ Branch 1 not taken.
223164 TypedAttributeArray<ValueType_, Codec_>::arrayMemUsage() const
1278 {
1279
1/2
✓ Branch 0 taken 111582 times.
✗ Branch 1 not taken.
223164 if (this->isOutOfCore()) return 0;
1280
1281
2/2
✓ Branch 0 taken 93242 times.
✓ Branch 1 taken 18340 times.
409648 return (mIsUniform ? 1 : this->dataSize()) * sizeof(StorageType);
1282 }
1283
1284
1285 template<typename ValueType_, typename Codec_>
1286 void
1287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 121338 times.
242657 TypedAttributeArray<ValueType_, Codec_>::allocate()
1288 {
1289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 121338 times.
242657 assert(!mData);
1290
2/2
✓ Branch 0 taken 33853 times.
✓ Branch 1 taken 87485 times.
242657 if (mIsUniform) {
1291
2/2
✓ Branch 1 taken 16594 times.
✓ Branch 2 taken 16594 times.
100889 mData.reset(new StorageType[1]);
1292 }
1293 else {
1294 174956 const size_t size(this->dataSize());
1295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87485 times.
174956 assert(size > 0);
1296
2/2
✓ Branch 1 taken 24617476 times.
✓ Branch 2 taken 52998 times.
49409907 mData.reset(new StorageType[size]);
1297 }
1298 242657 }
1299
1300
1301 template<typename ValueType_, typename Codec_>
1302 void
1303
2/2
✓ Branch 0 taken 4191 times.
✓ Branch 1 taken 283313 times.
574939 TypedAttributeArray<ValueType_, Codec_>::deallocate()
1304 {
1305 // detach from file if delay-loaded
1306
2/2
✓ Branch 0 taken 4191 times.
✓ Branch 1 taken 283313 times.
574939 if (this->isOutOfCore()) {
1307 this->setOutOfCore(false);
1308 this->mPageHandle.reset();
1309 }
1310
2/2
✓ Branch 0 taken 283311 times.
✓ Branch 1 taken 4193 times.
574939 if (mData) mData.reset();
1311 574939 }
1312
1313
1314 template<typename ValueType_, typename Codec_>
1315 bool
1316 59048 TypedAttributeArray<ValueType_, Codec_>::valueTypeIsFloatingPoint() const
1317 {
1318 // TODO: Update to use Traits that correctly handle matrices and quaternions.
1319
1320 if (std::is_same<ValueType, Quats>::value ||
1321 std::is_same<ValueType, Quatd>::value ||
1322 std::is_same<ValueType, Mat3s>::value ||
1323 std::is_same<ValueType, Mat3d>::value ||
1324 std::is_same<ValueType, Mat4s>::value ||
1325 std::is_same<ValueType, Mat4d>::value) return true;
1326
1327 using ElementT = typename VecTraits<ValueType>::ElementType;
1328
1329 // half is not defined as float point as expected, so explicitly handle it
1330 return std::is_floating_point<ElementT>::value || std::is_same<math::half, ElementT>::value;
1331 }
1332
1333
1334 template<typename ValueType_, typename Codec_>
1335 bool
1336 32 TypedAttributeArray<ValueType_, Codec_>::valueTypeIsClass() const
1337 {
1338 // half is not defined as a non-class type as expected, so explicitly exclude it
1339 32 return std::is_class<ValueType>::value && !std::is_same<math::half, ValueType>::value;
1340 }
1341
1342
1343 template<typename ValueType_, typename Codec_>
1344 bool
1345 32 TypedAttributeArray<ValueType_, Codec_>::valueTypeIsVector() const
1346 {
1347 32 return VecTraits<ValueType>::IsVec;
1348 }
1349
1350
1351 template<typename ValueType_, typename Codec_>
1352 bool
1353 32 TypedAttributeArray<ValueType_, Codec_>::valueTypeIsQuaternion() const
1354 {
1355 // TODO: improve performance by making this a compile-time check using type traits
1356
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
32 return !this->valueType().compare(0, 4, "quat");
1357 }
1358
1359
1360 template<typename ValueType_, typename Codec_>
1361 bool
1362 32 TypedAttributeArray<ValueType_, Codec_>::valueTypeIsMatrix() const
1363 {
1364 // TODO: improve performance by making this a compile-time check using type traits
1365
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
32 return !this->valueType().compare(0, 3, "mat");
1366 }
1367
1368
1369 template<typename ValueType_, typename Codec_>
1370 size_t
1371
2/2
✓ Branch 0 taken 53168 times.
✓ Branch 1 taken 33376 times.
173088 TypedAttributeArray<ValueType_, Codec_>::memUsage() const
1372 {
1373
2/2
✓ Branch 0 taken 53168 times.
✓ Branch 1 taken 33376 times.
173088 return sizeof(*this) + (bool(mData) ? this->arrayMemUsage() : 0);
1374 }
1375
1376 #if OPENVDB_ABI_VERSION_NUMBER >= 10
1377 template<typename ValueType_, typename Codec_>
1378 size_t
1379 TypedAttributeArray<ValueType_, Codec_>::memUsageIfLoaded() const
1380 {
1381 return sizeof(*this) + (mIsUniform ? 1 : this->dataSize()) * sizeof(StorageType);
1382 }
1383 #endif
1384
1385
1386 template<typename ValueType_, typename Codec_>
1387 typename TypedAttributeArray<ValueType_, Codec_>::ValueType
1388
2/2
✓ Branch 0 taken 214015318 times.
✓ Branch 1 taken 2 times.
428030103 TypedAttributeArray<ValueType_, Codec_>::getUnsafe(Index n) const
1389 {
1390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 214015320 times.
428030103 assert(n < this->dataSize());
1391
1392 ValueType val;
1393
2/2
✓ Branch 1 taken 209126211 times.
✓ Branch 2 taken 4889109 times.
428030103 Codec::decode(/*in=*/this->data()[mIsUniform ? 0 : n], /*out=*/val);
1394 428030103 return val;
1395 }
1396
1397
1398 template<typename ValueType_, typename Codec_>
1399 typename TypedAttributeArray<ValueType_, Codec_>::ValueType
1400
2/2
✓ Branch 0 taken 3048385 times.
✓ Branch 1 taken 3 times.
6096483 TypedAttributeArray<ValueType_, Codec_>::get(Index n) const
1401 {
1402
4/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3048384 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6096507 if (n >= this->dataSize()) OPENVDB_THROW(IndexError, "Out-of-range access.");
1403
2/2
✓ Branch 0 taken 2903 times.
✓ Branch 1 taken 3045481 times.
6096475 if (this->isOutOfCore()) this->doLoad();
1404
1405 6096475 return this->getUnsafe(n);
1406 }
1407
1408
1409 template<typename ValueType_, typename Codec_>
1410 template<typename T>
1411 void
1412 4 TypedAttributeArray<ValueType_, Codec_>::getUnsafe(Index n, T& val) const
1413 {
1414 4 val = static_cast<T>(this->getUnsafe(n));
1415 4 }
1416
1417
1418 template<typename ValueType_, typename Codec_>
1419 template<typename T>
1420 void
1421 6 TypedAttributeArray<ValueType_, Codec_>::get(Index n, T& val) const
1422 {
1423 6 val = static_cast<T>(this->get(n));
1424 }
1425
1426
1427 template<typename ValueType_, typename Codec_>
1428 typename TypedAttributeArray<ValueType_, Codec_>::ValueType
1429 349895114 TypedAttributeArray<ValueType_, Codec_>::getUnsafe(const AttributeArray* array, const Index n)
1430 {
1431 349895114 return static_cast<const TypedAttributeArray<ValueType, Codec>*>(array)->getUnsafe(n);
1432 }
1433
1434
1435 template<typename ValueType_, typename Codec_>
1436 void
1437
2/2
✓ Branch 0 taken 108631142 times.
✓ Branch 1 taken 100 times.
217260687 TypedAttributeArray<ValueType_, Codec_>::setUnsafe(Index n, const ValueType& val)
1438 {
1439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108631242 times.
217260687 assert(n < this->dataSize());
1440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108631242 times.
217260687 assert(!this->isOutOfCore());
1441
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108631242 times.
217260687 assert(!this->isUniform());
1442
1443 // this unsafe method assumes the data is not uniform, however if it is, this redirects the index
1444 // to zero, which is marginally less efficient but ensures not writing to an illegal address
1445
1446
3/4
✓ Branch 1 taken 108631242 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 60000015 times.
✓ Branch 4 taken 3 times.
217260687 Codec::encode(/*in=*/val, /*out=*/this->data()[mIsUniform ? 0 : n]);
1447 217260687 }
1448
1449
1450 template<typename ValueType_, typename Codec_>
1451 void
1452
2/2
✓ Branch 0 taken 520725 times.
✓ Branch 1 taken 100 times.
1041537 TypedAttributeArray<ValueType_, Codec_>::set(Index n, const ValueType& val)
1453 {
1454
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 520823 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
1041549 if (n >= this->dataSize()) OPENVDB_THROW(IndexError, "Out-of-range access.");
1455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 520823 times.
1041533 if (this->isOutOfCore()) this->doLoad();
1456
2/2
✓ Branch 0 taken 3039 times.
✓ Branch 1 taken 517784 times.
1041533 if (this->isUniform()) this->expand();
1457
1458 1041533 this->setUnsafe(n, val);
1459 1041533 }
1460
1461
1462 template<typename ValueType_, typename Codec_>
1463 template<typename T>
1464 void
1465 2 TypedAttributeArray<ValueType_, Codec_>::setUnsafe(Index n, const T& val)
1466 {
1467 2 this->setUnsafe(n, static_cast<ValueType>(val));
1468 2 }
1469
1470
1471 template<typename ValueType_, typename Codec_>
1472 template<typename T>
1473 void
1474 507331 TypedAttributeArray<ValueType_, Codec_>::set(Index n, const T& val)
1475 {
1476 507331 this->set(n, static_cast<ValueType>(val));
1477 507329 }
1478
1479
1480 template<typename ValueType_, typename Codec_>
1481 void
1482 156219146 TypedAttributeArray<ValueType_, Codec_>::setUnsafe(AttributeArray* array, const Index n, const ValueType& value)
1483 {
1484 156219146 static_cast<TypedAttributeArray<ValueType, Codec>*>(array)->setUnsafe(n, value);
1485 156219146 }
1486
1487
1488 template<typename ValueType_, typename Codec_>
1489 void
1490 TypedAttributeArray<ValueType_, Codec_>::set(Index n, const AttributeArray& sourceArray, const Index sourceIndex)
1491 {
1492 const TypedAttributeArray& sourceTypedArray = static_cast<const TypedAttributeArray&>(sourceArray);
1493
1494 ValueType sourceValue;
1495 sourceTypedArray.get(sourceIndex, sourceValue);
1496
1497 this->set(n, sourceValue);
1498 }
1499
1500
1501 template<typename ValueType_, typename Codec_>
1502 void
1503 173640 TypedAttributeArray<ValueType_, Codec_>::expand(bool fill)
1504 {
1505
2/2
✓ Branch 0 taken 38742 times.
✓ Branch 1 taken 48085 times.
173640 if (!mIsUniform) return;
1506
1507 164184 const StorageType val = this->data()[0];
1508
1509 {
1510 164184 tbb::spin_mutex::scoped_lock lock(mMutex);
1511 164184 this->deallocate();
1512 164184 mIsUniform = false;
1513
1/2
✓ Branch 1 taken 82099 times.
✗ Branch 2 not taken.
164184 this->allocate();
1514 }
1515
1516
2/2
✓ Branch 0 taken 78060 times.
✓ Branch 1 taken 4039 times.
164184 if (fill) {
1517
2/2
✓ Branch 0 taken 116331551 times.
✓ Branch 1 taken 78060 times.
232819177 for (Index i = 0; i < this->dataSize(); ++i) this->data()[i] = val;
1518 }
1519 }
1520
1521
1522 template<typename ValueType_, typename Codec_>
1523 bool
1524 35136 TypedAttributeArray<ValueType_, Codec_>::compact()
1525 {
1526
2/2
✓ Branch 0 taken 17356 times.
✓ Branch 1 taken 248 times.
35136 if (mIsUniform) return true;
1527
1528 // compaction is not possible if any values are different
1529 34690 const ValueType_ val = this->get(0);
1530
2/2
✓ Branch 0 taken 1014763 times.
✓ Branch 1 taken 3330 times.
4037614 for (Index i = 1; i < this->dataSize(); i++) {
1531
2/2
✓ Branch 1 taken 1000730 times.
✓ Branch 2 taken 14016 times.
2029538 if (!math::isExactlyEqual(this->get(i), val)) return false;
1532 }
1533
1534 6655 this->collapse(this->get(0));
1535 6655 return true;
1536 }
1537
1538
1539 template<typename ValueType_, typename Codec_>
1540 void
1541 39656 TypedAttributeArray<ValueType_, Codec_>::collapse()
1542 {
1543 39656 this->collapse(zeroVal<ValueType>());
1544 }
1545
1546
1547 template<typename ValueType_, typename Codec_>
1548 void
1549 69975 TypedAttributeArray<ValueType_, Codec_>::collapse(const ValueType& uniformValue)
1550 {
1551
2/2
✓ Branch 0 taken 33825 times.
✓ Branch 1 taken 1190 times.
69975 if (!mIsUniform) {
1552 67645 tbb::spin_mutex::scoped_lock lock(mMutex);
1553 67645 this->deallocate();
1554 67645 mIsUniform = true;
1555
1/2
✓ Branch 1 taken 33825 times.
✗ Branch 2 not taken.
67645 this->allocate();
1556 }
1557 69975 Codec::encode(uniformValue, this->data()[0]);
1558 69975 }
1559
1560
1561 template<typename ValueType_, typename Codec_>
1562 void
1563 23410 TypedAttributeArray<ValueType_, Codec_>::collapse(AttributeArray* array, const ValueType& value)
1564 {
1565 23410 static_cast<TypedAttributeArray<ValueType, Codec>*>(array)->collapse(value);
1566 23410 }
1567
1568
1569 template<typename ValueType_, typename Codec_>
1570 void
1571
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
20 TypedAttributeArray<ValueType_, Codec_>::fill(const ValueType& value)
1572 {
1573
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
20 if (this->isOutOfCore()) {
1574 4 tbb::spin_mutex::scoped_lock lock(mMutex);
1575 4 this->deallocate();
1576
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 this->allocate();
1577 }
1578
1579
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
20 const Index size = mIsUniform ? 1 : this->dataSize();
1580
2/2
✓ Branch 0 taken 616 times.
✓ Branch 1 taken 10 times.
1252 for (Index i = 0; i < size; ++i) {
1581
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
1232 Codec::encode(value, this->data()[i]);
1582 }
1583 }
1584
1585
1586 template<typename ValueType_, typename Codec_>
1587 void
1588 6 TypedAttributeArray<ValueType_, Codec_>::fill(AttributeArray* array, const ValueType& value)
1589 {
1590 6 static_cast<TypedAttributeArray<ValueType, Codec>*>(array)->fill(value);
1591 }
1592
1593
1594 template<typename ValueType_, typename Codec_>
1595 inline bool
1596 TypedAttributeArray<ValueType_, Codec_>::compress()
1597 {
1598 return false;
1599 }
1600
1601
1602 template<typename ValueType_, typename Codec_>
1603 inline bool
1604 TypedAttributeArray<ValueType_, Codec_>::compressUnsafe()
1605 {
1606 return false;
1607 }
1608
1609
1610 template<typename ValueType_, typename Codec_>
1611 inline bool
1612 TypedAttributeArray<ValueType_, Codec_>::decompress()
1613 {
1614 return false;
1615 }
1616
1617
1618 template<typename ValueType_, typename Codec_>
1619 bool
1620 TypedAttributeArray<ValueType_, Codec_>::isOutOfCore() const
1621 {
1622
27/54
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 1 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 1 times.
✗ Branch 40 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 47 taken 1 times.
✗ Branch 48 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 51 taken 1 times.
✗ Branch 52 not taken.
✓ Branch 53 taken 1 times.
32 return mOutOfCore;
1623 }
1624
1625
1626 template<typename ValueType_, typename Codec_>
1627 void
1628 TypedAttributeArray<ValueType_, Codec_>::setOutOfCore(const bool b)
1629 {
1630 36455 mOutOfCore = b;
1631 }
1632
1633
1634 template<typename ValueType_, typename Codec_>
1635 void
1636
2/2
✓ Branch 0 taken 265296 times.
✓ Branch 1 taken 38528 times.
607501 TypedAttributeArray<ValueType_, Codec_>::doLoad() const
1637 {
1638
2/2
✓ Branch 0 taken 265296 times.
✓ Branch 1 taken 38528 times.
607501 if (!(this->isOutOfCore())) return;
1639
1640 TypedAttributeArray<ValueType_, Codec_>* self =
1641 const_cast<TypedAttributeArray<ValueType_, Codec_>*>(this);
1642
1643 // This lock will be contended at most once, after which this buffer
1644 // will no longer be out-of-core.
1645 77056 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1646
1/2
✓ Branch 1 taken 38528 times.
✗ Branch 2 not taken.
77056 this->doLoadUnsafe();
1647 }
1648
1649
1650 template<typename ValueType_, typename Codec_>
1651 void
1652 495587 TypedAttributeArray<ValueType_, Codec_>::loadData() const
1653 {
1654 495587 this->doLoad();
1655 495587 }
1656
1657
1658 template<typename ValueType_, typename Codec_>
1659 bool
1660 78006 TypedAttributeArray<ValueType_, Codec_>::isDataLoaded() const
1661 {
1662 78006 return !this->isOutOfCore();
1663 }
1664
1665
1666 template<typename ValueType_, typename Codec_>
1667 void
1668 8 TypedAttributeArray<ValueType_, Codec_>::read(std::istream& is)
1669 {
1670 8 this->readMetadata(is);
1671 8 this->readBuffers(is);
1672 }
1673
1674
1675 template<typename ValueType_, typename Codec_>
1676 void
1677 72930 TypedAttributeArray<ValueType_, Codec_>::readMetadata(std::istream& is)
1678 {
1679 // read data
1680
1681 72930 Index64 bytes = Index64(0);
1682 72930 is.read(reinterpret_cast<char*>(&bytes), sizeof(Index64));
1683 72930 bytes = bytes - /*flags*/sizeof(Int16) - /*size*/sizeof(Index);
1684
1685 72930 uint8_t flags = uint8_t(0);
1686 72930 is.read(reinterpret_cast<char*>(&flags), sizeof(uint8_t));
1687 72930 mFlags = flags;
1688
1689 72930 uint8_t serializationFlags = uint8_t(0);
1690 72930 is.read(reinterpret_cast<char*>(&serializationFlags), sizeof(uint8_t));
1691
1692 72930 Index size = Index(0);
1693 72930 is.read(reinterpret_cast<char*>(&size), sizeof(Index));
1694 72930 mSize = size;
1695
1696 // warn if an unknown flag has been set
1697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36465 times.
72930 if (mFlags >= 0x20) {
1698 OPENVDB_LOG_WARN("Unknown attribute flags for VDB file format.");
1699 }
1700 // error if an unknown serialization flag has been set,
1701 // as this will adjust the layout of the data and corrupt the ability to read
1702
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 36464 times.
72930 if (serializationFlags >= 0x10) {
1703
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
8 OPENVDB_THROW(IoError, "Unknown attribute serialization flags for VDB file format.");
1704 }
1705
1706 // set uniform, compressed and page read state
1707
1708 72928 mIsUniform = serializationFlags & WRITEUNIFORM;
1709 72928 mUsePagedRead = serializationFlags & WRITEPAGED;
1710 72928 mCompressedBytes = bytes;
1711 72928 mFlags |= PARTIALREAD; // mark data as having been partially read
1712
1713 // read strided value (set to 1 if array is not strided)
1714
1715
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 36462 times.
72928 if (serializationFlags & WRITESTRIDED) {
1716 4 Index stride = Index(0);
1717 4 is.read(reinterpret_cast<char*>(&stride), sizeof(Index));
1718 4 mStrideOrTotalSize = stride;
1719 }
1720 else {
1721 72924 mStrideOrTotalSize = 1;
1722 }
1723 }
1724
1725
1726 template<typename ValueType_, typename Codec_>
1727 void
1728 18 TypedAttributeArray<ValueType_, Codec_>::readBuffers(std::istream& is)
1729 {
1730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
18 if (mUsePagedRead) {
1731 // use readBuffers(PagedInputStream&) for paged buffers
1732 OPENVDB_THROW(IoError, "Cannot read paged AttributeArray buffers.");
1733 }
1734
1735 18 tbb::spin_mutex::scoped_lock lock(mMutex);
1736
1737 18 this->deallocate();
1738
1739 18 uint8_t bloscCompressed(0);
1740
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
18 if (!mIsUniform) is.read(reinterpret_cast<char*>(&bloscCompressed), sizeof(uint8_t));
1741
1742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
18 assert(mFlags & PARTIALREAD);
1743
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
18 std::unique_ptr<char[]> buffer(new char[mCompressedBytes]);
1744
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
18 is.read(buffer.get(), mCompressedBytes);
1745 18 mCompressedBytes = 0;
1746 18 mFlags = static_cast<uint8_t>(mFlags & ~PARTIALREAD); // mark data read as having completed
1747
1748 // compressed on-disk
1749
1750
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
18 if (bloscCompressed == uint8_t(1)) {
1751
1752 // decompress buffer
1753
1754 4 const size_t inBytes = this->dataSize() * sizeof(StorageType);
1755
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 std::unique_ptr<char[]> newBuffer = compression::bloscDecompress(buffer.get(), inBytes);
1756
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 if (newBuffer) buffer.reset(newBuffer.release());
1757 }
1758
1759 // set data to buffer
1760
1761 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1762 }
1763
1764
1765 template<typename ValueType_, typename Codec_>
1766 void
1767 145820 TypedAttributeArray<ValueType_, Codec_>::readPagedBuffers(compression::PagedInputStream& is)
1768 {
1769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72910 times.
145820 if (!mUsePagedRead) {
1770 if (!is.sizeOnly()) this->readBuffers(is.getInputStream());
1771 72910 return;
1772 }
1773
1774 // If this array is being read from a memory-mapped file, delay loading of its data
1775 // until the data is actually accessed.
1776 145820 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is.getInputStream());
1777
2/2
✓ Branch 0 taken 36455 times.
✓ Branch 1 taken 36455 times.
145820 const bool delayLoad = (mappedFile.get() != nullptr);
1778
1779
2/2
✓ Branch 0 taken 36455 times.
✓ Branch 1 taken 36455 times.
145820 if (is.sizeOnly())
1780 {
1781 72910 size_t compressedBytes(mCompressedBytes);
1782 72910 mCompressedBytes = 0; // if not set to zero, mPageHandle will attempt to destroy invalid memory
1783 72910 mFlags = static_cast<uint8_t>(mFlags & ~PARTIALREAD); // mark data read as having completed
1784 assert(!mPageHandle);
1785
3/4
✓ Branch 1 taken 36455 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36453 times.
✓ Branch 4 taken 2 times.
145820 mPageHandle = is.createHandle(compressedBytes);
1786 return;
1787 }
1788
1789
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36455 times.
72910 assert(mPageHandle);
1790
1791 72910 tbb::spin_mutex::scoped_lock lock(mMutex);
1792
1793 72910 this->deallocate();
1794
1795
1/2
✓ Branch 1 taken 36455 times.
✗ Branch 2 not taken.
72910 this->setOutOfCore(delayLoad);
1796
1/2
✓ Branch 1 taken 36455 times.
✗ Branch 2 not taken.
72910 is.read(mPageHandle, std::streamsize(mPageHandle->size()), delayLoad);
1797
1798
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 36453 times.
72910 if (!delayLoad) {
1799
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 std::unique_ptr<char[]> buffer = mPageHandle->read();
1800 mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1801 mPageHandle.reset();
1802 }
1803
1804 // clear page state
1805
1806
1/2
✓ Branch 0 taken 36455 times.
✗ Branch 1 not taken.
72910 mUsePagedRead = 0;
1807 }
1808
1809
1810 template<typename ValueType_, typename Codec_>
1811 void
1812 10 TypedAttributeArray<ValueType_, Codec_>::write(std::ostream& os) const
1813 {
1814 10 this->write(os, /*outputTransient=*/false);
1815 }
1816
1817
1818 template<typename ValueType_, typename Codec_>
1819 void
1820 12 TypedAttributeArray<ValueType_, Codec_>::write(std::ostream& os, bool outputTransient) const
1821 {
1822 12 this->writeMetadata(os, outputTransient, /*paged=*/false);
1823 12 this->writeBuffers(os, outputTransient);
1824 }
1825
1826
1827 template<typename ValueType_, typename Codec_>
1828 void
1829 35350 TypedAttributeArray<ValueType_, Codec_>::writeMetadata(std::ostream& os, bool outputTransient, bool paged) const
1830 {
1831
4/4
✓ Branch 0 taken 17672 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 17670 times.
35350 if (!outputTransient && this->isTransient()) return;
1832
1833
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17672 times.
35346 if (mFlags & PARTIALREAD) {
1834
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
8 OPENVDB_THROW(IoError, "Cannot write out a partially-read AttributeArray.");
1835 }
1836
1837 35344 uint8_t flags(mFlags);
1838 35344 uint8_t serializationFlags(0);
1839 35344 Index size(mSize);
1840
2/2
✓ Branch 0 taken 17671 times.
✓ Branch 1 taken 1 times.
35344 Index stride(mStrideOrTotalSize);
1841 bool strideOfOne(this->stride() == 1);
1842
1843 35344 bool bloscCompression = io::getDataCompression(os) & io::COMPRESS_BLOSC;
1844
1845 // any compressed data needs to be loaded if out-of-core
1846
2/2
✓ Branch 0 taken 17664 times.
✓ Branch 1 taken 8 times.
35344 if (bloscCompression) this->doLoad();
1847
1848 size_t compressedBytes = 0;
1849
1850
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17669 times.
35344 if (!strideOfOne)
1851 {
1852 6 serializationFlags |= WRITESTRIDED;
1853 }
1854
1855
2/2
✓ Branch 0 taken 3011 times.
✓ Branch 1 taken 14661 times.
35344 if (mIsUniform)
1856 {
1857 6022 serializationFlags |= WRITEUNIFORM;
1858
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3007 times.
6022 if (bloscCompression && paged) serializationFlags |= WRITEPAGED;
1859 }
1860
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14657 times.
29322 else if (bloscCompression)
1861 {
1862
2/2
✓ Branch 0 taken 14655 times.
✓ Branch 1 taken 2 times.
29314 if (paged) serializationFlags |= WRITEPAGED;
1863 else {
1864 4 const char* charBuffer = reinterpret_cast<const char*>(this->data());
1865 4 const size_t inBytes = this->arrayMemUsage();
1866 4 compressedBytes = compression::bloscCompressedSize(charBuffer, inBytes);
1867 }
1868 }
1869
1870 35340 Index64 bytes = /*flags*/ sizeof(Int16) + /*size*/ sizeof(Index);
1871
1872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
35344 bytes += (compressedBytes > 0) ? compressedBytes : this->arrayMemUsage();
1873
1874 // write data
1875
1876 35344 os.write(reinterpret_cast<const char*>(&bytes), sizeof(Index64));
1877 35344 os.write(reinterpret_cast<const char*>(&flags), sizeof(uint8_t));
1878 35344 os.write(reinterpret_cast<const char*>(&serializationFlags), sizeof(uint8_t));
1879 35344 os.write(reinterpret_cast<const char*>(&size), sizeof(Index));
1880
1881 // write strided
1882
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17669 times.
35344 if (!strideOfOne) os.write(reinterpret_cast<const char*>(&stride), sizeof(Index));
1883 }
1884
1885
1886 template<typename ValueType_, typename Codec_>
1887 void
1888 24 TypedAttributeArray<ValueType_, Codec_>::writeBuffers(std::ostream& os, bool outputTransient) const
1889 {
1890
4/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 2 times.
24 if (!outputTransient && this->isTransient()) return;
1891
1892
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
20 if (mFlags & PARTIALREAD) {
1893 OPENVDB_THROW(IoError, "Cannot write out a partially-read AttributeArray.");
1894 }
1895
1896 20 this->doLoad();
1897
1898
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
20 if (this->isUniform()) {
1899 8 os.write(reinterpret_cast<const char*>(this->data()), sizeof(StorageType));
1900 }
1901
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
12 else if (io::getDataCompression(os) & io::COMPRESS_BLOSC)
1902 {
1903 4 std::unique_ptr<char[]> compressedBuffer;
1904 4 size_t compressedBytes = 0;
1905 4 const char* charBuffer = reinterpret_cast<const char*>(this->data());
1906 4 const size_t inBytes = this->arrayMemUsage();
1907
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 compressedBuffer = compression::bloscCompress(charBuffer, inBytes, compressedBytes);
1908
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 if (compressedBuffer) {
1909 4 uint8_t bloscCompressed(1);
1910
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 os.write(reinterpret_cast<const char*>(&bloscCompressed), sizeof(uint8_t));
1911
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 os.write(reinterpret_cast<const char*>(compressedBuffer.get()), compressedBytes);
1912 }
1913 else {
1914 uint8_t bloscCompressed(0);
1915 os.write(reinterpret_cast<const char*>(&bloscCompressed), sizeof(uint8_t));
1916 os.write(reinterpret_cast<const char*>(this->data()), inBytes);
1917 }
1918 }
1919 else
1920 {
1921 8 uint8_t bloscCompressed(0);
1922 8 os.write(reinterpret_cast<const char*>(&bloscCompressed), sizeof(uint8_t));
1923 8 os.write(reinterpret_cast<const char*>(this->data()), this->arrayMemUsage());
1924 }
1925 }
1926
1927
1928 template<typename ValueType_, typename Codec_>
1929 void
1930 70648 TypedAttributeArray<ValueType_, Codec_>::writePagedBuffers(compression::PagedOutputStream& os, bool outputTransient) const
1931 {
1932
2/4
✓ Branch 0 taken 35324 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35324 times.
✗ Branch 3 not taken.
70648 if (!outputTransient && this->isTransient()) return;
1933
1934 // paged compression only available when Blosc is enabled
1935 70648 bool bloscCompression = io::getDataCompression(os.getOutputStream()) & io::COMPRESS_BLOSC;
1936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35324 times.
70648 if (!bloscCompression) {
1937 if (!os.sizeOnly()) this->writeBuffers(os.getOutputStream(), outputTransient);
1938 return;
1939 }
1940
1941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35324 times.
70648 if (mFlags & PARTIALREAD) {
1942 OPENVDB_THROW(IoError, "Cannot write out a partially-read AttributeArray.");
1943 }
1944
1945 70648 this->doLoad();
1946
1947 70648 os.write(reinterpret_cast<const char*>(this->data()), this->arrayMemUsage());
1948 }
1949
1950
1951 template<typename ValueType_, typename Codec_>
1952 void
1953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38528 times.
77056 TypedAttributeArray<ValueType_, Codec_>::doLoadUnsafe(const bool /*compression*/) const
1954 {
1955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38528 times.
77056 if (!(this->isOutOfCore())) return;
1956
1957 // this function expects the mutex to already be locked
1958
1959 auto* self = const_cast<TypedAttributeArray<ValueType_, Codec_>*>(this);
1960
1961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38528 times.
77056 assert(self->mPageHandle);
1962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38528 times.
77056 assert(!(self->mFlags & PARTIALREAD));
1963
1964 77056 std::unique_ptr<char[]> buffer = self->mPageHandle->read();
1965
1966 self->mData.reset(reinterpret_cast<StorageType*>(buffer.release()));
1967
1968 self->mPageHandle.reset();
1969
1970 // clear all write and out-of-core flags
1971
1972 self->mOutOfCore = false;
1973 }
1974
1975
1976 template<typename ValueType_, typename Codec_>
1977 AttributeArray::AccessorBasePtr
1978 371960 TypedAttributeArray<ValueType_, Codec_>::getAccessor() const
1979 {
1980 // use the faster 'unsafe' get and set methods as attribute handles
1981 // ensure data is in-core when constructed
1982
1983 371960 return AccessorBasePtr(new AttributeArray::Accessor<ValueType_>(
1984 &TypedAttributeArray<ValueType_, Codec_>::getUnsafe,
1985 &TypedAttributeArray<ValueType_, Codec_>::setUnsafe,
1986 &TypedAttributeArray<ValueType_, Codec_>::collapse,
1987 371960 &TypedAttributeArray<ValueType_, Codec_>::fill));
1988 }
1989
1990
1991 template<typename ValueType_, typename Codec_>
1992 bool
1993 58 TypedAttributeArray<ValueType_, Codec_>::isEqual(const AttributeArray& other) const
1994 {
1995 58 const TypedAttributeArray<ValueType_, Codec_>* const otherT = dynamic_cast<const TypedAttributeArray<ValueType_, Codec_>* >(&other);
1996
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 1 times.
58 if(!otherT) return false;
1997 56 if(this->mSize != otherT->mSize ||
1998 56 this->mStrideOrTotalSize != otherT->mStrideOrTotalSize ||
1999
3/6
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
112 this->mIsUniform != otherT->mIsUniform ||
2000 this->attributeType() != this->attributeType()) return false;
2001
2002 56 this->doLoad();
2003 56 otherT->doLoad();
2004
2005 56 const StorageType *target = this->data(), *source = otherT->data();
2006
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
56 if (!target && !source) return true;
2007
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
56 if (!target || !source) return false;
2008
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 20 times.
56 Index n = this->mIsUniform ? 1 : mSize;
2009
6/6
✓ Branch 0 taken 726 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 59 times.
✓ Branch 3 taken 667 times.
✓ Branch 4 taken 726 times.
✓ Branch 5 taken 28 times.
1528 while (n && math::isExactlyEqual(*target++, *source++)) --n;
2010 56 return n == 0;
2011 }
2012
2013
2014 template<typename ValueType_, typename Codec_>
2015 char*
2016 29506 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray()
2017 {
2018 29506 return reinterpret_cast<char*>(this->data());
2019 }
2020
2021
2022 template<typename ValueType_, typename Codec_>
2023 const char*
2024 39075 TypedAttributeArray<ValueType_, Codec_>::dataAsByteArray() const
2025 {
2026 39075 return reinterpret_cast<const char*>(this->data());
2027 }
2028
2029
2030 ////////////////////////////////////////
2031
2032
2033 /// Accessor to call unsafe get and set methods based on templated Codec and Value
2034 template <typename CodecType, typename ValueType>
2035 struct AccessorEval
2036 {
2037 using GetterPtr = ValueType (*)(const AttributeArray* array, const Index n);
2038 using SetterPtr = void (*)(AttributeArray* array, const Index n, const ValueType& value);
2039
2040 /// Getter that calls to TypedAttributeArray::getUnsafe()
2041 /// @note Functor argument is provided but not required for the generic case
2042 static ValueType get(GetterPtr /*functor*/, const AttributeArray* array, const Index n) {
2043 return TypedAttributeArray<ValueType, CodecType>::getUnsafe(array, n);
2044 }
2045
2046 /// Getter that calls to TypedAttributeArray::setUnsafe()
2047 /// @note Functor argument is provided but not required for the generic case
2048 static void set(SetterPtr /*functor*/, AttributeArray* array, const Index n, const ValueType& value) {
2049 TypedAttributeArray<ValueType, CodecType>::setUnsafe(array, n, value);
2050 }
2051 };
2052
2053
2054 /// Partial specialization when Codec is not known at compile-time to use the supplied functor instead
2055 template <typename ValueType>
2056 struct AccessorEval<UnknownCodec, ValueType>
2057 {
2058 using GetterPtr = ValueType (*)(const AttributeArray* array, const Index n);
2059 using SetterPtr = void (*)(AttributeArray* array, const Index n, const ValueType& value);
2060
2061 /// Getter that calls the supplied functor
2062 static ValueType get(GetterPtr functor, const AttributeArray* array, const Index n) {
2063 return (*functor)(array, n);
2064 }
2065
2066 /// Setter that calls the supplied functor
2067 static void set(SetterPtr functor, AttributeArray* array, const Index n, const ValueType& value) {
2068 (*functor)(array, n, value);
2069 }
2070 };
2071
2072
2073 ////////////////////////////////////////
2074
2075 // AttributeHandle implementation
2076
2077 template <typename ValueType, typename CodecType>
2078 typename AttributeHandle<ValueType, CodecType>::Ptr
2079 82693 AttributeHandle<ValueType, CodecType>::create(const AttributeArray& array, const bool collapseOnDestruction)
2080 {
2081 return typename AttributeHandle<ValueType, CodecType>::Ptr(
2082
1/2
✓ Branch 2 taken 73825 times.
✗ Branch 3 not taken.
165386 new AttributeHandle<ValueType, CodecType>(array, collapseOnDestruction));
2083 }
2084
2085 template <typename ValueType, typename CodecType>
2086 359328 AttributeHandle<ValueType, CodecType>::AttributeHandle(const AttributeArray& array, const bool collapseOnDestruction)
2087 : mArray(&array)
2088
1/2
✓ Branch 1 taken 185981 times.
✗ Branch 2 not taken.
359321 , mStrideOrTotalSize(array.hasConstantStride() ? array.stride() : 1)
2089
2/4
✓ Branch 1 taken 185981 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
359328 , mSize(array.hasConstantStride() ? array.size() : array.dataSize())
2090
8/8
✓ Branch 0 taken 185981 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 185981 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 115833 times.
✓ Branch 5 taken 70152 times.
✓ Branch 6 taken 99144 times.
✓ Branch 7 taken 16689 times.
1077977 , mCollapseOnDestruction(collapseOnDestruction && array.isStreaming())
2091 {
2092
3/4
✓ Branch 1 taken 185985 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 185981 times.
359328 if (!this->compatibleType<std::is_same<CodecType, UnknownCodec>::value>()) {
2093
2/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
28 OPENVDB_THROW(TypeError, "Cannot bind handle due to incompatible type of AttributeArray.");
2094 }
2095
2096 // load data if delay-loaded
2097
2098
1/2
✓ Branch 1 taken 185981 times.
✗ Branch 2 not taken.
359321 mArray->loadData();
2099
2100 // bind getter and setter methods
2101
2102
1/2
✓ Branch 1 taken 185981 times.
✗ Branch 2 not taken.
359321 AttributeArray::AccessorBasePtr accessor = mArray->getAccessor();
2103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 185981 times.
359321 assert(accessor);
2104
2105 AttributeArray::Accessor<ValueType>* typedAccessor = static_cast<AttributeArray::Accessor<ValueType>*>(accessor.get());
2106
2107 359321 mGetter = typedAccessor->mGetter;
2108 359321 mSetter = typedAccessor->mSetter;
2109 359321 mCollapser = typedAccessor->mCollapser;
2110
1/2
✓ Branch 0 taken 185981 times.
✗ Branch 1 not taken.
359321 mFiller = typedAccessor->mFiller;
2111 359321 }
2112
2113 template <typename ValueType, typename CodecType>
2114 576798 AttributeHandle<ValueType, CodecType>::~AttributeHandle()
2115 {
2116 // if enabled, attribute is collapsed on destruction of the handle to save memory
2117 33378 if (mCollapseOnDestruction) const_cast<AttributeArray*>(this->mArray)->collapse();
2118 }
2119
2120 template <typename ValueType, typename CodecType>
2121 template <bool IsUnknownCodec>
2122 typename std::enable_if<IsUnknownCodec, bool>::type
2123 259334 AttributeHandle<ValueType, CodecType>::compatibleType() const
2124 {
2125 // if codec is unknown, just check the value type
2126
2127 259334 return mArray->hasValueType<ValueType>();
2128 }
2129
2130 template <typename ValueType, typename CodecType>
2131 template <bool IsUnknownCodec>
2132 typename std::enable_if<!IsUnknownCodec, bool>::type
2133 56003 AttributeHandle<ValueType, CodecType>::compatibleType() const
2134 {
2135 // if the codec is known, check the value type and codec
2136
2137 56003 return mArray->isType<TypedAttributeArray<ValueType, CodecType>>();
2138 }
2139
2140 template <typename ValueType, typename CodecType>
2141 226 const AttributeArray& AttributeHandle<ValueType, CodecType>::array() const
2142 {
2143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 226 times.
226 assert(mArray);
2144 226 return *mArray;
2145 }
2146
2147 template <typename ValueType, typename CodecType>
2148 503615662 Index AttributeHandle<ValueType, CodecType>::index(Index n, Index m) const
2149 {
2150 503615662 Index index = n * mStrideOrTotalSize + m;
2151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 253058087 times.
503615662 assert(index < (mSize * mStrideOrTotalSize));
2152 503615662 return index;
2153 }
2154
2155 template <typename ValueType, typename CodecType>
2156 348394999 ValueType AttributeHandle<ValueType, CodecType>::get(Index n, Index m) const
2157 {
2158 348394999 return this->get<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m));
2159 }
2160
2161 template <typename ValueType, typename CodecType>
2162 template <bool IsUnknownCodec>
2163 typename std::enable_if<IsUnknownCodec, ValueType>::type
2164 286848663 AttributeHandle<ValueType, CodecType>::get(Index index) const
2165 {
2166 // if the codec is unknown, use the getter functor
2167
2168 286848663 return (*mGetter)(mArray, index);
2169 }
2170
2171 template <typename ValueType, typename CodecType>
2172 template <bool IsUnknownCodec>
2173 typename std::enable_if<!IsUnknownCodec, ValueType>::type
2174 61523333 AttributeHandle<ValueType, CodecType>::get(Index index) const
2175 {
2176 // if the codec is known, call the method on the attribute array directly
2177
2178 61523333 return TypedAttributeArray<ValueType, CodecType>::getUnsafe(mArray, index);
2179 }
2180
2181 template <typename ValueType, typename CodecType>
2182 29017 bool AttributeHandle<ValueType, CodecType>::isUniform() const
2183 {
2184 29017 return mArray->isUniform();
2185 }
2186
2187 template <typename ValueType, typename CodecType>
2188 5 bool AttributeHandle<ValueType, CodecType>::hasConstantStride() const
2189 {
2190 5 return mArray->hasConstantStride();
2191 }
2192
2193 ////////////////////////////////////////
2194
2195 // AttributeWriteHandle implementation
2196
2197 template <typename ValueType, typename CodecType>
2198 typename AttributeWriteHandle<ValueType, CodecType>::Ptr
2199 66863 AttributeWriteHandle<ValueType, CodecType>::create(AttributeArray& array, const bool expand)
2200 {
2201 return typename AttributeWriteHandle<ValueType, CodecType>::Ptr(
2202
1/2
✓ Branch 2 taken 34006 times.
✗ Branch 3 not taken.
133726 new AttributeWriteHandle<ValueType, CodecType>(array, expand));
2203 }
2204
2205 template <typename ValueType, typename CodecType>
2206 128944 AttributeWriteHandle<ValueType, CodecType>::AttributeWriteHandle(AttributeArray& array, const bool expand)
2207 128944 : AttributeHandle<ValueType, CodecType>(array, /*collapseOnDestruction=*/false)
2208 {
2209
3/4
✓ Branch 0 taken 62704 times.
✓ Branch 1 taken 4039 times.
✓ Branch 3 taken 62704 times.
✗ Branch 4 not taken.
128944 if (expand) array.expand();
2210 128944 }
2211
2212 template <typename ValueType, typename CodecType>
2213 149898327 void AttributeWriteHandle<ValueType, CodecType>::set(Index n, const ValueType& value)
2214 {
2215 149898327 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, 0), value);
2216 149898325 }
2217
2218 template <typename ValueType, typename CodecType>
2219 4160756 void AttributeWriteHandle<ValueType, CodecType>::set(Index n, Index m, const ValueType& value)
2220 {
2221 4160756 this->set<std::is_same<CodecType, UnknownCodec>::value>(this->index(n, m), value);
2222 4160756 }
2223
2224 template <typename ValueType, typename CodecType>
2225 4176 void AttributeWriteHandle<ValueType, CodecType>::expand(const bool fill)
2226 {
2227 4176 const_cast<AttributeArray*>(this->mArray)->expand(fill);
2228 4176 }
2229
2230 template <typename ValueType, typename CodecType>
2231 2 void AttributeWriteHandle<ValueType, CodecType>::collapse()
2232 {
2233 2 const_cast<AttributeArray*>(this->mArray)->collapse();
2234 2 }
2235
2236 template <typename ValueType, typename CodecType>
2237 17281 bool AttributeWriteHandle<ValueType, CodecType>::compact()
2238 {
2239 17281 return const_cast<AttributeArray*>(this->mArray)->compact();
2240 }
2241
2242 template <typename ValueType, typename CodecType>
2243 23207 void AttributeWriteHandle<ValueType, CodecType>::collapse(const ValueType& uniformValue)
2244 {
2245 23207 this->mCollapser(const_cast<AttributeArray*>(this->mArray), uniformValue);
2246 23207 }
2247
2248 template <typename ValueType, typename CodecType>
2249 3 void AttributeWriteHandle<ValueType, CodecType>::fill(const ValueType& value)
2250 {
2251 3 this->mFiller(const_cast<AttributeArray*>(this->mArray), value);
2252 3 }
2253
2254 template <typename ValueType, typename CodecType>
2255 template <bool IsUnknownCodec>
2256 typename std::enable_if<IsUnknownCodec, void>::type
2257 79132037 AttributeWriteHandle<ValueType, CodecType>::set(Index index, const ValueType& value) const
2258 {
2259 // if the codec is unknown, use the setter functor
2260
2261 79132037 (*this->mSetter)(const_cast<AttributeArray*>(this->mArray), index, value);
2262 79132035 }
2263
2264 template <typename ValueType, typename CodecType>
2265 template <bool IsUnknownCodec>
2266 typename std::enable_if<!IsUnknownCodec, void>::type
2267 68544372 AttributeWriteHandle<ValueType, CodecType>::set(Index index, const ValueType& value) const
2268 {
2269 // if the codec is known, call the method on the attribute array directly
2270
2271 68544372 TypedAttributeArray<ValueType, CodecType>::setUnsafe(const_cast<AttributeArray*>(this->mArray), index, value);
2272 68544372 }
2273
2274 template <typename ValueType, typename CodecType>
2275 211 AttributeArray& AttributeWriteHandle<ValueType, CodecType>::array()
2276 {
2277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 211 times.
211 assert(this->mArray);
2278 211 return *const_cast<AttributeArray*>(this->mArray);
2279 }
2280
2281
2282 } // namespace points
2283 } // namespace OPENVDB_VERSION_NAME
2284 } // namespace openvdb
2285
2286 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
2287