Class SpatialQuadTree<V>

    • Constructor Detail

      • SpatialQuadTree

        public SpatialQuadTree​(LayoutModel<V> layoutModel)
        Parameters:
        layoutModel -
      • SpatialQuadTree

        public SpatialQuadTree​(LayoutModel<V> layoutModel,
                               double width,
                               double height)
        Parameters:
        layoutModel -
        width -
        height -
      • SpatialQuadTree

        public SpatialQuadTree​(LayoutModel<V> layoutModel,
                               int level,
                               double x,
                               double y,
                               double width,
                               double height)
        Parameters:
        level - level to start at. 0 is the root
        x -
        y -
        width -
        height -
    • Method Detail

      • setMaxObjects

        public SpatialQuadTree<V> setMaxObjects​(int o)
        Parameters:
        o - max number of objects allowed
        Returns:
        this QuadTree
      • setMaxLevels

        public SpatialQuadTree<V> setMaxLevels​(int l)
        Parameters:
        l - max levels allowed
        Returns:
      • getLevel

        protected int getLevel()
        Returns:
        the level of this cell
      • getVertices

        public Set<V> getVertices()
        Returns:
        the nodes in this cell, assuming it is a leaf
      • clear

        public void clear()
        Description copied from interface: Spatial
        destroy the current spatial structure
        Specified by:
        clear in interface Spatial<V,​V>
      • split

        protected void split()
      • getQuadrant

        protected org.jungrapht.visualization.spatial.SpatialQuadTree.Quadrant getQuadrant​(Point p)
        find the quadrant that the point would be in
        Parameters:
        p - the point of interest
        Returns:
        the quadrant that would contain the point
      • getQuadrant

        protected org.jungrapht.visualization.spatial.SpatialQuadTree.Quadrant getQuadrant​(double x,
                                                                                           double y)
        find the quadrant that the point would be in
        Parameters:
        x - , y the point of interest
        Returns:
        the quadrant that would contain the point
      • insert

        protected void insert​(V p)
      • retrieve

        protected Set<V> retrieve​(Set<V> returnObjects,
                                  Shape shape)
        Return all objects that are within the passed shape This is needed when the layout is rotated/skewed and the shape edges are no longer parallel to the grid edges.
      • getGrid

        public List<Shape> getGrid()
        Specified by:
        getGrid in interface Spatial<V,​V>
        Returns:
        a geometic representation of the spatial structure
      • getVisibleElements

        public Set<V> getVisibleElements​(Shape shape)
        Specified by:
        getVisibleElements in interface Spatial<V,​V>
        Parameters:
        shape - the possibly non-rectangular area of interest
        Returns:
        the nodes that are in the quadtree cells that intersect with the passed shape
      • getVisibleVertices

        public Set<V> getVisibleVertices​(Rectangle2D r)
        Parameters:
        r -
        Returns:
        the nodes that are in the quadtree cells that intersect with the passed rectangle
      • getLayoutArea

        public Rectangle2D getLayoutArea()
        tha layout area that this tree cell operates over
        Specified by:
        getLayoutArea in interface Spatial<V,​V>
        Returns:
      • recalculate

        public void recalculate()
        Description copied from interface: Spatial
        rebuild the data structure
        Specified by:
        recalculate in interface Spatial<V,​V>
      • getContainingQuadTreeLeaf

        public TreeNode getContainingQuadTreeLeaf​(V node)
        Parameters:
        node - the node to search for
        Returns:
        the quadtree leaf that contains the passed node
      • getContainingLeafs

        public Set<SpatialQuadTree<V>> getContainingLeafs​(double x,
                                                          double y)
        Specified by:
        getContainingLeafs in interface Spatial<V,​V>
        Parameters:
        x - the x location to search for
        y - the y location to search for
        Returns:
        all leaf nodes that contain the passed coordinates
      • getContainingLeaf

        public TreeNode getContainingLeaf​(Object element)
        Specified by:
        getContainingLeaf in interface Spatial<V,​V>
        Parameters:
        element - element to search for
        Returns:
        the leaf node that currently contains the element (not a spatial search)
      • getContainingQuadTreeLeaf

        public SpatialQuadTree<V> getContainingQuadTreeLeaf​(Point2D p)
        find the cell that would contain the passed point
        Parameters:
        p - the point of interest
        Returns:
        the cell that would contain p
      • getContainingQuadTreeLeaf

        public SpatialQuadTree<V> getContainingQuadTreeLeaf​(double x,
                                                            double y)
        Parameters:
        x - location of interest
        y - location of interest
        Returns:
        the cell that would contain (x, y)
      • getClosestElement

        public V getClosestElement​(Point2D p)
        Specified by:
        getClosestElement in interface Spatial<V,​V>
        Parameters:
        p - a point to search in the spatial structure
        Returns:
        the closest element to the passed point
      • getClosestElement

        public V getClosestElement​(double x,
                                   double y)
        get the node that is closest to the passed (x,y)
        Specified by:
        getClosestElement in interface Spatial<V,​V>
        Parameters:
        x -
        y -
        Returns:
        the node closest to x,y
      • setBounds

        public void setBounds​(Rectangle2D bounds)
        reset the side of this structure
        Specified by:
        setBounds in interface Spatial<V,​V>
        Parameters:
        bounds - the new bounds for the data struture
      • update

        public void update​(V node,
                           Point location)
        Update the structure for the passed node. If the node is still in the same cell, don't rebuild the structure. If it moved to a new cell, rebuild the structure
        Specified by:
        update in interface Spatial<V,​V>
        Parameters:
        node -
        location - the location of the element
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object