Package ucar.nc2.ui.gis
Class SpatialGrid
- java.lang.Object
-
- ucar.nc2.ui.gis.SpatialGrid
-
public class SpatialGrid extends Object
Fast implementation for tracking data overlap and closest point in a 2D region. The region of interest is divided into non-overlapping cells. Each cell may contain zero or one data objects. This allows quickly finding if a data object may be drawn (markIfClear) and closest drawn object to a point (findClosest).
-
-
Constructor Summary
Constructors Constructor Description SpatialGrid(int nx, int ny)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
clear all the grid cellsObject
findClosest(Point2D pt)
Find the closest marked cell to the given pointObject
findIntersection(Point2D p)
Check if the given point is contained in already drawn objectObject
findIntersection(Rectangle2D rect)
Check if the given rect intersects an already drawn objectboolean
markIfClear(Rectangle2D rect, Object o)
Check if the given rect intersects an already drawn one.void
setGrid(Rectangle2D bbox, double width, double height)
Set the grid scale.void
setOverlap(int overlap)
Set how much the data may overlap.
-
-
-
Method Detail
-
setGrid
public void setGrid(Rectangle2D bbox, double width, double height)
Set the grid scale.- Parameters:
bbox
- bounding box: we are only interested in points inside of thiswidth
- : divide the bounding box into cells of this width.height
- : divide the bounding box into cells of this height. maximum number of grid cells is nx x ny
-
setOverlap
public void setOverlap(int overlap)
Set how much the data may overlap.- Parameters:
overlap
- : percent overlap
-
clear
public void clear()
clear all the grid cells
-
markIfClear
public boolean markIfClear(Rectangle2D rect, Object o)
Check if the given rect intersects an already drawn one. If not, set the corresponding cell as marked, store object, return true, meaning "ok to draw".- Parameters:
rect
- the bounding box of the thing we want to drawo
- store this object- Returns:
- true if inside the bounding box and no intersection
-
findIntersection
public Object findIntersection(Rectangle2D rect)
Check if the given rect intersects an already drawn object- Parameters:
rect
- the bounding box of the thing we want to draw- Returns:
- object that intersects, or null if no intersection
-
findIntersection
public Object findIntersection(Point2D p)
Check if the given point is contained in already drawn object- Parameters:
p
- the point to check- Returns:
- object that intersects, or null if no intersection
-
-