Search this API

y.view
Class BridgeCalculator

java.lang.Object
  extended by y.view.BridgeCalculator

public class BridgeCalculator
extends java.lang.Object

Calculates and inserts "bridges" (also called "gaps" or "jumps") into PathIterators. Bridges are inserted when two (or more) segments cross, which can mean both segments of different paths or segments of one path.

Several different styles of bridges are supported: gaps, rectangular, trapezoidal, and round (using arcs). These bridge styles can also be scaled. Additionally, the orientation of bridges inserted into a PathIterator can be configured using a variety of schemes.
The calculation of the crossings can be determined using different crossing modes. This can be used for one-pass or two-pass calculation (see EdgeRealizer.registerObstacles(BridgeCalculator)).

See Also:
setCrossingMode(short), setCrossingStyle(short), setOrientationStyle(short), DefaultGraph2DRenderer.setBridgeCalculator(BridgeCalculator)
 

Field Summary
static short CROSSING_MODE_HORIZONTAL_CROSSES_VERTICAL
          Crossing mode constant.
static short CROSSING_MODE_ORDER_INDUCED
          Crossing mode constant.
static short CROSSING_MODE_VERTICAL_CROSSES_HORIZONTAL
          Crossing mode constant.
static short CROSSING_STYLE_ARC
          Crossing style constant.
static short CROSSING_STYLE_ARC_SCALED
          Crossing style constant.
static short CROSSING_STYLE_CUSTOM
          Crossing style constant.
static short CROSSING_STYLE_GAP
          Crossing style constant.
static short CROSSING_STYLE_SQUARE
          Crossing style constant.
static short CROSSING_STYLE_SQUARE_SCALED
          Crossing style constant.
static short CROSSING_STYLE_TWO_SIDES
          Crossing style constant.
static short CROSSING_STYLE_TWO_SIDES_SCALED
          Crossing style constant.
static short ORIENTATION_STYLE_DOWN
          Orientation style constant.
static short ORIENTATION_STYLE_FLOW_LEFT
          Orientation style constant.
static short ORIENTATION_STYLE_FLOW_RIGHT
          Orientation style constant.
static short ORIENTATION_STYLE_LEFT
          Orientation style constant.
static short ORIENTATION_STYLE_NEGATIVE
          Orientation style constant.
static short ORIENTATION_STYLE_POSITIVE
          Orientation style constant.
static short ORIENTATION_STYLE_RIGHT
          Orientation style constant.
static short ORIENTATION_STYLE_UP
          Orientation style constant.
 
Constructor Summary
BridgeCalculator()
          Creates a new BridgeCalculator instance using the default size for the storage of segments.
BridgeCalculator(int size)
          Creates a new BridgeCalculator instance with given initial size for the storage of segments.
 
Method Summary
 double getBridgeHeight()
          Returns the default height for a bridge.
 double getBridgeWidth()
          Returns the default width for a bridge.
 short getCrossingMode()
          Returns the mode that is responsible for determining crossings in the drawing.
 short getCrossingStyle()
          Returns the current default crossing drawing style.
 short getOrientationStyle()
          Returns the current default orientation style.
 java.awt.geom.PathIterator insertBridges(java.awt.geom.PathIterator pi)
          Takes the given PathIterator, calculates and inserts bridges into those segments that intersect with other segments (from either this or another path), and returns a new PathIterator instance with bridges inserted.
protected  void insertCustomBridge(MutableGeneralPath mgp, MutableGeneralPath.Segment beforeSegment, double up, double x1, double y1, double down, double x2, double y2)
          Callback method that is called during insertBridges(java.awt.geom.PathIterator) to allow for custom modifications of the MutableGeneralPath and optionally recording of the bridges.
 void registerObstacleLine(double x1, double y1, double x2, double y2)
          Registers a line as an obstacle for subsequent insertBridges(java.awt.geom.PathIterator) calls.
 void registerObstacles(java.awt.geom.PathIterator pi)
          Iterates over the given Path and inserts all straight-line segments as obstacles via registerObstacleLine(double, double, double, double)
 void reset()
          Resets the internal segment storage.
 void setBridgeHeight(double bridgeHeight)
          Sets the default height for a bridge.
 void setBridgeWidth(double bridgeWidth)
          Sets the default width for a bridge.
 void setCrossingMode(short crossingMode)
          Sets the mode that is used for calculation of the crossings.
 void setCrossingStyle(short crossingStyle)
          Sets the current default crossing drawing style.
 void setOrientationStyle(short orientationStyle)
          Sets the current default orientation style.
 void setScope(double minX, double minY, double maxX, double maxY)
          Limits the scope of the calculation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CROSSING_STYLE_GAP

public static final short CROSSING_STYLE_GAP
Crossing style constant. This style will draw a gap for each edge crossing.

See Also:
Constant Field Values

CROSSING_STYLE_ARC

public static final short CROSSING_STYLE_ARC
Crossing style constant. This style will draw two pieces of an arc connected by a line for each edge crossing.

See Also:
Constant Field Values

CROSSING_STYLE_SQUARE

public static final short CROSSING_STYLE_SQUARE
Crossing style constant. This style will draw a rectangular bridge for each edge crossing.

See Also:
Constant Field Values

CROSSING_STYLE_TWO_SIDES

public static final short CROSSING_STYLE_TWO_SIDES
Crossing style constant. This style will draw trapezoidal bridge for each edge crossing.

See Also:
Constant Field Values

CROSSING_STYLE_ARC_SCALED

public static final short CROSSING_STYLE_ARC_SCALED
Crossing style constant. This style will draw a scaled arc for each edge crossing.

See Also:
Constant Field Values

CROSSING_STYLE_SQUARE_SCALED

public static final short CROSSING_STYLE_SQUARE_SCALED
Crossing style constant. This style will draw a scaled rectangle with varying height for each edge crossing.

See Also:
Constant Field Values

CROSSING_STYLE_TWO_SIDES_SCALED

public static final short CROSSING_STYLE_TWO_SIDES_SCALED
Crossing style constant. This style will draw a scaled trapezoidal bridge with varying height for each edge crossing.

See Also:
Constant Field Values

CROSSING_STYLE_CUSTOM

public static final short CROSSING_STYLE_CUSTOM
Crossing style constant. This style will result in insertCustomBridge(MutableGeneralPath,y.view.MutableGeneralPath.Segment,double,double,double,double,double,double) being called for each bridge to insert into the path.

See Also:
Constant Field Values

ORIENTATION_STYLE_UP

public static final short ORIENTATION_STYLE_UP
Orientation style constant. All bridges will be oriented upwards.

See Also:
Constant Field Values

ORIENTATION_STYLE_DOWN

public static final short ORIENTATION_STYLE_DOWN
Orientation style constant. All bridges will be oriented downwards.

See Also:
Constant Field Values

ORIENTATION_STYLE_LEFT

public static final short ORIENTATION_STYLE_LEFT
Orientation style constant. All bridges will be oriented leftwards.

See Also:
Constant Field Values

ORIENTATION_STYLE_RIGHT

public static final short ORIENTATION_STYLE_RIGHT
Orientation style constant. All bridges will be oriented rightwards.

See Also:
Constant Field Values

ORIENTATION_STYLE_POSITIVE

public static final short ORIENTATION_STYLE_POSITIVE
Orientation style constant. All bridges will be oriented in the direction of the positive axes.

See Also:
Constant Field Values

ORIENTATION_STYLE_NEGATIVE

public static final short ORIENTATION_STYLE_NEGATIVE
Orientation style constant. All bridges will be oriented in the direction of the negative axes.

See Also:
Constant Field Values

ORIENTATION_STYLE_FLOW_LEFT

public static final short ORIENTATION_STYLE_FLOW_LEFT
Orientation style constant. All bridges will be oriented leftwards in the flow of the edge.

See Also:
Constant Field Values

ORIENTATION_STYLE_FLOW_RIGHT

public static final short ORIENTATION_STYLE_FLOW_RIGHT
Orientation style constant. All bridges will be oriented rightwards in the flow of the edge.

See Also:
Constant Field Values

CROSSING_MODE_ORDER_INDUCED

public static final short CROSSING_MODE_ORDER_INDUCED
Crossing mode constant. The crossings are determined in one pass. Each segment painted will only produce crossings with segments painted before this segment.

See Also:
Constant Field Values

CROSSING_MODE_HORIZONTAL_CROSSES_VERTICAL

public static final short CROSSING_MODE_HORIZONTAL_CROSSES_VERTICAL
Crossing mode constant. The crossings are determined in two passes. Each horizontal segment painted will be tested against all vertical segments collected during the first pass. This will only produce crossings on horizontal segments.

See Also:
Constant Field Values

CROSSING_MODE_VERTICAL_CROSSES_HORIZONTAL

public static final short CROSSING_MODE_VERTICAL_CROSSES_HORIZONTAL
Crossing mode constant. The crossings are determined in two passes. Each vertical segment painted will be tested against all horizontal segments collected during the first pass. This will only produce crossings on vertical segments.

See Also:
Constant Field Values
Constructor Detail

BridgeCalculator

public BridgeCalculator(int size)
Creates a new BridgeCalculator instance with given initial size for the storage of segments.

Crossing style CROSSING_STYLE_ARC and orientation style ORIENTATION_STYLE_POSITIVE are used as the default settings.


BridgeCalculator

public BridgeCalculator()
Creates a new BridgeCalculator instance using the default size for the storage of segments.

Crossing style CROSSING_STYLE_ARC and orientation style ORIENTATION_STYLE_POSITIVE are used as the default settings.

Method Detail

reset

public void reset()
Resets the internal segment storage.


getCrossingMode

public short getCrossingMode()
Returns the mode that is responsible for determining crossings in the drawing. The default is CROSSING_MODE_ORDER_INDUCED

Returns:
the current mode - one of CROSSING_MODE_ORDER_INDUCED, CROSSING_MODE_HORIZONTAL_CROSSES_VERTICAL, or CROSSING_MODE_VERTICAL_CROSSES_HORIZONTAL.
See Also:
setCrossingMode(short)

setCrossingMode

public void setCrossingMode(short crossingMode)
Sets the mode that is used for calculation of the crossings. There are different approaches for determining the crossings: One pass crossing calculation: Edges are rendered in one pass one after the other and each segment of an edge is an obstacle that produces a crossing with segments rendered after this one. (CROSSING_MODE_ORDER_INDUCED)
Two-pass crossing calculation: Edges are queried for their segments in the first pass and during the second pass all edge paths are calculated taking into account all of the segments of the first pass. This way it becomes possible for each pair of edge paths to be rendered both "on top and below" each other. For the two pass rendering there are two possible modes, both of which are especially useful in scenarios, where this is a dominant orthogonal edge routing:

Parameters:
crossingMode - one of CROSSING_MODE_ORDER_INDUCED, CROSSING_MODE_HORIZONTAL_CROSSES_VERTICAL, or CROSSING_MODE_VERTICAL_CROSSES_HORIZONTAL.

getOrientationStyle

public short getOrientationStyle()
Returns the current default orientation style.

Returns:
one of ORIENTATION_STYLE_UP, ORIENTATION_STYLE_DOWN, ORIENTATION_STYLE_FLOW_LEFT, ORIENTATION_STYLE_FLOW_RIGHT, ORIENTATION_STYLE_LEFT, ORIENTATION_STYLE_RIGHT, ORIENTATION_STYLE_POSITIVE, ORIENTATION_STYLE_NEGATIVE.

setOrientationStyle

public void setOrientationStyle(short orientationStyle)
Sets the current default orientation style.

Parameters:
orientationStyle - one of ORIENTATION_STYLE_UP, ORIENTATION_STYLE_DOWN, ORIENTATION_STYLE_FLOW_LEFT, ORIENTATION_STYLE_FLOW_RIGHT, ORIENTATION_STYLE_LEFT, ORIENTATION_STYLE_RIGHT, ORIENTATION_STYLE_POSITIVE, ORIENTATION_STYLE_NEGATIVE.

setCrossingStyle

public void setCrossingStyle(short crossingStyle)
Sets the current default crossing drawing style.

Parameters:
crossingStyle - one of CROSSING_STYLE_ARC, CROSSING_STYLE_ARC_SCALED, CROSSING_STYLE_GAP, CROSSING_STYLE_SQUARE, CROSSING_STYLE_SQUARE_SCALED, CROSSING_STYLE_TWO_SIDES, CROSSING_STYLE_TWO_SIDES_SCALED, CROSSING_STYLE_CUSTOM.

getCrossingStyle

public short getCrossingStyle()
Returns the current default crossing drawing style.

Returns:
one of CROSSING_STYLE_ARC, CROSSING_STYLE_ARC_SCALED, CROSSING_STYLE_GAP, CROSSING_STYLE_SQUARE, CROSSING_STYLE_SQUARE_SCALED, CROSSING_STYLE_TWO_SIDES, CROSSING_STYLE_TWO_SIDES_SCALED, CROSSING_STYLE_CUSTOM.

getBridgeWidth

public double getBridgeWidth()
Returns the default width for a bridge.

Returns:
the length of a bridge

setBridgeWidth

public void setBridgeWidth(double bridgeWidth)
Sets the default width for a bridge.

Parameters:
bridgeWidth - the length of a bridge

getBridgeHeight

public double getBridgeHeight()
Returns the default height for a bridge.

Returns:
the height of a bridge/jump

setBridgeHeight

public void setBridgeHeight(double bridgeHeight)
Sets the default height for a bridge.

Parameters:
bridgeHeight - the height of a bridge/jump

setScope

public void setScope(double minX,
                     double minY,
                     double maxX,
                     double maxY)
Limits the scope of the calculation. Segments that do not intersect with the current scope will be discarded during the calculation.


insertBridges

public java.awt.geom.PathIterator insertBridges(java.awt.geom.PathIterator pi)
Takes the given PathIterator, calculates and inserts bridges into those segments that intersect with other segments (from either this or another path), and returns a new PathIterator instance with bridges inserted.

Parameters:
pi - The PathIterator that should be processed.
Returns:
A new PathIterator that contains the bridges. This path iterator is only valid until the next call to this method.

registerObstacles

public void registerObstacles(java.awt.geom.PathIterator pi)
Iterates over the given Path and inserts all straight-line segments as obstacles via registerObstacleLine(double, double, double, double)

Parameters:
pi - the PathIterator that describes the path

registerObstacleLine

public void registerObstacleLine(double x1,
                                 double y1,
                                 double x2,
                                 double y2)
Registers a line as an obstacle for subsequent insertBridges(java.awt.geom.PathIterator) calls. The obstacle will not be registered if it does not intersect with the current scope.

Parameters:
x1 - the x coordinate of the first point of the line
y1 - the y coordinate of the first point of the line
x2 - the x coordinate of the second point of the line
y2 - the y coordinate of the second point of the line

insertCustomBridge

protected void insertCustomBridge(MutableGeneralPath mgp,
                                  MutableGeneralPath.Segment beforeSegment,
                                  double up,
                                  double x1,
                                  double y1,
                                  double down,
                                  double x2,
                                  double y2)
Callback method that is called during insertBridges(java.awt.geom.PathIterator) to allow for custom modifications of the MutableGeneralPath and optionally recording of the bridges. This method will be called if the crossing style is set to CROSSING_STYLE_CUSTOM. This implementation does nothing. The path stays unmodified.

Parameters:
mgp - the path to be modified
beforeSegment - the segment (PathIterator.SEG_MOVETO) that should be modified
up - the distance from the start of the segment to the first point
x1 - the x coordinate of the beginning of the bridge
y1 - the y coordinate of the beginning of the bridge
down - the distance from the start of the segment to the second point
x2 - the x coordinate of the end of the bridge
y2 - the y coordinate of the end of the bridge

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.