Skip to content

Commit fd064ea

Browse files
committed
Merge branch 'master' into master
2 parents 01a927f + 664398e commit fd064ea

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ public class FilterContoursOperation implements Operation {
4545
private final SocketHint<List> solidityHint =
4646
SocketHints.Inputs.createNumberListRangeSocketHint("Solidity", 0, 100);
4747

48+
private final SocketHint<Number> minVertexHint =
49+
SocketHints.Inputs.createNumberSpinnerSocketHint("Min Vertices", 0, 0, Integer.MAX_VALUE);
50+
51+
private final SocketHint<Number> maxVertexHint =
52+
SocketHints.Inputs.createNumberSpinnerSocketHint("Max Vertices", 0, 1000000, Integer.MAX_VALUE);
53+
54+
private final SocketHint<Number> minRatioHint =
55+
SocketHints.Inputs.createNumberSpinnerSocketHint("Min Ratio", 0, 0, Integer.MAX_VALUE);
56+
57+
private final SocketHint<Number> maxRatioHint =
58+
SocketHints.Inputs.createNumberSpinnerSocketHint("Max Ratio", 1000, 0, Integer.MAX_VALUE);
59+
60+
4861
@Override
4962
public String getName() {
5063
return "Filter Contours";
@@ -76,6 +89,10 @@ public InputSocket<?>[] createInputSockets(EventBus eventBus) {
7689
new InputSocket<>(eventBus, minHeightHint),
7790
new InputSocket<>(eventBus, maxHeightHint),
7891
new InputSocket<>(eventBus, solidityHint),
92+
new InputSocket<>(eventBus, minVertexHint),
93+
new InputSocket<>(eventBus, maxVertexHint),
94+
new InputSocket<>(eventBus, minRatioHint),
95+
new InputSocket<>(eventBus, maxRatioHint),
7996
};
8097
}
8198

@@ -96,6 +113,11 @@ public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) {
96113
final double maxHeight = ((Number) inputs[6].getValue().get()).doubleValue();
97114
final double minSolidity = ((List<Number>) inputs[7].getValue().get()).get(0).doubleValue();
98115
final double maxSolidity = ((List<Number>) inputs[7].getValue().get()).get(1).doubleValue();
116+
final double minVertexCount = ((Number) inputs[8].getValue().get()).doubleValue();
117+
final double maxVertexCount = ((Number) inputs[9].getValue().get()).doubleValue();
118+
final double minRatio = ((Number) inputs[10].getValue().get()).doubleValue();
119+
final double maxRatio = ((Number) inputs[11].getValue().get()).doubleValue();
120+
99121

100122
final MatVector inputContours = inputSocket.getValue().get().getContours();
101123
final MatVector outputContours = new MatVector(inputContours.size());
@@ -119,6 +141,11 @@ public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) {
119141
final double solidity = 100 * area / contourArea(hull);
120142
if (solidity < minSolidity || solidity > maxSolidity) continue;
121143

144+
if(contour.rows() < minVertexCount || contour.rows() > maxVertexCount) continue;
145+
146+
final double ratio = bb.width() / bb.height();
147+
if (ratio < minRatio || ratio > maxRatio) continue;
148+
122149
outputContours.put(filteredContourCount++, contour);
123150
}
124151

0 commit comments

Comments
 (0)