diff --git a/core/src/main/java/edu/wpi/grip/core/Description.java b/core/src/main/java/edu/wpi/grip/core/Description.java new file mode 100644 index 0000000000..60e7d8178f --- /dev/null +++ b/core/src/main/java/edu/wpi/grip/core/Description.java @@ -0,0 +1,49 @@ +package edu.wpi.grip.core; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static edu.wpi.grip.core.OperationDescription.Category; +import static edu.wpi.grip.core.OperationDescription.Category.MISCELLANEOUS; + +/** + * Annotates an {@link Operation} subclass to describe it. This annotation gets transformed into a + * {@link OperationDescription}. All operation classes with this annotation will be automatically + * discovered and added to the palette at startup. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Description { + + /** + * The name of the operation being described. + */ + String name(); + + /** + * A brief summary of the operation. In-depth descriptions, usage guides, and examples + * should be on the wiki, not here. + */ + String summary(); + + /** + * The category the operation belongs to. Defaults to + * {@link OperationDescription.Category#MISCELLANEOUS MISCELLANEOUS}. + */ + Category category() default MISCELLANEOUS; + + /** + * All known aliases of the operation. If the name of the operation changes, the previous name + * should be here. Defaults to an empty array. + */ + String[] aliases() default {}; + + /** + * The name of the icon to use to display the operation. If empty ({@code ""}), no icon will be + * shown. The icon should be located in {@code /edu/wpi/grip/ui/icons/}. + */ + String iconName() default ""; + +} diff --git a/core/src/main/java/edu/wpi/grip/core/OperationDescription.java b/core/src/main/java/edu/wpi/grip/core/OperationDescription.java index 6647c3b996..8025b47c15 100644 --- a/core/src/main/java/edu/wpi/grip/core/OperationDescription.java +++ b/core/src/main/java/edu/wpi/grip/core/OperationDescription.java @@ -27,6 +27,33 @@ public class OperationDescription { private final Icon icon; private final ImmutableSet aliases; + /** + * Creates an operation description from a {@link Description @Description} annotation on + * an operation subclass. + */ + public static OperationDescription from(Description description) { + checkNotNull(description, "The description annotation cannot be null"); + String iconName = description.iconName(); + return builder() + .name(description.name()) + .summary(description.summary()) + .category(description.category()) + .aliases(description.aliases()) + .icon(iconName.isEmpty() ? null : Icon.iconStream(iconName)) + .build(); + } + + /** + * Creates an operation description from a {@link Description @Description} annotation on + * an operation subclass. The class is assumed to have the annotation; be careful when using this + * method. + * + * @param clazz the class to generate a description for + */ + public static OperationDescription from(Class clazz) { + return from(clazz.getAnnotation(Description.class)); + } + /** * Private constructor - use {@link #builder} to instantiate this class. */ @@ -182,7 +209,7 @@ public Builder category(Category category) { } /** - * Sets the icon. + * Sets the icon. If {@code null}, the operation will have no icon. */ public Builder icon(Icon icon) { this.icon = icon; diff --git a/core/src/main/java/edu/wpi/grip/core/operations/CVOperations.java b/core/src/main/java/edu/wpi/grip/core/operations/CVOperations.java index cfd426b5dd..af12ad0da7 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/CVOperations.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/CVOperations.java @@ -366,7 +366,8 @@ public class CVOperations { )), new OperationMetaData(CVOperation.defaults("CV Threshold", - "Apply a fixed-level threshold to each array element in an image."), + "Apply a fixed-level threshold to each array element in an image.", + "CV threshold"), templateFactory.create( SocketHints.Inputs.createMatSocketHint("src", false), SocketHints.Inputs.createNumberSpinnerSocketHint("thresh", 0), diff --git a/core/src/main/java/edu/wpi/grip/core/operations/Operations.java b/core/src/main/java/edu/wpi/grip/core/operations/Operations.java index f2a864d6d5..1938b5b4a6 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/Operations.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/Operations.java @@ -1,202 +1,263 @@ package edu.wpi.grip.core.operations; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.FileManager; +import edu.wpi.grip.core.Operation; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.events.OperationAddedEvent; -import edu.wpi.grip.core.operations.composite.BlobsReport; -import edu.wpi.grip.core.operations.composite.BlurOperation; -import edu.wpi.grip.core.operations.composite.CascadeClassifierOperation; -import edu.wpi.grip.core.operations.composite.ContoursReport; -import edu.wpi.grip.core.operations.composite.ConvexHullsOperation; -import edu.wpi.grip.core.operations.composite.DesaturateOperation; -import edu.wpi.grip.core.operations.composite.DistanceTransformOperation; -import edu.wpi.grip.core.operations.composite.FilterContoursOperation; -import edu.wpi.grip.core.operations.composite.FilterLinesOperation; -import edu.wpi.grip.core.operations.composite.FindBlobsOperation; -import edu.wpi.grip.core.operations.composite.FindContoursOperation; -import edu.wpi.grip.core.operations.composite.FindLinesOperation; -import edu.wpi.grip.core.operations.composite.HSLThresholdOperation; -import edu.wpi.grip.core.operations.composite.HSVThresholdOperation; -import edu.wpi.grip.core.operations.composite.LinesReport; -import edu.wpi.grip.core.operations.composite.MaskOperation; -import edu.wpi.grip.core.operations.composite.NormalizeOperation; -import edu.wpi.grip.core.operations.composite.PublishVideoOperation; -import edu.wpi.grip.core.operations.composite.RGBThresholdOperation; -import edu.wpi.grip.core.operations.composite.RectsReport; -import edu.wpi.grip.core.operations.composite.ResizeOperation; -import edu.wpi.grip.core.operations.composite.SaveImageOperation; -import edu.wpi.grip.core.operations.composite.SwitchOperation; -import edu.wpi.grip.core.operations.composite.ThresholdMoving; -import edu.wpi.grip.core.operations.composite.ValveOperation; -import edu.wpi.grip.core.operations.composite.WatershedOperation; -import edu.wpi.grip.core.operations.network.BooleanPublishable; import edu.wpi.grip.core.operations.network.MapNetworkPublisherFactory; -import edu.wpi.grip.core.operations.network.NumberPublishable; -import edu.wpi.grip.core.operations.network.Vector2D; +import edu.wpi.grip.core.operations.network.PublishAnnotatedOperation; +import edu.wpi.grip.core.operations.network.Publishable; +import edu.wpi.grip.core.operations.network.PublishableProxy; +import edu.wpi.grip.core.operations.network.PublishableRosProxy; import edu.wpi.grip.core.operations.network.http.HttpPublishOperation; import edu.wpi.grip.core.operations.network.networktables.NTPublishAnnotatedOperation; import edu.wpi.grip.core.operations.network.ros.JavaToMessageConverter; import edu.wpi.grip.core.operations.network.ros.ROSNetworkPublisherFactory; import edu.wpi.grip.core.operations.network.ros.ROSPublishOperation; -import edu.wpi.grip.core.operations.opencv.MatFieldAccessor; -import edu.wpi.grip.core.operations.opencv.MinMaxLoc; -import edu.wpi.grip.core.operations.opencv.NewPointOperation; -import edu.wpi.grip.core.operations.opencv.NewSizeOperation; import edu.wpi.grip.core.sockets.InputSocket; -import edu.wpi.grip.core.sockets.OutputSocket; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; +import com.google.common.reflect.ClassPath; import com.google.inject.Inject; +import com.google.inject.Injector; import com.google.inject.Singleton; import com.google.inject.name.Named; -import org.bytedeco.javacpp.opencv_core.Point; -import org.bytedeco.javacpp.opencv_core.Size; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkNotNull; @Singleton public class Operations { + private static final Logger logger = Logger.getLogger(Operations.class.getName()); + private final EventBus eventBus; + private final Injector injector; + private final InputSocket.Factory isf; + private final MapNetworkPublisherFactory ntManager; + private final MapNetworkPublisherFactory httpManager; + private final ROSNetworkPublisherFactory rosManager; //NOPMD private final ImmutableList operations; + private List> publishableTypes = null; + + /** + * Creates a new Operations instance. This should only be used in tests. + * + * @param eventBus the app-global event bus + * @param ntManager the NetworkTable manager + * @param httpManager the HTTP manager + * @param rosManager the ROS manager + * @param injector the injector to use to create operations + * @param fileManager the file manager + * @param isf the factory for creating input sockets + */ @Inject Operations(EventBus eventBus, - @Named("ntManager") MapNetworkPublisherFactory ntPublisherFactory, - @Named("httpManager") MapNetworkPublisherFactory httpPublishFactory, - @Named("rosManager") ROSNetworkPublisherFactory rosPublishFactory, + @Named("ntManager") MapNetworkPublisherFactory ntManager, + @Named("httpManager") MapNetworkPublisherFactory httpManager, + @Named("rosManager") ROSNetworkPublisherFactory rosManager, + Injector injector, FileManager fileManager, - InputSocket.Factory isf, - OutputSocket.Factory osf) { + InputSocket.Factory isf) { + this.injector = checkNotNull(injector, "The injector cannot be null"); this.eventBus = checkNotNull(eventBus, "EventBus cannot be null"); - checkNotNull(ntPublisherFactory, "ntPublisherFactory cannot be null"); - checkNotNull(httpPublishFactory, "httpPublisherFactory cannot be null"); - checkNotNull(rosPublishFactory, "rosPublishFactory cannot be null"); + this.ntManager = checkNotNull(ntManager, "ntManager cannot be null"); + this.httpManager = checkNotNull(httpManager, "httpManager cannot be null"); + this.rosManager = checkNotNull(rosManager, "rosManager cannot be null"); + this.isf = checkNotNull(isf, "InputSocket factory cannot be null"); checkNotNull(fileManager, "fileManager cannot be null"); - this.operations = ImmutableList.of( - // Composite operations - new OperationMetaData(BlurOperation.DESCRIPTION, - () -> new BlurOperation(isf, osf)), - new OperationMetaData(ConvexHullsOperation.DESCRIPTION, - () -> new ConvexHullsOperation(isf, osf)), - new OperationMetaData(DesaturateOperation.DESCRIPTION, - () -> new DesaturateOperation(isf, osf)), - new OperationMetaData(DistanceTransformOperation.DESCRIPTION, - () -> new DistanceTransformOperation(isf, osf)), - new OperationMetaData(FilterContoursOperation.DESCRIPTION, - () -> new FilterContoursOperation(isf, osf)), - new OperationMetaData(FilterLinesOperation.DESCRIPTION, - () -> new FilterLinesOperation(isf, osf)), - new OperationMetaData(FindBlobsOperation.DESCRIPTION, - () -> new FindBlobsOperation(isf, osf)), - new OperationMetaData(FindContoursOperation.DESCRIPTION, - () -> new FindContoursOperation(isf, osf)), - new OperationMetaData(FindLinesOperation.DESCRIPTION, - () -> new FindLinesOperation(isf, osf)), - new OperationMetaData(HSLThresholdOperation.DESCRIPTION, - () -> new HSLThresholdOperation(isf, osf)), - new OperationMetaData(HSVThresholdOperation.DESCRIPTION, - () -> new HSVThresholdOperation(isf, osf)), - new OperationMetaData(MaskOperation.DESCRIPTION, - () -> new MaskOperation(isf, osf)), - new OperationMetaData(NormalizeOperation.DESCRIPTION, - () -> new NormalizeOperation(isf, osf)), - new OperationMetaData(PublishVideoOperation.DESCRIPTION, - () -> new PublishVideoOperation(isf)), - new OperationMetaData(ResizeOperation.DESCRIPTION, - () -> new ResizeOperation(isf, osf)), - new OperationMetaData(RGBThresholdOperation.DESCRIPTION, - () -> new RGBThresholdOperation(isf, osf)), - new OperationMetaData(SaveImageOperation.DESCRIPTION, - () -> new SaveImageOperation(isf, osf, fileManager)), - new OperationMetaData(SwitchOperation.DESCRIPTION, - () -> new SwitchOperation(isf, osf)), - new OperationMetaData(ValveOperation.DESCRIPTION, - () -> new ValveOperation(isf, osf)), - new OperationMetaData(WatershedOperation.DESCRIPTION, - () -> new WatershedOperation(isf, osf)), - new OperationMetaData(ThresholdMoving.DESCRIPTION, - () -> new ThresholdMoving(isf, osf)), - new OperationMetaData(CascadeClassifierOperation.DESCRIPTION, - () -> new CascadeClassifierOperation(isf, osf)), - - // OpenCV operations - new OperationMetaData(MatFieldAccessor.DESCRIPTION, - () -> new MatFieldAccessor(isf, osf)), - new OperationMetaData(MinMaxLoc.DESCRIPTION, - () -> new MinMaxLoc(isf, osf)), - new OperationMetaData(NewPointOperation.DESCRIPTION, - () -> new NewPointOperation(isf, osf)), - new OperationMetaData(NewSizeOperation.DESCRIPTION, - () -> new NewSizeOperation(isf, osf)), - - // NetworkTables publishing operations - new OperationMetaData(NTPublishAnnotatedOperation.descriptionFor(ContoursReport.class), - () -> new NTPublishAnnotatedOperation<>(isf, ContoursReport.class, ntPublisherFactory)), - new OperationMetaData(NTPublishAnnotatedOperation.descriptionFor(LinesReport.class), - () -> new NTPublishAnnotatedOperation<>(isf, LinesReport.class, ntPublisherFactory)), - new OperationMetaData(NTPublishAnnotatedOperation.descriptionFor(BlobsReport.class), - () -> new NTPublishAnnotatedOperation<>(isf, BlobsReport.class, ntPublisherFactory)), - new OperationMetaData(NTPublishAnnotatedOperation.descriptionFor(Size.class), - () -> new NTPublishAnnotatedOperation<>(isf, Size.class, Vector2D.class, - Vector2D::new, ntPublisherFactory)), - new OperationMetaData(NTPublishAnnotatedOperation.descriptionFor(Point.class), - () -> new NTPublishAnnotatedOperation<>(isf, Point.class, Vector2D.class, - Vector2D::new, ntPublisherFactory)), - new OperationMetaData(NTPublishAnnotatedOperation.descriptionFor(Number.class), - () -> new NTPublishAnnotatedOperation<>(isf, Number.class, NumberPublishable.class, - NumberPublishable::new, ntPublisherFactory)), - new OperationMetaData(NTPublishAnnotatedOperation.descriptionFor(Boolean.class), - () -> new NTPublishAnnotatedOperation<>(isf, Boolean.class, BooleanPublishable.class, - BooleanPublishable::new, ntPublisherFactory)), - new OperationMetaData(NTPublishAnnotatedOperation.descriptionFor(RectsReport.class), - () -> new NTPublishAnnotatedOperation<>(isf, RectsReport.class, ntPublisherFactory)), - - // ROS publishing operations - new OperationMetaData(ROSPublishOperation.descriptionFor(Number.class), - () -> new ROSPublishOperation<>(isf, Number.class, rosPublishFactory, - JavaToMessageConverter.FLOAT)), - new OperationMetaData(ROSPublishOperation.descriptionFor(Boolean.class), - () -> new ROSPublishOperation<>(isf, Boolean.class, rosPublishFactory, - JavaToMessageConverter.BOOL)), - new OperationMetaData(ROSPublishOperation.descriptionFor(ContoursReport.class), - () -> new ROSPublishOperation<>(isf, ContoursReport.class, rosPublishFactory, - JavaToMessageConverter.CONTOURS)), - new OperationMetaData(ROSPublishOperation.descriptionFor(BlobsReport.class), - () -> new ROSPublishOperation<>(isf, BlobsReport.class, rosPublishFactory, - JavaToMessageConverter.BLOBS)), - new OperationMetaData(ROSPublishOperation.descriptionFor(LinesReport.class), - () -> new ROSPublishOperation<>(isf, LinesReport.class, rosPublishFactory, - JavaToMessageConverter.LINES)), - - // HTTP publishing operations - new OperationMetaData(HttpPublishOperation.descriptionFor(ContoursReport.class), - () -> new HttpPublishOperation<>(isf, ContoursReport.class, httpPublishFactory)), - new OperationMetaData(HttpPublishOperation.descriptionFor(LinesReport.class), - () -> new HttpPublishOperation<>(isf, LinesReport.class, httpPublishFactory)), - new OperationMetaData(HttpPublishOperation.descriptionFor(BlobsReport.class), - () -> new HttpPublishOperation<>(isf, BlobsReport.class, httpPublishFactory)), - new OperationMetaData(HttpPublishOperation.descriptionFor(Size.class), - () -> new HttpPublishOperation<>(isf, Size.class, Vector2D.class, Vector2D::new, - httpPublishFactory)), - new OperationMetaData(HttpPublishOperation.descriptionFor(Point.class), - () -> new HttpPublishOperation<>(isf, Point.class, Vector2D.class, Vector2D::new, - httpPublishFactory)), - new OperationMetaData(HttpPublishOperation.descriptionFor(Number.class), - () -> new HttpPublishOperation<>(isf, Number.class, NumberPublishable.class, - NumberPublishable::new, httpPublishFactory)), - new OperationMetaData(HttpPublishOperation.descriptionFor(Boolean.class), - () -> new HttpPublishOperation<>(isf, Boolean.class, BooleanPublishable.class, - BooleanPublishable::new, httpPublishFactory)), - new OperationMetaData(HttpPublishOperation.descriptionFor(RectsReport.class), - () -> new HttpPublishOperation<>(isf, RectsReport.class, httpPublishFactory)) + + List all = new ArrayList<>(); + all.addAll(createBasicOperations()); + all.addAll(createNetworkTableOperations()); + all.addAll(createHttpOperations()); + all.addAll(createRosOperations()); + + // Sort alphabetically in each category + all.sort(Comparator.comparing((OperationMetaData md) -> md.getDescription().category()) + .thenComparing(md -> md.getDescription().name())); + this.operations = ImmutableList.copyOf(all); + } + + /** + * Creates an operation description for the given operation subclass. The subclass must + * be annotated with {@link Description @Description} or a {@code NullPointerException} will + * be thrown. + * + * @throws NullPointerException if {@code clazz} is null, or if it is not annotated with + * {@code @Description} + */ + private OperationDescription descriptionFor(Class clazz) { + return OperationDescription.from(clazz.getAnnotation(Description.class)); + } + + @SuppressWarnings("unchecked") + private List createBasicOperations() { + try { + ClassPath cp = ClassPath.from(getClass().getClassLoader()); + return cp.getAllClasses().stream() + .filter(ci -> ci.getName().startsWith("edu.wpi.grip.core.operations")) + .map(ClassPath.ClassInfo::load) + .filter(Operation.class::isAssignableFrom) + .map(c -> (Class) c) + .filter(c -> c.isAnnotationPresent(Description.class)) + .map(c -> new OperationMetaData(descriptionFor(c), () -> injector.getInstance(c))) + .collect(Collectors.toList()); + } catch (IOException e) { + logger.log(Level.WARNING, "Could not discover operations", e); + return ImmutableList.of(); + } + } + + /** + * Finds all subclasses of {@link Publishable} in {@code edu.wpi.grip.core.operation}. + */ + @SuppressWarnings("unchecked") + private List> findPublishables() { + if (publishableTypes == null) { + // Only need to search once + try { + ClassPath cp = ClassPath.from(getClass().getClassLoader()); + publishableTypes = cp.getAllClasses().stream() + // only look in our namespace (don't want to wade through tens of thousands of classes) + .filter(ci -> ci.getName().startsWith("edu.wpi.grip.core.operation")) + .map(ClassPath.ClassInfo::load) + .filter(Publishable.class::isAssignableFrom) + // only accept concrete top-level subclasses + .filter(c -> !c.isAnonymousClass() && !c.isInterface() && !c.isLocalClass() + && !c.isMemberClass()) + .filter(c -> Modifier.isPublic(c.getModifiers())) + .map(c -> (Class) c) + .collect(Collectors.toList()); + } catch (IOException e) { + logger.log(Level.WARNING, "Could not find the publishable types.", e); + publishableTypes = ImmutableList.of(); + } + } + return publishableTypes; + } + + /** + * Creates a list of operation metadata for every kind of publishable type for a specific subclass + * of {@link PublishAnnotatedOperation}. + * + * @param descriptionMaker a function that takes a data class and creates an operation description + * for it + * @param simpleFactory the factory to use when the data type is itself publishable + * @param complexFactory the factory to use when the publishable type is a proxy for the data + * type + * @param the data type (may also be {@code P} if the data type is publishable) + * @param

the publishable type + */ + // This is a mess of a function definition + @SuppressWarnings("unchecked") + private List createPublishAnnotatedOperations( + Function, OperationDescription> descriptionMaker, + Function, PublishAnnotatedOperation> simpleFactory, + BiFunction, Class

, PublishAnnotatedOperation> complexFactory) { + return findPublishables().stream() + .flatMap(p -> { + // Declare the stream type early to help the compiler figure out what the heck is going on + Stream stream; + if (p.isAnnotationPresent(PublishableProxy.class)) { + stream = Stream.of(p.getAnnotation(PublishableProxy.class).value()) + .map(d -> new OperationMetaData( + descriptionMaker.apply(d), + () -> complexFactory.apply(d, (Class

) p) + )); + } else { + // Class == Class

+ stream = Stream.of(new OperationMetaData(descriptionMaker.apply((Class) p), + () -> simpleFactory.apply((Class

) p))); + } + return stream; + }) + .collect(Collectors.toList()); + } + + private List createHttpOperations() { + return createPublishAnnotatedOperations( + HttpPublishOperation::descriptionFor, + d -> new HttpPublishOperation<>(isf, d, httpManager), + (d, p) -> new HttpPublishOperation<>(isf, d, p, + data -> createPublishableProxy(data, d, p), httpManager) + ); + } + + private List createNetworkTableOperations() { + return createPublishAnnotatedOperations( + NTPublishAnnotatedOperation::descriptionFor, + d -> new NTPublishAnnotatedOperation<>(isf, d, ntManager), + (d, p) -> new NTPublishAnnotatedOperation<>(isf, d, p, + data -> createPublishableProxy(data, d, p), ntManager) ); } + private List createRosOperations() { + return Stream.of(JavaToMessageConverter.class.getFields()) + .filter(f -> Modifier.isPublic(f.getModifiers()) && Modifier.isStatic(f.getModifiers())) + .filter(f -> f.isAnnotationPresent(PublishableRosProxy.class)) + .map(f -> { + Class dataType = f.getAnnotation(PublishableRosProxy.class).value(); + return new OperationMetaData(ROSPublishOperation.descriptionFor(dataType), + () -> new ROSPublishOperation<>(isf, dataType, rosManager, getStaticField(f))); + }) + .collect(Collectors.toList()); + } + + @SuppressWarnings("unchecked") + private T getStaticField(Field f) { + try { + return (T) f.get(null); + } catch (IllegalAccessException e) { + // This shouldn't have happened + logger.log(Level.WARNING, "", e); + throw new AssertionError(e); + } + } + + /** + * Creates a new publishable object to wrap the given data. The publishable proxy class + * must have a public constructor that only takes a single parameter of type {@code D}. + * An error will be thrown if this contract is broken. + * + * @param data the data to create a publishable proxy for + * @param publishableType the type of the publishable proxy class + */ + private P createPublishableProxy(D data, + Class dataType, + Class publishableType) { + checkNotNull(data, "Cannot publish null data"); + try { + return publishableType.getConstructor(dataType).newInstance(data); + } catch (ReflectiveOperationException | IllegalArgumentException e) { + // Uh oh, somebody broke the contract + throw new InternalError( + String.format("Operation instantiation failed: new %s(%s)", + publishableType.getSimpleName(), dataType.getSimpleName()), + e + ); + } + } + @VisibleForTesting ImmutableList operations() { return operations; diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/BlurOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/BlurOperation.java index 0baefa312d..7048c52b00 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/BlurOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/BlurOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; @@ -22,18 +23,12 @@ /** * An {@link Operation} that softens an image using one of several different filters. */ +@Description(name = "Blur", + summary = "Blurs an image to remove noise", + category = OperationDescription.Category.IMAGE_PROCESSING, + iconName = "blur") public class BlurOperation implements Operation { - /** - * Describes this operation. This is used by the 'Operations' class to add operations to GRIP. - */ - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Blur") - .summary("Blurs an image to remove noise") - .category(OperationDescription.Category.IMAGE_PROCESSING) - .icon(Icon.iconStream("blur")) - .build(); private final SocketHint inputHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint typeHint = SocketHints.createEnumSocketHint("Type", Type.BOX); private final SocketHint radiusHint = SocketHints.Inputs @@ -44,9 +39,10 @@ public class BlurOperation implements Operation { private final InputSocket radiusSocket; private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") - public BlurOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory - outputSocketFactory) { + public BlurOperation(InputSocket.Factory inputSocketFactory, + OutputSocket.Factory outputSocketFactory) { this.inputSocket = inputSocketFactory.create(inputHint); this.typeSocket = inputSocketFactory.create(typeHint); this.radiusSocket = inputSocketFactory.create(radiusHint); diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/CascadeClassifierOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/CascadeClassifierOperation.java index bfad91a05f..d6938248f4 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/CascadeClassifierOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/CascadeClassifierOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.opencv_core.Mat; import org.bytedeco.javacpp.opencv_core.Rect; @@ -22,16 +23,12 @@ /** * Operation for identifying parts of an image with a cascade classifier. */ +@Description(name = "Cascade Cassifier", + summary = "Runs a Haar cascade classifier on an image", + category = OperationDescription.Category.FEATURE_DETECTION, + iconName = "opencv") public class CascadeClassifierOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Cascade Classifier") - .summary("Runs a cascade classifier on an image") - .icon(Icon.iconStream("opencv")) - .category(OperationDescription.Category.FEATURE_DETECTION) - .build(); - private final SocketHint imageHint = SocketHints.Inputs.createMatSocketHint("Image", false); private final SocketHint classifierHint = @@ -60,6 +57,7 @@ public class CascadeClassifierOperation implements Operation { private final InputSocket maxSizeSocket; private final OutputSocket output; + @Inject @SuppressWarnings("JavadocMethod") public CascadeClassifierOperation(InputSocket.Factory isf, OutputSocket.Factory osf) { imageSocket = isf.create(imageHint); diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/ConvexHullsOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/ConvexHullsOperation.java index 583430fa50..5ae0fe8a81 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/ConvexHullsOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/ConvexHullsOperation.java @@ -1,5 +1,6 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; @@ -7,6 +8,7 @@ import edu.wpi.grip.core.sockets.SocketHint; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; @@ -17,15 +19,11 @@ * An {@link Operation} that finds the convex hull of each of a list of contours. This can help * remove holes in detected shapes, making them easier to analyze. */ +@Description(name = "Convex Hulls", + summary = "Compute the convex hulls of contours", + category = OperationDescription.Category.FEATURE_DETECTION) public class ConvexHullsOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Convex Hulls") - .summary("Compute the convex hulls of contours") - .category(OperationDescription.Category.FEATURE_DETECTION) - .build(); - private final SocketHint contoursHint = new SocketHint.Builder<>(ContoursReport .class) .identifier("Contours").initialValueSupplier(ContoursReport::new).build(); @@ -33,6 +31,7 @@ public class ConvexHullsOperation implements Operation { private final InputSocket inputSocket; private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public ConvexHullsOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/DesaturateOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/DesaturateOperation.java index 49284ed13e..a02861ab51 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/DesaturateOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/DesaturateOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; @@ -20,22 +21,19 @@ /** * An {@link Operation} that converts a color image into shades of gray. */ +@Description(name = "Desaturate", + summary = "Convert a color image into shades of gray", + category = OperationDescription.Category.IMAGE_PROCESSING, + iconName = "desaturate") public class DesaturateOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Desaturate") - .summary("Convert a color image into shades of gray.") - .category(OperationDescription.Category.IMAGE_PROCESSING) - .icon(Icon.iconStream("desaturate")) - .build(); - private final SocketHint inputHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint outputHint = SocketHints.Outputs.createMatSocketHint("Output"); private final InputSocket inputSocket; private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public DesaturateOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/DistanceTransformOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/DistanceTransformOperation.java index f720571c9c..904760a37a 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/DistanceTransformOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/DistanceTransformOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.opencv_core.Mat; @@ -23,16 +24,13 @@ /** * GRIP {@link Operation} for {@link org.bytedeco.javacpp.opencv_imgproc#distanceTransform}. */ +@Description(name = "Distance Transform", + summary = "Sets the values of pixels in a binary image to their distance to" + + " the nearest black pixel", + category = OperationDescription.Category.IMAGE_PROCESSING, + iconName = "opencv") public class DistanceTransformOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Distance Transform") - .summary("Sets the values of pixels in a binary image to their distance to the nearest " - + "black pixel.") - .category(OperationDescription.Category.IMAGE_PROCESSING) - .icon(Icon.iconStream("opencv")) - .build(); private final SocketHint srcHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint typeHint = SocketHints.createEnumSocketHint("Type", Type.DIST_L2); private final SocketHint maskSizeHint = SocketHints.createEnumSocketHint("Mask size", @@ -43,6 +41,7 @@ public class DistanceTransformOperation implements Operation { private final InputSocket maskSizeSocket; private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public DistanceTransformOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java index 748f1f9fef..f341b348e2 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; @@ -28,16 +29,12 @@ * small objects, as well as contours that do not meet the expected characteristics of the feature * we're actually looking for. So, this operation can help narrow them down. */ +@Description(name = "Filter Contours", + summary = "Find contours matching certain criteria", + category = OperationDescription.Category.FEATURE_DETECTION, + iconName = "find-contours") public class FilterContoursOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Filter Contours") - .summary("Find contours matching certain criteria") - .category(OperationDescription.Category.FEATURE_DETECTION) - .icon(Icon.iconStream("find-contours")) - .build(); - private final SocketHint contoursHint = new SocketHint.Builder<>(ContoursReport .class) .identifier("Contours").initialValueSupplier(ContoursReport::new).build(); @@ -92,6 +89,7 @@ public class FilterContoursOperation implements Operation { private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public FilterContoursOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterLinesOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterLinesOperation.java index 1f4e9f46f8..3047d8c97d 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterLinesOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterLinesOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; import java.util.stream.Collectors; @@ -17,16 +18,12 @@ * Given a ListReport, filter only the lines that meet certain criteria. This operation can be used * to narrow down detected lines to only relevant ones. */ +@Description(name = "Filter Lines", + summary = "Filter only lines from a Find Lines operation that fit certain criteria", + category = OperationDescription.Category.FEATURE_DETECTION, + iconName = "filter-lines") public class FilterLinesOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Filter Lines") - .summary("Filter only lines from a Find Lines operation that fit certain criteria") - .category(OperationDescription.Category.FEATURE_DETECTION) - .icon(Icon.iconStream("filter-lines")) - .build(); - private final SocketHint inputHint = new SocketHint.Builder<>(LinesReport.class).identifier("Lines").build(); @@ -47,6 +44,7 @@ public class FilterLinesOperation implements Operation { private final OutputSocket linesOutputSocket; + @Inject @SuppressWarnings("JavadocMethod") public FilterLinesOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java index 24dc7116ed..293288d490 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindBlobsOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.ArrayList; import java.util.List; @@ -21,16 +22,12 @@ /** * Find groups of similar pixels in a color or grayscale image. */ +@Description(name = "Find Blobs", + summary = "Detects groups of pixels in an image", + category = OperationDescription.Category.FEATURE_DETECTION, + iconName = "find-blobs") public class FindBlobsOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Find Blobs") - .summary("Detects groups of pixels in an image.") - .category(OperationDescription.Category.FEATURE_DETECTION) - .icon(Icon.iconStream("find-blobs")) - .build(); - private final SocketHint inputHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint minAreaHint = SocketHints.Inputs .createNumberSpinnerSocketHint("Min Area", 1); @@ -51,6 +48,7 @@ public class FindBlobsOperation implements Operation { private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public FindBlobsOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindContoursOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindContoursOperation.java index 06d03f93be..7762524da5 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindContoursOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindContoursOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; @@ -23,16 +24,12 @@ * An {@link Operation} that, given a binary image, produces a list of contours of all of the shapes * in the image. */ +@Description(name = "Find Contours", + summary = "Detects contours in a binary image", + category = OperationDescription.Category.FEATURE_DETECTION, + iconName = "find-contours") public class FindContoursOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Find Contours") - .summary("Detects contours in a binary image.") - .category(OperationDescription.Category.FEATURE_DETECTION) - .icon(Icon.iconStream("find-contours")) - .build(); - private final SocketHint inputHint = new SocketHint.Builder<>(Mat.class).identifier("Input").build(); @@ -49,6 +46,7 @@ public class FindContoursOperation implements Operation { private final OutputSocket contoursSocket; + @Inject @SuppressWarnings("JavadocMethod") public FindContoursOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindLinesOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindLinesOperation.java index 323adb1112..6833959aae 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/FindLinesOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/FindLinesOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.indexer.FloatIndexer; @@ -23,16 +24,12 @@ /** * Find line segments in a color or grayscale image. */ +@Description(name = "Find Lines", + summary = "Detects line segments in an image", + category = OperationDescription.Category.FEATURE_DETECTION, + iconName = "find-lines") public class FindLinesOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Find Lines") - .summary("Detects line segments in an image.") - .category(OperationDescription.Category.FEATURE_DETECTION) - .icon(Icon.iconStream("find-lines")) - .build(); - private final SocketHint inputHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint linesHint = new SocketHint.Builder<>(LinesReport.class) .identifier("Lines").initialValueSupplier(LinesReport::new).build(); @@ -42,6 +39,7 @@ public class FindLinesOperation implements Operation { private final OutputSocket linesReportSocket; + @Inject public FindLinesOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { this.inputSocket = inputSocketFactory.create(inputHint); diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/HSLThresholdOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/HSLThresholdOperation.java index d8de90c6ed..e2bca2c7bb 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/HSLThresholdOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/HSLThresholdOperation.java @@ -1,15 +1,16 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; import java.util.logging.Level; @@ -25,16 +26,12 @@ * An {@link Operation} that converts a color image into a binary image based on the HSL threshold * ranges. */ +@Description(name = "HSL Threshold", + summary = "Segment an image based on hue, saturation, and luminance ranges", + category = OperationDescription.Category.IMAGE_PROCESSING, + iconName = "threshold") public class HSLThresholdOperation extends ThresholdOperation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("HSL Threshold") - .summary("Segment an image based on hue, saturation, and luminance ranges.") - .category(OperationDescription.Category.IMAGE_PROCESSING) - .icon(Icon.iconStream("threshold")) - .build(); - private static final Logger logger = Logger.getLogger(HSLThresholdOperation.class.getName()); private final SocketHint inputHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint> hueHint = SocketHints.Inputs @@ -53,6 +50,7 @@ public class HSLThresholdOperation extends ThresholdOperation { private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public HSLThresholdOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/HSVThresholdOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/HSVThresholdOperation.java index c7e8700b95..dd4d1b3a0d 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/HSVThresholdOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/HSVThresholdOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.opencv_core.Mat; import org.bytedeco.javacpp.opencv_core.Scalar; @@ -25,16 +26,12 @@ * An {@link Operation} that converts a color image into a binary image based on the HSV threshold * ranges for each channel. */ +@Description(name = "HSV Threshold", + summary = "Segment an image based on hue, saturation, and value ranges", + category = OperationDescription.Category.IMAGE_PROCESSING, + iconName = "threshold") public class HSVThresholdOperation extends ThresholdOperation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("HSV Threshold") - .summary("Segment an image based on hue, saturation, and value ranges.") - .category(OperationDescription.Category.IMAGE_PROCESSING) - .icon(Icon.iconStream("threshold")) - .build(); - private static final Logger logger = Logger.getLogger(HSVThresholdOperation.class.getName()); private final SocketHint inputHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint> hueHint = SocketHints.Inputs @@ -53,6 +50,7 @@ public class HSVThresholdOperation extends ThresholdOperation { private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public HSVThresholdOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/MaskOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/MaskOperation.java index 6521f5947a..4b19e4de75 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/MaskOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/MaskOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; @@ -18,16 +19,12 @@ /** * An {@link Operation} that masks out an area of interest from an image. */ +@Description(name = "Mask", + summary = "Filter out an area of interest in an image using a binary mask", + category = OperationDescription.Category.IMAGE_PROCESSING, + iconName = "mask") public class MaskOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Mask") - .summary("Filter out an area of interest in an image using a binary mask.") - .category(OperationDescription.Category.IMAGE_PROCESSING) - .icon(Icon.iconStream("mask")) - .build(); - private final SocketHint inputHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint maskHint = SocketHints.Inputs.createMatSocketHint("Mask", false); @@ -39,6 +36,7 @@ public class MaskOperation implements Operation { private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public MaskOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/NormalizeOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/NormalizeOperation.java index 6b98c5a979..9006991bae 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/NormalizeOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/NormalizeOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; @@ -22,15 +23,12 @@ /** * GRIP {@link Operation} for {@link org.bytedeco.javacpp.opencv_core#normalize}. */ +@Description(name = "Normalize", + summary = "Normalizes or remaps the values of pixels in an image", + category = OperationDescription.Category.IMAGE_PROCESSING, + iconName = "opencv") public class NormalizeOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Normalize") - .summary("Normalizes or remaps the values of pixels in an image.") - .category(OperationDescription.Category.IMAGE_PROCESSING) - .icon(Icon.iconStream("opencv")) - .build(); private final SocketHint srcHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint typeHint = SocketHints.createEnumSocketHint("Type", Type.MINMAX); private final SocketHint aHint = SocketHints.Inputs @@ -44,6 +42,7 @@ public class NormalizeOperation implements Operation { private final InputSocket betaSocket; private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public NormalizeOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java index a30153bb9b..6d6bf53dfb 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java @@ -1,13 +1,14 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -35,16 +36,13 @@ * https://github.com/robotpy/allwpilib/blob/master/wpilibj/src/athena/java/edu/wpi/first/wpilibj * /CameraServer.java */ +@Description(name = "Publish Video", + summary = "Publish an MJPEG stream", + category = OperationDescription.Category.NETWORK, + iconName = "publish-video") public class PublishVideoOperation implements Operation { private static final Logger logger = Logger.getLogger(PublishVideoOperation.class.getName()); - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Publish Video") - .summary("Publish an M_JPEG stream to the dashboard.") - .category(OperationDescription.Category.NETWORK) - .icon(Icon.iconStream("publish-video")) - .build(); private static final int PORT = 1180; private static final byte[] MAGIC_NUMBER = {0x01, 0x00, 0x00, 0x00}; @@ -134,9 +132,10 @@ public class PublishVideoOperation implements Operation { } }; + @Inject @SuppressWarnings("JavadocMethod") @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", - justification = "Do not need to synchronize inside of a constructor") + justification = "Do not need to synchronize inside of a constructor") public PublishVideoOperation(InputSocket.Factory inputSocketFactory) { if (numSteps != 0) { throw new IllegalStateException("Only one instance of PublishVideoOperation may exist"); diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/RGBThresholdOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/RGBThresholdOperation.java index 965d4fea68..02bc466bc2 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/RGBThresholdOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/RGBThresholdOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; import java.util.logging.Level; @@ -22,16 +23,12 @@ * An {@link Operation} that converts a color image into a binary image based on threshold ranges * for each channel. */ +@Description(name = "RGB Threshold", + summary = "Segment an image based on color ranges", + category = OperationDescription.Category.IMAGE_PROCESSING, + iconName = "threshold") public class RGBThresholdOperation extends ThresholdOperation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("RGB Threshold") - .summary("Segment an image based on color ranges") - .category(OperationDescription.Category.IMAGE_PROCESSING) - .icon(Icon.iconStream("threshold")) - .build(); - private static final Logger logger = Logger.getLogger(RGBThresholdOperation.class.getName()); private final SocketHint inputHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint> redHint = SocketHints.Inputs @@ -51,6 +48,7 @@ public class RGBThresholdOperation extends ThresholdOperation { private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public RGBThresholdOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/ResizeOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/ResizeOperation.java index dcf66f3b6b..a673dc658f 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/ResizeOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/ResizeOperation.java @@ -1,13 +1,14 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; @@ -25,16 +26,12 @@ * images down can be a useful optimization, and scaling them up might be necessary for combining * multiple images that are different sizes. */ +@Description(name = "Resize Image", + summary = "Scale an image to an exact size", + category = OperationDescription.Category.IMAGE_PROCESSING, + iconName = "resize") public class ResizeOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Resize Image") - .summary("Scale an image to an exact size") - .category(OperationDescription.Category.IMAGE_PROCESSING) - .icon(Icon.iconStream("resize")) - .build(); - private final InputSocket inputSocket; private final InputSocket widthSocket; private final InputSocket heightSocket; @@ -42,6 +39,7 @@ public class ResizeOperation implements Operation { private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public ResizeOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/SaveImageOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/SaveImageOperation.java index f948bbec73..5935dc04df 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/SaveImageOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/SaveImageOperation.java @@ -1,16 +1,16 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.FileManager; import edu.wpi.grip.core.Operation; -import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.BytePointer; import org.bytedeco.javacpp.IntPointer; @@ -28,16 +28,11 @@ /** * Save JPEG files periodically to the local disk. */ +@Description(name = "Save Images to Disk", + summary = "Save image periodically to local disk", + iconName = "publish-video") public class SaveImageOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Save Images to Disk") - .summary("Save image periodically to local disk") - .category(OperationDescription.Category.MISCELLANEOUS) - .icon(Icon.iconStream("publish-video")) - .build(); - private final SocketHint inputHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint fileTypeHint @@ -74,6 +69,7 @@ public String toString() { } } + @Inject @SuppressWarnings("JavadocMethod") public SaveImageOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory, diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/SwitchOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/SwitchOperation.java index f3176ece20..7d63a4d6ee 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/SwitchOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/SwitchOperation.java @@ -1,6 +1,7 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; @@ -11,6 +12,7 @@ import edu.wpi.grip.core.sockets.SocketHints; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; @@ -18,21 +20,18 @@ * Allows for switching between two arbitrary typed {@link Socket} using a boolean {@link * InputSocket}. */ +@Description(name = "Switch", + summary = "Switch between two possible input sockets using a boolean", + category = OperationDescription.Category.LOGICAL) public class SwitchOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Switch") - .summary("Switch between two possible input sockets using a boolean") - .category(OperationDescription.Category.LOGICAL) - .build(); - private final InputSocket switcherSocket; private final InputSocket inputSocket1; // Intentionally using raw types private final InputSocket inputSocket2; private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public SwitchOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/ThresholdMoving.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/ThresholdMoving.java index 6f11218a7c..d8296fa7af 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/ThresholdMoving.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/ThresholdMoving.java @@ -1,12 +1,13 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; -import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHints; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.opencv_core; import org.bytedeco.javacpp.opencv_core.Mat; @@ -17,16 +18,16 @@ /** * Finds the absolute difference between the current image and the previous image. */ +@Description(name = "Threshold Moving", + summary = "Thresholds off parts of the image that have moved or changed between the" + + " previous and next image.") public class ThresholdMoving implements Operation { - public static final OperationDescription DESCRIPTION = OperationDescription - .builder().name("Threshold Moving") - .summary("Thresholds off parts of the image that have moved or changed between the previous" - + " and next image.") - .build(); + private final InputSocket imageSocket; private final OutputSocket outputSocket; private final Mat lastImage; + @Inject @SuppressWarnings("JavadocMethod") public ThresholdMoving(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/ThresholdOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/ThresholdOperation.java index 65cd124427..3016b4fe0d 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/ThresholdOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/ThresholdOperation.java @@ -14,6 +14,7 @@ public abstract class ThresholdOperation> implem * @param index The index of the data array that should be inspected * @param value The value that should be assigned to the mat regardless of being reallocated * @param input The input matrix that the dataArray element should be compared against + * * @return Either the old mat with the value assigned or a newly created Matrix. */ protected Mat reallocateMatIfInputSizeOrWidthChanged(final Mat[] dataArray, final int index, diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/ValveOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/ValveOperation.java index aff111cc08..5cf1fd5c76 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/ValveOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/ValveOperation.java @@ -1,6 +1,7 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; @@ -10,24 +11,22 @@ import edu.wpi.grip.core.sockets.SocketHints; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import java.util.List; import java.util.Optional; +@Description(name = "Valve", + summary = "Toggle an output socket on or off using a boolean", + category = OperationDescription.Category.LOGICAL) public class ValveOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Valve") - .summary("Toggle an output socket on or off using a boolean") - .category(OperationDescription.Category.LOGICAL) - .build(); - private final InputSocket switcherSocket; private final InputSocket inputSocket; // Intentionally using raw types private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public ValveOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/WatershedOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/WatershedOperation.java index bd388a4309..527886f44a 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/WatershedOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/WatershedOperation.java @@ -1,14 +1,15 @@ package edu.wpi.grip.core.operations.composite; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.Operation; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.opencv_core; @@ -40,16 +41,12 @@ * GRIP {@link Operation} for * {@link org.bytedeco.javacpp.opencv_imgproc#watershed}. */ +@Description(name = "Watershed", + summary = "Isolates overlapping objects from the background and each other", + category = OperationDescription.Category.FEATURE_DETECTION, + iconName = "opencv") public class WatershedOperation implements Operation { - public static final OperationDescription DESCRIPTION = - OperationDescription.builder() - .name("Watershed") - .summary("Isolates overlapping objects from the background and each other") - .category(OperationDescription.Category.FEATURE_DETECTION) - .icon(Icon.iconStream("opencv")) - .build(); - private final SocketHint srcHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint contoursHint = new SocketHint.Builder<>(ContoursReport.class) @@ -74,6 +71,7 @@ public class WatershedOperation implements Operation { private final Mat output = new Mat(); private final Point backgroundLabel = new Point(); + @Inject @SuppressWarnings("JavadocMethod") public WatershedOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/BooleanPublishable.java b/core/src/main/java/edu/wpi/grip/core/operations/network/BooleanPublishable.java index efada2393f..f9ad7eda60 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/BooleanPublishable.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/BooleanPublishable.java @@ -6,11 +6,12 @@ * An adapter to allow booleans to be published from GRIP sockets into a {@link NetworkPublisher}. */ @Immutable +@PublishableProxy(Boolean.class) public final class BooleanPublishable implements Publishable { private final boolean bool; public BooleanPublishable(Boolean bool) { - this.bool = bool.booleanValue(); + this.bool = bool; } @PublishValue(weight = 1) diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/NetworkPublishOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/network/NetworkPublishOperation.java index 9ebf11534c..2a3a5ab557 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/NetworkPublishOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/NetworkPublishOperation.java @@ -1,12 +1,10 @@ package edu.wpi.grip.core.operations.network; import edu.wpi.grip.core.Operation; -import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; @@ -19,16 +17,6 @@ */ public abstract class NetworkPublishOperation implements Operation { - /** - * OperationDescription builder that has the icon default to "publish" and the category to - * "NETWORK". - */ - protected static final OperationDescription.Builder defaultBuilder = - OperationDescription.builder() - .icon(Icon.iconStream("publish")) - .category(OperationDescription.Category.NETWORK); - - protected final Class dataType; protected final InputSocket dataSocket; protected final InputSocket nameSocket; diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/NumberPublishable.java b/core/src/main/java/edu/wpi/grip/core/operations/network/NumberPublishable.java index 4a9690dd77..212c768bfc 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/NumberPublishable.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/NumberPublishable.java @@ -8,6 +8,7 @@ * @see PublishAnnotatedOperation#PublishAnnotatedOperation */ @Immutable +@PublishableProxy(Number.class) public final class NumberPublishable implements Publishable { private final double number; diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/PublishAnnotatedOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/network/PublishAnnotatedOperation.java index 80fbbc2fb3..51abbe2092 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/PublishAnnotatedOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/PublishAnnotatedOperation.java @@ -59,7 +59,7 @@ protected PublishAnnotatedOperation(InputSocket.Factory isf, valueMethodStream() .findAny() .orElseThrow(() -> new IllegalArgumentException("A Publishable type must have at least " - + "one method annotated with @PublishValue")); + + "one method annotated with @PublishValue (at " + publishType.getName() + ")")); // Make sure keys and weights are distinct valueMethodStream() diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/PublishableProxy.java b/core/src/main/java/edu/wpi/grip/core/operations/network/PublishableProxy.java new file mode 100644 index 0000000000..bfacda6e56 --- /dev/null +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/PublishableProxy.java @@ -0,0 +1,26 @@ +package edu.wpi.grip.core.operations.network; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a class as being a publishable proxy for a non-publishable type, like + * {@code BooleanPublishable} for {@code Boolean}. This annotation only has an affect when placed + * on a public, concrete, top-level class that implements {@link Publishable}. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface PublishableProxy { + + /** + * The type(s) that the marked class is an publishable version of. The marked class must have + * a copy constructor for each type. + * + *

These types should use boxed classes instead of primitive types (e.g. {@code Integer.class} + * instead of {@code int.class}). + */ + Class[] value(); + +} diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/PublishableRosProxy.java b/core/src/main/java/edu/wpi/grip/core/operations/network/PublishableRosProxy.java new file mode 100644 index 0000000000..6ff6f868fd --- /dev/null +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/PublishableRosProxy.java @@ -0,0 +1,22 @@ +package edu.wpi.grip.core.operations.network; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a + * {@link edu.wpi.grip.core.operations.network.ros.JavaToMessageConverter JavaToMessageConverter} + * field as a proxy for a non-ROS-publishable type. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface PublishableRosProxy { + + /** + * The type the marked converter is a proxy for. + */ + Class value(); + +} diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/Vector2D.java b/core/src/main/java/edu/wpi/grip/core/operations/network/Vector2D.java index 8e17e1be2f..1c572b6c39 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/Vector2D.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/Vector2D.java @@ -11,6 +11,7 @@ * {@link Size}s are converted into this. */ @Immutable +@PublishableProxy({Point.class, Size.class}) public final class Vector2D implements Publishable { private final double x; diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/http/HttpPublishOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/network/http/HttpPublishOperation.java index b1d7d7f936..94413d8bb7 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/http/HttpPublishOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/http/HttpPublishOperation.java @@ -39,6 +39,7 @@ public HttpPublishOperation(InputSocket.Factory isf, * * @param dataType the type of the data published by the {@code HttpPublishOperation} for the data * type described + * * @return a description for an {@code HttpPublishOperation} that publishes the given data type */ public static OperationDescription descriptionFor(Class dataType) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/ros/JavaToMessageConverter.java b/core/src/main/java/edu/wpi/grip/core/operations/network/ros/JavaToMessageConverter.java index bc08be28d7..85a8f14757 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/ros/JavaToMessageConverter.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/ros/JavaToMessageConverter.java @@ -3,6 +3,7 @@ import edu.wpi.grip.core.operations.composite.BlobsReport; import edu.wpi.grip.core.operations.composite.ContoursReport; import edu.wpi.grip.core.operations.composite.LinesReport; +import edu.wpi.grip.core.operations.network.PublishableRosProxy; import com.google.common.reflect.TypeToken; @@ -19,6 +20,8 @@ * Used to convert from a java type to a ROS message. */ public abstract class JavaToMessageConverter { + + @PublishableRosProxy(BlobsReport.class) public static final JavaToMessageConverter BLOBS = new JavaToMessageConverter(grip_msgs.Blobs._TYPE) { @Override @@ -38,6 +41,8 @@ protected void doConvert(BlobsReport blobsReport, grip_msgs.Blobs blobsMsg, Mess blobsMsg.setBlobs(blobs); } }; + + @PublishableRosProxy(LinesReport.class) public static final JavaToMessageConverter LINES = new JavaToMessageConverter(grip_msgs.Lines._TYPE) { @Override @@ -57,6 +62,8 @@ protected void doConvert(LinesReport linesReport, grip_msgs.Lines linesMsg, Mess linesMsg.setLines(lines); } }; + + @PublishableRosProxy(ContoursReport.class) public static final JavaToMessageConverter CONTOURS = new JavaToMessageConverter(grip_msgs.Contours._TYPE) { @Override @@ -79,10 +86,14 @@ void doConvert(ContoursReport contoursReport, grip_msgs.Contours contoursMsg, Me contoursMsg.setContours(contours); } }; + + @PublishableRosProxy(Boolean.class) public static final JavaToMessageConverter BOOL = new SimpleConverter(std_msgs.Bool._TYPE, std_msgs.Bool::setData) { }; + + @PublishableRosProxy(Number.class) public static final JavaToMessageConverter FLOAT = new SimpleConverter( std_msgs.Float64._TYPE, diff --git a/core/src/main/java/edu/wpi/grip/core/operations/opencv/CVOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/opencv/CVOperation.java index 4376afdae4..db80b012f9 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/opencv/CVOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/opencv/CVOperation.java @@ -18,4 +18,9 @@ static OperationDescription.Builder defaultBuilder() { static OperationDescription defaults(String name, String description) { return defaultBuilder().name(name).summary(description).build(); } + + static OperationDescription defaults(String name, String summary, String... aliases) { + return defaultBuilder().name(name).summary(summary).aliases(aliases).build(); + } + } diff --git a/core/src/main/java/edu/wpi/grip/core/operations/opencv/MatFieldAccessor.java b/core/src/main/java/edu/wpi/grip/core/operations/opencv/MatFieldAccessor.java index fb6dff4ac6..b788de4686 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/opencv/MatFieldAccessor.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/opencv/MatFieldAccessor.java @@ -1,5 +1,6 @@ package edu.wpi.grip.core.operations.opencv; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; @@ -7,20 +8,19 @@ import edu.wpi.grip.core.sockets.SocketHints; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.opencv_core.Mat; import org.bytedeco.javacpp.opencv_core.Size; import java.util.List; +@Description(name = "Get Mat Info", + summary = "Provide access to the various elements and properties of an image", + category = OperationDescription.Category.OPENCV, + iconName = "opencv") public class MatFieldAccessor implements CVOperation { - public static final OperationDescription DESCRIPTION = - CVOperation.defaultBuilder() - .name("Get Mat Info") - .summary("Provide access to the various elements and properties of an image.") - .build(); - private static final Mat defaultsMat = new Mat(); private final SocketHint matHint = SocketHints.Inputs.createMatSocketHint("Input", false); private final SocketHint sizeHint = SocketHints.Inputs.createSizeSocketHint("size", true); @@ -45,6 +45,7 @@ public class MatFieldAccessor implements CVOperation { private final OutputSocket rowsSocket; private final OutputSocket highValueSocket; + @Inject @SuppressWarnings("JavadocMethod") public MatFieldAccessor(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/opencv/MinMaxLoc.java b/core/src/main/java/edu/wpi/grip/core/operations/opencv/MinMaxLoc.java index cc0771597c..993b2fc160 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/opencv/MinMaxLoc.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/opencv/MinMaxLoc.java @@ -1,5 +1,6 @@ package edu.wpi.grip.core.operations.opencv; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; @@ -7,6 +8,7 @@ import edu.wpi.grip.core.sockets.SocketHints; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.opencv_core; import org.bytedeco.javacpp.opencv_core.Mat; @@ -17,14 +19,12 @@ /** * Operation to call {@link opencv_core#minMaxLoc}. */ +@Description(name = "Find Min and Max", + summary = "Find the global minimum and maximum in a single channel grayscale image", + category = OperationDescription.Category.OPENCV, + iconName = "opencv") public class MinMaxLoc implements CVOperation { - public static final OperationDescription DESCRIPTION = - CVOperation.defaultBuilder() - .name("Find Min and Max") - .summary("Find the global minimum and manimum in a single channel grayscale image.") - .build(); - private final SocketHint srcInputHint = SocketHints.Inputs .createMatSocketHint("Image", false); private final SocketHint maskInputHint = SocketHints.Inputs @@ -48,6 +48,7 @@ public class MinMaxLoc implements CVOperation { private final OutputSocket minLocSocket; private final OutputSocket maxLocSocket; + @Inject @SuppressWarnings("JavadocMethod") public MinMaxLoc(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/opencv/NewPointOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/opencv/NewPointOperation.java index 5389ed710f..0019139de7 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/opencv/NewPointOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/opencv/NewPointOperation.java @@ -1,28 +1,25 @@ package edu.wpi.grip.core.operations.opencv; - +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; import com.google.common.collect.ImmutableList; +import com.google.inject.Inject; import org.bytedeco.javacpp.opencv_core.Point; import java.util.List; +@Description(name = "New Point", + summary = "Create a new point by (x,y) value", + category = OperationDescription.Category.OPENCV, + iconName = "point") public class NewPointOperation implements CVOperation { - public static final OperationDescription DESCRIPTION = - CVOperation.defaultBuilder() - .name("New Point") - .summary("Create a point by (x,y) value.") - .icon(Icon.iconStream("point")) - .build(); - private final SocketHint xHint = SocketHints.Inputs.createNumberSpinnerSocketHint("x", -1, Integer.MIN_VALUE, Integer.MAX_VALUE); private final SocketHint yHint = SocketHints.Inputs.createNumberSpinnerSocketHint("y", -1, @@ -35,6 +32,7 @@ public class NewPointOperation implements CVOperation { private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public NewPointOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/operations/opencv/NewSizeOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/opencv/NewSizeOperation.java index 8f2eaffb45..a9fe235457 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/opencv/NewSizeOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/opencv/NewSizeOperation.java @@ -1,27 +1,26 @@ package edu.wpi.grip.core.operations.opencv; +import edu.wpi.grip.core.Description; import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.sockets.InputSocket; import edu.wpi.grip.core.sockets.OutputSocket; import edu.wpi.grip.core.sockets.SocketHint; import edu.wpi.grip.core.sockets.SocketHints; -import edu.wpi.grip.core.util.Icon; + +import com.google.inject.Inject; import org.bytedeco.javacpp.opencv_core.Size; import org.python.google.common.collect.ImmutableList; import java.util.List; +@Description(name = "New Size", + summary = "Create a size by width and height values", + category = OperationDescription.Category.OPENCV, + iconName = "size") public class NewSizeOperation implements CVOperation { - public static final OperationDescription DESCRIPTION = - CVOperation.defaultBuilder() - .name("New Size") - .summary("Create a size.") - .icon(Icon.iconStream("size")) - .build(); - private final SocketHint widthHint = SocketHints.Inputs .createNumberSpinnerSocketHint("width", -1, -1, Integer.MAX_VALUE); private final SocketHint heightHint = SocketHints.Inputs @@ -34,6 +33,7 @@ public class NewSizeOperation implements CVOperation { private final OutputSocket outputSocket; + @Inject @SuppressWarnings("JavadocMethod") public NewSizeOperation(InputSocket.Factory inputSocketFactory, OutputSocket.Factory outputSocketFactory) { diff --git a/core/src/main/java/edu/wpi/grip/core/serialization/StepConverter.java b/core/src/main/java/edu/wpi/grip/core/serialization/StepConverter.java index 885e034891..8ea4961496 100644 --- a/core/src/main/java/edu/wpi/grip/core/serialization/StepConverter.java +++ b/core/src/main/java/edu/wpi/grip/core/serialization/StepConverter.java @@ -17,6 +17,7 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import java.util.Optional; +import java.util.stream.Collectors; import javax.inject.Inject; @@ -61,7 +62,12 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co .getOperationByName(operationName); if (!operationMetaData.isPresent()) { - throw new ConversionException("Unknown operation: " + operationName); + throw new ConversionException(String.format("Unknown operation: %s. Known operations: %s", + operationName, + palette.getOperations().stream() + .map(m -> m.getDescription()) + .map(d -> d.name()) + .collect(Collectors.toList()))); } // Instead of simply returning the step and having XStream insert it into the pipeline using diff --git a/core/src/test/java/edu/wpi/grip/core/CoreSanityTest.java b/core/src/test/java/edu/wpi/grip/core/CoreSanityTest.java index 30cbca1eae..75a62e95b6 100644 --- a/core/src/test/java/edu/wpi/grip/core/CoreSanityTest.java +++ b/core/src/test/java/edu/wpi/grip/core/CoreSanityTest.java @@ -43,5 +43,17 @@ public CoreSanityTest() { setDefault(OperationDescription.class, OperationDescription.builder().name("").summary("") .build()); setDefault(Step.class, new MockStep()); + + setDistinctValues(Description.class, + A.class.getAnnotation(Description.class), + B.class.getAnnotation(Description.class)); + } + + @Description(name = "A", summary = "A") + private static class A { + } + + @Description(name = "B", summary = "B") + private static class B { } } diff --git a/core/src/test/java/edu/wpi/grip/core/operations/OperationsFactory.java b/core/src/test/java/edu/wpi/grip/core/operations/OperationsFactory.java index 95aed4420c..ab369fae72 100644 --- a/core/src/test/java/edu/wpi/grip/core/operations/OperationsFactory.java +++ b/core/src/test/java/edu/wpi/grip/core/operations/OperationsFactory.java @@ -14,16 +14,18 @@ import edu.wpi.grip.core.util.MockFileManager; import com.google.common.eventbus.EventBus; +import com.google.inject.Injector; import java.util.Optional; public class OperationsFactory { - public static Operations create(EventBus eventBus) { + public static Operations create(EventBus eventBus, Injector injector) { return create(eventBus, MockMapNetworkPublisher::new, MockMapNetworkPublisher::new, MockROSMessagePublisher::new, + injector, new MockFileManager(), new MockInputSocketFactory(eventBus), new MockOutputSocketFactory(eventBus)); @@ -33,10 +35,12 @@ public static Operations create(EventBus eventBus, MapNetworkPublisherFactory mapFactory, MapNetworkPublisherFactory httpFactory, ROSNetworkPublisherFactory rosFactory, + Injector injector, FileManager fileManager, InputSocket.Factory isf, OutputSocket.Factory osf) { - return new Operations(eventBus, mapFactory, httpFactory, rosFactory, fileManager, isf, osf); + return new Operations(eventBus, mapFactory, httpFactory, rosFactory, + injector, fileManager, isf); } public static CVOperations createCV(EventBus eventBus) { @@ -44,8 +48,8 @@ public static CVOperations createCV(EventBus eventBus) { MockOutputSocketFactory(eventBus)); } - private static class MockROSMessagePublisher extends - ROSMessagePublisher { + private static class MockROSMessagePublisher + extends ROSMessagePublisher { public MockROSMessagePublisher(C converter) { } diff --git a/core/src/test/java/edu/wpi/grip/core/operations/OperationsTest.java b/core/src/test/java/edu/wpi/grip/core/operations/OperationsTest.java index 623629c981..ce3e62b690 100644 --- a/core/src/test/java/edu/wpi/grip/core/operations/OperationsTest.java +++ b/core/src/test/java/edu/wpi/grip/core/operations/OperationsTest.java @@ -1,13 +1,22 @@ package edu.wpi.grip.core.operations; +import edu.wpi.grip.core.GripCoreModule; +import edu.wpi.grip.core.GripFileModule; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.metrics.MockTimer; +import edu.wpi.grip.core.operations.network.GripNetworkModule; +import edu.wpi.grip.core.operations.network.MockGripNetworkModule; import edu.wpi.grip.core.util.MockExceptionWitness; +import edu.wpi.grip.util.GripCoreTestModule; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.util.Modules; +import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -19,19 +28,43 @@ import java.util.List; @RunWith(Parameterized.class) +@SuppressWarnings("all") public class OperationsTest { @Parameter public OperationMetaData operationMetaData; + private static GripCoreTestModule testModule; + private static Injector injector; + + static { + // Only because @Parameters runs before @BeforeClass... for some weird reason + setUpClass(); + } + + // @Parameters is called before @BeforeClass, so we call it manually in a static initializer block + // @BeforeClass + public static void setUpClass() { + testModule = new GripCoreTestModule(); + testModule.setUp(); + injector = Guice.createInjector( + Modules.override(new GripCoreModule(), new GripNetworkModule(), new GripFileModule()) + .with(new MockGripNetworkModule(), testModule)); + } + + @AfterClass + public static void tearDownClass() { + testModule.tearDown(); + } + @Parameters(name = "{index}: Operation({0})") public static Collection data() { - EventBus eventBus = new EventBus(); + EventBus eventBus = injector.getInstance(EventBus.class); List operationMetaDatas = ImmutableList.builder() .addAll( OperationsFactory - .create(eventBus) + .create(eventBus, injector) .operations()) .addAll( OperationsFactory diff --git a/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java b/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java index 69f4f9b3df..98e1c2a104 100644 --- a/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java +++ b/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java @@ -1,17 +1,21 @@ package edu.wpi.grip.core.serialization; +import edu.wpi.grip.core.GripCoreModule; +import edu.wpi.grip.core.GripFileModule; import edu.wpi.grip.core.Pipeline; import edu.wpi.grip.core.operations.OperationsFactory; +import edu.wpi.grip.core.operations.network.GripNetworkModule; +import edu.wpi.grip.core.operations.network.MockGripNetworkModule; import edu.wpi.grip.util.Files; import edu.wpi.grip.util.GripCoreTestModule; import com.google.common.eventbus.EventBus; import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.util.Modules; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import java.io.BufferedReader; @@ -31,7 +35,6 @@ * This tests for backwards compatibility by opening a project file containing ALL the steps of GRIP * at the time of this file's creation. Please note that this test requires a webcam at position 0. */ -@Ignore("OpenCV operations were removed. Remove this annotation after they are added back.") public class CompatibilityTest { private static final URI testphotoURI = Files.testphotoURI; //The location of the photo source @@ -47,15 +50,17 @@ public void setUp() throws Exception { testModule = new GripCoreTestModule(); testModule.setUp(); //Set up the stuff we need for the core functionality for GRIP - final Injector injector = Guice.createInjector(testModule); + final Injector injector = Guice.createInjector( + Modules.override(new GripCoreModule(), new GripFileModule(), new GripNetworkModule()) + .with(testModule, new MockGripNetworkModule())); final EventBus eventBus = injector.getInstance(EventBus.class); pipeline = injector.getInstance(Pipeline.class); final Project project = injector.getInstance(Project.class); //Add the operations so that GRIP will recognize them - OperationsFactory.create(eventBus).addOperations(); - //CVOperations.addOperations(eventBus); + OperationsFactory.create(eventBus, injector).addOperations(); + OperationsFactory.createCV(eventBus).addOperations(); //Set up the test project file to work with this machine String fileName = testprojectURI.toString().substring(5); diff --git a/core/src/test/resources/edu/wpi/grip/projects/testALL.grip b/core/src/test/resources/edu/wpi/grip/projects/testALL.grip index 092c0c3ee9..b2699999a8 100644 --- a/core/src/test/resources/edu/wpi/grip/projects/testALL.grip +++ b/core/src/test/resources/edu/wpi/grip/projects/testALL.grip @@ -405,9 +405,6 @@ COLOR_BGR2GRAY - - 0.0 - diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/BlurGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/BlurGenerationTesting.java index c3cbdab201..80b231a3c6 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/BlurGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/BlurGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -27,7 +28,8 @@ public class BlurGenerationTesting extends AbstractGenerationTesting { void generatePipeline(String blurType) { Step step = gen.addStep( - new OperationMetaData(BlurOperation.DESCRIPTION, () -> new BlurOperation(isf, osf))); + new OperationMetaData(OperationDescription.from(BlurOperation.class), + () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ConvexHullsGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ConvexHullsGenerationTesting.java index 22c7090f97..38797b37f0 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ConvexHullsGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ConvexHullsGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.ContoursReport; @@ -45,7 +46,8 @@ public ConvexHullsGenerationTesting() { } void generatePipeline() { - Step step0 = gen.addStep(new OperationMetaData(HSLThresholdOperation.DESCRIPTION, + Step step0 = gen.addStep(new OperationMetaData( + OperationDescription.from(HSLThresholdOperation.class), () -> new HSLThresholdOperation(isf, osf))); loadImage(Files.imageFile); OutputSocket imgOut0 = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -62,7 +64,8 @@ void generatePipeline() { } } - Step step1 = gen.addStep(new OperationMetaData(FindContoursOperation.DESCRIPTION, + Step step1 = gen.addStep(new OperationMetaData( + OperationDescription.from(FindContoursOperation.class), () -> new FindContoursOperation(isf, osf))); OutputSocket imgOut1 = pipeline.getSteps().get(0).getOutputSockets().get(0); for (InputSocket sock : step1.getInputSockets()) { @@ -73,7 +76,8 @@ void generatePipeline() { } } - Step step2 = gen.addStep(new OperationMetaData(ConvexHullsOperation.DESCRIPTION, + Step step2 = gen.addStep(new OperationMetaData( + OperationDescription.from(ConvexHullsOperation.class), () -> new ConvexHullsOperation(isf, osf))); OutputSocket imgOut2 = pipeline.getSteps().get(1).getOutputSockets().get(0); for (InputSocket sock : step2.getInputSockets()) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/DesaturateGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/DesaturateGenerationTesting.java index 8dd137c680..08a7e2f106 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/DesaturateGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/DesaturateGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.DesaturateOperation; @@ -22,7 +23,8 @@ public class DesaturateGenerationTesting extends AbstractGenerationTesting { void generatePipeline() { - Step desat = gen.addStep(new OperationMetaData(DesaturateOperation.DESCRIPTION, + Step desat = gen.addStep(new OperationMetaData( + OperationDescription.from(DesaturateOperation.class), () -> new DesaturateOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/DistanceTransformGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/DistanceTransformGenerationTesting.java index 7a8d3896b0..57ebb55167 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/DistanceTransformGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/DistanceTransformGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.DistanceTransformOperation; @@ -45,7 +46,8 @@ public boolean init() { lVal.add(new Double(0.0)); lVal.add(new Double(250.0)); GripIconHSLSetup.setup(this, GripIconHSLSetup.getHVal(), GripIconHSLSetup.getSVal(), lVal); - Step dist = gen.addStep(new OperationMetaData(DistanceTransformOperation.DESCRIPTION, + Step dist = gen.addStep(new OperationMetaData( + OperationDescription.from(DistanceTransformOperation.class), () -> new DistanceTransformOperation(isf, osf))); // output from HSL OutputSocket hslImg = pipeline.getSteps().get(0).getOutputSockets().get(0); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FilterContoursGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FilterContoursGenerationTesting.java index 3bed35863d..6e7f6610b2 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FilterContoursGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FilterContoursGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.ContoursReport; @@ -47,7 +48,8 @@ public FilterContoursGenerationTesting() { } void generatePipeline(String socketName, Object value) { - Step step0 = gen.addStep(new OperationMetaData(HSLThresholdOperation.DESCRIPTION, + Step step0 = gen.addStep(new OperationMetaData( + OperationDescription.from(HSLThresholdOperation.class), () -> new HSLThresholdOperation(isf, osf))); loadImage(Files.imageFile); OutputSocket imgOut0 = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -64,7 +66,8 @@ void generatePipeline(String socketName, Object value) { } } - Step step1 = gen.addStep(new OperationMetaData(FindContoursOperation.DESCRIPTION, + Step step1 = gen.addStep(new OperationMetaData( + OperationDescription.from(FindContoursOperation.class), () -> new FindContoursOperation(isf, osf))); OutputSocket imgOut1 = pipeline.getSteps().get(0).getOutputSockets().get(0); for (InputSocket sock : step1.getInputSockets()) { @@ -75,7 +78,8 @@ void generatePipeline(String socketName, Object value) { } } - Step step2 = gen.addStep(new OperationMetaData(FilterContoursOperation.DESCRIPTION, + Step step2 = gen.addStep(new OperationMetaData( + OperationDescription.from(FilterContoursOperation.class), () -> new FilterContoursOperation(isf, osf))); OutputSocket imgOut2 = pipeline.getSteps().get(1).getOutputSockets().get(0); for (InputSocket sock : step2.getInputSockets()) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FilterLinesGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FilterLinesGenerationTesting.java index 37eac1b3ce..8833838a06 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FilterLinesGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FilterLinesGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.FilterLinesOperation; @@ -53,7 +54,8 @@ public void ignoreIfWindows() { } void generatePipeline() { - Step step0 = gen.addStep(new OperationMetaData(HSLThresholdOperation.DESCRIPTION, + Step step0 = gen.addStep(new OperationMetaData( + OperationDescription.from(HSLThresholdOperation.class), () -> new HSLThresholdOperation(isf, osf))); loadImage(Files.imageFile); OutputSocket imgOut0 = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -70,7 +72,8 @@ void generatePipeline() { } } - Step step1 = gen.addStep(new OperationMetaData(FindLinesOperation.DESCRIPTION, + Step step1 = gen.addStep(new OperationMetaData( + OperationDescription.from(FindLinesOperation.class), () -> new FindLinesOperation(isf, osf))); OutputSocket imgOut1 = pipeline.getSteps().get(0).getOutputSockets().get(0); for (InputSocket sock : step1.getInputSockets()) { @@ -79,7 +82,8 @@ void generatePipeline() { } } - Step step2 = gen.addStep(new OperationMetaData(FilterLinesOperation.DESCRIPTION, + Step step2 = gen.addStep(new OperationMetaData( + OperationDescription.from(FilterLinesOperation.class), () -> new FilterLinesOperation(isf, osf))); OutputSocket imgOut2 = pipeline.getSteps().get(1).getOutputSockets().get(0); for (InputSocket sock : step2.getInputSockets()) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindBlobsGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindBlobsGenerationTesting.java index ab6eb4337c..3779a0a0dc 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindBlobsGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindBlobsGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlobsReport; @@ -40,7 +41,8 @@ public FindBlobsGenerationTesting() { } void generatePipeline(boolean darkBool, double minArea, List circularity) { - Step step0 = gen.addStep(new OperationMetaData(HSLThresholdOperation.DESCRIPTION, + Step step0 = gen.addStep(new OperationMetaData( + OperationDescription.from(HSLThresholdOperation.class), () -> new HSLThresholdOperation(isf, osf))); loadImage(Files.imageFile); OutputSocket imgOut0 = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -57,7 +59,8 @@ void generatePipeline(boolean darkBool, double minArea, List circularity } } - Step step1 = gen.addStep(new OperationMetaData(FindBlobsOperation.DESCRIPTION, + Step step1 = gen.addStep(new OperationMetaData( + OperationDescription.from(FindBlobsOperation.class), () -> new FindBlobsOperation(isf, osf))); OutputSocket imgOut1 = pipeline.getSteps().get(0).getOutputSockets().get(0); for (InputSocket sock : step1.getInputSockets()) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindContoursGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindContoursGenerationTesting.java index ec339835d7..6a0447107e 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindContoursGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindContoursGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.ContoursReport; @@ -45,7 +46,8 @@ public FindContoursGenerationTesting() { } void generatePipeline(boolean externalBool) { - Step step0 = gen.addStep(new OperationMetaData(HSLThresholdOperation.DESCRIPTION, + Step step0 = gen.addStep(new OperationMetaData( + OperationDescription.from(HSLThresholdOperation.class), () -> new HSLThresholdOperation(isf, osf))); loadImage(Files.imageFile); OutputSocket imgOut0 = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -62,7 +64,8 @@ void generatePipeline(boolean externalBool) { } } - Step step1 = gen.addStep(new OperationMetaData(FindContoursOperation.DESCRIPTION, + Step step1 = gen.addStep(new OperationMetaData( + OperationDescription.from(FindContoursOperation.class), () -> new FindContoursOperation(isf, osf))); OutputSocket imgOut1 = pipeline.getSteps().get(0).getOutputSockets().get(0); for (InputSocket sock : step1.getInputSockets()) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindLinesGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindLinesGenerationTesting.java index 53cb0d9f34..15181339bd 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindLinesGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/FindLinesGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.FindLinesOperation; @@ -51,7 +52,8 @@ public void ignoreIfWindows() { } void generatePipeline() { - Step step0 = gen.addStep(new OperationMetaData(HSLThresholdOperation.DESCRIPTION, + Step step0 = gen.addStep(new OperationMetaData( + OperationDescription.from(HSLThresholdOperation.class), () -> new HSLThresholdOperation(isf, osf))); loadImage(Files.imageFile); OutputSocket imgOut0 = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -68,7 +70,8 @@ void generatePipeline() { } } - Step step1 = gen.addStep(new OperationMetaData(FindLinesOperation.DESCRIPTION, + Step step1 = gen.addStep(new OperationMetaData( + OperationDescription.from(FindLinesOperation.class), () -> new FindLinesOperation(isf, osf))); OutputSocket imgOut1 = pipeline.getSteps().get(0).getOutputSockets().get(0); for (InputSocket sock : step1.getInputSockets()) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/GripIconHSLSetup.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/GripIconHSLSetup.java index 63ebdddfe4..5ddbc9a7cb 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/GripIconHSLSetup.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/GripIconHSLSetup.java @@ -1,5 +1,6 @@ package edu.wpi.grip.ui.codegeneration; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.HSLThresholdOperation; @@ -27,7 +28,8 @@ public static void setup(AbstractGenerationTesting caller) { public static void setup(AbstractGenerationTesting caller, List hVal, List sVal, List lVal) { - Step hsl = caller.gen.addStep(new OperationMetaData(HSLThresholdOperation.DESCRIPTION, + Step hsl = caller.gen.addStep(new OperationMetaData( + OperationDescription.from(HSLThresholdOperation.class), () -> new HSLThresholdOperation(caller.isf, caller.osf))); caller.loadImage(Files.imageFile); OutputSocket imgOut = caller.pipeline.getSources().get(0).getOutputSockets().get(0); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/HSVThresholdSetup.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/HSVThresholdSetup.java index 5124e2239d..84c35deeb0 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/HSVThresholdSetup.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/HSVThresholdSetup.java @@ -1,5 +1,6 @@ package edu.wpi.grip.ui.codegeneration; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.HSVThresholdOperation; @@ -16,7 +17,8 @@ static void setup(AbstractGenerationTesting caller) { List sVal = Arrays.asList(0.0d, 255.0d); List vVal = Arrays.asList(0.0d, 255.0d); - Step hsv = caller.gen.addStep(new OperationMetaData(HSVThresholdOperation.DESCRIPTION, + Step hsv = caller.gen.addStep(new OperationMetaData( + OperationDescription.from(HSVThresholdOperation.class), () -> new HSVThresholdOperation(caller.isf, caller.osf))); caller.loadImage(Files.imageFile); OutputSocket imgOut = caller.pipeline.getSources().get(0).getOutputSockets().get(0); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/MaskTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/MaskTesting.java index 45284ffd67..a2fbfdd832 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/MaskTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/MaskTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.MaskOperation; @@ -24,7 +25,8 @@ public class MaskTesting extends AbstractGenerationTesting { void set() { HSVThresholdSetup.setup(this); Step mask = gen.addStep( - new OperationMetaData(MaskOperation.DESCRIPTION, () -> new MaskOperation(isf, osf))); + new OperationMetaData(OperationDescription.from(MaskOperation.class), + () -> new MaskOperation(isf, osf))); OutputSocket hsvImg = pipeline.getSteps().get(0).getOutputSockets().get(0); for (InputSocket sock : mask.getInputSockets()) { String sockHint = sock.getSocketHint().getIdentifier(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NewPointGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NewPointGenerationTesting.java index e44a713ed3..2293081f0a 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NewPointGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NewPointGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.opencv.NewPointOperation; @@ -19,7 +20,8 @@ public class NewPointGenerationTesting extends AbstractGenerationTesting { void generatePipeline(double x, double y) { - Step desat = gen.addStep(new OperationMetaData(NewPointOperation.DESCRIPTION, + Step desat = gen.addStep(new OperationMetaData( + OperationDescription.from(NewPointOperation.class), () -> new NewPointOperation(isf, osf))); for (InputSocket sock : desat.getInputSockets()) { if (sock.getSocketHint().getIdentifier().equals("x")) { @@ -47,7 +49,7 @@ void pipelineTest(PipelineInterfacer pip) { pip.process(); Point genSize = (Point) pip.getOutput("New_Point_Output", GenType.POINT); assertSame("The grip x: " + gripSize.x() + "does not equals the generated x: " + genSize.x, - gripSize.x(), (int) genSize.x); + gripSize.x(), (int) genSize.x); assertSame("The grip y: " + gripSize.y() + "does not equals the generated y: " + genSize.y, gripSize.y(), (int) genSize.y); } diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NewSizeGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NewSizeGenerationTesting.java index 87229127bd..799f13f811 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NewSizeGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NewSizeGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.opencv.NewSizeOperation; @@ -20,7 +21,8 @@ public class NewSizeGenerationTesting extends AbstractGenerationTesting { void generatePipeline(double width, double height) { Step desat = gen.addStep( - new OperationMetaData(NewSizeOperation.DESCRIPTION, () -> new NewSizeOperation(isf, osf))); + new OperationMetaData(OperationDescription.from(NewSizeOperation.class), + () -> new NewSizeOperation(isf, osf))); for (InputSocket sock : desat.getInputSockets()) { if (sock.getSocketHint().getIdentifier().equals("width")) { sock.setValue(width); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NormalizeGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NormalizeGenerationTesting.java index 378a821471..c3936b72e3 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NormalizeGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/NormalizeGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.NormalizeOperation; @@ -24,7 +25,8 @@ public class NormalizeGenerationTesting extends AbstractGenerationTesting { void generatePipeline(String type, double minVal, double maxVal) { - Step step = gen.addStep(new OperationMetaData(NormalizeOperation.DESCRIPTION, + Step step = gen.addStep(new OperationMetaData( + OperationDescription.from(NormalizeOperation.class), () -> new NormalizeOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/RGBThresholdTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/RGBThresholdTesting.java index 924ad319c4..3ec4993a85 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/RGBThresholdTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/RGBThresholdTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.RGBThresholdOperation; @@ -25,8 +26,9 @@ public class RGBThresholdTesting extends AbstractGenerationTesting { boolean setup() { - final Step rgb = gen.addStep(new OperationMetaData(RGBThresholdOperation.DESCRIPTION, - () -> new RGBThresholdOperation(isf, osf))); + final Step rgb = gen.addStep( + new OperationMetaData(OperationDescription.from(RGBThresholdOperation.class), + () -> new RGBThresholdOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); List rVal = Arrays.asList(46d, 188d); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ResizeTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ResizeTesting.java index b02f81572a..ff79516a90 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ResizeTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ResizeTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.ResizeOperation; @@ -23,7 +24,8 @@ public class ResizeTesting extends AbstractGenerationTesting { void setup(String interp) { Step resize = gen.addStep( - new OperationMetaData(ResizeOperation.DESCRIPTION, () -> new ResizeOperation(isf, osf))); + new OperationMetaData(OperationDescription.from(ResizeOperation.class), + () -> new ResizeOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : resize.getInputSockets()) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/SwitchTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/SwitchTesting.java index 2062958c15..5dcb1189a0 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/SwitchTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/SwitchTesting.java @@ -1,5 +1,6 @@ package edu.wpi.grip.ui.codegeneration; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Source; import edu.wpi.grip.core.Step; @@ -31,7 +32,8 @@ boolean setupNum(double onTrue, double onFalse, Boolean initVal) { boolean setup(Source onTrue, Source onFalse, Boolean initVal) { Step step = gen.addStep( - new OperationMetaData(SwitchOperation.DESCRIPTION, () -> new SwitchOperation(isf, osf))); + new OperationMetaData(OperationDescription.from(SwitchOperation.class), + () -> new SwitchOperation(isf, osf))); for (InputSocket sock : step.getInputSockets()) { String sockHint = sock.getSocketHint().getIdentifier(); if ("if True".equalsIgnoreCase(sockHint)) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ThresholdMovingTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ThresholdMovingTesting.java index 20aa810521..130d4fc76b 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ThresholdMovingTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ThresholdMovingTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -27,6 +28,7 @@ public class ThresholdMovingTesting extends AbstractGenerationTesting { * Sets up the pipeline with given number of moving thresholds. * * @param num number of moving thresholds to put in pipeline, 1 indexed. + * * @return an array of the switch steps used to trigger the moving thresholds. */ public ThresholdSwitch[] setupThreshold(int num) { @@ -35,7 +37,8 @@ public ThresholdSwitch[] setupThreshold(int num) { OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (int idx = 0; idx < num; idx++) { Step blur = gen.addStep( - new OperationMetaData(BlurOperation.DESCRIPTION, () -> new BlurOperation(isf, osf))); + new OperationMetaData(OperationDescription.from(BlurOperation.class), + () -> new BlurOperation(isf, osf))); for (InputSocket sock : blur.getInputSockets()) { String socketHint = sock.getSocketHint().getIdentifier(); if ("Input".equals(socketHint)) { @@ -45,7 +48,8 @@ public ThresholdSwitch[] setupThreshold(int num) { } } // end of blur Step swtch = gen.addStep( - new OperationMetaData(SwitchOperation.DESCRIPTION, () -> new SwitchOperation(isf, osf))); + new OperationMetaData(OperationDescription.from(SwitchOperation.class), + () -> new SwitchOperation(isf, osf))); for (InputSocket sock : swtch.getInputSockets()) { String sockHint = sock.getSocketHint().getIdentifier(); if ("If True".equals(sockHint)) { @@ -55,7 +59,8 @@ public ThresholdSwitch[] setupThreshold(int num) { } } Step move = gen.addStep( - new OperationMetaData(ThresholdMoving.DESCRIPTION, () -> new ThresholdMoving(isf, osf))); + new OperationMetaData(OperationDescription.from(ThresholdMoving.class), + () -> new ThresholdMoving(isf, osf))); for (InputSocket sock : move.getInputSockets()) { if (sock.getSocketHint().getIdentifier().equalsIgnoreCase("image")) { gen.connect(swtch.getOutputSockets().get(0), sock); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ValveTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ValveTesting.java index f779b464aa..83bf9c3240 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ValveTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/ValveTesting.java @@ -1,5 +1,6 @@ package edu.wpi.grip.ui.codegeneration; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.ValveOperation; @@ -23,7 +24,8 @@ public class ValveTesting extends AbstractGenerationTesting { boolean setup(Number value) { Step valve = gen.addStep( - new OperationMetaData(ValveOperation.DESCRIPTION, () -> new ValveOperation(isf, osf))); + new OperationMetaData(OperationDescription.from(ValveOperation.class), + () -> new ValveOperation(isf, osf))); MockNumberSource src = new MockNumberSource(ewf, value.doubleValue(), osf); for (InputSocket sock : valve.getInputSockets()) { String socketHint = sock.getSocketHint().getIdentifier(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/WatershedGenerationTesting.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/WatershedGenerationTesting.java index 61d1761434..1bf0fb8829 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/WatershedGenerationTesting.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/WatershedGenerationTesting.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.FindContoursOperation; @@ -39,7 +40,8 @@ public WatershedGenerationTesting() { } void generatePipeline() { - Step step0 = gen.addStep(new OperationMetaData(HSLThresholdOperation.DESCRIPTION, + Step step0 = gen.addStep(new OperationMetaData( + OperationDescription.from(HSLThresholdOperation.class), () -> new HSLThresholdOperation(isf, osf))); loadImage(Files.imageFile); OutputSocket imgOut0 = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -56,7 +58,8 @@ void generatePipeline() { } } - Step step1 = gen.addStep(new OperationMetaData(FindContoursOperation.DESCRIPTION, + Step step1 = gen.addStep(new OperationMetaData( + OperationDescription.from(FindContoursOperation.class), () -> new FindContoursOperation(isf, osf))); OutputSocket imgOut1 = pipeline.getSteps().get(0).getOutputSockets().get(0); for (InputSocket sock : step1.getInputSockets()) { @@ -67,7 +70,8 @@ void generatePipeline() { } } - Step step2 = gen.addStep(new OperationMetaData(WatershedOperation.DESCRIPTION, + Step step2 = gen.addStep(new OperationMetaData( + OperationDescription.from(WatershedOperation.class), () -> new WatershedOperation(isf, osf))); OutputSocket imgOut2 = pipeline.getSteps().get(1).getOutputSockets().get(0); for (InputSocket sock : step2.getInputSockets()) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAbsDiff.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAbsDiff.java index e068bfca64..0a90de1bb5 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAbsDiff.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAbsDiff.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -13,7 +14,6 @@ import edu.wpi.grip.util.Files; import org.junit.Test; - import org.opencv.core.Mat; import java.util.Optional; @@ -24,7 +24,8 @@ public class CVAbsDiff extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -43,12 +44,12 @@ boolean set() { gen.connect(blur.getOutputSockets().get(0), abs.getInputSockets().get(1)); return true; } - + @Test public void absDiffTest() { test(() -> set(), (pip) -> validate(pip), "AbsDiffTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAdaptiveThreshold.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAdaptiveThreshold.java index 0b5a5ce099..69711f815b 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAdaptiveThreshold.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAdaptiveThreshold.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.CVOperations; @@ -26,8 +27,9 @@ public class CVAdaptiveThreshold extends AbstractGenerationTesting { boolean setup(AdaptiveThresholdTypesEnum adaptMethod, CVOperations.CVAdaptThresholdTypesEnum threshMethod) { - Step desat = gen.addStep(new OperationMetaData(DesaturateOperation.DESCRIPTION, () -> new - DesaturateOperation(isf, osf))); + Step desat = gen.addStep(new OperationMetaData( + OperationDescription.from(DesaturateOperation.class), + () -> new DesaturateOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : desat.getInputSockets()) { @@ -48,7 +50,7 @@ boolean setup(AdaptiveThresholdTypesEnum adaptMethod, @Test public void binaryMeanTest() { - test(() -> setup(AdaptiveThresholdTypesEnum.ADAPTIVE_THRESH_MEAN_C, + test(() -> setup(AdaptiveThresholdTypesEnum.ADAPTIVE_THRESH_MEAN_C, CVOperations.CVAdaptThresholdTypesEnum.THRESH_BINARY), (pip) -> validate(pip), "cvBinaryMeanATTest"); } diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAdd.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAdd.java index 59360c36bc..ab776dd4ee 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAdd.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAdd.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,8 +24,8 @@ public class CVAdd extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -42,12 +43,12 @@ boolean set() { gen.connect(blur.getOutputSockets().get(0), add.getInputSockets().get(1)); return true; } - + @Test public void cvAddTest() { test(() -> set(), (pip) -> validate(pip), "CvAddTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAddWeighted.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAddWeighted.java index f8fc0a9bab..1abd4780b2 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAddWeighted.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVAddWeighted.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,8 +24,8 @@ public class CVAddWeighted extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -45,12 +46,12 @@ boolean set() { add.getInputSockets().get(4).setValue(new Double(0.5)); return true; } - + @Test public void cvAddWeightedTest() { test(() -> set(), (pip) -> validate(pip), "CvAddWeightedTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseAnd.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseAnd.java index 55b21957a2..1c39cd5789 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseAnd.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseAnd.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,8 +24,8 @@ public class CVBitwiseAnd extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -42,12 +43,12 @@ boolean set() { gen.connect(blur.getOutputSockets().get(0), add.getInputSockets().get(1)); return true; } - + @Test public void cvBitwiseAndTest() { test(() -> set(), (pip) -> validate(pip), "CvBitwiseAndTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseOr.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseOr.java index f63385133c..d11905336c 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseOr.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseOr.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,8 +24,8 @@ public class CVBitwiseOr extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -42,12 +43,12 @@ boolean set() { gen.connect(blur.getOutputSockets().get(0), or.getInputSockets().get(1)); return true; } - + @Test public void cvBitwiseOrTest() { test(() -> set(), (pip) -> validate(pip), "CvBitwiseOrTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseXor.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseXor.java index 79b034fad8..f3c7ca009f 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseXor.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVBitwiseXor.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,8 +24,8 @@ public class CVBitwiseXor extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -42,12 +43,12 @@ boolean set() { gen.connect(blur.getOutputSockets().get(0), xOr.getInputSockets().get(1)); return true; } - + @Test public void cvBitwiseXorTest() { test(() -> set(), (pip) -> validate(pip), "CvBitwiseXorTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVCompare.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVCompare.java index a30ceb3ac2..68f8df7ffb 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVCompare.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVCompare.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -24,8 +25,8 @@ public class CVCompare extends AbstractGenerationTesting { boolean set(CmpTypesEnum val) { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -44,37 +45,37 @@ boolean set(CmpTypesEnum val) { cmp.getInputSockets().get(2).setValue(val); return true; } - + @Test public void cvCompareEqTest() { test(() -> set(CmpTypesEnum.CMP_EQ), (pip) -> validate(pip), "CvCmpEqTest"); } - + @Test public void cvCompareGtTest() { test(() -> set(CmpTypesEnum.CMP_GT), (pip) -> validate(pip), "CvCmpGtTest"); } - + @Test public void cvCompareGeTest() { test(() -> set(CmpTypesEnum.CMP_GE), (pip) -> validate(pip), "CvCmpGeTest"); } - + @Test public void cvCompareLtTest() { test(() -> set(CmpTypesEnum.CMP_LT), (pip) -> validate(pip), "CvCmpLtTest"); } - + @Test public void cvCompareLeTest() { test(() -> set(CmpTypesEnum.CMP_LE), (pip) -> validate(pip), "CvCmpLeTest"); } - + @Test public void cvCompareNeTest() { test(() -> set(CmpTypesEnum.CMP_NE), (pip) -> validate(pip), "CvCmpNeTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVDivide.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVDivide.java index 5e7e331b50..82c6e65dda 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVDivide.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVDivide.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,8 +24,8 @@ public class CVDivide extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -43,12 +44,12 @@ boolean set() { div.getInputSockets().get(2).setValue(new Double(0.5)); return true; } - + @Test public void cvDivideTest() { test(() -> set(), (pip) -> validate(pip), "CvDivideTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVGaussianBlur.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVGaussianBlur.java index 427edb9d5b..91f3b5543d 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVGaussianBlur.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVGaussianBlur.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.opencv.NewSizeOperation; @@ -27,8 +28,8 @@ public class CVGaussianBlur extends AbstractGenerationTesting { private static final double sigmay = 41; boolean setup(String type) { - Step step0 = gen.addStep(new OperationMetaData(NewSizeOperation.DESCRIPTION, () -> new - NewSizeOperation(isf, osf))); + Step step0 = gen.addStep(new OperationMetaData( + OperationDescription.from(NewSizeOperation.class), () -> new NewSizeOperation(isf, osf))); for (InputSocket sock : step0.getInputSockets()) { if (sock.getSocketHint().getIdentifier().equals("width")) { sock.setValue(width); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMax.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMax.java index b925d42d7a..7bb4db2d94 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMax.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMax.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,8 +24,8 @@ public class CVMax extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -42,12 +43,12 @@ boolean set() { gen.connect(blur.getOutputSockets().get(0), max.getInputSockets().get(1)); return true; } - + @Test public void cvMaxTest() { test(() -> set(), (pip) -> validate(pip), "CvMaxTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMin.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMin.java index a2543f2aca..ede9a9487d 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMin.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMin.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,8 +24,8 @@ public class CVMin extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -42,12 +43,12 @@ boolean set() { gen.connect(blur.getOutputSockets().get(0), min.getInputSockets().get(1)); return true; } - + @Test public void cvMinTest() { test(() -> set(), (pip) -> validate(pip), "CvMinTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMultiply.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMultiply.java index 47502186ef..04da96ed5d 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMultiply.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVMultiply.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,8 +24,8 @@ public class CVMultiply extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new - BlurOperation(isf, osf))); + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); for (InputSocket sock : blur.getInputSockets()) { @@ -43,12 +44,12 @@ boolean set() { max.getInputSockets().get(2).setValue(2); return true; } - + @Test public void cvMultiplyTest() { test(() -> set(), (pip) -> validate(pip), "CvMultiplyTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVRectangle.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVRectangle.java index f748ee17b6..3a174311df 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVRectangle.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVRectangle.java @@ -2,6 +2,7 @@ import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.opencv.NewPointOperation; @@ -31,7 +32,8 @@ public class CVRectangle extends AbstractGenerationTesting { boolean setup(String type) { - Step step0 = gen.addStep(new OperationMetaData(NewPointOperation.DESCRIPTION, () -> new + Step step0 = gen.addStep(new OperationMetaData( + OperationDescription.from(NewPointOperation.class), () -> new NewPointOperation(isf, osf))); for (InputSocket sock : step0.getInputSockets()) { if (sock.getSocketHint().getIdentifier().equals("x")) { @@ -41,7 +43,8 @@ boolean setup(String type) { } } - Step step1 = gen.addStep(new OperationMetaData(NewPointOperation.DESCRIPTION, () -> new + Step step1 = gen.addStep(new OperationMetaData( + OperationDescription.from(NewPointOperation.class), () -> new NewPointOperation(isf, osf))); for (InputSocket sock : step1.getInputSockets()) { if (sock.getSocketHint().getIdentifier().equals("x")) { diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVScaleAdd.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVScaleAdd.java index 465c4daeb2..082f5c1a72 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVScaleAdd.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVScaleAdd.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,7 +24,8 @@ public class CVScaleAdd extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -43,12 +45,12 @@ boolean set() { sAdd.getInputSockets().get(1).setValue(new Double(1.23)); return true; } - + @Test public void cvScaleAddTest() { test(() -> set(), (pip) -> validate(pip), "CvScaleAddTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVSubtract.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVSubtract.java index 84b6fd95d4..a521dc1ab9 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVSubtract.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVSubtract.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.BlurOperation; @@ -23,7 +24,8 @@ public class CVSubtract extends AbstractGenerationTesting { boolean set() { - Step blur = gen.addStep(new OperationMetaData(BlurOperation.DESCRIPTION, () -> new + Step blur = gen.addStep(new OperationMetaData( + OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); @@ -42,12 +44,12 @@ boolean set() { gen.connect(blur.getOutputSockets().get(0), sub.getInputSockets().get(1)); return true; } - + @Test public void cvSubtractTest() { test(() -> set(), (pip) -> validate(pip), "CvSubtractTest"); } - + void validate(PipelineInterfacer pip) { ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); runner.runPipeline(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVThreshold.java b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVThreshold.java index 7799254a0b..702d68e340 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVThreshold.java +++ b/ui/src/test/java/edu/wpi/grip/ui/codegeneration/cv/CVThreshold.java @@ -1,6 +1,7 @@ package edu.wpi.grip.ui.codegeneration.cv; import edu.wpi.grip.core.ManualPipelineRunner; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Step; import edu.wpi.grip.core.operations.composite.DesaturateOperation; @@ -25,7 +26,8 @@ public class CVThreshold extends AbstractGenerationTesting { private static final double maxval = 200; boolean setup(String type) { - Step desat = gen.addStep(new OperationMetaData(DesaturateOperation.DESCRIPTION, () -> new + Step desat = gen.addStep(new OperationMetaData( + OperationDescription.from(DesaturateOperation.class), () -> new DesaturateOperation(isf, osf))); loadImage(Files.gompeiJpegFile); OutputSocket imgOut = pipeline.getSources().get(0).getOutputSockets().get(0); diff --git a/ui/src/test/java/edu/wpi/grip/ui/pipeline/PipelineUITest.java b/ui/src/test/java/edu/wpi/grip/ui/pipeline/PipelineUITest.java index 355a16d8a6..e918a032b0 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/pipeline/PipelineUITest.java +++ b/ui/src/test/java/edu/wpi/grip/ui/pipeline/PipelineUITest.java @@ -3,6 +3,7 @@ import edu.wpi.grip.core.AdditionOperation; import edu.wpi.grip.core.Connection; import edu.wpi.grip.core.MockStep; +import edu.wpi.grip.core.OperationDescription; import edu.wpi.grip.core.OperationMetaData; import edu.wpi.grip.core.Pipeline; import edu.wpi.grip.core.Step; @@ -74,10 +75,11 @@ public void start(Stage stage) { AdditionOperation(isf, osf)); subtractionOperation = new OperationMetaData(SubtractionOperation.DESCRIPTION, () -> new SubtractionOperation(isf, osf)); - blurOperation = new OperationMetaData(BlurOperation.DESCRIPTION, () -> new + blurOperation = new OperationMetaData(OperationDescription.from(BlurOperation.class), () -> new BlurOperation(isf, osf)); - desaturateOperation = new OperationMetaData(DesaturateOperation.DESCRIPTION, () -> new - DesaturateOperation(isf, osf)); + desaturateOperation = new OperationMetaData( + OperationDescription.from(DesaturateOperation.class), + () -> new DesaturateOperation(isf, osf)); pipelineController = injector.getInstance(PipelineController.class); final Scene scene = new Scene(TestAnnotationFXMLLoader.load(pipelineController), 800, 600); stage.setScene(scene); diff --git a/ui/src/test/java/edu/wpi/grip/ui/pipeline/input/InputSocketControllerFactoryTest.java b/ui/src/test/java/edu/wpi/grip/ui/pipeline/input/InputSocketControllerFactoryTest.java index 632227c5d3..67ee90720d 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/pipeline/input/InputSocketControllerFactoryTest.java +++ b/ui/src/test/java/edu/wpi/grip/ui/pipeline/input/InputSocketControllerFactoryTest.java @@ -61,7 +61,7 @@ public static Collection data() { .with(new MockGripNetworkModule())); final Palette palette = injector.getInstance(Palette.class); final EventBus eventBus = injector.getInstance(EventBus.class); - OperationsFactory.create(eventBus).addOperations(); + OperationsFactory.create(eventBus, injector).addOperations(); OperationsFactory.createCV(eventBus).addOperations(); Collection operationMetas = palette.getOperations();