4 #ifndef OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
5 #define OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
15 #include <tbb/blocked_range.h>
16 #include <tbb/parallel_for.h>
17 #include <type_traits>
41 template<
class Gr
idType>
42 inline typename GridType::Ptr
61 template<
class Gr
idType>
62 inline typename GridType::Ptr
63 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
64 const math::Transform* xform =
nullptr);
82 template<
class Gr
idType,
typename InterruptT>
83 inline typename GridType::Ptr
84 levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
85 const math::Transform* xform =
nullptr, InterruptT* interrupter =
nullptr);
96 class PointListTransform
99 PointListTransform(
const PointList& pointsIn, std::vector<Vec3s>& pointsOut,
100 const math::Transform& xform)
101 : mPointsIn(pointsIn)
102 , mPointsOut(&pointsOut)
109 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPointsOut->size()), *
this);
114 (*this)(tbb::blocked_range<size_t>(0, mPointsOut->size()));
117 inline void operator()(
const tbb::blocked_range<size_t>& range)
const
119 for (
size_t n = range.begin(); n < range.end(); ++n) {
120 (*mPointsOut)[n] =
Vec3s(mXform.worldToIndex(mPointsIn[n]));
126 std::vector<Vec3s> *
const mPointsOut;
127 const math::Transform& mXform;
134 PrimCpy(
const PolygonPoolList& primsIn,
const std::vector<size_t>& indexList,
135 std::vector<Vec4I>& primsOut)
137 , mIndexList(indexList)
138 , mPrimsOut(&primsOut)
144 tbb::parallel_for(tbb::blocked_range<size_t>(0, mIndexList.size()), *
this);
149 (*this)(tbb::blocked_range<size_t>(0, mIndexList.size()));
152 inline void operator()(
const tbb::blocked_range<size_t>& range)
const
156 std::vector<Vec4I>& primsOut = *mPrimsOut;
158 for (
size_t n = range.begin(); n < range.end(); ++n) {
159 size_t index = mIndexList[n];
160 PolygonPool& polygons = mPrimsIn[n];
163 for (
size_t i = 0, I = polygons.numQuads(); i < I; ++i) {
164 primsOut[index++] = polygons.quad(i);
166 polygons.clearQuads();
169 for (
size_t i = 0, I = polygons.numTriangles(); i < I; ++i) {
171 quad[0] = triangle[0];
172 quad[1] = triangle[1];
173 quad[2] = triangle[2];
174 primsOut[index++] = quad;
177 polygons.clearTriangles();
183 const std::vector<size_t>& mIndexList;
184 std::vector<Vec4I> *
const mPrimsOut;
203 template<
class Gr
idType,
typename InterruptT>
204 inline typename std::enable_if<
205 std::is_floating_point<typename GridType::ValueType>::value,
typename GridType::Ptr>::type
206 doLevelSetRebuild(
const GridType& grid,
typename GridType::ValueType iso,
207 typename GridType::ValueType exWidth,
typename GridType::ValueType inWidth,
208 const math::Transform* xform, InterruptT* interrupter)
211 isovalue = float(iso),
212 exBandWidth = float(exWidth),
213 inBandWidth = float(inWidth);
215 tools::VolumeToMesh mesher(isovalue);
218 math::Transform::Ptr transform = (xform !=
nullptr) ? xform->copy() : grid.transform().copy();
220 std::vector<Vec3s> points(mesher.pointListSize());
223 internal::PointListTransform ptnXForm(mesher.pointList(), points, *transform);
224 ptnXForm.runParallel();
225 mesher.pointList().reset(
nullptr);
228 std::vector<Vec4I> primitives;
233 size_t numPrimitives = 0;
234 std::vector<size_t> indexlist(mesher.polygonPoolListSize());
236 for (
size_t n = 0, N = mesher.polygonPoolListSize(); n < N; ++n) {
237 const openvdb::tools::PolygonPool& polygons = polygonPoolList[n];
238 indexlist[n] = numPrimitives;
239 numPrimitives += polygons.numQuads();
240 numPrimitives += polygons.numTriangles();
243 primitives.resize(numPrimitives);
244 internal::PrimCpy primCpy(polygonPoolList, indexlist, primitives);
245 primCpy.runParallel();
248 QuadAndTriangleDataAdapter<Vec3s, Vec4I> mesh(points, primitives);
251 return meshToVolume<GridType>(*interrupter, mesh, *transform, exBandWidth, inBandWidth,
255 return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
262 template<
class Gr
idType,
typename InterruptT>
263 inline typename std::enable_if<
264 !std::is_floating_point<typename GridType::ValueType>::value,
typename GridType::Ptr>::type
265 doLevelSetRebuild(
const GridType&,
typename GridType::ValueType ,
266 typename GridType::ValueType ,
typename GridType::ValueType ,
267 const math::Transform*, InterruptT*)
270 "level set rebuild is supported only for scalar, floating-point grids");
280 template<
class Gr
idType,
typename InterruptT>
281 inline typename GridType::Ptr
285 using ValueT =
typename GridType::ValueType;
287 isovalue(zeroVal<ValueT>() + ValueT(iso)),
288 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
289 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
291 return doLevelSetRebuild(grid, isovalue, exBandWidth, inBandWidth, xform, interrupter);
295 template<
class Gr
idType>
296 inline typename GridType::Ptr
300 using ValueT =
typename GridType::ValueType;
302 isovalue(zeroVal<ValueT>() + ValueT(iso)),
303 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
304 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
306 return doLevelSetRebuild<GridType, util::NullInterrupter>(
307 grid, isovalue, exBandWidth, inBandWidth, xform,
nullptr);
311 template<
class Gr
idType>
312 inline typename GridType::Ptr
315 using ValueT =
typename GridType::ValueType;
317 isovalue(zeroVal<ValueT>() + ValueT(iso)),
318 halfWidth(zeroVal<ValueT>() + ValueT(halfVal));
320 return doLevelSetRebuild<GridType, util::NullInterrupter>(
321 grid, isovalue, halfWidth, halfWidth, xform,
nullptr);
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Convert polygonal meshes that consist of quads and/or triangles into signed or unsigned distance fiel...
Extract polygonal surfaces from scalar volumes.
Vec3< float > Vec3s
Definition: Vec3.h:667
OPENVDB_API const Index32 INVALID_IDX
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:343
Definition: Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:180