OpenVDB 10.0.1
Loading...
Searching...
No Matches
GeometryUtil.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3//
4/// @file GeometryUtil.h
5/// @author FX R&D Simulation team
6/// @brief Utility methods and tools for geometry processing
7
8#ifndef OPENVDB_HOUDINI_GEOMETRY_UTIL_HAS_BEEN_INCLUDED
9#define OPENVDB_HOUDINI_GEOMETRY_UTIL_HAS_BEEN_INCLUDED
10
11#include <openvdb/openvdb.h>
12#include <openvdb/tools/MeshToVolume.h> // for openvdb::tools::MeshToVoxelEdgeData
15#include <openvdb/util/Util.h> // for openvdb::util::COORD_OFFSETS
16
17#include <GU/GU_Detail.h>
18
19#include <algorithm> // for std::max/min()
20#include <memory>
21#include <string>
22#include <vector>
23
24
25class GA_SplittableRange;
26class OBJ_Camera;
27class OP_Context;
28class OP_Node;
29
30
31#ifdef SESI_OPENVDB
32 #ifdef OPENVDB_HOUDINI_API
33 #undef OPENVDB_HOUDINI_API
34 #define OPENVDB_HOUDINI_API
35 #endif
36#endif
37
38
39namespace openvdb_houdini {
40
41class Interrupter;
42
43
44/// Add geometry to the given detail to indicate the extents of a frustum transform.
46void
47drawFrustum(GU_Detail&, const openvdb::math::Transform&,
48 const UT_Vector3* boxColor, const UT_Vector3* tickColor,
49 bool shaded, bool drawTicks = true);
50
51
52/// Construct a frustum transform from a Houdini camera.
54openvdb::math::Transform::Ptr
56 OP_Node&, OP_Context&, OBJ_Camera&,
57 float offset, float nearPlaneDist, float farPlaneDist,
58 float voxelDepthSize = 1.0, int voxelCountX = 100);
59
60
61////////////////////////////////////////
62
63
64/// @brief Return @c true if the point at the given offset is referenced
65/// by primitives from a certain primitive group.
67bool
68pointInPrimGroup(GA_Offset ptnOffset, GU_Detail&, const GA_PrimitiveGroup&);
69
70
71////////////////////////////////////////
72
73
74/// @brief Convert geometry to quads and triangles.
75/// @return a pointer to a new GU_Detail object if the geometry was
76/// converted or subdivided, otherwise a null pointer
78std::unique_ptr<GU_Detail>
79convertGeometry(const GU_Detail&, std::string& warning, openvdb::util::NullInterrupter*);
80
81
82OPENVDB_DEPRECATED_MESSAGE("openvdb_houdini::Interrupter has been deprecated, use openvdb_houdini::HoudiniInterrupter")
84std::unique_ptr<GU_Detail>
85convertGeometry(const GU_Detail& detail, std::string& warning, Interrupter* boss);
86
87
88////////////////////////////////////////
89
90
91/// TBB body object for threaded world to voxel space transformation and copy of points
93{
94public:
95 TransformOp(GU_Detail const * const gdp,
96 const openvdb::math::Transform& transform,
97 std::vector<openvdb::Vec3s>& pointList);
98
99 void operator()(const GA_SplittableRange&) const;
100
101private:
102 GU_Detail const * const mGdp;
103 const openvdb::math::Transform& mTransform;
104 std::vector<openvdb::Vec3s>* const mPointList;
105};
106
107
108////////////////////////////////////////
109
110
111/// @brief TBB body object for threaded primitive copy
112/// @details Produces a primitive-vertex index list.
114{
115public:
116 PrimCpyOp(GU_Detail const * const gdp, std::vector<openvdb::Vec4I>& primList);
117 void operator()(const GA_SplittableRange&) const;
118
119private:
120 GU_Detail const * const mGdp;
121 std::vector<openvdb::Vec4I>* const mPrimList;
122};
123
124
125////////////////////////////////////////
126
127
128/// @brief TBB body object for threaded vertex normal generation
129/// @details Averages face normals from all similarly oriented primitives,
130/// that share the same vertex-point, to maintain sharp features.
132{
133public:
134 VertexNormalOp(GU_Detail&, const GA_PrimitiveGroup* interiorPrims=nullptr, float angle=0.7f);
135 void operator()(const GA_SplittableRange&) const;
136
137private:
138 bool isInteriorPrim(GA_Offset primOffset) const
139 {
140 return mInteriorPrims && mInteriorPrims->containsIndex(
141 mDetail.primitiveIndex(primOffset));
142 }
143
144 const GU_Detail& mDetail;
145 const GA_PrimitiveGroup* mInteriorPrims;
146 GA_RWHandleV3 mNormalHandle;
147 const float mAngle;
148};
149
150
151////////////////////////////////////////
152
153
154/// TBB body object for threaded sharp feature construction
156{
157public:
158 using EdgeData = openvdb::tools::MeshToVoxelEdgeData;
159
160 SharpenFeaturesOp(GU_Detail& meshGeo, const GU_Detail& refGeo, EdgeData& edgeData,
161 const openvdb::math::Transform& xform, const GA_PrimitiveGroup* surfacePrims = nullptr,
162 const openvdb::BoolTree* mask = nullptr);
163
164 void operator()(const GA_SplittableRange&) const;
165
166private:
167 GU_Detail& mMeshGeo;
168 const GU_Detail& mRefGeo;
169 EdgeData& mEdgeData;
170 const openvdb::math::Transform& mXForm;
171 const GA_PrimitiveGroup* mSurfacePrims;
172 const openvdb::BoolTree* mMaskTree;
173};
174
175
176////////////////////////////////////////
177
178
179/// TBB body object for threaded sharp feature construction
180template<typename IndexTreeType, typename BoolTreeType>
182{
183public:
184 using BoolLeafManager = openvdb::tree::LeafManager<BoolTreeType>;
185
186 GenAdaptivityMaskOp(const GU_Detail& refGeo,
187 const IndexTreeType& indexTree, BoolLeafManager&, float edgetolerance = 0.0);
188
189 void run(bool threaded = true);
190
191 void operator()(const tbb::blocked_range<size_t>&) const;
192
193private:
194 const GU_Detail& mRefGeo;
195 const IndexTreeType& mIndexTree;
196 BoolLeafManager& mLeafs;
197 float mEdgeTolerance;
198};
199
200
201template<typename IndexTreeType, typename BoolTreeType>
203 const IndexTreeType& indexTree, BoolLeafManager& leafMgr, float edgetolerance)
204 : mRefGeo(refGeo)
205 , mIndexTree(indexTree)
206 , mLeafs(leafMgr)
207 , mEdgeTolerance(edgetolerance)
208{
209 mEdgeTolerance = std::max(0.0f, mEdgeTolerance);
210 mEdgeTolerance = std::min(1.0f, mEdgeTolerance);
211}
212
213
214template<typename IndexTreeType, typename BoolTreeType>
215void
217{
218 if (threaded) {
219 tbb::parallel_for(mLeafs.getRange(), *this);
220 } else {
221 (*this)(mLeafs.getRange());
222 }
223}
224
225
226template<typename IndexTreeType, typename BoolTreeType>
227void
229 const tbb::blocked_range<size_t>& range) const
230{
231 using IndexAccessorType = typename openvdb::tree::ValueAccessor<const IndexTreeType>;
232 IndexAccessorType idxAcc(mIndexTree);
233
234 UT_Vector3 tmpN, normal;
235 GA_Offset primOffset;
236 int tmpIdx;
237
238 openvdb::Coord ijk, nijk;
239 typename BoolTreeType::LeafNodeType::ValueOnIter iter;
240
241 for (size_t n = range.begin(); n < range.end(); ++n) {
242 iter = mLeafs.leaf(n).beginValueOn();
243 for (; iter; ++iter) {
244 ijk = iter.getCoord();
245
246 bool edgeVoxel = false;
247
248 int idx = idxAcc.getValue(ijk);
249
250 primOffset = mRefGeo.primitiveOffset(idx);
251 normal = mRefGeo.getGEOPrimitive(primOffset)->computeNormal();
252
253 for (size_t i = 0; i < 18; ++i) {
254 nijk = ijk + openvdb::util::COORD_OFFSETS[i];
255 if (idxAcc.probeValue(nijk, tmpIdx) && tmpIdx != idx) {
256 primOffset = mRefGeo.primitiveOffset(tmpIdx);
257 tmpN = mRefGeo.getGEOPrimitive(primOffset)->computeNormal();
258
259 if (normal.dot(tmpN) < mEdgeTolerance) {
260 edgeVoxel = true;
261 break;
262 }
263 }
264 }
265
266 if (!edgeVoxel) iter.setValueOff();
267 }
268 }
269}
270
271
272} // namespace openvdb_houdini
273
274
275////////////////////////////////////////
276
277
278#endif // OPENVDB_HOUDINI_GEOMETRY_UTIL_HAS_BEEN_INCLUDED
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
Convert polygonal meshes that consist of quads and/or triangles into signed or unsigned distance fiel...
#define OPENVDB_HOUDINI_API
Definition Platform.h:259
#define OPENVDB_DEPRECATED_MESSAGE(msg)
Definition Platform.h:125
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:25
Definition Tree.h:178
TBB body object for threaded sharp feature construction.
Definition GeometryUtil.h:182
void run(bool threaded=true)
Definition GeometryUtil.h:216
void operator()(const tbb::blocked_range< size_t > &) const
Definition GeometryUtil.h:228
openvdb::tree::LeafManager< BoolTreeType > BoolLeafManager
Definition GeometryUtil.h:184
GenAdaptivityMaskOp(const GU_Detail &refGeo, const IndexTreeType &indexTree, BoolLeafManager &, float edgetolerance=0.0)
Definition GeometryUtil.h:202
Deprecated wrapper class with the same interface as HoudiniInterrupter, however it does not derive fr...
Definition Utils.h:209
TBB body object for threaded primitive copy.
Definition GeometryUtil.h:114
void operator()(const GA_SplittableRange &) const
PrimCpyOp(GU_Detail const *const gdp, std::vector< openvdb::Vec4I > &primList)
TBB body object for threaded sharp feature construction.
Definition GeometryUtil.h:156
void operator()(const GA_SplittableRange &) const
SharpenFeaturesOp(GU_Detail &meshGeo, const GU_Detail &refGeo, EdgeData &edgeData, const openvdb::math::Transform &xform, const GA_PrimitiveGroup *surfacePrims=nullptr, const openvdb::BoolTree *mask=nullptr)
openvdb::tools::MeshToVoxelEdgeData EdgeData
Definition GeometryUtil.h:158
TBB body object for threaded world to voxel space transformation and copy of points.
Definition GeometryUtil.h:93
void operator()(const GA_SplittableRange &) const
TransformOp(GU_Detail const *const gdp, const openvdb::math::Transform &transform, std::vector< openvdb::Vec3s > &pointList)
TBB body object for threaded vertex normal generation.
Definition GeometryUtil.h:132
void operator()(const GA_SplittableRange &) const
VertexNormalOp(GU_Detail &, const GA_PrimitiveGroup *interiorPrims=nullptr, float angle=0.7f)
Definition VoxToNanoVDB.h:14
Definition AttributeTransferUtil.h:34
OPENVDB_HOUDINI_API bool pointInPrimGroup(GA_Offset ptnOffset, GU_Detail &, const GA_PrimitiveGroup &)
Return true if the point at the given offset is referenced by primitives from a certain primitive gro...
OPENVDB_HOUDINI_API void drawFrustum(GU_Detail &, const openvdb::math::Transform &, const UT_Vector3 *boxColor, const UT_Vector3 *tickColor, bool shaded, bool drawTicks=true)
Add geometry to the given detail to indicate the extents of a frustum transform.
OPENVDB_HOUDINI_API std::unique_ptr< GU_Detail > convertGeometry(const GU_Detail &, std::string &warning, openvdb::util::NullInterrupter *)
Convert geometry to quads and triangles.
OPENVDB_HOUDINI_API openvdb::math::Transform::Ptr frustumTransformFromCamera(OP_Node &, OP_Context &, OBJ_Camera &, float offset, float nearPlaneDist, float farPlaneDist, float voxelDepthSize=1.0, int voxelCountX=100)
Construct a frustum transform from a Houdini camera.
Definition Coord.h:587