VTK-m  2.2
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>
18 #include <vtkm/exec/FunctorBase.h>
19 
20 #include <lcl/lcl.h>
21 
22 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wconversion"
25 #endif // gcc || clang
26 
27 namespace vtkm
28 {
29 namespace exec
30 {
31 
32 namespace internal
33 {
34 
35 template <typename VtkcCellShapeTag, typename FieldVecType, typename ParametricCoordType>
36 VTKM_EXEC vtkm::ErrorCode CellInterpolateImpl(VtkcCellShapeTag tag,
37  const FieldVecType& field,
38  const ParametricCoordType& pcoords,
39  typename FieldVecType::ComponentType& result)
40 {
41  if (tag.numberOfPoints() != field.GetNumberOfComponents())
42  {
43  result = { 0 };
45  }
46 
47  using FieldValueType = typename FieldVecType::ComponentType;
49  auto status =
50  lcl::interpolate(tag, lcl::makeFieldAccessorNestedSOA(field, numComponents), pcoords, result);
51  return vtkm::internal::LclErrorToVtkmError(status);
52 }
53 
54 } // namespace internal
55 
56 //-----------------------------------------------------------------------------
57 template <typename FieldVecType, typename ParametricCoordType, typename CellShapeTag>
58 VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& pointFieldValues,
59  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
60  CellShapeTag tag,
61  typename FieldVecType::ComponentType& result)
62 {
63  auto lclTag = vtkm::internal::make_LclCellShapeTag(tag, pointFieldValues.GetNumberOfComponents());
64  return internal::CellInterpolateImpl(lclTag, pointFieldValues, pcoords, result);
65 }
66 
67 //-----------------------------------------------------------------------------
68 template <typename FieldVecType, typename ParametricCoordType>
72  typename FieldVecType::ComponentType& result)
73 {
74  result = { 0 };
76 }
77 
78 //-----------------------------------------------------------------------------
79 template <typename FieldVecType, typename ParametricCoordType>
80 VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& field,
81  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
83  typename FieldVecType::ComponentType& result)
84 {
85  const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
86  if (numPoints < 1)
87  {
88  result = { 0 };
90  }
91 
92  if (numPoints == 1)
93  {
94  return CellInterpolate(field, pcoords, vtkm::CellShapeTagVertex(), result);
95  }
96 
97  using T = ParametricCoordType;
98 
99  T dt = 1 / static_cast<T>(numPoints - 1);
100  vtkm::IdComponent idx = static_cast<vtkm::IdComponent>(pcoords[0] / dt);
101  if (idx == numPoints - 1)
102  {
103  result = field[numPoints - 1];
105  }
106 
107  T pc = (pcoords[0] - static_cast<T>(idx) * dt) / dt;
108  return internal::CellInterpolateImpl(
109  lcl::Line{}, vtkm::make_Vec(field[idx], field[idx + 1]), &pc, result);
110 }
111 
112 //-----------------------------------------------------------------------------
113 template <typename FieldVecType, typename ParametricCoordType>
114 VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& field,
115  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
117  typename FieldVecType::ComponentType& result)
118 {
119  const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
120  if (numPoints < 1)
121  {
122  result = { 0 };
124  }
125 
126  switch (numPoints)
127  {
128  case 1:
129  return CellInterpolate(field, pcoords, vtkm::CellShapeTagVertex(), result);
130  case 2:
131  return CellInterpolate(field, pcoords, vtkm::CellShapeTagLine(), result);
132  default:
133  return internal::CellInterpolateImpl(lcl::Polygon(numPoints), field, pcoords, result);
134  }
135 }
136 
137 //-----------------------------------------------------------------------------
138 template <typename ParametricCoordType>
140  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
142  vtkm::Vec3f& result)
143 {
144  return internal::CellInterpolateImpl(lcl::Pixel{}, field, pcoords, result);
145 }
146 
147 //-----------------------------------------------------------------------------
148 template <typename ParametricCoordType>
150  const vtkm::Vec<ParametricCoordType, 3>& pcoords,
152  vtkm::Vec3f& result)
153 {
154  return internal::CellInterpolateImpl(lcl::Voxel{}, field, pcoords, result);
155 }
156 
157 //-----------------------------------------------------------------------------
171 template <typename FieldVecType, typename ParametricCoordType>
172 VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& pointFieldValues,
173  const vtkm::Vec<ParametricCoordType, 3>& parametricCoords,
175  typename FieldVecType::ComponentType& result)
176 {
177  vtkm::ErrorCode status;
178  switch (shape.Id)
179  {
181  status = CellInterpolate(pointFieldValues, parametricCoords, CellShapeTag(), result));
182  default:
183  result = { 0 };
185  }
186  return status;
187 }
188 
189 //-----------------------------------------------------------------------------
205 template <typename IndicesVecType,
206  typename FieldPortalType,
207  typename ParametricCoordType,
208  typename CellShapeTag>
209 VTKM_EXEC vtkm::ErrorCode CellInterpolate(const IndicesVecType& pointIndices,
210  const FieldPortalType& pointFieldPortal,
211  const vtkm::Vec<ParametricCoordType, 3>& parametricCoords,
212  CellShapeTag shape,
213  typename FieldPortalType::ValueType& result)
214 {
215  return CellInterpolate(vtkm::make_VecFromPortalPermute(&pointIndices, pointFieldPortal),
216  parametricCoords,
217  shape,
218  result);
219 }
220 
221 }
222 } // namespace vtkm::exec
223 
224 #if (defined(VTKM_GCC) || defined(VTKM_CLANG))
225 #pragma GCC diagnostic pop
226 #endif // gcc || clang
227 
228 #endif //vtk_m_exec_Interpolate_h
vtkm::CellShapeTagQuad
Definition: CellShape.h:156
vtkm::ErrorCode
ErrorCode
Identifies whether an operation was successful or what type of error it had.
Definition: ErrorCode.h:28
vtkm::exec::CellInterpolate
vtkm::ErrorCode CellInterpolate(const FieldVecType &pointFieldValues, const vtkm::Vec< ParametricCoordType, 3 > &pcoords, CellShapeTag tag, typename FieldVecType::ComponentType &result)
Definition: CellInterpolate.h:58
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::make_Vec
constexpr 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:1250
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::ErrorCode::Success
@ Success
A successful operation.
CellShape.h
vtkm::CellShapeTagPolygon
Definition: CellShape.h:154
VecFromPortalPermute.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:250
ArrayHandleUniformPointCoordinates.h
vtkm::CellShapeTagVertex
Definition: CellShape.h:148
vtkm::VecTraits::GetNumberOfComponents
static constexpr vtkm::IdComponent GetNumberOfComponents(const T &)
Returns the number of components in the given vector.
Definition: VecTraits.h:94
vtkm::CellShapeTagPolyLine
Definition: CellShape.h:151
FunctorBase.h
vtkm::make_VecFromPortalPermute
VecFromPortalPermute< IndexVecType, PortalType > make_VecFromPortalPermute(const IndexVecType *index, const PortalType &portal)
Definition: VecFromPortalPermute.h:166
vtkm::CellShapeTagLine
Definition: CellShape.h:150
vtkm::CellShapeTagEmpty
Definition: CellShape.h:147
vtkm::CellShapeTagHexahedron
Definition: CellShape.h:159
vtkm::Vec
A short fixed-length array.
Definition: Types.h:357
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
An identifier that corresponds to one of the CELL_SHAPE_* identifiers.
Definition: CellShape.h:180
vtkm::ErrorCode::OperationOnEmptyCell
@ OperationOnEmptyCell
An operation was attempted on a cell with an empty shape.
vtkm::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:170
VecAxisAlignedPointCoordinates.h
vtkm::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints
The wrong number of points was provided for a given cell type.
vtkm::ErrorCode::InvalidShapeId
@ InvalidShapeId
A unknown shape identifier was encountered.