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