//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ #ifndef vtk_m_VecFromPortalPermute_h #define vtk_m_VecFromPortalPermute_h #include #include #include #include namespace vtkm { /// \brief A short vector from an ArrayPortal and a vector of indices. /// /// The \c VecFromPortalPermute class is a Vec-like class that holds an array /// portal and a second Vec-like containing indices into the array. Each value /// of this vector is the value from the array with the respective index. /// template class VecFromPortalPermute { public: using ComponentType = typename std::remove_const::type; VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortalPermute() {} VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortalPermute(const IndexVecType* indices, const PortalType& portal) : Indices(indices) , Portal(portal) { } VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const { return this->Indices->GetNumberOfComponents(); } VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT void CopyInto(vtkm::Vec& dest) const { vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents()); for (vtkm::IdComponent index = 0; index < numComponents; index++) { dest[index] = (*this)[index]; } } VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT ComponentType operator[](vtkm::IdComponent index) const { return this->Portal.Get((*this->Indices)[index]); } private: const IndexVecType* const Indices; PortalType Portal; }; template class VecFromPortalPermute { public: using ComponentType = typename std::remove_const::type; VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortalPermute() {} VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortalPermute(const IndexVecType* indices, const PortalType* const portal) : Indices(indices) , Portal(portal) { } VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const { return this->Indices->GetNumberOfComponents(); } VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT void CopyInto(vtkm::Vec& dest) const { vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents()); for (vtkm::IdComponent index = 0; index < numComponents; index++) { dest[index] = (*this)[index]; } } VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT ComponentType operator[](vtkm::IdComponent index) const { return this->Portal->Get((*this->Indices)[index]); } private: const IndexVecType* const Indices; const PortalType* const Portal; }; template struct TypeTraits> { private: using VecType = vtkm::VecFromPortalPermute; using ComponentType = typename PortalType::ValueType; public: using NumericTag = typename vtkm::TypeTraits::NumericTag; using DimensionalityTag = TypeTraitsVectorTag; VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT static VecType ZeroInitialization() { return VecType(); } }; template struct VecTraits> { using VecType = vtkm::VecFromPortalPermute; using ComponentType = typename VecType::ComponentType; using BaseComponentType = typename vtkm::VecTraits::BaseComponentType; using HasMultipleComponents = vtkm::VecTraitsTagMultipleComponents; using IsSizeStatic = vtkm::VecTraitsTagSizeVariable; VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT static vtkm::IdComponent GetNumberOfComponents(const VecType& vector) { return vector.GetNumberOfComponents(); } VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT static ComponentType GetComponent(const VecType& vector, vtkm::IdComponent componentIndex) { return vector[componentIndex]; } VTKM_SUPPRESS_EXEC_WARNINGS template VTKM_EXEC_CONT static void CopyInto(const VecType& src, vtkm::Vec& dest) { src.CopyInto(dest); } }; template inline VTKM_EXEC VecFromPortalPermute make_VecFromPortalPermute( const IndexVecType* index, const PortalType& portal) { return VecFromPortalPermute(index, portal); } template inline VTKM_EXEC VecFromPortalPermute make_VecFromPortalPermute( const IndexVecType* index, const PortalType* const portal) { return VecFromPortalPermute(index, portal); } } // namespace vtkm #endif //vtk_m_VecFromPortalPermute_h