Package org.tinfour.contour
Class ContourRegion
- java.lang.Object
-
- org.tinfour.contour.ContourRegion
-
public class ContourRegion extends Object
Provides a elements and access methods for a region created through a contour-building process.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContourRegion.ContourRegionTypeAn enumeration that indicates the type of a contour region.
-
Constructor Summary
Constructors Constructor Description ContourRegion(Contour contour)Construct a region based on a single, closed-loop contour.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(ContourRegion region)Adds a child (nested) region to the internal list and sets the child-region's parent link.doublegetAbsArea()Gets the absolute value of the area for this region.doublegetAbsoluteArea()Gets the absolute value of the overall area of the region.doublegetAdjustedArea()Get the area for the region excluding that of any enclosed regions.intgetApplicationIndex()Gets an application-defined index value to be used by the calling implementation to associate supplemental data with the region.doublegetArea()Gets the signed area of the region.ContourRegion.ContourRegionTypegetContourRegionType()Gets an enumerated value indicating what kind of contour region this instance represents.List<ContourRegion>getEnclosedRegions()Gets a list of regions that are enclosed by this region.ContourRegiongetParent()Gets the parent region for this region, if any.Path2DgetPath2D(AffineTransform transform)Gets a Path2D suitable for rendering purposes including both the outer polygon and any internal (nested child) polygons.Path2DgetPath2DWithoutNesting(AffineTransform transform)Gets a Path2D suitable for rendering purposes.intgetRegionIndex()Gets the index of the region.ContourRegion.ContourRegionTypegetRegionType()Gets an enumeration value indicating the region type.Point2DgetTestPoint()Gets a point lying on one of the segments in the region to support testing for polygon enclosures.double[]getXY()Get the XY coordinates for the contour region.booleanhasChildren()Indicates that the contour region encloses internal, child regions.booleanisPointInsideRegion(double[] xy, double x, double y)Indicates whether the specified point is inside a closed polygon.booleanisPointInsideRegion(double x, double y)Indicates whether the specified point is inside the regionvoidremoveChildren()Removes all child (nested) regions from the internal list and nullifies any of the child-region parent links.voidsetApplicationIndex(int applicationIndex)Allows a calling implementation to set an application-defined index value to be used to associate supplemental data with the regionvoidsetParent(ContourRegion parent)Sets the reference to the contour region that encloses the region represented by this class.StringtoString()
-
-
-
Constructor Detail
-
ContourRegion
public ContourRegion(Contour contour)
Construct a region based on a single, closed-loop contour.- Parameters:
contour- a valid instance describing a single, closed-loop contour.
-
-
Method Detail
-
getXY
public double[] getXY()
Get the XY coordinates for the contour region. Coordinates are stored in a one-dimensional array of doubles in the order:{ (x0,y0), (x1,y1), (x2,y2), etc. }.- Returns:
- a safe copy of the geometry of the contour region.
-
addChild
public void addChild(ContourRegion region)
Adds a child (nested) region to the internal list and sets the child-region's parent link.- Parameters:
region- a valid reference.
-
removeChildren
public void removeChildren()
Removes all child (nested) regions from the internal list and nullifies any of the child-region parent links.
-
setParent
public void setParent(ContourRegion parent)
Sets the reference to the contour region that encloses the region represented by this class. A null parent reference indicates that the region is not enclosed by another.- Parameters:
parent- a valid reference; or a null.
-
getParent
public ContourRegion getParent()
Gets the parent region for this region, if any. Regions that are enclosed in other regions will have a parent. Regions that are not enclosed will not have a parent.- Returns:
- a valid instance, or a null.
-
isPointInsideRegion
public boolean isPointInsideRegion(double x, double y)Indicates whether the specified point is inside the region- Parameters:
x- the Cartesian coordinate for the point of interesty- the Cartesian coordinate for the point of interest- Returns:
- true if the point is inside the contour; otherwise, fakse
-
isPointInsideRegion
public boolean isPointInsideRegion(double[] xy, double x, double y)Indicates whether the specified point is inside a closed polygon.- Parameters:
xy- an array giving the Cartesian coordinates of the closed, simple polygon for the region to be tested.x- the Cartesian coordinate for the point of interesty- the Cartesian coordinate for the point of interest- Returns:
- true if the point is inside the contour; otherwise, fakse
-
getAbsoluteArea
public double getAbsoluteArea()
Gets the absolute value of the overall area of the region. No adjustment is made for enclosed regions.- Returns:
- a positive value.
-
getAdjustedArea
public double getAdjustedArea()
Get the area for the region excluding that of any enclosed regions. The enclosed regions are not, strictly speaking, part of this region and, so, are not included in the adjusted area.- Returns:
- a positive value.
-
getArea
public double getArea()
Gets the signed area of the region. If the points that specify the region are given in a counter-clockwise order, the region will have a positive area. If the points are given in a clockwise order, the region will have a negative area.- Returns:
- a signed real value.
-
getAbsArea
public double getAbsArea()
Gets the absolute value of the area for this region.- Returns:
- a positve value greater than zero
-
getRegionIndex
public int getRegionIndex()
Gets the index of the region. The indexing scheme is based on the original values of the zContour array used when the contour regions were built. The minimum proper region index is zero.At this time, regions are not constructed for areas of null data. In future implementations, null-data regions will be indicated by a region index of -1.
- Returns:
- a positive integer value, or -1 for null-data regions.
-
getPath2DWithoutNesting
public Path2D getPath2DWithoutNesting(AffineTransform transform)
Gets a Path2D suitable for rendering purposes. The path includes only the outer polygon for the region and does not include the internal (nested) polygons. Because the contour builder class sorts polygons by descending area, this method will general attain the same effect as the conventional getPath2D() call when rendering the full set of regions. However, this method is not suitable in cases where interior regions are to be omitted or filled with a semi-transparent color.- Parameters:
transform- a valid AffineTransform, typically specified to map the Cartesian coordinates of the contour to pixel coordinate.- Returns:
- a valid instance
-
getPath2D
public Path2D getPath2D(AffineTransform transform)
Gets a Path2D suitable for rendering purposes including both the outer polygon and any internal (nested child) polygons. In used for fill operations, regions that include nested child regions will be rendered with "holes" where the child polygons are indicated.- Parameters:
transform- a valid AffineTransform, typically specified to map the Cartesian coordinates of the contour to pixel coordinate.- Returns:
- a valid instance
-
getTestPoint
public Point2D getTestPoint()
Gets a point lying on one of the segments in the region to support testing for polygon enclosures. Note that the test point is never one of the vertices of the segment.- Returns:
- a valid instance of a Point2D object
-
getEnclosedRegions
public List<ContourRegion> getEnclosedRegions()
Gets a list of regions that are enclosed by this region. This list includes only those regions that are immediately enclosed by this region, but does not include any that may be "nested" within the enclosed regions.- Returns:
- a valid, potentially empty, list.
-
getContourRegionType
public ContourRegion.ContourRegionType getContourRegionType()
Gets an enumerated value indicating what kind of contour region this instance represents.- Returns:
- a valid enumeration.
-
setApplicationIndex
public void setApplicationIndex(int applicationIndex)
Allows a calling implementation to set an application-defined index value to be used to associate supplemental data with the region- Parameters:
applicationIndex- an arbitrary, application-specific index value.
-
getApplicationIndex
public int getApplicationIndex()
Gets an application-defined index value to be used by the calling implementation to associate supplemental data with the region.- Returns:
- an arbitrary, application-specific index value.
-
getRegionType
public ContourRegion.ContourRegionType getRegionType()
Gets an enumeration value indicating the region type.- Returns:
- a valid instance.
-
hasChildren
public boolean hasChildren()
Indicates that the contour region encloses internal, child regions.- Returns:
- true if the region enclosed child regions; otherwise, false.
-
-