Exemplo n.º 1
0
int
makePermVector(Display *dsply, int scrn, unsigned long **permIndex)
{
    static int firstTime = yes;
    unsigned long *spadColorsToo;
    static unsigned long *pIndex;
    Colormap cmap;
    int num_colors;
    int i, ts;

    if (firstTime) {

        /* initialization */

        cmap = DefaultColormap(dsply, scrn);    /* what are other cmaps?? */
        pIndex = (unsigned long *) saymem("makePermVector", Colorcells, sizeof(unsigned long));

        /* get spadColors table */

        if ((num_colors = makeColors(dsply, scrn, &cmap, &spadColorsToo, &ts)) < 0) {
            printf("num_colors < 0!!\n");
            exit(-1);
        }

        /* initialize unused slots in permutation vector */

        for (i = 0; i < spadColorsToo[0]; i++)
            pIndex[i] = 0;
        for (i = num_colors; i < Colorcells; i++)
            pIndex[i] = 0;

        /* make permutation vector */

        for (i = 0; i < num_colors; i++)
            pIndex[spadColorsToo[i]] = i;

        firstTime = no;
    }

    *permIndex = pIndex;
    return (Colorcells);
}
Exemplo n.º 2
0
int
makeColors(Display *dsply, int scrn, Colormap *colorMap,
           unsigned long **colorIndex, int *total_Shades)
{

    int h, s;
    static unsigned long *hiya; /* keep colortable around for next time */
    HSV hsv;
    RGB rgb;
    XColor color;
    int okay = yes;             /* is true (1) so long as XAllocColor is
                                 * working ok. if 0, then we ran out of room
                                 * on the color table. */
    int colorNum;

    /* shade5 definition */

    static float saturations[5] = {0.90, 0.80, 0.74, 0.50, 0.18};
    static float values[5] = {0.38, 0.58, 0.75, 0.88, 0.94};

    /* static float values[5]      = {0.34, 0.52, 0.80, 0.88, 0.94}; */

    /*     fprintf(stderr,"makeColors called\n");*/

    /* printf("making new colors....\n"); */
    *total_Shades = totalShadesConst;

    /* space for color table */
    hiya = (unsigned long *) saymem("spadcolors30.c", totalHuesConst * (*total_Shades) + 2, sizeof(unsigned long));
    *colorIndex = hiya;

    for (h = 0, colorNum = 0; okay && h < 60; h += (hueStep - 6)) {
        for (s = 0; okay && s < *total_Shades; s++) {
            hsv.h = h;
            hsv.s = saturations[s];
            hsv.v = values[s];
            rgb = HSVtoRGB(hsv);
            color.red    = rgb.r *((1<<16)-1);
            color.green  = rgb.g *((1<<16)-1);
            color.blue   = rgb.b *((1<<16)-1);
            color.flags = DoRed | DoGreen | DoBlue;
            /*
              fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b);
              fprintf(stderr,"%d\t%d\t%d\n",color.red,color.green,color.blue);
              */
            if ((okay = XAllocColor(dsply, *colorMap, &color)))
                hiya[colorNum++] = color.pixel; /* hiya points to table */
        }                       /* for s */
    }                           /* for h */
    for (h = 60; okay && h < 180; h += 20) {
        for (s = 0; okay && s < *total_Shades; s++) {
            hsv.h = h;
            hsv.s = saturations[s];
            hsv.v = values[s];
            rgb = HSVtoRGB(hsv);

            color.red    = rgb.r *((1<<16)-1);
            color.green  = rgb.g *((1<<16)-1);
            color.blue   = rgb.b *((1<<16)-1);
            color.flags = DoRed | DoGreen | DoBlue;
            /*
               fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b);
               fprintf(stderr,"%d\t%d\t%d\n",color.red,color.green,color.blue);
               */

            if ((okay = XAllocColor(dsply, *colorMap, &color)))
                hiya[colorNum++] = color.pixel;
        }
    }

    for (h = 180; okay && h <= 300; h += hueStep) {
        for (s = 0; okay && s < *total_Shades; s++) {
            hsv.h = h;
            hsv.s = saturations[s];
            hsv.v = values[s];
            rgb = HSVtoRGB(hsv);

            color.red    = rgb.r *((1<<16)-1);
            color.green  = rgb.g *((1<<16)-1);
            color.blue   = rgb.b *((1<<16)-1);
            color.flags = DoRed | DoGreen | DoBlue;
            /*
               fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b);
               fprintf(stderr,"%d\t%d\t%d\n",color.red,color.green,color.blue);
               */
            if ((okay = XAllocColor(dsply, *colorMap, &color)))
                hiya[colorNum++] = color.pixel;
        }
    }

    hiya[colorNum++] = BlackPixel(dsply, scrn);
    hiya[colorNum++] = WhitePixel(dsply, scrn);

    if (colorNum < (totalShadesConst * totalHuesConst + 2)) {
        free(*colorIndex);
        fprintf(stderr,
                "    > Warning: cannot allocate all the necessary colors - switching to monochrome mode\n");
        *colorIndex = (unsigned long *) saymem("while allocating the colormap for FriCAS ", 2, sizeof(unsigned long));
        (*colorIndex)[0] = BlackPixel(dsply, scrn);
        (*colorIndex)[1] = WhitePixel(dsply, scrn);
        return (-1);
    }

    return (colorNum);
}
Exemplo n.º 3
0
void
drawPhong(int dFlag)
{

    poly          *p, *head;
    polyList      *s;
    int           i,j,hue;
    int           *anIndex, redo;
    viewTriple    *aPoint, *polyPt;

    redo = (recalc || redoSmooth);
    if (redo || redoColor || redoDither) {
      rotated = no;  zoomed = no;  translated = no;
      switchedPerspective = no;  changedEyeDistance = no;
      redoSmooth = no;  movingLight = no;

      /* If only a color change don't recalculate polygon info. */
      if (!redo) {
        /* glossy shading if a single hue is indicated */
        changeColorMap();
        scanLines(dFlag);
        /* if axes are on then show axes labels */
        if (viewport->axesOn) showAxesLabels(dFlag);

        /* show pixmap of image */
        XCopyArea(dsply,viewmap,viewport->viewWindow,trashGC,0,0,
                  vwInfo.width,vwInfo.height,0,0);
      } else {
        if (keepDrawingViewport()) {
          if (!firstTime && !(scanline > 0)) {
            strcpy(control->message,"          Freeing Polygons          ");
            writeControlMessage();
            freeListOfPolygons(quickList);
            freePointResevoir();
          }
          if (keepDrawingViewport()) {
            strcpy(control->message,"         Collecting Polygons        ");
            writeControlMessage();
            quickList = copyPolygons(viewData.polygons);

            if (keepDrawingViewport()) {
              strcpy(control->message,"         Projecting Polygons        ");
              writeControlMessage();
              projectAllPolys(quickList);
              if (keepDrawingViewport()) {
                strcpy(control->message,
                       "       Setting Polygon Extremes      ");
                writeControlMessage();
                minMaxPolygons(quickList);
                if (keepDrawingViewport()) {
                  strcpy(control->message,
                         "          Sorting Polygons          ");
                  writeControlMessage();
                  quickList = msort(quickList,0,viewData.numPolygons,
                                    polyCompare);
                  calcEyePoint();
                  head = p = quickList;

                  /* glossy shading if a single hue is indicated */
                  changeColorMap();

                  for (i=0, aPoint=viewData.points;
                       i<viewData.numOfPoints; i++,aPoint++) {
                    aPoint->norm[0]= 0.0;
                    aPoint->norm[1]= 0.0;
                    aPoint->norm[2]= 0.0;
                  }
                  freePolyList();
                  for (i = 0; i < ARRAY_HEIGHT; i++)
                    scanList[i] = NIL(polyList);
                  /* for each polygon  */
                  /* calculate average normal for each vertex  */
                  strcpy(control->message,
                         "         Build Polygon Lists        ");
                  writeControlMessage();
                  p = head;
                  while ((p != NIL(poly)) && keepDrawingViewport()) {

                    for (j = 0, anIndex = p->indexPtr;
                         j < p->numpts; j++, anIndex++) {
                      polyPt = refPt3D(viewData,*(anIndex));
                      polyPt->norm[0] += p->N[0];
                      polyPt->norm[1] += p->N[1];
                      polyPt->norm[2] += p->N[2];
                      normalizeVector(polyPt->norm);
                      /* get hue for each point if multi-dithering is used */
                      if ((viewport->hueOffset != viewport->hueTop ||
                           smoothError) && !mono) {
                        if (absolute(p->color) > 1.0) {
                          hue = floor(absolute(p->color));
                        } else {
                          hue = floor(absolute(p->color) *
                                      viewport->numberOfHues) +
                                      viewport->hueOffset;
                        }
                        polyPt->sc = (float)hue;
                      } /* multi-color dither */
                    } /* for each point in polygon */

                    if ( ! ( p->partialClipPz ||
                             p->totalClipPz   ||
                             (viewData.clipStuff && (p->partialClip  || p->totalClip ) ) ) ) {
                      /* put polygon in each scanline list it intersects */
                      for (i=(int)p->pymin; i<= (int)p->pymax; i++) {
                        if ( (i>=0) && (i<ARRAY_HEIGHT ) ){
                           s = (polyList *)saymem("smoothShade.c",1,sizeof(polyList));
                           s->polyIndx = p;
                           s->next = scanList[i];
                           scanList[i] = s;
                        }
                      } /* put polygon in each scanline it intersects */
                    } /* if polygon not clipped */
                    p = p->next;
                  } /* while still polygons */

                  scanLines(dFlag);

                  /* if axes are on then show axes labels */
                  if (viewport->axesOn) showAxesLabels(dFlag);

                  /* show pixmap of image */
                  XCopyArea(dsply,viewmap,viewport->viewWindow,trashGC,0,0,
                          vwInfo.width,vwInfo.height,0,0);
                  /* freePolyList(scanList);   */

                } /* keepDrawingViewport() after setting extreme values */
              } /* keepDrawingViewport() after projecting all polygons */
            } /* keepDrawingViewport() after collecting polygons */
          } /* keepDrawingViewport() after freeing polygons */
        } /* keepDrawingViewport() after recalc */
        finishedList = !(scanline>0);
        if (firstTime) firstTime = no;
      } /* not only a color change */

    } else { /* else just redisplay current pixmap of image */
      XCopyArea(dsply,viewmap,viewport->viewWindow,trashGC,0,0,
                vwInfo.width,vwInfo.height,0,0);
    }
    clearControlMessage();
    strcpy(control->message,viewport->title);
    writeControlMessage();

} /* drawPhong */