Class SimpleNavGraph
java.lang.Object
eu.iv4xr.framework.extensions.pathfinding.SimpleNavGraph
- All Implemented Interfaces:
CanDealWithDynamicObstacle<LineIntersectable>
,Navigatable<Integer>
- Direct Known Subclasses:
SurfaceNavGraph
public class SimpleNavGraph
extends Object
implements Navigatable<Integer>, CanDealWithDynamicObstacle<LineIntersectable>
This class is provides an implementation of a navigation graph (an instance
of
Navigatable
) that facilitates pathfinding over a 3D-surface
defined by a surface-mesh with obstacles. By 3D surface we mean that it is a
surface in a 3D space. An obstacle is an object that can block travel
along one or more edges in a navigation graph. It moreover may have a dynamic
state (can change at the runtime), which is either blocking, or non-blocking.
If we don't have obstacles, that is also fine; we simply don't add any to the
graph. For the actual pathfinding over the graph, you can e.g. use
AStar
that can take an instance of Navigatable
to find a path
between two nodes in a navigation graph.
This class itself only keeps a navigation graph. In particular, it does not keep the original surface-mesh. Instead, we can convert a given surface-mesh to instance of this navigation graph using the method:
fromMeshFaceAverage(Mesh)
The center of the faces in the surface-mesh will be converted the nodes of
this navigation-graph. Two nodes are connected by an edge if the original
faces they belong to are adjacent. Travel is assumed to be possible by
following such edges.- Author:
- Naraenda
-
Field Summary
-
Constructor Summary
ConstructorDescriptionSimpleNavGraph(EdgeMap edges, ArrayList<Vec3> vertices, ArrayList<Obstacle<LineIntersectable>> obstacles)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addObstacle(LineIntersectable obstacle)
Add the obstacle to this navgraph.void
addObstacleInBlockingState(LineIntersectable obstacle)
Add the obstacle to this navgraph.float
The distance between two NEIGHBORING vertices.static SimpleNavGraph
fromMeshFaceAverage(Mesh mesh)
Generates a SimpleNavGraph from a mesh where a vertex in the navigation graph corresponds to the average center of a face in the mesh.getBlockingStatus(LineIntersectable obstacle)
Return the status of the given obstacle, if it is marked as blocking (true) or non-blocking (false).float
Heuristic distance between any two vertices.boolean
isBlocking(LineIntersectable obstacle)
Return the state of this obstacle.neighbours(Integer id)
An interable that can be used by pathfinders to explore a node's connections.position(int i)
void
removeObstacle(LineIntersectable tobeRemoved)
void
setBlockingState(LineIntersectable obstacle, boolean isBlocking)
Set the the state of this obstacle to blocking or unblocking.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.iv4xr.framework.extensions.pathfinding.CanDealWithDynamicObstacle
toggleBlockingOff, toggleBlockingOn
-
Field Details
-
vertices
The set of vertices that form the navigation graph. The index of the vertex is its id. So if v = vertices(i), then i is its id, and vertices(i) actually returns the 3D position of the vertex. -
edges
Describe the connectivity (edges) between the vertices. -
obstacles
-
-
Constructor Details
-
SimpleNavGraph
-
SimpleNavGraph
public SimpleNavGraph()
-
-
Method Details
-
addObstacle
Add the obstacle to this navgraph. The obstacle is set as non-blocking.- Specified by:
addObstacle
in interfaceCanDealWithDynamicObstacle<LineIntersectable>
-
addObstacleInBlockingState
Add the obstacle to this navgraph. The obstacle is set as blocking. -
removeObstacle
- Specified by:
removeObstacle
in interfaceCanDealWithDynamicObstacle<LineIntersectable>
-
isBlocking
Return the state of this obstacle. True means that it is in the blocking state.- Specified by:
isBlocking
in interfaceCanDealWithDynamicObstacle<LineIntersectable>
-
setBlockingState
Description copied from interface:CanDealWithDynamicObstacle
Set the the state of this obstacle to blocking or unblocking.- Specified by:
setBlockingState
in interfaceCanDealWithDynamicObstacle<LineIntersectable>
isBlocking
- If true then the obstacle will be set to its blocking state, and else non-blocking.
-
getBlockingStatus
Return the status of the given obstacle, if it is marked as blocking (true) or non-blocking (false). Return null of the said obstacle is not known. -
neighbours
Description copied from interface:Navigatable
An interable that can be used by pathfinders to explore a node's connections.- Specified by:
neighbours
in interfaceNavigatable<Integer>
- Parameters:
id
- the index of the vertex to inspect.- Returns:
- an iterable of the connected neighbours.
-
position
-
heuristic
Heuristic distance between any two vertices. Here it is chosen to be the geometric distance between them.- Specified by:
heuristic
in interfaceNavigatable<Integer>
- Parameters:
from
- : the index of the vertex to travel from.to
- : the index of the vertex to travel to.- Returns:
- the estimated distance.
-
distance
The distance between two NEIGHBORING vertices. If the connection is not blocked, it is deined to be their geometric distance, and else +inf.- Specified by:
distance
in interfaceNavigatable<Integer>
- Parameters:
from
- : the index of the vertex to travel from.to
- : the index of the vertex to travel to.- Returns:
- the measured distance. NaN if nodes are not connected.
-
fromMeshFaceAverage
Generates a SimpleNavGraph from a mesh where a vertex in the navigation graph corresponds to the average center of a face in the mesh. This works with any mesh, but only meshes that consist out of convex faces will guarantee to produce a useful result.- Parameters:
mesh
- a convex mesh.- Returns:
- a SimpleNavGraph constructed from the given mesh.
-