2015-08-19 22:04:38 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-08-19 22:04:38 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_exec_Interpolate_h
|
|
|
|
#define vtk_m_exec_Interpolate_h
|
|
|
|
|
|
|
|
#include <vtkm/CellShape.h>
|
2020-03-12 23:38:27 +00:00
|
|
|
#include <vtkm/ErrorCode.h>
|
2017-07-05 19:58:35 +00:00
|
|
|
#include <vtkm/VecAxisAlignedPointCoordinates.h>
|
2015-08-20 03:18:54 +00:00
|
|
|
#include <vtkm/exec/FunctorBase.h>
|
2015-08-19 22:04:38 +00:00
|
|
|
|
2019-10-07 19:38:36 +00:00
|
|
|
#include <lcl/lcl.h>
|
2019-09-25 01:22:10 +00:00
|
|
|
|
2018-05-02 13:23:07 +00:00
|
|
|
#if (defined(VTKM_GCC) || defined(VTKM_CLANG))
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wconversion"
|
|
|
|
#endif // gcc || clang
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace exec
|
|
|
|
{
|
2015-08-19 22:04:38 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
2015-08-27 06:09:06 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename VtkcCellShapeTag, typename FieldVecType, typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellInterpolateImpl(VtkcCellShapeTag tag,
|
|
|
|
const FieldVecType& field,
|
|
|
|
const ParametricCoordType& pcoords,
|
|
|
|
typename FieldVecType::ComponentType& result)
|
2015-08-27 06:09:06 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
if (tag.numberOfPoints() != field.GetNumberOfComponents())
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
2015-08-27 06:09:06 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
using FieldValueType = typename FieldVecType::ComponentType;
|
|
|
|
IdComponent numComponents = vtkm::VecTraits<FieldValueType>::GetNumberOfComponents(field[0]);
|
|
|
|
auto status =
|
2019-10-07 19:38:36 +00:00
|
|
|
lcl::interpolate(tag, lcl::makeFieldAccessorNestedSOA(field, numComponents), pcoords, result);
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::internal::LclErrorToVtkmError(status);
|
2015-08-27 06:09:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
} // namespace internal
|
|
|
|
|
2015-08-19 22:04:38 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType, typename CellShapeTag>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& pointFieldValues,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
CellShapeTag tag,
|
|
|
|
typename FieldVecType::ComponentType& result)
|
2015-08-19 22:04:38 +00:00
|
|
|
{
|
2020-03-11 23:56:05 +00:00
|
|
|
auto lclTag = vtkm::internal::make_LclCellShapeTag(tag, pointFieldValues.GetNumberOfComponents());
|
2020-03-12 23:38:27 +00:00
|
|
|
return internal::CellInterpolateImpl(lclTag, pointFieldValues, pcoords, result);
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType&,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>&,
|
|
|
|
vtkm::CellShapeTagEmpty,
|
2020-03-14 01:20:45 +00:00
|
|
|
typename FieldVecType::ComponentType& result)
|
2015-09-01 21:29:07 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::OperationOnEmptyCell;
|
2015-09-01 21:29:07 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 17:35:35 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& field,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagPolyLine,
|
|
|
|
typename FieldVecType::ComponentType& result)
|
2019-05-17 17:35:35 +00:00
|
|
|
{
|
|
|
|
const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints < 1)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
2019-05-17 17:35:35 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
if (numPoints == 1)
|
2019-05-17 17:35:35 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
return CellInterpolate(field, pcoords, vtkm::CellShapeTagVertex(), result);
|
2019-05-17 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 16:40:45 +00:00
|
|
|
using T = ParametricCoordType;
|
|
|
|
|
|
|
|
T dt = 1 / static_cast<T>(numPoints - 1);
|
2019-05-17 17:35:35 +00:00
|
|
|
vtkm::IdComponent idx = static_cast<vtkm::IdComponent>(pcoords[0] / dt);
|
|
|
|
if (idx == numPoints - 1)
|
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
result = field[numPoints - 1];
|
|
|
|
return vtkm::ErrorCode::Success;
|
2019-05-17 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
T pc = (pcoords[0] - static_cast<T>(idx) * dt) / dt;
|
|
|
|
return internal::CellInterpolateImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
lcl::Line{}, vtkm::make_Vec(field[idx], field[idx + 1]), &pc, result);
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& field,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagPolygon,
|
|
|
|
typename FieldVecType::ComponentType& result)
|
2015-08-19 22:04:38 +00:00
|
|
|
{
|
2015-08-27 06:09:06 +00:00
|
|
|
const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints < 1)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
|
|
|
|
2015-08-19 22:04:38 +00:00
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2020-03-12 23:38:27 +00:00
|
|
|
return CellInterpolate(field, pcoords, vtkm::CellShapeTagVertex(), result);
|
2015-08-19 22:04:38 +00:00
|
|
|
case 2:
|
2020-03-12 23:38:27 +00:00
|
|
|
return CellInterpolate(field, pcoords, vtkm::CellShapeTagLine(), result);
|
2019-09-25 01:22:10 +00:00
|
|
|
default:
|
2020-03-12 23:38:27 +00:00
|
|
|
return internal::CellInterpolateImpl(lcl::Polygon(numPoints), field, pcoords, result);
|
2015-08-27 06:09:06 +00:00
|
|
|
}
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const vtkm::VecAxisAlignedPointCoordinates<2>& field,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagQuad,
|
|
|
|
vtkm::Vec3f& result)
|
2015-08-19 22:04:38 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
return internal::CellInterpolateImpl(lcl::Pixel{}, field, pcoords, result);
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const vtkm::VecAxisAlignedPointCoordinates<3>& field,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagHexahedron,
|
|
|
|
vtkm::Vec3f& result)
|
|
|
|
{
|
|
|
|
return internal::CellInterpolateImpl(lcl::Voxel{}, field, pcoords, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \brief Interpolate a point field in a cell.
|
|
|
|
///
|
|
|
|
/// Given the point field values for each node and the parametric coordinates
|
|
|
|
/// of a point within the cell, interpolates the field to that point.
|
|
|
|
///
|
2024-03-12 19:06:20 +00:00
|
|
|
/// @param[in] pointFieldValues A list of field values for each point in the cell. This
|
|
|
|
/// usually comes from a `FieldInPoint` argument in a
|
|
|
|
/// `vtkm::worklet::WorkletVisitCellsWithPoints`.
|
|
|
|
/// @param[in] parametricCoords The parametric coordinates where you want to get the interpolated
|
|
|
|
/// field value for.
|
|
|
|
/// @param[in] shape A tag of type `CellShapeTag*` to identify the shape of the cell.
|
|
|
|
/// This method is overloaded for different shape types.
|
|
|
|
/// @param[out] result Value to store the interpolated field.
|
2020-03-12 23:38:27 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
|
|
|
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& pointFieldValues,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& parametricCoords,
|
|
|
|
vtkm::CellShapeTagGeneric shape,
|
|
|
|
typename FieldVecType::ComponentType& result)
|
2015-08-19 22:04:38 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkm::ErrorCode status;
|
2020-03-12 23:38:27 +00:00
|
|
|
switch (shape.Id)
|
|
|
|
{
|
|
|
|
vtkmGenericCellShapeMacro(
|
2020-03-14 01:20:45 +00:00
|
|
|
status = CellInterpolate(pointFieldValues, parametricCoords, CellShapeTag(), result));
|
2020-03-12 23:38:27 +00:00
|
|
|
default:
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
|
|
|
status = vtkm::ErrorCode::InvalidShapeId;
|
2020-03-12 23:38:27 +00:00
|
|
|
}
|
2020-03-14 01:20:45 +00:00
|
|
|
return status;
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
2020-03-11 23:56:05 +00:00
|
|
|
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::exec
|
|
|
|
|
2018-05-02 13:23:07 +00:00
|
|
|
#if (defined(VTKM_GCC) || defined(VTKM_CLANG))
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif // gcc || clang
|
|
|
|
|
2015-08-19 22:04:38 +00:00
|
|
|
#endif //vtk_m_exec_Interpolate_h
|