HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
boundable.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_BOUNDABLE_H
8 #define USDGEOM_GENERATED_BOUNDABLE_H
9 
10 /// \file usdGeom/boundable.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 // BOUNDABLE //
34 // -------------------------------------------------------------------------- //
35 
36 /// \class UsdGeomBoundable
37 ///
38 /// Boundable introduces the ability for a prim to persistently
39 /// cache a rectilinear, local-space, extent.
40 ///
41 /// \section UsdGeom_Boundable_Extent Why Extent and not Bounds ?
42 /// Boundable introduces the notion of "extent", which is a cached computation
43 /// of a prim's local-space 3D range for its resolved attributes <b>at the
44 /// layer and time in which extent is authored</b>. We have found that with
45 /// composed scene description, attempting to cache pre-computed bounds at
46 /// interior prims in a scene graph is very fragile, given the ease with which
47 /// one can author a single attribute in a stronger layer that can invalidate
48 /// many authored caches - or with which a re-published, referenced asset can
49 /// do the same.
50 ///
51 /// Therefore, we limit to precomputing (generally) leaf-prim extent, which
52 /// avoids the need to read in large point arrays to compute bounds, and
53 /// provides UsdGeomBBoxCache the means to efficiently compute and
54 /// (session-only) cache intermediate bounds. You are free to compute and
55 /// author intermediate bounds into your scenes, of course, which may work
56 /// well if you have sufficient locks on your pipeline to guarantee that once
57 /// authored, the geometry and transforms upon which they are based will
58 /// remain unchanged, or if accuracy of the bounds is not an ironclad
59 /// requisite.
60 ///
61 /// When intermediate bounds are authored on Boundable parents, the child prims
62 /// will be pruned from BBox computation; the authored extent is expected to
63 /// incorporate all child bounds.
64 ///
66 {
67 public:
68  /// Compile time constant representing what kind of schema this class is.
69  ///
70  /// \sa UsdSchemaKind
72 
73  /// Construct a UsdGeomBoundable on UsdPrim \p prim .
74  /// Equivalent to UsdGeomBoundable::Get(prim.GetStage(), prim.GetPath())
75  /// for a \em valid \p prim, but will not immediately throw an error for
76  /// an invalid \p prim
77  explicit UsdGeomBoundable(const UsdPrim& prim=UsdPrim())
78  : UsdGeomXformable(prim)
79  {
80  }
81 
82  /// Construct a UsdGeomBoundable on the prim held by \p schemaObj .
83  /// Should be preferred over UsdGeomBoundable(schemaObj.GetPrim()),
84  /// as it preserves SchemaBase state.
85  explicit UsdGeomBoundable(const UsdSchemaBase& schemaObj)
86  : UsdGeomXformable(schemaObj)
87  {
88  }
89 
90  /// Destructor.
92  virtual ~UsdGeomBoundable();
93 
94  /// Return a vector of names of all pre-declared attributes for this schema
95  /// class and all its ancestor classes. Does not include attributes that
96  /// may be authored by custom/extended methods of the schemas involved.
98  static const TfTokenVector &
99  GetSchemaAttributeNames(bool includeInherited=true);
100 
101  /// Return a UsdGeomBoundable holding the prim adhering to this
102  /// schema at \p path on \p stage. If no prim exists at \p path on
103  /// \p stage, or if the prim at that path does not adhere to this schema,
104  /// return an invalid schema object. This is shorthand for the following:
105  ///
106  /// \code
107  /// UsdGeomBoundable(stage->GetPrimAtPath(path));
108  /// \endcode
109  ///
111  static UsdGeomBoundable
112  Get(const UsdStagePtr &stage, const SdfPath &path);
113 
114 
115 protected:
116  /// Returns the kind of schema this class belongs to.
117  ///
118  /// \sa UsdSchemaKind
120  UsdSchemaKind _GetSchemaKind() const override;
121 
122 private:
123  // needs to invoke _GetStaticTfType.
124  friend class UsdSchemaRegistry;
126  static const TfType &_GetStaticTfType();
127 
128  static bool _IsTypedSchema();
129 
130  // override SchemaBase virtuals.
132  const TfType &_GetTfType() const override;
133 
134 public:
135  // --------------------------------------------------------------------- //
136  // EXTENT
137  // --------------------------------------------------------------------- //
138  /// Extent is a three dimensional range measuring the geometric
139  /// extent of the authored gprim in its own local space (i.e. its own
140  /// transform not applied), \em without accounting for any shader-induced
141  /// displacement. If __any__ extent value has been authored for a given
142  /// Boundable, then it should be authored at every timeSample at which
143  /// geometry-affecting properties are authored, to ensure correct
144  /// evaluation via ComputeExtent(). If __no__ extent value has been
145  /// authored, then ComputeExtent() will call the Boundable's registered
146  /// ComputeExtentFunction(), which may be expensive, which is why we
147  /// strongly encourage proper authoring of extent.
148  /// \sa ComputeExtent()
149  /// \sa \ref UsdGeom_Boundable_Extent.
150  ///
151  /// An authored extent on a prim which has children is expected to include
152  /// the extent of all children, as they will be pruned from BBox computation
153  /// during traversal.
154  ///
155  /// | ||
156  /// | -- | -- |
157  /// | Declaration | `float3[] extent` |
158  /// | C++ Type | VtArray<GfVec3f> |
159  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float3Array |
161  UsdAttribute GetExtentAttr() const;
162 
163  /// See GetExtentAttr(), and also
164  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
165  /// If specified, author \p defaultValue as the attribute's default,
166  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
167  /// the default for \p writeSparsely is \c false.
169  UsdAttribute CreateExtentAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
170 
171 public:
172  // ===================================================================== //
173  // Feel free to add custom code below this line, it will be preserved by
174  // the code generator.
175  //
176  // Just remember to:
177  // - Close the class declaration with };
178  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
179  // - Close the include guard with #endif
180  // ===================================================================== //
181  // --(BEGIN CUSTOM CODE)--
182 
183  /// If an extent is authored on this boundable, it queries the \p extent
184  /// from the extent attribute, otherwise if ComputeExtentFunction is
185  /// registered for the boundable's type, it computes the \p extent at
186  /// \p time. Returns true when extent is successfully populated, false
187  /// otherwise.
188  ///
189  /// \sa ComputeExtentFromPlugins
190  /// \sa UsdGeomRegisterComputeExtentFunction
192  bool ComputeExtent(const UsdTimeCode &time, VtVec3fArray *extent) const;
193 
194  /// Compute the extent for the Boundable prim \p boundable at time
195  /// \p time. If successful, populates \p extent with the result and
196  /// returns \c true, otherwise returns \c false.
197  ///
198  /// The extent computation is based on the concrete type of the prim
199  /// represented by \p boundable. Plugins that provide a Boundable
200  /// prim type may implement and register an extent computation for that
201  /// type using #UsdGeomRegisterComputeExtentFunction.
202  /// ComputeExtentFromPlugins will use this function to compute extents
203  /// for all prims of that type. If no function has been registered for
204  /// a prim type, but a function has been registered for one of its
205  /// base types, that function will be used instead.
206  ///
207  /// \note This function may load plugins in order to access the extent
208  /// computation for a prim type.
210  static bool ComputeExtentFromPlugins(const UsdGeomBoundable &boundable,
211  const UsdTimeCode &time,
212  VtVec3fArray *extent);
213 
214  /// \overload
215  /// Computes the extent as if the matrix \p transform was first applied.
217  static bool ComputeExtentFromPlugins(const UsdGeomBoundable &boundable,
218  const UsdTimeCode &time,
219  const GfMatrix4d &transform,
220  VtVec3fArray *extent);
221 
222 };
223 
225 
226 #endif
USDGEOM_API UsdAttribute GetExtentAttr() const
GT_API const UT_StringHolder time
virtual USDGEOM_API ~UsdGeomBoundable()
Destructor.
USDGEOM_API UsdAttribute CreateExtentAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDGEOM_API UsdSchemaKind _GetSchemaKind() const override
UsdGeomBoundable(const UsdSchemaBase &schemaObj)
Definition: boundable.h:85
UsdGeomBoundable(const UsdPrim &prim=UsdPrim())
Definition: boundable.h:77
Represents a non-concrete typed schema.
static const UsdSchemaKind schemaKind
Definition: boundable.h:71
static USDGEOM_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
static USDGEOM_API bool ComputeExtentFromPlugins(const UsdGeomBoundable &boundable, const UsdTimeCode &time, VtVec3fArray *extent)
Definition: path.h:273
GA_API const UT_StringHolder transform
UsdSchemaKind
Definition: common.h:112
static USDGEOM_API UsdGeomBoundable Get(const UsdStagePtr &stage, const SdfPath &path)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDGEOM_API bool ComputeExtent(const UsdTimeCode &time, VtVec3fArray *extent) const
Definition: type.h:47
#define USDGEOM_API
Definition: api.h:23
Definition: value.h:146