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
|
|
|
|
|
2016-04-20 21:41:14 +00:00
|
|
|
#include <vtkm/Assert.h>
|
2015-08-19 22:04:38 +00:00
|
|
|
#include <vtkm/CellShape.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>
|
|
|
|
VTKM_EXEC typename FieldVecType::ComponentType CellInterpolateImpl(
|
|
|
|
VtkcCellShapeTag tag,
|
|
|
|
const FieldVecType& field,
|
|
|
|
const ParametricCoordType& pcoords,
|
2020-03-11 23:56:05 +00:00
|
|
|
const vtkm::exec::FunctorBase* worklet = nullptr)
|
2015-08-27 06:09:06 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
VTKM_ASSERT(tag.numberOfPoints() == field.GetNumberOfComponents());
|
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]);
|
|
|
|
FieldValueType result(0);
|
|
|
|
auto status =
|
2019-10-07 19:38:36 +00:00
|
|
|
lcl::interpolate(tag, lcl::makeFieldAccessorNestedSOA(field, numComponents), pcoords, result);
|
2020-03-11 23:56:05 +00:00
|
|
|
if ((status != lcl::ErrorCode::SUCCESS) && (worklet != nullptr))
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2020-03-11 23:56:05 +00:00
|
|
|
worklet->RaiseError(lcl::errorString(status));
|
2017-05-18 14:29:41 +00:00
|
|
|
}
|
2019-09-25 01:22:10 +00:00
|
|
|
return result;
|
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
|
|
|
/// \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.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
|
|
|
VTKM_EXEC typename FieldVecType::ComponentType CellInterpolate(
|
2017-05-26 17:53:28 +00:00
|
|
|
const FieldVecType& pointFieldValues,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& parametricCoords,
|
|
|
|
vtkm::CellShapeTagGeneric shape,
|
2020-03-11 23:56:05 +00:00
|
|
|
const vtkm::exec::FunctorBase* worklet = nullptr)
|
2015-08-19 22:04:38 +00:00
|
|
|
{
|
2016-03-31 14:37:48 +00:00
|
|
|
typename FieldVecType::ComponentType result;
|
2015-08-19 22:04:38 +00:00
|
|
|
switch (shape.Id)
|
|
|
|
{
|
|
|
|
vtkmGenericCellShapeMacro(
|
2017-05-18 14:29:41 +00:00
|
|
|
result = CellInterpolate(pointFieldValues, parametricCoords, CellShapeTag(), worklet));
|
|
|
|
default:
|
2020-03-11 23:56:05 +00:00
|
|
|
if (worklet)
|
|
|
|
{
|
|
|
|
worklet->RaiseError("Unknown cell shape sent to interpolate.");
|
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
return typename FieldVecType::ComponentType();
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
2016-03-31 14:37:48 +00:00
|
|
|
return result;
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType, typename CellShapeTag>
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_EXEC typename FieldVecType::ComponentType CellInterpolate(
|
2017-05-26 17:53:28 +00:00
|
|
|
const FieldVecType& pointFieldValues,
|
2019-09-25 01:22:10 +00:00
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
CellShapeTag tag,
|
2020-03-11 23:56:05 +00:00
|
|
|
const vtkm::exec::FunctorBase* worklet = nullptr)
|
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());
|
2019-10-07 19:38:36 +00:00
|
|
|
return internal::CellInterpolateImpl(lclTag, pointFieldValues, pcoords, worklet);
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
|
|
|
VTKM_EXEC typename FieldVecType::ComponentType CellInterpolate(
|
2019-09-25 01:22:10 +00:00
|
|
|
const FieldVecType&,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>&,
|
|
|
|
vtkm::CellShapeTagEmpty,
|
2020-03-11 23:56:05 +00:00
|
|
|
const vtkm::exec::FunctorBase* worklet = nullptr)
|
2015-09-01 21:29:07 +00:00
|
|
|
{
|
2020-03-11 23:56:05 +00:00
|
|
|
if (worklet)
|
|
|
|
{
|
|
|
|
worklet->RaiseError("Attempted to interpolate an empty cell.");
|
|
|
|
}
|
2019-09-25 01:22:10 +00:00
|
|
|
return typename FieldVecType::ComponentType();
|
2015-09-01 21:29:07 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 17:35:35 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
|
|
|
VTKM_EXEC typename FieldVecType::ComponentType CellInterpolate(
|
|
|
|
const FieldVecType& field,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagPolyLine,
|
2020-03-11 23:56:05 +00:00
|
|
|
const vtkm::exec::FunctorBase* worklet = nullptr)
|
2019-05-17 17:35:35 +00:00
|
|
|
{
|
|
|
|
const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
|
|
|
VTKM_ASSERT(numPoints >= 1);
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
if (numPoints == 1)
|
2019-05-17 17:35:35 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return CellInterpolate(field, pcoords, vtkm::CellShapeTagVertex(), worklet);
|
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)
|
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return field[numPoints - 1];
|
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(
|
2019-10-07 19:38:36 +00:00
|
|
|
lcl::Line{}, vtkm::make_Vec(field[idx], field[idx + 1]), &pc, worklet);
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FieldVecType, typename ParametricCoordType>
|
|
|
|
VTKM_EXEC typename FieldVecType::ComponentType CellInterpolate(
|
2017-05-26 17:53:28 +00:00
|
|
|
const FieldVecType& field,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagPolygon,
|
2020-03-11 23:56:05 +00:00
|
|
|
const vtkm::exec::FunctorBase* worklet = nullptr)
|
2015-08-19 22:04:38 +00:00
|
|
|
{
|
2015-08-27 06:09:06 +00:00
|
|
|
const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(numPoints > 0);
|
2015-08-19 22:04:38 +00:00
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2017-05-18 14:29:41 +00:00
|
|
|
return CellInterpolate(field, pcoords, vtkm::CellShapeTagVertex(), worklet);
|
2015-08-19 22:04:38 +00:00
|
|
|
case 2:
|
2017-05-18 14:29:41 +00:00
|
|
|
return CellInterpolate(field, pcoords, vtkm::CellShapeTagLine(), worklet);
|
2019-09-25 01:22:10 +00:00
|
|
|
default:
|
2019-10-07 19:38:36 +00:00
|
|
|
return internal::CellInterpolateImpl(lcl::Polygon(numPoints), field, pcoords, worklet);
|
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>
|
2019-07-31 16:20:38 +00:00
|
|
|
VTKM_EXEC vtkm::Vec3f CellInterpolate(const vtkm::VecAxisAlignedPointCoordinates<2>& field,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagQuad,
|
2020-03-11 23:56:05 +00:00
|
|
|
const vtkm::exec::FunctorBase* worklet = nullptr)
|
2015-08-19 22:04:38 +00:00
|
|
|
{
|
2019-10-07 19:38:36 +00:00
|
|
|
return internal::CellInterpolateImpl(lcl::Pixel{}, field, pcoords, worklet);
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2019-07-31 16:20:38 +00:00
|
|
|
VTKM_EXEC vtkm::Vec3f CellInterpolate(const vtkm::VecAxisAlignedPointCoordinates<3>& field,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagHexahedron,
|
2020-03-11 23:56:05 +00:00
|
|
|
const vtkm::exec::FunctorBase* worklet = nullptr)
|
2015-08-19 22:04:38 +00:00
|
|
|
{
|
2019-10-07 19:38:36 +00:00
|
|
|
return internal::CellInterpolateImpl(lcl::Voxel{}, field, pcoords, worklet);
|
2015-08-19 22:04:38 +00:00
|
|
|
}
|
2020-03-11 23:56:05 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <typename FieldVecType, typename ParametricCoordType, typename CellShapeTag>
|
|
|
|
VTKM_EXEC typename FieldVecType::ComponentType CellInterpolate(
|
|
|
|
const FieldVecType& pointFieldValues,
|
|
|
|
const vtkm::Vec<ParametricCoordType, 3>& pcoords,
|
|
|
|
CellShapeTag shape,
|
|
|
|
const vtkm::exec::FunctorBase& worklet)
|
|
|
|
{
|
|
|
|
return CellInterpolate(pointFieldValues, pcoords, shape, &worklet);
|
|
|
|
}
|
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
|