Viskores  1.0
BoundaryState.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_exec_BoundaryState_h
19 #define viskores_exec_BoundaryState_h
20 
21 #include <viskores/Assert.h>
22 #include <viskores/Math.h>
23 
24 namespace viskores
25 {
26 namespace exec
27 {
28 
40 {
42  BoundaryState(const viskores::Id3& ijk, const viskores::Id3& pdims)
43  : IJK(ijk)
44  , PointDimensions(pdims)
45  {
46  }
47 
51  VISKORES_EXEC const viskores::Id3& GetCenterIndex() const { return this->IJK; }
52 
63  {
64  VISKORES_ASSERT(radius >= 0);
65  return (((this->IJK[0] - radius) >= 0) && ((this->IJK[0] + radius) < this->PointDimensions[0]));
66  }
69  {
70  VISKORES_ASSERT(radius >= 0);
71  return (((this->IJK[1] - radius) >= 0) && ((this->IJK[1] + radius) < this->PointDimensions[1]));
72  }
75  {
76  VISKORES_ASSERT(radius >= 0);
77  return (((this->IJK[2] - radius) >= 0) && ((this->IJK[2] + radius) < this->PointDimensions[2]));
78  }
79 
90  {
91  return this->IsRadiusInXBoundary(radius) && this->IsRadiusInYBoundary(radius) &&
92  this->IsRadiusInZBoundary(radius);
93  }
94 
101  {
102  return (((this->IJK[0] + offset) >= 0) && ((this->IJK[0] + offset) < this->PointDimensions[0]));
103  }
106  {
107  return (((this->IJK[1] + offset) >= 0) && ((this->IJK[1] + offset) < this->PointDimensions[1]));
108  }
111  {
112  return (((this->IJK[2] + offset) >= 0) && ((this->IJK[2] + offset) < this->PointDimensions[2]));
113  }
114 
120  {
121  return this->IsNeighborInXBoundary(neighbor[0]) && this->IsNeighborInYBoundary(neighbor[1]) &&
122  this->IsNeighborInZBoundary(neighbor[2]);
123  }
124 
136  {
137  VISKORES_ASSERT(radius >= 0);
138  viskores::IdComponent3 minIndices;
139 
140  for (viskores::IdComponent component = 0; component < 3; ++component)
141  {
142  if (this->IJK[component] >= radius)
143  {
144  minIndices[component] = -radius;
145  }
146  else
147  {
148  minIndices[component] = static_cast<viskores::IdComponent>(-this->IJK[component]);
149  }
150  }
151 
152  return minIndices;
153  }
154 
167  {
168  VISKORES_ASSERT(radius >= 0);
169  viskores::IdComponent3 maxIndices;
170 
171  for (viskores::IdComponent component = 0; component < 3; ++component)
172  {
173  if ((this->PointDimensions[component] - this->IJK[component] - 1) >= radius)
174  {
175  maxIndices[component] = radius;
176  }
177  else
178  {
179  maxIndices[component] = static_cast<viskores::IdComponent>(
180  this->PointDimensions[component] - this->IJK[component] - 1);
181  }
182  }
183 
184  return maxIndices;
185  }
186 
194  const viskores::IdComponent3& neighbor) const
195  {
196  viskores::Id3 fullIndex = this->IJK + neighbor;
197 
198  return viskores::Max(viskores::Id3(0),
199  viskores::Min(this->PointDimensions - viskores::Id3(1), fullIndex));
200  }
201 
204  viskores::IdComponent neighborJ,
205  viskores::IdComponent neighborK) const
206  {
207  return this->NeighborIndexToFullIndexClamp(viskores::make_Vec(neighborI, neighborJ, neighborK));
208  }
209 
215  {
216  return this->IJK + neighbor;
217  }
218 
221  viskores::IdComponent neighborJ,
222  viskores::IdComponent neighborK) const
223  {
224  return this->NeighborIndexToFullIndex(viskores::make_Vec(neighborI, neighborJ, neighborK));
225  }
226 
234  const viskores::IdComponent3& neighbor) const
235  {
236  const viskores::Id3 fullIndex = this->IJK + neighbor;
237  const viskores::Id3 clampedFullIndex = viskores::Max(
238  viskores::Id3(0), viskores::Min(this->PointDimensions - viskores::Id3(1), fullIndex));
239  return viskores::IdComponent3{ clampedFullIndex - this->IJK };
240  }
241 
244  viskores::IdComponent neighborJ,
245  viskores::IdComponent neighborK) const
246  {
247  return this->ClampNeighborIndex(viskores::make_Vec(neighborI, neighborJ, neighborK));
248  }
249 
257  const viskores::IdComponent3& neighbor) const
258  {
259  viskores::Id3 full = this->NeighborIndexToFullIndexClamp(neighbor);
260 
261  return (full[2] * this->PointDimensions[1] + full[1]) * this->PointDimensions[0] + full[0];
262  }
263 
266  viskores::IdComponent neighborJ,
267  viskores::IdComponent neighborK) const
268  {
269  return this->NeighborIndexToFlatIndexClamp(viskores::make_Vec(neighborI, neighborJ, neighborK));
270  }
271 
277  {
278  viskores::Id3 full = this->IJK + neighbor;
279  return (full[2] * this->PointDimensions[1] + full[1]) * this->PointDimensions[0] + full[0];
280  }
281 
284  viskores::IdComponent neighborJ,
285  viskores::IdComponent neighborK) const
286  {
287  return this->NeighborIndexToFlatIndex(viskores::make_Vec(neighborI, neighborJ, neighborK));
288  }
289 
292 
295 };
296 }
297 } // namespace viskores::exec
298 
299 #endif //viskores_exec_BoundaryState_h
viskores::exec::BoundaryState::NeighborIndexToFullIndexClamp
viskores::Id3 NeighborIndexToFullIndexClamp(const viskores::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:193
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::exec::BoundaryState::NeighborIndexToFlatIndexClamp
viskores::Id NeighborIndexToFlatIndexClamp(viskores::IdComponent neighborI, viskores::IdComponent neighborJ, viskores::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:265
viskores::exec::BoundaryState::IsNeighborInYBoundary
bool IsNeighborInYBoundary(viskores::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:105
viskores::exec::BoundaryState::GetCenterIndex
const viskores::Id3 & GetCenterIndex() const
Returns the center index of the neighborhood.
Definition: BoundaryState.h:51
viskores::exec::BoundaryState
Provides a neighborhood's placement with respect to the mesh's boundary.
Definition: BoundaryState.h:39
Assert.h
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
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
viskores::exec::BoundaryState::PointDimensions
viskores::Id3 PointDimensions
The dimensions of the elements in the mesh.
Definition: BoundaryState.h:294
viskores::exec::BoundaryState::ClampNeighborIndex
viskores::IdComponent3 ClampNeighborIndex(viskores::IdComponent neighborI, viskores::IdComponent neighborJ, viskores::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size),...
Definition: BoundaryState.h:243
viskores::exec::BoundaryState::IsNeighborInBoundary
bool IsNeighborInBoundary(const viskores::IdComponent3 &neighbor) const
Returns true if the neighbor at the specified offset vector is contained within the bounds of the cel...
Definition: BoundaryState.h:119
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Math.h
viskores::exec::BoundaryState::NeighborIndexToFullIndexClamp
viskores::Id3 NeighborIndexToFullIndexClamp(viskores::IdComponent neighborI, viskores::IdComponent neighborJ, viskores::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:203
viskores::exec::BoundaryState::ClampNeighborIndex
viskores::IdComponent3 ClampNeighborIndex(const viskores::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size),...
Definition: BoundaryState.h:233
viskores::exec::BoundaryState::NeighborIndexToFullIndex
viskores::Id3 NeighborIndexToFullIndex(viskores::IdComponent neighborI, viskores::IdComponent neighborJ, viskores::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:220
viskores::exec::BoundaryState::NeighborIndexToFlatIndexClamp
viskores::Id NeighborIndexToFlatIndexClamp(const viskores::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:256
viskores::exec::BoundaryState::BoundaryState
BoundaryState(const viskores::Id3 &ijk, const viskores::Id3 &pdims)
Definition: BoundaryState.h:42
VISKORES_ASSERT
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
viskores::exec::BoundaryState::NeighborIndexToFullIndex
viskores::Id3 NeighborIndexToFullIndex(const viskores::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:214
viskores::exec::BoundaryState::IsRadiusInYBoundary
bool IsRadiusInYBoundary(viskores::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:68
viskores::make_Vec
constexpr viskores::Vec< T, viskores::IdComponent(sizeof...(Ts)+1)> make_Vec(T value0, Ts &&... args)
Initializes and returns a Vec containing all the arguments.
Definition: Types.h:1262
viskores::exec::BoundaryState::IsRadiusInZBoundary
bool IsRadiusInZBoundary(viskores::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:74
viskores::exec::BoundaryState::IsRadiusInBoundary
bool IsRadiusInBoundary(viskores::IdComponent radius) const
Returns true if a neighborhood of the given radius is contained within the bounds of the cell set.
Definition: BoundaryState.h:89
viskores::exec::BoundaryState::IJK
viskores::Id3 IJK
The 3D index of the visited element.
Definition: BoundaryState.h:291
viskores::exec::BoundaryState::IsNeighborInXBoundary
bool IsNeighborInXBoundary(viskores::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:100
viskores::exec::BoundaryState::NeighborIndexToFlatIndex
viskores::Id NeighborIndexToFlatIndex(const viskores::IdComponent3 &neighbor) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:276
viskores::exec::BoundaryState::IsNeighborInZBoundary
bool IsNeighborInZBoundary(viskores::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:110
viskores::exec::BoundaryState::IsRadiusInXBoundary
bool IsRadiusInXBoundary(viskores::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:62
viskores::Vec< viskores::Id, 3 >
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59
viskores::exec::BoundaryState::NeighborIndexToFlatIndex
viskores::Id NeighborIndexToFlatIndex(viskores::IdComponent neighborI, viskores::IdComponent neighborJ, viskores::IdComponent neighborK) const
Takes a local neighborhood index (in the ranges of -neighborhood size to neighborhood size) and retur...
Definition: BoundaryState.h:283