Class LocatedObject
- java.lang.Object
-
- adams.flow.transformer.locateobjects.LocatedObject
-
- All Implemented Interfaces:
CloneHandler<LocatedObject>
,SpreadSheetSupporter
,Serializable
,Comparable<LocatedObject>
public class LocatedObject extends Object implements Serializable, CloneHandler<LocatedObject>, Comparable<LocatedObject>, SpreadSheetSupporter
Container for located objects.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
KEY_POLY_X
the key for the Xs of the polygon in the meta-data (comma-separated list).static String
KEY_POLY_Y
the key for the Ys of the polygon in the meta-data (comma-separated list).protected Polygon
m_ActualPolygon
the actual polygon.protected Rectangle
m_ActualRectangle
the actual rectangle.protected int
m_Height
the height of the actual object sub-image.protected BufferedImage
m_Image
the cut-out object, if available.protected Map<String,Object>
m_MetaData
additional meta-data.protected int
m_Width
the width of the actual object sub-image.protected int
m_X
the x of the top-left corner in the original image.protected int
m_Y
the y of the top-left corner in the original image.
-
Constructor Summary
Constructors Constructor Description LocatedObject(int x, int y, int width, int height)
Initializes the container.LocatedObject(BufferedImage image, int x, int y, int width, int height)
Initializes the container.LocatedObject(BufferedImage image, int x, int y, int width, int height, Map<String,Object> metaData)
Initializes the container.LocatedObject(BufferedImage image, Polygon polygon)
Initializes the container.LocatedObject(BufferedImage image, Polygon polygon, Map<String,Object> metaData)
Initializes the container.LocatedObject(BufferedImage image, Rectangle rect)
Initializes the container.LocatedObject(BufferedImage image, Rectangle rect, Map<String,Object> metaData)
Initializes the container.LocatedObject(Polygon polygon)
Initializes the container.LocatedObject(Rectangle rect)
Initializes the container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Polygon
bboxToPolygon()
Turns the bounding box into a polygon.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.int
compareTo(LocatedObject o)
Compares this object with the provided one.boolean
equals(Object obj)
Tests if this object is the same as the other one.Polygon
getActualPolygon()
Returns the actual size polygon.Rectangle
getActualRectangle()
Returns the actual size rectangle.LocatedObject
getClone()
Returns a clone of the object.int
getHeight()
Returns the height of the object sub-image.BufferedImage
getImage()
Returns the image.int
getIndex()
Returns the index of the object.String
getIndexString()
Returns the index string of the object.QuadrilateralLocation
getLocation()
Returns the quadrilateral location.Map<String,Object>
getMetaData()
Returns the meta-data of the object, if any.Map<String,Object>
getMetaData(boolean copy)
Returns the meta-data of the object, if any.protected int[]
getPolyCoords(String key)
Returns the specified polygon coordinates.Polygon
getPolygon()
Returns the polygon, if possible.Polygon
getPolygon(double scale)
Returns the polygon, if possible.Polygon
getPolygon(double scaleX, double scaleY)
Returns the polygon, if possible.int[]
getPolygonX()
Returns the X coordinates of the polygon (if any).int[]
getPolygonY()
Returns the Y coordinates of the polygon (if any).Rectangle
getRectangle()
Returns the object as rectangle.Rectangle
getRectangle(double scale)
Returns the object as rectangle.Rectangle
getRectangle(double scaleX, double scaleY)
Returns the object as rectangle.int
getWidth()
Returns the width of the object sub-image.int
getX()
Returns the X of the top-left corner.int
getY()
Returns the Y of the top-left corner.int
hashCode()
Returns the hashcode of the rectangle.boolean
hasPolygon()
Checks whether polygon meta-data is present.boolean
hasValidPolygon()
Checks whether polygon meta-data is present.protected boolean
inRange(int value, int min, int max)
Checks whether a value is within the range (allowed to be on borders).boolean
makeFit(int width, int height)
Ensures that the object fits within this region.boolean
overlap(LocatedObject other)
Returns whether the this and the other object overlap.double
overlapRatio(LocatedObject other)
Returns the overlap ratio (1 = full overlap, 0 = no overlap).Rectangle
overlapRectangle(LocatedObject other)
Returns the overlapping rectangle.boolean
renameMetaDataKey(String oldKey, String newKey)
Renames the meta-data key.void
scale(double scale)
Scales the actual size rectangle with the given factor.void
setPolygon(Polygon value)
Stores the polygon in the meta-data.void
setPolygon(org.locationtech.jts.geom.Polygon value)
Stores the JTS polygon in the meta-data.org.locationtech.jts.geom.Polygon
toGeometry()
Converts the polygon or rectangle into a JTS polygon (for proper intersects).SpreadSheet
toSpreadSheet()
Returns the content as spreadsheet.SpreadSheet
toSpreadSheet(String[] metaDataKeys)
Returns the content as spreadsheet.String
toString()
Returns a short description of the container.
-
-
-
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.
-
-
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 nullpolygon
- 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 nullpolygon
- the polygon to usemetaData
- 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 imagey
- the y of the top-left corner in the original imagewidth
- the width of the object sub-imageheight
- 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 nullx
- the x of the top-left corner in the original imagey
- the y of the top-left corner in the original imagewidth
- the width of the object sub-imageheight
- 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 nullx
- the x of the top-left corner in the original imagey
- the y of the top-left corner in the original imagewidth
- the width of the object sub-imageheight
- the height of the object sub-imagemetaData
- 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 nullrect
- the rectangle
-
LocatedObject
public LocatedObject(BufferedImage image, Rectangle rect, Map<String,Object> metaData)
Initializes the container.- Parameters:
image
- the object image, can be nullrect
- the rectanglemetaData
- optional meta-data, can be null
-
-
Method Detail
-
getClone
public LocatedObject getClone()
Returns a clone of the object.- Specified by:
getClone
in interfaceCloneHandler<LocatedObject>
- Returns:
- the clone
-
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
orKEY_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 XscaleY
- 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
-
toGeometry
public org.locationtech.jts.geom.Polygon toGeometry()
Converts the polygon or rectangle into a JTS polygon (for proper intersects).- Returns:
- the polygon
- See Also:
GeometryUtils.toGeometry(Polygon)
,GeometryUtils.toGeometry(Rectangle)
-
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 regionheight
- 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 checkmin
- the minimummax
- 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 keynewKey
- 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 interfaceComparable<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 classObject
- 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.
-
toString
public String toString()
Returns a short description of the container.
-
toSpreadSheet
public SpreadSheet toSpreadSheet()
Returns the content as spreadsheet.- Specified by:
toSpreadSheet
in interfaceSpreadSheetSupporter
- Returns:
- the content
-
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
-
-