16 #ifndef OPENVDB_TOOLS_POINT_INDEX_GRID_HAS_BEEN_INCLUDED
17 #define OPENVDB_TOOLS_POINT_INDEX_GRID_HAS_BEEN_INCLUDED
31 #include <tbb/blocked_range.h>
32 #include <tbb/parallel_for.h>
38 #include <type_traits>
48 template<Index,
typename>
struct SameLeafConfig;
92 template<
typename Gr
idT,
typename Po
intArrayT>
93 inline typename GridT::Ptr
102 template<
typename Gr
idT,
typename Po
intArrayT>
103 inline typename GridT::Ptr
112 template<
typename Po
intArrayT,
typename Gr
idT>
118 template<
typename Gr
idT,
typename Po
intArrayT>
119 inline typename GridT::ConstPtr
123 template<
typename Gr
idT,
typename Po
intArrayT>
124 inline typename GridT::Ptr
132 template<
typename TreeType = Po
intIndexTree>
180 template<
typename Po
intArray>
195 template<
typename Po
intArray>
206 template<
typename Po
intArray>
221 template<
typename Po
intArray>
234 bool test()
const {
return mRange.first < mRange.second || mIter != mRangeList.end(); }
235 operator bool()
const {
return this->
test(); }
258 using Range = std::pair<const ValueType*, const ValueType*>;
259 using RangeDeque = std::deque<Range>;
260 using RangeDequeCIter =
typename RangeDeque::const_iterator;
261 using IndexArray = std::unique_ptr<ValueType[]>;
267 RangeDeque mRangeList;
268 RangeDequeCIter mIter;
270 IndexArray mIndexArray;
271 size_t mIndexArraySize;
304 template<
typename Po
intArray,
typename TreeType = Po
intIndexTree>
325 template<
typename FilterType>
343 namespace point_index_grid_internal {
345 template<
typename Po
intArrayT>
346 struct ValidPartitioningOp
348 ValidPartitioningOp(std::atomic<bool>& hasChanged,
352 , mHasChanged(&hasChanged)
356 template <
typename LeafT>
357 void operator()(LeafT &leaf,
size_t )
const
359 if ((*mHasChanged)) {
360 thread::cancelGroupExecution();
366 using PosType =
typename PointArrayT::PosType;
368 typename LeafT::ValueOnCIter iter;
373 *
begin =
static_cast<IndexT*
>(
nullptr),
374 *
end = static_cast<IndexT*>(
nullptr);
376 for (iter = leaf.cbeginValueOn(); iter; ++iter) {
378 if ((*mHasChanged))
break;
380 voxelCoord = iter.getCoord();
381 leaf.getIndices(iter.pos(),
begin,
end);
383 while (begin <
end) {
385 mPoints->getPos(*begin, point);
386 if (voxelCoord != mTransform->worldToIndexCellCentered(point)) {
387 mHasChanged->store(
true);
397 PointArrayT
const *
const mPoints;
398 math::Transform
const *
const mTransform;
399 std::atomic<bool> *
const mHasChanged;
403 template<
typename LeafNodeT>
404 struct PopulateLeafNodesOp
406 using IndexT = uint32_t;
407 using Partitioner = PointPartitioner<IndexT, LeafNodeT::LOG2DIM>;
409 PopulateLeafNodesOp(std::unique_ptr<LeafNodeT*[]>& leafNodes,
410 const Partitioner& partitioner)
411 : mLeafNodes(leafNodes.
get())
412 , mPartitioner(&partitioner)
416 void operator()(
const tbb::blocked_range<size_t>&
range)
const {
418 using VoxelOffsetT =
typename Partitioner::VoxelOffsetType;
420 size_t maxPointCount = 0;
421 for (
size_t n = range.begin(),
N = range.
end();
n !=
N; ++
n) {
422 maxPointCount =
std::max(maxPointCount, mPartitioner->indices(
n).size());
428 std::unique_ptr<VoxelOffsetT[]>
offsets{
new VoxelOffsetT[maxPointCount]};
429 std::unique_ptr<IndexT[]>
histogram{
new IndexT[voxelCount]};
431 VoxelOffsetT
const *
const voxelOffsets = mPartitioner->voxelOffsets().get();
433 for (
size_t n = range.begin(),
N = range.
end();
n !=
N; ++
n) {
435 LeafNodeT* node =
new LeafNodeT();
436 node->setOrigin(mPartitioner->origin(
n));
438 typename Partitioner::IndexIterator it = mPartitioner->indices(
n);
441 IndexT
const *
const indices = &*it;
445 offsets[i] = voxelOffsets[ indices[i] ];
449 memset(&
histogram[0], 0, voxelCount *
sizeof(IndexT));
454 typename LeafNodeT::NodeMaskType&
mask = node->getValueMask();
458 IndexT
count = 0, startOffset;
459 for (
int i = 0; i <
int(voxelCount); ++i) {
466 buffer.setValue(i, count);
470 node->indices().resize(pointCount);
478 mLeafNodes[
n] = node;
484 LeafNodeT* *
const mLeafNodes;
485 Partitioner
const *
const mPartitioner;
490 template<
typename TreeType,
typename Po
intArray>
492 constructPointTree(TreeType& tree,
const math::Transform& xform,
const PointArray&
points)
494 using LeafType =
typename TreeType::LeafNodeType;
496 std::unique_ptr<LeafType*[]> leafNodes;
497 size_t leafNodeCount = 0;
503 PointPartitioner<uint32_t, LeafType::LOG2DIM> partitioner;
504 partitioner.construct(points, xform,
false,
true);
506 if (!partitioner.usingCellCenteredTransform()) {
508 "cell-centered transform.");
511 leafNodeCount = partitioner.size();
512 leafNodes.reset(
new LeafType*[leafNodeCount]);
514 const tbb::blocked_range<size_t>
range(0, leafNodeCount);
518 tree::ValueAccessor<TreeType> acc(tree);
519 for (
size_t n = 0;
n < leafNodeCount; ++
n) {
520 acc.addLeaf(leafNodes[
n]);
530 dequeToArray(
const std::deque<T>& d, std::unique_ptr<T[]>&
a,
size_t&
size)
533 a.reset(
new T[size]);
534 typename std::deque<T>::const_iterator it = d.begin(), itEnd = d.end();
536 for ( ; it != itEnd; ++it, ++item) *item = *it;
541 constructExclusiveRegions(std::vector<CoordBBox>& regions,
546 Coord cmin = ibox.min();
547 Coord cmax = ibox.max();
550 regions.push_back(bbox);
551 regions.back().max().z() = cmin.z();
554 regions.push_back(bbox);
555 regions.back().min().z() = cmax.z();
561 regions.push_back(bbox);
563 lastRegion->min().z() = cmin.z();
564 lastRegion->max().z() = cmax.z();
565 lastRegion->max().x() = cmin.x();
568 regions.push_back(*lastRegion);
569 lastRegion = ®ions.back();
570 lastRegion->min().x() = cmax.x();
571 lastRegion->max().x() = bbox.max().x();
577 regions.push_back(*lastRegion);
578 lastRegion = ®ions.back();
579 lastRegion->min().x() = cmin.x();
580 lastRegion->max().x() = cmax.x();
581 lastRegion->max().y() = cmin.y();
584 regions.push_back(*lastRegion);
585 lastRegion = ®ions.back();
586 lastRegion->min().y() = cmax.y();
587 lastRegion->max().y() = bbox.max().y();
591 template<
typename Po
intArray,
typename IndexT>
594 using PosType =
typename PointArray::PosType;
596 using Range = std::pair<const IndexT*, const IndexT*>;
597 using RangeDeque = std::deque<Range>;
598 using IndexDeque = std::deque<IndexT>;
600 BBoxFilter(RangeDeque& ranges, IndexDeque& indices,
const BBoxd& bbox,
601 const PointArray& points,
const math::Transform& xform)
606 , mMap(*xform.baseMap())
610 template <
typename LeafNodeType>
611 void filterLeafNode(
const LeafNodeType& leaf)
613 typename LeafNodeType::ValueOnCIter iter;
615 *begin =
static_cast<IndexT*
>(
nullptr),
616 *
end = static_cast<IndexT*>(
nullptr);
617 for (iter = leaf.cbeginValueOn(); iter; ++iter) {
618 leaf.getIndices(iter.pos(),
begin,
end);
619 filterVoxel(iter.getCoord(),
begin,
end);
623 void filterVoxel(
const Coord&,
const IndexT* begin,
const IndexT*
end)
628 mPoints.getPos(*begin, vec);
630 if (mRegion.isInside(mMap.applyInverseMap(vec))) {
631 mIndices.push_back(*begin);
638 IndexDeque& mIndices;
641 const math::MapBase& mMap;
645 template<
typename Po
intArray,
typename IndexT>
646 struct RadialRangeFilter
648 using PosType =
typename PointArray::PosType;
650 using Range = std::pair<const IndexT*, const IndexT*>;
651 using RangeDeque = std::deque<Range>;
652 using IndexDeque = std::deque<IndexT>;
654 RadialRangeFilter(RangeDeque& ranges, IndexDeque& indices,
const Vec3d& xyz,
double radius,
655 const PointArray& points,
const math::Transform& xform,
656 const double leafNodeDim,
const bool subvoxelAccuracy)
660 , mWSCenter(xform.indexToWorld(xyz))
661 , mVoxelDist1(ScalarType(0.0))
662 , mVoxelDist2(ScalarType(0.0))
663 , mLeafNodeDist1(ScalarType(0.0))
664 , mLeafNodeDist2(ScalarType(0.0))
665 , mWSRadiusSqr(ScalarType(radius * xform.voxelSize()[0]))
667 , mSubvoxelAccuracy(subvoxelAccuracy)
669 const ScalarType voxelRadius = ScalarType(
std::sqrt(3.0) * 0.5);
670 mVoxelDist1 = voxelRadius + ScalarType(radius);
671 mVoxelDist1 *= mVoxelDist1;
673 if (radius > voxelRadius) {
674 mVoxelDist2 = ScalarType(radius) - voxelRadius;
675 mVoxelDist2 *= mVoxelDist2;
678 const ScalarType leafNodeRadius = ScalarType(leafNodeDim *
std::sqrt(3.0) * 0.5);
679 mLeafNodeDist1 = leafNodeRadius + ScalarType(radius);
680 mLeafNodeDist1 *= mLeafNodeDist1;
682 if (radius > leafNodeRadius) {
683 mLeafNodeDist2 = ScalarType(radius) - leafNodeRadius;
684 mLeafNodeDist2 *= mLeafNodeDist2;
687 mWSRadiusSqr *= mWSRadiusSqr;
690 template <
typename LeafNodeType>
691 void filterLeafNode(
const LeafNodeType& leaf)
694 const Coord& ijk = leaf.origin();
696 vec[0] = ScalarType(ijk[0]);
697 vec[1] = ScalarType(ijk[1]);
698 vec[2] = ScalarType(ijk[2]);
699 vec += ScalarType(LeafNodeType::DIM - 1) * 0.5;
702 const ScalarType
dist = vec.lengthSqr();
703 if (dist > mLeafNodeDist1)
return;
705 if (mLeafNodeDist2 > 0.0 && dist < mLeafNodeDist2) {
706 const IndexT* begin = &leaf.indices().front();
707 mRanges.push_back(Range(begin, begin + leaf.indices().size()));
712 typename LeafNodeType::ValueOnCIter iter;
714 *begin =
static_cast<IndexT*
>(
nullptr),
715 *end = static_cast<IndexT*>(
nullptr);
716 for (iter = leaf.cbeginValueOn(); iter; ++iter) {
717 leaf.getIndices(iter.pos(),
begin,
end);
718 filterVoxel(iter.getCoord(),
begin,
end);
722 void filterVoxel(
const Coord& ijk,
const IndexT* begin,
const IndexT* end)
727 vec[0] = mCenter[0] - ScalarType(ijk[0]);
728 vec[1] = mCenter[1] - ScalarType(ijk[1]);
729 vec[2] = mCenter[2] - ScalarType(ijk[2]);
731 const ScalarType dist = vec.lengthSqr();
732 if (dist > mVoxelDist1)
return;
734 if (!mSubvoxelAccuracy || (mVoxelDist2 > 0.0 && dist < mVoxelDist2)) {
735 if (!mRanges.empty() && mRanges.back().second ==
begin) {
736 mRanges.back().second =
end;
738 mRanges.push_back(Range(begin, end));
745 while (begin < end) {
746 mPoints.getPos(*begin, vec);
747 vec = mWSCenter - vec;
749 if (vec.lengthSqr() < mWSRadiusSqr) {
750 mIndices.push_back(*begin);
758 IndexDeque& mIndices;
759 const PosType mCenter, mWSCenter;
760 ScalarType mVoxelDist1, mVoxelDist2, mLeafNodeDist1, mLeafNodeDist2, mWSRadiusSqr;
762 const bool mSubvoxelAccuracy;
769 template<
typename RangeFilterType,
typename LeafNodeType>
771 filteredPointIndexSearchVoxels(RangeFilterType&
filter,
772 const LeafNodeType& leaf,
const Coord&
min,
const Coord&
max)
775 Index xPos(0), yPos(0), pos(0);
778 const PointIndexT* dataPtr = &leaf.indices().front();
779 PointIndexT beginOffset, endOffset;
781 for (ijk[0] = min[0]; ijk[0] <= max[0]; ++ijk[0]) {
782 xPos = (ijk[0] & (LeafNodeType::DIM - 1u)) << (2 * LeafNodeType::LOG2DIM);
783 for (ijk[1] = min[1]; ijk[1] <= max[1]; ++ijk[1]) {
784 yPos = xPos + ((ijk[1] & (LeafNodeType::DIM - 1u)) << LeafNodeType::LOG2DIM);
785 for (ijk[2] = min[2]; ijk[2] <= max[2]; ++ijk[2]) {
786 pos = yPos + (ijk[2] & (LeafNodeType::DIM - 1u));
788 beginOffset = (pos == 0 ? PointIndexT(0) : leaf.
getValue(pos - 1));
789 endOffset = leaf.getValue(pos);
791 if (endOffset > beginOffset) {
792 filter.filterVoxel(ijk, dataPtr + beginOffset, dataPtr + endOffset);
800 template<
typename RangeFilterType,
typename ConstAccessor>
802 filteredPointIndexSearch(RangeFilterType& filter, ConstAccessor& acc,
const CoordBBox& bbox)
804 using LeafNodeType =
typename ConstAccessor::TreeType::LeafNodeType;
805 Coord ijk(0), ijkMax(0), ijkA(0), ijkB(0);
806 const Coord leafMin = bbox.min() & ~(LeafNodeType::DIM - 1);
807 const Coord leafMax = bbox.max() & ~(LeafNodeType::DIM - 1);
809 for (ijk[0] = leafMin[0]; ijk[0] <= leafMax[0]; ijk[0] += LeafNodeType::DIM) {
810 for (ijk[1] = leafMin[1]; ijk[1] <= leafMax[1]; ijk[1] += LeafNodeType::DIM) {
811 for (ijk[2] = leafMin[2]; ijk[2] <= leafMax[2]; ijk[2] += LeafNodeType::DIM) {
813 if (
const LeafNodeType* leaf = acc.probeConstLeaf(ijk)) {
815 ijkMax.offset(LeafNodeType::DIM - 1);
821 if (ijkA != ijk || ijkB != ijkMax) {
822 filteredPointIndexSearchVoxels(filter, *leaf, ijkA, ijkB);
824 filter.filterLeafNode(*leaf);
836 template<
typename RangeDeque,
typename LeafNodeType>
838 pointIndexSearchVoxels(RangeDeque& rangeList,
839 const LeafNodeType& leaf,
const Coord& min,
const Coord& max)
842 using IntT =
typename PointIndexT::IntType;
845 Index xPos(0), pos(0), zStride =
Index(max[2] - min[2]);
846 const PointIndexT* dataPtr = &leaf.indices().front();
847 PointIndexT beginOffset(0), endOffset(0),
848 previousOffset(static_cast<IntT>(leaf.indices().size() + 1u));
851 for (ijk[0] = min[0]; ijk[0] <= max[0]; ++ijk[0]) {
852 xPos = (ijk[0] & (LeafNodeType::DIM - 1u)) << (2 * LeafNodeType::LOG2DIM);
854 for (ijk[1] = min[1]; ijk[1] <= max[1]; ++ijk[1]) {
855 pos = xPos + ((ijk[1] & (LeafNodeType::DIM - 1u)) << LeafNodeType::LOG2DIM);
856 pos += (min[2] & (LeafNodeType::DIM - 1u));
858 beginOffset = (pos == 0 ? PointIndexT(0) : leaf.
getValue(pos - 1));
859 endOffset = leaf.getValue(pos+zStride);
861 if (endOffset > beginOffset) {
863 if (beginOffset == previousOffset) {
864 rangeList.back().second = dataPtr + endOffset;
866 rangeList.push_back(Range(dataPtr + beginOffset, dataPtr + endOffset));
869 previousOffset = endOffset;
876 template<
typename RangeDeque,
typename ConstAccessor>
878 pointIndexSearch(RangeDeque& rangeList, ConstAccessor& acc,
const CoordBBox& bbox)
880 using LeafNodeType =
typename ConstAccessor::TreeType::LeafNodeType;
884 Coord ijk(0), ijkMax(0), ijkA(0), ijkB(0);
885 const Coord leafMin = bbox.min() & ~(LeafNodeType::DIM - 1);
886 const Coord leafMax = bbox.max() & ~(LeafNodeType::DIM - 1);
888 for (ijk[0] = leafMin[0]; ijk[0] <= leafMax[0]; ijk[0] += LeafNodeType::DIM) {
889 for (ijk[1] = leafMin[1]; ijk[1] <= leafMax[1]; ijk[1] += LeafNodeType::DIM) {
890 for (ijk[2] = leafMin[2]; ijk[2] <= leafMax[2]; ijk[2] += LeafNodeType::DIM) {
892 if (
const LeafNodeType* leaf = acc.probeConstLeaf(ijk)) {
894 ijkMax.offset(LeafNodeType::DIM - 1);
900 if (ijkA != ijk || ijkB != ijkMax) {
901 pointIndexSearchVoxels(rangeList, *leaf, ijkA, ijkB);
904 const PointIndexT* begin = &leaf->indices().front();
905 rangeList.push_back(Range(begin, (begin + leaf->indices().size())));
920 template<
typename TreeType>
925 , mIter(mRangeList.begin())
932 template<
typename TreeType>
936 , mRangeList(rhs.mRangeList)
937 , mIter(mRangeList.begin())
939 , mIndexArraySize(rhs.mIndexArraySize)
941 if (rhs.mIndexArray) {
942 mIndexArray.reset(
new ValueType[mIndexArraySize]);
943 memcpy(mIndexArray.get(), rhs.mIndexArray.get(), mIndexArraySize *
sizeof(
ValueType));
948 template<
typename TreeType>
954 mRangeList = rhs.mRangeList;
955 mIter = mRangeList.begin();
957 mIndexArraySize = rhs.mIndexArraySize;
959 if (rhs.mIndexArray) {
960 mIndexArray.reset(
new ValueType[mIndexArraySize]);
961 memcpy(mIndexArray.get(), rhs.mIndexArray.get(), mIndexArraySize *
sizeof(
ValueType));
968 template<
typename TreeType>
973 , mIter(mRangeList.begin())
978 if (leaf && leaf->getIndices(ijk, mRange.first, mRange.second)) {
979 mRangeList.push_back(mRange);
980 mIter = mRangeList.begin();
985 template<
typename TreeType>
990 , mIter(mRangeList.begin())
994 point_index_grid_internal::pointIndexSearch(mRangeList, acc, bbox);
996 if (!mRangeList.empty()) {
997 mIter = mRangeList.begin();
998 mRange = mRangeList.front();
1003 template<
typename TreeType>
1007 mIter = mRangeList.begin();
1008 if (!mRangeList.empty()) {
1009 mRange = mRangeList.front();
1010 }
else if (mIndexArray) {
1011 mRange.first = mIndexArray.get();
1012 mRange.second = mRange.first + mIndexArraySize;
1014 mRange.first =
static_cast<ValueType*
>(
nullptr);
1015 mRange.second =
static_cast<ValueType*
>(
nullptr);
1020 template<
typename TreeType>
1025 if (mRange.first >= mRange.second && mIter != mRangeList.end()) {
1027 if (mIter != mRangeList.end()) {
1029 }
else if (mIndexArray) {
1030 mRange.first = mIndexArray.get();
1031 mRange.second = mRange.first + mIndexArraySize;
1037 template<
typename TreeType>
1041 if (!this->
test())
return false;
1043 return this->
test();
1047 template<
typename TreeType>
1052 typename RangeDeque::const_iterator it = mRangeList.begin();
1054 for ( ; it != mRangeList.end(); ++it) {
1055 count += it->second - it->first;
1058 return count + mIndexArraySize;
1062 template<
typename TreeType>
1066 mRange.first =
static_cast<ValueType*
>(
nullptr);
1067 mRange.second =
static_cast<ValueType*
>(
nullptr);
1069 mIter = mRangeList.end();
1070 mIndexArray.reset();
1071 mIndexArraySize = 0;
1075 template<
typename TreeType>
1081 if (leaf && leaf->getIndices(ijk, mRange.first, mRange.second)) {
1082 mRangeList.push_back(mRange);
1083 mIter = mRangeList.begin();
1088 template<
typename TreeType>
1093 point_index_grid_internal::pointIndexSearch(mRangeList, acc, bbox);
1095 if (!mRangeList.empty()) {
1096 mIter = mRangeList.begin();
1097 mRange = mRangeList.front();
1102 template<
typename TreeType>
1103 template<
typename Po
intArray>
1110 std::vector<CoordBBox> searchRegions;
1113 const Coord dim = region.dim();
1116 if (minExtent > 2) {
1121 point_index_grid_internal::pointIndexSearch(mRangeList, acc, ibox);
1125 point_index_grid_internal::constructExclusiveRegions(searchRegions, region, ibox);
1127 searchRegions.push_back(region);
1131 std::deque<ValueType> filteredIndices;
1132 point_index_grid_internal::BBoxFilter<PointArray, ValueType>
1133 filter(mRangeList, filteredIndices, bbox, points, xform);
1135 for (
size_t n = 0,
N = searchRegions.size();
n <
N; ++
n) {
1136 point_index_grid_internal::filteredPointIndexSearch(filter, acc, searchRegions[
n]);
1139 point_index_grid_internal::dequeToArray(filteredIndices, mIndexArray, mIndexArraySize);
1145 template<
typename TreeType>
1146 template<
typename Po
intArray>
1150 bool subvoxelAccuracy)
1153 std::vector<CoordBBox> searchRegions;
1157 Coord::round(Vec3d(center[0] - radius, center[1] - radius, center[2] - radius)),
1158 Coord::round(Vec3d(center[0] + radius, center[1] + radius, center[2] + radius)));
1161 const double iRadius = radius * double(1.0 /
std::sqrt(3.0));
1162 if (iRadius > 2.0) {
1165 Coord::round(Vec3d(center[0] - iRadius, center[1] - iRadius, center[2] - iRadius)),
1166 Coord::round(Vec3d(center[0] + iRadius, center[1] + iRadius, center[2] + iRadius)));
1170 point_index_grid_internal::pointIndexSearch(mRangeList, acc, ibox);
1173 point_index_grid_internal::constructExclusiveRegions(searchRegions, bbox, ibox);
1175 searchRegions.push_back(bbox);
1179 std::deque<ValueType> filteredIndices;
1180 const double leafNodeDim = double(TreeType::LeafNodeType::DIM);
1182 using FilterT = point_index_grid_internal::RadialRangeFilter<PointArray, ValueType>;
1184 FilterT
filter(mRangeList, filteredIndices,
1185 center, radius, points, xform, leafNodeDim, subvoxelAccuracy);
1187 for (
size_t n = 0,
N = searchRegions.size();
n <
N; ++
n) {
1188 point_index_grid_internal::filteredPointIndexSearch(filter, acc, searchRegions[
n]);
1191 point_index_grid_internal::dequeToArray(filteredIndices, mIndexArray, mIndexArraySize);
1197 template<
typename TreeType>
1198 template<
typename Po
intArray>
1203 this->searchAndUpdate(
1208 template<
typename TreeType>
1209 template<
typename Po
intArray>
1213 bool subvoxelAccuracy)
1216 (radius / xform.
voxelSize()[0]), acc, points, xform, subvoxelAccuracy);
1224 template<
typename Po
intArray,
typename TreeType>
1228 : mPoints(&points), mAcc(tree), mXform(xform), mInvVoxelSize(1.0/xform.voxelSize()[0])
1233 template<
typename Po
intArray,
typename TreeType>
1236 : mPoints(rhs.mPoints)
1237 , mAcc(rhs.mAcc.tree())
1238 , mXform(rhs.mXform)
1239 , mInvVoxelSize(rhs.mInvVoxelSize)
1244 template<
typename Po
intArray,
typename TreeType>
1245 template<
typename FilterType>
1250 if (radius * mInvVoxelSize <
ScalarType(8.0)) {
1252 mXform.worldToIndexCellCentered(center - radius),
1253 mXform.worldToIndexCellCentered(center + radius)), mAcc);
1255 mIter.worldSpaceSearchAndUpdate(
1256 center, radius, mAcc, *mPoints, mXform,
false);
1259 const ScalarType radiusSqr = radius * radius;
1262 for (; mIter; ++mIter) {
1263 mPoints->getPos(*mIter, pos);
1265 distSqr = pos.lengthSqr();
1267 if (distSqr < radiusSqr) {
1268 op(distSqr, *mIter);
1277 template<
typename Gr
idT,
typename Po
intArrayT>
1278 inline typename GridT::Ptr
1282 grid->setTransform(xform.
copy());
1284 if (points.size() > 0) {
1285 point_index_grid_internal::constructPointTree(
1286 grid->tree(), grid->transform(),
points);
1293 template<
typename Gr
idT,
typename Po
intArrayT>
1294 inline typename GridT::Ptr
1298 return createPointIndexGrid<GridT>(
points, *xform);
1302 template<
typename Po
intArrayT,
typename Gr
idT>
1308 size_t pointCount = 0;
1309 for (
size_t n = 0,
N = leafs.leafCount();
n <
N; ++
n) {
1310 pointCount += leafs.
leaf(
n).indices().size();
1317 std::atomic<bool> changed;
1320 point_index_grid_internal::ValidPartitioningOp<PointArrayT>
1321 op(changed, points, grid.transform());
1325 return !bool(changed);
1329 template<
typename Gr
idT,
typename Po
intArrayT>
1330 inline typename GridT::ConstPtr
1337 return createPointIndexGrid<GridT>(
points, grid->transform());
1341 template<
typename Gr
idT,
typename Po
intArrayT>
1342 inline typename GridT::Ptr
1349 return createPointIndexGrid<GridT>(
points, grid->transform());
1356 template<
typename T, Index Log2Dim>
1408 const T&
value = zeroVal<T>(),
bool active =
false)
1419 template<
typename OtherType, Index OtherLog2Dim>
1430 BaseLeaf::template merge<Policy>(rhs);
1432 template<MergePolicy Policy>
void merge(
const ValueType& tileValue,
bool tileActive) {
1433 BaseLeaf::template merge<Policy>(tileValue, tileActive);
1436 template<MergePolicy Policy>
1440 BaseLeaf::template merge<Policy>(other);
1444 template<
typename AccessorT>
1450 template<
typename AccessorT>
1453 template<
typename NodeT,
typename AccessorT>
1458 return reinterpret_cast<NodeT*
>(
this);
1462 template<
typename AccessorT>
1469 template<
typename AccessorT>
1471 template<
typename AccessorT>
1474 template<
typename NodeT,
typename AccessorT>
1479 return reinterpret_cast<const NodeT*
>(
this);
1487 void readBuffers(std::istream& is,
bool fromHalf =
false);
1489 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
1502 assert(
false &&
"Cannot modify voxel values in a PointIndexTree.");
1528 template<
typename ModifyOp>
1531 template<
typename ModifyOp>
1534 template<
typename ModifyOp>
1543 template<
typename AccessorT>
1546 template<
typename ModifyOp,
typename AccessorT>
1551 template<
typename AccessorT>
1554 template<
typename AccessorT>
1610 #define VMASK_ this->getValueMask()
1654 template<
typename T, Index Log2Dim>
1659 return getIndices(LeafNodeType::coordToOffset(ijk), begin, end);
1663 template<
typename T, Index Log2Dim>
1668 if (this->isValueMaskOn(offset)) {
1669 const ValueType* dataPtr = &mIndices.front();
1670 begin = dataPtr + (offset == 0 ?
ValueType(0) : this->
buffer()[offset - 1]);
1678 template<
typename T, Index Log2Dim>
1682 this->
buffer().setValue(offset, val);
1683 this->setValueMaskOn(offset);
1687 template<
typename T, Index Log2Dim>
1691 this->
buffer().setValue(offset, val);
1695 template<
typename T, Index Log2Dim>
1699 Index xPos, pos, zStride =
Index(bbox.max()[2] - bbox.min()[2]);
1702 for (ijk[0] = bbox.min()[0]; ijk[0] <= bbox.max()[0]; ++ijk[0]) {
1703 xPos = (ijk[0] & (DIM - 1u)) << (2 * LOG2DIM);
1705 for (ijk[1] = bbox.min()[1]; ijk[1] <= bbox.max()[1]; ++ijk[1]) {
1706 pos = xPos + ((ijk[1] & (DIM - 1u)) << LOG2DIM);
1707 pos += (bbox.min()[2] & (DIM - 1u));
1709 if (this->
buffer()[pos+zStride] > (pos == 0 ?
T(0) : this->
buffer()[pos - 1])) {
1719 template<
typename T, Index Log2Dim>
1723 BaseLeaf::readBuffers(is, fromHalf);
1726 is.read(reinterpret_cast<char*>(&numIndices),
sizeof(
Index64));
1728 mIndices.resize(
size_t(numIndices));
1729 is.read(reinterpret_cast<char*>(mIndices.data()), numIndices *
sizeof(
T));
1733 template<
typename T, Index Log2Dim>
1738 BaseLeaf::readBuffers(is, bbox, fromHalf);
1741 is.read(reinterpret_cast<char*>(&numIndices),
sizeof(
Index64));
1743 const Index64 numBytes = numIndices *
sizeof(
T);
1745 if (bbox.hasOverlap(
this->getNodeBoundingBox())) {
1746 mIndices.resize(
size_t(numIndices));
1747 is.read(reinterpret_cast<char*>(mIndices.data()), numBytes);
1753 std::unique_ptr<char[]>
buf{
new char[numBytes]};
1754 is.read(
buf.get(), numBytes);
1759 is.read(reinterpret_cast<char*>(&auxDataBytes),
sizeof(
Index64));
1760 if (auxDataBytes > 0) {
1762 std::unique_ptr<char[]> auxData{
new char[auxDataBytes]};
1763 is.read(auxData.get(), auxDataBytes);
1768 template<
typename T, Index Log2Dim>
1772 BaseLeaf::writeBuffers(os, toHalf);
1775 os.write(reinterpret_cast<const char*>(&numIndices),
sizeof(
Index64));
1776 os.write(reinterpret_cast<const char*>(mIndices.data()), numIndices *
sizeof(
T));
1780 os.write(reinterpret_cast<const char*>(&auxDataBytes),
sizeof(
Index64));
1784 template<
typename T, Index Log2Dim>
1788 return BaseLeaf::memUsage() +
Index64((
sizeof(
T)*mIndices.capacity()) +
sizeof(mIndices));
1791 template<
typename T, Index Log2Dim>
1808 template<Index Dim1,
typename T2>
1818 #endif // OPENVDB_TOOLS_POINT_INDEX_GRID_HAS_BEEN_INCLUDED
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
void parallel_for(int64_t start, int64_t end, std::function< void(int64_t index)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
GA_API const UT_StringHolder dist
__hostdev__ uint64_t pointCount() const
GLenum GLuint GLenum GLsizei const GLchar * buf
Leaf nodes have no children, so their child iterators have no get/set accessors.
cvex test(vector P=0;int unbound=3;export float s=0;export vector Cf=0;)
static const Index NUM_VOXELS
GLsizei GLenum const void * indices
GLdouble GLdouble GLint GLint const GLdouble * points
GLsizei const GLfloat * value
static const Index NUM_VALUES
vfloat4 sqrt(const vfloat4 &a)
GLboolean GLboolean GLboolean GLboolean a
#define OPENVDB_USE_VERSION_NAMESPACE
Base class for iterators over internal and leaf nodes.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
**But if you need a or simply need to know when the task has note that the like this
The Value Accessor Implementation and API methods. The majoirty of the API matches the API of a compa...
Selectively extract and filter point data using a custom filter operator.
bool isEmpty() const
Return true if this node has no active voxels.
Tag dispatch class that distinguishes constructors during file input.
__hostdev__ float getValue(uint32_t i) const
Spatially partitions points using a parallel radix-based sorting algorithm.
GLuint GLsizei const GLuint const GLintptr * offsets
std::shared_ptr< T > SharedPtr
SYS_FORCE_INLINE const_iterator end() const
std::vector< Index > IndexArray
OffMaskIterator< NodeMask > OffIterator
const Vec3T & min() const
Return a const reference to the minimum point of this bounding box.
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
auto get(const UT_ARTIterator< T > &it) -> decltype(it.key())
static const Index LOG2DIM
const LeafNodeT * probeConstLeaf(const Coord &xyz) const
Return a pointer to the leaf node that contains the voxel coordinate xyz. If no LeafNode exists...
vfloat4 round(const vfloat4 &a)
Container class that associates a tree with a transform and metadata.
const Vec3T & max() const
Return a const reference to the maximum point of this bounding box.
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
buffer(size_t sz) FMT_NOEXCEPT
DenseMaskIterator< NodeMask > DenseIterator
Library and file format version numbers.
OnMaskIterator< NodeMask > OnIterator
math::BBox< Vec3d > BBoxd
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
GA_API const UT_StringHolder N
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
LeafType & leaf(size_t leafIdx) const
Return a pointer to the leaf node at index leafIdx in the array.
bool hasSameTopology(const LeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
#define OPENVDB_THROW(exception, message)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.