22 #ifndef OPENVDB_TOOLS_POINT_SCATTER_HAS_BEEN_INCLUDED
23 #define OPENVDB_TOOLS_POINT_SCATTER_HAS_BEEN_INCLUDED
29 #include <tbb/parallel_sort.h>
30 #include <tbb/parallel_for.h>
41 template<
typename PointAccessorType,
42 typename RandomGenerator,
43 typename InterruptType = util::NullInterrupter>
84 template<
typename PointAccessorType,
85 typename RandomGenerator,
96 RandomGenerator& randGen,
100 , mTargetPointCount(pointCount)
101 , mPointsPerVolume(0.0
f)
105 float pointsPerVolume,
106 RandomGenerator& randGen,
110 , mTargetPointCount(0)
111 , mPointsPerVolume(pointsPerVolume)
116 template<
typename Gr
idT>
122 const auto voxelVolume = grid.transform().voxelVolume();
123 if (mPointsPerVolume > 0) {
124 BaseT::start(
"Uniform scattering with fixed point density");
126 }
else if (mTargetPointCount > 0) {
127 BaseT::start(
"Uniform scattering with fixed point count");
133 std::unique_ptr<Index64[]> idList{
new Index64[mTargetPointCount]};
135 for (
Index64 i=0; i<mTargetPointCount; ++i) idList[i] = rand();
136 tbb::parallel_sort(idList.get(), idList.get() + mTargetPointCount);
140 typename GridT::ValueOnCIter valueIter = grid.cbeginValueOn();
142 for (
Index64 i=0,
n=valueIter.getVoxelCount() ; i != mTargetPointCount; ++i) {
144 const Index64 voxelId = idList[i];
145 while (
n <= voxelId ) {
147 n += valueIter.getVoxelCount();
149 if (valueIter.isVoxelValue()) {
152 valueIter.getBoundingBox(bbox);
167 <<
" active voxels in \"" << name <<
"\" corresponding to "
168 << mPointsPerVolume <<
" points per volume." << std::endl;
179 float mPointsPerVolume;
185 template<
typename PointAccessorType,
186 typename RandomGenerator,
196 float pointsPerVoxel,
197 RandomGenerator& randGen,
201 , mPointsPerVoxel(pointsPerVoxel)
206 template<
typename Gr
idT>
209 using ValueIter =
typename GridT::ValueOnCIter;
210 if (mPointsPerVoxel < 1.0e-6)
return false;
213 BaseT::start(
"Dense uniform scattering with fixed point count");
218 const double delta = mPointsPerVoxel -
float(ppv);
221 for (ValueIter iter = grid.cbeginValueOn(); iter; ++iter) {
223 if (iter.isVoxelValue()) {
228 iter.getBoundingBox(bbox);
229 const Coord
size(bbox.extents());
231 const double d = mPointsPerVoxel *
float(iter.getVoxelCount());
247 <<
" active voxels in \"" << name <<
"\" corresponding to "
248 << mPointsPerVoxel <<
" points per voxel." << std::endl;
256 float mPointsPerVoxel;
267 template<
typename PointAccessorType,
268 typename RandomGenerator,
278 float pointsPerVolume,
279 RandomGenerator& randGen,
283 , mPointsPerVolume(pointsPerVolume)
289 template<
typename Gr
idT>
292 if (mPointsPerVolume <= 0.0
f)
return false;
295 BaseT::start(
"Non-uniform scattering with local point density");
296 const Vec3d dim = grid.voxelSize();
297 const double volumePerVoxel = dim[0]*dim[1]*dim[2],
298 pointsPerVoxel = mPointsPerVolume * volumePerVoxel;
301 for (
typename GridT::ValueOnCIter iter = grid.cbeginValueOn(); iter; ++iter) {
303 const double d = double(*iter) * pointsPerVoxel * double(iter.getVoxelCount());
304 const int n =
int(d);
305 if (iter.isVoxelValue()) {
310 iter.getBoundingBox(bbox);
311 const Coord
size(bbox.extents());
326 <<
" active voxels in \"" << name <<
"\"." << std::endl;
334 float mPointsPerVolume;
339 template<
typename PointAccessorType,
340 typename RandomGenerator,
341 typename InterruptType>
342 class BasePointScatter
361 RandomGenerator& randGen,
396 template <
typename Gr
idT>
402 mPoints.add(grid.indexToWorld(pos));
406 template <
typename Gr
idT>
410 dmin[1] + size[1]*this->
getRand(),
411 dmin[2] + size[2]*this->
getRand());
412 mPoints.add(grid.indexToWorld(pos));
421 #endif // OPENVDB_TOOLS_POINT_SCATTER_HAS_BEEN_INCLUDED
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
__hostdev__ uint64_t pointCount() const
GLdouble GLdouble GLint GLint const GLdouble * points
GLsizei const GLchar *const * string
#define OPENVDB_USE_VERSION_NAMESPACE
Base class for interrupters.
Simple random integer generator.
IMATH_NAMESPACE::V2f float
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
GLuint const GLchar * name
bool isApproxZero(const Type &x)
Return true if x is equal to zero to within the default floating-point comparison tolerance...
int Floor(float x)
Return the floor of x.
bool wasInterrupted(T *i, int percent=-1)
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Type Clamp01(Type x)
Return x clamped to [0, 1].