/*
 * #%L
 * ImageJ OPS: a framework for reusable algorithms.
 * %%
 * Copyright (C) 2014 Board of Regents of the University of
 * Wisconsin-Madison and University of Konstanz.
 * %%
 * 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 imagej.ops.convolve;

import imagej.ops.Op;

import java.util.Arrays;

import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.algorithm.gauss3.Gauss3;
import net.imglib2.algorithm.gauss3.SeparableSymmetricConvolution;
import net.imglib2.exception.IncompatibleTypeException;
import net.imglib2.outofbounds.OutOfBoundsFactory;
import net.imglib2.outofbounds.OutOfBoundsMirrorFactory;
import net.imglib2.outofbounds.OutOfBoundsMirrorFactory.Boundary;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.view.Views;

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

@SuppressWarnings({ "unchecked", "rawtypes" })
@Plugin(type = Op.class, name = "gauss")
public class Gauss<T extends RealType<T>> implements Op {

	@Parameter
	private RandomAccessibleInterval<T> in;

	@Parameter
	private RandomAccessibleInterval<T> out;

	@Parameter
	private double sigma;

	// TODO: make that selectable by the user/programmer
	private final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBounds =
		new OutOfBoundsMirrorFactory(Boundary.SINGLE);

	@Override
	public void run() {
		final RandomAccessible<FloatType> eIn =
			(RandomAccessible) Views.extend(in, outOfBounds);

		final double[] sigmas = new double[in.numDimensions()];
		Arrays.fill(sigmas, sigma);

		try {
			SeparableSymmetricConvolution.convolve(Gauss3.halfkernels(sigmas), eIn,
				out, Runtime.getRuntime().availableProcessors());

		}
		catch (final IncompatibleTypeException e) {
			// TODO: better error handling
			throw new RuntimeException(e);
		}

	}
}

@@ -1523,16 +1523,44 @@
 volve;%0A%0A
+import imagej.ops.Function;%0A
 import i
@@ -2351,46 +2351,26 @@
 T%3E%3E 
-implements Op %7B%0A%0A%09@Parameter%0A%09private 
+extends%0A%09Function%3C
 Rand
@@ -2396,34 +2396,9 @@
 l%3CT%3E
- in;%0A%0A%09@Parameter%0A%09private
+,
  Ran
@@ -2425,13 +2425,11 @@
 l%3CT%3E
- out;
+%3E%0A%7B
 %0A%0A%09@
@@ -2669,19 +2669,133 @@
 lic 
-void run() 
+RandomAccessibleInterval%3CT%3E compute(%0A%09%09final RandomAccessibleInterval%3CT%3E input,%0A%09%09final RandomAccessibleInterval%3CT%3E output)%0A%09
 %7B%0A%09%09
@@ -2871,16 +2871,19 @@
 xtend(in
+put
 , outOfB
@@ -2930,16 +2930,19 @@
 ouble%5Bin
+put
 .numDime
@@ -3073,16 +3073,19 @@
 %0A%09%09%09%09out
+put
 , Runtim
@@ -3248,12 +3248,30 @@
 ;%0A%09%09%7D%0A%0A%09
-%7D
+%09return output;%0A%09%7D%0A
 %0A%7D%0A

Make it a function