4 #ifndef OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED 5 #define OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED 16 #include <tbb/blocked_range.h> 17 #include <tbb/parallel_for.h> 18 #include <type_traits> 42 template<
class Gr
idType>
43 typename GridType::Ptr
62 template<
class Gr
idType>
63 typename GridType::Ptr
65 const math::Transform* xform =
nullptr);
83 template<
class Gr
idType,
typename InterruptT>
84 typename GridType::Ptr
86 const math::Transform* xform =
nullptr, InterruptT* interrupter =
nullptr);
97 class PointListTransform
100 PointListTransform(
const PointList& pointsIn, std::vector<Vec3s>& pointsOut,
101 const math::Transform& xform)
102 : mPointsIn(pointsIn)
103 , mPointsOut(&pointsOut)
110 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPointsOut->size()), *
this);
115 (*this)(tbb::blocked_range<size_t>(0, mPointsOut->size()));
118 inline void operator()(
const tbb::blocked_range<size_t>& range)
const 120 for (
size_t n = range.begin(); n < range.end(); ++n) {
121 (*mPointsOut)[n] =
Vec3s(mXform.worldToIndex(mPointsIn[n]));
127 std::vector<Vec3s> *
const mPointsOut;
128 const math::Transform& mXform;
135 PrimCpy(
const PolygonPoolList& primsIn,
const std::vector<size_t>& indexList,
136 std::vector<Vec4I>& primsOut)
138 , mIndexList(indexList)
139 , mPrimsOut(&primsOut)
145 tbb::parallel_for(tbb::blocked_range<size_t>(0, mIndexList.size()), *
this);
150 (*this)(tbb::blocked_range<size_t>(0, mIndexList.size()));
153 inline void operator()(
const tbb::blocked_range<size_t>& range)
const 157 std::vector<Vec4I>& primsOut = *mPrimsOut;
159 for (
size_t n = range.begin(); n < range.end(); ++n) {
160 size_t index = mIndexList[n];
161 PolygonPool& polygons = mPrimsIn[n];
164 for (
size_t i = 0, I = polygons.numQuads(); i < I; ++i) {
165 primsOut[index++] = polygons.quad(i);
167 polygons.clearQuads();
170 for (
size_t i = 0, I = polygons.numTriangles(); i < I; ++i) {
172 quad[0] = triangle[0];
173 quad[1] = triangle[1];
174 quad[2] = triangle[2];
175 primsOut[index++] = quad;
178 polygons.clearTriangles();
184 const std::vector<size_t>& mIndexList;
185 std::vector<Vec4I> *
const mPrimsOut;
204 template<
class Gr
idType,
typename InterruptT>
205 inline typename std::enable_if<
207 doLevelSetRebuild(
const GridType& grid,
typename GridType::ValueType iso,
208 typename GridType::ValueType exWidth,
typename GridType::ValueType inWidth,
209 const math::Transform* xform, InterruptT* interrupter)
212 isovalue = float(iso),
213 exBandWidth = float(exWidth),
214 inBandWidth = float(inWidth);
216 tools::VolumeToMesh mesher(isovalue);
219 math::Transform::Ptr transform = (xform !=
nullptr) ? xform->copy() : grid.transform().copy();
221 std::vector<Vec3s> points(mesher.pointListSize());
224 internal::PointListTransform ptnXForm(mesher.pointList(), points, *transform);
225 ptnXForm.runParallel();
226 mesher.pointList().reset(
nullptr);
229 std::vector<Vec4I> primitives;
234 size_t numPrimitives = 0;
235 std::vector<size_t> indexlist(mesher.polygonPoolListSize());
237 for (
size_t n = 0, N = mesher.polygonPoolListSize(); n < N; ++n) {
238 const openvdb::tools::PolygonPool& polygons = polygonPoolList[n];
239 indexlist[n] = numPrimitives;
240 numPrimitives += polygons.numQuads();
241 numPrimitives += polygons.numTriangles();
244 primitives.resize(numPrimitives);
245 internal::PrimCpy primCpy(polygonPoolList, indexlist, primitives);
246 primCpy.runParallel();
249 QuadAndTriangleDataAdapter<Vec3s, Vec4I> mesh(points, primitives);
252 return meshToVolume<GridType>(*interrupter, mesh, *transform, exBandWidth, inBandWidth,
256 return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
263 template<
class Gr
idType,
typename InterruptT>
264 inline typename std::enable_if<
265 !std::is_floating_point<typename GridType::ValueType>::value,
typename GridType::Ptr>::type
266 doLevelSetRebuild(
const GridType&,
typename GridType::ValueType ,
267 typename GridType::ValueType ,
typename GridType::ValueType ,
268 const math::Transform*, InterruptT*)
271 "level set rebuild is supported only for scalar, floating-point grids");
281 template<
class Gr
idType,
typename InterruptT>
282 typename GridType::Ptr
286 using ValueT =
typename GridType::ValueType;
288 isovalue(zeroVal<ValueT>() + ValueT(iso)),
289 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
290 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
292 return doLevelSetRebuild(grid, isovalue, exBandWidth, inBandWidth, xform, interrupter);
296 template<
class Gr
idType>
297 typename GridType::Ptr
301 using ValueT =
typename GridType::ValueType;
303 isovalue(zeroVal<ValueT>() + ValueT(iso)),
304 exBandWidth(zeroVal<ValueT>() + ValueT(exWidth)),
305 inBandWidth(zeroVal<ValueT>() + ValueT(inWidth));
307 return doLevelSetRebuild<GridType, util::NullInterrupter>(
308 grid, isovalue, exBandWidth, inBandWidth, xform,
nullptr);
312 template<
class Gr
idType>
313 typename GridType::Ptr
316 using ValueT =
typename GridType::ValueType;
318 isovalue(zeroVal<ValueT>() + ValueT(iso)),
319 halfWidth(zeroVal<ValueT>() + ValueT(halfVal));
321 return doLevelSetRebuild<GridType, util::NullInterrupter>(
322 grid, isovalue, halfWidth, halfWidth, xform,
nullptr);
331 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION 333 #ifdef OPENVDB_INSTANTIATE_LEVELSETREBUILD 337 #define _FUNCTION(TreeT) \ 338 Grid<TreeT>::Ptr levelSetRebuild(const Grid<TreeT>&, float, float, const math::Transform*) 342 #define _FUNCTION(TreeT) \ 343 Grid<TreeT>::Ptr levelSetRebuild(const Grid<TreeT>&, float, float, float, const math::Transform*) 347 #define _FUNCTION(TreeT) \ 348 Grid<TreeT>::Ptr levelSetRebuild(const Grid<TreeT>&, float, float, float, const math::Transform*, \ 349 util::NullInterrupter*) 353 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION 360 #endif // OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED #define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
OPENVDB_API const Index32 INVALID_IDX
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Extract polygonal surfaces from scalar volumes.
Convert polygonal meshes that consist of quads and/or triangles into signed or unsigned distance fiel...
Definition: Exceptions.h:13
ValueT value
Definition: GridBuilder.h:1287
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:216
Vec3< float > Vec3s
Definition: Vec3.h:667
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition: version.h.in:147
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:422
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202