capsuleMeshGenerator.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_CAPSULE_MESH_GENERATOR_H
8 #define PXR_IMAGING_GEOM_UTIL_CAPSULE_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 
70 {
71 public:
72  static constexpr size_t minNumRadial = 3;
73  static constexpr size_t minNumCapAxial = 1;
74 
75  GEOMUTIL_API
76  static size_t ComputeNumPoints(
77  const size_t numRadial,
78  const size_t numCapAxial,
79  const bool closedSweep = true);
80 
81  static size_t ComputeNumNormals(
82  const size_t numRadial,
83  const size_t numCapAxial,
84  const bool closedSweep = true)
85  {
86  // Normals are per point.
87  return ComputeNumPoints(numRadial, numCapAxial, closedSweep);
88  }
89 
90  static TfToken GetNormalsInterpolation()
91  {
92  // Normals are per point.
93  return GeomUtilInterpolationTokens->vertex;
94  }
95 
96  GEOMUTIL_API
97  static PxOsdMeshTopology GenerateTopology(
98  const size_t numRadial,
99  const size_t numCapAxial,
100  const bool closedSweep = true);
101 
102  template<typename PointIterType,
103  typename ScalarType,
104  typename Enabled =
105  typename _EnableIfGfVec3Iterator<PointIterType>::type>
106  static void GeneratePoints(
107  PointIterType iter,
108  const size_t numRadial,
109  const size_t numCapAxial,
110  const ScalarType radius,
111  const ScalarType height,
112  const GfMatrix4d* framePtr = nullptr)
113  {
114  GeneratePoints(iter, numRadial, numCapAxial,
115  /* bottomRadius = */ radius,
116  /* topRadius = */ radius,
117  height, framePtr);
118  }
119 
120  template<typename PointIterType,
121  typename ScalarType,
122  typename Enabled =
123  typename _EnableIfGfVec3Iterator<PointIterType>::type>
124  static void GeneratePoints(
125  PointIterType iter,
126  const size_t numRadial,
127  const size_t numCapAxial,
128  const ScalarType bottomRadius,
129  const ScalarType topRadius,
130  const ScalarType height,
131  const GfMatrix4d* framePtr = nullptr)
132  {
133  constexpr ScalarType sweep = 360;
134 
135  GeneratePoints(iter, numRadial, numCapAxial,
136  bottomRadius, topRadius,
137  height, sweep, framePtr);
138  }
139 
140  template<typename PointIterType,
141  typename ScalarType,
142  typename Enabled =
143  typename _EnableIfGfVec3Iterator<PointIterType>::type>
144  static void GeneratePoints(
145  PointIterType iter,
146  const size_t numRadial,
147  const size_t numCapAxial,
148  const ScalarType bottomRadius,
149  const ScalarType topRadius,
150  const ScalarType height,
151  const ScalarType sweepDegrees,
152  const GfMatrix4d* framePtr = nullptr)
153  {
154  using PointType =
155  typename std::iterator_traits<PointIterType>::value_type;
156 
157  _GeneratePointsImpl(numRadial, numCapAxial, bottomRadius, topRadius,
158  height, sweepDegrees,
159  framePtr ? _PointWriter<PointType>(iter, framePtr)
160  : _PointWriter<PointType>(iter));
161  }
162 
163  using GeomUtilMeshGeneratorBase::GeneratePoints;
164 
165 
166  template<typename PointIterType,
167  typename ScalarType,
168  typename Enabled =
169  typename _EnableIfGfVec3Iterator<PointIterType>::type>
170  static void GenerateNormals(
171  PointIterType iter,
172  const size_t numRadial,
173  const size_t numCapAxial,
174  const ScalarType radius,
175  const ScalarType height,
176  const GfMatrix4d* framePtr = nullptr)
177  {
178  GenerateNormals(iter, numRadial, numCapAxial,
179  /* bottomRadius = */ radius,
180  /* topRadius = */ radius,
181  height, framePtr);
182  }
183 
184  template<typename PointIterType,
185  typename ScalarType,
186  typename Enabled =
187  typename _EnableIfGfVec3Iterator<PointIterType>::type>
188  static void GenerateNormals(
189  PointIterType iter,
190  const size_t numRadial,
191  const size_t numCapAxial,
192  const ScalarType bottomRadius,
193  const ScalarType topRadius,
194  const ScalarType height,
195  const GfMatrix4d* framePtr = nullptr)
196  {
197  constexpr ScalarType sweep = 360;
198 
199  GenerateNormals(iter, numRadial, numCapAxial,
200  bottomRadius, topRadius,
201  height, sweep, framePtr);
202  }
203 
204  template<typename PointIterType,
205  typename ScalarType,
206  typename Enabled =
207  typename _EnableIfGfVec3Iterator<PointIterType>::type>
208  static void GenerateNormals(
209  PointIterType iter,
210  const size_t numRadial,
211  const size_t numCapAxial,
212  const ScalarType bottomRadius,
213  const ScalarType topRadius,
214  const ScalarType height,
215  const ScalarType sweepDegrees,
216  const GfMatrix4d* framePtr = nullptr)
217  {
218  using PointType =
219  typename std::iterator_traits<PointIterType>::value_type;
220 
221  _GenerateNormalsImpl(numRadial, numCapAxial, bottomRadius, topRadius,
222  height, sweepDegrees,
223  framePtr ? _PointWriter<PointType>(iter, framePtr)
224  : _PointWriter<PointType>(iter));
225  }
226 
227  using GeomUtilMeshGeneratorBase::GenerateNormals;
228 
229 private:
230 
231  template<typename ScalarType>
232  static size_t _ComputeNumBottomCapAxial(
233  const size_t numCapAxial,
234  const ScalarType latitudeRange);
235 
236  static size_t _ComputeNumTopCapAxial(
237  const size_t numCapAxial,
238  const size_t numBottomCapAxial);
239 
240  template<typename PointType>
241  static void _GeneratePointsImpl(
242  const size_t numRadial,
243  const size_t numCapAxial,
244  const typename PointType::ScalarType bottomRadius,
245  const typename PointType::ScalarType topRadius,
246  const typename PointType::ScalarType height,
247  const typename PointType::ScalarType sweep,
248  const _PointWriter<PointType>& ptWriter);
249 
250  template<typename PointType>
251  static void _GenerateNormalsImpl(
252  const size_t numRadial,
253  const size_t numCapAxial,
254  const typename PointType::ScalarType bottomRadius,
255  const typename PointType::ScalarType topRadius,
256  const typename PointType::ScalarType height,
257  const typename PointType::ScalarType sweep,
258  const _PointWriter<PointType>& ptWriter);
259 };
260 
261 PXR_NAMESPACE_CLOSE_SCOPE
262 
263 #endif // PXR_IMAGING_GEOM_UTIL_CAPSULE_MESH_GENERATOR_H
This class provides common implementation for the different mesh generator classes in GeomUtil.
This class provides an implementation for generating topology, point positions and surface normals on...
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