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 <boost/type_traits/is_floating_point.hpp>
43 #include <boost/utility/enable_if.hpp>
44 #include <tbb/blocked_range.h>
45 #include <tbb/parallel_for.h>
69 template<
class Gr
idType>
70 inline typename GridType::Ptr
89 template<
class Gr
idType>
90 inline typename GridType::Ptr
91 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
92 const math::Transform* xform = NULL);
110 template<
class Gr
idType,
typename InterruptT>
111 inline typename GridType::Ptr
112 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
113 const math::Transform* xform = NULL, InterruptT* interrupter = NULL);
128 : mPointsIn(pointsIn)
129 , mPointsOut(&pointsOut)
136 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPointsOut->size()), *
this);
141 (*this)(tbb::blocked_range<size_t>(0, mPointsOut->size()));
144 inline void operator()(
const tbb::blocked_range<size_t>& range)
const
146 for (
size_t n = range.begin(); n < range.end(); ++n) {
147 (*mPointsOut)[n] =
Vec3s(mXform.worldToIndex(mPointsIn[n]));
153 std::vector<Vec3s> *
const mPointsOut;
162 std::vector<Vec4I>& primsOut)
164 , mIndexList(indexList)
165 , mPrimsOut(&primsOut)
171 tbb::parallel_for(tbb::blocked_range<size_t>(0, mIndexList.size()), *
this);
176 (*this)(tbb::blocked_range<size_t>(0, mIndexList.size()));
179 inline void operator()(
const tbb::blocked_range<size_t>& range)
const
183 std::vector<Vec4I>& primsOut = *mPrimsOut;
185 for (
size_t n = range.begin(); n < range.end(); ++n) {
186 size_t index = mIndexList[n];
190 for (
size_t i = 0, I = polygons.
numQuads(); i < I; ++i) {
191 primsOut[index++] = polygons.
quad(i);
196 for (
size_t i = 0, I = polygons.
numTriangles(); i < I; ++i) {
198 quad[0] = triangle[0];
199 quad[1] = triangle[1];
200 quad[2] = triangle[2];
201 primsOut[index++] = quad;
210 const std::vector<size_t>& mIndexList;
211 std::vector<Vec4I> *
const mPrimsOut;
226 template<
class Gr
idType,
typename InterruptT>
227 inline typename boost::enable_if<boost::is_floating_point<typename GridType::ValueType>,
228 typename GridType::Ptr>::type
230 typename GridType::ValueType exWidth,
typename GridType::ValueType inWidth,
234 isovalue = float(iso),
235 exBandWidth = float(exWidth),
236 inBandWidth = float(inWidth);
251 std::vector<Vec4I> primitives;
256 size_t numPrimitives = 0;
260 const openvdb::tools::PolygonPool& polygons = polygonPoolList[n];
261 indexlist[n] = numPrimitives;
262 numPrimitives += polygons.numQuads();
263 numPrimitives += polygons.numTriangles();
266 primitives.resize(numPrimitives);
274 return meshToVolume<GridType>(*interrupter, mesh, *transform, exBandWidth, inBandWidth,
278 return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
285 template<
class Gr
idType,
typename InterruptT>
286 inline typename boost::disable_if<boost::is_floating_point<typename GridType::ValueType>,
287 typename GridType::Ptr>::type
289 typename GridType::ValueType ,
typename GridType::ValueType ,
293 "level set rebuild is supported only for scalar, floating-point grids");
300 template<
class Gr
idType,
typename InterruptT>
301 inline typename GridType::Ptr
305 typedef typename GridType::ValueType ValueT;
307 isovalue(zeroVal<ValueT>() + ValueT(iso)),
308 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
309 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
311 return doLevelSetRebuild(grid, isovalue, exBandWidth, inBandWidth, xform, interrupter);
315 template<
class Gr
idType>
316 inline typename GridType::Ptr
320 typedef typename GridType::ValueType ValueT;
322 isovalue(zeroVal<ValueT>() + ValueT(iso)),
323 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
324 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
326 return doLevelSetRebuild<GridType, util::NullInterrupter>(
327 grid, isovalue, exBandWidth, inBandWidth, xform, NULL);
331 template<
class Gr
idType>
332 inline typename GridType::Ptr
335 typedef typename GridType::ValueType ValueT;
337 isovalue(zeroVal<ValueT>() + ValueT(iso)),
338 halfWidth(zeroVal<ValueT>() + ValueT(halfVal));
340 return doLevelSetRebuild<GridType, util::NullInterrupter>(
341 grid, isovalue, halfWidth, halfWidth, xform, NULL);
349 #endif // OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
OPENVDB_API const Index32 INVALID_IDX
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Exceptions.h:39
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Definition: Exceptions.h:87
Vec3< float > Vec3s
Definition: Vec3.h:642
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:212