59 #ifndef OPENVDB_POINTS_POINT_MOVE_HAS_BEEN_INCLUDED 60 #define OPENVDB_POINTS_POINT_MOVE_HAS_BEEN_INCLUDED 67 #include <tbb/concurrent_vector.h> 74 #include <unordered_map> 86 namespace future {
struct Advect { }; }
95 template <
typename Po
intDataGr
idT,
typename DeformerT,
typename FilterT = NullFilter>
100 bool threaded =
true);
110 template <
typename Po
intDataGr
idT,
typename DeformerT,
typename FilterT = NullFilter>
111 inline void movePoints(PointDataGridT& points,
116 bool threaded =
true);
124 template <
typename T>
131 using LeafMapT = std::unordered_map<LeafIndex, Vec3T>;
161 template <
typename Po
intDataGr
idT,
typename DeformerT,
typename FilterT>
162 void evaluate(PointDataGridT& grid, DeformerT& deformer,
const FilterT& filter,
163 bool threaded =
true);
167 template <
typename LeafT>
168 void reset(
const LeafT& leaf,
size_t idx);
171 template <
typename IndexIterT>
172 void apply(
Vec3d& position,
const IndexIterT& iter)
const;
175 friend class ::TestPointMove;
186 namespace point_move_internal {
201 using LeafMap = std::unordered_map<Coord, LeafIndex>;
204 template <
typename DeformerT,
typename TreeT,
typename FilterT>
207 using LeafT =
typename TreeT::LeafNodeType;
217 const FilterT& filter)
218 : mDeformer(deformer)
219 , mGlobalMoveLeafMap(globalMoveLeafMap)
220 , mLocalMoveLeafMap(localMoveLeafMap)
221 , mTargetLeafMap(targetLeafMap)
222 , mTargetTransform(targetTransform)
223 , mSourceTransform(sourceTransform)
224 , mFilter(filter) { }
228 DeformerT deformer(mDeformer);
229 deformer.reset(leaf, idx);
233 Coord sourceLeafOrigin = leaf.origin();
237 for (
auto iter = leaf.beginIndexOn(mFilter); iter; iter++) {
243 Vec3d positionIS = sourceHandle->get(*iter) + iter.getCoord().asVec3d();
245 deformer.apply(positionIS, iter);
250 Vec3d positionWS = mSourceTransform.indexToWorld(positionIS);
251 if (!useIndexSpace) {
252 deformer.apply(positionWS, iter);
257 positionIS = mTargetTransform.worldToIndex(positionWS);
262 Index targetOffset = LeafT::coordToOffset(targetVoxel);
266 Vec3d voxelPosition(positionIS - targetVoxel.
asVec3d());
267 sourceHandle->set(*iter, voxelPosition);
271 Coord targetLeafOrigin = targetVoxel & ~(LeafT::DIM - 1);
272 assert(mTargetLeafMap.find(targetLeafOrigin) != mTargetLeafMap.end());
273 const LeafIndex targetLeafOffset(mTargetLeafMap.at(targetLeafOrigin));
277 if (targetLeafOrigin == sourceLeafOrigin) {
278 mLocalMoveLeafMap[targetLeafOffset].emplace_back(targetOffset, *iter);
281 mGlobalMoveLeafMap[targetLeafOffset].push_back(
IndexTriple(
282 LeafIndex(static_cast<LeafIndex>(idx)), targetOffset, *iter));
288 const DeformerT& mDeformer;
294 const FilterT& mFilter;
297 template <
typename LeafT>
305 Index targetOffset = offsets[voxelOffset]++;
306 if (voxelOffset > 0) {
307 targetOffset += static_cast<Index>(leaf.getValue(voxelOffset - 1));
313 #if OPENVDB_ABI_VERSION_NUMBER >= 6 316 template <
typename TreeT>
319 using LeafT =
typename TreeT::LeafNodeType;
326 const Index attributeIndex,
329 : mOffsetMap(offsetMap)
330 , mSourceLeafManager(sourceLeafManager)
331 , mAttributeIndex(attributeIndex)
332 , mMoveLeafMap(moveLeafMap)
333 , mMoveLeafIndices(moveLeafIndices) { }
342 , mSortedIndices(sortedIndices)
343 , mMoveIndices(moveIndices)
344 , mOffsets(offsets) { }
346 operator bool()
const {
return bool(mIt); }
351 mEndIndex = endIndex;
363 if (i < mSortedIndices.size()) {
364 return std::get<0>(this->leafIndexTriple(i));
372 return std::get<2>(*mIt);
384 if (mIndex >= mEndIndex || mIndex >= mSortedIndices.size()) {
388 mIt = &this->leafIndexTriple(mIndex);
395 return mMoveIndices[mSortedIndices[i]];
411 if (moveIndices.empty())
return;
412 const IndexArray& sortedIndices = mMoveLeafIndices[idx];
420 auto& targetArray = leaf.attributeArray(mAttributeIndex);
421 targetArray.loadData();
422 targetArray.expand();
426 CopyIterator copyIterator(leaf, sortedIndices, moveIndices, offsets);
431 Index startIndex = 0;
433 for (
size_t i = 1; i <= sortedIndices.size(); i++) {
434 Index endIndex = static_cast<Index>(i);
441 if (newSourceLeafIndex > sourceLeafIndex) {
442 copyIterator.
reset(startIndex, endIndex);
444 const LeafT& sourceLeaf = mSourceLeafManager.leaf(sourceLeafIndex);
445 const auto& sourceArray = sourceLeaf.constAttributeArray(mAttributeIndex);
446 sourceArray.loadData();
448 targetArray.copyValuesUnsafe(sourceArray, copyIterator);
450 sourceLeafIndex = newSourceLeafIndex;
451 startIndex = endIndex;
458 LeafManagerT& mSourceLeafManager;
459 const Index mAttributeIndex;
465 template <
typename TreeT>
468 using LeafT =
typename TreeT::LeafNodeType;
476 const Index attributeIndex,
478 : mOffsetMap(offsetMap)
479 , mSourceIndices(sourceIndices)
480 , mSourceLeafManager(sourceLeafManager)
481 , mAttributeIndex(attributeIndex)
482 , mMoveLeafMap(moveLeafMap) { }
491 , mOffsets(offsets) { }
493 operator bool()
const {
return mIndex < static_cast<int>(mIndices.size()); }
499 return mIndices[mIndex].second;
517 if (moveIndices.empty())
return;
525 assert(idx < mSourceIndices.size());
526 const Index sourceLeafOffset(mSourceIndices[idx]);
527 LeafT& sourceLeaf = mSourceLeafManager.leaf(sourceLeafOffset);
528 const auto& sourceArray = sourceLeaf.constAttributeArray(mAttributeIndex);
529 sourceArray.loadData();
533 auto& targetArray = leaf.attributeArray(mAttributeIndex);
534 targetArray.loadData();
535 targetArray.expand();
540 targetArray.copyValuesUnsafe(sourceArray, copyIterator);
546 LeafManagerT& mSourceLeafManager;
547 const Index mAttributeIndex;
563 template<
typename ValueType,
typename OpType>
564 struct ArrayProcessor {
565 static inline void call(OpType& op,
const AttributeArray& array) {
567 op.operator()<ValueType>(array);
569 op.template operator()<ValueType>(array);
577 template<
typename ArrayType,
typename OpType>
579 processTypedArray(
const ArrayType& array, OpType& op)
582 using namespace openvdb::math;
583 if (array.template hasValueType<bool>()) ArrayProcessor<bool, OpType>::call(op, array);
584 else if (array.template hasValueType<int16_t>()) ArrayProcessor<int16_t, OpType>::call(op, array);
585 else if (array.template hasValueType<int32_t>()) ArrayProcessor<int32_t, OpType>::call(op, array);
586 else if (array.template hasValueType<int64_t>()) ArrayProcessor<int64_t, OpType>::call(op, array);
587 else if (array.template hasValueType<float>()) ArrayProcessor<float, OpType>::call(op, array);
588 else if (array.template hasValueType<double>()) ArrayProcessor<double, OpType>::call(op, array);
589 else if (array.template hasValueType<
Vec3<int32_t>>()) ArrayProcessor<Vec3<int32_t>, OpType>::call(op, array);
590 else if (array.template hasValueType<
Vec3<float>>()) ArrayProcessor<Vec3<float>, OpType>::call(op, array);
591 else if (array.template hasValueType<
Vec3<double>>()) ArrayProcessor<Vec3<double>, OpType>::call(op, array);
592 else if (array.template hasValueType<GroupType>()) ArrayProcessor<GroupType, OpType>::call(op, array);
593 else if (array.template hasValueType<StringIndexType>()) ArrayProcessor<StringIndexType, OpType>::call(op, array);
594 else if (array.template hasValueType<
Mat3<float>>()) ArrayProcessor<Mat3<float>, OpType>::call(op, array);
595 else if (array.template hasValueType<
Mat3<double>>()) ArrayProcessor<Mat3<double>, OpType>::call(op, array);
596 else if (array.template hasValueType<
Mat4<float>>()) ArrayProcessor<Mat4<float>, OpType>::call(op, array);
597 else if (array.template hasValueType<
Mat4<double>>()) ArrayProcessor<Mat4<double>, OpType>::call(op, array);
598 else if (array.template hasValueType<
Quat<float>>()) ArrayProcessor<Quat<float>, OpType>::call(op, array);
599 else if (array.template hasValueType<
Quat<double>>()) ArrayProcessor<Quat<double>, OpType>::call(op, array);
606 struct AttributeHandles
608 using HandleArray = std::vector<AttributeHandle<int>::Ptr>;
610 AttributeHandles(
const size_t size)
611 : mHandles() { mHandles.reserve(size); }
613 AttributeArray& getArray(
const Index leafOffset)
615 auto* handle =
reinterpret_cast<AttributeWriteHandle<int>*
>(mHandles[leafOffset].get());
617 return handle->array();
620 const AttributeArray& getConstArray(
const Index leafOffset)
const 622 const auto* handle = mHandles[leafOffset].get();
624 return handle->array();
627 template <
typename ValueT>
628 AttributeHandle<ValueT>& getHandle(
const Index leafOffset)
630 auto* handle =
reinterpret_cast<AttributeHandle<ValueT>*
>(mHandles[leafOffset].get());
635 template <
typename ValueT>
636 AttributeWriteHandle<ValueT>& getWriteHandle(
const Index leafOffset)
638 auto* handle =
reinterpret_cast<AttributeWriteHandle<ValueT>*
>(mHandles[leafOffset].get());
646 CacheHandleOp(HandleArray& handles)
647 : mHandles(handles) { }
649 template<
typename ValueT>
650 void operator()(
const AttributeArray& array)
const 652 auto* handleAsInt =
reinterpret_cast<AttributeHandle<int>*
>(
653 new AttributeHandle<ValueT>(array));
654 mHandles.emplace_back(handleAsInt);
658 HandleArray& mHandles;
661 template <
typename LeafRangeT>
662 void cache(
const LeafRangeT& range,
const Index attributeIndex)
664 using namespace openvdb::math;
667 CacheHandleOp op(mHandles);
669 for (
auto leaf = range.begin(); leaf; ++leaf) {
670 const auto& array = leaf->constAttributeArray(attributeIndex);
671 processTypedArray(array, op);
676 HandleArray mHandles;
680 template <
typename TreeT>
681 struct GlobalMovePointsOp
683 using LeafT =
typename TreeT::LeafNodeType;
684 using LeafArrayT = std::vector<LeafT*>;
685 using LeafManagerT =
typename tree::LeafManager<TreeT>;
688 AttributeHandles& targetHandles,
689 AttributeHandles& sourceHandles,
690 const Index attributeIndex,
693 : mOffsetMap(offsetMap)
694 , mTargetHandles(targetHandles)
695 , mSourceHandles(sourceHandles)
696 , mAttributeIndex(attributeIndex)
697 , mMoveLeafMap(moveLeafMap)
698 , mMoveLeafIndices(moveLeafIndices) { }
700 struct PerformTypedMoveOp
702 PerformTypedMoveOp(AttributeHandles& targetHandles, AttributeHandles& sourceHandles,
703 Index targetOffset,
const LeafT& targetLeaf,
706 : mTargetHandles(targetHandles)
707 , mSourceHandles(sourceHandles)
708 , mTargetOffset(targetOffset)
709 , mTargetLeaf(targetLeaf)
712 , mSortedIndices(sortedIndices) { }
714 template<
typename ValueT>
715 void operator()(
const AttributeArray&)
const 717 auto& targetHandle = mTargetHandles.getWriteHandle<ValueT>(mTargetOffset);
718 targetHandle.expand();
720 for (
const auto& index : mSortedIndices) {
721 const auto& it = mIndices[index];
722 const auto& sourceHandle = mSourceHandles.getHandle<ValueT>(std::get<0>(it));
724 for (
Index i = 0; i < sourceHandle.stride(); i++) {
725 ValueT sourceValue = sourceHandle.get(std::get<2>(it), i);
726 targetHandle.set(targetIndex, i, sourceValue);
732 AttributeHandles& mTargetHandles;
733 AttributeHandles& mSourceHandles;
735 const LeafT& mTargetLeaf;
741 void performMove(
Index targetOffset,
const LeafT& targetLeaf,
745 auto& targetArray = mTargetHandles.getArray(targetOffset);
746 targetArray.loadData();
747 targetArray.expand();
749 for (
const auto& index : sortedIndices) {
750 const auto& it = indices[index];
752 const auto& sourceArray = mSourceHandles.getConstArray(std::get<0>(it));
754 const Index sourceOffset = std::get<2>(it);
757 targetArray.set(targetOffset, sourceArray, sourceOffset);
761 void operator()(LeafT& leaf,
size_t aIdx)
const 763 const Index idx(static_cast<Index>(aIdx));
764 const auto& moveIndices = mMoveLeafMap[aIdx];
765 if (moveIndices.empty())
return;
766 const auto& sortedIndices = mMoveLeafIndices[aIdx];
770 auto& offsets = mOffsetMap[aIdx];
772 const auto& array = leaf.constAttributeArray(mAttributeIndex);
774 PerformTypedMoveOp op(mTargetHandles, mSourceHandles, idx, leaf, offsets,
775 moveIndices, sortedIndices);
776 if (!processTypedArray(array, op)) {
777 this->performMove(idx, leaf, offsets, moveIndices, sortedIndices);
783 AttributeHandles& mTargetHandles;
784 AttributeHandles& mSourceHandles;
785 const Index mAttributeIndex;
791 template <
typename TreeT>
792 struct LocalMovePointsOp
794 using LeafT =
typename TreeT::LeafNodeType;
795 using LeafArrayT = std::vector<LeafT*>;
796 using LeafManagerT =
typename tree::LeafManager<TreeT>;
799 AttributeHandles& targetHandles,
801 AttributeHandles& sourceHandles,
802 const Index attributeIndex,
804 : mOffsetMap(offsetMap)
805 , mTargetHandles(targetHandles)
806 , mSourceIndices(sourceIndices)
807 , mSourceHandles(sourceHandles)
808 , mAttributeIndex(attributeIndex)
809 , mMoveLeafMap(moveLeafMap) { }
811 struct PerformTypedMoveOp
813 PerformTypedMoveOp(AttributeHandles& targetHandles, AttributeHandles& sourceHandles,
814 Index targetOffset,
Index sourceOffset,
const LeafT& targetLeaf,
816 : mTargetHandles(targetHandles)
817 , mSourceHandles(sourceHandles)
818 , mTargetOffset(targetOffset)
819 , mSourceOffset(sourceOffset)
820 , mTargetLeaf(targetLeaf)
822 , mIndices(indices) { }
824 template<
typename ValueT>
825 void operator()(
const AttributeArray&)
const 827 auto& targetHandle = mTargetHandles.getWriteHandle<ValueT>(mTargetOffset);
828 const auto& sourceHandle = mSourceHandles.getHandle<ValueT>(mSourceOffset);
830 targetHandle.expand();
832 for (
const auto& it : mIndices) {
834 for (
Index i = 0; i < sourceHandle.stride(); i++) {
835 ValueT sourceValue = sourceHandle.get(it.second, i);
836 targetHandle.set(targetIndex, i, sourceValue);
842 AttributeHandles& mTargetHandles;
843 AttributeHandles& mSourceHandles;
846 const LeafT& mTargetLeaf;
851 template <
typename ValueT>
852 void performTypedMove(
Index sourceOffset,
Index targetOffset,
const LeafT& targetLeaf,
855 auto& targetHandle = mTargetHandles.getWriteHandle<ValueT>(targetOffset);
856 const auto& sourceHandle = mSourceHandles.getHandle<ValueT>(sourceOffset);
858 targetHandle.expand();
860 for (
const auto& it : indices) {
862 for (
Index i = 0; i < sourceHandle.stride(); i++) {
863 ValueT sourceValue = sourceHandle.get(it.second, i);
864 targetHandle.set(tgtOffset, i, sourceValue);
869 void performMove(
Index targetOffset,
Index sourceOffset,
const LeafT& targetLeaf,
872 auto& targetArray = mTargetHandles.getArray(targetOffset);
873 const auto& sourceArray = mSourceHandles.getConstArray(sourceOffset);
875 for (
const auto& it : indices) {
876 const Index sourceOffset = it.second;
879 targetArray.set(targetOffset, sourceArray, sourceOffset);
883 void operator()(
const LeafT& leaf,
size_t aIdx)
const 885 const Index idx(static_cast<Index>(aIdx));
886 const auto& moveIndices = mMoveLeafMap.at(aIdx);
887 if (moveIndices.empty())
return;
891 auto& offsets = mOffsetMap[aIdx];
895 assert(aIdx < mSourceIndices.size());
896 const Index sourceOffset(mSourceIndices[aIdx]);
898 const auto& array = leaf.constAttributeArray(mAttributeIndex);
900 PerformTypedMoveOp op(mTargetHandles, mSourceHandles,
901 idx, sourceOffset, leaf, offsets, moveIndices);
902 if (!processTypedArray(array, op)) {
903 this->performMove(idx, sourceOffset, leaf, offsets, moveIndices);
909 AttributeHandles& mTargetHandles;
911 AttributeHandles& mSourceHandles;
912 const Index mAttributeIndex;
917 #endif // OPENVDB_ABI_VERSION_NUMBER >= 6 926 template <
typename Po
intDataGr
idT,
typename DeformerT,
typename FilterT>
930 const FilterT& filter,
935 using PointDataTreeT =
typename PointDataGridT::TreeType;
936 using LeafT =
typename PointDataTreeT::LeafNodeType;
939 using namespace point_move_internal;
942 assert(!objectNotInUse);
943 (void)objectNotInUse;
945 PointDataTreeT& tree = points.tree();
955 auto newPoints = point_mask_internal::convertPointsToScalar<PointDataGrid>(
956 points, transform, filter, deformer, threaded);
957 auto& newTree = newPoints->tree();
961 LeafManagerT sourceLeafManager(tree);
962 LeafManagerT targetLeafManager(newTree);
965 const auto& existingAttributeSet = points.tree().cbeginLeaf()->attributeSet();
978 auto sourceRange = sourceLeafManager.leafRange();
979 for (
auto leaf = sourceRange.begin(); leaf; ++leaf) {
980 sourceLeafMap.insert({leaf->origin(),
LeafIndex(static_cast<LeafIndex>(leaf.pos()))});
982 auto targetRange = targetLeafManager.leafRange();
983 for (
auto leaf = targetRange.begin(); leaf; ++leaf) {
984 targetLeafMap.insert({leaf->origin(),
LeafIndex(static_cast<LeafIndex>(leaf.pos()))});
992 targetLeafManager.foreach(
993 [&](LeafT& leaf,
size_t idx) {
995 auto* buffer = leaf.buffer().data();
996 for (
Index i = 1; i < leaf.buffer().size(); i++) {
997 buffer[i] = buffer[i-1] + buffer[i];
1000 leaf.replaceAttributeSet(
1001 new AttributeSet(existingAttributeSet, leaf.getLastValue(), &lock),
1004 const auto it = sourceLeafMap.find(leaf.origin());
1005 if (it != sourceLeafMap.end()) {
1006 sourceIndices[idx] = it->second;
1009 offsetMap[idx].resize(LeafT::SIZE);
1023 BuildMoveMapsOp<DeformerT, PointDataTreeT, NullFilter> op(deformer,
1024 globalMoveLeafMap, localMoveLeafMap, targetLeafMap,
1025 transform, points.transform(), nullFilter);
1026 sourceLeafManager.foreach(op, threaded);
1028 BuildMoveMapsOp<DeformerT, PointDataTreeT, FilterT> op(deformer,
1029 globalMoveLeafMap, localMoveLeafMap, targetLeafMap,
1030 transform, points.transform(), filter);
1031 sourceLeafManager.foreach(op, threaded);
1040 targetLeafManager.foreach(
1041 [&](LeafT& ,
size_t idx) {
1043 if (moveIndices.empty())
return;
1045 IndexArray& sortedIndices = globalMoveLeafIndices[idx];
1046 sortedIndices.resize(moveIndices.size());
1047 std::iota(std::begin(sortedIndices), std::end(sortedIndices), 0);
1048 std::sort(std::begin(sortedIndices), std::end(sortedIndices),
1051 const Index& indexI0(std::get<0>(moveIndices[i]));
1052 const Index& indexJ0(std::get<0>(moveIndices[j]));
1053 if (indexI0 < indexJ0)
return true;
1054 if (indexI0 > indexJ0)
return false;
1055 return std::get<2>(moveIndices[i]) < std::get<2>(moveIndices[j]);
1061 #if OPENVDB_ABI_VERSION_NUMBER < 6 1063 AttributeHandles sourceHandles(sourceLeafManager.leafCount());
1064 AttributeHandles targetHandles(targetLeafManager.leafCount());
1067 for (
const auto& it : existingAttributeSet.descriptor().map()) {
1069 const Index attributeIndex = static_cast<Index>(it.second);
1072 targetLeafManager.foreach(
1073 [&offsetMap](
const LeafT& ,
size_t idx) {
1074 std::fill(offsetMap[idx].begin(), offsetMap[idx].end(), 0);
1078 #if OPENVDB_ABI_VERSION_NUMBER >= 6 1082 GlobalMovePointsOp<PointDataTreeT> globalMoveOp(offsetMap,
1083 sourceLeafManager, attributeIndex, globalMoveLeafMap, globalMoveLeafIndices);
1084 targetLeafManager.foreach(globalMoveOp, threaded);
1088 LocalMovePointsOp<PointDataTreeT> localMoveOp(offsetMap,
1089 sourceIndices, sourceLeafManager, attributeIndex, localMoveLeafMap);
1090 targetLeafManager.foreach(localMoveOp, threaded);
1094 sourceHandles.cache(sourceLeafManager.leafRange(), attributeIndex);
1095 targetHandles.cache(targetLeafManager.leafRange(), attributeIndex);
1099 GlobalMovePointsOp<PointDataTreeT> globalMoveOp(offsetMap, targetHandles,
1100 sourceHandles, attributeIndex, globalMoveLeafMap, globalMoveLeafIndices);
1101 targetLeafManager.foreach(globalMoveOp, threaded);
1105 LocalMovePointsOp<PointDataTreeT> localMoveOp(offsetMap, targetHandles,
1106 sourceIndices, sourceHandles,
1107 attributeIndex, localMoveLeafMap);
1108 targetLeafManager.foreach(localMoveOp, threaded);
1109 #endif // OPENVDB_ABI_VERSION_NUMBER >= 6 1112 points.setTree(newPoints->treePtr());
1116 template <
typename Po
intDataGr
idT,
typename DeformerT,
typename FilterT>
1118 DeformerT& deformer,
1119 const FilterT& filter,
1123 movePoints(points, points.transform(), deformer, filter, objectNotInUse, threaded);
1130 template <
typename T>
1135 template <
typename T>
1136 template <
typename Po
intDataGr
idT,
typename DeformerT,
typename FilterT>
1140 using TreeT =
typename PointDataGridT::TreeType;
1141 using LeafT =
typename TreeT::LeafNodeType;
1143 LeafManagerT leafManager(grid.tree());
1146 auto& leafs = mCache.leafs;
1147 leafs.resize(leafManager.leafCount());
1149 const auto& transform = grid.transform();
1153 auto cachePositionsOp = [&](
const LeafT& leaf,
size_t idx) {
1155 const Index64 totalPointCount = leaf.pointCount();
1156 if (totalPointCount == 0)
return;
1160 DeformerT newDeformer(deformer);
1162 newDeformer.reset(leaf, idx);
1166 auto& cache = leafs[idx];
1171 const bool useVector = filter.state() ==
index::ALL &&
1172 (leaf.isDense() || (leaf.onPointCount() == leaf.pointCount()));
1174 cache.vecData.resize(totalPointCount);
1177 for (
auto iter = leaf.beginIndexOn(filter); iter; iter++) {
1181 Vec3d position = handle->get(*iter) + iter.getCoord().asVec3d();
1187 newDeformer.apply(position, iter);
1192 newDeformer.apply(position, iter);
1198 cache.vecData[*iter] = static_cast<Vec3T>(position);
1201 cache.mapData.insert({*iter, static_cast<Vec3T>(position)});
1207 if (!cache.mapData.empty()) {
1208 cache.totalSize = static_cast<Index>(totalPointCount);
1212 leafManager.foreach(cachePositionsOp, threaded);
1216 template <
typename T>
1217 template <
typename LeafT>
1220 if (idx >= mCache.leafs.size()) {
1221 if (mCache.leafs.empty()) {
1222 throw IndexError(
"No leafs in cache, perhaps CachedDeformer has not been evaluated?");
1224 throw IndexError(
"Leaf index is out-of-range of cache leafs.");
1227 auto& cache = mCache.leafs[idx];
1228 if (!cache.mapData.empty()) {
1229 mLeafMap = &cache.mapData;
1233 mLeafVec = &cache.vecData;
1239 template <
typename T>
1240 template <
typename IndexIterT>
1246 auto it = mLeafMap->find(*iter);
1247 if (it == mLeafMap->end())
return;
1248 position = static_cast<openvdb::Vec3d>(it->second);
1253 if (mLeafVec->empty())
return;
1254 assert(*iter < mLeafVec->size());
1255 position = static_cast<openvdb::Vec3d>((*mLeafVec)[*iter]);
1264 #endif // OPENVDB_POINTS_POINT_MOVE_HAS_BEEN_INCLUDED std::vector< IndexPairArray > LocalPointIndexMap
Definition: PointMove.h:197
std::tuple< LeafIndex, Index, Index > IndexTriple
Definition: PointMove.h:190
Index targetIndex() const
Definition: PointMove.h:375
GlobalMovePointsOp(LeafOffsetArray &offsetMap, LeafManagerT &sourceLeafManager, const Index attributeIndex, const GlobalPointIndexMap &moveLeafMap, const GlobalPointIndexIndices &moveLeafIndices)
Definition: PointMove.h:324
Definition: PointMove.h:486
Index32 LeafIndex
Definition: PointMove.h:120
std::vector< IndexTripleArray > GlobalPointIndexMap
Definition: PointMove.h:192
Index indexOffsetFromVoxel(const Index voxelOffset, const LeafT &leaf, IndexArray &offsets)
Definition: PointMove.h:299
std::unordered_map< Coord, LeafIndex > LeafMap
Definition: PointMove.h:201
Definition: PointMove.h:205
3x3 matrix class.
Definition: Mat3.h:55
void operator()(LeafT &leaf, size_t idx) const
Definition: PointMove.h:514
void operator()(LeafT &leaf, size_t idx) const
Definition: PointMove.h:408
std::vector< IndexPair > IndexPairArray
Definition: PointMove.h:196
Definition: PointMove.h:466
void operator()(LeafT &leaf, size_t idx) const
Definition: PointMove.h:226
std::vector< LeafIndexArray > LeafOffsetArray
Definition: PointMove.h:200
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:52
std::vector< AttributeArray * > AttributeArrays
Definition: PointMove.h:322
typename TreeT::LeafNodeType LeafT
Definition: PointMove.h:207
Index32 Index
Definition: Types.h:61
Index leafIndex(Index i) const
Definition: PointMove.h:361
std::vector< LeafIndex > LeafIndexArray
Definition: PointMove.h:199
static Ptr create(const AttributeArray &array, const bool collapseOnDestruction=true)
Definition: AttributeArray.h:2140
typename tree::LeafManager< TreeT > LeafManagerT
Definition: PointMove.h:321
Write-able version of AttributeHandle.
Definition: AttributeArray.h:944
Vec3< double > Vec3d
Definition: Vec3.h:689
std::vector< IndexArray > GlobalPointIndexIndices
Definition: PointMove.h:193
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
CopyIterator(const LeafT &leaf, const IndexPairArray &indices, IndexArray &offsets)
Definition: PointMove.h:488
typename TreeT::LeafNodeType LeafT
Definition: PointMove.h:319
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:128
std::vector< LeafT * > LeafArrayT
Definition: PointMove.h:469
CopyIterator & operator++()
Definition: PointMove.h:355
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:77
CopyIterator & operator++()
Definition: PointMove.h:495
Definition: Exceptions.h:40
Vec3d asVec3d() const
Definition: Coord.h:171
Definition: PointMove.h:86
typename tree::LeafManager< TreeT > LeafManagerT
Definition: PointMove.h:209
Definition: Exceptions.h:84
LocalMovePointsOp(LeafOffsetArray &offsetMap, const LeafIndexArray &sourceIndices, LeafManagerT &sourceLeafManager, const Index attributeIndex, const LocalPointIndexMap &moveLeafMap)
Definition: PointMove.h:473
std::vector< LeafT * > LeafArrayT
Definition: PointMove.h:208
uint64_t Index64
Definition: Types.h:60
std::pair< Index, Index > IndexPair
Definition: PointMove.h:195
BuildMoveMapsOp(const DeformerT &deformer, GlobalPointIndexMap &globalMoveLeafMap, LocalPointIndexMap &localMoveLeafMap, const LeafMap &targetLeafMap, const math::Transform &targetTransform, const math::Transform &sourceTransform, const FilterT &filter)
Definition: PointMove.h:211
std::vector< AttributeArray * > AttributeArrays
Definition: PointMove.h:471
Methods for extracting masks from VDB Point grids.
void movePoints(PointDataGridT &points, const math::Transform &transform, DeformerT &deformer, const FilterT &filter=NullFilter(), future::Advect *objectNotInUse=nullptr, bool threaded=true)
Move points in a PointDataGrid using a custom deformer and a new transform.
Definition: PointMove.h:927
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109
void reset(Index startIndex, Index endIndex)
Definition: PointMove.h:348
typename TreeT::LeafNodeType LeafT
Definition: PointMove.h:468
Definition: IndexIterator.h:70
static Coord round(const Vec3< T > &xyz)
Return xyz rounded to the closest integer coordinates (cell centered conversion).
Definition: Coord.h:78
Definition: PointMove.h:317
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Definition: AttributeArray.h:145
Index targetIndex() const
Definition: PointMove.h:502
Definition: PointMove.h:337
Index sourceIndex() const
Definition: PointMove.h:497
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180
4x4 -matrix class.
Definition: Mat3.h:49
typename tree::LeafManager< TreeT > LeafManagerT
Definition: PointMove.h:470
Base class for storing attribute data.
Definition: AttributeArray.h:118
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels)
Definition: TreeIterator.h:1218
tbb::concurrent_vector< IndexTriple > IndexTripleArray
Definition: PointMove.h:191
std::vector< Index > IndexArray
Definition: PointMove.h:188
uint32_t Index32
Definition: Types.h:59
std::vector< LeafT * > LeafArrayT
Definition: PointMove.h:320
Index sourceIndex() const
Definition: PointMove.h:369
CopyIterator(const LeafT &leaf, const IndexArray &sortedIndices, const IndexTripleArray &moveIndices, IndexArray &offsets)
Definition: PointMove.h:339