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 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 PXR_USD_USD_SKEL_TOPOLOGY_H
25 #define PXR_USD_USD_SKEL_TOPOLOGY_H
26 
27 /// \file usdSkel/topology.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdSkel/api.h"
31 
32 #include "pxr/base/tf/span.h"
33 #include "pxr/usd/sdf/path.h"
34 #include "pxr/usd/sdf/types.h"
35 
36 
38 
39 
40 /// \class UsdSkelTopology
41 ///
42 /// Object holding information describing skeleton topology.
43 /// This provides the hierarchical information needed to reason about joint
44 /// relationships in a manner suitable to computations.
46 {
47 public:
48  /// Construct an empty topology.
49  UsdSkelTopology() = default;
50 
51  /// Construct a skel topology from \p paths, an array holding ordered joint
52  /// paths as tokens.
53  /// Internally, each token must be converted to an SdfPath. If SdfPath
54  /// objects are already accessible, it is more efficient to use the
55  /// construct taking an SdfPath array.
58 
59  /// Construct a skel topology from \p paths, an array of joint paths.
62 
63  /// Construct a skel topology from an array of parent indices.
64  /// For each joint, this provides the parent index of that
65  /// joint, or -1 if none.
67  UsdSkelTopology(const VtIntArray& parentIndices);
68 
69  /// Validate the topology.
70  /// If validation is unsuccessful, a reason
71  /// why will be written to \p reason, if provided.
73  bool Validate(std::string* reason=nullptr) const;
74 
75  const VtIntArray& GetParentIndices() const { return _parentIndices; }
76 
77  size_t GetNumJoints() const { return size(); }
78 
79  size_t size() const { return _parentIndices.size(); }
80 
81  /// Returns the parent joint of the \p index'th joint,
82  /// Returns -1 for joints with no parent (roots).
83  inline int GetParent(size_t index) const;
84 
85  /// Returns true if the \p index'th joint is a root joint.
86  bool IsRoot(size_t index) const { return GetParent(index) < 0; }
87 
88  bool operator==(const UsdSkelTopology& o) const;
89 
90  bool operator!=(const UsdSkelTopology& o) const {
91  return !(*this == o);
92  }
93 
94 private:
95  VtIntArray _parentIndices;
96 };
97 
98 
99 int
101 {
102  TF_DEV_AXIOM(index < _parentIndices.size());
103  return _parentIndices[index];
104 }
105 
106 
108 
109 #endif // PXR_USD_USD_SKEL_TOPOLOGY_H
bool operator==(const UsdSkelTopology &o) const
const VtIntArray & GetParentIndices() const
Definition: topology.h:75
#define TF_DEV_AXIOM(cond)
Definition: span.h:87
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
UsdSkelTopology()=default
Construct an empty topology.
#define USDSKEL_API
Definition: api.h:40
size_t GetNumJoints() const
Definition: topology.h:77
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1394
size_t size() const
Definition: topology.h:79
int GetParent(size_t index) const
Definition: topology.h:100
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool operator!=(const UsdSkelTopology &o) const
Definition: topology.h:90
USDSKEL_API bool Validate(std::string *reason=nullptr) const
GLenum const void * paths
Definition: glew.h:13872
bool IsRoot(size_t index) const
Returns true if the index'th joint is a root joint.
Definition: topology.h:86