proj home

Files   Classes   Functions   Hierarchy  

d4fan.cpp

Go to the documentation of this file.
00001 
00002 #include <print.h>
00003 
00004 
00005 #include <d4tess.h>
00006 #include <d4fan.h>
00007 
00008 
00009 
00010 
00011 
00012 
00013 d4fan::d4fan( d4tess & _tess )
00014   : tess(_tess)
00015 {
00016 }
00017 
00018 
00019 void d4fan::addspike()
00020 {
00021   uint index = tess.vi.size();
00022   tess.vi.push_back( d4tri() );
00023   d4tri & ti(tess.vi[index]);
00024   d4tri const & x(tess.cpsimplex());
00025 
00026   virtualtetrahedron const & vs(tess.vs);
00027 
00028   cp = tess.cpsimplexface();
00029 
00030   ti.pi[0] = x.pi[ vs.v[0] ];
00031   ti.pi[1] = x.pi[ vs.v[2] ];
00032   ti.pi[2] = x.pi[ vs.v[1] ];
00033   ti.pi[3] = w;
00034   ti.ni[3] = cp.id;
00035 
00036   stot[cp] = index;
00037 }
00038 
00039 
00040 bool const d4fan::link(uint & ktni, uintc kt)
00041 {
00042   cp = tess.cpsimplexface();
00043 
00044   // Is the cp on the boundary or already processed?
00045   if (dead.find(cp)!=dead.end())
00046     return false;
00047 
00048   // Does the tetrahedron already exist?
00049   if (stot.find(cp)==stot.end())
00050   {
00051   
00052     if (tess.surfaceviewable(w)==false)
00053     {
00054       dead.insert(cp);
00055       return false;
00056     }
00057 
00058     addspike();
00059   }
00060 
00061   // This cp must be processed at a later date.
00062   process.push_back(cp);
00063 
00064 
00065   // Get the point on the surface base opposite the central triangle.
00066   uint p2 = tess.vi[cp.id].pi[ tess.vs.v[2] ];
00067 
00068   uintc z = stot[cp];
00069 
00070   d4tri & x(tess.vi[z]);
00071   x.niFrompiInverse(p2) = kt;
00072   ktni = z;
00073    
00074   return true;
00075 }
00076 
00077 
00078 void d4fan::eval(uintc _w )
00079 {
00080   w = _w;
00081   dead.clear();
00082   stot.clear();
00083   process.clear();
00084 
00085   process.push_back(cp = tess.cpsimplexface());
00086 
00087   // <TODO> Test if cp is viewable to w.
00088 
00089 //  MessageGlobal mg;
00090 
00091 //  mg() << *this << endl << endl;
00092 //  mg() << tess << endl;
00093 
00094   addspike();
00095 
00096 //  mg() << *this << endl << endl;
00097 //  mg() << tess << endl;
00098 
00099 
00100   // k is the current surface face being processed.
00101   simplexface k;
00102 
00103   // kt is an index into the central tetrehedron K.
00104   uint kt;
00105 
00106   uint p[3];
00107 
00108 
00109   uint sz = process.size();
00110   for ( ; sz!=0; sz = process.size() )
00111   {
00112     k = process[ sz-1 ];   
00113     process.pop_back();
00114     dead.insert(k);
00115 
00116 //    mg() << SHOW(k) << endl;
00117 
00118     // The current tetrahedron  must have vs's base viewable to w.
00119     tess.cp = k.id;
00120     tess.vs.set( k.face );
00121     assert(tess.surfaceviewable(w));
00122 
00123 //    mg() << SHOW(tess.cp) << " " << SHOW(tess.vs) << endl;
00124 
00125     for (uint i=0; i<3; ++i)
00126       p[i] = tess.vi[tess.cp].pi[ tess.vs.v[i] ];
00127 
00128 
00129 //    mg() << "p= " << p[0] << " " << p[1] << " " << p[2] << endl;
00130 
00131     kt = stot[k];
00132     d4tri & K(tess.vi[kt]);
00133 
00134 //    mg() << SHOW(kt) << "  " << SHOW(K) << endl;
00135 
00136     tess.surfacedown();
00137     link(K.niFrompiInverse(p[2]),kt);
00138 
00139     tess.surfacedown();
00140     tess.surfaceleft();
00141     link(K.niFrompiInverse(p[1]),kt);
00142 
00143     tess.surfacedown();
00144     tess.surfaceleft();
00145     link(K.niFrompiInverse(p[0]),kt);
00146   }
00147 
00148 
00149   // Iterate over surface connecting the surface with
00150   //   the fan.
00151 
00152   simplexface sf;
00153 
00154   for (map<simplexface,uint>::iterator i=stot.begin();
00155     i!=stot.end(); ++i)
00156   {
00157     sf = i->first;    
00158     tess.cp = sf.id;
00159     tess.vs.set(sf.face);
00160     tess.vi[ tess.cp ].ni[ tess.vs.v[3] ] = i->second;
00161   }
00162 
00163   tess.debugcheck();
00164 
00165   // Apply minimization to each new tetrahedron with
00166   //   an already existing tetrahedron on the old surface.
00167   for (map<simplexface,uint>::iterator i=stot.begin();
00168     i!=stot.end(); ++i)
00169     tess.minimizer->eval( (i->first).id, i->second );
00170 
00171 }
00172 
00173 
00174 ostream & operator << (ostream & os, d4fan const & x)
00175 {
00176   return x.print(os);
00177 }
00178 
00179 
00180 ostream & d4fan::print(ostream & os) const
00181 {
00182   os << "w=" << w << endl;
00183 //  os << "surf" << endl << " ";
00184 //  for( set<simplexface>::const_iterator i = surf.begin();
00185 //    i!=surf.end(); ++i)
00186 //    os << *i << ":" << tess.vi[(*i).id] << endl;
00187 //  os << endl;
00188 
00189   os << "dead" << endl << " ";
00190   for( set<simplexface>::const_iterator i = dead.begin();
00191     i!=dead.end(); ++i)
00192     os << *i << " ";
00193   os << endl;
00194 
00195   os << "stot" << endl << " ";
00196   for( map<simplexface,uint>::const_iterator i = stot.begin();
00197     i!=stot.end(); ++i)
00198     os << i->first << "->" << i->second << ": " << tess.vi[i->second] << endl;
00199   os << endl;
00200 
00201   os << "process" << endl << " ";
00202   for ( uint i=0; i<process.size(); ++i)
00203     os << process[i] << " ";
00204   os << endl;
00205 
00206   return os;
00207 } 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 

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