OpenVDB 11.0.0
 
Loading...
Searching...
No Matches
PointRasterizeFrustum.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 Dan Bailey, Rick Hankins
5///
6/// @file PointRasterizeFrustum.h
7///
8/// @brief Volume rasterization of VDB Points using velocity and camera motion-blur
9
10#ifndef OPENVDB_POINTS_POINT_RASTERIZE_FRUSTUM_HAS_BEEN_INCLUDED
11#define OPENVDB_POINTS_POINT_RASTERIZE_FRUSTUM_HAS_BEEN_INCLUDED
12
13#include <openvdb/math/Ray.h>
14#include <openvdb/math/DDA.h>
16#include <openvdb/thread/Threading.h>
17#include <openvdb/tools/GridTransformer.h> // for tools::resampleToMatch()
19#include "PointCount.h"
20#include "PointDataGrid.h"
21
22namespace openvdb {
24namespace OPENVDB_VERSION_NAME {
25namespace points {
26
27
28/// @brief How to composite points into a volume.
35
36
37/// @brief A camera class that provides an interface for camera motion blur when rasterizing
39{
40public:
41 explicit RasterCamera(const math::Transform& transform);
42
43 bool isStatic() const;
44
45 void clear();
46 void appendTransform(const math::Transform&, float weight = 1.0f);
47
48 size_t size() const;
49
50 void simplify();
51
52 bool hasWeight(Index i) const;
53 float weight(Index i) const;
54
55 const math::Transform& transform(Index i) const;
56 const math::Transform& firstTransform() const;
57 const math::Transform& lastTransform() const;
58
59 void setShutter(float start, float end);
60 float shutterStart() const;
61 float shutterEnd() const;
62
63private:
64 std::deque<math::Transform> mTransforms;
65 std::deque<float> mWeights;
66 // default to 180 degree film shutter
67 float mShutterStart = -0.25f,
68 mShutterEnd = 0.25f;
69}; // class RasterCamera
70
71
72/// @brief A group of shared settings to be used in the Volume Rasterizer
73/// @param scaleByVoxelVolume scale particle contributions by the volume of the receiving voxel
74/// @param velocityAttribute the name of the velocity attribute
75/// @param velocityMotionBlur bake the point velocities into the volume
76/// @param clipToFrustum if enabled and the transform is a frustum transform, eliminate
77/// points whose position does not lie within the frustum
78/// @param clipBBox an optional world-space bounding box to clip the points
79/// during rasterization
80/// @param clipMask an optional mask, each point samples the mask using a
81/// nearest-neighbor sampling and is only rasterized if active
82/// @param invertMask if mask is provided, only rasterize if sample is inactive
83/// @param framesPerSecond the global value for frames / second for computing motion blur
84/// @param threaded if enabled, use threading to accelerate rasterization
85/// @note rasterization can clip can using any combination of bounding box, mask and frustum
87{
89
90 explicit FrustumRasterizerSettings(const math::Transform& _transform)
91 : transform(new math::Transform(_transform))
92 , camera(_transform) { }
93
96 bool scaleByVoxelVolume = false,
97 useRadius = false,
101 threaded = true;
102 float threshold = 1e-6f,
106 radiusAttribute = "pscale";
108}; // struct FrustumRasterizerSettings
109
110
112{
114
116
117 explicit FrustumRasterizerMask(
118 const math::Transform& transform,
119 const MaskGrid* mask = nullptr,
120 const BBoxd& bbox = BBoxd(),
121 const bool clipToFrustum = true,
122 const bool invert = false);
123
124 operator bool() const;
125
127
128 bool valid(const Coord& ijk, AccessorT* acc) const;
129
130 const CoordBBox& clipBBox() const;
131
132private:
133 MaskGrid::Ptr mMask;
134 CoordBBox mClipBBox;
135 bool mInvert = false;
136}; // struct FrustumRasterizerMask
137
138
140
141template <typename PointDataGridT>
143
144} // namespace point_rasterize_internal
145
146
147/// @brief Efficient rasterization of one or more VDB Points grids into a linear
148/// or frustum volume with the option to bake in camera or geometry motion blur.
149///
150/// @details The camera transform can be provided using a RasterCamera object to
151/// offer linear camera motion blur and geometry motion blur is computed from reading
152/// a velocity attribute on the points. Sub-sampled camera motion blur is planned.
153///
154/// @note For maximum memory efficiency, the data can optionally be streamed from
155/// disk where the input VDB point grids are collapsed as they are read.
156///
157/// @note The total contribution for each point is spread across all the voxels being
158/// rasterized into and weighted by the total volume represented by each voxel. In an
159/// example use case where a point is moving away from a camera that is used to
160/// generate a frustum volume being rasterized into, each successive voxel is larger in
161/// size.
162template<typename PointDataGridT>
164{
165public:
166 using GridPtr = typename PointDataGridT::Ptr;
167 using GridConstPtr = typename PointDataGridT::ConstPtr;
169
170 /// @brief main constructor
171 /// @param settings the shared settings for rasterizing, see class for more details
172 /// @param mask a spatial mask to use to define the areas of rasterization
173 /// @param interrupt a pointer adhering to the util::NullInterrupter interface
174 explicit FrustumRasterizer(
175 const FrustumRasterizerSettings& settings,
177 util::NullInterrupter* interrupt = nullptr);
178
179 /// @brief Append a PointDataGrid to the rasterizer (but don't rasterize yet).
180 /// @param points the PointDataGrid
182
183 /// @brief Append a PointDataGrid to the rasterizer (but don't rasterize yet).
184 /// @param points the non-const PointDataGrid
185 /// @param stream if true, will destructively collapse attributes while
186 /// accessing so as to minimize the memory footprint.
187 void addPoints(GridPtr& points, bool stream = false);
188
189 /// @brief Clear all PointDataGrids in the rasterizer.
190 void clear();
191
192 /// @brief Return number of PointDataGrids in the rasterizer.
193 size_t size() const;
194
195 /// @brief Return memory usage of the rasterizer.
196 size_t memUsage() const;
197
198 template <typename FilterT = points::NullFilter>
201 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
202
203 template <typename FilterT = points::NullFilter>
206 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
207
208 template <typename FilterT = points::NullFilter>
211 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
212
213 template <typename GridT, typename AttributeT, typename FilterT = points::NullFilter>
214 typename GridT::Ptr
216 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
217
218 template <typename GridT, typename FilterT = points::NullFilter>
219 typename GridT::Ptr
220 rasterizeMask(bool reduceMemory = false, const FilterT& filter = FilterT());
221
222private:
223 template <typename AttributeT, typename GridT, typename FilterT>
224 void
225 performRasterization(
226 GridT& grid, RasterMode mode, const openvdb::Name& attribute,
227 bool reduceMemory, float scale, const FilterT& filter);
228
229private:
232
233 util::NullInterrupter* mInterrupter;
234 std::vector<GridToRasterize> mPointGrids;
235}; // class FrustumRasterizer
236
237
238/// @brief A struct that stores all include/exclude attribute names as strings
239/// and is internally converted into the resolved MultiGroupFilter
241{
242 std::vector<Name> includeNames;
243 std::vector<Name> excludeNames;
244}; // class RasterGroups
245
246
247} // namespace points
248} // namespace OPENVDB_VERSION_NAME
249} // namespace openvdb
250
252
253#endif // OPENVDB_POINTS_POINT_RASTERIZE_FRUSTUM_HAS_BEEN_INCLUDED
Digital Differential Analyzers specialized for VDB.
Methods for counting points in VDB Point grids.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
SharedPtr< GridBase > Ptr
Definition Grid.h:80
SharedPtr< Grid > Ptr
Definition Grid.h:573
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:251
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:25
Definition Transform.h:40
SharedPtr< Transform > Ptr
Definition Transform.h:42
typename PointDataGridT::ConstPtr GridConstPtr
Definition PointRasterizeFrustum.h:167
size_t memUsage() const
Return memory usage of the rasterizer.
Definition PointRasterizeFrustumImpl.h:1315
point_rasterize_internal::GridToRasterize< PointDataGridT > GridToRasterize
Definition PointRasterizeFrustum.h:168
size_t size() const
Return number of PointDataGrids in the rasterizer.
Definition PointRasterizeFrustumImpl.h:1308
FrustumRasterizer(const FrustumRasterizerSettings &settings, const FrustumRasterizerMask &mask=FrustumRasterizerMask(), util::NullInterrupter *interrupt=nullptr)
main constructor
Definition PointRasterizeFrustumImpl.h:1265
FloatGrid::Ptr rasterizeDensity(const openvdb::Name &attribute, RasterMode mode=RasterMode::MAXIMUM, bool reduceMemory=false, float scale=1.0f, const FilterT &filter=FilterT())
Definition PointRasterizeFrustumImpl.h:1340
void addPoints(GridConstPtr &points)
Append a PointDataGrid to the rasterizer (but don't rasterize yet).
Definition PointRasterizeFrustumImpl.h:1280
GridT::Ptr rasterizeMask(bool reduceMemory=false, const FilterT &filter=FilterT())
Definition PointRasterizeFrustumImpl.h:1440
typename PointDataGridT::Ptr GridPtr
Definition PointRasterizeFrustum.h:166
void clear()
Clear all PointDataGrids in the rasterizer.
Definition PointRasterizeFrustumImpl.h:1301
GridBase::Ptr rasterizeAttribute(const Name &attribute, RasterMode mode=RasterMode::ACCUMULATE, bool reduceMemory=false, float scale=1.0f, const FilterT &filter=FilterT())
Definition PointRasterizeFrustumImpl.h:1352
FloatGrid::Ptr rasterizeUniformDensity(RasterMode mode=RasterMode::MAXIMUM, bool reduceMemory=false, float scale=1.0f, const FilterT &filter=FilterT())
Definition PointRasterizeFrustumImpl.h:1327
A camera class that provides an interface for camera motion blur when rasterizing.
Definition PointRasterizeFrustum.h:39
float weight(Index i) const
Definition PointRasterizeFrustumImpl.h:1126
void simplify()
Definition PointRasterizeFrustumImpl.h:1089
const math::Transform & transform(Index i) const
Definition PointRasterizeFrustumImpl.h:1136
size_t size() const
Definition PointRasterizeFrustumImpl.h:1084
const math::Transform & firstTransform() const
Definition PointRasterizeFrustumImpl.h:1146
bool isStatic() const
Definition PointRasterizeFrustumImpl.h:1067
void setShutter(float start, float end)
Definition PointRasterizeFrustumImpl.h:1158
void appendTransform(const math::Transform &, float weight=1.0f)
Definition PointRasterizeFrustumImpl.h:1078
float shutterEnd() const
Definition PointRasterizeFrustumImpl.h:1169
bool hasWeight(Index i) const
Definition PointRasterizeFrustumImpl.h:1119
RasterCamera(const math::Transform &transform)
Definition PointRasterizeFrustumImpl.h:1063
void clear()
Definition PointRasterizeFrustumImpl.h:1072
const math::Transform & lastTransform() const
Definition PointRasterizeFrustumImpl.h:1152
float shutterStart() const
Definition PointRasterizeFrustumImpl.h:1164
SharedPtr< const Tree > ConstPtr
Definition Tree.h:181
Definition Types.h:28
Definition PointRasterizeFrustum.h:139
Definition AttributeArray.h:41
RasterMode
How to composite points into a volume.
Definition PointRasterizeFrustum.h:30
@ MAXIMUM
Definition PointRasterizeFrustum.h:32
@ AVERAGE
Definition PointRasterizeFrustum.h:33
@ ACCUMULATE
Definition PointRasterizeFrustum.h:31
ValueAccessorImpl< TreeType, IsSafe, MutexType, openvdb::make_index_sequence< CacheLevels > > ValueAccessor
Default alias for a ValueAccessor. This is simply a helper alias for the generic definition but takes...
Definition ValueAccessor.h:86
std::string Name
Definition Name.h:19
Index32 Index
Definition Types.h:54
math::BBox< Vec3d > BBoxd
Definition Types.h:84
Grid< MaskTree > MaskGrid
Definition openvdb.h:78
Definition Exceptions.h:13
A Ray class.
Definition PointRasterizeFrustum.h:112
bool valid(const Coord &ijk, AccessorT *acc) const
Definition PointRasterizeFrustumImpl.h:1252
const tree::ValueAccessor< const MaskTree > AccessorT
Definition PointRasterizeFrustum.h:113
MaskTree::ConstPtr getTreePtr() const
Definition PointRasterizeFrustumImpl.h:1240
const CoordBBox & clipBBox() const
Definition PointRasterizeFrustumImpl.h:1246
A group of shared settings to be used in the Volume Rasterizer.
Definition PointRasterizeFrustum.h:87
int motionSamples
Definition PointRasterizeFrustum.h:107
bool accurateFrustumRadius
Definition PointRasterizeFrustum.h:98
bool useRadius
Definition PointRasterizeFrustum.h:97
float threshold
Definition PointRasterizeFrustum.h:102
float radiusScale
Definition PointRasterizeFrustum.h:103
math::Transform::Ptr transform
Definition PointRasterizeFrustum.h:94
Name velocityAttribute
Definition PointRasterizeFrustum.h:105
bool velocityMotionBlur
Definition PointRasterizeFrustum.h:100
bool accurateSphereMotionBlur
Definition PointRasterizeFrustum.h:99
bool threaded
Definition PointRasterizeFrustum.h:101
float framesPerSecond
Definition PointRasterizeFrustum.h:104
RasterCamera camera
Definition PointRasterizeFrustum.h:95
FrustumRasterizerSettings(const math::Transform &_transform)
Definition PointRasterizeFrustum.h:90
bool scaleByVoxelVolume
Definition PointRasterizeFrustum.h:96
Name radiusAttribute
Definition PointRasterizeFrustum.h:106
A struct that stores all include/exclude attribute names as strings and is internally converted into ...
Definition PointRasterizeFrustum.h:241
std::vector< Name > excludeNames
Definition PointRasterizeFrustum.h:243
std::vector< Name > includeNames
Definition PointRasterizeFrustum.h:242
Base class for interrupters.
Definition NullInterrupter.h:26
#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