proj home

Files   Classes   Functions   Hierarchy  

d2toindex.cpp

Go to the documentation of this file.
00001 
00002 #include <particle.h>
00003 #include <d2toindex.h>
00004 
00005 d2toindex::d2toindex
00006 (
00007   boxcollision const & box_
00008 )
00009   : pi(0), box(box_), nb(new uint[9]), W(0) 
00010 {
00011 }
00012 
00013 
00014 d2toindex::d2toindex
00015 (
00016   particle const * pi_,
00017   boxcollision const & box_
00018 )
00019   : pi(pi_), box(box_), nb(new uint[9]), W(0) 
00020 {
00021 }
00022 
00023 
00024 d2toindex::~d2toindex()
00025 { 
00026   delete[] nb; 
00027 }
00028   
00029 void d2toindex::reset()
00030 { 
00031   assert(box.x1-box.x0!=0.0);
00032   assert(box.y1-box.y0!=0.0);
00033   xleninv = 1.0/(box.x1-box.x0);
00034   yleninv = 1.0/(box.y1-box.y0);
00035 }
00036 
00037 intc d2toindex::index(uintc i) const
00038 {
00039   assert(W!=0);
00040   assert(pi!=0);
00041 
00042   particle const & p(pi[i]);
00043   // cout << SHOW(p) << endl;
00044   //double x = (p.pos[0]-box.x0)/(box.x1-box.x0);
00045   //double y = 1.0 - (p.pos[1]-box.y0)/(box.y1-box.y0);
00046   double x = (p.pos[0]-box.x0)*xleninv; 
00047   double y = 1.0 - (p.pos[1]-box.y0)*yleninv;
00048   //cout << SHOW(x) << endl;
00049   //cout << SHOW(y) << endl;
00050   int ix = (int)(x*W) % W;
00051   int iy = (int)(y*W) % W;
00052   //cout << SHOW(ix) << endl;
00053   //cout << SHOW(iy) << endl;
00054   return ix + W*iy;
00055 }
00056 
00057 void d2toindex::getsurroundingcells
00058 (
00059   uint * & nb_,
00060   uint & sz,
00061   uintc k
00062 )
00063 {
00064   assert(W!=0);
00065   boolc above = (k>=W);
00066   boolc left = ((k%W)!=0);
00067   boolc below = (k+W<W*W);
00068   boolc right = ((k%W)!=W-1);
00069 
00070   uint index(0);
00071 
00072   nb[index++] = k;
00073 
00074   if (left)
00075   {
00076     nb[index++] = k-1;
00077     if (above)
00078       nb[index++] = k-W-1;
00079     if (below)
00080       nb[index++] = k+W-1;
00081   }
00082 
00083   if (right)
00084   {
00085     nb[index++] = k+1;
00086     if (above)
00087       nb[index++] = k-W+1;
00088     if (below)
00089       nb[index++] = k+W+1;
00090   }
00091 
00092   if (above)
00093     nb[index++] = k-W;
00094 
00095   if (below)
00096     nb[index++] = k+W;
00097   
00098   // finish
00099   nb_ = nb;
00100   sz = index;
00101 }
00102 
00103 
00104 

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