Atoms Crowd  4.1.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  }
151  }
152 
153  JointPtr Skeleton::pelvis(unsigned short id)
154  {
155  return m_pelvises.size() > 0 ? &m_joints[m_pelvises[id]] : &m_joints[0];
156  }
157 
158  JointCPtr Skeleton::pelvis(unsigned short id) const
159  {
160  return m_pelvises.size() > 0 ? &m_joints[m_pelvises[id]] : &m_joints[0];
161  }
162 
163  unsigned int Skeleton::numPelvisChains(unsigned int id) const
164  {
165  if (m_pelvisChains.size() > id)
166  return static_cast<unsigned int>(m_pelvisChains[id].size());
167  else
168  return 0;
169  }
170 
171  int Skeleton::jointId(const std::string& name) const
172  {
173  std::unordered_map<std::string, int>::const_iterator it = m_jointNameIdMap.find(name);
174  if (it != m_jointNameIdMap.end())
175  {
176  return it->second;
177  }
178  return -1;
179  }
180 
182  {
183  delete[] m_joints;
184  m_joints = nullptr;
185  m_feet.clear();
186  m_jointNameIdMap.clear();
187  m_jointMetadata.clear();
188  m_pelvises.clear();
189  m_root = 0;
190  m_numJoints = 0;
191  }
192 
193  MapMetadata& Skeleton::jointMetadata(unsigned short index)
194  {
195  return m_jointMetadata[index];
196  }
197 
198  void Skeleton::setJointMetadata(unsigned short index, const MapMetadata& data)
199  {
200  m_jointMetadata[index] = data;
201  }
202 
203  void Skeleton::addJointMetadata(unsigned short index, const std::string& key, AtomsPtr<Metadata> data)
204  {
205  m_jointMetadata[index].addEntry(key, data);
206  }
207 
208  void Skeleton::addJointMetadata(unsigned short index, const std::string& key, Metadata *data)
209  {
210  m_jointMetadata[index].addEntry(key, data);
211  }
212 
214  {
215  m_jointMetadata.clear();
216  }
217 
218  const std::vector<unsigned short>& Skeleton::detachedJoints() const
219  {
220  return m_detachedJoints;
221  }
222 
223  std::vector<SkeletonLod>& Skeleton::lods()
224  {
225  return m_lods;
226  }
227 
228  const std::vector<SkeletonLod>& Skeleton::lods() const
229  {
230  return m_lods;
231  }
232 }
233 
AtomsCore::Skeleton::footTip
JointPtr footTip(unsigned short id)
Get foot tip.
Definition: Skeleton.impl.h:78
AtomsCore::Skeleton::numJoints
unsigned short numJoints() const
Gets the number of joints.
Definition: Skeleton.impl.h:11
AtomsCore::Skeleton::addJointMetadata
void addJointMetadata(unsigned short index, const std::string &key, Metadata *data)
Adds joint metadata.
Definition: Skeleton.impl.h:208
AtomsCore::Skeleton::operator[]
Joint & operator[](unsigned short index)
Gets the joint.
Definition: Skeleton.impl.h:16
AtomsCore::Skeleton::pelvis
JointPtr pelvis(unsigned short id)
Gets a pelvis.
Definition: Skeleton.impl.h:153
AtomsCore::Skeleton::legJoints
const std::vector< unsigned short > & legJoints(unsigned short id) const
Get leg joints.
Definition: Skeleton.impl.h:118
AtomsCore::Skeleton::setRoot
void setRoot(unsigned short id)
Sets the root joint.
Definition: Skeleton.impl.h:36
AtomsCore::Skeleton::detachedJoints
const std::vector< unsigned short > & detachedJoints() const
Get joints without a parent.
Definition: Skeleton.impl.h:218
AtomsCore::Metadata
Base Metadata class.
Definition: Metadata.h:24
AtomsCore::FootStruct
Definition: Skeleton.h:33
AtomsCore::Skeleton::setJointMetadata
void setJointMetadata(unsigned short index, const MapMetadata &data)
Adds joint metadata.
Definition: Skeleton.impl.h:198
AtomsCore::Skeleton::root
JointCPtr root() const
Gets the root joint.
Definition: Skeleton.impl.h:26
AtomsCore::Skeleton::addFoot
void addFoot(unsigned short footIK, unsigned short footRoot, unsigned short footTip)
Adds a foot.
Definition: Skeleton.impl.h:52
AtomsCore::Skeleton::numFeet
unsigned short numFeet() const
Gets the number of feet.
Definition: Skeleton.impl.h:42
AtomsCore::Skeleton::footHasPoleVector
bool footHasPoleVector(unsigned short id) const
Returns true if the foot at the given id has a pole vector.
Definition: Skeleton.impl.h:88
AtomsCore::Skeleton::setFootPoleVector
void setFootPoleVector(unsigned short id, const AtomsCore::Vector3 &value)
Set the foto pole vector.
Definition: Skeleton.impl.h:98
AtomsCore::Skeleton::clearJointsMetadata
void clearJointsMetadata()
Clears all joint metadata.
Definition: Skeleton.impl.h:213
AtomsCore::Skeleton::footIK
JointPtr footIK(unsigned short id)
Gets the foot IK.
Definition: Skeleton.impl.h:58
AtomsCore::Vector3
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
AtomsCore::Skeleton::lods
std::vector< SkeletonLod > & lods()
Get sim lod info.
Definition: Skeleton.impl.h:223
AtomsCore::Joint
Joint class.
Definition: Joint.h:30
AtomsCore::Skeleton::clear
void clear()
Clears all joints and metadatas.
Definition: Skeleton.impl.h:181
AtomsCore
AtomsCore namespace.
Definition: AtomsMath.h:24
AtomsCore::MapMetadata
MapMetadata class.
Definition: MapMetadata.h:24
AtomsCore::Skeleton::numPelvisChains
unsigned int numPelvisChains(unsigned int id) const
Get number of pelvis chains.
Definition: Skeleton.impl.h:163
AtomsCore::Skeleton::jointMetadata
MapMetadata & jointMetadata(unsigned short index)
Gets joint metadata.
Definition: Skeleton.impl.h:193
AtomsCore::Skeleton::midJoints
const std::vector< unsigned short > & midJoints(unsigned short id) const
Get leg mid joints.
Definition: Skeleton.impl.h:113
AtomsCore::Skeleton::footPelvis
unsigned short footPelvis(unsigned short id) const
Get foot pelvis.
Definition: Skeleton.impl.h:108
AtomsCore::Skeleton::footPoleVector
AtomsCore::Vector3 footPoleVector(unsigned short id) const
Returns the foot pole vector.
Definition: Skeleton.impl.h:93
AtomsCore::Skeleton::addPelvis
void addPelvis(unsigned short pelvisJoint)
Adds a pelvis.
Definition: Skeleton.impl.h:133
AtomsCore::Skeleton::footRoot
JointPtr footRoot(unsigned short id)
Get foot root.
Definition: Skeleton.impl.h:68
AtomsCore::Skeleton::numPelvises
unsigned short numPelvises() const
Gets the number of pelvises.
Definition: Skeleton.impl.h:123
AtomsCore::Skeleton::clearPelvises
void clearPelvises()
Clears all pelvises.
Definition: Skeleton.impl.h:128
AtomsCore::Skeleton::clearFeet
void clearFeet()
Clears all the feet.
Definition: Skeleton.impl.h:47
AtomsCore::Skeleton::jointId
int jointId(const std::string &name) const
Gets the joint id.
Definition: Skeleton.impl.h:171