proj home

Files   Classes   Functions   Hierarchy  

pointgrid3D.cpp

Go to the documentation of this file.
00001 #include <cassert>
00002 using namespace std;
00003 
00004 #include <pointgrid3D.h>
00005 
00006 
00007 pointgrid3D::pointgrid3D(uintc M_, uintc N_)
00008   : M(M_), N(N_), pt(new point3<double>[M*N])
00009 {
00010   doublec dx = 1.0/((double)N-1.0);
00011   doublec dy = 1.0/((double)M-1.0);
00012 
00013   double x(0.0);
00014   double y(0.0);
00015 
00016   uint index(0);
00017   uint i,k;
00018   for (i=0; i<M; ++i)
00019   {
00020     x = 0.0;
00021     for (k=0; k<N; ++k)
00022     {
00023       pt[index].x = x;
00024       pt[index].y = y;
00025       ++index;
00026       x += dx;
00027     }
00028     y += dy;
00029   }
00030 }
00031 
00032 pointgrid3D::pointgrid3D
00033 (
00034   uintc M_, 
00035   uintc N_, 
00036   doublec x0,
00037   doublec x1,
00038   doublec y0,
00039   doublec y1
00040 )
00041   : M(M_), N(N_), pt(new point3<double>[M*N])
00042 {
00043   assert(x0<x1);
00044   assert(y0<y1);
00045 
00046   doublec dx = (x1-x0)/((double)N-1.0);
00047   doublec dy = (y1-y0)/((double)M-1.0);
00048 
00049   double x(x0);
00050   double y(y0);
00051 
00052   uint index(0);
00053   uint i,k;
00054   for (i=0; i<M; ++i)
00055   {
00056     x = x0;
00057     for (k=0; k<N; ++k)
00058     {
00059       pt[index].x = x;
00060       pt[index].y = y;
00061       ++index;
00062       x += dx;
00063     }
00064     y += dy;
00065   }
00066 }
00067 
00068 pointgrid3D::pointgrid3D
00069 (
00070   uintc M_, 
00071   uintc N_, 
00072   doublec x0,
00073   doublec x1,
00074   doublec z0,
00075   doublec z1,
00076   bool const xzsurface
00077 )
00078   : M(M_), N(N_), pt(new point3<double>[M*N])
00079 {
00080   assert(xzsurface==true);  // Dummy argument.
00081   assert(x0<x1);
00082   assert(z0<z1);
00083 
00084   doublec dx = (x1-x0)/((double)N-1.0);
00085   doublec dz = (z1-z0)/((double)M-1.0);
00086 
00087   double x(x0);
00088   double z(z0);
00089 
00090   uint index(0);
00091   uint i,k;
00092   for (i=0; i<M; ++i)
00093   {
00094     x = x0;
00095     for (k=0; k<N; ++k)
00096     {
00097       pt[index].x = x;
00098       pt[index].z = z;
00099       ++index;
00100       x += dx;
00101     }
00102     z += dz;
00103   }
00104 }
00105 
00106 pointgrid3D::~pointgrid3D()
00107 {
00108   delete[] pt;
00109 }
00110 
00111 void pointgrid3D::createIndexedTriangles
00112 (
00113   vector< point3<double> > & points,
00114   vector< point3<uint> > & vi
00115 ) const
00116 {
00117   uintc p0 = points.size();
00118 
00119   for (uint i=0; i<M*N; ++i)
00120     points.push_back(pt[i]);
00121 
00122   for (uint r=1; r<M; ++r)
00123   {
00124     for (uint k=1; k<N; ++k)
00125     {
00126       vi.push_back
00127       ( 
00128         point3<uint>(p0+r*N+k-1,p0+(r-1)*N+k-1,p0+(r-1)*N+k  )  
00129       );
00130       vi.push_back
00131       (
00132         point3<uint>(p0+r*N+k-1,p0+(r-1)*N+k,p0+r*N+k )
00133       );
00134     }
00135   }
00136 }
00137 

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