proj home

Files   Classes   Functions   Hierarchy  

d4minboundary.cpp

Go to the documentation of this file.
00001 #include <d4minboundary.h>
00002 
00003 #include <iostream>
00004 #include <algorithm>
00005 using namespace std;
00006 
00007 #include <mathlib.h>
00008 #include <print.h>
00009 
00010 
00011 #include <d4tess.h>
00012 
00013 /*
00014 
00015 d4mingreedy::d4mingreedy(d4tess & _tess)
00016   : d4minoperator(_tess) 
00017 {
00018 }
00019 
00020 bool const d4mingreedy::eval(uintc a, uintc b)
00021 {
00022   return tess.tet2to3_(a,b);
00023 }
00024 */
00025 
00026 
00027 
00028 
00029 
00030 d4minboundary::d4minboundary(d4tess & _tess)
00031   : d4minoperator(_tess)
00032 {
00033 }
00034 
00035 
00036 
00037 
00038 
00039 
00040 bool const d4minboundary::eval(uintc a, uintc b)
00041 {
00042 MessageGlobal mg;
00043 
00044   mg() << "a=" << a << " b=" << b << " convex " << tess.isconvex(a,b) << endl;
00045 
00046   if (tess.isconvex(a,b)==false)
00047     return false;
00048 
00049   uint aj[5];
00050 
00051   d4tri const A(tess.vi[a]);
00052   aj[0] = A.niInverse(b);
00053 
00054   d4tri const B(tess.vi[b]);
00055   aj[4] = B.niInverse(a);
00056 
00057   A.getclockwiseface(aj[1],aj[2],aj[3],aj[0]);
00058 
00059   uint pj[5];
00060   for (uint i=0; i<4; ++i)
00061     pj[i] = A.pi[aj[i]];
00062   pj[4] = B.pi[aj[4]];
00063 
00064 for (uint i=0; i<5; ++i)
00065   mg() << "aj[" << i << "]=" << aj[i] << " ";
00066 mg() << endl;
00067 for (uint i=0; i<5; ++i)
00068   mg() << "pj[" << i << "]=" << pj[i] << " ";
00069 mg() << endl;
00070 
00071   // Find which combination of tetrahedrons has 
00072   // the minimal boundary.
00073 
00074   // There are two possible tetrahedron permuations.
00075   // The current on has one inner partition through p0,p1,p2.
00076   //
00077   // The other permutation has three blades off line p0 to p4, to points p1,p2,p3.
00078   //
00079   // Choose the permutation with the minimum boundary area.
00080 
00081   double area1;
00082   trianglearea
00083   (
00084     area1,
00085     tess.pt[pj[1]],
00086     tess.pt[pj[2]],
00087     tess.pt[pj[3]]
00088   );
00089 
00090 mg() << SHOW(area1) << endl;
00091 
00092   double area2=0.0;
00093 
00094   double area;
00095 
00096   for (uint i=1; i<4; ++i)
00097   {
00098     trianglearea
00099     (
00100       area,
00101       tess.pt[pj[4]],
00102       tess.pt[pj[i]],
00103       tess.pt[pj[0]]
00104     );
00105 
00106     area2 += area;
00107   }
00108 
00109 mg() << SHOW(area2) << endl;
00110 
00111   if (area1<area2)
00112     return false;
00113 
00114 mg() << "FUCK" << endl;
00115 
00116 
00117   // nj[0] is ignored.
00118   // the indexes correspond with the points : the neighbour is opposite the point
00119   // with the same index.  For neighbours >3 simply subtract 3 and that is the
00120   // index for the second tetrahedron.
00121   uint nj[7];
00122   
00123   for (uint i=1; i<=3; ++i)
00124     nj[i] = A.ni[aj[i]];
00125 
00126   for (uint i=4; i<=6; ++i)
00127     nj[i] = B.ni[ B.piInverse(pj[i-3]) ];
00128 
00129 for (uint i=1; i<=6; ++i)
00130   mg() << "nj[" << i << "]=" << nj[i] << " ";
00131 mg() << endl;
00132 
00133   uint k1(a), k2(b), k3(tess.vi.size());
00134 
00135   tess.vi[a] = d4tri( pj[4],pj[2],pj[0],pj[3], nj[1],k3,nj[4],k2 );
00136   tess.vi[b] = d4tri( pj[4],pj[0],pj[2],pj[1], nj[3],nj[6],k3,k1 );
00137   tess.vi.push_back( d4tri( pj[4],pj[0],pj[1],pj[3], nj[2],nj[5],k1,k2 ) );
00138 
00139   if (nj[1]!=0)
00140     tess.vi[nj[1]].niReset(a,k1);
00141   if (nj[2]!=0)
00142     tess.vi[nj[2]].niReset(a,k3);
00143   if (nj[3]!=0)
00144     tess.vi[nj[3]].niReset(a,k2);
00145   if (nj[4]!=0)
00146     tess.vi[nj[4]].niReset(b,k1);
00147   if (nj[5]!=0)
00148     tess.vi[nj[5]].niReset(b,k3);
00149   if (nj[6]!=0)
00150     tess.vi[nj[6]].niReset(b,k2);
00151 
00152   tess.debugcheck();
00153 
00154   return true;
00155 }
00156 
00157 
00158 bool const d4mingreedy2::eval(uintc a, uintc b)
00159 {
00160   if (tess.isconvex(a,b)==false)
00161     return false;
00162 
00163   d4tri A(tess.vi[a]);
00164   d4tri B(tess.vi[b]);
00165 
00166   uint ai = A.niInverse(b);
00167   uint bi = B.niInverse(a);
00168 
00169   double const z = dist(A.pi[ai], B.pi[bi]);
00170 
00171   double l[3];
00172   uint u[3];
00173   A.getanticlockwiseface(u[0],u[1],u[2],ai);
00174   l[0] = dist(u[0],u[1]);
00175   l[1] = dist(u[1],u[2]);
00176   l[2] = dist(u[2],u[0]);
00177 
00178 
00179 
00180   // Order l[0],l[1],l[2] from smallest to largest.
00181 
00182   sort(l,l+3);
00183 
00184 cout << SHOW(l[0]) << " ";
00185 cout << SHOW(l[1]) << " ";
00186 cout << SHOW(l[2]) << " ";
00187 cout << SHOW(z) << endl;
00188 
00189   assert(l[2]!=0.0);
00190   
00191   // This is the ideal length of z when the tetrahedrons
00192   // have equal lengths and side lengths of 1.
00193   //double const e = 1.32287;
00194 
00195   // Ratio of l[2] to z;
00196   double const r = 1.5;
00197 
00198   if (z>l[2]*r)
00199   {
00200     cout << "large z" << endl;
00201     return twotetrahedronMInvert(a,ai,b,bi);
00202   }
00203 
00204   // Test for thin triangle boundary.
00205   if (approximatelyequal(l[2],l[1]))
00206   {
00207     cout << "thin triangle" << endl; 
00208     return twotetrahedronMInvert(a,ai,b,bi);
00209   }
00210 
00211   cout << "tet2to3" << endl;
00212 
00213   return tess.tet2to3(a,b);
00214 }
00215 

Generated on Fri Mar 4 00:49:31 2011 for Chelton Evans Source by  doxygen 1.5.8