proj home

Files   Classes   Functions   Hierarchy  

d3fan.cpp

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

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