9 #ifndef GU_VDBPOINTTOOLS_H_HAS_BEEN_INCLUDED 10 #define GU_VDBPOINTTOOLS_H_HAS_BEEN_INCLUDED 12 #if defined(SESI_OPENVDB) 13 #include "GU_Detail.h" 14 #include "GU_DetailHandle.h" 15 #include "GU_PackedContext.h" 16 #include "GU_PackedFragment.h" 17 #include "GU_PackedGeometry.h" 18 #include "GU_PrimPacked.h" 20 #include <GU/GU_Detail.h> 21 #include <GU/GU_DetailHandle.h> 22 #include <GU/GU_PackedContext.h> 23 #include <GU/GU_PackedFragment.h> 24 #include <GU/GU_PackedGeometry.h> 25 #include <GU/GU_PrimPacked.h> 27 #include <GA/GA_ElementGroup.h> 28 #include <UT/UT_SharedPtr.h> 29 #include <UT/UT_VectorTypes.h> 40 template<
typename VectorType>
43 using Ptr = UT_SharedPtr<GU_VDBPointList>;
44 using ConstPtr = UT_SharedPtr<const GU_VDBPointList>;
50 : mPositionHandle(detail.getP())
53 , mIndexMap(&detail.getP()->getIndexMap())
55 , mSize(mIndexMap->indexSize())
58 mSize = group->entries();
59 mOffsets.reserve(mSize);
62 GA_Range range(*group);
63 for (GA_Iterator it = range.begin(); it.blockAdvance(start, end); ) {
64 for (GA_Offset off = start; off < end; ++off) {
65 mOffsets.push_back(off);
69 getOffset = &GU_VDBPointList::offsetFromGroupMap;
70 }
else if (mIndexMap->isTrivialMap()) {
71 getOffset = &GU_VDBPointList::offsetFromIndexCast;
73 getOffset = &GU_VDBPointList::offsetFromGeoMap;
78 GA_ROAttributeRef velRef = detail.findFloatTuple(GA_ATTRIB_POINT, GEO_STD_ATTRIB_VELOCITY, 3);
79 if (velRef.isValid()) {
80 mVelocityHandle.bind(velRef.getAttribute());
83 GA_ROAttributeRef radRef = detail.findFloatTuple(GA_ATTRIB_POINT, GEO_STD_ATTRIB_PSCALE);
84 if (radRef.isValid()) {
85 mRadiusHandle.bind(radRef.getAttribute());
94 size_t size()
const {
return mSize; }
96 bool hasVelocity()
const {
return mVelocityHandle.isValid(); }
97 bool hasRadius()
const {
return mRadiusHandle.isValid(); }
116 return (this->*getOffset)(n);
120 const UT_Vector3 data = mPositionHandle.get(offset);
127 const UT_Vector3 data = mVelocityHandle.get(offset);
144 GA_Offset offsetFromGeoMap(
const size_t n)
const {
145 return mIndexMap->offsetFromIndex(GA_Index(n));
148 GA_Offset offsetFromGroupMap(
const size_t n)
const {
152 GA_Offset offsetFromIndexCast(
const size_t n)
const {
156 GA_ROHandleV3 mPositionHandle, mVelocityHandle;
157 GA_ROHandleF mRadiusHandle;
158 GA_IndexMap
const *
const mIndexMap;
159 std::vector<GA_Offset> mOffsets;
172 template<
typename Po
intArrayType>
176 template <
typename LeafT>
179 for (
size_t n = 0, N = indices.size(); n < N; ++n) {
180 indices[n] =
static_cast<typename LeafT::ValueType::IntType
>(
181 mPointList->offsetFromIndex(GA_Index{indices[n]}));
191 const openvdb::math::Transform& xform)
192 : mPrims(prims.empty() ? nullptr : &prims.front())
196 mMaskGrid->setTransform(mXForm.copy());
204 mMaskGrid->setTransform(mXForm.copy());
213 GU_PackedContext packedcontext;
215 for (
size_t n = range.begin(), N = range.end(); n < N; ++n) {
216 const GA_Primitive *prim = mPrims[n];
217 if (!prim || !GU_PrimPacked::isPackedPrimitive(*prim))
continue;
219 const GU_PrimPacked * pprim =
static_cast<const GU_PrimPacked*
>(prim);
222 const GU_Detail *detailtouse;
224 GU_DetailHandleAutoReadLock readlock(pprim->getPackedDetail(packedcontext));
227 pprim->getFullTransform4(mat);
228 if (mat.isIdentity() && readlock.isValid() && readlock.getGdp()) {
229 detailtouse = readlock.getGdp();
231 pprim->unpackWithContext(tmpdetail, packedcontext);
232 detailtouse = &tmpdetail;
237 mMaskGrid->tree().topologyUnion(grid->tree());
242 GA_Primitive
const *
const *
const mPrims;
243 openvdb::math::Transform mXForm;
251 const GA_Size numPacked = GU_PrimPacked::countPackedPrimitives(detail);
254 primitives.reserve(
size_t(numPacked));
256 if (numPacked != GA_Size(0)) {
257 GA_Offset start, end;
258 GA_Range range = detail.getPrimitiveRange();
259 const GA_PrimitiveList& primList = detail.getPrimitiveList();
261 for (GA_Iterator it = range.begin(); it.blockAdvance(start, end); ) {
262 for (GA_Offset off = start; off < end; ++off) {
264 const GA_Primitive *prim = primList.get(off);
266 if (prim && GU_PrimPacked::isPackedPrimitive(*prim)) {
267 primitives.push_back(prim);
293 template<
typename Po
intIndexTreeType,
typename Po
intArrayType>
297 openvdb::tree::LeafManager<PointIndexTreeType> leafnodes(tree);
304 inline openvdb::tools::PointIndexGrid::Ptr
306 const openvdb::math::Transform& xform,
308 const GA_PointGroup* pointGroup =
nullptr)
311 return openvdb::tools::createPointIndexGrid<openvdb::tools::PointIndexGrid>(points, xform);
317 template<
typename Po
intArrayType>
318 inline openvdb::tools::PointIndexGrid::Ptr
321 return openvdb::tools::createPointIndexGrid<openvdb::tools::PointIndexGrid>(points, xform);
327 template<
typename ParticleArrayType>
328 inline openvdb::tools::ParticleIndexAtlas::Ptr
334 if (particles.hasRadius()) {
335 atlas->construct(particles, minVoxelSize);
346 const openvdb::math::Transform& xform,
348 const GA_PointGroup* pointGroup =
nullptr)
350 std::vector<const GA_Primitive*> packed;
353 if (!packed.empty()) {
355 tbb::parallel_reduce(tbb::blocked_range<size_t>(0, packed.size()), op);
370 inline openvdb::tools::PointIndexGrid::Ptr
372 const openvdb::math::Transform& xform,
374 const GA_PointGroup* pointGroup =
nullptr)
378 openvdb::tools::PointIndexGrid::Ptr grid =
379 openvdb::tools::createPointIndexGrid<openvdb::tools::PointIndexGrid>(points, xform);
387 #endif // GU_VDBPOINTTOOLS_H_HAS_BEEN_INCLUDED std::vector< Index > IndexArray
Definition: PointMove.h:161
bool hasVelocity() const
Definition: GU_VDBPointTools.h:96
bool hasRadius() const
Definition: GU_VDBPointTools.h:97
SharedPtr< Grid > Ptr
Definition: Grid.h:579
Space-partitioning acceleration structure for particles, points with radius. Partitions particle indi...
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
VectorType PosType
Definition: GU_VDBPointTools.h:46
GU_VDBPointList(const GU_Detail &detail, const GA_PointGroup *group=nullptr)
Definition: GU_VDBPointTools.h:49
size_t size() const
Definition: GU_VDBPointTools.h:94
void getVelocity(size_t n, PosType &v) const
Definition: GU_VDBPointTools.h:105
void getRadiusFromOffset(const GA_Offset offset, ScalarType &r) const
Definition: GU_VDBPointTools.h:133
static Ptr create(const GU_Detail &detail, const GA_PointGroup *group=nullptr)
Definition: GU_VDBPointTools.h:89
UT_SharedPtr< GU_VDBPointList > Ptr
Definition: GU_VDBPointTools.h:43
Definition: VoxToNanoVDB.h:14
UT_SharedPtr< const GU_VDBPointList > ConstPtr
Definition: GU_VDBPointTools.h:44
void getRadius(size_t n, ScalarType &r) const
Definition: GU_VDBPointTools.h:109
Definition: Exceptions.h:13
This tool produces a grid where every voxel that contains a point is active. It employs thread-local ...
typename PosType::value_type ScalarType
Definition: GU_VDBPointTools.h:47
Houdini point attribute wrapper.
Definition: GU_VDBPointTools.h:41
void getVelocityFromOffset(const GA_Offset offset, PosType &v) const
Definition: GU_VDBPointTools.h:126
void getPos(size_t n, PosType &xyz) const
Definition: GU_VDBPointTools.h:101
GA_Offset offsetFromIndex(size_t n) const
Definition: GU_VDBPointTools.h:115
Grid< MaskTree > MaskGrid
Definition: openvdb.h:47
void getPosFromOffset(const GA_Offset offset, PosType &xyz) const
Definition: GU_VDBPointTools.h:119