src/main/java/sc/fiji/pQCT/utils/Tools.java
private static ArrayList<ArrayList<Integer>> cleave(final byte[] result,int width, int height,
		final ArrayList<Integer> fatRoiI, final ArrayList<Integer> fatRoiJ,
		final int[] cleavingIndices)
	{
		final int initI = fatRoiI.get(cleavingIndices[0]);
		final int initJ = fatRoiJ.get(cleavingIndices[0]);
		final int targetI = fatRoiI.get(cleavingIndices[1]);
		final int targetJ = fatRoiJ.get(cleavingIndices[1]);
		// remove cleaved elements
		int replacementI = fatRoiI.get(cleavingIndices[0]);
		int replacementJ = fatRoiJ.get(cleavingIndices[0]);
		// the elements to be cleaved
		final ArrayList<Integer> cleavedI = new ArrayList<Integer>(fatRoiI.subList(
			cleavingIndices[0] + 1, cleavingIndices[1] + 1));
		final ArrayList<Integer> cleavedJ = new ArrayList<Integer>(fatRoiJ.subList(
			cleavingIndices[0] + 1, cleavingIndices[1] + 1));
		for (int i = cleavingIndices[0]; i < cleavingIndices[1]; ++i) {
			// Remove the elements to be cleaved
			fatRoiI.remove(cleavingIndices[0]);
			fatRoiJ.remove(cleavingIndices[0]);
		}
		// Insert replacement line
		final double replacementLength = cleavingIndices[1] - cleavingIndices[0];
		final double repILength = targetI - initI;
		final double repJLength = targetJ - initJ;
		double relativeLength;
		final ArrayList<Integer> insertionI = new ArrayList<Integer>();
		final ArrayList<Integer> insertionJ = new ArrayList<Integer>();
		insertionI.add(replacementI);
		insertionJ.add(replacementJ);
		for (int k = cleavingIndices[0]; k < cleavingIndices[1]; ++k) {
			relativeLength = k - cleavingIndices[0];
			replacementI = ((int) (repILength * (relativeLength /
				replacementLength))) + initI;
			replacementJ = ((int) (repJLength * (relativeLength /
				replacementLength))) + initJ;
			if (replacementI != insertionI.get(insertionI.size()-1) || replacementJ != insertionJ
				.get(insertionJ.size()-1))
			{
				insertionI.add(replacementI);
				insertionJ.add(replacementJ);
				result[replacementI + replacementJ * width] = 1;
			}
		}
		fatRoiI.addAll(cleavingIndices[0], insertionI);
		fatRoiJ.addAll(cleavingIndices[0], insertionJ);
		Collections.reverse(insertionI);
		Collections.reverse(insertionJ);
		cleavedI.addAll(0, insertionI);
		cleavedJ.addAll(0, insertionJ);
		final ArrayList<ArrayList<Integer>> returnVectorPair = new ArrayList<ArrayList<Integer>>();
		returnVectorPair.add(new ArrayList<Integer>());
		returnVectorPair.add(new ArrayList<Integer>());
		returnVectorPair.get(0).addAll(cleavedI);
		returnVectorPair.get(1).addAll(cleavedJ);
		return returnVectorPair;
	}
// Remove the extra part from vectors and replace with a straight line
Remove the extra part from vectors and replace with a straight line
Remove the extra part from vectors and replace with a straight line
private static ArrayList<ArrayList<Integer>> cleave(final byte[] result,int width, int height,
		final ArrayList<Integer> fatRoiI, final ArrayList<Integer> fatRoiJ,
		final int[] cleavingIndices)
	{
		final int initI = fatRoiI.get(cleavingIndices[0]);
		final int initJ = fatRoiJ.get(cleavingIndices[0]);
		final int targetI = fatRoiI.get(cleavingIndices[1]);
		final int targetJ = fatRoiJ.get(cleavingIndices[1]);
		int replacementI = fatRoiI.get(cleavingIndices[0]);
		int replacementJ = fatRoiJ.get(cleavingIndices[0]);
		final ArrayList<Integer> cleavedI = new ArrayList<Integer>(fatRoiI.subList(
			cleavingIndices[0] + 1, cleavingIndices[1] + 1));
		final ArrayList<Integer> cleavedJ = new ArrayList<Integer>(fatRoiJ.subList(
			cleavingIndices[0] + 1, cleavingIndices[1] + 1));
		for (int i = cleavingIndices[0]; i < cleavingIndices[1]; ++i) {
			fatRoiI.remove(cleavingIndices[0]);
			fatRoiJ.remove(cleavingIndices[0]);
		}
		final double replacementLength = cleavingIndices[1] - cleavingIndices[0];
		final double repILength = targetI - initI;
		final double repJLength = targetJ - initJ;
		double relativeLength;
		final ArrayList<Integer> insertionI = new ArrayList<Integer>();
		final ArrayList<Integer> insertionJ = new ArrayList<Integer>();
		insertionI.add(replacementI);
		insertionJ.add(replacementJ);
		for (int k = cleavingIndices[0]; k < cleavingIndices[1]; ++k) {
			relativeLength = k - cleavingIndices[0];
			replacementI = ((int) (repILength * (relativeLength /
				replacementLength))) + initI;
			replacementJ = ((int) (repJLength * (relativeLength /
				replacementLength))) + initJ;
			if (replacementI != insertionI.get(insertionI.size()-1) || replacementJ != insertionJ
				.get(insertionJ.size()-1))
			{
				insertionI.add(replacementI);
				insertionJ.add(replacementJ);
				result[replacementI + replacementJ * width] = 1;
			}
		}
		fatRoiI.addAll(cleavingIndices[0], insertionI);
		fatRoiJ.addAll(cleavingIndices[0], insertionJ);
		Collections.reverse(insertionI);
		Collections.reverse(insertionJ);
		cleavedI.addAll(0, insertionI);
		cleavedJ.addAll(0, insertionJ);
		final ArrayList<ArrayList<Integer>> returnVectorPair = new ArrayList<ArrayList<Integer>>();
		returnVectorPair.add(new ArrayList<Integer>());
		returnVectorPair.add(new ArrayList<Integer>());
		returnVectorPair.get(0).addAll(cleavedI);
		returnVectorPair.get(1).addAll(cleavedJ);
		return returnVectorPair;
	}
private static ArrayList < ArrayList < Integer > > cleave ( final byte [ ] result , int width , int height , final ArrayList < Integer > fatRoiI , final ArrayList < Integer > fatRoiJ , final int [ ] cleavingIndices ) { final int initI = fatRoiI . get ( cleavingIndices [ 0 ] ) ; final int initJ = fatRoiJ . get ( cleavingIndices [ 0 ] ) ; final int targetI = fatRoiI . get ( cleavingIndices [ 1 ] ) ; final int targetJ = fatRoiJ . get ( cleavingIndices [ 1 ] ) ; int replacementI = fatRoiI . get ( cleavingIndices [ 0 ] ) ; int replacementJ = fatRoiJ . get ( cleavingIndices [ 0 ] ) ; final ArrayList < Integer > cleavedI = new ArrayList < Integer > ( fatRoiI . subList ( cleavingIndices [ 0 ] + 1 , cleavingIndices [ 1 ] + 1 ) ) ; final ArrayList < Integer > cleavedJ = new ArrayList < Integer > ( fatRoiJ . subList ( cleavingIndices [ 0 ] + 1 , cleavingIndices [ 1 ] + 1 ) ) ; for ( int i = cleavingIndices [ 0 ] ; i < cleavingIndices [ 1 ] ; ++ i ) { fatRoiI . remove ( cleavingIndices [ 0 ] ) ; fatRoiJ . remove ( cleavingIndices [ 0 ] ) ; } final double replacementLength = cleavingIndices [ 1 ] - cleavingIndices [ 0 ] ; final double repILength = targetI - initI ; final double repJLength = targetJ - initJ ; double relativeLength ; final ArrayList < Integer > insertionI = new ArrayList < Integer > ( ) ; final ArrayList < Integer > insertionJ = new ArrayList < Integer > ( ) ; insertionI . add ( replacementI ) ; insertionJ . add ( replacementJ ) ; for ( int k = cleavingIndices [ 0 ] ; k < cleavingIndices [ 1 ] ; ++ k ) { relativeLength = k - cleavingIndices [ 0 ] ; replacementI = ( ( int ) ( repILength * ( relativeLength / replacementLength ) ) ) + initI ; replacementJ = ( ( int ) ( repJLength * ( relativeLength / replacementLength ) ) ) + initJ ; if ( replacementI != insertionI . get ( insertionI . size ( ) - 1 ) || replacementJ != insertionJ . get ( insertionJ . size ( ) - 1 ) ) { insertionI . add ( replacementI ) ; insertionJ . add ( replacementJ ) ; result [ replacementI + replacementJ * width ] = 1 ; } } fatRoiI . addAll ( cleavingIndices [ 0 ] , insertionI ) ; fatRoiJ . addAll ( cleavingIndices [ 0 ] , insertionJ ) ; Collections . reverse ( insertionI ) ; Collections . reverse ( insertionJ ) ; cleavedI . addAll ( 0 , insertionI ) ; cleavedJ . addAll ( 0 , insertionJ ) ; final ArrayList < ArrayList < Integer > > returnVectorPair = new ArrayList < ArrayList < Integer > > ( ) ; returnVectorPair . add ( new ArrayList < Integer > ( ) ) ; returnVectorPair . add ( new ArrayList < Integer > ( ) ) ; returnVectorPair . get ( 0 ) . addAll ( cleavedI ) ; returnVectorPair . get ( 1 ) . addAll ( cleavedJ ) ; return returnVectorPair ; }
Remove the extra part from vectors and replace with a straight line
Remove the extra part from vectors and replace with a straight line
// remove cleaved elements // the elements to be cleaved // Remove the elements to be cleaved // Insert replacement line