VTK-m  2.0
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 
51  {
52  VTKM_ASSERT(radius >= 0);
53  return (((this->IJK[0] - radius) >= 0) && ((this->IJK[0] + radius) < this->PointDimensions[0]));
54  }
56  {
57  VTKM_ASSERT(radius >= 0);
58  return (((this->IJK[1] - radius) >= 0) && ((this->IJK[1] + radius) < this->PointDimensions[1]));
59  }
61  {
62  VTKM_ASSERT(radius >= 0);
63  return (((this->IJK[2] - radius) >= 0) && ((this->IJK[2] + radius) < this->PointDimensions[2]));
64  }
66 
77  {
78  return this->IsRadiusInXBoundary(radius) && this->IsRadiusInYBoundary(radius) &&
79  this->IsRadiusInZBoundary(radius);
80  }
81 
89  {
90  return (((this->IJK[0] + offset) >= 0) && ((this->IJK[0] + offset) < this->PointDimensions[0]));
91  }
93  {
94  return (((this->IJK[1] + offset) >= 0) && ((this->IJK[1] + offset) < this->PointDimensions[1]));
95  }
97  {
98  return (((this->IJK[2] + offset) >= 0) && ((this->IJK[2] + offset) < this->PointDimensions[2]));
99  }
101 
107  {
108  return this->IsNeighborInXBoundary(neighbor[0]) && this->IsNeighborInYBoundary(neighbor[1]) &&
109  this->IsNeighborInZBoundary(neighbor[2]);
110  }
111 
115  {
116  VTKM_ASSERT(radius >= 0);
117  vtkm::IdComponent3 minIndices;
118 
119  for (vtkm::IdComponent component = 0; component < 3; ++component)
120  {
121  if (this->IJK[component] >= radius)
122  {
123  minIndices[component] = -radius;
124  }
125  else
126  {
127  minIndices[component] = static_cast<vtkm::IdComponent>(-this->IJK[component]);
128  }
129  }
130 
131  return minIndices;
132  }
133 
137  {
138  VTKM_ASSERT(radius >= 0);
139  vtkm::IdComponent3 maxIndices;
140 
141  for (vtkm::IdComponent component = 0; component < 3; ++component)
142  {
143  if ((this->PointDimensions[component] - this->IJK[component] - 1) >= radius)
144  {
145  maxIndices[component] = radius;
146  }
147  else
148  {
149  maxIndices[component] = static_cast<vtkm::IdComponent>(this->PointDimensions[component] -
150  this->IJK[component] - 1);
151  }
152  }
153 
154  return maxIndices;
155  }
156 
165  {
166  vtkm::Id3 fullIndex = this->IJK + neighbor;
167 
168  return vtkm::Max(vtkm::Id3(0), vtkm::Min(this->PointDimensions - vtkm::Id3(1), fullIndex));
169  }
170 
172  vtkm::IdComponent neighborJ,
173  vtkm::IdComponent neighborK) const
174  {
175  return this->NeighborIndexToFullIndexClamp(vtkm::make_Vec(neighborI, neighborJ, neighborK));
176  }
178 
185  {
186  return this->IJK + neighbor;
187  }
188 
190  vtkm::IdComponent neighborJ,
191  vtkm::IdComponent neighborK) const
192  {
193  return this->NeighborIndexToFullIndex(vtkm::make_Vec(neighborI, neighborJ, neighborK));
194  }
196 
205  {
206  const vtkm::Id3 fullIndex = this->IJK + neighbor;
207  const vtkm::Id3 clampedFullIndex =
208  vtkm::Max(vtkm::Id3(0), vtkm::Min(this->PointDimensions - vtkm::Id3(1), fullIndex));
209  return vtkm::IdComponent3{ clampedFullIndex - this->IJK };
210  }
211 
213  vtkm::IdComponent neighborJ,
214  vtkm::IdComponent neighborK) const
215  {
216  return this->ClampNeighborIndex(vtkm::make_Vec(neighborI, neighborJ, neighborK));
217  }
219 
228  {
229  vtkm::Id3 full = this->NeighborIndexToFullIndexClamp(neighbor);
230 
231  return (full[2] * this->PointDimensions[1] + full[1]) * this->PointDimensions[0] + full[0];
232  }
233 
235  vtkm::IdComponent neighborJ,
236  vtkm::IdComponent neighborK) const
237  {
238  return this->NeighborIndexToFlatIndexClamp(vtkm::make_Vec(neighborI, neighborJ, neighborK));
239  }
241 
248  {
249  vtkm::Id3 full = this->IJK + neighbor;
250  return (full[2] * this->PointDimensions[1] + full[1]) * this->PointDimensions[0] + full[0];
251  }
252 
254  vtkm::IdComponent neighborJ,
255  vtkm::IdComponent neighborK) const
256  {
257  return this->NeighborIndexToFlatIndex(vtkm::make_Vec(neighborI, neighborJ, neighborK));
258  }
262 };
263 }
264 } // namespace vtkm::exec
265 
266 #endif //vtk_m_exec_BoundaryState_h
vtkm::exec::BoundaryState
Provides a neighborhood's placement with respect to the mesh's boundary.
Definition: BoundaryState.h:31
vtkm::exec::BoundaryState::NeighborIndexToFullIndex
VTKM_EXEC vtkm::Id3 NeighborIndexToFullIndex(const vtkm::IdComponent3 &neighbor) const
Definition: BoundaryState.h:184
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm::exec::BoundaryState::BoundaryState
VTKM_EXEC BoundaryState(const vtkm::Id3 &ijk, const vtkm::Id3 &pdims)
Definition: BoundaryState.h:34
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::exec::BoundaryState::ClampNeighborIndex
VTKM_EXEC vtkm::IdComponent3 ClampNeighborIndex(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Definition: BoundaryState.h:212
vtkm::exec::BoundaryState::NeighborIndexToFlatIndexClamp
VTKM_EXEC vtkm::Id NeighborIndexToFlatIndexClamp(const vtkm::IdComponent3 &neighbor) const
Definition: BoundaryState.h:227
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::exec::BoundaryState::IsNeighborInBoundary
VTKM_EXEC 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:106
vtkm::exec::BoundaryState::IJK
vtkm::Id3 IJK
Definition: BoundaryState.h:260
vtkm::exec::BoundaryState::NeighborIndexToFlatIndex
VTKM_EXEC vtkm::Id NeighborIndexToFlatIndex(const vtkm::IdComponent3 &neighbor) const
Definition: BoundaryState.h:247
Assert.h
vtkm::exec::BoundaryState::IsRadiusInXBoundary
VTKM_EXEC bool IsRadiusInXBoundary(vtkm::IdComponent radius) const
Definition: BoundaryState.h:50
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::exec::BoundaryState::ClampNeighborIndex
VTKM_EXEC vtkm::IdComponent3 ClampNeighborIndex(const vtkm::IdComponent3 &neighbor) const
Definition: BoundaryState.h:204
Math.h
vtkm::exec::BoundaryState::IsRadiusInYBoundary
VTKM_EXEC bool IsRadiusInYBoundary(vtkm::IdComponent radius) const
Definition: BoundaryState.h:55
vtkm::exec::BoundaryState::NeighborIndexToFullIndex
VTKM_EXEC vtkm::Id3 NeighborIndexToFullIndex(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Definition: BoundaryState.h:189
vtkm::exec::BoundaryState::NeighborIndexToFullIndexClamp
VTKM_EXEC vtkm::Id3 NeighborIndexToFullIndexClamp(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Definition: BoundaryState.h:171
vtkm::exec::BoundaryState::IsRadiusInZBoundary
VTKM_EXEC bool IsRadiusInZBoundary(vtkm::IdComponent radius) const
Definition: BoundaryState.h:60
vtkm::exec::BoundaryState::NeighborIndexToFlatIndexClamp
VTKM_EXEC vtkm::Id NeighborIndexToFlatIndexClamp(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Definition: BoundaryState.h:234
vtkm::make_Vec
constexpr VTKM_EXEC_CONT 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:1212
vtkm::exec::BoundaryState::PointDimensions
vtkm::Id3 PointDimensions
Definition: BoundaryState.h:261
vtkm::exec::BoundaryState::IsNeighborInXBoundary
VTKM_EXEC bool IsNeighborInXBoundary(vtkm::IdComponent offset) const
Definition: BoundaryState.h:88
vtkm::Vec< vtkm::Id, 3 >
vtkm::exec::BoundaryState::IsNeighborInYBoundary
VTKM_EXEC bool IsNeighborInYBoundary(vtkm::IdComponent offset) const
Definition: BoundaryState.h:92
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::exec::BoundaryState::NeighborIndexToFullIndexClamp
VTKM_EXEC vtkm::Id3 NeighborIndexToFullIndexClamp(const vtkm::IdComponent3 &neighbor) const
Definition: BoundaryState.h:164
vtkm::exec::BoundaryState::NeighborIndexToFlatIndex
VTKM_EXEC vtkm::Id NeighborIndexToFlatIndex(vtkm::IdComponent neighborI, vtkm::IdComponent neighborJ, vtkm::IdComponent neighborK) const
Definition: BoundaryState.h:253
vtkm::exec::BoundaryState::IsNeighborInZBoundary
VTKM_EXEC bool IsNeighborInZBoundary(vtkm::IdComponent offset) const
Definition: BoundaryState.h:96
vtkm::exec::BoundaryState::IsRadiusInBoundary
VTKM_EXEC 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:76