From 8aa1488e09dafcbdfca903fd9ed4ed67d24e5efd Mon Sep 17 00:00:00 2001 From: dietzc Date: Fri, 26 Aug 2016 15:02:29 +0200 Subject: [PATCH] refactor FeatureCalculator according to refactoring of OpRef in imagej-ops --- .../sets/AbstractOpRefFeatureSet.java | 20 +++---- .../knip/features/sets/NamedFeature.java | 10 ++-- .../KNIPCachedOpEnvironment.java | 53 +++++++++++-------- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/org.knime.knip.features/src/org/knime/knip/features/sets/AbstractOpRefFeatureSet.java b/org.knime.knip.features/src/org/knime/knip/features/sets/AbstractOpRefFeatureSet.java index 4fac6064..5788a3e2 100644 --- a/org.knime.knip.features/src/org/knime/knip/features/sets/AbstractOpRefFeatureSet.java +++ b/org.knime.knip.features/src/org/knime/knip/features/sets/AbstractOpRefFeatureSet.java @@ -49,22 +49,24 @@ package org.knime.knip.features.sets; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import net.imagej.ops.OpRef; -import net.imagej.ops.special.function.Functions; -import net.imagej.ops.special.function.UnaryFunctionOp; -import net.imglib2.type.numeric.RealType; - import org.scijava.command.CommandService; import org.scijava.module.Module; import org.scijava.module.ModuleItem; import org.scijava.plugin.Parameter; +import net.imagej.ops.Op; +import net.imagej.ops.OpRef; +import net.imagej.ops.special.function.Functions; +import net.imagej.ops.special.function.UnaryFunctionOp; +import net.imglib2.type.numeric.RealType; + /** * {@link OpRef} based {@link AbstractCachedFeatureSet}. * @@ -137,12 +139,12 @@ public void initialize() { args[i++] = self.getInput(param); } - @SuppressWarnings("rawtypes") - final OpRef ref = new OpRef(null, Class.forName((String) item.get(ATTR_TYPE)), null, null, args); + Class type = (Class) Class.forName((String) item.get(ATTR_TYPE)); + final OpRef ref = new OpRef(null, Arrays.asList(type), null, null, args); namedFeatureMap.put(new NamedFeature(ref, item.getLabel()), - (UnaryFunctionOp) Functions.unary(ops(), ref.getType(), RealType.class, - in(), ref.getArgs())); + (UnaryFunctionOp) Functions.unary(ops(), type, RealType.class, in(), + ref.getArgs())); } } } catch (final ClassNotFoundException e) { diff --git a/org.knime.knip.features/src/org/knime/knip/features/sets/NamedFeature.java b/org.knime.knip.features/src/org/knime/knip/features/sets/NamedFeature.java index fba00f8f..3314f16a 100644 --- a/org.knime.knip.features/src/org/knime/knip/features/sets/NamedFeature.java +++ b/org.knime.knip.features/src/org/knime/knip/features/sets/NamedFeature.java @@ -48,10 +48,10 @@ package org.knime.knip.features.sets; -import net.imagej.ops.OpRef; - import org.scijava.Named; +import net.imagej.ops.OpRef; + /** * Simple semantic description of an arbitrary feature * @@ -60,13 +60,13 @@ public class NamedFeature implements Named { private final String name; - private OpRef ref; + private OpRef ref; public NamedFeature(final String name) { this.name = name; } - public NamedFeature(final OpRef ref, final String name) { + public NamedFeature(final OpRef ref, final String name) { this(name); this.ref = ref; } @@ -107,7 +107,7 @@ public boolean equals(Object obj) { return true; } - public OpRef getOp() { + public OpRef getOp() { return ref; } diff --git a/org.knime.knip.features/src/org/knime/knip/features/sets/optimizedfeatures/KNIPCachedOpEnvironment.java b/org.knime.knip.features/src/org/knime/knip/features/sets/optimizedfeatures/KNIPCachedOpEnvironment.java index 781fc8d1..a3f775bd 100644 --- a/org.knime.knip.features/src/org/knime/knip/features/sets/optimizedfeatures/KNIPCachedOpEnvironment.java +++ b/org.knime.knip.features/src/org/knime/knip/features/sets/optimizedfeatures/KNIPCachedOpEnvironment.java @@ -30,9 +30,17 @@ package org.knime.knip.features.sets.optimizedfeatures; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; +import org.scijava.Priority; +import org.scijava.cache.CacheService; +import org.scijava.command.CommandInfo; +import org.scijava.module.Module; +import org.scijava.module.ModuleItem; +import org.scijava.plugin.Parameter; + import net.imagej.ops.AbstractOp; import net.imagej.ops.CustomOpEnvironment; import net.imagej.ops.Op; @@ -42,13 +50,6 @@ import net.imagej.ops.special.function.UnaryFunctionOp; import net.imagej.ops.special.hybrid.UnaryHybridCF; -import org.scijava.Priority; -import org.scijava.cache.CacheService; -import org.scijava.command.CommandInfo; -import org.scijava.module.Module; -import org.scijava.module.ModuleItem; -import org.scijava.plugin.Parameter; - /** * Creates {@link CachedFunctionOp}s which know how to cache their outputs. * @@ -75,25 +76,31 @@ public KNIPCachedOpEnvironment(final OpEnvironment parent, final Collection ref) { - final Op op = super.op(ref); - - for (final Class ignored : ignored) { - if (ignored.isAssignableFrom(ref.getType())) { - return op; + public Op op(final OpRef ref) { + try { + final Op op = super.op(ref); + + for (final Class ignored : ignored) { + for (final Type t : ref.getTypes()) { + if (ignored.isAssignableFrom(Class.forName(t.getTypeName()))) { + return op; + } + } } - } - final Op cachedOp; - if (op instanceof UnaryHybridCF) { - cachedOp = wrapUnaryHybrid((UnaryHybridCF) op); - } else if (op instanceof UnaryFunctionOp) { - cachedOp = wrapUnaryFunction((UnaryFunctionOp) op); - } else - return op; + final Op cachedOp; + if (op instanceof UnaryHybridCF) { + cachedOp = wrapUnaryHybrid((UnaryHybridCF) op); + } else if (op instanceof UnaryFunctionOp) { + cachedOp = wrapUnaryFunction((UnaryFunctionOp) op); + } else + return op; - getContext().inject(cachedOp); - return cachedOp; + getContext().inject(cachedOp); + return cachedOp; + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } } // -- Helper methods --