diff options
author | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-09-28 17:11:06 +0000 |
---|---|---|
committer | taw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1> | 2007-09-28 17:11:06 +0000 |
commit | 12271165c0948536f9b34603432ade4953c97b4e (patch) | |
tree | 8d52c7685ca99b7b836babc05b940ab537c05cf3 /src/reflections.c | |
parent | 1ed23746f6d27f648e3a5f96bf499823069fd171 (diff) |
'Satisfactory-ish' basis finding
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@135 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/reflections.c')
-rw-r--r-- | src/reflections.c | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/src/reflections.c b/src/reflections.c index 63eaa54..a1f6a2c 100644 --- a/src/reflections.c +++ b/src/reflections.c @@ -102,6 +102,7 @@ void reflection_free(ReflectionContext *reflectionctx) { Reflection *reflection_add(ReflectionContext *reflectionctx, double x, double y, double z, double intensity, ReflectionType type) { Reflection *new_reflection; + Reflection *nearest; if ( reflectionctx->list_capped ) return NULL; @@ -110,6 +111,10 @@ Reflection *reflection_add(ReflectionContext *reflectionctx, double x, double y, fprintf(stderr, "No further reflections will be stored. Go and fix the peak detection.\n"); reflectionctx->list_capped = 1; } + + nearest = reflection_find_nearest_type(reflectionctx, x, y, z, type); + if ( nearest && distance3d(x, y, z, nearest->x, nearest->y, nearest->z) < 0.1e9 ) return NULL; + reflectionctx->n_reflections++; new_reflection = malloc(sizeof(Reflection)); @@ -119,6 +124,7 @@ Reflection *reflection_add(ReflectionContext *reflectionctx, double x, double y, new_reflection->z = z; new_reflection->intensity = intensity; new_reflection->type = type; + new_reflection->found = 0; reflectionctx->last_reflection->next = new_reflection; reflectionctx->last_reflection = new_reflection; @@ -248,7 +254,56 @@ Reflection *reflection_find_nearest(ReflectionContext *reflectionctx, double x, reflection = reflectionctx->reflections; while ( reflection ) { - if ( reflection->type == REFLECTION_NORMAL ) { + if ( (reflection->type == REFLECTION_NORMAL) && (!reflection->found) ) { + double mod; + mod = modulus(x - reflection->x, y - reflection->y, z - reflection->z); + if ( mod < max ) { + max = mod; + best = reflection; + } + } + reflection = reflection->next; + }; + + if ( best ) best->found = 1; + return best; + + +} + +Reflection *reflection_find_nearest_longer(ReflectionContext *reflectionctx, double x, double y, double z, double min_distance) { + + double max = +INFINITY; + Reflection *reflection; + Reflection *best = NULL; + + reflection = reflectionctx->reflections; + while ( reflection ) { + if ( (reflection->type == REFLECTION_NORMAL) && (!reflection->found) ) { + double mod; + mod = modulus(x - reflection->x, y - reflection->y, z - reflection->z); + if ( (mod < max) && (mod >= min_distance) ) { + max = mod; + best = reflection; + } + } + reflection = reflection->next; + }; + + if ( best ) best->found = 1; + return best; + +} + +Reflection *reflection_find_nearest_type(ReflectionContext *reflectionctx, double x, double y, double z, ReflectionType type) { + + double max = +INFINITY; + Reflection *reflection; + Reflection *best = NULL; + + reflection = reflectionctx->reflections; + while ( reflection ) { + if ( reflection->type == type ) { double mod; mod = modulus(x - reflection->x, y - reflection->y, z - reflection->z); if ( mod < max ) { |