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-09-25 01:22:10 +00:00
|
|
|
#include <vtkc/vtkc.h>
|
|
|
|
|
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>
|
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&)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
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);
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
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&)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
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();
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
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&)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
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();
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2019-05-29 12:18:31 +00:00
|
|
|
ParametricCoordinatesCenter(numPoints, pcoords, vtkm::CellShapeTagVertex(), worklet);
|
|
|
|
return;
|
2019-05-17 17:35:35 +00:00
|
|
|
case 2:
|
2019-05-29 12:18:31 +00:00
|
|
|
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)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2016-04-20 21:41:14 +00:00
|
|
|
VTKM_ASSERT(numPoints > 0);
|
2015-08-20 03:18:54 +00:00
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2017-05-18 14:29:41 +00:00
|
|
|
ParametricCoordinatesCenter(numPoints, pcoords, vtkm::CellShapeTagVertex(), worklet);
|
2015-08-20 03:18:54 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-05-18 14:29:41 +00:00
|
|
|
ParametricCoordinatesCenter(numPoints, pcoords, vtkm::CellShapeTagLine(), worklet);
|
2015-08-20 03:18:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-09-25 01:22:10 +00:00
|
|
|
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
|
|
|
|
vtkc::parametricCenter(vtkc::Polygon(numPoints), pcoords);
|
2015-08-20 03:18:54 +00:00
|
|
|
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)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
|
|
|
switch (shape.Id)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkmGenericCellShapeMacro(
|
|
|
|
ParametricCoordinatesCenter(numPoints, pcoords, CellShapeTag(), worklet));
|
2015-08-20 03:18:54 +00:00
|
|
|
default:
|
|
|
|
worklet.RaiseError("Bad shape given to ParametricCoordinatesCenter.");
|
2015-08-28 04:13:19 +00:00
|
|
|
pcoords[0] = pcoords[1] = pcoords[2] = 0;
|
|
|
|
break;
|
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 CellShapeTag>
|
2019-07-31 16:20:38 +00:00
|
|
|
static inline VTKM_EXEC vtkm::Vec3f ParametricCoordinatesCenter(
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
CellShapeTag shape,
|
|
|
|
const vtkm::exec::FunctorBase& worklet)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
vtkm::Vec3f pcoords(0.0f);
|
2015-08-21 04:29:54 +00:00
|
|
|
ParametricCoordinatesCenter(numPoints, pcoords, shape, worklet);
|
2015-08-20 03:18:54 +00:00
|
|
|
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>
|
2017-05-26 17:53:28 +00:00
|
|
|
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)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
|
|
|
worklet.RaiseError("Empty cell has no points.");
|
2015-08-28 04:13:19 +00:00
|
|
|
pcoords[0] = pcoords[1] = pcoords[2] = 0;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
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&)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2016-04-21 15:32:02 +00:00
|
|
|
(void)numPoints; // Silence compiler warnings.
|
|
|
|
(void)pointIndex; // Silence compiler warnings.
|
2016-04-28 14:10:21 +00:00
|
|
|
VTKM_ASSUME(numPoints == 1);
|
|
|
|
VTKM_ASSUME(pointIndex == 0);
|
2019-09-25 01:22:10 +00:00
|
|
|
pcoords = vtkm::TypeTraits<vtkm::Vec<ParametricCoordType, 3>>::ZeroInitialization();
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2019-05-29 12:18:31 +00:00
|
|
|
ParametricCoordinatesPoint(
|
2019-05-17 17:35:35 +00:00
|
|
|
numPoints, pointIndex, pcoords, vtkm::CellShapeTagVertex(), functor);
|
2019-05-29 12:18:31 +00:00
|
|
|
return;
|
2019-05-17 17:35:35 +00:00
|
|
|
case 2:
|
2019-05-29 12:18:31 +00:00
|
|
|
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)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_ASSUME((numPoints > 0));
|
|
|
|
VTKM_ASSUME((pointIndex >= 0) && (pointIndex < numPoints));
|
2015-08-20 03:18:54 +00:00
|
|
|
|
|
|
|
switch (numPoints)
|
|
|
|
{
|
|
|
|
case 1:
|
2017-05-26 17:53:28 +00:00
|
|
|
ParametricCoordinatesPoint(
|
|
|
|
numPoints, pointIndex, pcoords, vtkm::CellShapeTagVertex(), worklet);
|
2015-08-20 03:18:54 +00:00
|
|
|
return;
|
|
|
|
case 2:
|
2017-05-18 14:29:41 +00:00
|
|
|
ParametricCoordinatesPoint(numPoints, pointIndex, pcoords, vtkm::CellShapeTagLine(), worklet);
|
2015-08-20 03:18:54 +00:00
|
|
|
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);
|
2015-08-20 03:18:54 +00:00
|
|
|
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)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
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(
|
|
|
|
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;
|
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.
|
|
|
|
///
|
|
|
|
template <typename CellShapeTag>
|
|
|
|
static inline VTKM_EXEC vtkm::Vec3f ParametricCoordinatesPoint(
|
|
|
|
vtkm::IdComponent numPoints,
|
|
|
|
vtkm::IdComponent pointIndex,
|
|
|
|
CellShapeTag shape,
|
|
|
|
const vtkm::exec::FunctorBase& worklet)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
vtkm::Vec3f pcoords(0.0f);
|
|
|
|
ParametricCoordinatesPoint(numPoints, pointIndex, pcoords, shape, worklet);
|
|
|
|
return pcoords;
|
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
|
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)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
worklet.RaiseError(vtkc::errorString(status));
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
2019-09-25 01:22:10 +00:00
|
|
|
return 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>
|
|
|
|
static inline VTKM_EXEC typename WorldCoordVector::ComponentType
|
|
|
|
ParametricCoordinatesToWorldCoordinates(const WorldCoordVector& pointWCoords,
|
|
|
|
const vtkm::Vec<PCoordType, 3>& pcoords,
|
|
|
|
CellShapeTag shape,
|
|
|
|
const vtkm::exec::FunctorBase& worklet)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
auto numPoints = pointWCoords.GetNumberOfComponents();
|
|
|
|
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
|
|
|
|
vtkm::internal::make_VtkcCellShapeTag(shape, numPoints), pointWCoords, pcoords, worklet);
|
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
|
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);
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
|
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)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return vtkm::exec::CellInterpolate(pointWCoords, pcoords, polyLine, worklet);
|
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
|
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)
|
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(
|
|
|
|
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);
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return internal::ParametricCoordinatesToWorldCoordinatesImpl(
|
|
|
|
vtkc::Pixel{}, pointWCoords, pcoords, worklet);
|
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
|
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);
|
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>
|
|
|
|
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)
|
2015-08-20 03:18:54 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
typename WorldCoordVector::ComponentType wcoords(0);
|
2015-08-20 03:18:54 +00:00
|
|
|
switch (shape.Id)
|
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
vtkmGenericCellShapeMacro(wcoords = ParametricCoordinatesToWorldCoordinates(
|
|
|
|
pointWCoords, pcoords, CellShapeTag(), worklet));
|
2015-08-20 03:18:54 +00:00
|
|
|
default:
|
|
|
|
worklet.RaiseError("Bad shape given to ParametricCoordinatesPoint.");
|
2015-08-28 04:13:19 +00:00
|
|
|
break;
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
2019-09-25 01:22:10 +00:00
|
|
|
return wcoords;
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
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,
|
2017-05-26 17:53:28 +00:00
|
|
|
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)
|
2015-08-26 04:15:44 +00:00
|
|
|
{
|
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);
|
2015-08-26 04:15:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 15:27:31 +00:00
|
|
|
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,
|
2017-10-02 21:18:17 +00:00
|
|
|
bool& success,
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::exec::FunctorBase& worklet)
|
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(
|
2019-09-25 01:22:10 +00:00
|
|
|
pointWCoords, wcoords, vtkm::CellShapeTagVertex{}, success, worklet);
|
2015-08-27 06:09:06 +00:00
|
|
|
case 2:
|
2017-05-26 17:53:28 +00:00
|
|
|
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);
|
2015-08-27 06:09:06 +00:00
|
|
|
}
|
2018-01-30 15:27:31 +00:00
|
|
|
}
|
|
|
|
|
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)
|
2018-01-30 15:27:31 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return internal::WorldCoordinatesToParametricCoordinatesImpl(
|
|
|
|
vtkc::Pixel{}, pointWCoords, wcoords, success, worklet);
|
2015-08-26 04:15:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 16:20:38 +00:00
|
|
|
static inline VTKM_EXEC vtkm::Vec3f 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,
|
2017-10-02 21:18:17 +00:00
|
|
|
bool& success,
|
2019-09-25 01:22:10 +00:00
|
|
|
const FunctorBase& worklet)
|
2015-08-26 04:15:44 +00:00
|
|
|
{
|
2019-09-25 01:22:10 +00:00
|
|
|
return internal::WorldCoordinatesToParametricCoordinatesImpl(
|
|
|
|
vtkc::Voxel{}, pointWCoords, wcoords, success, worklet);
|
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>
|
|
|
|
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;
|
2015-08-26 04:15:44 +00:00
|
|
|
}
|
2015-08-20 03:18:54 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::exec
|
|
|
|
|
|
|
|
#endif //vtk_m_exec_ParametricCoordinates_h
|