24 #ifndef PXR_USD_USD_SKEL_ANIM_MAPPER_H 25 #define PXR_USD_USD_SKEL_ANIM_MAPPER_H 30 #include "pxr/usd/usdSkel/api.h" 38 #include <type_traits> 42 PXR_NAMESPACE_OPEN_SCOPE
45 using UsdSkelAnimMapperRefPtr = std::shared_ptr<class UsdSkelAnimMapper>;
52 class UsdSkelAnimMapper {
61 UsdSkelAnimMapper(
size_t size);
66 UsdSkelAnimMapper(
const VtTokenArray& sourceOrder,
67 const VtTokenArray& targetOrder);
73 UsdSkelAnimMapper(
const TfToken* sourceOrder,
size_t sourceOrderSize,
74 const TfToken* targetOrder,
size_t targetOrderSize);
84 template <
typename Container>
85 bool Remap(
const Container& source,
88 const typename Container::value_type*
89 defaultValue=
nullptr)
const;
107 template <
typename Matrix4>
111 int elementSize=1)
const;
116 bool IsIdentity()
const;
122 bool IsSparse()
const;
132 size_t size()
const {
return _targetSize; }
134 bool operator==(
const UsdSkelAnimMapper& o)
const;
136 bool operator!=(
const UsdSkelAnimMapper& o)
const {
137 return !(*
this == o);
142 template <
typename T>
144 int elementSize,
const VtValue& defaultValue)
const;
146 template <
typename T>
147 static void _ResizeContainer(
VtArray<T>* array,
149 const T& defaultValue);
151 template <
typename Container>
152 static void _ResizeContainer(
153 Container* container,
155 const typename Container::value_type& defaultValue,
156 typename std::enable_if<
158 Container>::type* = 0)
159 { container->resize(size, defaultValue); }
162 bool _IsOrdered()
const;
173 VtIntArray _indexMap;
178 template <
typename T>
180 UsdSkelAnimMapper::_ResizeContainer(
VtArray<T>* array,
size_t size,
181 const T& defaultValue)
185 const size_t prevSize = array->
size();
188 for(
size_t i = prevSize; i < size; ++i) {
189 span[i] = defaultValue;
194 template <
typename Container>
196 UsdSkelAnimMapper::Remap(
const Container& source,
199 const typename Container::value_type* defaultValue)
const 201 using _ValueType =
typename Container::value_type;
207 if (elementSize <= 0) {
208 TF_WARN(
"Invalid elementSize [%d]: " 209 "size must be greater than zero.", elementSize);
213 const size_t targetArraySize = _targetSize*elementSize;
215 if (IsIdentity() && source.size() == targetArraySize) {
222 _ResizeContainer(target, targetArraySize,
223 defaultValue ? *defaultValue : _ValueType());
227 }
else if (_IsOrdered()) {
230 std::min(source.size(), targetArraySize - _offset*elementSize);
231 std::copy(source.cdata(), source.cdata()+copyCount,
232 target->data() + _offset*elementSize);
235 const _ValueType* sourceData = source.cdata();
237 _ValueType* targetData = target->data();
238 size_t copyCount = std::min(source.size()/elementSize,
241 const int* indexMap = _indexMap.data();
243 for (
size_t i = 0; i < copyCount; ++i) {
244 int targetIdx = indexMap[i];
245 if (targetIdx >= 0 &&
246 static_cast<size_t>(targetIdx) < target->size()) {
249 TF_DEV_AXIOM(static_cast<size_t>((targetIdx+1)*elementSize)
251 std::copy(sourceData + i*elementSize,
252 sourceData + (i+1)*elementSize,
253 targetData + targetIdx*elementSize);
261 PXR_NAMESPACE_CLOSE_SCOPE
263 #endif // PXR_USD_USD_SKEL_ANIM_MAPPER_H #define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
size_t size() const
Return the total number of elements in this array.
#define TF_WARN(...)
Issue a warning, but continue execution.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
void resize(size_t newSize)
Resize this array.
Token for efficient comparison, assignment, and hashing of known strings.
Represents an arbitrary dimensional rectangular container class.
Array concept. By default, types are not arrays.
VT_API bool operator==(VtDictionary const &, VtDictionary const &)
Equality comparison.
TfSpan< typename Container::value_type > TfMakeSpan(Container &cont)
Helper for constructing a non-const TfSpan from a container.
Provides a container which may hold any type, and provides introspection and iteration over array typ...