mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
//============================================================================
|
|
// 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 <vtkm/cont/ErrorFilterExecution.h>
|
|
#include <vtkm/cont/UnknownCellSet.h>
|
|
#include <vtkm/filter/field_conversion/CellAverage.h>
|
|
#include <vtkm/filter/field_conversion/worklet/CellAverage.h>
|
|
|
|
namespace vtkm
|
|
{
|
|
namespace filter
|
|
{
|
|
namespace field_conversion
|
|
{
|
|
//-----------------------------------------------------------------------------
|
|
vtkm::cont::DataSet CellAverage::DoExecute(const vtkm::cont::DataSet& input)
|
|
{
|
|
auto field = GetFieldFromDataSet(input);
|
|
if (!field.IsFieldPoint())
|
|
{
|
|
throw vtkm::cont::ErrorFilterExecution("Point field expected.");
|
|
}
|
|
|
|
vtkm::cont::UnknownCellSet inputCellSet = input.GetCellSet();
|
|
vtkm::cont::UnknownArrayHandle outArray;
|
|
|
|
auto resolveType = [&, this](const auto& concrete) {
|
|
using T = typename std::decay_t<decltype(concrete)>::ValueType;
|
|
vtkm::cont::ArrayHandle<T> result;
|
|
this->Invoke(vtkm::worklet::CellAverage{}, inputCellSet, concrete, result);
|
|
outArray = result;
|
|
};
|
|
field.GetData()
|
|
.CastAndCallForTypesWithFloatFallback<vtkm::TypeListField, VTKM_DEFAULT_STORAGE_LIST>(
|
|
resolveType);
|
|
|
|
std::string outputName = this->GetOutputFieldName();
|
|
if (outputName.empty())
|
|
{
|
|
// Default name is name of input.
|
|
outputName = field.GetName();
|
|
}
|
|
return this->CreateResultFieldCell(input, outputName, outArray);
|
|
}
|
|
} // namespace field_conversion
|
|
} // namespace filter
|
|
} // namespace vtkm
|