2015-08-20 03:18:54 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-08-20 03:18:54 +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_ParametricCoordinates_h
|
|
|
|
#define vtk_m_exec_ParametricCoordinates_h
|
|
|
|
|
2016-04-20 21:41:14 +00:00
|
|
|
#include <vtkm/Assert.h>
|
2015-08-20 03:18:54 +00:00
|
|
|
#include <vtkm/CellShape.h>
|
2017-07-05 19:58:35 +00:00
|
|
|
#include <vtkm/VecAxisAlignedPointCoordinates.h>
|
2015-08-26 04:15:44 +00:00
|
|
|
#include <vtkm/exec/CellInterpolate.h>
|
2015-08-20 03:18:54 +00:00
|
|
|
#include <vtkm/exec/FunctorBase.h>
|
2018-01-30 15:27:31 +00:00
|
|
|
#include <vtkm/exec/internal/FastVec.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/internal/Assume.h>
|
2015-08-20 03:18:54 +00:00
|
|
|
|
2019-10-07 19:38:36 +00:00
|
|
|
#include <lcl/lcl.h>
|
2019-09-25 01:22:10 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace exec
|
|
|
|
{
|
2015-08-20 03:18:54 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename ParametricCoordType, typename CellShapeTag>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesCenter(
|
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
CellShapeTag,
|
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-10-07 19:38:36 +00:00
|
|
|
auto lclTag = typename vtkm::internal::CellShapeTagVtkmToVtkc<CellShapeTag>::Type{};
|
2019-09-25 01:22:10 +00:00
|
|
|
|
|
|
|
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints != lclTag.numberOfPoints())
|
|
|
|
{
|
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vtkm::internal::LclErrorToVtkmError(lcl::parametricCenter(lclTag, pcoords));
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesCenter(
|
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::CellShapeTagEmpty,
|
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints != 0)
|
|
|
|
{
|
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
|
|
|
return vtkm::ErrorCode::Success;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesCenter(
|
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::CellShapeTagVertex,
|
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints != 1)
|
|
|
|
{
|
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
|
|
|
return vtkm::ErrorCode::Success;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 17:35:35 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesCenter(
|
2020-03-11 23:56:05 +00:00
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::CellShapeTagPolyLine,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2019-05-17 17:35:35 +00:00
|
|
|
{
|
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2020-03-12 23:38:27 +00:00
|
|
|
return ParametricCoordinatesCenter(numPoints, vtkm::CellShapeTagVertex(), pcoords);
|
2019-05-17 17:35:35 +00:00
|
|
|
case 2:
|
2020-03-12 23:38:27 +00:00
|
|
|
return ParametricCoordinatesCenter(numPoints, vtkm::CellShapeTagLine(), pcoords);
|
2019-05-17 17:35:35 +00:00
|
|
|
}
|
|
|
|
pcoords[0] = 0.5;
|
|
|
|
pcoords[1] = 0;
|
|
|
|
pcoords[2] = 0;
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::Success;
|
2019-05-17 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesCenter(
|
2020-03-11 23:56:05 +00:00
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::CellShapeTagPolygon,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints < 1)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
pcoords = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2020-03-12 23:38:27 +00:00
|
|
|
return ParametricCoordinatesCenter(numPoints, vtkm::CellShapeTagVertex(), pcoords);
|
2015-08-20 03:18:54 +00:00
|
|
|
case 2:
|
2020-03-12 23:38:27 +00:00
|
|
|
return ParametricCoordinatesCenter(numPoints, vtkm::CellShapeTagLine(), pcoords);
|
2015-08-20 03:18:54 +00:00
|
|
|
default:
|
2019-09-25 01:22:10 +00:00
|
|
|
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::internal::LclErrorToVtkmError(
|
|
|
|
lcl::parametricCenter(lcl::Polygon(numPoints), pcoords));
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// Returns the parametric center of the given cell shape with the given number
|
|
|
|
/// of points.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesCenter(
|
2020-03-11 23:56:05 +00:00
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::CellShapeTagGeneric shape,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkm::ErrorCode status;
|
2015-08-20 03:18:54 +00:00
|
|
|
switch (shape.Id)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkmGenericCellShapeMacro(status =
|
|
|
|
ParametricCoordinatesCenter(numPoints, CellShapeTag(), pcoords));
|
2015-08-20 03:18:54 +00:00
|
|
|
default:
|
2020-03-14 01:20:45 +00:00
|
|
|
pcoords = { 0 };
|
|
|
|
status = vtkm::ErrorCode::InvalidShapeId;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
2020-03-14 01:20:45 +00:00
|
|
|
return status;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename ParametricCoordType, typename CellShapeTag>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesPoint(
|
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::IdComponent pointIndex,
|
|
|
|
CellShapeTag,
|
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
2019-10-07 19:38:36 +00:00
|
|
|
auto lclTag = typename vtkm::internal::CellShapeTagVtkmToVtkc<CellShapeTag>::Type{};
|
2019-09-25 01:22:10 +00:00
|
|
|
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints != lclTag.numberOfPoints())
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
pcoords = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
|
|
|
if ((pointIndex < 0) || (pointIndex >= numPoints))
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
pcoords = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidPointId;
|
|
|
|
}
|
2019-09-25 01:22:10 +00:00
|
|
|
|
|
|
|
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::internal::LclErrorToVtkmError(lcl::parametricPoint(lclTag, pointIndex, pcoords));
|
2019-09-25 01:22:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesPoint(
|
2020-03-11 23:56:05 +00:00
|
|
|
vtkm::IdComponent,
|
|
|
|
vtkm::IdComponent,
|
|
|
|
vtkm::CellShapeTagEmpty,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2020-03-11 23:56:05 +00:00
|
|
|
{
|
2015-08-28 04:13:19 +00:00
|
|
|
pcoords[0] = pcoords[1] = pcoords[2] = 0;
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::OperationOnEmptyCell;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesPoint(
|
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::IdComponent pointIndex,
|
|
|
|
vtkm::CellShapeTagVertex,
|
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints != 1)
|
|
|
|
{
|
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
|
|
|
if (pointIndex != 0)
|
|
|
|
{
|
|
|
|
return vtkm::ErrorCode::InvalidPointId;
|
|
|
|
}
|
|
|
|
return vtkm::ErrorCode::Success;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 17:35:35 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesPoint(
|
2020-03-11 23:56:05 +00:00
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::IdComponent pointIndex,
|
|
|
|
vtkm::CellShapeTagPolyLine,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2019-05-17 17:35:35 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
if (numPoints < 1)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
pcoords = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
2019-05-17 17:35:35 +00:00
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2020-03-12 23:38:27 +00:00
|
|
|
return ParametricCoordinatesPoint(numPoints, pointIndex, vtkm::CellShapeTagVertex(), pcoords);
|
2019-05-17 17:35:35 +00:00
|
|
|
case 2:
|
2020-03-12 23:38:27 +00:00
|
|
|
return ParametricCoordinatesPoint(numPoints, pointIndex, vtkm::CellShapeTagLine(), pcoords);
|
2019-05-17 17:35:35 +00:00
|
|
|
}
|
|
|
|
pcoords[0] =
|
|
|
|
static_cast<ParametricCoordType>(pointIndex) / static_cast<ParametricCoordType>(numPoints - 1);
|
|
|
|
pcoords[1] = 0;
|
|
|
|
pcoords[2] = 0;
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::Success;
|
2019-05-17 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesPoint(
|
2020-03-11 23:56:05 +00:00
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::IdComponent pointIndex,
|
|
|
|
vtkm::CellShapeTagPolygon,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2020-03-12 23:38:27 +00:00
|
|
|
return ParametricCoordinatesPoint(numPoints, pointIndex, vtkm::CellShapeTagVertex(), pcoords);
|
2015-08-20 03:18:54 +00:00
|
|
|
case 2:
|
2020-03-12 23:38:27 +00:00
|
|
|
return ParametricCoordinatesPoint(numPoints, pointIndex, vtkm::CellShapeTagLine(), pcoords);
|
2019-09-25 01:22:10 +00:00
|
|
|
default:
|
|
|
|
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::internal::LclErrorToVtkmError(
|
|
|
|
lcl::parametricPoint(lcl::Polygon(numPoints), pointIndex, pcoords));
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// Returns the parametric coordinate of a cell point of the given shape with
|
|
|
|
/// the given number of points.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ParametricCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesPoint(
|
2020-03-11 23:56:05 +00:00
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::IdComponent pointIndex,
|
|
|
|
vtkm::CellShapeTagGeneric shape,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkm::ErrorCode status;
|
2019-09-25 01:22:10 +00:00
|
|
|
switch (shape.Id)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
vtkmGenericCellShapeMacro(
|
2020-03-14 01:20:45 +00:00
|
|
|
status = ParametricCoordinatesPoint(numPoints, pointIndex, CellShapeTag(), pcoords));
|
2019-09-25 01:22:10 +00:00
|
|
|
default:
|
|
|
|
pcoords[0] = pcoords[1] = pcoords[2] = 0;
|
2020-03-14 01:20:45 +00:00
|
|
|
status = vtkm::ErrorCode::InvalidShapeId;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
2020-03-14 01:20:45 +00:00
|
|
|
return status;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
|
2020-03-11 23:56:05 +00:00
|
|
|
template <typename LclCellShapeTag, typename WorldCoordVector, typename PCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesToWorldCoordinatesImpl(
|
|
|
|
LclCellShapeTag tag,
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const PCoordType& pcoords,
|
|
|
|
typename WorldCoordVector::ComponentType& wcoords)
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::internal::LclErrorToVtkmError(lcl::parametricToWorld(
|
|
|
|
tag, lcl::makeFieldAccessorNestedSOA(pointWCoords, 3), pcoords, wcoords));
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
template <typename WorldCoordVector, typename PCoordType, typename CellShapeTag>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesToWorldCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const vtkm::Vec<PCoordType, 3>& pcoords,
|
|
|
|
CellShapeTag shape,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
auto numPoints = pointWCoords.GetNumberOfComponents();
|
|
|
|
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::internal::make_LclCellShapeTag(shape, numPoints), pointWCoords, pcoords, result);
|
2019-09-25 01:22:10 +00:00
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename WorldCoordVector, typename PCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesToWorldCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const vtkm::Vec<PCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagEmpty empty,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::exec::CellInterpolate(pointWCoords, pcoords, empty, result);
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename WorldCoordVector, typename PCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesToWorldCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const vtkm::Vec<PCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagPolyLine polyLine,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::exec::CellInterpolate(pointWCoords, pcoords, polyLine, result);
|
2019-09-25 01:22:10 +00:00
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename WorldCoordVector, typename PCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesToWorldCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const vtkm::Vec<PCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagPolygon,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
|
|
|
auto numPoints = pointWCoords.GetNumberOfComponents();
|
|
|
|
switch (numPoints)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
case 1:
|
2019-09-25 01:22:10 +00:00
|
|
|
return ParametricCoordinatesToWorldCoordinates(
|
2020-03-12 23:38:27 +00:00
|
|
|
pointWCoords, pcoords, vtkm::CellShapeTagVertex{}, result);
|
2017-05-18 14:29:41 +00:00
|
|
|
case 2:
|
2019-09-25 01:22:10 +00:00
|
|
|
return ParametricCoordinatesToWorldCoordinates(
|
2020-03-12 23:38:27 +00:00
|
|
|
pointWCoords, pcoords, vtkm::CellShapeTagLine{}, result);
|
2019-09-25 01:22:10 +00:00
|
|
|
default:
|
|
|
|
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
lcl::Polygon(numPoints), pointWCoords, pcoords, result);
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename WorldCoordVector, typename PCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesToWorldCoordinates(
|
|
|
|
const vtkm::VecAxisAlignedPointCoordinates<2>& pointWCoords,
|
|
|
|
const vtkm::Vec<PCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagQuad,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
lcl::Pixel{}, pointWCoords, pcoords, result);
|
2019-09-25 01:22:10 +00:00
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename WorldCoordVector, typename PCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesToWorldCoordinates(
|
|
|
|
const vtkm::VecAxisAlignedPointCoordinates<3>& pointWCoords,
|
|
|
|
const vtkm::Vec<PCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagHexahedron,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
|
|
|
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
lcl::Voxel{}, pointWCoords, pcoords, result);
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-09-25 01:22:10 +00:00
|
|
|
/// Returns the world coordinate corresponding to the given parametric coordinate of a cell.
|
2015-08-20 03:18:54 +00:00
|
|
|
///
|
2019-09-25 01:22:10 +00:00
|
|
|
template <typename WorldCoordVector, typename PCoordType>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesToWorldCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const vtkm::Vec<PCoordType, 3>& pcoords,
|
|
|
|
vtkm::CellShapeTagGeneric shape,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkm::ErrorCode status;
|
2015-08-20 03:18:54 +00:00
|
|
|
switch (shape.Id)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkmGenericCellShapeMacro(status = ParametricCoordinatesToWorldCoordinates(
|
|
|
|
pointWCoords, pcoords, CellShapeTag(), result));
|
2015-08-20 03:18:54 +00:00
|
|
|
default:
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
|
|
|
status = vtkm::ErrorCode::InvalidShapeId;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
2020-03-14 01:20:45 +00:00
|
|
|
return status;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
namespace internal
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
|
2020-03-12 23:38:27 +00:00
|
|
|
template <typename LclCellShapeTag, typename WorldCoordVector>
|
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinatesImpl(
|
|
|
|
LclCellShapeTag tag,
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const typename WorldCoordVector::ComponentType& wcoords,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
if (pointWCoords.GetNumberOfComponents() != tag.numberOfPoints())
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
2019-09-25 01:22:10 +00:00
|
|
|
}
|
2020-03-12 23:38:27 +00:00
|
|
|
|
|
|
|
result = vtkm::TypeTraits<typename WorldCoordVector::ComponentType>::ZeroInitialization();
|
|
|
|
return vtkm::internal::LclErrorToVtkmError(
|
|
|
|
lcl::worldToParametric(tag, lcl::makeFieldAccessorNestedSOA(pointWCoords, 3), wcoords, result));
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
template <typename WorldCoordVector, typename CellShapeTag>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const typename WorldCoordVector::ComponentType& wcoords,
|
|
|
|
CellShapeTag shape,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2015-08-26 04:15:44 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
auto numPoints = pointWCoords.GetNumberOfComponents();
|
|
|
|
return internal::WorldCoordinatesToParametricCoordinatesImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::internal::make_LclCellShapeTag(shape, numPoints), pointWCoords, wcoords, result);
|
2015-08-26 04:15:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 15:27:31 +00:00
|
|
|
template <typename WorldCoordVector>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
|
|
|
const WorldCoordVector&,
|
|
|
|
const typename WorldCoordVector::ComponentType&,
|
|
|
|
vtkm::CellShapeTagEmpty,
|
2020-03-14 01:20:45 +00:00
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2018-01-30 15:27:31 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::OperationOnEmptyCell;
|
2018-01-30 15:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename WorldCoordVector>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const typename WorldCoordVector::ComponentType&,
|
|
|
|
vtkm::CellShapeTagVertex,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2018-01-30 15:27:31 +00:00
|
|
|
{
|
2020-03-12 23:38:27 +00:00
|
|
|
if (pointWCoords.GetNumberOfComponents() != 1)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
2020-03-12 23:38:27 +00:00
|
|
|
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
|
|
|
}
|
|
|
|
result = typename WorldCoordVector::ComponentType(0, 0, 0);
|
|
|
|
return vtkm::ErrorCode::Success;
|
2018-01-30 15:27:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 17:35:35 +00:00
|
|
|
template <typename WorldCoordVector>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const typename WorldCoordVector::ComponentType& wcoords,
|
|
|
|
vtkm::CellShapeTagPolyLine,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2019-05-17 17:35:35 +00:00
|
|
|
{
|
|
|
|
vtkm::IdComponent numPoints = pointWCoords.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
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return WorldCoordinatesToParametricCoordinates(
|
2020-03-12 23:38:27 +00:00
|
|
|
pointWCoords, wcoords, vtkm::CellShapeTagVertex(), result);
|
2019-05-17 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 15:42:49 +00:00
|
|
|
using Vector3 = typename WorldCoordVector::ComponentType;
|
|
|
|
using T = typename Vector3::ComponentType;
|
|
|
|
|
|
|
|
//Find the closest vertex to the point.
|
2019-05-17 17:35:35 +00:00
|
|
|
vtkm::IdComponent idx = 0;
|
2019-05-22 15:42:49 +00:00
|
|
|
Vector3 vec = pointWCoords[0] - wcoords;
|
|
|
|
T minDistSq = vtkm::Dot(vec, vec);
|
2019-05-17 17:35:35 +00:00
|
|
|
for (vtkm::IdComponent i = 1; i < numPoints; i++)
|
|
|
|
{
|
2019-05-22 15:42:49 +00:00
|
|
|
vec = pointWCoords[i] - wcoords;
|
|
|
|
T d = vtkm::Dot(vec, vec);
|
|
|
|
|
2019-05-17 17:35:35 +00:00
|
|
|
if (d < minDistSq)
|
|
|
|
{
|
|
|
|
idx = i;
|
|
|
|
minDistSq = d;
|
|
|
|
}
|
|
|
|
}
|
2019-05-22 15:42:49 +00:00
|
|
|
|
|
|
|
//Find the right segment, and the parameterization along that segment.
|
|
|
|
//Closest to 0, so segment is (0,1)
|
2019-05-17 17:35:35 +00:00
|
|
|
if (idx == 0)
|
2019-05-22 15:42:49 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
idx = 1;
|
2019-05-22 15:42:49 +00:00
|
|
|
}
|
2019-05-17 17:35:35 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
vtkm::Vec<Vector3, 2> line(pointWCoords[idx - 1], pointWCoords[idx]);
|
2020-03-12 23:38:27 +00:00
|
|
|
Vector3 lpc;
|
|
|
|
VTKM_RETURN_ON_ERROR(
|
|
|
|
WorldCoordinatesToParametricCoordinates(line, wcoords, vtkm::CellShapeTagLine{}, lpc));
|
2019-09-25 01:22:10 +00:00
|
|
|
|
2019-05-22 15:42:49 +00:00
|
|
|
//Segment param is [0,1] on that segment.
|
|
|
|
//Map that onto the param for the entire segment.
|
|
|
|
T dParam = static_cast<T>(1) / static_cast<T>(numPoints - 1);
|
2019-09-25 01:22:10 +00:00
|
|
|
T polyLineParam = static_cast<T>(idx - 1) * dParam + lpc[0] * dParam;
|
2019-05-17 17:35:35 +00:00
|
|
|
|
2020-03-12 23:38:27 +00:00
|
|
|
result = Vector3(polyLineParam, 0, 0);
|
|
|
|
return vtkm::ErrorCode::Success;
|
2019-05-17 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename WorldCoordVector>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const typename WorldCoordVector::ComponentType& wcoords,
|
|
|
|
vtkm::CellShapeTagPolygon,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2015-08-26 04:15:44 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
auto numPoints = pointWCoords.GetNumberOfComponents();
|
2015-08-27 06:09:06 +00:00
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2017-05-26 17:53:28 +00:00
|
|
|
return WorldCoordinatesToParametricCoordinates(
|
2020-03-12 23:38:27 +00:00
|
|
|
pointWCoords, wcoords, vtkm::CellShapeTagVertex{}, result);
|
2015-08-27 06:09:06 +00:00
|
|
|
case 2:
|
2017-05-26 17:53:28 +00:00
|
|
|
return WorldCoordinatesToParametricCoordinates(
|
2020-03-12 23:38:27 +00:00
|
|
|
pointWCoords, wcoords, vtkm::CellShapeTagLine{}, result);
|
2019-09-25 01:22:10 +00:00
|
|
|
default:
|
|
|
|
return internal::WorldCoordinatesToParametricCoordinatesImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
lcl::Polygon(numPoints), pointWCoords, wcoords, result);
|
2015-08-27 06:09:06 +00:00
|
|
|
}
|
2018-01-30 15:27:31 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
2019-09-25 01:22:10 +00:00
|
|
|
const vtkm::VecAxisAlignedPointCoordinates<2>& pointWCoords,
|
|
|
|
const vtkm::Vec3f& wcoords,
|
|
|
|
vtkm::CellShapeTagQuad,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec3f& result)
|
2018-01-30 15:27:31 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return internal::WorldCoordinatesToParametricCoordinatesImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
lcl::Pixel{}, pointWCoords, wcoords, result);
|
2015-08-26 04:15:44 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
2017-07-05 19:58:35 +00:00
|
|
|
const vtkm::VecAxisAlignedPointCoordinates<3>& pointWCoords,
|
2019-07-31 16:20:38 +00:00
|
|
|
const vtkm::Vec3f& wcoords,
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::CellShapeTagHexahedron,
|
2020-03-12 23:38:27 +00:00
|
|
|
vtkm::Vec3f& result)
|
2015-08-26 04:15:44 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return internal::WorldCoordinatesToParametricCoordinatesImpl(
|
2020-03-12 23:38:27 +00:00
|
|
|
lcl::Voxel{}, pointWCoords, wcoords, result);
|
2018-01-30 15:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-09-25 01:22:10 +00:00
|
|
|
/// Returns the world paramteric corresponding to the given world coordinate for a cell.
|
|
|
|
///
|
2018-01-30 15:27:31 +00:00
|
|
|
template <typename WorldCoordVector>
|
2020-03-12 23:38:27 +00:00
|
|
|
static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
|
|
|
const WorldCoordVector& pointWCoords,
|
|
|
|
const typename WorldCoordVector::ComponentType& wcoords,
|
|
|
|
vtkm::CellShapeTagGeneric shape,
|
|
|
|
typename WorldCoordVector::ComponentType& result)
|
2018-01-30 15:27:31 +00:00
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkm::ErrorCode status;
|
2018-01-30 15:27:31 +00:00
|
|
|
switch (shape.Id)
|
|
|
|
{
|
2020-03-14 01:20:45 +00:00
|
|
|
vtkmGenericCellShapeMacro(status = WorldCoordinatesToParametricCoordinates(
|
|
|
|
pointWCoords, wcoords, CellShapeTag(), result));
|
2018-01-30 15:27:31 +00:00
|
|
|
default:
|
2020-03-14 01:20:45 +00:00
|
|
|
result = { 0 };
|
|
|
|
status = vtkm::ErrorCode::InvalidShapeId;
|
2018-01-30 15:27:31 +00:00
|
|
|
}
|
2020-03-14 01:20:45 +00:00
|
|
|
return status;
|
2015-08-26 04:15:44 +00:00
|
|
|
}
|
2020-03-11 23:56:05 +00:00
|
|
|
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::exec
|
|
|
|
|
|
|
|
#endif //vtk_m_exec_ParametricCoordinates_h
|