movingregion
Class TriangleRep

java.lang.Object
  |
  +--movingregion.TriangleRep

public class TriangleRep
extends java.lang.Object

This class is used to create a time slice of a moving cycle. It takes two snapshots of a moving cycle and constructs and stores a graph representation of the moving cycle.


Field Summary
 int[] endpoints
           
 double min_overlap
           
 double min_overlap_match
           
 
Constructor Summary
TriangleRep()
          Constructor without parameters.
TriangleRep(ConvexHullTreeNode root1, ConvexHullTreeNode root2, double minOverlMatch)
          Constructs the graph representation from two arbitrarily shaped polygons represented by convex hull trees.
TriangleRep(LineWA[] poly1, LineWA[] poly2, double minOverlMatch)
          Constructs the graph representation from two arbitrarily shaped polygons represented as lists of lines.
 
Method Summary
 int findPoint(int x1, int y1, int t1)
          This function determines which point in the graph structure lies at a given coordinate value.
 int getCorrespondingPoint(int index1, int index2)
          Given two points in the same snapshot, finds the third point which forms a triangle with the two points.
 int[] getCorrespondingPoint(int x1, int y1, int x2, int y2, int t1)
          Given two points in the same snapshot, finds the third point which forms a triangle with the two points.
 int[] getNeighbours(int p1)
          This function is used to find which points are the neighbours of a given point.
 int[] getNeighbours(java.lang.Object p)
          This function is used to find which points are the neighbours of a given point.
 int getNumberOfNeighbours(int p1)
          Get the number of neighbours that a given point has.
 int getNumberOfPoints()
          Determines how many points there are in the graph representation.
 int[] getOrderedSnapshot(int time)
          This function is used to get the points in one snapshot from the graph representation and sort them so that they come in counterclockwise order.
 java.lang.Object getPoint(int index)
           
 java.lang.Object[] getPoints()
          This function returns the list of points as an array of objects.
 int[] getPosition(int p1)
          Returns the position of a point in space-time as an integer array.
 int[] getSnapshot(int time)
          This function is used to get the points in one snapshot from the graph representation.
 boolean insertConcavity(TriangleRep concavity, ConvexHullTreeNode root1, ConvexHullTreeNode root2)
          Inserts a concavity into this graph representation by removing two lines from the graph representation and replacing them with the graph representation of the concavity object.
 void insertHalfConcavity(LineWA[] lines, int p1, int p2, int copoint, int t)
          Insert a concavity in one snapshot that is matched to a point in the other into the graph representation.
 void insertLine(int p1, int p2)
          Inserts a line from p1 to p2 into the graph.
 int insertPoint(int x, int y, int t)
          Inserts a point into the graph structure.
 boolean neighbours(int p1, int p2)
          Test whether two points are neighbours.
 boolean pointExists(int index)
          This function checks whether a point is stored in a given index in the point list.
 boolean removeLine(int p1, int p2)
          Removes a previously inserted line from the graph structure.
 boolean removePoint(int p1)
          Removes a point from the graph structure.
 void saveAsVRML(java.lang.String filename)
          Creates a VRML file containing a VRML representation of the graph (an indexedFaceSet).
 void translateSnapshot(int dx, int dy, int time)
          This function moves the coordinate values of each point in the given snapshot.
 void writeTriangles(int time, java.io.OutputStreamWriter fs, java.util.Vector convertlist)
          Writes the individual triangular surfaces containing one line from the given snapshot into the VRML file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

min_overlap

public double min_overlap

min_overlap_match

public double min_overlap_match

endpoints

public int[] endpoints
Constructor Detail

TriangleRep

public TriangleRep()
Constructor without parameters. Makes an empty triangle representation.

TriangleRep

public TriangleRep(LineWA[] poly1,
                   LineWA[] poly2,
                   double minOverlMatch)
Constructs the graph representation from two arbitrarily shaped polygons represented as lists of lines.
Parameters:
poly1 - The first snapshot represented as a list of line segments
poly2 - The second snapshot represented as a list of line segments
minOverlMatch - How much overlap between concavities is necessary for them to be matched to each other.

TriangleRep

public TriangleRep(ConvexHullTreeNode root1,
                   ConvexHullTreeNode root2,
                   double minOverlMatch)
Constructs the graph representation from two arbitrarily shaped polygons represented by convex hull trees.
Parameters:
root1 - The root of the convex hull tree representing the first snapshot.
root2 - The root of the convex hull tree representing the second snapshot.
minOverlMatch - How much overlap between concavities is necessary for them to be matched to each other.
Method Detail

insertHalfConcavity

public void insertHalfConcavity(LineWA[] lines,
                                int p1,
                                int p2,
                                int copoint,
                                int t)
Insert a concavity in one snapshot that is matched to a point in the other into the graph representation.
Parameters:
lines - The concavity represented as a list of lines
p1 - The first point in the line which is to be replaced by the concavity.
p2 - The second point in the line which is to be replaced by the concavity.
copoint - The point in the other snapshot which is the "third corner of the triangle" with respect to p1 and p2.
t - Indicates which snapshot the concavity belongs to.

insertPoint

public int insertPoint(int x,
                       int y,
                       int t)
Inserts a point into the graph structure.
Parameters:
x - The x-coordinate of the point
y - The y-coordinate of the point
t - Which snapshot the point belongs to.
Returns:
The index of the point in the point list

insertLine

public void insertLine(int p1,
                       int p2)
Inserts a line from p1 to p2 into the graph. p1 and p2 must have been registered previously.
Parameters:
p1 - The starting point of the line
p2 - The ending point of the line

removeLine

public boolean removeLine(int p1,
                          int p2)
Removes a previously inserted line from the graph structure.
Parameters:
p1 - The index of the starting point of the line.
p2 - The index of the ending point of the line.
Returns:
FALSE if there is no such line, TRUE otherwise.

removePoint

public boolean removePoint(int p1)
Removes a point from the graph structure. To maintain the numbering of the points, the point is set to null instead of actually deleted. This function also removes all neighbour references to the point.
Parameters:
p1 - The index of the point to be removed
Returns:
TRUE if the point was successfully removed, FALSE otherwise.

getPosition

public int[] getPosition(int p1)
Returns the position of a point in space-time as an integer array.
Parameters:
p1 - The point.
Returns:
An array containing the position of the point. position 0 = x, position 1 = y, position 2 = t. If the point no longer exists, it returns an array with three -1 values.

getNeighbours

public int[] getNeighbours(int p1)
This function is used to find which points are the neighbours of a given point.
Parameters:
p1 - The index of the point.
Returns:
An array of integers, which contains the indexes of the neighbours of the point.

neighbours

public boolean neighbours(int p1,
                          int p2)
Test whether two points are neighbours.
Parameters:
p1 - The first point.
p2 - The second point.
Returns:
TRUE if there is a line in the graph from p1 to p2, FALSE otherwise.

getNumberOfNeighbours

public int getNumberOfNeighbours(int p1)
Get the number of neighbours that a given point has.
Parameters:
p1 - the point.
Returns:
The number of lines in the graph which go to/from p1.

getNeighbours

public int[] getNeighbours(java.lang.Object p)
This function is used to find which points are the neighbours of a given point.
Parameters:
p1 - The point given as a PointWNL object.
Returns:
An array of integers, which contains the indexes of the neighbours of the point.

getNumberOfPoints

public int getNumberOfPoints()
Determines how many points there are in the graph representation. This number includes points which have been inserted and subsequently deleted.
Returns:
The number of elements in the point list.

getPoints

public java.lang.Object[] getPoints()
This function returns the list of points as an array of objects. Because the points are really PointWNL objects, they cannot be interpreted by the functions in other classes.
Returns:
the list of points.

getPoint

public java.lang.Object getPoint(int index)

pointExists

public boolean pointExists(int index)
This function checks whether a point is stored in a given index in the point list.
Parameters:
index - The index.
Returns:
TRUE if a point is stored at that index in the point list, FALSE if the point at that position has been deleted.

getSnapshot

public int[] getSnapshot(int time)
This function is used to get the points in one snapshot from the graph representation.
Parameters:
time - Indicates which snapshot should be returned.
Returns:
The points in the graph structure that belong to the given snapshot. They are returned in the order in which that were inserted, which is not necessarily counterclockwise.

getOrderedSnapshot

public int[] getOrderedSnapshot(int time)
This function is used to get the points in one snapshot from the graph representation and sort them so that they come in counterclockwise order.
Parameters:
time - Indicates which snapshot should be returned.
Returns:
The points in the graph structure that belong to the given snapshot.

findPoint

public int findPoint(int x1,
                     int y1,
                     int t1)
This function determines which point in the graph structure lies at a given coordinate value.
Parameters:
x - The x-coordinate of the point
y - The y-coordinate of the point
t - Which snapshot the point belongs to.
Returns:
The index of the point in the point list. If there is no point at the given position, the function returns -1.

translateSnapshot

public void translateSnapshot(int dx,
                              int dy,
                              int time)
This function moves the coordinate values of each point in the given snapshot. It is used after the interpolation to move one of the snapshots back to it's original position.
Parameters:
dx - How far the snapshot should be moved in the x direction.
dy - How far the snapshot should be moved in the y direction.
t - Which snapshot should be moved.

getCorrespondingPoint

public int[] getCorrespondingPoint(int x1,
                                   int y1,
                                   int x2,
                                   int y2,
                                   int t1)
Given two points in the same snapshot, finds the third point which forms a triangle with the two points.
Parameters:
x1 - The x-coordinate of the first point.
y1 - The y-coordinate of the first point.
x2 - The x-coordinate of the second point.
y2 - The y-coordinate of the second point.
t - Which snapshot the points belong to.
Returns:
The integer indexes of all three points in the graph representation. If it doesn't find either point 1 or point 2, or it doesn't find a third point, it returns null.

getCorrespondingPoint

public int getCorrespondingPoint(int index1,
                                 int index2)
Given two points in the same snapshot, finds the third point which forms a triangle with the two points.
Parameters:
index1 - The index pf the first point.
index2 - The index of the second point.
Returns:
The index of the third point. It returns -1 if no neighbour was found, the original points are not neighbours, or the original points have different time values.

insertConcavity

public boolean insertConcavity(TriangleRep concavity,
                               ConvexHullTreeNode root1,
                               ConvexHullTreeNode root2)
Inserts a concavity into this graph representation by removing two lines from the graph representation and replacing them with the graph representation of the concavity object. The lines which are removed are those that match with lines in the concavity object. If there are no such matches, the function does nothing.
Parameters:
concavity - The concavity to be inserted.
root1 - The root of the first convex hull tree.
root2 - The root of the second convex hull tree.
Returns:
TRUE if the function successfully inserted the concavity, FALSE otherwise.

writeTriangles

public void writeTriangles(int time,
                           java.io.OutputStreamWriter fs,
                           java.util.Vector convertlist)
                    throws java.io.IOException
Writes the individual triangular surfaces containing one line from the given snapshot into the VRML file.
Parameters:
time - The snapshot.
fs - The file to write to.
convertlist - List which converts indexes in the point list of the graph structure to indexes in the point list of the VRML file.
Throws:
java.io.IOException - If the function cannot write to the file.

saveAsVRML

public void saveAsVRML(java.lang.String filename)
                throws java.io.FileNotFoundException,
                       java.io.IOException
Creates a VRML file containing a VRML representation of the graph (an indexedFaceSet).
Parameters:
filename - The file name of the VRML file.