Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.atnf.csiro.au/computing/software/gipsy/pguide/gui-example7.html
Дата изменения: Unknown
Дата индексирования: Sat Jan 17 05:27:18 2009
Кодировка:

Поисковые слова: п п п п п п п п п п п п р п р п р п
Plotfields, Images and Color Maps

Plotfields, Images and Color Maps

The Ggi plotfield driver supports PGPLOT's pixel primitives so that the routine PGIMAG can be used. Because the default number of colors is limited to 16, it will be necessary to increase the number of colors available to the plotfield. This page explains how this can be done.

Plotfield color map

For detailed information about the use of color maps, please consult the appropriate PGPLOT documentation: for instance pgscr.dc2 and pgscir.dc2 to start with. In summary: every PGPLOT device has an associated table of available color indices. For every color index there is a color representation, which is simply three floating point numbers in the range [0,1], one for each of the primary colors red, green and blue. Depending on the device, some, all or none of the color representations can be modified.

Within Ggi, there is one master color map which is shared by all plotfields. When Ggi is initialized, this color map is 16 elements long and contains PGPLOT's base colors. These 16 elements cannot be modified. Calling PGSCR for these elements is illegal. The number of colors in the master color map can be increased by calling GgiPlotColors(). This is done only once in the initialization phase of the program. The colors from the master color map can be assigned to the color maps of individual plot fields. This is done with GgiPlotMapColors(). Using this routine, many kinds of mappings can be specified. For instance it is possible to assign different parts of the master color map to different plot fields, so that the each has its private set of colors. But it is also possible that plot fields share their colors, all or some of them, so that the change of a color representation for one plot has also effect on other plots sharing the same color index.

Example program

(Sorry, image cannot be displayed) This program illustrates the use of colors with Ggi plot fields. It creates a plot field, in which a simple image is displayed using a gray-scale color map. This program has no provisions for manipulating the color map, but this can easily be added as will be shown in a next example.
/* example7.c -XT */

#include "stddef.h"
#include "math.h"
#include "gipsyc.h"
#include "cmain.h"
#include "init.h"
#include "finis.h"
#include "userfio.h"
#include "pgplot.h"
#include "ggi.h"

#define ROWS 100                               /* number of image rows    */
#define COLS 100                               /* number of image columns */
#define NCI   50                               /* number of color indices */


/*
 *  QUIT= keyword handler
 */
static void quit(ident id, char *key, int code, void *arg)
{
   bool button=toflog(FALSE);
   (void)userflog(&button, 1, 2, key, " ");
   if (tobool(button)) {
      wkeyf(key);
      finis_c();
   }
}

/*
 *   Main program
 */
MAIN_PROGRAM_ENTRY
{
   ident plotter, bquit;
   float image[ROWS][COLS];
   int   i, j;
   float tr[6];
   float a1=0.0, a2=1.0;
   fint  idim=COLS, jdim=ROWS, i1=1, i2=COLS, j1=1, j2=ROWS;
   fint  cilo=16, cihi=16+NCI-1;

   init_c();

   GgiAutoLayout(FALSE);                          /* custom layout            */
   GgiPostponeRealize(TRUE);                      /* don't show immediately   */
    
   (void)GgiPlotColors(NULL, 16+NCI);             /* NCI additional colors    */
   plotter = GgiPlotField("PLOT", 325, 325);      /* create plot field        */
   GgiPlotMapColors(plotter, 0, 16, 16, NCI, -1); /* assign colors to plotter */
   bquit   = GgiButton("QUIT=", NULL);
   
   GgiSetPosition(plotter, 0, NULL, 0, NULL);     /* top left                 */
   GgiSetPosition(bquit,   0, NULL, 0, plotter);  /* below plotter, left      */
   (void)ScheduleKeyevent(quit, "QUIT=", KEYCHANGE, NULL); /* handle QUIT     */

   GgiRealize();                                  /* show what we've made     */

   for (j=0; j<ROWS; j++) {                       /* build "image"            */
      for (i=0; i<COLS; i++) {
         float x = i-COLS/2, y = j-ROWS/2, w = 3*COLS;
         image[j][i] = exp(-(x*x+y*y)/w);
      }
   }

   (void)pgopen_c(tofchar("PLOT"));                  /* open plotter          */

   for (i=0; i<NCI; i++) {                           /* grayscale color map   */
      float value=(float)i/(float)(NCI-1);
      fint  ci=i+16;
      pgscr_c(&ci, &value, &value, &value);
   }

   pgscir_c(&cilo, &cihi);                           /* set color index range */

                                                     /* tranformation matrix  */
   tr[0] = 0.0; tr[1] = 1.0/(float)COLS; tr[2] = 0.0;
   tr[3] = 0.0; tr[4] = 0.0;             tr[5] = 1.0/(float)ROWS;

                                                     /* display image         */
   pgimag_c(&image[0][0], &idim, &jdim, &i1, &i2, &j1, &j2, &a1, &a2, tr);

   MainLoop();
}

Programming GIPSY Maintained by J. P. Terlouw