From octave-sources-request at bevo dot che dot wisc dot edu Wed Sep 1 13:01:53 1999 Subject: Matlab equivalent of pcolor From: jean-Marc Valin To: octave-sources at bevo dot che dot wisc dot edu, octave-graphics@bevo.che.wisc.edu Date: Wed, 01 Sep 1999 13:59:44 -0400 This is a multi-part message in MIME format. --Boundary_(ID_ZXfpHeF33LXSwDe0Sxr+jg) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit Here (in attachment) is a function that works like Matlab "pcolor" function. It calls (using popen2) a C executable. To compile pcolor.c, you need OpenGL (or Mesa): gcc -O2 -D_REENTRANT -o pcolor pcolor.c -L/usr/X11R6/lib -lMesaGL -lX11 -lXi -lpthread -lm Also, tell me is you have any problem with the octave wrapper. Jean-Marc Valin -- Jean-Marc Valin Universite de Sherbrooke - Genie Electrique valj01 at gel dot usherb dot ca --Boundary_(ID_ZXfpHeF33LXSwDe0Sxr+jg) Content-type: text/plain; name=pcolor.c; charset=us-ascii Content-disposition: inline; filename=pcolor.c Content-transfer-encoding: 7bit // Copyright (C) 1999 Jean-Marc Valin // modified from the 'glxdemo' sample Mesa program by Brian Paul // // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this file. If not, write to the Free Software Foundation, // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include #include #include #include #include /*#define redraw_funct redraw_interp*/ static int *table; static float RGBMap[256][3]; int sizeX, sizeY; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; Window win; Display *dpy; pthread_t thread; int exit_on_pipe_close; void (*redraw_funct) ( Display *dpy, Window w); void SetColor(int c) { glColor3fv(RGBMap[c]); //glColor3f(RGBMap[c][0],RGBMap[c][1],RGBMap[c][2]); } void SetColorScale (int color) { int i; pthread_mutex_lock (&mutex); if (color) { /* generate colorscale in color */ for (i=0;i<64;i++) { RGBMap[i][0]=0.0; RGBMap[i][1]=i/64.0; RGBMap[i][2]=1.0; } for (i=64;i<128;i++) { RGBMap[i][0]=0.0; RGBMap[i][1]=1; RGBMap[i][2]=1-(i-64)/64.0; } for (i=128;i<184;i++) { RGBMap[i][0]=(i-128)/64.0; RGBMap[i][1]=1.0; RGBMap[i][2]=0; } for (i=184;i<256;i++) { RGBMap[i][0]=1; RGBMap[i][1]=(1-(i-184)/64.0); RGBMap[i][2]=0; } } else { /* generate colorscale in black and white */ for (i=0;i<256;i++) RGBMap[i][0]=RGBMap[i][1]=RGBMap[i][2]=1.0-i/255.0; } pthread_mutex_unlock (&mutex); } /* Drawing routine for interpolation shading */ static void redraw_interp( Display *dpy, Window w ) { int width, height; int i,j; float top, bot, left, right; pthread_mutex_lock (&mutex); glClear( GL_COLOR_BUFFER_BIT ); for (i=0;ivisual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow( dpy, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr ); ctx = glXCreateContext( dpy, visinfo, NULL, True ); glXMakeCurrent( dpy, win, ctx ); return win; } static void event_loop( Display *dpy ) { XEvent event; while (1) { XNextEvent( dpy, &event ); switch (event.type) { case Expose: redraw_funct( dpy, event.xany.window ); break; case ConfigureNotify: resize( event.xconfigure.width, event.xconfigure.height ); break; } } } void change_data(void) { int i,j; int sx, sy; float *table_float; int *table_int; float ratio, min=FLT_MAX, max=-FLT_MAX; scanf ("%d %d",&sx, &sy); /*printf ("%d %d\n",sx, sy);*/ table_float = malloc (sx*sy*sizeof(float)); table_int = malloc (sx*sy*sizeof(int)); for (i=0;i max) max = tmp; if (tmp < min) min = tmp; table_float[i*sy+j] = tmp; } ratio = 254.99/(max-min); for (i=0;i function pcolor(x) global pcolor_pipe; global pcolor_pid; if !exist("pcolor_pipe") pcolor_pipe=0; end if (pcolor_pipe == 0) [pcolor_pipe,dummy,pcolor_pid] = popen2 ("pcolor",""); else [PID, MSG] = waitpid (pcolor_pid, 1); #printf ("received PID %d, MSG %s, pid=%d\n", PID, MSG, pcolor_pid); if (PID < 0) [pcolor_pipe,dummy,pcolor_pid] = popen2 ("pcolor",""); end end #fprintf (pcolor_pipe, "COLORSCALE BW\n"); fprintf (pcolor_pipe, "DATA\n"); fprintf (pcolor_pipe, "%d %d\n", size(x,1), size(x,2)); fprintf (pcolor_pipe, "%g ", x); fprintf (pcolor_pipe, "\n"); fflush (pcolor_pipe); --Boundary_(ID_ZXfpHeF33LXSwDe0Sxr+jg)--