de.unihalle.informatik.MiToBo.core.datatypes
Class MTBVectorField2D

java.lang.Object
  extended by de.unihalle.informatik.Alida.operator.ALDData
      extended by de.unihalle.informatik.MiToBo.core.datatypes.MTBVectorField2D

@ALDParametrizedClass
public class MTBVectorField2D
extends de.unihalle.informatik.Alida.operator.ALDData

Class to represent several kinds of vector fields. For example gvf-fields. A vector field has two field vectors, U and V. For the first time a kind of basic methods are implemented and implementation of other methods will be continued.

Author:
moeller, misiak

Field Summary
private  int height
          Height of the image where the vector field comes from.
private  double[] potential
          Potential of the vector field.
private  VectorField2DPotentialFinder potFinder
          Helper object for reconstructing potential from vector field.
private  double[] U
          Vector U including the x-values of the vector field.
private  double[] V
          Vector V including the y-values of the vector field.
private  int width
          Width of the image where the vector field comes from.
 
Constructor Summary
MTBVectorField2D()
           
MTBVectorField2D(double[] u, double[] v, int width, int height)
           
 
Method Summary
 double[] calcPotential_approxLeastSquares(boolean ignoreBorder)
          Calculates an approximation of the potential of the field by gradient descent.
 double[] calcPotential_exactLeastSquares(boolean ignoreBorder)
          Calculates the potential of the field by solving a LSE with least squares.
 double[] calcPotential_incrLeastSquares(boolean ignoreBorder)
          Calculates a rough approximation of the potential of the field in linear time.
 double getDirection(double x, double y)
          Get direction of the vector at position (x,y) in the vector field, relative to the x-axis.
 int getFieldSizeX()
           
 int getFieldSizeY()
           
 double getMagnitude(double x, double y)
          Get magnitude of the vector at position (x,y) in the vector field.
 double[] getPotential()
          Returns a copy of the potential field (for faster access!).
 double[] getU()
          Get vector U of the field.
 double[] getV()
          Get vector V of the field.
 double getValuePotential(double x, double y)
          Returns value of potential at specified position.
 double getValueU(double x, double y)
          Get value from vector U at position (x,y).
 double getValueV(double x, double y)
          Get value from vector V at position (x,y).
 boolean readFromBinFile(java.lang.String file)
          Reads a vector field from a file in binary format.
 void resetPotential()
          Resets the potential, next access to it will enforce recalculation.
 boolean saveToBinFile(java.lang.String file)
          Saves the vector field to a file in binary format.
 void setU(double[] u, int w, int h)
          Set vector U of the field.
 void setU(double x, double y, double value)
          Set value on (x,y) for vector U of the field.
 void setV(double[] v, int w, int h)
          Set value on (x,y) for vector V of the field.
 void setV(double x, double y, double value)
          Set value on (x,y) for vector V of the field.
 
Methods inherited from class de.unihalle.informatik.Alida.operator.ALDData
cloneProperties, getLocation, getProperty, getPropertyKeys, print, setLocation, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

height

@Parameter
private int height
Height of the image where the vector field comes from.


potential

@Parameter
private double[] potential
Potential of the vector field.


potFinder

private VectorField2DPotentialFinder potFinder
Helper object for reconstructing potential from vector field.


U

@Parameter
private double[] U
Vector U including the x-values of the vector field.


V

@Parameter
private double[] V
Vector V including the y-values of the vector field.


width

@Parameter
private int width
Width of the image where the vector field comes from. The width is necessary to calculate the right position in the vectors U and V, because the values are stored in a one dimensional array of length (width * height). To get a value on a position (x,y) of U or V you must calculate the right position in the vector by calculating the position = (y * width + height).

Constructor Detail

MTBVectorField2D

public MTBVectorField2D()

MTBVectorField2D

public MTBVectorField2D(double[] u,
                        double[] v,
                        int width,
                        int height)
Method Detail

calcPotential_approxLeastSquares

public double[] calcPotential_approxLeastSquares(boolean ignoreBorder)
Calculates an approximation of the potential of the field by gradient descent.

Parameters:
ignoreBorder - If true, outer rows and columns of the field are ignored.
Returns:
Returns a copy of the calculated potential field.

calcPotential_exactLeastSquares

public double[] calcPotential_exactLeastSquares(boolean ignoreBorder)
Calculates the potential of the field by solving a LSE with least squares.

Attention! This methods takes a lot of resources. If your field is large you better use another routine for potential reconstruction.

Parameters:
ignoreBorder - If true, outer rows and columns of the field are ignored.
Returns:
Returns a copy of the calculated potential field.

calcPotential_incrLeastSquares

public double[] calcPotential_incrLeastSquares(boolean ignoreBorder)
Calculates a rough approximation of the potential of the field in linear time.

Parameters:
ignoreBorder - If true, outer rows and columns of the field are ignored.
Returns:
Returns a copy of the calculated potential field.

getDirection

public double getDirection(double x,
                           double y)
Get direction of the vector at position (x,y) in the vector field, relative to the x-axis. The direction is given in radian measure, not in degrees.

Parameters:
x - x-coordinate
y - y-coordinate
Returns:
Direction of vector (U(x,y), V(x,y)) from the vector field at position (x,y).

getFieldSizeX

public int getFieldSizeX()

getFieldSizeY

public int getFieldSizeY()

getMagnitude

public double getMagnitude(double x,
                           double y)
Get magnitude of the vector at position (x,y) in the vector field.

Parameters:
x - x-coordinate
y - y-coordinate
Returns:
Magnitude of vector (U(x,y), V(x,y)) from the vector field at position (x,y).

getPotential

public double[] getPotential()
Returns a copy of the potential field (for faster access!).


getU

public double[] getU()
Get vector U of the field.

Returns:
Vector U including the x-values of the vector field.

getV

public double[] getV()
Get vector V of the field.

Returns:
Vector V including the y-values of the vector field.

getValuePotential

public double getValuePotential(double x,
                                double y)
Returns value of potential at specified position.

Parameters:
x - x coordinate of position.
y - y coordinate of position.
Returns:
0 if potential does not exist.

getValueU

public double getValueU(double x,
                        double y)
Get value from vector U at position (x,y).

Parameters:
x - x-coordinate
y - y-coordinate
Returns:
Value from vector U at position (x,y).

getValueV

public double getValueV(double x,
                        double y)
Get value from vector V at position (x,y).

Parameters:
x - x-coordinate
y - y-coordinate
Returns:
Value from vector V at position (x,y).

readFromBinFile

public boolean readFromBinFile(java.lang.String file)
Reads a vector field from a file in binary format.

Parameters:
file - Input file.
Returns:
True, if reading was successful.

resetPotential

public void resetPotential()
Resets the potential, next access to it will enforce recalculation.


saveToBinFile

public boolean saveToBinFile(java.lang.String file)
Saves the vector field to a file in binary format.

Parameters:
file - Output file.
Returns:
True, if saving was successful.

setU

public void setU(double[] u,
                 int w,
                 int h)
          throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Set vector U of the field.

Parameters:
u - vector to set U
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException

setU

public void setU(double x,
                 double y,
                 double value)
          throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Set value on (x,y) for vector U of the field.

Attention! Method assumes that memory for U is s already allocated.

Parameters:
x - x-coordinate
y - y-coordinate
value - value to set on position (x,y)
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException

setV

public void setV(double[] v,
                 int w,
                 int h)
          throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Set value on (x,y) for vector V of the field.

Parameters:
v - vector to set V
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException

setV

public void setV(double x,
                 double y,
                 double value)
          throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Set value on (x,y) for vector V of the field.

Attention! Method assumes that memory for V is s already allocated.

Parameters:
x - x-coordinate
y - y-coordinate
value - value to set on position (x,y)
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException