31 #ifndef OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED 32 #define OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED 37 #include <tbb/spin_mutex.h> 40 #include <type_traits> 52 template<
typename T, Index Log2Dim>
58 static const Index SIZE = 1 << 3 * Log2Dim;
60 #ifndef OPENVDB_2_ABI_COMPATIBLE 71 #ifdef OPENVDB_2_ABI_COMPATIBLE 82 bool isOutOfCore()
const {
return false; }
84 bool empty()
const {
return (mData ==
nullptr); }
100 bool empty()
const {
return !mData || this->isOutOfCore(); }
102 bool allocate() {
if (mData ==
nullptr) mData =
new ValueType[SIZE];
return true; }
129 inline Index memUsage()
const;
155 #ifdef OPENVDB_2_ABI_COMPATIBLE 156 void setOutOfCore(
bool) {}
157 void loadValues()
const {}
158 void doLoad()
const {}
159 bool detachFromFile() {
return false; }
161 inline void setOutOfCore(
bool b) { mOutOfCore = b; }
164 inline void loadValues()
const {
if (this->isOutOfCore()) this->doLoad(); }
165 inline void doLoad()
const;
166 inline bool detachFromFile();
170 #ifdef OPENVDB_2_ABI_COMPATIBLE 178 tbb::spin_mutex mMutex;
184 friend class ::TestLeaf;
194 #ifndef OPENVDB_2_ABI_COMPATIBLE 195 template<
typename T, Index Log2Dim>
200 #ifndef OPENVDB_2_ABI_COMPATIBLE 202 template<
typename T, Index Log2Dim>
212 template<
typename T, Index Log2Dim>
217 this->detachFromFile();
224 template<
typename T, Index Log2Dim>
228 , mOutOfCore(other.mOutOfCore)
232 }
else if (other.
mData !=
nullptr) {
237 while (n--) *target++ = *source++;
242 template<
typename T, Index Log2Dim>
247 #ifdef OPENVDB_2_ABI_COMPATIBLE 256 template<
typename T, Index Log2Dim>
260 if (&other !=
this) {
261 #ifdef OPENVDB_2_ABI_COMPATIBLE 262 if (other.
mData !=
nullptr) {
267 while (n--) *target++ = *source++;
269 #else // ! OPENVDB_2_ABI_COMPATIBLE 271 this->detachFromFile();
276 mOutOfCore = other.mOutOfCore;
278 }
else if (other.
mData !=
nullptr) {
283 while (n--) *target++ = *source++;
291 template<
typename T, Index Log2Dim>
295 this->detachFromFile();
296 if (
mData !=
nullptr) {
299 while (n--) *target++ = val;
304 template<
typename T, Index Log2Dim>
311 if (!target && !source)
return true;
312 if (!target || !source)
return false;
319 template<
typename T, Index Log2Dim>
324 #ifndef OPENVDB_2_ABI_COMPATIBLE 325 std::swap(mOutOfCore, other.mOutOfCore);
330 template<
typename T, Index Log2Dim>
334 size_t n =
sizeof(*this);
335 #ifdef OPENVDB_2_ABI_COMPATIBLE 341 return static_cast<Index>(n);
345 template<
typename T, Index Log2Dim>
349 #ifndef OPENVDB_2_ABI_COMPATIBLE 351 if (
mData ==
nullptr) {
354 tbb::spin_mutex::scoped_lock lock(self->mMutex);
361 template<
typename T, Index Log2Dim>
365 #ifndef OPENVDB_2_ABI_COMPATIBLE 367 if (
mData ==
nullptr) {
369 tbb::spin_mutex::scoped_lock lock(mMutex);
377 template<
typename T, Index Log2Dim>
382 #ifdef OPENVDB_2_ABI_COMPATIBLE 388 if (
mData)
return mData[i];
else return sZero;
393 template<
typename T, Index Log2Dim>
406 template<
typename T, Index Log2Dim>
416 tbb::spin_mutex::scoped_lock lock(self->mMutex);
419 std::unique_ptr<FileInfo> info(self->mFileInfo);
420 assert(info.get() !=
nullptr);
421 assert(info->mapping.get() !=
nullptr);
422 assert(info->meta.get() !=
nullptr);
425 self->mData =
nullptr;
429 std::istream is(buf.get());
434 is.seekg(info->maskpos);
437 is.seekg(info->bufpos);
440 self->setOutOfCore(
false);
444 template<
typename T, Index Log2Dim>
451 this->setOutOfCore(
false);
457 #endif // OPENVDB_2_ABI_COMPATIBLE 464 template<Index Log2Dim>
491 if (
mData.isOn(i))
return sOn;
else return sOff;
531 #endif // OPENVDB_TREE_LEAFBUFFER_HAS_BEEN_INCLUDED void fill(bool val)
Definition: LeafBuffer.h:483
uint32_t Index32
Definition: Types.h:55
bool operator!=(const LeafBuffer &other) const
Definition: LeafBuffer.h:496
LeafBuffer & operator=(const LeafBuffer &)
Copy the other buffer's values into this buffer.
Definition: LeafBuffer.h:258
void load(std::istream &is)
Definition: NodeMasks.h:569
const ValueType & getValue(Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:109
bool empty() const
Return true if memory for this buffer has not yet been allocated.
Definition: LeafBuffer.h:100
LeafBuffer()
Default constructor.
Definition: LeafBuffer.h:87
~LeafBuffer()
Destructor.
Definition: LeafBuffer.h:214
static const Index SIZE
Definition: LeafBuffer.h:58
static const Index32 WORD_COUNT
Definition: NodeMasks.h:315
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:502
static const bool sOff
Definition: LeafBuffer.h:476
bool operator==(const LeafBuffer &) const
Return true if the contents of the other buffer exactly equal the contents of this buffer...
Definition: LeafBuffer.h:306
const ValueType * data() const
Return a const pointer to the array of voxel values.
Definition: LeafBuffer.h:347
void swap(LeafBuffer &)
Exchange this buffer's values with the other buffer's values.
Definition: LeafBuffer.h:321
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:123
const bool & operator[](Index i) const
Definition: LeafBuffer.h:493
std::streamoff bufpos
Definition: LeafBuffer.h:64
typename NodeMaskType::Word WordType
Definition: LeafBuffer.h:469
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:339
ValueType * mData
Definition: LeafBuffer.h:174
SharedPtr< MappedFile > Ptr
Definition: io.h:152
~LeafBuffer()
Definition: LeafBuffer.h:482
LeafBuffer()
Definition: LeafBuffer.h:478
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:61
#define OPENVDB_VERSION_NAME
Definition: version.h:43
const ValueType & operator[](Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:111
bool allocate()
Allocate memory for this buffer if it has not already been allocated.
Definition: LeafBuffer.h:103
Index64 Word
Definition: NodeMasks.h:316
Definition: Exceptions.h:39
io::MappedFile::Ptr mapping
Definition: LeafBuffer.h:66
void swap(LeafBuffer &other)
Definition: LeafBuffer.h:500
Array of fixed size that stores the voxel values of a LeafNode.
Definition: LeafBuffer.h:53
ValueType ValueType
Definition: LeafBuffer.h:56
Definition: LeafBuffer.h:61
Index memUsage() const
Return the memory footprint of this buffer in bytes.
Definition: LeafBuffer.h:332
Index memUsage() const
Definition: LeafBuffer.h:502
static const bool sOn
Definition: LeafBuffer.h:475
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 ...
FileInfo * mFileInfo
Definition: LeafBuffer.h:175
void fill(const ValueType &)
Populate this buffer with a constant value.
Definition: LeafBuffer.h:293
LeafBuffer(PartialCreate, const ValueType &)
Construct a buffer but don't allocate memory for the full array of values.
Definition: LeafBuffer.h:93
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
void setValue(Index i, bool val)
Definition: LeafBuffer.h:498
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: LeafBuffer.h:98
static Index size()
Definition: LeafBuffer.h:503
const WordType * data() const
Return a const pointer to the C-style array of words encoding the bits.
Definition: LeafBuffer.h:510
bool operator==(const LeafBuffer &other) const
Definition: LeafBuffer.h:495
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...
std::shared_ptr< T > SharedPtr
Definition: Types.h:130
SharedPtr< io::StreamMetadata > meta
Definition: LeafBuffer.h:67
const bool & getValue(Index i) const
Definition: LeafBuffer.h:486
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:307
static Index size()
Return the number of values contained in this buffer.
Definition: LeafBuffer.h:131
LeafBuffer & operator=(const LeafBuffer &b)
Definition: LeafBuffer.h:484
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:505
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Index32 Index
Definition: Types.h:57
LeafBuffer(const NodeMaskType &other)
Definition: LeafBuffer.h:480
WordType * data()
Return a pointer to the C-style array of words encoding the bits.
Definition: LeafBuffer.h:507
std::streamoff maskpos
Definition: LeafBuffer.h:65
void setValue(Index i, const ValueType &)
Set the i'th value of this buffer to the specified value.
Definition: LeafBuffer.h:244
LeafBuffer(bool on)
Definition: LeafBuffer.h:479
FileInfo()
Definition: LeafBuffer.h:63
LeafBuffer(const LeafBuffer &other)
Definition: LeafBuffer.h:481