Facemorph.template
Class Contour

java.lang.Object
  extended by Facemorph.template.Contour

public class Contour
extends java.lang.Object

Class to store information about a Template's contour


Constructor Summary
Contour()
          Construct an empty Contour
Contour(int i)
          Construct a contour with initial contour index given
 
Method Summary
 void addPoint(int i, java.util.Vector landmarks)
          Adds a point to this contour
 void addPointInLine(int i, java.util.Vector landmarks)
          Adds a point to this contour
 void calculateContour(java.util.Vector landmarks)
          Calculate the position of each point along the curve given the control point positions
 void calculateSamples(java.util.Vector landmarks)
          Calculate the number of samples along a contour using the piecewise linear distance along the curve
 void close()
          Makes this a closed contour (closed = true)
 int controlPointCount()
          Get the number of control points in this contour
 boolean convert(java.util.StringTokenizer st)
          Read a contour from a StreamTokenizer
 void copy(Contour c)
          Copies the point indices and sample point positions from c
 void deletePoint(int PointNum, java.util.Vector landmarks)
          Deletes the given point index from this contour
 void draw(java.awt.Graphics g, int x_off, int y_off, java.awt.Color c)
          Draw the contour to the Graphics given, shifting by x_off and y_off and using colour c
 void drawZoomed(java.awt.Graphics g, int x_off, int y_off, float xs, float ys, java.awt.Color c)
          Draw the contour to the Graphics given, shifting by x_off and y_off, scaling by xs, ys and using colour c
 java.util.ArrayList<java.awt.geom.Rectangle2D> getBounds(java.util.Vector landmarks)
           
 java.awt.geom.Point2D.Float getControlPointNormal(int i, java.util.Vector landmarks)
          Gets the direction at right angles to this contour at the control points
 java.util.Vector<java.lang.Integer> getControlPoints()
          Get the control point vector
 int getLength()
          Get the length of this contour
 java.util.Vector<java.awt.geom.Point2D.Float> getPoints()
          Get the control points
 double[] getSamples()
           
 double getTol()
           
 boolean hitLine(java.awt.geom.Point2D.Float p, java.util.Vector landmarks)
           
 boolean isClosed()
          Is this a closed contour
 void open()
          Makes this an open contour (closed = false)
 boolean read(java.io.StreamTokenizer st)
          Read a contour from a StreamTokenizer
 void setLength()
          Sets the length to be the maximum t value
 void setLength(int len)
          Set the total number of samples along the contour
 void setSamples(double[] s)
           
 void setTol(float tol)
           
 java.lang.String toString()
          Convert this contour to a String representation
 java.lang.String toURLString()
          Convert this contour to a String representation suitable for putting in a URL
 void transform(float[][] mat)
          Transform this contour's samples using the affine matrix given
 void update(java.util.Vector landmarks)
          Recalculates the interpolated contour samples from the new landmark positions
 boolean write(java.io.PrintStream out)
          Write the contour to the PrintStream given
 void zoom(float zoomx, float zoomy, float crop_x, float crop_y)
          Zooms and shifts the contour
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Contour

public Contour()
Construct an empty Contour


Contour

public Contour(int i)
Construct a contour with initial contour index given

Parameters:
i - The index of the first point on this contour
Method Detail

setTol

public void setTol(float tol)

getTol

public double getTol()

getBounds

public java.util.ArrayList<java.awt.geom.Rectangle2D> getBounds(java.util.Vector landmarks)

hitLine

public boolean hitLine(java.awt.geom.Point2D.Float p,
                       java.util.Vector landmarks)

addPoint

public void addPoint(int i,
                     java.util.Vector landmarks)
Adds a point to this contour

Parameters:
i - The index of the point to add
landmarks - The array of landmarks hat i indexes into in Template

addPointInLine

public void addPointInLine(int i,
                           java.util.Vector landmarks)
Adds a point to this contour

Parameters:
i - The index of the point to add
landmarks - The array of landmarks hat i indexes into in Template

close

public void close()
Makes this a closed contour (closed = true)


open

public void open()
Makes this an open contour (closed = false)


isClosed

public boolean isClosed()
Is this a closed contour

Returns:
the value of closed

deletePoint

public void deletePoint(int PointNum,
                        java.util.Vector landmarks)
Deletes the given point index from this contour

Parameters:
PointNum - The index of the point to resetLocation from this contour
landmarks - The array of template landmarks

controlPointCount

public int controlPointCount()
Get the number of control points in this contour

Returns:
the number of control points in this contour

update

public void update(java.util.Vector landmarks)
Recalculates the interpolated contour samples from the new landmark positions

Parameters:
landmarks - The array of Template landmarks

getPoints

public java.util.Vector<java.awt.geom.Point2D.Float> getPoints()
Get the control points

Returns:
the control points

calculateSamples

public void calculateSamples(java.util.Vector landmarks)
Calculate the number of samples along a contour using the piecewise linear distance along the curve

Parameters:
landmarks - The array of Template landmark points

setSamples

public void setSamples(double[] s)

getSamples

public double[] getSamples()

setLength

public void setLength(int len)
Set the total number of samples along the contour

Parameters:
len - the length

getLength

public int getLength()
Get the length of this contour

Returns:
the length

setLength

public void setLength()
Sets the length to be the maximum t value


calculateContour

public void calculateContour(java.util.Vector landmarks)
Calculate the position of each point along the curve given the control point positions

Parameters:
landmarks - the control point positions

copy

public void copy(Contour c)
Copies the point indices and sample point positions from c

Parameters:
c - the contour to copy

draw

public void draw(java.awt.Graphics g,
                 int x_off,
                 int y_off,
                 java.awt.Color c)
Draw the contour to the Graphics given, shifting by x_off and y_off and using colour c

Parameters:
g - the Graphics to draw to
x_off - the x offset
y_off - the y offset
c - the colour to use

drawZoomed

public void drawZoomed(java.awt.Graphics g,
                       int x_off,
                       int y_off,
                       float xs,
                       float ys,
                       java.awt.Color c)
Draw the contour to the Graphics given, shifting by x_off and y_off, scaling by xs, ys and using colour c

Parameters:
g - the Graphics to draw to
x_off - the x offset
y_off - the y offset
xs - the x scale factor
ys - the y scale factor
c - the colour to use

read

public boolean read(java.io.StreamTokenizer st)
Read a contour from a StreamTokenizer

Parameters:
st - The StreamTokenizer used to parse the file
Returns:
true if the file was read correctly

write

public boolean write(java.io.PrintStream out)
Write the contour to the PrintStream given

Parameters:
out - The Printstream to write to
Returns:
true if written successfully

toString

public java.lang.String toString()
Convert this contour to a String representation

Overrides:
toString in class java.lang.Object
Returns:
The String representation of the Contour

toURLString

public java.lang.String toURLString()
Convert this contour to a String representation suitable for putting in a URL

Returns:
The String representation of the Contour

convert

public boolean convert(java.util.StringTokenizer st)
Read a contour from a StreamTokenizer

Parameters:
st - The StreamTokenizer used to parse the file
Returns:
true if the file was read correctly

transform

public void transform(float[][] mat)
Transform this contour's samples using the affine matrix given

Parameters:
mat - The affine transformation matrix to use

zoom

public void zoom(float zoomx,
                 float zoomy,
                 float crop_x,
                 float crop_y)
Zooms and shifts the contour

Parameters:
zoomx - zoom x factor
zoomy - zoom y factor
crop_x - subtract from each samples x coord
crop_y - subtract from each samples y coord

getControlPointNormal

public java.awt.geom.Point2D.Float getControlPointNormal(int i,
                                                         java.util.Vector landmarks)
Gets the direction at right angles to this contour at the control points

Parameters:
i - the control point index
landmarks - the Template's control points
Returns:
the normal vector

getControlPoints

public java.util.Vector<java.lang.Integer> getControlPoints()
Get the control point vector

Returns:
the control point vector