QUAD_DBM_2D.h

00001 
00002 // File : QUAD_DBM_2D.h
00004 //
00005 // Copyright 2006
00006 // The University of North Carolina at Chapel Hill
00007 // 
00009 //
00010 // Permission to use, copy, modify, distribute and sell this software and its 
00011 // documentation for any purpose is hereby granted without fee, provided that 
00012 // the above copyright notice appear in all copies and that both that copyright 
00013 // notice and this permission notice appear in supporting documentation. 
00014 // Binaries may be compiled with this software without any royalties or 
00015 // restrictions. 
00016 //
00017 // The University of North Carolina at Chapel Hill makes no representations 
00018 // about the suitability of this software for any purpose. It is provided 
00019 // "as is" without express or implied warranty.
00020 //
00021 
00022 #ifndef QUAD_DBM_2D_H 
00023 #define QUAD_DBM_2D_H
00024 
00025 #define USINGGLUT
00026 
00027 #include <vector>
00028 #ifdef USINGGLUT
00029 #include <gl/glut.h>
00030 #endif
00031 #include "DAG.h"
00032 #include "QUAD_POISSON.h"
00033 
00037 class QUAD_DBM_2D  
00038 {
00039 public:
00045         QUAD_DBM_2D(int xRes = 128, int yRes = 128, int iterations = 10);
00046 
00048         virtual ~QUAD_DBM_2D();
00049 
00051   bool addParticle();
00052   
00055   bool hitGround(CELL* cell = NULL);
00056  
00057 #ifdef USINGGLUT
00058 
00059   void draw();
00060 
00062   void drawSegments()  {
00063     glLineWidth(1.0f);
00064     glPushMatrix();
00065     glTranslatef(-0.5f, -0.5f, 0.0f);
00066     _dag->draw();
00067     glPopMatrix();
00068   };
00069 #endif
00070   
00072   // file IO
00074 
00076   void writeFields(const char* filename);
00077 
00079   void readFields(const char* filename);
00080 
00091   bool readImage(unsigned char* initial, 
00092                  unsigned char* attractors,
00093                  unsigned char* repulsors,
00094                  unsigned char* terminators,
00095                  int xRes, int yRes);
00096 
00098   void readDAG(const char* filename)     { _dag->read(filename); };
00099 
00101   void writeDAG(const char* filename)    { _dag->write(filename); };
00102   
00106   float*& renderOffscreen(int scale = 1) { return _dag->drawOffscreen(scale); };
00107   
00109   int xRes() { return _xRes; };
00111   int yRes() { return _yRes; };
00113   int xDagRes() { return _dag->xRes(); };
00115   int yDagRes() { return _dag->yRes(); };
00117   int inputWidth() { return _dag->inputWidth(); };
00119   int inputHeight() { return _dag->inputHeight(); };
00120 
00121 private:
00122   void allocate();
00123   void deallocate();
00124   
00126   // dielectric breakdown model components
00128   
00129   // field dimensions
00130   int _xRes;
00131   int _yRes;
00132   int _maxRes;
00133   float _dx;
00134   float _dy;
00135   int _iterations;
00136   
00137   // which cell did it hit bottom with?
00138   int _bottomHit;
00139 
00140   DAG* _dag;
00141 
00142   QUAD_POISSON* _quadPoisson;
00143 
00144   // current candidate list
00145   vector<CELL*> _candidates;
00146 
00147   // check if any of the neighbors of cell should be added to the
00148   // candidate list
00149   void checkForCandidates(CELL* cell);
00150 
00151   // number of particles to add before doing another Poisson solve
00152   int _skips;
00153 
00154   // Mersenne Twister
00155   RNG _twister;
00156 };
00157 
00158 #endif

Generated on Wed Oct 25 03:19:42 2006 for Lumos by  doxygen 1.4.6