43 #ifndef OPENVDB_TOOLS_POINT_INDEX_GRID_HAS_BEEN_INCLUDED
44 #define OPENVDB_TOOLS_POINT_INDEX_GRID_HAS_BEEN_INCLUDED
47 #include <openvdb/Grid.h>
48 #include <openvdb/Types.h>
49 #include <openvdb/math/Transform.h>
50 #include <openvdb/tree/Tree.h>
51 #include <openvdb/tree/LeafNode.h>
52 #include <openvdb/tree/LeafManager.h>
55 #include <boost/scoped_array.hpp>
56 #include <tbb/blocked_range.h>
57 #include <tbb/parallel_for.h>
58 #include <tbb/atomic.h>
112 template<
typename Gr
idT,
typename Po
intArrayT>
113 inline typename GridT::Ptr
122 template<
typename Po
intArrayT,
typename Gr
idT>
128 template<
typename Gr
idT,
typename Po
intArrayT>
129 inline typename GridT::ConstPtr
133 template<
typename Gr
idT,
typename Po
intArrayT>
134 inline typename GridT::Ptr
142 template<
typename TreeType = Po
intIndexTree>
173 void searchAndUpdate(
const Coord& ijk, ConstAccessor& acc);
181 void searchAndUpdate(
const CoordBBox& bbox, ConstAccessor& acc);
190 template<
typename Po
intArray>
191 void searchAndUpdate(
const BBoxd& bbox, ConstAccessor& acc,
205 template<
typename Po
intArray>
206 void searchAndUpdate(
const Vec3d& center,
double radius, ConstAccessor& acc,
216 template<
typename Po
intArray>
217 void worldSpaceSearchAndUpdate(
const BBoxd& bbox, ConstAccessor& acc,
231 template<
typename Po
intArray>
232 void worldSpaceSearchAndUpdate(
const Vec3d& center,
double radius, ConstAccessor& acc,
240 const ValueType&
operator*()
const {
return *mRange.first; }
244 bool test()
const {
return mRange.first < mRange.second || mIter != mRangeList.end(); }
245 operator bool()
const {
return this->test(); }
268 typedef std::pair<const ValueType*, const ValueType*> Range;
269 typedef std::deque<Range> RangeDeque;
270 typedef typename RangeDeque::const_iterator RangeDequeCIter;
271 typedef boost::scoped_array<ValueType> IndexArray;
277 RangeDeque mRangeList;
278 RangeDequeCIter mIter;
280 IndexArray mIndexArray;
281 size_t mIndexArraySize;
314 template<
typename Po
intArray,
typename TreeType = Po
intIndexTree>
335 template<
typename FilterType>
336 void searchAndApply(
const PointType& center, PointElementType radius,
FilterType& op);
342 const PointElementType mInvVoxelSize;
352 namespace point_index_grid_internal {
354 template<
typename Po
intArrayT>
361 , mHasChanged(&hasChanged)
365 template <
typename LeafT>
368 if ((*mHasChanged)) {
369 tbb::task::self().cancel_group_execution();
373 typedef typename LeafT::IndexArray IndexArrayT;
374 typedef typename IndexArrayT::value_type IndexT;
375 typedef typename PointArrayT::value_type PointT;
377 typename LeafT::ValueOnCIter iter;
381 const IndexT *begin =
static_cast<IndexT*
>(NULL), *end = static_cast<IndexT*>(NULL);
383 for (iter = leaf.cbeginValueOn(); iter; ++iter) {
385 if ((*mHasChanged))
break;
387 voxelCoord = iter.getCoord();
388 leaf.getIndices(iter.pos(), begin, end);
390 while (begin < end) {
392 mPoints->getPos(*begin, point);
393 if (voxelCoord != mTransform->worldToIndexCellCentered(point)) {
394 mHasChanged->fetch_and_store(
true);
404 PointArrayT
const *
const mPoints;
406 tbb::atomic<bool> *
const mHasChanged;
410 template<
typename LeafNodeT>
417 const Partitioner& partitioner)
418 : mLeafNodes(leafNodes.get())
419 , mPartitioner(&partitioner)
423 void operator()(
const tbb::blocked_range<size_t>& range)
const {
427 size_t maxPointCount = 0;
428 for (
size_t n = range.begin(), N = range.end(); n != N; ++n) {
429 maxPointCount =
std::max(maxPointCount, mPartitioner->indices(n).size());
432 const IndexT voxelCount = LeafNodeT::SIZE;
435 boost::scoped_array<VoxelOffsetT> offsets(
new VoxelOffsetT[maxPointCount]);
436 boost::scoped_array<IndexT>
histogram(
new IndexT[voxelCount]);
438 VoxelOffsetT
const *
const voxelOffsets = mPartitioner->voxelOffsets().get();
440 for (
size_t n = range.begin(), N = range.end(); n != N; ++n) {
442 LeafNodeT* node =
new LeafNodeT();
443 node->setOrigin(mPartitioner->origin(n));
447 const size_t pointCount = it.
size();
448 IndexT
const *
const indices = &*it;
451 for (IndexT i = 0; i < pointCount; ++i) {
452 offsets[i] = voxelOffsets[ indices[i] ];
456 memset(&histogram[0], 0, voxelCount *
sizeof(IndexT));
457 for (IndexT i = 0; i < pointCount; ++i) {
458 ++histogram[ offsets[i] ];
461 typename LeafNodeT::NodeMaskType& mask = node->getValueMask();
462 typename LeafNodeT::Buffer& buffer = node->buffer();
465 IndexT count = 0, startOffset;
466 for (
int i = 0; i < int(voxelCount); ++i) {
467 if (histogram[i] > 0) {
469 count += histogram[i];
470 histogram[i] = startOffset;
473 buffer.setValue(i, count);
477 node->indices().resize(pointCount);
478 typename LeafNodeT::ValueType *
const orderedIndices = node->indices().data();
481 for (IndexT i = 0; i < pointCount; ++i) {
482 orderedIndices[ histogram[ offsets[i] ]++ ] = indices[i];
485 mLeafNodes[n] = node;
497 template<
typename TreeType,
typename Po
intArray>
501 typedef typename TreeType::LeafNodeType LeafType;
503 boost::scoped_array<LeafType*> leafNodes;
504 size_t leafNodeCount = 0;
508 partitioner.
construct(points, xform,
false,
true);
510 leafNodeCount = partitioner.
size();
511 leafNodes.reset(
new LeafType*[leafNodeCount]);
513 const tbb::blocked_range<size_t> range(0, leafNodeCount);
518 for (
size_t n = 0; n < leafNodeCount; ++n) {
529 dequeToArray(
const std::deque<T>& d, boost::scoped_array<T>& a,
size_t& size)
532 a.reset(
new T[size]);
533 typename std::deque<T>::const_iterator it = d.begin(), itEnd = d.end();
535 for ( ; it != itEnd; ++it, ++item) *item = *it;
541 const CoordBBox& bbox,
const CoordBBox& ibox)
545 Coord cmin = ibox.min();
546 Coord cmax = ibox.max();
549 regions.push_back(bbox);
550 regions.back().max().z() = cmin.z();
553 regions.push_back(bbox);
554 regions.back().min().z() = cmax.z();
560 regions.push_back(bbox);
561 CoordBBox* lastRegion = ®ions.back();
562 lastRegion->min().z() = cmin.z();
563 lastRegion->max().z() = cmax.z();
564 lastRegion->max().x() = cmin.x();
567 regions.push_back(*lastRegion);
568 lastRegion = ®ions.back();
569 lastRegion->min().x() = cmax.x();
570 lastRegion->max().x() = bbox.max().x();
576 regions.push_back(*lastRegion);
577 lastRegion = ®ions.back();
578 lastRegion->min().x() = cmin.x();
579 lastRegion->max().x() = cmax.x();
580 lastRegion->max().y() = cmin.y();
583 regions.push_back(*lastRegion);
584 lastRegion = ®ions.back();
585 lastRegion->min().y() = cmax.y();
586 lastRegion->max().y() = bbox.max().y();
590 template<
typename Po
intArray,
typename IndexT>
595 typedef std::pair<const IndexT*, const IndexT*>
Range;
605 , mMap(*xform.baseMap())
609 template <
typename LeafNodeType>
612 typename LeafNodeType::ValueOnCIter iter;
613 const IndexT *begin =
static_cast<IndexT*
>(NULL), *end = static_cast<IndexT*>(NULL);
614 for (iter = leaf.cbeginValueOn(); iter; ++iter) {
615 leaf.getIndices(iter.pos(), begin, end);
616 filterVoxel(iter.getCoord(), begin, end);
620 void filterVoxel(
const Coord&,
const IndexT* begin,
const IndexT* end)
625 for (; begin < end; ++begin) {
626 mPoints.getPos(*begin, vec);
629 xyz = mMap.applyInverseMap(vec);
634 if (mRegion.isInside(xyz)) {
635 mIndices.push_back(*begin);
642 IndexDeque& mIndices;
649 template<
typename Po
intArray,
typename IndexT>
654 typedef std::pair<const IndexT*, const IndexT*>
Range;
660 const double leafNodeDim,
const bool subvoxelAccuracy)
664 , mWSCenter(xform.indexToWorld(xyz))
667 , mLeafNodeDist1(0.0)
668 , mLeafNodeDist2(0.0)
669 , mWSRadiusSqr(radius * xform.voxelSize()[0])
671 , mSubvoxelAccuracy(subvoxelAccuracy)
673 const PointElementType voxelRadius = std::sqrt(3.0) * 0.5;
674 mVoxelDist1 = voxelRadius + radius;
675 mVoxelDist1 *= mVoxelDist1;
677 if (radius > voxelRadius) {
678 mVoxelDist2 = radius - voxelRadius;
679 mVoxelDist2 *= mVoxelDist2;
682 const PointElementType leafNodeRadius = leafNodeDim * std::sqrt(3.0) * 0.5;
683 mLeafNodeDist1 = leafNodeRadius + radius;
684 mLeafNodeDist1 *= mLeafNodeDist1;
686 if (radius > leafNodeRadius) {
687 mLeafNodeDist2 = radius - leafNodeRadius;
688 mLeafNodeDist2 *= mLeafNodeDist2;
691 mWSRadiusSqr *= mWSRadiusSqr;
694 template <
typename LeafNodeType>
698 const Coord& ijk = leaf.origin();
700 vec[0] = PointElementType(ijk[0]);
701 vec[1] = PointElementType(ijk[1]);
702 vec[2] = PointElementType(ijk[2]);
703 vec += PointElementType(LeafNodeType::DIM - 1) * 0.5;
706 const PointElementType dist = vec.lengthSqr();
707 if (dist > mLeafNodeDist1)
return;
709 if (mLeafNodeDist2 > 0.0 && dist < mLeafNodeDist2) {
710 const IndexT* begin = &leaf.indices().front();
711 mRanges.push_back(Range(begin, begin + leaf.indices().size()));
716 typename LeafNodeType::ValueOnCIter iter;
717 const IndexT *begin =
static_cast<IndexT*
>(NULL), *end = static_cast<IndexT*>(NULL);
718 for (iter = leaf.cbeginValueOn(); iter; ++iter) {
719 leaf.getIndices(iter.pos(), begin, end);
720 filterVoxel(iter.getCoord(), begin, end);
724 void filterVoxel(
const Coord& ijk,
const IndexT* begin,
const IndexT* end)
729 vec[0] = mCenter[0] - PointElementType(ijk[0]);
730 vec[1] = mCenter[1] - PointElementType(ijk[1]);
731 vec[2] = mCenter[2] - PointElementType(ijk[2]);
733 const PointElementType dist = vec.lengthSqr();
734 if (dist > mVoxelDist1)
return;
736 if (!mSubvoxelAccuracy || (mVoxelDist2 > 0.0 && dist < mVoxelDist2)) {
737 if (!mRanges.empty() && mRanges.back().second == begin) {
738 mRanges.back().second = end;
740 mRanges.push_back(Range(begin, end));
747 while (begin < end) {
748 mPoints.getPos(*begin, vec);
749 vec = mWSCenter - vec;
751 if (vec.lengthSqr() < mWSRadiusSqr) {
752 mIndices.push_back(*begin);
760 IndexDeque& mIndices;
761 const PointType mCenter, mWSCenter;
762 PointElementType mVoxelDist1, mVoxelDist2, mLeafNodeDist1, mLeafNodeDist2, mWSRadiusSqr;
764 const bool mSubvoxelAccuracy;
771 template<
typename RangeFilterType,
typename LeafNodeType>
774 const LeafNodeType& leaf,
const Coord&
min,
const Coord&
max)
776 typedef typename LeafNodeType::ValueType PointIndexT;
777 Index xPos(0), yPos(0), pos(0);
780 const PointIndexT* dataPtr = &leaf.indices().front();
781 PointIndexT beginOffset, endOffset;
783 for (ijk[0] = min[0]; ijk[0] <= max[0]; ++ijk[0]) {
784 xPos = (ijk[0] & (LeafNodeType::DIM - 1u)) << (2 * LeafNodeType::LOG2DIM);
785 for (ijk[1] = min[1]; ijk[1] <= max[1]; ++ijk[1]) {
786 yPos = xPos + ((ijk[1] & (LeafNodeType::DIM - 1u)) << LeafNodeType::LOG2DIM);
787 for (ijk[2] = min[2]; ijk[2] <= max[2]; ++ijk[2]) {
788 pos = yPos + (ijk[2] & (LeafNodeType::DIM - 1u));
790 beginOffset = (pos == 0 ? PointIndexT(0) : leaf.getValue(pos - 1));
791 endOffset = leaf.getValue(pos);
793 if (endOffset > beginOffset) {
794 filter.filterVoxel(ijk, dataPtr + beginOffset, dataPtr + endOffset);
802 template<
typename RangeFilterType,
typename ConstAccessor>
806 typedef typename ConstAccessor::TreeType::LeafNodeType LeafNodeType;
807 Coord ijk(0), ijkMax(0), ijkA(0), ijkB(0);
808 const Coord leafMin = bbox.min() & ~(LeafNodeType::DIM - 1);
809 const Coord leafMax = bbox.max() & ~(LeafNodeType::DIM - 1);
811 for (ijk[0] = leafMin[0]; ijk[0] <= leafMax[0]; ijk[0] += LeafNodeType::DIM) {
812 for (ijk[1] = leafMin[1]; ijk[1] <= leafMax[1]; ijk[1] += LeafNodeType::DIM) {
813 for (ijk[2] = leafMin[2]; ijk[2] <= leafMax[2]; ijk[2] += LeafNodeType::DIM) {
815 if (
const LeafNodeType* leaf = acc.probeConstLeaf(ijk)) {
817 ijkMax.offset(LeafNodeType::DIM - 1);
823 if (ijkA != ijk || ijkB != ijkMax) {
826 filter.filterLeafNode(*leaf);
838 template<
typename RangeDeque,
typename LeafNodeType>
841 const LeafNodeType& leaf,
const Coord&
min,
const Coord&
max)
843 typedef typename LeafNodeType::ValueType PointIndexT;
844 typedef typename RangeDeque::value_type Range;
846 Index xPos(0), pos(0), zStride =
Index(max[2] - min[2]);
847 const PointIndexT* dataPtr = &leaf.indices().front();
848 PointIndexT beginOffset(0), endOffset(0),
849 previousOffset = PointIndexT(leaf.indices().size() + size_t(1));
852 for (ijk[0] = min[0]; ijk[0] <= max[0]; ++ijk[0]) {
853 xPos = (ijk[0] & (LeafNodeType::DIM - 1u)) << (2 * LeafNodeType::LOG2DIM);
855 for (ijk[1] = min[1]; ijk[1] <= max[1]; ++ijk[1]) {
856 pos = xPos + ((ijk[1] & (LeafNodeType::DIM - 1u)) << LeafNodeType::LOG2DIM);
857 pos += (min[2] & (LeafNodeType::DIM - 1u));
859 beginOffset = (pos == 0 ? PointIndexT(0) : leaf.getValue(pos - 1));
860 endOffset = leaf.getValue(pos+zStride);
862 if (endOffset > beginOffset) {
864 if (beginOffset == previousOffset) {
865 rangeList.back().second = dataPtr + endOffset;
867 rangeList.push_back(Range(dataPtr + beginOffset, dataPtr + endOffset));
870 previousOffset = endOffset;
877 template<
typename RangeDeque,
typename ConstAccessor>
881 typedef typename ConstAccessor::TreeType::LeafNodeType LeafNodeType;
882 typedef typename LeafNodeType::ValueType PointIndexT;
883 typedef typename RangeDeque::value_type Range;
885 Coord ijk(0), ijkMax(0), ijkA(0), ijkB(0);
886 const Coord leafMin = bbox.min() & ~(LeafNodeType::DIM - 1);
887 const Coord leafMax = bbox.max() & ~(LeafNodeType::DIM - 1);
889 for (ijk[0] = leafMin[0]; ijk[0] <= leafMax[0]; ijk[0] += LeafNodeType::DIM) {
890 for (ijk[1] = leafMin[1]; ijk[1] <= leafMax[1]; ijk[1] += LeafNodeType::DIM) {
891 for (ijk[2] = leafMin[2]; ijk[2] <= leafMax[2]; ijk[2] += LeafNodeType::DIM) {
893 if (
const LeafNodeType* leaf = acc.probeConstLeaf(ijk)) {
895 ijkMax.offset(LeafNodeType::DIM - 1);
901 if (ijkA != ijk || ijkB != ijkMax) {
905 const PointIndexT* begin = &leaf->indices().front();
906 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())
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*
>(NULL);
1015 mRange.second =
static_cast<ValueType*
>(NULL);
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*
>(NULL);
1067 mRange.second =
static_cast<ValueType*
>(NULL);
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>
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;
1111 CoordBBox region(Coord::round(bbox.
min()), Coord::round(bbox.
max()));
1113 const Coord dim = region.dim();
1116 if (minExtent > 2) {
1118 CoordBBox ibox = region;
1127 searchRegions.push_back(region);
1131 std::deque<ValueType> filteredIndices;
1133 filter(mRangeList, filteredIndices, bbox, points, xform);
1135 for (
size_t n = 0, N = searchRegions.size(); n < N; ++n) {
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)));
1175 searchRegions.push_back(bbox);
1179 std::deque<ValueType> filteredIndices;
1180 const double leafNodeDim = double(TreeType::LeafNodeType::DIM);
1184 FilterT filter(mRangeList, filteredIndices,
1185 center, radius, points, xform, leafNodeDim, subvoxelAccuracy);
1187 for (
size_t n = 0, N = searchRegions.size(); n < N; ++n) {
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>
1251 mIter.searchAndUpdate(openvdb::CoordBBox(
1252 mXform.worldToIndexCellCentered(center - radius),
1253 mXform.worldToIndexCellCentered(center + radius)), mAcc);
1255 mIter.worldSpaceSearchAndUpdate(
1256 center, radius, mAcc, *mPoints, mXform,
false);
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
1281 typename GridT::Ptr grid = GridT::create(
typename GridT::ValueType(0));
1282 grid->setTransform(xform.
copy());
1284 if (points.size() > 0) {
1286 grid->tree(), grid->transform(), points);
1293 template<
typename Po
intArrayT,
typename Gr
idT>
1299 size_t pointCount = 0;
1300 for (
size_t n = 0, N = leafs.leafCount(); n < N; ++n) {
1301 pointCount += leafs.
leaf(n).indices().size();
1304 if (points.size() != pointCount) {
1308 tbb::atomic<bool> changed;
1312 op(changed, points, grid.transform());
1316 return !bool(changed);
1320 template<
typename Gr
idT,
typename Po
intArrayT>
1321 inline typename GridT::ConstPtr
1328 return createPointIndexGrid<GridT>(points, grid->transform());
1332 template<
typename Gr
idT,
typename Po
intArrayT>
1333 inline typename GridT::Ptr
1340 return createPointIndexGrid<GridT>(points, grid->transform());
1347 template<
typename T, Index Log2Dim>
1351 typedef boost::shared_ptr<PointIndexLeafNode>
Ptr;
1358 const IndexArray&
indices()
const {
return mIndices; }
1360 bool getIndices(
const Coord& ijk,
const ValueType*& begin,
const ValueType*& end)
const;
1361 bool getIndices(
Index offset,
const ValueType*& begin,
const ValueType*& end)
const;
1366 bool isEmpty(
const CoordBBox& bbox)
const;
1369 IndexArray mIndices;
1393 : BaseLeaf(coords, value, active)
1398 #ifndef OPENVDB_2_ABI_COMPATIBLE
1400 const T& value = zeroVal<T>(),
bool active =
false)
1412 template<
typename OtherType, Index OtherLog2Dim>
1423 BaseLeaf::merge<Policy>(rhs);
1425 template<MergePolicy Policy>
void merge(
const ValueType& tileValue,
bool tileActive) {
1426 BaseLeaf::template merge<Policy>(tileValue, tileActive);
1429 template<MergePolicy Policy>
1431 const ValueType& ,
const ValueType& )
1433 BaseLeaf::template merge<Policy>(other);
1437 template<
typename AccessorT>
1443 template<
typename AccessorT>
1446 template<
typename NodeT,
typename AccessorT>
1450 if (!(boost::is_same<NodeT,PointIndexLeafNode>::value))
return NULL;
1451 return reinterpret_cast<NodeT*
>(
this);
1455 template<
typename AccessorT>
1462 template<
typename AccessorT>
1464 template<
typename AccessorT>
1467 template<
typename NodeT,
typename AccessorT>
1471 if (!(boost::is_same<NodeT,PointIndexLeafNode>::value))
return NULL;
1472 return reinterpret_cast<const NodeT*
>(
this);
1480 void readBuffers(std::istream& is,
bool fromHalf =
false);
1481 void readBuffers(std::istream& is,
const CoordBBox&,
bool fromHalf =
false);
1482 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
1494 assert(
false &&
"Cannot modify voxel values in a PointIndexTree.");
1520 template<
typename ModifyOp>
1523 template<
typename ModifyOp>
1526 template<
typename ModifyOp>
1535 template<
typename AccessorT>
1538 template<
typename ModifyOp,
typename AccessorT>
1543 template<
typename AccessorT>
1546 template<
typename AccessorT>
1579 typedef typename BaseLeaf::template
ValueIter<
1581 typedef typename BaseLeaf::template
ValueIter<
1583 typedef typename BaseLeaf::template
ValueIter<
1585 typedef typename BaseLeaf::template
ValueIter<
1587 typedef typename BaseLeaf::template
ValueIter<
1589 typedef typename BaseLeaf::template
ValueIter<
1591 typedef typename BaseLeaf::template
ChildIter<
1593 typedef typename BaseLeaf::template
ChildIter<
1595 typedef typename BaseLeaf::template
ChildIter<
1597 typedef typename BaseLeaf::template
ChildIter<
1599 typedef typename BaseLeaf::template
DenseIter<
1601 typedef typename BaseLeaf::template
DenseIter<
1604 #define VMASK_ this->getValueMask()
1648 template<
typename T, Index Log2Dim>
1651 const ValueType*& begin,
const ValueType*& end)
const
1653 return getIndices(LeafNodeType::coordToOffset(ijk), begin, end);
1657 template<
typename T, Index Log2Dim>
1660 const ValueType*& begin,
const ValueType*& end)
const
1662 if (this->isValueMaskOn(offset)) {
1663 const ValueType* dataPtr = &mIndices.front();
1664 begin = dataPtr + (offset == 0 ? ValueType(0) : this->buffer()[offset - 1]);
1665 end = dataPtr + this->buffer()[offset];
1672 template<
typename T, Index Log2Dim>
1676 this->buffer().setValue(offset, val);
1677 this->setValueMaskOn(offset);
1681 template<
typename T, Index Log2Dim>
1685 this->buffer().setValue(offset, val);
1689 template<
typename T, Index Log2Dim>
1693 Index xPos, pos, zStride =
Index(bbox.max()[2] - bbox.min()[2]);
1696 for (ijk[0] = bbox.min()[0]; ijk[0] <= bbox.max()[0]; ++ijk[0]) {
1697 xPos = (ijk[0] & (DIM - 1u)) << (2 * LOG2DIM);
1699 for (ijk[1] = bbox.min()[1]; ijk[1] <= bbox.max()[1]; ++ijk[1]) {
1700 pos = xPos + ((ijk[1] & (DIM - 1u)) << LOG2DIM);
1701 pos += (bbox.min()[2] & (DIM - 1u));
1703 if (this->buffer()[pos+zStride] > (pos == 0 ? T(0) : this->buffer()[pos - 1])) {
1713 template<
typename T, Index Log2Dim>
1717 BaseLeaf::readBuffers(is, fromHalf);
1720 is.read(reinterpret_cast<char*>(&numIndices),
sizeof(
Index64));
1722 mIndices.resize(
size_t(numIndices));
1723 is.read(reinterpret_cast<char*>(mIndices.data()), numIndices *
sizeof(T));
1727 template<
typename T, Index Log2Dim>
1732 BaseLeaf::readBuffers(is, bbox, fromHalf);
1735 is.read(reinterpret_cast<char*>(&numIndices),
sizeof(
Index64));
1737 const Index64 numBytes = numIndices *
sizeof(T);
1739 if (bbox.hasOverlap(this->getNodeBoundingBox())) {
1740 mIndices.resize(
size_t(numIndices));
1741 is.read(reinterpret_cast<char*>(mIndices.data()), numBytes);
1747 boost::scoped_array<char> buf(
new char[numBytes]);
1748 is.read(buf.get(), numBytes);
1753 is.read(reinterpret_cast<char*>(&auxDataBytes),
sizeof(
Index64));
1754 if (auxDataBytes > 0) {
1756 boost::scoped_array<char> auxData(
new char[auxDataBytes]);
1757 is.read(auxData.get(), auxDataBytes);
1762 template<
typename T, Index Log2Dim>
1766 BaseLeaf::writeBuffers(os, toHalf);
1769 os.write(reinterpret_cast<const char*>(&numIndices),
sizeof(
Index64));
1770 os.write(reinterpret_cast<const char*>(mIndices.data()), numIndices *
sizeof(T));
1774 os.write(reinterpret_cast<const char*>(&auxDataBytes),
sizeof(
Index64));
1778 template<
typename T, Index Log2Dim>
1782 return BaseLeaf::memUsage() +
Index64((
sizeof(T)*mIndices.capacity()) +
sizeof(mIndices));
1795 template<Index Dim1,
typename T2>
1805 #endif // OPENVDB_TOOLS_POINT_INDEX_GRID_HAS_BEEN_INCLUDED
void addLeaf(LeafNodeT *leaf)
Add the specified leaf to this tree, possibly creating a child branch in the process. If the leaf node already exists, replace it.
Definition: ValueAccessor.h:328
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:497
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1648
Definition: LeafNode.h:476
static const Index LEVEL
Definition: LeafNode.h:80
uint64_t Index64
Definition: Types.h:58
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNode.h:414
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec2.h:506
Multi-threaded space-partitioning scheme for points.
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...
Definition: LeafNode.h:1686
Selectively extract and filter point data using a custom filter operator.
static const Index TOTAL
Definition: LeafNode.h:75
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:65
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: LeafNode.h:472
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:511
Definition: LeafNode.h:472
Index32 Index
Definition: Types.h:59
#define VMASK_
Definition: PointIndexGrid.h:1604
static const Index NUM_VALUES
Definition: LeafNode.h:77
const LeafNodeT * probeConstLeaf(const Coord &xyz) const
Return a pointer to the leaf node that contains voxel (x, y, z), or NULL if no such node exists...
Definition: ValueAccessor.h:383
Definition: NodeMasks.h:236
Definition: Exceptions.h:39
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
Vec3< double > Vec3d
Definition: Vec3.h:629
Definition: NodeMasks.h:267
static const bool value
Definition: LeafNode.h:1099
Definition: LeafNode.h:473
static const Index SIZE
Definition: LeafNode.h:79
Definition: InternalNode.h:63
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:450
Definition: LeafNode.h:472
Definition: NodeMasks.h:205
Abstract base class for maps.
Definition: Maps.h:159
Definition: PointIndexGrid.h:68
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
static const Index LOG2DIM
Definition: LeafNode.h:74
static const Index NUM_VOXELS
Definition: LeafNode.h:78
const Vec3T & min() const
Return a const reference to the minimum point of the BBox.
Definition: BBox.h:81
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:304
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
Definition: LeafNode.h:520
float Round(float x)
Return x rounded to the nearest integer.
Definition: Math.h:751
const Vec3T & max() const
Return a const reference to the maximum point of the BBox.
Definition: BBox.h:84
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Definition: RootNode.h:75
Definition: LeafNode.h:473
math::BBox< Vec3d > BBoxd
Definition: Types.h:87
LeafType & leaf(size_t leafIdx) const
Return a pointer to the leaf node at index leafIdx in the array.
Definition: LeafManager.h:318
static const Index DIM
Definition: LeafNode.h:76
Definition: LeafNode.h:473
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58