HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cuboidMeshGenerator.h
Go to the documentation of this file.
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_CUBOID_MESH_GENERATOR_H
8 #define PXR_IMAGING_GEOM_UTIL_CUBOID_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 cuboid given the dimensions
23 /// along the X, Y and Z axes. The generated cuboid is centered at the origin.
24 ///
25 /// An optional transform may be provided to GeneratePoints and GenerateNormals
26 /// to orient the cuboid as necessary.
27 ///
28 /// Usage:
29 /// \code{.cpp}
30 ///
31 /// const size_t numPoints =
32 /// GeomUtilCuboidMeshGenerator::ComputeNumPoints();
33 /// const float l = 5, b = 4, h = 3;
34 ///
35 /// MyPointContainer<GfVec3f> points(numPoints);
36 ///
37 /// GeomUtilCuboidMeshGenerator::GeneratePoints(
38 /// points.begin(), l, b, h);
39 ///
40 /// const size_t numNormals =
41 /// GeomUtilCuboidMeshGenerator::ComputeNumNormals();
42 ///
43 /// MyPointContainer<GfVec3f> normals(numNormals);
44 ///
45 /// GeomUtilCuboidMeshGenerator::GenerateNormals(
46 /// normals.begin());
47 ///
48 /// \endcode
49 ///
52 {
53 public:
55  static size_t ComputeNumPoints();
56 
57  static size_t ComputeNumNormals()
58  {
59  // Normals are per face.
60  return 6;
61  }
62 
64  {
65  // Normals are per face.
66  return GeomUtilInterpolationTokens->uniform;
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 ScalarType zLength,
81  const GfMatrix4d* framePtr = nullptr)
82  {
83  using PointType =
85 
86  _GeneratePointsImpl(xLength, yLength, zLength,
87  framePtr ? _PointWriter<PointType>(iter, framePtr)
88  : _PointWriter<PointType>(iter));
89  }
90 
92 
93  template<typename PointIterType,
94  typename Enabled =
96  static void GenerateNormals(
97  PointIterType iter,
98  const GfMatrix4d* framePtr = nullptr)
99  {
100  using PointType =
102 
103  _GenerateNormalsImpl(
104  framePtr ? _PointWriter<PointType>(iter, framePtr)
105  : _PointWriter<PointType>(iter));
106  }
107 
109 
110 private:
111 
112  template<typename PointType>
113  static void _GeneratePointsImpl(
114  const typename PointType::ScalarType xLength,
115  const typename PointType::ScalarType yLength,
116  const typename PointType::ScalarType zLength,
117  const _PointWriter<PointType>& ptWriter);
118 
119  template<typename PointType>
120  static void _GenerateNormalsImpl(
121  const _PointWriter<PointType>& ptWriter);
122 };
123 
125 
126 #endif // PXR_IMAGING_GEOM_UTIL_CUBOID_MESH_GENERATOR_H
type
Definition: core.h:556
static TfToken GetNormalsInterpolation()
static GEOMUTIL_API size_t ComputeNumPoints()
uint64 value_type
Definition: GA_PrimCompat.h:29
Definition: token.h:70
#define GEOMUTIL_API
Definition: api.h:23
static void GenerateNormals(PointIterType iter, const GfMatrix4d *framePtr=nullptr)
static void GeneratePoints(PointIterType iter,...)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static void GeneratePoints(PointIterType iter, const ScalarType xLength, const ScalarType yLength, const ScalarType zLength, const GfMatrix4d *framePtr=nullptr)
static GEOMUTIL_API PxOsdMeshTopology GenerateTopology()
static void GenerateNormals(PointIterType iter,...)