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