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;
360 const Descriptor& expected, Descriptor::Ptr& replacement);
363 void reorderAttributes(
const Descriptor::Ptr& replacement);
367 void renameAttributes(
const Descriptor& expected, Descriptor::Ptr& replacement);
376 void replaceAttributeSet(
AttributeSet* attributeSet,
bool allowMismatchingDescriptors =
false);
380 void resetDescriptor(
const Descriptor::Ptr& replacement);
385 void setOffsets(
const std::vector<ValueType>& offsets,
const bool updateValueMask =
true);
389 void validateOffsets()
const;
398 const AttributeArray& constAttributeArray(
const size_t pos)
const;
411 GroupHandle groupHandle(
const AttributeSet::Descriptor::GroupIndex& index)
const;
415 GroupWriteHandle groupWriteHandle(
const AttributeSet::Descriptor::GroupIndex& index);
426 Index64 groupPointCount(
const Name& groupName)
const;
429 void updateValueMask();
433 void setOffsetOn(
Index offset,
const ValueType& val);
434 void setOffsetOnly(
Index offset,
const ValueType& val);
438 template<
typename OtherType, Index OtherLog2Dim>
440 return BaseLeaf::hasSameTopology(other);
446 if(BaseLeaf::operator==(other) !=
true)
return false;
447 return (*this->mAttributeSet == *other.mAttributeSet);
453 template<
typename AccessorT>
459 template<
typename AccessorT>
462 template<
typename NodeT,
typename AccessorT>
466 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
467 return reinterpret_cast<NodeT*
>(
this);
471 template<
typename AccessorT>
478 template<
typename AccessorT>
480 template<
typename AccessorT>
483 template<
typename NodeT,
typename AccessorT>
487 if (!(std::is_same<NodeT,PointDataLeafNode>::value))
return nullptr;
488 return reinterpret_cast<const NodeT*
>(
this);
495 void readTopology(std::istream& is,
bool fromHalf =
false);
496 void writeTopology(std::ostream& os,
bool toHalf =
false)
const;
498 Index buffers()
const;
500 void readBuffers(std::istream& is,
bool fromHalf =
false);
501 void readBuffers(std::istream& is,
const CoordBBox&,
bool fromHalf =
false);
502 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
507 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
519 assert(
false &&
"Cannot modify voxel values in a PointDataTree.");
526 if (value != zeroVal<T>()) this->assertNonmodifiable();
552 template<
typename ModifyOp>
555 template<
typename ModifyOp>
558 template<
typename ModifyOp>
564 void fill(
const CoordBBox&,
const ValueType&,
bool);
566 void fill(
const ValueType&,
bool);
568 template<
typename AccessorT>
571 template<
typename ModifyOp,
typename AccessorT>
573 assertNonmodifiable();
576 template<
typename AccessorT>
579 template<
typename AccessorT>
581 BaseLeaf::setActiveStateAndCache(xyz, on, parent);
585 assertNonModifiableUnlessZero(newBackground);
593 friend class ::TestPointDataLeaf;
601 uint16_t mVoxelBufferSize = 0;
660 return this->beginIndex<ValueAllCIter, NullFilter>(filter);
665 return this->beginIndex<ValueOnCIter, NullFilter>(filter);
670 return this->beginIndex<ValueOffCIter, NullFilter>(filter);
673 template<
typename IterT,
typename FilterT>
677 template<
typename FilterT>
680 return this->beginIndex<ValueAllCIter, FilterT>(filter);
682 template<
typename FilterT>
685 return this->beginIndex<ValueOnCIter, FilterT>(filter);
687 template<
typename FilterT>
690 return this->beginIndex<ValueOffCIter, FilterT>(filter);
694 IndexVoxelIter beginIndexVoxel(
const Coord& ijk)
const;
697 template<
typename FilterT>
700 #define VMASK_ this->getValueMask()
747 template<
typename T, Index Log2Dim>
748 inline AttributeSet::UniquePtr
752 std::swap(ptr, mAttributeSet);
756 template<
typename T, Index Log2Dim>
761 if (descriptor->size() != 1 ||
762 descriptor->find(
"P") == AttributeSet::INVALID_POS ||
768 mAttributeSet.reset(
new AttributeSet(descriptor, arrayLength, lock));
771 template<
typename T, Index Log2Dim>
776 mAttributeSet.reset(
new AttributeSet(*mAttributeSet, 0, lock));
784 if (updateValueMask) this->setValuesOff();
787 template<
typename T, Index Log2Dim>
791 return pos < mAttributeSet->size();
794 template<
typename T, Index Log2Dim>
798 const size_t pos = mAttributeSet->find(attributeName);
799 return pos != AttributeSet::INVALID_POS;
802 template<
typename T, Index Log2Dim>
810 return mAttributeSet->appendAttribute(
815 template<
typename T, Index Log2Dim>
826 template<
typename T, Index Log2Dim>
829 const Descriptor& expected, Descriptor::Ptr& replacement)
831 mAttributeSet->dropAttributes(pos, expected, replacement);
834 template<
typename T, Index Log2Dim>
841 template<
typename T, Index Log2Dim>
845 mAttributeSet->renameAttributes(expected, replacement);
848 template<
typename T, Index Log2Dim>
852 for (
size_t i = 0; i < mAttributeSet->size(); i++) {
858 template<
typename T, Index Log2Dim>
866 if (!allowMismatchingDescriptors && mAttributeSet->descriptor() != attributeSet->
descriptor()) {
870 mAttributeSet.reset(attributeSet);
873 template<
typename T, Index Log2Dim>
880 template<
typename T, Index Log2Dim>
884 if (offsets.size() != LeafNodeType::NUM_VALUES) {
888 for (
Index index = 0; index < offsets.size(); ++index) {
889 setOffsetOnly(index, offsets[index]);
892 if (updateValueMask) this->updateValueMask();
895 template<
typename T, Index Log2Dim>
900 for (
Index index = 1; index < BaseLeaf::SIZE; ++index) {
901 if (this->getValue(index-1) > this->getValue(index)) {
907 for (
size_t attributeIndex = 1; attributeIndex < mAttributeSet->size(); ++attributeIndex ) {
908 if (mAttributeSet->getConst(attributeIndex-1)->size() != mAttributeSet->getConst(attributeIndex)->size()) {
914 if (mAttributeSet->size() > 0 && this->getValue(BaseLeaf::SIZE-1) != mAttributeSet->getConst(0)->size()) {
919 template<
typename T, Index Log2Dim>
924 return *mAttributeSet->get(pos);
927 template<
typename T, Index Log2Dim>
932 return *mAttributeSet->getConst(pos);
935 template<
typename T, Index Log2Dim>
939 return this->attributeArray(pos);
942 template<
typename T, Index Log2Dim>
946 const size_t pos = mAttributeSet->find(attributeName);
948 return *mAttributeSet->get(pos);
951 template<
typename T, Index Log2Dim>
955 const size_t pos = mAttributeSet->find(attributeName);
957 return *mAttributeSet->getConst(pos);
960 template<
typename T, Index Log2Dim>
964 return this->attributeArray(attributeName);
967 template<
typename T, Index Log2Dim>
979 template<
typename T, Index Log2Dim>
983 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(
name);
984 return this->groupHandle(index);
987 template<
typename T, Index Log2Dim>
999 template<
typename T, Index Log2Dim>
1003 const AttributeSet::Descriptor::GroupIndex index = this->attributeSet().groupIndex(
name);
1004 return this->groupWriteHandle(index);
1007 template<
typename T, Index Log2Dim>
1008 template<
typename ValueIterT,
typename FilterT>
1020 FilterT newFilter(filter);
1021 newFilter.reset(*
this);
1027 ValueIterT valueIter = IterTraitsT::begin(*
this);
1032 template<
typename T, Index Log2Dim>
1036 const Index index = LeafNodeType::coordToOffset(ijk);
1037 assert(index < BaseLeaf::SIZE);
1038 const ValueType end = this->getValue(index);
1043 template<
typename T, Index Log2Dim>
1051 template<
typename T, Index Log2Dim>
1052 template<
typename FilterT>
1057 FilterT newFilter(filter);
1058 newFilter.reset(*
this);
1062 template<
typename T, Index Log2Dim>
1066 return this->getLastValue();
1069 template<
typename T, Index Log2Dim>
1073 if (this->isEmpty())
return 0;
1074 else if (this->isDense())
return this->
pointCount();
1078 template<
typename T, Index Log2Dim>
1082 if (this->isEmpty())
return this->
pointCount();
1083 else if (this->isDense())
return 0;
1084 return iterCount(this->beginIndexOff());
1087 template<
typename T, Index Log2Dim>
1091 if (!this->attributeSet().descriptor().hasGroup(groupName)) {
1094 GroupFilter filter(groupName, this->attributeSet());
1098 return iterCount(this->beginIndexAll(filter));
1102 template<
typename T, Index Log2Dim>
1107 for (
Index n = 0; n < LeafNodeType::NUM_VALUES; n++) {
1108 end = this->getValue(n);
1109 this->setValueMask(n, (end - start) > 0);
1114 template<
typename T, Index Log2Dim>
1118 this->buffer().
setValue(offset, val);
1119 this->setValueMaskOn(offset);
1122 template<
typename T, Index Log2Dim>
1126 this->buffer().
setValue(offset, val);
1129 template<
typename T, Index Log2Dim>
1133 BaseLeaf::readTopology(is, fromHalf);
1136 template<
typename T, Index Log2Dim>
1140 BaseLeaf::writeTopology(os, toHalf);
1143 template<
typename T, Index Log2Dim>
1150 mAttributeSet->size() +
1151 mAttributeSet->size() +
1155 template<
typename T, Index Log2Dim>
1162 template<
typename T, Index Log2Dim>
1171 std::string key(
"paged:" + std::to_string(index));
1172 auto it = auxData.find(key);
1173 if (it != auxData.end()) {
1181 std::string key(
"paged:" + std::to_string(index));
1182 auto it = auxData.find(key);
1183 if (it != auxData.end()) {
1184 return *(boost::any_cast<compression::PagedInputStream::Ptr>(it->second));
1189 return *pagedStream;
1195 std::string matchingKey(
"hasMatchingDescriptor");
1196 auto itMatching = auxData.find(matchingKey);
1197 return itMatching != auxData.end();
1202 std::string matchingKey(
"hasMatchingDescriptor");
1203 std::string descriptorKey(
"descriptorPtr");
1204 auto itMatching = auxData.find(matchingKey);
1205 auto itDescriptor = auxData.find(descriptorKey);
1211 const Descriptor::Ptr descriptor)
1213 std::string descriptorKey(
"descriptorPtr");
1214 std::string matchingKey(
"hasMatchingDescriptor");
1215 auto itMatching = auxData.find(matchingKey);
1216 if (itMatching == auxData.end()) {
1225 std::string descriptorKey(
"descriptorPtr");
1226 auto itDescriptor = auxData.find(descriptorKey);
1227 assert(itDescriptor != auxData.end());
1228 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1239 const Index pass(
static_cast<uint16_t
>(meta->pass()));
1240 const Index maximumPass(
static_cast<uint16_t
>(meta->pass() >> 16));
1242 const Index attributes = (maximumPass - 4) / 2;
1246 is.read(
reinterpret_cast<char*
>(&mVoxelBufferSize),
sizeof(uint16_t));
1247 Local::clearMatchingDescriptor(meta->auxData());
1249 else if (pass == 1) {
1251 if (Local::hasMatchingDescriptor(meta->auxData())) {
1252 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1253 mAttributeSet->resetDescriptor(descriptor,
true);
1257 is.read(
reinterpret_cast<char*
>(&header),
sizeof(uint8_t));
1258 mAttributeSet->readDescriptor(is);
1259 if (header & uint8_t(1)) {
1261 Local::insertDescriptor(meta->auxData(), descriptor);
1265 if (header & uint8_t(2)) {
1266 uint64_t bytesToSkip;
1267 is.read(
reinterpret_cast<char*
>(&bytesToSkip),
sizeof(uint64_t));
1268 if (bytesToSkip > uint64_t(0)) {
1270 if (metadata && metadata->seekable()) {
1271 is.seekg(bytesToSkip, std::ios_base::cur);
1274 std::vector<uint8_t> tempData(bytesToSkip);
1275 is.read(
reinterpret_cast<char*
>(&tempData[0]), bytesToSkip);
1280 if (header > uint8_t(3)) {
1284 mAttributeSet->readMetadata(is);
1286 else if (pass < (attributes + 2)) {
1288 const size_t attributeIndex = pass - 2;
1290 mAttributeSet->get(attributeIndex) :
nullptr;
1293 Local::getOrInsertPagedStream(meta->auxData(),
static_cast<Index>(attributeIndex));
1299 else if (pass == attributes + 2) {
1302 const Index passValue(meta->pass());
1306 nonConstMeta.
setPass(mVoxelBufferSize);
1309 BaseLeaf::readBuffers(is, fromHalf);
1312 nonConstMeta.
setPass(passValue);
1314 else if (pass < (attributes*2 + 3)) {
1316 const Index attributeIndex = pass - attributes - 3;
1318 mAttributeSet->get(attributeIndex) :
nullptr;
1321 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1327 if (pass > attributes + 3) {
1328 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1331 else if (pass < buffers()) {
1333 const Index attributeIndex = pass - attributes - 4;
1334 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1338 template<
typename T, Index Log2Dim>
1347 std::string key(
"paged:" + std::to_string(index));
1348 auto it = auxData.find(key);
1349 if (it != auxData.end()) {
1359 std::string key(
"paged:" + std::to_string(index));
1360 auto it = auxData.find(key);
1361 if (it != auxData.end()) {
1362 return *(boost::any_cast<compression::PagedOutputStream::Ptr>(it->second));
1367 return *pagedStream;
1372 const Descriptor::Ptr descriptor)
1374 std::string descriptorKey(
"descriptorPtr");
1375 std::string matchingKey(
"hasMatchingDescriptor");
1376 auto itMatching = auxData.find(matchingKey);
1377 auto itDescriptor = auxData.find(descriptorKey);
1378 if (itMatching == auxData.end()) {
1381 assert(itDescriptor == auxData.end());
1386 bool matching = boost::any_cast<bool>(itMatching->second);
1387 if (!matching)
return;
1388 assert(itDescriptor != auxData.end());
1391 const Descriptor::Ptr existingDescriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1392 if (*existingDescriptor != *descriptor) {
1400 std::string matchingKey(
"hasMatchingDescriptor");
1401 auto itMatching = auxData.find(matchingKey);
1403 if (itMatching == auxData.end())
return false;
1405 if (!boost::any_cast<bool>(itMatching->second))
return false;
1411 std::string descriptorKey(
"descriptorPtr");
1412 auto itDescriptor = auxData.find(descriptorKey);
1414 if (itDescriptor == auxData.end())
return nullptr;
1416 const Descriptor::Ptr descriptor = boost::any_cast<AttributeSet::Descriptor::Ptr>(itDescriptor->second);
1423 std::string matchingKey(
"hasMatchingDescriptor");
1424 std::string descriptorKey(
"descriptorPtr");
1425 auto itMatching = auxData.find(matchingKey);
1426 auto itDescriptor = auxData.find(descriptorKey);
1438 const Index pass(
static_cast<uint16_t
>(meta->pass()));
1443 if (meta->countingPasses()) {
1444 const Index requiredPasses = this->buffers();
1445 if (requiredPasses > pass) {
1446 meta->setPass(requiredPasses);
1451 const Index maximumPass(
static_cast<uint16_t
>(meta->pass() >> 16));
1452 const Index attributes = (maximumPass - 4) / 2;
1458 Local::insertDescriptor(meta->auxData(), mAttributeSet->descriptorPtr());
1460 else if (pass == 1) {
1462 bool matchingDescriptor = Local::hasMatchingDescriptor(meta->auxData());
1463 if (matchingDescriptor) {
1464 AttributeSet::Descriptor::Ptr descriptor = Local::retrieveMatchingDescriptor(meta->auxData());
1468 os.write(
reinterpret_cast<const char*
>(&header),
sizeof(uint8_t));
1469 mAttributeSet->writeDescriptor(os,
false);
1475 os.write(
reinterpret_cast<const char*
>(&header),
sizeof(uint8_t));
1476 mAttributeSet->writeDescriptor(os,
false);
1478 mAttributeSet->writeMetadata(os,
false,
true);
1480 else if (pass < attributes + 2) {
1482 const Index attributeIndex = pass - 2;
1485 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1488 mAttributeSet->getConst(attributeIndex) :
nullptr;
1491 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1497 else if (pass == attributes + 2) {
1498 const Index attributeIndex = pass - 3;
1499 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1501 BaseLeaf::writeBuffers(os, toHalf);
1503 else if (pass < (attributes*2 + 3)) {
1505 const Index attributeIndex = pass - attributes - 3;
1507 if (pass > attributes + 2) {
1508 Local::destroyPagedStream(meta->auxData(), attributeIndex-1);
1511 mAttributeSet->getConst(attributeIndex) :
nullptr;
1514 Local::getOrInsertPagedStream(meta->auxData(), attributeIndex);
1520 else if (pass < buffers()) {
1521 Local::clearMatchingDescriptor(meta->auxData());
1523 const Index attributeIndex = pass - attributes - 4;
1524 Local::destroyPagedStream(meta->auxData(), attributeIndex);
1528 template<
typename T, Index Log2Dim>
1532 return BaseLeaf::memUsage() + mAttributeSet->
memUsage();
1535 template<
typename T, Index Log2Dim>
1539 BaseLeaf::evalActiveBoundingBox(bbox, visitVoxels);
1542 template<
typename T, Index Log2Dim>
1546 return BaseLeaf::getNodeBoundingBox();
1549 template<
typename T, Index Log2Dim>
1553 if (!this->allocate())
return;
1555 this->assertNonModifiableUnlessZero(value);
1560 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1562 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1564 const Index offset = offsetXY + (z & (DIM-1u));
1565 this->setValueMask(offset, active);
1571 template<
typename T, Index Log2Dim>
1575 this->assertNonModifiableUnlessZero(value);
1579 if (active) this->setValuesOn();
1580 else this->setValuesOff();
1587 template <
typename Po
intDataTreeT>
1588 inline AttributeSet::Descriptor::Ptr
1591 auto leafIter = tree.beginLeaf();
1592 if (!leafIter)
return nullptr;
1594 const AttributeSet::Descriptor& descriptor = leafIter->attributeSet().descriptor();
1595 auto newDescriptor = std::make_shared<AttributeSet::Descriptor>(descriptor);
1596 for (; leafIter; ++leafIter) {
1597 leafIter->resetDescriptor(newDescriptor);
1600 return newDescriptor;
1604 template <
typename Po
intDataTreeT>
1608 auto leafIter = tree.beginLeaf();
1609 for (; leafIter; ++leafIter) {
1610 for (
size_t i = 0; i < leafIter->attributeSet().size(); i++) {
1611 leafIter->attributeArray(i).setStreaming(on);
1617 template <
typename Po
intDataTreeT>
1619 prefetch(PointDataTreeT& tree,
bool position,
bool otherAttributes)
1624 auto leaf = tree.cbeginLeaf();
1627 const auto& attributeSet = leaf->attributeSet();
1631 for ( ; leaf; ++leaf) {
1632 leaf->buffer().data();
1637 size_t positionIndex = attributeSet.find(
"P");
1639 if (position && positionIndex != AttributeSet::INVALID_POS) {
1640 for (leaf = tree.cbeginLeaf(); leaf; ++leaf) {
1641 assert(leaf->hasAttribute(positionIndex));
1642 leaf->constAttributeArray(positionIndex).loadData();
1648 if (otherAttributes) {
1649 const size_t attributes = attributeSet.size();
1650 for (
size_t attributeIndex = 0; attributeIndex < attributes; attributeIndex++) {
1651 if (attributeIndex == positionIndex)
continue;
1652 for (leaf = tree.cbeginLeaf(); leaf; ++leaf) {
1653 assert(leaf->hasAttribute(attributeIndex));
1654 leaf->constAttributeArray(attributeIndex).loadData();
1661 namespace internal {
1678 template<
typename HeadT,
int HeadLevel>
1683 using Type =
typename SubtreeT::template Append<RootNodeT>;
1688 template <
typename ChildT, Index Log2Dim,
int HeadLevel>
1693 using Type =
typename SubtreeT::template Append<InternalNodeT>;
1698 template <
typename ChildT, Index Log2Dim>
1712 template <
typename TreeType>
1731 template<Index Dim1,
typename T2>
1732 struct SameLeafConfig<Dim1, points::PointDataLeafNode<T2, Dim1>> {
static const bool value =
true; };
1738 #endif // OPENVDB_POINTS_POINT_DATA_GRID_HAS_BEEN_INCLUDED
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:49
typename BaseLeaf::ChildOff ChildOff
Definition: PointDataGrid.h:605
static index::State state()
Definition: AttributeGroup.h:145
Definition: AttributeGroup.h:73
void setOutputStream(std::ostream &os)
Definition: StreamCompression.h:260
A list of types (not necessarily unique)
Definition: Types.h:653
ChildAllIter endChildAll()
Definition: PointDataGrid.h:739
Recursive node chain which generates a openvdb::TypeList value converted types of nodes to PointDataG...
Definition: PointDataGrid.h:1680
ChildOffCIter beginChildOff() const
Definition: PointDataGrid.h:725
ValueOnIter endValueOn()
Definition: PointDataGrid.h:713
virtual void readPagedBuffers(compression::PagedInputStream &)=0
Read attribute buffers from a paged stream.
Set of Attribute Arrays which tracks metadata about each array.
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
Convenience wrappers to using Blosc and reading and writing of Paged data.
ChildOffIter beginChildOff()
Definition: PointDataGrid.h:726
const PointDataLeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition: PointDataGrid.h:479
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &value, TopologyCopy)
Definition: PointDataGrid.h:297
void setValueOnlyAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:569
ChildOnCIter endChildOn() const
Definition: PointDataGrid.h:732
std::shared_ptr< PagedInputStream > Ptr
Definition: StreamCompression.h:211
ValueOnCIter cbeginValueOn() const
Definition: PointDataGrid.h:701
void clip(const CoordBBox &, const ValueType &value)
Definition: PointDataGrid.h:562
IndexIter< ValueOffCIter, FilterT > beginIndexOff(const FilterT &filter) const
Definition: PointDataGrid.h:688
void modifyValue(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:556
Definition: AttributeGroup.h:102
void flush()
Manually flushes the current page to disk if non-zero.
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition: StreamCompression.h:218
void signedFloodFill(const ValueType &, const ValueType &)
Definition: PointDataGrid.h:589
bool hasSameTopology(const PointDataLeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
Definition: PointDataGrid.h:439
ChildOnIter beginChildOn()
Definition: PointDataGrid.h:723
virtual __attribute__((deprecated)) virtual AttributeArray Index size() const =0
void setValuesOn()
Definition: PointDataGrid.h:549
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:465
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:1045
typename BaseLeaf::template ChildIter< MaskOffIterator, const PointDataLeafNode, ChildOff > ChildOffCIter
Definition: PointDataGrid.h:645
Index32 Index
Definition: Types.h:31
Definition: LeafNode.h:204
void setValuesOff()
Definition: PointDataGrid.h:550
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition: PointDataGrid.h:463
Definition: LeafNode.h:912
ChildOnCIter cendChildOn() const
Definition: PointDataGrid.h:731
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:59
#define VMASK_
Definition: PointDataGrid.h:700
void fill(const CoordBBox &, const ValueType &, bool)
Definition: PointDataGrid.h:1551
std::string Name
Definition: Name.h:17
void setValueOffAndCache(const Coord &, const ValueType &, AccessorT &)
Definition: PointDataGrid.h:577
A forward iterator over array indices in a single voxel.
Definition: IndexIterator.h:65
typename BaseLeaf::template ChildIter< MaskOnIterator, PointDataLeafNode, ChildOn > ChildOnIter
Definition: PointDataGrid.h:639
const PointDataLeafNode * probeLeaf(const Coord &) const
Definition: PointDataGrid.h:482
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition: StreamCompression.h:255
typename BaseLeaf::ValueOn ValueOn
Definition: PointDataGrid.h:595
typename BaseLeaf::template ValueIter< MaskOffIterator, PointDataLeafNode, const ValueType, ValueOff > ValueOffIter
Definition: PointDataGrid.h:631
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:875
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
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:30
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
@ NONE
Definition: IndexIterator.h:42
ChildOffIter endChildOff()
Definition: PointDataGrid.h:736
ChildOnIter endChildOn()
Definition: PointDataGrid.h:733
void compactAttributes(PointDataTreeT &tree)
Compact attributes in a VDB tree (if possible).
Definition: PointAttribute.h:524
typename BaseLeaf::template ValueIter< MaskDenseIterator, const PointDataLeafNode, const ValueType, ValueAll > ValueAllCIter
Definition: PointDataGrid.h:637
Int32 y() const
Definition: Coord.h:132
ValueAllCIter cbeginValueAll() const
Definition: PointDataGrid.h:707
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
bool operator==(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:445
ChildOffCIter cendChildOff() const
Definition: PointDataGrid.h:734
ValueOffIter beginValueOff()
Definition: PointDataGrid.h:706
A forward iterator over array indices with filtering IteratorT can be either IndexIter or ValueIndexI...
Definition: IndexIterator.h:140
Library and file format version numbers.
bool operator!=(const PointDataLeafNode &other) const
Definition: PointDataGrid.h:450
typename BaseLeaf::template ChildIter< MaskOffIterator, PointDataLeafNode, ChildOff > ChildOffIter
Definition: PointDataGrid.h:643
Definition: NodeMasks.h:209
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
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition: PointDataGrid.h:484
Attribute Array storage templated on type and compression codec.
void signedFloodFill(const ValueType &)
Definition: PointDataGrid.h:588
uint64_t Index64
Definition: Types.h:30
ChildOffCIter cbeginChildOff() const
Definition: PointDataGrid.h:724
typename BaseLeaf::template ValueIter< MaskOnIterator, PointDataLeafNode, const ValueType, ValueOn > ValueOnIter
Definition: PointDataGrid.h:627
ChildAllCIter endChildAll() const
Definition: PointDataGrid.h:738
Int32 x() const
Definition: Coord.h:131
typename BaseLeaf::ChildOn ChildOn
Definition: PointDataGrid.h:604
ValueOffCIter cbeginValueOff() const
Definition: PointDataGrid.h:704
ChildAllCIter beginChildAll() const
Definition: PointDataGrid.h:728
ValueOnCIter cendValueOn() const
Definition: PointDataGrid.h:711
Definition: Exceptions.h:58
Definition: InternalNode.h:34
const PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition: PointDataGrid.h:481
ValueOffCIter cendValueOff() const
Definition: PointDataGrid.h:714
const Name const NamePair const Index strideOrTotalSize
Definition: PointAttribute.h:546
Definition: RootNode.h:39
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
void setActiveState(Index offset, bool on)
Definition: PointDataGrid.h:530
ChildOnCIter beginChildOn() const
Definition: PointDataGrid.h:722
Definition: PointDataGrid.h:233
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:572
Definition: NodeMasks.h:240
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:63
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
void setValueOff(Index, const ValueType &)
Definition: PointDataGrid.h:539
IndexIter< IterT, FilterT > beginIndex(const FilterT &filter) const
ValueOffCIter endValueOff() const
Definition: PointDataGrid.h:715
void setValueOnly(const Coord &, const ValueType &)
Definition: PointDataGrid.h:532
ChildOnCIter cbeginChildOn() const
Definition: PointDataGrid.h:721
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:1047
void fill(const ValueType &value)
Definition: PointDataGrid.h:565
ValueOnCIter beginValueOn() const
Definition: PointDataGrid.h:702
typename PointDataNodeChain< typename HeadT::ChildNodeType, HeadLevel-1 >::Type SubtreeT
Definition: PointDataGrid.h:1681
Attribute Group access and filtering for iteration.
PointDataLeafNode(PartialCreate, const Coord &coords, const T &value=zeroVal< T >(), bool active=false)
Definition: PointDataGrid.h:308
PointDataLeafNode(const PointDataLeafNode &other)
Construct using deep copy of other PointDataLeafNode.
Definition: PointDataGrid.h:268
typename BaseLeaf::template DenseIter< const PointDataLeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: PointDataGrid.h:649
IndexAllIter beginIndexAll() const
Leaf index iterator.
Definition: PointDataGrid.h:657
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: PointDataGrid.h:610
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...
int32_t Int32
Definition: Types.h:33
Definition: TreeIterator.h:60
Definition: Exceptions.h:60
Index filtering on group membership.
Definition: AttributeGroup.h:135
void assertNonmodifiable()
Definition: PointDataGrid.h:518
typename BaseLeaf::ValueOff ValueOff
Definition: PointDataGrid.h:596
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:641
PointDataLeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition: PointDataGrid.h:472
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:102
std::shared_ptr< PointDataLeafNode > Ptr
Definition: PointDataGrid.h:237
Typed class for storing attribute data.
Definition: AttributeArray.h:566
ValueAllIter beginValueAll()
Definition: PointDataGrid.h:709
void setValueOff(Index offset)
Definition: PointDataGrid.h:536
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:314
void setInputStream(std::istream &is)
Definition: StreamCompression.h:223
const Name const NamePair const Index const bool constantStride
Definition: PointAttribute.h:547
typename SubtreeT::template Append< InternalNodeT > Type
Definition: PointDataGrid.h:1693
Definition: LeafNode.h:203
virtual bool compact()=0
Compact the existing array to become uniform if all values are identical.
typename TreeType::RootNodeType RootNodeT
Definition: PointDataGrid.h:1714
void setValueOff(const Coord &xyz)
Definition: PointDataGrid.h:535
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition: NodeMasks.h:308
void setValueOn(Index offset)
Definition: PointDataGrid.h:542
AttributeSet::Descriptor::Ptr makeDescriptorUnique(PointDataTreeT &tree)
Deep copy the descriptor across all leaf nodes.
Definition: PointDataGrid.h:1589
typename BaseLeaf::template ValueIter< MaskDenseIterator, PointDataLeafNode, const ValueType, ValueAll > ValueAllIter
Definition: PointDataGrid.h:635
const AttributeSet & attributeSet() const
Retrieve the attribute set.
Definition: PointDataGrid.h:316
PointDataLeafNode(const tree::LeafNode< ValueType, Log2Dim > &other, const T &, const T &, TopologyCopy)
Definition: PointDataGrid.h:304
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 endValueAll()
Definition: PointDataGrid.h:719
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
IndexOffIter beginIndexOff() const
Definition: PointDataGrid.h:667
Int32 z() const
Definition: Coord.h:133
std::unique_ptr< AttributeSet > UniquePtr
Definition: AttributeSet.h:45
typename BaseLeaf::template ValueIter< MaskOffIterator, const PointDataLeafNode, const ValueType, ValueOff > ValueOffCIter
Definition: PointDataGrid.h:633
Similiar to ValueConverter, but allows for tree configuration conversion to a PointDataTree....
Definition: PointDataGrid.h:1713
void assertNonModifiableUnlessZero(const ValueType &value)
Definition: PointDataGrid.h:525
Definition: LeafNode.h:203
ChildOffCIter endChildOff() const
Definition: PointDataGrid.h:735
PointDataLeafNode(const tools::PointIndexLeafNode< OtherValueType, Log2Dim > &other)
Definition: PointDataGrid.h:290
IndexIter< ValueAllCIter, FilterT > beginIndexAll(const FilterT &filter) const
Filtered leaf index iterator.
Definition: PointDataGrid.h:678
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:377
ValueAllCIter cendValueAll() const
Definition: PointDataGrid.h:717
std::shared_ptr< PagedOutputStream > Ptr
Definition: StreamCompression.h:248
void uninitialize()
Global deregistration of point data-related types.
typename internal::PointDataNodeChain< RootNodeT, RootNodeT::LEVEL >::Type NodeChainT
Definition: PointDataGrid.h:1715
ChildAllCIter cbeginChildAll() const
Definition: PointDataGrid.h:727
Attribute array storage for string data using Descriptor Metadata.
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition: LeafNode.h:38
Index64 memUsage() const
Definition: PointDataGrid.h:1530
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
void setValueOn(const Coord &, const ValueType &)
Definition: PointDataGrid.h:544
Leaf nodes that require multi-pass I/O must inherit from this struct.
Definition: io.h:124
void modifyValueAndActiveStateAndCache(const Coord &, const ModifyOp &, AccessorT &)
Definition: PointDataGrid.h:572
Definition: LeafNode.h:203
void addLeaf(PointDataLeafNode *)
Definition: PointDataGrid.h:452
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:580
AttributeSet::Descriptor Descriptor
Definition: PointDataGrid.h:243
void setValueOnly(Index, const ValueType &)
Definition: PointDataGrid.h:533
PointDataLeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition: PointDataGrid.h:460
Base class for storing attribute data.
Definition: AttributeArray.h:93
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:39
typename NodeMaskType::OnIterator MaskOnIterator
Definition: PointDataGrid.h:608
ChildAllCIter cendChildAll() const
Definition: PointDataGrid.h:737
typename PointDataNodeChain< ChildT, HeadLevel-1 >::Type SubtreeT
Definition: PointDataGrid.h:1691
void setValueOn(const Coord &xyz)
Definition: PointDataGrid.h:541
void prefetch(PointDataTreeT &tree, bool position=true, bool otherAttributes=true)
Sequentially pre-fetch all delayed-load voxel and attribute data from disk in order to accelerate sub...
Definition: PointDataGrid.h:1619
const Coord & max() const
Definition: Coord.h:322
void writeCompressedValuesSize(std::ostream &os, const T *srcBuf, Index srcCount)
Definition: PointDataGrid.h:139
Integer wrapper, required to distinguish PointIndexGrid and PointDataGrid from Int32Grid and Int64Gri...
Definition: Types.h:134
const Coord & min() const
Definition: Coord.h:321
Definition: Exceptions.h:57
void setValue(const Coord &, const ValueType &)
Definition: PointDataGrid.h:547
typename SubtreeT::template Append< RootNodeT > Type
Definition: PointDataGrid.h:1683
void negate()
Definition: PointDataGrid.h:591
void modifyValueAndActiveState(const Coord &, const ModifyOp &)
Definition: PointDataGrid.h:559
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
const Name & name
Definition: PointAttribute.h:544
PointIndex< Index32, 1 > PointDataIndex32
Definition: Types.h:158
typename NodeMaskType::OffIterator MaskOffIterator
Definition: PointDataGrid.h:609
IndexOnIter beginIndexOn() const
Definition: PointDataGrid.h:662
void resetBackground(const ValueType &, const ValueType &newBackground)
Definition: PointDataGrid.h:584
@ ALL
Definition: IndexIterator.h:43
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
std::pair< ValueType, ValueType > ValueTypePair
Definition: PointDataGrid.h:240
T ValueType
Definition: PointDataGrid.h:239
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.
PointDataLeafNode * probeLeaf(const Coord &)
Definition: PointDataGrid.h:470
void addLeafAndCache(PointDataLeafNode *, AccessorT &)
Definition: PointDataGrid.h:454
Definition: AttributeArray.h:119
ValueOnIter beginValueOn()
Definition: PointDataGrid.h:703
ValueOnCIter endValueOn() const
Definition: PointDataGrid.h:712
ChildAllIter beginChildAll()
Definition: PointDataGrid.h:729
Definition: LeafNode.h:204
IndexIter< ValueOnCIter, FilterT > beginIndexOn(const FilterT &filter) const
Definition: PointDataGrid.h:683
Definition: LeafNode.h:204
Definition: Exceptions.h:65
const char * typeNameAsString< Vec3f >()
Definition: Types.h:898
void setStreamingMode(PointDataTreeT &tree, bool on=true)
Toggle the streaming mode on all attributes in the tree to collapse the attributes after deconstructi...
Definition: PointDataGrid.h:1606
Definition: Exceptions.h:13
void modifyValue(Index, const ModifyOp &)
Definition: PointDataGrid.h:553
ValueOffCIter beginValueOff() const
Definition: PointDataGrid.h:705
void setValueOff(const Coord &, const ValueType &)
Definition: PointDataGrid.h:538
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:319
void setValueOn(Index, const ValueType &)
Definition: PointDataGrid.h:545
virtual void writePagedBuffers(compression::PagedOutputStream &, bool outputTransient) const =0
~PointDataLeafNode()=default
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:51
ValueAllCIter endValueAll() const
Definition: PointDataGrid.h:718
typename BaseLeaf::template DenseIter< PointDataLeafNode, ValueType, ChildAll > ChildAllIter
Definition: PointDataGrid.h:647
std::vector< ValueType > IndexArray
Definition: PointDataGrid.h:241
void setActiveState(const Coord &xyz, bool on)
Definition: PointDataGrid.h:529
typename BaseLeaf::ValueAll ValueAll
Definition: PointDataGrid.h:597
ValueAllCIter beginValueAll() const
Definition: PointDataGrid.h:708
typename BaseLeaf::template ValueIter< MaskOnIterator, const PointDataLeafNode, const ValueType, ValueOn > ValueOnCIter
Definition: PointDataGrid.h:629
void initialize()
Global registration of point data-related types.
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:246
ValueOffIter endValueOff()
Definition: PointDataGrid.h:716
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
void reorderAttributes(const Descriptor::Ptr &replacement)
Reorder attribute set.
Definition: PointDataGrid.h:836
Definition: NodeMasks.h:271
PointDataLeafNode()
Default constructor.
Definition: PointDataGrid.h:262
typename BaseLeaf::ChildAll ChildAll
Definition: PointDataGrid.h:606