Skip to content

Commit a90c8b1

Browse files
committed
Combine advanced filters into regular filter class
1 parent 4dda181 commit a90c8b1

3 files changed

Lines changed: 34 additions & 116 deletions

File tree

core/src/main/java/edu/wpi/grip/core/operations/Operations.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public static void addOperations(EventBus eventBus) {
2727
eventBus.post(new OperationAddedEvent(new HSLThresholdOperation()));
2828
eventBus.post(new OperationAddedEvent(new FindContoursOperation()));
2929
eventBus.post(new OperationAddedEvent(new FilterContoursOperation()));
30-
eventBus.post(new OperationAddedEvent(new AdvancedFilterContoursOperation()));
3130
eventBus.post(new OperationAddedEvent(new ConvexHullsOperation()));
3231
eventBus.post(new OperationAddedEvent(new FindBlobsOperation()));
3332
eventBus.post(new OperationAddedEvent(new FindLinesOperation()));

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

Lines changed: 0 additions & 115 deletions
This file was deleted.

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ 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 Vertex Count", 0, 0, Integer.MAX_VALUE);
50+
51+
private final SocketHint<Number> maxVertexHint =
52+
SocketHints.Inputs.createNumberSpinnerSocketHint("Max Vertex Count", 0, 1000, Integer.MAX_VALUE);
53+
54+
private final SocketHint<Boolean> forceConvexHint =
55+
SocketHints.createBooleanSocketHint("Force Convex", false);
56+
57+
private final SocketHint<Number> minRatioHint =
58+
SocketHints.Inputs.createNumberSpinnerSocketHint("Min Ratio", 0, 0, Integer.MAX_VALUE);
59+
60+
private final SocketHint<Number> maxRatioHint =
61+
SocketHints.Inputs.createNumberSpinnerSocketHint("Max Ratio", 1000, 0, Integer.MAX_VALUE);
62+
63+
4864
@Override
4965
public String getName() {
5066
return "Filter Contours";
@@ -76,6 +92,11 @@ public InputSocket<?>[] createInputSockets(EventBus eventBus) {
7692
new InputSocket<>(eventBus, minHeightHint),
7793
new InputSocket<>(eventBus, maxHeightHint),
7894
new InputSocket<>(eventBus, solidityHint),
95+
new InputSocket<>(eventBus, minVertexHint),
96+
new InputSocket<>(eventBus, maxVertexHint),
97+
new InputSocket<>(eventBus, forceConvexHint),
98+
new InputSocket<>(eventBus, minRatioHint),
99+
new InputSocket<>(eventBus, maxRatioHint),
79100
};
80101
}
81102

@@ -96,6 +117,12 @@ public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) {
96117
final double maxHeight = ((Number) inputs[6].getValue().get()).doubleValue();
97118
final double minSolidity = ((List<Number>) inputs[7].getValue().get()).get(0).doubleValue();
98119
final double maxSolidity = ((List<Number>) inputs[7].getValue().get()).get(1).doubleValue();
120+
final double minVertexCount = ((Number) inputs[8].getValue().get()).doubleValue();
121+
final double maxVertexCount = ((Number) inputs[9].getValue().get()).doubleValue();
122+
final boolean forceConvex = ((Boolean) inputs[10].getValue().get()).booleanValue();
123+
final double minRatio = ((Number) inputs[11].getValue().get()).doubleValue();
124+
final double maxRatio = ((Number) inputs[12].getValue().get()).doubleValue();
125+
99126

100127
final MatVector inputContours = inputSocket.getValue().get().getContours();
101128
final MatVector outputContours = new MatVector(inputContours.size());
@@ -119,6 +146,13 @@ public void perform(InputSocket<?>[] inputs, OutputSocket<?>[] outputs) {
119146
final double solidity = 100 * area / contourArea(hull);
120147
if (solidity < minSolidity || solidity > maxSolidity) continue;
121148

149+
if(contour.rows() < minVertexCount || contour.rows() > maxVertexCount) continue;
150+
151+
if(forceConvex && !isContourConvex(contour)) continue;
152+
153+
final double ratio = bb.width() / bb.height();
154+
if (ratio < minRatio || ratio > maxRatio) continue;
155+
122156
outputContours.put(filteredContourCount++, contour);
123157
}
124158

0 commit comments

Comments
 (0)