//============================================================================ // 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_VecFromPortal_h #define vtk_m_VecFromPortal_h #include #include #include #include #include namespace vtkm { /// \brief A short variable-length array from a window in an ArrayPortal. /// /// The \c VecFromPortal class is a Vec-like class that holds an array portal /// and exposes a small window of that portal as if it were a \c Vec. /// template class VecFromPortal { public: using ComponentType = typename std::remove_const::type; VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortal() : NumComponents(0) , Offset(0) { } VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortal(const PortalType& portal, vtkm::IdComponent numComponents = 0, vtkm::Id offset = 0) : Portal(portal) , NumComponents(numComponents) , Offset(offset) { } VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const { return this->NumComponents; } template VTKM_EXEC_CONT void CopyInto(vtkm::Vec& dest) const { vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->NumComponents); for (vtkm::IdComponent index = 0; index < numComponents; index++) { dest[index] = this->Portal.Get(index + this->Offset); } } VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT vtkm::internal::ArrayPortalValueReference operator[](vtkm::IdComponent index) const { return vtkm::internal::ArrayPortalValueReference(this->Portal, index + this->Offset); } private: PortalType Portal; vtkm::IdComponent NumComponents; vtkm::Id Offset; }; template struct TypeTraits> { private: using ComponentType = typename PortalType::ValueType; public: using NumericTag = typename vtkm::TypeTraits::NumericTag; using DimensionalityTag = TypeTraitsVectorTag; VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT static vtkm::VecFromPortal ZeroInitialization() { return vtkm::VecFromPortal(); } }; template struct VecTraits> { using VecType = vtkm::VecFromPortal; 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); } }; } // namespace vtkm #endif //vtk_m_VecFromPortal_h