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_PointAverage_hxx
12 #define vtk_m_filter_PointAverage_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 //-----------------------------------------------------------------------------
23 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)24 vtkm::cont::DataSet PointAverage::DoExecute(const vtkm::cont::DataSet& input,
25                                             const vtkm::cont::ArrayHandle<T, StorageType>& inField,
26                                             const vtkm::filter::FieldMetadata& fieldMetadata,
27                                             vtkm::filter::PolicyBase<DerivedPolicy> policy)
28 {
29   if (!fieldMetadata.IsCellField())
30   {
31     throw vtkm::cont::ErrorFilterExecution("Cell field expected.");
32   }
33 
34   vtkm::cont::DynamicCellSet cellSet = input.GetCellSet();
35 
36   //todo: we need to ask the policy what storage type we should be using
37   //If the input is implicit, we should know what to fall back to
38   vtkm::cont::ArrayHandle<T> outArray;
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 CreateResultFieldPoint(input, outArray, outputName);
50 }
51 }
52 } // namespace vtkm::filter
53 #endif
54