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;
49 using compression::bloscDecompress;
51 const bool seek = destBuf ==
nullptr;
54 const size_t maximumBytes = std::numeric_limits<uint16_t>::max();
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));
76 if (bytes16 == std::numeric_limits<uint16_t>::max()) {
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);
94 std::unique_ptr<char[]> buffer = bloscDecompress( bloscBuffer.get(),
97 std::memcpy(destBuf, buffer.get(), destBytes);
110 using compression::bloscCompress;
113 const size_t maximumBytes = std::numeric_limits<uint16_t>::max();
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);
141 using compression::bloscCompressedSize;
143 const size_t srcBytes = srcCount*
sizeof(T);
144 const size_t maximumBytes = std::numeric_limits<uint16_t>::max();
145 if (srcBytes >= maximumBytes) {
147 maximumBytes <<
" bytes in voxel values.")
150 const char* charBuffer =
reinterpret_cast<const char*
>(srcBuf);
153 size_t compressedBytes = bloscCompressedSize(charBuffer, srcBytes);
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>
466 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
467 return reinterpret_cast<NodeT*
>(
this);
471 template<
typename AccessorT>
478 template<
typename AccessorT>
480 template<
typename AccessorT>
483 template<
typename NodeT,
typename AccessorT>
487 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
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;
506#if OPENVDB_ABI_VERSION_NUMBER >= 10
507 Index64 memUsageIfLoaded()
const;
510 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
522 assert(
false &&
"Cannot modify voxel values in a PointDataTree.");
529 if (
value != zeroVal<T>()) this->assertNonmodifiable();
555 template<
typename ModifyOp>
558 template<
typename ModifyOp>
561 template<
typename ModifyOp>
567 void fill(
const CoordBBox&,
const ValueType&,
bool);
569 void fill(
const ValueType&,
bool);
571 template<
typename AccessorT>
574 template<
typename ModifyOp,
typename AccessorT>
576 assertNonmodifiable();
579 template<
typename AccessorT>
582 template<
typename AccessorT>
584 BaseLeaf::setActiveStateAndCache(xyz, on, parent);
588 assertNonModifiableUnlessZero(newBackground);
596 friend class ::TestPointDataLeaf;
604 uint16_t mVoxelBufferSize = 0;
663 return this->beginIndex<ValueAllCIter, NullFilter>(filter);
668 return this->beginIndex<ValueOnCIter, NullFilter>(filter);
673 return this->beginIndex<ValueOffCIter, NullFilter>(filter);
676 template<
typename IterT,
typename FilterT>
680 template<
typename FilterT>
683 return this->beginIndex<ValueAllCIter, FilterT>(filter);
685 template<
typename FilterT>
688 return this->beginIndex<ValueOnCIter, FilterT>(filter);
690 template<
typename FilterT>
693 return this->beginIndex<ValueOffCIter, FilterT>(filter);
697 IndexVoxelIter beginIndexVoxel(
const Coord& ijk)
const;
700 template<
typename FilterT>
703#define VMASK_ this->getValueMask()
750template<
typename T, Index Log2Dim>
751inline AttributeSet::UniquePtr
755 std::swap(ptr, mAttributeSet);
759template<
typename T, Index Log2Dim>
764 if (descriptor->size() != 1 ||
765 descriptor->find(
"P") == AttributeSet::INVALID_POS ||
766 descriptor->valueType(0) != typeNameAsString<Vec3f>())
771 mAttributeSet.reset(
new AttributeSet(descriptor, arrayLength, lock));
774template<
typename T, Index Log2Dim>
779 mAttributeSet.reset(
new AttributeSet(*mAttributeSet, 0, lock));
787 if (updateValueMask) this->setValuesOff();
790template<
typename T, Index Log2Dim>
794 return pos < mAttributeSet->
size();
797template<
typename T, Index Log2Dim>
801 const size_t pos = mAttributeSet->find(attributeName);
802 return pos != AttributeSet::INVALID_POS;
805template<
typename T, Index Log2Dim>
808 const size_t pos,
const Index strideOrTotalSize,
809 const bool constantStride,
814 expected, replacement, pos, strideOrTotalSize, constantStride, metadata, lock);
817template<
typename T, Index Log2Dim>
820 const Descriptor& expected, Descriptor::Ptr& replacement)
825template<
typename T, Index Log2Dim>
832template<
typename T, Index Log2Dim>
839template<
typename T, Index Log2Dim>
843 for (
size_t i = 0; i < mAttributeSet->size(); i++) {
849template<
typename T, Index Log2Dim>
857 if (!allowMismatchingDescriptors && mAttributeSet->descriptor() != attributeSet->
descriptor()) {
861 mAttributeSet.reset(attributeSet);
864template<
typename T, Index Log2Dim>
871template<
typename T, Index Log2Dim>
875 if (offsets.size() != LeafNodeType::NUM_VALUES) {
879 for (
Index index = 0; index < offsets.size(); ++index) {
880 setOffsetOnly(index, offsets[index]);
883 if (updateValueMask) this->updateValueMask();
886template<
typename T, Index Log2Dim>
891 for (
Index index = 1; index < BaseLeaf::SIZE; ++index) {
892 if (this->getValue(index-1) > this->getValue(index)) {
898 for (
size_t attributeIndex = 1; attributeIndex < mAttributeSet->size(); ++attributeIndex ) {
899 if (mAttributeSet->getConst(attributeIndex-1)->size() != mAttributeSet->getConst(attributeIndex)->size()) {
905 if (mAttributeSet->size() > 0 && this->getValue(BaseLeaf::SIZE-1) != mAttributeSet->getConst(0)->size()) {
910template<
typename T, Index Log2Dim>
915 return *mAttributeSet->get(pos);
918template<
typename T, Index Log2Dim>
923 return *mAttributeSet->getConst(pos);
926template<
typename T, Index Log2Dim>
930 return this->attributeArray(pos);
933template<
typename T, Index Log2Dim>
937 const size_t pos = mAttributeSet->find(attributeName);
939 return *mAttributeSet->get(pos);
942template<
typename T, Index Log2Dim>
946 const size_t pos = mAttributeSet->find(attributeName);
948 return *mAttributeSet->getConst(pos);
951template<
typename T, Index Log2Dim>
955 return this->attributeArray(attributeName);
958template<
typename T, Index Log2Dim>
970template<
typename T, Index Log2Dim>
974 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
975 return this->groupHandle(index);
978template<
typename T, Index Log2Dim>
990template<
typename T, Index Log2Dim>
994 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
995 return this->groupWriteHandle(index);
998template<
typename T, Index Log2Dim>
999template<
typename ValueIterT,
typename FilterT>
1005 if (filter.state() == index::NONE) {
1011 FilterT newFilter(filter);
1012 newFilter.reset(*
this);
1018 ValueIterT valueIter = IterTraitsT::begin(*
this);
1023template<
typename T, Index Log2Dim>
1027 const Index index = LeafNodeType::coordToOffset(ijk);
1028 assert(index < BaseLeaf::SIZE);
1029 const ValueType end = this->getValue(index);
1034template<
typename T, Index Log2Dim>
1042template<
typename T, Index Log2Dim>
1043template<
typename FilterT>
1048 FilterT newFilter(filter);
1049 newFilter.reset(*
this);
1053template<
typename T, Index Log2Dim>
1057 return this->getLastValue();
1060template<
typename T, Index Log2Dim>
1064 if (this->isEmpty())
return 0;
1065 else if (this->isDense())
return this->
pointCount();
1069template<
typename T, Index Log2Dim>
1073 if (this->isEmpty())
return this->
pointCount();
1074 else if (this->isDense())
return 0;
1075 return iterCount(this->beginIndexOff());
1078template<
typename T, Index Log2Dim>
1082 if (!this->attributeSet().descriptor().hasGroup(groupName)) {
1085 GroupFilter filter(groupName, this->attributeSet());
1086 if (filter.
state() == index::ALL) {
1089 return iterCount(this->beginIndexAll(filter));
1093template<
typename T, Index Log2Dim>
1098 for (
Index n = 0; n < LeafNodeType::NUM_VALUES; n++) {
1099 end = this->getValue(n);
1100 this->setValueMask(n, (end - start) > 0);
1105template<
typename T, Index Log2Dim>
1109 this->buffer().
setValue(offset, val);
1110 this->setValueMaskOn(offset);
1113template<
typename T, Index Log2Dim>
1117 this->buffer().
setValue(offset, val);
1120template<
typename T, Index Log2Dim>
1124 BaseLeaf::readTopology(is, fromHalf);
1127template<
typename T, Index Log2Dim>
1131 BaseLeaf::writeTopology(os, toHalf);
1134template<
typename T, Index Log2Dim>
1141 mAttributeSet->size() +
1142 mAttributeSet->size() +
1146template<
typename T, Index Log2Dim>
1150 this->readBuffers(is, CoordBBox::inf(), fromHalf);
1153template<
typename T, Index Log2Dim>
1162 std::string key(
"paged:" + std::to_string(index));
1163 auto it = auxData.find(key);
1164 if (it != auxData.end()) {
1172 std::string key(
"paged:" + std::to_string(index));
1173 auto it = auxData.find(key);
1174 if (it != auxData.end()) {
1175 return *(boost::any_cast<compression::PagedInputStream::Ptr>(it->second));
1180 return *pagedStream;
1186 std::string matchingKey(
"hasMatchingDescriptor");
1187 auto itMatching = auxData.find(matchingKey);
1188 return itMatching != auxData.end();
1193 std::string matchingKey(
"hasMatchingDescriptor");
1194 std::string descriptorKey(
"descriptorPtr");
1195 auto itMatching = auxData.find(matchingKey);
1196 auto itDescriptor = auxData.find(descriptorKey);
1202 const Descriptor::Ptr descriptor)
1204 std::string descriptorKey(
"descriptorPtr");
1205 std::string matchingKey(
"hasMatchingDescriptor");
1206 auto itMatching = auxData.find(matchingKey);
1207 if (itMatching == auxData.end()) {
1216 std::string descriptorKey(
"descriptorPtr");
1217 auto itDescriptor = auxData.find(descriptorKey);
1218 assert(itDescriptor != auxData.end());
1219 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1230 const Index pass(
static_cast<uint16_t
>(meta->pass()));
1231 const Index maximumPass(
static_cast<uint16_t
>(meta->pass() >> 16));
1233 const Index attributes = (maximumPass - 4) / 2;
1237 is.read(
reinterpret_cast<char*
>(&mVoxelBufferSize),
sizeof(uint16_t));
1238 Local::clearMatchingDescriptor(meta->auxData());
1240 else if (pass == 1) {
1242 if (Local::hasMatchingDescriptor(meta->auxData())) {
1243 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1244 mAttributeSet->resetDescriptor(descriptor,
true);
1248 is.read(
reinterpret_cast<char*
>(&header),
sizeof(uint8_t));
1249 mAttributeSet->readDescriptor(is);
1250 if (header & uint8_t(1)) {
1252 Local::insertDescriptor(meta->auxData(), descriptor);
1256 if (header & uint8_t(2)) {
1257 uint64_t bytesToSkip;
1258 is.read(
reinterpret_cast<char*
>(&bytesToSkip),
sizeof(uint64_t));
1259 if (bytesToSkip > uint64_t(0)) {
1260 auto metadata = io::getStreamMetadataPtr(is);
1261 if (metadata && metadata->seekable()) {
1262 is.seekg(bytesToSkip, std::ios_base::cur);
1265 std::vector<uint8_t> tempData(bytesToSkip);
1266 is.read(
reinterpret_cast<char*
>(&tempData[0]), bytesToSkip);
1271 if (header > uint8_t(3)) {
1275 mAttributeSet->readMetadata(is);
1277 else if (pass < (attributes + 2)) {
1279 const size_t attributeIndex = pass - 2;
1281 mAttributeSet->get(attributeIndex) :
nullptr;
1284 Local::getOrInsertPagedStream(meta->auxData(),
static_cast<Index>(attributeIndex));
1290 else if (pass == attributes + 2) {
1293 const Index passValue(meta->pass());
1297 nonConstMeta.
setPass(mVoxelBufferSize);
1300 BaseLeaf::readBuffers(is, fromHalf);
1303 nonConstMeta.
setPass(passValue);
1305 else if (pass < (attributes*2 + 3)) {
1307 const Index attributeIndex = pass - attributes - 3;
1309 mAttributeSet->get(attributeIndex) :
nullptr;
1312 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1318 if (pass > attributes + 3) {
1319 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1322 else if (pass < buffers()) {
1324 const Index attributeIndex = pass - attributes - 4;
1325 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1329template<
typename T, Index Log2Dim>
1338 std::string key(
"paged:" + std::to_string(index));
1339 auto it = auxData.find(key);
1340 if (it != auxData.end()) {
1350 std::string key(
"paged:" + std::to_string(index));
1351 auto it = auxData.find(key);
1352 if (it != auxData.end()) {
1353 return *(boost::any_cast<compression::PagedOutputStream::Ptr>(it->second));
1358 return *pagedStream;
1363 const Descriptor::Ptr descriptor)
1365 std::string descriptorKey(
"descriptorPtr");
1366 std::string matchingKey(
"hasMatchingDescriptor");
1367 auto itMatching = auxData.find(matchingKey);
1368 auto itDescriptor = auxData.find(descriptorKey);
1369 if (itMatching == auxData.end()) {
1372 assert(itDescriptor == auxData.end());
1377 bool matching = boost::any_cast<bool>(itMatching->second);
1378 if (!matching)
return;
1379 assert(itDescriptor != auxData.end());
1382 const Descriptor::Ptr existingDescriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1383 if (*existingDescriptor != *descriptor) {
1391 std::string matchingKey(
"hasMatchingDescriptor");
1392 auto itMatching = auxData.find(matchingKey);
1394 if (itMatching == auxData.end())
return false;
1396 if (!boost::any_cast<bool>(itMatching->second))
return false;
1402 std::string descriptorKey(
"descriptorPtr");
1403 auto itDescriptor = auxData.find(descriptorKey);
1405 if (itDescriptor == auxData.end())
return nullptr;
1407 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1414 std::string matchingKey(
"hasMatchingDescriptor");
1415 std::string descriptorKey(
"descriptorPtr");
1416 auto itMatching = auxData.find(matchingKey);
1417 auto itDescriptor = auxData.find(descriptorKey);
1429 const Index pass(
static_cast<uint16_t
>(meta->pass()));
1434 if (meta->countingPasses()) {
1435 const Index requiredPasses = this->buffers();
1436 if (requiredPasses > pass) {
1437 meta->setPass(requiredPasses);
1442 const Index maximumPass(
static_cast<uint16_t
>(meta->pass() >> 16));
1443 const Index attributes = (maximumPass - 4) / 2;
1447 io::writeCompressedValuesSize(os, this->buffer().data(), SIZE);
1449 Local::insertDescriptor(meta->auxData(), mAttributeSet->descriptorPtr());
1451 else if (pass == 1) {
1453 bool matchingDescriptor = Local::hasMatchingDescriptor(meta->auxData());
1454 if (matchingDescriptor) {
1455 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1459 os.write(
reinterpret_cast<const char*
>(&header),
sizeof(uint8_t));
1460 mAttributeSet->writeDescriptor(os,
false);
1466 os.write(
reinterpret_cast<const char*
>(&header),
sizeof(uint8_t));
1467 mAttributeSet->writeDescriptor(os,
false);
1469 mAttributeSet->writeMetadata(os,
false,
true);
1471 else if (pass < attributes + 2) {
1473 const Index attributeIndex = pass - 2;
1476 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1479 mAttributeSet->getConst(attributeIndex) :
nullptr;
1482 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1488 else if (pass == attributes + 2) {
1489 const Index attributeIndex = pass - 3;
1490 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1492 BaseLeaf::writeBuffers(os, toHalf);
1494 else if (pass < (attributes*2 + 3)) {
1496 const Index attributeIndex = pass - attributes - 3;
1498 if (pass > attributes + 2) {
1499 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1502 mAttributeSet->getConst(attributeIndex) :
nullptr;
1505 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1511 else if (pass < buffers()) {
1512 Local::clearMatchingDescriptor(meta->auxData());
1514 const Index attributeIndex = pass - attributes - 4;
1515 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1519template<
typename T, Index Log2Dim>
1523 return BaseLeaf::memUsage() + mAttributeSet->
memUsage();
1526#if OPENVDB_ABI_VERSION_NUMBER >= 10
1527template<
typename T, Index Log2Dim>
1535template<
typename T, Index Log2Dim>
1539 BaseLeaf::evalActiveBoundingBox(bbox, visitVoxels);
1542template<
typename T, Index Log2Dim>
1546 return BaseLeaf::getNodeBoundingBox();
1549template<
typename T, Index Log2Dim>
1555 this->assertNonModifiableUnlessZero(
value);
1560 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1562 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1564 const Index offset = offsetXY + (z & (DIM-1u));
1565 this->setValueMask(offset, active);
1571template<
typename T, Index Log2Dim>
1575 this->assertNonModifiableUnlessZero(
value);
1579 if (active) this->setValuesOn();
1580 else this->setValuesOff();
1587template <
typename Po
intDataTreeT>
1588inline AttributeSet::Descriptor::Ptr
1591 auto leafIter = tree.beginLeaf();
1592 if (!leafIter)
return nullptr;
1594 const AttributeSet::Descriptor& descriptor = leafIter->attributeSet().descriptor();
1595 auto newDescriptor = std::make_shared<AttributeSet::Descriptor>(descriptor);
1596 for (; leafIter; ++leafIter) {
1597 leafIter->resetDescriptor(newDescriptor);
1600 return newDescriptor;
1604template <
typename Po
intDataTreeT>
1608 auto leafIter = tree.beginLeaf();
1609 for (; leafIter; ++leafIter) {
1610 for (
size_t i = 0; i < leafIter->attributeSet().size(); i++) {
1611 leafIter->attributeArray(i).setStreaming(on);
1617template <
typename Po
intDataTreeT>
1619prefetch(PointDataTreeT& tree,
bool position,
bool otherAttributes)
1624 auto leaf = tree.cbeginLeaf();
1627 const auto& attributeSet = leaf->attributeSet();
1631 for ( ; leaf; ++leaf) {
1632 leaf->buffer().data();
1637 size_t positionIndex = attributeSet.find(
"P");
1639 if (position && positionIndex != AttributeSet::INVALID_POS) {
1640 for (leaf = tree.cbeginLeaf(); leaf; ++leaf) {
1641 assert(leaf->hasAttribute(positionIndex));
1642 leaf->constAttributeArray(positionIndex).loadData();
1648 if (otherAttributes) {
1649 const size_t attributes = attributeSet.size();
1650 for (
size_t attributeIndex = 0; attributeIndex < attributes; attributeIndex++) {
1651 if (attributeIndex == positionIndex)
continue;
1652 for (leaf = tree.cbeginLeaf(); leaf; ++leaf) {
1653 assert(leaf->hasAttribute(attributeIndex));
1654 leaf->constAttributeArray(attributeIndex).loadData();
1678template<
typename HeadT,
int HeadLevel>
1683 using Type =
typename SubtreeT::template Append<RootNodeT>;
1688template <
typename ChildT, Index Log2Dim,
int HeadLevel>
1693 using Type =
typename SubtreeT::template Append<InternalNodeT>;
1698template <
typename ChildT, Index Log2Dim>
1712template <
typename TreeType>
1731template<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:1290
#define VMASK_
Definition PointDataGrid.h:703
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:571
Definition Exceptions.h:57
Definition Exceptions.h:58
Definition Exceptions.h:60
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:650
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:644
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:207
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition StreamCompression.h:216
void setInputStream(std::istream &is)
Definition StreamCompression.h:221
std::shared_ptr< PagedInputStream > Ptr
Definition StreamCompression.h:209
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition StreamCompression.h:244
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition StreamCompression.h:253
void setOutputStream(std::ostream &os)
Definition StreamCompression.h:258
std::shared_ptr< PagedOutputStream > Ptr
Definition StreamCompression.h:246
void flush()
Manually flushes the current page to disk if non-zero.
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:249
const Coord & min() const
Definition Coord.h:321
const Coord & max() const
Definition Coord.h:322
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:724
void setValueOn(Index offset)
Definition PointDataGrid.h:545
void setValueOff(const Coord &, const ValueType &)
Definition PointDataGrid.h:541
ChildOnCIter beginChildOn() const
Definition PointDataGrid.h:725
ChildOnIter beginChildOn()
Definition PointDataGrid.h:726
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &parent)
Definition PointDataGrid.h:583
ValueOnIter endValueOn()
Definition PointDataGrid.h:716
AttributeArray::Ptr appendAttribute(const Descriptor &expected, Descriptor::Ptr &replacement, const size_t pos, const Index strideOrTotalSize=1, const bool constantStride=true, const Metadata *metadata=nullptr, const AttributeArray::ScopedRegistryLock *lock=nullptr)
Append an attribute to the leaf.
Definition PointDataGrid.h:807
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:707
typename BaseLeaf::template ChildIter< MaskOnIterator, PointDataLeafNode, ChildOn > ChildOnIter
Definition PointDataGrid.h:642
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:736
ValueAllIter endValueAll()
Definition PointDataGrid.h:722
void modifyValue(Index, const ModifyOp &)
Definition PointDataGrid.h:556
void setValueOn(Index, const ValueType &)
Definition PointDataGrid.h:548
void setValuesOff()
Definition PointDataGrid.h:553
ValueAllCIter endValueAll() const
Definition PointDataGrid.h:721
const PointDataLeafNode * probeLeaf(const Coord &) const
Definition PointDataGrid.h:482
ChildOffCIter endChildOff() const
Definition PointDataGrid.h:738
void setValueOff(Index, const ValueType &)
Definition PointDataGrid.h:542
PointDataLeafNode(PartialCreate, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition PointDataGrid.h:314
ValueAllCIter cbeginValueAll() const
Definition PointDataGrid.h:710
typename BaseLeaf::ChildOff ChildOff
Definition PointDataGrid.h:608
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:536
std::shared_ptr< PointDataLeafNode > Ptr
Definition PointDataGrid.h:243
IndexAllIter beginIndexAll() const
Leaf index iterator.
Definition PointDataGrid.h:660
ValueOnCIter beginValueOn() const
Definition PointDataGrid.h:705
typename BaseLeaf::ChildOn ChildOn
Definition PointDataGrid.h:607
void signedFloodFill(const ValueType &, const ValueType &)
Definition PointDataGrid.h:592
PointDataLeafNode(const PointDataLeafNode &other)
Construct using deep copy of other PointDataLeafNode.
Definition PointDataGrid.h:274
void modifyValueAndActiveState(const Coord &, const ModifyOp &)
Definition PointDataGrid.h:562
typename BaseLeaf::template ValueIter< MaskDenseIterator, PointDataLeafNode, const ValueType, ValueAll > ValueAllIter
Definition PointDataGrid.h:638
typename BaseLeaf::ChildAll ChildAll
Definition PointDataGrid.h:609
IndexIter< IterT, FilterT > beginIndex(const FilterT &filter) const
typename BaseLeaf::template ValueIter< MaskOffIterator, PointDataLeafNode, const ValueType, ValueOff > ValueOffIter
Definition PointDataGrid.h:634
ValueOnCIter cendValueOn() const
Definition PointDataGrid.h:714
ValueOffCIter beginValueOff() const
Definition PointDataGrid.h:708
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:866
IndexOffIter beginIndexOff() const
Definition PointDataGrid.h:670
ChildAllCIter cbeginChildAll() const
Definition PointDataGrid.h:730
ChildOffIter endChildOff()
Definition PointDataGrid.h:739
void modifyValueAndActiveStateAndCache(const Coord &, const ModifyOp &, AccessorT &)
Definition PointDataGrid.h:575
void setValueOnly(const Coord &, const ValueType &)
Definition PointDataGrid.h:535
ChildAllIter beginChildAll()
Definition PointDataGrid.h:732
void renameAttributes(const Descriptor &expected, Descriptor::Ptr &replacement)
Rename attributes in attribute set (order must remain the same).
Definition PointDataGrid.h:834
const PointDataLeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition PointDataGrid.h:479
void setActiveState(const Coord &xyz, bool on)
Definition PointDataGrid.h:532
ValueOnIter beginValueOn()
Definition PointDataGrid.h:706
typename BaseLeaf::template ChildIter< MaskOffIterator, const PointDataLeafNode, ChildOff > ChildOffCIter
Definition PointDataGrid.h:648
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition PointDataGrid.h:463
IndexIter< ValueAllCIter, FilterT > beginIndexAll(const FilterT &filter) const
Filtered leaf index iterator.
Definition PointDataGrid.h:681
void assertNonModifiableUnlessZero(const ValueType &value)
Definition PointDataGrid.h:528
const PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition PointDataGrid.h:481
ChildOffCIter cbeginChildOff() const
Definition PointDataGrid.h:727
ChildOffIter beginChildOff()
Definition PointDataGrid.h:729
ChildOffCIter beginChildOff() const
Definition PointDataGrid.h:728
void dropAttributes(const std::vector< size_t > &pos, const Descriptor &expected, Descriptor::Ptr &replacement)
Drop list of attributes.
Definition PointDataGrid.h:819
void setValueOff(const Coord &xyz)
Definition PointDataGrid.h:538
bool operator!=(const PointDataLeafNode &other) const
Definition PointDataGrid.h:450
ValueOffIter endValueOff()
Definition PointDataGrid.h:719
void setValueOff(Index offset)
Definition PointDataGrid.h:539
IndexIter< ValueOnCIter, FilterT > beginIndexOn(const FilterT &filter) const
Definition PointDataGrid.h:686
ChildAllCIter endChildAll() const
Definition PointDataGrid.h:741
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition PointDataGrid.h:484
ValueOnCIter cbeginValueOn() const
Definition PointDataGrid.h:704
typename BaseLeaf::template DenseIter< const PointDataLeafNode, const ValueType, ChildAll > ChildAllCIter
Definition PointDataGrid.h:652
void clip(const CoordBBox &, const ValueType &value)
Definition PointDataGrid.h:565
ChildOnCIter endChildOn() const
Definition PointDataGrid.h:735
void reorderAttributes(const Descriptor::Ptr &replacement)
Reorder attribute set.
Definition PointDataGrid.h:827
typename BaseLeaf::template ValueIter< MaskOnIterator, const PointDataLeafNode, const ValueType, ValueOn > ValueOnCIter
Definition PointDataGrid.h:632
ChildOnCIter cendChildOn() const
Definition PointDataGrid.h:734
ChildAllCIter cendChildAll() const
Definition PointDataGrid.h:740
PointDataLeafNode()
Default constructor.
Definition PointDataGrid.h:268
const AttributeSet & attributeSet() const
Retrieve the attribute set.
Definition PointDataGrid.h:322
void assertNonmodifiable()
Definition PointDataGrid.h:521
Index64 memUsageIfLoaded() const
Definition PointDataGrid.h:1529
void setValueOffAndCache(const Coord &, const ValueType &, AccessorT &)
Definition PointDataGrid.h:580
ChildAllIter endChildAll()
Definition PointDataGrid.h:742
IndexIter< ValueOffCIter, FilterT > beginIndexOff(const FilterT &filter) const
Definition PointDataGrid.h:691
void resetBackground(const ValueType &, const ValueType &newBackground)
Definition PointDataGrid.h:587
typename NodeMaskType::OffIterator MaskOffIterator
Definition PointDataGrid.h:612
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &value, TopologyCopy)
Definition PointDataGrid.h:303
void setValue(const Coord &, const ValueType &)
Definition PointDataGrid.h:550
ValueAllCIter cendValueAll() const
Definition PointDataGrid.h:720
~PointDataLeafNode()=default
void negate()
Definition PointDataGrid.h:594
ChildAllCIter beginChildAll() const
Definition PointDataGrid.h:731
typename BaseLeaf::ValueAll ValueAll
Definition PointDataGrid.h:600
std::pair< ValueType, ValueType > ValueTypePair
Definition PointDataGrid.h:246
void setValuesOn()
Definition PointDataGrid.h:552
AttributeSet::Descriptor Descriptor
Definition PointDataGrid.h:249
typename BaseLeaf::ValueOn ValueOn
Definition PointDataGrid.h:598
ChildOffCIter cendChildOff() const
Definition PointDataGrid.h:737
void addLeafAndCache(PointDataLeafNode *, AccessorT &)
Definition PointDataGrid.h:454
void setValueOnlyAndCache(const Coord &, const ValueType &, AccessorT &)
Definition PointDataGrid.h:572
void fill(const ValueType &value)
Definition PointDataGrid.h:568
typename NodeMaskType::OnIterator MaskOnIterator
Definition PointDataGrid.h:611
typename BaseLeaf::template ChildIter< MaskOffIterator, PointDataLeafNode, ChildOff > ChildOffIter
Definition PointDataGrid.h:646
void addLeaf(PointDataLeafNode *)
Definition PointDataGrid.h:452
void signedFloodFill(const ValueType &)
Definition PointDataGrid.h:591
ValueOffIter beginValueOff()
Definition PointDataGrid.h:709
void setValueOn(const Coord &xyz)
Definition PointDataGrid.h:544
void setActiveState(Index offset, bool on)
Definition PointDataGrid.h:533
typename BaseLeaf::template ValueIter< MaskOffIterator, const PointDataLeafNode, const ValueType, ValueOff > ValueOffCIter
Definition PointDataGrid.h:636
IndexOnIter beginIndexOn() const
Definition PointDataGrid.h:665
typename BaseLeaf::ValueOff ValueOff
Definition PointDataGrid.h:599
void modifyValue(const Coord &, const ModifyOp &)
Definition PointDataGrid.h:559
ValueOffCIter cendValueOff() const
Definition PointDataGrid.h:717
Index64 memUsage() const
Definition PointDataGrid.h:1521
typename BaseLeaf::template ChildIter< MaskOnIterator, const PointDataLeafNode, ChildOn > ChildOnCIter
Definition PointDataGrid.h:644
void fill(const CoordBBox &, const ValueType &, bool)
Definition PointDataGrid.h:1551
ValueOffCIter endValueOff() const
Definition PointDataGrid.h:718
typename BaseLeaf::template ValueIter< MaskOnIterator, PointDataLeafNode, const ValueType, ValueOn > ValueOnIter
Definition PointDataGrid.h:630
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:715
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition PointDataGrid.h:613
ValueAllCIter beginValueAll() const
Definition PointDataGrid.h:711
typename BaseLeaf::template DenseIter< PointDataLeafNode, ValueType, ChildAll > ChildAllIter
Definition PointDataGrid.h:650
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:640
void setValueOn(const Coord &, const ValueType &)
Definition PointDataGrid.h:547
ValueAllIter beginValueAll()
Definition PointDataGrid.h:712
std::vector< ValueType > IndexArray
Definition PointDataGrid.h:247
Typed class for storing attribute data.
Definition AttributeArray.h:545
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 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
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition Compression.h:645
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition Compression.h:465
size_t writeCompressedValuesSize(ValueT *srcBuf, Index srcCount, const MaskT &valueMask, uint8_t maskMetadata, bool toHalf, uint32_t compress)
Definition Compression.h:591
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:1606
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:1619
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
bool isGroup(const AttributeArray &array)
Definition AttributeGroup.h:63
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
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:1589
std::string Name
Definition Name.h:17
Index32 Index
Definition Types.h:54
OPENVDB_IMPORT void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types....
OPENVDB_IMPORT void uninitialize()
Global deregistration of native Grid, Transform, Metadata and Point attribute types.
T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:70
int32_t Int32
Definition Types.h:56
uint64_t Index64
Definition Types.h:53
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:484
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:1713
typename TreeType::RootNodeType RootNodeT
Definition PointDataGrid.h:1714
typename internal::PointDataNodeChain< RootNodeT, RootNodeT::LEVEL >::Type NodeChainT
Definition PointDataGrid.h:1715
typename PointDataNodeChain< ChildT, HeadLevel-1 >::Type SubtreeT
Definition PointDataGrid.h:1691
typename SubtreeT::template Append< InternalNodeT > Type
Definition PointDataGrid.h:1693
Recursive node chain which generates a openvdb::TypeList value converted types of nodes to PointDataG...
Definition PointDataGrid.h:1680
typename PointDataNodeChain< typename HeadT::ChildNodeType, HeadLevel-1 >::Type SubtreeT
Definition PointDataGrid.h:1681
typename SubtreeT::template Append< RootNodeT > Type
Definition PointDataGrid.h:1683
Definition TreeIterator.h:60
Definition LeafNode.h:212
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition LeafNode.h:252
Definition LeafNode.h:212
Definition LeafNode.h:212
Definition LeafNode.h:261
Definition LeafNode.h:211
Definition LeafNode.h:220
Definition LeafNode.h:211
Definition LeafNode.h:211
Definition LeafNode.h:894
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212