|
1 | 1 | package edu.wpi.grip.core.operations;
|
2 | 2 |
|
| 3 | +import com.google.common.collect.ImmutableList; |
3 | 4 | import com.google.common.eventbus.EventBus;
|
| 5 | +import com.google.inject.Inject; |
| 6 | +import com.google.inject.Singleton; |
| 7 | +import com.google.inject.name.Named; |
| 8 | +import edu.wpi.grip.core.Operation; |
4 | 9 | import edu.wpi.grip.core.events.OperationAddedEvent;
|
5 | 10 | import edu.wpi.grip.core.operations.composite.*;
|
6 |
| -import edu.wpi.grip.core.operations.networktables.NTNumber; |
7 |
| -import edu.wpi.grip.core.operations.networktables.NTPublishOperation; |
8 |
| -import edu.wpi.grip.core.operations.networktables.NTVector2D; |
| 11 | +import edu.wpi.grip.core.operations.network.BooleanPublishable; |
| 12 | +import edu.wpi.grip.core.operations.network.Manager; |
| 13 | +import edu.wpi.grip.core.operations.network.NumberPublishable; |
| 14 | +import edu.wpi.grip.core.operations.network.Vector2D; |
| 15 | +import edu.wpi.grip.core.operations.network.networktables.NTKeyValuePublishOperation; |
| 16 | +import edu.wpi.grip.core.operations.network.ros.ROSKeyValuePublishOperation; |
9 | 17 | import edu.wpi.grip.core.operations.opencv.MatFieldAccessor;
|
10 | 18 | import edu.wpi.grip.core.operations.opencv.MinMaxLoc;
|
11 | 19 | import edu.wpi.grip.core.operations.opencv.NewPointOperation;
|
12 | 20 | import edu.wpi.grip.core.operations.opencv.NewSizeOperation;
|
13 | 21 |
|
14 |
| -import static org.bytedeco.javacpp.opencv_core.*; |
| 22 | +import java.util.function.Supplier; |
15 | 23 |
|
16 |
| -public final class Operations { |
| 24 | +import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | +import static org.bytedeco.javacpp.opencv_core.Point; |
| 26 | +import static org.bytedeco.javacpp.opencv_core.Size; |
17 | 27 |
|
18 |
| - private Operations() { /* no op */} |
| 28 | +@Singleton |
| 29 | +public class Operations { |
| 30 | + private final EventBus eventBus; |
| 31 | + private final ImmutableList<Supplier<Operation>> operations; |
19 | 32 |
|
20 |
| - public static void addOperations(EventBus eventBus) { |
21 |
| - // Add the default built-in operations to the palette |
22 |
| - eventBus.post(new OperationAddedEvent(new ResizeOperation())); |
23 |
| - eventBus.post(new OperationAddedEvent(new BlurOperation())); |
24 |
| - eventBus.post(new OperationAddedEvent(new DesaturateOperation())); |
25 |
| - eventBus.post(new OperationAddedEvent(new RGBThresholdOperation())); |
26 |
| - eventBus.post(new OperationAddedEvent(new HSVThresholdOperation())); |
27 |
| - eventBus.post(new OperationAddedEvent(new HSLThresholdOperation())); |
28 |
| - eventBus.post(new OperationAddedEvent(new FindContoursOperation())); |
29 |
| - eventBus.post(new OperationAddedEvent(new FilterContoursOperation())); |
30 |
| - eventBus.post(new OperationAddedEvent(new ConvexHullsOperation())); |
31 |
| - eventBus.post(new OperationAddedEvent(new FindBlobsOperation())); |
32 |
| - eventBus.post(new OperationAddedEvent(new FindLinesOperation())); |
33 |
| - eventBus.post(new OperationAddedEvent(new FilterLinesOperation())); |
34 |
| - eventBus.post(new OperationAddedEvent(new MaskOperation())); |
35 |
| - eventBus.post(new OperationAddedEvent(new MinMaxLoc())); |
36 |
| - eventBus.post(new OperationAddedEvent(new MatFieldAccessor())); |
37 |
| - eventBus.post(new OperationAddedEvent(new NewPointOperation())); |
38 |
| - eventBus.post(new OperationAddedEvent(new NewSizeOperation())); |
39 |
| - eventBus.post(new OperationAddedEvent(new NTPublishOperation<>(Number.class, NTNumber.class, NTNumber::new))); |
40 |
| - eventBus.post(new OperationAddedEvent(new NTPublishOperation<>(Point.class, NTVector2D.class, NTVector2D::new))); |
41 |
| - eventBus.post(new OperationAddedEvent(new NTPublishOperation<>(Size.class, NTVector2D.class, NTVector2D::new))); |
42 |
| - eventBus.post(new OperationAddedEvent(new NTPublishOperation<>(ContoursReport.class))); |
43 |
| - eventBus.post(new OperationAddedEvent(new NTPublishOperation<>(BlobsReport.class))); |
44 |
| - eventBus.post(new OperationAddedEvent(new NTPublishOperation<>(LinesReport.class))); |
45 |
| - eventBus.post(new OperationAddedEvent(new PublishVideoOperation())); |
46 |
| - eventBus.post(new OperationAddedEvent(new DistanceTransformOperation())); |
47 |
| - eventBus.post(new OperationAddedEvent(new NormalizeOperation())); |
48 |
| - eventBus.post(new OperationAddedEvent(new WatershedOperation())); |
| 33 | + @Inject |
| 34 | + Operations(EventBus eventBus, @Named("ntManager") Manager ntManager, @Named("rosManager") Manager rosManager) { |
| 35 | + this.eventBus = checkNotNull(eventBus, "EventBus cannot be null"); |
| 36 | + checkNotNull(ntManager, "ntManager cannot be null"); |
| 37 | + checkNotNull(rosManager, "rosManager cannot be null"); |
| 38 | + this.operations = ImmutableList.of( |
| 39 | + ResizeOperation::new, |
| 40 | + BlurOperation::new, |
| 41 | + DesaturateOperation::new, |
| 42 | + RGBThresholdOperation::new, |
| 43 | + HSVThresholdOperation::new, |
| 44 | + HSLThresholdOperation::new, |
| 45 | + FindContoursOperation::new, |
| 46 | + FilterContoursOperation::new, |
| 47 | + ConvexHullsOperation::new, |
| 48 | + FindBlobsOperation::new, |
| 49 | + FindLinesOperation::new, |
| 50 | + FilterLinesOperation::new, |
| 51 | + MaskOperation::new, |
| 52 | + MinMaxLoc::new, |
| 53 | + MatFieldAccessor::new, |
| 54 | + NewPointOperation::new, |
| 55 | + NewSizeOperation::new, |
| 56 | + () -> new NTKeyValuePublishOperation<Number, NumberPublishable, Number>(ntManager, NumberPublishable::new) { |
| 57 | + }, |
| 58 | + () -> new NTKeyValuePublishOperation<Boolean, BooleanPublishable, Boolean>(ntManager, BooleanPublishable::new) { |
| 59 | + }, |
| 60 | + () -> new NTKeyValuePublishOperation<Point, Vector2D, Double>(ntManager, Vector2D::new) { |
| 61 | + }, |
| 62 | + () -> new NTKeyValuePublishOperation<Size, Vector2D, Double>(ntManager, Vector2D::new) { |
| 63 | + }, |
| 64 | + () -> new NTKeyValuePublishOperation<ContoursReport, ContoursReport, double[]>(ntManager) { |
| 65 | + }, |
| 66 | + () -> new NTKeyValuePublishOperation<BlobsReport, BlobsReport, double[]>(ntManager) { |
| 67 | + }, |
| 68 | + () -> new NTKeyValuePublishOperation<LinesReport, LinesReport, double[]>(ntManager) { |
| 69 | + }, |
| 70 | + () -> new ROSKeyValuePublishOperation<Number, NumberPublishable, Number>(ntManager, NumberPublishable::new) { |
| 71 | + }, |
| 72 | + () -> new ROSKeyValuePublishOperation<Boolean, BooleanPublishable, Boolean>(ntManager, BooleanPublishable::new) { |
| 73 | + }, |
| 74 | + () -> new ROSKeyValuePublishOperation<Point, Vector2D, Double>(ntManager, Vector2D::new) { |
| 75 | + }, |
| 76 | + () -> new ROSKeyValuePublishOperation<Size, Vector2D, Double>(ntManager, Vector2D::new) { |
| 77 | + }, |
| 78 | + () -> new ROSKeyValuePublishOperation<ContoursReport, ContoursReport, double[]>(ntManager) { |
| 79 | + }, |
| 80 | + () -> new ROSKeyValuePublishOperation<BlobsReport, BlobsReport, double[]>(ntManager) { |
| 81 | + }, |
| 82 | + () -> new ROSKeyValuePublishOperation<LinesReport, LinesReport, double[]>(ntManager) { |
| 83 | + }, |
| 84 | + PublishVideoOperation::new, |
| 85 | + DistanceTransformOperation::new, |
| 86 | + NormalizeOperation::new, |
| 87 | + WatershedOperation::new |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public void addOperations() { |
| 92 | + operations.stream() |
| 93 | + .map(s -> s.get()) |
| 94 | + .map(OperationAddedEvent::new) |
| 95 | + .forEach(eventBus::post); |
49 | 96 | }
|
50 | 97 | }
|
0 commit comments