GlobalNavigation
Class PolygonMap

java.lang.Object
  extended by GlobalNavigation.PolygonMap

public class PolygonMap
extends java.lang.Object

The 2D worldRect, PolygonObstacle obstacles, robotStart, and robotGoal that make-up the environment in which the robot will navigate.

You can either make an instance of this class and use it from within your own program (typical usage), or you can run this code as an indepedent process (see #main). The latter mode allows you to display the contents of a map file, but does not give programmatic access to those contents, and thus is useful mostly for displaying/debugging map files.

.

The format of the map file is as follows (all items are signed doubles in ASCII text format, all units are meters, and all separators are whitespace):

 robotStartX robotStartY
 robotGoalX robotGoalY
 worldX worldY worldWidth worldHeight
 obstacle0X0 obstacle0Y0 obstacle0X1 obstacle0Y1 ...
 ...
 
The first three lines initialize the corresponding instance fields robotStart, robotGoal, and worldRect, respectively. Each obstacle line gives the coordinates of the obstacle's vertices in CCW order. There may be zero obstacles.


Field Summary
static java.lang.String APPNAME
          Name to use when run as an application.
protected  java.util.LinkedList<PolygonObstacle> obstacles
          The obstacles (does not include the world boundary).
protected  java.awt.geom.Point2D.Double robotGoal
          The goal point for the robot origin, read in from the map file (m).
protected  java.awt.geom.Point2D.Double robotStart
          The start point for the robot origin, read in from the map file (m).
protected  java.awt.geom.Rectangle2D.Double worldRect
          The location and size of the world boundary, read in from the map file (m).
 
Constructor Summary
PolygonMap()
          Create a new un-initialized polygon map.
PolygonMap(java.io.File mapFile)
          Create a new map, parsing mapFile.
PolygonMap(java.lang.String mapFile)
          Covers PolygonMap(File).
 
Method Summary
protected  void driverDisplayHook()
          Hook called after painting map objects in instanceMain(java.lang.String) to allow subclasses to display extra stuff.
protected  java.lang.String getAppName()
          Get the application name.
 GraphName getDefaultNodeName()
           
 java.util.List<PolygonObstacle> getObstacles()
          Get obstacles.
 java.awt.geom.Point2D.Double getRobotGoal()
          Get robotGoal.
 java.awt.geom.Point2D.Double getRobotStart()
          Get robotStart.
 java.awt.geom.Rectangle2D.Double getWorldRect()
          Get worldRect.
protected  void instanceMain(java.lang.String mapFile)
          Parses the specified map file, prints it out, and displays it in the GUI, if any.
 void onShutdown(Node node)
          Shutdown hook for ROS when called as stand-alone node
 void onShutdownComplete(Node node)
           
 void onStart(Node node)
          Entry hook for ROS when called as stand-alone node
protected  void parse(java.io.File mapFile)
          Parse mapFile.
protected  double parseDouble(java.io.BufferedReader br, java.lang.String name, int lineNumber)
          Parse a double.
protected  boolean parseExtra(java.io.BufferedReader br, int lineNumber)
          Hook called from parse(java.io.File) after the first four lines are parsed to allow subclasses to parse extra lines before the obstacles.
protected  PolygonObstacle parseObs(java.io.BufferedReader br, java.lang.String name, int lineNumber)
          Parse a PolygonObstacle.
protected  void parsePoint(java.awt.geom.Point2D.Double point, java.io.BufferedReader br, java.lang.String name, int lineNumber)
          Parse a Point2D.Double.
protected  void parseRect(java.awt.geom.Rectangle2D.Double rect, java.io.BufferedReader br, java.lang.String name, int lineNumber)
          Parse a Rectangle2D.Double.
 java.lang.String toString()
          Return a human-readable string representation of this map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

APPNAME

public static final java.lang.String APPNAME

Name to use when run as an application.

See Also:
Constant Field Values

robotStart

protected java.awt.geom.Point2D.Double robotStart

The start point for the robot origin, read in from the map file (m).


robotGoal

protected java.awt.geom.Point2D.Double robotGoal

The goal point for the robot origin, read in from the map file (m).


worldRect

protected java.awt.geom.Rectangle2D.Double worldRect

The location and size of the world boundary, read in from the map file (m).


obstacles

protected java.util.LinkedList<PolygonObstacle> obstacles

The obstacles (does not include the world boundary).

Constructor Detail

PolygonMap

public PolygonMap(java.io.File mapFile)
           throws java.io.IOException,
                  java.text.ParseException

Create a new map, parsing mapFile.

Parameters:
mapFile - the map file to parse, or null if none
Throws:
java.io.IOException
java.text.ParseException

PolygonMap

public PolygonMap(java.lang.String mapFile)
           throws java.io.IOException,
                  java.text.ParseException

Covers PolygonMap(File).

Throws:
java.io.IOException
java.text.ParseException

PolygonMap

public PolygonMap()

Create a new un-initialized polygon map.

You may populate it using the accessors below.

Method Detail

parseDouble

protected double parseDouble(java.io.BufferedReader br,
                             java.lang.String name,
                             int lineNumber)
                      throws java.io.IOException,
                             java.text.ParseException,
                             java.lang.NumberFormatException

Parse a double.

Parameters:
br - the double is expected to be on the next line of this reader
name - the name of the double
lineNumber - the line number of the double
Returns:
the parsed double
Throws:
java.io.IOException - if there was an I/O error
java.text.ParseException - if there was a format error
java.lang.NumberFormatException - if there was a format error

parsePoint

protected void parsePoint(java.awt.geom.Point2D.Double point,
                          java.io.BufferedReader br,
                          java.lang.String name,
                          int lineNumber)
                   throws java.io.IOException,
                          java.text.ParseException,
                          java.lang.NumberFormatException

Parse a Point2D.Double.

Parameters:
point - the returned point
br - the point is expected to be on the next line of this reader
name - the name of the point
lineNumber - the line number of the point
Throws:
java.io.IOException - if there was an I/O error
java.text.ParseException - if there was a format error
java.lang.NumberFormatException - if there was a format error

parseRect

protected void parseRect(java.awt.geom.Rectangle2D.Double rect,
                         java.io.BufferedReader br,
                         java.lang.String name,
                         int lineNumber)
                  throws java.io.IOException,
                         java.text.ParseException,
                         java.lang.NumberFormatException

Parse a Rectangle2D.Double.

Parameters:
rect - the returned rectangle
br - the rect is expected to be on the next line of this reader
name - the name of the rect
lineNumber - the line number of the rect
Throws:
java.io.IOException - if there was an I/O error
java.text.ParseException - if there was a format error
java.lang.NumberFormatException - if there was a format error

parseObs

protected PolygonObstacle parseObs(java.io.BufferedReader br,
                                   java.lang.String name,
                                   int lineNumber)
                            throws java.io.IOException,
                                   java.text.ParseException,
                                   java.lang.NumberFormatException

Parse a PolygonObstacle.

Parameters:
br - the polygon is expected to be on the next line of this reader
name - the name of the polygon
lineNumber - the line number of the polygon
Returns:
a new polygon containing the vertices on the line, or null if there was no line
Throws:
java.io.IOException - if there was an I/O error
java.text.ParseException - if there was a format error
java.lang.NumberFormatException - if there was a format error

parseExtra

protected boolean parseExtra(java.io.BufferedReader br,
                             int lineNumber)
                      throws java.io.IOException,
                             java.text.ParseException,
                             java.lang.NumberFormatException

Hook called from parse(java.io.File) after the first four lines are parsed to allow subclasses to parse extra lines before the obstacles.

Default impl just returns false.

Parameters:
br - the next line of this reader is the next to be parsed
lineNumber - the line number of the next line of br
Returns:
true if the line was parsed and more are expected, false if no more extra lines are expected
Throws:
java.io.IOException - if there was an I/O error
java.text.ParseException - if there was a format error
java.lang.NumberFormatException - if there was a format error

parse

protected void parse(java.io.File mapFile)
              throws java.io.IOException,
                     java.text.ParseException

Parse mapFile.

Format is specified in the class header doc for PolygonMap.

Parameters:
mapFile - the map file, not null
Throws:
java.io.IOException
java.text.ParseException

getRobotStart

public java.awt.geom.Point2D.Double getRobotStart()

Get robotStart.

Returns:
a reference to robotStart (you may modify it)

getRobotGoal

public java.awt.geom.Point2D.Double getRobotGoal()

Get robotGoal.

Returns:
a reference to robotGoal (you may modify it)

getWorldRect

public java.awt.geom.Rectangle2D.Double getWorldRect()

Get worldRect.

Returns:
a reference to worldRect (you may modify it)

getObstacles

public java.util.List<PolygonObstacle> getObstacles()

Get obstacles.

Returns:
a reference to obstacles (you may modify it)

toString

public java.lang.String toString()

Return a human-readable string representation of this map.

Overrides:
toString in class java.lang.Object
Returns:
a human-readable string representation of this map

instanceMain

protected void instanceMain(java.lang.String mapFile)

Parses the specified map file, prints it out, and displays it in the GUI, if any.

Usage: getAppName() <mapfile> [centralhost]


getAppName

protected java.lang.String getAppName()

Get the application name.

Returns:
the application name

driverDisplayHook

protected void driverDisplayHook()

Hook called after painting map objects in instanceMain(java.lang.String) to allow subclasses to display extra stuff.

Default impl does nothing.


onShutdown

public void onShutdown(Node node)
Shutdown hook for ROS when called as stand-alone node


onStart

public void onStart(Node node)
Entry hook for ROS when called as stand-alone node


onShutdownComplete

public void onShutdownComplete(Node node)

getDefaultNodeName

public GraphName getDefaultNodeName()