
package org.bonej.wrapperPlugins;

import static org.bonej.wrapperPlugins.CommonMessages.*;

import net.imagej.patcher.LegacyInjector;

import org.bonej.utilities.ImagePlusCheck;
import org.scijava.ItemIO;
import org.scijava.command.Command;
import org.scijava.command.ContextCommand;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

import ij.ImagePlus;
import ij.plugin.LutLoader;
import sc.fiji.skeletonize3D.Skeletonize3D_;

/**
 * A wrapper plugin to bundle Skeletonize3D into BoneJ2
 *
 * @author Richard Domander
 */
@Plugin(type = Command.class, menuPath = "Plugins>BoneJ>Skeletonise")
public class SkeletoniseWrapper extends ContextCommand {

	static {
		LegacyInjector.preinit();
	}

	/**
	 * @implNote Use ImagePlus because of conversion issues of composite images
	 */
	@Parameter(validater = "validateImage")
	private ImagePlus inputImage;

	/**
	 * @implNote Use ImagePlus because a (converted) Dataset has display issues
	 *           with a composite image
	 */
	@Parameter(type = ItemIO.OUTPUT)
	private ImagePlus skeleton;

	@Override
	public void run() {
		skeleton = inputImage.duplicate();
		skeleton.setTitle("Skeleton of " + inputImage.getTitle());

		final Skeletonize3D_ skeletoniser = new Skeletonize3D_();
		skeletoniser.setup("", skeleton);
		skeletoniser.run(null);

		skeleton.show();
		if (inputImage.isInvertedLut() != skeleton.isInvertedLut()) {
			// FIXME Does *not* work in headless mode!
			LutLoader lutLoader = new LutLoader();
			lutLoader.run("invert");
		}
	}

	@SuppressWarnings("unused")
	private void validateImage() {
		if (inputImage == null) {
			cancel(NO_IMAGE_OPEN);
			return;
		}

		if (inputImage.getType() != ImagePlus.GRAY8 || !ImagePlusCheck
			.isBinaryColour(inputImage))
		{
			cancel(NOT_8_BIT_BINARY_IMAGE);
		}
	}
}

@@ -83,17 +83,107 @@
 essages.
-*
+NOT_8_BIT_BINARY_IMAGE;%0Aimport static org.bonej.wrapperPlugins.CommonMessages.NO_IMAGE_OPEN
 ;%0A%0Aimpor
@@ -466,36 +466,8 @@
 us;%0A
-import ij.plugin.LutLoader;%0A
 impo
@@ -1377,212 +1377,8 @@
 ll);
-%0A%0A%09%09skeleton.show();%0A%09%09if (inputImage.isInvertedLut() != skeleton.isInvertedLut()) %7B%0A%09%09%09// FIXME Does *not* work in headless mode!%0A%09%09%09LutLoader lutLoader = new LutLoader();%0A%09%09%09lutLoader.run(%22invert%22);%0A%09%09%7D
 %0A%09%7D%0A

Refactor SkeletoniseWrapper