proland::ParticleGrid Class Reference
[screen]

A 2D grid containing particles, used to quickly find the neighbors of a particle or the particles covering a given point. More...

#include <ParticleGrid.h>

List of all members.

Public Member Functions

 ParticleGrid (float radius, int maxParticlesPerCell, float gridFactor=1.0f)
 Creates a new ParticleGrid.
 ~ParticleGrid ()
 Deletes this ParticleGrid.
float getParticleRadius () const
 Returns the radius of each particle.
void setParticleRadius (float radius)
 Sets the radius of each particle.
int getMaxParticlesPerCell () const
 Returns the maximum number of particles per cell.
void setMaxParticlesPerCell (int maxParticlesPerCell)
 Sets the maximum number of particles per cell.
box2i getViewport () const
 Returns the viewport covered by this grid.
void setViewport (const box2i &viewport)
 Sets the viewport that should be covered by this grid.
vec2i getGridSize () const
 Returns the number of columns and rows of the grid.
vec2i getCell (const vec2f &p)
 Returns the grid cell coordinates corresponding to the given point.
int getCellSize (const vec2i &cell)
 Returns the number of particles in the given cell.
ScreenParticleLayer::ScreenParticle ** getCellContent (const vec2i &cell)
 Returns the particles in the given cell.
void addParticle (ScreenParticleLayer::ScreenParticle *p, float intensity)
 Adds a particle to this grid.
void clear ()
 Removes all the particles from the grid.
ptr< Texture2D > copyToTexture (ptr< ScreenParticleLayer > l, ptr< Texture2D > t, int &pixelsPerCell)
 Copies the content of this ParticleGrid to the given texture.

Private Member Functions

void createGrid ()
 Creates the grid for the current viewport and particle radius.
void deleteGrid ()
 Deletes the grid.

Private Attributes

float radius
 The radius of each particle, in pixels.
int maxParticlesPerCell
 Maximum number of particles per grid cell.
box2i viewport
 The viewport covered by this particle grid, in pixels.
vec2i gridSize
 The number of columns and rows of the particle grid.
vec2i cellGridSize
 The number of columns and rows of the particle grid sent to the GPU.
int * cellSizes
 The number of particles in each grid cell.
ScreenParticleLayer::ScreenParticle ** cellContents
 The particles in each grid cell.
int * cellIndexes
 The indexes of the particles in each gpu grid cell.
float gridFactor
 Factor for the grid size, if required to be different to the specified one.

Detailed Description

A 2D grid containing particles, used to quickly find the neighbors of a particle or the particles covering a given point.

Each cell of the grid contains the particles that cover this cell (based on the screen particle position and a specified particle radius, all in pixels). The cell size is set approximatively to the particle radius. The grid covers a specified viewport (in pixels), and its cells are recomputed when this viewport changes (so that the size of each cell stays approximatively equal to the particle radius, in pixels). This class can also copy this grid in a GPU texture.

Author:
Antoine Begault

Constructor & Destructor Documentation

proland::ParticleGrid::ParticleGrid ( float  radius,
int  maxParticlesPerCell,
float  gridFactor = 1.0f 
)

Creates a new ParticleGrid.

Parameters:
radius the radius of each particle. A particle is added to each cell covered by its radius.
maxParticlesPerCell maximum number of particles per grid cell.
gridFactor factor for the grid size, if required to be different to the specified one.
proland::ParticleGrid::~ParticleGrid (  ) 

Deletes this ParticleGrid.


Member Function Documentation

void proland::ParticleGrid::addParticle ( ScreenParticleLayer::ScreenParticle p,
float  intensity 
)

Adds a particle to this grid.

The particle is added to each cell covered by the disk of radius getParticleRadius() around the particle.

Parameters:
p a particle.
void proland::ParticleGrid::clear (  ) 

Removes all the particles from the grid.

ptr<Texture2D> proland::ParticleGrid::copyToTexture ( ptr< ScreenParticleLayer l,
ptr< Texture2D >  t,
int &  pixelsPerCell 
)

Copies the content of this ParticleGrid to the given texture.

Each cell is represented with pixelsPerCell RGBA float values representing particle indexes. The cell particles are stored in the first pixels of the cell, and -1 is used to mark the end of the particle list.

Parameters:
l the layer managing the particles stored in this grid. This layer is used to compute the index of each particle via ParticleStorage::getParticleIndex().
t the destination texture, or NULL to create a new one.
[out] pixelsPerCell the number of pixels used to represent each cell in t. Equals to ceil(getMaxParticlesPerCell() / 4).
Returns:
the given texture, or a new one if t was not of correct size. The size of the texture must be gridSize.x * pixelsPerCell times gridSize.y pixels.
void proland::ParticleGrid::createGrid (  )  [private]

Creates the grid for the current viewport and particle radius.

void proland::ParticleGrid::deleteGrid (  )  [private]

Deletes the grid.

vec2i proland::ParticleGrid::getCell ( const vec2f &  p  ) 

Returns the grid cell coordinates corresponding to the given point.

Parameters:
p a point inside the viewport getViewport().
ScreenParticleLayer::ScreenParticle** proland::ParticleGrid::getCellContent ( const vec2i &  cell  ) 

Returns the particles in the given cell.

Parameters:
cell a cell given by its x and y coordinates (in number of columns and rows).
Returns:
an array of getCellSize() particles.
int proland::ParticleGrid::getCellSize ( const vec2i &  cell  ) 

Returns the number of particles in the given cell.

Parameters:
cell a cell given by its x and y coordinates (in number of columns and rows).
vec2i proland::ParticleGrid::getGridSize (  )  const

Returns the number of columns and rows of the grid.

int proland::ParticleGrid::getMaxParticlesPerCell (  )  const

Returns the maximum number of particles per cell.

float proland::ParticleGrid::getParticleRadius (  )  const

Returns the radius of each particle.

box2i proland::ParticleGrid::getViewport (  )  const

Returns the viewport covered by this grid.

void proland::ParticleGrid::setMaxParticlesPerCell ( int  maxParticlesPerCell  ) 

Sets the maximum number of particles per cell.

void proland::ParticleGrid::setParticleRadius ( float  radius  ) 

Sets the radius of each particle.

This clears the grid content.

void proland::ParticleGrid::setViewport ( const box2i &  viewport  ) 

Sets the viewport that should be covered by this grid.

This clears the grid content.


Member Data Documentation

The particles in each grid cell.

This array is of size gridSize.x * gridSize.y * maxParticlesPerCell.

The number of columns and rows of the particle grid sent to the GPU.

The indexes of the particles in each gpu grid cell.

This array is of size gpuGridSize.x * gpuGridSize.y * maxParticlesPerGpuCell.

The number of particles in each grid cell.

This array is of size gridSize.x * gridSize.y.

Factor for the grid size, if required to be different to the specified one.

The number of columns and rows of the particle grid.

Maximum number of particles per grid cell.

The radius of each particle, in pixels.

The viewport covered by this particle grid, in pixels.


Generated on Sat May 12 09:41:37 2012 for proland by  doxygen 1.6.1