Search this API

y.layout.router
Class ChannelRouter

java.lang.Object
  extended by y.layout.router.ChannelRouter

public class ChannelRouter
extends java.lang.Object

This routing algorithm applies orthogonal routes to the edges within a channel.

Each edge that should be routed has to be specified by a unique key (e.g., the edge itself) as well as two points that represent the two endpoints of this edge, see addSegment(Object, YPoint, YPoint). The orthogonal route of each edge consists of three segments. More precisely, for an edge with source point (sx,sy), target point (tx,ty) and vertical channel orientation, the algorithm calculates the x-coordinate of the vertical middle segment (called mx) that can be obtained with method getCoord(Object) after routing the edges. Hence, the actual route consists of points (sx,sy), (mx,sy), (mx,ty) and (tx,ty). Analogously, if the channel orientation is horizontal, the route consists of the points (sx,sy), (sx,my), (tx,my) and (tx,ty).

Besides the orientation, each channel is restricted by a smallest and largest assignable coordinate. If, for example, the orientation is vertical, the calculated x-coordinate of the middle segment lies between these two values. Both values can be changed by means of method setChannel(double, double, byte).

All edges assigned to the same coordinate are said to lie in the same sub-channel. In general, the routing algorithm tries to assign coordinates such the number of sub-channels as well as the number of edge crossings is small.

 
This class doesn't change the initial routes of the edges - it only calculates coordinates that can be retrieved with method getCoord(Object) or getSubChannelRank(Object).
 

Field Summary
static byte ROUTE_HORIZONTAL
          Channel orientation specifier for routing edges horizontally.
static byte ROUTE_VERTICAL
          Channel orientation specifier for routing edges vertically.
 
Constructor Summary
ChannelRouter(double min, double max)
          Creates a new instance of ChannelRouter for a channel with horizontal orientation.
ChannelRouter(double min, double max, byte orientation)
          Creates a new instance of ChannelRouter.
 
Method Summary
 void addGroupSegment(java.lang.Object key, java.lang.Object groupId, YPoint p1, YPoint p2)
          Adds an edge object that belongs to an edge group to the set of elements that should be routed within the channel.
 void addSegment(java.lang.Object key, YPoint p1, YPoint p2)
          Adds an edge object with endpoint p1 and p2 to the set of elements that should be routed within the channel.
 boolean containsGroupKey(java.lang.Object groupId)
          Returns whether the given id has already been registered as a group id.
 boolean containsKey(java.lang.Object key)
          Returns whether the given key has already been registered.
 double getCoord(java.lang.Object key)
          Returns the calculated channel coordinate for an added edge object.
 double getEpsilon()
          Returns the current epsilon value.
 int getGroupSubChannelRank(java.lang.Object groupId)
          Returns the sub-channel rank for the specified edge group within the channel.
 int getSubChannelCount()
          Returns the number of sub-channels (i.e., different coordinates assigned to the edge objects) within this channel.
 int getSubChannelRank(java.lang.Object key)
          Returns the sub-channel rank of the specified edge object within the channel.
 boolean isEpsilonChannelIgnored()
          Returns whether or not middle segments with lengths smaller than epsilon are ignored.
 void route()
          Routes all added edge objects within the specified channel.
 java.util.Iterator segmentKeys()
          Returns an iterator over all added keys of edge objects.
 void setChannel(double min, double max, byte orientation)
          Specifies the channel bounds and orientation.
 void setEpsilon(double epsilon)
          Specifies the current epsilon value.
 void setEpsilonChannelIgnored(boolean ignore)
          Specifies whether or not middle segments with lengths smaller than epsilon should be ignored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROUTE_VERTICAL

public static final byte ROUTE_VERTICAL
Channel orientation specifier for routing edges vertically.

More precisely, the algorithm calculates the x-coordinates of the vertical middle segments of the added edges.

See Also:
Constant Field Values

ROUTE_HORIZONTAL

public static final byte ROUTE_HORIZONTAL
Channel orientation specifier for routing edges horizontally.

More precisely, the algorithm calculates the y-coordinates of the horizontal middle segments of the added edges.

See Also:
Constant Field Values
Constructor Detail

ChannelRouter

public ChannelRouter(double min,
                     double max,
                     byte orientation)
Creates a new instance of ChannelRouter.

Parameters:
min - the smallest assignable coordinate within the channel
max - the largest assignable coordinate within the channel
orientation - the orientation of the channel

ChannelRouter

public ChannelRouter(double min,
                     double max)
Creates a new instance of ChannelRouter for a channel with horizontal orientation.

Parameters:
min - the smallest assignable coordinate within the channel
max - the largest assignable coordinate within the channel
Method Detail

setChannel

public void setChannel(double min,
                       double max,
                       byte orientation)
Specifies the channel bounds and orientation.

Calling this method removes all previously added elements.

Parameters:
min - the smallest assignable coordinate within the channel
max - the largest assignable coordinate within the channel
orientation - the orientation of the channel
See Also:
addSegment(Object, YPoint, YPoint)

addSegment

public void addSegment(java.lang.Object key,
                       YPoint p1,
                       YPoint p2)
Adds an edge object with endpoint p1 and p2 to the set of elements that should be routed within the channel.

Parameters:
key - the unique id of the edge
p1 - the first endpoint of the edge
p2 - the second endpoint of the edge

addGroupSegment

public void addGroupSegment(java.lang.Object key,
                            java.lang.Object groupId,
                            YPoint p1,
                            YPoint p2)
Adds an edge object that belongs to an edge group to the set of elements that should be routed within the channel. Edges having the same group id will be placed in the same sub-channel (i.e., the same coordinate).

Parameters:
key - the unique id of the edge
groupId - the id of the edge group
p1 - the first endpoint of the edge
p2 - the second endpoint of the edge

segmentKeys

public java.util.Iterator segmentKeys()
Returns an iterator over all added keys of edge objects. It also contains keys for grouped edges added with addGroupSegment(Object, Object, YPoint, YPoint).

Returns:
an iterator over all added keys of edge objects

containsKey

public boolean containsKey(java.lang.Object key)
Returns whether the given key has already been registered.

Parameters:
key - the key used during adding
Returns:
true if the key has already been registered, false otherwise

containsGroupKey

public boolean containsGroupKey(java.lang.Object groupId)
Returns whether the given id has already been registered as a group id.

Parameters:
groupId - the group id used during adding
Returns:
true if the key has already been registered, false otherwise

route

public void route()
Routes all added edge objects within the specified channel.

The resulting sub-channels can then be queried using method getSubChannelRank(Object), while the exact coordinates can be queried with method getCoord(Object).

See Also:
addSegment(Object, YPoint, YPoint), addGroupSegment(Object, Object, YPoint, YPoint)

getCoord

public double getCoord(java.lang.Object key)
Returns the calculated channel coordinate for an added edge object.

Parameters:
key - the key used during adding the edge object
Returns:
the channel coordinate of the associated edge object
See Also:
addSegment(Object, YPoint, YPoint)

getSubChannelCount

public int getSubChannelCount()
Returns the number of sub-channels (i.e., different coordinates assigned to the edge objects) within this channel.

A return value of 0 indicates that there are no sub-channels present.

Returns:
the number of sub-channels within this channel

getSubChannelRank

public int getSubChannelRank(java.lang.Object key)
Returns the sub-channel rank of the specified edge object within the channel.

 
The coordinate of an edge object increases with increasing sub-channel rank. Edge objects assigned to the same sub-channel rank are placed on the same coordinate.
Parameters:
key - the key used during adding the edge object
Returns:
the sub-channel rank of the given edge object
See Also:
getSubChannelCount(), addSegment(Object, YPoint, YPoint)

getGroupSubChannelRank

public int getGroupSubChannelRank(java.lang.Object groupId)
Returns the sub-channel rank for the specified edge group within the channel.

Parameters:
groupId - the group id used during adding an edge object
Returns:
the sub-channel rank of the edge group
See Also:
getSubChannelCount(), addGroupSegment(Object, Object, YPoint, YPoint)

isEpsilonChannelIgnored

public boolean isEpsilonChannelIgnored()
Returns whether or not middle segments with lengths smaller than epsilon are ignored.

Returns:
true if middle segments with length smaller than epsilon are ignored, false otherwise
See Also:
setEpsilon(double), setEpsilonChannelIgnored(boolean)

setEpsilonChannelIgnored

public void setEpsilonChannelIgnored(boolean ignore)
Specifies whether or not middle segments with lengths smaller than epsilon should be ignored.

Default Value:
The default value is true.
Parameters:
ignore - true if middle segments with length smaller than epsilon should be ignored, false otherwise
See Also:
setEpsilon(double)

getEpsilon

public double getEpsilon()
Returns the current epsilon value.

If option setEpsilonChannelIgnored(boolean) is enabled, middle segments with length smaller than this value are ignored.

Returns:
the current epsilon value
See Also:
setEpsilonChannelIgnored(boolean), setEpsilon(double)

setEpsilon

public void setEpsilon(double epsilon)
Specifies the current epsilon value.

If option setEpsilonChannelIgnored(boolean) is enabled, middle segments with length smaller than this value are ignored.

Default Value:
The default value is 0.5.
Parameters:
epsilon - the epsilon value
See Also:
setEpsilonChannelIgnored(boolean)

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