HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cylinderMeshGenerator.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_GEOM_UTIL_CYLINDER_MESH_GENERATOR_H
25 #define PXR_IMAGING_GEOM_UTIL_CYLINDER_MESH_GENERATOR_H
26 
29 
30 #include "pxr/pxr.h"
31 
33 
34 class GfMatrix4d;
35 class PxOsdMeshTopology;
36 
37 /// This class provides an implementation for generating topology and point
38 /// positions on a cylinder with a given radius and height. The cylinder is
39 /// made up of circular cross-sections in the XY plane and is centered at the
40 /// origin. Each cross-section has numRadial segments. The height is aligned
41 /// with the Z axis, with the base at Z = -h/2.
42 ///
43 /// An optional transform may be provided to GeneratePoints to orient the
44 /// cone as necessary (e.g., whose height is along the Y axis).
45 ///
46 /// An additional overload of GeneratePoints is provided to specify different
47 /// radii for the bottom and top discs of the cylinder and a sweep angle for
48 /// cylinder about the +Z axis. When the sweep is less than 360 degrees, the
49 /// generated geometry is not closed.
50 ///
51 /// \note Setting one radius to 0 in order to get a cone is inefficient and
52 /// could result in artifacts. Clients should use
53 /// GeomUtilConeMeshGenerator instead.
54 ///
55 /// Usage:
56 /// \code{.cpp}
57 ///
58 /// const size_t numRadial = 8;
59 /// const size_t numPoints =
60 /// GeomUtilCylinderMeshGenerator::ComputeNumPoints(numRadial);
61 /// const float radius = 1, height = 2;
62 ///
63 /// MyPointContainer<GfVec3f> points(numPoints);
64 ///
65 /// GeomUtilCylinderMeshGenerator::GeneratePoints(
66 /// points.begin(), numRadial, radius, height);
67 ///
68 /// \endcode
69 ///
72 {
73 public:
74  static constexpr size_t minNumRadial = 3;
75 
77  static size_t ComputeNumPoints(
78  const size_t numRadial,
79  const bool closedSweep = true);
80 
83  const size_t numRadial,
84  const bool closedSweep = true);
85 
86  template<typename PointIterType,
87  typename ScalarType,
88  typename Enabled =
90  static void GeneratePoints(
91  PointIterType iter,
92  const size_t numRadial,
93  const ScalarType radius,
94  const ScalarType height,
95  const GfMatrix4d* framePtr = nullptr)
96  {
97  constexpr ScalarType sweep = 360;
98 
99  GeneratePoints(iter, numRadial,
100  /* bottomRadius = */ radius,
101  /* topRadius = */ radius,
102  height, sweep, framePtr);
103  }
104 
105  template<typename PointIterType,
106  typename ScalarType,
107  typename Enabled =
109  static void GeneratePoints(
110  PointIterType iter,
111  const size_t numRadial,
112  const ScalarType bottomRadius,
113  const ScalarType topRadius,
114  const ScalarType height,
115  const ScalarType sweepDegrees,
116  const GfMatrix4d* framePtr = nullptr)
117  {
118  using PointType =
120 
121  _GeneratePointsImpl(numRadial, bottomRadius, topRadius, height,
122  sweepDegrees,
123  framePtr ? _PointWriter<PointType>(iter, framePtr)
124  : _PointWriter<PointType>(iter));
125  }
126 
128 
129 private:
130 
131  template<typename PointType>
132  static void _GeneratePointsImpl(
133  const size_t numRadial,
134  const typename PointType::ScalarType bottomRadius,
135  const typename PointType::ScalarType topRadius,
136  const typename PointType::ScalarType height,
137  const typename PointType::ScalarType sweep,
138  const _PointWriter<PointType>& ptWriter);
139 };
140 
142 
143 #endif // PXR_IMAGING_GEOM_UTIL_CYLINDER_MESH_GENERATOR_H
static void GeneratePoints(PointIterType iter, const size_t numRadial, const ScalarType bottomRadius, const ScalarType topRadius, const ScalarType height, const ScalarType sweepDegrees, const GfMatrix4d *framePtr=nullptr)
static void GeneratePoints(PointIterType iter, const size_t numRadial, const ScalarType radius, const ScalarType height, const GfMatrix4d *framePtr=nullptr)
static GEOMUTIL_API size_t ComputeNumPoints(const size_t numRadial, const bool closedSweep=true)
uint64 value_type
Definition: GA_PrimCompat.h:29
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
static constexpr size_t minNumRadial
#define GEOMUTIL_API
Definition: api.h:40
static GEOMUTIL_API PxOsdMeshTopology GenerateTopology(const size_t numRadial, const bool closedSweep=true)
static void GeneratePoints(PointIterType iter,...)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
type
Definition: core.h:1059