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 
44 GU_API void getParentAndChildren(const GU_Detail *gdp, const GA_Offset &node, GA_Offset& parent, GA_OffsetArray& children);
45 
47 {
48  Success = 0,
49  NoRoots,
50  BadRoot,
51  FoundCycle,
53 };
54 
55 /// Returns a descriptive message for the ComputeHierarchyResult.
58 
60  const GU_Detail *gdp,
61  GA_OffsetArray &roots,
62  GA_OffsetArray &nodes,
63  GA_OffsetArray &parents,
64  UT_Map<GA_Offset, GA_OffsetArray> *children = nullptr,
65  const bool depth_first = false);
66 
67 GU_API bool findRoots(const GU_Detail *gdp, GA_OffsetArray &roots);
68 
70  const GU_Detail *gdp,
71  const GA_OffsetArray &nodes,
72  const GA_OffsetArray &parents,
73  const UT_Vector3DArray &P,
75  UT_Matrix4DArray &local,
76  UT_Matrix4DArray &effective_local,
77  const UT_IntArray &model);
78 
80  const GU_Detail *gdp,
81  const GA_OffsetArray &nodes,
82  const GA_OffsetArray &parents,
85  const UT_Matrix4DArray &local,
86  UT_Matrix4DArray &effective_local,
87  const UT_IntArray &model,
88  const GA_PointGroup *constrain_grp,
89  const UT_Array<int> *flags,
90  bool constrain_all);
91 
92 } // namespace GU_Hierarchy
93 
95 {
96 public:
98 
99  bool rebuild(const GU_Detail *gdp, bool &topo_changed);
100  void clear();
101  bool worldTransformDirty(const GU_Detail *gdp);
102  bool localTransformDirty(const GU_Detail *gdp);
103  void initTransformData(const GU_Detail *gdp);
104  void updateLocalTransformCache(const GU_Detail *gdp);
105  void updateTransformCache(const GU_Detail *gdp, bool update_names=true);
106  void updateTransformDataIds(const GU_Detail *gdp);
107 
108  int lookUpPointIndex(GA_Index ptidx) const;
109  void computeLocalTransform(const GU_Detail *gdp);
110  void computeWorldTransform(const GU_Detail *gdp);
111  void computeWorldTransform(const GU_Detail *gdp,
112  const GA_PointGroup *constrain_grp,const UT_Array<int> *flags,
113  bool constrain);
114 
115  void clearSubHier();
116  void updateSubHier();
117  void appendSubHierLeaf(const GU_Detail *gdp, GA_Offset leaf_ptoff);
118  void computeSubHierLocalTransform(const GU_Detail *gdp);
119  void computeSubHierWorldTransform(const GU_Detail *gdp);
120  void computeSubHierWorldTransform(const GU_Detail *gdp,
121  const GA_PointGroup *contrain_grp, const UT_Array<int> *flags,
122  bool constrain);
123 
124  // Apply a world transform to all the joints
125  void transform(const UT_Matrix4D &m);
126 
127  // Apply a world transform to all the joints, but one
128  void transform(const UT_Matrix4D &m, exint ignore_index);
129 
130  // Apply a transform to the local transform of all the root joints.
131  void transformLocalRoots(const UT_Matrix4D &m);
132 
133  // Blend transforms using local space from another GU_HierarchyCache
134  // using a weight.
135  void blendLocalTransforms(const GU_HierarchyCache &hc, fpreal w,
136  const GA_PointGroup *grp=nullptr,
137  bool use_names=false);
138 
139  // Blend transforms using global space from another GU_HierarchyCache
140  // using a weight.
141  void blendWorldTransforms(const GU_HierarchyCache &hc, fpreal w,
142  const GA_PointGroup *grp=nullptr,
143  bool use_names=false);
144 
145  // Blend transforms using a rest pose space from another GU_HierarchyCache
146  // using a weight.
147  void blendRestTransforms( const GU_HierarchyCache &hc, fpreal w,
148  const GU_HierarchyCache &rest,
149  const GA_PointGroup *grp=nullptr,
150  bool use_names=false);
151 
152  // Copy transforms back to P,transform,localtransform attributes on a detail.
153  void copyTransforms(GU_Detail *gdp,
154  bool copy_P=true,
155  bool copy_transform=true,
156  bool copy_localtransform=true);
157 
158 
159  void update(const GU_HierarchyCache &hc);
160 
161  // Apply a world transform to all the joints, but ignore some indices.
162  void transform(const UT_Matrix4D &m, const UT_Array<exint> &ignore_indices);
163 
164  // Copy an array back to a point transform attribute.
165  bool copyExtraTransforms(GU_Detail *gdp, const UT_StringHolder &attrname);
166 
167  // Copy all the extra transforms back to point attributes
168  void copyExtraTransforms(GU_Detail *gdp);
169 
170  // Extract a named matrix4 attribute into the myExtraTransforms map.
171  // Puts an empty array on failure.
172  void updateExtraTransformArray(const GU_Detail *gdp, const UT_StringHolder &attrname);
173 
174 public:
183 
189 
191 
193  UT_StringArray myNames; // Point Name values
194  UT_StringArray myIndexNames; // Variable names for the point name index variable
195  UT_StringArray myNameNames; // Variable names for the point name name variable
196  UT_StringMap<GA_Index> myNamesMap; // for lookups to know if a point name appears more than once.
197  UT_BitArray myNamesValid; // tell has a unique name.
198  UT_Array<UT_StringArray> myNamesArray; //Point Name values, as UT_StringArray
199 
200 
202 
203  UT_StringMap<UT_Matrix4DArray> myExtraTransforms; // Hold extra transforms from attributes.
204 
205 private:
206 
207  UT_ValArray<int> myNodeLookup;
208 
209  UT_Array<bool> mySubHierarchy;
210  GA_OffsetArray mySubHierarchyNodes;
211  GA_OffsetArray mySubHierarchyParents;
212 
213 
214  template <int HAS_GRP, int USE_NAME>
216  exint mapIndex(const GU_HierarchyCache &hc,
217  const GA_PointGroup *grp, exint i);
218 
219  template <int HAS_GRP, int USE_NAME>
221  void blendLocalTransformsT(const GU_HierarchyCache &hc, fpreal w,
222  const GA_PointGroup *grp=nullptr);
223 
224  template <int HAS_GRP, int USE_NAME>
226  void blendWorldTransformsT(const GU_HierarchyCache &hc, fpreal w,
227  const GA_PointGroup *grp=nullptr);
228 
229  template <int HAS_GRP, int USE_NAME>
231  void blendRestTransformsT( const GU_HierarchyCache &hc, fpreal w,
232  const GU_HierarchyCache &rest,
233  const GA_PointGroup *grp=nullptr);
234 };
235 
236 #endif // __GU_HIERARCHY_H_INCLUDED__
GLbitfield flags
Definition: glcorearb.h:1596
UT_Matrix4DArray myEffectiveLocal
Definition: GU_Hierarchy.h:188
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:114
GA_DataId myLocalDataId
Definition: GU_Hierarchy.h:178
UT_IntArray myModel
Definition: GU_Hierarchy.h:187
int64 GA_DataId
Definition: GA_Types.h:703
UT_Matrix3DArray myTransform
Definition: GU_Hierarchy.h:185
GA_DataId myTransformDataId
Definition: GU_Hierarchy.h:177
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:179
GA_DataId myTopologyDataId
Definition: GU_Hierarchy.h:175
GU_Hierarchy::ComputeHierarchyResult myTraverseResult
Definition: GU_Hierarchy.h:201
int64 exint
Definition: SYS_Types.h:125
**But if you need a result
Definition: thread.h:622
UT_StringMap< UT_Matrix4DArray > myExtraTransforms
Definition: GU_Hierarchy.h:203
GU_API GA_Offset getParent(const GU_Detail *gdp, const GA_Offset &node)
GA_OffsetArray myParents
Definition: GU_Hierarchy.h:182
UT_StringArray myNameNames
Definition: GU_Hierarchy.h:195
GU_API const UT_StringHolder & getComputeHierarchyMessage(ComputeHierarchyResult result)
Returns a descriptive message for the ComputeHierarchyResult.
GA_Size GA_Offset
Definition: GA_Types.h:653
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:176
GU_API GA_OffsetArray getChildren(const GU_Detail *gdp, const GA_Offset &node, bool recurse=false)
GA_OffsetArray myRoots
Definition: GU_Hierarchy.h:180
GA_OffsetArray myNodes
Definition: GU_Hierarchy.h:181
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
UT_Vector3DArray myP
Definition: GU_Hierarchy.h:186
#define GU_API
Definition: GU_API.h:14
UT_Matrix4DArray myLocal
Definition: GU_Hierarchy.h:184
GU_API void getParentAndChildren(const GU_Detail *gdp, const GA_Offset &node, GA_Offset &parent, GA_OffsetArray &children)
UT_StringArray myIndexNames
Definition: GU_Hierarchy.h:194
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:647
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:196
UT_BitArray myNamesValid
Definition: GU_Hierarchy.h:197
fpreal64 fpreal
Definition: SYS_Types.h:283
UT_Array< UT_StringArray > myNamesArray
Definition: GU_Hierarchy.h:198
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, const bool depth_first=false)
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
UT_StringArray myNames
Definition: GU_Hierarchy.h:193
GU_API bool findRoots(const GU_Detail *gdp, GA_OffsetArray &roots)
UT_StringHolder myNamesFormat
Definition: GU_Hierarchy.h:192
GA_API const UT_StringHolder rest
UT_Array< GU_AgentXformD > myAgentXformsLocals
Definition: GU_Hierarchy.h:190