org.miv.pherd.ntree
Class Cell

java.lang.Object
  extended by org.miv.pherd.ntree.Cell

public class Cell
extends Object

A cell of the n-Tree. TODO: dès qu'une particule est ajoutée il peut y avoir mitose. Dès qu'une particule est enlevée il y a fusion. Cependant, durant le déplacement des particules (qui se fait de manière itérative, toutes les particules calculent leur nouvelle position, puis bougent. Ne serait-il pas plus efficace de réadapter l'arbre uniquement une fois que toutes les particules on bougé, et non pas à chaque particule ? C'est la raison pour laquelle certaines méthodes sont suffixées par "Direct". Elles agissent directement. Les méthodes équivalentes sans le suffixe "Direct" elles fonctionne itérativement.

Since:
2007
Author:
Antoine Dutot
See Also:
NTree

Field Summary
protected  CellData data
          The data specific to a given particle simulation.
protected  int depth
          Depth in the tree (distance from the root).
protected  String id
          The cell identifier.
protected  int index
          Cell index in its mother.
protected  Cell parent
          Mother cell.
protected  HashMap<Object,Particle> particles
          Particle bucket.
protected  int population
          The total particle population handled by this cell, counting its subcells population, as only leafs contains particles.
protected  CellSpace space
          The space occupied by this cell.
protected  Cell[] sub
          Daughter cells.
protected  NTree tree
          The tree containing me.
 
Constructor Summary
protected Cell(Cell parent, int index, CellSpace space, CellData data)
          Used to create a subcell.
  Cell(NTree tree, CellSpace space, String id, CellData data)
          Create a root cell in a given space.
 
Method Summary
 void addParticle(Particle particle)
          Add a particle in the n-Tree.
 boolean contains(double x, double y, double z)
          Does this cell contains the given position ?.
 boolean contains(Particle particle)
          Does this cell contains the position of the given particle ?.
protected  void describe(NTreeListener listener)
          Send the state of this cell to the given listener, then recurse on all subcells if any.
protected  void fusion()
           
 CellData getData()
          This cell data.
 int getDepth()
          Depth of this cell.
 String getId()
          Cell identifier.
 int getIndex()
          The cell index in its mother cell.
 Cell getParent()
          The parent cell, if any.
 Iterator<? extends Particle> getParticles()
          Set of stored particles, if this cell is a leaf, else null.
 int getPopulation()
          The total population of particle this cell stores.
 CellSpace getSpace()
          This cell space region.
 Cell getSub(int i)
          The i-th subcell or null if there is a leaf cell.
 NTree getTree()
          The cell tree.
 boolean hasParticle(Particle particle)
          True if the cell has the particle as a child.
 boolean isLeaf()
          Is this cell a leaf?.
 boolean isRoot()
          Is this cell a root cell?.
 boolean isValid()
           
protected  void mitosis()
          Subdivide a cell into several sub-cells according to the currently used cell space.
 void particleMoved(Particle particle)
          Message from a particle to indicate it moved.
 void recompute()
          Recursively check cells to see if they need fusion or subdivision and send a recompute signal to all cell data elements.
 void removeParticle(Object id)
          Remove a particle from the n-Tree.
protected  void resize(Point3 min, Point3 max)
          Resize the cell space so that
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected String id
The cell identifier.


tree

protected NTree tree
The tree containing me.


depth

protected int depth
Depth in the tree (distance from the root).


index

protected int index
Cell index in its mother.


parent

protected Cell parent
Mother cell.


sub

protected Cell[] sub
Daughter cells.


space

protected CellSpace space
The space occupied by this cell. This class allows to specify a bounding box (two extreme points in space), how to split a cell, and


data

protected CellData data
The data specific to a given particle simulation.


particles

protected HashMap<Object,Particle> particles
Particle bucket.


population

protected int population
The total particle population handled by this cell, counting its subcells population, as only leafs contains particles.

Constructor Detail

Cell

public Cell(NTree tree,
            CellSpace space,
            String id,
            CellData data)
Create a root cell in a given space.

Parameters:
tree - The n-tree containing this root cell.
space - The space occupied by this cell.
data - The cell data.

Cell

protected Cell(Cell parent,
               int index,
               CellSpace space,
               CellData data)
Used to create a subcell. This method is to be used only inside this class when subdividing a cell.

Parameters:
parent - The parent cell.
index - The cell index in its parent.
space - The space occupied by this cell.
data - The cell data.
Method Detail

getTree

public NTree getTree()
The cell tree.

Returns:
The n-tree this cell pertains to.

getId

public String getId()
Cell identifier.


isLeaf

public boolean isLeaf()
Is this cell a leaf?.

Returns:
True if this cell has no subcells.

isRoot

public boolean isRoot()
Is this cell a root cell?.

Returns:
True if this cell has no parent.

getPopulation

public int getPopulation()
The total population of particle this cell stores.

Returns:
Count of particle handled by this cell or its subcells.

getParent

public Cell getParent()
The parent cell, if any.

Returns:
A cell that contains this one or null if this is a root cell.

getSub

public Cell getSub(int i)
The i-th subcell or null if there is a leaf cell. Subcells are arranged in X row, then Y plane, then Z cube, going from the bottom-left-front point to the top-right-back point. This means for an octree that cell 0 is on the bottom, left front, cell 1 on the bottom right front, cell 2 on the top left front, cell 3 on the top right front, cell 4 on the bottom left back, cell 5 on the bottom right back, cell 6 on the top left back and cell 6 on the top right back. Pfew.

Parameters:
i - The subcell index.
Returns:
The i-th subcell, or null if this cell is a leaf.

getDepth

public int getDepth()
Depth of this cell.

Returns:
The number of parents of this cell.

getIndex

public int getIndex()
The cell index in its mother cell.

Returns:
An integer.

getSpace

public CellSpace getSpace()
This cell space region.

Returns:
The space occupied by this cell.

getData

public CellData getData()
This cell data.

Returns:
The cell data.

getParticles

public Iterator<? extends Particle> getParticles()
Set of stored particles, if this cell is a leaf, else null.

Returns:
An iterator on the set of stored particle or null if this cell is a leaf.

contains

public boolean contains(Particle particle)
Does this cell contains the position of the given particle ?. Be careful, this does not mean the cell contains the instance of the particle given, only that the particle position is within the cell space.

Parameters:
particle - The particle to classify.
Returns:
True if this cell contains the given particle.
See Also:
hasParticle(Particle)

contains

public boolean contains(double x,
                        double y,
                        double z)
Does this cell contains the given position ?.

Parameters:
x - The abscissa.
y - The ordinate.
z - The depth.
Returns:
True if this space contains the given position.

hasParticle

public boolean hasParticle(Particle particle)
True if the cell has the particle as a child. This test verifies that the cell is the container of the particle.

Parameters:
particle - The particle to test.
Returns:
True if the cell is the container of the particle.
See Also:
contains(Particle)

addParticle

public void addParticle(Particle particle)
Add a particle in the n-Tree. This method is recursive, starting from the tree root. It adds the particle to leaf cells only. It never subdivide cells if needed, which means that a cell may contain too many particles at a time. The subdivision will occur when the recompute() method will be called.

Parameters:
particle - The particle to add.

removeParticle

public void removeParticle(Object id)
Remove a particle from the n-Tree. This method must be called by the particle itself. It will recurse on the whole parent branch to adjust the population count. This method never try to fusion cells if the particle population size is too small. This will be done at a later time when the recompute() method will be called.

Parameters:
id - The particle identifier.

particleMoved

public void particleMoved(Particle particle)
Message from a particle to indicate it moved. This will move the particle from one cell to another if needed, but in this case, no subdivision or fusion will occur until the recompute() method is called.

Parameters:
particle - The particle that moved.

recompute

public void recompute()
Recursively check cells to see if they need fusion or subdivision and send a recompute signal to all cell data elements.


mitosis

protected void mitosis()
Subdivide a cell into several sub-cells according to the currently used cell space.


fusion

protected void fusion()

describe

protected void describe(NTreeListener listener)
Send the state of this cell to the given listener, then recurse on all subcells if any. This allows to send the ntree (or sub-ntree) description to a listener when it first connects to the tree.

Parameters:
listener - The listener that should receive the subtree description.

resize

protected void resize(Point3 min,
                      Point3 max)
Resize the cell space so that

Parameters:
min - The lowest new space point.
max - The hihest new space point.

toString

public String toString()
Overrides:
toString in class Object

isValid

public boolean isValid()


Copyright © 2011. All Rights Reserved.