コード例 #1
0
ファイル: cpgdemo.c プロジェクト: Milkyway-at-home/nemo
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;
}
コード例 #2
0
ファイル: Plotter2.cpp プロジェクト: schiebel/casa
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();
}
コード例 #3
0
ファイル: pgplot-module.c プロジェクト: hankem/ISIS
/* set hatching style */
static void _pgshs (double *ang, double *s, double *p)
{
   cpgshs ((float) *ang, (float) *s, (float) *p);
}