VTK-m  2.0
TypeOfCellTriangle.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 // This software is distributed WITHOUT ANY WARRANTY; without even
6 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 // PURPOSE. See the above copyright notice for more information.
8 //
9 // Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 // Copyright 2018 UT-Battelle, LLC.
11 // Copyright 2018 Los Alamos National Security.
12 //
13 // Under the terms of Contract DE-NA0003525 with NTESS,
14 // the U.S. Government retains certain rights in this software.
15 //
16 // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 // Laboratory (LANL), the U.S. Government retains certain rights in
18 // this software.
19 //============================================================================
20 #ifndef vtk_m_worklet_cellmetrics_TypeOfCellTriangle
21 #define vtk_m_worklet_cellmetrics_TypeOfCellTriangle
22 
35 #include <vtkm/Math.h>
36 #include <vtkm/VectorAnalysis.h>
37 
38 
45 template <typename Scalar, typename Vector, typename CollectionOfPoints>
46 VTKM_EXEC Vector GetTriangleL0(const CollectionOfPoints& pts)
47 {
48  const Vector L0(pts[2] - pts[1]);
49  return L0;
50 }
51 
58 template <typename Scalar, typename Vector, typename CollectionOfPoints>
59 VTKM_EXEC Vector GetTriangleL1(const CollectionOfPoints& pts)
60 {
61  const Vector L1(pts[0] - pts[2]);
62  return L1;
63 }
64 
71 template <typename Scalar, typename Vector, typename CollectionOfPoints>
72 VTKM_EXEC Vector GetTriangleL2(const CollectionOfPoints& pts)
73 {
74  const Vector L2(pts[1] - pts[0]);
75  return L2;
76 }
77 
84 template <typename Scalar, typename Vector, typename CollectionOfPoints>
85 VTKM_EXEC Scalar GetTriangleL0Magnitude(const CollectionOfPoints& pts)
86 {
87  const Scalar l0 = static_cast<Scalar>(
88  vtkm::Sqrt(vtkm::MagnitudeSquared(GetTriangleL0<Scalar, Vector, CollectionOfPoints>(pts))));
89  return l0;
90 }
91 
98 template <typename Scalar, typename Vector, typename CollectionOfPoints>
99 VTKM_EXEC Scalar GetTriangleL1Magnitude(const CollectionOfPoints& pts)
100 {
101  const Scalar l1 = static_cast<Scalar>(
102  vtkm::Sqrt(vtkm::MagnitudeSquared(GetTriangleL1<Scalar, Vector, CollectionOfPoints>(pts))));
103  return l1;
104 }
105 
112 template <typename Scalar, typename Vector, typename CollectionOfPoints>
113 VTKM_EXEC Scalar GetTriangleL2Magnitude(const CollectionOfPoints& pts)
114 {
115  const Scalar l2 = static_cast<Scalar>(
116  vtkm::Sqrt(vtkm::MagnitudeSquared(GetTriangleL2<Scalar, Vector, CollectionOfPoints>(pts))));
117  return l2;
118 }
119 
129 template <typename Scalar, typename Vector, typename CollectionOfPoints>
130 VTKM_EXEC Scalar GetTriangleLMax(const CollectionOfPoints& pts)
131 {
132  const Scalar l0 = GetTriangleL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
133  const Scalar l1 = GetTriangleL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
134  const Scalar l2 = GetTriangleL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
135  const Scalar lmax = vtkm::Max(l0, vtkm::Max(l1, l2));
136  return lmax;
137 }
138 
148 template <typename Scalar, typename Vector, typename CollectionOfPoints>
149 VTKM_EXEC Scalar GetTriangleLMin(const CollectionOfPoints& pts)
150 {
151  const Scalar l0 = GetTriangleL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
152  const Scalar l1 = GetTriangleL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
153  const Scalar l2 = GetTriangleL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
154  const Scalar lmin = vtkm::Min(l0, vtkm::Min(l1, l2));
155  return lmin;
156 }
157 
165 template <typename Scalar, typename Vector, typename CollectionOfPoints>
166 VTKM_EXEC Scalar GetTriangleArea(const CollectionOfPoints& pts)
167 {
168  const Vector L0 = GetTriangleL0<Scalar, Vector, CollectionOfPoints>(pts);
169  const Vector L1 = GetTriangleL1<Scalar, Vector, CollectionOfPoints>(pts);
170  const Scalar hhalf(0.5);
171  const Scalar crossProductMagnitude =
172  static_cast<Scalar>(vtkm::Sqrt(vtkm::MagnitudeSquared(vtkm::Cross(L0, L1))));
173  const Scalar area = hhalf * crossProductMagnitude;
174  return area;
175 }
176 
184 template <typename Scalar, typename Vector, typename CollectionOfPoints>
185 VTKM_EXEC Scalar GetTriangleInradius(const CollectionOfPoints& pts)
186 {
187  const Scalar two(2.0);
188  const Scalar area = GetTriangleArea<Scalar, Vector, CollectionOfPoints>(pts);
189  const Scalar l0 = GetTriangleL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
190  const Scalar l1 = GetTriangleL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
191  const Scalar l2 = GetTriangleL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
192  const Scalar inradius = (two * area) / (l0 + l1 + l2);
193  return inradius;
194 }
195 
203 template <typename Scalar, typename Vector, typename CollectionOfPoints>
204 VTKM_EXEC Scalar GetTriangleCircumradius(const CollectionOfPoints& pts)
205 {
206  const Scalar four(4.0);
207  const Scalar area = GetTriangleArea<Scalar, Vector, CollectionOfPoints>(pts);
208  const Scalar l0 = GetTriangleL0Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
209  const Scalar l1 = GetTriangleL1Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
210  const Scalar l2 = GetTriangleL2Magnitude<Scalar, Vector, CollectionOfPoints>(pts);
211  const Scalar circumradius = (l0 * l1 * l2) / (four * area);
212  return circumradius;
213 }
214 
215 #endif
vtkm::Sqrt
VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
Compute the square root of x.
Definition: Math.h:958
GetTriangleLMin
VTKM_EXEC Scalar GetTriangleLMin(const CollectionOfPoints &pts)
Returns the Min of the magnitude of each vector which makes up the sides of the triangle.
Definition: TypeOfCellTriangle.h:149
GetTriangleL2
VTKM_EXEC Vector GetTriangleL2(const CollectionOfPoints &pts)
Returns the L2 vector, as defined by the verdict manual.
Definition: TypeOfCellTriangle.h:72
GetTriangleInradius
VTKM_EXEC Scalar GetTriangleInradius(const CollectionOfPoints &pts)
Returns the radius of a circle inscribed within the given triangle.
Definition: TypeOfCellTriangle.h:185
vtkm::MagnitudeSquared
VTKM_EXEC_CONT detail::FloatingPointReturnType< T >::Type MagnitudeSquared(const T &x)
Returns the square of the magnitude of a vector.
Definition: VectorAnalysis.h:64
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
GetTriangleArea
VTKM_EXEC Scalar GetTriangleArea(const CollectionOfPoints &pts)
Returns the area of the triangle.
Definition: TypeOfCellTriangle.h:166
GetTriangleL0Magnitude
VTKM_EXEC Scalar GetTriangleL0Magnitude(const CollectionOfPoints &pts)
Returns the L0 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellTriangle.h:85
GetTriangleL1
VTKM_EXEC Vector GetTriangleL1(const CollectionOfPoints &pts)
Returns the L1 vector, as defined by the verdict manual.
Definition: TypeOfCellTriangle.h:59
VectorAnalysis.h
GetTriangleL1Magnitude
VTKM_EXEC Scalar GetTriangleL1Magnitude(const CollectionOfPoints &pts)
Returns the L1 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellTriangle.h:99
Math.h
vtkm::Cross
VTKM_EXEC_CONT vtkm::Vec< typename detail::FloatingPointReturnType< T >::Type, 3 > Cross(const vtkm::Vec< T, 3 > &x, const vtkm::Vec< T, 3 > &y)
Find the cross product of two vectors.
Definition: VectorAnalysis.h:177
GetTriangleL0
VTKM_EXEC Vector GetTriangleL0(const CollectionOfPoints &pts)
The Verdict manual defines a set of commonly used components of a triangle.
Definition: TypeOfCellTriangle.h:46
GetTriangleL2Magnitude
VTKM_EXEC Scalar GetTriangleL2Magnitude(const CollectionOfPoints &pts)
Returns the L2 vector's magnitude, as defined by the verdict manual.
Definition: TypeOfCellTriangle.h:113
GetTriangleCircumradius
VTKM_EXEC Scalar GetTriangleCircumradius(const CollectionOfPoints &pts)
Returns the radius of a circle circumscribed around the given triangle.
Definition: TypeOfCellTriangle.h:204
GetTriangleLMax
VTKM_EXEC Scalar GetTriangleLMax(const CollectionOfPoints &pts)
Returns the Max of the magnitude of each vector which makes up the sides of the triangle.
Definition: TypeOfCellTriangle.h:130