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
FieldsModifier and TypeFieldDescriptionstatic final intContours array consists of blocks (lines), where each block containsBLOCK_LENGTH= 2 elements.static final intstatic final intNumber of points, saved in the contour, cannot be greater than 1073741567 ~ 230.static final intMaximal 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 intCoordinates of points, saved in the contour, cannot be out of range -0x40000000 ≤ x, y ≤0x3FFFFFFF It allows to guarantee thatcontaining rectangleof each contour has sizes, less than Integer.MAX_VALUE. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContour(ContourHeader header, int[] contour) voidaddContour(ContourHeader header, int[] contour, int contourOffset, int contourLength) voidaddContour(ContourHeader header, IntArray contour) voidaddContour(ContourHeader header, IntArray contour, boolean packAddedContour) voidaddContour(Contours contours, int contourIndex) voidaddContours(Contours contours) voidaddContoursRange(Contours contours, int from, int to) voidaddPoint(long x, long y) voidaddPoint(long x, long y, boolean xAtMinXMatrixBoundary, boolean xAtMaxXMatrixBoundary, boolean yAtMinYMatrixBoundary, boolean yAtMaxYMatrixBoundary) voidaddPoint(Boundary2DScanner scanner, long startX, long startY) voidaddTransformedContours(Contours contours, double scaleX, double scaleY, double shiftX, double shiftY, boolean removeDegeneratedContours) voidclear()voidclear(boolean freeResources) voidcloseContour(ContourHeader header) Finishes adding points and closes the contour.contoursRange(int from, int to) static Contoursdeserialize(int[] serialized) booleanbooleanequalsToSerialized(int[] serialized) static intextractLength(long lengthAndOffset) static intextractOffset(long lengthAndOffset) findSomePointInside(int contourIndex) findSomePointInside(int contourIndex, boolean surelyUnpacked) booleanfindSomePointInside(Point2D result, int contourIndex) static booleanfindSomePointInside(Point2D result, int[] contour, int offset, int n, boolean surelyUnpacked) booleanfindSomePointInside(Point2D result, int contourIndex, boolean surelyUnpacked) int[]getAllFrameId(int absentId) boolean[]int[]getContour(int contourIndex) intgetContourLength(int contourIndex) longgetContourLengthAndOffset(int contourIndex) intgetContourNumberOfPoints(int contourIndex) static intgetContourNumberOfPoints(IntArray contour) intgetContourOffset(int contourIndex) intgetContourPoints(int[] resultPoints, int contourIndex) static intgetContourPoints(int[] resultPoints, IntArray contour) int[]getContourPointsAndReallocateResult(int[] resultPoints, ContourLength resultLength, int contourIndex) static int[]getContourPointsAndReallocateResult(int[] resultPoints, ContourLength resultLength, IntArray contour) doublegetContourPointX(int contourIndex, int pointIndex) doublegetContourPointY(int contourIndex, int pointIndex) getFrameIdOrNull(int contourIndex) getHeader(int contourIndex) getHeader(ContourHeader resultHeader, int contourIndex) intgetObjectLabel(int contourIndex) intgetSerializedHeaderOffset(int contourIndex) inthashCode()booleanbooleanisEmpty()booleanisInternalContour(int contourIndex) booleanbooleanisPointStrictlyInside(int contourIndex, double x, double y) booleanisPointStrictlyInside(int contourIndex, double x, double y, boolean surelyUnpacked) static booleanisSerializedContour(int[] serialized, int offset) static booleanisSerializedContours(int[] serialized) static ContoursintvoidopenContourForAdding(ContourHeader header) Starts adding points of new contour.static intpackContour(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 doublepointInsideContourInformation(int[] contour, int offset, int n, double x, double y, boolean surelyUnpacked) doublepointInsideContourInformation(int contourIndex, double x, double y, boolean surelyUnpacked) pointInsideContourStatus(int contourIndex, double x, double y, boolean surelyUnpacked) longpreciseDoubledArea(int contourIndex) static longpreciseDoubledArea(int[] contour, int offset, int n) voidremoveContoursRange(int from, int to) voidvoidremoveSingleContour(int contourIndex) static MutableIntArrayreverseContour(MutableIntArray resultContour, IntArray contour) doublesegmentCentersArea(int contourIndex) static doublesegmentCentersArea(int[] contour, int offset, int n) static doublesegmentCentersArea(IntArray contour) doublesegmentCentersPerimeter(int contourIndex) static doublesegmentCentersPerimeter(int[] contour, int offset, int n) static doublesegmentCentersPerimeter(IntArray contour) int[]voidsetObjectLabel(int contourIndex, int label) setOptimizeCollinearSteps(boolean optimizeCollinearSteps) voidsortIndexesByLabels(int[] indexes) voidsortIndexesByLabels(int[] indexes, boolean internalContoursFirst) voidsortIndexesByPreciseArea(int[] indexes, boolean absoluteValueOfArea) voidsortIndexesByPreciseArea(int[] indexes, boolean absoluteValueOfArea, boolean greaterAreasFirst) doublestrictArea(int contourIndex) static doublestrictArea(int[] contour, int offset, int n) static doublestrictArea(IntArray contour) doublestrictPerimeter(int contourIndex) static doublestrictPerimeter(int[] contour, int offset, int n) static doublestrictPerimeter(IntArray contour) toString()static voidtransformContour(int[] contour, int offset, int n, double scaleX, double scaleY, double shiftX, double shiftY) static MutableIntArraytransformContour(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 MutableIntArrayunpackContour(IntArray optimizedContour, boolean processDiagonalSegments) static intunpackContour(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 rectangleof 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 IDit 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 rectanglein 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)
-