proj home

Files   Classes   Functions   Hierarchy  

polytrimon Class Reference

Linear time triangulation of monotone polygons. More...

#include <polytrimon.h>

Collaboration diagram for polytrimon:

List of all members.

Public Member Functions

 polytrimon (vector< point2< float > > const &pts_)
 Pass in the points of monotone polygon ordered clockwise from the highest point.
template<typename T >
void tessellate (T f)
void vsprint () const
void colorsprint () const
void vyprint () const

Public Attributes

vector< point2< float > > const & pts
 Polyline of 2D points.
vector< uintcolors
 Each point is either on the rhs (black)=1, the left hand side (white)=2 or both=1+2=3 eg the start and finish points.
vector< uintvy
 pts[] ordered on the y-axis in constructor.
deque< uintvs
 The current tessellation state.


Detailed Description

Linear time triangulation of monotone polygons.

Assume that the order of the points is clockwise starting from the top.

Definition at line 20 of file polytrimon.h.


Constructor & Destructor Documentation

polytrimon::polytrimon ( vector< point2< float > > const &  pts_  ) 

Pass in the points of monotone polygon ordered clockwise from the highest point.

Definition at line 83 of file polytrimon.cpp.

References pts.

00086   : pts(pts_)
00087 {
00088   assert(pts.size()>2);
00089    
00090   colorsinit();
00091 
00092   vyinit();
00093 }


Member Function Documentation

void polytrimon::colorsprint (  )  const

Definition at line 19 of file polytrimon.cpp.

References colors.

00020 {
00021   cout << "colors: ";
00022   for (uint i=0; i<colors.size(); ++i)
00023     cout << i << "=" << colors[i] << " ";
00024   cout << endl;
00025 }

template<typename T >
void polytrimon::tessellate ( T  f  )  [inline]

Definition at line 64 of file polytrimon.h.

References colors, vs, and vy.

Referenced by test01(), and test02().

00065 {
00066   vs.push_front( vy[0] );
00067   vs.push_front( vy[1] );
00068 
00069   uint imax= vy.size();
00070 
00071   // The first two points from the current vs state. 
00072   uint z0;
00073   uint z1;
00074 
00075   for (uint i=2; i<imax; ++i)
00076   {
00077     vs.push_front( vy[i] );
00078 //vsprint();
00079 
00080     z0 = vs[0];
00081     z1 = vs[1];
00082 
00083     bool samecolor = 
00084       (( colors[ z0 ] & colors[ z1 ])!=0);
00085 
00086     if (samecolor==false)
00087     {
00088       // Triangle fan about z0.
00089       for (uint k=2; k<vs.size(); ++k)
00090         f(z0,vs[k-1],vs[k]);
00091 
00092       vs.clear();
00093       vs.push_front(z1);
00094       vs.push_front(z0);
00095     }
00096     else
00097     {
00098       for ( ; ispointvisible(); )
00099       {
00100         z0 = vs[0];
00101         z1 = vs[1];
00102 
00103         f(z0,z1,vs[2]);
00104 
00105         vs.pop_front();
00106         vs.pop_front();
00107         vs.push_front(z0);
00108       }
00109     }
00110   } 
00111 }

void polytrimon::vsprint (  )  const

Definition at line 11 of file polytrimon.cpp.

References vs.

00012 {
00013   cout << "vs: ";
00014   for (uint i=0; i<vs.size(); ++i)
00015     cout << vs[i] << " ";
00016   cout << endl;
00017 }

void polytrimon::vyprint (  )  const

Definition at line 27 of file polytrimon.cpp.

References vy.

00028 {
00029   cout << "vy: ";
00030   for (uint i=0; i<vy.size(); ++i)
00031     cout << vy[i] << " ";
00032   cout << endl;
00033 }


Member Data Documentation

Each point is either on the rhs (black)=1, the left hand side (white)=2 or both=1+2=3 eg the start and finish points.

Definition at line 38 of file polytrimon.h.

Referenced by colorsprint(), and tessellate().

vector< point2<float> > const& polytrimon::pts

Polyline of 2D points.

Definition at line 33 of file polytrimon.h.

The current tessellation state.

Definition at line 48 of file polytrimon.h.

Referenced by tessellate(), and vsprint().

vector< uint > polytrimon::vy

pts[] ordered on the y-axis in constructor.

Definition at line 41 of file polytrimon.h.

Referenced by tessellate(), and vyprint().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:10 2011 for Chelton Evans Source by  doxygen 1.5.8