/*
 * #%L
 * ImageJ software for multidimensional image processing and analysis.
 * %%
 * Copyright (C) 2009 - 2014 Board of Regents of the University of
 * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
 * Institute of Molecular Cell Biology and Genetics.
 * %%
 * 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.plugins.commands.assign;

import imagej.command.Command;
import imagej.command.ContextCommand;
import imagej.data.ChannelCollection;
import imagej.data.Dataset;
import imagej.data.Position;
import imagej.data.display.OverlayService;
import imagej.data.overlay.Overlay;
import imagej.menu.MenuConstants;
import net.imglib2.type.numeric.RealType;

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

/**
 * Fills the selected region of an input Dataset with the foreground values.
 * 
 * @author Barry DeZonia
 */
@Plugin(type = Command.class, menu = {
	@Menu(label = MenuConstants.EDIT_LABEL, weight = MenuConstants.EDIT_WEIGHT,
		mnemonic = MenuConstants.EDIT_MNEMONIC),
	@Menu(label = "Fill", weight = 28, accelerator = "^F") }, headless = true)
public class FillDataValues<T extends RealType<T>> extends ContextCommand {

	// -- Parameters --

	@Parameter
	private OverlayService overlayService;

	@Parameter(type = ItemIO.BOTH)
	private Dataset dataset;

	@Parameter
	private Position position;

	// TODO Investigate bug if persist = true
	@Parameter(persist = false)
	private Overlay overlay;

	@Parameter
	private ChannelCollection color;

	// -- public interface --

	@Override
	public void run() {
		if (overlay == null) {
			cancel("This command requires a selection");
			return;
		}
		if (color == null) {
			cancel("This command requires a color to fill with");
			return;
		}
		overlayService.fillOverlay(overlay, dataset, position, color);
	}

	public Dataset getDataset() {
		return dataset;
	}

	public void setDataset(final Dataset dataset) {
		this.dataset = dataset;
	}

	public Position getPosition() {
		return position;
	}

	public void setPosition(final Position position) {
		this.position = position;
	}

	public Overlay getOverlay() {
		return overlay;
	}

	public void setOverlay(final Overlay overlay) {
		this.overlay = overlay;
	}

	public ChannelCollection getColor() {
		return color;
	}

	public void setColor(final ChannelCollection color) {
		this.color = color;
	}

	// -- private helpers --

	// TODO - make this part of Dataset API maybe. or somewhere else.
	/*
	private void fillSelectedRegion(final Dataset dataset,
		final ChannelCollection channels)
	{
		final RealRect bounds = overlayService.getSelectionBounds(display);
		final long minX = (long) bounds.x;
		final long minY = (long) bounds.y;
		final long maxX = (long) (bounds.x + bounds.width - 1);
		final long maxY = (long) (bounds.y + bounds.height - 1);
		final long[] pos = new long[dataset.numDimensions()];
		final int xIndex = dataset.dimensionIndex(Axes.X);
		final int yIndex = dataset.dimensionIndex(Axes.Y);
		final int chIndex = dataset.dimensionIndex(Axes.CHANNEL);
		final ImgPlus<? extends RealType<?>> imgPlus = dataset.getImgPlus();
		final Cursor<? extends RealType<?>> cursor = imgPlus.localizingCursor();
		while (cursor.hasNext()) {
			final RealType<?> pixRef = cursor.next();
			cursor.localize(pos);
			if ((pos[xIndex] < minX) || (pos[xIndex] > maxX)) continue;
			if ((pos[yIndex] < minY) || (pos[yIndex] > maxY)) continue;
			long position = 0;
			if (chIndex >= 0) position = pos[chIndex];
			double value = channels.getChannelValue(position);
			pixRef.setReal(value);
		}
		dataset.update();
	}
	*/
}

@@ -3695,1232 +3695,6 @@
 %09%7D%0A%0A
-%09// -- private helpers --%0A%0A%09// TODO - make this part of Dataset API maybe. or somewhere else.%0A%09/*%0A%09private void fillSelectedRegion(final Dataset dataset,%0A%09%09final ChannelCollection channels)%0A%09%7B%0A%09%09final RealRect bounds = overlayService.getSelectionBounds(display);%0A%09%09final long minX = (long) bounds.x;%0A%09%09final long minY = (long) bounds.y;%0A%09%09final long maxX = (long) (bounds.x + bounds.width - 1);%0A%09%09final long maxY = (long) (bounds.y + bounds.height - 1);%0A%09%09final long%5B%5D pos = new long%5Bdataset.numDimensions()%5D;%0A%09%09final int xIndex = dataset.dimensionIndex(Axes.X);%0A%09%09final int yIndex = dataset.dimensionIndex(Axes.Y);%0A%09%09final int chIndex = dataset.dimensionIndex(Axes.CHANNEL);%0A%09%09final ImgPlus%3C? extends RealType%3C?%3E%3E imgPlus = dataset.getImgPlus();%0A%09%09final Cursor%3C? extends RealType%3C?%3E%3E cursor = imgPlus.localizingCursor();%0A%09%09while (cursor.hasNext()) %7B%0A%09%09%09final RealType%3C?%3E pixRef = cursor.next();%0A%09%09%09cursor.localize(pos);%0A%09%09%09if ((pos%5BxIndex%5D %3C minX) %7C%7C (pos%5BxIndex%5D %3E maxX)) continue;%0A%09%09%09if ((pos%5ByIndex%5D %3C minY) %7C%7C (pos%5ByIndex%5D %3E maxY)) continue;%0A%09%09%09long position = 0;%0A%09%09%09if (chIndex %3E= 0) position = pos%5BchIndex%5D;%0A%09%09%09double value = channels.getChannelValue(position);%0A%09%09%09pixRef.setReal(value);%0A%09%09%7D%0A%09%09dataset.update();%0A%09%7D%0A%09*/%0A
 %7D%0A

remove obsolete code