HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pointBased.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_POINTBASED_H
25 #define USDGEOM_GENERATED_POINTBASED_H
26 
27 /// \file usdGeom/pointBased.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 // POINTBASED //
51 // -------------------------------------------------------------------------- //
52 
53 /// \class UsdGeomPointBased
54 ///
55 /// Base class for all UsdGeomGprims that possess points,
56 /// providing common attributes such as normals and velocities.
57 ///
59 {
60 public:
61  /// Compile time constant representing what kind of schema this class is.
62  ///
63  /// \sa UsdSchemaKind
65 
66  /// Construct a UsdGeomPointBased on UsdPrim \p prim .
67  /// Equivalent to UsdGeomPointBased::Get(prim.GetStage(), prim.GetPath())
68  /// for a \em valid \p prim, but will not immediately throw an error for
69  /// an invalid \p prim
70  explicit UsdGeomPointBased(const UsdPrim& prim=UsdPrim())
71  : UsdGeomGprim(prim)
72  {
73  }
74 
75  /// Construct a UsdGeomPointBased on the prim held by \p schemaObj .
76  /// Should be preferred over UsdGeomPointBased(schemaObj.GetPrim()),
77  /// as it preserves SchemaBase state.
78  explicit UsdGeomPointBased(const UsdSchemaBase& schemaObj)
79  : UsdGeomGprim(schemaObj)
80  {
81  }
82 
83  /// Destructor.
85  virtual ~UsdGeomPointBased();
86 
87  /// Return a vector of names of all pre-declared attributes for this schema
88  /// class and all its ancestor classes. Does not include attributes that
89  /// may be authored by custom/extended methods of the schemas involved.
91  static const TfTokenVector &
92  GetSchemaAttributeNames(bool includeInherited=true);
93 
94  /// Return a UsdGeomPointBased holding the prim adhering to this
95  /// schema at \p path on \p stage. If no prim exists at \p path on
96  /// \p stage, or if the prim at that path does not adhere to this schema,
97  /// return an invalid schema object. This is shorthand for the following:
98  ///
99  /// \code
100  /// UsdGeomPointBased(stage->GetPrimAtPath(path));
101  /// \endcode
102  ///
104  static UsdGeomPointBased
105  Get(const UsdStagePtr &stage, const SdfPath &path);
106 
107 
108 protected:
109  /// Returns the kind of schema this class belongs to.
110  ///
111  /// \sa UsdSchemaKind
113  UsdSchemaKind _GetSchemaKind() const override;
114 
115 private:
116  // needs to invoke _GetStaticTfType.
117  friend class UsdSchemaRegistry;
119  static const TfType &_GetStaticTfType();
120 
121  static bool _IsTypedSchema();
122 
123  // override SchemaBase virtuals.
125  const TfType &_GetTfType() const override;
126 
127 public:
128  // --------------------------------------------------------------------- //
129  // POINTS
130  // --------------------------------------------------------------------- //
131  /// The primary geometry attribute for all PointBased
132  /// primitives, describes points in (local) space.
133  ///
134  /// | ||
135  /// | -- | -- |
136  /// | Declaration | `point3f[] points` |
137  /// | C++ Type | VtArray<GfVec3f> |
138  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Point3fArray |
140  UsdAttribute GetPointsAttr() const;
141 
142  /// See GetPointsAttr(), and also
143  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
144  /// If specified, author \p defaultValue as the attribute's default,
145  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
146  /// the default for \p writeSparsely is \c false.
148  UsdAttribute CreatePointsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
149 
150 public:
151  // --------------------------------------------------------------------- //
152  // VELOCITIES
153  // --------------------------------------------------------------------- //
154  /// If provided, 'velocities' should be used by renderers to
155  ///
156  /// compute positions between samples for the 'points' attribute, rather
157  /// than interpolating between neighboring 'points' samples. This is the
158  /// only reasonable means of computing motion blur for topologically
159  /// varying PointBased primitives. It follows that the length of each
160  /// 'velocities' sample must match the length of the corresponding
161  /// 'points' sample. Velocity is measured in position units per second,
162  /// as per most simulation software. To convert to position units per
163  /// UsdTimeCode, divide by UsdStage::GetTimeCodesPerSecond().
164  ///
165  /// See also \ref UsdGeom_VelocityInterpolation .
166  ///
167  /// | ||
168  /// | -- | -- |
169  /// | Declaration | `vector3f[] velocities` |
170  /// | C++ Type | VtArray<GfVec3f> |
171  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3fArray |
174 
175  /// See GetVelocitiesAttr(), and also
176  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
177  /// If specified, author \p defaultValue as the attribute's default,
178  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
179  /// the default for \p writeSparsely is \c false.
181  UsdAttribute CreateVelocitiesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
182 
183 public:
184  // --------------------------------------------------------------------- //
185  // ACCELERATIONS
186  // --------------------------------------------------------------------- //
187  /// If provided, 'accelerations' should be used with
188  /// velocities to compute positions between samples for the 'points'
189  /// attribute rather than interpolating between neighboring 'points'
190  /// samples. Acceleration is measured in position units per second-squared.
191  /// To convert to position units per squared UsdTimeCode, divide by the
192  /// square of UsdStage::GetTimeCodesPerSecond().
193  ///
194  /// | ||
195  /// | -- | -- |
196  /// | Declaration | `vector3f[] accelerations` |
197  /// | C++ Type | VtArray<GfVec3f> |
198  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3fArray |
201 
202  /// See GetAccelerationsAttr(), and also
203  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
204  /// If specified, author \p defaultValue as the attribute's default,
205  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
206  /// the default for \p writeSparsely is \c false.
208  UsdAttribute CreateAccelerationsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
209 
210 public:
211  // --------------------------------------------------------------------- //
212  // NORMALS
213  // --------------------------------------------------------------------- //
214  /// Provide an object-space orientation for individual points,
215  /// which, depending on subclass, may define a surface, curve, or free
216  /// points. Note that 'normals' should not be authored on any Mesh that
217  /// is subdivided, since the subdivision algorithm will define its own
218  /// normals. 'normals' is not a generic primvar, but the number of elements
219  /// in this attribute will be determined by its 'interpolation'. See
220  /// \ref SetNormalsInterpolation() . If 'normals' and 'primvars:normals'
221  /// are both specified, the latter has precedence.
222  ///
223  /// | ||
224  /// | -- | -- |
225  /// | Declaration | `normal3f[] normals` |
226  /// | C++ Type | VtArray<GfVec3f> |
227  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Normal3fArray |
230 
231  /// See GetNormalsAttr(), 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.
237  UsdAttribute CreateNormalsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
238 
239 public:
240  // ===================================================================== //
241  // Feel free to add custom code below this line, it will be preserved by
242  // the code generator.
243  //
244  // Just remember to:
245  // - Close the class declaration with };
246  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
247  // - Close the include guard with #endif
248  // ===================================================================== //
249  // --(BEGIN CUSTOM CODE)--
250 
251  /// Get the \ref Usd_InterpolationVals "interpolation" for the \em normals
252  /// attribute.
253  ///
254  /// Although 'normals' is not classified as a generic UsdGeomPrimvar (and
255  /// will not be included in the results of UsdGeomImageable::GetPrimvars() )
256  /// it does require an interpolation specification. The fallback
257  /// interpolation, if left unspecified, is UsdGeomTokens->vertex ,
258  /// which will generally produce smooth shading on a polygonal mesh.
259  /// To achieve partial or fully faceted shading of a polygonal mesh
260  /// with normals, one should use UsdGeomTokens->faceVarying or
261  /// UsdGeomTokens->uniform interpolation.
264 
265  /// Set the \ref Usd_InterpolationVals "interpolation" for the \em normals
266  /// attribute.
267  ///
268  /// \return true upon success, false if \p interpolation is not a legal
269  /// value as defined by UsdGeomPrimvar::IsValidInterpolation(), or if there
270  /// was a problem setting the value. No attempt is made to validate
271  /// that the normals attr's value contains the right number of elements
272  /// to match its interpolation to its prim's topology.
273  ///
274  /// \sa GetNormalsInterpolation()
276  bool SetNormalsInterpolation(TfToken const &interpolation);
277 
278  /// Compute the extent for the point cloud defined by points.
279  ///
280  /// \return true on success, false if extents was unable to be calculated.
281  ///
282  /// On success, extent will contain the axis-aligned bounding box of the
283  /// point cloud defined by points.
284  ///
285  /// This function is to provide easy authoring of extent for usd authoring
286  /// tools, hence it is static and acts outside a specific prim (as in
287  /// attribute based methods).
289  static bool ComputeExtent(const VtVec3fArray& points, VtVec3fArray* extent);
290 
291  /// \overload
292  /// Computes the extent as if the matrix \p transform was first applied.
294  static bool ComputeExtent(const VtVec3fArray& points,
295  const GfMatrix4d& transform, VtVec3fArray* extent);
296 
297 public:
298  /// Compute points given the positions, velocities and accelerations
299  /// at \p time.
300  ///
301  /// This will return \c false and leave \p points untouched if:
302  /// - \p points is NULL
303  /// - one of \p time and \p baseTime is numeric and the other is
304  /// UsdTimeCode::Default() (they must either both be numeric or both be
305  /// default)
306  /// - there is no authored points attribute
307  ///
308  /// If there is no error, we will return \c true and \p points will contain
309  /// the computed points.
310  ///
311  /// \param points - the out parameter for the new points. Its size
312  /// will depend on the authored data.
313  /// \param time - UsdTimeCode at which we want to evaluate the transforms
314  /// \param baseTime - required for correct interpolation between samples
315  /// when \em velocities or \em accelerations are
316  /// present. If there are samples for \em positions and
317  /// \em velocities at t1 and t2, normal value resolution
318  /// would attempt to interpolate between the two samples,
319  /// and if they could not be interpolated because they
320  /// differ in size (common in cases where velocity is
321  /// authored), will choose the sample at t1. When
322  /// sampling for the purposes of motion-blur, for example,
323  /// it is common, when rendering the frame at t2, to
324  /// sample at [ t2-shutter/2, t2+shutter/2 ] for a
325  /// shutter interval of \em shutter. The first sample
326  /// falls between t1 and t2, but we must sample at t2
327  /// and apply velocity-based interpolation based on those
328  /// samples to get a correct result. In such scenarios,
329  /// one should provide a \p baseTime of t2 when querying
330  /// \em both samples. If your application does not care
331  /// about off-sample interpolation, it can supply the
332  /// same value for \p baseTime that it does for \p time.
333  /// When \p baseTime is less than or equal to \p time,
334  /// we will choose the lower bracketing timeSample.
336  bool
339  const UsdTimeCode time,
340  const UsdTimeCode baseTime) const;
341 
342  /// Compute points as in ComputePointsAtTime, but using multiple sample times. An
343  /// array of vector arrays is returned where each vector array contains the
344  /// points for the corresponding time in \p times .
345  ///
346  /// \param times - A vector containing the UsdTimeCodes at which we want to
347  /// sample.
349  bool
351  std::vector<VtArray<GfVec3f>>* pointsArray,
352  const std::vector<UsdTimeCode>& times,
353  const UsdTimeCode baseTime) const;
354 
355  /// \overload
356  /// Perform the point computation. This does the same computation as
357  /// the non-static ComputePointsAtTime method, but takes all
358  /// data as parameters rather than accessing authored data.
359  ///
360  /// \param points - the out parameter for the computed points. Its size
361  /// will depend on the given data.
362  /// \param stage - the UsdStage
363  /// \param time - time at which we want to evaluate the transforms
364  /// \param positions - array containing all current points.
365  /// \param velocities - array containing all velocities. This array
366  /// must be either the same size as \p positions or
367  /// empty. If it is empty, points are computed as if
368  /// all velocities were zero in all dimensions.
369  /// \param velocitiesSampleTime - time at which the samples from
370  /// \p velocities were taken.
371  /// \param accelerations - array containing all accelerations.
372  /// This array must be either the same size as
373  /// \p positions or empty. If it is empty, points
374  /// are computed as if all accelerations were zero in
375  /// all dimensions.
376  /// \param velocityScale - factor used to artificially increase the effect
377  /// of velocity on positions.
379  static bool
382  UsdStageWeakPtr& stage,
384  const VtVec3fArray& positions,
385  const VtVec3fArray& velocities,
386  UsdTimeCode velocitiesSampleTime,
387  const VtVec3fArray& accelerations,
388  float velocityScale);
389 
390 };
391 
393 
394 #endif
GLint GLenum GLsizei GLsizei GLsizei GLsizei extent
Definition: glew.h:15877
GT_API const UT_StringHolder time
UsdGeomPointBased(const UsdPrim &prim=UsdPrim())
Definition: pointBased.h:70
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
USDGEOM_API bool ComputePointsAtTime(VtArray< GfVec3f > *points, const UsdTimeCode time, const UsdTimeCode baseTime) const
USDGEOM_API UsdAttribute CreateNormalsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDGEOM_API UsdAttribute GetAccelerationsAttr() const
USDGEOM_API UsdAttribute GetPointsAttr() const
GLuint GLenum GLenum transform
Definition: glew.h:15055
UsdSchemaKind
Definition: common.h:127
Definition: token.h:87
static const UsdSchemaKind schemaKind
Definition: pointBased.h:64
Definition: prim.h:132
USDGEOM_API TfToken GetNormalsInterpolation() const
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
Definition: path.h:288
USDGEOM_API UsdSchemaKind _GetSchemaKind() const override
UsdGeomPointBased(const UsdSchemaBase &schemaObj)
Definition: pointBased.h:78
static USDGEOM_API UsdGeomPointBased Get(const UsdStagePtr &stage, const SdfPath &path)
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glew.h:3460
USDGEOM_API UsdAttribute CreateVelocitiesAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdStagePtr UsdStageWeakPtr
Definition: common.h:55
USDGEOM_API UsdAttribute GetNormalsAttr() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
USDGEOM_API UsdAttribute CreateAccelerationsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
virtual USDGEOM_API ~UsdGeomPointBased()
Destructor.
USDGEOM_API UsdAttribute CreatePointsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDGEOM_API bool SetNormalsInterpolation(TfToken const &interpolation)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Represents a non-concrete typed schema.
Definition: type.h:64
#define USDGEOM_API
Definition: api.h:40
USDGEOM_API bool ComputePointsAtTimes(std::vector< VtArray< GfVec3f >> *pointsArray, const std::vector< UsdTimeCode > &times, const UsdTimeCode baseTime) const
Definition: value.h:168
USDGEOM_API UsdAttribute GetVelocitiesAttr() const
static USDGEOM_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
static USDGEOM_API bool ComputeExtent(const VtVec3fArray &points, VtVec3fArray *extent)