movingregion
Class TriRepUtil

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

public class TriRepUtil
extends java.lang.Object

This class contains a number of static utility methods used by the other classes.


Constructor Summary
TriRepUtil()
           
 
Method Summary
static void computeLineAngles(LineWA[] lines)
          Computes the angle between two consecutive lines for all the lines given, and stores this in the LineWA objects.
static void computeOverlapGraph(ConvexHullTreeNode obj1, ConvexHullTreeNode obj2, double min_overlap_match)
          Computes the overlaps between objects at the same level of the line tree.
static void computeOverlapGraphIter(ConvexHullTreeNode obj1, ConvexHullTreeNode obj2, double min_overlap_match)
          Iterator function used by computeOverlapGraph.
static LineWA[] convexHull(LineWA[] lt)
          Computes the convex hull of a list of lines and places this at the beginning of the array given in the input.
static double[] convexHullDistance(LineWA[] obj1, LineWA[] obj2)
          This function computes the distance between two polygons by computing the smallest convex hull containing both polygons and then computing how much each of the polygons overlap with this convex hull.
static LineWA[] createLineList(int[] xlist, int[] ylist)
          Creates a LineWA list from two sets of coordinate values.
static LineWA[] createLineList(java.util.Vector pointList)
          This function turns a vector of LineWA values into an array of LineWA.
static int findArea(LineWA[] obj)
          Finds the area of a polygon represented by a point list.
static double[] findOverlap(LineWA[] obj1, LineWA[] obj2)
          Finds the overlap between two polygons represented by point lists.
static int indexOf(java.lang.Object[] array, java.lang.Object obj)
          Finds where in an array a given object is.
static int indexOf(java.lang.Object[] array, java.lang.Object obj, int startindex)
          Finds where in an array a given object is.
static void printLineList(LineWA[] lines)
          For debugging purposes: prints the coordinate values of the points in a line list to the screen.
static void recomputeOverlapGraph(ConvexHullTreeNode obj1, ConvexHullTreeNode obj2, double min_overlap)
          Computes the overlaps between objects at the same level of the line tree.
static void removeAllOverlaps(ConvexHullTreeNode obj)
          Removes all overlap references to a given convex hull tree node and all it's children from the convex hull tree.
static void removeDuplicates(java.util.List list)
          Removes duplicate objects from the given list.
static void removeDuplicatesR(java.util.Vector list)
          Removes duplicated without sorting.
static void rotateCycle(LineWA[] shape, double angle)
          This function rotates the given cycle around its center.
static int sameSide(LineWA line1, LineWA line2, LineWA p1, LineWA p2)
          Checks whether the points p1 and p2 are on the same side of the line represented by line1 and line2.
static void translateCycle(LineWA[] outline, int dx, int dy)
          Moves the given cycle by dx and dy.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TriRepUtil

public TriRepUtil()
Method Detail

sameSide

public static int sameSide(LineWA line1,
                           LineWA line2,
                           LineWA p1,
                           LineWA p2)
Checks whether the points p1 and p2 are on the same side of the line represented by line1 and line2.
Parameters:
line1 - The starting point of the line given as a LineWA
line2 - The ending point of the line given as a LineWA
p1 - The first point
p2 - The second point
Returns:
A value indicating whether the two points are on the same side or not:
- less than 0: Points on different sides.
- equal to 0: At least one of the points is on the line.
- greater than 0: Points on the same side.

removeDuplicates

public static void removeDuplicates(java.util.List list)
Removes duplicate objects from the given list. It does this by first sorting the list and then going through the list testing whether two consecutive elements are equal using the equals() method. Only works if the natural ordering is consistent with equals! (That is, it doens't work with LineWA objects)
Parameters:
list - The list of object from which the function should remove duplicates.

removeDuplicatesR

public static void removeDuplicatesR(java.util.Vector list)
Removes duplicated without sorting. It therefore works with all vectors, even if the element's natural order is not consistent with equals. Its running time is O(n*n) instead of O(n*log(n)).
Parameters:
list - The list of object from which the function should remove duplicates.

convexHull

public static LineWA[] convexHull(LineWA[] lt)
Computes the convex hull of a list of lines and places this at the beginning of the array given in the input. Returns a new array containing only the lines of the convex hull.This function uses the graham scan algrithm.

Warning: The angle stored in the elements in the input list as well as the ordering of the elements in the list is changed by this function!

Parameters:
lt - The polygon represented as a list of lines
Returns:
A list of lines containing the convex hull of the input in counterclockwise order.

indexOf

public static int indexOf(java.lang.Object[] array,
                          java.lang.Object obj)
Finds where in an array a given object is. Unlike binary search, this function does not assume that the array is sorted. Uses the equals() method to test for equality unless the object is null.
Parameters:
array - The array to be searched
obj - The object to be searched for
Returns:
The index of the object in the array. If the array does not contain the object, the function returns -1.

indexOf

public static int indexOf(java.lang.Object[] array,
                          java.lang.Object obj,
                          int startindex)
Finds where in an array a given object is. Unlike binary search, this function does not assume that the array is sorted. Uses the equals() method to test for equality unless the object is null.
Parameters:
array - The array to be searched
obj - The object to be searched for
startindex - The index at which the function should start searching.
Returns:
The index of the object in the array. If the array does not contain the object, the function returns -1.

findArea

public static int findArea(LineWA[] obj)
Finds the area of a polygon represented by a point list.
Parameters:
obj - The polygon represented as a LineWA array.
Returns:
The area of the object.

findOverlap

public static double[] findOverlap(LineWA[] obj1,
                                   LineWA[] obj2)
Finds the overlap between two polygons represented by point lists. Uses the java.awt.geom.Area class to compute intersection between two area features.
Parameters:
obj1 - The first polygon represented as a LineWA array.
obj2 - The second polygon represented as a LineWA array.
Returns:
An array containing two doublevalues. The first is the percentage of obj1 that obj2 overlaps, and the second is the percentage of obj2 that obj1 overlaps.

convexHullDistance

public static double[] convexHullDistance(LineWA[] obj1,
                                          LineWA[] obj2)
This function computes the distance between two polygons by computing the smallest convex hull containing both polygons and then computing how much each of the polygons overlap with this convex hull.
Parameters:
obj1 - The first polygon represented as a LineWA array.
obj2 - The second polygon represented as a LineWA array.
Returns:
An array containing two doublevalues. The first is the percentage of the convex hull that obj1 overlaps, and the second is the percentage of the convex hull that obj2 overlaps.

computeOverlapGraph

public static void computeOverlapGraph(ConvexHullTreeNode obj1,
                                       ConvexHullTreeNode obj2,
                                       double min_overlap_match)
Computes the overlaps between objects at the same level of the line tree. Tries to find matching objects. The computed overlaps are stored in the convex hull tree nodes.
Parameters:
obj1 - The first object represented as a convex hull tree.
obj2 - The second object represented as a convex hull tree.
min_overlap_match - The amount of overlap required to consider the two objects to match.

computeOverlapGraphIter

public static void computeOverlapGraphIter(ConvexHullTreeNode obj1,
                                           ConvexHullTreeNode obj2,
                                           double min_overlap_match)
Iterator function used by computeOverlapGraph.
Parameters:
obj1 - The first object represented as a convex hull tree.
obj2 - The second object represented as a convex hull tree.
min_overlap_match - The amount of overlap required to consider the two objects to match.

recomputeOverlapGraph

public static void recomputeOverlapGraph(ConvexHullTreeNode obj1,
                                         ConvexHullTreeNode obj2,
                                         double min_overlap)
Computes the overlaps between objects at the same level of the line tree. Tries to find matching objects. The difference between this and computeOverlapGraph is that this one does not insert overlap graph edges for the nodes themselves, only for the children.
Parameters:
obj1 - The first object represented as a convex hull tree.
obj2 - The second object represented as a convex hull tree.
min_overlap - The amount of overlap required to consider the two objects to match.

removeAllOverlaps

public static void removeAllOverlaps(ConvexHullTreeNode obj)
Removes all overlap references to a given convex hull tree node and all it's children from the convex hull tree. (Used when deleting nodes from the convex hull tree)
Parameters:
obj - The comvex hull tree node to be removed.

createLineList

public static LineWA[] createLineList(int[] xlist,
                                      int[] ylist)
Creates a LineWA list from two sets of coordinate values. This function also computes the angles between two consecutive lines and stores these in the LineWA objects.
Parameters:
xlist - A list of the x-coordinates of the points.
ylist - A list of the y-coordinates of the points.
Returns:
A list of LineWA objects containing the points given.

createLineList

public static LineWA[] createLineList(java.util.Vector pointList)
This function turns a vector of LineWA values into an array of LineWA. The function also computes the angles between two consecutive lines and stores this in the LineWA objects.
Parameters:
pointList - The list of points given as LineWA's.
Returns:
The array of LineWA's

computeLineAngles

public static void computeLineAngles(LineWA[] lines)
Computes the angle between two consecutive lines for all the lines given, and stores this in the LineWA objects.
Parameters:
lines - The list of lines.

printLineList

public static void printLineList(LineWA[] lines)
For debugging purposes: prints the coordinate values of the points in a line list to the screen.
Parameters:
lines - The list of LineWA objects to be printed

rotateCycle

public static void rotateCycle(LineWA[] shape,
                               double angle)
This function rotates the given cycle around its center.
Parameters:
shape - The cycle to be rotated given as a LineWA array.
angle - The angle in radians that the shape should be rotated.

translateCycle

public static void translateCycle(LineWA[] outline,
                                  int dx,
                                  int dy)
Moves the given cycle by dx and dy.
Parameters:
outline - The cycle to be moved given as a LineWA array.
dx - How far along the x-axis the cycle should be moved.
dy - How far along the y-axis the cycle should be moved.