File indexing completed on 2025-01-18 10:14:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef VECGEOM_VOLUMES_TETSTRUCT_H_
0010 #define VECGEOM_VOLUMES_TETSTRUCT_H_
0011 #include "VecGeom/base/Global.h"
0012 #include "VecGeom/base/Vector3D.h"
0013
0014 namespace vecgeom {
0015
0016 inline namespace VECGEOM_IMPL_NAMESPACE {
0017
0018
0019 template <typename T = double>
0020 struct TetStruct {
0021
0022 Vector3D<T> fVertex[4];
0023 struct {
0024 Vector3D<T> n;
0025 T d;
0026 } fPlane[4];
0027
0028 Precision fCubicVolume;
0029 Precision fSurfaceArea;
0030
0031
0032 VECCORE_ATT_HOST_DEVICE
0033 TetStruct() {}
0034
0035
0036
0037
0038
0039
0040 VECCORE_ATT_HOST_DEVICE
0041 TetStruct(const T p0[], const T p1[], const T p2[], const T p3[])
0042 {
0043 Vector3D<T> vertices[4];
0044 vertices[0].Set(p0[0], p0[1], p0[2]);
0045 vertices[1].Set(p1[0], p1[1], p1[2]);
0046 vertices[2].Set(p2[0], p2[1], p2[2]);
0047 vertices[3].Set(p3[0], p3[1], p3[2]);
0048
0049 CalculateCached(vertices[0], vertices[1], vertices[2], vertices[3]);
0050 }
0051
0052
0053
0054
0055
0056
0057 VECCORE_ATT_HOST_DEVICE
0058 TetStruct(const Vector3D<T> p0, const Vector3D<T> p1, const Vector3D<T> p2, const Vector3D<T> p3)
0059 : fCubicVolume(0.), fSurfaceArea(0.)
0060 {
0061
0062 CalculateCached(p0, p1, p2, p3);
0063 }
0064
0065
0066
0067
0068
0069
0070 VECCORE_ATT_HOST_DEVICE
0071 void CalculateCached(const Vector3D<T> p0, const Vector3D<T> p1, const Vector3D<T> p2, const Vector3D<T> p3)
0072 {
0073
0074 fVertex[0] = p0;
0075 fVertex[1] = p1;
0076 fVertex[2] = p2;
0077 fVertex[3] = p3;
0078
0079
0080 CheckDegeneracy();
0081
0082 Vector3D<Precision> n0 = (fVertex[1] - fVertex[0]).Cross(fVertex[2] - fVertex[0]).Unit();
0083 Vector3D<Precision> n1 = (fVertex[2] - fVertex[1]).Cross(fVertex[3] - fVertex[1]).Unit();
0084 Vector3D<Precision> n2 = (fVertex[3] - fVertex[2]).Cross(fVertex[0] - fVertex[2]).Unit();
0085 Vector3D<Precision> n3 = (fVertex[0] - fVertex[3]).Cross(fVertex[1] - fVertex[3]).Unit();
0086
0087 if (n0.Dot(fVertex[3] - fVertex[0]) > 0) n0 = -n0;
0088 if (n1.Dot(fVertex[0] - fVertex[1]) > 0) n1 = -n1;
0089 if (n2.Dot(fVertex[1] - fVertex[2]) > 0) n2 = -n2;
0090 if (n3.Dot(fVertex[2] - fVertex[3]) > 0) n3 = -n3;
0091
0092 fPlane[0].n = n0;
0093 fPlane[0].d = -n0.Dot(fVertex[0]);
0094
0095
0096 fPlane[1].n = n1;
0097 fPlane[1].d = -n1.Dot(fVertex[1]);
0098
0099
0100 fPlane[2].n = n2;
0101 fPlane[2].d = -n2.Dot(fVertex[2]);
0102
0103
0104 fPlane[3].n = n3;
0105 fPlane[3].d = -n3.Dot(fVertex[3]);
0106
0107
0108 for (int i = 0; i < 4; i++) {
0109
0110 }
0111 }
0112
0113
0114 VECCORE_ATT_HOST_DEVICE
0115 void CalcCapacity()
0116 {
0117 fCubicVolume =
0118 vecCore::math::Abs((fVertex[1] - fVertex[0]).Dot((fVertex[2] - fVertex[0]).Cross(fVertex[3] - fVertex[0]))) /
0119 6.;
0120 }
0121
0122
0123 VECCORE_ATT_HOST_DEVICE
0124 void CalcSurfaceArea()
0125 {
0126 fSurfaceArea = ((fVertex[1] - fVertex[0]).Cross(fVertex[2] - fVertex[0]).Mag() +
0127 (fVertex[2] - fVertex[1]).Cross(fVertex[3] - fVertex[1]).Mag() +
0128 (fVertex[3] - fVertex[2]).Cross(fVertex[0] - fVertex[2]).Mag() +
0129 (fVertex[0] - fVertex[3]).Cross(fVertex[1] - fVertex[3]).Mag()) *
0130 0.5;
0131 }
0132
0133
0134
0135
0136
0137
0138 VECCORE_ATT_HOST_DEVICE
0139 void SetParameters(const Vector3D<T> p0, const Vector3D<T> p1, const Vector3D<T> p2, const Vector3D<T> p3)
0140 {
0141 CalculateCached(p0, p1, p2, p3);
0142 }
0143
0144
0145
0146 VECCORE_ATT_HOST_DEVICE
0147 bool CheckDegeneracy()
0148 {
0149 CalcCapacity();
0150 CalcSurfaceArea();
0151 if (fCubicVolume < kTolerance * kTolerance * kTolerance) return true;
0152 Precision s0 = (fVertex[1] - fVertex[0]).Cross(fVertex[2] - fVertex[0]).Mag() * 0.5;
0153 Precision s1 = (fVertex[2] - fVertex[1]).Cross(fVertex[3] - fVertex[1]).Mag() * 0.5;
0154 Precision s2 = (fVertex[3] - fVertex[2]).Cross(fVertex[0] - fVertex[2]).Mag() * 0.5;
0155 Precision s3 = (fVertex[0] - fVertex[3]).Cross(fVertex[1] - fVertex[3]).Mag() * 0.5;
0156 return (vecCore::math::Max(vecCore::math::Max(vecCore::math::Max(s0, s1), s2), s3) < 2 * kTolerance);
0157 }
0158 };
0159
0160 }
0161 }
0162
0163 #endif