//============================================================================= // // 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. // // Copyright 2012 Sandia Corporation. // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // the U.S. Government retains certain rights in this software. // //============================================================================= #ifndef vtkmlib_Portals_hxx #define vtkmlib_Portals_hxx #include "vtkDataArray.h" #include "vtkPoints.h" #include #include #include #include namespace { template struct fillComponents { template void operator()(T* t, const Tuple& tuple) const { fillComponents()(t, tuple); t[N - 1] = vtkm::VecTraits::GetComponent(tuple, N - 1); } }; template <> struct fillComponents<1> { template void operator()(T* t, const Tuple& tuple) const { t[0] = vtkm::VecTraits::GetComponent(tuple, 0); } }; } namespace tovtkm { //------------------------------------------------------------------------------ template vtkArrayPortal::vtkArrayPortal() : VTKData(nullptr), Size(0) { } //------------------------------------------------------------------------------ template vtkArrayPortal::vtkArrayPortal(VTKDataArrayType* array, vtkm::Id size) : VTKData(array), Size(size) { VTKM_ASSERT(this->GetNumberOfValues() >= 0); } //------------------------------------------------------------------------------ template typename vtkArrayPortal::ValueType vtkArrayPortal::Get(vtkm::Id index) const { VTKM_ASSUME(this->VTKData->GetNumberOfComponents() == NUM_COMPONENTS); ValueType tuple; for (int j = 0; j < NUM_COMPONENTS; ++j) { ComponentType temp = this->VTKData->GetTypedComponent(index, j); vtkPortalTraits::SetComponent(tuple, j, temp); } return tuple; } //------------------------------------------------------------------------------ template void vtkArrayPortal::Set(vtkm::Id index, const ValueType& value) const { VTKM_ASSUME((this->VTKData->GetNumberOfComponents() == NUM_COMPONENTS)); for (int j = 0; j < NUM_COMPONENTS; ++j) { ComponentType temp = vtkPortalTraits::GetComponent(value, j); this->VTKData->SetTypedComponent(index, j, temp); } } //------------------------------------------------------------------------------ template vtkPointsPortal::vtkPointsPortal() : Points(nullptr), Array(nullptr), Size(0) { } //------------------------------------------------------------------------------ template vtkPointsPortal::vtkPointsPortal(vtkPoints* points, vtkm::Id size) : Points(points), Array(static_cast(points->GetVoidPointer(0))), Size(size) { VTKM_ASSERT(this->GetNumberOfValues() >= 0); } //------------------------------------------------------------------------------ /// Copy constructor for any other vtkArrayPortal with an iterator /// type that can be copied to this iterator type. This allows us to do any /// type casting that the iterators do (like the non-const to const cast). /// template template vtkPointsPortal::vtkPointsPortal(const vtkPointsPortal& src) : Points(src.GetVtkData()), Array(static_cast(src.GetVtkData()->GetVoidPointer(0))), Size(src.GetNumberOfValues()) { } //------------------------------------------------------------------------------ template typename vtkPointsPortal::ValueType vtkPointsPortal::Get(vtkm::Id index) const { const ComponentType* const raw = this->Array + (index * NUM_COMPONENTS); return ValueType(raw[0], raw[1], raw[2]); } //------------------------------------------------------------------------------ template void vtkPointsPortal::Set(vtkm::Id index, const ValueType& value) const { ComponentType* rawArray = this->Array + (index * NUM_COMPONENTS); // use template magic to auto unroll insertion fillComponents()(rawArray, value); } } #endif // vtkmlib_Portals_hxx