vtk-m2/vtkm/exec/ParametricCoordinates.h

594 lines
24 KiB
C
Raw Normal View History

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +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
#include <vtkm/Assert.h>
#include <vtkm/CellShape.h>
#include <vtkm/VecAxisAlignedPointCoordinates.h>
#include <vtkm/exec/CellInterpolate.h>
#include <vtkm/exec/FunctorBase.h>
#include <vtkm/exec/internal/FastVec.h>
2017-05-18 14:51:24 +00:00
#include <vtkm/internal/Assume.h>
2019-09-25 01:22:10 +00:00
#include <vtkc/vtkc.h>
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace exec
{
//-----------------------------------------------------------------------------
2019-09-25 01:22:10 +00:00
template <typename ParametricCoordType, typename CellShapeTag>
2017-05-18 14:29:41 +00:00
static inline VTKM_EXEC void ParametricCoordinatesCenter(vtkm::IdComponent numPoints,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
2019-09-25 01:22:10 +00:00
CellShapeTag,
2017-05-18 14:29:41 +00:00
const vtkm::exec::FunctorBase&)
{
2019-09-25 01:22:10 +00:00
auto vtkcTag = typename vtkm::internal::CellShapeTagVtkmToVtkc<CellShapeTag>::Type{};
2017-05-18 14:29:41 +00:00
(void)numPoints; // Silence compiler warnings.
2019-09-25 01:22:10 +00:00
VTKM_ASSERT(numPoints == vtkcTag.numberOfPoints());
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
vtkc::parametricCenter(vtkcTag, pcoords);
}
2017-05-18 14:29:41 +00:00
template <typename ParametricCoordType>
static inline VTKM_EXEC void ParametricCoordinatesCenter(vtkm::IdComponent numPoints,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
2019-09-25 01:22:10 +00:00
vtkm::CellShapeTagEmpty,
2017-05-18 14:29:41 +00:00
const vtkm::exec::FunctorBase&)
{
2017-05-18 14:29:41 +00:00
(void)numPoints; // Silence compiler warnings.
2019-09-25 01:22:10 +00:00
VTKM_ASSERT(numPoints == 0);
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
}
2017-05-18 14:29:41 +00:00
template <typename ParametricCoordType>
static inline VTKM_EXEC void ParametricCoordinatesCenter(vtkm::IdComponent numPoints,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
2019-09-25 01:22:10 +00:00
vtkm::CellShapeTagVertex,
2017-05-18 14:29:41 +00:00
const vtkm::exec::FunctorBase&)
{
2017-05-18 14:29:41 +00:00
(void)numPoints; // Silence compiler warnings.
2019-09-25 01:22:10 +00:00
VTKM_ASSERT(numPoints == 1);
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
}
2019-05-17 17:35:35 +00:00
template <typename ParametricCoordType>
static inline VTKM_EXEC void ParametricCoordinatesCenter(vtkm::IdComponent numPoints,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
vtkm::CellShapeTagPolyLine,
const vtkm::exec::FunctorBase& worklet)
{
switch (numPoints)
{
case 1:
ParametricCoordinatesCenter(numPoints, pcoords, vtkm::CellShapeTagVertex(), worklet);
return;
2019-05-17 17:35:35 +00:00
case 2:
ParametricCoordinatesCenter(numPoints, pcoords, vtkm::CellShapeTagLine(), worklet);
return;
2019-05-17 17:35:35 +00:00
}
pcoords[0] = 0.5;
pcoords[1] = 0;
pcoords[2] = 0;
}
2017-05-18 14:29:41 +00:00
template <typename ParametricCoordType>
static inline VTKM_EXEC void ParametricCoordinatesCenter(vtkm::IdComponent numPoints,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
vtkm::CellShapeTagPolygon,
const vtkm::exec::FunctorBase& worklet)
{
VTKM_ASSERT(numPoints > 0);
switch (numPoints)
{
case 1:
2017-05-18 14:29:41 +00:00
ParametricCoordinatesCenter(numPoints, pcoords, vtkm::CellShapeTagVertex(), worklet);
break;
case 2:
2017-05-18 14:29:41 +00:00
ParametricCoordinatesCenter(numPoints, pcoords, vtkm::CellShapeTagLine(), worklet);
break;
default:
2019-09-25 01:22:10 +00:00
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
vtkc::parametricCenter(vtkc::Polygon(numPoints), pcoords);
break;
}
}
//-----------------------------------------------------------------------------
/// 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>
static inline VTKM_EXEC void ParametricCoordinatesCenter(vtkm::IdComponent numPoints,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
vtkm::CellShapeTagGeneric shape,
const vtkm::exec::FunctorBase& worklet)
{
switch (shape.Id)
{
2017-05-18 14:29:41 +00:00
vtkmGenericCellShapeMacro(
ParametricCoordinatesCenter(numPoints, pcoords, CellShapeTag(), worklet));
default:
worklet.RaiseError("Bad shape given to ParametricCoordinatesCenter.");
pcoords[0] = pcoords[1] = pcoords[2] = 0;
break;
}
}
/// 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 CellShapeTag>
static inline VTKM_EXEC vtkm::Vec3f ParametricCoordinatesCenter(
vtkm::IdComponent numPoints,
CellShapeTag shape,
const vtkm::exec::FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
vtkm::Vec3f pcoords(0.0f);
ParametricCoordinatesCenter(numPoints, pcoords, shape, worklet);
return pcoords;
}
//-----------------------------------------------------------------------------
2019-09-25 01:22:10 +00:00
template <typename ParametricCoordType, typename CellShapeTag>
static inline VTKM_EXEC void ParametricCoordinatesPoint(vtkm::IdComponent numPoints,
vtkm::IdComponent pointIndex,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
CellShapeTag,
const vtkm::exec::FunctorBase&)
{
auto vtkcTag = typename vtkm::internal::CellShapeTagVtkmToVtkc<CellShapeTag>::Type{};
(void)numPoints; // Silence compiler warnings.
VTKM_ASSUME(numPoints == vtkcTag.numberOfPoints());
VTKM_ASSUME((pointIndex >= 0) && (pointIndex < numPoints));
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
vtkc::parametricPoint(vtkcTag, pointIndex, pcoords);
}
2017-05-18 14:29:41 +00:00
template <typename ParametricCoordType>
static inline VTKM_EXEC void ParametricCoordinatesPoint(vtkm::IdComponent,
vtkm::IdComponent,
2017-05-18 14:29:41 +00:00
vtkm::Vec<ParametricCoordType, 3>& pcoords,
vtkm::CellShapeTagEmpty,
const vtkm::exec::FunctorBase& worklet)
{
worklet.RaiseError("Empty cell has no points.");
pcoords[0] = pcoords[1] = pcoords[2] = 0;
}
2017-05-18 14:29:41 +00:00
template <typename ParametricCoordType>
static inline VTKM_EXEC void ParametricCoordinatesPoint(vtkm::IdComponent numPoints,
vtkm::IdComponent pointIndex,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
vtkm::CellShapeTagVertex,
const vtkm::exec::FunctorBase&)
{
2016-04-21 15:32:02 +00:00
(void)numPoints; // Silence compiler warnings.
(void)pointIndex; // Silence compiler warnings.
VTKM_ASSUME(numPoints == 1);
VTKM_ASSUME(pointIndex == 0);
2019-09-25 01:22:10 +00:00
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
}
2019-05-17 17:35:35 +00:00
template <typename ParametricCoordType>
static inline VTKM_EXEC void ParametricCoordinatesPoint(vtkm::IdComponent numPoints,
vtkm::IdComponent pointIndex,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
vtkm::CellShapeTagPolyLine,
const vtkm::exec::FunctorBase& functor)
{
switch (numPoints)
{
case 1:
ParametricCoordinatesPoint(
2019-05-17 17:35:35 +00:00
numPoints, pointIndex, pcoords, vtkm::CellShapeTagVertex(), functor);
return;
2019-05-17 17:35:35 +00:00
case 2:
ParametricCoordinatesPoint(numPoints, pointIndex, pcoords, vtkm::CellShapeTagLine(), functor);
return;
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;
}
2017-05-18 14:29:41 +00:00
template <typename ParametricCoordType>
static inline VTKM_EXEC void ParametricCoordinatesPoint(vtkm::IdComponent numPoints,
vtkm::IdComponent pointIndex,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
vtkm::CellShapeTagPolygon,
const vtkm::exec::FunctorBase& worklet)
{
2017-05-18 14:29:41 +00:00
VTKM_ASSUME((numPoints > 0));
VTKM_ASSUME((pointIndex >= 0) && (pointIndex < numPoints));
switch (numPoints)
{
case 1:
ParametricCoordinatesPoint(
numPoints, pointIndex, pcoords, vtkm::CellShapeTagVertex(), worklet);
return;
case 2:
2017-05-18 14:29:41 +00:00
ParametricCoordinatesPoint(numPoints, pointIndex, pcoords, vtkm::CellShapeTagLine(), worklet);
return;
2019-09-25 01:22:10 +00:00
default:
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
vtkc::parametricPoint(vtkc::Polygon(numPoints), pointIndex, pcoords);
return;
}
}
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>
static inline VTKM_EXEC void ParametricCoordinatesPoint(vtkm::IdComponent numPoints,
vtkm::IdComponent pointIndex,
vtkm::Vec<ParametricCoordType, 3>& pcoords,
2019-09-25 01:22:10 +00:00
vtkm::CellShapeTagGeneric shape,
const vtkm::exec::FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
switch (shape.Id)
{
2019-09-25 01:22:10 +00:00
vtkmGenericCellShapeMacro(
ParametricCoordinatesPoint(numPoints, pointIndex, pcoords, CellShapeTag(), worklet));
default:
worklet.RaiseError("Bad shape given to ParametricCoordinatesPoint.");
pcoords[0] = pcoords[1] = pcoords[2] = 0;
2017-05-18 14:29:41 +00:00
break;
}
}
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.
///
template <typename CellShapeTag>
static inline VTKM_EXEC vtkm::Vec3f ParametricCoordinatesPoint(
vtkm::IdComponent numPoints,
vtkm::IdComponent pointIndex,
CellShapeTag shape,
const vtkm::exec::FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
vtkm::Vec3f pcoords(0.0f);
ParametricCoordinatesPoint(numPoints, pointIndex, pcoords, shape, worklet);
return pcoords;
}
2019-09-25 01:22:10 +00:00
//-----------------------------------------------------------------------------
namespace internal
{
template <typename VtkcCellShapeTag, typename WorldCoordVector, typename PCoordType>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
ParametricCoordinatesToWorldCoordinatesImpl(VtkcCellShapeTag tag,
const WorldCoordVector& pointWCoords,
const PCoordType& pcoords,
const vtkm::exec::FunctorBase& worklet)
{
typename WorldCoordVector::ComponentType wcoords(0);
auto status = vtkc::parametricToWorld(
tag, vtkc::makeFieldAccessorNestedSOA(pointWCoords, 3), pcoords, wcoords);
if (status != vtkc::ErrorCode::SUCCESS)
{
2019-09-25 01:22:10 +00:00
worklet.RaiseError(vtkc::errorString(status));
}
2019-09-25 01:22:10 +00:00
return wcoords;
}
2019-09-25 01:22:10 +00:00
} // namespace internal
template <typename WorldCoordVector, typename PCoordType, typename CellShapeTag>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
ParametricCoordinatesToWorldCoordinates(const WorldCoordVector& pointWCoords,
const vtkm::Vec<PCoordType, 3>& pcoords,
CellShapeTag shape,
const vtkm::exec::FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
auto numPoints = pointWCoords.GetNumberOfComponents();
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
vtkm::internal::make_VtkcCellShapeTag(shape, numPoints), pointWCoords, pcoords, worklet);
}
2019-09-25 01:22:10 +00:00
template <typename WorldCoordVector, typename PCoordType>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
ParametricCoordinatesToWorldCoordinates(const WorldCoordVector& pointWCoords,
const vtkm::Vec<PCoordType, 3>& pcoords,
vtkm::CellShapeTagEmpty empty,
const vtkm::exec::FunctorBase& worklet)
{
return vtkm::exec::CellInterpolate(pointWCoords, pcoords, empty, worklet);
}
2019-09-25 01:22:10 +00:00
template <typename WorldCoordVector, typename PCoordType>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
ParametricCoordinatesToWorldCoordinates(const WorldCoordVector& pointWCoords,
const vtkm::Vec<PCoordType, 3>& pcoords,
vtkm::CellShapeTagPolyLine polyLine,
const vtkm::exec::FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
return vtkm::exec::CellInterpolate(pointWCoords, pcoords, polyLine, worklet);
}
2019-09-25 01:22:10 +00:00
template <typename WorldCoordVector, typename PCoordType>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
ParametricCoordinatesToWorldCoordinates(const WorldCoordVector& pointWCoords,
const vtkm::Vec<PCoordType, 3>& pcoords,
vtkm::CellShapeTagPolygon,
const vtkm::exec::FunctorBase& worklet)
{
auto numPoints = pointWCoords.GetNumberOfComponents();
switch (numPoints)
{
2017-05-18 14:29:41 +00:00
case 1:
2019-09-25 01:22:10 +00:00
return ParametricCoordinatesToWorldCoordinates(
pointWCoords, pcoords, vtkm::CellShapeTagVertex{}, worklet);
2017-05-18 14:29:41 +00:00
case 2:
2019-09-25 01:22:10 +00:00
return ParametricCoordinatesToWorldCoordinates(
pointWCoords, pcoords, vtkm::CellShapeTagLine{}, worklet);
default:
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
vtkc::Polygon(numPoints), pointWCoords, pcoords, worklet);
}
}
2019-09-25 01:22:10 +00:00
template <typename WorldCoordVector, typename PCoordType>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
ParametricCoordinatesToWorldCoordinates(const vtkm::VecAxisAlignedPointCoordinates<2>& pointWCoords,
const vtkm::Vec<PCoordType, 3>& pcoords,
vtkm::CellShapeTagQuad,
const vtkm::exec::FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
vtkc::Pixel{}, pointWCoords, pcoords, worklet);
}
2019-09-25 01:22:10 +00:00
template <typename WorldCoordVector, typename PCoordType>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
ParametricCoordinatesToWorldCoordinates(const vtkm::VecAxisAlignedPointCoordinates<3>& pointWCoords,
const vtkm::Vec<PCoordType, 3>& pcoords,
vtkm::CellShapeTagHexahedron,
const vtkm::exec::FunctorBase& worklet)
{
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
vtkc::Voxel{}, pointWCoords, pcoords, worklet);
}
//-----------------------------------------------------------------------------
2019-09-25 01:22:10 +00:00
/// Returns the world coordinate corresponding to the given parametric coordinate of a cell.
///
2019-09-25 01:22:10 +00:00
template <typename WorldCoordVector, typename PCoordType>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
ParametricCoordinatesToWorldCoordinates(const WorldCoordVector& pointWCoords,
const vtkm::Vec<PCoordType, 3>& pcoords,
vtkm::CellShapeTagGeneric shape,
const vtkm::exec::FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
typename WorldCoordVector::ComponentType wcoords(0);
switch (shape.Id)
{
2019-09-25 01:22:10 +00:00
vtkmGenericCellShapeMacro(wcoords = ParametricCoordinatesToWorldCoordinates(
pointWCoords, pcoords, CellShapeTag(), worklet));
default:
worklet.RaiseError("Bad shape given to ParametricCoordinatesPoint.");
break;
}
2019-09-25 01:22:10 +00:00
return wcoords;
}
2019-09-25 01:22:10 +00:00
//-----------------------------------------------------------------------------
namespace internal
{
2019-09-25 01:22:10 +00:00
template <typename VtkcCellShapeTag, typename WorldCoordVector>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
WorldCoordinatesToParametricCoordinatesImpl(VtkcCellShapeTag tag,
const WorldCoordVector& pointWCoords,
const typename WorldCoordVector::ComponentType& wcoords,
bool& success,
const vtkm::exec::FunctorBase& worklet)
{
VTKM_ASSERT(pointWCoords.GetNumberOfComponents() == tag.numberOfPoints());
auto pcoords = vtkm::TypeTraits<typename WorldCoordVector::ComponentType>::ZeroInitialization();
auto status = vtkc::worldToParametric(
tag, vtkc::makeFieldAccessorNestedSOA(pointWCoords, 3), wcoords, pcoords);
success = true;
if (status != vtkc::ErrorCode::SUCCESS)
{
worklet.RaiseError(vtkc::errorString(status));
success = false;
}
return pcoords;
}
2019-09-25 01:22:10 +00:00
} // namespace internal
template <typename WorldCoordVector, typename CellShapeTag>
2017-05-18 14:29:41 +00:00
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
2019-09-25 01:22:10 +00:00
WorldCoordinatesToParametricCoordinates(const WorldCoordVector& pointWCoords,
const typename WorldCoordVector::ComponentType& wcoords,
CellShapeTag shape,
2019-09-25 01:22:10 +00:00
bool& success,
2017-05-18 14:29:41 +00:00
const vtkm::exec::FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
auto numPoints = pointWCoords.GetNumberOfComponents();
return internal::WorldCoordinatesToParametricCoordinatesImpl(
vtkm::internal::make_VtkcCellShapeTag(shape, numPoints),
pointWCoords,
wcoords,
success,
worklet);
}
template <typename WorldCoordVector>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
WorldCoordinatesToParametricCoordinates(const WorldCoordVector&,
const typename WorldCoordVector::ComponentType&,
vtkm::CellShapeTagEmpty,
bool& success,
const vtkm::exec::FunctorBase& worklet)
{
worklet.RaiseError("Attempted to find point coordinates in empty cell.");
success = false;
return typename WorldCoordVector::ComponentType();
}
template <typename WorldCoordVector>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
WorldCoordinatesToParametricCoordinates(const WorldCoordVector& pointWCoords,
const typename WorldCoordVector::ComponentType&,
vtkm::CellShapeTagVertex,
bool& success,
const vtkm::exec::FunctorBase& vtkmNotUsed(worklet))
{
(void)pointWCoords; // Silence compiler warnings.
VTKM_ASSERT(pointWCoords.GetNumberOfComponents() == 1);
success = true;
return typename WorldCoordVector::ComponentType(0, 0, 0);
}
2019-05-17 17:35:35 +00:00
template <typename WorldCoordVector>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
WorldCoordinatesToParametricCoordinates(const WorldCoordVector& pointWCoords,
const typename WorldCoordVector::ComponentType& wcoords,
vtkm::CellShapeTagPolyLine,
bool& success,
const vtkm::exec::FunctorBase& worklet)
{
vtkm::IdComponent numPoints = pointWCoords.GetNumberOfComponents();
VTKM_ASSERT(pointWCoords.GetNumberOfComponents() >= 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 WorldCoordinatesToParametricCoordinates(
pointWCoords, wcoords, vtkm::CellShapeTagVertex(), success, worklet);
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]);
auto lpc = WorldCoordinatesToParametricCoordinates(
line, wcoords, vtkm::CellShapeTagLine{}, success, worklet);
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
2019-05-22 15:42:49 +00:00
return Vector3(polyLineParam, 0, 0);
2019-05-17 17:35:35 +00:00
}
2017-05-18 14:29:41 +00:00
template <typename WorldCoordVector>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
WorldCoordinatesToParametricCoordinates(const WorldCoordVector& pointWCoords,
const typename WorldCoordVector::ComponentType& wcoords,
vtkm::CellShapeTagPolygon,
bool& success,
2017-05-18 14:29:41 +00:00
const vtkm::exec::FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
auto numPoints = pointWCoords.GetNumberOfComponents();
switch (numPoints)
{
case 1:
return WorldCoordinatesToParametricCoordinates(
2019-09-25 01:22:10 +00:00
pointWCoords, wcoords, vtkm::CellShapeTagVertex{}, success, worklet);
case 2:
return WorldCoordinatesToParametricCoordinates(
2019-09-25 01:22:10 +00:00
pointWCoords, wcoords, vtkm::CellShapeTagLine{}, success, worklet);
default:
return internal::WorldCoordinatesToParametricCoordinatesImpl(
vtkc::Polygon(numPoints), pointWCoords, wcoords, success, worklet);
}
}
2019-09-25 01:22:10 +00:00
static inline VTKM_EXEC vtkm::Vec3f WorldCoordinatesToParametricCoordinates(
const vtkm::VecAxisAlignedPointCoordinates<2>& pointWCoords,
const vtkm::Vec3f& wcoords,
vtkm::CellShapeTagQuad,
bool& success,
const FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
return internal::WorldCoordinatesToParametricCoordinatesImpl(
vtkc::Pixel{}, pointWCoords, wcoords, success, worklet);
}
static inline VTKM_EXEC vtkm::Vec3f WorldCoordinatesToParametricCoordinates(
const vtkm::VecAxisAlignedPointCoordinates<3>& pointWCoords,
const vtkm::Vec3f& wcoords,
vtkm::CellShapeTagHexahedron,
bool& success,
2019-09-25 01:22:10 +00:00
const FunctorBase& worklet)
{
2019-09-25 01:22:10 +00:00
return internal::WorldCoordinatesToParametricCoordinatesImpl(
vtkc::Voxel{}, pointWCoords, wcoords, success, worklet);
}
//-----------------------------------------------------------------------------
2019-09-25 01:22:10 +00:00
/// Returns the world paramteric corresponding to the given world coordinate for a cell.
///
template <typename WorldCoordVector>
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
WorldCoordinatesToParametricCoordinates(const WorldCoordVector& pointWCoords,
const typename WorldCoordVector::ComponentType& wcoords,
vtkm::CellShapeTagGeneric shape,
bool& success,
const vtkm::exec::FunctorBase& worklet)
{
typename WorldCoordVector::ComponentType result;
switch (shape.Id)
{
vtkmGenericCellShapeMacro(result = WorldCoordinatesToParametricCoordinates(
pointWCoords, wcoords, CellShapeTag(), success, worklet));
default:
success = false;
worklet.RaiseError("Unknown cell shape sent to world 2 parametric.");
return typename WorldCoordVector::ComponentType();
}
return result;
}
}
} // namespace vtkm::exec
#endif //vtk_m_exec_ParametricCoordinates_h