public class Boundary2DSimpleMeasurer extends Boundary2DWrapper
Wrapper of a boundary scanner, that measures some simple parameters of every scanned boundary.
This class overrides only next()
and reset()
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 reset()
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 xaxis, yaxis 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.
All calculations are performed by this class in strictfp mode, so the results are absolutely identical on all platforms.
Modifier and Type  Class and Description 

static class 
Boundary2DSimpleMeasurer.ObjectParameter
The class describing what parameters of the connected object boundary should be measured by
Boundary2DSimpleMeasurer class. 
Boundary2DScanner.Side, Boundary2DScanner.Step
parent
Modifier and Type  Method and Description 

double 
area()
Returns the oriented area inside the contour, following along the scanned boundary.

double 
centroidX()
Returns the xcoordinate of the centroid (center of mass) of the figure,
lying inside the contour, following along the scanned boundary.

double 
centroidY()
Returns the ycoordinate of the centroid (center of mass) of the figure,
lying inside the contour, following along the scanned boundary.

ContourLineType 
contourLineType()
Returns the contour line style, used for measuring:
this class measures the object, lying inside this line.

static Boundary2DSimpleMeasurer 
getInstance(Boundary2DScanner parent,
ContourLineType contourLineType,
java.util.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 xcoordinate of all points at the contour, following along the scanned boundary.

double 
maxXMinusY()
Returns the maximal value of the difference x−y of coordinates of all points at the contour,
following along the scanned boundary.

double 
maxXPlusY()
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 ycoordinate of all points at the contour, following along the scanned boundary.

java.util.EnumSet<Boundary2DSimpleMeasurer.ObjectParameter> 
measuredParameters()
Returns the set of parameters, measured by this instance.

double 
minX()
Returns the minimal xcoordinate of all points at the contour, following along the scanned boundary.

double 
minXMinusY()
Returns the minimal value of the difference x−y of coordinates of all points at the contour,
following along the scanned boundary.

double 
minXPlusY()
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 ycoordinate 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 
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.

long 
pixelCount()
Returns the number of pixels inside the contour, following along the scanned boundary,
with minus sign if the scanned boundary is an internal one.

void 
reset()
This method is automatically called by
Boundary2DWrapper.nextBoundary() and
Boundary2DWrapper.goTo(long, long, net.algart.matrices.scanning.Boundary2DScanner.Side) methods
after calling the same methods of the parent scanner. 
java.lang.String 
toString()
Returns a brief string description of this object.

boundaryFinished, connectivityType, coordinatesChanged, currentIndexInArray, get, goTo, isAllBoundariesScanner, isInitialized, isMainBoundariesScanner, isMovedAlongBoundary, isSingleBoundaryScanner, lastStep, nestingLevel, nextBoundary, parent, side, stepCount, x, y
checkInterruption, getAllBoundariesScanner, getMainBoundariesScanner, getSingleBoundaryScanner, goToSamePosition, isInternalBoundary, matrix, scanBoundary, scanBoundary, updateProgress
public static Boundary2DSimpleMeasurer getInstance(Boundary2DScanner parent, ContourLineType contourLineType, java.util.EnumSet<Boundary2DSimpleMeasurer.ObjectParameter> measuredParameters)
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 by next()
method
and stay to be equal to their initial value.java.lang.NullPointerException
 if one of the arguments is null.contourLineType()
,
measuredParameters()
public ContourLineType contourLineType()
The returned reference is identical to the corresponding argument of
getInstance(Boundary2DScanner, ContourLineType, EnumSet)
method,
used for creating this instance.
public final java.util.EnumSet<Boundary2DSimpleMeasurer.ObjectParameter> measuredParameters()
next()
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.
public void reset()
Boundary2DWrapper
Boundary2DWrapper.nextBoundary()
and
Boundary2DWrapper.goTo(long, long, net.algart.matrices.scanning.Boundary2DScanner.Side)
methods
after calling the same methods of the parent scanner.
The default implementation does nothing.
This method can be overridden, for example, to initialize analysis of the next boundary
in the inheritor.reset
in class Boundary2DWrapper
public void next()
Boundary2DScanner
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 classes Boundary2DSimpleMeasurer
, Boundary2DProjectionMeasurer
.
next
in class Boundary2DWrapper
public long pixelCount()
It is the same value as area()
in a case
contourLineType()
==ContourLineType.STRICT_BOUNDARY
,
but it is available for any contour line type.
(For comparison, the result of perimeter()
call for ContourLineType.STRICT_BOUNDARY
can be retrieved for any contour line type by Boundary2DWrapper.stepCount()
method.)
STRICT_BOUNDARY
model, independently on the current
contourLineType()
.public double area()
Boundary2DScanner
class.)
In particular, if contourLineType()
==ContourLineType.STRICT_BOUNDARY
,
the result is equal to the total number of pixels of the
completion of the current measured object
(with minus sign if it is an internal boundary, i.e. when it is the number of pixels in the "hole").
In the case contourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
,
the measured area can be 0.0 — for example, for 1pixel objects (isolated pixels) or for
"thin" 1pixel "lines".
pixelCount()
public double perimeter()
In particular, if contourLineType()
==ContourLineType.STRICT_BOUNDARY
,
the result is just the number of next()
calls for this boundary and is equal
to the result of stepCount()
method.
In the case contourLineType()
==ContourLineType.SEGMENT_CENTERS_POLYLINE
,
the measured length is a good approximation for the real perimeter of the object.
public double minX()
If contourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
, the result
is equal to the minimal value of the result of x()
method since the last reset()
call.
If contourLineType()
==ContourLineType.STRICT_BOUNDARY
or
contourLineType()
==ContourLineType.SEGMENT_CENTERS_POLYLINE
, the result
is less by 0.5.
public double maxX()
If contourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
, the result
is equal to the maximal value of the result of x()
method since the last reset()
call.
If contourLineType()
==ContourLineType.STRICT_BOUNDARY
or
contourLineType()
==ContourLineType.SEGMENT_CENTERS_POLYLINE
, the result
is greater by 0.5.
public double minY()
If contourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
, the result
is equal to the minimal value of the result of y()
method since the last reset()
call.
If contourLineType()
==ContourLineType.STRICT_BOUNDARY
or
contourLineType()
==ContourLineType.SEGMENT_CENTERS_POLYLINE
, the result
is less by 0.5.
public double maxY()
If contourLineType()
==ContourLineType.PIXEL_CENTERS_POLYLINE
, the result
is equal to the maximal value of the result of y()
method since the last reset()
call.
If contourLineType()
==ContourLineType.STRICT_BOUNDARY
or
contourLineType()
==ContourLineType.SEGMENT_CENTERS_POLYLINE
, the result
is greater by 0.5.
public double minXPlusY()
public double maxXPlusY()
public double minXMinusY()
public double maxXMinusY()
public double centroidX()
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" 1pixel "lines"
in the case contourLineType()
==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".
public double centroidY()
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" 1pixel "lines"
in the case contourLineType()
==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".
public java.lang.String toString()
The result of this method may depend on implementation.
toString
in class Boundary2DScanner