Skip to content

Commit 6807ab8

Browse files
committed
add comments to Contour class in response to confused email
1 parent f25fe8d commit 6807ab8

1 file changed

Lines changed: 61 additions & 6 deletions

File tree

src/gab/opencv/Contour.java

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ public void loadPoints(Point[] pts){
5151
}
5252
}
5353

54+
/**
55+
* Check if the Contour contains a given x-y point.
56+
* Particularly, useful for interaction via mouseX and mouseY.
57+
*
58+
* @param x
59+
* @param y
60+
* @return boolean
61+
*/
5462
public boolean containsPoint(int x, int y){
5563
Point p = new Point(x,y);
5664
MatOfPoint2f m = new MatOfPoint2f(pointMat.toArray());
@@ -59,26 +67,50 @@ public boolean containsPoint(int x, int y){
5967
return r == 1;
6068
}
6169

62-
// The polygonApproximationFactor is used to determine
63-
// how strictly to follow a curvy polygon when converting
64-
// it into a simpler polygon with getPolygonApproximation().
65-
// For advanced use only. Set to a sane value by default.
70+
/**
71+
* The polygonApproximationFactor is used to determine
72+
* how strictly to follow a curvy polygon when converting
73+
* it into a simpler polygon with getPolygonApproximation().
74+
* For advanced use only. Set to a sane value by default.
75+
*
76+
* @param polygonApproximationFactor, a double
77+
*/
6678
public void setPolygonApproximationFactor(double polygonApproximationFactor){
6779
this.polygonApproximationFactor = polygonApproximationFactor;
6880
}
6981

82+
/**
83+
* Access the current polygonApproximationFactor. The polygonApproximationFactor
84+
* is used to determine how strictly to follow a curvy polygon when converting
85+
* it into a simpler polygon with getPolygonApproximation().
86+
*
87+
* @return polygonApproximationFactor, a double
88+
*/
7089
public double getPolygonApproximationFactor(){
7190
return polygonApproximationFactor;
7291
}
7392

93+
/**
94+
* Get a new Contour that results from calculating
95+
* the polygon approximation of the current Contour.
96+
* The tightness of the approximation is set by the polygonApproximationFactor,
97+
* See setPolygonApproximationFactor() and getPolygonApproximationFactor().
98+
*
99+
* @return
100+
*/
74101
public Contour getPolygonApproximation(){
75102
MatOfPoint2f approx = new MatOfPoint2f();
76103
Imgproc.approxPolyDP(new MatOfPoint2f(inputPoints), approx, polygonApproximationFactor, true);
77104
return new Contour(parent, approx);
78105
}
79106

107+
/**
108+
* Calculate a convex hull from the current Contour.
109+
* Returns a new Contour representing the convex hull.
110+
*
111+
* @return Contour
112+
*/
80113
public Contour getConvexHull(){
81-
82114
MatOfInt hull = new MatOfInt();
83115
MatOfPoint points = new MatOfPoint(pointMat);
84116

@@ -96,6 +128,10 @@ public Contour getConvexHull(){
96128
return new Contour(parent, hullPoints);
97129
}
98130

131+
/**
132+
* Draw the Contour as a closed shape with one vertex per-point.
133+
*
134+
*/
99135
public void draw(){
100136
parent.beginShape();
101137
for (PVector p : points) {
@@ -104,19 +140,38 @@ public void draw(){
104140
parent.endShape(PConstants.CLOSE);
105141

106142
}
107-
143+
/**
144+
* Get the points that make up the Contour.
145+
*
146+
* @return ArrayList<PVector> points
147+
*/
108148
public ArrayList<PVector> getPoints(){
109149
return points;
110150
}
111151

152+
/**
153+
* The number of points in the Contour.
154+
*
155+
* @return int
156+
*/
112157
public int numPoints(){
113158
return points.size();
114159
}
115160

161+
/**
162+
* Get the bounding box for the Contour.
163+
*
164+
* @return A java.awt.Rectangle
165+
*/
116166
public Rectangle getBoundingBox(){
117167
return boundingBox;
118168
}
119169

170+
/**
171+
* The area of the Contour's bounding box. In most cases, this is a good approximation for the Contour's area.
172+
*
173+
* @return float area
174+
*/
120175
public float area(){
121176
return (boundingBox.width * boundingBox.height);
122177
}

0 commit comments

Comments
 (0)