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