Viskores  1.0
exec/CellLocatorUniformGrid.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_celllocatoruniformgrid_h
19 #define viskores_exec_celllocatoruniformgrid_h
20 
21 #include <viskores/Bounds.h>
22 #include <viskores/Math.h>
24 #include <viskores/Types.h>
26 
28 
31 
32 namespace viskores
33 {
34 
35 namespace exec
36 {
37 
47 class VISKORES_ALWAYS_EXPORT CellLocatorUniformGrid
48 {
49 public:
52  const viskores::Vec3f origin,
53  const viskores::Vec3f invSpacing,
54  const viskores::Vec3f maxPoint)
55  : CellDims(cellDims)
56  , MaxCellIds(viskores::Max(cellDims - viskores::Id3(1), viskores::Id3(0)))
57  , Origin(origin)
58  , InvSpacing(invSpacing)
59  , MaxPoint(maxPoint)
60  {
61  }
62 
63  VISKORES_EXEC inline bool IsInside(const viskores::Vec3f& point) const
64  {
65  bool inside = true;
66  if (point[0] < this->Origin[0] || point[0] > this->MaxPoint[0])
67  inside = false;
68  if (point[1] < this->Origin[1] || point[1] > this->MaxPoint[1])
69  inside = false;
70  if (point[2] < this->Origin[2] || point[2] > this->MaxPoint[2])
71  inside = false;
72  return inside;
73  }
74 
80  struct LastCell
81  {
82  };
83 
102  viskores::Id& cellId,
103  viskores::Vec3f& parametric,
104  LastCell& lastCell) const
105  {
106  (void)lastCell;
107  return this->FindCell(point, cellId, parametric);
108  }
109 
112  viskores::Id& cellId,
113  viskores::Vec3f& parametric) const
114  {
115  if (!this->IsInside(point))
116  {
117  cellId = -1;
119  }
120  // Get the Cell Id from the point.
121  viskores::Id3 logicalCell(0, 0, 0);
122 
123  viskores::Vec3f temp;
124  temp = point - this->Origin;
125  temp = temp * this->InvSpacing;
126 
127  //make sure that if we border the upper edge, we sample the correct cell
128  logicalCell = viskores::Min(viskores::Id3(temp), this->MaxCellIds);
129 
130  cellId =
131  (logicalCell[2] * this->CellDims[1] + logicalCell[1]) * this->CellDims[0] + logicalCell[0];
132  parametric = temp - logicalCell;
133 
135  }
136 
137 private:
143 };
144 }
145 }
146 
147 #endif //viskores_exec_celllocatoruniformgrid_h
viskores::exec::CellLocatorUniformGrid::FindCell
viskores::ErrorCode FindCell(const viskores::Vec3f &point, viskores::Id &cellId, viskores::Vec3f &parametric) const
Locate the cell containing the provided point.
Definition: exec/CellLocatorUniformGrid.h:111
viskores::exec::CellLocatorUniformGrid
Structure for locating cells.
Definition: exec/CellLocatorUniformGrid.h:47
Types.h
viskores::exec::CellLocatorUniformGrid::IsInside
bool IsInside(const viskores::Vec3f &point) const
Definition: exec/CellLocatorUniformGrid.h:63
viskores::exec::CellLocatorUniformGrid::CellDims
viskores::Id3 CellDims
Definition: exec/CellLocatorUniformGrid.h:138
viskores::ErrorCode
ErrorCode
Identifies whether an operation was successful or what type of error it had.
Definition: ErrorCode.h:36
viskores::exec::CellLocatorUniformGrid::CellLocatorUniformGrid
CellLocatorUniformGrid(const viskores::Id3 cellDims, const viskores::Vec3f origin, const viskores::Vec3f invSpacing, const viskores::Vec3f maxPoint)
Definition: exec/CellLocatorUniformGrid.h:51
viskores::exec::CellLocatorUniformGrid::MaxPoint
viskores::Vec3f MaxPoint
Definition: exec/CellLocatorUniformGrid.h:142
VecFromPortalPermute.h
viskores::exec::CellLocatorUniformGrid::InvSpacing
viskores::Vec3f InvSpacing
Definition: exec/CellLocatorUniformGrid.h:141
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
Bounds.h
CellInside.h
Math.h
viskores::exec::CellLocatorUniformGrid::LastCell
Structure capturing the location of a cell in the search structure.
Definition: exec/CellLocatorUniformGrid.h:80
viskores::ErrorCode::CellNotFound
@ CellNotFound
A cell matching some given criteria could not be found.
viskores::ErrorCode::Success
@ Success
A successful operation.
viskores::exec::CellLocatorUniformGrid::MaxCellIds
viskores::Id3 MaxCellIds
Definition: exec/CellLocatorUniformGrid.h:139
CellSetStructured.h
viskores::exec::CellLocatorUniformGrid::Origin
viskores::Vec3f Origin
Definition: exec/CellLocatorUniformGrid.h:140
ParametricCoordinates.h
viskores::Vec< viskores::Id, 3 >
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59
TopologyElementTag.h
viskores::exec::CellLocatorUniformGrid::FindCell
viskores::ErrorCode FindCell(const viskores::Vec3f &point, viskores::Id &cellId, viskores::Vec3f &parametric, LastCell &lastCell) const
Locate the cell containing the provided point.
Definition: exec/CellLocatorUniformGrid.h:101