sphereMeshGenerator.h
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 
10 #include "pxr/imaging/geomUtil/api.h"
11 #include "pxr/imaging/geomUtil/meshGeneratorBase.h"
13 
14 #include "pxr/pxr.h"
15 
16 PXR_NAMESPACE_OPEN_SCOPE
17 
18 class GfMatrix4d;
19 class PxOsdMeshTopology;
20 
60 {
61 public:
62  static constexpr size_t minNumRadial = 3;
63  static constexpr size_t minNumAxial = 2;
64 
65  GEOMUTIL_API
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 
80  static TfToken GetNormalsInterpolation()
81  {
82  // Normals are per point.
83  return GeomUtilInterpolationTokens->vertex;
84  }
85 
86  GEOMUTIL_API
87  static PxOsdMeshTopology GenerateTopology(
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 =
95  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
110  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
120  typename std::iterator_traits<PointIterType>::value_type;
121 
122  _GeneratePointsImpl(numRadial, numAxial, radius, sweepDegrees,
123  framePtr ? _PointWriter<PointType>(iter, framePtr)
124  : _PointWriter<PointType>(iter));
125  }
126 
127  using GeomUtilMeshGeneratorBase::GeneratePoints;
128 
129  template<typename PointIterType,
130  typename Enabled =
131  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
139  typename std::iterator_traits<PointIterType>::value_type;
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 =
148  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
157  typename std::iterator_traits<PointIterType>::value_type;
158 
159  _GenerateNormalsImpl(numRadial, numAxial, sweepDegrees,
160  framePtr ? _PointWriter<PointType>(iter, framePtr)
161  : _PointWriter<PointType>(iter));
162  }
163 
164  using GeomUtilMeshGeneratorBase::GenerateNormals;
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 
184 PXR_NAMESPACE_CLOSE_SCOPE
185 
186 #endif // PXR_IMAGING_GEOM_UTIL_SPHERE_MESH_GENERATOR_H
This class provides common implementation for the different mesh generator classes in GeomUtil.
Topology data for meshes.
Definition: meshTopology.h:52
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:80
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:70
This class provides an implementation for generating topology, point positions and surface normals on...