HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
capsuleMeshGenerator.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_CAPSULE_MESH_GENERATOR_H
25 #define PXR_IMAGING_GEOM_UTIL_CAPSULE_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 capsule. The simplest form takes a radius and height and is
39 /// a cylinder capped by two hemispheres that is centered at the origin. The
40 /// generated capsule is made up of circular cross-sections in the XY plane.
41 /// Each cross-section has numRadial segments. Successive cross-sections for
42 /// each of the hemispheres are generated at numCapAxial locations along the Z
43 /// and -Z axes respectively. The height is aligned with the Z axis and
44 /// represents the height of just the cylindrical portion.
45 ///
46 /// An optional transform may be provided to GeneratePoints to orient the
47 /// capsule as necessary (e.g., whose height is along the Y axis) .
48 ///
49 /// An additional overload of GeneratePoints is provided to specify different
50 /// radii and heights for the bottom and top caps, as well as the sweep angle
51 /// for the capsule about the +Z axis. When the sweep is less than 360 degrees,
52 /// the generated geometry is not closed.
53 ///
54 /// Usage:
55 /// \code{.cpp}
56 ///
57 /// const size_t numRadial = 4, numCapAxial = 4;
58 /// const size_t numPoints =
59 /// GeomUtilCapsuleMeshGenerator::ComputeNumPoints(numRadial, numCapAxial);
60 /// const float radius = 1, height = 2;
61 ///
62 /// MyPointContainer<GfVec3f> points(numPoints);
63 ///
64 /// GeomUtilCapsuleMeshGenerator::GeneratePoints(
65 /// points.begin(), numRadial, numCapAxial, radius, height);
66 ///
67 /// \endcode
68 ///
71 {
72 public:
73  static constexpr size_t minNumRadial = 3;
74  static constexpr size_t minNumCapAxial = 1;
75 
77  static size_t ComputeNumPoints(
78  const size_t numRadial,
79  const size_t numCapAxial,
80  const bool closedSweep = true);
81 
84  const size_t numRadial,
85  const size_t numCapAxial,
86  const bool closedSweep = true);
87 
88  template<typename PointIterType,
89  typename ScalarType,
90  typename Enabled =
92  static void GeneratePoints(
93  PointIterType iter,
94  const size_t numRadial,
95  const size_t numCapAxial,
96  const ScalarType radius,
97  const ScalarType height,
98  const GfMatrix4d* framePtr = nullptr)
99  {
100  constexpr ScalarType sweep = 360;
101 
102  GeneratePoints(iter, numRadial, numCapAxial,
103  /* bottomRadius = */ radius,
104  /* topRadius = */ radius,
105  height,
106  /* bottomCapHeight = */ radius,
107  /* topCapHeight = */ radius,
108  sweep, framePtr);
109  }
110 
111  template<typename PointIterType,
112  typename ScalarType,
113  typename Enabled =
115  static void GeneratePoints(
116  PointIterType iter,
117  const size_t numRadial,
118  const size_t numCapAxial,
119  const ScalarType bottomRadius,
120  const ScalarType topRadius,
121  const ScalarType height,
122  const ScalarType bottomCapHeight,
123  const ScalarType topCapHeight,
124  const ScalarType sweepDegrees,
125  const GfMatrix4d* framePtr = nullptr)
126  {
127  using PointType =
129 
130  _GeneratePointsImpl(numRadial, numCapAxial, bottomRadius, topRadius,
131  height, bottomCapHeight, topCapHeight, sweepDegrees,
132  framePtr ? _PointWriter<PointType>(iter, framePtr)
133  : _PointWriter<PointType>(iter));
134  }
135 
137 
138 private:
139  template<typename PointType>
140  static void _GeneratePointsImpl(
141  const size_t numRadial,
142  const size_t numCapAxial,
143  const typename PointType::ScalarType bottomRadius,
144  const typename PointType::ScalarType topRadius,
145  const typename PointType::ScalarType height,
146  const typename PointType::ScalarType bottomCapHeight,
147  const typename PointType::ScalarType topCapHeight,
148  const typename PointType::ScalarType sweep,
149  const _PointWriter<PointType>& ptWriter);
150 };
151 
153 
154 #endif // PXR_IMAGING_GEOM_UTIL_CAPSULE_MESH_GENERATOR_H
static GEOMUTIL_API size_t ComputeNumPoints(const size_t numRadial, const size_t numCapAxial, const bool closedSweep=true)
static void GeneratePoints(PointIterType iter, const size_t numRadial, const size_t numCapAxial, const ScalarType radius, const ScalarType height, const GfMatrix4d *framePtr=nullptr)
static GEOMUTIL_API PxOsdMeshTopology GenerateTopology(const size_t numRadial, const size_t numCapAxial, const bool closedSweep=true)
uint64 value_type
Definition: GA_PrimCompat.h:29
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
#define GEOMUTIL_API
Definition: api.h:40
static constexpr size_t minNumCapAxial
static void GeneratePoints(PointIterType iter, const size_t numRadial, const size_t numCapAxial, const ScalarType bottomRadius, const ScalarType topRadius, const ScalarType height, const ScalarType bottomCapHeight, const ScalarType topCapHeight, const ScalarType sweepDegrees, const GfMatrix4d *framePtr=nullptr)
static constexpr size_t minNumRadial
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