//============================================================================ // 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. //============================================================================ #include #include #include #include #include #include #include namespace { struct UnmaskedIndicesTransform { VTKM_EXEC vtkm::Id2 operator()(vtkm::Pair in) const { if (in.first == 0) { return { std::numeric_limits::max(), std::numeric_limits::min() }; } return { in.second }; } }; } // namespace vtkm::Id2 vtkm::cont::internal::GetFirstAndLastUnmaskedIndices( const vtkm::cont::ArrayHandle& maskArray, vtkm::cont::DeviceAdapterId device) { vtkm::Id2 initialValue = { std::numeric_limits::max(), std::numeric_limits::min() }; auto maskValsAndInds = vtkm::cont::make_ArrayHandleZip( maskArray, vtkm::cont::ArrayHandleIndex(maskArray.GetNumberOfValues())); auto unmaskedIndices = vtkm::cont::make_ArrayHandleTransform(maskValsAndInds, UnmaskedIndicesTransform{}); return vtkm::cont::Algorithm::Reduce( device, unmaskedIndices, initialValue, vtkm::MinAndMax()); }