31 #ifndef OPENVDB_TOOLS_LEVEL_SET_REBUILD_HAS_BEEN_INCLUDED
32 #define OPENVDB_TOOLS_LEVEL_SET_REBUILD_HAS_BEEN_INCLUDED
34 #include <openvdb/Grid.h>
35 #include <openvdb/math/Math.h>
36 #include <openvdb/math/Transform.h>
37 #include <openvdb/tools/VolumeToMesh.h>
38 #include <openvdb/tools/MeshToVolume.h>
39 #include <openvdb/util/NullInterrupter.h>
40 #include <openvdb/util/Util.h>
42 #include <tbb/blocked_range.h>
43 #include <tbb/parallel_reduce.h>
60 template<
class Gr
idType>
61 inline typename GridType::Ptr
62 levelSetRebuild(
const GridType& grid,
float isovalue,
float halfWidth = 3.0f,
63 const math::Transform* xform = NULL);
75 template<
class Gr
idType>
76 inline typename GridType::Ptr
77 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
78 const math::Transform* xform = NULL);
91 template<
class Gr
idType,
typename InterruptT>
92 inline typename GridType::Ptr
93 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
94 const math::Transform* xform = NULL, InterruptT* interrupter = NULL);
111 : mPointsIn(pointsIn)
112 , mPointsOut(&pointsOut)
119 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPointsOut->size()), *
this);
124 (*this)(tbb::blocked_range<size_t>(0, mPointsOut->size()));
127 inline void operator()(
const tbb::blocked_range<size_t>& range)
const
129 for (
size_t n = range.begin(); n < range.end(); ++n) {
130 (*mPointsOut)[n] = mXform.worldToIndex(mPointsIn[n]);
136 std::vector<Vec3s> *
const mPointsOut;
144 std::vector<Vec4I>& primsOut)
146 , mIndexList(indexList)
147 , mPrimsOut(&primsOut)
153 tbb::parallel_for(tbb::blocked_range<size_t>(0, mIndexList.size()), *
this);
158 (*this)(tbb::blocked_range<size_t>(0, mIndexList.size()));
161 inline void operator()(
const tbb::blocked_range<size_t>& range)
const
165 std::vector<Vec4I>& primsOut = *mPrimsOut;
167 for (
size_t n = range.begin(); n < range.end(); ++n) {
168 size_t index = mIndexList[n];
172 for (
size_t i = 0, I = polygons.
numQuads(); i < I; ++i) {
173 primsOut[index++] = polygons.
quad(i);
178 for (
size_t i = 0, I = polygons.
numTriangles(); i < I; ++i) {
180 quad[0] = triangle[0];
181 quad[1] = triangle[1];
182 quad[2] = triangle[2];
183 primsOut[index++] = quad;
192 const std::vector<size_t>& mIndexList;
193 std::vector<Vec4I> *
const mPrimsOut;
202 template<
class Gr
idType,
typename InterruptT>
203 inline typename GridType::Ptr
204 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
220 std::vector<Vec4I> primitives;
225 size_t numPrimitives = 0;
229 const openvdb::tools::PolygonPool& polygons = polygonPoolList[n];
230 indexlist[n] = numPrimitives;
231 numPrimitives += polygons.numQuads();
232 numPrimitives += polygons.numTriangles();
235 primitives.resize(numPrimitives);
246 template<
class Gr
idType>
247 inline typename GridType::Ptr
248 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
251 return levelSetRebuild<GridType, util::NullInterrupter>(
252 grid, isovalue, exBandWidth, inBandWidth, xform, NULL);
256 template<
class Gr
idType>
257 inline typename GridType::Ptr
261 return levelSetRebuild<GridType, util::NullInterrupter>(
262 grid, isovalue, halfWidth, halfWidth, xform, NULL);
270 #endif // OPENVDB_TOOLS_LEVEL_SET_REBUILD_HAS_BEEN_INCLUDED