Viskores  1.0
GridMetaData.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_filter_flow_internal_GridMetaData_h
19 #define viskores_filter_flow_internal_GridMetaData_h
20 
21 namespace viskores
22 {
23 namespace filter
24 {
25 namespace flow
26 {
27 namespace internal
28 {
29 
30 class GridMetaData
31 {
32 public:
33  using Structured2DType = viskores::cont::CellSetStructured<2>;
34  using Structured3DType = viskores::cont::CellSetStructured<3>;
35 
37  GridMetaData(const viskores::cont::UnknownCellSet cellSet)
38  {
39  if (cellSet.CanConvert<Structured2DType>())
40  {
41  this->cellSet2D = true;
42  viskores::Id2 dims = cellSet.AsCellSet<Structured2DType>().GetSchedulingRange(
44  this->Dims = viskores::Id3(dims[0], dims[1], 1);
45  }
46  else
47  {
48  this->cellSet2D = false;
49  this->Dims = cellSet.AsCellSet<Structured3DType>().GetSchedulingRange(
51  }
52  this->PlaneSize = Dims[0] * Dims[1];
53  this->RowSize = Dims[0];
54  }
55 
57  bool IsCellSet2D() const { return this->cellSet2D; }
58 
60  void GetLogicalIndex(const viskores::Id index, viskores::Id3& logicalIndex) const
61  {
62  logicalIndex[0] = index % Dims[0];
63  logicalIndex[1] = (index / Dims[0]) % Dims[1];
64  if (this->cellSet2D)
65  logicalIndex[2] = 0;
66  else
67  logicalIndex[2] = index / (Dims[0] * Dims[1]);
68  }
69 
71  const viskores::Vec<viskores::Id, 6> GetNeighborIndices(const viskores::Id index) const
72  {
74  viskores::Id3 logicalIndex;
75  GetLogicalIndex(index, logicalIndex);
76 
77  // For differentials w.r.t delta in x
78  indices[0] = (logicalIndex[0] == 0) ? index : index - 1;
79  indices[1] = (logicalIndex[0] == Dims[0] - 1) ? index : index + 1;
80  // For differentials w.r.t delta in y
81  indices[2] = (logicalIndex[1] == 0) ? index : index - RowSize;
82  indices[3] = (logicalIndex[1] == Dims[1] - 1) ? index : index + RowSize;
83  if (!this->cellSet2D)
84  {
85  // For differentials w.r.t delta in z
86  indices[4] = (logicalIndex[2] == 0) ? index : index - PlaneSize;
87  indices[5] = (logicalIndex[2] == Dims[2] - 1) ? index : index + PlaneSize;
88  }
89  return indices;
90  }
91 
92 private:
93  bool cellSet2D = false;
94  viskores::Id3 Dims;
95  viskores::Id PlaneSize;
96  viskores::Id RowSize;
97 };
98 
99 }
100 }
101 }
102 } //viskores::filter::flow::internal
103 
104 #endif //viskores_filter_flow_internal_GridMetaData_h
viskores::TopologyElementTagPoint
A tag used to identify the point elements in a topology.
Definition: TopologyElementTag.h:42
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::Id3
viskores::Vec< viskores::Id, 3 > Id3
Id3 corresponds to a 3-dimensional index for 3d arrays.
Definition: Types.h:1053
viskores::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:40
viskores::cont::UnknownCellSet::CanConvert
bool CanConvert() const
Returns true if this cell set can be retrieved as the given type.
Definition: UnknownCellSet.h:172
viskores::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:56
viskores::Vec< viskores::Id, 2 >
viskores::cont::UnknownCellSet::AsCellSet
void AsCellSet(CellSetType &cellSet) const
Get the cell set as a known type.
Definition: UnknownCellSet.h:189
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59