Class LocatedObject

    • Field Detail

      • KEY_POLY_X

        public static final String KEY_POLY_X
        the key for the Xs of the polygon in the meta-data (comma-separated list).
        See Also:
        Constant Field Values
      • KEY_POLY_Y

        public static final String KEY_POLY_Y
        the key for the Ys of the polygon in the meta-data (comma-separated list).
        See Also:
        Constant Field Values
      • m_Image

        protected BufferedImage m_Image
        the cut-out object, if available.
      • m_X

        protected int m_X
        the x of the top-left corner in the original image.
      • m_Y

        protected int m_Y
        the y of the top-left corner in the original image.
      • m_Width

        protected int m_Width
        the width of the actual object sub-image.
      • m_Height

        protected int m_Height
        the height of the actual object sub-image.
      • m_ActualRectangle

        protected Rectangle m_ActualRectangle
        the actual rectangle.
      • m_ActualPolygon

        protected Polygon m_ActualPolygon
        the actual polygon.
      • m_MetaData

        protected Map<String,​Object> m_MetaData
        additional meta-data.
    • Constructor Detail

      • LocatedObject

        public LocatedObject​(Polygon polygon)
        Initializes the container.
        Parameters:
        polygon - the polygon to use
      • LocatedObject

        public LocatedObject​(BufferedImage image,
                             Polygon polygon)
        Initializes the container.
        Parameters:
        image - the object image, can be null
        polygon - the polygon to use
      • LocatedObject

        public LocatedObject​(BufferedImage image,
                             Polygon polygon,
                             Map<String,​Object> metaData)
        Initializes the container.
        Parameters:
        image - the object image, can be null
        polygon - the polygon to use
        metaData - optional meta-data, can be null
      • LocatedObject

        public LocatedObject​(int x,
                             int y,
                             int width,
                             int height)
        Initializes the container.
        Parameters:
        x - the x of the top-left corner in the original image
        y - the y of the top-left corner in the original image
        width - the width of the object sub-image
        height - the height of the object sub-image
      • LocatedObject

        public LocatedObject​(BufferedImage image,
                             int x,
                             int y,
                             int width,
                             int height)
        Initializes the container.
        Parameters:
        image - the object image, can be null
        x - the x of the top-left corner in the original image
        y - the y of the top-left corner in the original image
        width - the width of the object sub-image
        height - the height of the object sub-image
      • LocatedObject

        public LocatedObject​(BufferedImage image,
                             int x,
                             int y,
                             int width,
                             int height,
                             Map<String,​Object> metaData)
        Initializes the container.
        Parameters:
        image - the object image, can be null
        x - the x of the top-left corner in the original image
        y - the y of the top-left corner in the original image
        width - the width of the object sub-image
        height - the height of the object sub-image
        metaData - optional meta-data, can be null
      • LocatedObject

        public LocatedObject​(Rectangle rect)
        Initializes the container.
        Parameters:
        rect - the rectangle
      • LocatedObject

        public LocatedObject​(BufferedImage image,
                             Rectangle rect)
        Initializes the container.
        Parameters:
        image - the object image, can be null
        rect - the rectangle
      • LocatedObject

        public LocatedObject​(BufferedImage image,
                             Rectangle rect,
                             Map<String,​Object> metaData)
        Initializes the container.
        Parameters:
        image - the object image, can be null
        rect - the rectangle
        metaData - optional meta-data, can be null
    • Method Detail

      • getImage

        public BufferedImage getImage()
        Returns the image.
        Returns:
        the image, null if not available
      • getX

        public int getX()
        Returns the X of the top-left corner.
        Returns:
        the X
      • getY

        public int getY()
        Returns the Y of the top-left corner.
        Returns:
        the Y
      • getWidth

        public int getWidth()
        Returns the width of the object sub-image.
        Returns:
        the width
      • getHeight

        public int getHeight()
        Returns the height of the object sub-image.
        Returns:
        the height
      • getIndexString

        public String getIndexString()
        Returns the index string of the object.
        Returns:
        the index, null if not available
      • getIndex

        public int getIndex()
        Returns the index of the object.
        Returns:
        the index, -1 if not available
      • getMetaData

        public Map<String,​Object> getMetaData()
        Returns the meta-data of the object, if any.
        Returns:
        the meta-data
      • getMetaData

        public Map<String,​Object> getMetaData​(boolean copy)
        Returns the meta-data of the object, if any.
        Parameters:
        copy - whether to return a copy
        Returns:
        the meta-data
      • getActualRectangle

        public Rectangle getActualRectangle()
        Returns the actual size rectangle.
        Returns:
        the actual size rectangle
      • getActualPolygon

        public Polygon getActualPolygon()
        Returns the actual size polygon.
        Returns:
        the actual size polygon
      • scale

        public void scale​(double scale)
        Scales the actual size rectangle with the given factor.
        Parameters:
        scale - the scale factor
      • getLocation

        public QuadrilateralLocation getLocation()
        Returns the quadrilateral location.
        Returns:
        the location
      • hasPolygon

        public boolean hasPolygon()
        Checks whether polygon meta-data is present.
        Returns:
        true if present
      • hasValidPolygon

        public boolean hasValidPolygon()
        Checks whether polygon meta-data is present.
        Returns:
        true if present
      • getRectangle

        public Rectangle getRectangle()
        Returns the object as rectangle.
        Returns:
        the rectangle
      • getRectangle

        public Rectangle getRectangle​(double scale)
        Returns the object as rectangle.
        Parameters:
        scale - the scale factor, 1.0 for 100%
        Returns:
        the rectangle
      • getRectangle

        public Rectangle getRectangle​(double scaleX,
                                      double scaleY)
        Returns the object as rectangle.
        Parameters:
        scaleX - the scale factor for X, 1.0 for 100%
        scaleY - the scale factor for Y, 1.0 for 100%
        Returns:
        the rectangle
      • getPolyCoords

        protected int[] getPolyCoords​(String key)
        Returns the specified polygon coordinates.
        Parameters:
        key - KEY_POLY_X or KEY_POLY_Y
        Returns:
        the coordinates, 0-length if none available or failed to parse
      • getPolygonX

        public int[] getPolygonX()
        Returns the X coordinates of the polygon (if any).
        Returns:
        the X coordinates
      • getPolygonY

        public int[] getPolygonY()
        Returns the Y coordinates of the polygon (if any).
        Returns:
        the Y coordinates
      • getPolygon

        public Polygon getPolygon()
        Returns the polygon, if possible.
        Returns:
        the polygon, null if no/incorrect data stored
      • getPolygon

        public Polygon getPolygon​(double scale)
        Returns the polygon, if possible.
        Parameters:
        scale - the scale to use
        Returns:
        the polygon, null if no/incorrect data stored
      • getPolygon

        public Polygon getPolygon​(double scaleX,
                                  double scaleY)
        Returns the polygon, if possible.
        Parameters:
        scaleX - the scale to use for X
        scaleY - the scale to use for Y
        Returns:
        the polygon, null if no/incorrect data stored
      • setPolygon

        public void setPolygon​(Polygon value)
        Stores the polygon in the meta-data.
        Parameters:
        value - the polygon
      • setPolygon

        public void setPolygon​(org.locationtech.jts.geom.Polygon value)
        Stores the JTS polygon in the meta-data.
        Parameters:
        value - the JTS polygon to use
      • bboxToPolygon

        public Polygon bboxToPolygon()
        Turns the bounding box into a polygon.
        Returns:
        the polygon
      • boundingBoxFallback

        public boolean boundingBoxFallback​(double minRatio)
        Checks whether we need fall back on the bounding box due to the object either not having a polygon or the polygon being too small in relation to the required polygon/bbox ratio.
        Parameters:
        minRatio - the minimum poly/bbox ratio that we need
        Returns:
        true if fall back on bbox
      • makeFit

        public boolean makeFit​(int width,
                               int height)
        Ensures that the object fits within this region.
        Parameters:
        width - the width of the region
        height - the height of the region
        Returns:
        true if object got adjusted
      • inRange

        protected boolean inRange​(int value,
                                  int min,
                                  int max)
        Checks whether a value is within the range (allowed to be on borders).
        Parameters:
        value - the value to check
        min - the minimum
        max - the maximum
        Returns:
        true if in range
      • overlap

        public boolean overlap​(LocatedObject other)
        Returns whether the this and the other object overlap.
        Parameters:
        other - the object object to use
        Returns:
        true if they overlap
      • overlapRectangle

        public Rectangle overlapRectangle​(LocatedObject other)
        Returns the overlapping rectangle.
        Parameters:
        other - the object object to use
        Returns:
        rectangle if they overlap, otherwise null
        See Also:
        overlap(LocatedObject)
      • overlapRatio

        public double overlapRatio​(LocatedObject other)
        Returns the overlap ratio (1 = full overlap, 0 = no overlap).
        Parameters:
        other - the object object to use
        Returns:
        rectangle if they overlap, otherwise null
        See Also:
        overlap(LocatedObject)
      • renameMetaDataKey

        public boolean renameMetaDataKey​(String oldKey,
                                         String newKey)
        Renames the meta-data key.
        Parameters:
        oldKey - the old key
        newKey - the new key
        Returns:
        if key got updated
      • compareTo

        public int compareTo​(LocatedObject o)
        Compares this object with the provided one. Bounding box, then polygon (if present).
        Specified by:
        compareTo in interface Comparable<LocatedObject>
        Parameters:
        o - the object to compare with
        Returns:
        if x/y/width/height are less, equal to, or larger than the other one
      • equals

        public boolean equals​(Object obj)
        Tests if this object is the same as the other one.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare with
        Returns:
        true if the same
        See Also:
        compareTo(LocatedObject)
      • hashCode

        public int hashCode()
        Returns the hashcode of the rectangle.
        Overrides:
        hashCode in class Object
        Returns:
        the hash
      • toString

        public String toString()
        Returns a short description of the container.
        Overrides:
        toString in class Object
        Returns:
        the description
      • toSpreadSheet

        public SpreadSheet toSpreadSheet​(String[] metaDataKeys)
        Returns the content as spreadsheet.
        Parameters:
        metaDataKeys - the additional meta-data keys to display as separate columns, can be null
        Returns:
        the content