Go to the documentation of this file.
12 #ifndef OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED
13 #define OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED
29 #include <type_traits>
33 class TestPointDataLeaf;
51 const bool seek = destBuf ==
nullptr;
55 if (destBytes >= maximumBytes) {
57 maximumBytes <<
" bytes in voxel values.")
67 bytes16 =
static_cast<uint16_t
>(meta->pass());
69 is.seekg(
sizeof(uint16_t), std::ios_base::cur);
73 is.read(
reinterpret_cast<char*
>(&bytes16),
sizeof(uint16_t));
79 is.seekg(destBytes, std::ios_base::cur);
82 is.read(
reinterpret_cast<char*
>(destBuf), destBytes);
88 is.seekg(
int(bytes16), std::ios_base::cur);
92 std::unique_ptr<char[]> bloscBuffer(
new char[
int(bytes16)]);
93 is.read(bloscBuffer.get(), bytes16);
97 std::memcpy(destBuf, buffer.get(), destBytes);
114 if (srcBytes >= maximumBytes) {
116 maximumBytes <<
" bytes in voxel values.")
119 const char* charBuffer =
reinterpret_cast<const char*
>(srcBuf);
121 size_t compressedBytes;
122 std::unique_ptr<char[]> buffer =
bloscCompress( charBuffer, srcBytes,
123 compressedBytes,
false);
125 if (compressedBytes > 0) {
126 auto bytes16 =
static_cast<uint16_t
>(compressedBytes);
127 os.write(
reinterpret_cast<const char*
>(&bytes16),
sizeof(uint16_t));
128 os.write(
reinterpret_cast<const char*
>(buffer.get()), compressedBytes);
131 auto bytes16 =
static_cast<uint16_t
>(maximumBytes);
132 os.write(
reinterpret_cast<const char*
>(&bytes16),
sizeof(uint16_t));
133 os.write(
reinterpret_cast<const char*
>(srcBuf), srcBytes);
137 template <
typename T>
143 const size_t srcBytes = srcCount*
sizeof(T);
145 if (srcBytes >= maximumBytes) {
147 maximumBytes <<
" bytes in voxel values.")
150 const char* charBuffer =
reinterpret_cast<const char*
>(srcBuf);
155 if (compressedBytes > 0) {
156 auto bytes16 =
static_cast<uint16_t
>(compressedBytes);
157 os.write(
reinterpret_cast<const char*
>(&bytes16),
sizeof(uint16_t));
160 auto bytes16 =
static_cast<uint16_t
>(maximumBytes);
161 os.write(
reinterpret_cast<const char*
>(&bytes16),
sizeof(uint16_t));
181 template<
typename T, Index Log2Dim>
class PointDataLeafNode;
199 template <
typename Po
intDataTreeT>
200 inline AttributeSet::Descriptor::Ptr
213 template <
typename Po
intDataTreeT>
224 template <
typename Po
intDataTreeT>
226 prefetch(PointDataTreeT& tree,
bool position =
true,
bool otherAttributes =
true);
232 template <
typename T, Index Log2Dim>
237 using Ptr = std::shared_ptr<PointDataLeafNode>;
253 using BaseLeaf::LOG2DIM;
254 using BaseLeaf::TOTAL;
256 using BaseLeaf::NUM_VALUES;
257 using BaseLeaf::NUM_VOXELS;
258 using BaseLeaf::SIZE;
259 using BaseLeaf::LEVEL;
270 , mAttributeSet(new
AttributeSet(*other.mAttributeSet)) { }
276 , mAttributeSet(new
AttributeSet) { assertNonModifiableUnlessZero(value); }
281 const T& value = zeroVal<T>(),
bool active =
false)
285 assertNonModifiableUnlessZero(value);
289 template<
typename OtherValueType>
296 template <
typename ValueType>
299 , mAttributeSet(new
AttributeSet) { assertNonModifiableUnlessZero(value); }
303 template <
typename ValueType>
309 const T& value = zeroVal<T>(),
bool active =
false)
311 , mAttributeSet(new
AttributeSet) { assertNonModifiableUnlessZero(value); }
322 void initializeAttributes(
const Descriptor::Ptr& descriptor,
const Index arrayLength,
325 void clearAttributes(
const bool updateValueMask =
true,
330 bool hasAttribute(
const size_t pos)
const;
333 bool hasAttribute(
const Name& attributeName)
const;
344 const size_t pos,
const Index strideOrTotalSize = 1,
345 const bool constantStride =
true,
354 const Descriptor& expected, Descriptor::Ptr& replacement);
357 void reorderAttributes(
const Descriptor::Ptr& replacement);
361 void renameAttributes(
const Descriptor& expected, Descriptor::Ptr& replacement);
370 void replaceAttributeSet(
AttributeSet* attributeSet,
bool allowMismatchingDescriptors =
false);
374 void resetDescriptor(
const Descriptor::Ptr& replacement);
379 void setOffsets(
const std::vector<ValueType>& offsets,
const bool updateValueMask =
true);
383 void validateOffsets()
const;
392 const AttributeArray& constAttributeArray(
const size_t pos)
const;
405 GroupHandle groupHandle(
const AttributeSet::Descriptor::GroupIndex& index)
const;
409 GroupWriteHandle groupWriteHandle(
const AttributeSet::Descriptor::GroupIndex& index);
420 Index64 groupPointCount(
const Name& groupName)
const;
423 void updateValueMask();
427 void setOffsetOn(
Index offset,
const ValueType& val);
428 void setOffsetOnly(
Index offset,
const ValueType& val);
432 template<
typename OtherType, Index OtherLog2Dim>
434 return BaseLeaf::hasSameTopology(other);
440 if(BaseLeaf::operator==(other) !=
true)
return false;
441 return (*this->mAttributeSet == *other.mAttributeSet);
447 template<
typename AccessorT>
453 template<
typename AccessorT>
456 template<
typename NodeT,
typename AccessorT>
460 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
461 return reinterpret_cast<NodeT*
>(
this);
465 template<
typename AccessorT>
472 template<
typename AccessorT>
474 template<
typename AccessorT>
477 template<
typename NodeT,
typename AccessorT>
481 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
482 return reinterpret_cast<const NodeT*
>(
this);
489 void readTopology(std::istream& is,
bool fromHalf =
false);
490 void writeTopology(std::ostream& os,
bool toHalf =
false)
const;
492 Index buffers()
const;
494 void readBuffers(std::istream& is,
bool fromHalf =
false);
495 void readBuffers(std::istream& is,
const CoordBBox&,
bool fromHalf =
false);
496 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
501 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
513 assert(
false &&
"Cannot modify voxel values in a PointDataTree.");
520 if (value != zeroVal<T>()) this->assertNonmodifiable();
546 template<
typename ModifyOp>
549 template<
typename ModifyOp>
552 template<
typename ModifyOp>
558 void fill(
const CoordBBox&,
const ValueType&,
bool);
560 void fill(
const ValueType&,
bool);
562 template<
typename AccessorT>
565 template<
typename ModifyOp,
typename AccessorT>
567 assertNonmodifiable();
570 template<
typename AccessorT>
573 template<
typename AccessorT>
575 BaseLeaf::setActiveStateAndCache(xyz, on, parent);
579 assertNonModifiableUnlessZero(newBackground);
587 friend class ::TestPointDataLeaf;
595 uint16_t mVoxelBufferSize = 0;
654 return this->beginIndex<ValueAllCIter, NullFilter>(filter);
659 return this->beginIndex<ValueOnCIter, NullFilter>(filter);
664 return this->beginIndex<ValueOffCIter, NullFilter>(filter);
667 template<
typename IterT,
typename FilterT>
671 template<
typename FilterT>
674 return this->beginIndex<ValueAllCIter, FilterT>(filter);
676 template<
typename FilterT>
679 return this->beginIndex<ValueOnCIter, FilterT>(filter);
681 template<
typename FilterT>
684 return this->beginIndex<ValueOffCIter, FilterT>(filter);
688 IndexVoxelIter beginIndexVoxel(
const Coord& ijk)
const;
691 template<
typename FilterT>
694 #define VMASK_ this->getValueMask()
741 template<
typename T, Index Log2Dim>
742 inline AttributeSet::UniquePtr
746 std::swap(ptr, mAttributeSet);
750 template<
typename T, Index Log2Dim>
755 if (descriptor->size() != 1 ||
756 descriptor->find(
"P") == AttributeSet::INVALID_POS ||
762 mAttributeSet.reset(
new AttributeSet(descriptor, arrayLength, lock));
765 template<
typename T, Index Log2Dim>
770 mAttributeSet.reset(
new AttributeSet(*mAttributeSet, 0, lock));
778 if (updateValueMask) this->setValuesOff();
781 template<
typename T, Index Log2Dim>
785 return pos < mAttributeSet->size();
788 template<
typename T, Index Log2Dim>
792 const size_t pos = mAttributeSet->find(attributeName);
793 return pos != AttributeSet::INVALID_POS;
796 template<
typename T, Index Log2Dim>
799 const size_t pos,
const Index strideOrTotalSize,
800 const bool constantStride,
804 return mAttributeSet->appendAttribute(
805 expected, replacement, pos, strideOrTotalSize, constantStride, metadata, lock);
808 template<
typename T, Index Log2Dim>
811 const Descriptor& expected, Descriptor::Ptr& replacement)
813 mAttributeSet->dropAttributes(pos, expected, replacement);
816 template<
typename T, Index Log2Dim>
823 template<
typename T, Index Log2Dim>
827 mAttributeSet->renameAttributes(expected, replacement);
830 template<
typename T, Index Log2Dim>
834 for (
size_t i = 0; i < mAttributeSet->size(); i++) {
840 template<
typename T, Index Log2Dim>
848 if (!allowMismatchingDescriptors && mAttributeSet->descriptor() != attributeSet->
descriptor()) {
852 mAttributeSet.reset(attributeSet);
855 template<
typename T, Index Log2Dim>
862 template<
typename T, Index Log2Dim>
866 if (offsets.size() != LeafNodeType::NUM_VALUES) {
870 for (
Index index = 0; index < offsets.size(); ++index) {
871 setOffsetOnly(index, offsets[index]);
874 if (updateValueMask) this->updateValueMask();
877 template<
typename T, Index Log2Dim>
882 for (
Index index = 1; index < BaseLeaf::SIZE; ++index) {
883 if (this->getValue(index-1) > this->getValue(index)) {
889 for (
size_t attributeIndex = 1; attributeIndex < mAttributeSet->size(); ++attributeIndex ) {
890 if (mAttributeSet->getConst(attributeIndex-1)->size() != mAttributeSet->getConst(attributeIndex)->size()) {
896 if (mAttributeSet->size() > 0 && this->getValue(BaseLeaf::SIZE-1) != mAttributeSet->getConst(0)->size()) {
901 template<
typename T, Index Log2Dim>
906 return *mAttributeSet->get(pos);
909 template<
typename T, Index Log2Dim>
914 return *mAttributeSet->getConst(pos);
917 template<
typename T, Index Log2Dim>
921 return this->attributeArray(pos);
924 template<
typename T, Index Log2Dim>
928 const size_t pos = mAttributeSet->find(attributeName);
930 return *mAttributeSet->get(pos);
933 template<
typename T, Index Log2Dim>
937 const size_t pos = mAttributeSet->find(attributeName);
939 return *mAttributeSet->getConst(pos);
942 template<
typename T, Index Log2Dim>
946 return this->attributeArray(attributeName);
949 template<
typename T, Index Log2Dim>
961 template<
typename T, Index Log2Dim>
965 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
966 return this->groupHandle(index);
969 template<
typename T, Index Log2Dim>
981 template<
typename T, Index Log2Dim>
985 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
986 return this->groupWriteHandle(index);
989 template<
typename T, Index Log2Dim>
990 template<
typename ValueIterT,
typename FilterT>
1002 FilterT newFilter(filter);
1003 newFilter.reset(*
this);
1009 ValueIterT valueIter = IterTraitsT::begin(*
this);
1014 template<
typename T, Index Log2Dim>
1018 const Index index = LeafNodeType::coordToOffset(ijk);
1019 assert(index < BaseLeaf::SIZE);
1020 const ValueType end = this->getValue(index);
1025 template<
typename T, Index Log2Dim>
1033 template<
typename T, Index Log2Dim>
1034 template<
typename FilterT>
1039 FilterT newFilter(filter);
1040 newFilter.reset(*
this);
1044 template<
typename T, Index Log2Dim>
1048 return this->getLastValue();
1051 template<
typename T, Index Log2Dim>
1055 if (this->isEmpty())
return 0;
1056 else if (this->isDense())
return this->
pointCount();
1060 template<
typename T, Index Log2Dim>
1064 if (this->isEmpty())
return this->
pointCount();
1065 else if (this->isDense())
return 0;
1066 return iterCount(this->beginIndexOff());
1069 template<
typename T, Index Log2Dim>
1073 if (!this->attributeSet().descriptor().hasGroup(groupName)) {
1076 GroupFilter filter(groupName, this->attributeSet());
1080 return iterCount(this->beginIndexAll(filter));
1084 template<
typename T, Index Log2Dim>
1089 for (
Index n = 0; n < LeafNodeType::NUM_VALUES; n++) {
1090 end = this->getValue(n);
1091 this->setValueMask(n, (end - start) > 0);
1096 template<
typename T, Index Log2Dim>
1100 this->buffer().
setValue(offset, val);
1101 this->setValueMaskOn(offset);
1104 template<
typename T, Index Log2Dim>
1108 this->buffer().
setValue(offset, val);
1111 template<
typename T, Index Log2Dim>
1115 BaseLeaf::readTopology(is, fromHalf);
1118 template<
typename T, Index Log2Dim>
1122 BaseLeaf::writeTopology(os, toHalf);
1125 template<
typename T, Index Log2Dim>
1132 mAttributeSet->size() +
1133 mAttributeSet->size() +
1137 template<
typename T, Index Log2Dim>
1144 template<
typename T, Index Log2Dim>
1153 std::string key(
"paged:" + std::to_string(index));
1154 auto it = auxData.find(key);
1155 if (it != auxData.end()) {
1163 std::string key(
"paged:" + std::to_string(index));
1164 auto it = auxData.find(key);
1165 if (it != auxData.end()) {
1166 return *(boost::any_cast<compression::PagedInputStream::Ptr>(it->second));
1171 return *pagedStream;
1177 std::string matchingKey(
"hasMatchingDescriptor");
1178 auto itMatching = auxData.find(matchingKey);
1179 return itMatching != auxData.end();
1184 std::string matchingKey(
"hasMatchingDescriptor");
1185 std::string descriptorKey(
"descriptorPtr");
1186 auto itMatching = auxData.find(matchingKey);
1187 auto itDescriptor = auxData.find(descriptorKey);
1193 const Descriptor::Ptr descriptor)
1195 std::string descriptorKey(
"descriptorPtr");
1196 std::string matchingKey(
"hasMatchingDescriptor");
1197 auto itMatching = auxData.find(matchingKey);
1198 if (itMatching == auxData.end()) {
1207 std::string descriptorKey(
"descriptorPtr");
1208 auto itDescriptor = auxData.find(descriptorKey);
1209 assert(itDescriptor != auxData.end());
1210 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1221 const Index pass(
static_cast<uint16_t
>(meta->pass()));
1222 const Index maximumPass(
static_cast<uint16_t
>(meta->pass() >> 16));
1224 const Index attributes = (maximumPass - 4) / 2;
1228 is.read(
reinterpret_cast<char*
>(&mVoxelBufferSize),
sizeof(uint16_t));
1229 Local::clearMatchingDescriptor(meta->auxData());
1231 else if (pass == 1) {
1233 if (Local::hasMatchingDescriptor(meta->auxData())) {
1234 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1235 mAttributeSet->resetDescriptor(descriptor,
true);
1239 is.read(
reinterpret_cast<char*
>(&header),
sizeof(uint8_t));
1240 mAttributeSet->readDescriptor(is);
1241 if (header & uint8_t(1)) {
1243 Local::insertDescriptor(meta->auxData(), descriptor);
1247 if (header & uint8_t(2)) {
1248 uint64_t bytesToSkip;
1249 is.read(
reinterpret_cast<char*
>(&bytesToSkip),
sizeof(uint64_t));
1250 if (bytesToSkip > uint64_t(0)) {
1252 if (metadata && metadata->seekable()) {
1253 is.seekg(bytesToSkip, std::ios_base::cur);
1256 std::vector<uint8_t> tempData(bytesToSkip);
1257 is.read(
reinterpret_cast<char*
>(&tempData[0]), bytesToSkip);
1262 if (header > uint8_t(3)) {
1266 mAttributeSet->readMetadata(is);
1268 else if (pass < (attributes + 2)) {
1270 const size_t attributeIndex = pass - 2;
1272 mAttributeSet->get(attributeIndex) :
nullptr;
1275 Local::getOrInsertPagedStream(meta->auxData(),
static_cast<Index>(attributeIndex));
1281 else if (pass == attributes + 2) {
1284 const Index passValue(meta->pass());
1288 nonConstMeta.
setPass(mVoxelBufferSize);
1291 BaseLeaf::readBuffers(is, fromHalf);
1294 nonConstMeta.
setPass(passValue);
1296 else if (pass < (attributes*2 + 3)) {
1298 const Index attributeIndex = pass - attributes - 3;
1300 mAttributeSet->get(attributeIndex) :
nullptr;
1303 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1309 if (pass > attributes + 3) {
1310 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1313 else if (pass < buffers()) {
1315 const Index attributeIndex = pass - attributes - 4;
1316 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1320 template<
typename T, Index Log2Dim>
1329 std::string key(
"paged:" + std::to_string(index));
1330 auto it = auxData.find(key);
1331 if (it != auxData.end()) {
1341 std::string key(
"paged:" + std::to_string(index));
1342 auto it = auxData.find(key);
1343 if (it != auxData.end()) {
1344 return *(boost::any_cast<compression::PagedOutputStream::Ptr>(it->second));
1349 return *pagedStream;
1354 const Descriptor::Ptr descriptor)
1356 std::string descriptorKey(
"descriptorPtr");
1357 std::string matchingKey(
"hasMatchingDescriptor");
1358 auto itMatching = auxData.find(matchingKey);
1359 auto itDescriptor = auxData.find(descriptorKey);
1360 if (itMatching == auxData.end()) {
1363 assert(itDescriptor == auxData.end());
1368 bool matching = boost::any_cast<bool>(itMatching->second);
1369 if (!matching)
return;
1370 assert(itDescriptor != auxData.end());
1373 const Descriptor::Ptr existingDescriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1374 if (*existingDescriptor != *descriptor) {
1382 std::string matchingKey(
"hasMatchingDescriptor");
1383 auto itMatching = auxData.find(matchingKey);
1385 if (itMatching == auxData.end())
return false;
1387 if (!boost::any_cast<bool>(itMatching->second))
return false;
1393 std::string descriptorKey(
"descriptorPtr");
1394 auto itDescriptor = auxData.find(descriptorKey);
1396 if (itDescriptor == auxData.end())
return nullptr;
1398 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1405 std::string matchingKey(
"hasMatchingDescriptor");
1406 std::string descriptorKey(
"descriptorPtr");
1407 auto itMatching = auxData.find(matchingKey);
1408 auto itDescriptor = auxData.find(descriptorKey);
1420 const Index pass(
static_cast<uint16_t
>(meta->pass()));
1425 if (meta->countingPasses()) {
1426 const Index requiredPasses = this->buffers();
1427 if (requiredPasses > pass) {
1428 meta->setPass(requiredPasses);
1433 const Index maximumPass(
static_cast<uint16_t
>(meta->pass() >> 16));
1434 const Index attributes = (maximumPass - 4) / 2;
1440 Local::insertDescriptor(meta->auxData(), mAttributeSet->descriptorPtr());
1442 else if (pass == 1) {
1444 bool matchingDescriptor = Local::hasMatchingDescriptor(meta->auxData());
1445 if (matchingDescriptor) {
1446 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1450 os.write(
reinterpret_cast<const char*
>(&header),
sizeof(uint8_t));
1451 mAttributeSet->writeDescriptor(os,
false);
1457 os.write(
reinterpret_cast<const char*
>(&header),
sizeof(uint8_t));
1458 mAttributeSet->writeDescriptor(os,
false);
1460 mAttributeSet->writeMetadata(os,
false,
true);
1462 else if (pass < attributes + 2) {
1464 const Index attributeIndex = pass - 2;
1467 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1470 mAttributeSet->getConst(attributeIndex) :
nullptr;
1473 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1479 else if (pass == attributes + 2) {
1480 const Index attributeIndex = pass - 3;
1481 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1483 BaseLeaf::writeBuffers(os, toHalf);
1485 else if (pass < (attributes*2 + 3)) {
1487 const Index attributeIndex = pass - attributes - 3;
1489 if (pass > attributes + 2) {
1490 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1493 mAttributeSet->getConst(attributeIndex) :
nullptr;
1496 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1502 else if (pass < buffers()) {
1503 Local::clearMatchingDescriptor(meta->auxData());
1505 const Index attributeIndex = pass - attributes - 4;
1506 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1510 template<
typename T, Index Log2Dim>
1514 return BaseLeaf::memUsage() + mAttributeSet->
memUsage();
1517 template<
typename T, Index Log2Dim>
1521 BaseLeaf::evalActiveBoundingBox(bbox, visitVoxels);
1524 template<
typename T, Index Log2Dim>
1528 return BaseLeaf::getNodeBoundingBox();
1531 template<
typename T, Index Log2Dim>
1535 if (!this->allocate())
return;
1537 this->assertNonModifiableUnlessZero(value);
1542 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1544 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1546 const Index offset = offsetXY + (z & (DIM-1u));
1547 this->setValueMask(offset, active);
1553 template<
typename T, Index Log2Dim>
1557 this->assertNonModifiableUnlessZero(value);
1561 if (active) this->setValuesOn();
1562 else this->setValuesOff();
1569 template <
typename Po
intDataTreeT>
1570 inline AttributeSet::Descriptor::Ptr
1573 auto leafIter = tree.beginLeaf();
1574 if (!leafIter)
return nullptr;
1576 const AttributeSet::Descriptor& descriptor = leafIter->attributeSet().descriptor();
1577 auto newDescriptor = std::make_shared<AttributeSet::Descriptor>(descriptor);
1578 for (; leafIter; ++leafIter) {
1579 leafIter->resetDescriptor(newDescriptor);
1582 return newDescriptor;
1586 template <
typename Po
intDataTreeT>
1590 auto leafIter = tree.beginLeaf();
1591 for (; leafIter; ++leafIter) {
1592 for (
size_t i = 0; i < leafIter->attributeSet().size(); i++) {
1593 leafIter->attributeArray(i).setStreaming(on);
1599 template <
typename Po
intDataTreeT>
1601 prefetch(PointDataTreeT& tree,
bool position,
bool otherAttributes)
1606 auto leaf = tree.cbeginLeaf();
1609 const auto& attributeSet = leaf->attributeSet();
1613 for ( ; leaf; ++leaf) {
1614 leaf->buffer().data();
1619 size_t positionIndex = attributeSet.find(
"P");
1621 if (position && positionIndex != AttributeSet::INVALID_POS) {
1622 for (leaf = tree.cbeginLeaf(); leaf; ++leaf) {
1623 assert(leaf->hasAttribute(positionIndex));
1624 leaf->constAttributeArray(positionIndex).loadData();
1630 if (otherAttributes) {
1631 const size_t attributes = attributeSet.size();
1632 for (
size_t attributeIndex = 0; attributeIndex < attributes; attributeIndex++) {
1633 if (attributeIndex == positionIndex)
continue;
1634 for (leaf = tree.cbeginLeaf(); leaf; ++leaf) {
1635 assert(leaf->hasAttribute(attributeIndex));
1636 leaf->constAttributeArray(attributeIndex).loadData();
1643 namespace internal {
1660 template<
typename HeadT,
int HeadLevel>
1665 using Type =
typename SubtreeT::template Append<RootNodeT>;
1670 template <
typename ChildT, Index Log2Dim,
int HeadLevel>
1675 using Type =
typename SubtreeT::template Append<InternalNodeT>;
1680 template <
typename ChildT, Index Log2Dim>
1694 template <
typename TreeType>
1713 template<Index Dim1,
typename T2>
1714 struct SameLeafConfig<Dim1, points::PointDataLeafNode<T2, Dim1>> {
static const bool value =
true; };
1720 #endif // OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED
PointDataLeafNode(PartialCreate, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:308
typename BaseLeaf::template DenseIter< const PointDataLeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: PointDataGrid.h:643
IndexAllIter beginIndexAll() const
Leaf index iterator.
Definition: PointDataGrid.h:651
PointDataLeafNode(const PointDataLeafNode &other)
Construct using deep copy of other PointDataLeafNode.
Definition: PointDataGrid.h:268
Index32 Index
Definition: openvdb/Types.h:32
void uninitialize()
Global deregistration of point data-related types.
const AttributeSet & attributeSet() const
Retrieve the attribute set.
Definition: PointDataGrid.h:316
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: PointDataGrid.h:604
Set of Attribute Arrays which tracks metadata about each array.
Convenience wrappers to using Blosc and reading and writing of Paged data.
PointDataLeafNode(const PointDataLeafNode &other, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:280
typename BaseLeaf::template ChildIter< MaskOnIterator, const PointDataLeafNode, ChildOn > ChildOnCIter
Definition: PointDataGrid.h:635
ChildOffCIter endChildOff() const
Definition: PointDataGrid.h:729
Definition: AttributeGroup.h:73
void assertNonmodifiable()
Definition: PointDataGrid.h:512
typename BaseLeaf::ValueOff ValueOff
Definition: PointDataGrid.h:590
void writeCompressedValues(std::ostream &os, PointDataIndex32 *srcBuf, Index srcCount, const util::NodeMask< 3 > &, const util::NodeMask< 3 > &, bool)
openvdb::io::writeCompressedValues specialized on PointDataIndex32 arrays to ignore the value mask,...
Definition: PointDataGrid.h:106
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::template ValueIter< MaskOffIterator, const PointDataLeafNode, const ValueType, ValueOff > ValueOffCIter
Definition: PointDataGrid.h:627
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:377
Definition: TreeIterator.h:60
ChildAllCIter cbeginChildAll() const
Definition: PointDataGrid.h:721
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition: StreamCompression.h:218
Definition: LeafNode.h:203
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition: StreamCompression.h:255
typename SubtreeT::template Append< RootNodeT > Type
Definition: PointDataGrid.h:1665
Definition: LeafNode.h:204
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:63
PointDataLeafNode(const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Construct using supplied origin, value and active status.
Definition: PointDataGrid.h:274
ValueAllIter beginValueAll()
Definition: PointDataGrid.h:703
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
void readCompressedValues(std::istream &is, PointDataIndex32 *destBuf, Index destCount, const util::NodeMask< 3 > &, bool)
openvdb::io::readCompressedValues specialized on PointDataIndex32 arrays to ignore the value mask,...
Definition: PointDataGrid.h:46
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1571
void setValueOn(Index offset)
Definition: PointDataGrid.h:536
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: openvdb/Types.h:542
Recursive node chain which generates a openvdb::TypeList value converted types of nodes to PointDataG...
Definition: PointDataGrid.h:1662
void addLeaf(PointDataLeafNode *)
Definition: PointDataGrid.h:446
void setValueOff(const Coord &xyz)
Definition: PointDataGrid.h:529
AttributeSet::Descriptor Descriptor
Definition: PointDataGrid.h:243
Definition: AttributeArray.h:119
ValueAllIter endValueAll()
Definition: PointDataGrid.h:713
void flush()
Manually flushes the current page to disk if non-zero.
PointDataLeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition: PointDataGrid.h:454
Definition: LeafNode.h:203
typename BaseLeaf::template ValueIter< MaskDenseIterator, PointDataLeafNode, const ValueType, ValueAll > ValueAllIter
Definition: PointDataGrid.h:629
IndexOffIter beginIndexOff() const
Definition: PointDataGrid.h:661
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &, const T &, TopologyCopy)
Definition: PointDataGrid.h:304
ChildAllCIter cendChildAll() const
Definition: PointDataGrid.h:731
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
Int32 y() const
Definition: Coord.h:132
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:39
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:49
PointDataLeafNode(const tools::PointIndexLeafNode< OtherValueType, Log2Dim > &other)
Definition: PointDataGrid.h:290
ValueAllCIter cendValueAll() const
Definition: PointDataGrid.h:711
void setValueOnly(Index, const ValueType &)
Definition: PointDataGrid.h:527
@ ALL
Definition: IndexIterator.h:43
IndexIter< ValueAllCIter, FilterT > beginIndexAll(const FilterT &filter) const
Filtered leaf index iterator.
Definition: PointDataGrid.h:672
typename SubtreeT::template Append< InternalNodeT > Type
Definition: PointDataGrid.h:1675
void assertNonModifiableUnlessZero(const ValueType &value)
Definition: PointDataGrid.h:519
#define VMASK_
Definition: PointDataGrid.h:694
void modifyValueAndActiveStateAndCache(const Coord &, const ModifyOp &, AccessorT &)
Definition: PointDataGrid.h:566
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:1601
Index64 memUsage() const
Definition: PointDataGrid.h:1512
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition: openvdb/Types.h:135
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:209
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &parent)
Definition: PointDataGrid.h:574
void setValueOn(const Coord &, const ValueType &)
Definition: PointDataGrid.h:538
void setValue(const Coord &, const ValueType &)
Definition: PointDataGrid.h:541
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
std::pair< ValueType, ValueType > ValueTypePair
Definition: PointDataGrid.h:240
IndexOnIter beginIndexOn() const
Definition: PointDataGrid.h:656
static index::State state()
Definition: AttributeGroup.h:145
void setInputStream(std::istream &is)
Definition: StreamCompression.h:223
void setValueOn(const Coord &xyz)
Definition: PointDataGrid.h:535
void addLeafAndCache(PointDataLeafNode *, AccessorT &)
Definition: PointDataGrid.h:448
ValueOnIter beginValueOn()
Definition: PointDataGrid.h:697
uint64_t Index64
Definition: openvdb/Types.h:31
const Coord & max() const
Definition: Coord.h:322
typename NodeMaskType::OnIterator MaskOnIterator
Definition: PointDataGrid.h:602
const char * typeNameAsString< Vec3f >()
Definition: openvdb/Types.h:395
IndexIter< ValueOnCIter, FilterT > beginIndexOn(const FilterT &filter) const
Definition: PointDataGrid.h:677
Library and file format version numbers.
Attribute Array storage templated on type and compression codec.
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition: NodeMasks.h:308
#define OPENVDB_THROW(exception, message)
Definition: openvdb/Exceptions.h:74
Similiar to ValueConverter, but allows for tree configuration conversion to a PointDataTree....
Definition: PointDataGrid.h:1695
void modifyValueAndActiveState(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:553
typename NodeMaskType::OffIterator MaskOffIterator
Definition: PointDataGrid.h:603
Definition: PointDataGrid.h:233
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:1588
Definition: NodeMasks.h:240
void modifyValue(Index, const ModifyOp &)
Definition: PointDataGrid.h:547
PointDataLeafNode * probeLeaf(const Coord &)
Definition: PointDataGrid.h:464
typename BaseLeaf::ValueAll ValueAll
Definition: PointDataGrid.h:591
Index filtering on group membership.
Definition: AttributeGroup.h:135
void negate()
Definition: PointDataGrid.h:585
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
ChildAllIter beginChildAll()
Definition: PointDataGrid.h:723
void resetBackground(const ValueType &, const ValueType &newBackground)
Definition: PointDataGrid.h:578
ValueOnCIter endValueOn() const
Definition: PointDataGrid.h:706
~PointDataLeafNode()=default
T ValueType
Definition: PointDataGrid.h:239
ValueAllCIter endValueAll() const
Definition: PointDataGrid.h:712
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:30
std::vector< ValueType > IndexArray
Definition: PointDataGrid.h:241
typename internal::PointDataNodeChain< RootNodeT, RootNodeT::LEVEL >::Type NodeChainT
Definition: PointDataGrid.h:1697
void initialize()
Global registration of point data-related types.
Definition: NodeMasks.h:271
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
std::string Name
Definition: Name.h:17
ValueOffCIter beginValueOff() const
Definition: PointDataGrid.h:699
Attribute Group access and filtering for iteration.
void setValueOff(const Coord &, const ValueType &)
Definition: PointDataGrid.h:532
void setActiveState(const Coord &xyz, bool on)
Definition: PointDataGrid.h:523
const Coord & min() const
Definition: Coord.h:321
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::ChildOff ChildOff
Definition: PointDataGrid.h:599
void setValueOn(Index, const ValueType &)
Definition: PointDataGrid.h:539
Typed class for storing attribute data.
Definition: AttributeArray.h:559
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
ValueAllCIter beginValueAll() const
Definition: PointDataGrid.h:702
typename BaseLeaf::template DenseIter< PointDataLeafNode, ValueType, ChildAll > ChildAllIter
Definition: PointDataGrid.h:641
void reorderAttributes(const Descriptor::Ptr &replacement)
Reorder attribute set.
Definition: PointDataGrid.h:818
typename BaseLeaf::template ValueIter< MaskOnIterator, const PointDataLeafNode, const ValueType, ValueOn > ValueOnCIter
Definition: PointDataGrid.h:623
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
typename TreeType::RootNodeType RootNodeT
Definition: PointDataGrid.h:1696
ValueOnIter endValueOn()
Definition: PointDataGrid.h:707
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &value, TopologyCopy)
Definition: PointDataGrid.h:297
Definition: openvdb/Exceptions.h:65
ValueOffIter endValueOff()
Definition: PointDataGrid.h:710
std::shared_ptr< PagedInputStream > Ptr
Definition: StreamCompression.h:211
Definition: RootNode.h:39
void setOutputStream(std::ostream &os)
Definition: StreamCompression.h:260
PointDataLeafNode()
Default constructor.
Definition: PointDataGrid.h:262
Definition: LeafNode.h:204
ChildAllIter endChildAll()
Definition: PointDataGrid.h:733
IndexIter< ValueOffCIter, FilterT > beginIndexOff(const FilterT &filter) const
Definition: PointDataGrid.h:682
typename BaseLeaf::ChildAll ChildAll
Definition: PointDataGrid.h:600
Definition: NodeMasks.h:209
ChildOffCIter beginChildOff() const
Definition: PointDataGrid.h:719
void modifyValue(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:550
void signedFloodFill(const ValueType &, const ValueType &)
Definition: PointDataGrid.h:583
const PointDataLeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition: PointDataGrid.h:473
void clip(const CoordBBox &, const ValueType &value)
Definition: PointDataGrid.h:556
void setValueOnlyAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:563
ChildOnCIter endChildOn() const
Definition: PointDataGrid.h:726
ChildOffIter beginChildOff()
Definition: PointDataGrid.h:720
void setValuesOn()
Definition: PointDataGrid.h:543
typename BaseLeaf::template ChildIter< MaskOffIterator, const PointDataLeafNode, ChildOff > ChildOffCIter
Definition: PointDataGrid.h:639
void setValuesOff()
Definition: PointDataGrid.h:544
int32_t Int32
Definition: openvdb/Types.h:34
ChildOnCIter cendChildOn() const
Definition: PointDataGrid.h:725
Definition: InternalNode.h:34
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition: PointDataGrid.h:457
Attribute array storage for string data using Descriptor Metadata.
A forward iterator over array indices with filtering IteratorT can be either IndexIter or ValueIndexI...
Definition: IndexIterator.h:140
const PointDataLeafNode * probeLeaf(const Coord &) const
Definition: PointDataGrid.h:476
void setValueOffAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:571
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153
ValueOnCIter cbeginValueOn() const
Definition: PointDataGrid.h:695
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
ChildOnIter beginChildOn()
Definition: PointDataGrid.h:717
typename PointDataNodeChain< ChildT, HeadLevel-1 >::Type SubtreeT
Definition: PointDataGrid.h:1673
typename BaseLeaf::ValueOn ValueOn
Definition: PointDataGrid.h:589
void writeCompressedValuesSize(std::ostream &os, const T *srcBuf, Index srcCount)
Definition: PointDataGrid.h:139
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:433
ValueAllCIter cbeginValueAll() const
Definition: PointDataGrid.h:701
void compactAttributes(PointDataTreeT &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:524
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:465
ValueOffIter beginValueOff()
Definition: PointDataGrid.h:700
bool operator==(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:439
typename BaseLeaf::template ChildIter< MaskOffIterator, PointDataLeafNode, ChildOff > ChildOffIter
Definition: PointDataGrid.h:637
typename BaseLeaf::template ChildIter< MaskOnIterator, PointDataLeafNode, ChildOn > ChildOnIter
Definition: PointDataGrid.h:633
typename PointDataNodeChain< typename HeadT::ChildNodeType, HeadLevel-1 >::Type SubtreeT
Definition: PointDataGrid.h:1663
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition: PointDataGrid.h:478
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:242
ChildAllCIter endChildAll() const
Definition: PointDataGrid.h:732
void fill(const CoordBBox &, const ValueType &, bool)
Definition: PointDataGrid.h:1533
ChildOffIter endChildOff()
Definition: PointDataGrid.h:730
typename BaseLeaf::template ValueIter< MaskOffIterator, PointDataLeafNode, const ValueType, ValueOff > ValueOffIter
Definition: PointDataGrid.h:625
ValueOnCIter cendValueOn() const
Definition: PointDataGrid.h:705
const PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition: PointDataGrid.h:475
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:69
Definition: openvdb/Exceptions.h:60
ChildOffCIter cbeginChildOff() const
Definition: PointDataGrid.h:718
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:857
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:101
ChildOnIter endChildOn()
Definition: PointDataGrid.h:727
typename BaseLeaf::template ValueIter< MaskDenseIterator, const PointDataLeafNode, const ValueType, ValueAll > ValueAllCIter
Definition: PointDataGrid.h:631
A list of types (not necessarily unique)
Definition: TypeList.h:366
Leaf nodes that require multi-pass I/O must inherit from this struct.
Definition: io.h:124
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:51
Definition: LeafNode.h:912
ChildOffCIter cendChildOff() const
Definition: PointDataGrid.h:728
Definition: AttributeGroup.h:102
@ NONE
Definition: IndexIterator.h:42
Definition: LeafNode.h:204
void signedFloodFill(const ValueType &)
Definition: PointDataGrid.h:582
A forward iterator over array indices in a single voxel.
Definition: IndexIterator.h:65
void setActiveState(Index offset, bool on)
Definition: PointDataGrid.h:524
typename BaseLeaf::template ValueIter< MaskOnIterator, PointDataLeafNode, const ValueType, ValueOn > ValueOnIter
Definition: PointDataGrid.h:621
Base class for storing attribute data.
Definition: AttributeArray.h:93
bool operator!=(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:444
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:246
ValueOffCIter cbeginValueOff() const
Definition: PointDataGrid.h:698
Tag dispatch class that distinguishes constructors during file input.
Definition: openvdb/Types.h:548
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition: LeafNode.h:38
typename BaseLeaf::ChildOn ChildOn
Definition: PointDataGrid.h:598
ChildOnCIter cbeginChildOn() const
Definition: PointDataGrid.h:715
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
ValueOffCIter endValueOff() const
Definition: PointDataGrid.h:709
ChildAllCIter beginChildAll() const
Definition: PointDataGrid.h:722
ValueOnCIter beginValueOn() const
Definition: PointDataGrid.h:696
Definition: openvdb/Exceptions.h:58
std::shared_ptr< PagedOutputStream > Ptr
Definition: StreamCompression.h:248
Definition: openvdb/Exceptions.h:13
Definition: LeafNode.h:203
virtual Index size() const =0
ValueOffCIter cendValueOff() const
Definition: PointDataGrid.h:708
std::unique_ptr< AttributeSet > UniquePtr
Definition: AttributeSet.h:45
IndexIter< IterT, FilterT > beginIndex(const FilterT &filter) const
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:319
Definition: openvdb/Exceptions.h:57
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:577
ChildOnCIter beginChildOn() const
Definition: PointDataGrid.h:716
Int32 x() const
Definition: Coord.h:131
PointIndex< Index32, 1 > PointDataIndex32
Definition: openvdb/Types.h:159
void setValueOff(Index, const ValueType &)
Definition: PointDataGrid.h:533
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:102
void setValueOnly(const Coord &, const ValueType &)
Definition: PointDataGrid.h:526
void fill(const ValueType &value)
Definition: PointDataGrid.h:559
void setValueOff(Index offset)
Definition: PointDataGrid.h:530
std::shared_ptr< PointDataLeafNode > Ptr
Definition: PointDataGrid.h:237
Int32 z() const
Definition: Coord.h:133
PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition: PointDataGrid.h:466
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:314