/*
 * #%L
 * ImageJ software for multidimensional image processing and analysis.
 * %%
 * Copyright (C) 2014 - 2015 Board of Regents of the University of
 * Wisconsin-Madison, University of Konstanz and Brian Northan.
 * %%
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 * #L%
 */

package net.imagej.ops.filter.dog;

import net.imagej.ops.AbstractHybridOp;
import net.imagej.ops.Contingent;
import net.imagej.ops.HybridOp;
import net.imagej.ops.Ops;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.outofbounds.OutOfBoundsFactory;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.util.Util;

import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.thread.ThreadService;

/**
 * Difference of Gaussians (DoG) implementation where sigmas can vary by
 * dimension.
 * 
 * @author Christian Dietz (University of Konstanz)
 * @param <T>
 */
@Plugin(type = Ops.Filter.DoG.class, name = Ops.Filter.DoG.NAME)
public class DoGVaryingSigmas<T extends NumericType<T> & NativeType<T>>
	extends
	AbstractHybridOp<RandomAccessibleInterval<T>, RandomAccessibleInterval<T>>
	implements Ops.Filter.DoG, Contingent
{

	@Parameter
	private ThreadService ts;

	@Parameter
	private double[] sigmas1;

	@Parameter
	private double[] sigmas2;

	@Parameter(required = false)
	private OutOfBoundsFactory<T, RandomAccessibleInterval<T>> fac;

	private HybridOp<RandomAccessibleInterval<T>, RandomAccessibleInterval<T>> worker;

	@Override
	public RandomAccessibleInterval<T> createOutput(
		final RandomAccessibleInterval<T> input)
	{
		return worker.createOutput(input);
	}

	@Override
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void initialize(final RandomAccessibleInterval<T> t) {
		worker = (HybridOp) ops().hybrid(Ops.Filter.DoG.class, //
			RandomAccessibleInterval.class, t, //
			ops().computer(Ops.Filter.Gauss.class, RandomAccessibleInterval.class, t, sigmas1), //
			ops().computer(Ops.Filter.Gauss.class, RandomAccessibleInterval.class, t, sigmas2), //
			ops().function(Ops.Create.Img.class, RandomAccessibleInterval.class, t), //
			ops().function(Ops.Create.Img.class, RandomAccessibleInterval.class, t, Util.getTypeFromInterval(t)), //
			fac);
	}

	@Override
	public void compute(final RandomAccessibleInterval<T> input,
		final RandomAccessibleInterval<T> output)
	{
		worker.compute(input, output);
	}

	@Override
	public boolean conforms() {
		return sigmas1.length == sigmas2.length &&
			sigmas1.length == getInput().numDimensions();
	}
}

@@ -1592,32 +1592,26 @@
 gej.ops.
-AbstractHybridOp
+Contingent
 ;%0Aimport
@@ -1622,34 +1622,41 @@
 .imagej.ops.
-Contingent
+HighLevelHybridOp
 ;%0Aimport net
@@ -2341,16 +2341,17 @@
 ds%0A%09
-Abstract
+HighLevel
 Hybr
@@ -2676,111 +2676,86 @@
 ;%0A%0A%09
-private HybridOp%3CRandomAccessibleInterval%3CT%3E, RandomAccessibleInterval%3CT%3E%3E worker;%0A%0A%09@Override%0A%09public 
+@Override%0A%09@SuppressWarnings(%7B %22rawtypes%22, %22unchecked%22 %7D)%0A%09protected HybridOp%3C
 Rand
@@ -2781,30 +2781,9 @@
 l%3CT%3E
- createOutput(%0A%09%09final
+,
  Ran
@@ -2810,142 +2810,24 @@
 l%3CT%3E
- input)%0A%09%7B%0A%09%09return worker.createOutput(input);%0A%09%7D%0A%0A%09@Override%0A%09@SuppressWarnings(%7B %22rawtypes%22, %22unchecked%22 %7D)%0A%09public void initialize
+%3E%0A%09%09createWorker
 (fin
@@ -2863,21 +2863,20 @@
 %3E t)
- 
+%0A%09
 %7B%0A%09%09
-worker =
+return
  (Hy
@@ -3346,165 +3346,8 @@
 %09%7D%0A%0A
-%09@Override%0A%09public void compute(final RandomAccessibleInterval%3CT%3E input,%0A%09%09final RandomAccessibleInterval%3CT%3E output)%0A%09%7B%0A%09%09worker.compute(input, output);%0A%09%7D%0A%0A
 %09@Ov

use the high-level base layer