OpenVDB 14.0.0
Loading...
Searching...
No Matches
PointRasterizeTrilinear.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 Nick Avramoussis
5///
6/// @file PointRasterizeTrilinear.h
7///
8/// @brief Weighted trilinear rasterization of point data
9///
10
11#ifndef OPENVDB_POINTS_RASTERIZE_TRILINEAR_HAS_BEEN_INCLUDED
12#define OPENVDB_POINTS_RASTERIZE_TRILINEAR_HAS_BEEN_INCLUDED
13
14#include <openvdb/openvdb.h>
15#include <openvdb/Types.h>
16#include <openvdb/Grid.h>
17#include <openvdb/math/Math.h>
21#include <openvdb/util/Assert.h>
22#include <openvdb/simd/Simd.h>
23
24#include "PointDataGrid.h"
25#include "PointMask.h"
26#include "PointTransfer.h"
27
28#include <string>
29
30namespace openvdb {
32namespace OPENVDB_VERSION_NAME {
33namespace points {
34
35/// @brief Traits for staggered (MAC) trilinear rasterization. This method
36/// only works on scalar or Vec3 attribute types and only ever returns a Vec3
37/// tree. It is typically used for velocity rasterization in fluid
38/// simulations to avoid the pressure-velocity decoupling problem that occurs
39/// on collocated (cell-centered) grids. The resulting Vec3 tree effectively
40/// represents the velocity values on the cell faces rather than the cell
41/// centers.
42template <typename ValueT, bool Staggered = true>
44{
45private:
46 using FltT = typename types_internal::flt_t<sizeof(typename ValueTraits<ValueT>::ElementType)*CHAR_BIT>::type;
47 static_assert(ValueTraits<ValueT>::IsScalar ||
49 "Source attribute type must be scalar or Vec3 for staggered rasterization.");
50public:
51 /// @brief Resulting rasterized Tree ValueType (always Vec3)
53 /// @brief Resulting rasterized TreeType
54 template <typename PointDataTreeT>
55 using TreeT = typename PointDataTreeT::template ValueConverter<ResultT>::Type;
56};
57
58/// @brief Traits for collocated, cell-centered rasterization. Work for any
59/// scalar, vector or matrix attribute. Note that integer values are
60/// interpolated at their respective floating point precision and returned
61/// as trees at that precision.
62template <typename ValueT>
63struct TrilinearTraits<ValueT, false>
64{
65private:
66 using FltT = typename types_internal::flt_t<sizeof(typename ValueTraits<ValueT>::ElementType)*CHAR_BIT>::type;
67public:
68 /// @brief Resulting rasterized Tree ValueType
70 /// @brief Resulting rasterized TreeType
71 template <typename PointDataTreeT>
72 using TreeT = typename PointDataTreeT::template ValueConverter<ResultT>::Type;
73};
74
75/// @brief Perform weighted trilinear rasterization of all points within a
76/// voxel. This method takes and returns a tree i.e. ignores grid
77/// transformations.
78/// @details Accumulates values and weights according to a simple 0-1-0 weighted
79/// hat function. This algorithm is an exact inverse of a trilinear
80/// interpolation and thus a key method used in PIC/FLIP style simulations.
81/// Returns a tree of the same precision as the input source attribute, but
82/// may be of a different math type depending on the value of the Staggered
83/// template attribute. If Staggered is true, this method produces values at
84/// each voxels negative faces, causing scalar attributes to produce
85/// math::Vec3<ValueT> tree types. The result Tree type is equal to:
86/// TrilinearTraits<ValueT, Staggered>::template TreeT<PointDataTreeT>
87/// @tparam Staggered whether to perform a staggered or collocated rasterization
88/// @tparam ValueT the value type of the point attribute to rasterize
89/// @param points the point tree to be rasterized
90/// @param attribute the name of the attribute to rasterize. Must be a scalar
91/// or Vec3 attribute for Staggered rasterization. Otherwise, can be any
92/// scalar, Vector or Matrix type. Integer values are interpolated at their
93/// float bitwidth precision and returned as a tree at that precision e.g:
94/// int32 -> float, FloatTree.
95/// @param filter an optional point filter to use
96template <bool Staggered,
97 typename ValueT,
98 typename FilterT = NullFilter,
99 typename PointDataTreeT = PointDataTree>
100inline auto
101rasterizeTrilinear(const PointDataTreeT& points,
102 const std::string& attribute,
103 const FilterT& filter = NullFilter());
104
105} // namespace points
106} // namespace OPENVDB_VERSION_NAME
107} // namespace openvdb
108
109#include "impl/PointRasterizeTrilinearImpl.h"
110
111#endif //OPENVDB_POINTS_RASTERIZE_TRILINEAR_HAS_BEEN_INCLUDED
Implementation of morphological dilation and erosion.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Methods for extracting masks from VDB Point grids.
Framework methods for rasterizing PointDataGrid data to Trees.
ValueAccessors are designed to help accelerate accesses into the OpenVDB Tree structures by storing c...
Definition Vec3.h:25
A no-op filter that can be used when iterating over all indices.
Definition IndexIterator.h:52
Definition Grid.h:1187
auto rasterizeTrilinear(const PointDataTreeT &points, const std::string &attribute, const FilterT &filter=NullFilter())
Perform weighted trilinear rasterization of all points within a voxel. This method takes and returns ...
tree::Tree< tree::RootNode< tree::InternalNode< tree::InternalNode< PointDataLeafNode< PointDataIndex32, 3 >, 4 >, 5 > > > PointDataTree
Point index tree configured to match the default VDB configurations.
Definition PointDataGrid.h:68
Definition Exceptions.h:13
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
SubT Type
Definition Types.h:372
static const bool IsVec
Definition Types.h:348
static const int Size
Definition Types.h:352
typename T::ValueType ElementType
Definition Types.h:354
static const bool IsScalar
Definition Types.h:351
typename PointDataTreeT::template ValueConverter< ResultT >::Type TreeT
Resulting rasterized TreeType.
Definition PointRasterizeTrilinear.h:72
typename ConvertElementType< ValueT, FltT >::Type ResultT
Resulting rasterized Tree ValueType.
Definition PointRasterizeTrilinear.h:69
Traits for staggered (MAC) trilinear rasterization. This method only works on scalar or Vec3 attribut...
Definition PointRasterizeTrilinear.h:44
math::Vec3< FltT > ResultT
Resulting rasterized Tree ValueType (always Vec3)
Definition PointRasterizeTrilinear.h:52
typename PointDataTreeT::template ValueConverter< ResultT >::Type TreeT
Resulting rasterized TreeType.
Definition PointRasterizeTrilinear.h:55
#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:291