src/main/java/sc/fiji/pQCT/selectroi/RoiSelector.java
private ArrayList<ArrayList<ArrayList<Integer>>> cleaveEdge(final byte[] result,
		final ArrayList<Integer> fatRoiI, final ArrayList<Integer> fatRoiJ,
		final double minRatio, final double minLength)
	{
		double distanceAlongTheEdge;
		double distance;
		double ratio;
		final double minEdge = fatRoiI.size() / minLength;
		final int[] cleavingIndices = new int[2];
		final ArrayList<ArrayList<ArrayList<Integer>>> returnVectorVectorPointer =
			new ArrayList<ArrayList<ArrayList<Integer>>>();
		while (true) {
			double highestRatio = minRatio - 0.1;
			/*Go through all point pairs*/
			for (int i = 0; i < fatRoiI.size() - 11; ++i) {
				for (int j = i + 10; j < fatRoiI.size(); ++j) {
					distance = Math.sqrt(Math.pow(fatRoiI.get(j) - fatRoiI.get(i), 2.0) +
						Math.pow(fatRoiJ.get(j) - fatRoiJ.get(i), 2.0));
					distanceAlongTheEdge = Math.min((j - i), fatRoiI.size() - j + i);
					ratio = distanceAlongTheEdge / distance;
					if (ratio > highestRatio && distanceAlongTheEdge > minEdge) {
						highestRatio = ratio;
						cleavingIndices[0] = i;
						cleavingIndices[1] = j;
					}

				}
			}
			/*If ratio is high enough, cleave at the highest ratio point pair*/
			if (highestRatio < minRatio) {
				break;
			}
			returnVectorVectorPointer.add(cleave(result, fatRoiI, fatRoiJ,
				cleavingIndices));
		}
		/*Insert the last retained part to first index.*/
		final ArrayList<ArrayList<Integer>> returnVectorPair = new ArrayList<ArrayList<Integer>>();
		returnVectorPair.add(new ArrayList<Integer>());
		returnVectorPair.add(new ArrayList<Integer>());
		returnVectorPair.get(0).addAll(fatRoiI);
		returnVectorPair.get(1).addAll(fatRoiJ);
		if (returnVectorVectorPointer.size() < 1) {
			returnVectorVectorPointer.add(returnVectorPair);
		}
		else {
			returnVectorVectorPointer.add(0,returnVectorPair);
		}
		return returnVectorVectorPointer;
	}
/*Cleaving is made by looking at the ratios of
	distances between two points along the edge and the shortest distance
	between the points. If the maximum of the  ratio is big enough, the
	highest ratio points will be connected with a straigth
	line and the edge with higher indices will be removed. E.g.
	for a circle, the maximum ratio is (pi/2)/d ~= 1.57 and for square
	it is 2/sqrt(2) = sqrt(2) ~= 1.41.*/
Cleaving is made by looking at the ratios of
distances between two points along the edge and the shortest distance
between the points. If the maximum of the  ratio is big enough, the
highest ratio points will be connected with a straigth
line and the edge with higher indices will be removed.
Cleaving is made by looking at the ratios of distances between two points along the edge and the shortest distance between the points . If the maximum of the ratio is big enough the highest ratio points will be connected with a straigth line and the edge with higher indices will be removed .
private ArrayList<ArrayList<ArrayList<Integer>>> cleaveEdge(final byte[] result,
		final ArrayList<Integer> fatRoiI, final ArrayList<Integer> fatRoiJ,
		final double minRatio, final double minLength)
	{
		double distanceAlongTheEdge;
		double distance;
		double ratio;
		final double minEdge = fatRoiI.size() / minLength;
		final int[] cleavingIndices = new int[2];
		final ArrayList<ArrayList<ArrayList<Integer>>> returnVectorVectorPointer =
			new ArrayList<ArrayList<ArrayList<Integer>>>();
		while (true) {
			double highestRatio = minRatio - 0.1;
			/*Go through all point pairs*/
			for (int i = 0; i < fatRoiI.size() - 11; ++i) {
				for (int j = i + 10; j < fatRoiI.size(); ++j) {
					distance = Math.sqrt(Math.pow(fatRoiI.get(j) - fatRoiI.get(i), 2.0) +
						Math.pow(fatRoiJ.get(j) - fatRoiJ.get(i), 2.0));
					distanceAlongTheEdge = Math.min((j - i), fatRoiI.size() - j + i);
					ratio = distanceAlongTheEdge / distance;
					if (ratio > highestRatio && distanceAlongTheEdge > minEdge) {
						highestRatio = ratio;
						cleavingIndices[0] = i;
						cleavingIndices[1] = j;
					}
				}
			}
			/*If ratio is high enough, cleave at the highest ratio point pair*/
			if (highestRatio < minRatio) {
				break;
			}
			returnVectorVectorPointer.add(cleave(result, fatRoiI, fatRoiJ,
				cleavingIndices));
		}
		/*Insert the last retained part to first index.*/
		final ArrayList<ArrayList<Integer>> returnVectorPair = new ArrayList<ArrayList<Integer>>();
		returnVectorPair.add(new ArrayList<Integer>());
		returnVectorPair.add(new ArrayList<Integer>());
		returnVectorPair.get(0).addAll(fatRoiI);
		returnVectorPair.get(1).addAll(fatRoiJ);
		if (returnVectorVectorPointer.size() < 1) {
			returnVectorVectorPointer.add(returnVectorPair);
		}
		else {
			returnVectorVectorPointer.add(0,returnVectorPair);
		}
		return returnVectorVectorPointer;
	}
private ArrayList < ArrayList < ArrayList < Integer > > > cleaveEdge ( final byte [ ] result , final ArrayList < Integer > fatRoiI , final ArrayList < Integer > fatRoiJ , final double minRatio , final double minLength ) { double distanceAlongTheEdge ; double distance ; double ratio ; final double minEdge = fatRoiI . size ( ) / minLength ; final int [ ] cleavingIndices = new int [ 2 ] ; final ArrayList < ArrayList < ArrayList < Integer > > > returnVectorVectorPointer = new ArrayList < ArrayList < ArrayList < Integer > > > ( ) ; while ( true ) { double highestRatio = minRatio - 0.1 ; /*Go through all point pairs*/ for ( int i = 0 ; i < fatRoiI . size ( ) - 11 ; ++ i ) { for ( int j = i + 10 ; j < fatRoiI . size ( ) ; ++ j ) { distance = Math . sqrt ( Math . pow ( fatRoiI . get ( j ) - fatRoiI . get ( i ) , 2.0 ) + Math . pow ( fatRoiJ . get ( j ) - fatRoiJ . get ( i ) , 2.0 ) ) ; distanceAlongTheEdge = Math . min ( ( j - i ) , fatRoiI . size ( ) - j + i ) ; ratio = distanceAlongTheEdge / distance ; if ( ratio > highestRatio && distanceAlongTheEdge > minEdge ) { highestRatio = ratio ; cleavingIndices [ 0 ] = i ; cleavingIndices [ 1 ] = j ; } } } /*If ratio is high enough, cleave at the highest ratio point pair*/ if ( highestRatio < minRatio ) { break ; } returnVectorVectorPointer . add ( cleave ( result , fatRoiI , fatRoiJ , cleavingIndices ) ) ; } /*Insert the last retained part to first index.*/ final ArrayList < ArrayList < Integer > > returnVectorPair = new ArrayList < ArrayList < Integer > > ( ) ; returnVectorPair . add ( new ArrayList < Integer > ( ) ) ; returnVectorPair . add ( new ArrayList < Integer > ( ) ) ; returnVectorPair . get ( 0 ) . addAll ( fatRoiI ) ; returnVectorPair . get ( 1 ) . addAll ( fatRoiJ ) ; if ( returnVectorVectorPointer . size ( ) < 1 ) { returnVectorVectorPointer . add ( returnVectorPair ) ; } else { returnVectorVectorPointer . add ( 0 , returnVectorPair ) ; } return returnVectorVectorPointer ; }
Cleaving is made by looking at the ratios of
distances between two points along the edge and the shortest distance
between the points.
Cleaving is made by looking at the ratios of distances between two points along the edge and the shortest distance between the points .