Class PolylineSplitMerge
public class PolylineSplitMerge extends Object
Fits a polyline to a contour by fitting the simplest model (3 sides) and adding more sides to it. The number of sides is increased until the number of sides reaches maxSides + extraConsider or it already has fit the contour to within the specified precision. It then merges lines together until no more can be merged.
When a side is added to the polygon it selects the side in which the score will be improved the most by splitting. The score is computed by computing the euclidean distance a point on the contour is from the line segment it belongs to. Note that distance from a line segment and not a line is found, thus if the closest point is past an end point the end point is used. The final score is the average distance.
A set of polylines is found and scored. The best polyline is the one with the best overall score. The overall score is found by summing up the average error across all line segments (sum of segment scores dividing by the number of segments) [1] and adding a fixed penalty for each line segment. Without a penalty the polyline with the largest number of sides will almost always be selected.
For a complete description of all parameters see the source code.
[1] Note that the score is NOT weighted based on the number of points in a line segment. This was done at one point at produced much worse results.
The polyline will always be in counter-clockwise ordering.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PolylineSplitMerge.CandidatePolyline
static class
PolylineSplitMerge.Corner
Corner in the polyline. -
Constructor Summary
Constructors Constructor Description PolylineSplitMerge()
-
Method Summary
Modifier and Type Method Description static void
assignLine(List<Point2D_I32> contour, int indexA, int indexB, LineParametric2D_F64 line)
Assigns the line so that it passes through points A and B.static void
assignLine(List<Point2D_I32> contour, int indexA, int indexB, LineSegment2D_F64 line)
@Nullable PolylineSplitMerge.CandidatePolyline
getBestPolyline()
Returns the polyline with the best score or null if it failed to fit a polylinedouble
getConvexTest()
double
getCornerScorePenalty()
ConfigLength
getExtraConsider()
int
getMaxNumberOfSideSamples()
ConfigLength
getMaxSideError()
int
getMaxSides()
int
getMinimumSideLength()
int
getMinSides()
DogArray<PolylineSplitMerge.CandidatePolyline>
getPolylines()
double
getThresholdSideSplitScore()
boolean
isConvex()
boolean
isLoops()
boolean
process(List<Point2D_I32> contour)
Process the contour and returns true if a polyline could be found.void
setConvex(boolean convex)
void
setConvexTest(double convexTest)
void
setCornerScorePenalty(double cornerScorePenalty)
void
setExtraConsider(ConfigLength extraConsider)
void
setLoops(boolean loops)
void
setMaxNumberOfSideSamples(int maxNumberOfSideSamples)
void
setMaxSideError(ConfigLength maxSideError)
void
setMaxSides(int maxSides)
void
setMinimumSideLength(int minimumSideLength)
void
setMinSides(int minSides)
void
setSplitter(SplitSelector splitter)
void
setThresholdSideSplitScore(double thresholdSideSplitScore)
-
Constructor Details
-
PolylineSplitMerge
public PolylineSplitMerge()
-
-
Method Details
-
process
Process the contour and returns true if a polyline could be found.- Parameters:
contour
- Contour. Must be a ordered in CW or CCW- Returns:
- true for success or false if one could not be fit
-
assignLine
public static void assignLine(List<Point2D_I32> contour, int indexA, int indexB, LineParametric2D_F64 line)Assigns the line so that it passes through points A and B. -
assignLine
public static void assignLine(List<Point2D_I32> contour, int indexA, int indexB, LineSegment2D_F64 line) -
getPolylines
-
getBestPolyline
Returns the polyline with the best score or null if it failed to fit a polyline -
setLoops
public void setLoops(boolean loops) -
isLoops
public boolean isLoops() -
isConvex
public boolean isConvex() -
setConvex
public void setConvex(boolean convex) -
getMaxSides
public int getMaxSides() -
setMaxSides
public void setMaxSides(int maxSides) -
getMinimumSideLength
public int getMinimumSideLength() -
setMinimumSideLength
public void setMinimumSideLength(int minimumSideLength) -
getCornerScorePenalty
public double getCornerScorePenalty() -
setCornerScorePenalty
public void setCornerScorePenalty(double cornerScorePenalty) -
getThresholdSideSplitScore
public double getThresholdSideSplitScore() -
setThresholdSideSplitScore
public void setThresholdSideSplitScore(double thresholdSideSplitScore) -
getMaxNumberOfSideSamples
public int getMaxNumberOfSideSamples() -
setMaxNumberOfSideSamples
public void setMaxNumberOfSideSamples(int maxNumberOfSideSamples) -
setSplitter
-
getMinSides
public int getMinSides() -
setMinSides
public void setMinSides(int minSides) -
getExtraConsider
-
setExtraConsider
-
getConvexTest
public double getConvexTest() -
setConvexTest
public void setConvexTest(double convexTest) -
getMaxSideError
-
setMaxSideError
-