HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Hierarchy.h
Go to the documentation of this file.
1 /*
2 * PROPRIETARY INFORMATION. This software is proprietary to
3 * Side Effects Software Inc., and is not to be reproduced,
4 * transmitted, or disclosed in any way without written permission.
5 *
6 * NAME: GU_Hierarchy.h (GU Library, C++)
7 *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_HIERARCHY_H_INCLUDED__
12 #define __GU_HIERARCHY_H_INCLUDED__
13 
14 #include "GU_API.h"
15 
16 #include "GU_AgentClip.h"
17 
18 #include <GA/GA_Types.h>
19 #include <UT/UT_Array.h>
20 #include <UT/UT_BitArray.h>
21 #include <UT/UT_Map.h>
22 #include <UT/UT_Set.h>
23 #include <UT/UT_StringArray.h>
24 #include <UT/UT_StringHolder.h>
25 #include <UT/UT_StringSet.h>
26 #include <UT/UT_ValArray.h>
27 #include <UT/UT_VectorTypes.h>
28 
29 
30 class GA_PointGroup;
31 class GU_Detail;
32 
33 namespace GU_Hierarchy
34 {
35 GU_API GA_Offset getParent(const GU_Detail *gdp, const GA_Offset &node);
36 GU_API GA_Offset getParentVertex(const GU_Detail *gdp, const GA_Offset &node);
37 GU_API void getParents(const GU_Detail *gdp, const GA_Offset &node, GA_OffsetArray &children);
38 GU_API void getParents(const GU_Detail *gdp, const GA_Offset &node, UT_Set<GA_Offset> &children);
39 
40 GU_API GA_OffsetArray getChildren(const GU_Detail *gdp, const GA_Offset &node, bool recurse=false);
41 GU_API void getChildren(const GU_Detail *gdp, const GA_Offset &node, GA_OffsetArray &children, bool recurse=false);
42 GU_API void getChildren(const GU_Detail *gdp, const GA_Offset &node, UT_Set<GA_Offset> &children, bool recurse=false);
43 
45 {
46  Success = 0,
47  NoRoots,
48  BadRoot,
49  FoundCycle,
51 };
52 
53 /// Returns a descriptive message for the ComputeHierarchyResult.
56 
58  const GU_Detail *gdp,
59  GA_OffsetArray &roots,
60  GA_OffsetArray &nodes,
61  GA_OffsetArray &parents,
62  UT_Map<GA_Offset, GA_OffsetArray> *children = nullptr);
63 
64 GU_API bool findRoots(const GU_Detail *gdp, GA_OffsetArray &roots);
65 
67  const GU_Detail *gdp,
68  const GA_OffsetArray &nodes,
69  const GA_OffsetArray &parents,
70  const UT_Vector3DArray &P,
72  UT_Matrix4DArray &local,
73  UT_Matrix4DArray &effective_local,
74  const UT_IntArray &model);
75 
77  const GU_Detail *gdp,
78  const GA_OffsetArray &nodes,
79  const GA_OffsetArray &parents,
82  const UT_Matrix4DArray &local,
83  UT_Matrix4DArray &effective_local,
84  const UT_IntArray &model,
85  const GA_PointGroup *constrain_grp,
86  const UT_Array<int> *flags,
87  bool constrain_all);
88 
89 } // namespace GU_Hierarchy
90 
92 {
93 public:
95 
96  bool rebuild(const GU_Detail *gdp, bool &topo_changed);
97  void clear();
98  bool worldTransformDirty(const GU_Detail *gdp);
99  bool localTransformDirty(const GU_Detail *gdp);
100  void initTransformData(const GU_Detail *gdp);
101  void updateLocalTransformCache(const GU_Detail *gdp);
102  void updateTransformCache(const GU_Detail *gdp, bool update_names=true);
103  void updateTransformDataIds(const GU_Detail *gdp);
104 
105  int lookUpPointIndex(GA_Index ptidx);
106  void computeLocalTransform(const GU_Detail *gdp);
107  void computeWorldTransform(const GU_Detail *gdp);
108  void computeWorldTransform(const GU_Detail *gdp,
109  const GA_PointGroup *constrain_grp,const UT_Array<int> *flags,
110  bool constrain);
111 
112  void clearSubHier();
113  void updateSubHier();
114  void appendSubHierLeaf(const GU_Detail *gdp, GA_Offset leaf_ptoff);
115  void computeSubHierLocalTransform(const GU_Detail *gdp);
116  void computeSubHierWorldTransform(const GU_Detail *gdp);
117  void computeSubHierWorldTransform(const GU_Detail *gdp,
118  const GA_PointGroup *contrain_grp, const UT_Array<int> *flags,
119  bool constrain);
120 
121  // Apply a world transform to all the joints
122  void transform(const UT_Matrix4D &m);
123 
124  // Apply a transform to the local transform of all the joints joints.
125  void transformLocalRoots(const UT_Matrix4D &m);
126 
127  // Blend transforms using local space from another GU_HierarchyCache
128  // using a weight.
129  void blendLocalTransforms(const GU_HierarchyCache &hc, fpreal w,
130  const GA_PointGroup *grp=nullptr);
131 
132  // Blend transforms using global space from another GU_HierarchyCache
133  // using a weight.
134  void blendWorldTransforms(const GU_HierarchyCache &hc, fpreal w,
135  const GA_PointGroup *grp=nullptr);
136 
137  // Blend transforms using a rest pose space from another GU_HierarchyCache
138  // using a weight.
139  void blendRestTransforms( const GU_HierarchyCache &hc, fpreal w,
140  const GU_HierarchyCache &rest,
141  const GA_PointGroup *grp=nullptr);
142 
143  // Copy transforms back to P,transform,localtransform attributes on a detail.
144  void copyTransforms(GU_Detail *gdp,
145  bool copy_P=true,
146  bool copy_transform=true,
147  bool copy_localtransform=true);
148 
149  void update(const GU_HierarchyCache &hc);
150 
151 public:
160 
166 
168 
170  UT_StringArray myNames; // Point Name values
171  UT_StringArray myIndexNames; // Variable names for the point name index variable
172  UT_StringArray myNameNames; // Variable names for the point name name variable
173  UT_StringSet myNamesSet; // for lookups to know if a point name appears more than once.
174  UT_BitArray myNamesValid; // tell has a unique name.
175  UT_Array<UT_StringArray> myNamesArray; //Point Name values, as UT_StringArray
176 
177 
179 
180 private:
181 
182  UT_ValArray<int> myNodeLookup;
183 
184  UT_Array<bool> mySubHierarchy;
185  GA_OffsetArray mySubHierarchyNodes;
186  GA_OffsetArray mySubHierarchyParents;
187 
188  template <int HAS_GRP>
190  void blendLocalTransformsT(const GU_HierarchyCache &hc, fpreal w,
191  const GA_PointGroup *grp=nullptr);
192 
193  template <int HAS_GRP>
195  void blendWorldTransformsT(const GU_HierarchyCache &hc, fpreal w,
196  const GA_PointGroup *grp=nullptr);
197 
198  template <int HAS_GRP>
200  void blendRestTransformsT( const GU_HierarchyCache &hc, fpreal w,
201  const GU_HierarchyCache &rest,
202  const GA_PointGroup *grp=nullptr);
203 };
204 
205 #endif // __GU_HIERARCHY_H_INCLUDED__
UT_StringSet myNamesSet
Definition: GU_Hierarchy.h:173
GLbitfield flags
Definition: glcorearb.h:1596
UT_Matrix4DArray myEffectiveLocal
Definition: GU_Hierarchy.h:165
Definition: UT_Set.h:58
GU_API void getParents(const GU_Detail *gdp, const GA_Offset &node, GA_OffsetArray &children)
Unsorted map container.
Definition: UT_Map.h:107
GA_DataId myLocalDataId
Definition: GU_Hierarchy.h:155
UT_IntArray myModel
Definition: GU_Hierarchy.h:164
int64 GA_DataId
Definition: GA_Types.h:687
UT_Matrix3DArray myTransform
Definition: GU_Hierarchy.h:162
GA_DataId myTransformDataId
Definition: GU_Hierarchy.h:154
GU_API void computeWorldTransform(const GU_Detail *gdp, const GA_OffsetArray &nodes, const GA_OffsetArray &parents, UT_Vector3DArray &P, UT_Matrix3DArray &transform, const UT_Matrix4DArray &local, UT_Matrix4DArray &effective_local, const UT_IntArray &model, const GA_PointGroup *constrain_grp, const UT_Array< int > *flags, bool constrain_all)
GA_DataId myNameDataId
Definition: GU_Hierarchy.h:156
GA_DataId myTopologyDataId
Definition: GU_Hierarchy.h:152
GU_Hierarchy::ComputeHierarchyResult myTraverseResult
Definition: GU_Hierarchy.h:178
**But if you need a result
Definition: thread.h:613
GU_API GA_Offset getParent(const GU_Detail *gdp, const GA_Offset &node)
GA_OffsetArray myParents
Definition: GU_Hierarchy.h:159
UT_StringArray myNameNames
Definition: GU_Hierarchy.h:172
GU_API const UT_StringHolder & getComputeHierarchyMessage(ComputeHierarchyResult result)
Returns a descriptive message for the ComputeHierarchyResult.
GA_Size GA_Offset
Definition: GA_Types.h:641
GU_API void computeLocalTransform(const GU_Detail *gdp, const GA_OffsetArray &nodes, const GA_OffsetArray &parents, const UT_Vector3DArray &P, const UT_Matrix3DArray &transform, UT_Matrix4DArray &local, UT_Matrix4DArray &effective_local, const UT_IntArray &model)
GA_DataId myPDataId
Definition: GU_Hierarchy.h:153
GU_API GA_OffsetArray getChildren(const GU_Detail *gdp, const GA_Offset &node, bool recurse=false)
GA_OffsetArray myRoots
Definition: GU_Hierarchy.h:157
GA_OffsetArray myNodes
Definition: GU_Hierarchy.h:158
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
UT_Vector3DArray myP
Definition: GU_Hierarchy.h:163
#define GU_API
Definition: GU_API.h:14
UT_Matrix4DArray myLocal
Definition: GU_Hierarchy.h:161
UT_StringArray myIndexNames
Definition: GU_Hierarchy.h:171
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:635
GA_API const UT_StringHolder transform
GU_API GA_Offset getParentVertex(const GU_Detail *gdp, const GA_Offset &node)
UT_BitArray myNamesValid
Definition: GU_Hierarchy.h:174
fpreal64 fpreal
Definition: SYS_Types.h:277
UT_Array< UT_StringArray > myNamesArray
Definition: GU_Hierarchy.h:175
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
UT_StringArray myNames
Definition: GU_Hierarchy.h:170
GU_API ComputeHierarchyResult traverse(const GU_Detail *gdp, GA_OffsetArray &roots, GA_OffsetArray &nodes, GA_OffsetArray &parents, UT_Map< GA_Offset, GA_OffsetArray > *children=nullptr)
GU_API bool findRoots(const GU_Detail *gdp, GA_OffsetArray &roots)
UT_StringHolder myNamesFormat
Definition: GU_Hierarchy.h:169
GA_API const UT_StringHolder rest
UT_Array< GU_AgentXformD > myAgentXformsLocals
Definition: GU_Hierarchy.h:167