3 template<
typename Real,
typename Coord, DeviceType deviceType,
typename IndexType>
11 bool validate =
false;
14 for (
uint j = 0; j < list.
size(); j++)
40 TTriangle3D<Real> t_min(vertices[index_min[0]], vertices[index_min[1]], vertices[index_min[2]]);
66 TTriangle3D<Real> tri(vertices[index[0]], vertices[index[1]], vertices[index[2]]);
68 Coord n = pi.origin - p3d.
point;
82 template<
typename Real,
typename Coord, DeviceType deviceType,
typename IndexType>
87 bool validate =
false;
90 for (
uint j = 0; j < list.
size(); j++)
115 TTriangle3D<Real> tri(vertices[index[0]], vertices[index[1]], vertices[index[2]]);
117 Coord n = pi.origin - p3d.
point;
127 template <
typename Coord,DeviceType deviceType,
typename IndexType>
140 int p = surf_triangles[surf_id][0];
141 int q = surf_triangles[surf_id][1];
142 int r = surf_triangles[surf_id][2];
143 Coord p0 = surf_points[p];
144 Coord p1 = surf_points[q];
145 Coord p2 = surf_points[r];
147 int eid00 = t2e[surf_id][0];
148 int eid11 = t2e[surf_id][1];
149 int eid22 = t2e[surf_id][2];
150 int te00 = glm::min(p, q), te01 = glm::max(p, q);
151 int te10 = glm::min(q, r), te11 = glm::max(q, r);
152 int te20 = glm::min(r, p), te21 = glm::max(r, p);
153 int eid0, eid1, eid2;
154 if (edge[eid00][0] == te00&& edge[eid00][1] == te01)
157 if (edge[eid11][0] == te10&& edge[eid11][1] == te11)
168 else if (edge[eid00][0] == te10&& edge[eid00][1] == te11)
171 if (edge[eid11][0] == te00&& edge[eid11][1] == te01)
182 else if (edge[eid00][0] == te20 && edge[eid00][1] == te21)
185 if (edge[eid11][0] == te00 && edge[eid11][1] == te01)
197 Coord dir = p0 - ppos;
204 Real d = e0.dot(dir);
205 Real e = e1.dot(dir);
206 Real f = dir.dot(dir);
208 Real det = a * c - b * b;
209 Real s = b * e - c * d;
210 Real t = b * d - a * e;
216 Real g = e2.normSquared();
237 Coord el = ppos - op0;
238 Coord edir = op1 - op0;
241 pobject = surf_points[oe[0]];
242 pnormal = vertexN[oe[0]];
246 Real et = el.dot(edir) / edir.normSquared();
250 pobject = surf_points[oe[0]];
251 pnormal = vertexN[oe[0]];
256 pobject = surf_points[oe[1]];
257 pnormal = vertexN[oe[1]];
262 Coord eq = op0 + et * edir;
264 if (oe ==
EKey(edge[eid0][0], edge[eid0][1]))
266 pnormal = edgeN[eid0];
269 else if (oe ==
EKey(edge[eid1][0], edge[eid1][1]))
271 pnormal = edgeN[eid1];
274 else if (oe ==
EKey(edge[eid2][0], edge[eid2][1]))
276 pnormal = edgeN[eid2];
295 t = (e >= 0 ? 0 : (-e >= c ? 1 : -e / c));
303 s = (d >= 0 ? 0 : (-d >= a ? 1 : -d / a));
309 Real invDet = 1 / det;
332 Real numer = c + e - b - d;
337 Real denom = a - 2 * b + c;
338 s = (numer >= denom ? 1 : numer / denom);
343 pobject = (p0 + s * e0 + t * e1);
344 if (s == 0 && t == 0)
346 pnormal = vertexN[p];
350 else if (s == 0 && t == 1)
352 pnormal = vertexN[r];
356 else if (s == 1 && t == 0)
358 pnormal = vertexN[q];
362 else if (s == 0 && t < 1)
364 pnormal = edgeN[eid2];
368 else if (s < 1 && t == 0)
370 pnormal = edgeN[eid0];
376 pnormal = edgeN[eid1];
382 pnormal = (p1 - p0).
cross(p2 - p0);
388 template<
typename Real,
typename Coord, DeviceType deviceType,
typename IndexType>
405 bool validate =
false;
406 for (
uint j = 0; j < list.
size(); j++)
408 Coord pnormal(0), pobject(0);
413 Real d =
sign * (point - pobject).norm();
This class is designed to be elegant, so it can be directly passed to GPU as parameters.
Be aware do not use this structure on GPU if the data size is large.
2D geometric primitives in three-dimensional space
0D geometric primitive in three-dimensional space
DYN_FUNC Real distance(const TPoint3D< Real > &pt) const
DYN_FUNC Coord3D normal() const
Vector< PointType, 3 > Triangle
This is an implementation of AdditiveCCD based on peridyno.
DYN_FUNC int sign(T const &a, T const EPS=EPSILON)
constexpr Real REAL_EPSILON_SQUARED
DYN_FUNC bool calculateSignedDistance2TriangleSet(ProjectedPoint3D< Real > &p3d, Coord point, Array< Coord, deviceType > &vertices, Array< TopologyModule::Triangle, deviceType > &indices, List< IndexType > &list, Real dHat=0)
Calculate the signed distance from a point to a triangular mesh.
DYN_FUNC void SO_ComputeObjectAndNormal(Coord &pobject, Coord &pnormal, Array< Coord, deviceType > &surf_points, Array< TopologyModule::Edge, deviceType > &edge, Array< TopologyModule::Triangle, deviceType > &surf_triangles, Array< TopologyModule::Tri2Edg, deviceType > &t2e, Array< Coord, deviceType > &edgeN, Array< Coord, deviceType > &vertexN, Coord ppos, IndexType surf_id)
DYN_FUNC bool calculateDistance2TriangleSet(ProjectedPoint3D< Real > &p3d, Coord point, Array< Coord, deviceType > &vertices, Array< TopologyModule::Triangle, deviceType > &indices, List< IndexType > &list, Real dHat=0)
Calculate the distance from a point to a triangular mesh.
DYN_FUNC Vector< T, 3 > cross(Vector< T, 3 > const &U, Vector< T, 3 > const &V)
DYN_FUNC T dot(Vector< T, 2 > const &U, Vector< T, 2 > const &V)
constexpr Real REAL_EPSILON
DYN_FUNC T maximum(const T &v0, const T &v1)
DYN_FUNC bool calculateSignedDistance2TriangleSetFromNormal(ProjectedPoint3D< Real > &p3d, Coord point, Array< Coord, deviceType > &vertices, Array< TopologyModule::Edge, deviceType > &edges, Array< TopologyModule::Triangle, deviceType > &triangles, Array< TopologyModule::Tri2Edg, deviceType > &t2e, Array< Coord, deviceType > &edgeNormal, Array< Coord, deviceType > &vertexNormal, List< IndexType > &list, Real dHat=0)