HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cylinderMeshGenerator.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_GEOM_UTIL_CYLINDER_MESH_GENERATOR_H
8 #define PXR_IMAGING_GEOM_UTIL_CYLINDER_MESH_GENERATOR_H
9 
13 
14 #include "pxr/pxr.h"
15 
17 
18 class GfMatrix4d;
19 class PxOsdMeshTopology;
20 
21 /// This class provides an implementation for generating topology, point
22 /// positions and surface normals on a cylinder with a given radius and height.
23 /// The cylinder is made up of circular cross-sections in the XY plane and is
24 /// centered at the origin. Each cross-section has numRadial segments. The
25 /// height is aligned with the Z axis, with the base at Z = -h/2.
26 ///
27 /// An optional transform may be provided to GeneratePoints and GenerateNormals
28 /// to orient the cylinder as necessary (e.g., whose height is aligned with the
29 /// Y axis).
30 ///
31 /// An additional overload of GeneratePoints is provided to specify different
32 /// radii for the bottom and top discs of the cylinder and a sweep angle for
33 /// cylinder about the +Z axis. When the sweep is less than 360 degrees, the
34 /// generated geometry is not closed.
35 ///
36 /// \note Setting one radius to 0 in order to get a cone is inefficient and
37 /// could result in artifacts. Clients should use
38 /// GeomUtilConeMeshGenerator instead.
39 ///
40 /// Usage:
41 /// \code{.cpp}
42 ///
43 /// const size_t numRadial = 8;
44 /// const size_t numPoints =
45 /// GeomUtilCylinderMeshGenerator::ComputeNumPoints(numRadial);
46 /// const float radius = 1, height = 2;
47 ///
48 /// MyPointContainer<GfVec3f> points(numPoints);
49 ///
50 /// GeomUtilCylinderMeshGenerator::GeneratePoints(
51 /// points.begin(), numRadial, radius, height);
52 ///
53 /// const size_t numNormals =
54 /// GeomUtilCylinderMeshGenerator::ComputeNumNormals(numRadial);
55 ///
56 /// MyPointContainer<GfVec3f> normals(numNormals);
57 ///
58 /// GeomUtilCylinderMeshGenerator::GenerateNormals(
59 /// normals.begin(), numRadial, radius, height);
60 ///
61 /// \endcode
62 ///
65 {
66 public:
67  static constexpr size_t minNumRadial = 3;
68 
70  static size_t ComputeNumPoints(
71  const size_t numRadial,
72  const bool closedSweep = true);
73 
74  static size_t ComputeNumNormals(
75  const size_t numRadial,
76  const bool closedSweep = true)
77  {
78  // Normals are per point.
79  return ComputeNumPoints(numRadial, closedSweep);
80  }
81 
83  {
84  // Normals are per point.
85  return GeomUtilInterpolationTokens->vertex;
86  }
87 
90  const size_t numRadial,
91  const bool closedSweep = true);
92 
93  template<typename PointIterType,
94  typename ScalarType,
95  typename Enabled =
97  static void GeneratePoints(
98  PointIterType iter,
99  const size_t numRadial,
100  const ScalarType radius,
101  const ScalarType height,
102  const GfMatrix4d* framePtr = nullptr)
103  {
104  GeneratePoints(iter, numRadial,
105  /* bottomRadius = */ radius,
106  /* topRadius = */ radius,
107  height, framePtr);
108  }
109 
110  template<typename PointIterType,
111  typename ScalarType,
112  typename Enabled =
114  static void GeneratePoints(
115  PointIterType iter,
116  const size_t numRadial,
117  const ScalarType bottomRadius,
118  const ScalarType topRadius,
119  const ScalarType height,
120  const GfMatrix4d* framePtr = nullptr)
121  {
122  constexpr ScalarType sweep = 360;
123 
124  GeneratePoints(iter, numRadial,
125  bottomRadius, topRadius,
126  height, sweep, framePtr);
127  }
128 
129  template<typename PointIterType,
130  typename ScalarType,
131  typename Enabled =
133  static void GeneratePoints(
134  PointIterType iter,
135  const size_t numRadial,
136  const ScalarType bottomRadius,
137  const ScalarType topRadius,
138  const ScalarType height,
139  const ScalarType sweepDegrees,
140  const GfMatrix4d* framePtr = nullptr)
141  {
142  using PointType =
144 
145  _GeneratePointsImpl(numRadial, bottomRadius, topRadius, height,
146  sweepDegrees,
147  framePtr ? _PointWriter<PointType>(iter, framePtr)
148  : _PointWriter<PointType>(iter));
149  }
150 
152 
153  template<typename PointIterType,
154  typename ScalarType,
155  typename Enabled =
157  static void GenerateNormals(
158  PointIterType iter,
159  const size_t numRadial,
160  const ScalarType radius,
161  const ScalarType height,
162  const GfMatrix4d* framePtr = nullptr)
163  {
164  GenerateNormals(iter, numRadial,
165  /* bottomRadius = */ radius,
166  /* topRadius = */ radius,
167  height, framePtr);
168  }
169 
170  template<typename PointIterType,
171  typename ScalarType,
172  typename Enabled =
174  static void GenerateNormals(
175  PointIterType iter,
176  const size_t numRadial,
177  const ScalarType bottomRadius,
178  const ScalarType topRadius,
179  const ScalarType height,
180  const GfMatrix4d* framePtr = nullptr)
181  {
182  constexpr ScalarType sweep = 360;
183  GenerateNormals(iter, numRadial,
184  bottomRadius, topRadius,
185  height, sweep, framePtr);
186  }
187 
188  template<typename PointIterType,
189  typename ScalarType,
190  typename Enabled =
192  static void GenerateNormals(
193  PointIterType iter,
194  const size_t numRadial,
195  const ScalarType bottomRadius,
196  const ScalarType topRadius,
197  const ScalarType height,
198  const ScalarType sweepDegrees,
199  const GfMatrix4d* framePtr = nullptr)
200  {
201  using PointType =
203 
204  _GenerateNormalsImpl(numRadial, bottomRadius, topRadius, height,
205  sweepDegrees,
206  framePtr ? _PointWriter<PointType>(iter, framePtr)
207  : _PointWriter<PointType>(iter));
208  }
209 
211 
212 private:
213 
214  template<typename PointType>
215  static void _GeneratePointsImpl(
216  const size_t numRadial,
217  const typename PointType::ScalarType bottomRadius,
218  const typename PointType::ScalarType topRadius,
219  const typename PointType::ScalarType height,
220  const typename PointType::ScalarType sweepDegrees,
221  const _PointWriter<PointType>& ptWriter);
222 
223  template<typename PointType>
224  static void _GenerateNormalsImpl(
225  const size_t numRadial,
226  const typename PointType::ScalarType bottomRadius,
227  const typename PointType::ScalarType topRadius,
228  const typename PointType::ScalarType height,
229  const typename PointType::ScalarType sweep,
230  const _PointWriter<PointType>& ptWriter);
231 };
232 
234 
235 #endif // PXR_IMAGING_GEOM_UTIL_CYLINDER_MESH_GENERATOR_H
type
Definition: core.h:556
static void GeneratePoints(PointIterType iter, const size_t numRadial, const ScalarType bottomRadius, const ScalarType topRadius, const ScalarType height, const ScalarType sweepDegrees, const GfMatrix4d *framePtr=nullptr)
static void GeneratePoints(PointIterType iter, const size_t numRadial, const ScalarType radius, const ScalarType height, const GfMatrix4d *framePtr=nullptr)
static GEOMUTIL_API size_t ComputeNumPoints(const size_t numRadial, const bool closedSweep=true)
static void GeneratePoints(PointIterType iter, const size_t numRadial, const ScalarType bottomRadius, const ScalarType topRadius, const ScalarType height, const GfMatrix4d *framePtr=nullptr)
uint64 value_type
Definition: GA_PrimCompat.h:29
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
Definition: token.h:70
static constexpr size_t minNumRadial
#define GEOMUTIL_API
Definition: api.h:23
static size_t ComputeNumNormals(const size_t numRadial, const bool closedSweep=true)
static GEOMUTIL_API PxOsdMeshTopology GenerateTopology(const size_t numRadial, const bool closedSweep=true)
static void GeneratePoints(PointIterType iter,...)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static void GenerateNormals(PointIterType iter, const size_t numRadial, const ScalarType bottomRadius, const ScalarType topRadius, const ScalarType height, const ScalarType sweepDegrees, const GfMatrix4d *framePtr=nullptr)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static void GenerateNormals(PointIterType iter, const size_t numRadial, const ScalarType radius, const ScalarType height, const GfMatrix4d *framePtr=nullptr)
static void GenerateNormals(PointIterType iter,...)
static void GenerateNormals(PointIterType iter, const size_t numRadial, const ScalarType bottomRadius, const ScalarType topRadius, const ScalarType height, const GfMatrix4d *framePtr=nullptr)