Viskores  1.0
CellInterpolate.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_Interpolate_h
19 #define viskores_exec_Interpolate_h
20 
21 #include <viskores/CellShape.h>
22 #include <viskores/ErrorCode.h>
27 
28 #include <lcl/lcl.h>
29 
30 #if (defined(VISKORES_GCC) || defined(VISKORES_CLANG))
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wconversion"
33 #endif // gcc || clang
34 
35 namespace viskores
36 {
37 namespace exec
38 {
39 
40 namespace internal
41 {
42 
43 template <typename VtkcCellShapeTag, typename FieldVecType, typename ParametricCoordType>
44 VISKORES_EXEC viskores::ErrorCode CellInterpolateImpl(VtkcCellShapeTag tag,
45  const FieldVecType& field,
46  const ParametricCoordType& pcoords,
47  typename FieldVecType::ComponentType& result)
48 {
49  if (tag.numberOfPoints() != field.GetNumberOfComponents())
50  {
51  result = { 0 };
53  }
54 
55  using FieldValueType = typename FieldVecType::ComponentType;
57  auto status =
58  lcl::interpolate(tag, lcl::makeFieldAccessorNestedSOA(field, numComponents), pcoords, result);
59  return viskores::internal::LclErrorToViskoresError(status);
60 }
61 
62 } // namespace internal
63 
64 //-----------------------------------------------------------------------------
65 template <typename FieldVecType, typename ParametricCoordType, typename CellShapeTag>
67  const FieldVecType& pointFieldValues,
69  CellShapeTag tag,
70  typename FieldVecType::ComponentType& result)
71 {
72  auto lclTag =
73  viskores::internal::make_LclCellShapeTag(tag, pointFieldValues.GetNumberOfComponents());
74  return internal::CellInterpolateImpl(lclTag, pointFieldValues, pcoords, result);
75 }
76 
77 //-----------------------------------------------------------------------------
78 template <typename FieldVecType, typename ParametricCoordType>
82  typename FieldVecType::ComponentType& result)
83 {
84  result = { 0 };
86 }
87 
88 //-----------------------------------------------------------------------------
89 template <typename FieldVecType, typename ParametricCoordType>
91  const FieldVecType& field,
94  typename FieldVecType::ComponentType& result)
95 {
96  const viskores::IdComponent numPoints = field.GetNumberOfComponents();
97  if (numPoints < 1)
98  {
99  result = { 0 };
101  }
102 
103  if (numPoints == 1)
104  {
105  return CellInterpolate(field, pcoords, viskores::CellShapeTagVertex(), result);
106  }
107 
108  using T = ParametricCoordType;
109 
110  T dt = 1 / static_cast<T>(numPoints - 1);
111  viskores::IdComponent idx = static_cast<viskores::IdComponent>(pcoords[0] / dt);
112  if (idx == numPoints - 1)
113  {
114  result = field[numPoints - 1];
116  }
117 
118  T pc = (pcoords[0] - static_cast<T>(idx) * dt) / dt;
119  return internal::CellInterpolateImpl(
120  lcl::Line{}, viskores::make_Vec(field[idx], field[idx + 1]), &pc, result);
121 }
122 
123 //-----------------------------------------------------------------------------
124 template <typename FieldVecType, typename ParametricCoordType>
126  const FieldVecType& field,
129  typename FieldVecType::ComponentType& result)
130 {
131  const viskores::IdComponent numPoints = field.GetNumberOfComponents();
132  if (numPoints < 1)
133  {
134  result = { 0 };
136  }
137 
138  switch (numPoints)
139  {
140  case 1:
141  return CellInterpolate(field, pcoords, viskores::CellShapeTagVertex(), result);
142  case 2:
143  return CellInterpolate(field, pcoords, viskores::CellShapeTagLine(), result);
144  default:
145  return internal::CellInterpolateImpl(lcl::Polygon(numPoints), field, pcoords, result);
146  }
147 }
148 
149 //-----------------------------------------------------------------------------
150 template <typename ParametricCoordType>
155  viskores::Vec3f& result)
156 {
157  return internal::CellInterpolateImpl(lcl::Pixel{}, field, pcoords, result);
158 }
159 
160 //-----------------------------------------------------------------------------
161 template <typename ParametricCoordType>
166  viskores::Vec3f& result)
167 {
168  return internal::CellInterpolateImpl(lcl::Voxel{}, field, pcoords, result);
169 }
170 
171 //-----------------------------------------------------------------------------
185 template <typename FieldVecType, typename ParametricCoordType>
187  const FieldVecType& pointFieldValues,
188  const viskores::Vec<ParametricCoordType, 3>& parametricCoords,
190  typename FieldVecType::ComponentType& result)
191 {
192  viskores::ErrorCode status;
193  switch (shape.Id)
194  {
196  status = CellInterpolate(pointFieldValues, parametricCoords, CellShapeTag(), result));
197  default:
198  result = { 0 };
200  }
201  return status;
202 }
203 
204 //-----------------------------------------------------------------------------
220 template <typename IndicesVecType,
221  typename FieldPortalType,
222  typename ParametricCoordType,
223  typename CellShapeTag>
225  const IndicesVecType& pointIndices,
226  const FieldPortalType& pointFieldPortal,
227  const viskores::Vec<ParametricCoordType, 3>& parametricCoords,
228  CellShapeTag shape,
229  typename FieldPortalType::ValueType& result)
230 {
231  return CellInterpolate(viskores::make_VecFromPortalPermute(&pointIndices, pointFieldPortal),
232  parametricCoords,
233  shape,
234  result);
235 }
236 
237 }
238 } // namespace viskores::exec
239 
240 #if (defined(VISKORES_GCC) || defined(VISKORES_CLANG))
241 #pragma GCC diagnostic pop
242 #endif // gcc || clang
243 
244 #endif //viskores_exec_Interpolate_h
viskores::CellShapeTagGeneric::Id
viskores::UInt8 Id
An identifier that corresponds to one of the CELL_SHAPE_* identifiers.
Definition: CellShape.h:188
viskores::VecAxisAlignedPointCoordinates
An implicit vector for point coordinates in axis aligned cells.
Definition: VecAxisAlignedPointCoordinates.h:86
viskores::CellShapeTagLine
Definition: CellShape.h:158
viskores::CellShapeTagHexahedron
Definition: CellShape.h:167
viskoresGenericCellShapeMacro
#define viskoresGenericCellShapeMacro(call)
A macro used in a switch statement to determine cell shape.
Definition: CellShape.h:257
viskores::ErrorCode
ErrorCode
Identifies whether an operation was successful or what type of error it had.
Definition: ErrorCode.h:36
viskores::ErrorCode::InvalidNumberOfPoints
@ InvalidNumberOfPoints
The wrong number of points was provided for a given cell type.
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
CellShape.h
VecFromPortalPermute.h
viskores::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:178
ErrorCode.h
viskores::ErrorCode::InvalidShapeId
@ InvalidShapeId
A unknown shape identifier was encountered.
viskores::Line
Ray< CoordType, Dim, true > Line
Lines are two-sided rays:
Definition: Geometry.h:338
viskores::CellShapeTagEmpty
Definition: CellShape.h:155
ArrayHandleUniformPointCoordinates.h
viskores::make_VecFromPortalPermute
VecFromPortalPermute< IndexVecType, PortalType > make_VecFromPortalPermute(const IndexVecType *index, const PortalType &portal)
Definition: VecFromPortalPermute.h:181
viskores::VecTraits::GetNumberOfComponents
static constexpr viskores::IdComponent GetNumberOfComponents(const T &)
Returns the number of components in the given vector.
Definition: VecTraits.h:102
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
FunctorBase.h
viskores::CellShapeTagVertex
Definition: CellShape.h:156
viskores::CellShapeTagQuad
Definition: CellShape.h:164
viskores::ErrorCode::OperationOnEmptyCell
@ OperationOnEmptyCell
An operation was attempted on a cell with an empty shape.
viskores::make_Vec
constexpr viskores::Vec< T, viskores::IdComponent(sizeof...(Ts)+1)> make_Vec(T value0, Ts &&... args)
Initializes and returns a Vec containing all the arguments.
Definition: Types.h:1262
viskores::CellShapeTagPolygon
Definition: CellShape.h:162
viskores::ErrorCode::Success
@ Success
A successful operation.
viskores::CellShapeTagPolyLine
Definition: CellShape.h:159
VecAxisAlignedPointCoordinates.h
viskores::Vec
A short fixed-length array.
Definition: Types.h:365
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59
viskores::exec::CellInterpolate
viskores::ErrorCode CellInterpolate(const FieldVecType &pointFieldValues, const viskores::Vec< ParametricCoordType, 3 > &pcoords, CellShapeTag tag, typename FieldVecType::ComponentType &result)
Definition: CellInterpolate.h:66