Skip to content

Commit 0d5c5f9

Browse files
committed
Granular updates
1 parent 98c8520 commit 0d5c5f9

File tree

14 files changed

+282
-193
lines changed

14 files changed

+282
-193
lines changed

scijava-ops-api/src/main/java/org/scijava/ops/api/OpEnvironment.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
*/
6464
public interface OpEnvironment extends Prioritized<OpEnvironment> {
6565

66+
/**
67+
* Generates an <b>empty</b> {@link OpEnvironment}, which can be populated with the Ops of the caller's choice.
68+
* @return an empty {@link OpEnvironment}
69+
* @see #build() for an {@link OpEnvironment} that is fully populated
70+
*/
6671
static OpEnvironment buildEmpty() {
6772
Optional<OpEnvironment> opsOptional = Discoverer //
6873
.using(ServiceLoader::load) //
@@ -72,22 +77,29 @@ static OpEnvironment buildEmpty() {
7277
);
7378
}
7479

80+
/**
81+
* Generates an {@link OpEnvironment} with all available Ops.
82+
* @return an {@link OpEnvironment} with all available Ops.
83+
* @see #buildEmpty() for an {@link OpEnvironment} that is empty
84+
*/
7585
static OpEnvironment build() {
7686
OpEnvironment ops = buildEmpty();
7787
ops.discoverEverything();
7888
return ops;
7989
}
8090

8191
/**
82-
* Obtains all Ops in the {@link OpEnvironment}.
92+
* Obtains all Ops in the {@link OpEnvironment}, sorted by priority.
8393
*
8494
* @return a {@link SortedSet} containing all Ops contained in the
8595
* {@link OpEnvironment}.
8696
*/
87-
SortedSet<OpInfo> infos();
97+
default SortedSet<OpInfo> infos() {
98+
return infos(null, getDefaultHints());
99+
}
88100

89101
/**
90-
* Obtains all Ops in the {@link OpEnvironment} that are named {@code name}.
102+
* Obtains all Ops in the {@link OpEnvironment} that are named {@code name}, sorted by priority.
91103
*
92104
* @param name the {@link String} of all Ops to be returned.
93105
* @return a {@link SortedSet} containing all Ops in the {@link OpEnvironment}
@@ -96,7 +108,7 @@ static OpEnvironment build() {
96108
SortedSet<OpInfo> infos(String name);
97109

98110
/**
99-
* Obtains all Ops in the {@link OpEnvironment} that match {@code hints}
111+
* Obtains all Ops in the {@link OpEnvironment} that match {@code hints}, sorted by priority
100112
*
101113
* @param hints the {@link Hints} used to filter available Ops.
102114
* @return a {@link SortedSet} containing all Ops in the {@link OpEnvironment}
@@ -106,7 +118,7 @@ static OpEnvironment build() {
106118

107119
/**
108120
* Obtains all Ops in the {@link OpEnvironment} that are named {@code name}
109-
* and match {@code hints}
121+
* and match {@code hints}, sorted by priority
110122
*
111123
* @param name the {@link String} of all Ops to be returned.
112124
* @param hints the {@link Hints} used to filter available Ops.

scijava-ops-engine/pom.xml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -107,36 +107,36 @@
107107

108108
<build>
109109
<plugins>
110-
<plugin>
111-
<artifactId>maven-invoker-plugin</artifactId>
112-
<version>${maven-invoker-plugin.version}</version>
113-
<configuration>
114-
<!-- <debug>true</debug> -->
115-
<showErrors>true</showErrors>
116-
<properties>
117-
<scijava-maven.version>${project.version}</scijava-maven.version>
118-
</properties>
119-
<projectsDirectory>src/it</projectsDirectory>
120-
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
121-
<pomIncludes>
122-
<pomInclude>*/pom.xml</pomInclude>
123-
</pomIncludes>
124-
<settingsFile>src/it/settings.xml</settingsFile>
125-
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
126-
<goals>
127-
<goal>install</goal>
128-
</goals>
129-
</configuration>
130-
<executions>
131-
<execution>
132-
<id>integration-test</id>
133-
<goals>
134-
<goal>install</goal>
135-
<goal>run</goal>
136-
</goals>
137-
</execution>
138-
</executions>
139-
</plugin>
110+
<!-- <plugin>-->
111+
<!-- <artifactId>maven-invoker-plugin</artifactId>-->
112+
<!-- <version>${maven-invoker-plugin.version}</version>-->
113+
<!-- <configuration>-->
114+
<!-- &lt;!&ndash; <debug>true</debug> &ndash;&gt;-->
115+
<!-- <showErrors>true</showErrors>-->
116+
<!-- <properties>-->
117+
<!-- <scijava-maven.version>${project.version}</scijava-maven.version>-->
118+
<!-- </properties>-->
119+
<!-- <projectsDirectory>src/it</projectsDirectory>-->
120+
<!-- <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>-->
121+
<!-- <pomIncludes>-->
122+
<!-- <pomInclude>*/pom.xml</pomInclude>-->
123+
<!-- </pomIncludes>-->
124+
<!-- <settingsFile>src/it/settings.xml</settingsFile>-->
125+
<!-- <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>-->
126+
<!-- <goals>-->
127+
<!-- <goal>install</goal>-->
128+
<!-- </goals>-->
129+
<!-- </configuration>-->
130+
<!-- <executions>-->
131+
<!-- <execution>-->
132+
<!-- <id>integration-test</id>-->
133+
<!-- <goals>-->
134+
<!-- <goal>install</goal>-->
135+
<!-- <goal>run</goal>-->
136+
<!-- </goals>-->
137+
<!-- </execution>-->
138+
<!-- </executions>-->
139+
<!-- </plugin>-->
140140
</plugins>
141141
</build>
142142

scijava-ops-image/src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
requires org.scijava.concurrent;
4343
requires org.scijava.function;
4444
requires org.scijava.meta;
45-
requires org.scijava.ops.api;
4645
requires org.scijava.progress;
46+
requires org.scijava.ops.api;
4747
requires org.scijava.ops.spi;
4848
requires org.scijava.priority;
4949
requires org.scijava.types;

scijava-ops-image/src/main/java/org/scijava/ops/image/copy/Copiers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static <T> void copyRAI( //
8989
final RandomAccessibleInterval<T> copy //
9090
) {
9191
ensureEqualDimensions(input, copy);
92-
LoopBuilder.setImages(input, copy).forEachPixel(copier::compute);
92+
LoopBuilder.setImages(input, copy).multiThreaded().forEachPixel(copier::compute);
9393
}
9494

9595
/**

scijava-ops-image/src/main/java/org/scijava/ops/image/deconvolve/PadAndRichardsonLucy.java

Lines changed: 88 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.scijava.function.Inplaces;
5050
import org.scijava.ops.spi.Nullable;
5151
import org.scijava.ops.spi.OpDependency;
52+
import org.scijava.progress.Progress;
5253

5354
/**
5455
* Richardson Lucy function op that operates on (@link RandomAccessibleInterval)
@@ -104,6 +105,93 @@ public class PadAndRichardsonLucy<I extends RealType<I> & NativeType<I>, O exten
104105

105106
private Integer maxIterations;
106107

108+
/**
109+
* TODO
110+
*
111+
* @param input
112+
* @param kernel
113+
* @param outType
114+
* @param complexType
115+
* @param maxIterations max number of iterations
116+
* @param nonCirculant indicates whether to use non-circulant edge handling
117+
* @param accelerate indicates whether or not to use acceleration
118+
* @param borderSize
119+
* @param obfInput
120+
* @return the output
121+
*/
122+
@Override
123+
public RandomAccessibleInterval<O> apply(RandomAccessibleInterval<I> input,
124+
RandomAccessibleInterval<K> kernel, O outType, C complexType,
125+
Integer maxIterations, @Nullable Boolean nonCirculant,
126+
@Nullable Boolean accelerate, @Nullable long[] borderSize,
127+
@Nullable OutOfBoundsFactory<I, RandomAccessibleInterval<I>> obfInput)
128+
{
129+
// default to circulant
130+
if (nonCirculant == null) {
131+
nonCirculant = false;
132+
this.nonCirculant = nonCirculant;
133+
}
134+
else {
135+
this.nonCirculant = nonCirculant;
136+
}
137+
138+
// out of bounds factory will be different depending on if circulant or
139+
// non-circulant is used
140+
if (obfInput == null) {
141+
if (nonCirculant) {
142+
obfInput = new OutOfBoundsConstantValueFactory<>(Util
143+
.getTypeFromInterval(input).createVariable());
144+
}
145+
else {
146+
obfInput = new OutOfBoundsMirrorFactory<>(
147+
OutOfBoundsMirrorFactory.Boundary.SINGLE);
148+
}
149+
}
150+
151+
// default to no acceleration
152+
if (accelerate == null) accelerate = false;
153+
154+
this.maxIterations = maxIterations;
155+
156+
RandomAccessibleInterval<O> output = outputCreator.apply(input, outType);
157+
158+
final int numDimensions = input.numDimensions();
159+
160+
// 1. Calculate desired extended size of the image
161+
162+
final long[] paddedSize = new long[numDimensions];
163+
164+
if (borderSize == null) {
165+
// if no border size was passed in, then extend based on kernel size
166+
for (int d = 0; d < numDimensions; ++d) {
167+
paddedSize[d] = (int) input.dimension(d) + (int) kernel.dimension(d) -
168+
1;
169+
}
170+
171+
}
172+
else {
173+
// if borderSize was passed in
174+
for (int d = 0; d < numDimensions; ++d) {
175+
176+
paddedSize[d] = Math.max(kernel.dimension(d) + 2 * borderSize[d], input
177+
.dimension(d) + 2 * borderSize[d]);
178+
}
179+
}
180+
181+
Progress.defineTotalProgress(0, 3);
182+
RandomAccessibleInterval<I> paddedInput = padOp.apply(input,
183+
new FinalDimensions(paddedSize), true, obfInput);
184+
185+
RandomAccessibleInterval<K> paddedKernel = padKernelOp.apply(kernel,
186+
new FinalDimensions(paddedSize));
187+
188+
computeFilter(input, kernel, paddedInput, paddedKernel, output, paddedSize,
189+
complexType, accelerate);
190+
191+
return output;
192+
}
193+
194+
107195
/**
108196
* create a richardson lucy filter
109197
*/
@@ -193,89 +281,4 @@ private void computeFilter(final RandomAccessibleInterval<I> input,
193281
filter.compute(paddedInput, paddedKernel, output);
194282
}
195283

196-
/**
197-
* TODO
198-
*
199-
* @param input
200-
* @param kernel
201-
* @param outType
202-
* @param complexType
203-
* @param maxIterations max number of iterations
204-
* @param nonCirculant indicates whether to use non-circulant edge handling
205-
* @param accelerate indicates whether or not to use acceleration
206-
* @param borderSize
207-
* @param obfInput
208-
* @return the output
209-
*/
210-
@Override
211-
public RandomAccessibleInterval<O> apply(RandomAccessibleInterval<I> input,
212-
RandomAccessibleInterval<K> kernel, O outType, C complexType,
213-
Integer maxIterations, @Nullable Boolean nonCirculant,
214-
@Nullable Boolean accelerate, @Nullable long[] borderSize,
215-
@Nullable OutOfBoundsFactory<I, RandomAccessibleInterval<I>> obfInput)
216-
{
217-
// default to circulant
218-
if (nonCirculant == null) {
219-
nonCirculant = false;
220-
this.nonCirculant = nonCirculant;
221-
}
222-
else {
223-
this.nonCirculant = nonCirculant;
224-
}
225-
226-
// out of bounds factory will be different depending on if circulant or
227-
// non-circulant is used
228-
if (obfInput == null) {
229-
if (nonCirculant) {
230-
obfInput = new OutOfBoundsConstantValueFactory<>(Util
231-
.getTypeFromInterval(input).createVariable());
232-
}
233-
else {
234-
obfInput = new OutOfBoundsMirrorFactory<>(
235-
OutOfBoundsMirrorFactory.Boundary.SINGLE);
236-
}
237-
}
238-
239-
// default to no acceleration
240-
if (accelerate == null) accelerate = false;
241-
242-
this.maxIterations = maxIterations;
243-
244-
RandomAccessibleInterval<O> output = outputCreator.apply(input, outType);
245-
246-
final int numDimensions = input.numDimensions();
247-
248-
// 1. Calculate desired extended size of the image
249-
250-
final long[] paddedSize = new long[numDimensions];
251-
252-
if (borderSize == null) {
253-
// if no border size was passed in, then extend based on kernel size
254-
for (int d = 0; d < numDimensions; ++d) {
255-
paddedSize[d] = (int) input.dimension(d) + (int) kernel.dimension(d) -
256-
1;
257-
}
258-
259-
}
260-
else {
261-
// if borderSize was passed in
262-
for (int d = 0; d < numDimensions; ++d) {
263-
264-
paddedSize[d] = Math.max(kernel.dimension(d) + 2 * borderSize[d], input
265-
.dimension(d) + 2 * borderSize[d]);
266-
}
267-
}
268-
269-
RandomAccessibleInterval<I> paddedInput = padOp.apply(input,
270-
new FinalDimensions(paddedSize), true, obfInput);
271-
272-
RandomAccessibleInterval<K> paddedKernel = padKernelOp.apply(kernel,
273-
new FinalDimensions(paddedSize));
274-
275-
computeFilter(input, kernel, paddedInput, paddedKernel, output, paddedSize,
276-
complexType, accelerate);
277-
278-
return output;
279-
}
280-
281284
}

scijava-ops-image/src/main/java/org/scijava/ops/image/deconvolve/PadAndRichardsonLucyTV.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public class PadAndRichardsonLucyTV<I extends RealType<I> & NativeType<I>, O ext
9696
@OpDependency(name = "filter.createFFTOutput")
9797
private Functions.Arity3<Dimensions, C, Boolean, RandomAccessibleInterval<C>> createOp;
9898

99-
@OpDependency(name = "deconvolve.richardsonLucy")
99+
@OpDependency(name = "deconvolve.richardsonLucy", hints = {"progress.TRACK"})
100100
private Computers.Arity12<RandomAccessibleInterval<I>, RandomAccessibleInterval<K>, //
101101
RandomAccessibleInterval<C>, RandomAccessibleInterval<C>, Boolean, //
102102
Boolean, C, Integer, Boolean, //

scijava-ops-image/src/main/java/org/scijava/ops/image/deconvolve/RichardsonLucyC.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.scijava.function.Inplaces;
4646
import org.scijava.ops.spi.Nullable;
4747
import org.scijava.ops.spi.OpDependency;
48+
import org.scijava.progress.Progress;
4849

4950
/**
5051
* Richardson Lucy algorithm for (@link RandomAccessibleInterval) (Lucy, L. B.
@@ -165,9 +166,9 @@ public void compute(RandomAccessibleInterval<I> in, //
165166
AccelerationState<O> state = new AccelerationState<>(raiExtendedEstimate);
166167

167168
// -- perform iterations --
168-
169+
Progress.defineTotalProgress(1);
170+
Progress.setStageMax(maxIterations);
169171
for (int i = 0; i < maxIterations; i++) {
170-
171172
// create reblurred by convolving kernel with estimate
172173
// NOTE: the FFT of the PSF of the kernel has been passed in as a
173174
// parameter. when the op was set up, and computed above, so we can use
@@ -189,6 +190,8 @@ public void compute(RandomAccessibleInterval<I> in, //
189190

190191
// accelerate the algorithm by taking a larger step
191192
if (accelerate) accelerator.mutate(state);
193+
194+
Progress.update();
192195
}
193196

194197
// -- copy crop padded back to original size

0 commit comments

Comments
 (0)