7#ifndef PXR_USD_USD_SKEL_ANIM_MAPPER_H
8#define PXR_USD_USD_SKEL_ANIM_MAPPER_H
13#include "pxr/usd/usdSkel/api.h"
25PXR_NAMESPACE_OPEN_SCOPE
28using UsdSkelAnimMapperRefPtr = std::shared_ptr<class UsdSkelAnimMapper>;
35class UsdSkelAnimMapper {
44 UsdSkelAnimMapper(
size_t size);
49 UsdSkelAnimMapper(
const VtTokenArray& sourceOrder,
50 const VtTokenArray& targetOrder);
56 UsdSkelAnimMapper(
const TfToken* sourceOrder,
size_t sourceOrderSize,
57 const TfToken* targetOrder,
size_t targetOrderSize);
67 template <
typename Container>
68 bool Remap(
const Container& source,
71 const typename Container::value_type*
72 defaultValue=
nullptr)
const;
90 template <
typename Matrix4>
94 int elementSize=1)
const;
99 bool IsIdentity()
const;
105 bool IsSparse()
const;
115 size_t size()
const {
return _targetSize; }
117 bool operator==(
const UsdSkelAnimMapper& o)
const;
119 bool operator!=(
const UsdSkelAnimMapper& o)
const {
120 return !(*
this == o);
125 template <
typename T>
127 int elementSize,
const VtValue& defaultValue)
const;
129 template <
typename T>
130 static void _ResizeContainer(
VtArray<T>* array,
132 const T& defaultValue);
134 template <
typename Container>
135 static void _ResizeContainer(
136 Container* container,
138 const typename Container::value_type& defaultValue,
139 typename std::enable_if<
141 Container>::type* = 0)
142 { container->resize(size, defaultValue); }
145 bool _IsOrdered()
const;
156 VtIntArray _indexMap;
163UsdSkelAnimMapper::_ResizeContainer(
VtArray<T>* array,
size_t size,
164 const T& defaultValue)
168 const size_t prevSize = array->
size();
171 for(
size_t i = prevSize; i < size; ++i) {
172 span[i] = defaultValue;
177template <
typename Container>
179UsdSkelAnimMapper::Remap(
const Container& source,
182 const typename Container::value_type* defaultValue)
const
184 using _ValueType =
typename Container::value_type;
190 if (elementSize <= 0) {
191 TF_WARN(
"Invalid elementSize [%d]: "
192 "size must be greater than zero.", elementSize);
196 const size_t targetArraySize = _targetSize*elementSize;
198 if (IsIdentity() && source.size() == targetArraySize) {
205 _ResizeContainer(target, targetArraySize,
206 defaultValue ? *defaultValue : _ValueType());
210 }
else if (_IsOrdered()) {
213 std::min(source.size(), targetArraySize - _offset*elementSize);
214 std::copy(source.cdata(), source.cdata()+copyCount,
215 target->data() + _offset*elementSize);
218 const _ValueType* sourceData = source.cdata();
220 _ValueType* targetData = target->data();
221 size_t copyCount = std::min(source.size()/elementSize,
224 const int* indexMap = _indexMap.data();
226 for (
size_t i = 0; i < copyCount; ++i) {
227 int targetIdx = indexMap[i];
228 if (targetIdx >= 0 &&
229 static_cast<size_t>(targetIdx) < target->size()) {
232 TF_DEV_AXIOM(
static_cast<size_t>((targetIdx+1)*elementSize)
234 std::copy(sourceData + i*elementSize,
235 sourceData + (i+1)*elementSize,
236 targetData + targetIdx*elementSize);
244PXR_NAMESPACE_CLOSE_SCOPE
Token for efficient comparison, assignment, and hashing of known strings.
Represents an arbitrary dimensional rectangular container class.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
size_t size() const
Return the total number of elements in this array.
void resize(size_t newSize)
Resize this array.
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
#define TF_WARN(...)
Issue a warning, but continue execution.
TfSpan< typename Container::value_type > TfMakeSpan(Container &cont)
Helper for constructing a non-const TfSpan from a container.
Array concept. By default, types are not arrays.