OpenVDB 13.0.1
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>
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:
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
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
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/// @cond OPENVDB_DOCS_INTERNAL
140
141namespace point_rasterize_internal {
142
143template <typename PointDataGridT>
144class GridToRasterize;
145
146} // namespace point_rasterize_internal
147
148/// @endcond
149
150/// @brief Efficient rasterization of one or more VDB Points grids into a linear
151/// or frustum volume with the option to bake in camera or geometry motion blur.
152///
153/// @details The camera transform can be provided using a RasterCamera object to
154/// offer linear camera motion blur and geometry motion blur is computed from reading
155/// a velocity attribute on the points. Sub-sampled camera motion blur is planned.
156///
157/// @note For maximum memory efficiency, the data can optionally be streamed from
158/// disk where the input VDB point grids are collapsed as they are read.
159///
160/// @note The total contribution for each point is spread across all the voxels being
161/// rasterized into and weighted by the total volume represented by each voxel. In an
162/// example use case where a point is moving away from a camera that is used to
163/// generate a frustum volume being rasterized into, each successive voxel is larger in
164/// size.
165template<typename PointDataGridT>
167{
168public:
169 using GridPtr = typename PointDataGridT::Ptr;
170 using GridConstPtr = typename PointDataGridT::ConstPtr;
171 using GridToRasterize = point_rasterize_internal::GridToRasterize<PointDataGridT>;
172
173 /// @brief main constructor
174 /// @param settings the shared settings for rasterizing, see class for more details
175 /// @param mask a spatial mask to use to define the areas of rasterization
176 /// @param interrupt a pointer adhering to the util::NullInterrupter interface
178 const FrustumRasterizerSettings& settings,
180 util::NullInterrupter* interrupt = nullptr);
181
182 /// @brief Append a PointDataGrid to the rasterizer (but don't rasterize yet).
183 /// @param points the PointDataGrid
185
186 /// @brief Append a PointDataGrid to the rasterizer (but don't rasterize yet).
187 /// @param points the non-const PointDataGrid
188 /// @param stream if true, will destructively collapse attributes while
189 /// accessing so as to minimize the memory footprint.
190 void addPoints(GridPtr& points, bool stream = false);
191
192 /// @brief Clear all PointDataGrids in the rasterizer.
193 void clear();
194
195 /// @brief Return number of PointDataGrids in the rasterizer.
196 size_t size() const;
197
198 /// @brief Return memory usage of the rasterizer.
199 size_t memUsage() const;
200
201 template <typename FilterT = points::NullFilter>
204 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
205
206 template <typename FilterT = points::NullFilter>
209 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
210
211 template <typename FilterT = points::NullFilter>
214 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
215
216 template <typename GridT, typename AttributeT, typename FilterT = points::NullFilter>
217 typename GridT::Ptr
219 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
220
221 template <typename GridT, typename FilterT = points::NullFilter>
222 typename GridT::Ptr
223 rasterizeMask(bool reduceMemory = false, const FilterT& filter = FilterT());
224
225private:
226 template <typename AttributeT, typename GridT, typename FilterT>
227 void
228 performRasterization(
229 GridT& grid, RasterMode mode, const openvdb::Name& attribute,
230 bool reduceMemory, float scale, const FilterT& filter);
231
232private:
235
236 util::NullInterrupter* mInterrupter;
237 std::vector<GridToRasterize> mPointGrids;
238}; // class FrustumRasterizer
239
240
241/// @brief A struct that stores all include/exclude attribute names as strings
242/// and is internally converted into the resolved MultiGroupFilter
244{
245 std::vector<Name> includeNames;
246 std::vector<Name> excludeNames;
247}; // class RasterGroups
248
249
250} // namespace points
251} // namespace OPENVDB_VERSION_NAME
252} // namespace openvdb
253
254#include "impl/PointRasterizeFrustumImpl.h"
255
256#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
GridT::Ptr rasterizeAttribute(const Name &attribute, RasterMode mode=RasterMode::ACCUMULATE, bool reduceMemory=false, float scale=1.0f, const FilterT &filter=FilterT())
typename PointDataGridT::ConstPtr GridConstPtr
Definition PointRasterizeFrustum.h:170
size_t memUsage() const
Return memory usage of the rasterizer.
point_rasterize_internal::GridToRasterize< PointDataGridT > GridToRasterize
Definition PointRasterizeFrustum.h:171
size_t size() const
Return number of PointDataGrids in the rasterizer.
FrustumRasterizer(const FrustumRasterizerSettings &settings, const FrustumRasterizerMask &mask=FrustumRasterizerMask(), util::NullInterrupter *interrupt=nullptr)
main constructor
FloatGrid::Ptr rasterizeDensity(const openvdb::Name &attribute, RasterMode mode=RasterMode::MAXIMUM, bool reduceMemory=false, float scale=1.0f, const FilterT &filter=FilterT())
void addPoints(GridPtr &points, bool stream=false)
Append a PointDataGrid to the rasterizer (but don't rasterize yet).
void addPoints(GridConstPtr &points)
Append a PointDataGrid to the rasterizer (but don't rasterize yet).
GridT::Ptr rasterizeMask(bool reduceMemory=false, const FilterT &filter=FilterT())
typename PointDataGridT::Ptr GridPtr
Definition PointRasterizeFrustum.h:169
void clear()
Clear all PointDataGrids in the rasterizer.
GridBase::Ptr rasterizeAttribute(const Name &attribute, RasterMode mode=RasterMode::ACCUMULATE, bool reduceMemory=false, float scale=1.0f, const FilterT &filter=FilterT())
FloatGrid::Ptr rasterizeUniformDensity(RasterMode mode=RasterMode::MAXIMUM, bool reduceMemory=false, float scale=1.0f, const FilterT &filter=FilterT())
A camera class that provides an interface for camera motion blur when rasterizing.
Definition PointRasterizeFrustum.h:40
const math::Transform & transform(Index i) const
const math::Transform & firstTransform() const
void setShutter(float start, float end)
void appendTransform(const math::Transform &, float weight=1.0f)
RasterCamera(const math::Transform &transform)
const math::Transform & lastTransform() const
SharedPtr< const Tree > ConstPtr
Definition Tree.h:198
Definition Types.h:763
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:34
math::BBox< Vec3d > BBoxd
Definition Types.h:65
Grid< MaskTree > MaskGrid
Definition openvdb.h:80
Definition Exceptions.h:13
A Ray class.
Definition PointRasterizeFrustum.h:113
bool valid(const Coord &ijk, AccessorT *acc) const
const tree::ValueAccessor< const MaskTree > AccessorT
Definition PointRasterizeFrustum.h:114
FrustumRasterizerMask(const math::Transform &transform, const MaskGrid *mask=nullptr, const BBoxd &bbox=BBoxd(), const bool clipToFrustum=true, const bool invert=false)
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:244
std::vector< Name > excludeNames
Definition PointRasterizeFrustum.h:246
std::vector< Name > includeNames
Definition PointRasterizeFrustum.h:245
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