Atoms Crowd  7.0.0
Skeleton.impl.h
1 // ===========================================================================
2 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
3 //
4 // Use of this software is subject to the terms of the Toolchefs license
5 // agreement provided at the time of installation or download, or which
6 // otherwise accompanies this software in either electronic or hard copy form.
7 // ===========================================================================
8 
9 namespace AtomsCore
10 {
11  unsigned short Skeleton::numJoints() const
12  {
13  return m_numJoints;
14  }
15 
16  Joint& Skeleton::operator[](unsigned short index)
17  {
18  return m_joints[index];
19  }
20 
21  const Joint& Skeleton::operator[](unsigned short index) const
22  {
23  return m_joints[index];
24  }
25 
27  {
28  return &m_joints[m_root];
29  }
30 
32  {
33  return &m_joints[m_root];
34  }
35 
36  void Skeleton::setRoot(unsigned short id)
37  {
38  if (id < m_numJoints)
39  m_root = id;
40  }
41 
42  unsigned short Skeleton::numFeet() const
43  {
44  return static_cast<unsigned short>(m_feet.size());
45  }
46 
48  {
49  m_feet.clear();
50  }
51 
52  void Skeleton::addFoot(unsigned short footIK, unsigned short footRoot, unsigned short footTip)
53  {
54  if ((footIK < m_numJoints) && (footRoot < m_numJoints) && (footTip < m_numJoints))
55  m_feet.push_back(FootStruct(footIK, footRoot, footTip));
56  }
57 
58  JointPtr Skeleton::footIK(unsigned short id)
59  {
60  return &m_joints[m_feet[id].footIK];
61  }
62 
63  JointCPtr Skeleton::footIK(unsigned short id) const
64  {
65  return &m_joints[m_feet[id].footIK];
66  }
67 
68  JointPtr Skeleton::footRoot(unsigned short id)
69  {
70  return &m_joints[m_feet[id].footRoot];
71  }
72 
73  JointCPtr Skeleton::footRoot(unsigned short id) const
74  {
75  return &m_joints[m_feet[id].footRoot];
76  }
77 
78  JointPtr Skeleton::footTip(unsigned short id)
79  {
80  return &m_joints[m_feet[id].footTip];
81  }
82 
83  JointCPtr Skeleton::footTip(unsigned short id) const
84  {
85  return &m_joints[m_feet[id].footTip];
86  }
87 
88  bool Skeleton::footHasPoleVector(unsigned short id) const
89  {
90  return m_feet[id].hasPoleVector;
91  }
92 
94  {
95  return m_feet[id].poleVector;
96  }
97 
98  void Skeleton::setFootPoleVector(unsigned short id, const AtomsCore::Vector3& value)
99  {
100  if (id < m_feet.size())
101  {
102  auto& foot = m_feet[id];
103  foot.poleVector = value;
104  foot.hasPoleVector = true;
105  }
106  }
107 
108  unsigned short Skeleton::footPelvis(unsigned short id) const
109  {
110  return m_feet[id].pelvis;
111  }
112 
113  const std::vector<unsigned short>& Skeleton::midJoints(unsigned short id) const
114  {
115  return m_feet[id].midJoints;
116  }
117 
118  const std::vector<unsigned short>& Skeleton::legJoints(unsigned short id) const
119  {
120  return m_feet[id].legJoints;
121  }
122 
123  unsigned short Skeleton::numPelvises() const
124  {
125  return static_cast<unsigned short>(std::max(m_pelvises.size(), static_cast<size_t>(1)));
126  }
127 
129  {
130  m_pelvises.clear();
131  }
132 
133  void Skeleton::addPelvis(unsigned short pelvisJoint)
134  {
135  if (pelvisJoint < m_numJoints)
136  {
137  bool alreadyExists = false;
138  for (auto& id : m_pelvises)
139  {
140  if (id == pelvisJoint)
141  {
142  alreadyExists = true;
143  break;
144  }
145  }
146  if (!alreadyExists)
147  {
148  m_pelvises.push_back(pelvisJoint);
149 
150  std::sort(m_pelvises.begin(), m_pelvises.end());
151 
152  }
153  }
154  }
155 
156  JointPtr Skeleton::pelvis(unsigned short id)
157  {
158  return m_pelvises.size() > 0 ? &m_joints[m_pelvises[id]] : &m_joints[0];
159  }
160 
161  JointCPtr Skeleton::pelvis(unsigned short id) const
162  {
163  return m_pelvises.size() > 0 ? &m_joints[m_pelvises[id]] : &m_joints[0];
164  }
165 
166  unsigned int Skeleton::numPelvisChains(unsigned int id) const
167  {
168  if (m_pelvisChains.size() > id)
169  return static_cast<unsigned int>(m_pelvisChains[id].size());
170  else
171  return 0;
172  }
173 
174  int Skeleton::jointId(const std::string& name) const
175  {
176  std::unordered_map<std::string, int>::const_iterator it = m_jointNameIdMap.find(name);
177  if (it != m_jointNameIdMap.end())
178  {
179  return it->second;
180  }
181  return -1;
182  }
183 
185  {
186  delete[] m_joints;
187  m_joints = nullptr;
188  m_feet.clear();
189  m_jointNameIdMap.clear();
190  m_jointMetadata.clear();
191  m_pelvises.clear();
192  m_root = 0;
193  m_numJoints = 0;
194  }
195 
196  MapMetadata& Skeleton::jointMetadata(unsigned short index)
197  {
198  return m_jointMetadata[index];
199  }
200 
201  void Skeleton::setJointMetadata(unsigned short index, const MapMetadata& data)
202  {
203  m_jointMetadata[index] = data;
204  }
205 
206  void Skeleton::addJointMetadata(unsigned short index, const std::string& key, AtomsPtr<Metadata> data)
207  {
208  m_jointMetadata[index].addEntry(key, data);
209  }
210 
211  void Skeleton::addJointMetadata(unsigned short index, const std::string& key, Metadata *data)
212  {
213  m_jointMetadata[index].addEntry(key, data);
214  }
215 
217  {
218  m_jointMetadata.clear();
219  }
220 
221  const std::vector<unsigned short>& Skeleton::detachedJoints() const
222  {
223  return m_detachedJoints;
224  }
225 
226  std::vector<SkeletonLod>& Skeleton::lods()
227  {
228  return m_lods;
229  }
230 
231  const std::vector<SkeletonLod>& Skeleton::lods() const
232  {
233  return m_lods;
234  }
235 }
236 
Joint class.
Definition: Joint.h:30
MapMetadata class.
Definition: MapMetadata.h:24
Base Metadata class.
Definition: Metadata.h:24
unsigned short numPelvises() const
Gets the number of pelvises.
Definition: Skeleton.impl.h:123
JointPtr footTip(unsigned short id)
Get foot tip.
Definition: Skeleton.impl.h:78
bool footHasPoleVector(unsigned short id) const
Returns true if the foot at the given id has a pole vector.
Definition: Skeleton.impl.h:88
const std::vector< unsigned short > & legJoints(unsigned short id) const
Get leg joints.
Definition: Skeleton.impl.h:118
const std::vector< unsigned short > & midJoints(unsigned short id) const
Get leg mid joints.
Definition: Skeleton.impl.h:113
JointPtr footRoot(unsigned short id)
Get foot root.
Definition: Skeleton.impl.h:68
JointCPtr root() const
Gets the root joint.
Definition: Skeleton.impl.h:26
unsigned int numPelvisChains(unsigned int id) const
Get number of pelvis chains.
Definition: Skeleton.impl.h:166
MapMetadata & jointMetadata(unsigned short index)
Gets joint metadata.
Definition: Skeleton.impl.h:196
void clear()
Clears all joints and metadatas.
Definition: Skeleton.impl.h:184
Joint & operator[](unsigned short index)
Gets the joint.
Definition: Skeleton.impl.h:16
void setFootPoleVector(unsigned short id, const AtomsCore::Vector3 &value)
Set the foto pole vector.
Definition: Skeleton.impl.h:98
AtomsCore::Vector3 footPoleVector(unsigned short id) const
Returns the foot pole vector.
Definition: Skeleton.impl.h:93
void setJointMetadata(unsigned short index, const MapMetadata &data)
Adds joint metadata.
Definition: Skeleton.impl.h:201
void clearPelvises()
Clears all pelvises.
Definition: Skeleton.impl.h:128
unsigned short footPelvis(unsigned short id) const
Get foot pelvis.
Definition: Skeleton.impl.h:108
const std::vector< unsigned short > & detachedJoints() const
Get joints without a parent.
Definition: Skeleton.impl.h:221
void clearJointsMetadata()
Clears all joint metadata.
Definition: Skeleton.impl.h:216
void addPelvis(unsigned short pelvisJoint)
Adds a pelvis.
Definition: Skeleton.impl.h:133
std::vector< SkeletonLod > & lods()
Get sim lod info.
Definition: Skeleton.impl.h:226
JointPtr footIK(unsigned short id)
Gets the foot IK.
Definition: Skeleton.impl.h:58
unsigned short numJoints() const
Gets the number of joints.
Definition: Skeleton.impl.h:11
void clearFeet()
Clears all the feet.
Definition: Skeleton.impl.h:47
int jointId(const std::string &name) const
Gets the joint id.
Definition: Skeleton.impl.h:174
JointPtr pelvis(unsigned short id)
Gets a pelvis.
Definition: Skeleton.impl.h:156
unsigned short numFeet() const
Gets the number of feet.
Definition: Skeleton.impl.h:42
void setRoot(unsigned short id)
Sets the root joint.
Definition: Skeleton.impl.h:36
void addJointMetadata(unsigned short index, const std::string &key, Metadata *data)
Adds joint metadata.
Definition: Skeleton.impl.h:211
void addFoot(unsigned short footIK, unsigned short footRoot, unsigned short footTip)
Adds a foot.
Definition: Skeleton.impl.h:52
AtomsCore namespace.
Definition: Agent.h:344
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
Definition: Skeleton.h:33