/*
 * #%L
 * ImageJ software for multidimensional image processing and analysis.
 * %%
 * Copyright (C) 2014 - 2017 ImageJ developers.
 * %%
 * 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.ifft;

import net.imagej.ops.Contingent;
import net.imagej.ops.Ops;
import net.imagej.ops.special.computer.AbstractUnaryComputerOp;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.algorithm.fft2.FFTMethods;
import net.imglib2.type.numeric.ComplexType;
import net.imglib2.type.numeric.RealType;

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

/**
 * Inverse FFT computer that operates on an RAI and wraps FFTMethods. The input
 * and output size must conform to supported FFT size. Use
 * {@link net.imagej.ops.filter.fftSize.ComputeFFTSize} to calculate the
 * supported FFT size.
 * 
 * @author Brian Northan
 * @param <C>
 * @param <T>
 */
@Plugin(type = Ops.Filter.IFFT.class)
public class IFFTMethodsOpC<C extends ComplexType<C>, T extends RealType<T>>
	extends
	AbstractUnaryComputerOp<RandomAccessibleInterval<C>, RandomAccessibleInterval<T>>
	implements Ops.Filter.IFFT, Contingent
{

	@Parameter
	ThreadService ts;

	/**
	 * Compute an ND inverse FFT
	 */
	@Override
	public void compute(final RandomAccessibleInterval<C> input,
		final RandomAccessibleInterval<T> output)
	{
		for (int d = input.numDimensions() - 1; d > 0; d--)
			FFTMethods.complexToComplex(input, d, false, true, ts
				.getExecutorService());

		FFTMethods.complexToReal(input, output, FFTMethods
			.unpaddingIntervalCentered(input, output), 0, true, ts
				.getExecutorService());
	}

	/**
	 * Make sure that the input size conforms to a supported FFT size.
	 */
	@Override
	public boolean conforms() {

		long[] paddedDimensions = new long[in().numDimensions()];
		long[] realDimensions = new long[in().numDimensions()];

		boolean fastSizeConforms = false;

		FFTMethods.dimensionsComplexToRealFast(in(), paddedDimensions,
			realDimensions);

		if (FFTMethods.dimensionsEqual(in(), paddedDimensions) == true) {
			fastSizeConforms = true;
		}

		boolean smallSizeConforms = false;

		FFTMethods.dimensionsComplexToRealSmall(in(), paddedDimensions,
			realDimensions);

		if ((FFTMethods.dimensionsEqual(in(), paddedDimensions) == true)) {
			smallSizeConforms = true;
		}

		return fastSizeConforms || smallSizeConforms;

	}

}

@@ -1584,37 +1584,135 @@
 al.c
-omputer.AbstractUnaryComputer
+hain.RAIs;%0Aimport net.imagej.ops.special.computer.AbstractUnaryComputerOp;%0Aimport net.imagej.ops.special.function.UnaryFunction
 Op;%0A
@@ -2585,16 +2585,232 @@
 ce ts;%0A%0A
+%09private UnaryFunctionOp%3CRandomAccessibleInterval%3CC%3E, RandomAccessibleInterval%3CC%3E%3E copyOp;%0A%0A%09@Override%0A%09public void initialize() %7B%0A%09%09super.initialize();%0A%09%09copyOp = RAIs.function(ops(), Ops.Copy.RAI.class, in());%0A%09%7D%0A%0A
 %09/**%0A%09 *
@@ -2961,16 +2961,85 @@
 put)%0A%09%7B%0A
+%09%09final RandomAccessibleInterval%3CC%3E temp = copyOp.calculate(input);%0A%0A
 %09%09for (i
@@ -3115,21 +3115,20 @@
 Complex(
-input
+temp
 , d, fal
@@ -3196,21 +3196,20 @@
 xToReal(
-input
+temp
 , output
@@ -3220,20 +3220,16 @@
 TMethods
-%0A%09%09%09
 .unpaddi
@@ -3247,21 +3247,24 @@
 entered(
-input
+%0A%09%09%09temp
 , output
@@ -3269,37 +3269,32 @@
 ut), 0, true, ts
-%0A%09%09%09%09
 .getExecutorServ

Make ifft computer really a computer