Esempio n. 1
0
void cart_makecart(double *pointx, double *pointy, int npoints,
		   int xsize, int ysize, double blur)
{
  int s,sp;
  int step;
  double t,h;
  double error,dr;
  double desiredratio;

  /* Calculate the initial density and velocity for snapshot zero */

  cart_density(0.0,0,xsize,ysize);
  cart_vgrid(0,xsize,ysize);
  s = 0;

  /* Now integrate the points in the polygons */

  step = 0;
  t = 0.5*blur*blur;
  h = INITH;

  do {

    /* Do a combined (triple) integration step */

    cart_twosteps(pointx,pointy,npoints,t,h,s,xsize,ysize,&error,&dr,&sp);

    /* Increase the time by 2h and rotate snapshots */

    t += 2.0*h;
    step += 2;
    s = sp;

    /* Adjust the time-step.  Factor of 2 arises because the target for
     * the two-step process is twice the target for an individual step */

    desiredratio = pow(2*TARGETERROR/error,0.2);
    if (desiredratio>MAXRATIO) h *= MAXRATIO;
    else h *= desiredratio;

    /* If no point moved then we are finished */

  } while (dr>0.0);

}
Esempio n. 2
0
void cart_makecart(double *pointx, double *pointy, int npoints,
		   int xsize, int ysize, options_t *options)
{
  int i;
  int s,sp;
  int step;
  int done;
  double t,h,prev_h;
  double error,dr;
  double desiredratio, chosenratio;
  double *pointx_copy, *pointy_copy;

  pointx_copy = malloc(npoints * sizeof(double));
  pointy_copy = malloc(npoints * sizeof(double));

  /* Calculate the initial velocity for snapshot zero */

  s = 0;

  /* Now integrate the points in the polygons */

  step = 0;
  t = 0.5*options->blur*options->blur;
  h = INITH;

  do {

    /* Do a combined (triple) integration step */

    memcpy(pointx_copy, pointx, npoints * sizeof(double));
    memcpy(pointy_copy, pointy, npoints * sizeof(double));
    cart_twosteps(pointx, pointy, npoints, t, h, s, xsize, ysize, &error, &dr, &sp);

    while(error > MAXERROR) {
      h /= 2;
      if (options->progress_mode == DETAILED)
        fprintf(stderr, "dr = %g and error = %g, so retrying with h = %g\n", dr, error, h);
    
      memcpy(pointx, pointx_copy, npoints * sizeof(double));
      memcpy(pointy, pointy_copy, npoints * sizeof(double));
      cart_twosteps(pointx,pointy,npoints,t,h,s,xsize,ysize,&error,&dr,&sp);
    }

    /* Increase the time by 2h and rotate snapshots */

    t += 2.0*h;
    step += 2;
    s = sp;

    /* Adjust the time-step.  Factor of 2 arises because the target for
     * the two-step process is twice the target for an individual step */

    desiredratio = pow(2 * TARGETERROR / error, 0.2);
    if (desiredratio > MAXRATIO) chosenratio = MAXRATIO;
    else chosenratio = desiredratio;
    
    prev_h = h;
    if (h * chosenratio <= options->max_h)
      h *= chosenratio;
    else
      fprintf(stderr, "h * chosenratio = %g, which is > max_h = %g\n", h * chosenratio, options->max_h);

    done = cart_complete(t);
    switch (options->progress_mode) {
      case NONE:
        break;
      case NORMAL:
        fprintf(stderr,"  %3i%%  |",done);
        for (i=0; i < done/2; i++) fprintf(stderr,"=");
        for (i=done/2; i < 50; i++) fprintf(stderr," ");
        fprintf(stderr,"|\r");
        break;
      case PERCENT:
        fprintf(stderr, "%i\n",done);
        break;
      case DETAILED:
        fprintf(stderr, "step=%d, t=%g, h=%g, dr=%g, error=%g, done=%d%%\n", step, t, h, dr, error, done);
        break;
    }
    
    /* If no point moved then we are finished */

  } while (dr > 0.0);

  switch (options->progress_mode) {
    case PERCENT:
      fprintf(stderr, "\n");
      break;
    case NORMAL:
      fprintf(stderr,"  100%%  |==================================================|\n");
      break;
    default:
      break;
  }
  
  free(pointx_copy);
  free(pointy_copy);
}
/* Function to do the transformation of the given set of points
 * to the cartogram */
void cart_makecart(double *pointx, double *pointy, int npoints,
				   int xsize, int ysize, double blur)
{
	int i;
	int s,sp;
	int step;
	int done;
	double t,h;
	double error,dr;
	double desiredratio;
	
	/* Calculate the initial density and velocity for snapshot zero */
	
	cart_density(0.0,0,xsize,ysize);
	cart_vgrid(0,xsize,ysize);
	s = 0;
	
	/* Now integrate the points in the polygons */
	
	step = 0;
	t = 0.5*blur*blur;
	h = INITH;
	
	do {
		
		/* Do a combined (triple) integration step */
		
		cart_twosteps(pointx,pointy,npoints,t,h,s,xsize,ysize,&error,&dr,&sp);
		
		/* Increase the time by 2h and rotate snapshots */
		
		t += 2.0*h;
		step += 2;
		s = sp;
		
		/* Adjust the time-step.  Factor of 2 arises because the target for
		 * the two-step process is twice the target for an individual step */
		
		desiredratio = pow(2*TARGETERROR/error,0.2);
		if (desiredratio>MAXRATIO) h *= MAXRATIO;
		else h *= desiredratio;
		
		done = cart_complete(t);
#ifdef PERCENT
		fprintf(stdout,"%i\n",done);
#endif
#ifndef NOPROGRESS
		fprintf(stderr,"  %3i%%  |",done);
		for (i=0; i<done/2; i++) fprintf(stderr,"=");
		for (i=done/2; i<50; i++) fprintf(stderr," ");
		fprintf(stderr,"|\r");
#endif
		
		/* If no point moved then we are finished */
		
	} while (dr>0.0);
	
#ifdef PERCENT
	fprintf(stdout,"\n");
#endif
#ifndef NOPROGRESS
	fprintf(stderr,"  100%%  |==================================================|\n");
#endif
}