Atoms Crowd  7.0.0
AgentsLayoutToolData.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <AtomsCore/AtomsMath.h>
11 #include <Atoms/Globals.h>
12 #include <Atoms/AgentGroup.h>
13 #include <AtomsCore/Metadata/Vector3Metadata.h>
14 #include <string>
15 #include <vector>
16 #include <map>
17 #include <map>
18 
19 
20 namespace Atoms
21 {
22  class ATOMS_EXPORT AgentsLayoutToolData
23  {
24  public:
25 
26  enum RotationAxis
27  {
28  kRotX = 0,
29  kRotY,
30  kRotZ,
31  };
32 
33  enum Mode
34  {
35  kAdd = 0,
36  kSelect,
37  kMove,
38  kRotate,
39  kScale,
40  kTimeOffset,
41  kVariation,
42  kSocialLayout,
43  kClip
44  };
45 
46  enum UP
47  {
48  kX = 0,
49  kY,
50  kZ,
51  kAgentUp
52  };
53 
54  enum Space
55  {
56  kLocal = 0,
57  kGlobal
58  };
59 
60  enum GlobalRotationMode
61  {
62  kRotationPositionAndDirection = 0,
63  kRotationPosition
64  };
65 
66  enum FalloffMode
67  {
68  kLinear = 0,
69  kEaseInEaseOut
70  };
71 
72  enum GlobalSpaceMode
73  {
74  kScalePositionAndAgent = 0,
75  kScalePosition
76  };
77 
78  enum SocialLayoutMode
79  {
80  kAverageOrientation = 0,
81  kAveragePosition,
82  kLookTowardCenter,
83  kLookTowardLocator,
84  kOrientationNoise,
85  kDistanceNoise,
86  kAgentSeparation
87  };
88 
89  enum Layout
90  {
91  kPoint = 0,
92  kGrid,
93  kPoisson,
94  kPolygon,
95  kMeshScatter
96  };
97 
98  enum Poisson
99  {
100  kCircle = 0,
101  kSquare = 1,
102  kImage = 2
103  };
104 
105  enum AgentMode
106  {
107  kAgentMode = 0,
108  kJointMode
109  };
110 
111  enum AgentGroupSelectionMode
112  {
113  kAllAgentGroups = 0,
114  kVisibleAgentGroups,
115  kSelectedAgentGroups
116  };
117 
118 
120 
122 
123  static AgentsLayoutToolData& instance();
124 
125  /*
126  inline void setNode(MObject& node) { m_nodeHandle = node;}
127  inline ObjectType node() { return m_nodeHandle.object(); }
128  void updateCachedNodes();
129  inline int getNumCachedNodes() { return m_nodeHandles.size(); };
130  inline ObjectType getCachedNode(unsigned int index) { return m_nodeHandles[index].object(); };
131  void removeCachedNode(const ObjectType &node);
132  */
133 
134  inline void setMode(unsigned short mode) { m_mode = mode; m_falloffDirty = true;}
135  inline unsigned short mode() { return m_mode; }
136 
137  inline void setRotationAxis(unsigned short mode) { m_rotationAxis = mode; }
138  inline unsigned short rotationAxis() { return m_rotationAxis; }
139 
140  inline void setAgentMode(unsigned short mode) { m_agentMode = mode; }
141  inline unsigned short agentMode() { return m_agentMode; }
142 
143  inline void setAgentGroupSelectionMode(unsigned short mode) { m_agentGroupSelectionMode = mode; }
144  inline unsigned short agentGroupSelectionMode() { return m_agentGroupSelectionMode; }
145 
146  inline void setLayout(unsigned short layout) { m_layout = layout; generateSamples(); }
147  inline unsigned short layout() { return m_layout; }
148 
149  inline void setUseHeightFields(bool val) { m_useHeightFields = val; }
150  inline short useHeightFields() { return m_useHeightFields; }
151 
152  inline void setMoveSpace(bool val) { m_moveSpace = val; }
153  inline short moveSpace() { return m_moveSpace; }
154 
155  inline void setRotationSpace(bool val) { m_rotationSpace = val; }
156  inline short rotationSpace() { return m_rotationSpace; }
157 
158  inline void setGlobalRotationMode(unsigned short val) { m_globalRotationMode = val; }
159  inline short globalRotationMode() { return m_globalRotationMode; }
160 
161  inline void setScaleSpace(bool val) { m_scaleSpace = val; }
162  inline short scaleSpace() { return m_scaleSpace; }
163 
164  inline void setGlobalScaleMode(unsigned short val) { m_globalScaleMode = val; }
165  inline short globalScaleMode() { return m_globalScaleMode; }
166 
167  inline void setRandomSelected(bool val) { m_randomSelected = val; }
168  inline bool randomSelected() { return m_randomSelected; }
169 
170  inline void setUpVector(short val) { m_upVector = val; }
171  inline short upVector() { return m_upVector; }
172 
173  inline void setSelectedObjects(std::vector<std::string>& obList) { m_selectedObjects = obList; }
174  inline std::vector<std::string>& selectedObjects() { return m_selectedObjects; }
175 
176  inline void setTargetObjects(std::vector<std::string>& obList) { m_targetObjects = obList; }
177  inline std::vector<std::string>& targetObjects() { return m_targetObjects; }
178 
179  inline void setAgentTypes(std::vector<std::string>& agentTypes) { m_agentTypes = agentTypes; }
180  inline std::vector<std::string>& agentTypes() { return m_agentTypes; }
181 
182  inline void setAgentTypeWeights(std::vector<int>& weights) { m_agentTypeWeights = weights; }
183  inline std::vector<int>& agentTypeWeights() { return m_agentTypeWeights; }
184 
185  std::string agentType();
186 
187  inline bool translateLockX() { return m_translateLockX; }
188  inline bool translateLockY() { return m_translateLockY; }
189  inline bool translateLockZ() { return m_translateLockZ; }
190 
191  inline void setTranslateLockX(bool val) { m_translateLockX = val; }
192  inline void setTranslateLockY(bool val) { m_translateLockY = val; }
193  inline void setTranslateLockZ(bool val) { m_translateLockZ = val; }
194 
195  inline bool rotateLockX() { return m_rotateLockX; }
196  inline bool rotateLockY() { return m_rotateLockY; }
197  inline bool rotateLockZ() { return m_rotateLockZ; }
198 
199  inline void setRotateLockX(bool val) { m_rotateLockX = val; }
200  inline void setRotateLockY(bool val) { m_rotateLockY = val; }
201  inline void setRotateLockZ(bool val) { m_rotateLockZ = val; }
202 
203  inline bool scaleLockX() { return m_scaleLockX; }
204  inline bool scaleLockY() { return m_scaleLockY; }
205  inline bool scaleLockZ() { return m_scaleLockZ; }
206 
207  inline void setScaleLockX(bool val) { m_scaleLockX = val; }
208  inline void setScaleLockY(bool val) { m_scaleLockY = val; }
209  inline void setScaleLockZ(bool val) { m_scaleLockZ = val; }
210 
211  inline void setDirection(const AtomsCore::Vector3& val) { m_direction = val; }
212  inline AtomsCore::Vector3 direction() { return m_direction; }
213 
214  inline void setDirectionRandom(const AtomsCore::Vector3& val) { m_directionRandom = val; }
215  inline AtomsCore::Vector3 directionRandom() { return m_directionRandom; }
216 
217  inline void setGridSize(const AtomsCore::Vector3i& val) { m_gridSize = val; generateSamples();}
218  inline AtomsCore::Vector3i gridSize() { return m_gridSize; }
219 
220  inline void setGridSpace(const AtomsCore::Vector3& val) { m_gridSpace = val; generateSamples();}
221  inline AtomsCore::Vector3 gridSpace() { return m_gridSpace; }
222 
223  inline void setGridSpaceRandom(const AtomsCore::Vector3& val) { m_gridSpaceRandom = val; generateSamples();}
224  inline AtomsCore::Vector3 gridSpaceRandom() { return m_gridSpaceRandom; }
225 
226  inline void setGridRotation(const AtomsCore::Vector3& val) { m_gridRotation = val;}
227  inline AtomsCore::Vector3 gridRotation() { return m_gridRotation; }
228 
229  inline void setPointOffset(const AtomsCore::Vector3& val) { m_pointOffset = val; }
230  inline AtomsCore::Vector3 pointOffset() { return m_pointOffset; }
231 
232  inline void setPoissonRadius(double val) { m_poissonRadius = val; generateSamples();}
233  inline double poissonRadius() { return m_poissonRadius; }
234 
235  inline void setPoissonMinDistance(double val) { m_poissonMinDistance = val; generateSamples();}
236  inline double poissonMinDistance() { return m_poissonMinDistance; }
237 
238  inline void setPoissonNumPoints(int val) { m_poissonPoints = val; generateSamples(); }
239  inline int poissonNumPoints() { return m_poissonPoints; }
240 
241  inline void setPoissonSeed(int val) { m_poissonSeed = val; generateSamples(); }
242  inline int poissonSeed() { return m_poissonSeed; }
243 
244  inline void setPoissonShape(short val) { m_poissonShape = val; generateSamples(); }
245  inline short poissonShape() { return m_poissonShape; }
246 
247  inline void setDrawScale(double value) { m_drawScale = value; }
248  inline double drawScale() { return m_drawScale; }
249 
250  inline bool timeOffsetGroupAgents() { return m_timeOffsetGroupAgents; }
251  inline void setTimeOffsetGroupAgents(const bool value) { m_timeOffsetGroupAgents = value; }
252 
253  inline const std::string &copiedVariationName(const std::string &agentType) { return m_copiedVariationName[agentType]; }
254  inline void setCopiedVariationName(const std::string &agentType, const std::string &name) { m_copiedVariationName[agentType] = name; }
255 
256  inline const bool falloffEnabled() { return m_falloffEnabled; }
257  inline void setFalloffEnabled(const bool value) { m_falloffEnabled = value; m_falloffDirty = true; }
258 
259  inline const double falloffRadius() { return m_falloffRadius; }
260  inline void setFalloffRadius(const double value) { m_falloffRadius = value; m_falloffDirty = true; }
261 
262  inline void setFalloffMode(const unsigned int mode) { m_falloffMode = mode; }
263  inline const unsigned int falloffMode() { return m_falloffMode; }
264 
265  inline void clearFalloffDirty() { m_falloffDirty = false; }
266  inline bool falloffDirty() { return m_falloffDirty; }
267  inline void markFalloffDirty() { m_falloffDirty = true; }
268 
269  virtual void generateSamples();
270 
271  inline std::vector<AtomsCore::Vector3> cachedSamples() { return m_cachedSamples; }
272  inline void setCachedSamples(std::vector<AtomsCore::Vector3>& samples) { m_cachedSamples = samples; }
273 
274  void agentSelectionChanged();
275 
276  virtual void reset();
277 
278  inline void setJointModeAgentGroupId(size_t mode) { m_jointModeAgentId = mode; }
279  inline size_t jointModeAgentGroupId() { return m_jointModeAgentId; }
280 
281  inline void setJointModeJointId(int mode) { m_jointModeJointId = mode; }
282  inline int jointModeJointId() { return m_jointModeJointId; }
283 
284  inline void setJointModeGroupIndex(int index) { m_jointModeGroupIndex = index; }
285  inline int jointModeGroupIndex() { return m_jointModeGroupIndex; }
286 
287  inline double polyMinRadius() { return m_polyMinRadius; };
288  inline double polyMaxRadius() { return m_polyMaxRadius; };
289  inline int polyNumAgents() { return m_polyNumAgents; };
290  inline int polyIterations() { return m_polyIterations; };
291  inline int polySeed() { return m_polySeed; };
292  inline bool polyRandom() { return m_polyRandom; };
293 
294  inline void setPolyMinRadius(double value) { m_polyMinRadius = value; m_polyHash++; };
295  inline void setPolyMaxRadius(double value) { m_polyMaxRadius = value; m_polyHash++; };
296  inline void setPolyNumAgents(int value) { m_polyNumAgents = value; m_polyHash++; };
297  inline void setPolyIterations(int value) { m_polyIterations = value; m_polyHash++;};
298  inline void setPolySeed(int value) { m_polySeed = value; m_polyHash++;};
299  inline void setPolyRandom(bool value) { m_polyRandom = value; m_polyHash++;};
300  inline long polyHash() { return m_polyHash; }
301 
302  inline void setDuplicateAgentGroupIds(const std::string groupName, const int id1, const int id2) { m_agentDuplicateIds[groupName][id1] = id2; };
303  inline void resetDuplicateAgentGroupIds() { m_agentDuplicateIds.clear(); };
304  int getDuplicateAgentGroupIds(const std::string &groupName, const int id);
305 
306  inline SocialLayoutMode socialLayoutMode() { return m_socialLayoutMode; };
307  inline void setSocialLayoutMode(SocialLayoutMode mode) { m_socialLayoutMode = mode; };
308  inline std::vector<int> &getSocialAgentIds() { return m_socialAgentIds; }
309  inline std::vector<AtomsCore::Vector3> &socialAgentPositions() { return m_socialAgentPositions; }
310  inline std::vector<AtomsCore::Vector3> &socialAgentDirections() { return m_socialAgentDirections; }
311  inline std::vector<AtomsCore::Quaternion> &socialAgentRotations() { return m_socialAgentRotations; }
312  inline AtomsCore::Vector3 &socialAveragePosition() { return m_socialAgentsAveragePosition; }
313  inline AtomsCore::Vector3 &socialAverageDirection() { return m_socialAgentsAverageDirection; }
314  inline AtomsCore::Vector3 &socialReferencePosition() { return m_socialReferencePosition; }
315  inline void setSocialReferencePosition(const AtomsCore::Vector3 &pos) { m_socialReferencePosition = pos; }
316  inline std::vector<int> &socialGroupSizes() { return m_socialGroupSizes; }
317 
318  inline void setDisplayTimeOffsetBarOnScreenBottom(const bool value) { m_displayTimeOffsetBarOnScreenBottom = value; }
319  inline bool displayTimeOffsetBarOnScreenBottom() { return m_displayTimeOffsetBarOnScreenBottom; }
320 
321  inline void setSocialSeparationForce(double value) { m_socialSeparationForce = value; };
322  inline void setSocialSeparationRadius(double value) { m_socialSeparationRadius = value; };
323  inline void setSocialDistanceNoise(const AtomsCore::Vector3 &value) { m_socialDistanceNoise = value; };
324  inline void setSocialOrientationNoise(const AtomsCore::Vector3 &value) { m_socialOrientationNoise = value; };
325  inline double socialSeparationRadius() { return m_socialSeparationRadius; };
326  inline double socialSeparationForce() { return m_socialSeparationForce; };
327  inline const AtomsCore::Vector3& socialDistanceNoise() { return m_socialDistanceNoise; };
328  inline const AtomsCore::Vector3& socialOrientationNoise() { return m_socialOrientationNoise; };
329  inline const std::vector<AtomsCore::Vector3> &socialFinalDirections() { return m_socialFinalDirections; };
330  inline const std::vector<AtomsCore::Vector3> &socialFinalPositions() { return m_socialFinalPositions; };
331  inline void setSocialFinalDirections(const std::vector<AtomsCore::Vector3> &value) { m_socialFinalDirections = value; };
332  inline void setSocialFinalPositions(const std::vector<AtomsCore::Vector3> &value) { m_socialFinalPositions = value; };
333 
334  inline void setMeshScatterIterations(const int value) { m_meshScatterIterations = value; }
335  inline void setMeshScatterDefaultRadius(const double value) { m_meshScatterDefaultRadius = value; }
336  inline void setMeshScatterMaxRadius(const double value) { m_meshScatterMaxRadius = value; }
337  inline void setMeshScatterSeed(const int value) { m_meshScatterSeed = value; }
338  inline void setMeshScatterMode(const int value) { m_meshScatterMode = value; }
339  inline void setRandRadius(const bool value) { m_meshScatterRandRadius = value; }
340  inline void setMeshScatterMesh(const AtomsUtils::Mesh &mesh) { m_meshScatterMesh = mesh; }
341  inline int meshScatterIterations() { return m_meshScatterIterations; }
342  inline double meshScatterDefaultRadius() { return m_meshScatterDefaultRadius; }
343  inline double meshScatterMaxRadius() { return m_meshScatterMaxRadius; }
344  inline int meshScatterSeed() { return m_meshScatterSeed; }
345  inline int meshScatterMode() { return m_meshScatterMode; }
346  inline bool meshRandRadius() { return m_meshScatterRandRadius; }
347 
348  int getSocialIndex(const int id) const;
349 
350  void initSocialLayoutData(const std::vector<Atoms::AgentGroup *> &agentGroups);
351  void editAgentsWithSocialValue(double value);
352 
353  static void searchAgents(const std::vector<Atoms::AgentGroup * > &agentGroups, const bool useSearchRadius, const double searchRadius, const bool ignoreOneAgent, const bool usePercentage, const int percentage, const bool useAgentType, const std::vector<std::string> &agentTypeNames, const bool useMetadata, const std::string &metadataName, const double metadataMin, const double metadataMax, const std::string& metadataStrValue, std::vector<std::vector<int>> &selection);
354  static double getPelvisHeightFromAgentType(Atoms::AgentTypeCPtr agentType);
355 
356  inline void setApplyPelvisHeightOffset(bool val) { m_applyPelvisHeightOffset = val; }
357  inline bool applyPelvisHeightOffset() { return m_applyPelvisHeightOffset; }
358 
359  protected:
360 
361  void cachePelvisTransformation(const std::vector<Atoms::AgentGroup *> &agentGroups);
362  void getHeightFieldsFromAgentGroup(AtomsPtr<Atoms::AgentGroup>& agentGroup, std::string &hfName, std::string &gfName, Atoms::HeightField* &hf, Atoms::HeightField* &gf);
363  bool computeHeightField(Atoms::Agent *agent, AtomsCore::Poser &poser, Atoms::HeightField *hf, Atoms::HeightField *gf, AtomsCore::Vector3 &jointRootWorldTranlsate, AtomsCore::Quaternion &jointRootWorldRotation, AtomsCore::Vector3 &jointRootWorldScale, AtomsCore::Vector3f &currPose, AtomsCore::Vector3 &agentUp, AtomsPtr<AtomsCore::Vector3Metadata> &upVec, double &pelvisHeight, bool useHeightFields);
364  void findModules(const AtomsPtr<Atoms::AgentGroup> &agentGroup, bool &isPointLayout, bool &isCacheReader, std::string &currentModuleName);
365 
366  unsigned short m_mode;
367 
368  unsigned short m_layout;
369 
370  unsigned short m_agentMode;
371  unsigned short m_agentGroupSelectionMode;
372 
373  unsigned short m_globalRotationMode;
374  unsigned short m_globalScaleMode;
375 
376  unsigned short m_rotationAxis;
377 
378  bool m_useHeightFields;
379 
380  bool m_randomSelected;
381 
382  bool m_timeOffsetGroupAgents;
383 
384  // 0:x 1:y 2:z
385  short m_upVector;
386 
387  bool m_translateLockX;
388  bool m_translateLockY;
389  bool m_translateLockZ;
390 
391  bool m_rotateLockX;
392  bool m_rotateLockY;
393  bool m_rotateLockZ;
394 
395  bool m_scaleLockX;
396  bool m_scaleLockY;
397  bool m_scaleLockZ;
398 
399  short m_moveSpace;
400  short m_rotationSpace;
401  short m_scaleSpace;
402 
403  bool m_displayTimeOffsetBarOnScreenBottom;
404 
405  AtomsCore::Vector3 m_pointOffset;
406 
407  AtomsCore::Vector3i m_gridSize;
408  AtomsCore::Vector3 m_gridSpace;
409  AtomsCore::Vector3 m_gridSpaceRandom;
410  AtomsCore::Vector3 m_gridRotation;
411 
412  AtomsCore::Vector3 m_direction;
413  AtomsCore::Vector3 m_directionRandom;
414 
415  std::map<std::string, std::map<int, int>> m_agentDuplicateIds;
416 
417  double m_poissonRadius;
418  double m_poissonMinDistance;
419  double m_poissonPoints;
420  short m_poissonShape;
421  unsigned int m_poissonSeed;
422  std::string m_poissonMask;
423 
424  std::map<std::string, std::string> m_copiedVariationName;
425 
426  double m_drawScale;
427 
428  std::vector<std::string> m_agentTypes;
429  std::vector<int> m_agentTypeWeights;
430 
431  std::vector<std::string> m_selectedObjects;
432 
433  std::vector<std::string> m_targetObjects;
434 
435  std::vector<AtomsCore::Vector3> m_cachedSamples;
436 
437  size_t m_jointModeAgentId;
438 
439  int m_jointModeJointId;
440  int m_jointModeGroupIndex;
441 
442  bool m_falloffEnabled;
443  double m_falloffRadius;
444  bool m_falloffDirty;
445  unsigned short m_falloffMode;
446 
447  double m_polyMinRadius;
448  double m_polyMaxRadius;
449  int m_polyNumAgents;
450  int m_polyIterations;
451  int m_polySeed;
452  bool m_polyRandom;
453 
454  long m_polyHash;
455 
456  std::vector<int> m_socialAgentIds;
457  std::vector<int> m_socialGroupSizes;
458  std::vector<AtomsCore::Vector3> m_socialAgentPositions;
459  std::vector<AtomsCore::Vector3> m_socialAgentDirections;
460  std::vector<AtomsCore::Quaternion> m_socialAgentRotations;
461  std::vector<AtomsCore::Vector3> m_agentRandomOffsetDistances;
462  std::vector<AtomsCore::Vector3> m_agentRandomOffsetDirections;
463  std::vector<std::string> m_socialAgentGroupNames;
464  AtomsCore::Vector3 m_socialAgentsAveragePosition;
465  AtomsCore::Vector3 m_socialAgentsAverageDirection;
466  AtomsCore::Vector3 m_socialReferencePosition;
467  std::vector<AtomsCore::Vector3> m_socialFinalPositions;
468  std::vector<AtomsCore::Vector3> m_socialFinalDirections;
469  SocialLayoutMode m_socialLayoutMode;
470 
471  AtomsCore::Vector3 m_socialOrientationNoise;
472  AtomsCore::Vector3 m_socialDistanceNoise;
473  double m_socialSeparationForce;
474  double m_socialSeparationRadius;
475  AtomsUtils::KdTreePoint m_socialKdTree;
476 
477  AtomsUtils::Mesh m_meshScatterMesh;
478  int m_meshScatterIterations;
479  double m_meshScatterDefaultRadius;
480  double m_meshScatterMaxRadius;
481  int m_meshScatterSeed;
482  int m_meshScatterMode;
483  bool m_meshScatterRandRadius;
484 
486  AtomsCore::Rand48 m_random;
487 
488  bool m_applyPelvisHeightOffset;
489  };
490 }
Agent.
Definition: Agent.h:44
Definition: AgentsLayoutToolData.h:23
AtomsCore::Rand48 m_random
Random number generator.
Definition: AgentsLayoutToolData.h:486
Container for all agent types.
Definition: HeightField.h:17
Poser class.
Definition: Poser.h:24
Definition: KdTreePoint.h:19
Mesh class.
Definition: Mesh.h:30
AtomsMath::Vector3i Vector3i
Vector3i class.
Definition: AtomsMath.h:59
AtomsMath::Quaternion Quaternion
Quaternion class.
Definition: AtomsMath.h:67
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
AtomsMath::Vector3f Vector3f
Vector3 class.
Definition: AtomsMath.h:58
Atoms namespace.
Definition: Agent.h:29
AtomsPtr< const AgentType > AgentTypeCPtr
Agent type const pointer.
Definition: AgentType.h:21