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);
279 template<
class Gr
idType,
typename InterruptT>
280 inline typename boost::disable_if<boost::is_floating_point<typename GridType::ValueType>,
281 typename GridType::Ptr>::type
283 typename GridType::ValueType ,
typename GridType::ValueType ,
287 "level set rebuild is supported only for scalar, floating-point grids");
294 template<
class Gr
idType,
typename InterruptT>
295 inline typename GridType::Ptr
299 typedef typename GridType::ValueType ValueT;
301 isovalue(zeroVal<ValueT>() + iso),
302 exBandWidth(zeroVal<ValueT>() + exWidth),
303 inBandWidth(zeroVal<ValueT>() + inWidth);
305 return doLevelSetRebuild(grid, isovalue, exBandWidth, inBandWidth, xform, interrupter);
309 template<
class Gr
idType>
310 inline typename GridType::Ptr
314 typedef typename GridType::ValueType ValueT;
316 isovalue(zeroVal<ValueT>() + iso),
317 exBandWidth(zeroVal<ValueT>() + exWidth),
318 inBandWidth(zeroVal<ValueT>() + inWidth);
320 return doLevelSetRebuild<GridType, util::NullInterrupter>(
321 grid, isovalue, exBandWidth, inBandWidth, xform, NULL);
325 template<
class Gr
idType>
326 inline typename GridType::Ptr
329 typedef typename GridType::ValueType ValueT;
331 isovalue(zeroVal<ValueT>() + iso),
332 halfWidth(zeroVal<ValueT>() + half);
334 return doLevelSetRebuild<GridType, util::NullInterrupter>(
335 grid, isovalue, halfWidth, halfWidth, xform, NULL);
343 #endif // OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED