HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
points.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 USDGEOM_GENERATED_POINTS_H
8 #define USDGEOM_GENERATED_POINTS_H
9 
10 /// \file usdGeom/points.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdGeom/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 #include "pxr/usd/usdGeom/tokens.h"
18 
19 #include "pxr/base/vt/value.h"
20 
21 #include "pxr/base/gf/vec3d.h"
22 #include "pxr/base/gf/vec3f.h"
23 #include "pxr/base/gf/matrix4d.h"
24 
25 #include "pxr/base/tf/token.h"
26 #include "pxr/base/tf/type.h"
27 
29 
30 class SdfAssetPath;
31 
32 // -------------------------------------------------------------------------- //
33 // POINTS //
34 // -------------------------------------------------------------------------- //
35 
36 /// \class UsdGeomPoints
37 ///
38 /// Points are analogous to the <A HREF="https://renderman.pixar.com/resources/RenderMan_20/appnote.18.html">RiPoints spec</A>.
39 ///
40 /// Points can be an efficient means of storing and rendering particle
41 /// effects comprised of thousands or millions of small particles. Points
42 /// generally receive a single shading sample each, which should take
43 /// \em normals into account, if present.
44 ///
45 /// While not technically UsdGeomPrimvars, the widths and normals also
46 /// have interpolation metadata. It's common for authored widths and normals
47 /// to have constant or varying interpolation.
48 ///
50 {
51 public:
52  /// Compile time constant representing what kind of schema this class is.
53  ///
54  /// \sa UsdSchemaKind
56 
57  /// Construct a UsdGeomPoints on UsdPrim \p prim .
58  /// Equivalent to UsdGeomPoints::Get(prim.GetStage(), prim.GetPath())
59  /// for a \em valid \p prim, but will not immediately throw an error for
60  /// an invalid \p prim
61  explicit UsdGeomPoints(const UsdPrim& prim=UsdPrim())
62  : UsdGeomPointBased(prim)
63  {
64  }
65 
66  /// Construct a UsdGeomPoints on the prim held by \p schemaObj .
67  /// Should be preferred over UsdGeomPoints(schemaObj.GetPrim()),
68  /// as it preserves SchemaBase state.
69  explicit UsdGeomPoints(const UsdSchemaBase& schemaObj)
70  : UsdGeomPointBased(schemaObj)
71  {
72  }
73 
74  /// Destructor.
76  virtual ~UsdGeomPoints();
77 
78  /// Return a vector of names of all pre-declared attributes for this schema
79  /// class and all its ancestor classes. Does not include attributes that
80  /// may be authored by custom/extended methods of the schemas involved.
82  static const TfTokenVector &
83  GetSchemaAttributeNames(bool includeInherited=true);
84 
85  /// Return a UsdGeomPoints holding the prim adhering to this
86  /// schema at \p path on \p stage. If no prim exists at \p path on
87  /// \p stage, or if the prim at that path does not adhere to this schema,
88  /// return an invalid schema object. This is shorthand for the following:
89  ///
90  /// \code
91  /// UsdGeomPoints(stage->GetPrimAtPath(path));
92  /// \endcode
93  ///
95  static UsdGeomPoints
96  Get(const UsdStagePtr &stage, const SdfPath &path);
97 
98  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
99  /// is defined (according to UsdPrim::IsDefined()) on this stage.
100  ///
101  /// If a prim adhering to this schema at \p path is already defined on this
102  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
103  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
104  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
105  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
106  /// current EditTarget for any nonexistent, or existing but not \a Defined
107  /// ancestors.
108  ///
109  /// The given \a path must be an absolute prim path that does not contain
110  /// any variant selections.
111  ///
112  /// If it is impossible to author any of the necessary PrimSpecs, (for
113  /// example, in case \a path cannot map to the current UsdEditTarget's
114  /// namespace) issue an error and return an invalid \a UsdPrim.
115  ///
116  /// Note that this method may return a defined prim whose typeName does not
117  /// specify this schema class, in case a stronger typeName opinion overrides
118  /// the opinion at the current EditTarget.
119  ///
121  static UsdGeomPoints
122  Define(const UsdStagePtr &stage, const SdfPath &path);
123 
124 protected:
125  /// Returns the kind of schema this class belongs to.
126  ///
127  /// \sa UsdSchemaKind
129  UsdSchemaKind _GetSchemaKind() const override;
130 
131 private:
132  // needs to invoke _GetStaticTfType.
133  friend class UsdSchemaRegistry;
135  static const TfType &_GetStaticTfType();
136 
137  static bool _IsTypedSchema();
138 
139  // override SchemaBase virtuals.
141  const TfType &_GetTfType() const override;
142 
143 public:
144  // --------------------------------------------------------------------- //
145  // WIDTHS
146  // --------------------------------------------------------------------- //
147  /// Widths are defined as the \em diameter of the points, in
148  /// object space. 'widths' is not a generic Primvar, but
149  /// the number of elements in this attribute will be determined by
150  /// its 'interpolation'. See \ref SetWidthsInterpolation() . If
151  /// 'widths' and 'primvars:widths' are both specified, the latter
152  /// has precedence.
153  ///
154  /// | ||
155  /// | -- | -- |
156  /// | Declaration | `float[] widths` |
157  /// | C++ Type | VtArray<float> |
158  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->FloatArray |
160  UsdAttribute GetWidthsAttr() const;
161 
162  /// See GetWidthsAttr(), and also
163  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
164  /// If specified, author \p defaultValue as the attribute's default,
165  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
166  /// the default for \p writeSparsely is \c false.
168  UsdAttribute CreateWidthsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
169 
170 public:
171  // --------------------------------------------------------------------- //
172  // IDS
173  // --------------------------------------------------------------------- //
174  /// Ids are optional; if authored, the ids array should be the same
175  /// length as the points array, specifying (at each timesample if
176  /// point identities are changing) the id of each point. The
177  /// type is signed intentionally, so that clients can encode some
178  /// binary state on Id'd points without adding a separate
179  /// primvar.
180  ///
181  /// | ||
182  /// | -- | -- |
183  /// | Declaration | `int64[] ids` |
184  /// | C++ Type | VtArray<int64_t> |
185  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int64Array |
187  UsdAttribute GetIdsAttr() const;
188 
189  /// See GetIdsAttr(), 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 CreateIdsAttr(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 for each point.
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 point cloud defined by points and widths.
234  ///
235  /// \return true upon success, false if widths and points are different
236  /// sized arrays.
237  ///
238  /// On success, extent will contain the axis-aligned bounding box of the
239  /// point cloud defined by points with the given widths.
240  ///
241  /// This function is to provide easy authoring of extent for usd authoring
242  /// tools, hence it is static and acts outside a specific prim (as in
243  /// attribute based methods).
245  static bool ComputeExtent(const VtVec3fArray& points,
246  const VtFloatArray& widths, VtVec3fArray* extent);
247 
248  /// \overload
249  /// Computes the extent as if the matrix \p transform was first applied.
251  static bool ComputeExtent(const VtVec3fArray& points,
252  const VtFloatArray& widths, const GfMatrix4d& transform,
253  VtVec3fArray* extent);
254 
255  /// Returns the number of points as defined by the size of the
256  /// _points_ array at _timeCode_.
257  ///
258  /// \snippetdoc snippets.dox GetCount
259  /// \sa GetPointsAttr()
261  size_t GetPointCount(UsdTimeCode timeCode = UsdTimeCode::Default()) const;
262 
263 };
264 
266 
267 #endif
USDGEOM_API size_t GetPointCount(UsdTimeCode timeCode=UsdTimeCode::Default()) const
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
static USDGEOM_API UsdGeomPoints Define(const UsdStagePtr &stage, const SdfPath &path)
static constexpr UsdTimeCode Default()
Definition: timeCode.h:113
static USDGEOM_API UsdGeomPoints Get(const UsdStagePtr &stage, const SdfPath &path)
USDGEOM_API TfToken GetWidthsInterpolation() const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
static USDGEOM_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
virtual USDGEOM_API ~UsdGeomPoints()
Destructor.
USDGEOM_API UsdAttribute CreateIdsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: token.h:70
Represents a concrete typed schema.
USDGEOM_API UsdAttribute GetIdsAttr() const
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
USDGEOM_API UsdAttribute GetWidthsAttr() const
static USDGEOM_API bool ComputeExtent(const VtVec3fArray &points, const VtFloatArray &widths, VtVec3fArray *extent)
Definition: path.h:273
GA_API const UT_StringHolder transform
UsdGeomPoints(const UsdPrim &prim=UsdPrim())
Definition: points.h:61
UsdSchemaKind
Definition: common.h:112
USDGEOM_API UsdSchemaKind _GetSchemaKind() const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDGEOM_API bool SetWidthsInterpolation(TfToken const &interpolation)
static const UsdSchemaKind schemaKind
Definition: points.h:55
UsdGeomPoints(const UsdSchemaBase &schemaObj)
Definition: points.h:69
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: type.h:47
#define USDGEOM_API
Definition: api.h:23
USDGEOM_API UsdAttribute CreateWidthsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: value.h:146