Projects >> imagej >>0ebce4f366e48db978018df6e4632422ff1532a4

Chunk
Conflicting content
package imagej.core.commands.display;

<<<<<<< HEAD:core/commands/display/src/main/java/imagej/core/commands/display/ShowLUT.java
import imagej.command.ContextCommand;
=======
import java.util.List;

>>>>>>> 4669b3785cc2b24740d9cd9172e1a24ae6a6a6e1:core/plugins/display/src/main/java/imagej/core/plugins/display/ShowLUT.java
import imagej.data.ChannelCollection;
import imagej.data.Dataset;
import imagej.data.DatasetService;
Solution content
package imagej.core.commands.display;

import imagej.command.ContextCommand;
import imagej.data.ChannelCollection;
import imagej.data.Dataset;
import imagej.data.DatasetService;
File
ShowLUT.java
Developer's decision
Version 1
Kind of conflict
Import
Chunk
Conflicting content
import imagej.data.display.DatasetView;
import imagej.data.display.ImageDisplay;
import imagej.data.display.ImageDisplayService;
<<<<<<< HEAD:core/commands/display/src/main/java/imagej/core/commands/display/ShowLUT.java
import imagej.menu.MenuConstants;
import imagej.module.ItemIO;
import imagej.plugin.Menu;
import imagej.plugin.Parameter;
import imagej.plugin.Plugin;
import imagej.render.RenderingService;
import imagej.render.TextRenderer.TextJustification;
=======
import imagej.ext.menu.MenuConstants;
import imagej.ext.module.ItemIO;
import imagej.ext.plugin.Menu;
import imagej.ext.plugin.Parameter;
import imagej.ext.plugin.Plugin;
import imagej.ext.plugin.RunnablePlugin;
>>>>>>> 4669b3785cc2b24740d9cd9172e1a24ae6a6a6e1:core/plugins/display/src/main/java/imagej/core/plugins/display/ShowLUT.java
import imagej.util.ColorRGB;
import imagej.util.Colors;
Solution content
import imagej.data.display.DatasetView;
import imagej.data.display.ImageDisplay;
import imagej.data.display.ImageDisplayService;
import imagej.menu.MenuConstants;
import imagej.module.ItemIO;
import imagej.plugin.Menu;
import imagej.plugin.Parameter;
import imagej.plugin.Plugin;
import imagej.render.RenderingService;
import imagej.render.TextRenderer.TextJustification;
import imagej.util.ColorRGB;
import imagej.util.Colors;
File
ShowLUT.java
Developer's decision
Version 1
Kind of conflict
Import
Chunk
Conflicting content
		return ds;
	}
	
<<<<<<< HEAD:core/commands/display/src/main/java/imagej/core/commands/display/ShowLUT.java
	private void drawLutInfo(Dataset ds, ColorTable8 lut) {
		DrawingTool tool = new DrawingTool(ds, renderingService);
=======
	private void drawLutInfo(Dataset ds, ColorTable ct) {
		DrawingTool tool = new DrawingTool(ds);
>>>>>>> 4669b3785cc2b24740d9cd9172e1a24ae6a6a6e1:core/plugins/display/src/main/java/imagej/core/plugins/display/ShowLUT.java
		int xMargin = 35;
		int yMargin = 20;
		int width = 256;
Solution content
		return ds;
	}
	
	private void drawLutInfo(Dataset ds, ColorTable ct) {
		DrawingTool tool = new DrawingTool(ds, renderingService);
		int xMargin = 35;
		int yMargin = 20;
		int width = 256;
File
ShowLUT.java
Developer's decision
Combination
Kind of conflict
Method invocation
Method signature
Variable
Chunk
Conflicting content
package imagej.data.display;

<<<<<<< HEAD
import imagej.util.ColorRGB;
=======
import java.awt.Color;

import net.imglib2.display.AbstractColorTable;
>>>>>>> 4669b3785cc2b24740d9cd9172e1a24ae6a6a6e1
import net.imglib2.display.ColorTable;
import net.imglib2.display.ColorTable8;
Solution content
package imagej.data.display;

import imagej.util.ColorRGB;
import net.imglib2.display.ColorTable;
import net.imglib2.display.ColorTable8;
File
ColorTables.java
Developer's decision
Version 1
Kind of conflict
Import
Chunk
Conflicting content
			}
		if (mode == ColorMode.COMPOSITE) {
			double rSum = 0, gSum = 0, bSum = 0;
			for (int c = 0; c < channelCount; c++) {
<<<<<<< HEAD
				final double value = channels.getChannelValue(c);
				final RealLUTConverter> converter =
					converters.get(c);
				final double min = converter.getMin();
				final double max = converter.getMax();
				double relativeValue = (value - min) / (max - min);
				if (relativeValue < 0) relativeValue = 0;
				if (relativeValue > 1) relativeValue = 1;
				final int grayValue = (int) (relativeValue * 255);
				final ColorTable8 colorTable = converter.getLUT();
				rSum += colorTable.get(0, grayValue);
				gSum += colorTable.get(1, grayValue);
				bSum += colorTable.get(2, grayValue);
=======
				double value = channels.getChannelValue(c);
				RealLUTConverter> converter = converters.get(c);
				double min = converter.getMin();
				double max = converter.getMax();
				int grayValue = Binning.valueToBin(256, min, max, value);
				ColorTable colorTable = converter.getLUT();
				rSum += colorTable.getResampled(ColorTable.RED, 256, grayValue);
				gSum += colorTable.getResampled(ColorTable.GREEN, 256, grayValue);
				bSum += colorTable.getResampled(ColorTable.BLUE, 256, grayValue);
>>>>>>> 4669b3785cc2b24740d9cd9172e1a24ae6a6a6e1
			r = (rSum > 255) ? 255 : (int) Math.round(rSum);
			g = (gSum > 255) ? 255 : (int) Math.round(gSum);
Solution content
		if (mode == ColorMode.COMPOSITE) {
			double rSum = 0, gSum = 0, bSum = 0;
			for (int c = 0; c < channelCount; c++) {
				final double value = channels.getChannelValue(c);
				final RealLUTConverter> converter =
						converters.get(c);
				final double min = converter.getMin();
				final double max = converter.getMax();
				final int grayValue = Binning.valueToBin(256, min, max, value);
				final ColorTable colorTable = converter.getLUT();
				rSum += colorTable.getResampled(ColorTable.RED, 256, grayValue);
				gSum += colorTable.getResampled(ColorTable.GREEN, 256, grayValue);
				bSum += colorTable.getResampled(ColorTable.BLUE, 256, grayValue);
			}
			r = (rSum > 255) ? 255 : (int) Math.round(rSum);
			g = (gSum > 255) ? 255 : (int) Math.round(gSum);
File
DefaultDatasetView.java
Developer's decision
Manual
Kind of conflict
Cast expression
If statement
Method invocation
Variable
Chunk
Conflicting content
			b = (bSum > 255) ? 255 : (int) Math.round(bSum);
		}
		else { // grayscale or color
<<<<<<< HEAD
			final long currChannel = getLongPosition(Axes.CHANNEL);
			final double value = channels.getChannelValue(currChannel);
			final RealLUTConverter> converter =
				converters.get((int) currChannel);
			final double min = converter.getMin();
			final double max = converter.getMax();
			double relativeValue = (value - min) / (max - min);
			if (relativeValue < 0) relativeValue = 0;
			if (relativeValue > 1) relativeValue = 1;
			final int grayValue = (int) Math.round(relativeValue * 255);
			if (mode == ColorMode.COLOR) {
				final ColorTable8 colorTable = converter.getLUT();
				r = colorTable.get(0, grayValue);
				g = colorTable.get(1, grayValue);
				b = colorTable.get(2, grayValue);
=======
			long currChannel = getLongPosition(Axes.CHANNEL);
			double value = channels.getChannelValue(currChannel);
			RealLUTConverter> converter =
					converters.get((int) currChannel);
			double min = converter.getMin();
			double max = converter.getMax();
            int grayValue = Binning.valueToBin(256, min, max, value);
			if (mode == ColorMode.COLOR) {
				ColorTable colorTable = converter.getLUT();
				r = colorTable.getResampled(ColorTable.RED, 256, grayValue);
				g = colorTable.getResampled(ColorTable.GREEN, 256, grayValue);
				b = colorTable.getResampled(ColorTable.BLUE, 256, grayValue);
>>>>>>> 4669b3785cc2b24740d9cd9172e1a24ae6a6a6e1
			}
			else { // mode == grayscale
				r = grayValue;
Solution content
			b = (bSum > 255) ? 255 : (int) Math.round(bSum);
		}
		else { // grayscale or color
			final long currChannel = getLongPosition(Axes.CHANNEL);
			final double value = channels.getChannelValue(currChannel);
			final RealLUTConverter> converter =
					converters.get((int) currChannel);
			final double min = converter.getMin();
			final double max = converter.getMax();
			final int grayValue = Binning.valueToBin(256, min, max, value);
			if (mode == ColorMode.COLOR) {
				final ColorTable colorTable = converter.getLUT();
				r = colorTable.getResampled(ColorTable.RED, 256, grayValue);
				g = colorTable.getResampled(ColorTable.GREEN, 256, grayValue);
				b = colorTable.getResampled(ColorTable.BLUE, 256, grayValue);
			}
			else { // mode == grayscale
				r = grayValue;
File
DefaultDatasetView.java
Developer's decision
Manual
Kind of conflict
Cast expression
If statement
Method invocation
Variable
Chunk
Conflicting content
import imagej.data.display.ImageDisplay;
import imagej.service.Service;
<<<<<<< HEAD
=======
import imagej.util.RealRect;

import java.util.ArrayList;
import java.util.List;

import net.imglib2.RandomAccess;
import net.imglib2.display.ColorTable;
import net.imglib2.display.ColorTable16;
import net.imglib2.display.ColorTable8;
import net.imglib2.display.RealLUTConverter;
import net.imglib2.meta.Axes;
import net.imglib2.meta.AxisType;
import net.imglib2.type.numeric.RealType;

//TODO
//1) Maintain metadata
//2) maintain overlays: does an overlay in Z == 7 show up on correct slice
// in output data?
//3) report parse error string somehow
//5) test the contains(num) code works
//TODO - multiple places I'm relying on a Display's axes rather than a
//Dataset's axes. See if there are problems with this
//TODO - the iterators work with Lists which can only hold 2 gig or fewer
//elements. Thus data cannot be copied > 2 gig per dimension.
//TODO:
//-- for speed eliminate reliance on Longs. Make primitive arrays.
//-- make a EnormousList that can store more than 2 gig of longs
//In other plugins replace RestructureUtils calls with methods from here
//Note when user specifies 1-1000 I am storing them all consecutively (i.e.
// 1,2,3,4,5...1000. For small amounts this is fine but might want something
// more sophisticated for large dimensional ranges.
>>>>>>> 4669b3785cc2b24740d9cd9172e1a24ae6a6a6e1

/**
 * Interface for sampler operations which manipulate {@link ImageDisplay} data.
Solution content
import imagej.data.display.ImageDisplay;
import imagej.service.Service;

/**
 * Interface for sampler operations which manipulate {@link ImageDisplay} data.
File
SamplerService.java
Developer's decision
Version 1
Kind of conflict
Comment
Import
Chunk
Conflicting content
		*/

	 * Creates a copy of all the planes bounded by the currently selected 2d
	 * region of an ImageDisplay.
	 */
<<<<<<< HEAD
	ImageDisplay duplicateSelectedPlanes(ImageDisplay display);
=======
	public ImageDisplay duplicateSelectedPlanes(final ImageDisplay display) {
		final SamplingDefinition copyDef =
			SamplingDefinition.sampleAllPlanes(display);
		final RealRect selection = overlayService.getSelectionBounds(display);
		final long minX = (long) selection.x;
		final long minY = (long) selection.y;
		final long maxX = (long) (selection.x + selection.width);
		final long maxY = (long) (selection.y + selection.height);
		final AxisSubrange xSubrange = new AxisSubrange(minX, maxX);
		final AxisSubrange ySubrange = new AxisSubrange(minY, maxY);
		copyDef.constrain(Axes.X, xSubrange);
		copyDef.constrain(Axes.Y, ySubrange);
		return createSampledImage(copyDef);
	}

	// -- private helpers --

	/**
	 * Creates an output image from a sampling definition. All data initialized to
	 * zero.
	 */
	private ImageDisplay createOutputImage(final SamplingDefinition def) {
		final ImageDisplay origDisp = def.getDisplay();
		// TODO - remove evil cast
		final Dataset origDs = (Dataset) origDisp.getActiveView().getData();
		final long[] dims = def.getOutputDims();
		final String name = origDisp.getName();
		final AxisType[] axes = def.getOutputAxes();
		final double[] cal = def.getOutputCalibration(axes);
		final int bitsPerPixel = origDs.getType().getBitsPerPixel();
		final boolean signed = origDs.isSigned();
		final boolean floating = !origDs.isInteger();
		final Dataset output =
			datasetService.create(dims, name, axes, bitsPerPixel, signed, floating);
		output.setCalibration(cal);
		long numPlanes = calcNumPlanes(dims, axes);
		if (numPlanes > Integer.MAX_VALUE) {
			throw new IllegalArgumentException(
				"output image has more planes than "+Integer.MAX_VALUE);
		}
		output.getImgPlus().initializeColorTables((int)numPlanes);
		if (origDs.isRGBMerged()) {
			final int chanAxis = output.getAxisIndex(Axes.CHANNEL);
			if (chanAxis >= 0) {
				if (output.dimension(chanAxis) == 3) {
					output.setRGBMerged(true);
				}
			}
		}
		// TODO - remove evil cast
		return (ImageDisplay) displayService.createDisplay(name, output);
	}

	/** Copies all associated data from a SamplingDefinition to an output image. */
	private void copyData(final SamplingDefinition def,
		final ImageDisplay outputImage)
	{
		final PositionIterator iter1 = new SparsePositionIterator(def);
		final PositionIterator iter2 = new DensePositionIterator(def);
		// TODO - remove evil casts
		final Dataset input = (Dataset) def.getDisplay().getActiveView().getData();
		final Dataset output = (Dataset) outputImage.getActiveView().getData();
		final long[] inputDims = input.getDims();
		final long[] outputDims = output.getDims();
		final RandomAccess> inputAccessor =
			input.getImgPlus().randomAccess();
		final RandomAccess> outputAccessor =
			output.getImgPlus().randomAccess();
		double min = Double.MAX_VALUE;
		double max = -Double.MAX_VALUE;
		while (iter1.hasNext() && iter2.hasNext()) {

			// determine data positions within datasets
			final long[] inputPos = iter1.next();
			final long[] outputPos = iter2.next();
			inputAccessor.setPosition(inputPos);
			outputAccessor.setPosition(outputPos);

			// copy value
			final double value = inputAccessor.get().getRealDouble();
			min = Math.min(value, min);
			max = Math.max(value, max);
			outputAccessor.get().setReal(value);

			// TODO - notice there is a lot of inefficiency following here.
			// We are setting color tables once per pixel in image and do a lot of
			// calculation to figure out what table. This should be done once per
			// plane.
			
			// keep dataset color tables in sync
			final int inputPlaneNumber = planeNum(inputDims, inputPos);
			final ColorTable colorTable = input.getColorTable(inputPlaneNumber);
			final int outputPlaneNumber = planeNum(outputDims, outputPos);
			output.setColorTable(colorTable, outputPlaneNumber);
		}

		// TODO - enable this code
		// List overlays = overlayService.getOverlays(def.getDisplay());
		// attachOverlays(def.getDisplay(), outputImage, overlays);

		/* TODO
		setOtherMetadata();  // user defined info that has been added to orig data
		// keep composite status in sync
		setCompositeChannelCount(input, output);

		// keep display color tables in sync
		updateDisplayColorTables(def.getDisplay(), outputImage);

		// set the display range from actual data values
		// TODO - could just reuse input image's display ranges for valid channels
		setDisplayRange(outputImage, min, max);
	}

	/** Calculates a plane number from a position within a dimensional space. */
	private int planeNum(final long[] dims, final long[] pos) {
		int plane = 0;
		int inc = 1;
		for (int i = 2; i < dims.length; i++) { // TODO - assumes X & Y are 1st two dims
			plane += pos[i] * inc;
			inc *= dims[i];
		}
		return plane;
	}

	/**
	 * Sets an output Dataset's composite channel count based upon an input
	 * Dataset's composite channel characteristics.
	 */
	private void setCompositeChannelCount(final Dataset input,
		final Dataset output)
	{
		if (input.getCompositeChannelCount() == 1) return;
		final int index = output.getAxisIndex(Axes.CHANNEL);
		final long numChannels = (index < 0) ? 1 : output.dimension(index);
		output.setCompositeChannelCount((int) numChannels);
		// outside viewers need to know composite channel count changed
		output.rebuild();
	}

	/**
	 * Copies the appropriate color tables from the input ImageDisplay to the
	 * output ImageDiosplay.
	 */
	private void updateDisplayColorTables(final ImageDisplay input,
		final ImageDisplay output)
	{
		final int chAxisIn = input.getAxisIndex(Axes.CHANNEL);
		final int chAxisOut = output.getAxisIndex(Axes.CHANNEL);
		if (chAxisIn < 0 || chAxisOut < 0) {
			return;
		}
		if (input.dimension(chAxisIn) != output.dimension(chAxisOut)) {
			return;
		}

		// otherwise if here the two displays have channel axes of the same size

		// TODO - cannot assume 1 color table per channel, right? if so then no
		// idea how to copy color tables. For now will assume 1 per channel
		final DatasetView inView = imgDispService.getActiveDatasetView(input);
		final DatasetView outView = imgDispService.getActiveDatasetView(output);
		final List colorTables = inView.getColorTables();
		for (int c = 0; c < colorTables.size(); c++) {
			final ColorTable table = colorTables.get(c);
			outView.setColorTable(table, c);
		}
	}

	private void attachOverlays(final ImageDisplay inputDisp,
		final ImageDisplay outputDisp, final List overlays)
	{
		final RealRect bounds = overlayService.getSelectionBounds(inputDisp);
		final double[] toOrigin = new double[2];
		toOrigin[0] = -bounds.x;
		toOrigin[1] = -bounds.y;
		final List newOverlays = new ArrayList();
		for (final Overlay overlay : overlays) {
			if (overlayWithinBounds(overlay, bounds)) {
				// add a reference to existing overlay?
				if (toOrigin[0] == 0 && toOrigin[1] == 0) {
					newOverlays.add(overlay);
				}
				else { // different origins means must create new overlays
					final Overlay newOverlay = overlay.duplicate();
					newOverlay.move(toOrigin);
					newOverlays.add(newOverlay);
				}
			}
		}
		overlayService.addOverlays(outputDisp, newOverlays);
	}

	private boolean overlayWithinBounds(final Overlay overlay,
		final RealRect bounds)
	{
		if (overlay.min(0) < bounds.x) return false;
		if (overlay.min(1) < bounds.y) return false;
		if (overlay.max(0) > bounds.x + bounds.width) return false;
		if (overlay.max(1) > bounds.y + bounds.height) return false;
		return true;
	}
>>>>>>> 4669b3785cc2b24740d9cd9172e1a24ae6a6a6e1

}
Solution content
	 * Creates a copy of all the planes bounded by the currently selected 2d
	 * region of an ImageDisplay.
	 */
	ImageDisplay duplicateSelectedPlanes(ImageDisplay display);

}
File
SamplerService.java
Developer's decision
Version 1
Kind of conflict
Comment
Method declaration
Method interface