proj home

Files   Classes   Functions   Hierarchy  

d2toindex Class Reference

The box is divided into a square grid of cells. 0 1 2 .. W-1, W W+1 ... 2W-1, ... W*W-1. More...

#include <d2toindex.h>

Collaboration diagram for d2toindex:
Collaboration graph

List of all members.

Public Member Functions

 d2toindex (boxcollision const &box_)
 Constructor.
 d2toindex (particle const *pi_, boxcollision const &box_)
 ~d2toindex ()
void reset ()
intc index (uintc i) const
 Access the ith particle's grid index.
void getsurroundingcells (uint *&nb_, uint &sz, uintc k)
 Includes k.

Public Attributes

particle const * pi
 Array of particles set by the client.
boxcollision const & box
 Bounding space.
uintnb
 Neighbour cells and self.
uint W
 W^2 cell grid, W is set by the client.

Detailed Description

The box is divided into a square grid of cells. 0 1 2 .. W-1, W W+1 ... 2W-1, ... W*W-1.

Definition at line 26 of file d2toindex.h.


Constructor & Destructor Documentation

d2toindex::d2toindex ( boxcollision const &  box_  ) 

Constructor.

Definition at line 6 of file d2toindex.cpp.

00009   : pi(0), box(box_), nb(new uint[9]), W(0) 
00010 {
00011 }

d2toindex::d2toindex ( particle const *  pi_,
boxcollision const &  box_ 
)

Definition at line 15 of file d2toindex.cpp.

00019   : pi(pi_), box(box_), nb(new uint[9]), W(0) 
00020 {
00021 }

d2toindex::~d2toindex (  ) 

Definition at line 24 of file d2toindex.cpp.

References nb.

00025 { 
00026   delete[] nb; 
00027 }


Member Function Documentation

void d2toindex::getsurroundingcells ( uint *&  nb_,
uint sz,
uintc  k 
)

Includes k.

Definition at line 58 of file d2toindex.cpp.

Referenced by test03().

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 }

intc d2toindex::index ( uintc  i  )  const

Access the ith particle's grid index.

Definition at line 37 of file d2toindex.cpp.

References box, pi, particle::pos, W, boxcollision::x0, and boxcollision::y0.

Referenced by test03().

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 }

void d2toindex::reset (  ) 

Definition at line 29 of file d2toindex.cpp.

References box, boxcollision::x0, boxcollision::x1, boxcollision::y0, and boxcollision::y1.

Referenced by test03().

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 }


Member Data Documentation

Bounding space.

Definition at line 37 of file d2toindex.h.

Referenced by index(), and reset().

Neighbour cells and self.

Cell surrounded by neighbour cells.
  xxx
  xox
  xxx

Definition at line 47 of file d2toindex.h.

Referenced by ~d2toindex().

Array of particles set by the client.

Definition at line 34 of file d2toindex.h.

Referenced by index().

W^2 cell grid, W is set by the client.

Definition at line 50 of file d2toindex.h.

Referenced by index(), and test03().


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

Generated on 27 Nov 2012 for Chelton Evans Source by  doxygen 1.6.1