From d156448fddfe1b668f37a6611959309ed66b4d94 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 10 Aug 2011 10:51:50 +0200 Subject: Fix coarse indexing directions --- src/reax.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/reax.c b/src/reax.c index 81ead49e..3d89d0a2 100644 --- a/src/reax.c +++ b/src/reax.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "image.h" #include "utils.h" @@ -357,48 +358,52 @@ void reax_index(IndexingPrivate *pp, struct image *image, UnitCell *cell) IndexingPrivate *reax_prepare() { struct reax_private *p; - int ui, vi; int samp; + double th; p = calloc(1, sizeof(*p)); if ( p == NULL ) return NULL; p->base.indm = INDEXING_REAX; - /* Decide on sampling interval */ - p->angular_inc = 0.03; /* From Steller (1997) */ - samp = (2.0 * M_PI) / p->angular_inc; + p->angular_inc = deg2rad(1.7); /* From Steller (1997) */ - p->n_dir = samp*samp; - p->directions = malloc(p->n_dir*sizeof(struct dvec)); + /* Reserve memory, over-estimating the number of directions */ + samp = 2.0*M_PI / p->angular_inc; + p->directions = malloc(samp*samp*sizeof(struct dvec)); if ( p == NULL) { free(p); return NULL; } + STATUS("Allocated space for %i directions\n", samp*samp); /* Generate vectors for 1D Fourier transforms */ - for ( ui=0; uin_dir = 0; + for ( th=0.0; thangular_inc ) { - double u, v; - double th, ph; - struct dvec *dir; + double ph, phstep, n_phstep; - u = (double)ui/samp; - v = (double)vi/samp; + n_phstep = 2.0*M_PI*sin(th)/p->angular_inc; + n_phstep = nearbyint(n_phstep); + phstep = 2.0*M_PI/n_phstep; - /* Uniform sampling of a hemisphere */ - th = 2.0 * M_PI * u; /* "Longitude" */ - ph = acos(v); /* "Latitude" */ + for ( ph=0.0; ph<2.0*M_PI; ph+=phstep ) { - dir = &p->directions[ui + vi*samp]; + struct dvec *dir; - dir->x = cos(th) * sin(ph); - dir->y = sin(th) * sin(ph); - dir->z = cos(ph); + assert(p->n_dirdirections[p->n_dir++]; + + dir->x = cos(ph) * sin(th); + dir->y = sin(ph) * sin(th); + dir->z = cos(th); + + } } - } + STATUS("Generated %i directions (angular increment %.3f deg)\n", + p->n_dir, rad2deg(p->angular_inc)); p->nel = 1024; -- cgit v1.2.3