Beispiel #1
0
static void demo3()
{
#define TWOPI (2.0*3.14159265)
#define NPOL  6
  
  int i, j, k;
  int n1[] = {3, 4, 5, 5, 6, 8};
  int n2[] = {1, 1, 1, 2, 1, 3};
  float x[10], y[10], y0;
  
  char* lab[] =  {"Fill style 1 (solid)",
		  "Fill style 2 (outline)",
		  "Fill style 3 (hatched)",
		  "Fill style 4 (cross-hatched)"};
  
/* Initialize the viewport and window. */

  cpgbbuf();
  cpgsave();
  cpgpage();
  cpgsvp(0.0, 1.0, 0.0, 1.0);
  cpgwnad(0.0, 10.0, 0.0, 10.0);
  
/* Label the graph. */

  cpgsci(1);
  cpgmtxt("T", -2.0, 0.5, 0.5, 
          "PGPLOT fill area: routines cpgpoly(), cpgcirc(), cpgrect()");
  
/* Draw assorted polygons. */

  for (k=1; k<5; k++) {
    cpgsci(1);
    y0 = 10.0 -2.0*k;
    cpgtext(0.2, y0+0.6, lab[k-1]);
    cpgsfs(k);
    for (i=0; i<NPOL; i++) {
      cpgsci(i+1);
      for (j=0; j<n1[i]; j++) {
	x[j] = i+1 + 0.5*cos(n2[i]*TWOPI*j/n1[i]);
	y[j] = y0 + 0.5*sin(n2[i]*TWOPI*j/n1[i]);
      }
      cpgpoly(n1[i], x, y);
    }
    cpgsci(7);
    cpgshs(0.0, 1.0, 0.0);
    cpgcirc(7.0, y0, 0.5);
    cpgsci(8);
    cpgshs(-45.0, 1.0, 0.0);
    cpgrect(7.8, 9.5, y0-0.5, y0+0.5);
  }
  cpgunsa();
  cpgebuf();
  return;
}
Beispiel #2
0
static void _pgpoly (void)
{
   SLang_Array_Type *x, *y;

   if (-1 == pop_two_float_vectors (&x, &y))
     return;

   cpgpoly (x->num_elements, (float *) x->data, (float *) y->data);

   free_arrays (x, y, NULL, NULL);
}
Beispiel #3
0
void Plotter2::plot() {
    open();

    if ((width > 0.0) && (aspect > 0.0)) {
        cpgpap(width, aspect);
    }

    cpgscr(0, 1.0, 1.0, 1.0); // set background color white
    cpgscr(1, 0.0, 0.0, 0.0); // set foreground color black

    for (unsigned int i = 0; i < vInfo.size(); ++i) {
        Plotter2ViewportInfo vi = vInfo[i];

	if (vi.showViewport) {
	    resetAttributes(vi);

	    // setup viewport
            cpgsvp(vi.vpPosXMin, vi.vpPosXMax, vi.vpPosYMin, vi.vpPosYMax);
	    cpgswin(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);

	    // background color (default is transparent)
	    if (vi.vpBColor >= 0) {
	        cpgsci(vi.vpBColor);
	        cpgrect(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);
	        cpgsci(1);  // reset foreground colour to the initial one (black)
	    }

	    // data
	    for (unsigned int j = 0; j < vi.vData.size(); ++j) {
	        resetAttributes(vi);

	        Plotter2DataInfo di = vi.vData[j];
	        std::vector<float> vxdata = di.xData;
                int ndata = vxdata.size();
	        float* pxdata = new float[ndata];
	        float* pydata = new float[ndata];
	        for (int k = 0; k < ndata; ++k) {
	            pxdata[k] = di.xData[k];
	            pydata[k] = di.yData[k];
	        }

	        if (di.drawLine) {
  	            cpgsls(di.lineStyle);
	            cpgslw(di.lineWidth);
		    int colorIdx = di.lineColor;
		    if (colorIdx < 0) {
		        colorIdx = (j + 1) % 15 + 1;
		    }
	            cpgsci(colorIdx);
	            cpgline(ndata, pxdata, pydata);
	        }

	        if (di.drawMarker) {
	            cpgsch(di.markerSize);
	            cpgsci(di.markerColor);
	            cpgpt(ndata, pxdata, pydata, di.markerType);
	        }

	        delete [] pxdata;
	        delete [] pydata;
	    }

	    //calculate y-range of xmasks
	    std::vector<float> yrange = vi.getRangeY();
	    float yexcess = 0.1*(yrange[1] - yrange[0]);
	    float xmaskymin = yrange[0] - yexcess;
	    float xmaskymax = yrange[1] + yexcess;

	    // masks
	    for (unsigned int j = 0; j < vi.vRect.size(); ++j) {
	        resetAttributes(vi);

	        Plotter2RectInfo ri = vi.vRect[j];
                cpgsci(ri.color);
	        cpgsfs(ri.fill);
	        cpgslw(ri.width);
	        cpgshs(45.0, ri.hsep, 0.0);
	        float* mxdata = new float[4];
	        float* mydata = new float[4];
	        mxdata[0] = ri.xmin;
	        mxdata[1] = ri.xmax;
	        mxdata[2] = ri.xmax;
	        mxdata[3] = ri.xmin;
	        mydata[0] = xmaskymin;
	        mydata[1] = xmaskymin;
	        mydata[2] = xmaskymax;
	        mydata[3] = xmaskymax;
                cpgpoly(4, mxdata, mydata);
	    }

	    // arrows
	    for (unsigned int j = 0; j < vi.vArro.size(); ++j) {
  	        resetAttributes(vi);

		Plotter2ArrowInfo ai = vi.vArro[j];
		cpgsci(ai.color);
		cpgslw(ai.width);
                cpgsls(ai.lineStyle);
		cpgsch(ai.headSize);
		cpgsah(ai.headFillStyle, ai.headAngle, ai.headVent);
		cpgarro(ai.xtail, ai.ytail, ai.xhead, ai.yhead);
	    }

	    // arbitrary texts
	    for (unsigned int j = 0; j < vi.vText.size(); ++j) {
  	        resetAttributes(vi);

		Plotter2TextInfo ti = vi.vText[j];
		cpgsch(ti.size);
		cpgsci(ti.color);
		cpgstbg(ti.bgcolor);
		cpgptxt(ti.posx, ti.posy, ti.angle, ti.fjust, ti.text.c_str());
	    }

	    // viewport outline and ticks
	    resetAttributes(vi);

            cpgbox("BCTS",  vi.majorTickIntervalX, vi.nMinorTickWithinMajorTicksX, 
	           "BCTSV", vi.majorTickIntervalY, vi.nMinorTickWithinMajorTicksY);

	    // viewport numberings
	    std::string numformatx, numformaty;
	    if (vi.numLocationX == "b") {
	        numformatx = "N";
	    } else if (vi.numLocationX == "t") {
	        numformatx = "M";
	    } else if (vi.numLocationX == "") {
	        numformatx = "";
	    }
	    if (vi.numLocationY == "l") {
	        numformaty = "NV";
	    } else if (vi.numLocationY == "r") {
	        numformaty = "MV";
	    } else if (vi.numLocationY == "") {
	        numformaty = "";
	    }

            cpgbox(numformatx.c_str(), vi.majorTickIntervalX * vi.nMajorTickWithinTickNumsX, 0, 
	           numformaty.c_str(), vi.majorTickIntervalY * vi.nMajorTickWithinTickNumsY, 0);

	    float xpos, ypos;

	    // x-label
	    vi.getWorldCoordByWindowCoord(vi.labelXPosX, vi.labelXPosY, &xpos, &ypos);
	    cpgsch(vi.labelXSize);
            cpgsci(vi.labelXColor);
            cpgstbg(vi.labelXBColor); //outside viewports, works ONLY with /xwindow
            cpgptxt(xpos, ypos, vi.labelXAngle, vi.labelXFJust, vi.labelXString.c_str());

	    // y-label
	    vi.getWorldCoordByWindowCoord(vi.labelYPosX, vi.labelYPosY, &xpos, &ypos);
	    cpgsch(vi.labelYSize);
            cpgsci(vi.labelYColor);
            cpgstbg(vi.labelYBColor); //outside viewports, works ONLY with /xwindow
            cpgptxt(xpos, ypos, vi.labelYAngle, vi.labelYFJust, vi.labelYString.c_str());

	    // title
	    vi.getWorldCoordByWindowCoord(vi.titlePosX, vi.titlePosY, &xpos, &ypos);
	    cpgsch(vi.titleSize);
            cpgsci(vi.titleColor);
            cpgstbg(vi.titleBColor); //outside viewports, works ONLY with /xwindow
            cpgptxt(xpos, ypos, vi.titleAngle, vi.titleFJust, vi.titleString.c_str());
	}

    }

    close();
}
void projCircle(double racen, double deccen, double radius, double val) {
  int i, j, ip, in, sign, pixval;
  float mx[NCIRC], my[NCIRC];
  double t, axialvec[3], cenvec[3], angvec[3], rotvec[3], rmat[3][3];
  double ra[NCIRC], rap[NCIRC], ran[NCIRC];
  double dec[NCIRC], decp[NCIRC], decn[NCIRC];
  double x, y;

  // make Cartesian representation of the vector pointing to center
  slaDcs2c(racen, deccen, cenvec);

  // make Cartesian representation of a vector pointing radius away
  if(deccen>0.0)
    slaDcs2c(racen, deccen-radius, angvec);
  else
    slaDcs2c(racen, deccen+radius, angvec);

  t = 0;
  for(i=0; i<NCIRC; i++) {
    // length of axial vector is angle of rotation
    for(j=0;j<3;j++) axialvec[j] = cenvec[j]*t;
    // get rotation matrix
    slaDav2m(axialvec, rmat);
    // apply rotation to angled vector
    slaDmxv(rmat, angvec, rotvec);
    // get new ra, dec
    slaDcc2s(rotvec, &(ra[i]), &(dec[i]));
    //    if(ra[i] < 0 && racen > 0.0) ra[i] += 2*M_PI;
    //    if(ra[i] > 0 && racen < 0.0) ra[i] -= 2*M_PI;
    // update rotation angle
    t += 2.0*M_PI/(double) (NCIRC-1);
  }

  pixval = rint((__minind*(__maxval-val) + __maxind*(val-__minval))/
               (__maxval-__minval));

  // saturate properly
  pixval = MIN(__maxind, pixval);
  pixval = MAX(__minind, pixval);

  cpgsci(pixval);

  // determine if the polygon wraps around
  sign = 0;
  for(i=0; i<NCIRC-1; i++) {
    if(dec[i]>deccen && ra[i+1]*ra[i] < 0 && ra[i+1]<ra[i]) sign = 1;
  }

  // if so, draw two polygons separately
  if(sign) {
    in = 0;
    ip = 0;
    for(i=0; i<NCIRC; i++) {
      if(ra[i]<0.0) {
        ran[in] = ra[i]; decn[in] = dec[i]; in++;
      }
      else {
        ran[in] = -0.99999*M_PI; decn[in] = dec[i]; in++;
      }
      if(ra[i]>0.0) {
        rap[ip] = ra[i]; decp[ip] = dec[i]; ip++;
      }
      else {
        rap[ip] = 0.99999*M_PI; decp[ip] = dec[i]; ip++;
      }
    }
    
    for(i=0; i<ip; i++) {
      // Hammer-Aitoff projection
      project(rap[i], decp[i], &x, &y);
      mx[i] = x; my[i] = y;
    }
    cpgpoly(ip,mx,my);
    
    for(i=0; i<in; i++) {
      // Hammer-Aitoff projection
      project(ran[i], decn[i], &x, &y);
      mx[i] = x; my[i] = y;
    }
    cpgpoly(in,mx,my);
  }
  // otherwise draw only one
  else {
    for(i=0; i<NCIRC; i++) {
      // Hammer-Aitoff projection
      project(ra[i], dec[i], &x, &y);
      mx[i] = x; my[i] = y;
    }
    cpgpoly(NCIRC,mx,my);
  }

  cpgsci(1);
}