4#ifndef OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
5#define OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
18#include <tbb/blocked_range.h>
19#include <tbb/parallel_for.h>
44template<
class Gr
idType>
47 float halfWidth =
float(LEVEL_SET_HALF_WIDTH),
const math::Transform* xform =
nullptr);
64template<
class Gr
idType>
66levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
67 const math::Transform* xform =
nullptr);
85template<
class Gr
idType,
typename InterruptT>
87levelSetRebuild(
const GridType& grid,
float isovalue,
float exBandWidth,
float inBandWidth,
88 const math::Transform* xform =
nullptr, InterruptT* interrupter =
nullptr);
99class PointListTransform
102 PointListTransform(
const PointList& pointsIn, std::vector<Vec3s>& pointsOut,
103 const math::Transform& xform)
104 : mPointsIn(pointsIn)
105 , mPointsOut(&pointsOut)
112 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPointsOut->size()), *
this);
117 (*this)(tbb::blocked_range<size_t>(0, mPointsOut->size()));
120 inline void operator()(
const tbb::blocked_range<size_t>& range)
const
122 for (
size_t n = range.begin(); n < range.end(); ++n) {
123 (*mPointsOut)[n] =
Vec3s(mXform.worldToIndex(mPointsIn[n]));
129 std::vector<Vec3s> *
const mPointsOut;
130 const math::Transform& mXform;
137 PrimCpy(
const PolygonPoolList& primsIn,
const std::vector<size_t>& indexList,
138 std::vector<Vec4I>& primsOut)
140 , mIndexList(indexList)
141 , mPrimsOut(&primsOut)
147 tbb::parallel_for(tbb::blocked_range<size_t>(0, mIndexList.size()), *
this);
152 (*this)(tbb::blocked_range<size_t>(0, mIndexList.size()));
155 inline void operator()(
const tbb::blocked_range<size_t>& range)
const
158 quad[3] = openvdb::util::INVALID_IDX;
159 std::vector<Vec4I>& primsOut = *mPrimsOut;
161 for (
size_t n = range.begin(); n < range.end(); ++n) {
162 size_t index = mIndexList[n];
163 PolygonPool& polygons = mPrimsIn[n];
166 for (
size_t i = 0, I = polygons.numQuads(); i < I; ++i) {
167 primsOut[index++] = polygons.quad(i);
169 polygons.clearQuads();
172 for (
size_t i = 0, I = polygons.numTriangles(); i < I; ++i) {
174 quad[0] = triangle[0];
175 quad[1] = triangle[1];
176 quad[2] = triangle[2];
177 primsOut[index++] = quad;
180 polygons.clearTriangles();
186 const std::vector<size_t>& mIndexList;
187 std::vector<Vec4I> *
const mPrimsOut;
206template<
class Gr
idType,
typename InterruptT>
207inline typename std::enable_if<
208 std::is_floating_point<typename GridType::ValueType>::value,
typename GridType::Ptr>::type
209doLevelSetRebuild(
const GridType& grid,
typename GridType::ValueType iso,
210 typename GridType::ValueType exWidth,
typename GridType::ValueType inWidth,
211 const math::Transform* xform, InterruptT* interrupter)
214 isovalue = float(iso),
215 exBandWidth = float(exWidth),
216 inBandWidth = float(inWidth);
218 tools::VolumeToMesh mesher(isovalue);
221 math::Transform::Ptr transform = (xform !=
nullptr) ? xform->copy() : grid.transform().copy();
223 std::vector<Vec3s> points(mesher.pointListSize());
226 internal::PointListTransform ptnXForm(mesher.pointList(), points, *transform);
227 ptnXForm.runParallel();
228 mesher.pointList().reset(
nullptr);
231 std::vector<Vec4I> primitives;
236 size_t numPrimitives = 0;
237 std::vector<size_t> indexlist(mesher.polygonPoolListSize());
239 for (
size_t n = 0, N = mesher.polygonPoolListSize(); n < N; ++n) {
240 const openvdb::tools::PolygonPool& polygons = polygonPoolList[n];
241 indexlist[n] = numPrimitives;
242 numPrimitives += polygons.numQuads();
243 numPrimitives += polygons.numTriangles();
246 primitives.resize(numPrimitives);
247 internal::PrimCpy primCpy(polygonPoolList, indexlist, primitives);
248 primCpy.runParallel();
251 QuadAndTriangleDataAdapter<Vec3s, Vec4I> mesh(points, primitives);
254 return meshToVolume<GridType>(*interrupter, mesh, *transform, exBandWidth, inBandWidth,
255 DISABLE_RENORMALIZATION,
nullptr);
258 return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
259 DISABLE_RENORMALIZATION,
nullptr);
265template<
class Gr
idType,
typename InterruptT>
266inline typename std::enable_if<
267 !std::is_floating_point<typename GridType::ValueType>::value,
typename GridType::Ptr>::type
268doLevelSetRebuild(
const GridType&,
typename GridType::ValueType ,
269 typename GridType::ValueType ,
typename GridType::ValueType ,
270 const math::Transform*, InterruptT*)
273 "level set rebuild is supported only for scalar, floating-point grids");
283template<
class Gr
idType,
typename InterruptT>
284typename GridType::Ptr
288 using ValueT =
typename GridType::ValueType;
290 isovalue(zeroVal<ValueT>() + ValueT(iso)),
291 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
292 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
294 return doLevelSetRebuild(grid, isovalue, exBandWidth, inBandWidth, xform, interrupter);
298template<
class Gr
idType>
299typename GridType::Ptr
303 using ValueT =
typename GridType::ValueType;
305 isovalue(zeroVal<ValueT>() + ValueT(iso)),
306 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
307 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
309 return doLevelSetRebuild<GridType, util::NullInterrupter>(
310 grid, isovalue, exBandWidth, inBandWidth, xform,
nullptr);
314template<
class Gr
idType>
315typename GridType::Ptr
318 using ValueT =
typename GridType::ValueType;
320 isovalue(zeroVal<ValueT>() + ValueT(iso)),
321 halfWidth(zeroVal<ValueT>() + ValueT(halfVal));
323 return doLevelSetRebuild<GridType, util::NullInterrupter>(
324 grid, isovalue, halfWidth, halfWidth, xform,
nullptr);
333#ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
335#ifdef OPENVDB_INSTANTIATE_LEVELSETREBUILD
339#define _FUNCTION(TreeT) \
340 Grid<TreeT>::Ptr levelSetRebuild(const Grid<TreeT>&, float, float, const math::Transform*)
344#define _FUNCTION(TreeT) \
345 Grid<TreeT>::Ptr levelSetRebuild(const Grid<TreeT>&, float, float, float, const math::Transform*)
349#define _FUNCTION(TreeT) \
350 Grid<TreeT>::Ptr levelSetRebuild(const Grid<TreeT>&, float, float, float, const math::Transform*, \
351 util::NullInterrupter*)
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:663
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:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition: version.h.in:157