HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
coneMeshGenerator.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_CONE_MESH_GENERATOR_H
8 #define PXR_IMAGING_GEOM_UTIL_CONE_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 cone of a given radius and height. The
23 /// cone is made up of circular cross-sections in the XY plane and is centered
24 /// at the origin. Each cross-section has numRadial segments. The height is
25 /// aligned with the Z axis, with the base of the object at Z = -h/2 and apex
26 /// at Z = h/2.
27 ///
28 /// An optional transform may be provided to GeneratePoints and GenerateNormals
29 /// to orient the cone as necessary (e.g., whose height is aligned with the
30 /// Y axis).
31 ///
32 /// An additional overload of GeneratePoints is provided to specify the sweep
33 /// angle for the cone about the +Z axis. When the sweep is less than 360
34 /// degrees, the generated geometry is not closed.
35 ///
36 /// Usage:
37 /// \code{.cpp}
38 ///
39 /// const size_t numRadial = 8;
40 /// const size_t numPoints =
41 /// GeomUtilConeMeshGenerator::ComputeNumPoints(numRadial);
42 /// const float radius = 1, height = 2;
43 ///
44 /// MyPointContainer<GfVec3f> points(numPoints);
45 ///
46 /// GeomUtilConeMeshGenerator::GeneratePoints(
47 /// points.begin(), numRadial, radius, height);
48 ///
49 /// const size_t numNormals =
50 /// GeomUtilConeMeshGenerator::ComputeNumNormals(numRadial);
51 ///
52 /// MyPointContainer<GfVec3f> normals(numNormals);
53 ///
54 /// GeomUtilConeMeshGenerator::GenerateNormals(
55 /// normals.begin(), numRadial, radius, height);
56 ///
57 /// \endcode
58 ///
61 {
62 public:
63  static constexpr size_t minNumRadial = 3;
64 
66  static size_t ComputeNumPoints(
67  const size_t numRadial,
68  const bool closedSweep = true);
69 
70  static size_t ComputeNumNormals(
71  const size_t numRadial,
72  const bool closedSweep = true)
73  {
74  // Normals are per point.
75  return ComputeNumPoints(numRadial, closedSweep);
76  }
77 
79  {
80  // Normals are per point.
81  return GeomUtilInterpolationTokens->vertex;
82  }
83 
86  const size_t numRadial,
87  const bool closedSweep = true);
88 
89  template<typename PointIterType,
90  typename ScalarType,
91  typename Enabled =
93  static void GeneratePoints(
94  PointIterType iter,
95  const size_t numRadial,
96  const ScalarType radius,
97  const ScalarType height,
98  const GfMatrix4d* framePtr = nullptr)
99  {
100  constexpr ScalarType sweep = 360;
101  GeneratePoints(iter, numRadial, radius, height, sweep, framePtr);
102  }
103 
104  template<typename PointIterType,
105  typename ScalarType,
106  typename Enabled =
108  static void GeneratePoints(
109  PointIterType iter,
110  const size_t numRadial,
111  const ScalarType radius,
112  const ScalarType height,
113  const ScalarType sweepDegrees,
114  const GfMatrix4d* framePtr = nullptr)
115  {
116  using PointType =
118 
119  _GeneratePointsImpl(numRadial, radius, height, sweepDegrees,
120  framePtr ? _PointWriter<PointType>(iter, framePtr)
121  : _PointWriter<PointType>(iter));
122  }
123 
125 
126  template<typename PointIterType,
127  typename ScalarType,
128  typename Enabled =
130  static void GenerateNormals(
131  PointIterType iter,
132  const size_t numRadial,
133  const ScalarType radius,
134  const ScalarType height,
135  const GfMatrix4d* framePtr = nullptr)
136  {
137  constexpr ScalarType sweep = 360;
138  GenerateNormals(iter, numRadial, radius, height, sweep, framePtr);
139  }
140 
141  template<typename PointIterType,
142  typename ScalarType,
143  typename Enabled =
145  static void GenerateNormals(
146  PointIterType iter,
147  const size_t numRadial,
148  const ScalarType radius,
149  const ScalarType height,
150  const ScalarType sweepDegrees,
151  const GfMatrix4d* framePtr = nullptr)
152  {
153  using PointType =
155 
156  _GenerateNormalsImpl(numRadial, radius, height, sweepDegrees,
157  framePtr ? _PointWriter<PointType>(iter, framePtr)
158  : _PointWriter<PointType>(iter));
159  }
160 
162 
163 private:
164 
165  template<typename PointType>
166  static void _GeneratePointsImpl(
167  const size_t numRadial,
168  const typename PointType::ScalarType radius,
169  const typename PointType::ScalarType height,
170  const typename PointType::ScalarType sweepDegrees,
171  const _PointWriter<PointType>& ptWriter);
172 
173  template<typename PointType>
174  static void _GenerateNormalsImpl(
175  const size_t numRadial,
176  const typename PointType::ScalarType radius,
177  const typename PointType::ScalarType height,
178  const typename PointType::ScalarType sweepDegrees,
179  const _PointWriter<PointType>& ptWriter);
180 };
181 
183 
184 #endif // PXR_IMAGING_GEOM_UTIL_CONE_MESH_GENERATOR_H
type
Definition: core.h:556
static void GenerateNormals(PointIterType iter, const size_t numRadial, const ScalarType radius, const ScalarType height, const GfMatrix4d *framePtr=nullptr)
static void GeneratePoints(PointIterType iter, const size_t numRadial, const ScalarType radius, const ScalarType height, const ScalarType sweepDegrees, const GfMatrix4d *framePtr=nullptr)
static TfToken GetNormalsInterpolation()
uint64 value_type
Definition: GA_PrimCompat.h:29
static constexpr size_t minNumRadial
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
Definition: token.h:70
static void GenerateNormals(PointIterType iter, const size_t numRadial, const ScalarType radius, const ScalarType height, const ScalarType sweepDegrees, const GfMatrix4d *framePtr=nullptr)
#define GEOMUTIL_API
Definition: api.h:23
static void GeneratePoints(PointIterType iter, const size_t numRadial, const ScalarType radius, const ScalarType height, const GfMatrix4d *framePtr=nullptr)
static void GeneratePoints(PointIterType iter,...)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static GEOMUTIL_API size_t ComputeNumPoints(const size_t numRadial, const bool closedSweep=true)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static GEOMUTIL_API PxOsdMeshTopology GenerateTopology(const size_t numRadial, const bool closedSweep=true)
static size_t ComputeNumNormals(const size_t numRadial, const bool closedSweep=true)
static void GenerateNormals(PointIterType iter,...)