Exemplo n.º 1
0
Arquivo: demo.c Projeto: Juanlu001/gr
int main(void)
{
  float positions[3] = {0, 0, 0}, colors[3] = {0.5, 0.5, 0.5}, radii[1] = {2};

  gr3_clear();
  gr_setviewport(0.1, 0.95, 0.1, 0.95);
  gr3_setbackgroundcolor(1, 1, 1, 1);
  gr3_drawspheremesh(1, positions, colors, radii);
  gr3_drawimage(0, 1, 0, 1, 500, 500, GR3_DRAWABLE_GKS);
  gr_axes(0.04, 0.04, 0, 0, 5, 5, -0.01);
  gr_settextalign(2, 4);
  gr_text(0.525, 0.95, "GR3 Demo");
  gr3_export("gr3demo.png", 500, 500);
  gr_updatews();
}
Exemplo n.º 2
0
Arquivo: demo.c Projeto: jheinen/gr
int main(void)
{
  double x[POINTS], y[CURVES][POINTS];
  int i, j, k;

  putenv("GKS_DOUBLE_BUF=1");
#ifdef __APPLE__
  putenv("GKS_WSTYPE=211");
#endif

  srand(0);
  for (j = 0; j < CURVES; j++)
    {
      x[0] = y[j][0] = 0;
      for (i = 1; i < POINTS; i++)
        {
          x[i] = i;
          y[j][i] = y[j][i - 1] + (-0.5 + (double)rand() / RAND_MAX);
        }
    }

  k = 0;
  while (1)
    {
      gr_clearws();
      gr_setviewport(0.1, 0.95, 0.1, 0.95);
      gr_setwindow(k, k + POINTS, -20, 20);
      gr_setlinecolorind(1);
      gr_setcharheight(0.02);
      gr_axes(20, 1, k, -20, 5, 5, -0.01);
      for (j = 0; j < CURVES; j++)
        {
          gr_setlinecolorind(980 + j);
          gr_polyline(POINTS, x, y[j]);
        }
      gr_updatews();
      k++;
      for (i = 1; i < POINTS; i++)
        {
          x[i - 1] = x[i];
          for (j = 0; j < CURVES; j++) y[j][i - 1] = y[j][i];
        }
      x[POINTS - 1] = k + POINTS;
      for (j = 0; j < CURVES; j++) y[j][POINTS - 1] = y[j][POINTS - 2] + (-0.5 + (double)rand() / RAND_MAX);
    }
}
Exemplo n.º 3
0
int main(void) {
    int mesh = 0;
    int nx = 93;
    int ny = 64;
    int nz = 64;
    unsigned int stride_x = 1;
    unsigned int stride_y = nx;
    unsigned int stride_z = nx*ny;
    double step_x = 2.0/(nx-1);
    double step_y = 2.0*ny/nx/(ny-1)*1.5;
    double step_z = 2.0*nz/nx/(nz-1)*1.5;
    double offset_x = -step_x * (nx-1) / 2;
    double offset_y = -step_y * (ny-1) / 2;
    double offset_z = -step_z * (nz-1) / 2;
    float position[3] = {0, 0, 0};
    float direction[3] = {0, 0, 1};
    float up[3] = {0, 1, 0};
    float color[3] = {1, 1, 1};
    float scales[3] = {1, 1, 1};
    GR3_MC_DTYPE *data = malloc(nx * ny * nz * sizeof(GR3_MC_DTYPE));
    FILE *fp = fopen("mri.raw", "rb");
    assert(fp);
    assert(data);
    fread(data, 2, nx*ny*nz, fp);
    fclose(fp);
    {
        int ix, iy, iz;
        float input_max = 2000;
        GR3_MC_DTYPE dtype_max = (1UL << (8*sizeof(GR3_MC_DTYPE)))-1;
        for (iz = 0; iz < nz; iz++) {
            for (iy = 0; iy < ny; iy++) {
                for (ix = 0; ix < nx; ix++) {
                    if (data[nx*nz*iz+nx*iy+ix] > input_max) {
                        data[nx*nz*iz+nx*iy+ix] = input_max;
                    }
                    data[nx*ny*iz+nx*iy+ix] = (GR3_MC_DTYPE)(data[nx*nz*iz+nx*iy+ix]/input_max*dtype_max);
                }
            }
        }
    }
    gr_setviewport(0, 1, 0, 1);
    gr_setcolormap(1);
    gr3_init(NULL);
    
   gr3_createisosurfacemesh(&mesh, data, 40000,
                            nx, ny, nz,
                            stride_x, stride_y, stride_z,
                            step_x, step_y, step_z,
                            offset_x, offset_y, offset_z);
    gr3_cameralookat(-3, 3, -4, 0, 0, 0, -1, 0, 0);
    {
        int i;
        for (i = 0; i < 200; i++) {
            gr3_clear();
            gr3_drawmesh(mesh, 1, position, direction, up, color, scales);
            gr3_drawxslicemesh(data, i*nx/199, nx, ny, nz,
                               stride_x, stride_y, stride_z,
                               step_x, step_y, step_z,
                               offset_x, offset_y, offset_z);
            gr3_drawyslicemesh(data, i*ny/199, nx, ny, nz,
                               stride_x, stride_y, stride_z,
                               step_x, step_y, step_z,
                               offset_x, offset_y, offset_z);
            gr3_drawzslicemesh(data, i*nz/199, nx, ny, nz,
                               stride_x, stride_y, stride_z,
                               step_x, step_y, step_z,
                               offset_x, offset_y, offset_z);
            gr_clearws();
            gr3_drawimage(0, 1, 0, 1, 500, 500, GR3_DRAWABLE_GKS);
            gr_updatews();
        }
    }
    gr_setcolormap(19);
    {
        int i;
        for (i = 299; i >= 0; i--) {
            gr3_clear();
            gr3_drawmesh(mesh, 1, position, direction, up, color, scales);
            gr3_drawxslicemesh(data, i*nx/299, nx, ny, nz,
                               stride_x, stride_y, stride_z,
                               step_x, step_y, step_z,
                               offset_x, offset_y, offset_z);
            gr_clearws();
            gr3_drawimage(0, 1, 0, 1, 500, 500, GR3_DRAWABLE_GKS);
            gr_updatews();
        }
        for (i = 0; i < 300; i++) {
            gr3_clear();
            gr3_drawmesh(mesh, 1, position, direction, up, color, scales);
            gr3_drawyslicemesh(data, i*ny/299, nx, ny, nz,
                               stride_x, stride_y, stride_z,
                               step_x, step_y, step_z,
                               offset_x, offset_y, offset_z);
            gr_clearws();
            gr3_drawimage(0, 1, 0, 1, 500, 500, GR3_DRAWABLE_GKS);
            gr_updatews();
        }
        for (i = 299; i >= 0; i--) {
            gr3_clear();
            gr3_drawmesh(mesh, 1, position, direction, up, color, scales);
            gr3_drawzslicemesh(data, i*nz/299, nx, ny, nz,
                               stride_x, stride_y, stride_z,
                               step_x, step_y, step_z,
                               offset_x, offset_y, offset_z);
            gr_clearws();
            gr3_drawimage(0, 1, 0, 1, 500, 500, GR3_DRAWABLE_GKS);
            gr_updatews();
        }
    }
    gr3_deletemesh(mesh);
    free(data);
    gr3_terminate();
    return 0;
}
Exemplo n.º 4
0
void FORTRAN(gr_setviewport)(double *xmin, double *xmax, double *ymin, double *ymax)
{
  gr_setviewport(*xmin, *xmax, *ymin, *ymax);
}