OpenVDB 12.1.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: Apache-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#include <openvdb/util/Assert.h>
28
29#include "AttributeArray.h"
30#include "PointCount.h"
31#include "PointDataGrid.h"
32
33#include <tbb/parallel_sort.h>
34#include <tbb/parallel_for.h>
35
36 namespace openvdb {
37 OPENVDB_USE_VERSION_NAMESPACE
38 namespace OPENVDB_VERSION_NAME {
39 namespace points {
40
41/// @brief The free functions depend on the following class:
42///
43/// The @c InterrupterT template argument below refers to any class
44/// with the following interface:
45/// @code
46/// class Interrupter {
47/// ...
48/// public:
49/// void start(const char* name = nullptr) // called when computations begin
50/// void end() // called when computations end
51/// bool wasInterrupted(int percent=-1) // return true to break computation
52///};
53/// @endcode
54///
55/// @note If no template argument is provided for this InterrupterT
56/// the util::NullInterrupter is used which implies that all
57/// interrupter calls are no-ops (i.e. incurs no computational overhead).
58
59
60/// @brief Uniformly scatter a total amount of points in active regions
61///
62/// @param grid A source grid. The resulting PointDataGrid will copy this grids
63/// transform and scatter in its active voxelized topology.
64/// @param count The total number of points to scatter
65/// @param seed A seed for the RandGenT
66/// @param spread The spread of points as a scale from each voxels center. A value of
67/// 1.0f indicates points can be placed anywhere within the voxel, where
68/// as a value of 0.0f will force all points to be created exactly at the
69/// centers of each voxel.
70/// @param interrupter An optional interrupter
71/// @note returns the scattered PointDataGrid
72 template<
73 typename GridT,
74 typename RandGenT = std::mt19937,
75 typename PositionArrayT = TypedAttributeArray<Vec3f, NullCodec>,
76 typename PointDataGridT = Grid<
77 typename points::TreeConverter<typename GridT::TreeType>::Type>,
78 typename InterrupterT = util::NullInterrupter>
79 inline typename PointDataGridT::Ptr
80 uniformPointScatter(const GridT& grid,
81 const Index64 count,
82 const unsigned int seed = 0,
83 const float spread = 1.0f,
84 InterrupterT* interrupter = nullptr);
85
86/// @brief Uniformly scatter a fixed number of points per active voxel. If the pointsPerVoxel
87/// value provided is a fractional value, each voxel calculates a delta value of
88/// how likely it is to contain an extra point.
89///
90/// @param grid A source grid. The resulting PointDataGrid will copy this grids
91/// transform and scatter in its active voxelized topology.
92/// @param pointsPerVoxel The number of points to scatter per voxel
93/// @param seed A seed for the RandGenT
94/// @param spread The spread of points as a scale from each voxels center. A value of
95/// 1.0f indicates points can be placed anywhere within the voxel, where
96/// as a value of 0.0f will force all points to be created exactly at the
97/// centers of each voxel.
98/// @param interrupter An optional interrupter
99/// @note returns the scattered PointDataGrid
100
101 template<
102 typename GridT,
103 typename RandGenT = std::mt19937,
104 typename PositionArrayT = TypedAttributeArray<Vec3f, NullCodec>,
105 typename PointDataGridT = Grid<
106 typename points::TreeConverter<typename GridT::TreeType>::Type>,
107 typename InterrupterT = util::NullInterrupter>
108 inline typename PointDataGridT::Ptr
109 denseUniformPointScatter(const GridT& grid,
110 const float pointsPerVoxel,
111 const unsigned int seed = 0,
112 const float spread = 1.0f,
113 InterrupterT* interrupter = nullptr);
114
115/// @brief Non uniformly scatter points per active voxel. The pointsPerVoxel value is used
116/// to weight each grids cell value to compute a fixed number of points for every
117/// active voxel. If the computed result is a fractional value, each voxel calculates
118/// a delta value of how likely it is to contain an extra point.
119///
120/// @param grid A source grid. The resulting PointDataGrid will copy this grids
121/// transform, voxelized topology and use its values to compute a
122/// target points per voxel. The grids ValueType must be convertible
123/// to a scalar value. Only active and larger than zero values will
124/// contain points.
125/// @param pointsPerVoxel The number of points to scatter per voxel
126/// @param seed A seed for the RandGenT
127/// @param spread The spread of points as a scale from each voxels center. A value of
128/// 1.0f indicates points can be placed anywhere within the voxel, where
129/// as a value of 0.0f will force all points to be created exactly at the
130/// centers of each voxel.
131/// @param interrupter An optional interrupter
132/// @note returns the scattered PointDataGrid
133 template<
134 typename GridT,
135 typename RandGenT = std::mt19937,
136 typename PositionArrayT = TypedAttributeArray<Vec3f, NullCodec>,
137 typename PointDataGridT = Grid<
138 typename points::TreeConverter<typename GridT::TreeType>::Type>,
139 typename InterrupterT = util::NullInterrupter>
140 inline typename PointDataGridT::Ptr
141 nonUniformPointScatter(const GridT& grid,
142 const float pointsPerVoxel,
143 const unsigned int seed = 0,
144 const float spread = 1.0f,
145 InterrupterT* interrupter = nullptr);
146
147} // namespace points
148} // namespace OPENVDB_VERSION_NAME
149} // namespace openvdb
150
151#include "impl/PointScatterImpl.h"
152
153#endif // OPENVDB_POINTS_POINT_SCATTER_HAS_BEEN_INCLUDED
Assert.h
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::v12_1::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::v12_1::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::v12_1::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:43
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:218