10 #ifndef vtk_m_exec_ParametricCoordinates_h
11 #define vtk_m_exec_ParametricCoordinates_h
29 template <
typename ParametricCoordType,
typename CellShapeTag>
35 auto lclTag =
typename vtkm::internal::CellShapeTagVtkmToVtkc<CellShapeTag>::Type{};
38 if (numPoints != lclTag.numberOfPoints())
43 return vtkm::internal::LclErrorToVtkmError(lcl::parametricCenter(lclTag, pcoords));
46 template <
typename ParametricCoordType>
49 vtkm::CellShapeTagEmpty,
60 template <
typename ParametricCoordType>
63 vtkm::CellShapeTagVertex,
74 template <
typename ParametricCoordType>
77 vtkm::CellShapeTagPolyLine,
83 return ParametricCoordinatesCenter(numPoints, vtkm::CellShapeTagVertex(), pcoords);
85 return ParametricCoordinatesCenter(numPoints, vtkm::CellShapeTagLine(), pcoords);
93 template <
typename ParametricCoordType>
96 vtkm::CellShapeTagPolygon,
107 return ParametricCoordinatesCenter(numPoints, vtkm::CellShapeTagVertex(), pcoords);
109 return ParametricCoordinatesCenter(numPoints, vtkm::CellShapeTagLine(), pcoords);
112 return vtkm::internal::LclErrorToVtkmError(
113 lcl::parametricCenter(lcl::Polygon(numPoints), pcoords));
121 template <
typename ParametricCoordType>
131 ParametricCoordinatesCenter(numPoints, CellShapeTag(), pcoords));
140 template <
typename ParametricCoordType,
typename CellShapeTag>
147 auto lclTag =
typename vtkm::internal::CellShapeTagVtkmToVtkc<CellShapeTag>::Type{};
149 if (numPoints != lclTag.numberOfPoints())
154 if ((pointIndex < 0) || (pointIndex >= numPoints))
161 return vtkm::internal::LclErrorToVtkmError(lcl::parametricPoint(lclTag, pointIndex, pcoords));
164 template <
typename ParametricCoordType>
168 vtkm::CellShapeTagEmpty,
171 pcoords[0] = pcoords[1] = pcoords[2] = 0;
175 template <
typename ParametricCoordType>
179 vtkm::CellShapeTagVertex,
194 template <
typename ParametricCoordType>
198 vtkm::CellShapeTagPolyLine,
209 return ParametricCoordinatesPoint(numPoints, pointIndex, vtkm::CellShapeTagVertex(), pcoords);
211 return ParametricCoordinatesPoint(numPoints, pointIndex, vtkm::CellShapeTagLine(), pcoords);
214 static_cast<ParametricCoordType
>(pointIndex) /
static_cast<ParametricCoordType
>(numPoints - 1);
220 template <
typename ParametricCoordType>
224 vtkm::CellShapeTagPolygon,
230 return ParametricCoordinatesPoint(numPoints, pointIndex, vtkm::CellShapeTagVertex(), pcoords);
232 return ParametricCoordinatesPoint(numPoints, pointIndex, vtkm::CellShapeTagLine(), pcoords);
235 return vtkm::internal::LclErrorToVtkmError(
236 lcl::parametricPoint(lcl::Polygon(numPoints), pointIndex, pcoords));
244 template <
typename ParametricCoordType>
255 status = ParametricCoordinatesPoint(numPoints, pointIndex, CellShapeTag(), pcoords));
257 pcoords[0] = pcoords[1] = pcoords[2] = 0;
267 template <
typename LclCellShapeTag,
typename WorldCoordVector,
typename PCoordType>
270 const WorldCoordVector& pointWCoords,
271 const PCoordType& pcoords,
272 typename WorldCoordVector::ComponentType& wcoords)
274 return vtkm::internal::LclErrorToVtkmError(lcl::parametricToWorld(
275 tag, lcl::makeFieldAccessorNestedSOA(pointWCoords, 3), pcoords, wcoords));
280 template <
typename WorldCoordVector,
typename PCoordType,
typename CellShapeTag>
282 const WorldCoordVector& pointWCoords,
285 typename WorldCoordVector::ComponentType& result)
287 auto numPoints = pointWCoords.GetNumberOfComponents();
288 return internal::ParametricCoordinatesToWorldCoordinatesImpl(
289 vtkm::internal::make_LclCellShapeTag(shape, numPoints), pointWCoords, pcoords, result);
292 template <
typename WorldCoordVector,
typename PCoordType>
294 const WorldCoordVector& pointWCoords,
296 vtkm::CellShapeTagEmpty empty,
297 typename WorldCoordVector::ComponentType& result)
302 template <
typename WorldCoordVector,
typename PCoordType>
304 const WorldCoordVector& pointWCoords,
306 vtkm::CellShapeTagPolyLine polyLine,
307 typename WorldCoordVector::ComponentType& result)
312 template <
typename WorldCoordVector,
typename PCoordType>
314 const WorldCoordVector& pointWCoords,
316 vtkm::CellShapeTagPolygon,
317 typename WorldCoordVector::ComponentType& result)
319 auto numPoints = pointWCoords.GetNumberOfComponents();
323 return ParametricCoordinatesToWorldCoordinates(
324 pointWCoords, pcoords, vtkm::CellShapeTagVertex{}, result);
326 return ParametricCoordinatesToWorldCoordinates(
327 pointWCoords, pcoords, vtkm::CellShapeTagLine{}, result);
329 return internal::ParametricCoordinatesToWorldCoordinatesImpl(
330 lcl::Polygon(numPoints), pointWCoords, pcoords, result);
334 template <
typename WorldCoordVector,
typename PCoordType>
338 vtkm::CellShapeTagQuad,
339 typename WorldCoordVector::ComponentType& result)
341 return internal::ParametricCoordinatesToWorldCoordinatesImpl(
342 lcl::Pixel{}, pointWCoords, pcoords, result);
345 template <
typename WorldCoordVector,
typename PCoordType>
349 vtkm::CellShapeTagHexahedron,
350 typename WorldCoordVector::ComponentType& result)
352 return internal::ParametricCoordinatesToWorldCoordinatesImpl(
353 lcl::Voxel{}, pointWCoords, pcoords, result);
359 template <
typename WorldCoordVector,
typename PCoordType>
361 const WorldCoordVector& pointWCoords,
364 typename WorldCoordVector::ComponentType& result)
370 pointWCoords, pcoords, CellShapeTag(), result));
382 template <
typename LclCellShapeTag,
typename WorldCoordVector>
385 const WorldCoordVector& pointWCoords,
386 const typename WorldCoordVector::ComponentType& wcoords,
387 typename WorldCoordVector::ComponentType& result)
389 if (pointWCoords.GetNumberOfComponents() != tag.numberOfPoints())
396 return vtkm::internal::LclErrorToVtkmError(
397 lcl::worldToParametric(tag, lcl::makeFieldAccessorNestedSOA(pointWCoords, 3), wcoords, result));
402 template <
typename WorldCoordVector,
typename CellShapeTag>
404 const WorldCoordVector& pointWCoords,
405 const typename WorldCoordVector::ComponentType& wcoords,
407 typename WorldCoordVector::ComponentType& result)
409 auto numPoints = pointWCoords.GetNumberOfComponents();
410 return internal::WorldCoordinatesToParametricCoordinatesImpl(
411 vtkm::internal::make_LclCellShapeTag(shape, numPoints), pointWCoords, wcoords, result);
414 template <
typename WorldCoordVector>
416 const WorldCoordVector&,
417 const typename WorldCoordVector::ComponentType&,
418 vtkm::CellShapeTagEmpty,
419 typename WorldCoordVector::ComponentType& result)
425 template <
typename WorldCoordVector>
427 const WorldCoordVector& pointWCoords,
428 const typename WorldCoordVector::ComponentType&,
429 vtkm::CellShapeTagVertex,
430 typename WorldCoordVector::ComponentType& result)
432 if (pointWCoords.GetNumberOfComponents() != 1)
437 result =
typename WorldCoordVector::ComponentType(0, 0, 0);
441 template <
typename WorldCoordVector>
443 const WorldCoordVector& pointWCoords,
444 const typename WorldCoordVector::ComponentType& wcoords,
445 vtkm::CellShapeTagPolyLine,
446 typename WorldCoordVector::ComponentType& result)
457 return WorldCoordinatesToParametricCoordinates(
458 pointWCoords, wcoords, vtkm::CellShapeTagVertex(), result);
461 using Vector3 =
typename WorldCoordVector::ComponentType;
462 using T =
typename Vector3::ComponentType;
466 Vector3 vec = pointWCoords[0] - wcoords;
467 T minDistSq = vtkm::Dot(vec, vec);
470 vec = pointWCoords[i] - wcoords;
471 T d = vtkm::Dot(vec, vec);
490 WorldCoordinatesToParametricCoordinates(line, wcoords, vtkm::CellShapeTagLine{}, lpc));
494 T dParam =
static_cast<T
>(1) /
static_cast<T
>(numPoints - 1);
495 T polyLineParam =
static_cast<T
>(idx - 1) * dParam + lpc[0] * dParam;
497 result = Vector3(polyLineParam, 0, 0);
501 template <
typename WorldCoordVector>
503 const WorldCoordVector& pointWCoords,
504 const typename WorldCoordVector::ComponentType& wcoords,
505 vtkm::CellShapeTagPolygon,
506 typename WorldCoordVector::ComponentType& result)
508 auto numPoints = pointWCoords.GetNumberOfComponents();
512 return WorldCoordinatesToParametricCoordinates(
513 pointWCoords, wcoords, vtkm::CellShapeTagVertex{}, result);
515 return WorldCoordinatesToParametricCoordinates(
516 pointWCoords, wcoords, vtkm::CellShapeTagLine{}, result);
518 return internal::WorldCoordinatesToParametricCoordinatesImpl(
519 lcl::Polygon(numPoints), pointWCoords, wcoords, result);
526 vtkm::CellShapeTagQuad,
529 return internal::WorldCoordinatesToParametricCoordinatesImpl(
530 lcl::Pixel{}, pointWCoords, wcoords, result);
536 vtkm::CellShapeTagHexahedron,
539 return internal::WorldCoordinatesToParametricCoordinatesImpl(
540 lcl::Voxel{}, pointWCoords, wcoords, result);
546 template <
typename WorldCoordVector>
548 const WorldCoordVector& pointWCoords,
549 const typename WorldCoordVector::ComponentType& wcoords,
551 typename WorldCoordVector::ComponentType& result)
557 pointWCoords, wcoords, CellShapeTag(), result));
568 #endif //vtk_m_exec_ParametricCoordinates_h