HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
topology.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 PXR_USD_USD_SKEL_TOPOLOGY_H
8 #define PXR_USD_USD_SKEL_TOPOLOGY_H
9 
10 /// \file usdSkel/topology.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdSkel/api.h"
14 
15 #include "pxr/base/tf/span.h"
16 #include "pxr/usd/sdf/path.h"
17 #include "pxr/usd/sdf/types.h"
18 
19 
21 
22 
23 /// \class UsdSkelTopology
24 ///
25 /// Object holding information describing skeleton topology.
26 /// This provides the hierarchical information needed to reason about joint
27 /// relationships in a manner suitable to computations.
29 {
30 public:
31  /// Construct an empty topology.
32  UsdSkelTopology() = default;
33 
34  /// Construct a skel topology from \p paths, an array holding ordered joint
35  /// paths as tokens.
36  /// Internally, each token must be converted to an SdfPath. If SdfPath
37  /// objects are already accessible, it is more efficient to use the
38  /// construct taking an SdfPath array.
41 
42  /// Construct a skel topology from \p paths, an array of joint paths.
45 
46  /// Construct a skel topology from an array of parent indices.
47  /// For each joint, this provides the parent index of that
48  /// joint, or -1 if none.
50  UsdSkelTopology(const VtIntArray& parentIndices);
51 
52  /// Validate the topology.
53  /// If validation is unsuccessful, a reason
54  /// why will be written to \p reason, if provided.
56  bool Validate(std::string* reason=nullptr) const;
57 
58  const VtIntArray& GetParentIndices() const { return _parentIndices; }
59 
60  size_t GetNumJoints() const { return size(); }
61 
62  size_t size() const { return _parentIndices.size(); }
63 
64  /// Returns the parent joint of the \p index'th joint,
65  /// Returns -1 for joints with no parent (roots).
66  inline int GetParent(size_t index) const;
67 
68  /// Returns true if the \p index'th joint is a root joint.
69  bool IsRoot(size_t index) const { return GetParent(index) < 0; }
70 
71  bool operator==(const UsdSkelTopology& o) const;
72 
73  bool operator!=(const UsdSkelTopology& o) const {
74  return !(*this == o);
75  }
76 
77 private:
78  VtIntArray _parentIndices;
79 };
80 
81 
82 int
84 {
85  TF_DEV_AXIOM(index < _parentIndices.size());
86  return _parentIndices[index];
87 }
88 
89 
91 
92 #endif // PXR_USD_USD_SKEL_TOPOLOGY_H
bool operator==(const UsdSkelTopology &o) const
const VtIntArray & GetParentIndices() const
Definition: topology.h:58
#define TF_DEV_AXIOM(cond)
Definition: span.h:70
UsdSkelTopology()=default
Construct an empty topology.
#define USDSKEL_API
Definition: api.h:23
size_t GetNumJoints() const
Definition: topology.h:60
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
size_t size() const
Definition: topology.h:62
int GetParent(size_t index) const
Definition: topology.h:83
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
bool operator!=(const UsdSkelTopology &o) const
Definition: topology.h:73
USDSKEL_API bool Validate(std::string *reason=nullptr) const
bool IsRoot(size_t index) const
Returns true if the index'th joint is a root joint.
Definition: topology.h:69