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