Files Classes Functions Hierarchy
00001 #include <iostream> 00002 using namespace std; 00003 00004 #include <delaunay3D.h> 00005 #include <halfspaceD3.h> 00006 #include <tetrahedron.h> 00007 00008 00009 delaunay3D::delaunay3D 00010 ( 00011 vector<point3<double> > const & vi_ 00012 ) 00013 : vi(vi_) 00014 { 00015 n = vi.size(); 00016 } 00017 00018 void delaunay3D::eval() 00019 { 00020 tet.clear(); 00021 00022 if (n>200) 00023 { 00024 cout << "error: n is too large." << endl; 00025 cout << " this is an O(n^5) algorithm." << endl; 00026 return; 00027 } 00028 00029 uint a,i,j,k; 00030 00031 for (i=0; i<n-3; ++i) 00032 { 00033 for (j=i+1; j<n-2; ++j) 00034 { 00035 for (k=j+1; k<n-1; ++k) 00036 { 00037 for (a=k+1; a<n; ++a) 00038 { 00039 evaluateTetrahedron(i,j,k,a); 00040 } 00041 } 00042 } 00043 } 00044 } 00045 00046 bool const delaunay3D::evaluateTetrahedron 00047 ( 00048 uintc i, 00049 uintc j, 00050 uintc k, 00051 uintc a 00052 ) 00053 { 00054 point3<double> const & P0(vi[i]); 00055 point3<double> const & P1(vi[j]); 00056 point3<double> const & P2(vi[k]); 00057 point3<double> const & P3(vi[a]); 00058 00059 //tetrahedron< point3<double>,double> const t(P0,P1,P2,P3); 00060 tetrahedron< point3<double>,double> t; 00061 t.constructUnordered(P0,P1,P2,P3); 00062 00063 point3<double> c0; 00064 t.circumcenter(c0); 00065 point3<double> const c(c0); 00066 00067 // Avoid the square root function by comparing 00068 // the distance squared. 00069 double const dist = (P0-c).dot(); 00070 00071 for (uint w=0; w<n; ++w) 00072 { 00073 if (w==i) 00074 continue; 00075 if (w==j) 00076 continue; 00077 if (w==k) 00078 continue; 00079 if (w==a) 00080 continue; 00081 00082 if ( ((vi[w]-c).dot()) < dist ) 00083 return false; 00084 } 00085 00086 halfspaceD3< point3<double>,double> h(P0,P1,P2); 00087 00088 //if (! h.eval(P3)) 00089 if (! h.isInside(P3)) 00090 tet.push_back( point4<uint>(i,j,k,a) ); 00091 else 00092 tet.push_back( point4<uint>(k,j,i,a) ); 00093 00094 return true; 00095 } 00096 00097
1.5.8