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> 20 #include <type_traits> 44 template<
class Gr
idType>
45 typename GridType::Ptr
64 template<
class Gr
idType>
65 typename GridType::Ptr
67 const math::Transform* xform =
nullptr);
85 template<
class Gr
idType,
typename InterruptT>
86 typename GridType::Ptr
88 const math::Transform* xform =
nullptr, InterruptT* interrupter =
nullptr);
99 class 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 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;
206 template<
class Gr
idType,
typename InterruptT>
207 inline typename std::enable_if<
209 doLevelSetRebuild(
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,
258 return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
265 template<
class Gr
idType,
typename InterruptT>
266 inline typename std::enable_if<
268 doLevelSetRebuild(
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");
283 template<
class Gr
idType,
typename InterruptT>
284 typename 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);
298 template<
class Gr
idType>
299 typename 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);
314 template<
class Gr
idType>
315 typename 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*) 355 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION 362 #endif // OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED #define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:422
OPENVDB_API const Index32 INVALID_IDX
Extract polygonal surfaces from scalar volumes.
Convert polygonal meshes that consist of quads and/or triangles into signed or unsigned distance fiel...
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition: version.h.in:157
Definition: Exceptions.h:13
Vec3< float > Vec3s
Definition: Vec3.h:663
ValueT value
Definition: GridBuilder.h:1290
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:243
#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