IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19835


Ignore:
Timestamp:
Oct 2, 2008, 10:44:40 AM (18 years ago)
Author:
eugene
Message:

fix flips, colors and ellipse

Location:
trunk/Ohana/src/kapa2/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa2/src/PSOverlay.c

    r16255 r19835  
    11# include "Ximage.h"
     2
     3static char name[4][16] = {"red", "green", "blue", "yellow"};
    24
    35void PSOverlay (KapaImageWidget *image, int N, FILE *f, int extra) {
     
    68  double X, Y, dX, dY;
    79  int Xmin, Ymin, Xmax, Ymax;
    8   double expand, X0, Y0;
     10  double expand, pX, pY;
     11  bDrawColor color;
    912 
     13  /* translate color to bDrawColors : image[0].overlay[N].color */
     14  color = KapaColorByName (name[N]);
     15  fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(color));
     16 
    1017  expand = 1.0;
    1118  if (image[0].picture.expand > 0) {
    12     expand = 1 / (1.0*image[0].picture.expand);
     19    expand = image[0].picture.expand;
    1320  }
    1421  if (image[0].picture.expand < 0) {
    15     expand = fabs((double)image[0].picture.expand);
     22    expand = 1.0 / fabs((double)image[0].picture.expand);
    1623  }
    17 
    18   Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);
    19   X0 -= image[0].picture.x;
    20   Y0 -= image[0].picture.y;
    2124
    2225  Xmin = 0;
     
    2629
    2730  for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
    28     X  = (image[0].overlay[N].objects[i].x)/expand + X0;
    29     Y =  Ymax - (image[0].overlay[N].objects[i].y)/expand - Y0;
    30     dX = (image[0].overlay[N].objects[i].dx)/expand;
    31     dY = (image[0].overlay[N].objects[i].dy)/expand;
    32    
     31
     32    Image_to_Screen (&X, &Y, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].picture);
     33    dX = image[0].overlay[N].objects[i].dx * expand;
     34    dY = image[0].overlay[N].objects[i].dy * expand;
     35    if (image[0].picture.flipx) dX *= -1;
     36    if (image[0].picture.flipy) dY *= -1;
     37
     38    // PS coord system is flipped relative to screen
     39    Y = Ymax - Y;
     40
     41    pX = (image[0].picture.flipx) ? -1.0 : +1.0;
     42    pY = (image[0].picture.flipy) ? -1.0 : +1.0;
     43
    3344    switch (image[0].overlay[N].objects[i].type) {
    3445      case KII_OVERLAY_LINE:
     
    5869          break;
    5970        }
    60         // XXX add in the rotated ellipse version (rotate in PS space)
    61         fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
     71        // is this a true circle, or is it an ellipse?
     72        if (fabs(dX - dY) < 0.01) {
     73          fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
     74        } else {
     75          // moderately-stupid rotated ellipse drawing:
     76          // ANGLE is distance ccw from the x-axis to the major axis
     77          double x0, y0, x1, y1, t;
     78          double angle = image[0].overlay[N].objects[i].angle * RAD_DEG;
     79          double cs = cos(angle);
     80          double sn = sin(angle);
     81          x0 = X + pX*dX*cs;
     82          y0 = Y + pY*dX*sn;
     83          // XXX dt should be based on the size of the ellipse...
     84          // 0.10 -> 60 segments on the ellipse
     85          # define DT 0.1
     86          for (t = DT; t < 2*M_PI + DT; t+=DT) {
     87            x1 = X + pX*dX*cos(t)*cs - pX*dY*sin(t)*sn;
     88            y1 = Y + pY*dX*cos(t)*sn + pY*dY*sin(t)*cs;
     89            fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", x0 + extra, y0 + extra, x1 + extra, y1 + extra);
     90            x0 = x1;
     91            y0 = y1;
     92          }
     93        }
    6294        break;
    6395      default:
  • trunk/Ohana/src/kapa2/src/PaintOverlay.c

    r17120 r19835  
    66  int dX, dY, dx, dy;
    77  int x, y, Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
    8   double t, expand, X, Y;
     8  double t, expand, X, Y, pX, pY;
    99 
    1010  XSetForeground (graphic[0].display, graphic[0].gc, image[0].overlay[N].color);
     
    3737    if (Y - dY > Ymax);
    3838
     39    pX = (image[0].picture.flipx) ? -1.0 : +1.0;
     40    pY = (image[0].picture.flipy) ? -1.0 : +1.0;
     41
    3942    /* for a LINE, (x, y) is the start, (dx, dy) is the distance to end
    4043       for a CIRCLE (x, y) is the center, (dx, dy) is the radius
     
    6265          XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy, 0, 23040);
    6366        } else {
    64           // very stupid rotate ellipse drawing:
     67          // very stupid rotated ellipse drawing:
     68          double x0, y0, x1, y1;
    6569          double angle = image[0].overlay[N].objects[i].angle * RAD_DEG;
    6670          double cs = cos(angle);
    6771          double sn = sin(angle);
     72          x0 = X + pX*dx*cs;
     73          y0 = Y - pY*dx*sn;
    6874          // XXX dt should be based on the size of the ellipse...
    69           for (t = 0; t < 2*M_PI; t+=0.05) {
    70             x = X + dx*cos(t)*cs + dy*sin(t)*sn;
    71             y = Y - dx*cos(t)*sn + dy*sin(t)*cs;
    72             XDrawPoint (graphic[0].display, graphic[0].window, graphic[0].gc, x, y);
     75          // 0.10 -> 60 segments on the ellipse
     76          # define DT 0.1
     77          for (t = DT; t < 2*M_PI + DT; t+=DT) {
     78            x1 = X + pX*dx*cos(t)*cs + pX*dy*sin(t)*sn;
     79            y1 = Y - pY*dx*cos(t)*sn + pY*dy*sin(t)*cs;
     80            XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, x0, y0, x1, y1);
     81            x0 = x1;
     82            y0 = y1;
    7383          }
    7484        }
Note: See TracChangeset for help on using the changeset viewer.