HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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_VectorTypes.h>
26 
27 #include <SYS/SYS_AtomicInt.h>
28 #include <SYS/SYS_Types.h>
29 
30 #include "GT_API.h"
31 #include "GT_DataArray.h"
32 
33 class RE_VertexArray;
34 class GU_PrimPacked;
35 
36 class GT_AgentIndexMap;
37 class GT_AgentVisibility;
39 class GT_AgentTransforms;
40 class GT_AgentSelection;
41 class GT_AgentID;
42 class GT_AgentColors;
44 
53 
54 /// Mapping from GA_Index to per-rig agent index
56  : public UT_IntrusiveRefCounter<GT_AgentIndexMap>
57 {
58 public:
59  void clear() { myIndexMap.entries(0); }
60  exint entries() const { return myIndexMap.entries(); }
61 
62  // returns the index within the rig given the agent prim's GA index.
63  int getAgentIndex(exint ga_index) const
64  { return myIndexMap(ga_index); }
65 
66  void setAgentIndex(int ga_index, int agent_index);
67 
68 private:
69  UT_IntArray myIndexMap;
70 };
71 
72 
73 /// Visibility and LOD class for agents.
75  : public UT_IntrusiveRefCounter<GT_AgentVisibility>
76 {
77 public:
78  void setEntries(exint entries) { myVisibility.entries(entries); }
79  exint entries() const { return myVisibility.entries(); }
80 
81  void setVisibility(exint idx, bool visible, fpreal lod = 1.0)
82  { myVisibility(idx) = visible ? lod : 0.0; }
83 
84  bool getVisibility(exint idx) const
85  { return myVisibility(idx) != 0.0f; }
86 
87  bool getLOD(exint idx, fpreal32 &lod) const
88  {
89  lod = myVisibility(idx);
90  return (lod < 0.0f);
91  }
92 
93  void allVisible() { myVisibility.constant(1.0); }
94 private:
95  UT_FloatArray myVisibility;
96 };
97 
98 /// Transform lists for rigs, one per agent
100  : public UT_IntrusiveRefCounter<GT_AgentRigTransforms>
101 {
102 public:
104 
106  {
107  myTransforms.entries(entries);
108  mySerial.entries(entries);
109  }
110 
112  { return myTransforms(agent_idx); }
113 
114  const UT_Matrix4FArray &transforms(exint agent_idx) const
115  { return *myTransforms(agent_idx); }
116 
117  int getSerial(exint agent_idx) { return mySerial(agent_idx); }
118  void setSerial(exint agent_idx, int serial)
119  { mySerial(agent_idx) = serial; }
120 private:
121  UT_Array<Matrix4ArrayConstPtr> myTransforms;
122  UT_IntArray mySerial;
123 };
124 
125 
126 /// Transforms for each entire agent
128  : public UT_IntrusiveRefCounter<GT_AgentTransforms>
129 {
130 public:
131  void setEntries(exint entries) { myTransforms.entries(entries); }
132 
134  { return myTransforms(agent_idx); }
135 
136  const UT_Matrix4F &agentTransform(exint agent_idx) const
137  { return myTransforms(agent_idx); }
138 private:
139  UT_Matrix4FArray myTransforms;
140 };
141 
142 /// Contains a bool array of selected agents.
144  : public UT_IntrusiveRefCounter<GT_AgentSelection>
145 {
146 public:
147  GT_AgentSelection() : mySelectState(0) {}
148 
149  void setEntries(exint entries) { mySelection.entries(entries); }
150 
151  void clear() { mySelection.zero(); mySelectState = 0; }
152  void allSelected() { mySelection.constant(1); mySelectState = 1; }
153  void partiallySelected() { mySelectState = -1; }
154 
155  void setSelected(exint idx, bool selected)
156  { mySelection(idx) = selected?1:0; }
157 
158  bool isSelected(exint idx) const
159  { return mySelection(idx)==1; }
160 
161  // Usage of these methods depends upon clear, allSelected, or
162  // partiallySelection() being called appropriately.
163  bool isFullySelected() const { return (mySelectState == 1); }
164  bool isNothingSelected() const { return (mySelectState == 0); }
165  bool isPartiallySelected() const { return (mySelectState == -1); }
166 
167 private:
168  UT_IntArray mySelection;
169  int mySelectState;
170 };
171 
172 /// Contains IDs for each agent
174  : public UT_IntrusiveRefCounter<GT_AgentID>
175 {
176 public:
177  void setEntries(exint entries) { myIDs.entries(entries); }
178  void setID(exint idx, int id) { myIDs(idx) = id; }
179  int getID(exint idx) const { return myIDs(idx); }
180 
181  const UT_IntArray &getIDs() const { return myIDs; }
182  void fetchIDs(int *id_array) const
183  { memcpy(id_array, myIDs.array(), myIDs.entries()*sizeof(int));}
184 private:
185  UT_IntArray myIDs;
186 };
187 
188 /// Contains colors for each agent
190  : public UT_IntrusiveRefCounter<GT_AgentColors>
191 {
192 public:
193  void setColors(const GT_DataArrayHandle &colors, GT_Owner owner,
194  exint num_agents)
195  {
196  if (colors)
197  {
198  // Note the color is vec3 but padded to vec4 because TBOs
199  // only support 1,2 or 4 components with non-32b components.
200  // The fill below compensates for this.
201  myColors.setSizeNoInit(num_agents * 4);
202 
203  if (owner == GT_OWNER_DETAIL)
204  {
205  // For now, just fill an array with the constant color instead
206  // of adding extra optimizations for detail Cd.
207  colors->extendedFillArray(myColors.data(), 0, 1, 3, num_agents,
208  4);
209  }
210  else
211  colors->fillArray(myColors.data(), 0, num_agents, 3, 4);
212  }
213  else
214  myColors.clear();
215  }
216 
217  bool hasColor() const { return !myColors.isEmpty(); }
218 
219  /// Fetch the (4 uint8) color for an agent.
220  void fetchColor(exint agent_idx, uint8 *data) const
221  {
222  memcpy(data, myColors.data() + 4 * agent_idx, 4 * sizeof(uint8));
223  }
224 
225 private:
226  UT_Array<uint8> myColors;
227 };
228 
229 /// Data common to all levels-of-detail for a series of GT_PrimAgentShapes
231  : public UT_IntrusiveRefCounter<GT_ShapeLODGroup>
232 {
233 public:
235  const GT_AgentRigTransformsHandle &rh,
236  const GT_AgentVisibilityHandle &vis,
237  const GT_AgentIndexMapHandle &map,
238  const GT_AgentSelectionHandle &select,
239  const GT_AgentIDHandle &ids,
240  const GT_AgentColorsHandle &colors,
241  int shape_id);
242 
243  ~GT_ShapeLODGroup();
244 
245 public:
255 
263 
271 
272  // this data is temporary, only valid during agent collection/refinement.
276 };
277 
278 
279 #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)
bool isSelected(exint idx) const
GT_AgentIDHandle myAgentPrimID
Contains colors for each agent.
UT_Array< const GU_PrimPacked * > myAgents
UT_Array< RE_VertexArray * > * myRigTransformVA
#define GT_API
Definition: GT_API.h:11
bool getLOD(exint idx, fpreal32 &lod) const
exint entries() const
UT_IntArray myBindings
Wrapper around hboost::shared_ptr.
Definition: UT_SharedPtr.h:27
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.
GLuint * ids
Definition: glcorearb.h:651
UT_IntrusivePtr< GT_ShapeLODGroup > GT_ShapeLODGroupHandle
void setSelected(exint idx, bool selected)
UT_Array< RE_VertexArray * > * myPrimIDVA
UT_IntrusivePtr< GT_AgentColors > GT_AgentColorsHandle
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)
GLuint id
Definition: glcorearb.h:654
GT_AgentColorsHandle myAgentColors
UT_IntArray * myDeformMap
const UT_Matrix4F & agentTransform(exint agent_idx) const
GLfloat f
Definition: glcorearb.h:1925
void fetchIDs(int *id_array) const
Matrix4ArrayConstPtr & transformsPtr(exint agent_idx)
int64 exint
Definition: SYS_Types.h:115
GT_AgentSelectionHandle myAgentSelection
void setColors(const GT_DataArrayHandle &colors, GT_Owner owner, exint num_agents)
int getSerial(exint agent_idx)
GLboolean * data
Definition: glcorearb.h:130
bool hasColor() const
GT_AgentRigTransformsHandle myAgentRigTransforms
bool isNothingSelected() const
UT_IntrusivePtr< GT_AgentVisibility > GT_AgentVisibilityHandle
GT_Owner
Definition: GT_Types.h:72
void setSerial(exint agent_idx, int serial)
GT_AgentTransformsHandle myAgentTransforms
double fpreal
Definition: SYS_Types.h:269
UT_Matrix4F & agentTransform(exint agent_idx)
GT_AgentVisibilityHandle myVisibility
png_infop png_sPLT_tpp entries
Definition: png.h:2481
typedef int
Definition: png.h:1175
UT_IntArray myTransforms
GT_AgentIndexMapHandle myAgentIndexMap
UT_IntrusivePtr< GT_AgentID > GT_AgentIDHandle
unsigned char uint8
Definition: SYS_Types.h:31
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
UT_Matrix4FArray * myInvRestTransform
void setID(exint idx, int id)
Contains a bool array of selected agents.
void setVisibility(exint idx, bool visible, fpreal lod=1.0)
UT_IntrusivePtr< GT_AgentRigTransforms > GT_AgentRigTransformsHandle
const UT_Matrix4FArray & transforms(exint agent_idx) const
bool getVisibility(exint idx) const
UT_SharedPtr< const UT_Matrix4FArray > Matrix4ArrayConstPtr
exint entries() const
float fpreal32
Definition: SYS_Types.h:190
GLint lod
Definition: glcorearb.h:2764
UT_IntrusivePtr< GT_AgentTransforms > GT_AgentTransformsHandle
Transforms for each entire agent.