proj home

Files   Classes   Functions   Hierarchy  

polytrimon.cpp

Go to the documentation of this file.
00001 
00002 #include <cassert>
00003 #include <algorithm>
00004 using namespace std;
00005 
00006 #include <indextable.h>
00007 #include <point.h>
00008 #include <polytrimon.h>
00009 
00010 
00011 void polytrimon::vsprint() const 
00012 {
00013   cout << "vs: ";
00014   for (uint i=0; i<vs.size(); ++i)
00015     cout << vs[i] << " ";
00016   cout << endl;
00017 }
00018 
00019 void polytrimon::colorsprint() const
00020 {
00021   cout << "colors: ";
00022   for (uint i=0; i<colors.size(); ++i)
00023     cout << i << "=" << colors[i] << " ";
00024   cout << endl;
00025 }
00026 
00027 void polytrimon::vyprint() const
00028 {
00029   cout << "vy: ";
00030   for (uint i=0; i<vy.size(); ++i)
00031     cout << vy[i] << " ";
00032   cout << endl;
00033 }
00034 
00035 void polytrimon::colorsinit()
00036 {
00037   uint iend = pts.size();
00038   uint i = 1; 
00039 
00040   colors.resize(pts.size());
00041 
00042   // Assume clockwise ordering of points
00043   // from top.
00044 
00045   // Let top be black.
00046   colors[0] = 1; 
00047 
00048   for ( ; pts[i].y <= pts[i-1].y; )
00049   {
00050     colors[i] = 1;
00051 
00052     ++i;
00053 
00054     if (i==iend)
00055       break;
00056   }
00057 
00058 //cout << SHOW(i) << " " SHOW(pts[i]) << endl;
00059 
00060   for ( ; i<iend; ++i)
00061     colors[i] = 2;
00062 
00063   // Taken out multicolored state
00064   //colors[0] = 3;
00065 }
00066 
00067 void polytrimon::vyinit()
00068 {
00069   int i = 0;
00070   int k = pts.size()-1;
00071 
00072   for ( ; i!=k; )
00073   {
00074     if ( pts[i].y> pts[k].y )
00075       vy.push_back(i++);
00076     else
00077       vy.push_back(k--);
00078   }
00079   vy.push_back(i);
00080 }
00081 
00082 polytrimon::polytrimon
00083 (  
00084   vector< point2<float> > const & pts_ 
00085 )
00086   : pts(pts_)
00087 {
00088   assert(pts.size()>2);
00089    
00090   colorsinit();
00091 
00092   vyinit();
00093 }
00094 
00095 boolc polytrimon::ispointvisible() const
00096 {
00097   if (vs.size()<3)
00098     return false;
00099 
00100 //  Points of different colors are always visible.  
00101 //  So no need to use this test in this case.
00102 assert(colors[vs[0]]==colors[vs[1]]);
00103 
00104   uint a;
00105   uint b;
00106 
00107   // Moving down the right hand side the vector
00108   // needs to point left. Moving down the left
00109   // hand side the vector needs to point right.
00110   if (colors[vs[1]]==2)
00111   {
00112     a = vs[2];
00113     b = vs[1];
00114   }
00115   else
00116   {
00117     a = vs[1];
00118     b = vs[2];
00119   }
00120 
00121   uint x = vs[0];
00122  
00123   point2<float> X = pts[x] - pts[a];
00124   point2<float> W = pts[b] - pts[a];
00125   point2<float> W90(-W.y,W.x);
00126    
00127   if ( X.x*W90.x + X.y*W90.y > 0 )
00128     return true; 
00129 
00130   return false;
00131 }
00132 
00133 
00134 
00135 
00136 
00137 

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