24 #ifndef PXR_USD_USD_SKEL_ANIM_MAPPER_H
25 #define PXR_USD_USD_SKEL_ANIM_MAPPER_H
35 #include "pxr/base/vt/array.h"
38 #include <type_traits>
67 const VtTokenArray& targetOrder);
74 const TfToken* targetOrder,
size_t targetOrderSize);
84 template <
typename Container>
89 defaultValue=
nullptr)
const;
107 template <
typename Matrix4>
111 int elementSize=1)
const;
132 size_t size()
const {
return _targetSize; }
134 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,
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>
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)
252 sourceData + (i+1)*elementSize,
253 targetData + targetIdx*elementSize);
263 #endif // PXR_USD_USD_SKEL_ANIM_MAPPER_H
bool Remap(const Container &source, Container *target, int elementSize=1, const typename Container::value_type *defaultValue=nullptr) const
USDSKEL_API bool RemapTransforms(const VtArray< Matrix4 > &source, VtArray< Matrix4 > *target, int elementSize=1) const
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define TF_DEV_AXIOM(cond)
std::shared_ptr< class UsdSkelAnimMapper > UsdSkelAnimMapperRefPtr
bool operator!=(const UsdSkelAnimMapper &o) const
GLsizei GLsizei GLchar * source
USDSKEL_API bool IsNull() const
USDSKEL_API bool IsSparse() const
Array concept. By default, types are not arrays.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
USDSKEL_API bool IsIdentity() const
bool operator==(const UsdSkelAnimMapper &o) const
USDSKEL_API size_t size() const
TfSpan< typename Container::value_type > TfMakeSpan(Container &cont)
Helper for constructing a non-const TfSpan from a container.
#define PXR_NAMESPACE_CLOSE_SCOPE
USDSKEL_API UsdSkelAnimMapper()
Construct a null mapper.