/*
 * #%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.math.add;

import net.imagej.ops.AbstractHybridOp;
import net.imagej.ops.Contingent;
import net.imagej.ops.Ops;
import net.imglib2.Cursor;
import net.imglib2.IterableInterval;
import net.imglib2.RandomAccess;
import net.imglib2.img.Img;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.util.Intervals;

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

@Plugin(type = Ops.Math.Add.class, name = Ops.Math.Add.NAME)
public class AddIterableIntervalToImg<T extends NumericType<T>> extends
	AbstractHybridOp<Img<T>, Img<T>> implements Ops.Math.Add, Contingent
{

	// TODO: extend common abstract base class which implements Contingent
	// for dimensionality checking.
	// TODO: code generate this and all add ops to generalize them to other
	// operators.

	@Parameter
	private IterableInterval<T> ii;

	@Override
	public boolean conforms() {
		if (!Intervals.equalDimensions(getInput(), ii)) return false;
		if (getOutput() == null) return true;
		return Intervals.equalDimensions(ii, getOutput());
	}

	@Override
	public Img<T> createOutput(final Img<T> input) {
		return input.factory().create(input, input.firstElement());
	}

	@Override
	public void compute(final Img<T> input, final Img<T> output) {
		final Cursor<T> cursor = ii.localizingCursor();
		final RandomAccess<T> iRA = input.randomAccess();
		final RandomAccess<T> oRA = output.randomAccess();
		final T tmp = output.firstElement().copy();
		while (cursor.hasNext()) {
			cursor.fwd();
			iRA.setPosition(cursor);
			oRA.setPosition(cursor);
			tmp.set(iRA.get());
			tmp.add(cursor.get());
			oRA.get().set(tmp);
		}
	}

}

@@ -1875,16 +1875,45 @@
 rvals;%0A%0A
+import org.scijava.Priority;%0A
 import o
@@ -2035,16 +2035,52 @@
 Add.NAME
+,%0A%09priority = Priority.HIGH_PRIORITY
 )%0Apublic

Fix clash of two math.add ops with same priority