diff options
-rw-r--r-- | src/control.c | 4 | ||||
-rw-r--r-- | src/displaywindow.c | 17 | ||||
-rw-r--r-- | src/ipr.c | 38 | ||||
-rw-r--r-- | src/reflections.c | 21 | ||||
-rw-r--r-- | src/reflections.h | 6 | ||||
-rw-r--r-- | src/reproject.c | 19 | ||||
-rw-r--r-- | src/reproject.h | 2 |
7 files changed, 52 insertions, 55 deletions
diff --git a/src/control.c b/src/control.c index e0318c0..1b4e826 100644 --- a/src/control.c +++ b/src/control.c @@ -26,11 +26,11 @@ int control_add_image(ControlContext *ctx, int16_t *image, int width, int height if ( ctx->fmode == FORMULATION_PIXELSIZE ) { ctx->images[ctx->n_images].pixel_size = ctx->pixel_size; ctx->images[ctx->n_images].camera_len = 0; - ctx->images[ctx->n_images].resolution = ctx->resolution; + ctx->images[ctx->n_images].resolution = 0; } else if ( ctx->fmode == FORMULATION_CLEN ) { ctx->images[ctx->n_images].pixel_size = 0; ctx->images[ctx->n_images].camera_len = ctx->camera_length; - ctx->images[ctx->n_images].resolution = 0; + ctx->images[ctx->n_images].resolution = ctx->resolution; } ctx->n_images++; diff --git a/src/displaywindow.c b/src/displaywindow.c index cc8fa0e..e73cbc5 100644 --- a/src/displaywindow.c +++ b/src/displaywindow.c @@ -349,17 +349,15 @@ static gint displaywindow_gl_expose(GtkWidget *widget, GdkEventExpose *event, Co do { if ( reflection->type == REFLECTION_CENTRAL ) { + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue); glPushMatrix(); glTranslatef(reflection->x/1e9, reflection->y/1e9, reflection->z/1e9); gluSphere(quadric, 0.2, 32, 32); glPopMatrix(); - } - if ( reflection->type == REFLECTION_GENERATED ) { - #if 0 - /* Generated reflections are displayed by index, not coordinates. - xyz field in Reflection will be used later for "measured" location. */ + } else if ( reflection->type == REFLECTION_GENERATED ) { + double x, y, z; signed int h, k, l; @@ -375,7 +373,14 @@ static gint displaywindow_gl_expose(GtkWidget *widget, GdkEventExpose *event, Co gluSphere(quadric, 0.2, 8, 8); glPopMatrix(); - #endif + + } else if ( reflection->type == REFLECTION_MARKER ) { + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, gold); + glPushMatrix(); + glTranslatef(reflection->x/1e9, reflection->y/1e9, reflection->z/1e9); + gluSphere(quadric, 0.2, 8, 8); + glPopMatrix(); } reflection = reflection->next; @@ -187,7 +187,6 @@ static ReflectionContext *ipr_generate(ControlContext *ctx, Basis *basis) { ReflectionContext *ordered; double max_res; - int max_order_a, max_order_b, max_order_c; signed int h, k, l; /* NB This assumes the diffraction pattern is "vaguely" centered... */ @@ -197,25 +196,31 @@ static ReflectionContext *ipr_generate(ControlContext *ctx, Basis *basis) { } else { max_res = sqrt(ctx->width*ctx->width + ctx->height*ctx->height) / (ctx->lambda * ctx->camera_length); } - max_res = max_res / 4; + max_res = max_res / 2; } else { max_res = 2e10; //works until I put some more in the reflect.cache header } - max_order_a = max_res/basis->a.modulus; - max_order_b = max_res/basis->b.modulus; - max_order_c = max_res/basis->c.modulus; - ordered = reflection_init(); - - for ( h=-max_order_a; h<=max_order_a; h++ ) { - for ( k=-max_order_b; k<=max_order_b; k++ ) { - for ( l=-max_order_c; l<=max_order_c; l++ ) { - Reflection *ref; - ref = reflection_add_index(ordered, h, k, l, 1, REFLECTION_GENERATED); - ref->x = h*basis->a.x + k*basis->b.x + l*basis->c.x; - ref->y = h*basis->a.y + k*basis->b.y + l*basis->c.y; - ref->z = h*basis->a.z + k*basis->b.z + l*basis->c.z; + basis->a.x = 5e9; basis->a.y = 0.0; basis->a.z = 0.0; + basis->b.x = 0.0; basis->b.y = 5e9; basis->b.z = 0.0; + basis->c.x = 0.0; basis->c.y = 0.0; basis->c.z = 3e9; + for ( h=-30; h<=30; h++ ) { + for ( k=-30; k<=30; k++ ) { + for ( l=-30; l<=30; l++ ) { + + double x, y, z; + + x = h*basis->a.x + k*basis->b.x + l*basis->c.x; + y = h*basis->a.y + k*basis->b.y + l*basis->c.y; + z = h*basis->a.z + k*basis->b.z + l*basis->c.z; + + if ( ( x*x + y*y + z*z ) <= max_res*max_res ) { + Reflection *ref; + ref = reflection_add(ordered, x, y, z, 1, REFLECTION_GENERATED); + ref->h = h; ref->k = k; ref->l = l; + } + } } } @@ -253,9 +258,10 @@ int ipr_refine(ControlContext *ctx) { /* Select an image */ i = ipr_random_image(ctx); + i = 1; cur = imagedisplay_open(ctx->images[i].image, ctx->images[i].width, ctx->images[i].height, "Current Image"); - refl = reproject_get_reflections(ctx->images[i], &n, lat); + refl = reproject_get_reflections(ctx->images[i], &n, lat, ctx); for ( j=0; j<n; j++ ) { imagedisplay_mark_circle(cur, refl[j].x, refl[j].y); } diff --git a/src/reflections.c b/src/reflections.c index 955eb82..4d9f448 100644 --- a/src/reflections.c +++ b/src/reflections.c @@ -59,10 +59,10 @@ void reflection_free(ReflectionContext *reflectionctx) { free(reflectionctx); } -void reflection_add(ReflectionContext *reflectionctx, double x, double y, double z, double intensity, ReflectionType type) { +Reflection *reflection_add(ReflectionContext *reflectionctx, double x, double y, double z, double intensity, ReflectionType type) { Reflection *new_reflection; - //printf("Added reflection (%f,%f,%f)\n",x,y,z); + new_reflection = malloc(sizeof(Reflection)); new_reflection->next = NULL; new_reflection->x = x; @@ -74,23 +74,6 @@ void reflection_add(ReflectionContext *reflectionctx, double x, double y, double reflectionctx->last_reflection->next = new_reflection; reflectionctx->last_reflection = new_reflection; -} - -Reflection *reflection_add_index(ReflectionContext *reflectionctx, signed int h, signed int k, signed int l, double intensity, ReflectionType type) { - - Reflection *new_reflection; - - new_reflection = malloc(sizeof(Reflection)); - new_reflection->next = NULL; - new_reflection->h = h; - new_reflection->k = k; - new_reflection->l = l; - new_reflection->intensity = intensity; - new_reflection->type = type; - - reflectionctx->last_reflection->next = new_reflection; - reflectionctx->last_reflection = new_reflection; - return new_reflection; } diff --git a/src/reflections.h b/src/reflections.h index 55c294c..dc15d88 100644 --- a/src/reflections.h +++ b/src/reflections.h @@ -19,7 +19,8 @@ typedef enum { REFLECTION_NORMAL, /* Measured - expressed as x, y, z position */ REFLECTION_CENTRAL, /* The central beam */ - REFLECTION_GENERATED /* Generated and intensity-measured - expressed as h, k, l index */ + REFLECTION_GENERATED, /* Generated and intensity-measured - expressed as h, k, l index */ + REFLECTION_MARKER } ReflectionType; typedef struct reflection_struct { @@ -68,8 +69,7 @@ extern ReflectionContext *reflection_init(void); extern void reflection_clear(ReflectionContext *reflectionctx); extern void reflection_free(ReflectionContext *reflectionctx); -extern void reflection_add(ReflectionContext *reflectionctx, double x, double y, double z, double intensity, ReflectionType type); -extern Reflection *reflection_add_index(ReflectionContext *reflectionctx, signed int h, signed int k, signed int l, double intensity, ReflectionType type); +extern Reflection *reflection_add(ReflectionContext *reflectionctx, double x, double y, double z, double intensity, ReflectionType type); #include "control.h" diff --git a/src/reproject.c b/src/reproject.c index c6cf2ce..f3c3480 100644 --- a/src/reproject.c +++ b/src/reproject.c @@ -15,14 +15,14 @@ #include "control.h" #include "reflections.h" -#define MAX_IMAGE_REFLECTIONS 1024 +#define MAX_IMAGE_REFLECTIONS 8*1024 -ImageReflection *reproject_get_reflections(ImageRecord image, size_t *n, ReflectionContext *rctx) { +ImageReflection *reproject_get_reflections(ImageRecord image, size_t *n, ReflectionContext *rctx, ControlContext *ctx) { ImageReflection *refl; Reflection *reflection; int i; - double smax = 1e9; + double smax = 0.5e9; double tilt, omega; tilt = 2*M_PI*(image.tilt/360); @@ -60,10 +60,10 @@ ImageReflection *reproject_get_reflections(ImageRecord image, size_t *n, Reflect c = xl*xl + yl*yl + zl*zl - 2.0*zl/image.lambda; s1 = (-b + sqrt(b*b-4.0*a*c))/(2.0*a); s2 = (-b - sqrt(b*b-4.0*a*c))/(2.0*a); - if ( s1 < s2 ) s = s1; else s = s2; + if ( fabs(s1) < fabs(s2) ) s = s1; else s = s2; /* Skip this reflection if s is large */ - if ( s <= smax ) { + if ( fabs(s) <= smax ) { double xddd, yddd, zddd; double xdd, ydd, zdd; @@ -73,7 +73,9 @@ ImageReflection *reproject_get_reflections(ImageRecord image, size_t *n, Reflect /* Determine the intersection point */ xddd = xl + s*nx; yddd = yl + s*ny; zddd = zl + s*nz; - printf("intersection at %f,%f,%f\n", xddd, yddd,zddd); + reflection_add(ctx->reflectionctx, xl, yl, zl, 1, REFLECTION_CENTRAL); + reflection_add(ctx->reflectionctx, xddd, yddd, zddd, 1, REFLECTION_MARKER); + /* Invert the image->3D mapping to get the image coordinates */ xdd = xddd; ydd = (yddd/cos(tilt) - zddd*tan(tilt)/cos(tilt))/(1+tan(tilt)*tan(tilt)); @@ -85,10 +87,11 @@ ImageReflection *reproject_get_reflections(ImageRecord image, size_t *n, Reflect if ( image.fmode == FORMULATION_CLEN ) { psi = atan2(-yd, xd); - theta = acos(1-zd*image.lambda); + theta = acos(1+zd*image.lambda); x = image.camera_len*sin(theta)*cos(psi); y = image.camera_len*sin(theta)*sin(psi); x *= image.resolution; + y *= image.resolution; } else if ( image.fmode == FORMULATION_PIXELSIZE ) { x = xd / image.pixel_size; y = yd / image.pixel_size; @@ -117,7 +120,7 @@ ImageReflection *reproject_get_reflections(ImageRecord image, size_t *n, Reflect printf("Reflection %i at %i,%i\n", i, refl[i-1].x, refl[i-1].y); } else { - fprintf(stderr, "Reflection failed sanity test (x=%f, y=%f)\n", x, y); + //fprintf(stderr, "Reflection failed sanity test (x=%f, y=%f)\n", x, y); } } diff --git a/src/reproject.h b/src/reproject.h index ac7b240..790f43d 100644 --- a/src/reproject.h +++ b/src/reproject.h @@ -19,7 +19,7 @@ #include "control.h" #include "reflections.h" -extern ImageReflection *reproject_get_reflections(ImageRecord image, size_t *n, ReflectionContext *rctx); +extern ImageReflection *reproject_get_reflections(ImageRecord image, size_t *n, ReflectionContext *rctx, ControlContext *ctx); #endif /* REPROJECT_H */ |