HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
capsule.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 USDGEOM_GENERATED_CAPSULE_H
25 #define USDGEOM_GENERATED_CAPSULE_H
26 
27 /// \file usdGeom/capsule.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdGeom/api.h"
31 #include "pxr/usd/usdGeom/gprim.h"
32 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/stage.h"
34 #include "pxr/usd/usdGeom/tokens.h"
35 
36 #include "pxr/base/vt/value.h"
37 
38 #include "pxr/base/gf/vec3d.h"
39 #include "pxr/base/gf/vec3f.h"
40 #include "pxr/base/gf/matrix4d.h"
41 
42 #include "pxr/base/tf/token.h"
43 #include "pxr/base/tf/type.h"
44 
46 
47 class SdfAssetPath;
48 
49 // -------------------------------------------------------------------------- //
50 // CAPSULE //
51 // -------------------------------------------------------------------------- //
52 
53 /// \class UsdGeomCapsule
54 ///
55 /// Defines a primitive capsule, i.e. a cylinder capped by two half
56 /// spheres, centered at the origin, whose spine is along the specified
57 /// \em axis.
58 /// The spherical cap heights (sagitta) of the two endcaps are a function of
59 /// the relative radii of the endcaps, such that cylinder tangent and sphere
60 /// tangent are coincident and maintain C1 continuity.
61 ///
62 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
63 /// that are text/tokens, the actual token is published and defined in \ref UsdGeomTokens.
64 /// So to set an attribute to the value "rightHanded", use UsdGeomTokens->rightHanded
65 /// as the value.
66 ///
68 {
69 public:
70  /// Compile time constant representing what kind of schema this class is.
71  ///
72  /// \sa UsdSchemaKind
74 
75  /// Construct a UsdGeomCapsule on UsdPrim \p prim .
76  /// Equivalent to UsdGeomCapsule::Get(prim.GetStage(), prim.GetPath())
77  /// for a \em valid \p prim, but will not immediately throw an error for
78  /// an invalid \p prim
79  explicit UsdGeomCapsule(const UsdPrim& prim=UsdPrim())
80  : UsdGeomGprim(prim)
81  {
82  }
83 
84  /// Construct a UsdGeomCapsule on the prim held by \p schemaObj .
85  /// Should be preferred over UsdGeomCapsule(schemaObj.GetPrim()),
86  /// as it preserves SchemaBase state.
87  explicit UsdGeomCapsule(const UsdSchemaBase& schemaObj)
88  : UsdGeomGprim(schemaObj)
89  {
90  }
91 
92  /// Destructor.
94  virtual ~UsdGeomCapsule();
95 
96  /// Return a vector of names of all pre-declared attributes for this schema
97  /// class and all its ancestor classes. Does not include attributes that
98  /// may be authored by custom/extended methods of the schemas involved.
100  static const TfTokenVector &
101  GetSchemaAttributeNames(bool includeInherited=true);
102 
103  /// Return a UsdGeomCapsule holding the prim adhering to this
104  /// schema at \p path on \p stage. If no prim exists at \p path on
105  /// \p stage, or if the prim at that path does not adhere to this schema,
106  /// return an invalid schema object. This is shorthand for the following:
107  ///
108  /// \code
109  /// UsdGeomCapsule(stage->GetPrimAtPath(path));
110  /// \endcode
111  ///
113  static UsdGeomCapsule
114  Get(const UsdStagePtr &stage, const SdfPath &path);
115 
116  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
117  /// is defined (according to UsdPrim::IsDefined()) on this stage.
118  ///
119  /// If a prim adhering to this schema at \p path is already defined on this
120  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
121  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
122  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
123  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
124  /// current EditTarget for any nonexistent, or existing but not \a Defined
125  /// ancestors.
126  ///
127  /// The given \a path must be an absolute prim path that does not contain
128  /// any variant selections.
129  ///
130  /// If it is impossible to author any of the necessary PrimSpecs, (for
131  /// example, in case \a path cannot map to the current UsdEditTarget's
132  /// namespace) issue an error and return an invalid \a UsdPrim.
133  ///
134  /// Note that this method may return a defined prim whose typeName does not
135  /// specify this schema class, in case a stronger typeName opinion overrides
136  /// the opinion at the current EditTarget.
137  ///
139  static UsdGeomCapsule
140  Define(const UsdStagePtr &stage, const SdfPath &path);
141 
142 protected:
143  /// Returns the kind of schema this class belongs to.
144  ///
145  /// \sa UsdSchemaKind
147  UsdSchemaKind _GetSchemaKind() const override;
148 
149 private:
150  // needs to invoke _GetStaticTfType.
151  friend class UsdSchemaRegistry;
153  static const TfType &_GetStaticTfType();
154 
155  static bool _IsTypedSchema();
156 
157  // override SchemaBase virtuals.
159  const TfType &_GetTfType() const override;
160 
161 public:
162  // --------------------------------------------------------------------- //
163  // HEIGHT
164  // --------------------------------------------------------------------- //
165  /// The length of the capsule's spine along the specified
166  /// \em axis excluding the size of the two half spheres, i.e.
167  /// the length of the cylinder portion of the capsule.
168  /// If you author \em height you must also author \em extent.
169  /// \sa GetExtentAttr()
170  ///
171  /// | ||
172  /// | -- | -- |
173  /// | Declaration | `double height = 1` |
174  /// | C++ Type | double |
175  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Double |
177  UsdAttribute GetHeightAttr() const;
178 
179  /// See GetHeightAttr(), and also
180  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
181  /// If specified, author \p defaultValue as the attribute's default,
182  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
183  /// the default for \p writeSparsely is \c false.
185  UsdAttribute CreateHeightAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
186 
187 public:
188  // --------------------------------------------------------------------- //
189  // RADIUS
190  // --------------------------------------------------------------------- //
191  /// The radius of the capsule. If you
192  /// author \em radius you must also author \em extent.
193  ///
194  /// \sa GetExtentAttr()
195  ///
196  /// | ||
197  /// | -- | -- |
198  /// | Declaration | `double radius = 0.5` |
199  /// | C++ Type | double |
200  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Double |
202  UsdAttribute GetRadiusAttr() const;
203 
204  /// See GetRadiusAttr(), and also
205  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
206  /// If specified, author \p defaultValue as the attribute's default,
207  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
208  /// the default for \p writeSparsely is \c false.
210  UsdAttribute CreateRadiusAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
211 
212 public:
213  // --------------------------------------------------------------------- //
214  // AXIS
215  // --------------------------------------------------------------------- //
216  /// The axis along which the spine of the capsule is aligned
217  ///
218  /// | ||
219  /// | -- | -- |
220  /// | Declaration | `uniform token axis = "Z"` |
221  /// | C++ Type | TfToken |
222  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
223  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
224  /// | \ref UsdGeomTokens "Allowed Values" | X, Y, Z |
226  UsdAttribute GetAxisAttr() const;
227 
228  /// See GetAxisAttr(), and also
229  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
230  /// If specified, author \p defaultValue as the attribute's default,
231  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
232  /// the default for \p writeSparsely is \c false.
234  UsdAttribute CreateAxisAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
235 
236 public:
237  // --------------------------------------------------------------------- //
238  // EXTENT
239  // --------------------------------------------------------------------- //
240  /// Extent is re-defined on Capsule only to provide a fallback
241  /// value. \sa UsdGeomGprim::GetExtentAttr().
242  ///
243  /// | ||
244  /// | -- | -- |
245  /// | Declaration | `float3[] extent = [(-0.5, -0.5, -1), (0.5, 0.5, 1)]` |
246  /// | C++ Type | VtArray<GfVec3f> |
247  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float3Array |
249  UsdAttribute GetExtentAttr() const;
250 
251  /// See GetExtentAttr(), and also
252  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
253  /// If specified, author \p defaultValue as the attribute's default,
254  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
255  /// the default for \p writeSparsely is \c false.
257  UsdAttribute CreateExtentAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
258 
259 public:
260  // ===================================================================== //
261  // Feel free to add custom code below this line, it will be preserved by
262  // the code generator.
263  //
264  // Just remember to:
265  // - Close the class declaration with };
266  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
267  // - Close the include guard with #endif
268  // ===================================================================== //
269  // --(BEGIN CUSTOM CODE)--
270 
271  /// Compute the extent for the capsule defined by the height, radius, and
272  /// axis.
273  ///
274  /// \return true upon success, false if unable to calculate extent.
275  ///
276  /// On success, extent will contain an approximate axis-aligned bounding
277  /// box of the capsule defined by the height, radius, and axis.
278  ///
279  /// This function is to provide easy authoring of extent for usd authoring
280  /// tools, hence it is static and acts outside a specific prim (as in
281  /// attribute based methods).
283  static bool ComputeExtent(double height, double radius, const TfToken& axis,
284  VtVec3fArray* extent);
285 
286  /// \overload
287  /// Computes the extent as if the matrix \p transform was first applied.
289  static bool ComputeExtent(double height, double radius, const TfToken& axis,
290  const GfMatrix4d& transform, VtVec3fArray* extent);
291 };
292 
294 
295 #endif
static USDGEOM_API UsdGeomCapsule Get(const UsdStagePtr &stage, const SdfPath &path)
USDGEOM_API UsdAttribute GetExtentAttr() const
static USDGEOM_API UsdGeomCapsule Define(const UsdStagePtr &stage, const SdfPath &path)
static const UsdSchemaKind schemaKind
Definition: capsule.h:73
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDGEOM_API UsdAttribute GetRadiusAttr() const
USDGEOM_API UsdAttribute GetHeightAttr() const
USDGEOM_API UsdAttribute CreateRadiusAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdGeomCapsule(const UsdPrim &prim=UsdPrim())
Definition: capsule.h:79
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
Definition: token.h:87
Represents a concrete typed schema.
static USDGEOM_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
USDGEOM_API UsdAttribute CreateExtentAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDGEOM_API UsdAttribute GetAxisAttr() const
virtual USDGEOM_API ~UsdGeomCapsule()
Destructor.
Definition: prim.h:133
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
Definition: path.h:290
USDGEOM_API UsdAttribute CreateHeightAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
GA_API const UT_StringHolder transform
static USDGEOM_API bool ComputeExtent(double height, double radius, const TfToken &axis, VtVec3fArray *extent)
UsdGeomCapsule(const UsdSchemaBase &schemaObj)
Definition: capsule.h:87
UsdSchemaKind
Definition: common.h:129
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: type.h:64
#define USDGEOM_API
Definition: api.h:40
USDGEOM_API UsdSchemaKind _GetSchemaKind() const override
USDGEOM_API UsdAttribute CreateAxisAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: value.h:164