Skip to content

Commit

Permalink
refactor FeatureCalculator according to refactoring of OpRef in image…
Browse files Browse the repository at this point in the history
…j-ops
  • Loading branch information
dietzc committed Aug 26, 2016
1 parent f4ebbe5 commit 8aa1488
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand Down Expand Up @@ -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<? extends Op> type = (Class<? extends Op>) 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<Object, ? extends O>) Functions.unary(ops(), ref.getType(), RealType.class,
in(), ref.getArgs()));
(UnaryFunctionOp<Object, ? extends O>) Functions.unary(ops(), type, RealType.class, in(),
ref.getArgs()));
}
}
} catch (final ClassNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public boolean equals(Object obj) {
return true;
}

public OpRef<?> getOp() {
public OpRef getOp() {
return ref;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand All @@ -75,25 +76,31 @@ public KNIPCachedOpEnvironment(final OpEnvironment parent, final Collection<? ex
}

@Override
public Op op(final OpRef<?> 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 --
Expand Down

0 comments on commit 8aa1488

Please sign in to comment.