cgma
|
00001 // file: GeomIntersectionTool.hpp 00002 // author: Michael Stephenson 00003 // 00004 00005 #ifndef INTERSECTION_TOOL_HPP 00006 #define INTERSECTION_TOOL_HPP 00007 00008 #include "CubitDefines.h" 00009 #include "CGMUtilConfigure.h" 00010 00011 class CubitVector; 00012 template <class X> class DLIList; 00013 00014 class CUBIT_UTIL_EXPORT IntersectionTool 00015 { 00016 public: 00017 IntersectionTool(const double &tol = 0.0001); 00018 virtual ~IntersectionTool() {} 00019 00020 virtual CubitStatus closest_points_on_segments(CubitVector &p0, 00021 CubitVector &p1, 00022 CubitVector &p2, 00023 CubitVector &p3, 00024 CubitVector &point_1, 00025 CubitVector &point_2, 00026 double &sc, double &tc); 00027 //- Finds the two closest points on the line segments {p0,p1} and {p2,p3}, 00028 //- and returns them in point_1 and point_2. Will return failure 00029 //- if a divide by zero is attempted. 00030 00031 double distance_point_line(const double point[3], const double start[3], 00032 const double end[3], double &t); 00033 int point_on_polyline(CubitVector& pt, DLIList<CubitVector*> &pt_list, 00034 double *tol_in = NULL); 00035 00036 double parametric_position(const double node[3], 00037 const double pt1[3], 00038 const double pt2[3]); 00039 00050 00051 virtual CubitStatus initialize(){return CUBIT_SUCCESS;} 00052 00053 // The following copyright applies to the following two functions... 00054 // 00055 // Copyright 2001, softSurfer (www.softsurfer.com) 00056 // 00057 // This code may be freely used and modified for any purpose 00058 // providing that this copyright notice is included with it. 00059 // SoftSurfer makes no warranty for this code, and cannot be held 00060 // liable for any real or imagined damage resulting from its use. 00061 // Users of this code must verify correctness for their application. 00062 00063 static int intersect_triangle_with_ray( CubitVector &ray_origin, CubitVector &ray_direction, 00064 const CubitVector *p0, const CubitVector *p1, const CubitVector *p2, 00065 CubitVector* point, double &distance, int &edge_hit ); 00066 //- Find intersection point of a ray and a triangle 00067 // Return: -1 = triangle is degenerate (a segment or point) 00068 // 0 = disjoint (no intersect) 00069 // 1 = intersect at unique point 00070 // 2 = are in the same plane 00071 00072 static int intersect_segment_with_ray( CubitVector &ray_origin, CubitVector &ray_direction, 00073 const CubitVector *p0, const CubitVector *p1, 00074 CubitVector* point, double &distance, int &point_hit, double tol=0.0 ); 00075 //- Find intersection point of a ray and a facet edge 00076 // Return: -1 = edge is degenerate (a point) 00077 // 0 = disjoint (no intersect) 00078 // 1 = intersect at unique point 00079 // 2 = are the same line (infinite points) 00080 00081 static int intersect_point_with_ray( CubitVector &ray_origin, CubitVector &ray_direction, 00082 const CubitVector* point, double &distance, double tol=0.0); 00083 //- Find intersection of a ray and a point 00084 // Return: 0 = no intersection 00085 // 1 = intersection 00086 00087 00088 protected: 00089 double mTolerance; 00090 double mToleranceSquared; 00091 00092 CubitBoolean ray_tri_test(const double start[3], const double dir[3], 00093 const double tri1[3], const double tri2[3], 00094 const double tri3[3], 00095 double &t, double &alpha, double &beta); 00096 00097 CubitBoolean skew_line_test(const double start1[3], const double end1[3], 00098 const double start2[3], const double end2[3], 00099 double &t, double &u); 00100 00101 void tolerance(const double &tol); 00102 double tolerance(void) const; 00103 00104 private: 00105 }; 00106 00107 inline IntersectionTool::IntersectionTool(const double &tol) 00108 : mTolerance(tol) 00109 { 00110 mToleranceSquared = tol * tol; 00111 } 00112 00113 #endif // INTERSECTION_TOOL_HPP 00114