vtk-m/vtkm/filter/image_processing/ComputeMoments.cxx
Kenneth Moreland 4064a3bd06 Allow ComputeMoments to operate on any scalar field
Previously, the `ComputeMoments` filter only operated on a finite set of
array types as its input field. This included a prescribed list of `Vec`
sizes for the input. The filter has been updated to use more generic
interfaces to the field's array (and float fallback) to enable the
computation of moments on any type of scalar field.
2023-06-05 08:44:03 -04:00

52 lines
1.6 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.
//
//=============================================================================
#ifndef vtk_m_filter_ComputeMoments_hxx
#define vtk_m_filter_ComputeMoments_hxx
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/filter/image_processing/ComputeMoments.h>
#include <vtkm/filter/image_processing/worklet/ComputeMoments.h>
namespace vtkm
{
namespace filter
{
namespace image_processing
{
VTKM_CONT ComputeMoments::ComputeMoments()
{
this->SetOutputFieldName("moments_");
}
VTKM_CONT vtkm::cont::DataSet ComputeMoments::DoExecute(const vtkm::cont::DataSet& input)
{
const auto& field = this->GetFieldFromDataSet(input);
if (!field.IsPointField())
{
throw vtkm::cont::ErrorBadValue("Active field for ComputeMoments must be a point field.");
}
vtkm::cont::DataSet output = this->CreateResult(input);
auto worklet = vtkm::worklet::moments::ComputeMoments(this->Radius, this->Spacing);
auto resolveType = [&](const auto& concrete) {
worklet.Run(input.GetCellSet(), concrete, this->Order, output);
};
this->CastAndCallVariableVecField(field, resolveType);
return output;
}
} // namespace image_processing
} // namespace filter
} // namespace vtkm
#endif //vtk_m_filter_ComputeMoments_hxx