Atoms Crowd  7.0.0
AtomsClip.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 Atoms
10 {
11  template <typename T>
12  void AtomsClip::setJointMetadata(const unsigned int jointId, const std::string &metadataName, const AtomsPtr<AtomsCore::TypedArrayMetadata<T>> &value)
13  {
14  if (jointId >= m_numJoints)
15  {
16  AtomsUtils::Logger::error() << "joint id out of range " << jointId;
17  return;
18  }
19  const auto &ms = value->get();
20  if (ms.size() != m_numFrames)
21  {
22  AtomsUtils::Logger::error() << "Joint metadata " << metadataName << " size differs from atoms clip num frames.";
23  return;
24  }
25 
26  AtomsPtr<AtomsCore::MapMetadata> jointMapPtr = m_jointArray.getTypedElement<AtomsCore::MapMetadata>(jointId);
27  if (jointMapPtr == nullptr)
28  {
29  AtomsUtils::Logger::error() << "Could not find joint map from internal joints map.";
30  return;
31  }
32  AtomsPtr<AtomsCore::MapMetadata> metaMap = jointMapPtr->getTypedEntry<AtomsCore::MapMetadata>(JOINT_META);
33  if (metaMap == nullptr)
34  {
35  AtomsUtils::Logger::error() << "No metadata map found for joint " << jointId;
36  return;
37  }
38 
39  metaMap->addEntry(metadataName, value);
40  }
41 
42  template <typename T>
43  const AtomsPtr<AtomsCore::TypedArrayMetadata<T>> AtomsClip::getJointMetadata(const unsigned int jointId, const std::string &metadataName) const
44  {
45  if (jointId >= m_numJoints)
46  {
47  AtomsUtils::Logger::error() << "joint id out of range " << jointId;
48  return AtomsPtr<const AtomsCore::TypedArrayMetadata<T>>();
49  }
50 
51  auto jointMapPtr = m_jointArray.getTypedElement<AtomsCore::MapMetadata>(jointId);
52  if (jointMapPtr == nullptr)
53  {
54  AtomsUtils::Logger::error() << "Could not find joint map from internal joints map.";
55  return AtomsPtr<const AtomsCore::TypedArrayMetadata<T>>();
56  }
57  auto metaMap = jointMapPtr->getTypedEntry<AtomsCore::MapMetadata>(JOINT_META);
58  if (metaMap == nullptr)
59  {
60  AtomsUtils::Logger::error() << "No metadata map found for joint " << jointId;
61  return AtomsPtr<const AtomsCore::TypedArrayMetadata<T>>();
62  }
63  return metaMap->getTypedEntry<const AtomsCore::TypedArrayMetadata<T>>(metadataName);
64  }
65 
66  template <typename T> void AtomsClip::setJointStaticMetadata(const unsigned int jointId, const std::string &metadataName, const AtomsPtr<AtomsCore::MetadataImpl<T>> &value)
67  {
68  if (jointId >= m_numJoints)
69  {
70  AtomsUtils::Logger::error() << "joint id out of range " << jointId;
71  return;
72  }
73 
74  AtomsPtr<AtomsCore::MapMetadata> jointMapPtr = m_jointArray.getTypedElement<AtomsCore::MapMetadata>(jointId);
75  if (jointMapPtr == nullptr)
76  {
77  AtomsUtils::Logger::error() << "Could not find joint map from internal joints map.";
78  return;
79  }
80  AtomsPtr<AtomsCore::MapMetadata> metaMap = jointMapPtr->getTypedEntry<AtomsCore::MapMetadata>(JOINT_STATIC_META);
81  if (metaMap == nullptr)
82  {
83  AtomsUtils::Logger::error() << "No metadata map found for joint " << jointId;
84  return;
85  }
86 
87  metaMap->addEntry(metadataName, value);
88  }
89 
90  template <typename T> const AtomsPtr<AtomsCore::MetadataImpl<T>> AtomsClip::getJointStaticMetadata(const unsigned int jointId, const std::string &metadataName) const
91  {
92  if (jointId >= m_numJoints)
93  {
94  AtomsUtils::Logger::error() << "joint id out of range " << jointId;
95  return AtomsPtr<const AtomsCore::MetadataImpl<T>>();
96  }
97 
98  auto jointMapPtr = m_jointArray.getTypedElement<AtomsCore::MapMetadata>(jointId);
99  if (jointMapPtr == nullptr)
100  {
101  AtomsUtils::Logger::error() << "Could not find joint map from internal joints map.";
102  return AtomsPtr<const AtomsCore::MetadataImpl<T>>();
103  }
104  auto metaMap = jointMapPtr->getTypedEntry<AtomsCore::MapMetadata>(JOINT_STATIC_META);
105  if (metaMap == nullptr)
106  {
107  AtomsUtils::Logger::error() << "No metadata map found for joint " << jointId;
108  return AtomsPtr<const AtomsCore::MetadataImpl<T>>();
109  }
110  return metaMap->getTypedEntry<const AtomsCore::MetadataImpl<T>>(metadataName);
111  }
112 
114  {
115  m_inParentSpace = flag;
116  }
117 
119  {
120  return m_inParentSpace;
121  }
122 }
void setJointStaticMetadata(const unsigned int jointId, const std::string &metadataName, const AtomsPtr< AtomsCore::MetadataImpl< T >> &value)
Sets joint static metadata.
Definition: AtomsClip.impl.h:66
void setJointMetadata(const unsigned int jointId, const std::string &metadataName, const AtomsPtr< AtomsCore::TypedArrayMetadata< T >> &value)
Sets joint metadata.
Definition: AtomsClip.impl.h:12
const AtomsPtr< AtomsCore::TypedArrayMetadata< T > > getJointMetadata(const unsigned int jointId, const std::string &metadataName) const
Gets joint metadata.
Definition: AtomsClip.impl.h:43
bool inParentSpace() const
Gets the parent space flag.
Definition: AtomsClip.impl.h:118
const AtomsPtr< AtomsCore::MetadataImpl< T > > getJointStaticMetadata(const unsigned int jointId, const std::string &metadataName) const
Get joint static metadata.
Definition: AtomsClip.impl.h:90
void setInParentSpace(bool flag)
Sets use parent space flag.
Definition: AtomsClip.impl.h:113
AtomsPtr< T > getTypedElement(size_t index)
Get a typed element.
Definition: ArrayMetadata.impl.h:4
MapMetadata class.
Definition: MapMetadata.h:24
Metadata template class.
Definition: MetadataImpl.h:158
Metadata template class.
Definition: TypedArrayMetadata.h:160
static LogProxy error()
Get logger proxy error.
Atoms namespace.
Definition: Agent.h:29