39 #ifndef OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED 40 #define OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED 51 #include <type_traits> 55 class TestPointDataLeaf;
73 const bool seek = destBuf ==
nullptr;
77 if (destBytes >= maximumBytes) {
79 maximumBytes <<
" bytes in voxel values.")
89 bytes16 =
static_cast<uint16_t
>(meta->pass());
91 is.seekg(
sizeof(uint16_t), std::ios_base::cur);
95 is.read(reinterpret_cast<char*>(&bytes16),
sizeof(uint16_t));
101 is.seekg(destBytes, std::ios_base::cur);
104 is.read(reinterpret_cast<char*>(destBuf), destBytes);
110 is.seekg(
int(bytes16), std::ios_base::cur);
114 std::unique_ptr<char[]> bloscBuffer(
new char[
int(bytes16)]);
115 is.read(bloscBuffer.get(), bytes16);
119 std::memcpy(destBuf, buffer.get(), destBytes);
136 if (srcBytes >= maximumBytes) {
138 maximumBytes <<
" bytes in voxel values.")
141 const char* charBuffer =
reinterpret_cast<const char*
>(srcBuf);
143 size_t compressedBytes;
144 std::unique_ptr<char[]> buffer =
bloscCompress( charBuffer, srcBytes,
145 compressedBytes,
false);
147 if (compressedBytes > 0) {
148 auto bytes16 =
static_cast<uint16_t
>(compressedBytes);
149 os.write(reinterpret_cast<const char*>(&bytes16),
sizeof(uint16_t));
150 os.write(reinterpret_cast<const char*>(buffer.get()), compressedBytes);
153 auto bytes16 =
static_cast<uint16_t
>(maximumBytes);
154 os.write(reinterpret_cast<const char*>(&bytes16),
sizeof(uint16_t));
155 os.write(reinterpret_cast<const char*>(srcBuf), srcBytes);
159 template <
typename T>
165 const size_t srcBytes = srcCount*
sizeof(T);
167 if (srcBytes >= maximumBytes) {
169 maximumBytes <<
" bytes in voxel values.")
172 const char* charBuffer =
reinterpret_cast<const char*
>(srcBuf);
177 if (compressedBytes > 0) {
178 auto bytes16 =
static_cast<uint16_t
>(compressedBytes);
179 os.write(reinterpret_cast<const char*>(&bytes16),
sizeof(uint16_t));
182 auto bytes16 =
static_cast<uint16_t
>(maximumBytes);
183 os.write(reinterpret_cast<const char*>(&bytes16),
sizeof(uint16_t));
221 template <
typename Po
intDataTreeT>
222 inline AttributeSet::Descriptor::Ptr
235 template <
typename Po
intDataTreeT>
244 template <
typename Po
intDataTreeT>
252 template <
typename T, Index Log2Dim>
257 using Ptr = std::shared_ptr<PointDataLeafNode>;
273 using BaseLeaf::LOG2DIM;
274 using BaseLeaf::TOTAL;
276 using BaseLeaf::NUM_VALUES;
277 using BaseLeaf::NUM_VOXELS;
278 using BaseLeaf::SIZE;
279 using BaseLeaf::LEVEL;
290 , mAttributeSet(new
AttributeSet(*other.mAttributeSet)) { }
296 , mAttributeSet(new
AttributeSet) { assertNonModifiableUnlessZero(value); }
301 const T& value = zeroVal<T>(),
bool active =
false)
305 assertNonModifiableUnlessZero(value);
309 template<
typename OtherValueType>
316 template <
typename ValueType>
319 , mAttributeSet(new
AttributeSet) { assertNonModifiableUnlessZero(value); }
323 template <
typename ValueType>
328 #ifndef OPENVDB_2_ABI_COMPATIBLE 330 const T& value = zeroVal<T>(),
bool active =
false)
332 , mAttributeSet(new
AttributeSet) { assertNonModifiableUnlessZero(value); }
341 void initializeAttributes(
const Descriptor::Ptr& descriptor,
const Index arrayLength);
343 void clearAttributes(
const bool updateValueMask =
true);
347 bool hasAttribute(
const size_t pos)
const;
350 bool hasAttribute(
const Name& attributeName)
const;
359 const size_t pos,
const Index strideOrTotalSize = 1,
360 const bool constantStride =
true);
367 const Descriptor& expected, Descriptor::Ptr& replacement);
370 void reorderAttributes(
const Descriptor::Ptr& replacement);
383 void replaceAttributeSet(
AttributeSet* attributeSet,
bool allowMismatchingDescriptors =
false);
387 void resetDescriptor(
const Descriptor::Ptr& replacement);
392 void setOffsets(
const std::vector<ValueType>& offsets,
const bool updateValueMask =
true);
396 void validateOffsets()
const;
402 const AttributeArray& constAttributeArray(
const size_t pos)
const;
412 GroupHandle groupHandle(
const AttributeSet::Descriptor::GroupIndex& index)
const;
416 GroupWriteHandle groupWriteHandle(
const AttributeSet::Descriptor::GroupIndex& index);
430 void updateValueMask();
439 template<
typename OtherType, Index OtherLog2Dim>
441 return BaseLeaf::hasSameTopology(other);
447 if(BaseLeaf::operator==(other) !=
true)
return false;
448 return (*this->mAttributeSet == *other.mAttributeSet);
454 template<
typename AccessorT>
460 template<
typename AccessorT>
463 template<
typename NodeT,
typename AccessorT>
467 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
468 return reinterpret_cast<NodeT*
>(
this);
472 template<
typename AccessorT>
479 template<
typename AccessorT>
481 template<
typename AccessorT>
484 template<
typename NodeT,
typename AccessorT>
488 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
489 return reinterpret_cast<const NodeT*
>(
this);
496 void readTopology(std::istream& is,
bool fromHalf =
false);
497 void writeTopology(std::ostream& os,
bool toHalf =
false)
const;
499 Index buffers()
const;
501 void readBuffers(std::istream& is,
bool fromHalf =
false);
502 void readBuffers(std::istream& is,
const CoordBBox&,
bool fromHalf =
false);
503 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
508 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
520 assert(
false &&
"Cannot modify voxel values in a PointDataTree.");
527 if (value != zeroVal<T>()) this->assertNonmodifiable();
553 template<
typename ModifyOp>
556 template<
typename ModifyOp>
559 template<
typename ModifyOp>
569 template<
typename AccessorT>
572 template<
typename ModifyOp,
typename AccessorT>
574 assertNonmodifiable();
577 template<
typename AccessorT>
580 template<
typename AccessorT>
582 BaseLeaf::setActiveStateAndCache(xyz, on, parent);
586 assertNonModifiableUnlessZero(newBackground);
594 friend class ::TestPointDataLeaf;
601 std::unique_ptr<AttributeSet> mAttributeSet;
602 uint16_t mVoxelBufferSize = 0;
631 MaskOnIterator,
const PointDataLeafNode,
const ValueType, ValueOn>;
635 MaskOffIterator,
const PointDataLeafNode,
const ValueType,ValueOff>;
639 MaskDenseIterator,
const PointDataLeafNode,
const ValueType,ValueAll>;
641 MaskOnIterator, PointDataLeafNode,
ChildOn>;
643 MaskOnIterator,
const PointDataLeafNode, ChildOn>;
645 MaskOffIterator, PointDataLeafNode,
ChildOff>;
647 MaskOffIterator,
const PointDataLeafNode, ChildOff>;
649 PointDataLeafNode, ValueType,
ChildAll>;
651 const PointDataLeafNode,
const ValueType, ChildAll>;
654 MaskOnIterator, PointDataLeafNode,
const ValueType, ValueOn>;
656 MaskOnIterator,
const PointDataLeafNode,
const ValueType, ValueOn>;
658 MaskOffIterator, PointDataLeafNode,
const ValueType, ValueOff>;
660 MaskOffIterator,
const PointDataLeafNode,
const ValueType,ValueOff>;
662 MaskDenseIterator, PointDataLeafNode,
const ValueType, ValueAll>;
664 MaskDenseIterator,
const PointDataLeafNode,
const ValueType,ValueAll>;
666 MaskOnIterator, PointDataLeafNode, ChildOn>;
668 MaskOnIterator,
const PointDataLeafNode, ChildOn>;
670 MaskOffIterator, PointDataLeafNode, ChildOff>;
672 MaskOffIterator,
const PointDataLeafNode, ChildOff>;
674 PointDataLeafNode, ValueType, ChildAll>;
676 const PointDataLeafNode,
const ValueType, ChildAll>;
689 template<
typename IterT,
typename FilterT>
693 template<
typename FilterT>
695 template<
typename FilterT>
697 template<
typename FilterT>
704 template<
typename FilterT>
707 #define VMASK_ this->getValueMask() 754 template<
typename T, Index Log2Dim>
758 if (descriptor->size() != 1 ||
759 descriptor->find(
"P") == AttributeSet::INVALID_POS ||
765 mAttributeSet.reset(
new AttributeSet(descriptor, arrayLength));
768 template<
typename T, Index Log2Dim>
772 mAttributeSet.reset(
new AttributeSet(*mAttributeSet, 0));
776 for (
Index n = 0; n < LeafNodeType::NUM_VALUES; n++) {
777 this->setOffsetOnly(n, 0);
782 if (updateValueMask) this->setValuesOff();
785 template<
typename T, Index Log2Dim>
789 return pos < mAttributeSet->
size();
792 template<
typename T, Index Log2Dim>
796 const size_t pos = mAttributeSet->find(attributeName);
797 return pos != AttributeSet::INVALID_POS;
800 template<
typename T, Index Log2Dim>
803 const size_t pos,
const Index strideOrTotalSize,
804 const bool constantStride)
806 return mAttributeSet->appendAttribute(expected, replacement, pos, strideOrTotalSize, constantStride);
809 template<
typename T, Index Log2Dim>
812 const Descriptor& expected, Descriptor::Ptr& replacement)
814 mAttributeSet->dropAttributes(pos, expected, replacement);
817 template<
typename T, Index Log2Dim>
824 template<
typename T, Index Log2Dim>
828 mAttributeSet->renameAttributes(expected, replacement);
831 template<
typename T, Index Log2Dim>
835 for (
size_t i = 0;
i < mAttributeSet->size();
i++) {
841 template<
typename T, Index Log2Dim>
849 if (!allowMismatchingDescriptors && mAttributeSet->descriptor() != attributeSet->
descriptor()) {
853 mAttributeSet.reset(attributeSet);
856 template<
typename T, Index Log2Dim>
863 template<
typename T, Index Log2Dim>
867 if (offsets.size() != LeafNodeType::NUM_VALUES) {
871 for (
Index index = 0; index < offsets.size(); ++index) {
872 setOffsetOnly(index, offsets[index]);
875 if (updateValueMask) this->updateValueMask();
878 template<
typename T, Index Log2Dim>
883 for (
Index index = 1; index < BaseLeaf::SIZE; ++index) {
884 if (this->getValue(index-1) > this->getValue(index)) {
890 for (
size_t attributeIndex = 1; attributeIndex < mAttributeSet->size(); ++attributeIndex ) {
891 if (mAttributeSet->getConst(attributeIndex-1)->size() != mAttributeSet->getConst(attributeIndex)->size()) {
897 if (mAttributeSet->size() > 0 && this->getValue(BaseLeaf::SIZE-1) != mAttributeSet->getConst(0)->size()) {
902 template<
typename T, Index Log2Dim>
907 return *mAttributeSet->get(pos);
910 template<
typename T, Index Log2Dim>
915 return *mAttributeSet->getConst(pos);
918 template<
typename T, Index Log2Dim>
922 return this->attributeArray(pos);
925 template<
typename T, Index Log2Dim>
929 const size_t pos = mAttributeSet->find(attributeName);
931 return *mAttributeSet->get(pos);
934 template<
typename T, Index Log2Dim>
938 const size_t pos = mAttributeSet->find(attributeName);
940 return *mAttributeSet->getConst(pos);
943 template<
typename T, Index Log2Dim>
947 return this->attributeArray(attributeName);
950 template<
typename T, Index Log2Dim>
962 template<
typename T, Index Log2Dim>
966 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
967 return this->groupHandle(index);
970 template<
typename T, Index Log2Dim>
982 template<
typename T, Index Log2Dim>
986 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
987 return this->groupWriteHandle(index);
990 template<
typename T, Index Log2Dim>
991 template<
typename ValueIterT,
typename FilterT>
999 ValueIterT valueIter = IterTraitsT::begin(*
this);
1000 FilterT newFilter(filter);
1001 newFilter.reset(*
this);
1006 template<
typename T, Index Log2Dim>
1007 template<
typename FilterT>
1011 return this->beginIndex<ValueAllCIter, FilterT>(filter);
1014 template<
typename T, Index Log2Dim>
1015 template<
typename FilterT>
1019 return this->beginIndex<ValueOnCIter, FilterT>(filter);
1022 template<
typename T, Index Log2Dim>
1023 template<
typename FilterT>
1027 return this->beginIndex<ValueOffCIter, FilterT>(filter);
1030 template<
typename T, Index Log2Dim>
1031 inline IndexIter<typename PointDataLeafNode<T, Log2Dim>::ValueAllCIter,
NullFilter>
1035 return this->beginIndex<ValueAllCIter, NullFilter>(filter);
1038 template<
typename T, Index Log2Dim>
1043 return this->beginIndex<ValueOnCIter, NullFilter>(filter);
1046 template<
typename T, Index Log2Dim>
1051 return this->beginIndex<ValueOffCIter, NullFilter>(filter);
1054 template<
typename T, Index Log2Dim>
1058 const Index index = LeafNodeType::coordToOffset(ijk);
1059 assert(index < BaseLeaf::SIZE);
1060 const ValueType end = this->getValue(index);
1065 template<
typename T, Index Log2Dim>
1073 template<
typename T, Index Log2Dim>
1074 template<
typename FilterT>
1079 FilterT newFilter(filter);
1080 newFilter.reset(*
this);
1084 template<
typename T, Index Log2Dim>
1088 return iterCount(this->beginIndexAll());
1091 template<
typename T, Index Log2Dim>
1095 if (this->isEmpty())
return 0;
1096 else if (this->isDense())
return this->
pointCount();
1100 template<
typename T, Index Log2Dim>
1104 if (this->isEmpty())
return this->
pointCount();
1105 else if (this->isDense())
return 0;
1106 return iterCount(this->beginIndexOff());
1109 template<
typename T, Index Log2Dim>
1114 return iterCount(this->beginIndexAll(filter));
1117 template<
typename T, Index Log2Dim>
1122 for (
Index n = 0; n < LeafNodeType::NUM_VALUES; n++) {
1123 end = this->getValue(n);
1124 this->setValueMask(n, (end - start) > 0);
1129 template<
typename T, Index Log2Dim>
1133 this->buffer().
setValue(offset, val);
1134 this->setValueMaskOn(offset);
1137 template<
typename T, Index Log2Dim>
1141 this->buffer().
setValue(offset, val);
1144 template<
typename T, Index Log2Dim>
1148 BaseLeaf::readTopology(is, fromHalf);
1151 template<
typename T, Index Log2Dim>
1155 BaseLeaf::writeTopology(os, toHalf);
1158 template<
typename T, Index Log2Dim>
1165 mAttributeSet->size() +
1166 mAttributeSet->size() +
1170 template<
typename T, Index Log2Dim>
1177 template<
typename T, Index Log2Dim>
1186 std::string key(
"paged:" + std::to_string(index));
1187 auto it = auxData.find(key);
1188 if (it != auxData.end()) {
1196 std::string key(
"paged:" + std::to_string(index));
1197 auto it = auxData.find(key);
1198 if (it != auxData.end()) {
1204 return *pagedStream;
1210 std::string matchingKey(
"hasMatchingDescriptor");
1211 auto itMatching = auxData.find(matchingKey);
1212 return itMatching != auxData.end();
1217 std::string matchingKey(
"hasMatchingDescriptor");
1218 std::string descriptorKey(
"descriptorPtr");
1219 auto itMatching = auxData.find(matchingKey);
1220 auto itDescriptor = auxData.find(descriptorKey);
1221 if (itMatching != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itMatching);
1222 if (itDescriptor != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itDescriptor);
1226 const Descriptor::Ptr descriptor)
1228 std::string descriptorKey(
"descriptorPtr");
1229 std::string matchingKey(
"hasMatchingDescriptor");
1230 auto itMatching = auxData.find(matchingKey);
1231 if (itMatching == auxData.end()) {
1240 std::string descriptorKey(
"descriptorPtr");
1241 auto itDescriptor = auxData.find(descriptorKey);
1242 assert(itDescriptor != auxData.end());
1243 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1254 const Index pass(static_cast<uint16_t>(meta->pass()));
1255 const Index maximumPass(static_cast<uint16_t>(meta->pass() >> 16));
1257 const Index attributes = (maximumPass - 4) / 2;
1261 is.read(reinterpret_cast<char*>(&mVoxelBufferSize),
sizeof(uint16_t));
1262 Local::clearMatchingDescriptor(meta->auxData());
1264 else if (pass == 1) {
1266 if (Local::hasMatchingDescriptor(meta->auxData())) {
1267 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1268 mAttributeSet->resetDescriptor(descriptor,
true);
1272 is.read(reinterpret_cast<char*>(&header),
sizeof(uint8_t));
1273 mAttributeSet->readDescriptor(is);
1274 if (header == uint8_t(1)) {
1276 Local::insertDescriptor(meta->auxData(), descriptor);
1279 mAttributeSet->readMetadata(is);
1281 else if (pass < (attributes + 2)) {
1283 const size_t attributeIndex = pass - 2;
1285 mAttributeSet->get(attributeIndex) :
nullptr;
1288 Local::getOrInsertPagedStream(meta->auxData(),
static_cast<Index>(attributeIndex));
1294 else if (pass == attributes + 2) {
1297 const Index passValue(meta->pass());
1301 nonConstMeta.
setPass(mVoxelBufferSize);
1304 BaseLeaf::readBuffers(is, fromHalf);
1307 nonConstMeta.setPass(passValue);
1309 else if (pass < (attributes*2 + 3)) {
1311 const Index attributeIndex = pass - attributes - 3;
1313 mAttributeSet->get(attributeIndex) :
nullptr;
1316 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1322 if (pass > attributes + 3) {
1323 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1326 else if (pass < buffers()) {
1328 const Index attributeIndex = pass - attributes - 4;
1329 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1333 template<
typename T, Index Log2Dim>
1342 std::string key(
"paged:" + std::to_string(index));
1343 auto it = auxData.find(key);
1344 if (it != auxData.end()) {
1354 std::string key(
"paged:" + std::to_string(index));
1355 auto it = auxData.find(key);
1356 if (it != auxData.end()) {
1362 return *pagedStream;
1367 const Descriptor::Ptr descriptor)
1369 std::string descriptorKey(
"descriptorPtr");
1370 std::string matchingKey(
"hasMatchingDescriptor");
1371 auto itMatching = auxData.find(matchingKey);
1372 auto itDescriptor = auxData.find(descriptorKey);
1373 if (itMatching == auxData.end()) {
1376 assert(itDescriptor == auxData.end());
1381 bool matching = boost::any_cast<
bool>(itMatching->second);
1382 if (!matching)
return;
1383 assert(itDescriptor != auxData.end());
1386 const Descriptor::Ptr existingDescriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1387 if (*existingDescriptor != *descriptor) {
1395 std::string matchingKey(
"hasMatchingDescriptor");
1396 auto itMatching = auxData.find(matchingKey);
1398 if (itMatching == auxData.end())
return false;
1400 if (!boost::any_cast<bool>(itMatching->second))
return false;
1406 std::string descriptorKey(
"descriptorPtr");
1407 auto itDescriptor = auxData.find(descriptorKey);
1409 if (itDescriptor == auxData.end())
return nullptr;
1411 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1418 std::string matchingKey(
"hasMatchingDescriptor");
1419 std::string descriptorKey(
"descriptorPtr");
1420 auto itMatching = auxData.find(matchingKey);
1421 auto itDescriptor = auxData.find(descriptorKey);
1422 if (itMatching != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itMatching);
1423 if (itDescriptor != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itDescriptor);
1433 const Index pass(static_cast<uint16_t>(meta->pass()));
1438 if (meta->countingPasses()) {
1439 const Index requiredPasses = this->buffers();
1440 if (requiredPasses > pass) {
1441 meta->setPass(requiredPasses);
1446 const Index maximumPass(static_cast<uint16_t>(meta->pass() >> 16));
1447 const Index attributes = (maximumPass - 4) / 2;
1453 Local::insertDescriptor(meta->auxData(), mAttributeSet->descriptorPtr());
1455 else if (pass == 1) {
1457 bool matchingDescriptor = Local::hasMatchingDescriptor(meta->auxData());
1458 if (matchingDescriptor) {
1459 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1463 os.write(reinterpret_cast<const char*>(&header),
sizeof(uint8_t));
1464 mAttributeSet->writeDescriptor(os,
false);
1470 os.write(reinterpret_cast<const char*>(&header),
sizeof(uint8_t));
1471 mAttributeSet->writeDescriptor(os,
false);
1473 mAttributeSet->writeMetadata(os,
false,
true);
1475 else if (pass < attributes + 2) {
1477 const Index attributeIndex = pass - 2;
1480 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1483 mAttributeSet->getConst(attributeIndex) :
nullptr;
1486 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1489 array->writePagedBuffers(pagedStream,
false);
1492 else if (pass == attributes + 2) {
1493 const Index attributeIndex = pass - 3;
1494 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1496 BaseLeaf::writeBuffers(os, toHalf);
1498 else if (pass < (attributes*2 + 3)) {
1500 const Index attributeIndex = pass - attributes - 3;
1502 if (pass > attributes + 2) {
1503 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1506 mAttributeSet->getConst(attributeIndex) :
nullptr;
1509 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1512 array->writePagedBuffers(pagedStream,
false);
1515 else if (pass < buffers()) {
1516 Local::clearMatchingDescriptor(meta->auxData());
1518 const Index attributeIndex = pass - attributes - 4;
1519 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1523 template<
typename T, Index Log2Dim>
1527 return BaseLeaf::memUsage() + mAttributeSet->
memUsage();
1530 template<
typename T, Index Log2Dim>
1534 BaseLeaf::evalActiveBoundingBox(bbox, visitVoxels);
1537 template<
typename T, Index Log2Dim>
1541 return BaseLeaf::getNodeBoundingBox();
1544 template<
typename T, Index Log2Dim>
1548 #ifndef OPENVDB_2_ABI_COMPATIBLE 1549 if (!this->allocate())
return;
1552 this->assertNonModifiableUnlessZero(value);
1557 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1559 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1561 const Index offset = offsetXY + (z & (DIM-1u));
1562 this->setValueMask(offset, active);
1568 template<
typename T, Index Log2Dim>
1572 this->assertNonModifiableUnlessZero(value);
1576 if (active) this->setValuesOn();
1577 else this->setValuesOff();
1584 template <
typename Po
intDataTreeT>
1585 inline AttributeSet::Descriptor::Ptr
1588 auto leafIter = tree.beginLeaf();
1589 if (!leafIter)
return nullptr;
1591 const AttributeSet::Descriptor& descriptor = leafIter->attributeSet().descriptor();
1592 auto newDescriptor = std::make_shared<AttributeSet::Descriptor>(descriptor);
1593 for (; leafIter; ++leafIter) {
1594 leafIter->resetDescriptor(newDescriptor);
1597 return newDescriptor;
1601 template <
typename Po
intDataTreeT>
1605 auto leafIter = tree.beginLeaf();
1606 for (; leafIter; ++leafIter) {
1607 for (
size_t i = 0;
i < leafIter->attributeSet().size();
i++) {
1608 leafIter->attributeArray(
i).setStreaming(on);
1614 template <
typename Po
intDataTreeT>
1622 const size_t attributes = leafIter->attributeSet().size();
1624 for ( ; leafIter; ++leafIter) {
1625 const PointDataTree::LeafNodeType::Buffer& buffer = leafIter->buffer();
1629 for (
size_t pos = 0; pos < attributes; pos++) {
1630 leafIter = tree.cbeginLeaf();
1631 for ( ; leafIter; ++leafIter) {
1632 if (leafIter->hasAttribute(pos)) {
1633 const AttributeArray& array = leafIter->constAttributeArray(pos);
1642 namespace internal {
1673 template<Index Dim1,
typename T2>
1674 struct SameLeafConfig<Dim1, points::PointDataLeafNode<T2, Dim1>> {
static const bool value =
true; };
1680 #endif // OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED typename BaseLeaf::template DenseIter< PointDataLeafNode, ValueType, ChildAll > ChildAllIter
Definition: PointDataGrid.h:674
void setValueOff(Index, const ValueType &)
Definition: PointDataGrid.h:540
ValueAllCIter beginValueAll() const
Definition: PointDataGrid.h:715
std::shared_ptr< PagedOutputStream > Ptr
Definition: StreamCompression.h:265
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition: StreamCompression.h:272
Definition: TreeIterator.h:106
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:86
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
void negate()
Definition: PointDataGrid.h:592
Attribute Group access and filtering for iteration.
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &, const T &, TopologyCopy)
Definition: PointDataGrid.h:324
PointDataLeafNode(PartialCreate, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:329
typename BaseLeaf::template ChildIter< MaskOnIterator, const PointDataLeafNode, ChildOn > ChildOnCIter
Definition: PointDataGrid.h:668
ValueOnCIter cbeginValueOn() const
Definition: PointDataGrid.h:708
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...
typename BaseLeaf::ChildAll ChildAll
Definition: PointDataGrid.h:607
A forward iterator over array indices with filtering IteratorT can be either IndexIter or ValueIndexI...
Definition: IndexIterator.h:144
typename NodeMaskType::OnIterator MaskOnIterator
Definition: PointDataGrid.h:609
Definition: Exceptions.h:85
typename BaseLeaf::template ValueIter< MaskDenseIterator, PointDataLeafNode, const ValueType, ValueAll > ValueAllIter
Definition: PointDataGrid.h:662
void setActiveState(Index offset, bool on)
Definition: PointDataGrid.h:531
ValueAllIter endValueAll()
Definition: PointDataGrid.h:726
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:92
Int32 z() const
Definition: Coord.h:156
void modifyValue(Index, const ModifyOp &)
Definition: PointDataGrid.h:554
void assertNonModifiableUnlessZero(const ValueType &value)
Definition: PointDataGrid.h:526
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
bool operator!=(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:451
const PointDataLeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:483
typename BaseLeaf::template ValueIter< MaskDenseIterator, const PointDataLeafNode, const ValueType, ValueAll > ValueAllCIter
Definition: PointDataGrid.h:664
#define VMASK_
Definition: PointDataGrid.h:707
void addLeaf(PointDataLeafNode *)
Definition: PointDataGrid.h:453
ValueOnIter beginValueOn()
Definition: PointDataGrid.h:710
typename BaseLeaf::ChildOff ChildOff
Definition: PointDataGrid.h:606
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
ValueAllCIter endValueAll() const
Definition: PointDataGrid.h:725
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:1603
PointDataLeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: PointDataGrid.h:461
typename BaseLeaf::template ValueIter< MaskOffIterator, const PointDataLeafNode, const ValueType, ValueOff > ValueOffCIter
Definition: PointDataGrid.h:660
ChildOnCIter beginChildOn() const
Definition: PointDataGrid.h:729
ChildAllCIter endChildAll() const
Definition: PointDataGrid.h:745
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
Int32 y() const
Definition: Coord.h:155
Attribute Array storage templated on type and compression codec.
ValueOnCIter beginValueOn() const
Definition: PointDataGrid.h:709
void setOutputStream(std::ostream &os)
Definition: StreamCompression.h:277
typename BaseLeaf::template ChildIter< MaskOnIterator, PointDataLeafNode, ChildOn > ChildOnIter
Definition: PointDataGrid.h:666
A forward iterator over array indices in a single voxel.
Definition: IndexIterator.h:72
tbb::atomic< Index32 > i
Definition: LeafBuffer.h:71
ChildAllIter beginChildAll()
Definition: PointDataGrid.h:736
void clip(const CoordBBox &, const ValueType &value)
Definition: PointDataGrid.h:563
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.
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1586
const PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:482
void compactAttributes(PointDataTree &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:750
const char * typeNameAsString< Vec3f >()
Definition: Types.h:343
PointDataLeafNode(const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Construct using supplied origin, value and active status.
Definition: PointDataGrid.h:294
void setValueOff(const Coord &, const ValueType &)
Definition: PointDataGrid.h:539
ChildOnCIter cbeginChildOn() const
Definition: PointDataGrid.h:728
ValueOffCIter cendValueOff() const
Definition: PointDataGrid.h:721
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
typename BaseLeaf::ValueAll ValueAll
Definition: PointDataGrid.h:598
const AttributeSet & attributeSet() const
Retrieve the attribute set.
Definition: PointDataGrid.h:338
ValueOffCIter beginValueOff() const
Definition: PointDataGrid.h:712
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:261
T * data
Definition: LeafBuffer.h:71
Definition: LeafNode.h:277
Index filtering on group membership.
Definition: AttributeGroup.h:157
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:62
void setValue(const Coord &, const ValueType &)
Definition: PointDataGrid.h:548
Definition: LeafNode.h:230
ChildOffIter endChildOff()
Definition: PointDataGrid.h:743
void renameAttributes(PointDataTree &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:691
virtual void loadData() const =0
Ensures all data is in-core.
Index32 Index
Definition: Types.h:57
Definition: NodeMasks.h:270
void setValuesOff()
Definition: PointDataGrid.h:551
ChildAllCIter cbeginChildAll() const
Definition: PointDataGrid.h:734
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:148
ChildOnCIter cendChildOn() const
Definition: PointDataGrid.h:738
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:505
void modifyValueAndActiveStateAndCache(const Coord &, const ModifyOp &, AccessorT &)
Definition: PointDataGrid.h:573
void setValueOffAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:578
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:72
std::vector< ValueType > IndexArray
Definition: PointDataGrid.h:261
ValueOffCIter endValueOff() const
Definition: PointDataGrid.h:722
typename BaseLeaf::template ChildIter< MaskOffIterator, const PointDataLeafNode, ChildOff > ChildOffCIter
Definition: PointDataGrid.h:672
void setValueOff(const Coord &xyz)
Definition: PointDataGrid.h:536
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
PointDataLeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: PointDataGrid.h:471
ValueOffCIter cbeginValueOff() const
Definition: PointDataGrid.h:711
ChildOnCIter endChildOn() const
Definition: PointDataGrid.h:739
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:313
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:68
typename BaseLeaf::ValueOff ValueOff
Definition: PointDataGrid.h:597
ChildAllIter endChildAll()
Definition: PointDataGrid.h:746
PointDataLeafNode(const PointDataLeafNode &other)
Construct using deep copy of other PointDataLeafNode.
Definition: PointDataGrid.h:288
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:61
uint64_t Index64
Definition: Types.h:56
Convenience wrappers to using Blosc and reading and writing of Paged data.
void setValueOff(Index offset)
Definition: PointDataGrid.h:537
bool operator==(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:446
ChildOffCIter cbeginChildOff() const
Definition: PointDataGrid.h:731
std::string Name
Definition: Name.h:44
void assertNonmodifiable()
Definition: PointDataGrid.h:519
Definition: LeafNode.h:229
typename BaseLeaf::ValueOn ValueOn
Definition: PointDataGrid.h:596
#define OPENVDB_VERSION_NAME
Definition: version.h:43
PointDataLeafNode()
Default constructor.
Definition: PointDataGrid.h:282
ChildOnIter beginChildOn()
Definition: PointDataGrid.h:730
ChildOffCIter cendChildOff() const
Definition: PointDataGrid.h:741
std::pair< ValueType, ValueType > ValueTypePair
Definition: PointDataGrid.h:260
ChildOffCIter beginChildOff() const
Definition: PointDataGrid.h:732
Definition: LeafNode.h:229
const PointDataLeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:480
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:262
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:268
ValueOnIter endValueOn()
Definition: PointDataGrid.h:720
void modifyValueAndActiveState(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:560
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:332
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:858
void setValueOnly(Index, const ValueType &)
Definition: PointDataGrid.h:534
void dropAttributes(PointDataTree &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:604
Definition: LeafNode.h:229
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &value, TopologyCopy)
Definition: PointDataGrid.h:317
Definition: Exceptions.h:39
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels) ...
Definition: TreeIterator.h:1228
T ValueType
Definition: PointDataGrid.h:259
const Coord & max() const
Definition: Coord.h:335
Definition: NodeMasks.h:239
void signedFloodFill(const ValueType &)
Definition: PointDataGrid.h:589
void setValueOn(const Coord &xyz)
Definition: PointDataGrid.h:542
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
void signedFloodFill(const ValueType &, const ValueType &)
Definition: PointDataGrid.h:590
Typed class for storing attribute data.
Definition: AttributeArray.h:437
Definition: Exceptions.h:87
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: PointDataGrid.h:611
ValueOnCIter cendValueOn() const
Definition: PointDataGrid.h:718
void setInputStream(std::istream &is)
Definition: StreamCompression.h:240
Index64 groupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=false)
Total points in the group in the PointDataTree.
Definition: PointCount.h:237
void flush()
Manually flushes the current page to disk if non-zero.
void setActiveState(const Coord &xyz, bool on)
Definition: PointDataGrid.h:530
ChildOnIter endChildOn()
Definition: PointDataGrid.h:740
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition: StreamCompression.h:235
void fill(const ValueType &value)
Definition: PointDataGrid.h:566
ValueAllIter beginValueAll()
Definition: PointDataGrid.h:716
Definition: Exceptions.h:92
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:440
void prefetch(PointDataTreeT &tree)
Sequentially pre-fetch all delayed-load voxel and attribute data from disk in order to accelerate sub...
Definition: PointDataGrid.h:1616
typename BaseLeaf::template ValueIter< MaskOnIterator, const PointDataLeafNode, const ValueType, ValueOn > ValueOnCIter
Definition: PointDataGrid.h:656
PointIndex< Index32, 1 > PointDataIndex32
Definition: Types.h:195
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:485
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
Int32 x() const
Definition: Coord.h:154
Definition: AttributeGroup.h:128
ValueOffIter endValueOff()
Definition: PointDataGrid.h:723
Definition: PointDataGrid.h:203
Definition: LeafNode.h:230
PointDataLeafNode(const PointDataLeafNode &other, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:300
Definition: NodeMasks.h:208
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: PointDataGrid.h:464
AttributeSet::Descriptor Descriptor
Definition: PointDataGrid.h:263
Leaf nodes that require multi-pass I/O must inherit from this struct.
Definition: io.h:140
PointDataLeafNode(const tools::PointIndexLeafNode< OtherValueType, Log2Dim > &other)
Definition: PointDataGrid.h:310
typename BaseLeaf::template ValueIter< MaskOffIterator, PointDataLeafNode, const ValueType, ValueOff > ValueOffIter
Definition: PointDataGrid.h:658
Definition: PointDataGrid.h:192
OPENVDB_DEPRECATED void initialize()
Index64 memUsage() const
Definition: PointDataGrid.h:1525
std::shared_ptr< PointDataLeafNode > Ptr
Definition: PointDataGrid.h:257
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:503
Base class for storing attribute data.
Definition: AttributeArray.h:118
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:48
std::shared_ptr< PagedInputStream > Ptr
Definition: StreamCompression.h:228
Definition: Exceptions.h:84
typename BaseLeaf::template ChildIter< MaskOffIterator, PointDataLeafNode, ChildOff > ChildOffIter
Definition: PointDataGrid.h:670
ValueOnCIter endValueOn() const
Definition: PointDataGrid.h:719
Attribute array storage for string data using Descriptor Metadata.
int32_t Int32
Definition: Types.h:59
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:307
ChildOffCIter endChildOff() const
Definition: PointDataGrid.h:742
ValueAllCIter cendValueAll() const
Definition: PointDataGrid.h:724
typename BaseLeaf::template ValueIter< MaskOnIterator, PointDataLeafNode, const ValueType, ValueOn > ValueOnIter
Definition: PointDataGrid.h:654
typename BaseLeaf::template DenseIter< const PointDataLeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: PointDataGrid.h:676
void setValueOn(Index offset)
Definition: PointDataGrid.h:543
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:225
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
virtual Index size() const =0
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Definition: RootNode.h:70
void setValueOnly(const Coord &, const ValueType &)
Definition: PointDataGrid.h:533
ChildAllCIter beginChildAll() const
Definition: PointDataGrid.h:735
void setValuesOn()
Definition: PointDataGrid.h:550
void setValueOn(Index, const ValueType &)
Definition: PointDataGrid.h:546
void appendAttribute(PointDataTree &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, Metadata::Ptr metaDefaultValue=Metadata::Ptr(), 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:463
void addLeafAndCache(PointDataLeafNode *, AccessorT &)
Definition: PointDataGrid.h:455
Definition: AttributeGroup.h:101
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &parent)
Definition: PointDataGrid.h:581
void resetBackground(const ValueType &, const ValueType &newBackground)
Definition: PointDataGrid.h:585
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition: Types.h:173
const Coord & min() const
Definition: Coord.h:334
void reorderAttributes(const Descriptor::Ptr &replacement)
Reorder attribute set.
Definition: PointDataGrid.h:819
OPENVDB_DEPRECATED void uninitialize()
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:128
ValueAllCIter cbeginValueAll() const
Definition: PointDataGrid.h:714
Definition: InternalNode.h:60
ValueOffIter beginValueOff()
Definition: PointDataGrid.h:713
void setValueOn(const Coord &, const ValueType &)
Definition: PointDataGrid.h:545
ChildOffIter beginChildOff()
Definition: PointDataGrid.h:733
Index64 pointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total points in the PointDataTree.
Definition: PointCount.h:198
Set of Attribute Arrays which tracks metadata about each array.
typename NodeMaskType::OffIterator MaskOffIterator
Definition: PointDataGrid.h:610
typename BaseLeaf::ChildOn ChildOn
Definition: PointDataGrid.h:605
Definition: LeafNode.h:233
ChildAllCIter cendChildAll() const
Definition: PointDataGrid.h:744
void writeCompressedValuesSize(std::ostream &os, const T *srcBuf, Index srcCount)
Definition: PointDataGrid.h:161
PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: PointDataGrid.h:473
void modifyValue(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:557
void setValueOnlyAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:570
Definition: LeafNode.h:230