-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinteractiveContours.pde
59 lines (45 loc) · 1.17 KB
/
interactiveContours.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public class InteractiveContour {
Contour ct;
ArrayList<PVector> blobPts;
PVector centerPt;
Rectangle bondingBox;
public InteractiveContour(Contour t_contour) {
this.ct = t_contour;
bondingBox = this.ct.getBoundingBox();
blobPts = new ArrayList<PVector>();
smoothContour();
}
public void smoothContour() {
ct.setPolygonApproximationFactor(max( (float)ct.getPolygonApproximationFactor()*0.2 , 0.1));
blobPts = ct.getPolygonApproximation().getPoints();
}
public void calculatePolyCenter() {
float x = 0.;
float y = 0.;
int pointCount = 0;
for (PVector point : blobPts) {
x += point.x;
y += point.y;
pointCount++;
}
x = x/(float)pointCount;
y = y/(float)pointCount;
centerPt = new PVector(x, y);
}
public PVector getCenterPoint() {
calculatePolyCenter();
return centerPt;
}
public Rectangle getBoundingBox(){
return bondingBox;
}
public float area() {
return ct.area();
}
public ArrayList<PVector> getPoints() {
return blobPts;
}
public boolean isInside(PVector pos) {
return ct.containsPoint((int)pos.x, (int)pos.y);
}
}