VTK-m  2.0
CellInterpolate.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 vtk_m_exec_Interpolate_h
11 #define vtk_m_exec_Interpolate_h
12 
13 #include <vtkm/CellShape.h>
14 #include <vtkm/ErrorCode.h>
16 #include <vtkm/exec/FunctorBase.h>
17 
18 #include <lcl/lcl.h>
19 
20 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
21 #pragma GCC diagnostic push
22 #pragma GCC diagnostic ignored "-Wconversion"
23 #endif // gcc || clang
24 
25 namespace vtkm
26 {
27 namespace exec
28 {
29 
30 namespace internal
31 {
32 
33 template <typename VtkcCellShapeTag, typename FieldVecType, typename ParametricCoordType>
34 VTKM_EXEC vtkm::ErrorCode CellInterpolateImpl(VtkcCellShapeTag tag,
35  const FieldVecType& field,
36  const ParametricCoordType& pcoords,
37  typename FieldVecType::ComponentType& result)
38 {
39  if (tag.numberOfPoints() != field.GetNumberOfComponents())
40  {
41  result = { 0 };
43  }
44 
45  using FieldValueType = typename FieldVecType::ComponentType;
47  auto status =
48  lcl::interpolate(tag, lcl::makeFieldAccessorNestedSOA(field, numComponents), pcoords, result);
49  return vtkm::internal::LclErrorToVtkmError(status);
50 }
51 
52 } // namespace internal
53 
54 //-----------------------------------------------------------------------------
55 template <typename FieldVecType, typename ParametricCoordType, typename CellShapeTag>
56 VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& pointFieldValues,
57  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
58  CellShapeTag tag,
59  typename FieldVecType::ComponentType& result)
60 {
61  auto lclTag = vtkm::internal::make_LclCellShapeTag(tag, pointFieldValues.GetNumberOfComponents());
62  return internal::CellInterpolateImpl(lclTag, pointFieldValues, pcoords, result);
63 }
64 
65 //-----------------------------------------------------------------------------
66 template <typename FieldVecType, typename ParametricCoordType>
69  vtkm::CellShapeTagEmpty,
70  typename FieldVecType::ComponentType& result)
71 {
72  result = { 0 };
74 }
75 
76 //-----------------------------------------------------------------------------
77 template <typename FieldVecType, typename ParametricCoordType>
78 VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& field,
79  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
80  vtkm::CellShapeTagPolyLine,
81  typename FieldVecType::ComponentType& result)
82 {
83  const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
84  if (numPoints < 1)
85  {
86  result = { 0 };
88  }
89 
90  if (numPoints == 1)
91  {
92  return CellInterpolate(field, pcoords, vtkm::CellShapeTagVertex(), result);
93  }
94 
95  using T = ParametricCoordType;
96 
97  T dt = 1 / static_cast<T>(numPoints - 1);
98  vtkm::IdComponent idx = static_cast<vtkm::IdComponent>(pcoords[0] / dt);
99  if (idx == numPoints - 1)
100  {
101  result = field[numPoints - 1];
103  }
104 
105  T pc = (pcoords[0] - static_cast<T>(idx) * dt) / dt;
106  return internal::CellInterpolateImpl(
107  lcl::Line{}, vtkm::make_Vec(field[idx], field[idx + 1]), &pc, result);
108 }
109 
110 //-----------------------------------------------------------------------------
111 template <typename FieldVecType, typename ParametricCoordType>
112 VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& field,
113  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
114  vtkm::CellShapeTagPolygon,
115  typename FieldVecType::ComponentType& result)
116 {
117  const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
118  if (numPoints < 1)
119  {
120  result = { 0 };
122  }
123 
124  switch (numPoints)
125  {
126  case 1:
127  return CellInterpolate(field, pcoords, vtkm::CellShapeTagVertex(), result);
128  case 2:
129  return CellInterpolate(field, pcoords, vtkm::CellShapeTagLine(), result);
130  default:
131  return internal::CellInterpolateImpl(lcl::Polygon(numPoints), field, pcoords, result);
132  }
133 }
134 
135 //-----------------------------------------------------------------------------
136 template <typename ParametricCoordType>
138  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
139  vtkm::CellShapeTagQuad,
140  vtkm::Vec3f& result)
141 {
142  return internal::CellInterpolateImpl(lcl::Pixel{}, field, pcoords, result);
143 }
144 
145 //-----------------------------------------------------------------------------
146 template <typename ParametricCoordType>
148  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
149  vtkm::CellShapeTagHexahedron,
150  vtkm::Vec3f& result)
151 {
152  return internal::CellInterpolateImpl(lcl::Voxel{}, field, pcoords, result);
153 }
154 
155 //-----------------------------------------------------------------------------
161 template <typename FieldVecType, typename ParametricCoordType>
162 VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& pointFieldValues,
163  const vtkm::Vec<ParametricCoordType, 3>& parametricCoords,
165  typename FieldVecType::ComponentType& result)
166 {
167  vtkm::ErrorCode status;
168  switch (shape.Id)
169  {
171  status = CellInterpolate(pointFieldValues, parametricCoords, CellShapeTag(), result));
172  default:
173  result = { 0 };
175  }
176  return status;
177 }
178 
179 }
180 } // namespace vtkm::exec
181 
182 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
183 #pragma GCC diagnostic pop
184 #endif // gcc || clang
185 
186 #endif //vtk_m_exec_Interpolate_h
vtkm::ErrorCode
ErrorCode
Definition: ErrorCode.h:19
vtkm::VecAxisAlignedPointCoordinates
An implicit vector for point coordinates in axis aligned cells.
Definition: VecAxisAlignedPointCoordinates.h:78
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::ErrorCode::Success
@ Success
CellShape.h
ErrorCode.h
vtkm::Line
Ray< CoordType, Dim, true > Line
Lines are two-sided rays:
Definition: Geometry.h:330
vtkmGenericCellShapeMacro
#define vtkmGenericCellShapeMacro(call)
A macro used in a switch statement to determine cell shape.
Definition: CellShape.h:230
FunctorBase.h
vtkm::exec::CellInterpolate
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType &pointFieldValues, const vtkm::Vec< ParametricCoordType, 3 > &pcoords, CellShapeTag tag, typename FieldVecType::ComponentType &result)
Definition: CellInterpolate.h:56
vtkm::make_Vec
constexpr VTKM_EXEC_CONT vtkm::Vec< T, vtkm::IdComponent(sizeof...(Ts)+1)> make_Vec(T value0, Ts &&... args)
Initializes and returns a Vec containing all the arguments.
Definition: Types.h:1212
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
Definition: CellShape.h:160
vtkm::ErrorCode::OperationOnEmptyCell
@ OperationOnEmptyCell
vtkm::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:152
VecAxisAlignedPointCoordinates.h
vtkm::VecTraits::GetNumberOfComponents
static vtkm::IdComponent GetNumberOfComponents(const VecType &vec)
Number of components in the given vector.
vtkm::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints
vtkm::ErrorCode::InvalidShapeId
@ InvalidShapeId