diff --git a/scijava-ops-tutorial/src/main/java/module-info.java b/scijava-ops-tutorial/src/main/java/module-info.java index 12cf5091c..bfeb5c282 100644 --- a/scijava-ops-tutorial/src/main/java/module-info.java +++ b/scijava-ops-tutorial/src/main/java/module-info.java @@ -1,3 +1,5 @@ +import org.scijava.ops.tutorial.OpConversion; + /*- * #%L * ImageJ2 software for multidimensional image processing and analysis. @@ -26,46 +28,14 @@ * POSSIBILITY OF SUCH DAMAGE. * #L% */ -module org.scijava.ops.tutorial { - exports org.scijava.ops.tutorial; +module org.scijava.ops.tutorial{exports org.scijava.ops.tutorial; - // -- Open plugins to scijava-ops, therapi - opens org.scijava.ops.tutorial to therapi.runtime.javadoc, org.scijava.ops.engine; +// -- Open plugins to scijava-ops, therapi +opens org.scijava.ops.tutorial to therapi.runtime.javadoc,org.scijava.ops.engine; - requires io.scif; - requires java.scripting; - requires net.imglib2; - requires net.imglib2.algorithm; - requires net.imglib2.algorithm.fft2; - requires net.imglib2.roi; - requires org.joml; - requires org.scijava.collections; - requires org.scijava.function; - requires org.scijava.meta; - requires org.scijava.ops.api; - requires org.scijava.ops.engine; - requires org.scijava.ops.image; - requires org.scijava.ops.spi; - requires org.scijava.parsington; - requires org.scijava.priority; - requires org.scijava.progress; - requires org.scijava.types; - requires org.scijava; +requires io.scif;requires java.scripting;requires net.imglib2;requires net.imglib2.algorithm;requires net.imglib2.algorithm.fft2;requires net.imglib2.roi;requires org.joml;requires org.scijava.collections;requires org.scijava.function;requires org.scijava.meta;requires org.scijava.ops.api;requires org.scijava.ops.engine;requires org.scijava.ops.image;requires org.scijava.ops.spi;requires org.scijava.parsington;requires org.scijava.priority;requires org.scijava.progress;requires org.scijava.types;requires org.scijava; - // FIXME: these module names derive from filenames and are thus unstable - requires commons.math3; - requires ojalgo; - requires jama; - requires mines.jtk; +// FIXME: these module names derive from filenames and are thus unstable +requires commons.math3;requires ojalgo;requires jama;requires mines.jtk; - provides org.scijava.ops.spi.OpCollection with - org.scijava.ops.tutorial.OpAdaptation, - org.scijava.ops.tutorial.OpDependencies, - org.scijava.ops.tutorial.OpParallelization, - org.scijava.ops.tutorial.OpPriorities, - org.scijava.ops.tutorial.OpReduction, - org.scijava.ops.tutorial.OpSimplification, - org.scijava.ops.tutorial.ReportingProgress, - org.scijava.ops.tutorial.UsingNils, - org.scijava.ops.tutorial.WritingOpCollections; -} +provides org.scijava.ops.spi.OpCollection with org.scijava.ops.tutorial.OpAdaptation,org.scijava.ops.tutorial.OpDependencies,org.scijava.ops.tutorial.OpParallelization,org.scijava.ops.tutorial.OpPriorities,org.scijava.ops.tutorial.OpReduction,OpConversion,org.scijava.ops.tutorial.ReportingProgress,org.scijava.ops.tutorial.UsingNils,org.scijava.ops.tutorial.WritingOpCollections;} diff --git a/scijava-ops-tutorial/src/main/java/org/scijava/ops/tutorial/OpSimplification.java b/scijava-ops-tutorial/src/main/java/org/scijava/ops/tutorial/OpConversion.java similarity index 55% rename from scijava-ops-tutorial/src/main/java/org/scijava/ops/tutorial/OpSimplification.java rename to scijava-ops-tutorial/src/main/java/org/scijava/ops/tutorial/OpConversion.java index f146d3cb1..1782b4635 100644 --- a/scijava-ops-tutorial/src/main/java/org/scijava/ops/tutorial/OpSimplification.java +++ b/scijava-ops-tutorial/src/main/java/org/scijava/ops/tutorial/OpConversion.java @@ -42,32 +42,43 @@ * calls with just one implementation. The simplest type of transformation is * showcased in {@link OpAdaptation}. *

- * A more complex type of transformation is called "simplification". This type - * involves transforming some subset of Op inputs into a different, but similar - * type. This process makes use of three different Op types: + * A more complex type of transformation transforms Op parameters, termed + * parameter "conversion". This type This process makes use of two different Op + * types: *

*

- * Simplification can be used to call a method implemented for parameters of one - * type on a completely different type. This can be as simple as using an - * Integer instead of a Double, or go beyond the Java type assignability with - * custom defined type conversion (e.g. images from one library to another). + * Conversion can be used to call an Op using parameters of completely different + * types. This can be as simple as using an Integer instead of a Double, or go + * beyond the Java type assignability with custom defined type conversion (e.g. + * images from one library to another). When this happens, the following steps + * are taken: + *

    + *
  1. All inputs are converted to types required by the Op, using + * {@code engine.convert} "preconverter" Ops.
  2. + *
  3. The Op is invoked on the converted inputs
  4. + *
  5. If the Op defines a pure output object, that output is converted + * to the user's requested type using a {@code engine.convert} "postconverter" + * Op
  6. + *
  7. If the Op defines a mutable output object (i.e. a pre-allocated + * output buffer), the converted pre-allocated output buffer is copied back into + * the user's pre-allocated output buffer using a {@code engine.copy} Op.
  8. + *
*

* Below, we can see how this works by calling the above Field Op, implemented * for Double, on a Double[] instead */ -public class OpSimplification implements OpCollection { +public class OpConversion implements OpCollection { /** * A simple Op, written as a {@link Field}, that performs a simple * calculation. */ - @OpField(names = "tutorial.simplify") + @OpField(names = "tutorial.conversion") public final BiFunction fieldOp = (a, b) -> { return a * 2 + b; }; @@ -78,8 +89,8 @@ public static void main(String... args) { // Call the Op on some inputs Integer first = 1; Integer second = 2; - // Ask for an Op of name "tutorial.simplify" - Integer result = ops.binary("tutorial.simplify") // + // Ask for an Op of name "tutorial.conversion" + Integer result = ops.binary("tutorial.conversion") // // With our two Integer inputs .input(first, second) // // And get an Integer out @@ -89,22 +100,22 @@ public static void main(String... args) { .apply(); /* - The simplification routine works as follows: - 1. SciJava Ops determines that there are no existing "tutorial.simplify" Ops - that work on Integers + The conversion routine works as follows: + 1. SciJava Ops determines that there are no existing "tutorial.conversion" + Ops that work on Integers - 2. SciJava Ops finds a "engine.focus" Op that can make Doubles from Numbers. Thus, - if the inputs are Numbers, SciJava Ops could use this "engine.focus" Op to make - those Numbers into Doubles + 2. SciJava Ops finds an "engine.convert" Op that can make Doubles from + Integers. Thus, if the inputs are Integers, SciJava Ops could use this + "engine.convert" Op to make those Integers into Doubles - 3. SciJava Ops finds a "engine.convert" Op that can make Numbers from Integers. - Thus, if the inputs are Integers, SciJava Ops can use this "engine.convert" Op - to make those Integers into Numbers + 2. SciJava Ops finds an "engine.convert" Op that can make Integers from + Doubles. Thus, if a Double output is requested, SciJava Ops could use this + "engine.convert" Op to make a Double output from an Integer - 4. By using the "engine.convert" and then the "engine.focus" Op, SciJava Ops can convert - the Integer inputs into Double inputs, and by creating a similar chain - in reverse, can convert the Double output into an Integer output. - Thus, we get an Op that can run on Integers! + 3. By using the "engine.convert" Ops, SciJava Ops can convert each of + the Integer inputs into Double inputs, and then can convert the Double + output back into the Integer the user requested. Thus, we get an Op that can + run on Integers! */ System.out.println(result); diff --git a/scijava-ops-tutorial/src/main/resources/META-INF/services/org.scijava.ops.spi.OpCollection b/scijava-ops-tutorial/src/main/resources/META-INF/services/org.scijava.ops.spi.OpCollection index 63ae28d1f..4217cc2e9 100644 --- a/scijava-ops-tutorial/src/main/resources/META-INF/services/org.scijava.ops.spi.OpCollection +++ b/scijava-ops-tutorial/src/main/resources/META-INF/services/org.scijava.ops.spi.OpCollection @@ -5,7 +5,7 @@ org.scijava.ops.tutorial.OpDependencies org.scijava.ops.tutorial.OpParallelization org.scijava.ops.tutorial.OpPriorities org.scijava.ops.tutorial.OpReduction -org.scijava.ops.tutorial.OpSimplification +org.scijava.ops.tutorial.OpConversion org.scijava.ops.tutorial.ReportingProgress org.scijava.ops.tutorial.UsingNils org.scijava.ops.tutorial.WritingOpCollections