OpenVDB 11.0.0

Loading...
Searching...
No Matches
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
13#include <openvdb/util/NullInterrupter.h>
14#include <openvdb/thread/Threading.h>
15#include <openvdb/tools/Interpolation.h>
16
17#include "PointDataGrid.h"
18#include "PointAttribute.h"
19
20#include <sstream>
21#include <type_traits>
22
23 namespace openvdb {
24 OPENVDB_USE_VERSION_NAMESPACE
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.
84 struct SampleWithRounding
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
Interpolation.h
NullInterrupter.h
PointAttribute.h
Point attribute manipulation in a VDB Point Grid.
PointDataGrid.h
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
PointSampleImpl.h
openvdb::v11_0::points::NullFilter
A no-op filter that can be used when iterating over all indices.
Definition IndexIterator.h:51
openvdb::v11_0::points::sampleGrid
void sampleGrid(size_t order, PointDataGridT &points, const SourceGridT &sourceGrid, const Name &targetAttribute, const FilterT &filter=NullFilter(), const SamplerT &sampler=SampleWithRounding(), InterrupterT *const interrupter=nullptr, const bool threaded=true)
Performs sampling and conversion from a VDB grid onto a VDB Points attribute.
Definition PointSampleImpl.h:319
openvdb::v11_0::points::boxSample
void boxSample(PointDataGridT &points, const SourceGridT &sourceGrid, const Name &targetAttribute="", const FilterT &filter=NullFilter(), InterrupterT *const interrupter=nullptr)
Performs tri-linear sampling from a VDB grid onto a VDB Points attribute.
Definition PointSampleImpl.h:428
openvdb::v11_0::points::quadraticSample
void quadraticSample(PointDataGridT &points, const SourceGridT &sourceGrid, const Name &targetAttribute="", const FilterT &filter=NullFilter(), InterrupterT *const interrupter=nullptr)
Performs tri-quadratic sampling from a VDB grid onto a VDB Points attribute.
Definition PointSampleImpl.h:439
openvdb::v11_0::points::pointSample
void pointSample(PointDataGridT &points, const SourceGridT &sourceGrid, const Name &targetAttribute="", const FilterT &filter=NullFilter(), InterrupterT *const interrupter=nullptr)
Performs closest point sampling from a VDB grid onto a VDB Points attribute.
Definition PointSampleImpl.h:417
openvdb::v11_0::Name
std::string Name
Definition Name.h:19
openvdb
Definition Exceptions.h:13
openvdb::v11_0::points::DummySampleType
Definition PointSample.h:92
openvdb::v11_0::points::SampleWithRounding
Definition PointSample.h:85
openvdb::v11_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