18 #ifndef viskores_cont_ArrayHandleSwizzle_h
19 #define viskores_cont_ArrayHandleSwizzle_h
25 #include <viskoresstd/integer_sequence.h>
32 template <
typename InType,
typename OutType>
45 using IndexList = viskoresstd::make_integer_sequence<viskores::IdComponent, NUM_OUT_COMPONENTS>;
59 return this->Swizzle(vec, IndexList{});
62 VISKORES_CONT static MapType InitMap() {
return IndexListAsMap(IndexList{}); }
66 VISKORES_CONT static MapType IndexListAsMap(IndexSequence<Is...>)
77 MapType Map = InitMap();
83 template <
typename InType,
typename OutType,
typename Invertible>
84 struct GetInverseSwizzleImpl;
86 template <
typename InType,
typename OutType>
87 struct GetInverseSwizzleImpl<InType, OutType, std::true_type>
89 using Type = viskores::internal::SwizzleFunctor<OutType, InType>;
90 template <
typename ForwardMapType>
91 VISKORES_CONT static Type Value(
const ForwardMapType& forwardMap)
96 using InverseMapType =
typename Type::MapType;
97 InverseMapType inverseMap = Type::InitMap();
100 inverseMap[forwardMap[inIndex]] = inIndex;
103 return Type(inverseMap);
107 template <
typename InType,
typename OutType>
108 struct GetInverseSwizzleImpl<InType, OutType, std::false_type>
110 using Type = viskores::cont::internal::NullFunctorType;
111 template <
typename ForwardMapType>
118 template <
typename InType,
typename OutType>
119 using SwizzleInvertible = std::integral_constant<bool,
125 template <
typename InType,
typename OutType>
126 VISKORES_CONT viskores::internal::SwizzleFunctor<InType, OutType> GetSwizzleFunctor(
129 return viskores::internal::SwizzleFunctor<InType, OutType>(forwardMap);
132 template <
typename InType,
typename OutType>
133 using InverseSwizzleType =
typename detail::
134 GetInverseSwizzleImpl<InType, OutType, detail::SwizzleInvertible<InType, OutType>>::Type;
136 template <
typename InType,
typename OutType>
137 VISKORES_CONT InverseSwizzleType<InType, OutType> GetInverseSwizzleFunctor(
141 GetInverseSwizzleImpl<InType, OutType, detail::SwizzleInvertible<InType, OutType>>::Value(
156 template <
typename ArrayHandleType, viskores::IdComponent OutSize>
157 struct ArrayHandleSwizzleTraits
161 using InType =
typename ArrayHandleType::ValueType;
163 using SwizzleFunctor = viskores::internal::SwizzleFunctor<InType, OutType>;
164 using InverseSwizzleFunctor = viskores::internal::InverseSwizzleType<InType, OutType>;
165 using MapType =
typename SwizzleFunctor::MapType;
167 static SwizzleFunctor GetFunctor(
const MapType& forwardMap)
169 return viskores::internal::GetSwizzleFunctor<InType, OutType>(forwardMap);
172 static InverseSwizzleFunctor GetInverseFunctor(
const MapType& forwardMap)
174 return viskores::internal::GetInverseSwizzleFunctor<InType, OutType>(forwardMap);
200 template <
typename ArrayHandleType, viskores::IdComponent OutSize>
202 :
public detail::ArrayHandleSwizzleTraits<ArrayHandleType, OutSize>
::Superclass
206 using Traits = detail::ArrayHandleSwizzleTraits<ArrayHandleType, OutSize>;
231 template <
typename ArrayHandleType, viskores::IdComponent OutSize>
233 const ArrayHandleType& array,
243 template <
typename ArrayHandleType,
typename... SwizzleIndexTypes>
246 SwizzleIndexTypes... swizzleIndices)
261 template <
typename InType,
typename OutType>
262 struct SerializableTypeString<
viskores::internal::SwizzleFunctor<InType, OutType>>
272 template <
typename AH, viskores::IdComponent NComps>
273 struct SerializableTypeString<
viskores::cont::ArrayHandleSwizzle<AH, NComps>>
274 : SerializableTypeString<typename viskores::cont::ArrayHandleSwizzle<AH, NComps>::Superclass>
283 template <
typename AH, viskores::IdComponent NComps>
284 struct Serialization<
viskores::cont::ArrayHandleSwizzle<AH, NComps>>
285 : Serialization<typename viskores::cont::ArrayHandleSwizzle<AH, NComps>::Superclass>
292 #endif // viskores_cont_ArrayHandleSwizzle_h