proj home

Files   Classes   Functions   Hierarchy  

Public Member Functions | Public Attributes | List of all members
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

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.

: pi(0), box(box_), nb(new uint[9]), W(0)
{
}
d2toindex::d2toindex ( particle const *  pi_,
boxcollision const &  box_ 
)

Definition at line 15 of file d2toindex.cpp.

: pi(pi_), box(box_), nb(new uint[9]), W(0)
{
}
d2toindex::~d2toindex ( )

Definition at line 24 of file d2toindex.cpp.

References nb.

{
delete[] nb;
}

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().

{
assert(W!=0);
boolc above = (k>=W);
boolc left = ((k%W)!=0);
boolc below = (k+W<W*W);
boolc right = ((k%W)!=W-1);
uint index(0);
nb[index++] = k;
if (left)
{
nb[index++] = k-1;
if (above)
nb[index++] = k-W-1;
if (below)
nb[index++] = k+W-1;
}
if (right)
{
nb[index++] = k+1;
if (above)
nb[index++] = k-W+1;
if (below)
nb[index++] = k+W+1;
}
if (above)
nb[index++] = k-W;
if (below)
nb[index++] = k+W;
// finish
nb_ = nb;
sz = index;
}
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().

{
assert(W!=0);
assert(pi!=0);
particle const & p(pi[i]);
// cout << SHOW(p) << endl;
//double x = (p.pos[0]-box.x0)/(box.x1-box.x0);
//double y = 1.0 - (p.pos[1]-box.y0)/(box.y1-box.y0);
double x = (p.pos[0]-box.x0)*xleninv;
double y = 1.0 - (p.pos[1]-box.y0)*yleninv;
//cout << SHOW(x) << endl;
//cout << SHOW(y) << endl;
int ix = (int)(x*W) % W;
int iy = (int)(y*W) % W;
//cout << SHOW(ix) << endl;
//cout << SHOW(iy) << endl;
return ix + W*iy;
}
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().

{
assert(box.x1-box.x0!=0.0);
assert(box.y1-box.y0!=0.0);
xleninv = 1.0/(box.x1-box.x0);
yleninv = 1.0/(box.y1-box.y0);
}

Member Data Documentation

boxcollision const& d2toindex::box

Bounding space.

Definition at line 37 of file d2toindex.h.

Referenced by index(), and reset().

uint* d2toindex::nb

Neighbour cells and self.

Cell surrounded by neighbour cells.
  xxx
  xox
  xxx

Definition at line 47 of file d2toindex.h.

Referenced by ~d2toindex().

particle const* d2toindex::pi

Array of particles set by the client.

Definition at line 34 of file d2toindex.h.

Referenced by index().

uint d2toindex::W

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: