aboutsummaryrefslogtreecommitdiff
path: root/src/displaywindow.c
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-10-23 16:12:29 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-10-23 16:12:29 +0000
commit6f1015eee069822dd30578c89038dc567564a82f (patch)
treee9c57036174ef42ffa7ca886737c59404cc4796c /src/displaywindow.c
parentb7ba021860c13552972efed75d051f271f025505 (diff)
Implement indexing lines (don't work as well as I'd imagined)
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@169 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/displaywindow.c')
-rw-r--r--src/displaywindow.c115
1 files changed, 111 insertions, 4 deletions
diff --git a/src/displaywindow.c b/src/displaywindow.c
index fa3e5ba..bcbeece 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -184,7 +184,7 @@ static gint displaywindow_gl_motion_notify(GtkWidget *widget, GdkEventMotion *ev
} \
glPopMatrix();
-static void displaywindow_gl_create_list(DisplayWindow *dw) {
+static void displaywindow_gl_prepare(DisplayWindow *dw) {
GLfloat bblue[] = { 0.0, 0.0, 1.0, 1.0 };
GLfloat blue[] = { 0.0, 0.0, 0.5, 1.0 };
@@ -316,6 +316,71 @@ static void displaywindow_gl_create_list(DisplayWindow *dw) {
}
}
+ /* Indexing lines */
+ if ( ctx->cell && dw->lines ) {
+
+ int max_ind;
+ signed int h, k, l;
+
+ max_ind = 2;
+ dw->gl_line_num_vertices = 3*2*((2*max_ind+1)*(2*max_ind+1));
+
+ if ( dw->gl_use_buffers ) {
+ glGenBuffersARB(1, &dw->gl_line_vertex_buffer);
+ }
+ reflection = ctx->reflectionlist->reflections;
+ vertices = malloc(3*dw->gl_line_num_vertices*sizeof(GLfloat));
+
+ /* Lines parallel to a */
+ for ( k=-max_ind; k<=max_ind; k++ ) {
+ for ( l=-max_ind; l<=max_ind; l++ ) {
+ vertices[3*i + 0] = (ctx->cell->a.x*(-max_ind) + ctx->cell->b.x*k + ctx->cell->c.x*l)/1e9;
+ vertices[3*i + 1] = (ctx->cell->a.y*(-max_ind) + ctx->cell->b.y*k + ctx->cell->c.y*l)/1e9;
+ vertices[3*i + 2] = (ctx->cell->a.z*(-max_ind) + ctx->cell->b.z*k + ctx->cell->c.z*l)/1e9;
+ i++;
+ vertices[3*i + 0] = (ctx->cell->a.x*(max_ind) + ctx->cell->b.x*k + ctx->cell->c.x*l)/1e9;
+ vertices[3*i + 1] = (ctx->cell->a.y*(max_ind) + ctx->cell->b.y*k + ctx->cell->c.y*l)/1e9;
+ vertices[3*i + 2] = (ctx->cell->a.z*(max_ind) + ctx->cell->b.z*k + ctx->cell->c.z*l)/1e9;
+ i++;
+ }
+ }
+ /* Lines parallel to b */
+ for ( h=-max_ind; h<=max_ind; h++ ) {
+ for ( l=-max_ind; l<=max_ind; l++ ) {
+ vertices[3*i + 0] = (ctx->cell->a.x*h + ctx->cell->b.x*(-max_ind) + ctx->cell->c.x*l)/1e9;
+ vertices[3*i + 1] = (ctx->cell->a.y*h + ctx->cell->b.y*(-max_ind) + ctx->cell->c.y*l)/1e9;
+ vertices[3*i + 2] = (ctx->cell->a.z*h + ctx->cell->b.z*(-max_ind) + ctx->cell->c.z*l)/1e9;
+ i++;
+ vertices[3*i + 0] = (ctx->cell->a.x*h + ctx->cell->b.x*(max_ind) + ctx->cell->c.x*l)/1e9;
+ vertices[3*i + 1] = (ctx->cell->a.y*h + ctx->cell->b.y*(max_ind) + ctx->cell->c.y*l)/1e9;
+ vertices[3*i + 2] = (ctx->cell->a.z*h + ctx->cell->b.z*(max_ind) + ctx->cell->c.z*l)/1e9;
+ i++;
+ }
+ }
+ /* Lines parallel to c */
+ for ( h=-max_ind; h<=max_ind; h++ ) {
+ for ( k=-max_ind; k<=max_ind; k++ ) {
+ vertices[3*i + 0] = (ctx->cell->a.x*h + ctx->cell->b.x*k + ctx->cell->c.x*(-max_ind))/1e9;
+ vertices[3*i + 1] = (ctx->cell->a.y*h + ctx->cell->b.y*k + ctx->cell->c.y*(-max_ind))/1e9;
+ vertices[3*i + 2] = (ctx->cell->a.z*h + ctx->cell->b.z*k + ctx->cell->c.z*(-max_ind))/1e9;
+ i++;
+ vertices[3*i + 0] = (ctx->cell->a.x*h + ctx->cell->b.x*k + ctx->cell->c.x*(max_ind))/1e9;
+ vertices[3*i + 1] = (ctx->cell->a.y*h + ctx->cell->b.y*k + ctx->cell->c.y*(max_ind))/1e9;
+ vertices[3*i + 2] = (ctx->cell->a.z*h + ctx->cell->b.z*k + ctx->cell->c.z*(max_ind))/1e9;
+ i++;
+ }
+ }
+
+ if ( dw->gl_use_buffers ) {
+ glBindBufferARB(GL_ARRAY_BUFFER, dw->gl_line_vertex_buffer);
+ glBufferDataARB(GL_ARRAY_BUFFER, 3*dw->gl_line_num_vertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
+ free(vertices);
+ } else {
+ dw->gl_line_vertex_array = vertices;
+ }
+
+ }
+
dw->gl_list_id = glGenLists(1);
glNewList(dw->gl_list_id, GL_COMPILE);
@@ -573,6 +638,7 @@ static gint displaywindow_gl_expose(GtkWidget *widget, GdkEventExpose *event, Di
GLfloat light0_specular[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat bg_top[] = { 0.0, 0.2, 0.0, 1.0 };
GLfloat bg_bot[] = { 0.0, 0.0, 0.0, 1.0 };
+ GLfloat grey[] = { 0.6, 0.6, 0.6, 1.0 };
if ( !gdk_gl_drawable_gl_begin(gldrawable, glcontext) ) {
return 0;
@@ -650,6 +716,7 @@ static gint displaywindow_gl_expose(GtkWidget *widget, GdkEventExpose *event, Di
glNormalPointer(GL_FLOAT, 0, dw->gl_ref_normal_array);
glDrawArrays(GL_POINTS, 0, dw->gl_ref_num_vertices);
}
+ glDisableClientState(GL_NORMAL_ARRAY);
glPopClientAttrib();
}
@@ -674,6 +741,7 @@ static gint displaywindow_gl_expose(GtkWidget *widget, GdkEventExpose *event, Di
glNormalPointer(GL_FLOAT, 0, dw->gl_marker_normal_array);
glDrawArrays(GL_QUADS, 0, dw->gl_marker_num_vertices);
}
+ glDisableClientState(GL_NORMAL_ARRAY);
glPopClientAttrib();
}
@@ -698,6 +766,26 @@ static gint displaywindow_gl_expose(GtkWidget *widget, GdkEventExpose *event, Di
glNormalPointer(GL_FLOAT, 0, dw->gl_gen_normal_array);
glDrawArrays(GL_QUADS, 0, dw->gl_gen_num_vertices);
}
+ glDisableClientState(GL_NORMAL_ARRAY);
+ glPopClientAttrib();
+ }
+
+ /* Draw indexing lines */
+ if ( dw->lines && dw->gl_line_num_vertices ) {
+ glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, grey);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, black);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
+ if ( dw->gl_use_buffers ) {
+ glBindBufferARB(GL_ARRAY_BUFFER, dw->gl_line_vertex_buffer);
+ glVertexPointer(3, GL_FLOAT, 0, NULL);
+ glDrawArrays(GL_LINES, 0, dw->gl_line_num_vertices);
+ glBindBufferARB(GL_ARRAY_BUFFER, 0);
+ } else {
+ glVertexPointer(3, GL_FLOAT, 0, dw->gl_line_vertex_array);
+ glDrawArrays(GL_LINES, 0, dw->gl_line_num_vertices);
+ }
glPopClientAttrib();
}
@@ -728,7 +816,7 @@ static gint displaywindow_gl_realise(GtkWidget *widget, DisplayWindow *dw) {
}
displaywindow_gl_set_ortho(dw, w, h);
- displaywindow_gl_create_list(dw);
+ displaywindow_gl_prepare(dw);
gdk_gl_drawable_gl_end(gldrawable);
@@ -777,6 +865,7 @@ static void displaywindow_gl_free_resources(DisplayWindow *dw) {
glDeleteBuffersARB(1, &dw->gl_marker_normal_buffer);
glDeleteBuffersARB(1, &dw->gl_gen_vertex_buffer);
glDeleteBuffersARB(1, &dw->gl_gen_normal_buffer);
+ glDeleteBuffersARB(1, &dw->gl_line_vertex_buffer);
} else {
free(dw->gl_ref_vertex_array);
free(dw->gl_ref_normal_array);
@@ -784,6 +873,7 @@ static void displaywindow_gl_free_resources(DisplayWindow *dw) {
free(dw->gl_marker_normal_array);
free(dw->gl_gen_vertex_array);
free(dw->gl_gen_normal_array);
+ free(dw->gl_line_vertex_array);
}
glDeleteLists(dw->gl_list_id, 1);
@@ -930,6 +1020,20 @@ static gint displaywindow_setaxis_response(GtkWidget *widget, gint response, Dis
}
+static gint displaywindow_setaxis_activate(GtkWidget *widget, DisplayWindow *dw) {
+ return displaywindow_setaxis_response(dw->tiltaxis_window, GTK_RESPONSE_OK, dw);
+}
+
+static gint displaywindow_incraxis(GtkWidget *widget, DisplayWindow *dw) {
+ mapping_adjust_axis(dw->ctx, 0.2);
+ return 0;
+}
+
+static gint displaywindow_decraxis(GtkWidget *widget, DisplayWindow *dw) {
+ mapping_adjust_axis(dw->ctx, -0.2);
+ return 0;
+}
+
static gint displaywindow_setaxis(GtkWidget *widget, DisplayWindow *dw) {
GtkWidget *vbox;
@@ -961,6 +1065,7 @@ static gint displaywindow_setaxis(GtkWidget *widget, DisplayWindow *dw) {
gtk_entry_set_alignment(GTK_ENTRY(dw->tiltaxis_entry), 1);
g_signal_connect(G_OBJECT(dw->tiltaxis_window), "response", G_CALLBACK(displaywindow_setaxis_response), dw);
+ g_signal_connect(G_OBJECT(dw->tiltaxis_entry), "activate", G_CALLBACK(displaywindow_setaxis_activate), dw);
gtk_widget_show_all(dw->tiltaxis_window);
gtk_widget_grab_focus(GTK_WIDGET(dw->tiltaxis_entry));
@@ -973,6 +1078,7 @@ static void displaywindow_addmenubar(DisplayWindow *dw) {
GtkActionEntry entries[] = {
{ "FileAction", NULL, "_File", NULL, NULL, NULL },
+ { "SaveCacheAction", GTK_STOCK_SAVE, "Save Image Analysis to _Cache", NULL, NULL, G_CALLBACK(displaywindow_savecache) },
{ "CloseAction", GTK_STOCK_QUIT, "_Quit", NULL, NULL, G_CALLBACK(displaywindow_close) },
{ "ViewAction", NULL, "_View", NULL, NULL, NULL },
@@ -981,8 +1087,9 @@ static void displaywindow_addmenubar(DisplayWindow *dw) {
{ "DirAxAction", GTK_STOCK_EXECUTE, "Start _DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax) },
{ "StopDirAxAction", GTK_STOCK_CLOSE, "Stop DirAx", NULL, NULL, G_CALLBACK(displaywindow_dirax_stop) },
{ "ReprojectAction", NULL, "_Reproject Diffraction Patterns", NULL, NULL, G_CALLBACK(displaywindow_reproject) },
- { "SaveCacheAction", NULL, "Save Image Analysis to _Cache", NULL, NULL, G_CALLBACK(displaywindow_savecache) },
{ "SetAxisAction", NULL, "Set Tilt Axis Position", NULL, NULL, G_CALLBACK(displaywindow_setaxis) },
+ { "IncrAxisAction", NULL, "Decrease Tilt Axis Position", "<Ctrl>Up", NULL, G_CALLBACK(displaywindow_incraxis) },
+ { "DecrAxisAction", NULL, "Increase Tilt Axis Position", "<Ctrl>Down", NULL, G_CALLBACK(displaywindow_decraxis) },
{ "HelpAction", NULL, "_Help", NULL, NULL, NULL },
{ "AboutAction", GTK_STOCK_ABOUT, "_About DTR...", NULL, NULL, G_CALLBACK(displaywindow_about) },
@@ -1090,7 +1197,7 @@ DisplayWindow *displaywindow_open(ControlContext *ctx) {
void displaywindow_update(DisplayWindow *dw) {
displaywindow_gl_free_resources(dw);
- displaywindow_gl_create_list(dw);
+ displaywindow_gl_prepare(dw);
gdk_window_invalidate_rect(dw->drawing_area->window, &dw->drawing_area->allocation, FALSE);
}