7#ifndef PXR_IMAGING_GEOM_UTIL_MESH_GENERATOR_BASE_H
8#define PXR_IMAGING_GEOM_UTIL_MESH_GENERATOR_BASE_H
10#include "pxr/imaging/geomUtil/api.h"
23PXR_NAMESPACE_OPEN_SCOPE
74 template<
typename IterType>
75 struct _IsGfVec3Iterator
77 using PointType =
typename std::iterator_traits<IterType>::value_type;
78 static constexpr bool value =
79 std::is_same<PointType, GfVec3f>::value ||
80 std::is_same<PointType, GfVec3d>::value;
83 template<
typename IterType>
84 struct _EnableIfGfVec3Iterator
85 :
public std::enable_if<_IsGfVec3Iterator<IterType>::value, void>
88 template<
typename IterType>
89 struct _EnableIfNotGfVec3Iterator
90 :
public std::enable_if<!_IsGfVec3Iterator<IterType>::value, void>
107 template<
typename Po
intType>
110 template<
class IterType>
113 : _writeFnPtr(&_PointWriter<PointType>::_WritePoint<IterType>)
114 , _writeDirFnPtr(&_PointWriter<PointType>::_WriteDir<IterType>)
115 , _untypedIterPtr(
static_cast<void*
>(&iter))
118 template<
class IterType>
123 &_PointWriter<PointType>::_TransformAndWritePoint<IterType>)
125 &_PointWriter<PointType>::_TransformAndWriteDir<IterType>)
126 , _untypedIterPtr(
static_cast<void*
>(&iter))
127 , _framePtr(framePtr)
131 const PointType& pt)
const
133 (this->*_writeFnPtr)(pt);
137 const typename PointType::ScalarType scaleXY,
138 const std::vector<std::array<
139 typename PointType::ScalarType, 2>>& arcXY,
140 const typename PointType::ScalarType arcZ)
const
142 for (
const auto& xy : arcXY) {
143 Write(PointType(scaleXY * xy[0], scaleXY * xy[1], arcZ));
148 const PointType& dir)
const
150 (this->*_writeDirFnPtr)(dir);
154 const typename PointType::ScalarType scaleXY,
155 const std::vector<std::array<
156 typename PointType::ScalarType, 2>>& arcXY,
157 const typename PointType::ScalarType arcZ)
const
159 for (
const auto& xy : arcXY) {
160 WriteDir(PointType(scaleXY * xy[0], scaleXY * xy[1], arcZ));
165 template<
class IterType>
167 const PointType& pt)
const
169 IterType& iter = *
static_cast<IterType*
>(_untypedIterPtr);
174 template<
class IterType>
175 void _TransformAndWritePoint(
176 const PointType& pt)
const
178 IterType& iter = *
static_cast<IterType*
>(_untypedIterPtr);
179 using OutType =
typename std::remove_reference_t<
decltype(*iter)>;
180 *iter =
static_cast<OutType
>(_framePtr->Transform(pt));
184 template<
class IterType>
186 const PointType& pt)
const
188 IterType& iter = *
static_cast<IterType*
>(_untypedIterPtr);
193 template<
class IterType>
194 void _TransformAndWriteDir(
195 const PointType& dir)
const
197 IterType& iter = *
static_cast<IterType*
>(_untypedIterPtr);
198 using OutType =
typename std::remove_reference_t<
decltype(*iter)>;
199 *iter =
static_cast<OutType
>(_framePtr->TransformDir(dir));
204 void (_PointWriter<PointType>::*)(
const PointType &)
const;
205 _WriteFnPtr _writeFnPtr;
206 _WriteFnPtr _writeDirFnPtr;
207 void* _untypedIterPtr;
245 const size_t numRadial,
246 const size_t numQuadStrips,
247 const _CapStyle bottomCapStyle,
248 const _CapStyle topCapStyle,
249 const bool closedSweep);
256 static size_t _ComputeNumRadialPoints(
257 const size_t numRadial,
258 const bool closedSweep);
263 static size_t _ComputeNumCappedQuadTopologyPoints(
264 const size_t numRadial,
265 const size_t numQuadStrips,
266 const _CapStyle bottomCapStyle,
267 const _CapStyle topCapStyle,
268 const bool closedSweep);
273 template<
typename ScalarType>
274 static std::vector<std::array<ScalarType, 2>> _GenerateUnitArcXY(
275 const size_t numRadial,
276 const ScalarType sweepDegrees)
278 constexpr ScalarType twoPi = 2.0 * M_PI;
280 const ScalarType sweep =
GfClamp(sweepRadians, -twoPi, twoPi);
282 const size_t numPts = _ComputeNumRadialPoints(numRadial, closedSweep);
285 std::vector<std::array<ScalarType, 2>> result(numPts);
286 for (
size_t radIdx = 0; radIdx < numPts; ++radIdx) {
288 const ScalarType longAngle =
289 (ScalarType(radIdx) / ScalarType(numRadial)) * sweep;
290 result[radIdx][0] = cos(longAngle);
291 result[radIdx][1] = sin(longAngle);
305 template<
typename PointIterType,
307 typename _EnableIfNotGfVec3Iterator<PointIterType>::type>
308 static void GeneratePoints(
309 PointIterType iter, ...)
311 static_assert(_IsGfVec3Iterator<PointIterType>::value,
312 "This function only supports iterators to GfVec3f or GfVec3d "
323 template<
typename PointIterType,
325 typename _EnableIfNotGfVec3Iterator<PointIterType>::type>
326 static void GenerateNormals(
327 PointIterType iter, ...)
329 static_assert(_IsGfVec3Iterator<PointIterType>::value,
330 "This function only supports iterators to GfVec3f or GfVec3d "
337PXR_NAMESPACE_CLOSE_SCOPE
Architecture-specific math function calls.
This class provides common implementation for the different mesh generator classes in GeomUtil.
Stores a 4x4 matrix of double elements.
Topology data for meshes.
bool GfIsClose(GfColor const &c1, GfColor const &c2, double tolerance)
Tests for equality of the RGB tuple in a color with a given tolerance, returning true if the length o...
Assorted mathematical utility functions.
double GfDegreesToRadians(double degrees)
Converts an angle in degrees to radians.
double GfClamp(double value, double min, double max)
Return the resulting of clamping value to lie between min and max.
double GfAbs(double f)
Return abs(f).