39 #ifndef OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED 40 #define OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED 56 #include <type_traits> 60 #include <boost/mpl/vector.hpp> 61 #include <boost/mpl/push_back.hpp> 62 #include <boost/mpl/back.hpp> 64 class TestPointDataLeaf;
82 const bool seek = destBuf ==
nullptr;
86 if (destBytes >= maximumBytes) {
88 maximumBytes <<
" bytes in voxel values.")
98 bytes16 =
static_cast<uint16_t
>(meta->pass());
100 is.seekg(
sizeof(uint16_t), std::ios_base::cur);
104 is.read(reinterpret_cast<char*>(&bytes16),
sizeof(uint16_t));
110 is.seekg(destBytes, std::ios_base::cur);
113 is.read(reinterpret_cast<char*>(destBuf), destBytes);
119 is.seekg(
int(bytes16), std::ios_base::cur);
123 std::unique_ptr<char[]> bloscBuffer(
new char[
int(bytes16)]);
124 is.read(bloscBuffer.get(), bytes16);
128 std::memcpy(destBuf, buffer.get(), destBytes);
145 if (srcBytes >= maximumBytes) {
147 maximumBytes <<
" bytes in voxel values.")
150 const char* charBuffer =
reinterpret_cast<const char*
>(srcBuf);
152 size_t compressedBytes;
153 std::unique_ptr<char[]> buffer =
bloscCompress( charBuffer, srcBytes,
154 compressedBytes,
false);
156 if (compressedBytes > 0) {
157 auto bytes16 =
static_cast<uint16_t
>(compressedBytes);
158 os.write(reinterpret_cast<const char*>(&bytes16),
sizeof(uint16_t));
159 os.write(reinterpret_cast<const char*>(buffer.get()), compressedBytes);
162 auto bytes16 =
static_cast<uint16_t
>(maximumBytes);
163 os.write(reinterpret_cast<const char*>(&bytes16),
sizeof(uint16_t));
164 os.write(reinterpret_cast<const char*>(srcBuf), srcBytes);
168 template <
typename T>
174 const size_t srcBytes = srcCount*
sizeof(T);
176 if (srcBytes >= maximumBytes) {
178 maximumBytes <<
" bytes in voxel values.")
181 const char* charBuffer =
reinterpret_cast<const char*
>(srcBuf);
186 if (compressedBytes > 0) {
187 auto bytes16 =
static_cast<uint16_t
>(compressedBytes);
188 os.write(reinterpret_cast<const char*>(&bytes16),
sizeof(uint16_t));
191 auto bytes16 =
static_cast<uint16_t
>(maximumBytes);
192 os.write(reinterpret_cast<const char*>(&bytes16),
sizeof(uint16_t));
230 template <
typename Po
intDataTreeT>
231 inline AttributeSet::Descriptor::Ptr
244 template <
typename Po
intDataTreeT>
253 template <
typename Po
intDataTreeT>
261 template <
typename T, Index Log2Dim>
266 using Ptr = std::shared_ptr<PointDataLeafNode>;
282 using BaseLeaf::LOG2DIM;
283 using BaseLeaf::TOTAL;
285 using BaseLeaf::NUM_VALUES;
286 using BaseLeaf::NUM_VOXELS;
287 using BaseLeaf::SIZE;
288 using BaseLeaf::LEVEL;
299 , mAttributeSet(new
AttributeSet(*other.mAttributeSet)) { }
305 , mAttributeSet(new
AttributeSet) { assertNonModifiableUnlessZero(value); }
310 const T& value = zeroVal<T>(),
bool active =
false)
314 assertNonModifiableUnlessZero(value);
318 template<
typename OtherValueType>
325 template <
typename ValueType>
328 , mAttributeSet(new
AttributeSet) { assertNonModifiableUnlessZero(value); }
332 template <
typename ValueType>
337 #if OPENVDB_ABI_VERSION_NUMBER >= 3 339 const T& value = zeroVal<T>(),
bool active =
false)
341 , mAttributeSet(new
AttributeSet) { assertNonModifiableUnlessZero(value); }
350 void initializeAttributes(
const Descriptor::Ptr& descriptor,
const Index arrayLength);
352 void clearAttributes(
const bool updateValueMask =
true);
356 bool hasAttribute(
const size_t pos)
const;
359 bool hasAttribute(
const Name& attributeName)
const;
368 const size_t pos,
const Index strideOrTotalSize = 1,
369 const bool constantStride =
true);
376 const Descriptor& expected, Descriptor::Ptr& replacement);
379 void reorderAttributes(
const Descriptor::Ptr& replacement);
383 void renameAttributes(
const Descriptor& expected, Descriptor::Ptr& replacement);
392 void replaceAttributeSet(
AttributeSet* attributeSet,
bool allowMismatchingDescriptors =
false);
396 void resetDescriptor(
const Descriptor::Ptr& replacement);
401 void setOffsets(
const std::vector<ValueType>& offsets,
const bool updateValueMask =
true);
405 void validateOffsets()
const;
411 const AttributeArray& constAttributeArray(
const size_t pos)
const;
421 GroupHandle groupHandle(
const AttributeSet::Descriptor::GroupIndex& index)
const;
425 GroupWriteHandle groupWriteHandle(
const AttributeSet::Descriptor::GroupIndex& index);
439 void updateValueMask();
443 void setOffsetOn(
Index offset,
const ValueType& val);
444 void setOffsetOnly(
Index offset,
const ValueType& val);
448 template<
typename OtherType, Index OtherLog2Dim>
450 return BaseLeaf::hasSameTopology(other);
456 if(BaseLeaf::operator==(other) !=
true)
return false;
457 return (*this->mAttributeSet == *other.mAttributeSet);
463 template<
typename AccessorT>
469 template<
typename AccessorT>
472 template<
typename NodeT,
typename AccessorT>
476 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
477 return reinterpret_cast<NodeT*
>(
this);
481 template<
typename AccessorT>
488 template<
typename AccessorT>
490 template<
typename AccessorT>
493 template<
typename NodeT,
typename AccessorT>
497 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
498 return reinterpret_cast<const NodeT*
>(
this);
505 void readTopology(std::istream& is,
bool fromHalf =
false);
506 void writeTopology(std::ostream& os,
bool toHalf =
false)
const;
508 Index buffers()
const;
510 void readBuffers(std::istream& is,
bool fromHalf =
false);
511 void readBuffers(std::istream& is,
const CoordBBox&,
bool fromHalf =
false);
512 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
517 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
529 assert(
false &&
"Cannot modify voxel values in a PointDataTree.");
536 if (value != zeroVal<T>()) this->assertNonmodifiable();
562 template<
typename ModifyOp>
565 template<
typename ModifyOp>
568 template<
typename ModifyOp>
574 void fill(
const CoordBBox&,
const ValueType&,
bool);
576 void fill(
const ValueType&,
bool);
578 template<
typename AccessorT>
581 template<
typename ModifyOp,
typename AccessorT>
583 assertNonmodifiable();
586 template<
typename AccessorT>
589 template<
typename AccessorT>
591 BaseLeaf::setActiveStateAndCache(xyz, on, parent);
595 assertNonModifiableUnlessZero(newBackground);
603 friend class ::TestPointDataLeaf;
610 std::unique_ptr<AttributeSet> mAttributeSet;
611 uint16_t mVoxelBufferSize = 0;
698 template<
typename IterT,
typename FilterT>
702 template<
typename FilterT>
704 template<
typename FilterT>
706 template<
typename FilterT>
713 template<
typename FilterT>
716 #define VMASK_ this->getValueMask() 763 template<
typename T, Index Log2Dim>
767 if (descriptor->size() != 1 ||
768 descriptor->find(
"P") == AttributeSet::INVALID_POS ||
774 mAttributeSet.reset(
new AttributeSet(descriptor, arrayLength));
777 template<
typename T, Index Log2Dim>
781 mAttributeSet.reset(
new AttributeSet(*mAttributeSet, 0));
789 if (updateValueMask) this->setValuesOff();
792 template<
typename T, Index Log2Dim>
796 return pos < mAttributeSet->
size();
799 template<
typename T, Index Log2Dim>
803 const size_t pos = mAttributeSet->find(attributeName);
804 return pos != AttributeSet::INVALID_POS;
807 template<
typename T, Index Log2Dim>
810 const size_t pos,
const Index strideOrTotalSize,
811 const bool constantStride)
813 return mAttributeSet->appendAttribute(expected, replacement, pos, strideOrTotalSize, constantStride);
816 template<
typename T, Index Log2Dim>
819 const Descriptor& expected, Descriptor::Ptr& replacement)
821 mAttributeSet->dropAttributes(pos, expected, replacement);
824 template<
typename T, Index Log2Dim>
831 template<
typename T, Index Log2Dim>
835 mAttributeSet->renameAttributes(expected, replacement);
838 template<
typename T, Index Log2Dim>
842 for (
size_t i = 0; i < mAttributeSet->size(); i++) {
848 template<
typename T, Index Log2Dim>
856 if (!allowMismatchingDescriptors && mAttributeSet->descriptor() != attributeSet->
descriptor()) {
860 mAttributeSet.reset(attributeSet);
863 template<
typename T, Index Log2Dim>
870 template<
typename T, Index Log2Dim>
874 if (offsets.size() != LeafNodeType::NUM_VALUES) {
878 for (
Index index = 0; index < offsets.size(); ++index) {
879 setOffsetOnly(index, offsets[index]);
882 if (updateValueMask) this->updateValueMask();
885 template<
typename T, Index Log2Dim>
890 for (
Index index = 1; index < BaseLeaf::SIZE; ++index) {
891 if (this->getValue(index-1) > this->getValue(index)) {
897 for (
size_t attributeIndex = 1; attributeIndex < mAttributeSet->size(); ++attributeIndex ) {
898 if (mAttributeSet->getConst(attributeIndex-1)->size() != mAttributeSet->getConst(attributeIndex)->size()) {
904 if (mAttributeSet->size() > 0 && this->getValue(BaseLeaf::SIZE-1) != mAttributeSet->getConst(0)->size()) {
909 template<
typename T, Index Log2Dim>
914 return *mAttributeSet->get(pos);
917 template<
typename T, Index Log2Dim>
922 return *mAttributeSet->getConst(pos);
925 template<
typename T, Index Log2Dim>
929 return this->attributeArray(pos);
932 template<
typename T, Index Log2Dim>
936 const size_t pos = mAttributeSet->find(attributeName);
938 return *mAttributeSet->get(pos);
941 template<
typename T, Index Log2Dim>
945 const size_t pos = mAttributeSet->find(attributeName);
947 return *mAttributeSet->getConst(pos);
950 template<
typename T, Index Log2Dim>
954 return this->attributeArray(attributeName);
957 template<
typename T, Index Log2Dim>
969 template<
typename T, Index Log2Dim>
973 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
974 return this->groupHandle(index);
977 template<
typename T, Index Log2Dim>
989 template<
typename T, Index Log2Dim>
993 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(name);
994 return this->groupWriteHandle(index);
997 template<
typename T, Index Log2Dim>
998 template<
typename ValueIterT,
typename FilterT>
1006 ValueIterT valueIter = IterTraitsT::begin(*
this);
1007 FilterT newFilter(filter);
1008 newFilter.reset(*
this);
1013 template<
typename T, Index Log2Dim>
1014 template<
typename FilterT>
1018 return this->beginIndex<ValueAllCIter, FilterT>(filter);
1021 template<
typename T, Index Log2Dim>
1022 template<
typename FilterT>
1026 return this->beginIndex<ValueOnCIter, FilterT>(filter);
1029 template<
typename T, Index Log2Dim>
1030 template<
typename FilterT>
1034 return this->beginIndex<ValueOffCIter, FilterT>(filter);
1037 template<
typename T, Index Log2Dim>
1042 return this->beginIndex<ValueAllCIter, NullFilter>(filter);
1045 template<
typename T, Index Log2Dim>
1050 return this->beginIndex<ValueOnCIter, NullFilter>(filter);
1053 template<
typename T, Index Log2Dim>
1058 return this->beginIndex<ValueOffCIter, NullFilter>(filter);
1061 template<
typename T, Index Log2Dim>
1065 const Index index = LeafNodeType::coordToOffset(ijk);
1066 assert(index < BaseLeaf::SIZE);
1067 const ValueType end = this->getValue(index);
1072 template<
typename T, Index Log2Dim>
1080 template<
typename T, Index Log2Dim>
1081 template<
typename FilterT>
1086 FilterT newFilter(filter);
1087 newFilter.reset(*
this);
1091 template<
typename T, Index Log2Dim>
1095 return iterCount(this->beginIndexAll());
1098 template<
typename T, Index Log2Dim>
1102 if (this->isEmpty())
return 0;
1103 else if (this->isDense())
return this->
pointCount();
1107 template<
typename T, Index Log2Dim>
1111 if (this->isEmpty())
return this->
pointCount();
1112 else if (this->isDense())
return 0;
1113 return iterCount(this->beginIndexOff());
1116 template<
typename T, Index Log2Dim>
1120 if (!this->attributeSet().descriptor().hasGroup(groupName)) {
1123 GroupFilter filter(groupName, this->attributeSet());
1124 return iterCount(this->beginIndexAll(filter));
1127 template<
typename T, Index Log2Dim>
1132 for (
Index n = 0; n < LeafNodeType::NUM_VALUES; n++) {
1133 end = this->getValue(n);
1134 this->setValueMask(n, (end - start) > 0);
1139 template<
typename T, Index Log2Dim>
1143 this->buffer().
setValue(offset, val);
1144 this->setValueMaskOn(offset);
1147 template<
typename T, Index Log2Dim>
1151 this->buffer().
setValue(offset, val);
1154 template<
typename T, Index Log2Dim>
1158 BaseLeaf::readTopology(is, fromHalf);
1161 template<
typename T, Index Log2Dim>
1165 BaseLeaf::writeTopology(os, toHalf);
1168 template<
typename T, Index Log2Dim>
1175 mAttributeSet->size() +
1176 mAttributeSet->size() +
1180 template<
typename T, Index Log2Dim>
1187 template<
typename T, Index Log2Dim>
1196 std::string key(
"paged:" + std::to_string(index));
1197 auto it = auxData.find(key);
1198 if (it != auxData.end()) {
1206 std::string key(
"paged:" + std::to_string(index));
1207 auto it = auxData.find(key);
1208 if (it != auxData.end()) {
1214 return *pagedStream;
1220 std::string matchingKey(
"hasMatchingDescriptor");
1221 auto itMatching = auxData.find(matchingKey);
1222 return itMatching != auxData.end();
1227 std::string matchingKey(
"hasMatchingDescriptor");
1228 std::string descriptorKey(
"descriptorPtr");
1229 auto itMatching = auxData.find(matchingKey);
1230 auto itDescriptor = auxData.find(descriptorKey);
1231 if (itMatching != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itMatching);
1232 if (itDescriptor != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itDescriptor);
1236 const Descriptor::Ptr descriptor)
1238 std::string descriptorKey(
"descriptorPtr");
1239 std::string matchingKey(
"hasMatchingDescriptor");
1240 auto itMatching = auxData.find(matchingKey);
1241 if (itMatching == auxData.end()) {
1250 std::string descriptorKey(
"descriptorPtr");
1251 auto itDescriptor = auxData.find(descriptorKey);
1252 assert(itDescriptor != auxData.end());
1253 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1264 const Index pass(static_cast<uint16_t>(meta->pass()));
1265 const Index maximumPass(static_cast<uint16_t>(meta->pass() >> 16));
1267 const Index attributes = (maximumPass - 4) / 2;
1271 is.read(reinterpret_cast<char*>(&mVoxelBufferSize),
sizeof(uint16_t));
1272 Local::clearMatchingDescriptor(meta->auxData());
1274 else if (pass == 1) {
1276 if (Local::hasMatchingDescriptor(meta->auxData())) {
1277 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1278 mAttributeSet->resetDescriptor(descriptor,
true);
1282 is.read(reinterpret_cast<char*>(&header),
sizeof(uint8_t));
1283 mAttributeSet->readDescriptor(is);
1284 if (header & uint8_t(1)) {
1286 Local::insertDescriptor(meta->auxData(), descriptor);
1290 if (header & uint8_t(2)) {
1291 uint64_t bytesToSkip;
1292 is.read(reinterpret_cast<char*>(&bytesToSkip),
sizeof(uint64_t));
1293 if (bytesToSkip > uint64_t(0)) {
1295 if (metadata && metadata->seekable()) {
1296 is.seekg(bytesToSkip, std::ios_base::cur);
1299 std::vector<uint8_t> tempData(bytesToSkip);
1300 is.read(reinterpret_cast<char*>(&tempData[0]), bytesToSkip);
1305 if (header > uint8_t(3)) {
1309 mAttributeSet->readMetadata(is);
1311 else if (pass < (attributes + 2)) {
1313 const size_t attributeIndex = pass - 2;
1315 mAttributeSet->get(attributeIndex) :
nullptr;
1318 Local::getOrInsertPagedStream(meta->auxData(),
static_cast<Index>(attributeIndex));
1324 else if (pass == attributes + 2) {
1327 const Index passValue(meta->pass());
1331 nonConstMeta.
setPass(mVoxelBufferSize);
1334 BaseLeaf::readBuffers(is, fromHalf);
1337 nonConstMeta.setPass(passValue);
1339 else if (pass < (attributes*2 + 3)) {
1341 const Index attributeIndex = pass - attributes - 3;
1343 mAttributeSet->get(attributeIndex) :
nullptr;
1346 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1352 if (pass > attributes + 3) {
1353 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1356 else if (pass < buffers()) {
1358 const Index attributeIndex = pass - attributes - 4;
1359 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1363 template<
typename T, Index Log2Dim>
1372 std::string key(
"paged:" + std::to_string(index));
1373 auto it = auxData.find(key);
1374 if (it != auxData.end()) {
1384 std::string key(
"paged:" + std::to_string(index));
1385 auto it = auxData.find(key);
1386 if (it != auxData.end()) {
1392 return *pagedStream;
1397 const Descriptor::Ptr descriptor)
1399 std::string descriptorKey(
"descriptorPtr");
1400 std::string matchingKey(
"hasMatchingDescriptor");
1401 auto itMatching = auxData.find(matchingKey);
1402 auto itDescriptor = auxData.find(descriptorKey);
1403 if (itMatching == auxData.end()) {
1406 assert(itDescriptor == auxData.end());
1411 bool matching = boost::any_cast<
bool>(itMatching->second);
1412 if (!matching)
return;
1413 assert(itDescriptor != auxData.end());
1416 const Descriptor::Ptr existingDescriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1417 if (*existingDescriptor != *descriptor) {
1425 std::string matchingKey(
"hasMatchingDescriptor");
1426 auto itMatching = auxData.find(matchingKey);
1428 if (itMatching == auxData.end())
return false;
1430 if (!boost::any_cast<bool>(itMatching->second))
return false;
1436 std::string descriptorKey(
"descriptorPtr");
1437 auto itDescriptor = auxData.find(descriptorKey);
1439 if (itDescriptor == auxData.end())
return nullptr;
1441 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1448 std::string matchingKey(
"hasMatchingDescriptor");
1449 std::string descriptorKey(
"descriptorPtr");
1450 auto itMatching = auxData.find(matchingKey);
1451 auto itDescriptor = auxData.find(descriptorKey);
1452 if (itMatching != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itMatching);
1453 if (itDescriptor != auxData.end()) (const_cast<io::StreamMetadata::AuxDataMap&>(auxData)).erase(itDescriptor);
1463 const Index pass(static_cast<uint16_t>(meta->pass()));
1468 if (meta->countingPasses()) {
1469 const Index requiredPasses = this->buffers();
1470 if (requiredPasses > pass) {
1471 meta->setPass(requiredPasses);
1476 const Index maximumPass(static_cast<uint16_t>(meta->pass() >> 16));
1477 const Index attributes = (maximumPass - 4) / 2;
1483 Local::insertDescriptor(meta->auxData(), mAttributeSet->descriptorPtr());
1485 else if (pass == 1) {
1487 bool matchingDescriptor = Local::hasMatchingDescriptor(meta->auxData());
1488 if (matchingDescriptor) {
1489 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1493 os.write(reinterpret_cast<const char*>(&header),
sizeof(uint8_t));
1494 mAttributeSet->writeDescriptor(os,
false);
1500 os.write(reinterpret_cast<const char*>(&header),
sizeof(uint8_t));
1501 mAttributeSet->writeDescriptor(os,
false);
1503 mAttributeSet->writeMetadata(os,
false,
true);
1505 else if (pass < attributes + 2) {
1507 const Index attributeIndex = pass - 2;
1510 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1513 mAttributeSet->getConst(attributeIndex) :
nullptr;
1516 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1522 else if (pass == attributes + 2) {
1523 const Index attributeIndex = pass - 3;
1524 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1526 BaseLeaf::writeBuffers(os, toHalf);
1528 else if (pass < (attributes*2 + 3)) {
1530 const Index attributeIndex = pass - attributes - 3;
1532 if (pass > attributes + 2) {
1533 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1536 mAttributeSet->getConst(attributeIndex) :
nullptr;
1539 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1545 else if (pass < buffers()) {
1546 Local::clearMatchingDescriptor(meta->auxData());
1548 const Index attributeIndex = pass - attributes - 4;
1549 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1553 template<
typename T, Index Log2Dim>
1557 return BaseLeaf::memUsage() + mAttributeSet->
memUsage();
1560 template<
typename T, Index Log2Dim>
1564 BaseLeaf::evalActiveBoundingBox(bbox, visitVoxels);
1567 template<
typename T, Index Log2Dim>
1571 return BaseLeaf::getNodeBoundingBox();
1574 template<
typename T, Index Log2Dim>
1578 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1579 if (!this->allocate())
return;
1582 this->assertNonModifiableUnlessZero(value);
1587 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1589 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1591 const Index offset = offsetXY + (z & (DIM-1u));
1592 this->setValueMask(offset, active);
1598 template<
typename T, Index Log2Dim>
1602 this->assertNonModifiableUnlessZero(value);
1606 if (active) this->setValuesOn();
1607 else this->setValuesOff();
1614 template <
typename Po
intDataTreeT>
1615 inline AttributeSet::Descriptor::Ptr
1618 auto leafIter = tree.beginLeaf();
1619 if (!leafIter)
return nullptr;
1621 const AttributeSet::Descriptor& descriptor = leafIter->attributeSet().descriptor();
1622 auto newDescriptor = std::make_shared<AttributeSet::Descriptor>(descriptor);
1623 for (; leafIter; ++leafIter) {
1624 leafIter->resetDescriptor(newDescriptor);
1627 return newDescriptor;
1631 template <
typename Po
intDataTreeT>
1635 auto leafIter = tree.beginLeaf();
1636 for (; leafIter; ++leafIter) {
1637 for (
size_t i = 0; i < leafIter->attributeSet().size(); i++) {
1638 leafIter->attributeArray(i).setStreaming(on);
1644 template <
typename Po
intDataTreeT>
1652 const size_t attributes = leafIter->attributeSet().size();
1654 for ( ; leafIter; ++leafIter) {
1655 const PointDataTree::LeafNodeType::Buffer& buffer = leafIter->buffer();
1659 for (
size_t pos = 0; pos < attributes; pos++) {
1660 leafIter = tree.cbeginLeaf();
1661 for ( ; leafIter; ++leafIter) {
1662 if (leafIter->hasAttribute(pos)) {
1663 const AttributeArray& array = leafIter->constAttributeArray(pos);
1672 namespace internal {
1689 template<
typename HeadT,
int HeadLevel>
1694 using Type =
typename boost::mpl::push_back<SubtreeT, RootNodeT>::type;
1699 template <
typename ChildT, Index Log2Dim,
int HeadLevel>
1704 using Type =
typename boost::mpl::push_back<SubtreeT, InternalNodeT>::type;
1709 template <
typename ChildT, Index Log2Dim>
1714 using Type =
typename boost::mpl::vector<LeafNodeT, InternalNodeT>::type;
1723 template <
typename TreeType>
1742 template<Index Dim1,
typename T2>
1743 struct SameLeafConfig<Dim1, points::PointDataLeafNode<T2, Dim1>> {
static const bool value =
true; };
1749 #endif // OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED 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:77
Index64 pointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total points in the PointDataTree.
Definition: PointCount.h:241
ValueOnIter endValueOn()
Definition: PointDataGrid.h:729
Typed class for storing attribute data.
Definition: AttributeArray.h:441
typename BaseLeaf::template ChildIter< MaskOffIterator, const PointDataLeafNode, ChildOff > ChildOffCIter
Definition: PointDataGrid.h:681
void setValueOn(Index, const ValueType &)
Definition: PointDataGrid.h:555
ValueAllCIter endValueAll() const
Definition: PointDataGrid.h:734
Attribute Group access and filtering for iteration.
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: PointDataGrid.h:473
std::vector< ValueType > IndexArray
Definition: PointDataGrid.h:270
const Coord & max() const
Definition: Coord.h:338
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:56
void setValueOffAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:587
ChildOffIter beginChildOff()
Definition: PointDataGrid.h:742
Base class for storing attribute data.
Definition: AttributeArray.h:118
void modifyValue(Index, const ModifyOp &)
Definition: PointDataGrid.h:563
std::string Name
Definition: Name.h:44
void fill(const CoordBBox &, const ValueType &, bool)
Definition: PointDataGrid.h:1576
Definition: LeafNode.h:232
void setValueOnlyAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:579
void setOutputStream(std::ostream &os)
Definition: StreamCompression.h:277
void setValueOff(const Coord &, const ValueType &)
Definition: PointDataGrid.h:548
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:264
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:86
ChildOffIter endChildOff()
Definition: PointDataGrid.h:752
typename BaseLeaf::template DenseIter< PointDataLeafNode, ValueType, ChildAll > ChildAllIter
Definition: PointDataGrid.h:683
Definition: LeafNode.h:233
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
typename BaseLeaf::template ChildIter< MaskOnIterator, PointDataLeafNode, ChildOn > ChildOnIter
Definition: PointDataGrid.h:675
Definition: LeafNode.h:232
#define VMASK_
Definition: PointDataGrid.h:716
typename BaseLeaf::template ValueIter< MaskOffIterator, PointDataLeafNode, const ValueType, ValueOff > ValueOffIter
Definition: PointDataGrid.h:667
Index64 groupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=false)
Total points in the group in the PointDataTree.
Definition: PointCount.h:280
ChildOnCIter cendChildOn() const
Definition: PointDataGrid.h:747
void renameAttributes(PointDataTree &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:694
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:72
Definition: TreeIterator.h:108
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &value, TopologyCopy)
Definition: PointDataGrid.h:326
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
Definition: LeafNode.h:233
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:494
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:271
Attribute Array storage templated on type and compression codec.
ChildAllIter endChildAll()
Definition: PointDataGrid.h:755
typename BaseLeaf::ChildOff ChildOff
Definition: PointDataGrid.h:615
void dropAttributes(PointDataTree &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:607
ChildOffCIter cendChildOff() const
Definition: PointDataGrid.h:750
void clip(const CoordBBox &, const ValueType &value)
Definition: PointDataGrid.h:572
ChildOffCIter cbeginChildOff() const
Definition: PointDataGrid.h:740
ChildAllCIter beginChildAll() const
Definition: PointDataGrid.h:744
ChildOffCIter beginChildOff() const
Definition: PointDataGrid.h:741
typename boost::mpl::vector< LeafNodeT, InternalNodeT >::type Type
Definition: PointDataGrid.h:1714
void modifyValue(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:566
const char * typeNameAsString< Vec3f >()
Definition: Types.h:353
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:449
void uninitialize()
Global deregistration of point data-related types.
ChildOnIter beginChildOn()
Definition: PointDataGrid.h:739
ValueOnCIter cbeginValueOn() const
Definition: PointDataGrid.h:717
typename PointDataNodeChain< typename HeadT::ChildNodeType, HeadLevel-1 >::Type SubtreeT
Definition: PointDataGrid.h:1692
void compactAttributes(PointDataTree &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:753
ChildOnCIter cbeginChildOn() const
Definition: PointDataGrid.h:737
void setValuesOn()
Definition: PointDataGrid.h:559
typename BaseLeaf::template ValueIter< MaskOnIterator, PointDataLeafNode, const ValueType, ValueOn > ValueOnIter
Definition: PointDataGrid.h:663
ValueOffIter beginValueOff()
Definition: PointDataGrid.h:722
A forward iterator over array indices with filtering IteratorT can be either IndexIter or ValueIndexI...
Definition: IndexIterator.h:144
const PointDataLeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:492
Definition: AttributeGroup.h:130
Definition: Exceptions.h:85
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:865
void setActiveState(Index offset, bool on)
Definition: PointDataGrid.h:540
void signedFloodFill(const ValueType &, const ValueType &)
Definition: PointDataGrid.h:599
PointDataLeafNode(const PointDataLeafNode &other)
Construct using deep copy of other PointDataLeafNode.
Definition: PointDataGrid.h:297
void setValueOff(Index, const ValueType &)
Definition: PointDataGrid.h:549
ValueOnCIter cendValueOn() const
Definition: PointDataGrid.h:727
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:466
Definition: NodeMasks.h:241
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:515
void signedFloodFill(const ValueType &)
Definition: PointDataGrid.h:598
typename BaseLeaf::template DenseIter< const PointDataLeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: PointDataGrid.h:685
Index filtering on group membership.
Definition: AttributeGroup.h:159
ValueOffCIter cbeginValueOff() const
Definition: PointDataGrid.h:720
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:517
typename boost::mpl::push_back< SubtreeT, RootNodeT >::type Type
Definition: PointDataGrid.h:1694
ValueAllIter beginValueAll()
Definition: PointDataGrid.h:725
void assertNonmodifiable()
Definition: PointDataGrid.h:528
bool operator!=(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:460
typename BaseLeaf::template ValueIter< MaskDenseIterator, const PointDataLeafNode, const ValueType, ValueAll > ValueAllCIter
Definition: PointDataGrid.h:673
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:62
ValueOffCIter cendValueOff() const
Definition: PointDataGrid.h:730
ValueOffCIter endValueOff() const
Definition: PointDataGrid.h:731
typename boost::mpl::push_back< SubtreeT, InternalNodeT >::type Type
Definition: PointDataGrid.h:1704
Convenience wrappers to using Blosc and reading and writing of Paged data.
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:335
typename BaseLeaf::ValueOn ValueOn
Definition: PointDataGrid.h:605
const PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:491
ChildOnIter endChildOn()
Definition: PointDataGrid.h:749
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
ChildAllCIter endChildAll() const
Definition: PointDataGrid.h:754
ValueAllCIter cbeginValueAll() const
Definition: PointDataGrid.h:723
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
void assertNonModifiableUnlessZero(const ValueType &value)
Definition: PointDataGrid.h:535
void prefetch(PointDataTreeT &tree)
Sequentially pre-fetch all delayed-load voxel and attribute data from disk in order to accelerate sub...
Definition: PointDataGrid.h:1646
void writeCompressedValuesSize(std::ostream &os, const T *srcBuf, Index srcCount)
Definition: PointDataGrid.h:170
typename PointDataNodeChain< ChildT, HeadLevel-1 >::Type SubtreeT
Definition: PointDataGrid.h:1702
const Coord & min() const
Definition: Coord.h:337
bool operator==(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:455
Similiar to ValueConverter, but allows for tree configuration conversion to a PointDataTree. ValueConverter<PointDataIndex32> cannot be used as a PointDataLeafNode is not a specialization of LeafNode.
Definition: PointDataGrid.h:1724
typename BaseLeaf::template ChildIter< MaskOffIterator, PointDataLeafNode, ChildOff > ChildOffIter
Definition: PointDataGrid.h:679
typename TreeType::RootNodeType RootNodeT
Definition: PointDataGrid.h:1725
Definition: Exceptions.h:92
void setValueOff(const Coord &xyz)
Definition: PointDataGrid.h:545
typename BaseLeaf::ChildOn ChildOn
Definition: PointDataGrid.h:614
Definition: LeafNode.h:233
void setValueOnly(const Coord &, const ValueType &)
Definition: PointDataGrid.h:542
void fill(const ValueType &value)
Definition: PointDataGrid.h:575
ChildOnCIter beginChildOn() const
Definition: PointDataGrid.h:738
Int32 z() const
Definition: Coord.h:159
Definition: Exceptions.h:87
uint64_t Index64
Definition: Types.h:60
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
int32_t Int32
Definition: Types.h:63
void setValueOn(Index offset)
Definition: PointDataGrid.h:552
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:313
PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: PointDataGrid.h:482
void setValueOn(const Coord &xyz)
Definition: PointDataGrid.h:551
void setValueOn(const Coord &, const ValueType &)
Definition: PointDataGrid.h:554
Definition: Exceptions.h:40
void initialize()
Global registration of point data-related types.
void setValueOff(Index offset)
Definition: PointDataGrid.h:546
void addLeaf(PointDataLeafNode *)
Definition: PointDataGrid.h:462
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:93
Definition: LeafNode.h:280
PointIndex< Index32, 1 > PointDataIndex32
Definition: Types.h:205
typename NodeMaskType::OnIterator MaskOnIterator
Definition: PointDataGrid.h:618
Definition: AttributeGroup.h:102
Definition: NodeMasks.h:272
PointDataLeafNode(const PointDataLeafNode &other, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:309
PointDataLeafNode(const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Construct using supplied origin, value and active status.
Definition: PointDataGrid.h:303
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition: StreamCompression.h:235
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:151
ValueOnCIter beginValueOn() const
Definition: PointDataGrid.h:718
Definition: PointDataGrid.h:212
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:225
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels) ...
Definition: TreeIterator.h:1235
Index64 memUsage() const
Definition: PointDataGrid.h:1555
Int32 y() const
Definition: Coord.h:158
ChildAllCIter cbeginChildAll() const
Definition: PointDataGrid.h:743
void negate()
Definition: PointDataGrid.h:601
void modifyValueAndActiveStateAndCache(const Coord &, const ModifyOp &, AccessorT &)
Definition: PointDataGrid.h:582
PointDataLeafNode(PartialCreate, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:338
typename BaseLeaf::template ValueIter< MaskOffIterator, const PointDataLeafNode, const ValueType, ValueOff > ValueOffCIter
Definition: PointDataGrid.h:669
Definition: NodeMasks.h:210
typename BaseLeaf::template ChildIter< MaskOnIterator, const PointDataLeafNode, ChildOn > ChildOnCIter
Definition: PointDataGrid.h:677
Definition: PointDataGrid.h:201
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: PointDataGrid.h:620
Library and file format version numbers.
ValueOnCIter endValueOn() const
Definition: PointDataGrid.h:728
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...
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &, const T &, TopologyCopy)
Definition: PointDataGrid.h:333
std::shared_ptr< PointDataLeafNode > Ptr
Definition: PointDataGrid.h:266
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:137
AttributeSet::Descriptor Descriptor
Definition: PointDataGrid.h:272
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
PointDataLeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: PointDataGrid.h:470
typename BaseLeaf::ValueOff ValueOff
Definition: PointDataGrid.h:606
PointDataLeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: PointDataGrid.h:480
void setValueOnly(Index, const ValueType &)
Definition: PointDataGrid.h:543
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:262
Definition: RootNode.h:70
typename BaseLeaf::template ValueIter< MaskDenseIterator, PointDataLeafNode, const ValueType, ValueAll > ValueAllIter
Definition: PointDataGrid.h:671
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &parent)
Definition: PointDataGrid.h:590
PointDataLeafNode(const tools::PointIndexLeafNode< OtherValueType, Log2Dim > &other)
Definition: PointDataGrid.h:319
Recursive node chain which generates a boost::mpl::vector listing value converted types of nodes to P...
Definition: PointDataGrid.h:1690
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition: Types.h:183
Leaf nodes that require multi-pass I/O must inherit from this struct.
Definition: io.h:140
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
Definition: Exceptions.h:84
typename BaseLeaf::template ValueIter< MaskOnIterator, const PointDataLeafNode, const ValueType, ValueOn > ValueOnCIter
Definition: PointDataGrid.h:665
ValueAllIter endValueAll()
Definition: PointDataGrid.h:735
Definition: InternalNode.h:60
const AttributeSet & attributeSet() const
Retrieve the attribute set.
Definition: PointDataGrid.h:347
typename NodeMaskType::OffIterator MaskOffIterator
Definition: PointDataGrid.h:619
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
std::pair< ValueType, ValueType > ValueTypePair
Definition: PointDataGrid.h:269
ValueOffIter endValueOff()
Definition: PointDataGrid.h:732
void flush()
Manually flushes the current page to disk if non-zero.
ChildAllCIter cendChildAll() const
Definition: PointDataGrid.h:753
ValueOnIter beginValueOn()
Definition: PointDataGrid.h:719
ChildOffCIter endChildOff() const
Definition: PointDataGrid.h:751
std::shared_ptr< PagedOutputStream > Ptr
Definition: StreamCompression.h:265
ChildAllIter beginChildAll()
Definition: PointDataGrid.h:745
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1616
ValueAllCIter cendValueAll() const
Definition: PointDataGrid.h:733
Attribute array storage for string data using Descriptor Metadata.
void modifyValueAndActiveState(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:569
virtual void loadData() const =0
Ensures all data is in-core.
void reorderAttributes(const Descriptor::Ptr &replacement)
Reorder attribute set.
Definition: PointDataGrid.h:826
typename BaseLeaf::ValueAll ValueAll
Definition: PointDataGrid.h:607
Index32 Index
Definition: Types.h:61
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
ValueAllCIter beginValueAll() const
Definition: PointDataGrid.h:724
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition: StreamCompression.h:272
virtual Index size() const =0
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
A forward iterator over array indices in a single voxel.
Definition: IndexIterator.h:72
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 setActiveState(const Coord &xyz, bool on)
Definition: PointDataGrid.h:539
PointDataLeafNode()
Default constructor.
Definition: PointDataGrid.h:291
void setValue(const Coord &, const ValueType &)
Definition: PointDataGrid.h:557
void addLeafAndCache(PointDataLeafNode *, AccessorT &)
Definition: PointDataGrid.h:464
const PointDataLeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: PointDataGrid.h:489
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
Set of Attribute Arrays which tracks metadata about each array.
std::shared_ptr< PagedInputStream > Ptr
Definition: StreamCompression.h:228
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:64
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:121
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:1633
T ValueType
Definition: PointDataGrid.h:268
void setInputStream(std::istream &is)
Definition: StreamCompression.h:240
typename BaseLeaf::ChildAll ChildAll
Definition: PointDataGrid.h:616
Definition: LeafNode.h:232
Definition: LeafNode.h:236
ValueOffCIter beginValueOff() const
Definition: PointDataGrid.h:721
ChildOnCIter endChildOn() const
Definition: PointDataGrid.h:748
typename internal::PointDataNodeChain< RootNodeT, RootNodeT::LEVEL >::Type NodeChainT
Definition: PointDataGrid.h:1726
void resetBackground(const ValueType &, const ValueType &newBackground)
Definition: PointDataGrid.h:594
void setValuesOff()
Definition: PointDataGrid.h:560
Int32 x() const
Definition: Coord.h:157
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:309