proj home

Files   Classes   Functions   Hierarchy  

d3tess.h

Go to the documentation of this file.
00001 #ifndef D3TESS_H
00002 #define D3TESS_H
00003 
00004 #include <cassert>
00005 #include <vector>
00006 #include <set>
00007 #include <iosfwd>
00008 using namespace std;
00009 
00010 #include <d3fan.h>
00011 #include <d3fan2.h>
00012 #include <d3minoperator.h>
00013 #include <point.h>
00014 #include <simplexD2linked.h>
00015 #include <simplexface.h>
00016 #include <virtualtriangle.h>
00017 
00018 
00019 typedef unsigned int uint;
00020 typedef unsigned int const uintc;
00021 typedef point3<double> pt3;
00022 typedef point3<double> const pt3c;
00023 
00029 class d3tess
00030 {
00031 public:
00032 
00033   vector<pt3> pt;
00034 
00035   vector<simplexD2linked> vi;
00036 
00037   /* Current Pointer. */
00038   uint cp;
00039   /* Current Orientation - virtual simplex. */
00040   virtualtriangle vs;
00041 
00042   /* Decide which fan you are plugging in.
00043      Not templated because then this whole class has to be
00044        templated. */
00045   d3fan2 fan;
00046 
00047   // Upon insertion of a new primitive shape, it is minimized
00048   //   with the existing mesh.  This is a pointer to the binary 
00049   /*   operator. */
00050   d3minoperator* minimizer;
00051 
00052   bool debugenable;
00053 
00054   /* Statistics: count the number of moves a search takes. */
00055   uint movecounter;
00056 
00057   /* Add a simplex */
00058   void viadd
00059   ( 
00060     uintc v0, uintc v1, uintc v2,
00061     uintc n0=0, uintc n1=0, uintc n2=0
00062   );
00063 
00065   void minimizerSet( d3minoperator* m);
00066 
00067   /* Move to the neighbouring simplex relative to vs. */
00068   bool const moveleft();
00069   /* Move to the neighbouring simplex relative to vs. */
00070   bool const moveright();
00071   /* Move to the neighbouring simplex relative to vs. */
00072   bool const movedown();
00073 
00074   /* Orient the base triangle of vs to the boundary. */
00075   bool const boundaryorient();
00076   /* Assuming base of vs on the boundary, move right */
00077   void surfaceright();
00078   /* Assuming base of vs on the boundary, move left */
00079   void surfaceleft();
00080 
00081   /* Get the current simplex. */
00082   simplexD2linked const & cpsimplex() const  
00083    { assert((cp!=0) && (cp<vi.size())); return vi[cp]; }
00084 
00085   /* Get the current cp orientation as a cp and face pair. */
00086   simplexface const cpsimplexfaceget() const;
00087   /* Set the current cp and orientation. */
00088   void cpsimplexfaceset( simplexface const & sf);
00089 
00090   /* Greedy search minimizing towards point p in the mesh.
00091      If the point is outside the mesh the virtual triangle vs
00092      is oriented to have its base on the viewable face. */
00093   bool const searchminimizetowardspoint( uintc p );
00094 
00096   bool const move_terminated
00097   (
00098     bool & insidesimplex,
00099     uint & viewableface,
00100     uintc p
00101   );
00102 
00103 
00106   void initialize();
00107 
00109   void addpoint(uintc k);
00110 
00112   void print(string & s) const;
00114   ostream & print(ostream & os) const;
00116   istream & serializeInverse(istream & is);
00117 
00118   // Error checking code.
00119   bool const valid(uintc k) const;
00120   bool const debugcheck() const;
00121 
00123   d3tess( uintc arrayMax );
00124 
00126   ~d3tess();
00127 
00130   void reset();
00131 
00133   bool const isconnected(uintc a, uintc b) const; 
00135   bool const isconvex(uintc a, uintc b) const;
00136 
00138   bool const surfaceviewable(uintc k) const;
00139 
00142   bool const flip();
00145   bool const flip(uintc a, uintc b);
00146 
00148   bool const simplexdelete(uintc s);
00150   void simplexswap(uintc s0, uintc s1);
00153   void removenullsimplexes();
00154 
00156   double const cpbasemeasure() const;
00157 
00158 //  bool enablesplit;
00159 //  bool enablefan;
00160 
00162   void cppreserve(uint & cp0, virtualtriangle & vs0) const;
00164   void cppreserveInverse
00165   (
00166     uint const & cp0, 
00167     virtualtriangle const & vs0
00168   );
00169 
00170   //
00171   //  Splitting Operators
00172   //
00173 
00174   //  splitonboundary and spliton1D have equivalent functionality but
00175   //    the former is more efficient, but more difficult to use and 
00176   //    has less error checking.
00177 
00179   void split2D( uintc w );
00180 
00182   void split1D( uintc s, uintc p0, uintc w0 );
00183 
00184   // I have avoided this routine. 
00185   //void split1D( uint & , uint * si, uintc s, uintc p0, uintc w0 );
00186 
00187 
00189   void splitwithline( uintc s, uintc p0, uintc w0, uintc p1, uintc w1 );
00190 
00191 
00193   void splitmidpoint1D(uintc s, uintc p1);
00194 
00195 
00196 private:
00197 
00198   // Two triangles produced.
00199   void splitonboundarynoneighbor
00200   ( 
00201     uintc s,
00202     uintc j, 
00203     uintc w 
00204   );
00205 };
00206 
00207 //  Brief:  Save the current cp orientation and restore when
00208 //          the object dies.
00209 class d3tesspreserve
00210 {
00211   d3tess & tess;
00212   uint cp0;
00213   virtualtriangle vs0;
00214 public:
00215 
00216   // Store the current cp and orientation.
00217   d3tesspreserve( d3tess & _tess);
00218 
00219   // Restore the saved cp and orientation.
00220   ~d3tesspreserve();
00221 };
00222   
00223     
00224   
00225 
00226   
00227 
00228 
00229 ostream & operator << (ostream& os, d3tess const & x);
00230 
00231 istream & operator >> (istream & is, d3tess & x);
00232 
00233 
00234 class maxEdgeLength
00235 {
00236   d3tess & tess;
00237   vector<simplexD2linked> & vi;
00238   vector<pt3> & pt;
00239   double const delta;
00240 public:
00241 
00242   maxEdgeLength(d3tess & _tess, double const _delta)
00243     : tess(_tess), vi(tess.vi), pt(tess.pt), delta(_delta) {}
00244 
00245   bool const eval(uintc s, uintc j)
00246   {
00247     assert(j<3);
00248 
00249     simplexD2linked * x = & vi[s];
00250     pt3c & A(pt[ x->pi[(j+1)%3] ]);
00251     pt3c & B(pt[ x->pi[(j+2)%3] ]);
00252     if ( (A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y) > delta )
00253     {
00254       tess.splitmidpoint1D(s,x->pi[j]);
00255       return true;
00256     }
00257 
00258     return false;
00259   }
00260 
00261 };
00262 
00263 
00264 
00265 
00266 #endif
00267 
00268 

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