31 #ifndef OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED 32 #define OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED 34 #include <openvdb/Grid.h> 35 #include <openvdb/Exceptions.h> 36 #include <openvdb/math/Math.h> 37 #include <openvdb/math/Transform.h> 38 #include <openvdb/tools/VolumeToMesh.h> 39 #include <openvdb/tools/MeshToVolume.h> 40 #include <openvdb/util/NullInterrupter.h> 41 #include <openvdb/util/Util.h> 42 #include <tbb/blocked_range.h> 43 #include <tbb/parallel_for.h> 44 #include <type_traits> 68 template<
class Gr
idType>
69 inline typename GridType::Ptr
88 template<
class Gr
idType>
89 inline typename GridType::Ptr
90 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
91 const math::Transform* xform =
nullptr);
109 template<
class Gr
idType,
typename InterruptT>
110 inline typename GridType::Ptr
111 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
112 const math::Transform* xform =
nullptr, InterruptT* interrupter =
nullptr);
127 : mPointsIn(pointsIn)
128 , mPointsOut(&pointsOut)
135 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPointsOut->size()), *
this);
140 (*this)(tbb::blocked_range<size_t>(0, mPointsOut->size()));
143 inline void operator()(
const tbb::blocked_range<size_t>& range)
const 145 for (
size_t n = range.begin(); n < range.end(); ++n) {
146 (*mPointsOut)[n] =
Vec3s(mXform.worldToIndex(mPointsIn[n]));
152 std::vector<Vec3s> *
const mPointsOut;
161 std::vector<Vec4I>& primsOut)
163 , mIndexList(indexList)
164 , mPrimsOut(&primsOut)
170 tbb::parallel_for(tbb::blocked_range<size_t>(0, mIndexList.size()), *
this);
175 (*this)(tbb::blocked_range<size_t>(0, mIndexList.size()));
178 inline void operator()(
const tbb::blocked_range<size_t>& range)
const 182 std::vector<Vec4I>& primsOut = *mPrimsOut;
184 for (
size_t n = range.begin(); n < range.end(); ++n) {
185 size_t index = mIndexList[n];
189 for (
size_t i = 0, I = polygons.
numQuads(); i < I; ++i) {
190 primsOut[index++] = polygons.
quad(i);
195 for (
size_t i = 0, I = polygons.
numTriangles(); i < I; ++i) {
197 quad[0] = triangle[0];
198 quad[1] = triangle[1];
199 quad[2] = triangle[2];
200 primsOut[index++] = quad;
209 const std::vector<size_t>& mIndexList;
210 std::vector<Vec4I> *
const mPrimsOut;
228 template<
class Gr
idType,
typename InterruptT>
229 inline typename std::enable_if<
230 std::is_floating_point<typename GridType::ValueType>::value,
typename GridType::Ptr>::type
231 doLevelSetRebuild(
const GridType& grid,
typename GridType::ValueType iso,
232 typename GridType::ValueType exWidth,
typename GridType::ValueType inWidth,
236 isovalue = float(iso),
237 exBandWidth = float(exWidth),
238 inBandWidth = float(inWidth);
253 std::vector<Vec4I> primitives;
258 size_t numPrimitives = 0;
262 const openvdb::tools::PolygonPool& polygons = polygonPoolList[n];
263 indexlist[n] = numPrimitives;
264 numPrimitives += polygons.numQuads();
265 numPrimitives += polygons.numTriangles();
268 primitives.resize(numPrimitives);
276 return meshToVolume<GridType>(*interrupter, mesh, *transform, exBandWidth, inBandWidth,
280 return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
287 template<
class Gr
idType,
typename InterruptT>
288 inline typename std::enable_if<
289 !std::is_floating_point<typename GridType::ValueType>::value,
typename GridType::Ptr>::type
290 doLevelSetRebuild(
const GridType&,
typename GridType::ValueType ,
291 typename GridType::ValueType ,
typename GridType::ValueType ,
295 "level set rebuild is supported only for scalar, floating-point grids");
305 template<
class Gr
idType,
typename InterruptT>
306 inline typename GridType::Ptr
310 using ValueT =
typename GridType::ValueType;
312 isovalue(zeroVal<ValueT>() + ValueT(iso)),
313 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
314 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
316 return doLevelSetRebuild(grid, isovalue, exBandWidth, inBandWidth, xform, interrupter);
320 template<
class Gr
idType>
321 inline typename GridType::Ptr
325 using ValueT =
typename GridType::ValueType;
327 isovalue(zeroVal<ValueT>() + ValueT(iso)),
328 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
329 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
331 return doLevelSetRebuild<GridType, util::NullInterrupter>(
332 grid, isovalue, exBandWidth, inBandWidth, xform,
nullptr);
336 template<
class Gr
idType>
337 inline typename GridType::Ptr
340 using ValueT =
typename GridType::ValueType;
342 isovalue(zeroVal<ValueT>() + ValueT(iso)),
343 halfWidth(zeroVal<ValueT>() + ValueT(halfVal));
345 return doLevelSetRebuild<GridType, util::NullInterrupter>(
346 grid, isovalue, halfWidth, halfWidth, xform,
nullptr);
354 #endif // OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
Definition: Exceptions.h:91
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:283
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: Exceptions.h:40
OPENVDB_API const Index32 INVALID_IDX
Vec3< float > Vec3s
Definition: Vec3.h:678
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188