HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
planeMeshGenerator.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_PLANE_MESH_GENERATOR_H
8 #define PXR_IMAGING_GEOM_UTIL_PLANE_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 rectangular plane given the dimensions
23 /// along the X and Y axes. The generated plane is centered at the origin.
24 ///
25 /// An optional transform may be provided to GeneratePoints and GenerateNormals
26 /// to orient the plane as necessary.
27 ///
28 /// Usage:
29 /// \code{.cpp}
30 ///
31 /// const size_t numPoints =
32 /// GeomUtilPlaneMeshGenerator::ComputeNumPoints();
33 /// const float w = 5, l = 4;
34 ///
35 /// MyPointContainer<GfVec3f> points(numPoints);
36 ///
37 /// GeomUtilPlaneMeshGenerator::GeneratePoints(
38 /// points.begin(), w, l);
39 ///
40 /// const size_t numNormals =
41 /// GeomUtilPlaneMeshGenerator::ComputeNumNormals();
42 ///
43 /// MyPointContainer<GfVec3f> normals(numNormals);
44 ///
45 /// GeomUtilPlaneMeshGenerator::GenerateNormals(
46 /// normals.begin());
47 ///
48 /// \endcode
49 ///
52 {
53 public:
55  static size_t ComputeNumPoints();
56 
57  static size_t ComputeNumNormals()
58  {
59  // A single normal for all points.
60  return 1;
61  }
62 
64  {
65  // A single normal for all points.
66  return GeomUtilInterpolationTokens->constant;
67  }
68 
71 
72  template<typename PointIterType,
73  typename ScalarType,
74  typename Enabled =
76  static void GeneratePoints(
77  PointIterType iter,
78  const ScalarType xLength,
79  const ScalarType yLength,
80  const GfMatrix4d* framePtr = nullptr)
81  {
82  using PointType =
84 
85  _GeneratePointsImpl(xLength, yLength,
86  framePtr ? _PointWriter<PointType>(iter, framePtr)
87  : _PointWriter<PointType>(iter));
88  }
89 
91 
92  template<typename PointIterType,
93  typename Enabled =
95  static void GenerateNormals(
96  PointIterType iter,
97  const GfMatrix4d* framePtr = nullptr)
98  {
99  using PointType =
101 
102  _GenerateNormalsImpl(
103  framePtr ? _PointWriter<PointType>(iter, framePtr)
104  : _PointWriter<PointType>(iter));
105  }
106 
108 
109 private:
110 
111  template<typename PointType>
112  static void _GeneratePointsImpl(
113  const typename PointType::ScalarType xLength,
114  const typename PointType::ScalarType yLength,
115  const _PointWriter<PointType>& ptWriter);
116 
117  template<typename PointType>
118  static void _GenerateNormalsImpl(
119  const _PointWriter<PointType>& ptWriter);
120 };
121 
123 
124 #endif // PXR_IMAGING_GEOM_UTIL_PLANE_MESH_GENERATOR_H
type
Definition: core.h:556
static void GeneratePoints(PointIterType iter, const ScalarType xLength, const ScalarType yLength, const GfMatrix4d *framePtr=nullptr)
uint64 value_type
Definition: GA_PrimCompat.h:29
Definition: token.h:70
#define GEOMUTIL_API
Definition: api.h:23
static TfToken GetNormalsInterpolation()
static void GeneratePoints(PointIterType iter,...)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static GEOMUTIL_API size_t ComputeNumPoints()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static void GenerateNormals(PointIterType iter, const GfMatrix4d *framePtr=nullptr)
static GEOMUTIL_API PxOsdMeshTopology GenerateTopology()
static void GenerateNormals(PointIterType iter,...)