Class FourWayGridMesh

  • All Implemented Interfaces:
    NavigationMesh

    public class FourWayGridMesh
    extends java.lang.Object
    implements NavigationMesh
    Generates a grid of nodes. Spacing between the grid nodes and clearance around map geometry can be specified. This set can be generated once at the beginning of a user program, and the same node set can be used for all subsequent navigation.
    Author:
    BB
    • Constructor Summary

      Constructors 
      Constructor Description
      FourWayGridMesh​(LineMap map, float gridSpace, float clearance)
      Instantiates a grid mesh of nodes which won't interconnect between any map geometry.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int addNode​(Node node, int neighbors)
      Adds a node to this set and connects it with a number of neighboring nodes.
      boolean connect​(Node node1, Node node2)
      Attempts to connect two nodes together by adding them as neighbors.
      boolean disconnect​(Node node1, Node node2)
      Disconnects two nodes by removing them as neighbors.
      java.util.Collection<Node> getMesh()
      Returns a collection of all nodes within this navigation mesh.
      void regenerate()
      Throws away the previous set of nodes and recalculates them all.
      boolean removeNode​(Node node)
      Removes a node from the set and removes any existing connections with its neighbors.
      void setClearance​(float clearance)
      Changes the safety zone between all nodes/connections and map geometry.
      void setGridSpacing​(float gridSpace)
      Change the size of each grid square.
      void setMap​(LineMap map)
      Feeds this class a new map.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FourWayGridMesh

        public FourWayGridMesh​(LineMap map,
                               float gridSpace,
                               float clearance)
        Instantiates a grid mesh of nodes which won't interconnect between any map geometry. Will also keep away the set parameter from map geometry. Grid spacing is adjustable via the constructor.
        Parameters:
        map - The map containing geometry.
        gridSpace - The size of each grid square.
        clearance - The safety zone between all nodes/connections and the map geometry.
    • Method Detail

      • getMesh

        public java.util.Collection<Node> getMesh()
        Description copied from interface: NavigationMesh
        Returns a collection of all nodes within this navigation mesh.
        Specified by:
        getMesh in interface NavigationMesh
        Returns:
        A Collection of Nodes.
      • setGridSpacing

        public void setGridSpacing​(float gridSpace)
        Change the size of each grid square. NOTE: When grid space value is changed, this class does not regenerate the navigation mesh until regenerate() is explicitly called.
        Parameters:
        gridSpace - The unit size of each grid square.
      • setClearance

        public void setClearance​(float clearance)
        Changes the safety zone between all nodes/connections and map geometry. This leaves a margin of error between potential object collisions and the robot. NOTE: When clearance value is changed, this class does not regenerate the navigation mesh until regenerate() is explicitly called.
        Parameters:
        clearance - The safety clearance between nodes/connections and map geometry.
      • setMap

        public void setMap​(LineMap map)
        Feeds this class a new map. NOTE: When Map is changed, this class does not regenerate the navigation mesh until regenerate() is explicitly called.
        Parameters:
        map - The new map data.
      • regenerate

        public void regenerate()
        Description copied from interface: NavigationMesh
        Throws away the previous set of nodes and recalculates them all. If any setting were changed, such as the spacing between nodes, then it will recalculate them with the new settings.
        Specified by:
        regenerate in interface NavigationMesh
      • connect

        public boolean connect​(Node node1,
                               Node node2)
        Description copied from interface: NavigationMesh
        Attempts to connect two nodes together by adding them as neighbors. If map data exists for this NavigationMesh, it will check the map data to see if the connection intersects or comes too close to map geometry. If it does they will not be connected and this method returns false.
        Specified by:
        connect in interface NavigationMesh
        Returns:
        Boolean value, true if the nodes were connected successfully, false if they could not connect.
      • disconnect

        public boolean disconnect​(Node node1,
                                  Node node2)
        Description copied from interface: NavigationMesh
        Disconnects two nodes by removing them as neighbors. If they were not previously connected it returns false.
        Specified by:
        disconnect in interface NavigationMesh
        Returns:
        Returns false if they were not previously connected.
      • addNode

        public int addNode​(Node node,
                           int neighbors)
        Adds a node to this set and connects it with a number of neighboring nodes. If it is unable to find any neighbors it will return 0. This might occur because the node is outside of the bounded area of the map. Note: The most FourWayGridMesh can connect a node to is four. If you select a number larger than four, a maximum of four neighbors will be connected with the node.
        Specified by:
        addNode in interface NavigationMesh
        Parameters:
        node - The unconnected node to add to this mesh. Will be connected with others in the set.
        neighbors - The maximum number of neighbors to attempt to connect with.
        Returns:
        the number of neighboring nodes it was able to connect with
      • removeNode

        public boolean removeNode​(Node node)
        Description copied from interface: NavigationMesh
        Removes a node from the set and removes any existing connections with its neighbors. Note: There is no guarantee it is disconnecting from only nodes in this mesh. This method will disconnect the node from all the nodes registered as neighbors.
        Specified by:
        removeNode in interface NavigationMesh
        Parameters:
        node - The node to remove.
        Returns:
        Returns true if the node was removed, false if it did not exist in this set.