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 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_POINTS_H
25 #define USDGEOM_GENERATED_POINTS_H
26 
27 /// \file usdGeom/points.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 // POINTS //
51 // -------------------------------------------------------------------------- //
52 
53 /// \class UsdGeomPoints
54 ///
55 /// Points are analogous to the <A HREF="https://renderman.pixar.com/resources/RenderMan_20/appnote.18.html">RiPoints spec</A>.
56 ///
57 /// Points can be an efficient means of storing and rendering particle
58 /// effects comprised of thousands or millions of small particles. Points
59 /// generally receive a single shading sample each, which should take
60 /// \em normals into account, if present.
61 ///
62 /// While not technically UsdGeomPrimvars, the widths and normals also
63 /// have interpolation metadata. It's common for authored widths and normals
64 /// to have constant or varying interpolation.
65 ///
67 {
68 public:
69  /// Compile time constant representing what kind of schema this class is.
70  ///
71  /// \sa UsdSchemaKind
73 
74  /// Construct a UsdGeomPoints on UsdPrim \p prim .
75  /// Equivalent to UsdGeomPoints::Get(prim.GetStage(), prim.GetPath())
76  /// for a \em valid \p prim, but will not immediately throw an error for
77  /// an invalid \p prim
78  explicit UsdGeomPoints(const UsdPrim& prim=UsdPrim())
79  : UsdGeomPointBased(prim)
80  {
81  }
82 
83  /// Construct a UsdGeomPoints on the prim held by \p schemaObj .
84  /// Should be preferred over UsdGeomPoints(schemaObj.GetPrim()),
85  /// as it preserves SchemaBase state.
86  explicit UsdGeomPoints(const UsdSchemaBase& schemaObj)
87  : UsdGeomPointBased(schemaObj)
88  {
89  }
90 
91  /// Destructor.
93  virtual ~UsdGeomPoints();
94 
95  /// Return a vector of names of all pre-declared attributes for this schema
96  /// class and all its ancestor classes. Does not include attributes that
97  /// may be authored by custom/extended methods of the schemas involved.
99  static const TfTokenVector &
100  GetSchemaAttributeNames(bool includeInherited=true);
101 
102  /// Return a UsdGeomPoints holding the prim adhering to this
103  /// schema at \p path on \p stage. If no prim exists at \p path on
104  /// \p stage, or if the prim at that path does not adhere to this schema,
105  /// return an invalid schema object. This is shorthand for the following:
106  ///
107  /// \code
108  /// UsdGeomPoints(stage->GetPrimAtPath(path));
109  /// \endcode
110  ///
112  static UsdGeomPoints
113  Get(const UsdStagePtr &stage, const SdfPath &path);
114 
115  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
116  /// is defined (according to UsdPrim::IsDefined()) on this stage.
117  ///
118  /// If a prim adhering to this schema at \p path is already defined on this
119  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
120  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
121  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
122  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
123  /// current EditTarget for any nonexistent, or existing but not \a Defined
124  /// ancestors.
125  ///
126  /// The given \a path must be an absolute prim path that does not contain
127  /// any variant selections.
128  ///
129  /// If it is impossible to author any of the necessary PrimSpecs, (for
130  /// example, in case \a path cannot map to the current UsdEditTarget's
131  /// namespace) issue an error and return an invalid \a UsdPrim.
132  ///
133  /// Note that this method may return a defined prim whose typeName does not
134  /// specify this schema class, in case a stronger typeName opinion overrides
135  /// the opinion at the current EditTarget.
136  ///
138  static UsdGeomPoints
139  Define(const UsdStagePtr &stage, const SdfPath &path);
140 
141 protected:
142  /// Returns the kind of schema this class belongs to.
143  ///
144  /// \sa UsdSchemaKind
146  UsdSchemaKind _GetSchemaKind() const override;
147 
148 private:
149  // needs to invoke _GetStaticTfType.
150  friend class UsdSchemaRegistry;
152  static const TfType &_GetStaticTfType();
153 
154  static bool _IsTypedSchema();
155 
156  // override SchemaBase virtuals.
158  const TfType &_GetTfType() const override;
159 
160 public:
161  // --------------------------------------------------------------------- //
162  // WIDTHS
163  // --------------------------------------------------------------------- //
164  /// Widths are defined as the \em diameter of the points, in
165  /// object space. 'widths' is not a generic Primvar, but
166  /// the number of elements in this attribute will be determined by
167  /// its 'interpolation'. See \ref SetWidthsInterpolation() . If
168  /// 'widths' and 'primvars:widths' are both specified, the latter
169  /// has precedence.
170  ///
171  /// | ||
172  /// | -- | -- |
173  /// | Declaration | `float[] widths` |
174  /// | C++ Type | VtArray<float> |
175  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->FloatArray |
177  UsdAttribute GetWidthsAttr() const;
178 
179  /// See GetWidthsAttr(), and also
180  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
181  /// If specified, author \p defaultValue as the attribute's default,
182  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
183  /// the default for \p writeSparsely is \c false.
185  UsdAttribute CreateWidthsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
186 
187 public:
188  // --------------------------------------------------------------------- //
189  // IDS
190  // --------------------------------------------------------------------- //
191  /// Ids are optional; if authored, the ids array should be the same
192  /// length as the points array, specifying (at each timesample if
193  /// point identities are changing) the id of each point. The
194  /// type is signed intentionally, so that clients can encode some
195  /// binary state on Id'd points without adding a separate
196  /// primvar.
197  ///
198  /// | ||
199  /// | -- | -- |
200  /// | Declaration | `int64[] ids` |
201  /// | C++ Type | VtArray<int64_t> |
202  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int64Array |
204  UsdAttribute GetIdsAttr() const;
205 
206  /// See GetIdsAttr(), and also
207  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
208  /// If specified, author \p defaultValue as the attribute's default,
209  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
210  /// the default for \p writeSparsely is \c false.
212  UsdAttribute CreateIdsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
213 
214 public:
215  // ===================================================================== //
216  // Feel free to add custom code below this line, it will be preserved by
217  // the code generator.
218  //
219  // Just remember to:
220  // - Close the class declaration with };
221  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
222  // - Close the include guard with #endif
223  // ===================================================================== //
224  // --(BEGIN CUSTOM CODE)--
225 
226  /// Get the \ref Usd_InterpolationVals "interpolation" for the \em widths
227  /// attribute.
228  ///
229  /// Although 'widths' is not classified as a generic UsdGeomPrimvar (and
230  /// will not be included in the results of UsdGeomPrimvarsAPI::GetPrimvars() )
231  /// it does require an interpolation specification. The fallback
232  /// interpolation, if left unspecified, is UsdGeomTokens->vertex ,
233  /// which means a width value is specified for each point.
236 
237  /// Set the \ref Usd_InterpolationVals "interpolation" for the \em widths
238  /// attribute.
239  ///
240  /// \return true upon success, false if \p interpolation is not a legal
241  /// value as defined by UsdPrimvar::IsValidInterpolation(), or if there
242  /// was a problem setting the value. No attempt is made to validate
243  /// that the widths attr's value contains the right number of elements
244  /// to match its interpolation to its prim's topology.
245  ///
246  /// \sa GetWidthsInterpolation()
248  bool SetWidthsInterpolation(TfToken const &interpolation);
249 
250  /// Compute the extent for the point cloud defined by points and widths.
251  ///
252  /// \return true upon success, false if widths and points are different
253  /// sized arrays.
254  ///
255  /// On success, extent will contain the axis-aligned bounding box of the
256  /// point cloud defined by points with the given widths.
257  ///
258  /// This function is to provide easy authoring of extent for usd authoring
259  /// tools, hence it is static and acts outside a specific prim (as in
260  /// attribute based methods).
262  static bool ComputeExtent(const VtVec3fArray& points,
263  const VtFloatArray& widths, VtVec3fArray* extent);
264 
265  /// \overload
266  /// Computes the extent as if the matrix \p transform was first applied.
268  static bool ComputeExtent(const VtVec3fArray& points,
269  const VtFloatArray& widths, const GfMatrix4d& transform,
270  VtVec3fArray* extent);
271 
272  /// Returns the number of points as defined by the size of the
273  /// _points_ array at _timeCode_.
274  ///
275  /// \snippetdoc snippets.dox GetCount
276  /// \sa GetPointsAttr()
278  size_t GetPointCount(UsdTimeCode timeCode = UsdTimeCode::Default()) const;
279 
280 };
281 
283 
284 #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:112
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:87
Represents a concrete typed schema.
USDGEOM_API UsdAttribute GetIdsAttr() const
Definition: prim.h:133
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
USDGEOM_API UsdAttribute GetWidthsAttr() const
static USDGEOM_API bool ComputeExtent(const VtVec3fArray &points, const VtFloatArray &widths, VtVec3fArray *extent)
Definition: path.h:290
GA_API const UT_StringHolder transform
UsdGeomPoints(const UsdPrim &prim=UsdPrim())
Definition: points.h:78
UsdSchemaKind
Definition: common.h:129
USDGEOM_API UsdSchemaKind _GetSchemaKind() const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
USDGEOM_API bool SetWidthsInterpolation(TfToken const &interpolation)
static const UsdSchemaKind schemaKind
Definition: points.h:72
UsdGeomPoints(const UsdSchemaBase &schemaObj)
Definition: points.h:86
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: type.h:64
#define USDGEOM_API
Definition: api.h:40
USDGEOM_API UsdAttribute CreateWidthsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
Definition: value.h:164