VTK-m  2.3
exec/CellLocatorUniformGrid.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 vtkm_exec_celllocatoruniformgrid_h
11 #define vtkm_exec_celllocatoruniformgrid_h
12 
13 #include <vtkm/Bounds.h>
14 #include <vtkm/Math.h>
16 #include <vtkm/Types.h>
18 
20 
21 #include <vtkm/exec/CellInside.h>
23 
24 namespace vtkm
25 {
26 
27 namespace exec
28 {
29 
40 {
41 public:
42  VTKM_CONT
44  const vtkm::Vec3f origin,
45  const vtkm::Vec3f invSpacing,
46  const vtkm::Vec3f maxPoint)
47  : CellDims(cellDims)
48  , MaxCellIds(vtkm::Max(cellDims - vtkm::Id3(1), vtkm::Id3(0)))
49  , Origin(origin)
50  , InvSpacing(invSpacing)
51  , MaxPoint(maxPoint)
52  {
53  }
54 
55  VTKM_EXEC inline bool IsInside(const vtkm::Vec3f& point) const
56  {
57  bool inside = true;
58  if (point[0] < this->Origin[0] || point[0] > this->MaxPoint[0])
59  inside = false;
60  if (point[1] < this->Origin[1] || point[1] > this->MaxPoint[1])
61  inside = false;
62  if (point[2] < this->Origin[2] || point[2] > this->MaxPoint[2])
63  inside = false;
64  return inside;
65  }
66 
72  struct LastCell
73  {
74  };
75 
94  vtkm::Id& cellId,
95  vtkm::Vec3f& parametric,
96  LastCell& lastCell) const
97  {
98  (void)lastCell;
99  return this->FindCell(point, cellId, parametric);
100  }
101 
104  vtkm::Id& cellId,
105  vtkm::Vec3f& parametric) const
106  {
107  if (!this->IsInside(point))
108  {
109  cellId = -1;
111  }
112  // Get the Cell Id from the point.
113  vtkm::Id3 logicalCell(0, 0, 0);
114 
115  vtkm::Vec3f temp;
116  temp = point - this->Origin;
117  temp = temp * this->InvSpacing;
118 
119  //make sure that if we border the upper edge, we sample the correct cell
120  logicalCell = vtkm::Min(vtkm::Id3(temp), this->MaxCellIds);
121 
122  cellId =
123  (logicalCell[2] * this->CellDims[1] + logicalCell[1]) * this->CellDims[0] + logicalCell[0];
124  parametric = temp - logicalCell;
125 
127  }
128 
129 private:
135 };
136 }
137 }
138 
139 #endif //vtkm_exec_celllocatoruniformgrid_h
vtkm::ErrorCode
ErrorCode
Identifies whether an operation was successful or what type of error it had.
Definition: ErrorCode.h:28
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::CellLocatorUniformGrid::MaxCellIds
vtkm::Id3 MaxCellIds
Definition: exec/CellLocatorUniformGrid.h:131
Types.h
vtkm::ErrorCode::Success
@ Success
A successful operation.
vtkm::exec::CellLocatorUniformGrid::CellLocatorUniformGrid
CellLocatorUniformGrid(const vtkm::Id3 cellDims, const vtkm::Vec3f origin, const vtkm::Vec3f invSpacing, const vtkm::Vec3f maxPoint)
Definition: exec/CellLocatorUniformGrid.h:43
vtkm::exec::CellLocatorUniformGrid
Structure for locating cells.
Definition: exec/CellLocatorUniformGrid.h:39
VecFromPortalPermute.h
vtkm::exec::CellLocatorUniformGrid::FindCell
vtkm::ErrorCode FindCell(const vtkm::Vec3f &point, vtkm::Id &cellId, vtkm::Vec3f &parametric) const
Locate the cell containing the provided point.
Definition: exec/CellLocatorUniformGrid.h:103
vtkm::exec::CellLocatorUniformGrid::LastCell
Structure capturing the location of a cell in the search structure.
Definition: exec/CellLocatorUniformGrid.h:72
vtkm::exec::CellLocatorUniformGrid::Origin
vtkm::Vec3f Origin
Definition: exec/CellLocatorUniformGrid.h:132
Bounds.h
CellInside.h
Math.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::ErrorCode::CellNotFound
@ CellNotFound
A cell matching some given criteria could not be found.
vtkm::exec::CellLocatorUniformGrid::CellDims
vtkm::Id3 CellDims
Definition: exec/CellLocatorUniformGrid.h:130
vtkm::Vec< vtkm::Id, 3 >
vtkm::exec::CellLocatorUniformGrid::IsInside
bool IsInside(const vtkm::Vec3f &point) const
Definition: exec/CellLocatorUniformGrid.h:55
CellSetStructured.h
vtkm::exec::CellLocatorUniformGrid::MaxPoint
vtkm::Vec3f MaxPoint
Definition: exec/CellLocatorUniformGrid.h:134
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
vtkm::exec::CellLocatorUniformGrid::InvSpacing
vtkm::Vec3f InvSpacing
Definition: exec/CellLocatorUniformGrid.h:133
vtkm::exec::CellLocatorUniformGrid::FindCell
vtkm::ErrorCode FindCell(const vtkm::Vec3f &point, vtkm::Id &cellId, vtkm::Vec3f &parametric, LastCell &lastCell) const
Locate the cell containing the provided point.
Definition: exec/CellLocatorUniformGrid.h:93
ParametricCoordinates.h
TopologyElementTag.h