HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_AgentSupport.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: GT_AgentSupport.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  * Support classes for crowd agents:
10  *
11  * GT_AgentIndexMap - mapping of agent primitive GA index to per-rig index
12  * GT_AgentVisibility - list of LOD/visible per agent
13  * GT_AgentTransforms - agent packed primitive transform list
14  * GT_AgentRigTransforms - lists of rig transforms, one per agent
15  * GT_ShapeLODGroup - data common to LOD levels of a shape
16  */
17 #ifndef _GT_AgentSupport_h_
18 #define _GT_AgentSupport_h_
19 
20 #include <UT/UT_IntArray.h>
21 #include <UT/UT_IntrusivePtr.h>
22 #include <UT/UT_Matrix4.h>
23 #include <UT/UT_NonCopyable.h>
24 #include <UT/UT_SharedPtr.h>
25 #include <UT/UT_UniquePtr.h>
26 #include <UT/UT_VectorTypes.h>
27 
28 #include <SYS/SYS_AtomicInt.h>
29 #include <SYS/SYS_Types.h>
30 
31 #include "GT_API.h"
32 #include "GT_DataArray.h"
33 
35 
36 class RE_VertexArray;
37 class GU_PrimPacked;
38 
39 class GT_AgentIndexMap;
40 class GT_AgentVisibility;
42 class GT_AgentTransforms;
43 class GT_AgentSelection;
44 class GT_AgentID;
45 class GT_AgentColors;
48 
58 
59 /// Index of a shape binding in one of the agent's current layers.
61 {
62  GT_AgentShapeBindingID(int layer_idx, int shape_idx)
63  : myLayerIdx(layer_idx), myBindingIdx(shape_idx)
64  {
65  }
66 
69 };
71 
72 /// Mapping from GA_Index to per-rig agent index
75 {
76 public:
77  void clear() { myIndexMap.entries(0); }
78  exint entries() const { return myIndexMap.entries(); }
79 
80  // returns the index within the rig given the agent prim's GA index.
81  int getAgentIndex(exint ga_index) const
82  { return myIndexMap(ga_index); }
83 
84  void setAgentIndex(int ga_index, int agent_index);
85 
86 private:
87  UT_IntArray myIndexMap;
88 };
89 
90 
91 /// Visibility and LOD class for agents.
93  : public UT_IntrusiveRefCounter<GT_AgentVisibility>
94 {
95 public:
96  void setEntries(exint entries) { myVisibility.entries(entries); }
97  exint entries() const { return myVisibility.entries(); }
98 
99  void setVisibility(exint idx, bool visible, fpreal lod = 1.0)
100  { myVisibility(idx) = visible ? lod : 0.0; }
101 
102  bool getVisibility(exint idx) const
103  { return myVisibility(idx) != 0.0f; }
104 
105  bool getLOD(exint idx, fpreal32 &lod) const
106  {
107  lod = myVisibility(idx);
108  return (lod < 0.0f);
109  }
110 
111  void allVisible() { myVisibility.constant(1.0); }
112 private:
113  UT_FloatArray myVisibility;
114 };
115 
116 /// Transform lists for rigs, one per agent
118  : public UT_IntrusiveRefCounter<GT_AgentRigTransforms>
119 {
120 public:
123 
124  void setEntries(exint entries)
125  {
126  myTransforms.entries(entries);
127  myChannelValues.entries(entries);
128  mySerial.entries(entries);
129  }
130 
132  { return myTransforms(agent_idx); }
133 
134  const UT_Array<UT_Matrix4F> &transforms(exint agent_idx) const
135  { return *myTransforms(agent_idx); }
136 
138  { return myChannelValues[agent_idx]; }
139 
140  const UT_Array<fpreal32> &channelValues(exint agent_idx) const
141  { return *myChannelValues(agent_idx); }
142 
143  int getSerial(exint agent_idx) { return mySerial(agent_idx); }
144  void setSerial(exint agent_idx, int serial)
145  { mySerial(agent_idx) = serial; }
146 private:
147  UT_Array<Matrix4ArrayConstPtr> myTransforms;
148  UT_Array<FloatArrayConstPtr> myChannelValues;
149  UT_IntArray mySerial;
150 };
151 
152 
153 /// Transforms for each entire agent
155  : public UT_IntrusiveRefCounter<GT_AgentTransforms>
156 {
157 public:
158  void setEntries(exint entries) { myTransforms.entries(entries); }
159 
161  { return myTransforms(agent_idx); }
162 
163  const UT_Matrix4F &agentTransform(exint agent_idx) const
164  { return myTransforms(agent_idx); }
165 private:
166  UT_Matrix4FArray myTransforms;
167 };
168 
169 /// Contains a bool array of selected agents.
171  : public UT_IntrusiveRefCounter<GT_AgentSelection>
172 {
173 public:
174  GT_AgentSelection() : mySelectState(0) {}
175 
176  void setEntries(exint entries) { mySelection.entries(entries); }
177 
178  void clear() { mySelection.zero(); mySelectState = 0; }
179  void allSelected() { mySelection.constant(1); mySelectState = 1; }
180  void partiallySelected() { mySelectState = -1; }
181 
182  void setSelected(exint idx, bool selected)
183  { mySelection(idx) = selected?1:0; }
184 
185  bool isSelected(exint idx) const
186  { return mySelection(idx)==1; }
187 
188  // Usage of these methods depends upon clear, allSelected, or
189  // partiallySelection() being called appropriately.
190  bool isFullySelected() const { return (mySelectState == 1); }
191  bool isNothingSelected() const { return (mySelectState == 0); }
192  bool isPartiallySelected() const { return (mySelectState == -1); }
193 
194 private:
195  UT_IntArray mySelection;
196  int mySelectState;
197 };
198 
199 /// Contains IDs for each agent
201  : public UT_IntrusiveRefCounter<GT_AgentID>
202 {
203 public:
204  void setEntries(exint entries) { myIDs.entries(entries); }
205  void setID(exint idx, int id) { myIDs(idx) = id; }
206  int getID(exint idx) const { return myIDs(idx); }
207 
208  const UT_IntArray &getIDs() const { return myIDs; }
209  void fetchIDs(int *id_array) const
210  { memcpy(id_array, myIDs.array(), myIDs.entries()*sizeof(int));}
211 private:
212  UT_IntArray myIDs;
213 };
214 
215 /// Rig-specific data for a shape, such as mapping from the capture attribute's
216 /// regions to the rig's transforms.
218  : public UT_IntrusiveRefCounter<GT_AgentShapeRigInfo>
219 {
220 public:
221  /// Map from region index to agent rig index.
223  /// Inverse rest transform for each region.
225  /// Cache of blendshape targets and the rig channel associated with each
226  /// primary target shape.
228 };
229 
230 /// Contains colors for each agent
232  : public UT_IntrusiveRefCounter<GT_AgentColors>
233 {
234 public:
235  void setColors(const GT_DataArrayHandle &colors, GT_Owner owner,
236  exint num_agents)
237  {
238  if (colors)
239  {
240  // Note the color is vec3 but padded to vec4 because TBOs
241  // only support 1,2 or 4 components with non-32b components.
242  // The fill below compensates for this.
243  myColors.setSizeNoInit(num_agents * 4);
244 
245  if (owner == GT_OWNER_DETAIL)
246  {
247  // For now, just fill an array with the constant color instead
248  // of adding extra optimizations for detail Cd.
249  colors->extendedFillArray(myColors.data(), 0, 1, 3, num_agents,
250  4);
251  }
252  else
253  colors->fillArray(myColors.data(), 0, num_agents, 3, 4);
254  }
255  else
256  myColors.clear();
257  }
258 
259  bool hasColor() const { return !myColors.isEmpty(); }
260 
261  /// Fetch the (4 uint8) color for an agent.
262  void fetchColor(exint agent_idx, uint8 *data) const
263  {
264  memcpy(data, myColors.data() + 4 * agent_idx, 4 * sizeof(uint8));
265  }
266 
267 private:
268  UT_Array<uint8> myColors;
269 };
270 
271 /// Flags for the supported viewport deformation types (blendshapes and/or
272 /// linear skinning).
273 namespace GT_AgentDeformFlags
274 {
275  static constexpr uint None = 0;
276  static constexpr uint BlendShapes = 1;
277  static constexpr uint Skinning = 2;
278 };
279 
280 /// Data common to all levels-of-detail for a series of GT_PrimAgentShapes
282  : public UT_IntrusiveRefCounter<GT_ShapeLODGroup>
283 {
284 public:
286  const GT_AgentRigTransformsHandle &rh,
287  const GT_AgentVisibilityHandle &vis,
288  const GT_AgentIndexMapHandle &map,
290  const GT_AgentIDHandle &ids,
291  const GT_AgentColorsHandle &colors,
292  int shape_id,
293  uint deform_flags);
294 
295  ~GT_ShapeLODGroup();
296 
297  void setRigInfo(const GT_AgentShapeRigInfoHandle &rig_info);
298 
299  bool isDeforming() const
300  {
301  return myDeformFlags != GT_AgentDeformFlags::None;
302  }
303  bool hasSkinning() const
304  {
305  return myDeformFlags & GT_AgentDeformFlags::Skinning;
306  }
307  bool hasBlendShapes() const
308  {
309  return myDeformFlags & GT_AgentDeformFlags::BlendShapes;
310  }
311 
312 public:
320 
325 
332 
337 
338  // this data is temporary, only valid during agent collection/refinement.
342 };
343 
344 
345 #endif
Mapping from GA_Index to per-rig agent index.
void setEntries(exint entries)
Visibility and LOD class for agents.
void setEntries(exint entries)
Contains IDs for each agent.
bool isFullySelected() const
void setEntries(exint entries)
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
bool isSelected(exint idx) const
GT_AgentIDHandle myAgentPrimID
GT_AgentShapeBindingID(int layer_idx, int shape_idx)
Contains colors for each agent.
UT_Array< const GU_PrimPacked * > myAgents
UT_Array< RE_VertexArray * > * myRigTransformVA
bool hasSkinning() const
bool isDeforming() const
UT_Matrix4FArray myInvRestTransforms
Inverse rest transform for each region.
#define GT_API
Definition: GT_API.h:11
int64 exint
Definition: SYS_Types.h:125
bool getLOD(exint idx, fpreal32 &lod) const
exint entries() const
void setEntries(exint entries)
Data common to all levels-of-detail for a series of GT_PrimAgentShapes.
A reference counter base class for use with UT_IntrusivePtr.
float fpreal32
Definition: SYS_Types.h:200
UT_IntrusivePtr< GT_ShapeLODGroup > GT_ShapeLODGroupHandle
void setSelected(exint idx, bool selected)
UT_Array< RE_VertexArray * > * myPrimIDVA
UT_IntrusivePtr< GT_AgentColors > GT_AgentColorsHandle
GU_AgentBlendShapeUtils::InputCache myBlendShapeInputs
void fetchColor(exint agent_idx, uint8 *data) const
Fetch the (4 uint8) color for an agent.
int getID(exint idx) const
void setEntries(exint entries)
GT_AgentColorsHandle myAgentColors
unsigned char uint8
Definition: SYS_Types.h:36
UT_Array< GT_AgentShapeBindingID > myBindings
const UT_Matrix4F & agentTransform(exint agent_idx) const
void fetchIDs(int *id_array) const
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
Definition: simd.h:4816
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
Matrix4ArrayConstPtr & transformsPtr(exint agent_idx)
GT_AgentSelectionHandle myAgentSelection
bool hasBlendShapes() const
#define SYS_DECLARE_IS_POD(T)
Declare a type as POD.
void setColors(const GT_DataArrayHandle &colors, GT_Owner owner, exint num_agents)
GLuint id
Definition: glcorearb.h:655
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
const UT_Array< fpreal32 > & channelValues(exint agent_idx) const
int getSerial(exint agent_idx)
bool hasColor() const
GLuint * ids
Definition: glcorearb.h:652
GT_AgentShapeRigInfoHandle myRigInfo
UT_SharedPtr< const UT_Array< UT_Matrix4F >> Matrix4ArrayConstPtr
GT_AgentRigTransformsHandle myAgentRigTransforms
bool isNothingSelected() const
const UT_Array< UT_Matrix4F > & transforms(exint agent_idx) const
UT_IntrusivePtr< GT_AgentVisibility > GT_AgentVisibilityHandle
GT_Owner
Definition: GT_Types.h:86
UT_IntArray myDeformMap
Map from region index to agent rig index.
void setSerial(exint agent_idx, int serial)
GT_AgentTransformsHandle myAgentTransforms
UT_Matrix4F & agentTransform(exint agent_idx)
GT_AgentVisibilityHandle myVisibility
FloatArrayConstPtr & channelValuesPtr(exint agent_idx)
UT_IntArray myTransforms
GT_AgentIndexMapHandle myAgentIndexMap
UT_IntrusivePtr< GT_AgentID > GT_AgentIDHandle
fpreal64 fpreal
Definition: SYS_Types.h:277
UT_Array< RE_VertexArray * > * myTransformVA
int getAgentIndex(exint ga_index) const
const UT_IntArray & getIDs() const
Transform lists for rigs, one per agent.
UT_Array< RE_VertexArray * > * mySelectionVA
UT_IntrusivePtr< GT_AgentIndexMap > GT_AgentIndexMapHandle
UT_IntrusivePtr< GT_AgentSelection > GT_AgentSelectionHandle
UT_Array< RE_VertexArray * > * myColorVA
bool isPartiallySelected() const
void setID(exint idx, int id)
Contains a bool array of selected agents.
GLfloat f
Definition: glcorearb.h:1926
void setVisibility(exint idx, bool visible, fpreal lod=1.0)
UT_IntrusivePtr< GT_AgentRigTransforms > GT_AgentRigTransformsHandle
bool getVisibility(exint idx) const
exint entries() const
Index of a shape binding in one of the agent's current layers.
UT_SharedPtr< const UT_Array< fpreal32 >> FloatArrayConstPtr
unsigned int uint
Definition: SYS_Types.h:45
UT_IntrusivePtr< GT_AgentShapeRigInfo > GT_AgentShapeRigInfoHandle
GLint lod
Definition: glcorearb.h:2765
UT_IntrusivePtr< GT_AgentTransforms > GT_AgentTransformsHandle
Definition: format.h:895
Transforms for each entire agent.