//============================================================================ // 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 namespace vtkm { namespace cont { //----------------------------------------------------------------------------- VTKM_CONT vtkm::cont::ArrayHandle FieldRangeCompute(const vtkm::cont::DataSet& dataset, const std::string& name, vtkm::cont::Field::Association assoc) { vtkm::cont::Field field; try { field = dataset.GetField(name, assoc); } catch (vtkm::cont::ErrorBadValue&) { // field missing, return empty range. return vtkm::cont::ArrayHandle(); } return field.GetRange(); } //----------------------------------------------------------------------------- VTKM_CONT vtkm::cont::ArrayHandle FieldRangeCompute(const vtkm::cont::PartitionedDataSet& pds, const std::string& name, vtkm::cont::Field::Association assoc) { std::vector result_vector = std::accumulate( pds.begin(), pds.end(), std::vector(), [&](const std::vector& accumulated_value, const vtkm::cont::DataSet& dataset) { vtkm::cont::ArrayHandle partition_range = vtkm::cont::FieldRangeCompute(dataset, name, assoc); std::vector result = accumulated_value; // if the current partition has more components than we have seen so far, // resize the result to fit all components. result.resize( std::max(result.size(), static_cast(partition_range.GetNumberOfValues()))); auto portal = partition_range.ReadPortal(); std::transform(vtkm::cont::ArrayPortalToIteratorBegin(portal), vtkm::cont::ArrayPortalToIteratorEnd(portal), result.begin(), result.begin(), std::plus()); return result; }); return vtkm::cont::make_ArrayHandleMove(std::move(result_vector)); } } } // namespace vtkm::cont