Skip to content

Commit 18eca6e

Browse files
committed
Add suggested updates to WritingYourOwnOpPackage
1 parent dafc9af commit 18eca6e

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

docs/ops/doc/WritingYourOwnOpPackage.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,37 +278,51 @@ class DoubleSizeOp implements Function<double[], Double> {
278278

279279
### Defining Op Progress
280280

281-
By adding the `scijava-progress` module, your Op can define and update its progress, providing user value for long-running Ops. To add progress to your Op, you must add the following steps to your Op:
281+
The `scijava-progress` module provides a mechanism for long-running tasks to describe their progress through textual or graphical means. For example, `scijava-progress` enables [Fiji](https://fiji.sc/) users to observe the progress of every Op invoked within the application, as shown below.
282+
283+
<figure>
284+
<img src="https://media.scijava.org/scijava-ops/1.0.0/scijava_progress_example.png" alt="scijava-progress updates within Fiji"/>
285+
<figcaption><em>scijava-progress provides updates from all Op executions within Fiji's `Tasks` pane. </em></figcaption>
286+
</figure>
287+
288+
While all Ops emit "binary" progress (denoting each Op's beginning and end), your Op can provide richer updates by adding the `scijava-progress` module, providing user value for long-running Ops. To add progress to your Op, you must add the following steps to your Op:
289+
282290
* Before any significant computation, add the line `Progress.defineTotal(long elements)` where `elements` is the number of "discrete packets" of computation.
283291
* At convenient spots within your Op, call `Progress.update()` to denote that one packet of computation has finished.
284292
* **Alternatively**, it may be more convenient or performant to call `Progress.update(long numElements)` to denote `numElements` packets have completed at once.
285293

286294
```java
295+
import java.util.function.Function;
296+
import org.scijava.progress.Progress;
297+
287298
/**
288299
* A simple summer
289300
*
290301
* @implNote op names="stats.sum"
291302
*/
292303
class DoubleSumOp implements Function<double[], Double> {
293304
public Double apply(final double[] inArray) {
305+
// define total progress size
294306
Progress.defineTotal(inArray.length);
295307
double sum = 0;
296308
for (double v : inArray) {
297309
sum += v;
310+
// increment progress
298311
Progress.update();
299312
}
300313
return i;
301314
}
302315
}
303316
```
304317

305-
If your Op defines Op dependencies whose progress you'd like to include in your total progress, you can make the following changes.
306-
* For each Op dependency that you want to track, pass the Hint `"progress.TRACK"` within the `@OpDependency` annotation.
318+
If your want to include the progress of Op dependencies within your Op's total progress, you can make the following changes.
319+
* For each Op dependency that you want to track, pass the Hint `"progress.TRACK"` within the `@OpDependency` annotation. Note that it is **not** necessary for each Op to explicitly define its progress, but if it does so your Op will provide richer progress updates!
307320
* Replace `Progress.defineTotal(long elements)` with `Progress.defineTotal(long elements, long subTasks)`, where `subTasks` is the **total** number of times you will invoke Op dependencies annotated with `"progress.TRACK"`.
308321

309322

310323
```java
311-
324+
import java.util.function.Function;
325+
import org.scijava.progress.Progress;
312326
import org.scijava.ops.spi.OpDependency;
313327

314328
/**
@@ -336,6 +350,8 @@ class DoubleMeanOp implements Function<double[], Double> {
336350
}
337351
```
338352

353+
For best results, ensure your Op records Progress updates at a reasonable frequency. If too frequent, progress updates can detract from algorithm performance, and if too infrequent, they will be of little help to the user!
354+
339355
### Element-wise Ops
340356

341357
Simple pixel-wise operations like addition, inversion, and more can be written on a single pixel (i.e. `RealType`) - therefore, SciJava Ops Image takes care to automagically adapt pixel-wise Ops across a wide variety of image types. If you would like to write a pixel-wise Op, we recommend the following structure.

0 commit comments

Comments
 (0)