HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PointSample.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
4 /// @author Nick Avramoussis, Francisco Gochez, Dan Bailey
5 ///
6 /// @file points/PointSample.h
7 ///
8 /// @brief Sample a VDB Grid onto a VDB Points attribute
9 
10 #ifndef OPENVDB_POINTS_POINT_SAMPLE_HAS_BEEN_INCLUDED
11 #define OPENVDB_POINTS_POINT_SAMPLE_HAS_BEEN_INCLUDED
12 
16 
17 #include "PointDataGrid.h"
18 #include "PointAttribute.h"
19 
20 #include <sstream>
21 #include <type_traits>
22 
23 namespace openvdb {
25 namespace OPENVDB_VERSION_NAME {
26 namespace points {
27 
28 /// @brief Performs closest point sampling from a VDB grid onto a VDB Points attribute
29 /// @param points the PointDataGrid whose points will be sampled on to
30 /// @param sourceGrid VDB grid which will be sampled
31 /// @param targetAttribute a target attribute on the points which will hold samples. This
32 /// attribute will be created with the source grid type if it does
33 /// not exist, and with the source grid name if the name is empty
34 /// @param filter an optional index filter
35 /// @param interrupter an optional interrupter
36 /// @note The target attribute may exist provided it can be cast to the SourceGridT ValueType
37 template<typename PointDataGridT, typename SourceGridT,
38  typename FilterT = NullFilter, typename InterrupterT = util::NullInterrupter>
39 inline void pointSample(PointDataGridT& points,
40  const SourceGridT& sourceGrid,
41  const Name& targetAttribute = "",
42  const FilterT& filter = NullFilter(),
43  InterrupterT* const interrupter = nullptr);
44 
45 /// @brief Performs tri-linear sampling from a VDB grid onto a VDB Points attribute
46 /// @param points the PointDataGrid whose points will be sampled on to
47 /// @param sourceGrid VDB grid which will be sampled
48 /// @param targetAttribute a target attribute on the points which will hold samples. This
49 /// attribute will be created with the source grid type if it does
50 /// not exist, and with the source grid name if the name is empty
51 /// @param filter an optional index filter
52 /// @param interrupter an optional interrupter
53 /// @note The target attribute may exist provided it can be cast to the SourceGridT ValueType
54 template<typename PointDataGridT, typename SourceGridT,
55  typename FilterT = NullFilter, typename InterrupterT = util::NullInterrupter>
56 inline void boxSample( PointDataGridT& points,
57  const SourceGridT& sourceGrid,
58  const Name& targetAttribute = "",
59  const FilterT& filter = NullFilter(),
60  InterrupterT* const interrupter = nullptr);
61 
62 /// @brief Performs tri-quadratic sampling from a VDB grid onto a VDB Points attribute
63 /// @param points the PointDataGrid whose points will be sampled on to
64 /// @param sourceGrid VDB grid which will be sampled
65 /// @param targetAttribute a target attribute on the points which will hold samples. This
66 /// attribute will be created with the source grid type if it does
67 /// not exist, and with the source grid name if the name is empty
68 /// @param filter an optional index filter
69 /// @param interrupter an optional interrupter
70 /// @note The target attribute may exist provided it can be cast to the SourceGridT ValueType
71 template<typename PointDataGridT, typename SourceGridT,
72  typename FilterT = NullFilter, typename InterrupterT = util::NullInterrupter>
73 inline void quadraticSample(PointDataGridT& points,
74  const SourceGridT& sourceGrid,
75  const Name& targetAttribute = "",
76  const FilterT& filter = NullFilter(),
77  InterrupterT* const interrupter = nullptr);
78 
79 
80 // This struct samples the source grid accessor using the world-space position supplied,
81 // with SamplerT providing the sampling scheme. In the case where ValueT does not match
82 // the value type of the source grid, the sample() method will also convert the sampled
83 // value into a ValueT value, using round-to-nearest for float-to-integer conversion.
85 {
86  template<typename ValueT, typename SamplerT, typename AccessorT>
87  inline ValueT sample(const AccessorT& accessor, const Vec3d& position) const;
88 };
89 
90 // A dummy struct that is used to mean that the sampled attribute should either match the type
91 // of the existing attribute or the type of the source grid (if the attribute doesn't exist yet)
92 struct DummySampleType { };
93 
94 /// @brief Performs sampling and conversion from a VDB grid onto a VDB Points attribute
95 /// @param order the sampling order - 0 = closest-point, 1 = trilinear, 2 = triquadratic
96 /// @param points the PointDataGrid whose points will be sampled on to
97 /// @param sourceGrid VDB grid which will be sampled
98 /// @param targetAttribute a target attribute on the points which will hold samples. This
99 /// attribute will be created with the source grid type if it does
100 /// not exist, and with the source grid name if the name is empty
101 /// @param filter an optional index filter
102 /// @param sampler handles sampling and conversion into the target attribute type,
103 /// which by default this uses the SampleWithRounding struct.
104 /// @param interrupter an optional interrupter
105 /// @param threaded enable or disable threading (threading is enabled by default)
106 /// @note The target attribute may exist provided it can be cast to the SourceGridT ValueType
107 template<typename PointDataGridT, typename SourceGridT, typename TargetValueT = DummySampleType,
108  typename SamplerT = SampleWithRounding, typename FilterT = NullFilter,
109  typename InterrupterT = util::NullInterrupter>
110 inline void sampleGrid( size_t order,
111  PointDataGridT& points,
112  const SourceGridT& sourceGrid,
113  const Name& targetAttribute,
114  const FilterT& filter = NullFilter(),
115  const SamplerT& sampler = SampleWithRounding(),
116  InterrupterT* const interrupter = nullptr,
117  const bool threaded = true);
118 
119 } // namespace points
120 } // namespace OPENVDB_VERSION_NAME
121 } // namespace openvdb
122 
123 #include "impl/PointSampleImpl.h"
124 
125 #endif // OPENVDB_POINTS_POINT_SAMPLE_HAS_BEEN_INCLUDED
Definition: ImfName.h:28
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:239
void pointSample(PointDataGridT &points, const SourceGridT &sourceGrid, const Name &targetAttribute, const FilterT &filter, InterrupterT *const interrupter)
Performs closest point sampling from a VDB grid onto a VDB Points attribute.
GLuint sampler
Definition: glcorearb.h:1656
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:50
void boxSample(PointDataGridT &points, const SourceGridT &sourceGrid, const Name &targetAttribute, const FilterT &filter, InterrupterT *const interrupter)
Performs tri-linear sampling from a VDB grid onto a VDB Points attribute.
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
void sampleGrid(size_t order, PointDataGridT &points, const SourceGridT &sourceGrid, const Name &targetAttribute, const FilterT &filter, const SamplerT &sampler, InterrupterT *const interrupter, const bool threaded)
Performs sampling and conversion from a VDB grid onto a VDB Points attribute.
Point attribute manipulation in a VDB Point Grid.
SIM_API const UT_StringHolder position
void quadraticSample(PointDataGridT &points, const SourceGridT &sourceGrid, const Name &targetAttribute, const FilterT &filter, InterrupterT *const interrupter)
Performs tri-quadratic sampling from a VDB grid onto a VDB Points attribute.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:119
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
ValueT sample(const AccessorT &accessor, const Vec3d &position) const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297