Exemplo n.º 1
0
/*=========================================================*/
Float_t AGX(Char_t *matn,Float_t peak,Float_t width=0.0)
{
  Axis_t aymax=aymin+numchy;
  setcanvas(2);
  TH1D *hist;
  hist=(TH1D*)gROOT->FindObject("ytemp");
  if(hist!=NULL)hist->Delete();
  hist=new TH1D("ytemp","ytemp",NCHY,0,DIMY);
  hist->Add(histy,1.0);
  Float_t a=GX(matn,peak,width);
  histy->Add(hist,1.0);
  c1->cd(2);
  histy->SetAxisRange(aymin,aymax);
  histy->SetLineColor(3);
  histy->Draw();
  return a;
}
Exemplo n.º 2
0
void write_animated_gif(universe *u, const char *filename) {

        FILE *out = fopen(filename, "wb");
        gdImagePtr im;

        int l, r, t, b;
        int ll, rr, tt, bb;

        generation *g = u->first;
        generation_find_bounds(g, &l, &r, &t, &b);

        for(g = g->next; g; g = g->next) {
                generation_find_bounds(g, &ll, &rr, &tt, &bb);
                if(ll < l) l = ll;
                if(rr > r) r = rr;
                if(tt < t) t = tt;
                if(bb > b) b = bb;
        }

        int scale = 4;
	int delay = 10;

        im = gdImageCreate((r - l) * scale, (b - t) * scale);

        int background = gdImageColorAllocate(im, 230, 230, 255);
        gdImageRectangle(im, 0, 0, (r-l) * scale, (b-t) * scale, background);

        int tile_bg = gdImageColorAllocate(im, 255, 255, 255);
        int tile_frame = gdImageColorAllocate(im, 230, 230, 230);

        int on = gdImageColorAllocate(im, 0, 0, 0);
        int unknown = gdImageColorAllocate(im, 255, 255, 0);
        int unknown_stable = gdImageColorAllocate(im, 192, 255, 0);

	gdImageGifAnimBegin(im, out, 1, 0);

        for(g = u->first; g; g = g->next) {
                tile *tp;
                for(tp = g->all_first; tp; tp = tp->all_next) {
                        if(!(tp->flags & IS_LIVE)) {
                                continue;
                        }

                        gdImageFilledRectangle(im, GX(tp->xpos), GY(tp->ypos),
                                               GX(tp->xpos + TILE_WIDTH)-1, 
                                               GY(tp->ypos + TILE_HEIGHT)-1,
                                               tile_bg);

                        gdImageRectangle(im, GX(tp->xpos), GY(tp->ypos),
                                         GX(tp->xpos + TILE_WIDTH)-1, 
                                         GY(tp->ypos + TILE_HEIGHT)-1,
                                         tile_frame);
                        int xx, yy;
                        for(xx = 0; xx < TILE_WIDTH; xx++) {
                                for(yy = 0; yy < TILE_HEIGHT; yy++) {
                                        cellvalue cv = tile_get_cell(tp, xx, yy);
                                        int colour = -1;
                                        if(cv == ON) {
                                                colour = on;
                                        } else if(cv == UNKNOWN) {
                                                colour = unknown;
                                        } else if(cv == UNKNOWN_STABLE) {
                                                colour = unknown_stable;
                                        } 
                                        if(colour >= 0)
                                                gdImageFilledRectangle(im, 
                                                                       GX(tp->xpos + xx),
                                                                       GY(tp->ypos + yy),
                                                                       GX(tp->xpos + xx + 1) - 1,
                                                                       GY(tp->ypos + yy + 1) - 1,
                                                                       colour);
                                }
                        }
                }
		gdImageGifAnimAdd(im, out, 0, 0, 0,
				  delay, gdDisposalNone, NULL);
        }

	gdImageGifAnimEnd(out);

        fclose(out);
        gdImageDestroy(im);
}
Exemplo n.º 3
0
void write_gif(universe *u, int gen, const char *filename) {

        FILE *out = fopen(filename, "wb");
        gdImagePtr im;

        int l, r, t, b;

        generation *g = universe_find_generation(u, gen, 0);
        generation_find_bounds(g, &l, &r, &t, &b);

        int scale = 4;

        im = gdImageCreate((r - l) * scale, (b - t) * scale);

        int background = gdImageColorAllocate(im, 230, 230, 255);
        gdImageRectangle(im, 0, 0, (r-l) * scale, (b-t) * scale, background);

        int tile_bg = gdImageColorAllocate(im, 255, 255, 255);
        int tile_frame = gdImageColorAllocate(im, 230, 230, 230);

        int on = gdImageColorAllocate(im, 0, 0, 0);
        int unknown = gdImageColorAllocate(im, 255, 255, 0);
        int unknown_stable = gdImageColorAllocate(im, 192, 255, 0);

        tile *tp;
        for(tp = g->all_first; tp; tp = tp->all_next) {
                if(!(tp->flags & (IS_LIVE | HAS_UNKNOWN_CELLS))) {
                        continue;
                }

                gdImageFilledRectangle(im, GX(tp->xpos), GY(tp->ypos),
                                       GX(tp->xpos + TILE_WIDTH)-1, 
                                       GY(tp->ypos + TILE_HEIGHT)-1,
                                       tile_bg);

                gdImageRectangle(im, GX(tp->xpos), GY(tp->ypos),
                                 GX(tp->xpos + TILE_WIDTH)-1, 
                                 GY(tp->ypos + TILE_HEIGHT)-1,
                                 tile_frame);
                int xx, yy;
                for(xx = 0; xx < TILE_WIDTH; xx++) {
                        for(yy = 0; yy < TILE_HEIGHT; yy++) {
                                cellvalue cv = tile_get_cell(tp, xx, yy);
                                if(cv == ON) {
                                        gdImageFilledRectangle(im, 
                                                               GX(tp->xpos + xx),
                                                               GY(tp->ypos + yy),
                                                               GX(tp->xpos + xx + 1) - 1,
                                                               GY(tp->ypos + yy + 1) - 1,
                                                               on);
                                } else if(cv == UNKNOWN) {
                                        gdImageFilledRectangle(im, 
                                                               GX(tp->xpos + xx),
                                                               GY(tp->ypos + yy),
                                                               GX(tp->xpos + xx + 1) - 1,
                                                               GY(tp->ypos + yy + 1) - 1,
                                                               unknown);
                                } else if(cv == UNKNOWN_STABLE) {
                                        gdImageFilledRectangle(im, 
                                                               GX(tp->xpos + xx),
                                                               GY(tp->ypos + yy),
                                                               GX(tp->xpos + xx + 1) - 1,
                                                               GY(tp->ypos + yy + 1) - 1,
                                                               unknown_stable);
                                } 
                        }
                }
        }

        gdImageGif(im, out);
        fclose(out);
        gdImageDestroy(im);
}
Exemplo n.º 4
0
void clGeometryReader::ReadPatch(fstream &file, clPatch &patch) const
{
  int          EndOfBlock;
  int          AllRead;
  char         line[LINE_SIZE];
  char         *ptrLine = line;
  const char   *tkn     = " ;:";
  int          countData;

  int     ID   = 0;
  char    type = 'B';
  dMatrix GX(4, 4);
  dMatrix GY(4, 4);
  dMatrix GZ(4, 4);

  // Read line
  file.getline(line, LINE_SIZE);

  EndOfBlock = 0;
  AllRead    = 0;
  countData  = 0;
  while(!file.eof() && file.good() && !EndOfBlock)
  {
    // Check first character in trimmed line
    switch(*strtrim(line))
    {
      case '#':
      case '*':
        // Comment line
        file.getline(line, LINE_SIZE);
        break;
      case '&':
      case '$':
      {
        // Block specifier
        int blockCommand = GetBlockSpec(line);

        switch(blockCommand)
        {
          case UNKNOWN_SPEC:
            throw clExceptionTree("clGeometryReader", "ReadPatch", "Unknown block specifier.");
            break;

          case PATCH_SPEC:
            throw clExceptionTree("clGeometryReader", "ReadPatch", "Unexpected start of block PATCH.");
            break;

          case SURFACE_SPEC:
            throw clExceptionTree("clGeometryReader", "ReadPatch", "Unexpected start of block SURFACE.");
            break;

          case GEOMETRY_SPEC:
            throw clExceptionTree("clGeometryReader", "ReadPatch", "Unexpected start of block GEOMETRY.");
            break;

          case END_SPEC:
            EndOfBlock = 1;
            break;

          default:
            throw clExceptionTree("clGeometryReader", "ReadPatch", "Function GetBlockSpec returned unknown value.");
            break;
        }

        break;
      }
      case '/':
        // End of block specifier
        EndOfBlock = 1;
        break;
      default:
        if(strlen(strtrim(line)) > 0)
        {
          // Data line
          countData++;
          switch(countData)
          {
            // ID Number
            case 1:
              ID      = str2int(line);
              AllRead = 0;
              break;

            // blendType
            case 2:
              if(chrloc('H', line) != -1)
              {
                type = 'H';
              }
              else if(chrloc('B', line) != -1)
              {
                type = 'B';
              }
              else
              {
                throw clExceptionTree("clGeometryReader", "ReadPatch", "Unknown blending type.");
              }
              break;

            // Matrix GX
            case 3:
            case 4:
            case 5:
            case 6:
              ptrLine = strtok(line, tkn);
              GX.SetElement(countData-2, 1, str2double(ptrLine));

              ptrLine = strtok(0, tkn);
              GX.SetElement(countData-2, 2, str2double(ptrLine));

              ptrLine = strtok(0, tkn);
              GX.SetElement(countData-2, 3, str2double(ptrLine));

              ptrLine = strtok(0, tkn);
              GX.SetElement(countData-2, 4, str2double(ptrLine));
              break;

            // Matrix GY
            case 7:
            case 8:
            case 9:
            case 10:
              ptrLine = strtok(line, tkn);
              GY.SetElement(countData-6, 1, str2double(ptrLine));

              ptrLine = strtok(0, tkn);
              GY.SetElement(countData-6, 2, str2double(ptrLine));

              ptrLine = strtok(0, tkn);
              GY.SetElement(countData-6, 3, str2double(ptrLine));

              ptrLine = strtok(0, tkn);
              GY.SetElement(countData-6, 4, str2double(ptrLine));
              break;

            // Matrix GZ
            case 11:
            case 12:
            case 13:
            case 14:
              ptrLine = strtok(line, tkn);
              GZ.SetElement(countData-10, 1, str2double(ptrLine));

              ptrLine = strtok(0, tkn);
              GZ.SetElement(countData-10, 2, str2double(ptrLine));

              ptrLine = strtok(0, tkn);
              GZ.SetElement(countData-10, 3, str2double(ptrLine));

              ptrLine = strtok(0, tkn);
              GZ.SetElement(countData-10, 4, str2double(ptrLine));

              if(countData == 14)
              {
                AllRead = 1;

                // Correct for right hand axis system when type is Bezier
                if(type=='B')
                {
                  GX.Transpose(); GX.MirrorColumns();
                  GY.Transpose(); GY.MirrorColumns();
                  GZ.Transpose(); GZ.MirrorColumns();
                }

                // Now create the patch
                patch.SetNumberID(ID);
                patch.SetGX(GX);
                patch.SetGY(GY);
                patch.SetGZ(GZ);
                patch.SetBlendType(type);
              }
              break;

            // Error
            default:
              throw clExceptionTree("clGeometryReader", "ReadPatch", "Wrong number of data lines.");
              break;
          }
        }

        file.getline(line, LINE_SIZE);
        break;
    }
  }

  if(!EndOfBlock || !AllRead)
  {
    throw clExceptionTree("clGeometryReader", "ReadPatch", "Unexpected end while reading block PATCH.");
  }
}