4 #ifndef OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED 5 #define OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED 10 #include <tbb/atomic.h> 11 #include <tbb/spin_mutex.h> 16 #include <type_traits> 43 using type = tbb::atomic<Index32>;
44 static constexpr
bool IsAtomic =
true;
52 template<
typename T, Index Log2Dim>
59 static const Index SIZE = 1 << 3 * Log2Dim;
84 bool empty()
const {
return !mData || this->isOutOfCore(); }
112 inline Index memUsage()
const;
138 inline void setOutOfCore(
bool b) { mOutOfCore = b; }
141 inline void loadValues()
const {
if (this->isOutOfCore()) this->doLoad(); }
142 inline void doLoad()
const;
143 inline bool detachFromFile();
151 FlagsType mOutOfCore;
152 tbb::spin_mutex mMutex;
157 friend class ::TestLeaf;
166 template<
typename T, Index Log2Dim>
170 template<
typename T, Index Log2Dim>
180 template<
typename T, Index Log2Dim>
185 this->detachFromFile();
192 template<
typename T, Index Log2Dim>
196 , mOutOfCore(other.mOutOfCore)
200 }
else if (other.
mData !=
nullptr) {
205 while (n--) *target++ = *source++;
210 template<
typename T, Index Log2Dim>
220 template<
typename T, Index Log2Dim>
224 if (&other !=
this) {
226 this->detachFromFile();
231 mOutOfCore = other.mOutOfCore;
233 }
else if (other.
mData !=
nullptr) {
238 while (n--) *target++ = *source++;
245 template<
typename T, Index Log2Dim>
249 this->detachFromFile();
250 if (
mData !=
nullptr) {
253 while (n--) *target++ = val;
258 template<
typename T, Index Log2Dim>
265 if (!target && !source)
return true;
266 if (!target || !source)
return false;
273 template<
typename T, Index Log2Dim>
278 std::swap(mOutOfCore, other.mOutOfCore);
282 template<
typename T, Index Log2Dim>
286 size_t n =
sizeof(*this);
289 return static_cast<Index>(n);
293 template<
typename T, Index Log2Dim>
298 if (
mData ==
nullptr) {
301 tbb::spin_mutex::scoped_lock lock(self->mMutex);
307 template<
typename T, Index Log2Dim>
312 if (
mData ==
nullptr) {
314 tbb::spin_mutex::scoped_lock lock(mMutex);
321 template<
typename T, Index Log2Dim>
329 if (
mData)
return mData[i];
else return sZero;
333 template<
typename T, Index Log2Dim>
346 template<
typename T, Index Log2Dim>
356 tbb::spin_mutex::scoped_lock lock(self->mMutex);
359 std::unique_ptr<FileInfo> info(self->mFileInfo);
360 assert(info.get() !=
nullptr);
361 assert(info->mapping.get() !=
nullptr);
362 assert(info->meta.get() !=
nullptr);
365 self->mData =
nullptr;
369 std::istream is(buf.get());
374 is.seekg(info->maskpos);
377 is.seekg(info->bufpos);
380 self->setOutOfCore(
false);
384 template<
typename T, Index Log2Dim>
391 this->setOutOfCore(
false);
402 template<Index Log2Dim>
431 if (
mData.isOn(i))
return sOn;
else return sOff;
471 #endif // OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED tbb::atomic< Index32 > type
The type of LeafBuffer::mOutOfCore.
Definition: LeafBuffer.h:43
FileInfo()
Definition: LeafBuffer.h:63
Array of fixed size 23Log2Dim that stores the voxel values of a LeafNode.
Definition: LeafBuffer.h:53
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:106
void setValue(Index i, const ValueType &)
Set the i'th value of this buffer to the specified value.
Definition: LeafBuffer.h:212
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:465
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:37
const ValueType & operator[](Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:94
LeafBuffer()
Definition: LeafBuffer.h:418
bool allocate()
Allocate memory for this buffer if it has not already been allocated.
Definition: LeafBuffer.h:86
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:426
LeafBuffer()
Default constructor.
Definition: LeafBuffer.h:71
Index64 Word
Definition: NodeMasks.h:316
void load(std::istream &is)
Definition: NodeMasks.h:569
ValueType ValueType
Definition: LeafBuffer.h:56
bool ValueType
Definition: LeafBuffer.h:408
~LeafBuffer()
Destructor.
Definition: LeafBuffer.h:182
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...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
LeafBuffer(const NodeMaskType &other)
Definition: LeafBuffer.h:420
LeafBuffer(PartialCreate, const ValueType &)
Construct a buffer but don't allocate memory for the full array of values.
Definition: LeafBuffer.h:77
typename NodeMaskType::Word WordType
Definition: LeafBuffer.h:407
const WordType * data() const
Return a const pointer to the C-style array of words encoding the bits.
Definition: LeafBuffer.h:450
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
Definition: openvdb/Exceptions.h:13
std::streamoff maskpos
Definition: LeafBuffer.h:65
void swap(LeafBuffer &)
Exchange this buffer's values with the other buffer's values.
Definition: LeafBuffer.h:275
static const Index32 WORD_COUNT
Definition: NodeMasks.h:315
static const bool sOff
Definition: LeafBuffer.h:416
Definition: LeafBuffer.h:61
const bool & operator[](Index i) const
Definition: LeafBuffer.h:433
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:434
io::MappedFile::Ptr mapping
Definition: LeafBuffer.h:66
static Index size()
Return the number of values contained in this buffer.
Definition: LeafBuffer.h:114
void swap(LeafBuffer &other)
Definition: LeafBuffer.h:440
const ValueType & getValue(Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:92
ValueType * mData
Definition: LeafBuffer.h:148
static const bool sOn
Definition: LeafBuffer.h:415
bool operator==(const LeafBuffer &other) const
Definition: LeafBuffer.h:435
LeafBuffer(const LeafBuffer &other)
Definition: LeafBuffer.h:421
LeafBuffer & operator=(const LeafBuffer &)
Copy the other buffer's values into this buffer.
Definition: LeafBuffer.h:222
Index memUsage() const
Return the memory footprint of this buffer in bytes.
Definition: LeafBuffer.h:284
std::shared_ptr< T > SharedPtr
Definition: openvdb/Types.h:92
SharedPtr< io::StreamMetadata > meta
Definition: LeafBuffer.h:67
Definition: LeafBuffer.h:40
bool empty() const
Return true if memory for this buffer has not yet been allocated.
Definition: LeafBuffer.h:84
WordType StorageType
Definition: LeafBuffer.h:409
WordType * data()
Return a pointer to the C-style array of words encoding the bits.
Definition: LeafBuffer.h:447
LeafBuffer & operator=(const LeafBuffer &b)
Definition: LeafBuffer.h:424
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 ...
static Index size()
Definition: LeafBuffer.h:443
bool operator==(const LeafBuffer &) const
Return true if the contents of the other buffer exactly equal the contents of this buffer...
Definition: LeafBuffer.h:260
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: LeafBuffer.h:82
LeafBuffer(bool on)
Definition: LeafBuffer.h:419
void fill(const ValueType &)
Populate this buffer with a constant value.
Definition: LeafBuffer.h:247
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
ValueType StorageType
Definition: LeafBuffer.h:57
void setValue(Index i, bool val)
Definition: LeafBuffer.h:438
void fill(bool val)
Definition: LeafBuffer.h:423
FileInfo * mFileInfo
Definition: LeafBuffer.h:149
std::streamoff bufpos
Definition: LeafBuffer.h:64
Index32 Index
Definition: openvdb/Types.h:32
Tag dispatch class that distinguishes constructors during file input.
Definition: openvdb/Types.h:548
bool operator!=(const LeafBuffer &other) const
Definition: LeafBuffer.h:436
SharedPtr< MappedFile > Ptr
Definition: io.h:136
Index memUsage() const
Definition: LeafBuffer.h:442
static const Index SIZE
Definition: LeafBuffer.h:59
const ValueType * data() const
Return a const pointer to the array of voxel values.
Definition: LeafBuffer.h:295
~LeafBuffer()
Definition: LeafBuffer.h:422