VTK-m  2.2
BoundaryState.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_exec_BoundaryState_h
11 #define vtk_m_exec_BoundaryState_h
12 
13 #include <vtkm/Assert.h>
14 #include <vtkm/Math.h>
15 
16 namespace vtkm
17 {
18 namespace exec
19 {
20 
32 {
33  VTKM_EXEC
34  BoundaryState(const vtkm::Id3& ijk, const vtkm::Id3& pdims)
35  : IJK(ijk)
36  , PointDimensions(pdims)
37  {
38  }
39 
43  VTKM_EXEC const vtkm::Id3& GetCenterIndex() const { return this->IJK; }
44 
55  {
56  VTKM_ASSERT(radius >= 0);
57  return (((this->IJK[0] - radius) >= 0) && ((this->IJK[0] + radius) < this->PointDimensions[0]));
58  }
61  {
62  VTKM_ASSERT(radius >= 0);
63  return (((this->IJK[1] - radius) >= 0) && ((this->IJK[1] + radius) < this->PointDimensions[1]));
64  }
67  {
68  VTKM_ASSERT(radius >= 0);
69  return (((this->IJK[2] - radius) >= 0) && ((this->IJK[2] + radius) < this->PointDimensions[2]));
70  }
71 
82  {
83  return this->IsRadiusInXBoundary(radius) && this->IsRadiusInYBoundary(radius) &&
84  this->IsRadiusInZBoundary(radius);
85  }
86 
93  {
94  return (((this->IJK[0] + offset) >= 0) && ((this->IJK[0] + offset) < this->PointDimensions[0]));
95  }
98  {
99  return (((this->IJK[1] + offset) >= 0) && ((this->IJK[1] + offset) < this->PointDimensions[1]));
100  }
103  {
104  return (((this->IJK[2] + offset) >= 0) && ((this->IJK[2] + offset) < this->PointDimensions[2]));
105  }
106 
112  {
113  return this->IsNeighborInXBoundary(neighbor[0]) && this->IsNeighborInYBoundary(neighbor[1]) &&
114  this->IsNeighborInZBoundary(neighbor[2]);
115  }
116 
128  {
129  VTKM_ASSERT(radius >= 0);
130  vtkm::IdComponent3 minIndices;
131 
132  for (vtkm::IdComponent component = 0; component < 3; ++component)
133  {
134  if (this->IJK[component] >= radius)
135  {
136  minIndices[component] = -radius;
137  }
138  else
139  {
140  minIndices[component] = static_cast<vtkm::IdComponent>(-this->IJK[component]);
141  }
142  }
143 
144  return minIndices;
145  }
146 
159  {
160  VTKM_ASSERT(radius >= 0);
161  vtkm::IdComponent3 maxIndices;
162 
163  for (vtkm::IdComponent component = 0; component < 3; ++component)
164  {
165  if ((this->PointDimensions[component] - this->IJK[component] - 1) >= radius)
166  {
167  maxIndices[component] = radius;
168  }
169  else
170  {
171  maxIndices[component] = static_cast<vtkm::IdComponent>(this->PointDimensions[component] -
172  this->IJK[component] - 1);
173  }
174  }
175 
176  return maxIndices;
177  }
178 
186  {
187  vtkm::Id3 fullIndex = this->IJK + neighbor;
188 
189  return vtkm::Max(vtkm::Id3(0), vtkm::Min(this->PointDimensions - vtkm::Id3(1), fullIndex));
190  }
191 
194  vtkm::IdComponent neighborJ,
195  vtkm::IdComponent neighborK) const
196  {
197  return this->NeighborIndexToFullIndexClamp(vtkm::make_Vec(neighborI, neighborJ, neighborK));
198  }
199 
205  {
206  return this->IJK + neighbor;
207  }
208 
211  vtkm::IdComponent neighborJ,
212  vtkm::IdComponent neighborK) const
213  {
214  return this->NeighborIndexToFullIndex(vtkm::make_Vec(neighborI, neighborJ, neighborK));
215  }
216 
224  {
225  const vtkm::Id3 fullIndex = this->IJK + neighbor;
226  const vtkm::Id3 clampedFullIndex =
227  vtkm::Max(vtkm::Id3(0), vtkm::Min(this->PointDimensions - vtkm::Id3(1), fullIndex));
228  return vtkm::IdComponent3{ clampedFullIndex - this->IJK };
229  }
230 
233  vtkm::IdComponent neighborJ,
234  vtkm::IdComponent neighborK) const
235  {
236  return this->ClampNeighborIndex(vtkm::make_Vec(neighborI, neighborJ, neighborK));
237  }
238 
246  {
247  vtkm::Id3 full = this->NeighborIndexToFullIndexClamp(neighbor);
248 
249  return (full[2] * this->PointDimensions[1] + full[1]) * this->PointDimensions[0] + full[0];
250  }
251 
254  vtkm::IdComponent neighborJ,
255  vtkm::IdComponent neighborK) const
256  {
257  return this->NeighborIndexToFlatIndexClamp(vtkm::make_Vec(neighborI, neighborJ, neighborK));
258  }
259 
265  {
266  vtkm::Id3 full = this->IJK + neighbor;
267  return (full[2] * this->PointDimensions[1] + full[1]) * this->PointDimensions[0] + full[0];
268  }
269 
272  vtkm::IdComponent neighborJ,
273  vtkm::IdComponent neighborK) const
274  {
275  return this->NeighborIndexToFlatIndex(vtkm::make_Vec(neighborI, neighborJ, neighborK));
276  }
277 
280 
283 };
284 }
285 } // namespace vtkm::exec
286 
287 #endif //vtk_m_exec_BoundaryState_h
vtkm::exec::BoundaryState::NeighborIndexToFullIndex
vtkm::Id3 NeighborIndexToFullIndex(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:210
vtkm::exec::BoundaryState
Provides a neighborhood's placement with respect to the mesh's boundary.
Definition: BoundaryState.h:31
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::IdComponent3 MaxNeighborIndices(vtkm::IdComponent radius) const
Returns the minimum neighborhood indices that are within the bounds of the data.
Definition: BoundaryState.h:158
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::make_Vec
constexpr vtkm::Vec< T, vtkm::IdComponent(sizeof...(Ts)+1)> make_Vec(T value0, Ts &&... args)
Initializes and returns a Vec containing all the arguments.
Definition: Types.h:1253
vtkm::exec::BoundaryState::ClampNeighborIndex
vtkm::IdComponent3 ClampNeighborIndex(const vtkm::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size),...
Definition: BoundaryState.h:223
vtkm::exec::BoundaryState::NeighborIndexToFullIndexClamp
vtkm::Id3 NeighborIndexToFullIndexClamp(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:193
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::exec::BoundaryState::IsNeighborInXBoundary
bool IsNeighborInXBoundary(vtkm::IdComponent offset) const
Returns true if the neighbor at the specified offset is contained within the bounds of the cell set i...
Definition: BoundaryState.h:92
vtkm::exec::BoundaryState::GetCenterIndex
const vtkm::Id3 & GetCenterIndex() const
Returns the center index of the neighborhood.
Definition: BoundaryState.h:43
vtkm::exec::BoundaryState::IsRadiusInBoundary
bool IsRadiusInBoundary(vtkm::IdComponent radius) const
Returns true if a neighborhood of the given radius is contained within the bounds of the cell set.
Definition: BoundaryState.h:81
vtkm::exec::BoundaryState::ClampNeighborIndex
vtkm::IdComponent3 ClampNeighborIndex(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size),...
Definition: BoundaryState.h:232
vtkm::exec::BoundaryState::IJK
vtkm::Id3 IJK
The 3D index of the visited element.
Definition: BoundaryState.h:279
Assert.h
vtkm::exec::BoundaryState::IsRadiusInZBoundary
bool IsRadiusInZBoundary(vtkm::IdComponent radius) const
Returns true if a neighborhood of the given radius is contained within the bounds of the cell set in ...
Definition: BoundaryState.h:66
vtkm::exec::BoundaryState::IsRadiusInXBoundary
bool IsRadiusInXBoundary(vtkm::IdComponent radius) const
Returns true if a neighborhood of the given radius is contained within the bounds of the cell set in ...
Definition: BoundaryState.h:54
vtkm::exec::BoundaryState::NeighborIndexToFlatIndex
vtkm::Id NeighborIndexToFlatIndex(const vtkm::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:264
vtkm::exec::BoundaryState::IsNeighborInYBoundary
bool IsNeighborInYBoundary(vtkm::IdComponent offset) const
Returns true if the neighbor at the specified offset is contained within the bounds of the cell set i...
Definition: BoundaryState.h:97
Math.h
vtkm::exec::BoundaryState::NeighborIndexToFlatIndex
vtkm::Id NeighborIndexToFlatIndex(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:271
vtkm::exec::BoundaryState::IsNeighborInBoundary
bool IsNeighborInBoundary(const vtkm::IdComponent3 &neighbor) const
Returns true if the neighbor at the specified offset vector is contained within the bounds of the cel...
Definition: BoundaryState.h:111
vtkm::exec::BoundaryState::IsNeighborInZBoundary
bool IsNeighborInZBoundary(vtkm::IdComponent offset) const
Returns true if the neighbor at the specified offset is contained within the bounds of the cell set i...
Definition: BoundaryState.h:102
vtkm::exec::BoundaryState::MinNeighborIndices
vtkm::IdComponent3 MinNeighborIndices(vtkm::IdComponent radius) const
Returns the minimum neighborhood indices that are within the bounds of the data.
Definition: BoundaryState.h:127
vtkm::exec::BoundaryState::IsRadiusInYBoundary
bool IsRadiusInYBoundary(vtkm::IdComponent radius) const
Returns true if a neighborhood of the given radius is contained within the bounds of the cell set in ...
Definition: BoundaryState.h:60
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::exec::BoundaryState::PointDimensions
vtkm::Id3 PointDimensions
The dimensions of the elements in the mesh.
Definition: BoundaryState.h:282
vtkm::exec::BoundaryState::NeighborIndexToFlatIndexClamp
vtkm::Id NeighborIndexToFlatIndexClamp(const vtkm::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:245
vtkm::Vec< vtkm::Id, 3 >
vtkm::exec::BoundaryState::NeighborIndexToFullIndex
vtkm::Id3 NeighborIndexToFullIndex(const vtkm::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:204
vtkm::exec::BoundaryState::BoundaryState
BoundaryState(const vtkm::Id3 &ijk, const vtkm::Id3 &pdims)
Definition: BoundaryState.h:34
vtkm::exec::BoundaryState::NeighborIndexToFullIndexClamp
vtkm::Id3 NeighborIndexToFullIndexClamp(const vtkm::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:185
vtkm::exec::BoundaryState::NeighborIndexToFlatIndexClamp
vtkm::Id NeighborIndexToFlatIndexClamp(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:253