HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sphereMeshGenerator.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_SPHERE_MESH_GENERATOR_H
25 #define PXR_IMAGING_GEOM_UTIL_SPHERE_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 sphere with a given radius. The sphere is made up of
39 /// circular cross-sections in the XY plane and is centered at the origin.
40 /// Each cross-section has numRadial segments. Successive cross-sections are
41 /// generated at numAxial locations along the Z axis, with the bottom of the
42 /// sphere at Z = -r and top at Z = r.
43 ///
44 /// An optional transform may be provided to GeneratePoints to orient the
45 /// sphere as necessary (e.g., cross-sections in the YZ plane).
46 ///
47 /// An additional overload of GeneratePoints is provided to specify a sweep
48 /// angle for the sphere about the +Z axis. When the sweep is less than 360
49 /// degrees, the generated geometry is not closed.
50 ///
51 /// Usage:
52 /// \code{.cpp}
53 ///
54 /// const size_t numRadial = 4, numAxial = 4;
55 /// const size_t numPoints =
56 /// GeomUtilSphereMeshGenerator::ComputeNumPoints(numRadial, numAxial);
57 /// const float radius = 5;
58 ///
59 /// MyPointContainer<GfVec3f> points(numPoints);
60 ///
61 /// GeomUtilSphereMeshGenerator::GeneratePoints(
62 /// points.begin(), numRadial, numAxial, radius);
63 ///
64 /// \endcode
65 ///
68 {
69 public:
70  static constexpr size_t minNumRadial = 3;
71  static constexpr size_t minNumAxial = 2;
72 
74  static size_t ComputeNumPoints(
75  const size_t numRadial,
76  const size_t numAxial,
77  const bool closedSweep = true);
78 
81  const size_t numRadial,
82  const size_t numAxial,
83  const bool closedSweep = true);
84 
85  template<typename PointIterType,
86  typename ScalarType,
87  typename Enabled =
89  static void GeneratePoints(
90  PointIterType iter,
91  const size_t numRadial,
92  const size_t numAxial,
93  const ScalarType radius,
94  const GfMatrix4d* framePtr = nullptr)
95  {
96  constexpr ScalarType sweep = 360;
97  GeneratePoints(iter, numRadial, numAxial, radius, sweep, framePtr);
98  }
99 
100  template<typename PointIterType,
101  typename ScalarType,
102  typename Enabled =
104  static void GeneratePoints(
105  PointIterType iter,
106  const size_t numRadial,
107  const size_t numAxial,
108  const ScalarType radius,
109  const ScalarType sweepDegrees,
110  const GfMatrix4d* framePtr = nullptr)
111  {
112  using PointType =
114 
115  _GeneratePointsImpl(numRadial, numAxial, radius, sweepDegrees,
116  framePtr ? _PointWriter<PointType>(iter, framePtr)
117  : _PointWriter<PointType>(iter));
118  }
119 
121 
122 private:
123 
124  template<typename PointType>
125  static void _GeneratePointsImpl(
126  const size_t numRadial,
127  const size_t numAxial,
128  const typename PointType::ScalarType radius,
129  const typename PointType::ScalarType sweepDegrees,
130  const _PointWriter<PointType>& ptWriter);
131 };
132 
134 
135 #endif // PXR_IMAGING_GEOM_UTIL_SPHERE_MESH_GENERATOR_H
static GEOMUTIL_API PxOsdMeshTopology GenerateTopology(const size_t numRadial, const size_t numAxial, const bool closedSweep=true)
uint64 value_type
Definition: GA_PrimCompat.h:29
#define GEOMUTIL_API
Definition: api.h:40
static void GeneratePoints(PointIterType iter, const size_t numRadial, const size_t numAxial, const ScalarType radius, const GfMatrix4d *framePtr=nullptr)
static constexpr size_t minNumRadial
static GEOMUTIL_API size_t ComputeNumPoints(const size_t numRadial, const size_t numAxial, const bool closedSweep=true)
static constexpr size_t minNumAxial
static void GeneratePoints(PointIterType iter,...)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
static void GeneratePoints(PointIterType iter, const size_t numRadial, const size_t numAxial, const ScalarType radius, const ScalarType sweepDegrees, const GfMatrix4d *framePtr=nullptr)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
type
Definition: core.h:1059