diva.sketch.parser2d
Class AbstractRule

java.lang.Object
  extended by diva.sketch.parser2d.AbstractRule
All Implemented Interfaces:
Rule

public abstract class AbstractRule
extends Object
implements Rule

A parse rule implementation that matches the RHS of a production and generates the LHS. Subclasses fill in the match() method to impose the constraints of the rule.

Version:
$Revision: 1.9 $
Author:
Michael Shilman (michaels@eecs.berkeley.edu)

Field Summary
static int CENTER
          The center direction constant.
static int EAST
          The east direction constant.
static double NO_MAX
           
static double NO_MIN
           
static int NORTH
          The north direction constant.
static int NORTH_EAST
          The north-east direction constant.
static int NORTH_WEST
          The north-west direction constant.
static int SOUTH
          The south direction constant.
static int SOUTH_EAST
          The south-east direction constant.
static int SOUTH_WEST
          The south-west direction constant.
static int WEST
          The west direction constant.
 
Constructor Summary
AbstractRule(String lhsType, String rhsNames, String rhsTypes)
          A utility constructor which simply takes strings with single words separated by whitespace, separates these strings into arrays, and calls the standard array constructor.
AbstractRule(Type lhsType, String[] rhsNames, Type[] rhsTypes)
          Construct a new basic rule with the given LHS and RHS structure.
 
Method Summary
protected static double angle(SceneElement from, int fromSite, SceneElement to, int toSite)
          Return the angle between the constructor-specified sites on r1 and r2, respectively.
static double areaRatio(SceneElement num, SceneElement denom)
          Calculate the ratio of areas with the constructor-specified rectangle as the numerator for the calculation.
static double calcProb(List children)
          Return a probability calculation of an aggregate based on the probabilities of the children.
protected static double distance(SceneElement from, int fromSite, SceneElement to, int toSite)
          Return the distance between the constructor-specified sites on r1 and r2, respectively.
 Type getLHSType()
          Return the LHS type of the rule.
 String[] getRHSNames()
          Return the RHS names of the rule.
 Type[] getRHSTypes()
          Return the RHS types of the rule.
static double heightRatio(SceneElement num, SceneElement denom)
          Calculate the height ratio of the bounding boxes of the two given scene elements.
abstract  CompositeElement match(CompositeElement[] rhs, Scene db)
          Match the given scene elements and return a resulting element, or return null if there is no match.
static double overlap(SceneElement which, SceneElement other)
          Calculate the ratio of the area of the intersection of the bounding boxes of the two given scene elements to the area of the bounding box of the "which" argument.
static double siteX(SceneElement e, int site)
          Return the X coordinate of the given site for the given rectangle.
static double siteY(SceneElement e, int site)
          Return the Y coordinate of the given site for the given rectangle.
static double widthRatio(SceneElement num, SceneElement denom)
          Calculate the width ratio of the bounding boxes of the two given scene elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_MIN

public static final double NO_MIN
See Also:
Constant Field Values

NO_MAX

public static final double NO_MAX
See Also:
Constant Field Values

NORTH_EAST

public static final int NORTH_EAST
The north-east direction constant.

See Also:
Constant Field Values

NORTH

public static final int NORTH
The north direction constant.

See Also:
Constant Field Values

NORTH_WEST

public static final int NORTH_WEST
The north-west direction constant.

See Also:
Constant Field Values

WEST

public static final int WEST
The west direction constant.

See Also:
Constant Field Values

SOUTH_WEST

public static final int SOUTH_WEST
The south-west direction constant.

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
The south direction constant.

See Also:
Constant Field Values

SOUTH_EAST

public static final int SOUTH_EAST
The south-east direction constant.

See Also:
Constant Field Values

EAST

public static final int EAST
The east direction constant.

See Also:
Constant Field Values

CENTER

public static final int CENTER
The center direction constant.

See Also:
Constant Field Values
Constructor Detail

AbstractRule

public AbstractRule(String lhsType,
                    String rhsNames,
                    String rhsTypes)
A utility constructor which simply takes strings with single words separated by whitespace, separates these strings into arrays, and calls the standard array constructor.


AbstractRule

public AbstractRule(Type lhsType,
                    String[] rhsNames,
                    Type[] rhsTypes)
Construct a new basic rule with the given LHS and RHS structure. The RHS consists of an array of types to match, and an array of names to use if a match occurs.

Method Detail

getLHSType

public Type getLHSType()
Return the LHS type of the rule.

Specified by:
getLHSType in interface Rule

getRHSTypes

public Type[] getRHSTypes()
Return the RHS types of the rule.

Specified by:
getRHSTypes in interface Rule

getRHSNames

public String[] getRHSNames()
Return the RHS names of the rule.

Specified by:
getRHSNames in interface Rule

match

public abstract CompositeElement match(CompositeElement[] rhs,
                                       Scene db)
Match the given scene elements and return a resulting element, or return null if there is no match.

Specified by:
match in interface Rule

siteX

public static final double siteX(SceneElement e,
                                 int site)
Return the X coordinate of the given site for the given rectangle.


siteY

public static final double siteY(SceneElement e,
                                 int site)
Return the Y coordinate of the given site for the given rectangle.


angle

protected static final double angle(SceneElement from,
                                    int fromSite,
                                    SceneElement to,
                                    int toSite)
Return the angle between the constructor-specified sites on r1 and r2, respectively. The answer is given in degrees between 0 and 360.


areaRatio

public static final double areaRatio(SceneElement num,
                                     SceneElement denom)
Calculate the ratio of areas with the constructor-specified rectangle as the numerator for the calculation.


distance

protected static final double distance(SceneElement from,
                                       int fromSite,
                                       SceneElement to,
                                       int toSite)
Return the distance between the constructor-specified sites on r1 and r2, respectively.


heightRatio

public static final double heightRatio(SceneElement num,
                                       SceneElement denom)
Calculate the height ratio of the bounding boxes of the two given scene elements.


widthRatio

public static final double widthRatio(SceneElement num,
                                      SceneElement denom)
Calculate the width ratio of the bounding boxes of the two given scene elements.


overlap

public static final double overlap(SceneElement which,
                                   SceneElement other)
Calculate the ratio of the area of the intersection of the bounding boxes of the two given scene elements to the area of the bounding box of the "which" argument.


calcProb

public static final double calcProb(List children)
Return a probability calculation of an aggregate based on the probabilities of the children.



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.