HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
splineAPI.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef USDRI_GENERATED_SPLINEAPI_H
8 #define USDRI_GENERATED_SPLINEAPI_H
9 
10 /// \file usdRi/splineAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdRi/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 
18 #include "pxr/base/vt/value.h"
19 
20 #include "pxr/base/gf/vec3d.h"
21 #include "pxr/base/gf/vec3f.h"
22 #include "pxr/base/gf/matrix4d.h"
23 
24 #include "pxr/base/tf/token.h"
25 #include "pxr/base/tf/type.h"
26 
28 
29 class SdfAssetPath;
30 
31 // -------------------------------------------------------------------------- //
32 // RISPLINEAPI //
33 // -------------------------------------------------------------------------- //
34 
35 /// \class UsdRiSplineAPI
36 ///
37 ///
38 /// \deprecated This API schema will be removed in a future release.
39 ///
40 /// RiSplineAPI is a general purpose API schema used to describe
41 /// a named spline stored as a set of attributes on a prim.
42 ///
43 /// It is an add-on schema that can be applied many times to a prim with
44 /// different spline names. All the attributes authored by the schema
45 /// are namespaced under "$NAME:spline:", with the name of the
46 /// spline providing a namespace for the attributes.
47 ///
48 /// The spline describes a 2D piecewise cubic curve with a position and
49 /// value for each knot. This is chosen to give straightforward artistic
50 /// control over the shape. The supported basis types are:
51 ///
52 /// - linear (UsdRiTokens->linear)
53 /// - bspline (UsdRiTokens->bspline)
54 /// - Catmull-Rom (UsdRiTokens->catmullRom)
55 ///
56 ///
58 {
59 public:
60  /// Compile time constant representing what kind of schema this class is.
61  ///
62  /// \sa UsdSchemaKind
64 
65  /// Construct a UsdRiSplineAPI on UsdPrim \p prim .
66  /// Equivalent to UsdRiSplineAPI::Get(prim.GetStage(), prim.GetPath())
67  /// for a \em valid \p prim, but will not immediately throw an error for
68  /// an invalid \p prim
69  explicit UsdRiSplineAPI(const UsdPrim& prim=UsdPrim())
70  : UsdAPISchemaBase(prim)
71  {
72  }
73 
74  /// Construct a UsdRiSplineAPI on the prim held by \p schemaObj .
75  /// Should be preferred over UsdRiSplineAPI(schemaObj.GetPrim()),
76  /// as it preserves SchemaBase state.
77  explicit UsdRiSplineAPI(const UsdSchemaBase& schemaObj)
78  : UsdAPISchemaBase(schemaObj)
79  {
80  }
81 
82  /// Destructor.
83  USDRI_API
84  virtual ~UsdRiSplineAPI();
85 
86  /// Return a vector of names of all pre-declared attributes for this schema
87  /// class and all its ancestor classes. Does not include attributes that
88  /// may be authored by custom/extended methods of the schemas involved.
89  USDRI_API
90  static const TfTokenVector &
91  GetSchemaAttributeNames(bool includeInherited=true);
92 
93  /// Return a UsdRiSplineAPI holding the prim adhering to this
94  /// schema at \p path on \p stage. If no prim exists at \p path on
95  /// \p stage, or if the prim at that path does not adhere to this schema,
96  /// return an invalid schema object. This is shorthand for the following:
97  ///
98  /// \code
99  /// UsdRiSplineAPI(stage->GetPrimAtPath(path));
100  /// \endcode
101  ///
102  USDRI_API
103  static UsdRiSplineAPI
104  Get(const UsdStagePtr &stage, const SdfPath &path);
105 
106 
107  /// Returns true if this <b>single-apply</b> API schema can be applied to
108  /// the given \p prim. If this schema can not be a applied to the prim,
109  /// this returns false and, if provided, populates \p whyNot with the
110  /// reason it can not be applied.
111  ///
112  /// Note that if CanApply returns false, that does not necessarily imply
113  /// that calling Apply will fail. Callers are expected to call CanApply
114  /// before calling Apply if they want to ensure that it is valid to
115  /// apply a schema.
116  ///
117  /// \sa UsdPrim::GetAppliedSchemas()
118  /// \sa UsdPrim::HasAPI()
119  /// \sa UsdPrim::CanApplyAPI()
120  /// \sa UsdPrim::ApplyAPI()
121  /// \sa UsdPrim::RemoveAPI()
122  ///
123  USDRI_API
124  static bool
125  CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
126 
127  /// Applies this <b>single-apply</b> API schema to the given \p prim.
128  /// This information is stored by adding "RiSplineAPI" to the
129  /// token-valued, listOp metadata \em apiSchemas on the prim.
130  ///
131  /// \return A valid UsdRiSplineAPI object is returned upon success.
132  /// An invalid (or empty) UsdRiSplineAPI object is returned upon
133  /// failure. See \ref UsdPrim::ApplyAPI() for conditions
134  /// resulting in failure.
135  ///
136  /// \sa UsdPrim::GetAppliedSchemas()
137  /// \sa UsdPrim::HasAPI()
138  /// \sa UsdPrim::CanApplyAPI()
139  /// \sa UsdPrim::ApplyAPI()
140  /// \sa UsdPrim::RemoveAPI()
141  ///
142  USDRI_API
143  static UsdRiSplineAPI
144  Apply(const UsdPrim &prim);
145 
146 protected:
147  /// Returns the kind of schema this class belongs to.
148  ///
149  /// \sa UsdSchemaKind
150  USDRI_API
151  UsdSchemaKind _GetSchemaKind() const override;
152 
153 private:
154  // needs to invoke _GetStaticTfType.
155  friend class UsdSchemaRegistry;
156  USDRI_API
157  static const TfType &_GetStaticTfType();
158 
159  static bool _IsTypedSchema();
160 
161  // override SchemaBase virtuals.
162  USDRI_API
163  const TfType &_GetTfType() const override;
164 
165 public:
166  // ===================================================================== //
167  // Feel free to add custom code below this line, it will be preserved by
168  // the code generator.
169  //
170  // Just remember to:
171  // - Close the class declaration with };
172  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
173  // - Close the include guard with #endif
174  // ===================================================================== //
175  // --(BEGIN CUSTOM CODE)--
176 
177  /// Construct a UsdRiSplineAPI with the given \p splineName on
178  /// the UsdPrim \p prim .
179  explicit UsdRiSplineAPI(const UsdPrim& prim, const TfToken &splineName,
180  const SdfValueTypeName &valuesTypeName,
181  bool doesDuplicateBSplineEndpoints)
182  : UsdAPISchemaBase(prim)
183  , _splineName(splineName)
184  , _valuesTypeName(valuesTypeName)
185  , _duplicateBSplineEndpoints(doesDuplicateBSplineEndpoints)
186  {
187  }
188 
189  /// Construct a UsdRiSplineAPI with the given \p splineName on
190  /// the prim held by \p schemaObj .
191  explicit UsdRiSplineAPI(const UsdSchemaBase& schemaObj,
192  const TfToken &splineName,
193  const SdfValueTypeName &valuesTypeName,
194  bool doesDuplicateBSplineEndpoints)
195  : UsdAPISchemaBase(schemaObj.GetPrim())
196  , _splineName(splineName)
197  , _valuesTypeName(valuesTypeName)
198  , _duplicateBSplineEndpoints(doesDuplicateBSplineEndpoints)
199  {
200  }
201 
202  /// Returns true if this UsdRiSplineAPI is configured to ensure
203  /// the endpoints are duplicated when using a bspline basis.
204  ///
205  /// Duplicating the endpoints ensures that the spline reaches
206  /// those points at either end of the parameter range.
207  USDRI_API
209  return _duplicateBSplineEndpoints;
210  }
211 
212  /// Returns the intended typename of the values attribute of the spline.
213  USDRI_API
215  return _valuesTypeName;
216  }
217 
218  // --------------------------------------------------------------------- //
219  // INTERPOLATION
220  // --------------------------------------------------------------------- //
221  /// Interpolation method for the spline.
222  ///
223  /// \n C++ Type: TfToken
224  /// \n Usd Type: SdfValueTypeNames->Token
225  /// \n Variability: SdfVariabilityUniform
226  /// \n Fallback Value: linear
227  /// \n \ref UsdRiTokens "Allowed Values": [linear, constant, bspline, catmullRom]
228  USDRI_API
230 
231  /// See GetInterpolationAttr(), and also
232  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
233  /// If specified, author \p defaultValue as the attribute's default,
234  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
235  /// the default for \p writeSparsely is \c false.
236  USDRI_API
237  UsdAttribute CreateInterpolationAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
238 
239  // --------------------------------------------------------------------- //
240  // POSITIONS
241  // --------------------------------------------------------------------- //
242  /// Positions of the knots.
243  ///
244  /// \n C++ Type: VtArray<float>
245  /// \n Usd Type: SdfValueTypeNames->FloatArray
246  /// \n Variability: SdfVariabilityUniform
247  /// \n Fallback Value: No Fallback
248  USDRI_API
250 
251  /// See GetPositionsAttr(), 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.
256  USDRI_API
257  UsdAttribute CreatePositionsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
258 
259  // --------------------------------------------------------------------- //
260  // VALUES
261  // --------------------------------------------------------------------- //
262  /// Values of the knots.
263  ///
264  /// \n C++ Type: See GetValuesTypeName()
265  /// \n Usd Type: See GetValuesTypeName()
266  /// \n Variability: SdfVariabilityUniform
267  /// \n Fallback Value: No Fallback
268  USDRI_API
269  UsdAttribute GetValuesAttr() const;
270 
271  /// See GetValuesAttr(), and also
272  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
273  /// If specified, author \p defaultValue as the attribute's default,
274  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
275  /// the default for \p writeSparsely is \c false.
276  USDRI_API
277  UsdAttribute CreateValuesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
278 
279  /// \anchor UsdRiSplineAPI_Validation
280  /// \name Spline Validation API
281  ///
282  /// API for validating the properties of a spline.
283  ///
284  /// @{
285 
286  /// Validates the attribute values belonging to the spline. Returns true
287  /// if the spline has all valid attribute values. Returns false and
288  /// populates the \p reason output argument if the spline has invalid
289  /// attribute values.
290  ///
291  /// Here's the list of validations performed by this method:
292  /// \li the SplineAPI must be fully initialized
293  /// \li interpolation attribute must exist and use an allowed value
294  /// \li the positions array must be a float array
295  /// \li the positions array must be sorted by increasing value
296  /// \li the values array must use the correct value type
297  /// \li the positions and values array must have the same size
298  ///
299  USDRI_API
300  bool Validate(std::string *reason) const;
301 
302  /// @}
303 
304 private:
305  /// Returns the properly-scoped form of the given property name,
306  /// accounting for the spline name.
307  TfToken _GetScopedPropertyName(const TfToken &baseName) const;
308 
309 private:
310  const TfToken _splineName;
311  const SdfValueTypeName _valuesTypeName;
312  bool _duplicateBSplineEndpoints;
313 };
314 
316 
317 #endif
USDRI_API bool DoesDuplicateBSplineEndpoints() const
Definition: splineAPI.h:208
static const UsdSchemaKind schemaKind
Definition: splineAPI.h:63
USDRI_API UsdAttribute GetValuesAttr() const
virtual USDRI_API ~UsdRiSplineAPI()
Destructor.
Single Apply API schema.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
UsdRiSplineAPI(const UsdSchemaBase &schemaObj)
Definition: splineAPI.h:77
static USDRI_API UsdRiSplineAPI Apply(const UsdPrim &prim)
UsdRiSplineAPI(const UsdPrim &prim=UsdPrim())
Definition: splineAPI.h:69
USDRI_API UsdAttribute GetPositionsAttr() const
Definition: token.h:70
USDRI_API UsdAttribute CreatePositionsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
static USDRI_API bool CanApply(const UsdPrim &prim, std::string *whyNot=nullptr)
Definition: prim.h:116
static USDRI_API UsdRiSplineAPI Get(const UsdStagePtr &stage, const SdfPath &path)
USDRI_API UsdAttribute GetInterpolationAttr() const
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
static USDRI_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
#define USDRI_API
Definition: api.h:23
Definition: path.h:273
UsdSchemaKind
Definition: common.h:112
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
USDRI_API SdfValueTypeName GetValuesTypeName() const
Returns the intended typename of the values attribute of the spline.
Definition: splineAPI.h:214
USDRI_API bool Validate(std::string *reason) const
USDRI_API UsdAttribute CreateInterpolationAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDRI_API UsdSchemaKind _GetSchemaKind() const override
USDRI_API UsdAttribute CreateValuesAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdRiSplineAPI(const UsdPrim &prim, const TfToken &splineName, const SdfValueTypeName &valuesTypeName, bool doesDuplicateBSplineEndpoints)
Definition: splineAPI.h:179
UsdPrim GetPrim() const
Return this schema object's held prim.
Definition: schemaBase.h:103
Definition: value.h:146
UsdRiSplineAPI(const UsdSchemaBase &schemaObj, const TfToken &splineName, const SdfValueTypeName &valuesTypeName, bool doesDuplicateBSplineEndpoints)
Definition: splineAPI.h:191