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;
512 CoordBBox getNodeBoundingBox()
const;
520 assert(
false &&
"Cannot modify voxel values in a PointDataTree.");
527 if (value != zeroVal<T>()) this->assertNonmodifiable();
530 void setActiveState(
const Coord& xyz,
bool on) { BaseLeaf::setActiveState(xyz, on); }
536 void setValueOff(
const Coord& xyz) { BaseLeaf::setValueOff(xyz); }
542 void setValueOn(
const Coord& xyz) { BaseLeaf::setValueOn(xyz); }
553 template<
typename ModifyOp>
556 template<
typename ModifyOp>
557 void modifyValue(
const Coord&,
const ModifyOp&) { assertNonmodifiable(); }
559 template<
typename ModifyOp>
563 void clip(
const CoordBBox&,
const ValueType& value) { assertNonModifiableUnlessZero(value); }
565 void fill(
const CoordBBox&,
const ValueType&,
bool);
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>
1174 this->readBuffers(is, CoordBBox::inf(), fromHalf);
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()) {
1194 return *pagedStream;
1200 std::string matchingKey(
"hasMatchingDescriptor");
1201 auto itMatching = auxData.find(matchingKey);
1202 return itMatching != auxData.end();
1207 std::string matchingKey(
"hasMatchingDescriptor");
1208 std::string descriptorKey(
"descriptorPtr");
1209 auto itMatching = auxData.find(matchingKey);
1210 auto itDescriptor = auxData.find(descriptorKey);
1211 if (itMatching != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itMatching);
1212 if (itDescriptor != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itDescriptor);
1216 const Descriptor::Ptr descriptor)
1218 std::string descriptorKey(
"descriptorPtr");
1219 std::string matchingKey(
"hasMatchingDescriptor");
1220 auto itMatching = auxData.find(matchingKey);
1221 if (itMatching == auxData.end()) {
1230 std::string descriptorKey(
"descriptorPtr");
1231 auto itDescriptor = auxData.find(descriptorKey);
1232 assert(itDescriptor != auxData.end());
1233 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1244 const Index pass(static_cast<uint16_t>(meta->pass()));
1245 const Index maximumPass(static_cast<uint16_t>(meta->pass() >> 16));
1247 const Index attributes = (maximumPass - 4) / 2;
1251 is.read(reinterpret_cast<char*>(&mVoxelBufferSize),
sizeof(uint16_t));
1252 Local::clearMatchingDescriptor(meta->auxData());
1254 else if (pass == 1) {
1256 if (Local::hasMatchingDescriptor(meta->auxData())) {
1257 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1258 mAttributeSet->resetDescriptor(descriptor,
true);
1262 is.read(reinterpret_cast<char*>(&header),
sizeof(uint8_t));
1263 mAttributeSet->readDescriptor(is);
1264 if (header == uint8_t(1)) {
1266 Local::insertDescriptor(meta->auxData(), descriptor);
1269 mAttributeSet->readMetadata(is);
1271 else if (pass < (attributes + 2)) {
1273 const size_t attributeIndex = pass - 2;
1275 mAttributeSet->get(attributeIndex) :
nullptr;
1278 Local::getOrInsertPagedStream(meta->auxData(),
static_cast<Index>(attributeIndex));
1284 else if (pass == attributes + 2) {
1287 const Index passValue(meta->pass());
1291 nonConstMeta.
setPass(mVoxelBufferSize);
1294 BaseLeaf::readBuffers(is, fromHalf);
1297 nonConstMeta.setPass(passValue);
1299 else if (pass < (attributes*2 + 3)) {
1301 const Index attributeIndex = pass - attributes - 3;
1303 mAttributeSet->get(attributeIndex) :
nullptr;
1306 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1314 template<
typename T, Index Log2Dim>
1323 std::string key(
"paged:" + std::to_string(index));
1324 auto it = auxData.find(key);
1325 if (it != auxData.end()) {
1335 std::string key(
"paged:" + std::to_string(index));
1336 auto it = auxData.find(key);
1337 if (it != auxData.end()) {
1343 return *pagedStream;
1348 const Descriptor::Ptr descriptor)
1350 std::string descriptorKey(
"descriptorPtr");
1351 std::string matchingKey(
"hasMatchingDescriptor");
1352 auto itMatching = auxData.find(matchingKey);
1353 auto itDescriptor = auxData.find(descriptorKey);
1354 if (itMatching == auxData.end()) {
1357 assert(itDescriptor == auxData.end());
1362 bool matching = boost::any_cast<
bool>(itMatching->second);
1363 if (!matching)
return;
1364 assert(itDescriptor != auxData.end());
1367 const Descriptor::Ptr existingDescriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1368 if (*existingDescriptor != *descriptor) {
1376 std::string matchingKey(
"hasMatchingDescriptor");
1377 auto itMatching = auxData.find(matchingKey);
1379 if (itMatching == auxData.end())
return false;
1381 if (!boost::any_cast<bool>(itMatching->second))
return false;
1387 std::string descriptorKey(
"descriptorPtr");
1388 auto itDescriptor = auxData.find(descriptorKey);
1390 if (itDescriptor == auxData.end())
return nullptr;
1392 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1399 std::string matchingKey(
"hasMatchingDescriptor");
1400 std::string descriptorKey(
"descriptorPtr");
1401 auto itMatching = auxData.find(matchingKey);
1402 auto itDescriptor = auxData.find(descriptorKey);
1403 if (itMatching != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itMatching);
1404 if (itDescriptor != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itDescriptor);
1414 const Index pass(static_cast<uint16_t>(meta->pass()));
1419 if (meta->countingPasses()) {
1420 const Index requiredPasses = this->buffers();
1421 if (requiredPasses > pass) {
1422 meta->setPass(requiredPasses);
1427 const Index maximumPass(static_cast<uint16_t>(meta->pass() >> 16));
1428 const Index attributes = (maximumPass - 4) / 2;
1434 Local::insertDescriptor(meta->auxData(), mAttributeSet->descriptorPtr());
1436 else if (pass == 1) {
1438 bool matchingDescriptor = Local::hasMatchingDescriptor(meta->auxData());
1439 if (matchingDescriptor) {
1440 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1444 os.write(reinterpret_cast<const char*>(&header),
sizeof(uint8_t));
1445 mAttributeSet->writeDescriptor(os,
false);
1451 os.write(reinterpret_cast<const char*>(&header),
sizeof(uint8_t));
1452 mAttributeSet->writeDescriptor(os,
false);
1454 mAttributeSet->writeMetadata(os,
false,
true);
1456 else if (pass < attributes + 2) {
1458 const Index attributeIndex = pass - 2;
1461 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1464 mAttributeSet->getConst(attributeIndex) :
nullptr;
1467 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1470 array->writePagedBuffers(pagedStream,
false);
1473 else if (pass == attributes + 2) {
1474 const Index attributeIndex = pass - 3;
1475 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1477 BaseLeaf::writeBuffers(os, toHalf);
1479 else if (pass < (attributes*2 + 3)) {
1481 const Index attributeIndex = pass - attributes - 3;
1483 if (pass > attributes + 2) {
1484 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1487 mAttributeSet->getConst(attributeIndex) :
nullptr;
1490 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1493 array->writePagedBuffers(pagedStream,
false);
1496 else if (pass < buffers()) {
1497 Local::clearMatchingDescriptor(meta->auxData());
1499 const Index attributeIndex = pass - attributes - 4;
1500 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1504 template<
typename T, Index Log2Dim>
1508 return BaseLeaf::memUsage() + mAttributeSet->
memUsage();
1511 template<
typename T, Index Log2Dim>
1515 BaseLeaf::evalActiveBoundingBox(bbox, visitVoxels);
1518 template<
typename T, Index Log2Dim>
1522 return BaseLeaf::getNodeBoundingBox();
1525 template<
typename T, Index Log2Dim>
1529 #ifndef OPENVDB_2_ABI_COMPATIBLE 1530 if (!this->allocate())
return;
1533 this->assertNonModifiableUnlessZero(value);
1537 for (
Int32 x = bbox.min().x(); x <= bbox.max().x(); ++x) {
1538 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1539 for (
Int32 y = bbox.min().y(); y <= bbox.max().y(); ++y) {
1540 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1541 for (
Int32 z = bbox.min().z(); z <= bbox.max().z(); ++z) {
1542 const Index offset = offsetXY + (z & (DIM-1u));
1543 this->setValueMask(offset, active);
1549 template<
typename T, Index Log2Dim>
1553 this->assertNonModifiableUnlessZero(value);
1557 if (active) this->setValuesOn();
1558 else this->setValuesOff();
1565 template <
typename Po
intDataTreeT>
1566 inline AttributeSet::Descriptor::Ptr
1569 auto leafIter = tree.beginLeaf();
1570 if (!leafIter)
return nullptr;
1572 const AttributeSet::Descriptor& descriptor = leafIter->attributeSet().descriptor();
1573 auto newDescriptor = std::make_shared<AttributeSet::Descriptor>(descriptor);
1574 for (; leafIter; ++leafIter) {
1575 leafIter->resetDescriptor(newDescriptor);
1578 return newDescriptor;
1582 template <
typename Po
intDataTreeT>
1586 auto leafIter = tree.beginLeaf();
1587 for (; leafIter; ++leafIter) {
1588 for (
size_t i = 0; i < leafIter->attributeSet().size(); i++) {
1589 leafIter->attributeArray(i).setStreaming(on);
1595 template <
typename Po
intDataTreeT>
1603 const size_t attributes = leafIter->attributeSet().size();
1605 for ( ; leafIter; ++leafIter) {
1606 const PointDataTree::LeafNodeType::Buffer& buffer = leafIter->buffer();
1610 for (
size_t pos = 0; pos < attributes; pos++) {
1611 leafIter = tree.cbeginLeaf();
1612 for ( ; leafIter; ++leafIter) {
1613 if (leafIter->hasAttribute(pos)) {
1614 const AttributeArray& array = leafIter->constAttributeArray(pos);
1623 namespace internal {
1654 template<Index Dim1,
typename T2>
1655 struct SameLeafConfig<Dim1, points::PointDataLeafNode<T2, Dim1>> {
static const bool value =
true; };
1661 #endif // OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED PointDataLeafNode(const tools::PointIndexLeafNode< OtherValueType, Log2Dim > &other)
Definition: PointDataGrid.h:310
PointDataLeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: PointDataGrid.h:471
void setValue(const Coord &, const ValueType &)
Definition: PointDataGrid.h:548
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:503
void setValuesOn()
Definition: PointDataGrid.h:550
PointDataLeafNode(const PointDataLeafNode &other)
Construct using deep copy of other PointDataLeafNode.
Definition: PointDataGrid.h:288
void setValuesOff()
Definition: PointDataGrid.h:551
ValueOnCIter cendValueOn() const
Definition: PointDataGrid.h:718
Attribute Group access and filtering for iteration.
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: PointDataGrid.h:611
const char * typeNameAsString< Vec3f >()
Definition: Types.h:343
void setValueOffAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:578
void prefetch(PointDataTreeT &tree)
Sequentially pre-fetch all delayed-load voxel and attribute data from disk in order to accelerate sub...
Definition: PointDataGrid.h:1597
Index64 groupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=false)
Total points in the group in the PointDataTree.
Definition: PointCount.h:237
PointIndex< Index32, 1 > PointDataIndex32
Definition: Types.h:195
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &value, TopologyCopy)
Definition: PointDataGrid.h:317
ChildOnIter beginChildOn()
Definition: PointDataGrid.h:730
Definition: LeafNode.h:233
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:72
Leaf nodes that require multi-pass I/O must inherit from this struct.
Definition: io.h:140
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
void writeCompressedValuesSize(std::ostream &os, const T *srcBuf, Index srcCount)
Definition: PointDataGrid.h:161
void setValueOn(Index, const ValueType &)
Definition: PointDataGrid.h:546
ChildOnCIter beginChildOn() const
Definition: PointDataGrid.h:729
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &parent)
Definition: PointDataGrid.h:581
std::shared_ptr< PointDataLeafNode > Ptr
Definition: PointDataGrid.h:257
ChildOffCIter endChildOff() const
Definition: PointDataGrid.h:742
#define VMASK_
Definition: PointDataGrid.h:707
void modifyValueAndActiveStateAndCache(const Coord &, const ModifyOp &, AccessorT &)
Definition: PointDataGrid.h:573
const PointDataLeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:480
ValueOffCIter beginValueOff() const
Definition: PointDataGrid.h:712
void reorderAttributes(const Descriptor::Ptr &replacement)
Reorder attribute set.
Definition: PointDataGrid.h:819
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:485
void modifyValueAndActiveState(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:560
Definition: PointDataGrid.h:203
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.
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:92
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
Attribute Array storage templated on type and compression codec.
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:1584
ChildOffIter beginChildOff()
Definition: PointDataGrid.h:733
ValueOnCIter cbeginValueOn() const
Definition: PointDataGrid.h:708
T ValueType
Definition: PointDataGrid.h:259
Index64 memUsage() const
Definition: PointDataGrid.h:1506
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
typename BaseLeaf::ValueOff ValueOff
Definition: PointDataGrid.h:597
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:94
std::shared_ptr< PagedOutputStream > Ptr
Definition: StreamCompression.h:265
void modifyValue(Index, const ModifyOp &)
Definition: PointDataGrid.h:554
typename BaseLeaf::template DenseIter< PointDataLeafNode, ValueType, ChildAll > ChildAllIter
Definition: PointDataGrid.h:674
bool operator!=(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:451
void setValueOnly(Index, const ValueType &)
Definition: PointDataGrid.h:534
const AttributeSet & attributeSet() const
Retrieve the attribute set.
Definition: PointDataGrid.h:338
void setActiveState(const Coord &xyz, bool on)
Definition: PointDataGrid.h:530
void setValueOn(Index offset)
Definition: PointDataGrid.h:543
typename BaseLeaf::ChildOff ChildOff
Definition: PointDataGrid.h:606
ChildOnCIter cbeginChildOn() const
Definition: PointDataGrid.h:728
ValueOnCIter endValueOn() const
Definition: PointDataGrid.h:719
PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: PointDataGrid.h:473
ValueAllCIter beginValueAll() const
Definition: PointDataGrid.h:715
void resetBackground(const ValueType &, const ValueType &newBackground)
Definition: PointDataGrid.h:585
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:313
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
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
PointDataLeafNode(const PointDataLeafNode &other, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:300
Base class for storing attribute data.
Definition: AttributeArray.h:118
typename BaseLeaf::ChildOn ChildOn
Definition: PointDataGrid.h:605
Convenience wrappers to using Blosc and reading and writing of Paged data.
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:61
ChildAllCIter beginChildAll() const
Definition: PointDataGrid.h:735
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:262
void signedFloodFill(const ValueType &)
Definition: PointDataGrid.h:589
Definition: AttributeGroup.h:101
void setValueOn(const Coord &xyz)
Definition: PointDataGrid.h:542
void setActiveState(Index offset, bool on)
Definition: PointDataGrid.h:531
#define OPENVDB_VERSION_NAME
Definition: version.h:43
ChildOffCIter beginChildOff() const
Definition: PointDataGrid.h:732
ChildOffCIter cendChildOff() const
Definition: PointDataGrid.h:741
Definition: LeafNode.h:229
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:268
Definition: LeafNode.h:229
Definition: Exceptions.h:87
ValueOffIter beginValueOff()
Definition: PointDataGrid.h:713
typename BaseLeaf::template DenseIter< const PointDataLeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: PointDataGrid.h:676
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:62
std::vector< ValueType > IndexArray
Definition: PointDataGrid.h:261
void addLeaf(PointDataLeafNode *)
Definition: PointDataGrid.h:453
void negate()
Definition: PointDataGrid.h:592
PointDataLeafNode(PartialCreate, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:329
void setValueOnly(const Coord &, const ValueType &)
Definition: PointDataGrid.h:533
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels) ...
Definition: TreeIterator.h:1228
typename BaseLeaf::template ValueIter< MaskOffIterator, const PointDataLeafNode, const ValueType, ValueOff > ValueOffCIter
Definition: PointDataGrid.h:660
typename BaseLeaf::template ChildIter< MaskOffIterator, const PointDataLeafNode, ChildOff > ChildOffCIter
Definition: PointDataGrid.h:672
ValueAllIter beginValueAll()
Definition: PointDataGrid.h:716
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
A forward iterator over array indices with filtering IteratorT can be either IndexIter or ValueIndexI...
Definition: IndexIterator.h:144
OPENVDB_DEPRECATED void initialize()
typename BaseLeaf::template ValueIter< MaskOnIterator, const PointDataLeafNode, const ValueType, ValueOn > ValueOnCIter
Definition: PointDataGrid.h:656
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1567
void compactAttributes(PointDataTree &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:750
Definition: NodeMasks.h:239
Definition: Exceptions.h:39
ValueOffIter endValueOff()
Definition: PointDataGrid.h:723
typename BaseLeaf::template ChildIter< MaskOffIterator, PointDataLeafNode, ChildOff > ChildOffIter
Definition: PointDataGrid.h:670
ValueOffCIter cendValueOff() const
Definition: PointDataGrid.h:721
void setValueOff(Index offset)
Definition: PointDataGrid.h:537
Typed class for storing attribute data.
Definition: AttributeArray.h:437
void setValueOn(const Coord &, const ValueType &)
Definition: PointDataGrid.h:545
typename NodeMaskType::OffIterator MaskOffIterator
Definition: PointDataGrid.h:610
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:225
ChildAllCIter cbeginChildAll() const
Definition: PointDataGrid.h:734
typename BaseLeaf::ValueOn ValueOn
Definition: PointDataGrid.h:596
typename BaseLeaf::template ValueIter< MaskOffIterator, PointDataLeafNode, const ValueType, ValueOff > ValueOffIter
Definition: PointDataGrid.h:658
ValueAllCIter endValueAll() const
Definition: PointDataGrid.h:725
void renameAttributes(PointDataTree &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:691
ChildOffCIter cbeginChildOff() const
Definition: PointDataGrid.h:731
Definition: NodeMasks.h:270
ValueOnIter endValueOn()
Definition: PointDataGrid.h:720
typename BaseLeaf::template ValueIter< MaskOnIterator, PointDataLeafNode, const ValueType, ValueOn > ValueOnIter
Definition: PointDataGrid.h:654
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
virtual void loadData() const =0
Ensures all data is in-core.
Definition: Exceptions.h:92
Definition: LeafNode.h:230
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
void setOutputStream(std::ostream &os)
Definition: StreamCompression.h:277
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:148
void setInputStream(std::istream &is)
Definition: StreamCompression.h:240
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
PointDataLeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: PointDataGrid.h:461
typename BaseLeaf::template ChildIter< MaskOnIterator, const PointDataLeafNode, ChildOn > ChildOnCIter
Definition: PointDataGrid.h:668
Definition: TreeIterator.h:106
Index64 pointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total points in the PointDataTree.
Definition: PointCount.h:198
uint64_t Index64
Definition: Types.h:56
typename BaseLeaf::ChildAll ChildAll
Definition: PointDataGrid.h:607
Definition: InternalNode.h:64
ValueOffCIter endValueOff() const
Definition: PointDataGrid.h:722
Definition: LeafNode.h:229
void modifyValue(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:557
Definition: Exceptions.h:85
std::string Name
Definition: Name.h:44
Definition: NodeMasks.h:208
A forward iterator over array indices in a single voxel.
Definition: IndexIterator.h:72
ValueOffCIter cbeginValueOff() const
Definition: PointDataGrid.h:711
void signedFloodFill(const ValueType &, const ValueType &)
Definition: PointDataGrid.h:590
ValueOnCIter beginValueOn() const
Definition: PointDataGrid.h:709
Definition: PointDataGrid.h:192
typename BaseLeaf::template ValueIter< MaskDenseIterator, const PointDataLeafNode, const ValueType, ValueAll > ValueAllCIter
Definition: PointDataGrid.h:664
ChildAllCIter endChildAll() const
Definition: PointDataGrid.h:745
void dropAttributes(PointDataTree &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:604
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition: StreamCompression.h:235
bool operator==(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:446
ValueAllCIter cendValueAll() const
Definition: PointDataGrid.h:724
Index filtering on group membership.
Definition: AttributeGroup.h:157
const PointDataLeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:483
void setValueOff(const Coord &xyz)
Definition: PointDataGrid.h:536
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
Definition: Exceptions.h:84
Attribute array storage for string data using Descriptor Metadata.
std::pair< ValueType, ValueType > ValueTypePair
Definition: PointDataGrid.h:260
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:307
void setValueOnlyAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:570
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
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...
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
const PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:482
ChildAllIter endChildAll()
Definition: PointDataGrid.h:746
typename BaseLeaf::template ChildIter< MaskOnIterator, PointDataLeafNode, ChildOn > ChildOnIter
Definition: PointDataGrid.h:666
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
Definition: LeafNode.h:277
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:505
ChildOnCIter cendChildOn() const
Definition: PointDataGrid.h:738
void setValueOff(Index, const ValueType &)
Definition: PointDataGrid.h:540
ChildAllIter beginChildAll()
Definition: PointDataGrid.h:736
void flush()
Manually flushes the current page to disk if non-zero.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Definition: RootNode.h:75
int32_t Int32
Definition: Types.h:59
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
Definition: LeafNode.h:230
Index32 Index
Definition: Types.h:57
void assertNonmodifiable()
Definition: PointDataGrid.h:519
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition: Types.h:173
std::shared_ptr< PagedInputStream > Ptr
Definition: StreamCompression.h:228
ValueOnIter beginValueOn()
Definition: PointDataGrid.h:710
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: PointDataGrid.h:464
AttributeSet::Descriptor Descriptor
Definition: PointDataGrid.h:263
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &, const T &, TopologyCopy)
Definition: PointDataGrid.h:324
ChildOnCIter endChildOn() const
Definition: PointDataGrid.h:739
PointDataLeafNode()
Default constructor.
Definition: PointDataGrid.h:282
ChildOnIter endChildOn()
Definition: PointDataGrid.h:740
Definition: LeafNode.h:230
typename NodeMaskType::OnIterator MaskOnIterator
Definition: PointDataGrid.h:609
ChildOffIter endChildOff()
Definition: PointDataGrid.h:743
Definition: AttributeGroup.h:128
typename BaseLeaf::template ValueIter< MaskDenseIterator, PointDataLeafNode, const ValueType, ValueAll > ValueAllIter
Definition: PointDataGrid.h:662
ValueAllIter endValueAll()
Definition: PointDataGrid.h:726
void fill(const ValueType &value)
Definition: PointDataGrid.h:566
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
ValueAllCIter cbeginValueAll() const
Definition: PointDataGrid.h:714
Set of Attribute Arrays which tracks metadata about each array.
virtual Index size() const =0
void assertNonModifiableUnlessZero(const ValueType &value)
Definition: PointDataGrid.h:526
void clip(const CoordBBox &, const ValueType &value)
Definition: PointDataGrid.h:563
ChildAllCIter cendChildAll() const
Definition: PointDataGrid.h:744
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition: StreamCompression.h:272
OPENVDB_DEPRECATED void uninitialize()
typename BaseLeaf::ValueAll ValueAll
Definition: PointDataGrid.h:598