Facemorph.aam
Class OpenGLwarp

java.lang.Object
  extended by Facemorph.aam.OpenGLwarp
All Implemented Interfaces:
java.util.EventListener, javax.media.opengl.GLEventListener

public class OpenGLwarp
extends java.lang.Object
implements javax.media.opengl.GLEventListener

Opengl BASED WARPING


Constructor Summary
OpenGLwarp(int width, int height, java.awt.image.BufferedImage bimg, java.util.Vector<java.awt.geom.Point2D.Float> sourcePoints, java.util.Vector<java.awt.geom.Point2D.Float> targetPoints)
          Creates a new OpenGL warp
OpenGLwarp(int width, int height, java.awt.image.BufferedImage bimg, java.util.Vector<java.awt.geom.Point2D.Float> sourcePoints, java.util.Vector<java.awt.geom.Point2D.Float> targetPoints, javax.media.opengl.GLAutoDrawable canvas)
          Constructor for OpenGLWarp
 
Method Summary
static void addAffineBorderPoints(java.util.Vector<java.awt.geom.Point2D.Float> srcPoints, java.util.Vector<java.awt.geom.Point2D.Float> dstPoints, int width, int height, boolean addBorder)
          Adds points to pin down the border
static void addBorderPoints(java.util.Vector<java.awt.geom.Point2D.Float> points, int width, int height)
          Add border points to the point set given
 void checkError(javax.media.opengl.GL gl)
          Check for opengl errors
 DelaunayTriangle[] computeTriangulation(java.util.Vector<java.awt.geom.Point2D.Float> points)
          Compute the Delaunay Triangulation of a set of points
 void destroy()
          Destroy the offscreen context
 void display()
          Force a redraw of the offscreen context
 void display(javax.media.opengl.GLAutoDrawable drawable)
           
 void displayChanged(javax.media.opengl.GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)
           
 void dispose()
          Dispose of this
static FloatImage getAlpha(java.awt.image.BufferedImage bimg)
          Get the alpha channel as a FloatImage
 int getHeight()
          Get the height
 FloatImage[] getResult()
          Get the warped image
 FloatImage[] getResult(boolean alpha)
          Get the warped image
 int getWidth()
          Get the width
 void grab(javax.media.opengl.GL gl, FloatImage[] result)
          Grab the frame buffer into the FloatImage
 void init(javax.media.opengl.GLAutoDrawable drawable)
           
 double jacobianError()
          Calculate the jacobean error, i.e.
static void main(java.lang.String[] args)
          Main method used for testing
 double overlap(double minArea, boolean adjust)
          Calculate and optionally apply scaling to prevent warp folding
 void reshape(javax.media.opengl.GLAutoDrawable drawable, int x, int y, int width, int height)
           
static java.awt.Color sample(java.awt.image.BufferedImage img, float x, float y)
          Sample from a BufferedImage
static java.awt.image.BufferedImage setAlpha(java.awt.image.BufferedImage bimg, FloatImage alpha)
          Set the alpha channel
 void setDrawTriangulation(boolean drawTriangulation)
          Indicate that the triangulation should be drawn
 void setDrawWarp(boolean drawWarp)
          Indicate that the warped image should be drawn (??)
 void setGLAutoDrawable(javax.media.opengl.GLAutoDrawable drawable)
          Set the opengl context
 void setImage(java.awt.image.BufferedImage img)
          Set the image to warp
 void setPoints(java.util.Vector<java.awt.geom.Point2D.Float> sourcePoints, java.util.Vector<java.awt.geom.Point2D.Float> targetPoints)
          Set the warping points
 void setSize(int w, int h)
          Sets the size
 void setTriangulation(DelaunayTriangle[] dtTess)
          Set teh triangulation to use
static java.nio.FloatBuffer toFloatBuffer(java.awt.image.BufferedImage bimg)
          Convert the image to a FloatBuffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpenGLwarp

public OpenGLwarp(int width,
                  int height,
                  java.awt.image.BufferedImage bimg,
                  java.util.Vector<java.awt.geom.Point2D.Float> sourcePoints,
                  java.util.Vector<java.awt.geom.Point2D.Float> targetPoints)
Creates a new OpenGL warp

Parameters:
width - the width
height - the height
bimg - the image to warp
sourcePoints - the start points
targetPoints - the end points

OpenGLwarp

public OpenGLwarp(int width,
                  int height,
                  java.awt.image.BufferedImage bimg,
                  java.util.Vector<java.awt.geom.Point2D.Float> sourcePoints,
                  java.util.Vector<java.awt.geom.Point2D.Float> targetPoints,
                  javax.media.opengl.GLAutoDrawable canvas)
Constructor for OpenGLWarp

Parameters:
width - the width
height - the height
bimg - the image to warp
sourcePoints - the start points
targetPoints - the end points
canvas - the opengl canvas to use
Method Detail

setSize

public void setSize(int w,
                    int h)
Sets the size

Parameters:
w - the width
h - the height

dispose

public void dispose()
Dispose of this


setGLAutoDrawable

public void setGLAutoDrawable(javax.media.opengl.GLAutoDrawable drawable)
Set the opengl context

Parameters:
drawable - the new opengl context

getWidth

public int getWidth()
Get the width

Returns:
returns the width

getHeight

public int getHeight()
Get the height

Returns:
returns the height

getResult

public FloatImage[] getResult()
Get the warped image

Returns:
returns the warped image as an array of 3 FloatImage

getResult

public FloatImage[] getResult(boolean alpha)
Get the warped image

Parameters:
alpha - indicates that the alpha channel should be included
Returns:
returns the warped image as an array of 3 or 4 FloatImage

checkError

public void checkError(javax.media.opengl.GL gl)
Check for opengl errors

Parameters:
gl - the opengl context

destroy

public void destroy()
Destroy the offscreen context


setImage

public void setImage(java.awt.image.BufferedImage img)
Set the image to warp

Parameters:
img - the image to warp

setPoints

public void setPoints(java.util.Vector<java.awt.geom.Point2D.Float> sourcePoints,
                      java.util.Vector<java.awt.geom.Point2D.Float> targetPoints)
Set the warping points

Parameters:
sourcePoints - the start points
targetPoints - the end points

display

public void display()
Force a redraw of the offscreen context


setDrawWarp

public void setDrawWarp(boolean drawWarp)
Indicate that the warped image should be drawn (??)

Parameters:
drawWarp - if treu draw the warped image

setDrawTriangulation

public void setDrawTriangulation(boolean drawTriangulation)
Indicate that the triangulation should be drawn

Parameters:
drawTriangulation - if true draw the triangulation

sample

public static java.awt.Color sample(java.awt.image.BufferedImage img,
                                    float x,
                                    float y)
Sample from a BufferedImage

Parameters:
img - the image to sample from
x - the x coord
y - the y coord
Returns:
return the sampled colour

toFloatBuffer

public static java.nio.FloatBuffer toFloatBuffer(java.awt.image.BufferedImage bimg)
Convert the image to a FloatBuffer

Parameters:
bimg - the buffered image to convert
Returns:
returns the image as a FloatBuffer

computeTriangulation

public DelaunayTriangle[] computeTriangulation(java.util.Vector<java.awt.geom.Point2D.Float> points)
Compute the Delaunay Triangulation of a set of points

Parameters:
points - the points to triangulate
Returns:
returns the triangulation

setTriangulation

public void setTriangulation(DelaunayTriangle[] dtTess)
Set teh triangulation to use

Parameters:
dtTess - the triangulation to use

init

public void init(javax.media.opengl.GLAutoDrawable drawable)
Specified by:
init in interface javax.media.opengl.GLEventListener

display

public void display(javax.media.opengl.GLAutoDrawable drawable)
Specified by:
display in interface javax.media.opengl.GLEventListener

grab

public void grab(javax.media.opengl.GL gl,
                 FloatImage[] result)
Grab the frame buffer into the FloatImage

Parameters:
gl - the opengl context
result - the array of FloatImage to store the grabbed image

reshape

public void reshape(javax.media.opengl.GLAutoDrawable drawable,
                    int x,
                    int y,
                    int width,
                    int height)
Specified by:
reshape in interface javax.media.opengl.GLEventListener

displayChanged

public void displayChanged(javax.media.opengl.GLAutoDrawable drawable,
                           boolean modeChanged,
                           boolean deviceChanged)
Specified by:
displayChanged in interface javax.media.opengl.GLEventListener

addAffineBorderPoints

public static void addAffineBorderPoints(java.util.Vector<java.awt.geom.Point2D.Float> srcPoints,
                                         java.util.Vector<java.awt.geom.Point2D.Float> dstPoints,
                                         int width,
                                         int height,
                                         boolean addBorder)
Adds points to pin down the border

Parameters:
srcPoints - the start point array
dstPoints - the end point array
width - the width
height - the height
addBorder - indicates that points need to be added to both arrays, not just the output array

addBorderPoints

public static void addBorderPoints(java.util.Vector<java.awt.geom.Point2D.Float> points,
                                   int width,
                                   int height)
Add border points to the point set given

Parameters:
points - the point set to add the border points too
width - the width
height - the height

jacobianError

public double jacobianError()
Calculate the jacobean error, i.e. area change

Returns:
return the Jacobean error

overlap

public double overlap(double minArea,
                      boolean adjust)
Calculate and optionally apply scaling to prevent warp folding

Parameters:
minArea - The minimum permited area
adjust - if true and the scaling is less than 1 rescale the warp
Returns:
returns the scale factor

setAlpha

public static java.awt.image.BufferedImage setAlpha(java.awt.image.BufferedImage bimg,
                                                    FloatImage alpha)
Set the alpha channel

Parameters:
bimg - the image
alpha - the new alpha channel
Returns:
returns a copy of the image with the new alpha channel

getAlpha

public static FloatImage getAlpha(java.awt.image.BufferedImage bimg)
Get the alpha channel as a FloatImage

Parameters:
bimg - the image to get the alpha channel from
Returns:
returns the alpha channel in a FloatImage

main

public static void main(java.lang.String[] args)
Main method used for testing

Parameters:
args - the arguments