7 #ifndef PXR_USD_USD_SKEL_ANIM_MAPPER_H
8 #define PXR_USD_USD_SKEL_ANIM_MAPPER_H
18 #include "pxr/base/vt/array.h"
21 #include <type_traits>
50 const VtTokenArray& targetOrder);
57 const TfToken* targetOrder,
size_t targetOrderSize);
67 template <
typename Container>
72 defaultValue=
nullptr)
const;
90 template <
typename Matrix4>
94 int elementSize=1)
const;
115 size_t size()
const {
return _targetSize; }
117 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,
139 typename std::enable_if<
141 Container>::
type* = 0)
142 { container->resize(size, defaultValue); }
145 bool _IsOrdered()
const;
156 VtIntArray _indexMap;
161 template <
typename T>
163 UsdSkelAnimMapper::_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;
177 template <
typename Container>
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)
235 sourceData + (i+1)*elementSize,
236 targetData + targetIdx*elementSize);
246 #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)
GLint GLint GLsizei GLint GLenum GLenum type
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.