OpenVDB: openvdb/tools/LevelSetTubes.h Source File

OpenVDB 12.1.1

Loading...
Searching...
No Matches
LevelSetTubes.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 Greg Hurst
5///
6/// @file LevelSetTubes.h
7///
8/// @brief Generate a narrow-band level set of a capsule, tapered capsule, and tube complex.
9///
10/// @note By definition a level set has a fixed narrow band width
11/// (the half width is defined by LEVEL_SET_HALF_WIDTH in Types.h),
12/// whereas an SDF can have a variable narrow band width.
13
14#ifndef OPENVDB_TOOLS_LEVELSETTUBES_HAS_BEEN_INCLUDED
15#define OPENVDB_TOOLS_LEVELSETTUBES_HAS_BEEN_INCLUDED
16
17#include <openvdb/Grid.h>
18#include <openvdb/openvdb.h>
19#include <openvdb/math/Math.h>
20#include <openvdb/util/NullInterrupter.h>
21
22#include <vector>
23
24
25namespace openvdb {
26 OPENVDB_USE_VERSION_NAMESPACE
27namespace OPENVDB_VERSION_NAME {
28namespace tools {
29
30/// @brief Return a grid of type @c GridType containing a narrow-band level set
31/// representation of a capsule (tube with constant radius and sphere caps).
32///
33/// @param pt1 First capsule endpoint in world units.
34/// @param pt2 Second capsule endpoint in world units.
35/// @param radius Radius of the capsule in world units.
36/// @param voxelSize Voxel size in world units.
37/// @param halfWidth Half the width of the narrow band, in voxel units.
38/// @param interrupter Interrupter adhering to the util::NullInterrupter interface.
39/// @param threaded If true multi-threading is enabled (true by default).
40///
41/// @note @c GridType::ValueType must be a floating-point scalar.
42/// @note @c ScalarType represents the capsule endpoint and radius type
43/// and must be a floating-point scalar.
44template <typename GridType, typename ScalarType, typename InterruptT>
45typename GridType::Ptr
46 createLevelSetCapsule(const math::Vec3<ScalarType>& pt1, const math::Vec3<ScalarType>& pt2,
47 ScalarType radius, float voxelSize, float halfWidth = float(LEVEL_SET_HALF_WIDTH),
48 InterruptT* interrupter = nullptr, bool threaded = true);
49
50/// @brief Return a grid of type @c GridType containing a narrow-band level set
51/// representation of a capsule (tube with constant radius and sphere caps).
52///
53/// @param pt1 First capsule endpoint in world units.
54/// @param pt2 Second capsule endpoint in world units.
55/// @param radius Radius of the capsule in world units.
56/// @param voxelSize Voxel size in world units.
57/// @param halfWidth Half the width of the narrow band, in voxel units.
58/// @param threaded If true multi-threading is enabled (true by default).
59///
60/// @note @c GridType::ValueType must be a floating-point scalar.
61/// @note @c ScalarType represents the capsule endpoint and radius type
62/// and must be a floating-point scalar.
63template <typename GridType, typename ScalarType>
64typename GridType::Ptr
65 createLevelSetCapsule(const math::Vec3<ScalarType>& pt1, const math::Vec3<ScalarType>& pt2,
66 ScalarType radius, float voxelSize, float halfWidth = float(LEVEL_SET_HALF_WIDTH),
67 bool threaded = true);
68
69
70/// @brief Return a grid of type @c GridType containing a narrow-band level set
71/// representation of a tapered capsule (tube with sphere caps and different radii at both ends,
72/// or equivalently the convex hull of two spheres with possibly different centers and radii).
73///
74/// @param pt1 First tapered capsule endpoint in world units.
75/// @param pt2 Second tapered capsule endpoint in world units.
76/// @param radius1 Radius of the tapered capsule at @c pt1 in world units.
77/// @param radius2 Radius of the tapered capsule at @c pt2 in world units.
78/// @param voxelSize Voxel size in world units.
79/// @param halfWidth Half the width of the narrow band, in voxel units.
80/// @param interrupter Interrupter adhering to the util::NullInterrupter interface.
81/// @param threaded If true multi-threading is enabled (true by default).
82///
83/// @note @c GridType::ValueType must be a floating-point scalar.
84/// @note @c ScalarType represents the tapered capsule endpoint and radius type
85/// and must be a floating-point scalar.
86template <typename GridType, typename ScalarType, typename InterruptT>
87typename GridType::Ptr
88 createLevelSetTaperedCapsule(const math::Vec3<ScalarType>& pt1, const math::Vec3<ScalarType>& pt2,
89 ScalarType radius1, ScalarType radius2,
90 float voxelSize, float halfWidth = float(LEVEL_SET_HALF_WIDTH),
91 InterruptT* interrupter = nullptr, bool threaded = true);
92
93/// @brief Return a grid of type @c GridType containing a narrow-band level set
94/// representation of a tapered capsule (tube with sphere caps and different radii at both ends,
95/// or equivalently the convex hull of two spheres with possibly different centers and radii).
96///
97/// @param pt1 First tapered capsule endpoint in world units.
98/// @param pt2 Second tapered capsule endpoint in world units.
99/// @param radius1 Radius of the tapered capsule at @c pt1 in world units.
100/// @param radius2 Radius of the tapered capsule at @c pt2 in world units.
101/// @param voxelSize Voxel size in world units.
102/// @param halfWidth Half the width of the narrow band, in voxel units.
103/// @param threaded If true multi-threading is enabled (true by default).
104///
105/// @note @c GridType::ValueType must be a floating-point scalar.
106/// @note @c ScalarType represents the tapered capsule endpoint and radius type
107/// and must be a floating-point scalar.
108template <typename GridType, typename ScalarType>
109typename GridType::Ptr
110 createLevelSetTaperedCapsule(const math::Vec3<ScalarType>& pt1, const math::Vec3<ScalarType>& pt2,
111 ScalarType radius1, ScalarType radius2, float voxelSize,
112 float halfWidth = float(LEVEL_SET_HALF_WIDTH), bool threaded = true);
113
114/// @brief Different policies when creating a tube complex with varying radii
115/// @details
116/// <dl>
117/// <dt><b>TUBE_VERTEX_RADII</b>
118/// <dd>Specify that the tube complex radii are per-vertex,
119/// meaning each tube has different radii at its two endpoints
120/// and the complex is a collection of tapered capsules.
121///
122/// <dt><b>TUBE_SEGMENT_RADII</b>
123/// <dd>Specify that the tube complex radii are per-segment,
124/// meaning each tube has a constant radius and the complex is a collection of capsules.
125///
126/// <dt><b>TUBE_AUTOMATIC</b>
127/// <dd>Specify that the only valid setting is to be chosen,
128/// defaulting to the per-vertex policy if both are valid.
129/// </dl>
130 enum TubeRadiiPolicy { TUBE_AUTOMATIC = 0, TUBE_VERTEX_RADII, TUBE_SEGMENT_RADII };
131
132/// @brief Return a grid of type @c GridType containing a narrow-band level set
133/// representation of a tube complex (a collection of capsules defined by endpoint coordinates and segment indices).
134///
135/// @param vertices Endpoint vertices in the tube complex in world units.
136/// @param segments Segment indices in the tube complex.
137/// @param radius Radius of all tubes in world units.
138/// @param voxelSize Voxel size in world units.
139/// @param halfWidth Half the width of the narrow band, in voxel units.
140/// @param interrupter Interrupter adhering to the util::NullInterrupter interface.
141///
142/// @note @c GridType::ValueType must be a floating-point scalar.
143/// @note @c ScalarType represents the capsule complex vertex and radius type
144/// and must be a floating-point scalar.
145template <typename GridType, typename ScalarType, typename InterruptT = util::NullInterrupter>
146typename GridType::Ptr
147createLevelSetTubeComplex(const std::vector<math::Vec3<ScalarType>>& vertices,
148 const std::vector<Vec2I>& segments, ScalarType radius, float voxelSize,
149 float halfWidth = float(LEVEL_SET_HALF_WIDTH), InterruptT* interrupter = nullptr);
150
151/// @brief Return a grid of type @c GridType containing a narrow-band level set
152/// representation of a tube complex (a collection of tubes defined by endpoint coordinates, segment indices, and radii).
153///
154/// @param vertices Endpoint vertices in the tube complex in world units.
155/// @param segments Segment indices in the tube complex.
156/// @param radii Radii specification for all tubes in world units.
157/// @param voxelSize Voxel size in world units.
158/// @param halfWidth Half the width of the narrow band, in voxel units.
159/// @param TubeRadiiPolicy Policies: per-segment, per-vertex, or automatic (default).
160/// @param interrupter Interrupter adhering to the util::NullInterrupter interface.
161///
162/// @note @c GridType::ValueType must be a floating-point scalar.
163/// @note @c ScalarType represents the capsule complex vertex and radius type
164/// and must be a floating-point scalar.
165/// @note The automatic @c TubeRadiiPolicy chooses the valid per-segment or per-vertex policy,
166/// defaulting to per-vertex if both are valid.
167template <typename GridType, typename ScalarType, typename InterruptT = util::NullInterrupter>
168typename GridType::Ptr
169createLevelSetTubeComplex(const std::vector<math::Vec3<ScalarType>>& vertices,
170 const std::vector<Vec2I>& segments, const std::vector<ScalarType>& radii, float voxelSize,
171 float halfWidth = float(LEVEL_SET_HALF_WIDTH), TubeRadiiPolicy radii_policy = TUBE_AUTOMATIC,
172 InterruptT* interrupter = nullptr);
173
174
175////////////////////////////////////////
176
177
178// Explicit Template Instantiation
179
180#ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
181
182#ifdef OPENVDB_INSTANTIATE_LEVELSETTUBES
183#include <openvdb/util/ExplicitInstantiation.h>
184#endif
185
186#define _FUNCTION(TreeT) \
187 Grid<TreeT>::Ptr createLevelSetTubeComplex<Grid<TreeT>>(const std::vector<Vec3s>&, \
188 const std::vector<Vec2I>&, float, float, float, util::NullInterrupter*)
189 OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION)
190#undef _FUNCTION
191
192#define _FUNCTION(TreeT) \
193 Grid<TreeT>::Ptr createLevelSetTubeComplex<Grid<TreeT>>(const std::vector<Vec3s>&, \
194 const std::vector<Vec2I>&, const std::vector<float>&, float, float, TubeRadiiPolicy, \
195 util::NullInterrupter*)
196 OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION)
197#undef _FUNCTION
198
199#define _FUNCTION(TreeT) \
200 Grid<TreeT>::Ptr createLevelSetCapsule<Grid<TreeT>>(const Vec3s&, const Vec3s&, \
201 float, float, float, util::NullInterrupter*, bool)
202 OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION)
203#undef _FUNCTION
204
205#define _FUNCTION(TreeT) \
206 Grid<TreeT>::Ptr createLevelSetTaperedCapsule<Grid<TreeT>>(const Vec3s&, const Vec3s&, \
207 float, float, float, float, util::NullInterrupter*, bool)
208 OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION)
209#undef _FUNCTION
210
211#endif // OPENVDB_USE_EXPLICIT_INSTANTIATION
212
213} // namespace tools
214} // namespace OPENVDB_VERSION_NAME
215} // namespace openvdb
216
217#include "impl/LevelSetTubesImpl.h"
218
219#endif // OPENVDB_TOOLS_LEVELSETTUBES_HAS_BEEN_INCLUDED
ExplicitInstantiation.h
Grid.h
LevelSetTubesImpl.h
Generate a narrow-band level set of a capsule, tapered capsule, and tube complex.
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
NullInterrupter.h
openvdb::v12_1::math::Vec3
Definition Vec3.h:25
openvdb::v12_1::tools::createLevelSetCapsule
GridType::Ptr createLevelSetCapsule(const math::Vec3< ScalarType > &pt1, const math::Vec3< ScalarType > &pt2, ScalarType radius, float voxelSize, float halfWidth=float(LEVEL_SET_HALF_WIDTH), InterruptT *interrupter=nullptr, bool threaded=true)
Return a grid of type GridType containing a narrow-band level set representation of a capsule (tube w...
Definition LevelSetTubesImpl.h:1398
openvdb::v12_1::tools::createLevelSetTaperedCapsule
GridType::Ptr createLevelSetTaperedCapsule(const math::Vec3< ScalarType > &pt1, const math::Vec3< ScalarType > &pt2, ScalarType radius1, ScalarType radius2, float voxelSize, float halfWidth=float(LEVEL_SET_HALF_WIDTH), InterruptT *interrupter=nullptr, bool threaded=true)
Return a grid of type GridType containing a narrow-band level set representation of a tapered capsule...
Definition LevelSetTubesImpl.h:1437
openvdb::v12_1::tools::TubeRadiiPolicy
TubeRadiiPolicy
Different policies when creating a tube complex with varying radii.
Definition LevelSetTubes.h:130
openvdb::v12_1::tools::TUBE_VERTEX_RADII
@ TUBE_VERTEX_RADII
Definition LevelSetTubes.h:130
openvdb::v12_1::tools::TUBE_AUTOMATIC
@ TUBE_AUTOMATIC
Definition LevelSetTubes.h:130
openvdb::v12_1::tools::TUBE_SEGMENT_RADII
@ TUBE_SEGMENT_RADII
Definition LevelSetTubes.h:130
openvdb::v12_1::LEVEL_SET_HALF_WIDTH
static const Real LEVEL_SET_HALF_WIDTH
Definition Types.h:532
openvdb
Definition Exceptions.h:13
openvdb.h
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
OPENVDB_REAL_TREE_INSTANTIATE
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition version.h.in:162