aboutsummaryrefslogtreecommitdiff
path: root/src/reflections.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reflections.c')
-rw-r--r--src/reflections.c87
1 files changed, 61 insertions, 26 deletions
diff --git a/src/reflections.c b/src/reflections.c
index a0ff76d..56871f0 100644
--- a/src/reflections.c
+++ b/src/reflections.c
@@ -22,26 +22,18 @@
#include "reflections.h"
#include "utils.h"
-static void reflection_addfirst(ReflectionList *reflectionlist) {
- /* Create first items on lists - saves faffing later. Corresponds to a central marker.
- Reflections are only stored if they have non-zero value. */
- reflectionlist->reflections = malloc(sizeof(Reflection));
- reflectionlist->reflections->next = NULL;
- reflectionlist->reflections->x = 0;
- reflectionlist->reflections->y = 0;
- reflectionlist->reflections->z = 0;
- reflectionlist->reflections->type = REFLECTION_CENTRAL;
- reflectionlist->last_reflection = reflectionlist->reflections;
- reflectionlist->n_reflections = 1;
+static void reflectionlist_init(ReflectionList *reflectionlist) {
+ reflectionlist->n_reflections = 0;
reflectionlist->list_capped = 0;
+ reflectionlist->reflections = NULL;
+ reflectionlist->last_reflection = NULL;
}
-ReflectionList *reflection_init() {
+ReflectionList *reflectionlist_new() {
ReflectionList *reflectionlist = malloc(sizeof(ReflectionList));
- reflectionlist->n_reflections = 0;
- reflection_addfirst(reflectionlist);
- reflectionlist->list_capped = 0;
+
+ reflectionlist_init(reflectionlist);
return reflectionlist;
@@ -87,15 +79,12 @@ void reflection_clear(ReflectionList *reflectionlist) {
reflection = next;
} while ( reflection );
- reflectionlist->n_reflections = 0;
- reflectionlist->list_capped = 0;
- reflection_addfirst(reflectionlist);
+ reflectionlist_init(reflectionlist);
}
void reflection_free(ReflectionList *reflectionlist) {
reflection_clear(reflectionlist);
- free(reflectionlist->reflections);
free(reflectionlist);
}
@@ -115,8 +104,6 @@ Reflection *reflection_add(ReflectionList *reflectionlist, double x, double y, d
nearest = reflection_find_nearest_type(reflectionlist, x, y, z, type);
if ( nearest && distance3d(x, y, z, nearest->x, nearest->y, nearest->z) < 0.1e9 ) return NULL;
- reflectionlist->n_reflections++;
-
new_reflection = malloc(sizeof(Reflection));
new_reflection->next = NULL;
new_reflection->x = x;
@@ -126,8 +113,14 @@ Reflection *reflection_add(ReflectionList *reflectionlist, double x, double y, d
new_reflection->type = type;
new_reflection->found = 0;
- reflectionlist->last_reflection->next = new_reflection;
- reflectionlist->last_reflection = new_reflection;
+ if ( reflectionlist->last_reflection ) {
+ reflectionlist->last_reflection->next = new_reflection;
+ reflectionlist->last_reflection = new_reflection;
+ } else {
+ reflectionlist->reflections = new_reflection;
+ reflectionlist->last_reflection = new_reflection;
+ }
+ reflectionlist->n_reflections++;
return new_reflection;
@@ -222,9 +215,15 @@ void reflection_add_from_dp(ControlContext *ctx, double x, double y, ImageRecord
}
void reflection_add_from_reflection(ReflectionList *reflectionlist, Reflection *r) {
+ if ( reflectionlist->last_reflection ) {
+ reflectionlist->last_reflection->next = r;
+ reflectionlist->last_reflection = r;
+ } else {
+ reflectionlist->reflections = r;
+ reflectionlist->last_reflection = r;
+ }
r->next = NULL;
- reflectionlist->last_reflection->next = r;
- reflectionlist->last_reflection = r;
+ reflectionlist->n_reflections++;
}
double reflection_largest_g(ReflectionList *reflectionlist) {
@@ -269,7 +268,7 @@ Reflection *reflection_find_nearest(ReflectionList *reflectionlist, double x, do
}
-Reflection *reflection_find_nearest_longer(ReflectionList *reflectionlist, double x, double y, double z, double min_distance) {
+Reflection *reflection_find_nearest_longer_unknown(ReflectionList *reflectionlist, double x, double y, double z, double min_distance) {
double max = +INFINITY;
Reflection *reflection;
@@ -316,3 +315,39 @@ Reflection *reflection_find_nearest_type(ReflectionList *reflectionlist, double
}
+/* This destroys the lfom values in the input list */
+ReflectionList *reflection_sort_lfom(ReflectionList *in) {
+
+ ReflectionList *out;
+ Reflection *best;
+
+ out = reflectionlist_new();
+
+ do {
+
+ Reflection *reflection;
+ int lfom = 0;
+
+ reflection = in->reflections;
+ best = NULL;
+ while ( reflection ) {
+ if ( reflection->lfom > lfom ) {
+ best = reflection;
+ lfom = reflection->lfom;
+ }
+ reflection = reflection->next;
+ };
+
+ if ( best ) {
+ Reflection *new;
+ new = reflection_add(out, best->x, best->y, best->z, best->intensity, best->type);
+ new->lfom = best->lfom;
+ best->lfom = 0;
+ }
+
+ } while ( best );
+
+ return out;
+
+}
+