4 #ifndef OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED 5 #define OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED 15 #include <tbb/blocked_range.h> 16 #include <tbb/parallel_for.h> 17 #include <type_traits> 41 template<
class Gr
idType>
42 inline typename GridType::Ptr
61 template<
class Gr
idType>
62 inline typename GridType::Ptr
63 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
64 const math::Transform* xform =
nullptr);
82 template<
class Gr
idType,
typename InterruptT>
83 inline typename GridType::Ptr
84 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
85 const math::Transform* xform =
nullptr, InterruptT* interrupter =
nullptr);
100 : mPointsIn(pointsIn)
101 , mPointsOut(&pointsOut)
108 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPointsOut->size()), *
this);
113 (*this)(tbb::blocked_range<size_t>(0, mPointsOut->size()));
116 inline void operator()(
const tbb::blocked_range<size_t>& range)
const 118 for (
size_t n = range.begin(); n < range.end(); ++n) {
119 (*mPointsOut)[n] =
Vec3s(mXform.worldToIndex(mPointsIn[n]));
125 std::vector<Vec3s> *
const mPointsOut;
134 std::vector<Vec4I>& primsOut)
136 , mIndexList(indexList)
137 , mPrimsOut(&primsOut)
143 tbb::parallel_for(tbb::blocked_range<size_t>(0, mIndexList.size()), *
this);
148 (*this)(tbb::blocked_range<size_t>(0, mIndexList.size()));
151 inline void operator()(
const tbb::blocked_range<size_t>& range)
const 155 std::vector<Vec4I>& primsOut = *mPrimsOut;
157 for (
size_t n = range.begin(); n < range.end(); ++n) {
158 size_t index = mIndexList[n];
162 for (
size_t i = 0, I = polygons.
numQuads(); i < I; ++i) {
163 primsOut[index++] = polygons.
quad(i);
168 for (
size_t i = 0, I = polygons.
numTriangles(); i < I; ++i) {
170 quad[0] = triangle[0];
171 quad[1] = triangle[1];
172 quad[2] = triangle[2];
173 primsOut[index++] = quad;
182 const std::vector<size_t>& mIndexList;
183 std::vector<Vec4I> *
const mPrimsOut;
201 template<
class Gr
idType,
typename InterruptT>
202 inline typename std::enable_if<
203 std::is_floating_point<typename GridType::ValueType>::value,
typename GridType::Ptr>::type
204 doLevelSetRebuild(
const GridType& grid,
typename GridType::ValueType iso,
205 typename GridType::ValueType exWidth,
typename GridType::ValueType inWidth,
209 isovalue = float(iso),
210 exBandWidth = float(exWidth),
211 inBandWidth = float(inWidth);
218 std::vector<Vec3s> points(mesher.pointListSize());
221 internal::PointListTransform ptnXForm(mesher.pointList(), points, *transform);
222 ptnXForm.runParallel();
223 mesher.pointList().reset(
nullptr);
226 std::vector<Vec4I> primitives;
231 size_t numPrimitives = 0;
232 std::vector<size_t> indexlist(mesher.polygonPoolListSize());
234 for (
size_t n = 0, N = mesher.polygonPoolListSize(); n < N; ++n) {
235 const openvdb::tools::PolygonPool& polygons = polygonPoolList[n];
236 indexlist[n] = numPrimitives;
237 numPrimitives += polygons.numQuads();
238 numPrimitives += polygons.numTriangles();
241 primitives.resize(numPrimitives);
242 internal::PrimCpy primCpy(polygonPoolList, indexlist, primitives);
243 primCpy.runParallel();
246 QuadAndTriangleDataAdapter<Vec3s, Vec4I> mesh(points, primitives);
249 return meshToVolume<GridType>(*interrupter, mesh, *transform, exBandWidth, inBandWidth,
253 return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
260 template<
class Gr
idType,
typename InterruptT>
261 inline typename std::enable_if<
262 !std::is_floating_point<typename GridType::ValueType>::value,
typename GridType::Ptr>::type
263 doLevelSetRebuild(
const GridType&,
typename GridType::ValueType ,
264 typename GridType::ValueType ,
typename GridType::ValueType ,
265 const math::Transform*, InterruptT*)
268 "level set rebuild is supported only for scalar, floating-point grids");
278 template<
class Gr
idType,
typename InterruptT>
279 inline typename GridType::Ptr
283 using ValueT =
typename GridType::ValueType;
285 isovalue(zeroVal<ValueT>() + ValueT(iso)),
286 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
287 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
289 return doLevelSetRebuild(grid, isovalue, exBandWidth, inBandWidth, xform, interrupter);
293 template<
class Gr
idType>
294 inline typename GridType::Ptr
298 using ValueT =
typename GridType::ValueType;
300 isovalue(zeroVal<ValueT>() + ValueT(iso)),
301 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
302 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
304 return doLevelSetRebuild<GridType, util::NullInterrupter>(
305 grid, isovalue, exBandWidth, inBandWidth, xform,
nullptr);
309 template<
class Gr
idType>
310 inline typename GridType::Ptr
313 using ValueT =
typename GridType::ValueType;
315 isovalue(zeroVal<ValueT>() + ValueT(iso)),
316 halfWidth(zeroVal<ValueT>() + ValueT(halfVal));
318 return doLevelSetRebuild<GridType, util::NullInterrupter>(
319 grid, isovalue, halfWidth, halfWidth, xform,
nullptr);
327 #endif // OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED OPENVDB_API const Index32 INVALID_IDX
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:460
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
Extract polygonal surfaces from scalar volumes.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
Convert polygonal meshes that consist of quads and/or triangles into signed or unsigned distance fiel...
Definition: Exceptions.h:13
Vec3< float > Vec3s
Definition: Vec3.h:661
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154