From 6a2ce6ae01f08fe0b0384f044a7919fc44d54ecb Mon Sep 17 00:00:00 2001 From: Helen Ginn Date: Fri, 11 Nov 2016 15:45:15 +0000 Subject: Find potential matches between observed and simulated vectors now returns a list, not a single match, in preparation for being more thorough searching --- libcrystfel/src/taketwo.c | 152 ++++++++++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 71 deletions(-) diff --git a/libcrystfel/src/taketwo.c b/libcrystfel/src/taketwo.c index 28a1a973..07b05a6e 100644 --- a/libcrystfel/src/taketwo.c +++ b/libcrystfel/src/taketwo.c @@ -431,18 +431,21 @@ static int obs_shares_spot_w_array(struct SpotVec *obs_vecs, int test_idx, } +// FIXME: decide if match count is returned or put in variable name /** Note: this could potentially (and cautiously) converted to comparing * cosines rather than angles, to lose an "acos" but different parts of the * cosine graph are more sensitive than others, so may be a trade off... or not. */ static int obs_vecs_match_angles(struct SpotVec *her_obs, struct SpotVec *his_obs, - int *her_match_idx, int *his_match_idx) + int **her_match_idxs, int **his_match_idxs, + int *match_count) { int i, j; + *match_count = 0; - *her_match_idx = -1; - *his_match_idx = -1; + // *her_match_idx = -1; + // *his_match_idx = -1; /* calculate angle between observed vectors */ double obs_angle = rvec_angle(her_obs->obsvec, his_obs->obsvec); @@ -462,14 +465,31 @@ static int obs_vecs_match_angles(struct SpotVec *her_obs, double angle_diff = fabs(theory_angle - obs_angle); if ( angle_diff < ANGLE_TOLERANCE ) { - *her_match_idx = i; - *his_match_idx = j; - return 1; + + /* Reallocate the array to fit in another match */ + int *temp_hers; + temp_hers = realloc(her_match_idxs, *match_count * + sizeof(int)); + int *temp_his; + temp_his = realloc(his_match_idxs, *match_count * + sizeof(int)); + + if ( temp_hers == NULL || temp_his == NULL ) { + apologise(); + } + + (*her_match_idxs) = temp_hers; + (*his_match_idxs) = temp_his; + + (*her_match_idxs)[*match_count] = i; + (*his_match_idxs)[*match_count] = j; + + (*match_count)++; } } } - return 0; + return (match_count > 0); } @@ -489,13 +509,16 @@ static int obs_angles_match_array(struct SpotVec *obs_vecs, int test_idx, struct SpotVec *his_obs = &obs_vecs[obs_members[i]]; /* placeholders, but results are ignored */ - int idx1, idx2; + int *idx1; + int *idx2; + int match_count; /* check our test vector matches existing network member */ - int matches = obs_vecs_match_angles(her_obs, his_obs, - &idx1, &idx2); + obs_vecs_match_angles(her_obs, his_obs, + &idx1, &idx2, &match_count); - if (idx2 != match_members[i]) return 0; + /* FIXME: this is going to be broken */ + // if (idx2 != match_members[i]) return 0; //STATUS("match %i %i %i %i\n", idx1, idx2, test_idx, // match_members[i]); } @@ -535,60 +558,47 @@ static signed int find_next_index(gsl_matrix *rot, struct SpotVec *obs_vecs, * so for now, just sticking to the first two... */ - /* need to grab the matching vector index */ + /* need to grab all the matching vector indices */ - int member_idx, test_idx; + int *member_idx; + int *test_idx; + int match_num; /* FIXME: this may be a source of a problem */ obs_vecs_match_angles(&obs_vecs[obs_members[0]], &obs_vecs[i], - &member_idx, &test_idx); - - *match_found = test_idx; - struct rvec test_match = obs_vecs[i].matches[test_idx]; - - int j; + &member_idx, &test_idx, &match_num); /* if ok is set to 0, give up on this vector before - * thecking the next value of j */ - int ok = 1; - - for ( j=0; j<2; j++ ) { - - gsl_matrix *test_rot = gsl_matrix_calloc(3, 3); - struct rvec member_match; - int j_idx = obs_members[j]; - - member_match = obs_vecs[j_idx].matches[match_members[j]]; - STATUS("]]]]] %i %i %i %i\n", - j_idx, i, match_members[j], test_idx); - - //STATUS("test:\n"); - //struct rvec obs1 = {0, 1, 2}; - //struct rvec obs2 = {3, 4, 5}; - //struct rvec cell1 = {5, 7, 2}; - //struct rvec cell2 = {-1, 4, 3}; - //generate_rot_mat(obs1, obs2, cell1, cell2); - //STATUS("end of test\n"); - //exit(0); - - test_rot = generate_rot_mat(obs_vecs[j_idx].obsvec, - obs_vecs[i].obsvec, - member_match, - test_match); - - ok = rot_mats_are_similar(rot, test_rot); - //exit(0); - //STATUS("--\n"); - //show_matrix(rot); - STATUS("ok = %i\n", ok); - if ( !ok ) break; - } - - if ( !ok ) continue; - - /* successful branch - return to calling function...*/ - - return i; + * checking the next value of j */ + int j; + + for ( j=0; j