VTK-m  2.0
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 
31 {
32 public:
33  VTKM_CONT
35  const vtkm::Vec3f origin,
36  const vtkm::Vec3f invSpacing,
37  const vtkm::Vec3f maxPoint)
38  : CellDims(cellDims)
39  , MaxCellIds(vtkm::Max(cellDims - vtkm::Id3(1), vtkm::Id3(0)))
40  , Origin(origin)
41  , InvSpacing(invSpacing)
42  , MaxPoint(maxPoint)
43  {
44  }
45 
46  VTKM_EXEC inline bool IsInside(const vtkm::Vec3f& point) const
47  {
48  bool inside = true;
49  if (point[0] < this->Origin[0] || point[0] > this->MaxPoint[0])
50  inside = false;
51  if (point[1] < this->Origin[1] || point[1] > this->MaxPoint[1])
52  inside = false;
53  if (point[2] < this->Origin[2] || point[2] > this->MaxPoint[2])
54  inside = false;
55  return inside;
56  }
57 
58  struct LastCell
59  {
60  };
61 
62  VTKM_EXEC
64  vtkm::Id& cellId,
65  vtkm::Vec3f& parametric,
66  LastCell& vtkmNotUsed(lastCell)) const
67  {
68  return this->FindCell(point, cellId, parametric);
69  }
70 
71  VTKM_EXEC
73  vtkm::Id& cellId,
74  vtkm::Vec3f& parametric) const
75  {
76  if (!this->IsInside(point))
77  {
78  cellId = -1;
80  }
81  // Get the Cell Id from the point.
82  vtkm::Id3 logicalCell(0, 0, 0);
83 
84  vtkm::Vec3f temp;
85  temp = point - this->Origin;
86  temp = temp * this->InvSpacing;
87 
88  //make sure that if we border the upper edge, we sample the correct cell
89  logicalCell = vtkm::Min(vtkm::Id3(temp), this->MaxCellIds);
90 
91  cellId =
92  (logicalCell[2] * this->CellDims[1] + logicalCell[1]) * this->CellDims[0] + logicalCell[0];
93  parametric = temp - logicalCell;
94 
96  }
97 
98 private:
104 };
105 }
106 }
107 
108 #endif //vtkm_exec_celllocatoruniformgrid_h
vtkm::ErrorCode
ErrorCode
Definition: ErrorCode.h:19
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:100
Types.h
vtkm::exec::CellLocatorUniformGrid::FindCell
VTKM_EXEC vtkm::ErrorCode FindCell(const vtkm::Vec3f &point, vtkm::Id &cellId, vtkm::Vec3f &parametric) const
Definition: exec/CellLocatorUniformGrid.h:72
vtkm::ErrorCode::Success
@ Success
vtkm::exec::CellLocatorUniformGrid::CellLocatorUniformGrid
VTKM_CONT CellLocatorUniformGrid(const vtkm::Id3 cellDims, const vtkm::Vec3f origin, const vtkm::Vec3f invSpacing, const vtkm::Vec3f maxPoint)
Definition: exec/CellLocatorUniformGrid.h:34
vtkm::exec::CellLocatorUniformGrid
Definition: exec/CellLocatorUniformGrid.h:30
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
VecFromPortalPermute.h
vtkm::exec::CellLocatorUniformGrid::LastCell
Definition: exec/CellLocatorUniformGrid.h:58
vtkm::exec::CellLocatorUniformGrid::Origin
vtkm::Vec3f Origin
Definition: exec/CellLocatorUniformGrid.h:101
Bounds.h
CellInside.h
Math.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::ErrorCode::CellNotFound
@ CellNotFound
vtkm::exec::CellLocatorUniformGrid::CellDims
vtkm::Id3 CellDims
Definition: exec/CellLocatorUniformGrid.h:99
vtkm::Vec< vtkm::Id, 3 >
CellSetStructured.h
vtkm::exec::CellLocatorUniformGrid::FindCell
VTKM_EXEC vtkm::ErrorCode FindCell(const vtkm::Vec3f &point, vtkm::Id &cellId, vtkm::Vec3f &parametric, LastCell &vtkmNotUsed(lastCell)) const
Definition: exec/CellLocatorUniformGrid.h:63
vtkm::exec::CellLocatorUniformGrid::MaxPoint
vtkm::Vec3f MaxPoint
Definition: exec/CellLocatorUniformGrid.h:103
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
vtkm::exec::CellLocatorUniformGrid::InvSpacing
vtkm::Vec3f InvSpacing
Definition: exec/CellLocatorUniformGrid.h:102
ParametricCoordinates.h
TopologyElementTag.h
vtkm::exec::CellLocatorUniformGrid::IsInside
VTKM_EXEC bool IsInside(const vtkm::Vec3f &point) const
Definition: exec/CellLocatorUniformGrid.h:46