/************************************************************************* ************************************************************************** #cat: sort_neighbors - Takes a list of primary minutia and its neighboring #cat: minutia indices and sorts the neighbors based on their #cat: position relative to the primary minutia point. Neighbors #cat: are sorted starting vertical to the primary point and #cat: proceeding clockwise. Input: nbr_list - list of neighboring minutia indices nnbrs - number of neighbors in the list first - the index of the primary minutia point minutiae - list of minutiae Output: nbr_list - neighboring minutia indices in sorted order Return Code: Zero - successful completion Negative - system error **************************************************************************/ int sort_neighbors(int *nbr_list, const int nnbrs, const int first, MINUTIAE *minutiae) { double *join_thetas, theta; int i; static double pi2 = M_PI*2.0; /* List of angles of lines joining the current primary to each */ /* of the secondary neighbors. */ join_thetas = (double *)malloc(nnbrs * sizeof(double)); if(join_thetas == (double *)NULL){ fprintf(stderr, "ERROR : sort_neighbors : malloc : join_thetas\n"); return(-490); } for(i = 0; i < nnbrs; i++){ /* Compute angle to line connecting the 2 points. */ /* Coordinates are swapped and order of points reversed to */ /* account for 0 direction is vertical and positive direction */ /* is clockwise. */ theta = angle2line(minutiae->list[nbr_list[i]]->y, minutiae->list[nbr_list[i]]->x, minutiae->list[first]->y, minutiae->list[first]->x); /* Make sure the angle is positive. */ theta += pi2; theta = fmod(theta, pi2); join_thetas[i] = theta; } /* Sort the neighbor indicies into rank order. */ bubble_sort_double_inc_2(join_thetas, nbr_list, nnbrs); /* Deallocate the list of angles. */ free(join_thetas); /* Return normally. */ return(0); }
/************************************************************************* ************************************************************************** #cat: sort_indices_double_inc - Takes a list of doubles and returns a list of #cat: indices referencing the double list in increasing order. #cat: The original list of doubles is also returned in sorted #cat: order. Input: ranks - list of doubles to be sorted num - number of doubles in the list Output: optr - list of indices referencing the double list in sorted order ranks - list of doubles in increasing order Return Code: Zero - successful completion Negative - system error **************************************************************************/ int sort_indices_double_inc(int **optr, double *ranks, const int num) { int *order; int i; /* Allocate list of sequential indices. */ order = (int *)malloc(num * sizeof(int)); if(order == (int *)NULL){ fprintf(stderr, "ERROR : sort_indices_double_inc : malloc : order\n"); return(-400); } /* Initialize list of sequential indices. */ for(i = 0; i < num; i++) order[i] = i; /* Sort the indicies into rank order. */ bubble_sort_double_inc_2(ranks, order, num); /* Set output pointer to the resulting order of sorted indices. */ *optr = order; /* Return normally. */ return(0); }