4 #ifndef OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED 5 #define OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED 11 #include <tbb/spin_mutex.h> 17 #include <type_traits> 30 template<
typename T, Index Log2Dim>
37 static const Index SIZE = 1 << 3 * Log2Dim;
39 #ifdef OPENVDB_USE_DELAYED_LOADING 42 FileInfo(): bufpos(0) , maskpos(0) {}
43 std::streamoff bufpos;
44 std::streamoff maskpos;
45 io::MappedFile::Ptr mapping;
53 #ifdef OPENVDB_USE_DELAYED_LOADING 64 #ifdef OPENVDB_USE_DELAYED_LOADING 74 #ifdef OPENVDB_USE_DELAYED_LOADING 75 return bool(mOutOfCore);
81 bool empty()
const {
return !mData || this->isOutOfCore(); }
136 inline void setOutOfCore(
bool b)
139 #ifdef OPENVDB_USE_DELAYED_LOADING 145 inline void loadValues()
const 147 #ifdef OPENVDB_USE_DELAYED_LOADING 148 if (this->isOutOfCore()) this->doLoad();
151 inline void doLoad()
const;
152 inline bool detachFromFile();
154 using FlagsType = std::atomic<Index32>;
156 #ifdef OPENVDB_USE_DELAYED_LOADING 164 FlagsType mOutOfCore;
165 tbb::spin_mutex mMutex;
168 friend class ::TestLeaf;
177 template<
typename T, Index Log2Dim>
182 #ifdef OPENVDB_USE_DELAYED_LOADING 189 template<
typename T, Index Log2Dim>
193 #ifdef OPENVDB_USE_DELAYED_LOADING 195 this->detachFromFile();
205 template<
typename T, Index Log2Dim>
210 , mOutOfCore(other.mOutOfCore.load())
213 #ifdef OPENVDB_USE_DELAYED_LOADING 215 mFileInfo =
new FileInfo(*other.mFileInfo);
218 if (other.mData !=
nullptr) {
223 while (n--) *target++ = *source++;
225 #ifdef OPENVDB_USE_DELAYED_LOADING 231 template<
typename T, Index Log2Dim>
237 if (mData) mData[i] = val;
241 template<
typename T, Index Log2Dim>
245 if (&other !=
this) {
246 #ifdef OPENVDB_USE_DELAYED_LOADING 248 this->detachFromFile();
253 mOutOfCore.store(other.mOutOfCore.load(std::memory_order_acquire),
254 std::memory_order_release);
255 mFileInfo =
new FileInfo(*other.mFileInfo);
258 if (other.mData !=
nullptr) {
263 while (n--) *target++ = *source++;
265 #ifdef OPENVDB_USE_DELAYED_LOADING 273 template<
typename T, Index Log2Dim>
277 this->detachFromFile();
278 if (mData !=
nullptr) {
281 while (n--) *target++ = val;
286 template<
typename T, Index Log2Dim>
292 const ValueType *target = mData, *source = other.mData;
293 if (!target && !source)
return true;
294 if (!target || !source)
return false;
301 template<
typename T, Index Log2Dim>
305 std::swap(mData, other.mData);
306 #ifdef OPENVDB_USE_DELAYED_LOADING 311 auto tmp = other.mOutOfCore.load(std::memory_order_acquire);
312 tmp = mOutOfCore.exchange(std::move(tmp));
313 other.mOutOfCore.store(std::move(tmp), std::memory_order_release);
318 template<
typename T, Index Log2Dim>
322 size_t n =
sizeof(*this);
323 #ifdef OPENVDB_USE_DELAYED_LOADING 328 #ifdef OPENVDB_USE_DELAYED_LOADING 331 return static_cast<Index>(n);
335 template<
typename T, Index Log2Dim>
339 size_t n =
sizeof(*this);
341 return static_cast<Index>(n);
345 template<
typename T, Index Log2Dim>
350 if (mData ==
nullptr) {
352 #ifdef OPENVDB_USE_DELAYED_LOADING 354 tbb::spin_mutex::scoped_lock lock(self->mMutex);
361 template<
typename T, Index Log2Dim>
366 if (mData ==
nullptr) {
367 #ifdef OPENVDB_USE_DELAYED_LOADING 369 tbb::spin_mutex::scoped_lock lock(mMutex);
377 template<
typename T, Index Log2Dim>
381 static const ValueType sZero = zeroVal<T>();
386 if (mData)
return mData[i];
else return sZero;
390 template<
typename T, Index Log2Dim>
395 if (mData !=
nullptr) {
396 #ifdef OPENVDB_USE_DELAYED_LOADING 407 template<
typename T, Index Log2Dim>
411 #ifdef OPENVDB_USE_DELAYED_LOADING 418 tbb::spin_mutex::scoped_lock lock(self->mMutex);
421 std::unique_ptr<FileInfo> info(self->mFileInfo);
427 self->mData =
nullptr;
431 std::istream is(buf.get());
436 is.seekg(info->maskpos);
439 is.seekg(info->bufpos);
442 self->setOutOfCore(
false);
447 template<
typename T, Index Log2Dim>
451 #ifdef OPENVDB_USE_DELAYED_LOADING 455 this->setOutOfCore(
false);
467 template<Index Log2Dim>
479 static inline const bool sOn =
true;
480 static inline const bool sOff =
false;
487 void fill(
bool val) { mData.set(val); }
495 if (mData.isOn(i))
return sOn;
else return sOff;
504 void swap(
LeafBuffer& other) {
if (&other !=
this) std::swap(mData, other.mData); }
528 #endif // OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:443
LeafBuffer()
Default constructor.
Definition: LeafBuffer.h:51
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:38
LeafBuffer(const LeafBuffer &other)
Definition: LeafBuffer.h:485
OPENVDB_API bool getHalfFloat(std::ios_base &)
Return true if floating-point values should be quantized to 16 bits when writing to the given stream ...
bool empty() const
Return true if memory for this buffer has not yet been allocated.
Definition: LeafBuffer.h:81
void swap(LeafBuffer &)
Exchange this buffer's values with the other buffer's values.
Definition: LeafBuffer.h:303
bool operator==(const LeafBuffer &) const
Return true if the contents of the other buffer exactly equal the contents of this buffer...
Definition: LeafBuffer.h:288
LeafBuffer(PartialCreate, const ValueType &)
Construct a buffer but don't allocate memory for the full array of values.
Definition: LeafBuffer.h:62
WordType StorageType
Definition: LeafBuffer.h:474
Index memUsageIfLoaded() const
Definition: LeafBuffer.h:337
LeafBuffer(const NodeMaskType &other)
Definition: LeafBuffer.h:484
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:307
const bool & getValue(Index i) const
Definition: LeafBuffer.h:490
LeafBuffer & operator=(const LeafBuffer &)
Copy the other buffer's values into this buffer.
Definition: LeafBuffer.h:243
Index memUsageIfLoaded() const
Definition: LeafBuffer.h:507
Index memUsage() const
Return the memory footprint of this buffer in bytes.
Definition: LeafBuffer.h:320
bool operator!=(const LeafBuffer &other) const
Definition: LeafBuffer.h:500
Index32 Index
Definition: Types.h:54
OPENVDB_API void setStreamMetadataPtr(std::ios_base &, SharedPtr< StreamMetadata > &, bool transfer=true)
Associate the given stream with (a shared pointer to) an object that stores metadata (file format...
Index64 Word
Definition: NodeMasks.h:316
bool operator==(const LeafBuffer &other) const
Definition: LeafBuffer.h:499
static const Index SIZE
Definition: LeafBuffer.h:37
void fill(bool val)
Definition: LeafBuffer.h:487
const ValueType & getValue(Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:89
void swap(LeafBuffer &other)
Definition: LeafBuffer.h:504
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:474
bool operator!=(const LeafBuffer &other) const
Return true if the contents of the other buffer are not exactly equal to the contents of this buffer...
Definition: LeafBuffer.h:103
static Index size()
Return the number of values contained in this buffer.
Definition: LeafBuffer.h:112
static Index size()
Definition: LeafBuffer.h:508
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:466
static const Index32 WORD_COUNT
Definition: NodeMasks.h:315
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: LeafBuffer.h:72
#define OPENVDB_USE_DELAYED_LOADING
Definition: version.h.in:143
void setValue(Index i, const ValueType &)
Set the i'th value of this buffer to the specified value.
Definition: LeafBuffer.h:233
Definition: Exceptions.h:13
Array of fixed size 23Log2Dim that stores the voxel values of a LeafNode.
Definition: LeafBuffer.h:31
~LeafBuffer()
Definition: LeafBuffer.h:486
WordType * data()
Return a pointer to the C-style array of words encoding the bits.
Definition: LeafBuffer.h:512
~LeafBuffer()
Destructor.
Definition: LeafBuffer.h:191
typename NodeMaskType::Word WordType
Definition: LeafBuffer.h:472
Index memUsage() const
Definition: LeafBuffer.h:506
LeafBuffer & operator=(const LeafBuffer &b)
Definition: LeafBuffer.h:488
bool ValueType
Definition: LeafBuffer.h:473
ValueType StorageType
Definition: LeafBuffer.h:35
bool allocate()
Allocate memory for this buffer if it has not already been allocated.
Definition: LeafBuffer.h:83
const bool & operator[](Index i) const
Definition: LeafBuffer.h:497
const ValueType & operator[](Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:91
void setValue(Index i, bool val)
Definition: LeafBuffer.h:502
const ValueType * data() const
Return a const pointer to the array of voxel values.
Definition: LeafBuffer.h:347
const WordType * data() const
Return a const pointer to the C-style array of words encoding the bits.
Definition: LeafBuffer.h:515
void load(std::istream &is)
Definition: NodeMasks.h:569
LeafBuffer()
Definition: LeafBuffer.h:482
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
ValueType ValueType
Definition: LeafBuffer.h:34
void fill(const ValueType &)
Populate this buffer with a constant value.
Definition: LeafBuffer.h:275
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:689
LeafBuffer(bool on)
Definition: LeafBuffer.h:483