12#ifndef OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED
13#define OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED
15#include <openvdb/version.h>
33class TestPointDataLeaf;
51 const bool seek = destBuf ==
nullptr;
55 if (destBytes >= maximumBytes) {
57 maximumBytes <<
" bytes in voxel values.")
67 bytes16 =
static_cast<uint16_t
>(meta->pass());
69 is.seekg(
sizeof(uint16_t), std::ios_base::cur);
73 is.read(
reinterpret_cast<char*
>(&bytes16),
sizeof(uint16_t));
79 is.seekg(destBytes, std::ios_base::cur);
82 is.read(
reinterpret_cast<char*
>(destBuf), destBytes);
88 is.seekg(
int(bytes16), std::ios_base::cur);
92 std::unique_ptr<char[]> bloscBuffer(
new char[
int(bytes16)]);
93 is.read(bloscBuffer.get(), bytes16);
97 std::memcpy(destBuf, buffer.get(), destBytes);
114 if (srcBytes >= maximumBytes) {
116 maximumBytes <<
" bytes in voxel values.")
119 const char* charBuffer =
reinterpret_cast<const char*
>(srcBuf);
121 size_t compressedBytes;
122 std::unique_ptr<char[]> buffer =
bloscCompress( charBuffer, srcBytes,
123 compressedBytes,
false);
125 if (compressedBytes > 0) {
126 auto bytes16 =
static_cast<uint16_t
>(compressedBytes);
127 os.write(
reinterpret_cast<const char*
>(&bytes16),
sizeof(uint16_t));
128 os.write(
reinterpret_cast<const char*
>(buffer.get()), compressedBytes);
131 auto bytes16 =
static_cast<uint16_t
>(maximumBytes);
132 os.write(
reinterpret_cast<const char*
>(&bytes16),
sizeof(uint16_t));
133 os.write(
reinterpret_cast<const char*
>(srcBuf), srcBytes);
143 const size_t srcBytes = srcCount*
sizeof(T);
145 if (srcBytes >= maximumBytes) {
147 maximumBytes <<
" bytes in voxel values.")
150 const char* charBuffer =
reinterpret_cast<const char*
>(srcBuf);
155 if (compressedBytes > 0) {
156 auto bytes16 =
static_cast<uint16_t
>(compressedBytes);
157 os.write(
reinterpret_cast<const char*
>(&bytes16),
sizeof(uint16_t));
160 auto bytes16 =
static_cast<uint16_t
>(maximumBytes);
161 os.write(
reinterpret_cast<const char*
>(&bytes16),
sizeof(uint16_t));
181template<
typename T, Index Log2Dim>
class PointDataLeafNode;
186#ifndef OPENVDB_DISABLE_POINT_DATA_TREE_ALIAS
205template <
typename Po
intDataTreeT>
206inline AttributeSet::Descriptor::Ptr
219template <
typename Po
intDataTreeT>
230template <
typename Po
intDataTreeT>
232prefetch(PointDataTreeT& tree,
bool position =
true,
bool otherAttributes =
true);
238template <
typename T, Index Log2Dim>
243 using Ptr = std::shared_ptr<PointDataLeafNode>;
259 using BaseLeaf::LOG2DIM;
260 using BaseLeaf::TOTAL;
262 using BaseLeaf::NUM_VALUES;
263 using BaseLeaf::NUM_VOXELS;
264 using BaseLeaf::SIZE;
265 using BaseLeaf::LEVEL;
276 , mAttributeSet(new
AttributeSet(*other.mAttributeSet)) { }
287 const T&
value = zeroVal<T>(),
bool active =
false)
291 assertNonModifiableUnlessZero(
value);
295 template<
typename OtherValueType>
302 template <
typename ValueType>
309 template <
typename ValueType>
315 const T&
value = zeroVal<T>(),
bool active =
false)
328 void initializeAttributes(
const Descriptor::Ptr& descriptor,
const Index arrayLength,
331 void clearAttributes(
const bool updateValueMask =
true,
336 bool hasAttribute(
const size_t pos)
const;
339 bool hasAttribute(
const Name& attributeName)
const;
350 const size_t pos,
const Index strideOrTotalSize = 1,
351 const bool constantStride =
true,
360 const Descriptor& expected, Descriptor::Ptr& replacement);
363 void reorderAttributes(
const Descriptor::Ptr& replacement);
367 void renameAttributes(
const Descriptor& expected, Descriptor::Ptr& replacement);
376 void replaceAttributeSet(
AttributeSet* attributeSet,
bool allowMismatchingDescriptors =
false);
380 void resetDescriptor(
const Descriptor::Ptr& replacement);
385 void setOffsets(
const std::vector<ValueType>& offsets,
const bool updateValueMask =
true);
389 void validateOffsets()
const;
398 const AttributeArray& constAttributeArray(
const size_t pos)
const;
411 GroupHandle groupHandle(
const AttributeSet::Descriptor::GroupIndex& index)
const;
415 GroupWriteHandle groupWriteHandle(
const AttributeSet::Descriptor::GroupIndex& index);
426 Index64 groupPointCount(
const Name& groupName)
const;
429 void updateValueMask();
433 void setOffsetOn(
Index offset,
const ValueType& val);
434 void setOffsetOnly(
Index offset,
const ValueType& val);
438 template<
typename OtherType, Index OtherLog2Dim>
440 return BaseLeaf::hasSameTopology(other);
446 if(BaseLeaf::operator==(other) !=
true)
return false;
447 return (*this->mAttributeSet == *other.mAttributeSet);
453 template<
typename AccessorT>
459 template<
typename AccessorT>
462 template<
typename NodeT,
typename AccessorT>
467 return reinterpret_cast<NodeT*
>(
this);
471 template<
typename AccessorT>
478 template<
typename AccessorT>
480 template<
typename AccessorT>
483 template<
typename NodeT,
typename AccessorT>
488 return reinterpret_cast<const NodeT*
>(
this);
495 void readTopology(std::istream& is,
bool fromHalf =
false);
496 void writeTopology(std::ostream& os,
bool toHalf =
false)
const;
498 Index buffers()
const;
500 void readBuffers(std::istream& is,
bool fromHalf =
false);
501 void readBuffers(std::istream& is,
const CoordBBox&,
bool fromHalf =
false);
502 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
507 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
519 assert(
false &&
"Cannot modify voxel values in a PointDataTree.");
526 if (
value != zeroVal<T>()) this->assertNonmodifiable();
552 template<
typename ModifyOp>
555 template<
typename ModifyOp>
558 template<
typename ModifyOp>
564 void fill(
const CoordBBox&,
const ValueType&,
bool);
566 void fill(
const ValueType&,
bool);
568 template<
typename AccessorT>
571 template<
typename ModifyOp,
typename AccessorT>
573 assertNonmodifiable();
576 template<
typename AccessorT>
579 template<
typename AccessorT>
581 BaseLeaf::setActiveStateAndCache(xyz, on, parent);
585 assertNonModifiableUnlessZero(newBackground);
593 friend class ::TestPointDataLeaf;
601 uint16_t mVoxelBufferSize = 0;
660 return this->beginIndex<ValueAllCIter, NullFilter>(filter);
665 return this->beginIndex<ValueOnCIter, NullFilter>(filter);
670 return this->beginIndex<ValueOffCIter, NullFilter>(filter);
673 template<
typename IterT,
typename FilterT>
677 template<
typename FilterT>
680 return this->beginIndex<ValueAllCIter, FilterT>(filter);
682 template<
typename FilterT>
685 return this->beginIndex<ValueOnCIter, FilterT>(filter);
687 template<
typename FilterT>
690 return this->beginIndex<ValueOffCIter, FilterT>(filter);
694 IndexVoxelIter beginIndexVoxel(
const Coord& ijk)
const;
697 template<
typename FilterT>
700#define VMASK_ this->getValueMask()
747template<
typename T, Index Log2Dim>
748inline AttributeSet::UniquePtr
752 std::swap(ptr, mAttributeSet);
756template<
typename T, Index Log2Dim>
761 if (descriptor->size() != 1 ||
762 descriptor->find(
"P") == AttributeSet::INVALID_POS ||
768 mAttributeSet.reset(
new AttributeSet(descriptor, arrayLength, lock));
771template<
typename T, Index Log2Dim>
776 mAttributeSet.reset(
new AttributeSet(*mAttributeSet, 0, lock));
784 if (updateValueMask) this->setValuesOff();
787template<
typename T, Index Log2Dim>
791 return pos < mAttributeSet->
size();
794template<
typename T, Index Log2Dim>
798 const size_t pos = mAttributeSet->find(attributeName);
799 return pos != AttributeSet::INVALID_POS;
802template<
typename T, Index Log2Dim>
805 const size_t pos,
const Index strideOrTotalSize,
806 const bool constantStride,
810 return mAttributeSet->appendAttribute(
811 expected, replacement, pos, strideOrTotalSize, constantStride, metadata, lock);
814template<
typename T, Index Log2Dim>
817 const Descriptor& expected, Descriptor::Ptr& replacement)
819 mAttributeSet->dropAttributes(pos, expected, replacement);
822template<
typename T, Index Log2Dim>
829template<
typename T, Index Log2Dim>
833 mAttributeSet->renameAttributes(expected, replacement);
836template<
typename T, Index Log2Dim>
840 for (
size_t i = 0; i < mAttributeSet->size(); i++) {
846template<
typename T, Index Log2Dim>
854 if (!allowMismatchingDescriptors && mAttributeSet->descriptor() != attributeSet->
descriptor()) {
858 mAttributeSet.reset(attributeSet);
861template<
typename T, Index Log2Dim>
868template<
typename T, Index Log2Dim>
872 if (offsets.size() != LeafNodeType::NUM_VALUES) {
876 for (
Index index = 0; index < offsets.size(); ++index) {
877 setOffsetOnly(index, offsets[index]);
880 if (updateValueMask) this->updateValueMask();
883template<
typename T, Index Log2Dim>
888 for (
Index index = 1; index < BaseLeaf::SIZE; ++index) {
889 if (this->getValue(index-1) > this->getValue(index)) {
895 for (
size_t attributeIndex = 1; attributeIndex < mAttributeSet->size(); ++attributeIndex ) {
896 if (mAttributeSet->getConst(attributeIndex-1)->size() != mAttributeSet->getConst(attributeIndex)->size()) {
902 if (mAttributeSet->size() > 0 && this->getValue(BaseLeaf::SIZE-1) != mAttributeSet->getConst(0)->size()) {
907template<
typename T, Index Log2Dim>
912 return *mAttributeSet->get(pos);
915template<
typename T, Index Log2Dim>
920 return *mAttributeSet->getConst(pos);
923template<
typename T, Index Log2Dim>
927 return this->attributeArray(pos);
930template<
typename T, Index Log2Dim>
934 const size_t pos = mAttributeSet->find(attributeName);
936 return *mAttributeSet->get(pos);
939template<
typename T, Index Log2Dim>
943 const size_t pos = mAttributeSet->find(attributeName);
945 return *mAttributeSet->getConst(pos);
948template<
typename T, Index Log2Dim>
952 return this->attributeArray(attributeName);
955template<
typename T, Index Log2Dim>
967template<
typename T, Index Log2Dim>
971 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
972 return this->groupHandle(index);
975template<
typename T, Index Log2Dim>
987template<
typename T, Index Log2Dim>
991 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
992 return this->groupWriteHandle(index);
995template<
typename T, Index Log2Dim>
996template<
typename ValueIterT,
typename FilterT>
1008 FilterT newFilter(filter);
1009 newFilter.reset(*
this);
1015 ValueIterT valueIter = IterTraitsT::begin(*
this);
1020template<
typename T, Index Log2Dim>
1024 const Index index = LeafNodeType::coordToOffset(ijk);
1025 assert(index < BaseLeaf::SIZE);
1026 const ValueType end = this->getValue(index);
1031template<
typename T, Index Log2Dim>
1039template<
typename T, Index Log2Dim>
1040template<
typename FilterT>
1045 FilterT newFilter(filter);
1046 newFilter.reset(*
this);
1050template<
typename T, Index Log2Dim>
1054 return this->getLastValue();
1057template<
typename T, Index Log2Dim>
1061 if (this->isEmpty())
return 0;
1062 else if (this->isDense())
return this->
pointCount();
1066template<
typename T, Index Log2Dim>
1070 if (this->isEmpty())
return this->
pointCount();
1071 else if (this->isDense())
return 0;
1072 return iterCount(this->beginIndexOff());
1075template<
typename T, Index Log2Dim>
1079 if (!this->attributeSet().descriptor().hasGroup(groupName)) {
1082 GroupFilter filter(groupName, this->attributeSet());
1086 return iterCount(this->beginIndexAll(filter));
1090template<
typename T, Index Log2Dim>
1095 for (
Index n = 0; n < LeafNodeType::NUM_VALUES; n++) {
1096 end = this->getValue(n);
1097 this->setValueMask(n, (end - start) > 0);
1102template<
typename T, Index Log2Dim>
1106 this->buffer().
setValue(offset, val);
1107 this->setValueMaskOn(offset);
1110template<
typename T, Index Log2Dim>
1114 this->buffer().
setValue(offset, val);
1117template<
typename T, Index Log2Dim>
1121 BaseLeaf::readTopology(is, fromHalf);
1124template<
typename T, Index Log2Dim>
1128 BaseLeaf::writeTopology(os, toHalf);
1131template<
typename T, Index Log2Dim>
1138 mAttributeSet->size() +
1139 mAttributeSet->size() +
1143template<
typename T, Index Log2Dim>
1150template<
typename T, Index Log2Dim>
1159 std::string key(
"paged:" + std::to_string(index));
1160 auto it = auxData.find(key);
1161 if (it != auxData.end()) {
1169 std::string key(
"paged:" + std::to_string(index));
1170 auto it = auxData.find(key);
1171 if (it != auxData.end()) {
1172 return *(boost::any_cast<compression::PagedInputStream::Ptr>(it->second));
1177 return *pagedStream;
1183 std::string matchingKey(
"hasMatchingDescriptor");
1184 auto itMatching = auxData.find(matchingKey);
1185 return itMatching != auxData.end();
1190 std::string matchingKey(
"hasMatchingDescriptor");
1191 std::string descriptorKey(
"descriptorPtr");
1192 auto itMatching = auxData.find(matchingKey);
1193 auto itDescriptor = auxData.find(descriptorKey);
1199 const Descriptor::Ptr descriptor)
1201 std::string descriptorKey(
"descriptorPtr");
1202 std::string matchingKey(
"hasMatchingDescriptor");
1203 auto itMatching = auxData.find(matchingKey);
1204 if (itMatching == auxData.end()) {
1213 std::string descriptorKey(
"descriptorPtr");
1214 auto itDescriptor = auxData.find(descriptorKey);
1215 assert(itDescriptor != auxData.end());
1216 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1227 const Index pass(
static_cast<uint16_t
>(meta->pass()));
1228 const Index maximumPass(
static_cast<uint16_t
>(meta->pass() >> 16));
1230 const Index attributes = (maximumPass - 4) / 2;
1234 is.read(
reinterpret_cast<char*
>(&mVoxelBufferSize),
sizeof(uint16_t));
1235 Local::clearMatchingDescriptor(meta->auxData());
1237 else if (pass == 1) {
1239 if (Local::hasMatchingDescriptor(meta->auxData())) {
1240 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1241 mAttributeSet->resetDescriptor(descriptor,
true);
1245 is.read(
reinterpret_cast<char*
>(&header),
sizeof(uint8_t));
1246 mAttributeSet->readDescriptor(is);
1247 if (header & uint8_t(1)) {
1249 Local::insertDescriptor(meta->auxData(), descriptor);
1253 if (header & uint8_t(2)) {
1254 uint64_t bytesToSkip;
1255 is.read(
reinterpret_cast<char*
>(&bytesToSkip),
sizeof(uint64_t));
1256 if (bytesToSkip > uint64_t(0)) {
1258 if (metadata && metadata->seekable()) {
1259 is.seekg(bytesToSkip, std::ios_base::cur);
1262 std::vector<uint8_t> tempData(bytesToSkip);
1263 is.read(
reinterpret_cast<char*
>(&tempData[0]), bytesToSkip);
1268 if (header > uint8_t(3)) {
1272 mAttributeSet->readMetadata(is);
1274 else if (pass < (attributes + 2)) {
1276 const size_t attributeIndex = pass - 2;
1278 mAttributeSet->get(attributeIndex) :
nullptr;
1281 Local::getOrInsertPagedStream(meta->auxData(),
static_cast<Index>(attributeIndex));
1287 else if (pass == attributes + 2) {
1290 const Index passValue(meta->pass());
1294 nonConstMeta.
setPass(mVoxelBufferSize);
1297 BaseLeaf::readBuffers(is, fromHalf);
1300 nonConstMeta.
setPass(passValue);
1302 else if (pass < (attributes*2 + 3)) {
1304 const Index attributeIndex = pass - attributes - 3;
1306 mAttributeSet->get(attributeIndex) :
nullptr;
1309 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1315 if (pass > attributes + 3) {
1316 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1319 else if (pass < buffers()) {
1321 const Index attributeIndex = pass - attributes - 4;
1322 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1326template<
typename T, Index Log2Dim>
1335 std::string key(
"paged:" + std::to_string(index));
1336 auto it = auxData.find(key);
1337 if (it != auxData.end()) {
1347 std::string key(
"paged:" + std::to_string(index));
1348 auto it = auxData.find(key);
1349 if (it != auxData.end()) {
1350 return *(boost::any_cast<compression::PagedOutputStream::Ptr>(it->second));
1355 return *pagedStream;
1360 const Descriptor::Ptr descriptor)
1362 std::string descriptorKey(
"descriptorPtr");
1363 std::string matchingKey(
"hasMatchingDescriptor");
1364 auto itMatching = auxData.find(matchingKey);
1365 auto itDescriptor = auxData.find(descriptorKey);
1366 if (itMatching == auxData.end()) {
1369 assert(itDescriptor == auxData.end());
1374 bool matching = boost::any_cast<bool>(itMatching->second);
1375 if (!matching)
return;
1376 assert(itDescriptor != auxData.end());
1379 const Descriptor::Ptr existingDescriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1380 if (*existingDescriptor != *descriptor) {
1388 std::string matchingKey(
"hasMatchingDescriptor");
1389 auto itMatching = auxData.find(matchingKey);
1391 if (itMatching == auxData.end())
return false;
1393 if (!boost::any_cast<bool>(itMatching->second))
return false;
1399 std::string descriptorKey(
"descriptorPtr");
1400 auto itDescriptor = auxData.find(descriptorKey);
1402 if (itDescriptor == auxData.end())
return nullptr;
1404 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1411 std::string matchingKey(
"hasMatchingDescriptor");
1412 std::string descriptorKey(
"descriptorPtr");
1413 auto itMatching = auxData.find(matchingKey);
1414 auto itDescriptor = auxData.find(descriptorKey);
1426 const Index pass(
static_cast<uint16_t
>(meta->pass()));
1431 if (meta->countingPasses()) {
1432 const Index requiredPasses = this->buffers();
1433 if (requiredPasses > pass) {
1434 meta->setPass(requiredPasses);
1439 const Index maximumPass(
static_cast<uint16_t
>(meta->pass() >> 16));
1440 const Index attributes = (maximumPass - 4) / 2;
1446 Local::insertDescriptor(meta->auxData(), mAttributeSet->descriptorPtr());
1448 else if (pass == 1) {
1450 bool matchingDescriptor = Local::hasMatchingDescriptor(meta->auxData());
1451 if (matchingDescriptor) {
1452 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1456 os.write(
reinterpret_cast<const char*
>(&header),
sizeof(uint8_t));
1457 mAttributeSet->writeDescriptor(os,
false);
1463 os.write(
reinterpret_cast<const char*
>(&header),
sizeof(uint8_t));
1464 mAttributeSet->writeDescriptor(os,
false);
1466 mAttributeSet->writeMetadata(os,
false,
true);
1468 else if (pass < attributes + 2) {
1470 const Index attributeIndex = pass - 2;
1473 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1476 mAttributeSet->getConst(attributeIndex) :
nullptr;
1479 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1485 else if (pass == attributes + 2) {
1486 const Index attributeIndex = pass - 3;
1487 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1489 BaseLeaf::writeBuffers(os, toHalf);
1491 else if (pass < (attributes*2 + 3)) {
1493 const Index attributeIndex = pass - attributes - 3;
1495 if (pass > attributes + 2) {
1496 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1499 mAttributeSet->getConst(attributeIndex) :
nullptr;
1502 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1508 else if (pass < buffers()) {
1509 Local::clearMatchingDescriptor(meta->auxData());
1511 const Index attributeIndex = pass - attributes - 4;
1512 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1516template<
typename T, Index Log2Dim>
1523template<
typename T, Index Log2Dim>
1527 BaseLeaf::evalActiveBoundingBox(bbox, visitVoxels);
1530template<
typename T, Index Log2Dim>
1534 return BaseLeaf::getNodeBoundingBox();
1537template<
typename T, Index Log2Dim>
1543 this->assertNonModifiableUnlessZero(
value);
1548 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1550 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1552 const Index offset = offsetXY + (z & (DIM-1u));
1553 this->setValueMask(offset, active);
1559template<
typename T, Index Log2Dim>
1563 this->assertNonModifiableUnlessZero(
value);
1567 if (active) this->setValuesOn();
1568 else this->setValuesOff();
1575template <
typename Po
intDataTreeT>
1576inline AttributeSet::Descriptor::Ptr
1579 auto leafIter = tree.beginLeaf();
1580 if (!leafIter)
return nullptr;
1582 const AttributeSet::Descriptor& descriptor = leafIter->attributeSet().descriptor();
1583 auto newDescriptor = std::make_shared<AttributeSet::Descriptor>(descriptor);
1584 for (; leafIter; ++leafIter) {
1585 leafIter->resetDescriptor(newDescriptor);
1588 return newDescriptor;
1592template <
typename Po
intDataTreeT>
1596 auto leafIter = tree.beginLeaf();
1597 for (; leafIter; ++leafIter) {
1598 for (
size_t i = 0; i < leafIter->attributeSet().size(); i++) {
1599 leafIter->attributeArray(i).setStreaming(on);
1605template <
typename Po
intDataTreeT>
1607prefetch(PointDataTreeT& tree,
bool position,
bool otherAttributes)
1612 auto leaf = tree.cbeginLeaf();
1615 const auto& attributeSet = leaf->attributeSet();
1619 for ( ; leaf; ++leaf) {
1620 leaf->buffer().data();
1625 size_t positionIndex = attributeSet.find(
"P");
1627 if (position && positionIndex != AttributeSet::INVALID_POS) {
1628 for (leaf = tree.cbeginLeaf(); leaf; ++leaf) {
1629 assert(leaf->hasAttribute(positionIndex));
1630 leaf->constAttributeArray(positionIndex).loadData();
1636 if (otherAttributes) {
1637 const size_t attributes = attributeSet.size();
1638 for (
size_t attributeIndex = 0; attributeIndex < attributes; attributeIndex++) {
1639 if (attributeIndex == positionIndex)
continue;
1640 for (leaf = tree.cbeginLeaf(); leaf; ++leaf) {
1641 assert(leaf->hasAttribute(attributeIndex));
1642 leaf->constAttributeArray(attributeIndex).loadData();
1666template<
typename HeadT,
int HeadLevel>
1671 using Type =
typename SubtreeT::template Append<RootNodeT>;
1676template <
typename ChildT, Index Log2Dim,
int HeadLevel>
1681 using Type =
typename SubtreeT::template Append<InternalNodeT>;
1686template <
typename ChildT, Index Log2Dim>
1700template <
typename TreeType>
1719template<Index Dim1,
typename T2>
Attribute array storage for string data using Descriptor Metadata.
Attribute Array storage templated on type and compression codec.
Attribute Group access and filtering for iteration.
Set of Attribute Arrays which tracks metadata about each array.
ValueT value
Definition: GridBuilder.h:1287
#define VMASK_
Definition: PointDataGrid.h:700
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
Convenience wrappers to using Blosc and reading and writing of Paged data.
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:577
Definition: Exceptions.h:57
Definition: Exceptions.h:58
Definition: Exceptions.h:60
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:570
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:564
Definition: Exceptions.h:65
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:205
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition: StreamCompression.h:214
void setInputStream(std::istream &is)
Definition: StreamCompression.h:219
std::shared_ptr< PagedInputStream > Ptr
Definition: StreamCompression.h:207
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:242
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition: StreamCompression.h:251
void setOutputStream(std::ostream &os)
Definition: StreamCompression.h:256
std::shared_ptr< PagedOutputStream > Ptr
Definition: StreamCompression.h:244
void flush()
Manually flushes the current page to disk if non-zero.
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:248
const Coord & min() const
Definition: Coord.h:320
const Coord & max() const
Definition: Coord.h:321
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:318
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:25
Int32 y() const
Definition: Coord.h:131
Int32 x() const
Definition: Coord.h:130
Int32 z() const
Definition: Coord.h:132
Definition: AttributeArray.h:119
Base class for storing attribute data.
Definition: AttributeArray.h:93
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
virtual Index size() const =0
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:39
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:102
std::unique_ptr< AttributeSet > UniquePtr
Definition: AttributeSet.h:45
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:49
Index filtering on group membership.
Definition: AttributeGroup.h:135
static index::State state()
Definition: AttributeGroup.h:145
Definition: AttributeGroup.h:73
Definition: AttributeGroup.h:102
A forward iterator over array indices with filtering IteratorT can be either IndexIter or ValueIndexI...
Definition: IndexIterator.h:140
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:51
Definition: PointDataGrid.h:239
ChildOnCIter cbeginChildOn() const
Definition: PointDataGrid.h:721
void setValueOn(Index offset)
Definition: PointDataGrid.h:542
void setValueOff(const Coord &, const ValueType &)
Definition: PointDataGrid.h:538
ChildOnCIter beginChildOn() const
Definition: PointDataGrid.h:722
ChildOnIter beginChildOn()
Definition: PointDataGrid.h:723
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &parent)
Definition: PointDataGrid.h:580
ValueOnIter endValueOn()
Definition: PointDataGrid.h:713
PointDataLeafNode * touchLeaf(const Coord &)
Return a pointer to this node.
Definition: PointDataGrid.h:458
PointDataLeafNode(const tools::PointIndexLeafNode< OtherValueType, Log2Dim > &other)
Definition: PointDataGrid.h:296
ValueOffCIter cbeginValueOff() const
Definition: PointDataGrid.h:704
typename BaseLeaf::template ChildIter< MaskOnIterator, PointDataLeafNode, ChildOn > ChildOnIter
Definition: PointDataGrid.h:639
PointDataLeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition: PointDataGrid.h:460
PointDataLeafNode(const PointDataLeafNode &other, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:286
bool operator==(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:445
bool hasSameTopology(const PointDataLeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
Definition: PointDataGrid.h:439
ChildOnIter endChildOn()
Definition: PointDataGrid.h:733
ValueAllIter endValueAll()
Definition: PointDataGrid.h:719
void modifyValue(Index, const ModifyOp &)
Definition: PointDataGrid.h:553
void setValueOn(Index, const ValueType &)
Definition: PointDataGrid.h:545
void setValuesOff()
Definition: PointDataGrid.h:550
ValueAllCIter endValueAll() const
Definition: PointDataGrid.h:718
const PointDataLeafNode * probeLeaf(const Coord &) const
Definition: PointDataGrid.h:482
ChildOffCIter endChildOff() const
Definition: PointDataGrid.h:735
void setValueOff(Index, const ValueType &)
Definition: PointDataGrid.h:539
PointDataLeafNode(PartialCreate, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:314
ValueAllCIter cbeginValueAll() const
Definition: PointDataGrid.h:707
typename BaseLeaf::ChildOff ChildOff
Definition: PointDataGrid.h:605
const PointDataLeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:477
void setValueOnly(Index, const ValueType &)
Definition: PointDataGrid.h:533
std::shared_ptr< PointDataLeafNode > Ptr
Definition: PointDataGrid.h:243
IndexAllIter beginIndexAll() const
Leaf index iterator.
Definition: PointDataGrid.h:657
ValueOnCIter beginValueOn() const
Definition: PointDataGrid.h:702
typename BaseLeaf::ChildOn ChildOn
Definition: PointDataGrid.h:604
void signedFloodFill(const ValueType &, const ValueType &)
Definition: PointDataGrid.h:589
PointDataLeafNode(const PointDataLeafNode &other)
Construct using deep copy of other PointDataLeafNode.
Definition: PointDataGrid.h:274
void modifyValueAndActiveState(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:559
typename BaseLeaf::template ValueIter< MaskDenseIterator, PointDataLeafNode, const ValueType, ValueAll > ValueAllIter
Definition: PointDataGrid.h:635
typename BaseLeaf::ChildAll ChildAll
Definition: PointDataGrid.h:606
IndexIter< IterT, FilterT > beginIndex(const FilterT &filter) const
typename BaseLeaf::template ValueIter< MaskOffIterator, PointDataLeafNode, const ValueType, ValueOff > ValueOffIter
Definition: PointDataGrid.h:631
ValueOnCIter cendValueOn() const
Definition: PointDataGrid.h:711
ValueOffCIter beginValueOff() const
Definition: PointDataGrid.h:705
void resetDescriptor(const Descriptor::Ptr &replacement)
Replace the descriptor with a new one The new Descriptor must exactly match the old one.
Definition: PointDataGrid.h:863
IndexOffIter beginIndexOff() const
Definition: PointDataGrid.h:667
ChildAllCIter cbeginChildAll() const
Definition: PointDataGrid.h:727
ChildOffIter endChildOff()
Definition: PointDataGrid.h:736
void modifyValueAndActiveStateAndCache(const Coord &, const ModifyOp &, AccessorT &)
Definition: PointDataGrid.h:572
void setValueOnly(const Coord &, const ValueType &)
Definition: PointDataGrid.h:532
ChildAllIter beginChildAll()
Definition: PointDataGrid.h:729
const PointDataLeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition: PointDataGrid.h:479
void setActiveState(const Coord &xyz, bool on)
Definition: PointDataGrid.h:529
ValueOnIter beginValueOn()
Definition: PointDataGrid.h:703
typename BaseLeaf::template ChildIter< MaskOffIterator, const PointDataLeafNode, ChildOff > ChildOffCIter
Definition: PointDataGrid.h:645
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition: PointDataGrid.h:463
IndexIter< ValueAllCIter, FilterT > beginIndexAll(const FilterT &filter) const
Filtered leaf index iterator.
Definition: PointDataGrid.h:678
void assertNonModifiableUnlessZero(const ValueType &value)
Definition: PointDataGrid.h:525
const PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition: PointDataGrid.h:481
ChildOffCIter cbeginChildOff() const
Definition: PointDataGrid.h:724
ChildOffIter beginChildOff()
Definition: PointDataGrid.h:726
ChildOffCIter beginChildOff() const
Definition: PointDataGrid.h:725
void setValueOff(const Coord &xyz)
Definition: PointDataGrid.h:535
bool operator!=(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:450
ValueOffIter endValueOff()
Definition: PointDataGrid.h:716
void setValueOff(Index offset)
Definition: PointDataGrid.h:536
IndexIter< ValueOnCIter, FilterT > beginIndexOn(const FilterT &filter) const
Definition: PointDataGrid.h:683
ChildAllCIter endChildAll() const
Definition: PointDataGrid.h:738
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition: PointDataGrid.h:484
ValueOnCIter cbeginValueOn() const
Definition: PointDataGrid.h:701
typename BaseLeaf::template DenseIter< const PointDataLeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: PointDataGrid.h:649
void clip(const CoordBBox &, const ValueType &value)
Definition: PointDataGrid.h:562
ChildOnCIter endChildOn() const
Definition: PointDataGrid.h:732
void reorderAttributes(const Descriptor::Ptr &replacement)
Reorder attribute set.
Definition: PointDataGrid.h:824
typename BaseLeaf::template ValueIter< MaskOnIterator, const PointDataLeafNode, const ValueType, ValueOn > ValueOnCIter
Definition: PointDataGrid.h:629
ChildOnCIter cendChildOn() const
Definition: PointDataGrid.h:731
ChildAllCIter cendChildAll() const
Definition: PointDataGrid.h:737
PointDataLeafNode()
Default constructor.
Definition: PointDataGrid.h:268
const AttributeSet & attributeSet() const
Retrieve the attribute set.
Definition: PointDataGrid.h:322
void assertNonmodifiable()
Definition: PointDataGrid.h:518
void setValueOffAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:577
ChildAllIter endChildAll()
Definition: PointDataGrid.h:739
IndexIter< ValueOffCIter, FilterT > beginIndexOff(const FilterT &filter) const
Definition: PointDataGrid.h:688
void resetBackground(const ValueType &, const ValueType &newBackground)
Definition: PointDataGrid.h:584
typename NodeMaskType::OffIterator MaskOffIterator
Definition: PointDataGrid.h:609
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &value, TopologyCopy)
Definition: PointDataGrid.h:303
void setValue(const Coord &, const ValueType &)
Definition: PointDataGrid.h:547
ValueAllCIter cendValueAll() const
Definition: PointDataGrid.h:717
~PointDataLeafNode()=default
void negate()
Definition: PointDataGrid.h:591
ChildAllCIter beginChildAll() const
Definition: PointDataGrid.h:728
typename BaseLeaf::ValueAll ValueAll
Definition: PointDataGrid.h:597
std::pair< ValueType, ValueType > ValueTypePair
Definition: PointDataGrid.h:246
void setValuesOn()
Definition: PointDataGrid.h:549
AttributeSet::Descriptor Descriptor
Definition: PointDataGrid.h:249
typename BaseLeaf::ValueOn ValueOn
Definition: PointDataGrid.h:595
ChildOffCIter cendChildOff() const
Definition: PointDataGrid.h:734
void addLeafAndCache(PointDataLeafNode *, AccessorT &)
Definition: PointDataGrid.h:454
void setValueOnlyAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:569
void fill(const ValueType &value)
Definition: PointDataGrid.h:565
typename NodeMaskType::OnIterator MaskOnIterator
Definition: PointDataGrid.h:608
typename BaseLeaf::template ChildIter< MaskOffIterator, PointDataLeafNode, ChildOff > ChildOffIter
Definition: PointDataGrid.h:643
void addLeaf(PointDataLeafNode *)
Definition: PointDataGrid.h:452
void signedFloodFill(const ValueType &)
Definition: PointDataGrid.h:588
ValueOffIter beginValueOff()
Definition: PointDataGrid.h:706
void setValueOn(const Coord &xyz)
Definition: PointDataGrid.h:541
void setActiveState(Index offset, bool on)
Definition: PointDataGrid.h:530
typename BaseLeaf::template ValueIter< MaskOffIterator, const PointDataLeafNode, const ValueType, ValueOff > ValueOffCIter
Definition: PointDataGrid.h:633
IndexOnIter beginIndexOn() const
Definition: PointDataGrid.h:662
typename BaseLeaf::ValueOff ValueOff
Definition: PointDataGrid.h:596
void modifyValue(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:556
ValueOffCIter cendValueOff() const
Definition: PointDataGrid.h:714
typename BaseLeaf::template ChildIter< MaskOnIterator, const PointDataLeafNode, ChildOn > ChildOnCIter
Definition: PointDataGrid.h:641
void fill(const CoordBBox &, const ValueType &, bool)
Definition: PointDataGrid.h:1539
ValueOffCIter endValueOff() const
Definition: PointDataGrid.h:715
typename BaseLeaf::template ValueIter< MaskOnIterator, PointDataLeafNode, const ValueType, ValueOn > ValueOnIter
Definition: PointDataGrid.h:627
PointDataLeafNode * probeLeaf(const Coord &)
Definition: PointDataGrid.h:470
T ValueType
Definition: PointDataGrid.h:245
PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition: PointDataGrid.h:472
ValueOnCIter endValueOn() const
Definition: PointDataGrid.h:712
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: PointDataGrid.h:610
ValueAllCIter beginValueAll() const
Definition: PointDataGrid.h:708
typename BaseLeaf::template DenseIter< PointDataLeafNode, ValueType, ChildAll > ChildAllIter
Definition: PointDataGrid.h:647
PointDataLeafNode(const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Construct using supplied origin, value and active status.
Definition: PointDataGrid.h:280
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &, const T &, TopologyCopy)
Definition: PointDataGrid.h:310
typename BaseLeaf::template ValueIter< MaskDenseIterator, const PointDataLeafNode, const ValueType, ValueAll > ValueAllCIter
Definition: PointDataGrid.h:637
void setValueOn(const Coord &, const ValueType &)
Definition: PointDataGrid.h:544
ValueAllIter beginValueAll()
Definition: PointDataGrid.h:709
std::vector< ValueType > IndexArray
Definition: PointDataGrid.h:247
Typed class for storing attribute data.
Definition: AttributeArray.h:533
A forward iterator over array indices in a single voxel.
Definition: IndexIterator.h:65
Definition: InternalNode.h:34
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:30
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition: LeafNode.h:38
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:121
Definition: RootNode.h:39
Definition: NodeMasks.h:271
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition: NodeMasks.h:308
Definition: NodeMasks.h:240
Definition: NodeMasks.h:209
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
OPENVDB_API void bloscDecompress(char *uncompressedBuffer, const size_t expectedBytes, const size_t bufferBytes, const char *compressedBuffer)
Decompress into the supplied buffer. Will throw if decompression fails or uncompressed buffer has ins...
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
void writeCompressedValuesSize(std::ostream &os, const T *srcBuf, Index srcCount)
Definition: PointDataGrid.h:139
void writeCompressedValues(std::ostream &os, PointDataIndex32 *srcBuf, Index srcCount, const util::NodeMask< 3 > &, const util::NodeMask< 3 > &, bool)
openvdb::io::writeCompressedValues specialized on PointDataIndex32 arrays to ignore the value mask,...
Definition: PointDataGrid.h:106
void readCompressedValues(std::istream &is, PointDataIndex32 *destBuf, Index destCount, const util::NodeMask< 3 > &, bool)
openvdb::io::readCompressedValues specialized on PointDataIndex32 arrays to ignore the value mask,...
Definition: PointDataGrid.h:46
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
@ ALL
Definition: IndexIterator.h:43
@ NONE
Definition: IndexIterator.h:42
void uninitialize()
Global deregistration of point data-related types.
void initialize()
Global registration of point data-related types.
void setStreamingMode(PointDataTreeT &tree, bool on=true)
Toggle the streaming mode on all attributes in the tree to collapse the attributes after deconstructi...
Definition: PointDataGrid.h:1594
void prefetch(PointDataTreeT &tree, bool position=true, bool otherAttributes=true)
Sequentially pre-fetch all delayed-load voxel and attribute data from disk in order to accelerate sub...
Definition: PointDataGrid.h:1607
void compactAttributes(PointDataTreeT &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:527
Index64 pointCount(const PointDataTreeT &tree, const FilterT &filter=NullFilter(), const bool inCoreOnly=false, const bool threaded=true)
Count the total number of points in a PointDataTree.
Definition: PointCount.h:88
void appendAttribute(PointDataTreeT &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, const Metadata *defaultValue=nullptr, const bool hidden=false, const bool transient=false)
Appends a new attribute to the VDB tree (this method does not require a templated AttributeType)
Definition: PointAttribute.h:245
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:380
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:468
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:63
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:314
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1577
std::string Name
Definition: Name.h:17
const char * typeNameAsString< Vec3f >()
Definition: Types.h:417
Index32 Index
Definition: Types.h:54
int32_t Int32
Definition: Types.h:56
uint64_t Index64
Definition: Types.h:53
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:69
PointIndex< Index32, 1 > PointDataIndex32
Definition: Types.h:181
Definition: Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t *poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
Definition: pnanovdb_validate_strides.h:20
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition: Types.h:157
A list of types (not necessarily unique)
Definition: TypeList.h:366
Leaf nodes that require multi-pass I/O must inherit from this struct.
Definition: io.h:124
Similiar to ValueConverter, but allows for tree configuration conversion to a PointDataTree....
Definition: PointDataGrid.h:1701
typename TreeType::RootNodeType RootNodeT
Definition: PointDataGrid.h:1702
typename internal::PointDataNodeChain< RootNodeT, RootNodeT::LEVEL >::Type NodeChainT
Definition: PointDataGrid.h:1703
typename PointDataNodeChain< ChildT, HeadLevel-1 >::Type SubtreeT
Definition: PointDataGrid.h:1679
typename SubtreeT::template Append< InternalNodeT > Type
Definition: PointDataGrid.h:1681
Recursive node chain which generates a openvdb::TypeList value converted types of nodes to PointDataG...
Definition: PointDataGrid.h:1668
typename PointDataNodeChain< typename HeadT::ChildNodeType, HeadLevel-1 >::Type SubtreeT
Definition: PointDataGrid.h:1669
typename SubtreeT::template Append< RootNodeT > Type
Definition: PointDataGrid.h:1671
Definition: TreeIterator.h:60
Definition: LeafNode.h:211
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:251
Definition: LeafNode.h:211
Definition: LeafNode.h:211
Definition: LeafNode.h:260
Definition: LeafNode.h:210
Definition: LeafNode.h:219
Definition: LeafNode.h:210
Definition: LeafNode.h:210
Definition: LeafNode.h:923
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202