edu.jhu.cs.cisst.algorithms.optimize.fmg.grid
Class Grid

java.lang.Object
  extended by edu.jhu.cs.cisst.algorithms.optimize.fmg.grid.Grid
All Implemented Interfaces:
ConstGrid, java.lang.Cloneable
Direct Known Subclasses:
BoundaryGrid, NoBoundaryGrid

public abstract class Grid
extends java.lang.Object
implements ConstGrid

A grid in 3D whose elements are alterable doubles. Each element of the grid is a double value and is uniquely identified by three non-negative integer indices. The grid knows about the concept of a boundary, but the actual handling of the boundary elements is deferred to subclasses. Dependent on the boundary strategy of the subclass, accessing the boundary elements may or may not be allowed.

Author:
Gerald Loeffler (Gerald.Loeffler@univie.ac.at)

Field Summary
protected  double[][][] g
           
protected  int level
           
protected  int sx
           
protected  int sy
           
protected  int sz
           
 
Constructor Summary
protected Grid(int sx, int sy, int sz, int level, double value)
          construct from size and initial value for all elements.
 
Method Summary
 Grid add(ConstGrid grid)
          implements method from ConstGrid.
 void add(int x, int y, int z, double v)
          add to the element at the specified position, which must be in the interior of the grid.
 ConstGrid clone()
          implements method from ConstGrid.
 double get(int x, int y, int z)
          implements method from ConstGrid.
protected abstract  double getBoundary(int x, int y, int z)
          get an element from the boundary of the grid.
 int getCols()
          implements method from ConstGrid.
 int getLevel()
          Get the resolution level.
 int getRows()
          implements method from ConstGrid.
 int getSlices()
          implements method from ConstGrid.
 boolean isBoundary(int x, int y, int z)
          implements method from ConstGrid.
 boolean isInterior(int x, int y, int z)
          implements method from ConstGrid.
 void set(int x, int y, int z, double v)
          set the element at the specified position, which must be in the interior of the grid.
 void setLevel(int level)
          Set the resolution level.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.jhu.cs.cisst.algorithms.optimize.fmg.grid.ConstGrid
newInstance
 

Field Detail

sx

protected int sx

sy

protected int sy

sz

protected int sz

level

protected int level

g

protected double[][][] g
Constructor Detail

Grid

protected Grid(int sx,
               int sy,
               int sz,
               int level,
               double value)
construct from size and initial value for all elements.

The constructor allocates memory for the interior and the boundary of the grid, riscing that the space for the boundary is wasted if a subclass decides to handle boundary elements differently.

Parameters:
size - the size of the grid ( > 0)
value - the initial value to which all grid element will be set
Method Detail

get

public final double get(int x,
                        int y,
                        int z)
implements method from ConstGrid.

Specified by:
get in interface ConstGrid
Parameters:
x - the x index of the element (0 <= x < size())
y - the y index of the element (0 <= y < size())
z - the z index of the element (0 <= z < size())
Returns:
the element (a double value) at the specified position
See Also:
ConstGrid.get(int, int, int)

set

public void set(int x,
                int y,
                int z,
                double v)
set the element at the specified position, which must be in the interior of the grid.

Specified by:
set in interface ConstGrid
Parameters:
x - the x index of the element (1 <= x < (size() - 1))
y - the y index of the element (1 <= y < (size() - 1))
z - the z index of the element (1 <= z < (size() - 1))
v - the value to which the element is to be set

add

public final void add(int x,
                      int y,
                      int z,
                      double v)
add to the element at the specified position, which must be in the interior of the grid.

Parameters:
x - the x index of the element (1 <= x < (size() - 1))
y - the y index of the element (1 <= y < (size() - 1))
z - the z index of the element (1 <= z < (size() - 1))
v - the value which is to be added to the element

getRows

public final int getRows()
implements method from ConstGrid.

Specified by:
getRows in interface ConstGrid
Returns:
the rows
See Also:
ConstGrid#size

getCols

public final int getCols()
implements method from ConstGrid.

Specified by:
getCols in interface ConstGrid
Returns:
the cols
See Also:
ConstGrid#size

getSlices

public final int getSlices()
implements method from ConstGrid.

Specified by:
getSlices in interface ConstGrid
Returns:
the slices
See Also:
ConstGrid#size

getLevel

public final int getLevel()
Description copied from interface: ConstGrid
Get the resolution level.

Specified by:
getLevel in interface ConstGrid
Returns:
level

isInterior

public final boolean isInterior(int x,
                                int y,
                                int z)
implements method from ConstGrid.

Specified by:
isInterior in interface ConstGrid
Parameters:
x - the x index of the element
y - the y index of the element
z - the z index of the element
Returns:
true if the element is in the interior of the grid, false otherwise
See Also:
ConstGrid.isInterior(int, int, int)

isBoundary

public final boolean isBoundary(int x,
                                int y,
                                int z)
implements method from ConstGrid.

Specified by:
isBoundary in interface ConstGrid
Parameters:
x - the x index of the element
y - the y index of the element
z - the z index of the element
Returns:
true if the element is at the boundary of the grid, false otherwise
See Also:
ConstGrid.isBoundary(int, int, int)

clone

public ConstGrid clone()
implements method from ConstGrid.

Specified by:
clone in interface ConstGrid
Overrides:
clone in class java.lang.Object
Returns:
the const grid
See Also:
ConstGrid.clone()

add

public final Grid add(ConstGrid grid)
implements method from ConstGrid.

Specified by:
add in interface ConstGrid
Parameters:
grid - the grid to add to this grid
Returns:
the newly constructed grid that is the sum of the grids
See Also:
ConstGrid.add(edu.jhu.cs.cisst.algorithms.optimize.fmg.grid.ConstGrid)

getBoundary

protected abstract double getBoundary(int x,
                                      int y,
                                      int z)
get an element from the boundary of the grid.

Parameters:
x - the x index of the boundary element
y - the y index of the boundary element
z - the z index of the boundary element
Returns:
the element (a double value) at the specified position
Throws:
java.lang.IndexOutOfBoundsException - if read access to the boundary is not allowed

setLevel

public void setLevel(int level)
Description copied from interface: ConstGrid
Set the resolution level.

Specified by:
setLevel in interface ConstGrid
Parameters:
level - the level