proj home

Files   Classes   Functions   Hierarchy  

d4tri.cpp

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <iostream>
00003 using namespace std;
00004 
00005 #include <d4tri.h>
00006 
00007 
00008 // Uninitialized tetrahedron.
00009 d4tri::d4tri()
00010 {
00011   for (uint i=0; i<4; ++i)
00012   {
00013     pi[i] = 0;
00014     ni[i] = 0;
00015   }
00016 }
00017 
00018 d4tri::d4tri
00019 (
00020   uintc a,
00021   uintc b,
00022   uintc c,
00023   uintc d,
00024   uintc na,
00025   uintc nb,
00026   uintc nc,
00027   uintc nd
00028 ) 
00029 { 
00030   construct(a,b,c,d,na,nb,nc,nd); 
00031 }
00032 
00033 /*
00034 void d4tri::solvex(uint & x, uintc a, uintc b, uintc c) const
00035 {
00036   bool y[4] = { false, false, false, false };
00037 
00038   y[a]=true;
00039   y[b]=true;
00040   y[c]=true;
00041   for (uint i=0; i<4; ++i)
00042   {
00043     if (y[i]==false)
00044     {
00045       x=i;
00046       return;
00047     }
00048   }
00049 
00050   assert(false);
00051 }
00052 */
00053 
00054 
00055 
00056 /*
00057 uintc d4tri::getoppvertex
00058 ( 
00059   uintc neib 
00060 ) const
00061 { 
00062   return pi[ niInverse(neib) ]; 
00063 }
00064 */
00065 
00066 
00067 
00068 uintc d4tri::piInverse 
00069 (
00070   bool & res,
00071   uintc gpt
00072 ) const
00073 {
00074   assert(gpt!=0);
00075 
00076   res=true;
00077 
00078   if (pi[0]==gpt) return 0;
00079   if (pi[1]==gpt) return 1;
00080   if (pi[2]==gpt) return 2;
00081   if (pi[3]==gpt) return 3;
00082 
00083   res=false;
00084   return 4; // Return crap.
00085 }
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 /*
00094 uintc d4tri::piInverse 
00095 (
00096   uintc gpt
00097 ) const
00098 {
00099   assert(gpt!=0);
00100 
00101   if (pi[0]==gpt) return 0;
00102   if (pi[1]==gpt) return 1;
00103   if (pi[2]==gpt) return 2;
00104   if (pi[3]==gpt) return 3;
00105 
00106   assert(false);
00107   return 4; // Return crap.
00108 }
00109 */
00110 
00111 boolc d4tri::isonboundary() const
00112 {
00113   if (ni[0]==0) return true;
00114   if (ni[1]==0) return true;
00115   if (ni[2]==0) return true;
00116   if (ni[3]==0) return true;
00117   
00118   return false;
00119 }
00120 
00121 /*
00122 uintc d4tri::niInverse
00123 (
00124   uintc neib
00125 ) const
00126 {  
00127   if (ni[0]==neib) return 0;
00128   if (ni[1]==neib) return 1;
00129   if (ni[2]==neib) return 2;
00130   if (ni[3]==neib) return 3;
00131 
00132   assert(false);
00133   return 4; // Return crap.
00134 }
00135 */
00136 
00137 uintc d4tri::niInverse
00138 (
00139   bool & res,
00140   uintc neib
00141 ) const
00142 {  
00143   res=true;
00144 
00145   if (ni[0]==neib) return 0;
00146   if (ni[1]==neib) return 1;
00147   if (ni[2]==neib) return 2;
00148   if (ni[3]==neib) return 3;
00149 
00150   res=false;
00151   return 4; // Return crap.
00152 }
00153 
00154 
00155 
00156 
00157 boolc d4tri::isavertex( uintc gpt ) const
00158 {
00159   if (gpt==pi[0]) return true;
00160   if (gpt==pi[1]) return true;
00161   if (gpt==pi[2]) return true;
00162   if (gpt==pi[3]) return true;
00163 
00164   return false;
00165 }
00166 
00167 
00168 
00169 
00170 
00171 ostream & d4tri::print(ostream& os) const
00172 {
00173   for (uint i=0; i<4; ++i)
00174     os << pi[i] << " ";
00175 
00176   os << "  ";
00177 
00178   for (uint i=0; i<4; ++i)
00179     os << ni[i] << " ";
00180 
00181   return os;
00182 }
00183 
00184 
00185 
00186 
00187 /*
00188 void d4tri::isneighbour
00189 (
00190   bool &res,
00191   uint & index,
00192   uintc x
00193 )
00194 {
00195   for (uint i=0; i<4; ++i)
00196   {
00197     if (x==ni[i])
00198     {
00199       res=true;
00200       index=i;
00201       return;
00202     }
00203   }
00204 
00205   res=false;
00206 }
00207 */
00208 
00209 
00210 
00211 
00212 void d4tri::construct
00213 (
00214   uintc a,
00215   uintc b,
00216   uintc c,
00217   uintc d,
00218   uintc na,
00219   uintc nb,
00220   uintc nc,
00221   uintc nd
00222 )
00223 {
00224   pi[0] = a;
00225   pi[1] = b;
00226   pi[2] = c;
00227   pi[3] = d;
00228   ni[0] = na;
00229   ni[1] = nb;
00230   ni[2] = nc;
00231   ni[3] = nd;
00232 };
00233 
00234 
00235 void d4tri::getanticlockwiseface
00236 (
00237   uint & a, 
00238   uint & b, 
00239   uint & c, 
00240   uintc face
00241 ) const 
00242 {
00243   switch (face)
00244   {
00245     case 0:
00246       a=2; b=1; c=3;
00247       break;
00248 
00249     case 1:
00250       a=0; b=2; c=3;
00251       break;
00252 
00253     case 2:
00254       a=1; b=0; c=3;
00255       break;
00256 
00257     case 3:
00258       a=0; b=1; c=2;
00259       break;
00260 
00261     default:
00262       assert(false);
00263   }
00264 }
00265 
00266 void d4tri::getclockwiseface
00267 (
00268   uint & a, 
00269   uint & b, 
00270   uint & c, 
00271   uintc face
00272 ) const 
00273 {
00274   switch (face)
00275   {
00276     case 0:
00277       a=3; b=1; c=2;
00278       break;
00279 
00280     case 1:
00281       a=3; b=2; c=0;
00282       break;
00283 
00284     case 2:
00285       a=3; b=0; c=1;
00286       break;
00287 
00288     case 3:
00289       a=2; b=1; c=0;
00290       break;
00291 
00292     default:
00293       assert(false);
00294   }
00295 
00296 //  uint a2,c2;
00297 //  getanticlockwiseface(a2,b,c2,face);
00298 
00299 //  a=c2;
00300 //  c=a2;
00301 }
00302 
00303 boolc d4tri::isnull() const
00304 {
00305   for (uint i=0; i<4; ++i)
00306   {
00307     if (pi[i]!=0)
00308       return false;
00309 
00310     if (ni[i]!=0)
00311       return false;
00312   }
00313 
00314   return true;
00315 }
00316 
00317 void d4tri::setnull()
00318 {
00319   for (uint i=0; i<4; ++i)
00320   {
00321     pi[i]=0;
00322     ni[i]=0;
00323   }
00324 }
00325 
00326 uintc d4tri::sumofpoints() const
00327 {
00328   return pi[0]+pi[1]+pi[2]+pi[3];
00329 }
00330 
00331 boolc d4tri::hassamepoints(d4tri const & w) const
00332 {
00333   if (sumofpoints()!=w.sumofpoints())
00334     return false;
00335 
00336   for (uint i=0; i<4; ++i)
00337   {
00338     bool res(false);
00339     for (uint k=0; k<4; ++k)
00340     {
00341       if (w.pi[k]==pi[i])
00342       {
00343         res=true;
00344         k=3;
00345       }
00346     }
00347     if (res==false)
00348       return false;
00349   }
00350 
00351   return true;
00352 }
00353 
00354 
00355 
00356 ostream & operator << (ostream& os, d4tri const & x)
00357 { 
00358   return x.print(os); 
00359 }
00360 

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