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] = 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);
280 template<
class Gr
idType,
typename InterruptT>
281 inline typename boost::disable_if<boost::is_floating_point<typename GridType::ValueType>,
282 typename GridType::Ptr>::type
284 typename GridType::ValueType ,
typename GridType::ValueType ,
288 "level set rebuild is supported only for scalar, floating-point grids");
295 template<
class Gr
idType,
typename InterruptT>
296 inline typename GridType::Ptr
300 typedef typename GridType::ValueType ValueT;
302 isovalue(zeroVal<ValueT>() + iso),
303 exBandWidth(zeroVal<ValueT>() + exWidth),
304 inBandWidth(zeroVal<ValueT>() + inWidth);
306 return doLevelSetRebuild(grid, isovalue, exBandWidth, inBandWidth, xform, interrupter);
310 template<
class Gr
idType>
311 inline typename GridType::Ptr
315 typedef typename GridType::ValueType ValueT;
317 isovalue(zeroVal<ValueT>() + iso),
318 exBandWidth(zeroVal<ValueT>() + exWidth),
319 inBandWidth(zeroVal<ValueT>() + inWidth);
321 return doLevelSetRebuild<GridType, util::NullInterrupter>(
322 grid, isovalue, exBandWidth, inBandWidth, xform, NULL);
326 template<
class Gr
idType>
327 inline typename GridType::Ptr
330 typedef typename GridType::ValueType ValueT;
332 isovalue(zeroVal<ValueT>() + iso),
333 halfWidth(zeroVal<ValueT>() + halfVal);
335 return doLevelSetRebuild<GridType, util::NullInterrupter>(
336 grid, isovalue, halfWidth, halfWidth, xform, NULL);
344 #endif // OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
OPENVDB_API const Index32 INVALID_IDX
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:176
Definition: Exceptions.h:87
#define OPENVDB_VERSION_NAME
Definition: version.h:45
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67