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) const;
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 world transform to all the joints, but one
125  void transform(const UT_Matrix4D &m, exint ignore_index);
126 
127  // Apply a transform to the local transform of all the root joints.
128  void transformLocalRoots(const UT_Matrix4D &m);
129 
130  // Blend transforms using local space from another GU_HierarchyCache
131  // using a weight.
132  void blendLocalTransforms(const GU_HierarchyCache &hc, fpreal w,
133  const GA_PointGroup *grp=nullptr,
134  bool use_names=false);
135 
136  // Blend transforms using global space from another GU_HierarchyCache
137  // using a weight.
138  void blendWorldTransforms(const GU_HierarchyCache &hc, fpreal w,
139  const GA_PointGroup *grp=nullptr,
140  bool use_names=false);
141 
142  // Blend transforms using a rest pose space from another GU_HierarchyCache
143  // using a weight.
144  void blendRestTransforms( const GU_HierarchyCache &hc, fpreal w,
145  const GU_HierarchyCache &rest,
146  const GA_PointGroup *grp=nullptr,
147  bool use_names=false);
148 
149  // Copy transforms back to P,transform,localtransform attributes on a detail.
150  void copyTransforms(GU_Detail *gdp,
151  bool copy_P=true,
152  bool copy_transform=true,
153  bool copy_localtransform=true);
154 
155  void update(const GU_HierarchyCache &hc);
156 
157 public:
166 
172 
174 
176  UT_StringArray myNames; // Point Name values
177  UT_StringArray myIndexNames; // Variable names for the point name index variable
178  UT_StringArray myNameNames; // Variable names for the point name name variable
179  UT_StringMap<GA_Index> myNamesMap; // for lookups to know if a point name appears more than once.
180  UT_BitArray myNamesValid; // tell has a unique name.
181  UT_Array<UT_StringArray> myNamesArray; //Point Name values, as UT_StringArray
182 
183 
185 
186 private:
187 
188  UT_ValArray<int> myNodeLookup;
189 
190  UT_Array<bool> mySubHierarchy;
191  GA_OffsetArray mySubHierarchyNodes;
192  GA_OffsetArray mySubHierarchyParents;
193 
194 
195  template <int HAS_GRP, int USE_NAME>
197  exint mapIndex(const GU_HierarchyCache &hc,
198  const GA_PointGroup *grp, exint i);
199 
200  template <int HAS_GRP, int USE_NAME>
202  void blendLocalTransformsT(const GU_HierarchyCache &hc, fpreal w,
203  const GA_PointGroup *grp=nullptr);
204 
205  template <int HAS_GRP, int USE_NAME>
207  void blendWorldTransformsT(const GU_HierarchyCache &hc, fpreal w,
208  const GA_PointGroup *grp=nullptr);
209 
210  template <int HAS_GRP, int USE_NAME>
212  void blendRestTransformsT( const GU_HierarchyCache &hc, fpreal w,
213  const GU_HierarchyCache &rest,
214  const GA_PointGroup *grp=nullptr);
215 };
216 
217 #endif // __GU_HIERARCHY_H_INCLUDED__
GLbitfield flags
Definition: glcorearb.h:1596
UT_Matrix4DArray myEffectiveLocal
Definition: GU_Hierarchy.h:171
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:109
GA_DataId myLocalDataId
Definition: GU_Hierarchy.h:161
UT_IntArray myModel
Definition: GU_Hierarchy.h:170
int64 GA_DataId
Definition: GA_Types.h:696
UT_Matrix3DArray myTransform
Definition: GU_Hierarchy.h:168
GA_DataId myTransformDataId
Definition: GU_Hierarchy.h:160
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:162
GA_DataId myTopologyDataId
Definition: GU_Hierarchy.h:158
GU_Hierarchy::ComputeHierarchyResult myTraverseResult
Definition: GU_Hierarchy.h:184
int64 exint
Definition: SYS_Types.h:125
**But if you need a result
Definition: thread.h:622
GU_API GA_Offset getParent(const GU_Detail *gdp, const GA_Offset &node)
GA_OffsetArray myParents
Definition: GU_Hierarchy.h:165
UT_StringArray myNameNames
Definition: GU_Hierarchy.h:178
GU_API const UT_StringHolder & getComputeHierarchyMessage(ComputeHierarchyResult result)
Returns a descriptive message for the ComputeHierarchyResult.
GA_Size GA_Offset
Definition: GA_Types.h:646
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:159
GU_API GA_OffsetArray getChildren(const GU_Detail *gdp, const GA_Offset &node, bool recurse=false)
GA_OffsetArray myRoots
Definition: GU_Hierarchy.h:163
GA_OffsetArray myNodes
Definition: GU_Hierarchy.h:164
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
UT_Vector3DArray myP
Definition: GU_Hierarchy.h:169
#define GU_API
Definition: GU_API.h:14
UT_Matrix4DArray myLocal
Definition: GU_Hierarchy.h:167
UT_StringArray myIndexNames
Definition: GU_Hierarchy.h:177
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
GA_API const UT_StringHolder transform
GU_API GA_Offset getParentVertex(const GU_Detail *gdp, const GA_Offset &node)
UT_StringMap< GA_Index > myNamesMap
Definition: GU_Hierarchy.h:179
UT_BitArray myNamesValid
Definition: GU_Hierarchy.h:180
fpreal64 fpreal
Definition: SYS_Types.h:278
UT_Array< UT_StringArray > myNamesArray
Definition: GU_Hierarchy.h:181
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
UT_StringArray myNames
Definition: GU_Hierarchy.h:176
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:175
GA_API const UT_StringHolder rest
UT_Array< GU_AgentXformD > myAgentXformsLocals
Definition: GU_Hierarchy.h:173