proj home

Files   Classes   Functions   Hierarchy  

pointsurface.h

Go to the documentation of this file.
00001 #ifndef POINTSURFACE_H
00002 #define POINTSURFACE_H
00003 
00004 #include <cassert>
00005 
00006 #include <point.h>
00007 #include <gobj.h>
00008 
00009 #include <random.h>
00010 
00011 
00034 template< typename T=double, typename G=randomgenerator >
00035 class pointsurface : public gobjContainerPrePost
00036 {
00037   pointsurface()
00038     { assert(false); }
00039 public:
00040 
00042   uint N;
00043 
00046   random11<T,G> rnd;
00047 
00050   pointsurface(uintc N_)
00051     : N(N_)
00052   {
00053     pre.push( new gobjglPushAttrib(GL_LIGHTING) );
00054     pre.push( new gobjglPushAttrib(GL_CURRENT_BIT) );
00055     pre.push( new gobjglDisable(GL_LIGHTING) );
00056 
00057     post.push( new gobjglPopAttrib() );
00058     post.push( new gobjglPopAttrib() );
00059   }
00060 
00062   template< typename FN >
00063   void addsurface2D( FN & fn )
00064   {
00065     point3<double> p;
00066     bool valid(false);
00067 
00068     nuke();
00069 
00070     push( new gobjglBegin(GL_POINTS) );
00071 
00072     for (uint i=0; i<N; )
00073     {
00074       point3<double> p;
00075       fn(valid,p.x,p.y,p.z,rnd(),rnd());
00076       if (valid)
00077       {
00078         push( new gobjglVertex3d(p) );
00079         ++i;
00080       }
00081     }
00082 
00083     push( new gobjglEnd() );
00084   }
00085 
00087   template< typename FN >
00088   void addsurface3D( FN & fn )
00089   {
00090     point3<double> p;
00091     bool valid(false);
00092 
00093     nuke();
00094 
00095     push( new gobjglBegin(GL_POINTS) );
00096 
00097     for (uint i=0; i<N; )
00098     {
00099       point3<double> p;
00100       fn(valid,p.x,p.y,p.z,rnd(),rnd(),rnd());
00101       if (valid)
00102       {
00103         push( new gobjglVertex3d(p) );
00104         ++i;
00105       }
00106     }
00107 
00108     push( new gobjglEnd() );
00109   }
00110 
00111 };
00112 
00113 // <TODO> Template the glVertex3d so that the type T determines which
00114 //  OpenGL call is made. ie double -> glVertex3d, float -> glVertex3f.
00115 
00120 class pointsurfaceSphere
00121 {
00122 public:
00123 
00126   void operator()
00127   (
00128     bool & accept,
00129     double & x,
00130     double & y,
00131     double & z,
00132     doublec u,
00133     doublec v,
00134     doublec w 
00135   );
00136 
00137 };
00138 
00142 class pointsurfaceParallelogram
00143 {
00144 public:
00145 
00147   point3<double> p0;
00148 
00150   point3<double> pu;
00152   point3<double> pv;
00153 
00156   pointsurfaceParallelogram
00157   (
00158     point3<double> const & p0_,
00159     point3<double> const & p1,
00160     point3<double> const & p2
00161   )
00162     : p0(p0_), pu(p1-p0), pv(p2-p0) {}
00163 
00166   void operator()
00167   (
00168     bool & accept,
00169     double & x,
00170     double & y,
00171     double & z,
00172     doublec u,
00173     doublec v
00174   ) const
00175   {
00176     accept = true;
00177     x = p0.x + pu.x*u + pv.x*v;
00178     y = p0.y + pu.y*u + pv.y*v;
00179     z = p0.z + pu.z*u + pv.z*v;
00180   }
00181 };
00182 
00183 
00184 #endif
00185 
00186 

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