OpenVDB 13.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: Apache-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#include <openvdb/util/Assert.h>
17
18#include "PointDataGrid.h"
19#include "PointAttribute.h"
20
21#include <sstream>
22#include <type_traits>
23
24 namespace openvdb {
25 OPENVDB_USE_VERSION_NAMESPACE
26 namespace OPENVDB_VERSION_NAME {
27 namespace points {
28
29/// @brief Performs closest point sampling from a VDB grid onto a VDB Points attribute
30/// @param points the PointDataGrid whose points will be sampled on to
31/// @param sourceGrid VDB grid which will be sampled
32/// @param targetAttribute a target attribute on the points which will hold samples. This
33/// attribute will be created with the source grid type if it does
34/// not exist, and with the source grid name if the name is empty
35/// @param filter an optional index filter
36/// @param interrupter an optional interrupter
37/// @note The target attribute may exist provided it can be cast to the SourceGridT ValueType
38 template<typename PointDataGridT, typename SourceGridT,
39 typename FilterT = NullFilter, typename InterrupterT = util::NullInterrupter>
40 inline void pointSample(PointDataGridT& points,
41 const SourceGridT& sourceGrid,
42 const Name& targetAttribute = "",
43 const FilterT& filter = NullFilter(),
44 InterrupterT* const interrupter = nullptr);
45
46/// @brief Performs tri-linear sampling from a VDB grid onto a VDB Points attribute
47/// @param points the PointDataGrid whose points will be sampled on to
48/// @param sourceGrid VDB grid which will be sampled
49/// @param targetAttribute a target attribute on the points which will hold samples. This
50/// attribute will be created with the source grid type if it does
51/// not exist, and with the source grid name if the name is empty
52/// @param filter an optional index filter
53/// @param interrupter an optional interrupter
54/// @note The target attribute may exist provided it can be cast to the SourceGridT ValueType
55 template<typename PointDataGridT, typename SourceGridT,
56 typename FilterT = NullFilter, typename InterrupterT = util::NullInterrupter>
57 inline void boxSample( PointDataGridT& points,
58 const SourceGridT& sourceGrid,
59 const Name& targetAttribute = "",
60 const FilterT& filter = NullFilter(),
61 InterrupterT* const interrupter = nullptr);
62
63/// @brief Performs tri-quadratic sampling from a VDB grid onto a VDB Points attribute
64/// @param points the PointDataGrid whose points will be sampled on to
65/// @param sourceGrid VDB grid which will be sampled
66/// @param targetAttribute a target attribute on the points which will hold samples. This
67/// attribute will be created with the source grid type if it does
68/// not exist, and with the source grid name if the name is empty
69/// @param filter an optional index filter
70/// @param interrupter an optional interrupter
71/// @note The target attribute may exist provided it can be cast to the SourceGridT ValueType
72 template<typename PointDataGridT, typename SourceGridT,
73 typename FilterT = NullFilter, typename InterrupterT = util::NullInterrupter>
74 inline void quadraticSample(PointDataGridT& points,
75 const SourceGridT& sourceGrid,
76 const Name& targetAttribute = "",
77 const FilterT& filter = NullFilter(),
78 InterrupterT* const interrupter = nullptr);
79
80
81// This struct samples the source grid accessor using the world-space position supplied,
82// with SamplerT providing the sampling scheme. In the case where ValueT does not match
83// the value type of the source grid, the sample() method will also convert the sampled
84// value into a ValueT value, using round-to-nearest for float-to-integer conversion.
85 struct SampleWithRounding
86{
87 template<typename ValueT, typename SamplerT, typename AccessorT>
88 inline ValueT sample(const AccessorT& accessor, const Vec3d& position) const;
89};
90
91// A dummy struct that is used to mean that the sampled attribute should either match the type
92// of the existing attribute or the type of the source grid (if the attribute doesn't exist yet)
93 struct DummySampleType { };
94
95/// @brief Performs sampling and conversion from a VDB grid onto a VDB Points attribute
96/// @param order the sampling order - 0 = closest-point, 1 = trilinear, 2 = triquadratic
97/// @param points the PointDataGrid whose points will be sampled on to
98/// @param sourceGrid VDB grid which will be sampled
99/// @param targetAttribute a target attribute on the points which will hold samples. This
100/// attribute will be created with the source grid type if it does
101/// not exist, and with the source grid name if the name is empty
102/// @param filter an optional index filter
103/// @param sampler handles sampling and conversion into the target attribute type,
104/// which by default this uses the SampleWithRounding struct.
105/// @param interrupter an optional interrupter
106/// @param threaded enable or disable threading (threading is enabled by default)
107/// @note The target attribute may exist provided it can be cast to the SourceGridT ValueType
108 template<typename PointDataGridT, typename SourceGridT, typename TargetValueT = DummySampleType,
109 typename SamplerT = SampleWithRounding, typename FilterT = NullFilter,
110 typename InterrupterT = util::NullInterrupter>
111 inline void sampleGrid( size_t order,
112 PointDataGridT& points,
113 const SourceGridT& sourceGrid,
114 const Name& targetAttribute,
115 const FilterT& filter = NullFilter(),
116 const SamplerT& sampler = SampleWithRounding(),
117 InterrupterT* const interrupter = nullptr,
118 const bool threaded = true);
119
120} // namespace points
121} // namespace OPENVDB_VERSION_NAME
122} // namespace openvdb
123
124#include "impl/PointSampleImpl.h"
125
126#endif // OPENVDB_POINTS_POINT_SAMPLE_HAS_BEEN_INCLUDED
Assert.h
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::v13_0::points::NullFilter
A no-op filter that can be used when iterating over all indices.
Definition IndexIterator.h:52
openvdb::v13_0::math::Vec3d
Vec3< double > Vec3d
Definition Vec3.h:665
openvdb::v13_0::points
Definition AttributeArray.h:42
openvdb::v13_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::v13_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::v13_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::v13_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::v13_0::Name
std::string Name
Definition Name.h:19
openvdb
Definition Exceptions.h:13
openvdb::v13_0::points::DummySampleType
Definition PointSample.h:93
openvdb::v13_0::points::SampleWithRounding
Definition PointSample.h:86
openvdb::v13_0::points::SampleWithRounding::sample
ValueT sample(const AccessorT &accessor, const Vec3d &position) const
Definition PointSampleImpl.h:298
openvdb::v13_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