getColumnSorting method
Assumes that detectRowPeaks() was called before.
Sorts the resulting peaklist so as to return a "stacked peaks" list, sorted
according same columns by considering drift
.
A peak in the result is given as a row,col
pair.
A list of such pairs represents "stacked peaks", i.e. peaks occuring
in all rows at the same column (+-drift). In the contour display
"stacked peaks" are displayed in the same column (+-drift).
The returned list is a list of stacked peak lists, where the first list
has the smalled column:
Result =
stacked peaklist1, stacked peaklist2, ...
where
stacked peaklist = [row, col
, row, col
,...], hence
[[row, col
, row, col
,...], [row, col
, row, col
,...], ...]
A peak is only taken over into a stacked peak list if its column index
is no more than drift
apart from the column index of the first row.
[0, 20
Implementation
List<List<List<int>>> getColumnSorting(int drift) {
List<List<List<int>>> result = [];
// Returns a list of peaks whose column coordinate matches [col].
// Matching means a peak's cols coordinate is close to [col] and
// at maximum [drift] points apart from it.
List<List<int>> getPeaksWithCol(int col, int drift) {
List<List<int>> result = [];
rowPeaks.forEach((int rowi, List<int> cols) {
cols.forEach((int colk) {
if ((colk - col).abs() <= drift) {
result.add([rowi, colk]);
}
});
});
return result;
}
// construct a Map of columns
Map<int, List<int>> colmap = {};
rowPeaks.forEach((int row, List<int> cols) {
cols.forEach((int col) {
colmap[col] = [row, col];
});
});
// for each column find machting columns in all rows
colmap.forEach((int coli, List<int> peaks) {
List<List<int>> rowsWithCol = getPeaksWithCol(coli, drift);
if (rowsWithCol.isNotEmpty) {
result.add(rowsWithCol);
}
});
return result;
}