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

import net.imglib2.RandomAccess;
import net.imglib2.RandomAccessible;
import net.imglib2.type.logic.BitType;

/**
 * This abstract class represents an rough framework for a Thinning algorithm
 * operating on a 3x3 neighbourhood by providing some often needed functions.
 *
 * @author Andreas Burger, University of Konstanz
 */
public abstract class Abstract3x3NeighbourhoodThinning implements
	ThinningStrategy
{

	/**
	 * Boolean value of the foreground.
	 */
	protected boolean m_foreground;

	/**
	 * Boolean value of the background.
	 */
	protected boolean m_background;

	protected Abstract3x3NeighbourhoodThinning() {
		m_foreground = true;
		m_background = false;
	}

	/**
	 * Create a new abstract thinning strategy. The passed boolean will represent
	 * the foreground-value of the image.
	 *
	 * @param foreground Value determining the boolean value of foreground pixels.
	 */
	protected Abstract3x3NeighbourhoodThinning(final boolean foreground) {
		m_foreground = foreground;
		m_background = !foreground;
	}

	@Override
	public boolean removePixel(final long[] position,
		final RandomAccessible<BitType> access, final int iteration)
	{
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * Returns all booleans in a 3x3 neighbourhood of the pixel the RandomAccess
	 * points to. These booleans are stored in an Array in the following order:
	 * <br>
	 * 8 1 2 <br>
	 * 7 0 3 <br>
	 * 6 5 4 <br>
	 *
	 * @param access A RandomAccess pointing to a pixel of the image
	 * @return A boolean Array holding the values of the neighbourhood in
	 *         clockwise order.
	 */
	protected boolean[] getNeighbourhood(final RandomAccess<BitType> access) {
		final boolean[] vals = new boolean[9];

		vals[0] = access.get().get();

		access.move(-1, 1);
		vals[1] = access.get().get();

		access.move(1, 0);
		vals[2] = access.get().get();

		access.move(1, 1);
		vals[3] = access.get().get();

		access.move(1, 1);
		vals[4] = access.get().get();

		access.move(-1, 0);
		vals[5] = access.get().get();

		access.move(-1, 0);
		vals[6] = access.get().get();

		access.move(-1, 1);
		vals[7] = access.get().get();

		access.move(-1, 1);
		vals[8] = access.get().get();

		return vals;

	}

	/**
	 * Returns the amount of switches from foreground to background occurring in
	 * the circle around vals[1]
	 *
	 * @param vals Boolean Array holding the neighbourhood.
	 * @return Amount of true-false switches in the neighbourhood.
	 */
	protected int findPatternSwitches(final boolean[] vals) {
		int res = 0;
		for (int i = 1; i < vals.length - 1; ++i) {
			if (vals[i] == m_foreground && vals[i + 1] == m_background) {
				++res;
			}
			if (vals[vals.length - 1] == m_foreground && vals[1] == m_background) {
				++res;
			}
		}
		return res;
	}

	@Override
	public void afterCycle() {
		// Intentionally left blank.
	}

	@Override
	public int getIterationsPerCycle() {
		return 1;
	}

}

@@ -1529,45 +1529,8 @@
 ss;%0A
-import net.imglib2.RandomAccessible;%0A
 impo
@@ -2481,193 +2481,8 @@
 %09%7D%0A%0A
-%09@Override%0A%09public boolean removePixel(final long%5B%5D position,%0A%09%09final RandomAccessible%3CBitType%3E access, final int iteration)%0A%09%7B%0A%09%09// TODO Auto-generated method stub%0A%09%09return false;%0A%09%7D%0A%0A
 %09/**

Remove unneeded method