Loading...
Searching...
No Matches
PointRasterizeFrustum.h
Go to the documentation of this file.
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: MPL-2.0
/// @author Dan Bailey, Rick Hankins
///
/// @file PointRasterizeFrustum.h
///
/// @brief Volume rasterization of VDB Points using velocity and camera motion-blur
#ifndef OPENVDB_POINTS_POINT_RASTERIZE_FRUSTUM_HAS_BEEN_INCLUDED
#define OPENVDB_POINTS_POINT_RASTERIZE_FRUSTUM_HAS_BEEN_INCLUDED
#include <openvdb/math/Ray.h>
#include <openvdb/math/DDA.h>
#include <openvdb/util/NullInterrupter.h>
#include <openvdb/thread/Threading.h>
#include <openvdb/tools/GridTransformer.h> // for tools::resampleToMatch()
#include <openvdb/tools/Interpolation.h>
#include "PointCount.h"
#include "PointDataGrid.h"
namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
namespace points {
/// @brief How to composite points into a volume.
enum class RasterMode
{
ACCUMULATE = 0,
MAXIMUM,
AVERAGE
};
/// @brief A camera class that provides an interface for camera motion blur when rasterizing
class RasterCamera
{
public:
explicit RasterCamera(const math::Transform& transform);
bool isStatic() const;
void clear();
void appendTransform(const math::Transform&, float weight = 1.0f);
size_t size() const;
void simplify();
bool hasWeight(Index i) const;
float weight(Index i) const;
const math::Transform& transform(Index i) const;
const math::Transform& firstTransform() const;
const math::Transform& lastTransform() const;
void setShutter(float start, float end);
float shutterStart() const;
float shutterEnd() const;
private:
std::deque<math::Transform> mTransforms;
std::deque<float> mWeights;
// default to 180 degree film shutter
float mShutterStart = -0.25f,
mShutterEnd = 0.25f;
}; // class RasterCamera
/// @brief A group of shared settings to be used in the Volume Rasterizer
/// @param scaleByVoxelVolume scale particle contributions by the volume of the receiving voxel
/// @param velocityAttribute the name of the velocity attribute
/// @param velocityMotionBlur bake the point velocities into the volume
/// @param clipToFrustum if enabled and the transform is a frustum transform, eliminate
/// points whose position does not lie within the frustum
/// @param clipBBox an optional world-space bounding box to clip the points
/// during rasterization
/// @param clipMask an optional mask, each point samples the mask using a
/// nearest-neighbor sampling and is only rasterized if active
/// @param invertMask if mask is provided, only rasterize if sample is inactive
/// @param framesPerSecond the global value for frames / second for computing motion blur
/// @param threaded if enabled, use threading to accelerate rasterization
/// @note rasterization can clip can using any combination of bounding box, mask and frustum
struct FrustumRasterizerSettings
{
FrustumRasterizerSettings() = delete;
explicit FrustumRasterizerSettings(const math::Transform& _transform)
: transform(new math::Transform(_transform))
, camera(_transform) { }
math::Transform::Ptr transform;
RasterCamera camera;
bool scaleByVoxelVolume = false,
useRadius = false,
accurateFrustumRadius = false,
accurateSphereMotionBlur = false,
velocityMotionBlur = false,
threaded = true;
float threshold = 1e-6f,
radiusScale = 1.0f,
framesPerSecond = 24.0f;
Name velocityAttribute = "v",
radiusAttribute = "pscale";
int motionSamples = 2;
}; // struct FrustumRasterizerSettings
struct FrustumRasterizerMask
{
using AccessorT = const tree::ValueAccessor<const MaskTree>;
FrustumRasterizerMask() = default;
explicit FrustumRasterizerMask(
const math::Transform& transform,
const MaskGrid* mask = nullptr,
const BBoxd& bbox = BBoxd(),
const bool clipToFrustum = true,
const bool invert = false);
operator bool() const;
MaskTree::ConstPtr getTreePtr() const;
bool valid(const Coord& ijk, AccessorT* acc) const;
const CoordBBox& clipBBox() const;
private:
MaskGrid::Ptr mMask;
CoordBBox mClipBBox;
bool mInvert = false;
}; // struct FrustumRasterizerMask
namespace point_rasterize_internal {
template <typename PointDataGridT>
class GridToRasterize;
} // namespace point_rasterize_internal
/// @brief Efficient rasterization of one or more VDB Points grids into a linear
/// or frustum volume with the option to bake in camera or geometry motion blur.
///
/// @details The camera transform can be provided using a RasterCamera object to
/// offer linear camera motion blur and geometry motion blur is computed from reading
/// a velocity attribute on the points. Sub-sampled camera motion blur is planned.
///
/// @note For maximum memory efficiency, the data can optionally be streamed from
/// disk where the input VDB point grids are collapsed as they are read.
///
/// @note The total contribution for each point is spread across all the voxels being
/// rasterized into and weighted by the total volume represented by each voxel. In an
/// example use case where a point is moving away from a camera that is used to
/// generate a frustum volume being rasterized into, each successive voxel is larger in
/// size.
template<typename PointDataGridT>
class FrustumRasterizer
{
public:
using GridPtr = typename PointDataGridT::Ptr;
using GridConstPtr = typename PointDataGridT::ConstPtr;
using GridToRasterize = point_rasterize_internal::GridToRasterize<PointDataGridT>;
/// @brief main constructor
/// @param settings the shared settings for rasterizing, see class for more details
/// @param mask a spatial mask to use to define the areas of rasterization
/// @param interrupt a pointer adhering to the util::NullInterrupter interface
explicit FrustumRasterizer(
const FrustumRasterizerSettings& settings,
const FrustumRasterizerMask& mask = FrustumRasterizerMask(),
util::NullInterrupter* interrupt = nullptr);
/// @brief Append a PointDataGrid to the rasterizer (but don't rasterize yet).
/// @param points the PointDataGrid
void addPoints(GridConstPtr& points);
/// @brief Append a PointDataGrid to the rasterizer (but don't rasterize yet).
/// @param points the non-const PointDataGrid
/// @param stream if true, will destructively collapse attributes while
/// accessing so as to minimize the memory footprint.
void addPoints(GridPtr& points, bool stream = false);
/// @brief Clear all PointDataGrids in the rasterizer.
void clear();
/// @brief Return number of PointDataGrids in the rasterizer.
size_t size() const;
/// @brief Return memory usage of the rasterizer.
size_t memUsage() const;
template <typename FilterT = points::NullFilter>
FloatGrid::Ptr
rasterizeUniformDensity(RasterMode mode=RasterMode::MAXIMUM,
bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
template <typename FilterT = points::NullFilter>
FloatGrid::Ptr
rasterizeDensity(const openvdb::Name& attribute, RasterMode mode=RasterMode::MAXIMUM,
bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
template <typename FilterT = points::NullFilter>
GridBase::Ptr
rasterizeAttribute(const Name& attribute, RasterMode mode=RasterMode::ACCUMULATE,
bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
template <typename GridT, typename AttributeT, typename FilterT = points::NullFilter>
typename GridT::Ptr
rasterizeAttribute(const Name& attribute, RasterMode mode=RasterMode::ACCUMULATE,
bool reduceMemory = false, float scale = 1.0f, const FilterT& filter = FilterT());
template <typename GridT, typename FilterT = points::NullFilter>
typename GridT::Ptr
rasterizeMask(bool reduceMemory = false, const FilterT& filter = FilterT());
private:
template <typename AttributeT, typename GridT, typename FilterT>
void
performRasterization(
GridT& grid, RasterMode mode, const openvdb::Name& attribute,
bool reduceMemory, float scale, const FilterT& filter);
private:
FrustumRasterizerSettings mSettings;
FrustumRasterizerMask mMask;
util::NullInterrupter* mInterrupter;
std::vector<GridToRasterize> mPointGrids;
}; // class FrustumRasterizer
/// @brief A struct that stores all include/exclude attribute names as strings
/// and is internally converted into the resolved MultiGroupFilter
struct RasterGroups
{
std::vector<Name> includeNames;
std::vector<Name> excludeNames;
}; // class RasterGroups
} // namespace points
} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb
#include "impl/PointRasterizeFrustumImpl.h"
#endif // OPENVDB_POINTS_POINT_RASTERIZE_FRUSTUM_HAS_BEEN_INCLUDED
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::v10_0::GridBase::Ptr
SharedPtr< GridBase > Ptr
Definition Grid.h:80
openvdb::v10_0::Grid< MaskTree >::Ptr
SharedPtr< Grid > Ptr
Definition Grid.h:573
openvdb::v10_0::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:249
openvdb::v10_0::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:25
openvdb::v10_0::math::Transform
Definition Transform.h:40
openvdb::v10_0::math::Transform::Ptr
SharedPtr< Transform > Ptr
Definition Transform.h:42
openvdb::v10_0::points::FrustumRasterizer::GridConstPtr
typename PointDataGridT::ConstPtr GridConstPtr
Definition PointRasterizeFrustum.h:167
openvdb::v10_0::points::FrustumRasterizer::memUsage
size_t memUsage() const
Return memory usage of the rasterizer.
Definition PointRasterizeFrustumImpl.h:1315
openvdb::v10_0::points::FrustumRasterizer::GridToRasterize
point_rasterize_internal::GridToRasterize< PointDataGridT > GridToRasterize
Definition PointRasterizeFrustum.h:168
openvdb::v10_0::points::FrustumRasterizer::size
size_t size() const
Return number of PointDataGrids in the rasterizer.
Definition PointRasterizeFrustumImpl.h:1308
openvdb::v10_0::points::FrustumRasterizer::FrustumRasterizer
FrustumRasterizer(const FrustumRasterizerSettings &settings, const FrustumRasterizerMask &mask=FrustumRasterizerMask(), util::NullInterrupter *interrupt=nullptr)
main constructor
Definition PointRasterizeFrustumImpl.h:1265
openvdb::v10_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::v10_0::points::FrustumRasterizer::addPoints
void addPoints(GridConstPtr &points)
Append a PointDataGrid to the rasterizer (but don't rasterize yet).
Definition PointRasterizeFrustumImpl.h:1280
openvdb::v10_0::points::FrustumRasterizer::rasterizeMask
GridT::Ptr rasterizeMask(bool reduceMemory=false, const FilterT &filter=FilterT())
Definition PointRasterizeFrustumImpl.h:1440
openvdb::v10_0::points::FrustumRasterizer::GridPtr
typename PointDataGridT::Ptr GridPtr
Definition PointRasterizeFrustum.h:166
openvdb::v10_0::points::FrustumRasterizer::clear
void clear()
Clear all PointDataGrids in the rasterizer.
Definition PointRasterizeFrustumImpl.h:1301
openvdb::v10_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::v10_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::v10_0::points::RasterCamera
A camera class that provides an interface for camera motion blur when rasterizing.
Definition PointRasterizeFrustum.h:39
openvdb::v10_0::points::RasterCamera::weight
float weight(Index i) const
Definition PointRasterizeFrustumImpl.h:1126
openvdb::v10_0::points::RasterCamera::simplify
void simplify()
Definition PointRasterizeFrustumImpl.h:1089
openvdb::v10_0::points::RasterCamera::transform
const math::Transform & transform(Index i) const
Definition PointRasterizeFrustumImpl.h:1136
openvdb::v10_0::points::RasterCamera::size
size_t size() const
Definition PointRasterizeFrustumImpl.h:1084
openvdb::v10_0::points::RasterCamera::firstTransform
const math::Transform & firstTransform() const
Definition PointRasterizeFrustumImpl.h:1146
openvdb::v10_0::points::RasterCamera::isStatic
bool isStatic() const
Definition PointRasterizeFrustumImpl.h:1067
openvdb::v10_0::points::RasterCamera::setShutter
void setShutter(float start, float end)
Definition PointRasterizeFrustumImpl.h:1158
openvdb::v10_0::points::RasterCamera::appendTransform
void appendTransform(const math::Transform &, float weight=1.0f)
Definition PointRasterizeFrustumImpl.h:1078
openvdb::v10_0::points::RasterCamera::shutterEnd
float shutterEnd() const
Definition PointRasterizeFrustumImpl.h:1169
openvdb::v10_0::points::RasterCamera::hasWeight
bool hasWeight(Index i) const
Definition PointRasterizeFrustumImpl.h:1119
openvdb::v10_0::points::RasterCamera::RasterCamera
RasterCamera(const math::Transform &transform)
Definition PointRasterizeFrustumImpl.h:1063
openvdb::v10_0::points::RasterCamera::clear
void clear()
Definition PointRasterizeFrustumImpl.h:1072
openvdb::v10_0::points::RasterCamera::lastTransform
const math::Transform & lastTransform() const
Definition PointRasterizeFrustumImpl.h:1152
openvdb::v10_0::points::RasterCamera::shutterStart
float shutterStart() const
Definition PointRasterizeFrustumImpl.h:1164
openvdb::v10_0::points::point_rasterize_internal::GridToRasterize
Definition PointRasterizeFrustum.h:142
openvdb::v10_0::tree::Tree::ConstPtr
SharedPtr< const Tree > ConstPtr
Definition Tree.h:181
openvdb::v10_0::tree::ValueAccessor
Definition ValueAccessor.h:191
openvdb::v10_0::math
Definition Types.h:28
openvdb::v10_0::points::point_rasterize_internal
Definition PointRasterizeFrustum.h:139
openvdb::v10_0::points
Definition AttributeArray.h:41
openvdb::v10_0::points::RasterMode
RasterMode
How to composite points into a volume.
Definition PointRasterizeFrustum.h:30
openvdb::v10_0::points::RasterMode::MAXIMUM
@ MAXIMUM
Definition PointRasterizeFrustum.h:32
openvdb::v10_0::points::RasterMode::AVERAGE
@ AVERAGE
Definition PointRasterizeFrustum.h:33
openvdb::v10_0::points::RasterMode::ACCUMULATE
@ ACCUMULATE
Definition PointRasterizeFrustum.h:31
openvdb::v10_0::Name
std::string Name
Definition Name.h:17
openvdb::v10_0::Index
Index32 Index
Definition Types.h:54
openvdb::v10_0::BBoxd
math::BBox< Vec3d > BBoxd
Definition Types.h:84
openvdb::v10_0::MaskGrid
Grid< MaskTree > MaskGrid
Definition openvdb.h:78
openvdb
Definition Exceptions.h:13
Ray.h
A Ray class.
openvdb::v10_0::points::FrustumRasterizerMask
Definition PointRasterizeFrustum.h:112
openvdb::v10_0::points::FrustumRasterizerMask::FrustumRasterizerMask
FrustumRasterizerMask()=default
openvdb::v10_0::points::FrustumRasterizerMask::valid
bool valid(const Coord &ijk, AccessorT *acc) const
Definition PointRasterizeFrustumImpl.h:1252
openvdb::v10_0::points::FrustumRasterizerMask::AccessorT
const tree::ValueAccessor< const MaskTree > AccessorT
Definition PointRasterizeFrustum.h:113
openvdb::v10_0::points::FrustumRasterizerMask::getTreePtr
MaskTree::ConstPtr getTreePtr() const
Definition PointRasterizeFrustumImpl.h:1240
openvdb::v10_0::points::FrustumRasterizerMask::clipBBox
const CoordBBox & clipBBox() const
Definition PointRasterizeFrustumImpl.h:1246
openvdb::v10_0::points::FrustumRasterizerSettings
A group of shared settings to be used in the Volume Rasterizer.
Definition PointRasterizeFrustum.h:87
openvdb::v10_0::points::FrustumRasterizerSettings::motionSamples
int motionSamples
Definition PointRasterizeFrustum.h:107
openvdb::v10_0::points::FrustumRasterizerSettings::accurateFrustumRadius
bool accurateFrustumRadius
Definition PointRasterizeFrustum.h:98
openvdb::v10_0::points::FrustumRasterizerSettings::useRadius
bool useRadius
Definition PointRasterizeFrustum.h:97
openvdb::v10_0::points::FrustumRasterizerSettings::FrustumRasterizerSettings
FrustumRasterizerSettings()=delete
openvdb::v10_0::points::FrustumRasterizerSettings::threshold
float threshold
Definition PointRasterizeFrustum.h:102
openvdb::v10_0::points::FrustumRasterizerSettings::radiusScale
float radiusScale
Definition PointRasterizeFrustum.h:103
openvdb::v10_0::points::FrustumRasterizerSettings::transform
math::Transform::Ptr transform
Definition PointRasterizeFrustum.h:94
openvdb::v10_0::points::FrustumRasterizerSettings::velocityAttribute
Name velocityAttribute
Definition PointRasterizeFrustum.h:105
openvdb::v10_0::points::FrustumRasterizerSettings::velocityMotionBlur
bool velocityMotionBlur
Definition PointRasterizeFrustum.h:100
openvdb::v10_0::points::FrustumRasterizerSettings::accurateSphereMotionBlur
bool accurateSphereMotionBlur
Definition PointRasterizeFrustum.h:99
openvdb::v10_0::points::FrustumRasterizerSettings::threaded
bool threaded
Definition PointRasterizeFrustum.h:101
openvdb::v10_0::points::FrustumRasterizerSettings::framesPerSecond
float framesPerSecond
Definition PointRasterizeFrustum.h:104
openvdb::v10_0::points::FrustumRasterizerSettings::camera
RasterCamera camera
Definition PointRasterizeFrustum.h:95
openvdb::v10_0::points::FrustumRasterizerSettings::FrustumRasterizerSettings
FrustumRasterizerSettings(const math::Transform &_transform)
Definition PointRasterizeFrustum.h:90
openvdb::v10_0::points::FrustumRasterizerSettings::scaleByVoxelVolume
bool scaleByVoxelVolume
Definition PointRasterizeFrustum.h:96
openvdb::v10_0::points::FrustumRasterizerSettings::radiusAttribute
Name radiusAttribute
Definition PointRasterizeFrustum.h:106
openvdb::v10_0::points::RasterGroups
A struct that stores all include/exclude attribute names as strings and is internally converted into ...
Definition PointRasterizeFrustum.h:241
openvdb::v10_0::points::RasterGroups::excludeNames
std::vector< Name > excludeNames
Definition PointRasterizeFrustum.h:243
openvdb::v10_0::points::RasterGroups::includeNames
std::vector< Name > includeNames
Definition PointRasterizeFrustum.h:242
openvdb::v10_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:212