Class Boundary2DSimpleMeasurer
Wrapper of a boundary scanner, that measures some simple parameters of every scanned boundary.
This class overrides only next()
and resetCounters()
methods
of the abstract Boundary2DWrapper
class.
Namely, next()
method, after calling parent
.next()
,
corrects several internal fields, describing some parameters of the current measured object (more precisely,
parameters of its completions).
These fields are reset to initial values by resetCounters()
method.
After finishing scanning some boundary, for example, after
scanBoundary
call,
you may use the following access methods to get measured parameters:
area()
(the area of the current object),perimeter()
(the length of the contour of the object),minX()
,maxX()
,minY()
,maxY()
,minXPlusY()
,minXPlusY()
,minXMinusY()
,maxXMinusY()
(parameters of the minimal octagon, containing the measured object or "hole", with sides parallel to x-axis, y-axis and diagonals of the quadrants);centroidX()
,centroidY()
(coordinates of the centroid of the current object or "hole").
More precisely, this class measures the figure, bounded by some contour line,
following along the scanned boundary. The precise type of this line is specified by an argument
of ContourLineType
class, passed to the instantiation method:
getInstance(Boundary2DScanner, ContourLineType, java.util.EnumSet)
In the simplest case (ContourLineType.STRICT_BOUNDARY
), the contour line is just
the scanned boundary.
Please also note that not all parameters, available via area()
, perimeter()
and other
methods, are measured by this class. The set of parameters that should be really measured
is specified via EnumSet while creating the instance in the instantiation method.
You should not specify extra parameters, that are not needful: extra calculations can slow down
the scanning.
- Author:
- Daniel Alievsky
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The class describing what parameters of the connected object boundary should be measured byBoundary2DSimpleMeasurer
class.Nested classes/interfaces inherited from class net.algart.matrices.scanning.Boundary2DScanner
Boundary2DScanner.Side, Boundary2DScanner.Step
-
Field Summary
Fields inherited from class net.algart.matrices.scanning.Boundary2DWrapper
parent
-
Method Summary
Modifier and TypeMethodDescriptiondouble
area()
Returns the oriented area inside the contour, following along the scanned boundary.double
Returns the x-coordinate of the centroid (center of mass) of the figure, lying inside the contour, following along the scanned boundary.double
Returns the y-coordinate of the centroid (center of mass) of the figure, lying inside the contour, following along the scanned boundary.Returns the contour line style, used for measuring: this class measures the object, lying inside this line.static Boundary2DSimpleMeasurer
getInstance
(Boundary2DScanner parent, ContourLineType contourLineType, EnumSet<Boundary2DSimpleMeasurer.ObjectParameter> measuredParameters) Creates an instance of this class, that is based on the specified parent scanner and, while scanning any boundary by the parent scanner, measures the specified set of object parameters.double
maxX()
Returns the maximal x-coordinate of all points at the contour, following along the scanned boundary.double
Returns the maximal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.double
Returns the maximal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.double
maxY()
Returns the maximal y-coordinate of all points at the contour, following along the scanned boundary.Returns the set of parameters, measured by this instance.double
minX()
Returns the minimal x-coordinate of all points at the contour, following along the scanned boundary.double
Returns the minimal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.double
Returns the minimal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.double
minY()
Returns the minimal y-coordinate of all points at the contour, following along the scanned boundary.void
next()
Move the current position to the next segment of the currently scanned object boundary.double
Returns the total length of the contour, following along the scanned boundary: an estimated perimeter of the measured object, "drawn" at the bit matrix.void
Resets the counters, returned byBoundary2DScanner.stepCount()
andBoundary2DScanner.orientedArea()
method, and all other counters, that are possibly increased by inheritors of this class.toString()
Returns a brief string description of this object.Methods inherited from class net.algart.matrices.scanning.Boundary2DWrapper
atMatrixBoundary, boundaryFinished, connectivityType, coordinatesChanged, currentIndexInArray, diagonalStepCount, get, goTo, isAllBoundariesScanner, isInitialized, isMainBoundariesScanner, isMovedAlongBoundary, isSingleBoundaryScanner, lastStep, nestingLevel, nextBoundary, orientedArea, parent, rotationStepCount, side, stepCount, x, y
Methods inherited from class net.algart.matrices.scanning.Boundary2DScanner
area, checkInterruption, dimX, dimY, fillHoles, fillHoles, getAllBoundariesScanner, getMainBoundariesScanner, getSingleBoundaryScanner, goToSamePosition, isInternalBoundary, matrix, perimeter, scanBoundary, scanBoundary, straightStepCount, updateProgress
-
Method Details
-
getInstance
public static Boundary2DSimpleMeasurer getInstance(Boundary2DScanner parent, ContourLineType contourLineType, EnumSet<Boundary2DSimpleMeasurer.ObjectParameter> measuredParameters) Creates an instance of this class, that is based on the specified parent scanner and, while scanning any boundary by the parent scanner, measures the specified set of object parameters.- Parameters:
parent
- the parent scanner.contourLineType
- the style of the contour line: the created object will measure the object, lying inside this line.measuredParameters
- the set of parameters that should be measured: all parameters, which are not inside this set, are not modified bynext()
method and stay to be equal to their initial value.- Returns:
- new instance of this class.
- Throws:
NullPointerException
- if one of the arguments is null.- See Also:
-
contourLineType
Returns the contour line style, used for measuring: this class measures the object, lying inside this line.The returned reference is identical to the corresponding argument of
getInstance(Boundary2DScanner, ContourLineType, EnumSet)
method, used for creating this instance.- Returns:
- the contour line style, used for measuring by this instance.
-
measuredParameters
Returns the set of parameters, measured by this instance. All parameters, which are not inside this set, are not modified bynext()
method and stay to be equal to their initial value.The returned set is a clone of the corresponding argument of
getInstance(Boundary2DScanner, ContourLineType, EnumSet)
method, used for creating this instance.- Returns:
- the set of parameters, measured by this instance.
-
resetCounters
public void resetCounters()Description copied from class:Boundary2DScanner
Resets the counters, returned byBoundary2DScanner.stepCount()
andBoundary2DScanner.orientedArea()
method, and all other counters, that are possibly increased by inheritors of this class. This method is automatically called at the end ofBoundary2DScanner.nextBoundary()
andBoundary2DScanner.goTo(long, long, net.algart.matrices.scanning.Boundary2DScanner.Side)
methods.- Overrides:
resetCounters
in classBoundary2DWrapper
-
next
public void next()Description copied from class:Boundary2DScanner
Move the current position to the next segment of the currently scanned object boundary. External boundaries are scanned in clockwise order, internal boundaries in anticlockwise order (if we suppose that the x axis is directed rightwards and the y axis is directed downwards).If the current position does not correspond to an object boundary, the position will be changed to some unknown position near the current one (precise behavior is not specified).
In addition to switching to the next position, this method can do something else: see comments to methods
getSingleBoundaryScanner
,getAllBoundariesScanner
,getMainBoundariesScanner
, and comments to classesBoundary2DSimpleMeasurer
,Boundary2DProjectionMeasurer
.- Overrides:
next
in classBoundary2DWrapper
-
area
public double area()Returns the oriented area inside the contour, following along the scanned boundary. "Oriented" means that the result is equal to the area of the figure inside this contour, Equivalent toarea
(thisObject.contourLineType()
).- Returns:
- the oriented area inside the scanned contour.
-
perimeter
public double perimeter()Returns the total length of the contour, following along the scanned boundary: an estimated perimeter of the measured object, "drawn" at the bit matrix. Equivalent toperimeter
(thisObject.contourLineType()
).- Returns:
- the length of the contour line, following along the scanned boundary.
-
minX
public double minX()Returns the minimal x-coordinate of all points at the contour, following along the scanned boundary.If
contourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
, the result is equal to the minimal value of the result ofx()
method since the lastresetCounters()
call. IfcontourLineType()
==ContourLineType.STRICT_BOUNDARY
orcontourLineType()
==ContourLineType.SEGMENT_CENTERS_POLYLINE
, the result is less by 0.5.- Returns:
- the minimal x-coordinate of all points at the contour, following along the scanned boundary.
-
maxX
public double maxX()Returns the maximal x-coordinate of all points at the contour, following along the scanned boundary.If
contourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
, the result is equal to the maximal value of the result ofx()
method since the lastresetCounters()
call. IfcontourLineType()
==ContourLineType.STRICT_BOUNDARY
orcontourLineType()
==ContourLineType.SEGMENT_CENTERS_POLYLINE
, the result is greater by 0.5.- Returns:
- the maximal x-coordinate of all points at the contour, following along the scanned boundary.
-
minY
public double minY()Returns the minimal y-coordinate of all points at the contour, following along the scanned boundary.If
contourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
, the result is equal to the minimal value of the result ofy()
method since the lastresetCounters()
call. IfcontourLineType()
==ContourLineType.STRICT_BOUNDARY
orcontourLineType()
==ContourLineType.SEGMENT_CENTERS_POLYLINE
, the result is less by 0.5.- Returns:
- the minimal x-coordinate of all points at the contour, following along the scanned boundary.
-
maxY
public double maxY()Returns the maximal y-coordinate of all points at the contour, following along the scanned boundary.If
contourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
, the result is equal to the maximal value of the result ofy()
method since the lastresetCounters()
call. IfcontourLineType()
==ContourLineType.STRICT_BOUNDARY
orcontourLineType()
==ContourLineType.SEGMENT_CENTERS_POLYLINE
, the result is greater by 0.5.- Returns:
- the maximal y-coordinate of all points at the contour, following along the scanned boundary.
-
minXPlusY
public double minXPlusY()Returns the minimal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.- Returns:
- the minimal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.
-
maxXPlusY
public double maxXPlusY()Returns the maximal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.- Returns:
- the maximal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.
-
minXMinusY
public double minXMinusY()Returns the minimal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.- Returns:
- the minimal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.
-
maxXMinusY
public double maxXMinusY()Returns the maximal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.- Returns:
- the maximal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.
-
centroidX
public double centroidX()Returns the x-coordinate of the centroid (center of mass) of the figure, lying inside the contour, following along the scanned boundary.Note that the centroid may be undefined for some styles of contours, if the area of the figure inside the contour, returned by
area()
method, is zero. For example, it is possible for "thin" 1-pixel "lines" in the casecontourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
. In this case, this method returns Double.NaN.Also note: if it is an internal boundary, it is the centroid of a "hole".
- Returns:
- the x-coordinate of the centroid of the figure the contour, following along the scanned boundary.
-
centroidY
public double centroidY()Returns the y-coordinate of the centroid (center of mass) of the figure, lying inside the contour, following along the scanned boundary.Note that the centroid may be undefined for some styles of contours, if the area of the figure inside the contour, returned by
area()
method, is zero. For example, it is possible for "thin" 1-pixel "lines" in the casecontourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
. In this case, this method returns Double.NaN.Also note: if it is an internal boundary, it is the centroid of a "hole".
- Returns:
- the y-coordinate of the centroid of the figure the contour, following along the scanned boundary.
-
toString
Returns a brief string description of this object.The result of this method may depend on implementation.
- Overrides:
toString
in classBoundary2DScanner
- Returns:
- a brief string description of this object.
-