VTK-m  2.0
AveragePointNeighborhood.h
Go to the documentation of this file.
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 #ifndef vtk_m_worklet_AveragePointNeighborhood_h
11 #define vtk_m_worklet_AveragePointNeighborhood_h
12 
13 #include <vtkm/VecTraits.h>
14 
15 #include <vtkm/cont/ArrayHandle.h>
17 
19 
20 namespace vtkm
21 {
22 namespace worklet
23 {
24 
26 {
27 public:
28  using ControlSignature = void(CellSetIn cellSet,
29  FieldInNeighborhood inputField,
30  FieldOut outputField);
31  using ExecutionSignature = _3(_2, Boundary);
32  using InputDomain = _1;
33 
35  {
36  VTKM_ASSERT(radius > 0);
37  this->BoundaryRadius = radius;
38  }
39 
40  template <typename InputFieldPortalType>
41  VTKM_EXEC typename InputFieldPortalType::ValueType operator()(
43  const vtkm::exec::BoundaryState& boundary) const
44  {
45  using T = typename InputFieldPortalType::ValueType;
46 
47  auto minIndices = boundary.MinNeighborIndices(this->BoundaryRadius);
48  auto maxIndices = boundary.MaxNeighborIndices(this->BoundaryRadius);
49 
50  T sum(0);
51  vtkm::IdComponent size = 0;
52  for (vtkm::IdComponent i = minIndices[0]; i <= maxIndices[0]; i++)
53  {
54  for (vtkm::IdComponent j = minIndices[1]; j <= maxIndices[1]; j++)
55  {
56  for (vtkm::IdComponent k = minIndices[2]; k <= maxIndices[2]; k++)
57  {
58  sum = sum + inputField.Get(i, j, k);
59  size++;
60  }
61  }
62  }
63  return static_cast<T>(sum / size);
64  }
65 
66 private:
68 };
69 
70 } // vtkm::worklet
71 } // vtkm
72 
73 #endif // vtk_m_worklet_AveragePointNeighborhood_h
vtkm::worklet::AveragePointNeighborhood::AveragePointNeighborhood
AveragePointNeighborhood(vtkm::IdComponent radius)
Definition: AveragePointNeighborhood.h:34
vtkm::exec::BoundaryState
Provides a neighborhood's placement with respect to the mesh's boundary.
Definition: BoundaryState.h:31
ArrayHandle.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::exec::BoundaryState::MaxNeighborIndices
VTKM_EXEC vtkm::IdComponent3 MaxNeighborIndices(vtkm::IdComponent radius) const
Returns the minimum neighborhood indices that are within the bounds of the data.
Definition: BoundaryState.h:136
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::worklet::WorkletNeighborhood::CellSetIn
A control signature tag for input connectivity.
Definition: WorkletNeighborhood.h:110
vtkm::worklet::WorkletNeighborhood::FieldOut
A control signature tag for output point fields.
Definition: WorkletNeighborhood.h:89
WorkletPointNeighborhood.h
DeviceAdapterAlgorithm.h
vtkm::exec::FieldNeighborhood::Get
VTKM_EXEC ValueType Get(vtkm::IdComponent i, vtkm::IdComponent j, vtkm::IdComponent k) const
Definition: FieldNeighborhood.h:48
vtkm::worklet::AveragePointNeighborhood::BoundaryRadius
vtkm::IdComponent BoundaryRadius
Definition: AveragePointNeighborhood.h:67
vtkm::worklet::AveragePointNeighborhood::ExecutionSignature
_3(_2, Boundary) ExecutionSignature
Definition: AveragePointNeighborhood.h:31
vtkm::worklet::AveragePointNeighborhood
Definition: AveragePointNeighborhood.h:25
vtkm::worklet::AveragePointNeighborhood::InputDomain
_1 InputDomain
Definition: AveragePointNeighborhood.h:32
vtkm::worklet::AveragePointNeighborhood::ControlSignature
void(CellSetIn cellSet, FieldInNeighborhood inputField, FieldOut outputField) ControlSignature
Definition: AveragePointNeighborhood.h:30
vtkm::worklet::WorkletNeighborhood::Boundary
The ExecutionSignature tag to query if the current iteration is inside the boundary.
Definition: WorkletNeighborhood.h:54
vtkm::exec::BoundaryState::MinNeighborIndices
VTKM_EXEC vtkm::IdComponent3 MinNeighborIndices(vtkm::IdComponent radius) const
Returns the minimum neighborhood indices that are within the bounds of the data.
Definition: BoundaryState.h:114
vtkm::worklet::WorkletNeighborhood::FieldInNeighborhood
A control signature tag for neighborhood input values.
Definition: WorkletNeighborhood.h:129
vtkm::worklet::WorkletPointNeighborhood
Definition: WorkletPointNeighborhood.h:27
vtkm::exec::FieldNeighborhood
Retrieves field values from a neighborhood.
Definition: FieldNeighborhood.h:36
VecTraits.h
vtkm::worklet::AveragePointNeighborhood::operator()
VTKM_EXEC InputFieldPortalType::ValueType operator()(const vtkm::exec::FieldNeighborhood< InputFieldPortalType > &inputField, const vtkm::exec::BoundaryState &boundary) const
Definition: AveragePointNeighborhood.h:41