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>
216 if (this->isOutOfCore()) {
217 this->detachFromFile();
224 template<
typename T, Index Log2Dim>
228 , mOutOfCore(other.mOutOfCore)
231 mFileInfo =
new FileInfo(*other.
mFileInfo);
232 }
else if (other.
mData !=
nullptr) {
237 while (n--) *target++ = *source++;
242 template<
typename T, Index Log2Dim>
247 #ifdef OPENVDB_2_ABI_COMPATIBLE 251 if (mData) mData[i] = val;
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 270 if (this->isOutOfCore()) {
271 this->detachFromFile();
276 mOutOfCore = other.mOutOfCore;
277 mFileInfo =
new FileInfo(*other.
mFileInfo);
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>
323 std::swap(mData, other.
mData);
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 336 if (mData) n += SIZE *
sizeof(
ValueType);
338 if (this->isOutOfCore()) n +=
sizeof(FileInfo);
339 else if (mData) n += SIZE *
sizeof(
ValueType);
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);
355 if (mData ==
nullptr)
self->mData =
new ValueType[SIZE];
361 template<
typename T, Index Log2Dim>
365 #ifndef OPENVDB_2_ABI_COMPATIBLE 367 if (mData ==
nullptr) {
369 tbb::spin_mutex::scoped_lock lock(mMutex);
370 if (mData ==
nullptr) mData =
new ValueType[SIZE];
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>
397 if (mData !=
nullptr && !this->isOutOfCore()) {
406 template<
typename T, Index Log2Dim>
410 if (!this->isOutOfCore())
return;
416 tbb::spin_mutex::scoped_lock lock(self->mMutex);
417 if (!this->isOutOfCore())
return;
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>
448 if (this->isOutOfCore()) {
451 this->setOutOfCore(
false);
457 #endif // OPENVDB_2_ABI_COMPATIBLE 464 template<Index Log2Dim>
471 static const Index WORD_COUNT = NodeMaskType::WORD_COUNT;
472 static const Index SIZE = 1 << 3 * Log2Dim;
483 void fill(
bool val) { mData.set(val); }
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
Index memUsage() const
Definition: LeafBuffer.h:502
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:496
const bool & getValue(Index i) const
Definition: LeafBuffer.h:486
const bool & operator[](Index i) const
Definition: LeafBuffer.h:493
void load(std::istream &is)
Definition: NodeMasks.h:569
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
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
bool empty() const
Return true if memory for this buffer has not yet been allocated.
Definition: LeafBuffer.h:100
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
bool operator==(const LeafBuffer &other) const
Definition: LeafBuffer.h:495
Definition: LeafBuffer.h:61
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
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
static Index size()
Definition: LeafBuffer.h:503
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
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
const ValueType & operator[](Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:111
SharedPtr< io::StreamMetadata > meta
Definition: LeafBuffer.h:67
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:307
const ValueType & getValue(Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafBuffer.h:109
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
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: LeafBuffer.h:98
LeafBuffer(bool on)
Definition: LeafBuffer.h:479
FileInfo()
Definition: LeafBuffer.h:63
LeafBuffer(const LeafBuffer &other)
Definition: LeafBuffer.h:481