1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10
11 #ifndef vtk_m_filter_CellAverage_hxx
12 #define vtk_m_filter_CellAverage_hxx
13
14 #include <vtkm/cont/DynamicCellSet.h>
15 #include <vtkm/cont/ErrorFilterExecution.h>
16
17 namespace vtkm
18 {
19 namespace filter
20 {
21 //-----------------------------------------------------------------------------
22 template <typename T, typename StorageType, typename DerivedPolicy>
DoExecute(const vtkm::cont::DataSet & input,const vtkm::cont::ArrayHandle<T,StorageType> & inField,const vtkm::filter::FieldMetadata & fieldMetadata,vtkm::filter::PolicyBase<DerivedPolicy> policy)23 vtkm::cont::DataSet CellAverage::DoExecute(const vtkm::cont::DataSet& input,
24 const vtkm::cont::ArrayHandle<T, StorageType>& inField,
25 const vtkm::filter::FieldMetadata& fieldMetadata,
26 vtkm::filter::PolicyBase<DerivedPolicy> policy)
27 {
28 if (!fieldMetadata.IsPointField())
29 {
30 throw vtkm::cont::ErrorFilterExecution("Point field expected.");
31 }
32
33 vtkm::cont::DynamicCellSet cellSet = input.GetCellSet();
34
35 //todo: we need to ask the policy what storage type we should be using
36 //If the input is implicit, we should know what to fall back to
37 vtkm::cont::ArrayHandle<T> outArray;
38
39 this->Invoke(
40 this->Worklet, vtkm::filter::ApplyPolicyCellSet(cellSet, policy, *this), inField, outArray);
41
42 std::string outputName = this->GetOutputFieldName();
43 if (outputName.empty())
44 {
45 // Default name is name of input.
46 outputName = fieldMetadata.GetName();
47 }
48
49 return CreateResultFieldCell(input, outArray, outputName);
50 }
51 }
52 } // namespace vtkm::filter
53
54 #endif
55