shady.common.multi
Class MultiEnvironment

java.lang.Object
  extended by shady.common.Environment
      extended by shady.common.multi.MultiEnvironment
All Implemented Interfaces:
java.io.Serializable

public class MultiEnvironment
extends Environment

An Environment for MultiShady.

A MultiEnvironment is a set of MultiSegments.

Copyright (C) 2006 Marsette A. Vona, III

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Author:
Marsette (Marty) A. Vona, III
See Also:
Serialized Form

Field Summary
static double CONSISTENCY_CHECK_ORIENTATION_SLOP
          Orientation tolerance for place consistency check in degrees.
static double CONSISTENCY_CHECK_TRANSLATION_SLOP
          Translation tolerance for place consistency check in meters.
private static java.lang.String cvsid
          CVS id.
static double DEFAULT_BASE_WIDTH
          The width of the grounded base segment in the default environment.
protected  boolean deferPlace
          Whether place() is currently deferred.
protected  boolean needsPlace
          Whether place() needs to be called after deferPlace is turned off.
 
Fields inherited from class shady.common.Environment
boundsDirty, centerX, centerY, DEFAULT_BAR_WIDTH, DEFAULT_COLUMN_WIDTH, DEFAULT_MAX_LOWER_ROW_HEIGHT, DEFAULT_MIN_LOWER_ROW_HEIGHT, DEFAULT_NUM_PANE_COLUMNS, DEFAULT_UPPER_ROW_HEIGHT, height, listeners, lockBounds, maxX, maxY, minX, minY, segments, width
 
Constructor Summary
MultiEnvironment()
          Makes a default environment (see makeDefaultEnvironment()).
MultiEnvironment(MultiSegment[] segment)
          Make a new MulitEnvironment.
 
Method Summary
 int addSegment(double startX, double startY, double endX, double endY)
          Covers addSegment(double, double, double, double, boolean), always adds a grounded segment.
 int addSegment(double startX, double startY, double endX, double endY, boolean grounded)
          Add a new segment at the end of the list.
protected  boolean checkPrune(MultiSegment child, MemberShadyCommonAPI member, ShadyPose pose)
          Check if child needs to be placed.
 boolean isDeferPlace()
          Check whether place is currently deferred.
protected  void makeDefaultEnvironment()
          Makes a default environment with a single horizontal grounded base segment of widthDEFAULT_BASE_WIDTH centered at the origin.
 void moveSegment(int index, double startX, double startY, double endX, double endY)
          Move the Segment at index.
 int place()
          Try to place all non-grounded segments.
protected  boolean placeChild(MultiSegment child, Point.OnSegment parentPoint, Point.OnSegment childPoint, double parentToChildOrientation, double childOrientation, double l)
          Place the segment child.
protected  int placeFrom(MultiSegment root, ShadyPose pose)
          Recursively place unplaced segments in a DFS starting from root.
protected  int placeImpl()
          Implementation of place().
 void setDeferPlace(boolean deferPlace)
          Whether to defer all calls to place().
 
Methods inherited from class shady.common.Environment
addListener, clearSegments, enumerateSegments, fireEnvironmentChanged, getCenterX, getCenterY, getHeight, getMaxX, getMaxY, getMinX, getMinY, getSegment, getWidth, isEmpty, makeDefaultEnvironment, numSegments, pick, pick, pick, recomputeBounds, removeLastSegment, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cvsid

private static final java.lang.String cvsid

CVS id.

See Also:
Constant Field Values

CONSISTENCY_CHECK_ORIENTATION_SLOP

public static final double CONSISTENCY_CHECK_ORIENTATION_SLOP

Orientation tolerance for place consistency check in degrees.

See Also:
Constant Field Values

CONSISTENCY_CHECK_TRANSLATION_SLOP

public static final double CONSISTENCY_CHECK_TRANSLATION_SLOP

Translation tolerance for place consistency check in meters.

See Also:
Constant Field Values

DEFAULT_BASE_WIDTH

public static final double DEFAULT_BASE_WIDTH

The width of the grounded base segment in the default environment.

See Also:
Constant Field Values

needsPlace

protected boolean needsPlace

Whether place() needs to be called after deferPlace is turned off.


deferPlace

protected boolean deferPlace

Whether place() is currently deferred.

Constructor Detail

MultiEnvironment

public MultiEnvironment()

Makes a default environment (see makeDefaultEnvironment()).


MultiEnvironment

public MultiEnvironment(MultiSegment[] segment)

Make a new MulitEnvironment.

Parameters:
segment - the set of MultiSegments, not null, a copy is made, the connected Shady sets (MultiSegment.members) are not copied
Method Detail

addSegment

public int addSegment(double startX,
                      double startY,
                      double endX,
                      double endY)

Covers addSegment(double, double, double, double, boolean), always adds a grounded segment.

Overrides:
addSegment in class Environment
Parameters:
startX - the start X coord of the segment in meters
startY - the start Y coord of the segment in meters
endX - the end X coord of the segment in meters
endY - the end Y coord of the segment in meters
Returns:
the new number of segments

addSegment

public int addSegment(double startX,
                      double startY,
                      double endX,
                      double endY,
                      boolean grounded)

Add a new segment at the end of the list.

Same as Environment.addSegment(double, double, double, double) but includes groundedspecification.

Parameters:
grounded - whether the new segment is grounded

moveSegment

public void moveSegment(int index,
                        double startX,
                        double startY,
                        double endX,
                        double endY)

Move the Segment at index.

A EnvironmentListener.environmentChanged(shady.common.Environment) event will be fired to all registered listeners.

Extends super impl to place().

Overrides:
moveSegment in class Environment
Parameters:
index - the zero-based index of the segment to move
startX - the new start X coord of the segment in meters
startY - the new start Y coord of the segment in meters
endX - the new end X coord of the segment in meters
endY - the new end Y coord of the segment in meters

setDeferPlace

public void setDeferPlace(boolean deferPlace)

Whether to defer all calls to place().

Has no effect if request is same as current defer state.

If defer is turned off then place() will be called immediately iff it was called at all while defer was on.

Parameters:
deferPlace - whether to defer all calls to place().

isDeferPlace

public boolean isDeferPlace()

Check whether place is currently deferred.

See setDeferPlace(boolean).

Returns:
true iff place is currently deferred

place

public int place()

Try to place all non-grounded segments.

The implementation is currently a depth-first traversal of the connectivity graph starting from all grounded segments. First all non-grounded segments are marked not MultiSegment.placed. Then segments adjacent to placed or grounded segments in the connectivity graph are recursively placed. This continues until no unplaced segments adj placed or grounded segments remain. Note that unplaced segments will still remain iff the connectivity graph contains any connected components with zero grounded segments.

Overconstrained non-grounded segments are placed only by the first path found in the connectivity graph.

Calls to this method should be synchronized wrt modifications to the topology of the connectivity graph and the state of all members. By convention, the MultiShady object is used for this synchronization.

It is not normally necessary to call this method manually. It is called by implementations of MemberShadyCommonAPI after rotations or gripper opens or closes, and by moveSegment(int, double, double, double, double).

It is possible to defer the place algorithm, see setDeferPlace(boolean).

Returns:
the number of segments that remain unplaced (or 0 if place is currently deferred)

placeImpl

protected int placeImpl()

Implementation of place().

Synchronized.


placeFrom

protected int placeFrom(MultiSegment root,
                        ShadyPose pose)

Recursively place unplaced segments in a DFS starting from root.

See place().

Parameters:
root - the starting segment, assumed MultiSegment.grounded or MultiSegment.placed
pose - a ShadyPose to use as scratch
Returns:
the number of segments that were placed

checkPrune

protected boolean checkPrune(MultiSegment child,
                             MemberShadyCommonAPI member,
                             ShadyPose pose)

Check if child needs to be placed.

Parameters:
child - the segment to check
member - the connecting member shady, to be used for consistency check if necessary
pose - the pose of member
Returns:
true iff child does not need to be placed

placeChild

protected boolean placeChild(MultiSegment child,
                             Point.OnSegment parentPoint,
                             Point.OnSegment childPoint,
                             double parentToChildOrientation,
                             double childOrientation,
                             double l)

Place the segment child.

Does not set child.placed.

Parameters:
child - the segment to place
parentPoint - the member attachment point on the parent segment
childPoint - the member attachment point on child
parentToChildOrientation - the absolute orientation of the member in degrees from parentPoint to childPoint
childOrientation - the absolute orientation in degrees of child
l - the center-to-center length of the connecting member in meters
Returns:
whether child was successfully placed

makeDefaultEnvironment

protected void makeDefaultEnvironment()

Makes a default environment with a single horizontal grounded base segment of widthDEFAULT_BASE_WIDTH centered at the origin.