Viskores  1.0
AveragePointNeighborhood.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_worklet_AveragePointNeighborhood_h
19 #define viskores_worklet_AveragePointNeighborhood_h
20 
21 #include <viskores/VecTraits.h>
22 
25 
27 
28 namespace viskores
29 {
30 namespace worklet
31 {
32 
34 {
35 public:
36  using ControlSignature = void(CellSetIn cellSet,
37  FieldInNeighborhood inputField,
38  FieldOut outputField);
39  using ExecutionSignature = _3(_2, Boundary);
40  using InputDomain = _1;
41 
43  {
44  VISKORES_ASSERT(radius > 0);
45  this->BoundaryRadius = radius;
46  }
47 
48  template <typename InputFieldPortalType>
49  VISKORES_EXEC typename InputFieldPortalType::ValueType operator()(
51  const viskores::exec::BoundaryState& boundary) const
52  {
53  using T = typename InputFieldPortalType::ValueType;
54 
55  auto minIndices = boundary.MinNeighborIndices(this->BoundaryRadius);
56  auto maxIndices = boundary.MaxNeighborIndices(this->BoundaryRadius);
57 
58  T sum(0);
59  viskores::IdComponent size = 0;
60  for (viskores::IdComponent i = minIndices[0]; i <= maxIndices[0]; i++)
61  {
62  for (viskores::IdComponent j = minIndices[1]; j <= maxIndices[1]; j++)
63  {
64  for (viskores::IdComponent k = minIndices[2]; k <= maxIndices[2]; k++)
65  {
66  sum = sum + inputField.Get(i, j, k);
67  size++;
68  }
69  }
70  }
71  return static_cast<T>(sum / size);
72  }
73 
74 private:
76 };
77 
78 } // viskores::worklet
79 } // viskores
80 
81 #endif // viskores_worklet_AveragePointNeighborhood_h
viskores::worklet::WorkletNeighborhood::FieldOut
A control signature tag for output fields.
Definition: WorkletNeighborhood.h:106
ArrayHandle.h
viskores::worklet::AveragePointNeighborhood::AveragePointNeighborhood
AveragePointNeighborhood(viskores::IdComponent radius)
Definition: AveragePointNeighborhood.h:42
viskores::exec::BoundaryState::MaxNeighborIndices
viskores::IdComponent3 MaxNeighborIndices(viskores::IdComponent radius) const
Returns the minimum neighborhood indices that are within the bounds of the data.
Definition: BoundaryState.h:166
viskores::worklet::WorkletPointNeighborhood
Base class for worklets that map over the points in a structured grid with neighborhood information.
Definition: WorkletPointNeighborhood.h:40
WorkletPointNeighborhood.h
viskores::exec::BoundaryState
Provides a neighborhood's placement with respect to the mesh's boundary.
Definition: BoundaryState.h:39
viskores::worklet::WorkletNeighborhood::Boundary
The ExecutionSignature tag to query if the current iteration is inside the boundary.
Definition: WorkletNeighborhood.h:62
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::worklet::AveragePointNeighborhood::BoundaryRadius
viskores::IdComponent BoundaryRadius
Definition: AveragePointNeighborhood.h:75
viskores::exec::BoundaryState::MinNeighborIndices
viskores::IdComponent3 MinNeighborIndices(viskores::IdComponent radius) const
Returns the minimum neighborhood indices that are within the bounds of the data.
Definition: BoundaryState.h:135
DeviceAdapterAlgorithm.h
viskores::worklet::AveragePointNeighborhood::ControlSignature
void(CellSetIn cellSet, FieldInNeighborhood inputField, FieldOut outputField) ControlSignature
Definition: AveragePointNeighborhood.h:38
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::worklet::AveragePointNeighborhood::InputDomain
_1 InputDomain
Definition: AveragePointNeighborhood.h:40
viskores::exec::FieldNeighborhood
Retrieves field values from a neighborhood.
Definition: FieldNeighborhood.h:42
VISKORES_ASSERT
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
viskores::worklet::AveragePointNeighborhood::operator()
InputFieldPortalType::ValueType operator()(const viskores::exec::FieldNeighborhood< InputFieldPortalType > &inputField, const viskores::exec::BoundaryState &boundary) const
Definition: AveragePointNeighborhood.h:49
viskores::exec::FieldNeighborhood::Get
ValueType Get(viskores::IdComponent i, viskores::IdComponent j, viskores::IdComponent k) const
Retrieve a field value relative to the visited element.
Definition: FieldNeighborhood.h:69
viskores::worklet::AveragePointNeighborhood
Definition: AveragePointNeighborhood.h:33
viskores::worklet::WorkletNeighborhood::FieldInNeighborhood
A control signature tag for neighborhood input values.
Definition: WorkletNeighborhood.h:165
viskores::worklet::AveragePointNeighborhood::ExecutionSignature
_3(_2, Boundary) ExecutionSignature
Definition: AveragePointNeighborhood.h:39
viskores::worklet::WorkletNeighborhood::CellSetIn
A control signature tag for input connectivity.
Definition: WorkletNeighborhood.h:137
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59
VecTraits.h