Class Contours
Array of 2D contours.
Every contour is a sequence of 32-bit int values, describing N integer points (xk,yk). Every contours starts from the header, containing K 32-bit special values. In current version, K is 8 or 10, Format:
MAGIC_WORD, 2*N+K, (MAGIC_WORD = 2135109896 or 2135109898) minX, maxX, minY, maxY, RESERVED | FLAGS, objectLabel, (RESERVED = 2147418112) RESERVED, frameID (optional pair) x1, y1, . . . xN, yN
Here MAGIC_WORD contains (in low bits) the value K. Value 2*N+K is the total number of 32-bit integers, occupied by this contour: the next contours starts at the position "offset of this contour"+2*N+K.
minX, maxX, minY, maxY are the mininal/maximal coordinates of all points in this contour, i.e. the rectangle, containing all this contour. (It is allowed to store here some greater rectangle, containing it, but if the contour is created by standard methods, minX, maxX, minY, maxY will contain correct minimums and maximums.)
RESERVED | FLAGS contains in low bits some additional information (see ContourHeader
class),
in particular, whether this contour is external or internal and whether this header contains
frameID (see below). objectLabel is an integer label of the object, the boundary of which
is represented by this contour.
The last pair is optional. RESERVED is a special indicator 0x7FFF0000; frameID is some integer ID, that can be stored together with contour and should have some unique ID of the frame in a multi-frame map, from which this contour has been scanned.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Contours array consists of blocks (lines), where each block containsBLOCK_LENGTH
= 2 elements.static final int
static final int
Number of points, saved in the contour, cannot be greater than 1073741567 ~ 230.static final int
Maximal allowed number of contours: 500000000.
It is essentially less than Integer.MAX_VALUE, that allows to simplify arithmetic operations with number of contours.static final int
Coordinates of points, saved in the contour, cannot be out of range -0x40000000 ≤ x, y ≤0x3FFFFFFF It allows to guarantee thatcontaining rectangle
of each contour has sizes, less than Integer.MAX_VALUE. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addContour
(ContourHeader header, int[] contour) void
addContour
(ContourHeader header, int[] contour, int contourOffset, int contourLength) void
addContour
(ContourHeader header, IntArray contour) void
addContour
(ContourHeader header, IntArray contour, boolean packAddedContour) void
addContour
(Contours contours, int contourIndex) void
addContours
(Contours contours) void
addContoursRange
(Contours contours, int from, int to) void
addPoint
(long x, long y) void
addPoint
(long x, long y, boolean xAtMinXMatrixBoundary, boolean xAtMaxXMatrixBoundary, boolean yAtMinYMatrixBoundary, boolean yAtMaxYMatrixBoundary) void
addPoint
(Boundary2DScanner scanner, long startX, long startY) void
addTransformedContours
(Contours contours, double scaleX, double scaleY, double shiftX, double shiftY, boolean removeDegeneratedContours) void
clear()
void
clear
(boolean freeResources) void
closeContour
(ContourHeader header) Finishes adding points and closes the contour.contoursRange
(int from, int to) static Contours
deserialize
(int[] serialized) boolean
boolean
equalsToSerialized
(int[] serialized) static int
extractLength
(long lengthAndOffset) static int
extractOffset
(long lengthAndOffset) findSomePointInside
(int contourIndex) findSomePointInside
(int contourIndex, boolean surelyUnpacked) boolean
findSomePointInside
(Point2D result, int contourIndex) static boolean
findSomePointInside
(Point2D result, int[] contour, int offset, int n, boolean surelyUnpacked) boolean
findSomePointInside
(Point2D result, int contourIndex, boolean surelyUnpacked) int[]
getAllFrameId
(int absentId) boolean[]
int[]
getContour
(int contourIndex) int
getContourLength
(int contourIndex) long
getContourLengthAndOffset
(int contourIndex) int
getContourNumberOfPoints
(int contourIndex) static int
getContourNumberOfPoints
(IntArray contour) int
getContourOffset
(int contourIndex) int
getContourPoints
(int[] resultPoints, int contourIndex) static int
getContourPoints
(int[] resultPoints, IntArray contour) int[]
getContourPointsAndReallocateResult
(int[] resultPoints, ContourLength resultLength, int contourIndex) static int[]
getContourPointsAndReallocateResult
(int[] resultPoints, ContourLength resultLength, IntArray contour) double
getContourPointX
(int contourIndex, int pointIndex) double
getContourPointY
(int contourIndex, int pointIndex) getFrameIdOrNull
(int contourIndex) getHeader
(int contourIndex) getHeader
(ContourHeader resultHeader, int contourIndex) int
getObjectLabel
(int contourIndex) int
getSerializedHeaderOffset
(int contourIndex) int
hashCode()
boolean
boolean
isEmpty()
boolean
isInternalContour
(int contourIndex) boolean
boolean
isPointStrictlyInside
(int contourIndex, double x, double y) boolean
isPointStrictlyInside
(int contourIndex, double x, double y, boolean surelyUnpacked) static boolean
isSerializedContour
(int[] serialized, int offset) static boolean
isSerializedContours
(int[] serialized) static Contours
int
void
openContourForAdding
(ContourHeader header) Starts adding points of new contour.static int
packContour
(MutableIntArray resultContour, IntArray nonOptimizedContour) static int[]
packContourAndReallocateResult
(int[] resultPoints, ContourLength resultLength, int[] nonOptimizedContour, int nonOptimizedOffset, int n) static int[]
packContourAndReallocateResult
(int[] resultPoints, ContourLength resultLength, IntArray nonOptimizedContour) static double
pointInsideContourInformation
(int[] contour, int offset, int n, double x, double y, boolean surelyUnpacked) double
pointInsideContourInformation
(int contourIndex, double x, double y, boolean surelyUnpacked) pointInsideContourStatus
(int contourIndex, double x, double y, boolean surelyUnpacked) long
preciseDoubledArea
(int contourIndex) static long
preciseDoubledArea
(int[] contour, int offset, int n) void
removeContoursRange
(int from, int to) void
void
removeSingleContour
(int contourIndex) static MutableIntArray
reverseContour
(MutableIntArray resultContour, IntArray contour) double
segmentCentersArea
(int contourIndex) static double
segmentCentersArea
(int[] contour, int offset, int n) static double
segmentCentersArea
(IntArray contour) double
segmentCentersPerimeter
(int contourIndex) static double
segmentCentersPerimeter
(int[] contour, int offset, int n) static double
segmentCentersPerimeter
(IntArray contour) int[]
void
setObjectLabel
(int contourIndex, int label) setOptimizeCollinearSteps
(boolean optimizeCollinearSteps) void
sortIndexesByLabels
(int[] indexes) void
sortIndexesByLabels
(int[] indexes, boolean internalContoursFirst) void
sortIndexesByPreciseArea
(int[] indexes, boolean absoluteValueOfArea) void
sortIndexesByPreciseArea
(int[] indexes, boolean absoluteValueOfArea, boolean greaterAreasFirst) double
strictArea
(int contourIndex) static double
strictArea
(int[] contour, int offset, int n) static double
strictArea
(IntArray contour) double
strictPerimeter
(int contourIndex) static double
strictPerimeter
(int[] contour, int offset, int n) static double
strictPerimeter
(IntArray contour) toString()
static void
transformContour
(int[] contour, int offset, int n, double scaleX, double scaleY, double shiftX, double shiftY) static MutableIntArray
transformContour
(MutableIntArray resultContour, IntArray contour, double scaleX, double scaleY, double shiftX, double shiftY) transformContours
(double scaleX, double scaleY, double shiftX, double shiftY, boolean removeDegeneratedContours) unpackContour
(int contourIndex) unpackContour
(int contourIndex, boolean processDiagonalSegments) static MutableIntArray
unpackContour
(IntArray optimizedContour, boolean processDiagonalSegments) static int
unpackContour
(MutableIntArray resultContour, IntArray optimizedContour, boolean processDiagonalSegments) int[]
unpackContourAndReallocateResult
(int[] resultPoints, ContourLength resultLength, int contourIndex) int[]
unpackContourAndReallocateResult
(int[] resultPoints, ContourLength resultLength, int contourIndex, boolean processDiagonalSegments) static int[]
unpackContourAndReallocateResult
(int[] resultPoints, ContourLength resultLength, IntArray optimizedContour, boolean processDiagonalSegments) unpackContours
(boolean processDiagonalSegments) unpackContours
(boolean processDiagonalSegments, long[] doubledAreas)
-
Field Details
-
BLOCK_LENGTH
public static final int BLOCK_LENGTHContours array consists of blocks (lines), where each block containsBLOCK_LENGTH
= 2 elements. Typical block contains two coordinates (x, y).- See Also:
-
MIN_ABSOLUTE_COORDINATE
public static final int MIN_ABSOLUTE_COORDINATECoordinates of points, saved in the contour, cannot be out of range -0x40000000 ≤ x, y ≤0x3FFFFFFF It allows to guarantee thatcontaining rectangle
of each contour has sizes, less than Integer.MAX_VALUE. Also it allows to use positive values with bit #30 = 1 as reserved.- See Also:
-
MAX_ABSOLUTE_COORDINATE
public static final int MAX_ABSOLUTE_COORDINATE- See Also:
-
MAX_NUMBER_OF_CONTOURS
public static final int MAX_NUMBER_OF_CONTOURSMaximal allowed number of contours: 500000000.
It is essentially less than Integer.MAX_VALUE, that allows to simplify arithmetic operations with number of contours.More precisely, we guarantee that this value is less than Integer.MAX_VALUE / 4: for example, you can freely multiply number of contours by 4.
- See Also:
-
MAX_CONTOUR_NUMBER_OF_POINTS
public static final int MAX_CONTOUR_NUMBER_OF_POINTSNumber of points, saved in the contour, cannot be greater than 1073741567 ~ 230. It allows to guarantee that each contour can be successfully stored in simple Java int[] array.- See Also:
-
-
Method Details
-
newInstance
-
isOptimizeCollinearSteps
public boolean isOptimizeCollinearSteps() -
setOptimizeCollinearSteps
-
isSerializedContours
public static boolean isSerializedContours(int[] serialized) -
isSerializedContour
public static boolean isSerializedContour(int[] serialized, int offset) -
deserialize
-
serialize
public int[] serialize() -
isEmpty
public boolean isEmpty() -
numberOfContours
public int numberOfContours() -
clear
public void clear() -
clear
public void clear(boolean freeResources) -
openContourForAdding
Starts adding points of new contour.Note: most fields in the header may be not filled yet (they will be written in
closeContour(ContourHeader)
method). Butframe ID
it is an exception and must be filled now; it cannot be added while closing contour.- Parameters:
header
- header of new contour.
-
addPoint
-
addPoint
public void addPoint(long x, long y) -
addPoint
public void addPoint(long x, long y, boolean xAtMinXMatrixBoundary, boolean xAtMaxXMatrixBoundary, boolean yAtMinYMatrixBoundary, boolean yAtMaxYMatrixBoundary) -
closeContour
Finishes adding points and closes the contour.Note: touching matrix boundary flags, stored in the contour array, are defined by previous addPoint calls, not by these 4 flags from the header. Corresponding 4 flags in the passed header are ignored.
Containing rectangle
in the passed header is also ignored; instead, this function stores in the contour array the rectangle, calculated while previous addPoint calls.- Parameters:
header
- additional information about contour.
-
isContourOpened
public boolean isContourOpened() -
addContour
-
addContour
-
addContour
-
addContour
-
addContoursRange
-
addContour
-
contoursRange
-
addContours
-
addTransformedContours
public void addTransformedContours(Contours contours, double scaleX, double scaleY, double shiftX, double shiftY, boolean removeDegeneratedContours) -
transformContours
public Contours transformContours(double scaleX, double scaleY, double shiftX, double shiftY, boolean removeDegeneratedContours) -
removeContoursRange
public void removeContoursRange(int from, int to) -
removeSingleContour
public void removeSingleContour(int contourIndex) -
removeLastContour
public void removeLastContour() -
getContourNumberOfPoints
public int getContourNumberOfPoints(int contourIndex) -
getContourLength
public int getContourLength(int contourIndex) -
getContourOffset
public int getContourOffset(int contourIndex) -
getContourLengthAndOffset
public long getContourLengthAndOffset(int contourIndex) -
extractLength
public static int extractLength(long lengthAndOffset) -
extractOffset
public static int extractOffset(long lengthAndOffset) -
getSerializedHeaderOffset
public int getSerializedHeaderOffset(int contourIndex) -
getContour
-
getContourPoints
public int getContourPoints(int[] resultPoints, int contourIndex) -
getContourPointX
public double getContourPointX(int contourIndex, int pointIndex) -
getContourPointY
public double getContourPointY(int contourIndex, int pointIndex) -
getContourPointsAndReallocateResult
public int[] getContourPointsAndReallocateResult(int[] resultPoints, ContourLength resultLength, int contourIndex) -
unpackContour
-
unpackContour
-
unpackContourAndReallocateResult
public int[] unpackContourAndReallocateResult(int[] resultPoints, ContourLength resultLength, int contourIndex) -
unpackContourAndReallocateResult
public int[] unpackContourAndReallocateResult(int[] resultPoints, ContourLength resultLength, int contourIndex, boolean processDiagonalSegments) -
packContours
-
unpackContours
-
unpackContours
-
unpackContours
-
getHeader
-
getHeader
-
getObjectLabel
public int getObjectLabel(int contourIndex) -
setObjectLabel
public void setObjectLabel(int contourIndex, int label) -
getFrameIdOrNull
-
isInternalContour
public boolean isInternalContour(int contourIndex) -
getAllObjectLabels
public int[] getAllObjectLabels() -
getAllInternalContour
public boolean[] getAllInternalContour() -
getAllFrameId
public int[] getAllFrameId(int absentId) -
isPointStrictlyInside
public boolean isPointStrictlyInside(int contourIndex, double x, double y) -
isPointStrictlyInside
public boolean isPointStrictlyInside(int contourIndex, double x, double y, boolean surelyUnpacked) -
pointInsideContourStatus
public InsideContourStatus pointInsideContourStatus(int contourIndex, double x, double y, boolean surelyUnpacked) -
pointInsideContourInformation
public double pointInsideContourInformation(int contourIndex, double x, double y, boolean surelyUnpacked) -
findSomePointInside
-
findSomePointInside
-
findSomePointInside
-
findSomePointInside
-
strictPerimeter
public double strictPerimeter(int contourIndex) -
segmentCentersPerimeter
public double segmentCentersPerimeter(int contourIndex) -
strictArea
public double strictArea(int contourIndex) -
segmentCentersArea
public double segmentCentersArea(int contourIndex) -
preciseDoubledArea
public long preciseDoubledArea(int contourIndex) -
sortIndexesByLabels
public void sortIndexesByLabels(int[] indexes) -
sortIndexesByLabels
public void sortIndexesByLabels(int[] indexes, boolean internalContoursFirst) -
sortIndexesByPreciseArea
public void sortIndexesByPreciseArea(int[] indexes, boolean absoluteValueOfArea) -
sortIndexesByPreciseArea
public void sortIndexesByPreciseArea(int[] indexes, boolean absoluteValueOfArea, boolean greaterAreasFirst) -
equalsToSerialized
public boolean equalsToSerialized(int[] serialized) -
toString
-
equals
-
hashCode
public int hashCode() -
getContourNumberOfPoints
-
getContourPoints
-
getContourPointsAndReallocateResult
public static int[] getContourPointsAndReallocateResult(int[] resultPoints, ContourLength resultLength, IntArray contour) -
packContour
-
packContourAndReallocateResult
public static int[] packContourAndReallocateResult(int[] resultPoints, ContourLength resultLength, IntArray nonOptimizedContour) -
packContourAndReallocateResult
public static int[] packContourAndReallocateResult(int[] resultPoints, ContourLength resultLength, int[] nonOptimizedContour, int nonOptimizedOffset, int n) -
unpackContour
public static MutableIntArray unpackContour(IntArray optimizedContour, boolean processDiagonalSegments) -
unpackContour
public static int unpackContour(MutableIntArray resultContour, IntArray optimizedContour, boolean processDiagonalSegments) -
unpackContourAndReallocateResult
public static int[] unpackContourAndReallocateResult(int[] resultPoints, ContourLength resultLength, IntArray optimizedContour, boolean processDiagonalSegments) -
reverseContour
-
transformContour
public static MutableIntArray transformContour(MutableIntArray resultContour, IntArray contour, double scaleX, double scaleY, double shiftX, double shiftY) -
transformContour
public static void transformContour(int[] contour, int offset, int n, double scaleX, double scaleY, double shiftX, double shiftY) -
pointInsideContourInformation
public static double pointInsideContourInformation(int[] contour, int offset, int n, double x, double y, boolean surelyUnpacked) -
findSomePointInside
public static boolean findSomePointInside(Point2D result, int[] contour, int offset, int n, boolean surelyUnpacked) -
strictPerimeter
-
strictPerimeter
public static double strictPerimeter(int[] contour, int offset, int n) -
segmentCentersPerimeter
-
segmentCentersPerimeter
public static double segmentCentersPerimeter(int[] contour, int offset, int n) -
strictArea
-
strictArea
public static double strictArea(int[] contour, int offset, int n) -
segmentCentersArea
-
segmentCentersArea
public static double segmentCentersArea(int[] contour, int offset, int n) -
preciseDoubledArea
public static long preciseDoubledArea(int[] contour, int offset, int n)
-