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

import net.imagej.ops.Ops;
import net.imagej.ops.special.computer.AbstractUnaryComputerOp;
import net.imagej.ops.special.computer.Computers;
import net.imagej.ops.special.computer.UnaryComputerOp;
import net.imglib2.type.logic.BitType;
import net.imglib2.type.numeric.RealType;

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

/**
 * Applies the given threshold value to every element along the given
 * {@link Iterable} input.
 *
 * @author Martin Horn (University of Konstanz)
 * @author Christian Dietz (University of Konstanz)
 */
@Plugin(type = Ops.Threshold.Apply.class, priority = Priority.HIGH_PRIORITY)
public class ApplyConstantThreshold<T extends RealType<T>> extends
	AbstractUnaryComputerOp<Iterable<T>, Iterable<BitType>> implements
	Ops.Threshold.Apply
{

	@Parameter
	private T threshold;
	private UnaryComputerOp<T, BitType> applyThreshold;
	private UnaryComputerOp<Iterable<T>, Iterable<BitType>> mapper;

	@SuppressWarnings("unchecked")
	@Override
	public void initialize() {
		applyThreshold = (UnaryComputerOp<T, BitType>) Computers.unary(ops(),
			ApplyThresholdComparable.class, BitType.class, threshold.getClass(),
			threshold);
		mapper = Computers.unary(ops(), Ops.Map.class, out(), in(), applyThreshold);
	}

	@Override
	public void compute1(final Iterable<T> input, final Iterable<BitType> output) {
		mapper.compute1(input, output);
	}

}

@@ -1641,33 +1641,91 @@
 omputer.Abstract
-U
+BinaryComputerOp;%0Aimport net.imagej.ops.special.computer.Bi
 naryComputerOp;%0A
@@ -1945,45 +1945,8 @@
 ty;%0A
-import org.scijava.plugin.Parameter;%0A
 impo
@@ -2337,17 +2337,18 @@
 Abstract
-U
+Bi
 naryComp
@@ -2358,32 +2358,35 @@
 rOp%3CIterable%3CT%3E,
+ T,
  Iterable%3CBitTyp
@@ -2429,51 +2429,18 @@
 %7B%0A%0A%09
-@Parameter%0A%09private T threshold;%0A%09private U
+private Bi
 nary
@@ -2444,32 +2444,35 @@
 aryComputerOp%3CT,
+ T,
  BitType%3E applyT
@@ -2551,40 +2551,8 @@
 r;%0A%0A
-%09@SuppressWarnings(%22unchecked%22)%0A
 %09@Ov
@@ -2608,38 +2608,8 @@
 ld =
- (UnaryComputerOp%3CT, BitType%3E)
  Com
@@ -2607,33 +2607,34 @@
 old = Computers.
-u
+bi
 nary(ops(),%0A%09%09%09A
@@ -2628,20 +2628,17 @@
 y(ops(),
-%0A%09%09%09
+ 
 ApplyThr
@@ -2660,17 +2660,20 @@
 e.class,
- 
+%0A%09%09%09
 BitType.
@@ -2683,42 +2683,20 @@
 ss, 
-threshold.getClass(),%0A%09%09%09threshold
+in2(), in2()
 );%0A%09
@@ -2808,17 +2808,17 @@
  compute
-1
+2
 (final I
@@ -2837,16 +2837,17 @@
 nput
+1
 , final 
 Iter
@@ -2838,24 +2838,42 @@
 put1, final 
+T input2,%0A%09%09final 
 Iterable%3CBit
@@ -2885,19 +2885,56 @@
  output)
- 
+%0A%09
 %7B%0A
+%09%09applyThreshold.setInput2(input2);%0A
 %09%09mapper
@@ -2948,16 +2948,17 @@
 e1(input
+1
 , output

Make ApplyConstantThreshold binary