vsurf3d.C

Go to the documentation of this file.
00001 /* Gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
00006  *
00007  * Authors: Percy Zahl <zahl@users.sf.net>
00008  * additional features: Andreas Klust <klust@users.sf.net>
00009  * WWW Home: http://gxsm.sf.net
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00024  */
00025 
00026 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00027 
00028 #include <locale.h>
00029 #include <libintl.h>
00030 
00031 
00032 #include "gnome-res.h"
00033 
00034 #include "view.h"
00035 #include "mem2d.h"
00036 #include "xsmmasks.h"
00037 #include "glbvars.h"
00038 
00039 #include "bench.h"
00040 #include "util.h"
00041 
00042 #include "app_v3dcontrol.h"
00043 
00044 #include <GL/glx.h>
00045 #include <glib.h>
00046 #include <gnome.h>
00047 #include <gdk/gdkkeysyms.h>
00048 #include <gtk/gtkgl.h>
00049 #include <GL/gl.h>
00050 
00051 #include "trackball.h"
00052 
00053 #include "action_id.h"
00054 
00055 #include "vsurf3d_pref.C"
00056 
00057 
00058 // not yet done
00059 #undef __ALTIVEC__
00060 
00061 #ifdef __ALTIVEC__
00062 #include <altivec.h> /* it's here: /usr/lib/gcc-lib/powerpc-linux/3.3.1/include/altivec.h */
00063 #endif
00064 
00065 #define ZRANGE_MAPPED 4096
00066 
00067 // some vector utilities
00068 
00069 #ifdef __ALTIVEC__
00070 void copyvec3 (float4 &u, float4 &v){ u=v; }
00071 #else
00072 void copyvec3 (GLfloat u[3], GLfloat v[3]){
00073         for (int i=0; i<3; ++i)
00074                 u[i] = v[i];
00075 }
00076 #endif
00077 
00078 #ifdef __ALTIVEC__
00079 void copyvec4 (float4 *u, float4 *v){ *u = *v; }
00080 #else
00081 void copyvec4 (GLfloat u[4], GLfloat v[4]){
00082         for (int i=0; i<4; ++i)
00083                 u[i] = v[i];
00084 }
00085 #endif
00086 
00087 #ifdef __ALTIVEC__
00088 float dotprod (float4 *v1, float4 *v2){
00089         ;
00090 }
00091 #else
00092 GLfloat dotprod (GLfloat v1[3], GLfloat v2[3]){
00093         return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
00094 }
00095 #endif
00096 
00097 #ifdef __ALTIVEC__
00098 inline void addtovec (float4 *u, float4 *v){
00099         u = vec_add_float4 (u, v);
00100 }
00101 #else
00102 void addtovec (GLfloat u[3], GLfloat v[3]){
00103         for (int i=0; i<3; ++i)
00104                 u[i] += v[i];
00105 }
00106 #endif
00107 
00108 #ifdef __ALTIVEC__
00109 #else
00110 void mulvecwf (GLfloat u[3], GLfloat f){
00111         for (int i=0; i<3; ++i)
00112                 u[i] *= f;
00113 }
00114 #endif
00115 
00116 #ifdef __ALTIVEC__
00117 #else
00118 void normcrossprod (GLfloat v1[3], GLfloat v2[3], GLfloat n[3]){
00119         GLfloat d;
00120         n[0] = v1[1]*v2[2] - v1[2]*v2[1];
00121         n[1] = v1[2]*v2[0] - v1[0]*v2[2];
00122         n[2] = v1[0]*v2[1] - v1[1]*v2[0];
00123         d = sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);
00124         n[0] /= d;
00125         n[1] /= d;
00126         n[2] /= d;
00127 }
00128 #endif
00129 
00130 #ifdef __ALTIVEC__
00131 #else
00132 void norm3pkte (GLfloat p1[3], GLfloat p2[3], GLfloat p3[3], GLfloat n[3]){
00133         GLfloat v1[3], v2[3];
00134 
00135         v1[0] = p2[0] - p1[0];
00136         v1[1] = p2[1] - p1[1];
00137         v1[2] = p2[2] - p1[2];
00138 
00139         v2[0] = p3[0] - p1[0];
00140         v2[1] = p3[1] - p1[1];
00141         v2[2] = p3[2] - p1[2];
00142 
00143         normcrossprod (v1, v2, n);
00144 }
00145 #endif
00146 
00147 
00148 // v[0][] = vertex for normal to be found
00149 // v[1,2,3,4][] = vertices around
00150 // n[] averaged normal
00151 #ifdef __ALTIVEC__
00152 #else
00153 void avgpolynorm (GLfloat v[5][3], GLfloat n[3]){
00154         GLfloat a[4], as;
00155         GLfloat u[4][3];
00156         GLfloat ni[3];
00157         
00158         n[0]=n[1]=n[2]=0.;
00159 
00160         for (int i=0; i<4; ++i)
00161                 for (int j=0; j<3; ++j)
00162                         u[i][j] = v[i+1][j] - v[0][j];
00163         
00164         as = 0.;
00165         for (int i=0; i<4; ++i)
00166                 as += (a[i] = 1./cos (dotprod (u[i], u[(i+1)%4])));
00167                 
00168         for (int i=0; i<4; ++i){
00169                 normcrossprod (u[i], u[(i+1)%4], ni);
00170                 mulvecwf (ni, a[i]);
00171                 addtovec (n, ni);
00172         }
00173         mulvecwf (n, 1./as);
00174 }
00175 #endif
00176 
00177 
00178 
00179 // ============================== Class Surf3d ==============================
00180 
00181 Surf3d::Surf3d(Scan *sc, int ChNo):View(sc, ChNo){
00182         XSM_DEBUG (DBG_L2, "Surf3d::Surf3d");
00183         v3dcontrol = NULL;
00184         GLvarinit();
00185 }
00186 
00187 Surf3d::Surf3d():View(){
00188         v3dcontrol = NULL;
00189         GLvarinit();
00190 }
00191 
00192 Surf3d::~Surf3d(){
00193         XSM_DEBUG (DBG_L2, "Surf3d::~");
00194         if (v3dControl_pref_dlg)
00195                 gnome_res_destroy (v3dControl_pref_dlg);
00196         hide();
00197         DelSmem();
00198         g_free (v3dControl_pref_def);
00199 }
00200 
00201 void Surf3d::hide(){
00202         if (v3dcontrol)
00203                 delete v3dcontrol;
00204         v3dcontrol = NULL;
00205         XSM_DEBUG (DBG_L2, "Surf3d::hide");
00206 }
00207 
00208 void inline Surf3d::PutPointMode(int k, int j){
00209         int i;
00210         GLfloat val;
00211         i = (k/QuenchFac) + (j/QuenchFac)*XPM_x;
00212         if (i >= (int)size) return;
00213 
00214         surface[i] = (GLfloat)(mem2d->GetDataVMode (k,j));
00215 
00216         if (GLv_data.ColorSrc[0] != 'U'){
00217                 switch (GLv_data.ColorSrc[0]){
00218                 case 'H': 
00219                         val = (GLfloat) (GLv_data.ColorOffset + GLv_data.ColorContrast * surface[i]/ZRANGE_MAPPED);
00220                         break;
00221                 case 'X': 
00222                         if (mem2d_x){
00223                                 // map to index range of Chan-X, assumes scan range is the same.
00224                                 int u = (int) (k * (double)mem2d_x->GetNx () / (double)mem2d->GetNx ());
00225                                 int v = (int) (j * (double)mem2d_x->GetNy () / (double)mem2d->GetNy ());
00226                                 val = (GLfloat) (GLv_data.ColorOffset + 
00227                                                  GLv_data.ColorContrast * mem2d_x->GetDataVMode (u,v)/mem2d_x->GetDataRange ());
00228                         } else
00229                                 val = 1.;
00230                         break;
00231                 default: 
00232                         val = 1.; 
00233                         break;
00234                 }
00235 
00236                 switch (GLv_data.ColorMode[0]){
00237                 case 'T': // Terrain Color
00238                         calccolor(val, surfacecolor[i]);
00239                         break;
00240                 case 'M': // Material Color
00241                         surfacecolor[i][0] = GLv_data.surf_mat_color[0];
00242                         surfacecolor[i][1] = GLv_data.surf_mat_color[1];
00243                         surfacecolor[i][2] = GLv_data.surf_mat_color[2];
00244                         break;
00245                 case 'P': // Palette, ToDo
00246                         int ci = (int)(val*1024);
00247                         ci = ci < 0 ? 0 : ci >= 1024 ? 1023 : ci;
00248                         surfacecolor[i][0] = ColorLookup[ci][0];
00249                         surfacecolor[i][1] = ColorLookup[ci][1];
00250                         surfacecolor[i][2] = ColorLookup[ci][2];
00251                         break;
00252                 }  
00253                 surfacecolor[i][0] *= GLv_data.ColorSat;
00254                 surfacecolor[i][1] *= GLv_data.ColorSat;
00255                 surfacecolor[i][2] *= GLv_data.ColorSat;
00256         }
00257                 
00258         surface[i] *= GLv_data.hskl/64.;
00259         surface[i] /= QuenchFac;
00260 }
00261 
00262 
00263 void Surf3d::GLvarinit(){
00264         mem2d_x=NULL;
00265         
00266         glZeroFrameList=0; 
00267         glSurfaceList=1; 
00268         glSurfaceListRange=0;
00269         
00270         XPM_x = XPM_y = 0;
00271         scrwidth=300;
00272         ZoomFac=1;
00273         
00274         size=0L;
00275         valid=0;
00276 
00277         GL_realized = FALSE;
00278         
00279         surface=NULL;
00280         surfacecolor=NULL;
00281 
00282 // create preferences table from static table and replace pointers to
00283 // functions with callbacks of this instance
00284         GnomeResEntryInfoType *res = v3dControl_pref_def_const;
00285         int n;
00286         for (n=0; res->type != GNOME_RES_LAST; ++res, ++n); 
00287         ++n; // include last!
00288 
00289         v3dControl_pref_def = g_new (GnomeResEntryInfoType, n);
00290 
00291         res = v3dControl_pref_def_const;
00292         GnomeResEntryInfoType *rescopy = v3dControl_pref_def;
00293         for (; res->type != GNOME_RES_LAST; ++res, ++rescopy){
00294                 memcpy (rescopy, res, sizeof (GnomeResEntryInfoType));
00295                 rescopy->var = (void*)((long)res->var + (long)(&GLv_data));
00296                 rescopy->changed_callback = GLupdate;
00297                 rescopy->moreinfo = (gpointer) this;
00298         }
00299         memcpy (rescopy, res, sizeof (GnomeResEntryInfoType)); // do last!
00300 
00301         // read user values or make defaults if not present
00302         v3dControl_pref_dlg = gnome_res_preferences_new (v3dControl_pref_def);
00303         gnome_res_set_apply_callback (v3dControl_pref_dlg, GLupdate, (gpointer)this);
00304         gnome_res_set_destroy_on_close (v3dControl_pref_dlg, FALSE);
00305         gnome_res_read_user_config (v3dControl_pref_dlg);
00306         
00307         ReadPalette (xsmres.Palette);
00308 }
00309 
00310 void Surf3d::GLupdate (void* data){
00311         Surf3d *s = (Surf3d *) data;
00312         s->ColorSrc();
00313         s->reshape(s->v3dcontrol->GetGlarea(), NULL); 
00314         if (s->v3dcontrol)
00315                 gtk_widget_queue_draw (s->v3dcontrol->GetGlarea());
00316 }
00317 
00318 
00319 int Surf3d::GetSmem(){ 
00320         if (surface) DelSmem();
00321 
00322         QuenchFac = 1 + (int) ((double) mem2d->GetNx () / (double) scrwidth
00323                                * 4. * GLv_data.preV);
00324 
00325         if (v3dcontrol){
00326                 gchar *titel = g_strdup_printf ("MesaGL: Ch%d: %s Q%d %s", 
00327                                                 ChanNo+1, data->ui.name, 
00328                                                 QuenchFac, mem2d->GetEname());
00329                 
00330                 v3dcontrol->SetTitle(titel);
00331                 g_free(titel);
00332         }
00333 
00334         XPM_x = mem2d->GetNx()/QuenchFac;
00335         XPM_y = mem2d->GetNy()/QuenchFac;
00336 
00337         size = XPM_x * XPM_y;
00338 
00339         surface = new GLfloat[size];
00340         if(!surface) { XSM_SHOW_MESSAGES(ERR_NOMEM); DelSmem(); return -1; }
00341 
00342         surfacecolor = new GLfloat*[size];
00343         if(!surfacecolor) { XSM_SHOW_MESSAGES(ERR_NOMEM); DelSmem(); return -1; }
00344         for(int i=0; i<(int)size; i++){
00345                 surfacecolor[i] = new GLfloat[3];
00346                 if(!surfacecolor[i]) { 
00347                         XSM_SHOW_MESSAGES(ERR_NOMEM); 
00348                         DelSmem(); 
00349                         return -1;
00350                 }
00351         }
00352 
00353         setup_data_transformation();
00354 
00355         for(int j=0; j<mem2d->GetNy(); j+=QuenchFac)
00356                 for(int k=0; k<mem2d->GetNx(); k+=QuenchFac)
00357                         PutPointMode(k,j);
00358 
00359         valid=2; // force GL lists to refresh
00360         if (v3dcontrol)
00361                 gtk_widget_queue_draw (v3dcontrol->GetGlarea());
00362 
00363         return 0;
00364 }
00365 
00366 int Surf3d::DelSmem(){ 
00367         valid = 0;
00368 
00369         if (surface)
00370                 delete [] surface;
00371         surface = NULL;
00372         
00373         for (int i=0; i<(int)size; i++){
00374                 if (surfacecolor[i])
00375                         delete surfacecolor[i];
00376         }
00377         delete [] surfacecolor;
00378         surfacecolor = NULL;
00379 
00380         size = 0L;
00381 
00382         return 0;
00383 }
00384 
00385 gboolean Surf3d::reshape(GtkWidget *widget, GdkEventConfigure *event){
00386         XSM_DEBUG (DBG_L2, "** SURF3D:::RESHAPE"); 
00387 
00388         GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
00389         GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);
00390         // OpenGL BEGIN
00391         if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
00392                 return FALSE;
00393 
00394 
00395         glViewport (0,0, scrwidth=widget->allocation.width, scrheight=widget->allocation.height);
00396         
00397         glMatrixMode (GL_PROJECTION);
00398         glLoadIdentity ();
00399         gluPerspective (GLv_data.fov, /* field of view in degree */
00400                         ((GLfloat)scrwidth/(GLfloat)scrheight), /* aspect ratio */
00401                         GLv_data.Znear, /* Z near */
00402                         XPM_x*GLv_data.Zfar); /* Z far */
00403         glMatrixMode (GL_MODELVIEW);
00404         glLoadIdentity ();
00405 
00406         glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00407 
00408         gdk_gl_drawable_gl_end (gldrawable);
00409         // OpenGL END
00410         
00411         GetSmem ();
00412 
00413         return TRUE;
00414 }
00415 
00416 void Surf3d::printstring(void *font, char *string)
00417 {
00418 //      int len,i;
00419 //      len = (int)strlen(string);
00420 //      for(i=0; i<len; i++)
00421 //              glutBitmapCharacter(font,string[i]);
00422 }
00423 
00424 void Surf3d::RotateAbs(int n, double phi){
00425         GLv_data.rot[n] = phi;
00426         if (v3dcontrol)
00427                 gtk_widget_queue_draw (v3dcontrol->GetGlarea());
00428 }
00429 
00430 void Surf3d::Rotate(int n, double dphi){
00431         if(n>2){
00432                 GLv_data.rot[1] += dphi;
00433                 GLv_data.rot[2] += dphi;
00434         }
00435         else
00436                 GLv_data.rot[n] += dphi;
00437 }
00438 
00439 double Surf3d::RotateX(double dphi){
00440         GLv_data.rot[0] += 5*dphi;
00441         if (v3dcontrol)
00442                 gtk_widget_queue_draw (v3dcontrol->GetGlarea());
00443         return GLv_data.rot[0];
00444 }
00445 
00446 double Surf3d::RotateY(double dphi){
00447         GLv_data.rot[1] += 5*dphi;
00448         if (v3dcontrol)
00449                 gtk_widget_queue_draw (v3dcontrol->GetGlarea());
00450         return GLv_data.rot[1];
00451 }
00452 
00453 double Surf3d::RotateZ(double dphi){
00454         GLv_data.rot[2] += 5*dphi;
00455         if (v3dcontrol)
00456                 gtk_widget_queue_draw (v3dcontrol->GetGlarea());
00457         return GLv_data.rot[2];
00458 }
00459 
00460 void Surf3d::Translate(int n, double delta){ GLv_data.trans[n] += delta; }
00461 
00462 double Surf3d::Zoom(double x){ 
00463         GLv_data.dist += 0.1*x; 
00464         if (v3dcontrol)
00465                 gtk_widget_queue_draw (v3dcontrol->GetGlarea());
00466         return GLv_data.dist; 
00467 }
00468 
00469 double Surf3d::HeightSkl(double x){ 
00470         GLv_data.hskl += 0.1*x; 
00471         draw(); 
00472         return GLv_data.hskl; 
00473 }
00474 
00475 void Surf3d::ColorSrc(){
00476         mem2d_x=NULL;
00477         switch (GLv_data.ColorSrc[0]){
00478         case 'U': // Uniform Coloring
00479                 draw();
00480                 break;
00481         case 'X':  // from Channel X
00482                 int ChSrc2;
00483                 if ((ChSrc2=gapp->xsm->FindChan (ID_CH_M_X))>=0){
00484                         if(gapp->xsm->scan[ChSrc2]){
00485                                 mem2d_x = gapp->xsm->scan[ChSrc2]->mem2d;
00486                                 draw (); // automatically maps to chan-x index range, assumes same size - user should know...
00487                         }else{ XSM_SHOW_ALERT(ERR_SORRY, ERR_NO2SRC, HINT_MAKESRC2,1); }
00488                 }else{ XSM_SHOW_ALERT(ERR_SORRY, ERR_NO2SRC, HINT_MAKESRC2,1); }
00489                 break;
00490         case 'H': // from Height
00491                 draw();
00492                 break;
00493         }  
00494 }
00495 
00496 void Surf3d::GLModes(int n, int m){
00497         switch(n){
00498         case ID_GL_nZP: 
00499                 GLv_data.ZeroPlane=m?1:0; break;
00500         case ID_GL_Mesh: 
00501                 GLv_data.Mesh=m?1:0; break;
00502         case ID_GL_Ticks: 
00503                 GLv_data.Ticks=m?1:0; break;
00504         case ID_GL_Cull: 
00505                 GLv_data.Cull=m?1:0; break;
00506         case ID_GL_Smooth: 
00507                 GLv_data.Smooth=m?1:0; break;
00508         }  
00509         if (v3dcontrol)
00510                 gtk_widget_queue_draw (v3dcontrol->GetGlarea());
00511 }
00512 
00513 
00514 void Surf3d::ReadPalette(char *name){
00515         if (name){
00516                 std::ifstream cpal;
00517                 char pline[256];
00518                 int nx,ny;
00519                 cpal.open(name, std::ios::in);
00520                 if(cpal.good()){
00521                         cpal.getline(pline, 255);
00522                         cpal.getline(pline, 255);
00523                         cpal >> nx >> ny;
00524                         cpal.getline(pline, 255);
00525                         cpal.getline(pline, 255);
00526                         
00527                         for (int i=0; i<1024; ++i){
00528                                 int r,g,b;
00529                                 cpal >> r >> g >> b;
00530                                 ColorLookup[i][0] = r/255.;
00531                                 ColorLookup[i][1] = g/255.;
00532                                 ColorLookup[i][2] = b/255.;
00533                         }
00534                         return;
00535                 }
00536         }
00537         // default grey and fallback mode:
00538         for (int i=0; i<1024; ++i)
00539                 ColorLookup[i][0] =
00540                 ColorLookup[i][1] =
00541                 ColorLookup[i][2] = i/1024.;
00542 }
00543 
00544 // height in [0..1] expected!
00545 void Surf3d::calccolor(GLfloat height, GLfloat c[3])
00546 {
00547         GLfloat color[4][3]={
00548                 {1.0,1.0,1.0},
00549                 {0.0,0.8,0.0},
00550                 {1.0,1.0,0.3},
00551                 {0.0,0.0,0.8}
00552         };
00553         GLfloat fact;
00554         
00555         if(height>=0.9) {
00556                 c[0]=color[0][0]; c[1]=color[0][1]; c[2]=color[0][2];
00557                 return;
00558         }
00559         
00560         if((height<0.9) && (height>=0.7)) {
00561                 fact=(height-0.7)*5.0;
00562                 c[0]=fact*color[0][0]+(1.0-fact)*color[1][0];
00563                 c[1]=fact*color[0][1]+(1.0-fact)*color[1][1];
00564                 c[2]=fact*color[0][2]+(1.0-fact)*color[1][2];
00565                 return;
00566         }
00567         
00568         if((height<0.7) && (height>=0.6)) {
00569                 fact=(height-0.6)*10.0;
00570                 c[0]=fact*color[1][0]+(1.0-fact)*color[2][0];
00571                 c[1]=fact*color[1][1]+(1.0-fact)*color[2][1];
00572                 c[2]=fact*color[1][2]+(1.0-fact)*color[2][2];
00573                 return;
00574         }
00575         
00576         if((height<0.6) && (height>=0.5)) {
00577                 fact=(height-0.5)*10.0;
00578                 c[0]=fact*color[2][0]+(1.0-fact)*color[3][0];
00579                 c[1]=fact*color[2][1]+(1.0-fact)*color[3][1];
00580                 c[2]=fact*color[2][2]+(1.0-fact)*color[3][2];
00581                 return;
00582         }
00583         
00584         c[0]=color[3][0]; c[1]=color[3][1]; c[2]=color[3][2];
00585 }
00586 
00587 
00588 void Surf3d::setup_data_transformation(){
00589         mem2d->SetDataPktMode (data->display.ViewFlg);
00590         mem2d->SetDataRange (0, ZRANGE_MAPPED);
00591 }
00592 
00593 int Surf3d::update(int y1, int y2){
00594 
00595         setup_data_transformation();
00596 
00597         for(int j=y1; j < y2; j += QuenchFac)
00598                 for(int k=0; k < mem2d->GetNx (); k+=QuenchFac)
00599                         PutPointMode (k,j);
00600         
00601 
00602 //      if ((y2 - y1) == 1)
00603 //              GLdrawscene(y2/QuenchFac);
00604 //      else
00605 //              GLdrawscene(-1, TRUE);
00606 
00607         if (valid){
00608                 valid=2; // force GL lists refresh
00609                 if (v3dcontrol)
00610                         gtk_widget_queue_draw (v3dcontrol->GetGlarea());
00611         }
00612 
00613         return 0;
00614 }
00615 
00616 
00617 #define DrawOneLine(x1,y1,z1,x2,y2,z2) \
00618                     glBegin(GL_LINES);  \
00619                     glVertex3f((x1),(y1),(z1));   glVertex3f((x2),(y2),(z2)); \
00620                     glEnd();
00621 
00622 /* 
00623  * Tickmarks and other stuff....
00624  */
00625 
00626 void Surf3d::GLdrawGimmicks(){
00627         char buf[80];
00628         
00629         // number of pixels = mem2d->GetNx ()
00630         double x1 = mem2d->data->GetXLookup((int)0);
00631         double y1 = mem2d->data->GetYLookup((int)0);
00632         double x2 = mem2d->data->GetXLookup(  mem2d->GetNx()-1);
00633         double y2 = mem2d->data->GetYLookup(  mem2d->GetNy()-1);
00634 
00635         // labels at tips of axis, is only confusing
00636         //glColor4f(0.1,0.1,0.1,.1);
00637         //sprintf(buf,"(%f/%f)", x1, y1);
00638         //glRasterPos3f(-(XPM_x/2.0),0.0,-(XPM_y/2.0)); printstring(GLUT_BITMAP_HELVETICA_12, buf);
00639         //sprintf(buf,"(%f/%f)", x2, y1);
00640         //glRasterPos3f( (XPM_x/2.0),0.0,-(XPM_y/2.0)); printstring(GLUT_BITMAP_HELVETICA_12, buf);
00641         //sprintf(buf,"(%f/%f)", x1, y2);
00642         //glRasterPos3f(-(XPM_x/2.0),0.0, (XPM_y/2.0)); printstring(GLUT_BITMAP_HELVETICA_12, buf);
00643         //sprintf(buf,"(%f/%f)", x2, y2);
00644         //glRasterPos3f( (XPM_x/2.0),0.0, (XPM_y/2.0)); printstring(GLUT_BITMAP_HELVETICA_12, buf);
00645                         
00646         // Variables for label-calculation
00647         double totalsize;
00648         double xt;
00649         double mag;
00650         double onetic;
00651         double offset; 
00652         double firststep; 
00653         double side = 1.0; // default side for labels
00654         GLfloat m[16];
00655         glGetFloatv (GL_MODELVIEW_MATRIX, m);// Need this matrix for label side calcu.
00656                 
00657         int i, stellen;
00658         // X axis
00659         totalsize = (x2-x1);
00660         xt = 0.0;
00661         mag = log10(totalsize);
00662         onetic = pow(10, int(mag));
00663         offset = onetic*floor(x2/onetic); 
00664         firststep =  XPM_x/2.0  - (x2-offset)/totalsize*XPM_x ;
00665         
00666         i = 0;
00667         
00668         if (onetic >= 1)
00669                         stellen = 0;
00670         else
00671                         stellen = abs(int(mag+1));
00672         
00673         if (m[0] < 0) // put labels on other side
00674                 side = -1.0;
00675         
00676         while (offset-i*onetic > x1){
00677                 // There is something badly wrong with x-scaling,
00678                 // When you crop a region, you dont get new offsets.
00679                 sprintf(buf,"x=%.*f",stellen, offset-i*onetic);
00680                 xt = firststep - i*onetic/totalsize*XPM_x;
00681                 glRasterPos3f(xt, 0.0, 1.1*side*XPM_y/2.0); printstring(GLUT_BITMAP_HELVETICA_12, buf);
00682                 DrawOneLine(xt, 0.0, 1.1*(side*XPM_y/2.0), xt, 0.0, (side*XPM_y/2.0));
00683                 i++;
00684         }
00685         
00686         // Y axis
00687         
00688         totalsize = (y1-y2); // y1-y2 is positive.
00689         xt = 0.0;
00690         mag = log10(totalsize);
00691         onetic = pow(10, int(mag));
00692         offset = onetic*floor(y1/onetic); 
00693         firststep = -XPM_y/2.0  + (y1-offset)/totalsize*XPM_y;
00694         i = 0;
00695         
00696         if (onetic >= 1)
00697                         stellen = 0;
00698         else
00699                         stellen = abs(int(mag+1));
00700                 
00701         side = 1.0; // if matrix says so, change sides.
00702         if (m[8] > 0)
00703                 side = -1.0;
00704         
00705         while (offset-i*onetic > y2){
00706                 sprintf(buf,"y=%.*f",stellen, offset-i*onetic);
00707                 xt = firststep + i*onetic/totalsize*XPM_y;
00708                 glRasterPos3f(1.1*side*XPM_x/2.0 ,0.0, xt); printstring(GLUT_BITMAP_HELVETICA_12, buf);
00709                 DrawOneLine(1.1*(side*XPM_x/2.0), 0.0, xt, (side*XPM_x/2.0), 0.0, xt);
00710                 i++;
00711         }
00712         // *** coordinate-axis ***
00713         //glColor4f(0.1,0.1,0.1,.7);
00714         // how long should my z-axis be? Scale with h?
00715         DrawOneLine(-XPM_x/2.0,0.0,-XPM_y/2.0, -XPM_x/2.0,  (GLfloat)(mem2d->GetDataVMode (0,0))/100.0,-XPM_y/2.0);
00716         
00717         // Frame along x-y-Zero.
00718         DrawOneLine(-XPM_x/2.0,0.0,-XPM_y/2.0, (XPM_x/2.0),0.0,-(XPM_y/2.0));
00719         DrawOneLine(-XPM_x/2.0,0.0,-XPM_y/2.0, -(XPM_x/2.0),0.0, (XPM_y/2.0));
00720         DrawOneLine(+XPM_x/2.0,0.0,+XPM_y/2.0, (XPM_x/2.0),0.0,-(XPM_y/2.0));
00721         DrawOneLine(+XPM_x/2.0,0.0,+XPM_y/2.0, -(XPM_x/2.0),0.0, (XPM_y/2.0));
00722 }
00723 
00724 void Surf3d::GLdrawsurface(int y_to_update, int refresh_all){
00725         int x,y,idx;
00726 #ifdef __ALTIVEC__
00727         float x0,y0;
00728         float v[4] __attribute__((aligned(16)));
00729         float n[4] __attribute__((aligned(16)));
00730         float4 v4[5], n4;
00731 #else
00732         GLfloat v[5][3], n[3];
00733 #endif
00734         if (GLv_data.ZeroPlane){
00735                 if (glIsList (glZeroFrameList) && y_to_update == -1 && !refresh_all){
00736                         XSM_DEBUG(DBG_L4, "glCallList..." );
00737                         glCallList (glZeroFrameList);
00738                 }else{
00739                         if (glIsList (glZeroFrameList))
00740                                 glDeleteLists (glZeroFrameList, 1);
00741 
00742                         glZeroFrameList = glGenLists(1);
00743                         glNewList (glZeroFrameList, GL_COMPILE_AND_EXECUTE);
00744 
00745                         XSM_DEBUG(DBG_L4, "NewGLList - Frame" );
00746 
00747                         glBegin (GL_QUAD_STRIP);
00748 
00749                         glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, GLv_data.box_mat_specular);
00750                         glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, GLv_data.box_mat_shininess);
00751                         glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, GLv_data.box_mat_diffuse);
00752                         glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, GLv_data.box_mat_ambient);
00753                         glColor3fv (GLv_data.box_mat_color);
00754 
00755                         glNormal3f (-1.,0.,0.);
00756                         for(x=y=1; y<XPM_y-1; y++){
00757                                 idx = x + y*XPM_x;
00758                                 
00759                                 v[0][0] = x-XPM_x/2;
00760                                 v[0][1] = surface[idx];
00761                                 v[0][2] = y-XPM_y/2;
00762                                 glVertex3fv (v[0]);
00763                         
00764                                 v[0][1] = 0.;
00765                                 glVertex3fv (v[0]);
00766                         }
00767                         
00768                         glNormal3f (0.,0.,1.);
00769                         for(y=XPM_y-2,x=1; x<XPM_x-1; x++){
00770                                 idx = x + y*XPM_x;
00771                                 
00772                                 v[0][0] = x-XPM_x/2;
00773                                 v[0][1] = surface[idx];
00774                                 v[0][2] = y-XPM_y/2;
00775                                 glVertex3fv (v[0]);
00776                                 
00777                                 v[0][1] = 0.;
00778                                 glVertex3fv (v[0]);
00779                         }
00780                         glNormal3f (1.,0.,0.);
00781                         for(x=XPM_x-2, y=XPM_y-2; y>1; y--){
00782                                 idx = x + y*XPM_x;
00783                                 
00784                                 v[0][0] = x-XPM_x/2;
00785                                 v[0][1] = surface[idx];
00786                                 v[0][2] = y-XPM_y/2;
00787                                 glVertex3fv (v[0]);
00788                                 
00789                                 v[0][1] = 0.;
00790                                 glVertex3fv (v[0]);
00791                         }
00792                         
00793                         glNormal3f (0.,0.,-1.);
00794                         for(y=1,x=XPM_x-2; x>1; x--){
00795                                 idx = x + y*XPM_x;
00796                                 
00797                                 v[0][0] = x-XPM_x/2;
00798                                 v[0][1] = surface[idx];
00799                                 v[0][2] = y-XPM_y/2;
00800                                 glVertex3fv (v[0]);
00801                                 
00802                                 v[0][1] = 0.;
00803                                 glVertex3fv (v[0]);
00804                         }
00805                         glEnd();
00806                         
00807                         glBegin(GL_QUADS);
00808                         glNormal3f (0.,-1.,0.);
00809                         glColor4f(0.1,0.7,1.0,0.4);
00810                         glVertex3f(-(XPM_x)/2.0,0.,-(XPM_y)/2.0);
00811                         glVertex3f(-(XPM_x)/2.0,0.,(XPM_y)/2.0);
00812                         glVertex3f((XPM_x)/2.0,0.,(XPM_y)/2.0);
00813                         glVertex3f((XPM_x)/2.0,0.,-(XPM_y)/2.0);
00814                         glEnd();
00815 
00816                         glEndList ();
00817                 }
00818         }
00819 
00820 // <Addi> http://dmawww.epfl.ch:80/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/@Generic__BookTextView/10431
00821 // added glNormal() calculus
00822         if (surface){
00823                 if (!(glIsList (glSurfaceList) && !refresh_all)){
00824                         if (glIsList (glSurfaceList))
00825                                 glDeleteLists (glSurfaceList, glSurfaceListRange);
00826                         glSurfaceList = glGenLists (glSurfaceListRange=XPM_y-2);
00827 //                      XSM_DEBUG(DBG_L2, "NewGLList - Surface" );
00828                 }
00829 // use Shape File?
00830                 int *x1, *x2;
00831                 x1 = new int[XPM_y];
00832                 x2 = new int[XPM_y];
00833                 for (y=0; y<XPM_y; ++y) { x1[y]=1; x2[y]=XPM_x-1; }
00834                 std::ifstream shape;
00835                 shape.open ("shape.xx", std::ios::in);
00836                 if (shape.good ()){
00837                         for (y=0; y<XPM_y && shape.good(); ++y) { 
00838                                 shape >> x1[y] >> x2[y]; 
00839                                 x1[y]/=QuenchFac; x2[y]/=QuenchFac;
00840                         }
00841                 }
00842 
00843                 for (y=1; y<XPM_y-1; y++){
00844                         if (x1[y] < 1 || x2[y] >= XPM_x) continue;
00845 
00846                         if (glIsList (glSurfaceList) && y_to_update != y && !refresh_all)
00847                                 glCallList (glSurfaceList+y-1);
00848                         else{
00849                                 if (glIsList (glSurfaceList+y-1))
00850                                         glDeleteLists (glSurfaceList+y-1, 1);
00851 
00852                                 glNewList (glSurfaceList+y-1, GL_COMPILE_AND_EXECUTE);
00853 
00854                                 glBegin (GL_QUAD_STRIP);
00855                                 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, GLv_data.surf_mat_specular);
00856                                 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, GLv_data.surf_mat_shininess);
00857                                 if (GLv_data.ColorSrc[0] == 'U'){
00858                                         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, GLv_data.surf_mat_diffuse);
00859                                         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, GLv_data.surf_mat_ambient);
00860                                 }
00861 //                              for (x=1; x<XPM_x-1; x++){
00862                                 for (x=x1[y]; x<x2[y]; x++){
00863                                 
00864                                         idx = x + y*XPM_x;
00865                                         
00866 //                                      glTexCoord2f (x,y);
00867                                         if (GLv_data.ColorSrc[0] != 'U')
00868                                                 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, surfacecolor[idx]);
00869 #ifdef __ALTIVEC__
00870                                         v[0] = x0 = x-XPM_x/2;
00871                                         v[1] = surface[idx];
00872                                         v[2] = y0 = y-XPM_y/2;
00873                                         v4[0] = vec_load (v);
00874                                         
00875                                         v[0] = x0+1;
00876                                         v[1] = surface[idx+1];
00877                                         v4[1] = vec_load (v);
00878                                         
00879                                         v[0] = x0;
00880                                         v[1] = surface[idx-XPM_x];
00881                                         v[2] = y0-1;
00882                                         v4[2] = vec_load (v);
00883                                         
00884                                         v[0] = x0-1;
00885                                         v[1] = surface[idx-1];
00886                                         v[2] = y0;
00887                                         v4[3] = vec_load (v);
00888                                         
00889                                         v[0] = x0;
00890                                         v[1] = surface[idx+XPM_x];
00891                                         v[2] = y0+1;
00892                                         v4[4] = vec_load (v);
00893                                         
00894                                         avgpolynorm (v4, n4);
00895                                         vec_store (n, n4);
00896                                         vec_store (v, v[0]);
00897                                         
00898                                         glNormal3fv (n);
00899                                         glVertex3fv (v);
00900 #else
00901                                         v[0][0] = x-XPM_x/2;
00902                                         v[0][1] = surface[idx];
00903                                         v[0][2] = y-XPM_y/2;
00904                                         
00905                                         v[1][0] = v[0][0]+1;
00906                                         v[1][1] = surface[idx+1];
00907                                         v[1][2] = v[0][2];
00908                                         
00909                                         v[2][0] = v[0][0];
00910                                         v[2][1] = surface[idx-XPM_x];
00911                                         v[2][2] = v[0][2]-1;
00912                                         
00913                                         v[3][0] = v[0][0]-1;
00914                                         v[3][1] = surface[idx-1];
00915                                         v[3][2] = v[0][2];
00916                                         
00917                                         v[4][0] = v[0][0];
00918                                         v[4][1] = surface[idx+XPM_x];
00919                                         v[4][2] = v[0][2]+1;
00920                                         
00921                                         avgpolynorm (v, n);
00922                                         
00923                                         glNormal3fv (n);
00924                                         glVertex3fv (v[0]);
00925 #endif
00926                                         
00927                                         // next vertex y+1
00928                                         idx += XPM_x;
00929                                         
00930 //                                      glTexCoord2f (x,y+1);
00931                                         if (GLv_data.ColorSrc[0] != 'U')
00932                                                 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, surfacecolor[idx]);
00933 #ifdef __ALTIVEC__
00934                                         v[0] = x0 = x-XPM_x/2;
00935                                         v[1] = surface[idx];
00936                                         v[2] = y0 = y-XPM_y/2;
00937                                         v4[0] = vec_load (v);
00938                                         
00939                                         v[0] = x0+1;
00940                                         v[1] = surface[idx+1];
00941                                         v4[1] = vec_load (v);
00942                                         
00943                                         v[0] = x0;
00944                                         v[1] = surface[idx-XPM_x];
00945                                         v[2] = y0-1;
00946                                         v4[2] = vec_load (v);
00947                                         
00948                                         v[0] = x0-1;
00949                                         v[1] = surface[idx-1];
00950                                         v[2] = y0;
00951                                         v4[3] = vec_load (v);
00952                                         
00953                                         v[0] = x0;
00954                                         v[1] = surface[idx+XPM_x];
00955                                         v[2] = y0+1;
00956                                         v4[4] = vec_load (v);
00957                                         
00958                                         avgpolynorm (v4, n4);
00959                                         vec_store (n, n4);
00960                                         vec_store (v, v[0]);
00961                                         
00962                                         glNormal3fv (n);
00963                                         glVertex3fv (v);
00964 #else
00965                                         v[0][1] = surface[idx];
00966                                         v[0][2] = y-XPM_y/2+1;
00967                                         
00968                                         v[1][1] = surface[idx+1];
00969                                         v[1][2] = v[0][2];
00970                                         
00971                                         v[2][1] = surface[idx-XPM_x];
00972                                         v[2][2] = v[0][2]-1;
00973                                         
00974                                         v[3][1] = surface[idx-1];
00975                                         v[3][2] = v[0][2];
00976                                         
00977                                         v[4][1] = surface[idx+XPM_x];
00978                                         v[4][2] = v[0][2]+1;
00979                                         
00980                                         avgpolynorm (v, n);
00981                                         
00982                                         glNormal3fv (n);
00983                                         glVertex3fv (v[0]);
00984 #endif
00985                                 }
00986                                 glEnd ();
00987 
00988                                 glEndList ();
00989                         }
00990                 }
00991                 delete [] x2;
00992                 delete [] x1;
00993         }
00994 }
00995 
00996 
00997 /* ::GLdrawscene
00998  * ======================================================================
00999  * (re)draw all: create/recall scene
01000  * - adjust scene settings
01001  * - create transform/rotate matrix
01002  * - draw surface
01003  * - draw extra stuff
01004  * - swap/flush buffer(s) to visual
01005  */
01006 
01007 gboolean Surf3d::GLdrawscene(int y_to_update, int refresh_all){
01008         if(!valid) return FALSE;
01009         if(!v3dcontrol) return FALSE;
01010         
01011         GdkGLContext *glcontext = gtk_widget_get_gl_context (v3dcontrol->GetGlarea());
01012         GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (v3dcontrol->GetGlarea());
01013         // OpenGL BEGIN
01014         if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
01015                 return FALSE;
01016 
01017         glClearDepth (1.0);
01018         glDepthFunc (GL_LEQUAL);
01019         glDisable (GL_BLEND);
01020         glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01021         //      glEnable (GL_NORMALIZE);
01022 #ifdef FX
01023         glHint (GL_FOG_HINT, GL_NICEST);
01024 #endif
01025 
01026 
01027         if(GLv_data.Mesh)
01028                 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
01029         else
01030                 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
01031 
01032         glClearColor (GLv_data.clear_color[0], 
01033                       GLv_data.clear_color[1],  
01034                       GLv_data.clear_color[2],
01035                       GLv_data.clear_color[3]);
01036 
01037         if (GLv_data.Cull)
01038                 glEnable (GL_CULL_FACE);
01039         else
01040                 glDisable (GL_CULL_FACE);
01041 
01042         if (GLv_data.Smooth)
01043                 glShadeModel(GL_SMOOTH);
01044         else
01045                 glShadeModel(GL_FLAT);
01046 
01047         GLfloat light_position[4];
01048         GLenum light_no[3] = { GL_LIGHT0, GL_LIGHT1, GL_LIGHT2 };
01049         for (int i=0; i<3; ++i){
01050                 if ( GLv_data.light[i][1] == 'n' ){ // "On" / "Off" ?
01051                         copyvec4  (light_position, GLv_data.light_position[i]);
01052                         mulvecwf  (light_position, (GLfloat)XPM_x);
01053                         glLightfv (light_no[i], GL_POSITION, light_position);
01054                         glLightfv (light_no[i], GL_AMBIENT,  GLv_data.light_ambient[i]);
01055                         glLightfv (light_no[i], GL_SPECULAR, GLv_data.light_specular[i]);
01056                         glLightfv (light_no[i], GL_DIFFUSE,  GLv_data.light_diffuse[i]);
01057                         glEnable  (light_no[i]);
01058                 }
01059                 else
01060                         glDisable (light_no[i]);
01061         }
01062         glEnable (GL_LIGHTING);
01063         glEnable (GL_DEPTH_TEST);
01064                 
01065         if (GLv_data.Texture)
01066                 glEnable (GL_TEXTURE_2D);
01067         else
01068                 glDisable (GL_TEXTURE_2D);
01069                 
01070         if (GLv_data.Fog){
01071                 glEnable (GL_FOG);
01072                 glFogi (GL_FOG_MODE,GL_EXP2);
01073                 glFogfv (GL_FOG_COLOR, GLv_data.fog_color);
01074                 glFogf (GL_FOG_DENSITY, GLv_data.fog_density/XPM_x);
01075         }
01076         else
01077                 glDisable (GL_FOG);
01078                 
01079         glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
01080                 
01081         glPushMatrix ();
01082                 
01083         float x=XPM_x*GLv_data.dist;
01084         gluLookAt(0., -x, 0., 0., x+1., 0.,  0.0,0.0,1.0);
01085                 
01086         int ox,oy,oz;
01087         ox = (int)(GLv_data.trans[0]*XPM_x/2./100.);
01088         oy = (int)(GLv_data.trans[1]*XPM_y/2./100.);
01089         oz = (int)(GLv_data.trans[2]*(XPM_x+XPM_y)/4./100.);
01090                 
01091         // setup scene in space
01092         
01093         glPushMatrix ();
01094         glTranslatef ((float)ox,(float)oz,(float)oy);
01095         
01096         glRotatef (GLv_data.rot[0], 1.0, 0.0, 0.0);
01097         glRotatef (GLv_data.rot[1], 0.0, 1.0, 0.0);
01098         glRotatef (GLv_data.rot[2], 0.0, 0.0, 1.0);
01099 
01100 
01101         // valid == 1 :  GLlists and data valid
01102         // valid == 2 :  GLliste need to refreshed, data is valid, but changed!
01103 
01104         GLdrawsurface (y_to_update, glSurfaceListRange==0 || valid == 2 ? TRUE:refresh_all);
01105 
01106         if (GLv_data.Ticks)
01107                 GLdrawGimmicks ();
01108 
01109         // data and lists are valid now!
01110         valid = 1;
01111 
01112         glPopMatrix ();
01113         glPopMatrix ();
01114 
01115         /* Swap buffers. */
01116         if (gdk_gl_drawable_is_double_buffered (gldrawable))
01117                 gdk_gl_drawable_swap_buffers (gldrawable);
01118         else
01119                 glFlush ();
01120 
01121         gdk_gl_drawable_gl_end (gldrawable);
01122         // OpenGL END
01123 
01124         return TRUE;
01125 }
01126 
01127 
01128 
01129 // =========== GTK-GL-CALLBACKS =================
01130 // realize :         realize GL object(s)
01131 // configure_event : configure scene: canvas size/aspect changes, etc.
01132 // expose_event :    redraw scene
01133 
01134 static void
01135 realize (GtkWidget *widget,
01136          gpointer   data)
01137 {
01138         XSM_DEBUG (DBG_L2, "GL:::REALIZE"); 
01139         ((Surf3d*)gtk_object_get_data (GTK_OBJECT (widget), "vdata"))->GLdrawscene();
01140         ((Surf3d*)gtk_object_get_data (GTK_OBJECT (widget), "vdata"))->GL_realized = TRUE;
01141 }
01142 
01143 static gboolean
01144 configure_event (GtkWidget         *widget,
01145                  GdkEventConfigure *event,
01146                  gpointer           data)
01147 {
01148         XSM_DEBUG (DBG_L2, "GL:::CONFIGURE-EVENT"); 
01149         ((Surf3d*)gtk_object_get_data (GTK_OBJECT (widget), "vdata"))->reshape(widget, event);
01150         return TRUE;
01151 }
01152 
01153 static gboolean
01154 expose_event (GtkWidget      *widget,
01155               GdkEventExpose *event,
01156               gpointer        data)
01157 {
01158         XSM_DEBUG (DBG_L2, "GL:::EXPOSE-EVENT");
01159         return ((Surf3d*)gtk_object_get_data (GTK_OBJECT (widget), "vdata"))->GLdrawscene();
01160 }
01161 
01162 
01163 // =========================================================================
01164 
01165 
01166 /* -- templates --
01167 static float begin_x = 0.0;
01168 static float begin_y = 0.0;
01169 static float view_quat[4] = { 0.0, 0.0, 0.0, 1.0 };
01170 static float view_scale = 1.0;
01171 
01172 static gboolean
01173 button_press_event (GtkWidget      *widget,
01174                     GdkEventButton *event,
01175                     GtkWidget      *menu)
01176 {
01177   begin_x = event->x;
01178   begin_y = event->y;
01179 
01180   return FALSE;
01181 }
01182 
01183 #define VIEW_SCALE_MAX 2.0
01184 #define VIEW_SCALE_MIN 0.5
01185 
01186 static gboolean
01187 motion_notify_event (GtkWidget      *widget,
01188                      GdkEventMotion *event,
01189                      gpointer        data)
01190 {
01191   float w = widget->allocation.width;
01192   float h = widget->allocation.height;
01193   float x = event->x;
01194   float y = event->y;
01195   float d_quat[4];
01196   gboolean redraw = FALSE;
01197 
01198   // Rotation.
01199   if (event->state & GDK_BUTTON1_MASK)
01200     {
01201       trackball (d_quat,
01202                  (2.0 * begin_x - w) / w,
01203                  (h - 2.0 * begin_y) / h,
01204                  (2.0 * x - w) / w,
01205                  (h - 2.0 * y) / h);
01206       add_quats (d_quat, view_quat, view_quat);
01207       redraw = TRUE;
01208     }
01209 
01210   // Scaling.
01211   if (event->state & GDK_BUTTON2_MASK)
01212     {
01213       view_scale = view_scale * (1.0 + (y - begin_y) / h);
01214       if (view_scale > VIEW_SCALE_MAX)
01215         view_scale = VIEW_SCALE_MAX;
01216       else if (view_scale < VIEW_SCALE_MIN)
01217         view_scale = VIEW_SCALE_MIN;
01218       redraw = TRUE;
01219     }
01220 
01221   begin_x = x;
01222   begin_y = y;
01223 
01224   if (redraw)
01225     gtk_widget_queue_draw (widget);
01226 
01227   return TRUE;
01228 }
01229 
01230 static gboolean
01231 key_press_event (GtkWidget   *widget,
01232                  GdkEventKey *event,
01233                  gpointer     data)
01234 {
01235   switch (event->keyval)
01236     {
01237     default:
01238       return TRUE;
01239     }
01240 
01241   return TRUE;
01242 }
01243 */
01244 
01245 int Surf3d::draw(int zoomoverride){
01246 
01247         XSM_DEBUG (DBG_L2, "SURF3D:::DRAW");
01248 
01249         if (!mem2d) { 
01250                 XSM_DEBUG (DBG_L2, "Surf3d: no mem2d !"); 
01251                 return 1; 
01252         }
01253         
01254         if ( !v3dcontrol )
01255                 v3dcontrol = new V3dControl ("3D GL-View", ChanNo, scan,
01256                                              G_CALLBACK (realize),
01257                                              G_CALLBACK (configure_event),
01258                                              G_CALLBACK (expose_event),
01259                                              this);
01260 
01261         if (GL_realized)
01262                 gtk_widget_queue_draw (v3dcontrol->GetGlarea());
01263               
01264         XSM_DEBUG (DBG_L5, "SURF3D:::DRAW, realized=" << GL_realized);
01265         
01266         return 0;
01267 }
01268 
01269 void Surf3d::preferences(){
01270         if (v3dControl_pref_dlg)
01271                 gnome_res_run_change_user_config (v3dControl_pref_dlg, "GL Scene Setup");
01272 }

Generated on Sat Apr 1 09:04:06 2006 for GXSM by  doxygen 1.4.6