20 #ifndef vtk_m_worklet_cellmetrics_CellMaxAspectFrobeniusMetric_h
21 #define vtk_m_worklet_cellmetrics_CellMaxAspectFrobeniusMetric_h
45 #define UNUSED(expr) (void)(expr);
64 template <
typename OutType,
typename VecType>
69 OutType det = (OutType)vtkm::Dot(edges[0],
vtkm::Cross(edges[1], edges[2]));
71 if (det <= vtkm::NegativeInfinity<OutType>())
72 return vtkm::Infinity<OutType>();
74 OutType term1 =
static_cast<OutType
>(
75 vtkm::Dot(edges[0], edges[0]) + vtkm::Dot(edges[1], edges[1]) + vtkm::Dot(edges[2], edges[2]));
77 VecType crosses[3] = {
vtkm::Cross(edges[0], edges[1]),
82 static_cast<OutType
>(vtkm::Dot(crosses[0], crosses[0]) + vtkm::Dot(crosses[1], crosses[1]) +
83 vtkm::Dot(crosses[2], crosses[2]));
91 template <
typename OutType,
typename Po
intCoordVecType,
typename CellShapeType>
93 const PointCoordVecType&,
105 template <
typename OutType,
typename Po
intCoordVecType>
107 const PointCoordVecType& pts,
108 vtkm::CellShapeTagPolygon,
112 return vtkm::worklet::cellmetrics::CellAspectFrobeniusMetric<OutType>(
113 numPts, pts, vtkm::CellShapeTagTriangle(), ec);
115 return CellMaxAspectFrobeniusMetric<OutType>(numPts, pts, vtkm::CellShapeTagQuad(), ec);
124 template <
typename OutType,
typename Po
intCoordVecType>
126 const PointCoordVecType&,
127 vtkm::CellShapeTagLine,
137 template <
typename OutType,
typename Po
intCoordVecType>
139 const PointCoordVecType& pts,
140 vtkm::CellShapeTagTriangle,
148 return vtkm::worklet::cellmetrics::CellAspectFrobeniusMetric<OutType>(
149 numPts, pts, vtkm::CellShapeTagTriangle(), ec);
153 template <
typename OutType,
typename Po
intCoordVecType>
155 const PointCoordVecType&,
156 vtkm::CellShapeTagPyramid,
174 template <
typename OutType,
typename Po
intCoordVecType>
176 const PointCoordVecType& pts,
177 vtkm::CellShapeTagQuad,
186 using Edge =
typename PointCoordVecType::ComponentType;
187 const Edge QuadEdges[4] = { pts[1] - pts[0], pts[2] - pts[1], pts[3] - pts[2], pts[0] - pts[3] };
201 if (ab < vtkm::NegativeInfinity<OutType>() || bc < vtkm::NegativeInfinity<OutType>() ||
202 cd < vtkm::NegativeInfinity<OutType>() || da < vtkm::NegativeInfinity<OutType>())
203 return vtkm::Infinity<OutType>();
208 qmax = qmax > qcur ? qmax : qcur;
210 qcur = (c2 + d2) / cd;
211 qmax = qmax > qcur ? qmax : qcur;
213 qcur = (d2 + a2) / da;
214 qmax = qmax > qcur ? qmax : qcur;
216 OutType max_aspect_frobenius = 0.5f * (OutType)qmax;
218 if (max_aspect_frobenius > 0)
219 vtkm::Min(max_aspect_frobenius, vtkm::Infinity<OutType>());
221 return vtkm::Max(max_aspect_frobenius, vtkm::NegativeInfinity<OutType>());
231 template <
typename OutType,
typename Po
intCoordVecType>
233 const PointCoordVecType& pts,
234 vtkm::CellShapeTagTetra,
243 return vtkm::worklet::cellmetrics::CellAspectFrobeniusMetric<OutType, PointCoordVecType>(
244 numPts, pts, vtkm::CellShapeTagTetra(), ec);
256 template <
typename OutType,
typename Po
intCoordVecType>
258 const PointCoordVecType& pts,
259 vtkm::CellShapeTagHexahedron,
268 using Edge =
typename PointCoordVecType::ComponentType;
272 const Edge TetEdges[8][3] = {
279 { pts[2] - pts[1], pts[0] - pts[1], pts[5] - pts[1] },
281 { pts[3] - pts[2], pts[1] - pts[2], pts[6] - pts[2] },
283 { pts[0] - pts[3], pts[2] - pts[3], pts[7] - pts[3] },
285 { pts[7] - pts[4], pts[5] - pts[4], pts[0] - pts[4] },
287 { pts[4] - pts[5], pts[6] - pts[5], pts[1] - pts[5] },
289 { pts[5] - pts[6], pts[7] - pts[6], pts[2] - pts[6] },
291 { pts[6] - pts[7], pts[4] - pts[7], pts[3] - pts[7] }
297 OutType max_aspect_frobenius = ComputeTetCondition<OutType, Edge>(TetEdges[0]);
301 curr = ComputeTetCondition<OutType, Edge>(TetEdges[i]);
303 return vtkm::Infinity<OutType>();
304 if (curr > max_aspect_frobenius)
305 max_aspect_frobenius = curr;
308 max_aspect_frobenius *= (OutType)0.3333333;
310 if (max_aspect_frobenius > 0)
311 return vtkm::Min(max_aspect_frobenius, vtkm::Infinity<OutType>());
313 return vtkm::Max(max_aspect_frobenius, OutType(0.0));
325 template <
typename OutType,
typename Po
intCoordVecType>
327 const PointCoordVecType& pts,
328 vtkm::CellShapeTagWedge,
337 using Vector =
typename PointCoordVecType::ComponentType;
352 OutType max_aspect_frobenius = vtkm::worklet::cellmetrics::CellAspectFrobeniusMetric<OutType>(
353 tetPts, tetras[0], vtkm::CellShapeTagTetra(), ec);
357 curr = vtkm::worklet::cellmetrics::CellAspectFrobeniusMetric<OutType>(
358 tetPts, tetras[i], vtkm::CellShapeTagTetra(), ec);
359 if (curr > max_aspect_frobenius)
360 max_aspect_frobenius = curr;
364 max_aspect_frobenius /= 1.16477;
366 if (max_aspect_frobenius > 0)
368 return vtkm::Min(max_aspect_frobenius, vtkm::Infinity<OutType>());
372 return vtkm::Max(max_aspect_frobenius, vtkm::NegativeInfinity<OutType>());
378 #endif // vtk_m_worklet_cellmetrics_CellMaxAspectFrobeniusMetric_h