coneMeshGenerator.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_CONE_MESH_GENERATOR_H
8 #define PXR_IMAGING_GEOM_UTIL_CONE_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 
61 {
62 public:
63  static constexpr size_t minNumRadial = 3;
64 
65  GEOMUTIL_API
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 
78  static TfToken GetNormalsInterpolation()
79  {
80  // Normals are per point.
81  return GeomUtilInterpolationTokens->vertex;
82  }
83 
84  GEOMUTIL_API
85  static PxOsdMeshTopology GenerateTopology(
86  const size_t numRadial,
87  const bool closedSweep = true);
88 
89  template<typename PointIterType,
90  typename ScalarType,
91  typename Enabled =
92  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
107  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
117  typename std::iterator_traits<PointIterType>::value_type;
118 
119  _GeneratePointsImpl(numRadial, radius, height, sweepDegrees,
120  framePtr ? _PointWriter<PointType>(iter, framePtr)
121  : _PointWriter<PointType>(iter));
122  }
123 
124  using GeomUtilMeshGeneratorBase::GeneratePoints;
125 
126  template<typename PointIterType,
127  typename ScalarType,
128  typename Enabled =
129  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
144  typename _EnableIfGfVec3Iterator<PointIterType>::type>
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 =
154  typename std::iterator_traits<PointIterType>::value_type;
155 
156  _GenerateNormalsImpl(numRadial, radius, height, sweepDegrees,
157  framePtr ? _PointWriter<PointType>(iter, framePtr)
158  : _PointWriter<PointType>(iter));
159  }
160 
161  using GeomUtilMeshGeneratorBase::GenerateNormals;
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 
182 PXR_NAMESPACE_CLOSE_SCOPE
183 
184 #endif // PXR_IMAGING_GEOM_UTIL_CONE_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...