OpenVDB: openvdb/points/PointScatter.h Source File

OpenVDB 11.0.0

Loading...
Searching...
No Matches
PointScatter.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3
4/// @author Nick Avramoussis
5///
6/// @file points/PointScatter.h
7///
8/// @brief Various point scattering methods for generating VDB Points.
9///
10/// All random number calls are made to the same generator to produce
11/// temporarily consistent results in relation to the provided seed. This
12/// comes with some multi-threaded performance trade-offs.
13
14#ifndef OPENVDB_POINTS_POINT_SCATTER_HAS_BEEN_INCLUDED
15#define OPENVDB_POINTS_POINT_SCATTER_HAS_BEEN_INCLUDED
16
17#include <type_traits>
18#include <algorithm>
19#include <thread>
20#include <random>
21
22#include <openvdb/openvdb.h>
23#include <openvdb/Types.h>
24#include <openvdb/tree/LeafManager.h>
25#include <openvdb/tools/Prune.h>
26#include <openvdb/util/NullInterrupter.h>
27
28#include "AttributeArray.h"
29#include "PointCount.h"
30#include "PointDataGrid.h"
31
32#include <tbb/parallel_sort.h>
33#include <tbb/parallel_for.h>
34
35namespace openvdb {
36 OPENVDB_USE_VERSION_NAMESPACE
37namespace OPENVDB_VERSION_NAME {
38namespace points {
39
40/// @brief The free functions depend on the following class:
41///
42/// The @c InterrupterT template argument below refers to any class
43/// with the following interface:
44/// @code
45/// class Interrupter {
46/// ...
47/// public:
48/// void start(const char* name = nullptr) // called when computations begin
49/// void end() // called when computations end
50/// bool wasInterrupted(int percent=-1) // return true to break computation
51///};
52/// @endcode
53///
54/// @note If no template argument is provided for this InterrupterT
55/// the util::NullInterrupter is used which implies that all
56/// interrupter calls are no-ops (i.e. incurs no computational overhead).
57
58
59/// @brief Uniformly scatter a total amount of points in active regions
60///
61/// @param grid A source grid. The resulting PointDataGrid will copy this grids
62/// transform and scatter in its active voxelized topology.
63/// @param count The total number of points to scatter
64/// @param seed A seed for the RandGenT
65/// @param spread The spread of points as a scale from each voxels center. A value of
66/// 1.0f indicates points can be placed anywhere within the voxel, where
67/// as a value of 0.0f will force all points to be created exactly at the
68/// centers of each voxel.
69/// @param interrupter An optional interrupter
70/// @note returns the scattered PointDataGrid
71template<
72 typename GridT,
73 typename RandGenT = std::mt19937,
74 typename PositionArrayT = TypedAttributeArray<Vec3f, NullCodec>,
75 typename PointDataGridT = Grid<
76 typename points::TreeConverter<typename GridT::TreeType>::Type>,
77 typename InterrupterT = util::NullInterrupter>
78inline typename PointDataGridT::Ptr
79 uniformPointScatter(const GridT& grid,
80 const Index64 count,
81 const unsigned int seed = 0,
82 const float spread = 1.0f,
83 InterrupterT* interrupter = nullptr);
84
85/// @brief Uniformly scatter a fixed number of points per active voxel. If the pointsPerVoxel
86/// value provided is a fractional value, each voxel calculates a delta value of
87/// how likely it is to contain an extra point.
88///
89/// @param grid A source grid. The resulting PointDataGrid will copy this grids
90/// transform and scatter in its active voxelized topology.
91/// @param pointsPerVoxel The number of points to scatter per voxel
92/// @param seed A seed for the RandGenT
93/// @param spread The spread of points as a scale from each voxels center. A value of
94/// 1.0f indicates points can be placed anywhere within the voxel, where
95/// as a value of 0.0f will force all points to be created exactly at the
96/// centers of each voxel.
97/// @param interrupter An optional interrupter
98/// @note returns the scattered PointDataGrid
99
100template<
101 typename GridT,
102 typename RandGenT = std::mt19937,
103 typename PositionArrayT = TypedAttributeArray<Vec3f, NullCodec>,
104 typename PointDataGridT = Grid<
105 typename points::TreeConverter<typename GridT::TreeType>::Type>,
106 typename InterrupterT = util::NullInterrupter>
107inline typename PointDataGridT::Ptr
108 denseUniformPointScatter(const GridT& grid,
109 const float pointsPerVoxel,
110 const unsigned int seed = 0,
111 const float spread = 1.0f,
112 InterrupterT* interrupter = nullptr);
113
114/// @brief Non uniformly scatter points per active voxel. The pointsPerVoxel value is used
115/// to weight each grids cell value to compute a fixed number of points for every
116/// active voxel. If the computed result is a fractional value, each voxel calculates
117/// a delta value of how likely it is to contain an extra point.
118///
119/// @param grid A source grid. The resulting PointDataGrid will copy this grids
120/// transform, voxelized topology and use its values to compute a
121/// target points per voxel. The grids ValueType must be convertible
122/// to a scalar value. Only active and larger than zero values will
123/// contain points.
124/// @param pointsPerVoxel The number of points to scatter per voxel
125/// @param seed A seed for the RandGenT
126/// @param spread The spread of points as a scale from each voxels center. A value of
127/// 1.0f indicates points can be placed anywhere within the voxel, where
128/// as a value of 0.0f will force all points to be created exactly at the
129/// centers of each voxel.
130/// @param interrupter An optional interrupter
131/// @note returns the scattered PointDataGrid
132template<
133 typename GridT,
134 typename RandGenT = std::mt19937,
135 typename PositionArrayT = TypedAttributeArray<Vec3f, NullCodec>,
136 typename PointDataGridT = Grid<
137 typename points::TreeConverter<typename GridT::TreeType>::Type>,
138 typename InterrupterT = util::NullInterrupter>
139inline typename PointDataGridT::Ptr
140 nonUniformPointScatter(const GridT& grid,
141 const float pointsPerVoxel,
142 const unsigned int seed = 0,
143 const float spread = 1.0f,
144 InterrupterT* interrupter = nullptr);
145
146} // namespace points
147} // namespace OPENVDB_VERSION_NAME
148} // namespace openvdb
149
150#include "impl/PointScatterImpl.h"
151
152#endif // OPENVDB_POINTS_POINT_SCATTER_HAS_BEEN_INCLUDED
AttributeArray.h
Attribute Array storage templated on type and compression codec.
LeafManager.h
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
NullInterrupter.h
PointCount.h
Methods for counting points in VDB Point grids.
PointDataGrid.h
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
PointScatterImpl.h
Prune.h
Defined various multi-threaded utility functions for trees.
openvdb::v11_0::points::denseUniformPointScatter
PointDataGridT::Ptr denseUniformPointScatter(const GridT &grid, const float pointsPerVoxel, const unsigned int seed=0, const float spread=1.0f, InterrupterT *interrupter=nullptr)
Uniformly scatter a fixed number of points per active voxel. If the pointsPerVoxel value provided is ...
Definition PointScatterImpl.h:264
openvdb::v11_0::points::uniformPointScatter
PointDataGridT::Ptr uniformPointScatter(const GridT &grid, const Index64 count, const unsigned int seed=0, const float spread=1.0f, InterrupterT *interrupter=nullptr)
The free functions depend on the following class:
Definition PointScatterImpl.h:92
openvdb::v11_0::points::nonUniformPointScatter
PointDataGridT::Ptr nonUniformPointScatter(const GridT &grid, const float pointsPerVoxel, const unsigned int seed=0, const float spread=1.0f, InterrupterT *interrupter=nullptr)
Non uniformly scatter points per active voxel. The pointsPerVoxel value is used to weight each grids ...
Definition PointScatterImpl.h:346
openvdb_houdini::Grid
openvdb::GridBase Grid
Definition Utils.h:34
openvdb
Definition Exceptions.h:13
Types.h
openvdb.h
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212