HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
curves.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_CURVES_H
25 #define USDGEOM_GENERATED_CURVES_H
26 
27 /// \file usdGeom/curves.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdGeom/api.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 // CURVES //
51 // -------------------------------------------------------------------------- //
52 
53 /// \class UsdGeomCurves
54 ///
55 /// Base class for UsdGeomBasisCurves, UsdGeomNurbsCurves, and
56 /// UsdGeomHermiteCurves. The BasisCurves schema is designed to be
57 /// analagous to offline renderers' notion of batched curves (such as
58 /// the classical RIB definition via Basis and Curves statements),
59 /// while the NurbsCurve schema is designed to be analgous to the
60 /// NURBS curves found in packages like Maya and Houdini while
61 /// retaining their consistency with the RenderMan specification for
62 /// NURBS Patches. HermiteCurves are useful for the
63 /// interchange of animation guides and paths.
64 ///
65 /// It is safe to use the length of the curve vertex count to derive
66 /// the number of curves and the number and layout of curve vertices,
67 /// but this schema should NOT be used to derive the number of curve
68 /// points. While vertex indices are implicit in all shipped
69 /// descendent types of this schema, one should not assume that all
70 /// internal or future shipped schemas will follow this pattern. Be
71 /// sure to key any indexing behavior off the concrete type, not this
72 /// abstract type.
73 ///
74 ///
76 {
77 public:
78  /// Compile time constant representing what kind of schema this class is.
79  ///
80  /// \sa UsdSchemaKind
82 
83  /// Construct a UsdGeomCurves on UsdPrim \p prim .
84  /// Equivalent to UsdGeomCurves::Get(prim.GetStage(), prim.GetPath())
85  /// for a \em valid \p prim, but will not immediately throw an error for
86  /// an invalid \p prim
87  explicit UsdGeomCurves(const UsdPrim& prim=UsdPrim())
88  : UsdGeomPointBased(prim)
89  {
90  }
91 
92  /// Construct a UsdGeomCurves on the prim held by \p schemaObj .
93  /// Should be preferred over UsdGeomCurves(schemaObj.GetPrim()),
94  /// as it preserves SchemaBase state.
95  explicit UsdGeomCurves(const UsdSchemaBase& schemaObj)
96  : UsdGeomPointBased(schemaObj)
97  {
98  }
99 
100  /// Destructor.
102  virtual ~UsdGeomCurves();
103 
104  /// Return a vector of names of all pre-declared attributes for this schema
105  /// class and all its ancestor classes. Does not include attributes that
106  /// may be authored by custom/extended methods of the schemas involved.
108  static const TfTokenVector &
109  GetSchemaAttributeNames(bool includeInherited=true);
110 
111  /// Return a UsdGeomCurves holding the prim adhering to this
112  /// schema at \p path on \p stage. If no prim exists at \p path on
113  /// \p stage, or if the prim at that path does not adhere to this schema,
114  /// return an invalid schema object. This is shorthand for the following:
115  ///
116  /// \code
117  /// UsdGeomCurves(stage->GetPrimAtPath(path));
118  /// \endcode
119  ///
121  static UsdGeomCurves
122  Get(const UsdStagePtr &stage, const SdfPath &path);
123 
124 
125 protected:
126  /// Returns the kind of schema this class belongs to.
127  ///
128  /// \sa UsdSchemaKind
130  UsdSchemaKind _GetSchemaKind() const override;
131 
132 private:
133  // needs to invoke _GetStaticTfType.
134  friend class UsdSchemaRegistry;
136  static const TfType &_GetStaticTfType();
137 
138  static bool _IsTypedSchema();
139 
140  // override SchemaBase virtuals.
142  const TfType &_GetTfType() const override;
143 
144 public:
145  // --------------------------------------------------------------------- //
146  // CURVEVERTEXCOUNTS
147  // --------------------------------------------------------------------- //
148  /// Curves-derived primitives can represent multiple distinct,
149  /// potentially disconnected curves. The length of 'curveVertexCounts'
150  /// gives the number of such curves, and each element describes the
151  /// number of vertices in the corresponding curve
152  ///
153  /// | ||
154  /// | -- | -- |
155  /// | Declaration | `int[] curveVertexCounts` |
156  /// | C++ Type | VtArray<int> |
157  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->IntArray |
160 
161  /// See GetCurveVertexCountsAttr(), and also
162  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
163  /// If specified, author \p defaultValue as the attribute's default,
164  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
165  /// the default for \p writeSparsely is \c false.
167  UsdAttribute CreateCurveVertexCountsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
168 
169 public:
170  // --------------------------------------------------------------------- //
171  // WIDTHS
172  // --------------------------------------------------------------------- //
173  /// Provides width specification for the curves, whose application
174  /// will depend on whether the curve is oriented (normals are defined for
175  /// it), in which case widths are "ribbon width", or unoriented, in which
176  /// case widths are cylinder width. 'widths' is not a generic Primvar,
177  /// but the number of elements in this attribute will be determined by
178  /// its 'interpolation'. See \ref SetWidthsInterpolation() . If 'widths'
179  /// and 'primvars:widths' are both specified, the latter has precedence.
180  ///
181  /// | ||
182  /// | -- | -- |
183  /// | Declaration | `float[] widths` |
184  /// | C++ Type | VtArray<float> |
185  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->FloatArray |
187  UsdAttribute GetWidthsAttr() const;
188 
189  /// See GetWidthsAttr(), and also
190  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
191  /// If specified, author \p defaultValue as the attribute's default,
192  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
193  /// the default for \p writeSparsely is \c false.
195  UsdAttribute CreateWidthsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
196 
197 public:
198  // ===================================================================== //
199  // Feel free to add custom code below this line, it will be preserved by
200  // the code generator.
201  //
202  // Just remember to:
203  // - Close the class declaration with };
204  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
205  // - Close the include guard with #endif
206  // ===================================================================== //
207  // --(BEGIN CUSTOM CODE)--
208 
209  /// Get the \ref Usd_InterpolationVals "interpolation" for the \em widths
210  /// attribute.
211  ///
212  /// Although 'widths' is not classified as a generic UsdGeomPrimvar (and
213  /// will not be included in the results of UsdGeomPrimvarsAPI::GetPrimvars() )
214  /// it does require an interpolation specification. The fallback
215  /// interpolation, if left unspecified, is UsdGeomTokens->vertex ,
216  /// which means a width value is specified at the end of each curve segment.
219 
220  /// Set the \ref Usd_InterpolationVals "interpolation" for the \em widths
221  /// attribute.
222  ///
223  /// \return true upon success, false if \p interpolation is not a legal
224  /// value as defined by UsdPrimvar::IsValidInterpolation(), or if there
225  /// was a problem setting the value. No attempt is made to validate
226  /// that the widths attr's value contains the right number of elements
227  /// to match its interpolation to its prim's topology.
228  ///
229  /// \sa GetWidthsInterpolation()
231  bool SetWidthsInterpolation(TfToken const &interpolation);
232 
233  /// Compute the extent for the curves defined by points and widths.
234  ///
235  /// \return true upon success, false if unable to calculate extent.
236  ///
237  /// On success, extent will contain an approximate axis-aligned bounding
238  /// box of the curve defined by points with the given widths.
239  ///
240  /// This function is to provide easy authoring of extent for usd authoring
241  /// tools, hence it is static and acts outside a specific prim (as in
242  /// attribute based methods).
244  static bool ComputeExtent(const VtVec3fArray& points,
245  const VtFloatArray& widths, VtVec3fArray* extent);
246 
247  /// \overload
248  /// Computes the extent as if the matrix \p transform was first applied.
250  static bool ComputeExtent(const VtVec3fArray& points,
251  const VtFloatArray& widths, const GfMatrix4d& transform,
252  VtVec3fArray* extent);
253 
254  /// Returns the number of curves as defined by the size of the
255  /// _curveVertexCounts_ array at _timeCode_.
256  ///
257  /// \snippetdoc snippets.dox GetCount
258  /// \sa GetCurveVertexCountsAttr()
260  size_t GetCurveCount(UsdTimeCode timeCode = UsdTimeCode::Default()) const;
261 };
262 
264 
265 #endif
USDGEOM_API UsdSchemaKind _GetSchemaKind() const override
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
static constexpr UsdTimeCode Default()
Definition: timeCode.h:112
virtual USDGEOM_API ~UsdGeomCurves()
Destructor.
USDGEOM_API bool SetWidthsInterpolation(TfToken const &interpolation)
static const UsdSchemaKind schemaKind
Definition: curves.h:81
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDGEOM_API UsdAttribute CreateCurveVertexCountsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDGEOM_API UsdAttribute CreateWidthsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
static USDGEOM_API bool ComputeExtent(const VtVec3fArray &points, const VtFloatArray &widths, VtVec3fArray *extent)
Definition: token.h:87
Represents a non-concrete typed schema.
USDGEOM_API UsdAttribute GetWidthsAttr() const
USDGEOM_API size_t GetCurveCount(UsdTimeCode timeCode=UsdTimeCode::Default()) const
Definition: prim.h:133
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
Definition: path.h:290
GA_API const UT_StringHolder transform
UsdGeomCurves(const UsdSchemaBase &schemaObj)
Definition: curves.h:95
UsdSchemaKind
Definition: common.h:129
static USDGEOM_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
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
UsdGeomCurves(const UsdPrim &prim=UsdPrim())
Definition: curves.h:87
USDGEOM_API UsdAttribute GetCurveVertexCountsAttr() const
Definition: value.h:164
static USDGEOM_API UsdGeomCurves Get(const UsdStagePtr &stage, const SdfPath &path)
USDGEOM_API TfToken GetWidthsInterpolation() const