cylinderMeshGenerator.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_CYLINDER_MESH_GENERATOR_H
8 #define PXR_IMAGING_GEOM_UTIL_CYLINDER_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 
65 {
66 public:
67  static constexpr size_t minNumRadial = 3;
68 
69  GEOMUTIL_API
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 
82  static TfToken GetNormalsInterpolation()
83  {
84  // Normals are per point.
85  return GeomUtilInterpolationTokens->vertex;
86  }
87 
88  GEOMUTIL_API
89  static PxOsdMeshTopology GenerateTopology(
90  const size_t numRadial,
91  const bool closedSweep = true);
92 
93  template<typename PointIterType,
94  typename ScalarType,
95  typename Enabled =
96  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
113  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
132  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
143  typename std::iterator_traits<PointIterType>::value_type;
144 
145  _GeneratePointsImpl(numRadial, bottomRadius, topRadius, height,
146  sweepDegrees,
147  framePtr ? _PointWriter<PointType>(iter, framePtr)
148  : _PointWriter<PointType>(iter));
149  }
150 
151  using GeomUtilMeshGeneratorBase::GeneratePoints;
152 
153  template<typename PointIterType,
154  typename ScalarType,
155  typename Enabled =
156  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
173  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
191  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
202  typename std::iterator_traits<PointIterType>::value_type;
203 
204  _GenerateNormalsImpl(numRadial, bottomRadius, topRadius, height,
205  sweepDegrees,
206  framePtr ? _PointWriter<PointType>(iter, framePtr)
207  : _PointWriter<PointType>(iter));
208  }
209 
210  using GeomUtilMeshGeneratorBase::GenerateNormals;
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 
233 PXR_NAMESPACE_CLOSE_SCOPE
234 
235 #endif // PXR_IMAGING_GEOM_UTIL_CYLINDER_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...