Files Classes Functions Hierarchy
00001 00002 #include <mathlib.h> 00003 #include <trianglespace.h> 00004 #include <d3meshpartition.h> 00005 00006 typedef point3<double> pt3; 00007 typedef point3<double> const pt3c; 00008 00009 bool const d3meshpartition::isInside(pt3c & x) const 00010 { 00011 vector<d3tri> const & vi(meshB.vi); 00012 vector<pt3> const & pt(meshB.pt); 00013 uintc sz = vi.size(); 00014 for (uint i=1; i<sz; ++i) 00015 { 00016 d3tri const & y(vi[i]); 00017 00018 trianglespace< pt3, double > t 00019 ( 00020 pt[ y.pi[0] ], 00021 pt[ y.pi[1] ], 00022 pt[ y.pi[2] ] 00023 ); 00024 00025 if (!t.isInside(x)) 00026 return true; 00027 } 00028 00029 return false; 00030 } 00031 00032 00033 00034 bool const d3meshpartition::intersection(pt3 & x, pt3c & w, pt3c & b) const 00035 { 00036 00037 vector<d3tri> const & vi(meshB.vi); 00038 vector<pt3> const & pt(meshB.pt); 00039 00040 static vector<pt3> solutions; 00041 solutions.clear(); 00042 00043 double t0,t1; 00044 00045 uintc sz = vi.size(); 00046 uint k; 00047 for (uint i=1; i<sz; ++i) 00048 { 00049 d3tri const & y(vi[i]); 00050 00051 if (y.isonboundary()==false) 00052 continue; 00053 00054 for (k=0; k<3; ++k) 00055 { 00056 if (y.ni[k]!=0) 00057 continue; 00058 00059 pt3c & c(pt[ y.pi[(k+1)%3] ]); 00060 pt3c & d(pt[ y.pi[(k+2)%3] ]); 00061 if (lineintersection(t0,t1,w,b,c,d)) 00062 { 00063 if ((t1>=0.0)&&(t1<=1.0)) 00064 solutions.push_back(c+(d-c)*t1); 00065 } 00066 } 00067 } 00068 00069 assert(solutions.empty()==false); 00070 00071 uintc solsz = solutions.size(); 00072 if (solsz==1) 00073 { 00074 x = solutions[0]; 00075 return true; 00076 } 00077 00078 uint di = 0; 00079 double dmin = (w-solutions[0]).dot(); 00080 double d; 00081 00082 for (uint i=1; i<solsz; ++i) 00083 { 00084 d = (w-solutions[i]).dot(); 00085 if (d<dmin) 00086 { 00087 dmin = d; 00088 di = i; 00089 } 00090 } 00091 00092 x = solutions[di]; 00093 return true; 00094 } 00095 00096 bool const d3meshpartition::isOnBoundary(pt3c & w, double const zero) const 00097 { 00098 // Find the simplex with the point w. 00099 00100 vector<d3tri> const & vi(meshB.vi); 00101 vector<pt3> const & pt(meshB.pt); 00102 uintc sz = vi.size(); 00103 for (uint i=1; i<sz; ++i) 00104 { 00105 d3tri const & y(vi[i]); 00106 00107 // Inefficent code. Just get working, optimize later. 00108 trianglespace< pt3, double > t 00109 ( 00110 pt[ y.pi[0] ], 00111 pt[ y.pi[1] ], 00112 pt[ y.pi[2] ] 00113 ); 00114 00115 // if (!t.isInside(w)) 00116 if (t.isOnBoundary(w,zero)) 00117 return true; 00118 } 00119 00120 return false; 00121 } 00122 00123 00124
1.5.8