HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diskMeshGenerator.h
Go to the documentation of this file.
1 //
2 // Copyright 2024 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_DISK_MESH_GENERATOR_H
8 #define PXR_IMAGING_GEOM_UTIL_DISK_MESH_GENERATOR_H
9 
13 
14 #include "pxr/pxr.h"
15 
17 
18 class GfMatrix4d;
19 class PxOsdMeshTopology;
20 
21 /// This class provides an implementation for generating topology, point
22 /// positions and surface normals on a circular disk given the radius with
23 /// numRadial segments. The generated disk is centered at the origin.
24 ///
25 /// An optional transform may be provided to GeneratePoints and GenerateNormals
26 /// to orient the disk as necessary.
27 ///
28 /// Usage:
29 /// \code{.cpp}
30 ///
31 /// const size_t numRadial = 8;
32 /// const size_t numPoints =
33 /// GeomUtilDiskMeshGenerator::ComputeNumPoints(numRadial);
34 /// const float radius = 6;
35 ///
36 /// MyPointContainer<GfVec3f> points(numPoints);
37 ///
38 /// GeomUtilDiskMeshGenerator::GeneratePoints(
39 /// points.begin(), numRadial, radius);
40 ///
41 /// const size_t numNormals =
42 /// GeomUtilDiskMeshGenerator::ComputeNumNormals();
43 ///
44 /// MyPointContainer<GfVec3f> normals(numNormals);
45 ///
46 /// GeomUtilDiskMeshGenerator::GenerateNormals(
47 /// normals.begin());
48 ///
49 /// \endcode
50 ///
53 {
54 public:
55  static constexpr size_t minNumRadial = 3;
56 
58  static size_t ComputeNumPoints(
59  const size_t numRadial,
60  const bool closedSweep = true);
61 
62  static size_t ComputeNumNormals()
63  {
64  // A single normal for all points.
65  return 1;
66  }
67 
69  {
70  // A single normal for all points.
71  return GeomUtilInterpolationTokens->constant;
72  }
73 
76  const size_t numRadial,
77  const bool closedSweep = true);
78 
79  template<typename PointIterType,
80  typename ScalarType,
81  typename Enabled =
83  static void GeneratePoints(
84  PointIterType iter,
85  const size_t numRadial,
86  const ScalarType radius,
87  const GfMatrix4d* framePtr = nullptr)
88  {
89  constexpr ScalarType sweep = 360;
90 
91  GeneratePoints(iter, numRadial,
92  radius, sweep, framePtr);
93  }
94 
95  template<typename PointIterType,
96  typename ScalarType,
97  typename Enabled =
99  static void GeneratePoints(
100  PointIterType iter,
101  const size_t numRadial,
102  const ScalarType radius,
103  const ScalarType sweepDegrees,
104  const GfMatrix4d* framePtr = nullptr)
105  {
106  using PointType =
108 
109  _GeneratePointsImpl(numRadial, radius, sweepDegrees,
110  framePtr ? _PointWriter<PointType>(iter, framePtr)
111  : _PointWriter<PointType>(iter));
112  }
113 
115 
116  template<typename PointIterType,
117  typename Enabled =
119  static void GenerateNormals(
120  PointIterType iter,
121  const GfMatrix4d* framePtr = nullptr)
122  {
123  using PointType =
125 
126  _GenerateNormalsImpl(
127  framePtr ? _PointWriter<PointType>(iter, framePtr)
128  : _PointWriter<PointType>(iter));
129  }
130 
132 
133 private:
134 
135  template<typename PointType>
136  static void _GeneratePointsImpl(
137  const size_t numRadial,
138  const typename PointType::ScalarType radius,
139  const typename PointType::ScalarType sweepDegrees,
140  const _PointWriter<PointType>& ptWriter);
141 
142  template<typename PointType>
143  static void _GenerateNormalsImpl(
144  const _PointWriter<PointType>& ptWriter);
145 };
146 
148 
149 #endif // PXR_IMAGING_GEOM_UTIL_DISK_MESH_GENERATOR_H
type
Definition: core.h:556
static GEOMUTIL_API PxOsdMeshTopology GenerateTopology(const size_t numRadial, const bool closedSweep=true)
static constexpr size_t minNumRadial
uint64 value_type
Definition: GA_PrimCompat.h:29
Definition: token.h:70
static GEOMUTIL_API size_t ComputeNumPoints(const size_t numRadial, const bool closedSweep=true)
#define GEOMUTIL_API
Definition: api.h:23
static void GenerateNormals(PointIterType iter, const GfMatrix4d *framePtr=nullptr)
static void GeneratePoints(PointIterType iter,...)
static void GeneratePoints(PointIterType iter, const size_t numRadial, const ScalarType radius, const ScalarType sweepDegrees, const GfMatrix4d *framePtr=nullptr)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static void GeneratePoints(PointIterType iter, const size_t numRadial, const ScalarType radius, const GfMatrix4d *framePtr=nullptr)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static size_t ComputeNumNormals()
static TfToken GetNormalsInterpolation()
static void GenerateNormals(PointIterType iter,...)