OpenVDB: openvdb/points/PointRasterizeFrustum.h Source File

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>
15#include <openvdb/util/NullInterrupter.h>
16#include <openvdb/util/Assert.h>
17#include <openvdb/thread/Threading.h>
18#include <openvdb/tools/GridTransformer.h> // for tools::resampleToMatch()
19#include <openvdb/tools/Interpolation.h>
20#include "PointCount.h"
21#include "PointDataGrid.h"
22
23namespace openvdb {
24 OPENVDB_USE_VERSION_NAMESPACE
25namespace OPENVDB_VERSION_NAME {
26namespace points {
27
28
29/// @brief How to composite points into a volume.
30 enum class RasterMode
31{
32 ACCUMULATE = 0,
33 MAXIMUM,
34 AVERAGE
35};
36
37
38/// @brief A camera class that provides an interface for camera motion blur when rasterizing
39 class RasterCamera
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
87 struct FrustumRasterizerSettings
88{
89 FrustumRasterizerSettings() = delete;
90
91 explicit FrustumRasterizerSettings(const math::Transform& _transform)
92 : transform(new math::Transform(_transform))
93 , camera(_transform) { }
94
95 math::Transform::Ptr transform;
96 RasterCamera camera;
97 bool scaleByVoxelVolume = false,
98 useRadius = false,
99 accurateFrustumRadius = false,
100 accurateSphereMotionBlur = false,
101 velocityMotionBlur = false,
102 threaded = true;
103 float threshold = 1e-6f,
104 radiusScale = 1.0f,
105 framesPerSecond = 24.0f;
106 Name velocityAttribute = "v",
107 radiusAttribute = "pscale";
108 int motionSamples = 2;
109}; // struct FrustumRasterizerSettings
110
111
112 struct FrustumRasterizerMask
113{
114 using AccessorT = const tree::ValueAccessor<const MaskTree>;
115
116 FrustumRasterizerMask() = default;
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
127 MaskTree::ConstPtr getTreePtr() const;
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
140 namespace point_rasterize_internal {
141
142template <typename PointDataGridT>
143 class GridToRasterize;
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>
164 class FrustumRasterizer
165{
166public:
167 using GridPtr = typename PointDataGridT::Ptr;
168 using GridConstPtr = typename PointDataGridT::ConstPtr;
169 using GridToRasterize = point_rasterize_internal::GridToRasterize<PointDataGridT>;
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,
177 const FrustumRasterizerMask& mask = FrustumRasterizerMask(),
178 util::NullInterrupter* interrupt = nullptr);
179
180 /// @brief Append a PointDataGrid to the rasterizer (but don't rasterize yet).
181 /// @param points the PointDataGrid
182 void addPoints(GridConstPtr& points);
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>
200 FloatGrid::Ptr
201 rasterizeUniformDensity(RasterMode mode=RasterMode::MAXIMUM,
202 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
203
204 template <typename FilterT = points::NullFilter>
205 FloatGrid::Ptr
206 rasterizeDensity(const openvdb::Name& attribute, RasterMode mode=RasterMode::MAXIMUM,
207 bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
208
209 template <typename FilterT = points::NullFilter>
210 GridBase::Ptr
211 rasterizeAttribute(const Name& attribute, RasterMode mode=RasterMode::ACCUMULATE,
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
216 rasterizeAttribute(const Name& attribute, RasterMode mode=RasterMode::ACCUMULATE,
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:
231 FrustumRasterizerSettings mSettings;
232 FrustumRasterizerMask mMask;
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
241 struct RasterGroups
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
252#include "impl/PointRasterizeFrustumImpl.h"
253
254#endif // OPENVDB_POINTS_POINT_RASTERIZE_FRUSTUM_HAS_BEEN_INCLUDED
Assert.h
DDA.h
Digital Differential Analyzers specialized for VDB.
GridTransformer.h
Interpolation.h
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...
PointRasterizeFrustumImpl.h
openvdb::v12_0::GridBase::Ptr
SharedPtr< GridBase > Ptr
Definition Grid.h:80
openvdb::v12_0::Grid< MaskTree >::Ptr
SharedPtr< Grid > Ptr
Definition Grid.h:573
openvdb::v12_0::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
openvdb::v12_0::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
openvdb::v12_0::math::Transform
Definition Transform.h:40
openvdb::v12_0::math::Transform::Ptr
SharedPtr< Transform > Ptr
Definition Transform.h:42
openvdb::v12_0::points::FrustumRasterizer::GridConstPtr
typename PointDataGridT::ConstPtr GridConstPtr
Definition PointRasterizeFrustum.h:168
openvdb::v12_0::points::FrustumRasterizer::memUsage
size_t memUsage() const
Return memory usage of the rasterizer.
Definition PointRasterizeFrustumImpl.h:1315
openvdb::v12_0::points::FrustumRasterizer::GridToRasterize
point_rasterize_internal::GridToRasterize< PointDataGridT > GridToRasterize
Definition PointRasterizeFrustum.h:169
openvdb::v12_0::points::FrustumRasterizer::size
size_t size() const
Return number of PointDataGrids in the rasterizer.
Definition PointRasterizeFrustumImpl.h:1308
openvdb::v12_0::points::FrustumRasterizer::FrustumRasterizer
FrustumRasterizer(const FrustumRasterizerSettings &settings, const FrustumRasterizerMask &mask=FrustumRasterizerMask(), util::NullInterrupter *interrupt=nullptr)
main constructor
Definition PointRasterizeFrustumImpl.h:1265
openvdb::v12_0::points::FrustumRasterizer::rasterizeDensity
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
openvdb::v12_0::points::FrustumRasterizer::addPoints
void addPoints(GridConstPtr &points)
Append a PointDataGrid to the rasterizer (but don't rasterize yet).
Definition PointRasterizeFrustumImpl.h:1280
openvdb::v12_0::points::FrustumRasterizer::rasterizeMask
GridT::Ptr rasterizeMask(bool reduceMemory=false, const FilterT &filter=FilterT())
Definition PointRasterizeFrustumImpl.h:1440
openvdb::v12_0::points::FrustumRasterizer::GridPtr
typename PointDataGridT::Ptr GridPtr
Definition PointRasterizeFrustum.h:167
openvdb::v12_0::points::FrustumRasterizer::clear
void clear()
Clear all PointDataGrids in the rasterizer.
Definition PointRasterizeFrustumImpl.h:1301
openvdb::v12_0::points::FrustumRasterizer::rasterizeAttribute
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
openvdb::v12_0::points::FrustumRasterizer::rasterizeUniformDensity
FloatGrid::Ptr rasterizeUniformDensity(RasterMode mode=RasterMode::MAXIMUM, bool reduceMemory=false, float scale=1.0f, const FilterT &filter=FilterT())
Definition PointRasterizeFrustumImpl.h:1327
openvdb::v12_0::points::RasterCamera
A camera class that provides an interface for camera motion blur when rasterizing.
Definition PointRasterizeFrustum.h:40
openvdb::v12_0::points::RasterCamera::weight
float weight(Index i) const
Definition PointRasterizeFrustumImpl.h:1126
openvdb::v12_0::points::RasterCamera::simplify
void simplify()
Definition PointRasterizeFrustumImpl.h:1089
openvdb::v12_0::points::RasterCamera::transform
const math::Transform & transform(Index i) const
Definition PointRasterizeFrustumImpl.h:1136
openvdb::v12_0::points::RasterCamera::size
size_t size() const
Definition PointRasterizeFrustumImpl.h:1084
openvdb::v12_0::points::RasterCamera::firstTransform
const math::Transform & firstTransform() const
Definition PointRasterizeFrustumImpl.h:1146
openvdb::v12_0::points::RasterCamera::isStatic
bool isStatic() const
Definition PointRasterizeFrustumImpl.h:1067
openvdb::v12_0::points::RasterCamera::setShutter
void setShutter(float start, float end)
Definition PointRasterizeFrustumImpl.h:1158
openvdb::v12_0::points::RasterCamera::appendTransform
void appendTransform(const math::Transform &, float weight=1.0f)
Definition PointRasterizeFrustumImpl.h:1078
openvdb::v12_0::points::RasterCamera::shutterEnd
float shutterEnd() const
Definition PointRasterizeFrustumImpl.h:1169
openvdb::v12_0::points::RasterCamera::hasWeight
bool hasWeight(Index i) const
Definition PointRasterizeFrustumImpl.h:1119
openvdb::v12_0::points::RasterCamera::RasterCamera
RasterCamera(const math::Transform &transform)
Definition PointRasterizeFrustumImpl.h:1063
openvdb::v12_0::points::RasterCamera::clear
void clear()
Definition PointRasterizeFrustumImpl.h:1072
openvdb::v12_0::points::RasterCamera::lastTransform
const math::Transform & lastTransform() const
Definition PointRasterizeFrustumImpl.h:1152
openvdb::v12_0::points::RasterCamera::shutterStart
float shutterStart() const
Definition PointRasterizeFrustumImpl.h:1164
openvdb::v12_0::points::point_rasterize_internal::GridToRasterize
Definition PointRasterizeFrustum.h:143
openvdb::v12_0::tree::Tree::ConstPtr
SharedPtr< const Tree > ConstPtr
Definition Tree.h:198
openvdb::v12_0::math
Definition Types.h:28
openvdb::v12_0::points::point_rasterize_internal
Definition PointRasterizeFrustum.h:140
openvdb::v12_0::points
Definition AttributeArray.h:42
openvdb::v12_0::points::RasterMode
RasterMode
How to composite points into a volume.
Definition PointRasterizeFrustum.h:31
openvdb::v12_0::points::RasterMode::MAXIMUM
@ MAXIMUM
Definition PointRasterizeFrustum.h:33
openvdb::v12_0::points::RasterMode::AVERAGE
@ AVERAGE
Definition PointRasterizeFrustum.h:34
openvdb::v12_0::points::RasterMode::ACCUMULATE
@ ACCUMULATE
Definition PointRasterizeFrustum.h:32
openvdb::v12_0::tree::ValueAccessor
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
openvdb::v12_0::Name
std::string Name
Definition Name.h:19
openvdb::v12_0::Index
Index32 Index
Definition Types.h:54
openvdb::v12_0::BBoxd
math::BBox< Vec3d > BBoxd
Definition Types.h:84
openvdb::v12_0::MaskGrid
Grid< MaskTree > MaskGrid
Definition openvdb.h:78
openvdb
Definition Exceptions.h:13
Ray.h
A Ray class.
openvdb::v12_0::points::FrustumRasterizerMask
Definition PointRasterizeFrustum.h:113
openvdb::v12_0::points::FrustumRasterizerMask::FrustumRasterizerMask
FrustumRasterizerMask()=default
openvdb::v12_0::points::FrustumRasterizerMask::valid
bool valid(const Coord &ijk, AccessorT *acc) const
Definition PointRasterizeFrustumImpl.h:1252
openvdb::v12_0::points::FrustumRasterizerMask::AccessorT
const tree::ValueAccessor< const MaskTree > AccessorT
Definition PointRasterizeFrustum.h:114
openvdb::v12_0::points::FrustumRasterizerMask::getTreePtr
MaskTree::ConstPtr getTreePtr() const
Definition PointRasterizeFrustumImpl.h:1240
openvdb::v12_0::points::FrustumRasterizerMask::clipBBox
const CoordBBox & clipBBox() const
Definition PointRasterizeFrustumImpl.h:1246
openvdb::v12_0::points::FrustumRasterizerSettings
A group of shared settings to be used in the Volume Rasterizer.
Definition PointRasterizeFrustum.h:88
openvdb::v12_0::points::FrustumRasterizerSettings::motionSamples
int motionSamples
Definition PointRasterizeFrustum.h:108
openvdb::v12_0::points::FrustumRasterizerSettings::accurateFrustumRadius
bool accurateFrustumRadius
Definition PointRasterizeFrustum.h:99
openvdb::v12_0::points::FrustumRasterizerSettings::useRadius
bool useRadius
Definition PointRasterizeFrustum.h:98
openvdb::v12_0::points::FrustumRasterizerSettings::FrustumRasterizerSettings
FrustumRasterizerSettings()=delete
openvdb::v12_0::points::FrustumRasterizerSettings::threshold
float threshold
Definition PointRasterizeFrustum.h:103
openvdb::v12_0::points::FrustumRasterizerSettings::radiusScale
float radiusScale
Definition PointRasterizeFrustum.h:104
openvdb::v12_0::points::FrustumRasterizerSettings::transform
math::Transform::Ptr transform
Definition PointRasterizeFrustum.h:95
openvdb::v12_0::points::FrustumRasterizerSettings::velocityAttribute
Name velocityAttribute
Definition PointRasterizeFrustum.h:106
openvdb::v12_0::points::FrustumRasterizerSettings::velocityMotionBlur
bool velocityMotionBlur
Definition PointRasterizeFrustum.h:101
openvdb::v12_0::points::FrustumRasterizerSettings::accurateSphereMotionBlur
bool accurateSphereMotionBlur
Definition PointRasterizeFrustum.h:100
openvdb::v12_0::points::FrustumRasterizerSettings::threaded
bool threaded
Definition PointRasterizeFrustum.h:102
openvdb::v12_0::points::FrustumRasterizerSettings::framesPerSecond
float framesPerSecond
Definition PointRasterizeFrustum.h:105
openvdb::v12_0::points::FrustumRasterizerSettings::camera
RasterCamera camera
Definition PointRasterizeFrustum.h:96
openvdb::v12_0::points::FrustumRasterizerSettings::FrustumRasterizerSettings
FrustumRasterizerSettings(const math::Transform &_transform)
Definition PointRasterizeFrustum.h:91
openvdb::v12_0::points::FrustumRasterizerSettings::scaleByVoxelVolume
bool scaleByVoxelVolume
Definition PointRasterizeFrustum.h:97
openvdb::v12_0::points::FrustumRasterizerSettings::radiusAttribute
Name radiusAttribute
Definition PointRasterizeFrustum.h:107
openvdb::v12_0::points::RasterGroups
A struct that stores all include/exclude attribute names as strings and is internally converted into ...
Definition PointRasterizeFrustum.h:242
openvdb::v12_0::points::RasterGroups::excludeNames
std::vector< Name > excludeNames
Definition PointRasterizeFrustum.h:244
openvdb::v12_0::points::RasterGroups::includeNames
std::vector< Name > includeNames
Definition PointRasterizeFrustum.h:243
openvdb::v12_0::util::NullInterrupter
Base class for interrupters.
Definition NullInterrupter.h:26
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