Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

plot_strip.c File Reference

#include "coxplot.h"
#include <math.h>

Go to the source code of this file.


Defines

#define WAY_BIG   1.e+10
#define NCLR   4
#define STGOOD(s)   ( (s) != NULL && (s)[0] != '\0' )
#define THIK   0.003
#define SY   0.07

Functions

float p10 (float x)
MEM_topshell_dataplot_strip_init (Display *dpy, int nx, float dx, int ny, float ybot, float ytop, char *lab_xxx, char *lab_yyy, char *lab_top, char **nam_yyy, void_func *killfunc)
void plot_strip_addto (MEM_topshell_data *mp, int nadd, float **y)
void plot_strip_clear (MEM_topshell_data *mp)

Variables

float ccc [NCLR][3]

Define Documentation

#define NCLR   4
 

Definition at line 11 of file plot_strip.c.

Referenced by plot_strip_addto(), and plot_strip_init().

#define STGOOD      ( (s) != NULL && (s)[0] != '\0' )
 

Definition at line 19 of file plot_strip.c.

#define SY   0.07
 

Definition at line 22 of file plot_strip.c.

Referenced by flip_xy(), flip_yz(), plot_strip_addto(), and plot_strip_init().

#define THIK   0.003
 

Definition at line 21 of file plot_strip.c.

Referenced by plot_strip_addto(), and plot_strip_init().

#define WAY_BIG   1.e+10
 

Definition at line 5 of file plot_strip.c.

Referenced by plot_strip_addto().


Function Documentation

float p10 float    x [static]
 

Definition at line 30 of file plot_strip.c.

00031 {
00032    double y ;
00033 
00034    if( x == 0.0 ) return 0.0 ;
00035    if( x <  0.0 ) x = -x ;
00036    y = floor(log10(x)+0.000001) ; y = pow( 10.0 , y ) ;
00037    return (float) y ;
00038 }

void plot_strip_addto MEM_topshell_data   mp,
int    nadd,
float **    y
 

Definition at line 229 of file plot_strip.c.

References ADDTO_MEMPLOT, ccc, insert_at_memplot(), MEMPLOT_IDENT, mp, MEM_topshell_data::mp, NCLR, plotpak_line(), plotpak_set(), redraw_topshell(), set_active_memplot(), set_color_memplot(), set_thick_memplot(), SY, THIK, MEM_topshell_data::userdata, MEM_topshell_data::valid, and WAY_BIG.

Referenced by AFNI_drive_addto_graph_1D().

00230 {
00231    int ii , jj , yall , start , xx , nx , ny ;
00232    float pbot,ptop , xobot,xotop,yobot,yotop , yll,yhh ;
00233    float xbot,xtop , ybot,ytop ;
00234    float dxx , dyy ;
00235    float * ud ;
00236    MEM_plotdata *mplot ;
00237 
00238    if( mp == NULL || mp->userdata == NULL ||
00239       !mp->valid  || nadd <= 0            || y == NULL ) return ;
00240 
00241    ud = (float *) mp->userdata ;
00242    xobot = ud[0] ; xotop = ud[1] ; yobot = ud[2] ; yotop = ud[3] ;
00243    xbot  = ud[4] ; xtop  = ud[5] ; ybot  = ud[6] ; ytop  = ud[7] ;
00244    ny    = ud[8] ; yall  = ud[9] ; start = ud[10]; xx    = ud[11];
00245    nx    = xtop  ;
00246 
00247    if( nadd > nx ) nadd = nx ;  /* can't add too many points */
00248 
00249    mplot = mp->mp ;
00250    ii = set_active_memplot( MEMPLOT_IDENT(mplot) ) ;
00251    if( ii != 0 ) return ;
00252 
00253    dxx = 0.01*nx ;
00254 
00255    /* last x-value plotted was at xx */
00256 
00257    if( yall ){  /*-- all in one big happy box --*/
00258 
00259       dyy = 0.01*(ytop-ybot) ;
00260 
00261       plotpak_set( xobot,xotop , yobot,yotop , xbot,xtop , ybot,ytop , 1 ) ;
00262       set_thick_memplot( THIK ) ;
00263 
00264       if( xx >= 0 ){  /* connect to last time in */
00265          for( jj=0 ; jj < ny ; jj++ ){
00266            insert_at_memplot( start + xx + jj*nx , mplot ) ;
00267            if( ud[12+jj] < WAY_BIG && y[jj][0] < WAY_BIG ){
00268              set_color_memplot( ccc[jj%NCLR][0], ccc[jj%NCLR][1], ccc[jj%NCLR][2] ) ;
00269              plotpak_line( xx , ud[12+jj] , xx+1 , y[jj][0] ) ;
00270            } else {
00271              ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00272            }
00273          }
00274          xx++ ; if( xx == nx ) xx = 0 ; /* start plotting at next point */
00275 
00276       } else {        /* only happens 1st time in */
00277          xx = 0 ;
00278       }
00279 
00280       for( ii=1 ; ii < nadd ; ii++ ){
00281          for( jj=0 ; jj < ny ; jj++ ){
00282            insert_at_memplot( start + xx + jj*nx , mplot ) ;
00283            if( y[jj][ii-1] < WAY_BIG && y[jj][ii] < WAY_BIG ){
00284              set_color_memplot( ccc[jj%NCLR][0],ccc[jj%NCLR][1],ccc[jj%NCLR][2] );
00285              plotpak_line( xx , y[jj][ii-1] , xx+1 , y[jj][ii] ) ;
00286            } else {
00287              ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00288            }
00289          }
00290          xx++ ; if( xx == nx ) xx = 0 ;
00291       }
00292 
00293       /* 16 Nov 2001: add X at the end */
00294 
00295       set_thick_memplot( 2*THIK ) ;
00296 
00297       ii = nadd-1 ;
00298       for( jj=0 ; jj < ny ; jj++ ){
00299         if( y[jj][ii] < WAY_BIG ){
00300           set_color_memplot( ccc[jj%NCLR][0],ccc[jj%NCLR][1],ccc[jj%NCLR][2] );
00301           insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00302           plotpak_line( xx-dxx , y[jj][ii]-dyy , xx+dxx , y[jj][ii]+dyy ) ;
00303           insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00304           plotpak_line( xx-dxx , y[jj][ii]+dyy , xx+dxx , y[jj][ii]-dyy ) ;
00305         } else {
00306           insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00307           ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00308           insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00309           ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00310         }
00311       }
00312 
00313    } else {  /*-- each in its own little sad box --*/
00314 
00315       float dyo = (yotop-yobot) / ( (1.0+SY) * ny - SY ) ;
00316 
00317       dyy = 0.01*(ytop-ybot)*ny ;
00318 
00319       set_thick_memplot( THIK ) ;
00320 
00321       if( xx >= 0 ){  /* connect to last time in */
00322          for( jj=0 ; jj < ny ; jj++ ){
00323            insert_at_memplot( start + xx + jj*nx , mplot ) ;
00324            if( ud[12+jj] < WAY_BIG && y[jj][0] < WAY_BIG ){
00325              yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00326              plotpak_set( xobot,xotop , yll,yhh , xbot,xtop , ybot,ytop , 1 ) ;
00327              set_color_memplot( ccc[jj%NCLR][0], ccc[jj%NCLR][1], ccc[jj%NCLR][2] ) ;
00328              plotpak_line( xx , ud[12+jj] , xx+1 , y[jj][0] ) ;
00329            } else {
00330              ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00331            }
00332          }
00333          xx++ ; if( xx == nx ) xx = 0 ; /* start plotting at next point */
00334 
00335       } else {        /* only happens 1st time in */
00336          xx = 0 ;
00337       }
00338 
00339       for( ii=1 ; ii < nadd ; ii++ ){
00340          for( jj=0 ; jj < ny ; jj++ ){
00341            insert_at_memplot( start + xx + jj*nx , mplot ) ;
00342            if( y[jj][ii-1] < WAY_BIG && y[jj][ii] < WAY_BIG ){
00343              yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00344              plotpak_set( xobot,xotop , yll,yhh , xbot,xtop , ybot,ytop , 1 ) ;
00345              set_color_memplot( ccc[jj%NCLR][0],ccc[jj%NCLR][1],ccc[jj%NCLR][2] );
00346              plotpak_line( xx , y[jj][ii-1] , xx+1 , y[jj][ii] ) ;
00347            } else {
00348              ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00349            }
00350          }
00351          xx++ ; if( xx == nx ) xx = 0 ;
00352       }
00353 
00354       /* 16 Nov 2001: add X at the end */
00355 
00356       set_thick_memplot( 2*THIK ) ;
00357 
00358       ii = nadd-1 ;
00359       for( jj=0 ; jj < ny ; jj++ ){
00360         if( y[jj][ii] < WAY_BIG ){
00361           yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00362           plotpak_set( xobot,xotop , yll,yhh , xbot,xtop , ybot,ytop , 1 ) ;
00363           set_color_memplot( ccc[jj%NCLR][0],ccc[jj%NCLR][1],ccc[jj%NCLR][2] );
00364           insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00365           plotpak_line( xx-dxx , y[jj][ii]-dyy , xx+dxx , y[jj][ii]+dyy ) ;
00366           insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00367           plotpak_line( xx-dxx , y[jj][ii]+dyy , xx+dxx , y[jj][ii]-dyy ) ;
00368         } else {
00369           insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00370           ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00371           insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00372           ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00373         }
00374       }
00375 
00376    }
00377 
00378    /*- reset plot parameters -*/
00379 
00380    insert_at_memplot( -1 , mplot ) ;
00381    set_thick_memplot( 0.0 ) ;
00382    set_color_memplot( 0.0 , 0.0 , 0.0 ) ;
00383 
00384    /*- redisplay the plot (all of it, Frank) -*/
00385 
00386    redraw_topshell( mp ) ;
00387 
00388    /*- save some stuff for next time in -*/
00389 
00390    ud[11] = xx ;                      /* last x index plotted */
00391    for( jj=0 ; jj < ny ; jj++ )       /* last y values plotted */
00392       ud[12+jj] = y[jj][nadd-1] ;
00393 
00394    return ;
00395 }

void plot_strip_clear MEM_topshell_data   mp
 

Definition at line 402 of file plot_strip.c.

References ADDTO_MEMPLOT, insert_at_memplot(), mp, MEM_topshell_data::mp, redraw_topshell(), MEM_topshell_data::userdata, and MEM_topshell_data::valid.

Referenced by AFNI_drive_clear_graph_1D().

00403 {
00404    int ii , jj , start , nx , ny ;
00405    float * ud ;
00406    MEM_plotdata *mplot ;
00407 
00408    if( mp == NULL || mp->userdata == NULL || !mp->valid  ) return ;
00409 
00410    ud = (float *) mp->userdata ;
00411    nx = ud[5] ; ny = ud[8] ; start = ud[10] ;
00412 
00413    mplot = mp->mp ;
00414 
00415    for( jj=0 ; jj < ny ; jj++ ){
00416 
00417      for( ii=0 ; ii < nx ; ii++ ){                      /* clear graph lines */
00418         insert_at_memplot( start + ii + jj*nx , mplot ) ;
00419         ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00420      }
00421                                                         /* clear X */
00422      insert_at_memplot( start + nx*ny + 2*jj , mplot ) ;
00423      ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00424      insert_at_memplot( start + nx*ny + 2*jj+1 , mplot ) ;
00425      ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00426    }
00427 
00428    insert_at_memplot( -1 , mplot ) ;  /* reset to normal insertion */
00429    redraw_topshell( mp ) ;
00430 
00431    ud[11] = -1 ;  /* reset current x index */
00432    return ;
00433 }

MEM_topshell_data* plot_strip_init Display *    dpy,
int    nx,
float    dx,
int    ny,
float    ybot,
float    ytop,
char *    lab_xxx,
char *    lab_yyy,
char *    lab_top,
char **    nam_yyy,
void_func   killfunc
 

Definition at line 45 of file plot_strip.c.

References ADDTO_MEMPLOT, calloc, ccc, create_memplot_surely(), dpy, get_active_memplot(), MEMPLOT_NLINE, memplot_to_topshell(), mp, NCLR, p10(), plotpak_line(), plotpak_periml(), plotpak_perimm(), plotpak_pwritf(), plotpak_set(), plotpak_setlin(), set_color_memplot(), set_thick_memplot(), STGOOD, SY, THIK, and MEM_topshell_data::userdata.

Referenced by AFNI_drive_open_graph_1D().

00051 {
00052    int ii , jj , np , nnax,nnay , mmax,mmay , yall ;
00053    float pbot,ptop , xobot,xotop,yobot,yotop , yll,yhh ;
00054    char str[32] ;
00055    float *ud ;
00056    MEM_topshell_data * mp ;
00057    MEM_plotdata      * mplot ;
00058 
00059    /*-- sanity check --*/
00060 
00061    if( dpy == NULL || ny == 0 || nx < 9 || ybot >= ytop ) return NULL ;
00062 
00063    if( dx <= 0.0 ) dx = 1.0 ;
00064 
00065    yall = (ny > 0) ; if( !yall ) ny = -ny ; if( ny == 1 ) yall = 1 ;
00066 
00067    /*-- data ranges --*/
00068 
00069    ptop = p10(nx) ;
00070    nnax = rint(nx/ptop) ;
00071    if( nnax == 1 ) nnax = 10 ;
00072    mmax = (nnax < 3) ? 10
00073                      : (nnax < 6) ? 5 : 2 ;
00074 
00075    pbot = p10(ybot) ; ptop = p10(ytop) ; if( ptop < pbot ) ptop = pbot ;
00076    nnay = rint((ytop-ybot)/ptop) ;
00077    if( nnay == 1 ) nnay = 10 ;
00078    mmay = (nnay < 3) ? 10
00079                      : (nnay < 6) ? 5 : 2 ;
00080 
00081    /*-- setup to plot --*/
00082 
00083    create_memplot_surely( "Striplot" , 1.3 ) ;
00084    set_color_memplot( 0.0 , 0.0 , 0.0 ) ;
00085    set_thick_memplot( 0.0 ) ;
00086    mplot = get_active_memplot() ;
00087 
00088    /*-- plot labels, if any --*/
00089 
00090    xobot = 0.15 ; xotop = 1.27 ;  /* set objective size of plot */
00091    yobot = 0.1  ; yotop = 0.95 ;
00092 
00093    if( STGOOD(lab_top) ){ yotop -= 0.02 ; yobot -= 0.01 ; }
00094    if( nam_yyy != NULL ){ xotop -= 0.16 ; xobot -= 0.02 ; }
00095 
00096    /* x-axis label? */
00097 
00098    if( STGOOD(lab_xxx) )
00099       plotpak_pwritf( 0.5*(xobot+xotop) , yobot-0.06 , lab_xxx , 16 , 0 , 0 ) ;
00100 
00101    /* y-axis label? */
00102 
00103    if( STGOOD(lab_yyy) )
00104       plotpak_pwritf( xobot-0.10 , 0.5*(yobot+yotop) , lab_yyy , 16 , 90 , 0 ) ;
00105 
00106    /* label at top? */
00107 
00108    if( STGOOD(lab_top) )
00109       plotpak_pwritf( xobot+0.01 , yotop+0.01 , lab_top , 18 , 0 , -2 ) ;
00110 
00111    /*-- plot all on same vertical scale --*/
00112 
00113    if( yall ){
00114 
00115       /* do name labels at right? */
00116 
00117       if( nam_yyy != NULL ){
00118          float yv = yotop ; int sz ;
00119 
00120          for( jj=0 ; jj < ny ; jj++ ){
00121             if( STGOOD(nam_yyy[jj]) ){
00122                set_color_memplot( ccc[jj%NCLR][0] , ccc[jj%NCLR][1] , ccc[jj%NCLR][2] ) ;
00123                set_thick_memplot( 2*THIK ) ;
00124                plotpak_line( xotop+0.008 , yv , xotop+0.042 , yv ) ;
00125                set_thick_memplot( 0.0 ) ;
00126                set_color_memplot( 0.0 , 0.0 , 0.0 ) ;
00127                sz = (strlen(nam_yyy[jj]) <= 10) ? 12 : 10 ;
00128                plotpak_pwritf( xotop+0.048 , yv , nam_yyy[jj] , sz , 0 , -1 ) ;
00129                yv -= 0.05 ;
00130             }
00131          }
00132       }
00133 
00134       /* plot axes */
00135 
00136       plotpak_set( xobot,xotop , yobot,yotop , 0.0,nx*dx , ybot,ytop , 1 ) ;
00137       plotpak_periml( nnax,mmax , nnay,mmay ) ;
00138 
00139    } else {  /*-- plot each on separate vertical scale --*/
00140 
00141       float dyo = (yotop-yobot) / ( (1.0+SY) * ny - SY ) ;
00142 
00143       /* name labels at right? */
00144 
00145       if( nam_yyy != NULL ){
00146          float yv = yotop ; int sz ;
00147 
00148          for( jj=0 ; jj < ny ; jj++ ){
00149             yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00150             if( STGOOD(nam_yyy[jj]) ){
00151                set_color_memplot( ccc[jj%NCLR][0] , ccc[jj%NCLR][1] , ccc[jj%NCLR][2] ) ;
00152                set_thick_memplot( 2*THIK ) ;
00153                yv = 0.7*yhh + 0.3*yll ;
00154                plotpak_line( xotop+0.008 , yv , xotop+0.042 , yv ) ;
00155                set_thick_memplot( 0.0 ) ;
00156                set_color_memplot( 0.0 , 0.0 , 0.0 ) ;
00157                sz = (strlen(nam_yyy[jj]) <= 10) ? 12 : 10 ;
00158                plotpak_pwritf( xotop+0.048 , yv , nam_yyy[jj] , sz , 0 , -1 ) ;
00159             }
00160          }
00161       }
00162 
00163       /* data each in its own box */
00164 
00165       nnay = 1 ;
00166       pbot = p10(ybot) ; ptop = p10(ytop) ;
00167       if( ptop > pbot && pbot > 0.0 ) ptop = pbot ;
00168       if( ptop != 0.0 ) mmay = floor( (ytop-ybot) / ptop + 0.5 ) ;
00169       else              mmay = 5 ;   /* shouldn't happen */
00170 
00171            if( mmay == 1 ) mmay = 5 ;
00172       else if( mmay == 2 ) mmay = 4 ;
00173       else if( mmay == 3 ) mmay = 6 ;
00174 
00175       for( jj=ny-1 ; jj >= 0 ; jj-- ){
00176          yll = yobot + jj*(1.0+SY)*dyo ; yhh = yll + dyo ;
00177 
00178          plotpak_set( xobot,xotop , yll,yhh , 0.0,nx*dx , ybot,ytop , 1 ) ;
00179 
00180          plotpak_perimm( nnax,mmax , nnay,mmay , (jj==0) ? 1 : 3 ) ;
00181          if( ybot < 0.0 && ytop > 0.0 ){
00182             plotpak_setlin(5) ;
00183             plotpak_line( 0.0,0.0 , nx*dx,0.0 ) ;
00184             plotpak_setlin(1) ;
00185          }
00186       }
00187    }
00188 
00189    /*-- open display for this plot --*/
00190 
00191    mp = memplot_to_topshell( dpy , mplot , killfunc ) ;
00192    if( mp == NULL ) return NULL ;
00193 
00194    /*-- auxiliary data needed by addto --*/
00195 
00196    ud = (float *) calloc( (12+ny) , sizeof(float) ) ;
00197    ud[0] = xobot ; ud[1] = xotop ; ud[2] = yobot ; ud[3] = yotop ;
00198    ud[4] = 0.0   ; ud[5] = nx    ; ud[6] = ybot  ; ud[7] = ytop  ;
00199    ud[8] = ny    ; ud[9] = yall  ;
00200 
00201    ud[10] = MEMPLOT_NLINE(mplot) ;  /* number of init lines */
00202    ud[11] = -1 ;                    /* current x position   */
00203 
00204    mp->userdata = ud ;
00205 
00206    /*-- plot invalid lines, to be replaced later with valid lines --*/
00207 
00208    /* line connecting ii to ii+1 at the jj-th y level
00209       is number ud[10] + ii + jj*nx in the memplot structure */
00210 
00211    for( jj=0 ; jj < ny ; jj++ )
00212       for( ii=0 ; ii < nx ; ii++ )
00213          ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00214 
00215    /* and two more for each y (an X at the current point):
00216       X for the jj-th y level is the two lines numbered
00217       ud[10] + nx*ny + 2*jj  and ud[10] + nx*ny + 2*jj+1   */
00218 
00219    for( jj=0 ; jj < 2*ny ; jj++ )
00220       ADDTO_MEMPLOT( mplot , 0.0,0.0,0.0,0.0,0.0,-THCODE_INVALID ) ;
00221 
00222    /*-- exit, stage left --*/
00223 
00224    return mp ;
00225 }

Variable Documentation

float ccc[NCLR][3] [static]
 

Initial value:

 {
  { 0.0 , 0.0 , 0.0 } ,
  { 0.9 , 0.0 , 0.0 } ,
  { 0.0 , 0.7 , 0.0 } ,
  { 0.0 , 0.0 , 0.9 } ,
}

Definition at line 12 of file plot_strip.c.

Referenced by plot_strip_addto(), and plot_strip_init().

 

Powered by Plone

This site conforms to the following standards: