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());
89 static Ptr create(
const GU_Detail& detail,
const GA_PointGroup* group =
nullptr)
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,
307 const GU_Detail& detail,
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,
347 const GU_Detail& detail,
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,
373 const GU_Detail& detail,
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