Пример #1
0
void shape_copy_rotate(SHAPE_COPY *copy, int angle) {
	int i;

	if (!copy)
		return;

	memcpy(copy->rot, copy->coord, sizeof(int) * (copy->lines * 2 + 2));
	i = 0;
	rotate_coord(angle, &copy->rot[i * 2], &copy->rot[i * 2 + 1]);
	for (; i < copy->lines; i++) {
		rotate_coord(angle, &copy->rot[i * 2 + 2], &copy->rot[i * 2 + 3]);
		if (i < copy->lines)
			d_render_line_move(copy->line, i, copy->rot[i * 2], copy->rot[i * 2 + 1], copy->rot[i * 2 + 2], copy->rot[i * 2 + 3]);
	}

	return;
}
Пример #2
0
/* deal with events sent to the option window */
void    optionaction(W_Event * data)
{
  register struct option *op;
  int     i;
  register char *cp;

  if (data->y >= CurrentMenu->numopt)
    {
      W_Beep();
      return;
    }
  if (notdone == 0)
    return;

  op = &(CurrentMenu->menu[data->y]);

  /* Update string; don't claim keystrokes for non-string options */
  /* deal with options with string input first */
  if (op->op_string == 0)
    {
      if (data->type == W_EV_KEY)
  return;
    }
  else
    {
      if (data->type == W_EV_BUTTON)
  return;
      switch (data->key)
  {

  case '\b':         /* delete character */
  case '\177':
    cp = op->op_string;
    i = strlen(cp);
    if (i > 0)
      {
        cp += i - 1;
        *cp = '\0';
      }
    break;

  case '\027':         /* word erase */
    cp = op->op_string;
    i = strlen(cp);
    /* back up over blanks */
    while (--i >= 0 && isspace(cp[i]))
      ;
    i++;
    /* back up over non-blanks */
    while (--i >= 0 && !isspace(cp[i]))
      ;
    i++;
    cp[i] = '\0';
    break;

  case '\025':         /* kill line */
  case '\030':
    op->op_string[0] = '\0';
    break;

  default:         /* add character to the list
              *
              */
    if (data->key < 32 || data->key > 127)
      break;
    cp = op->op_string;
    i = strlen(cp);
    if (i < (op->op_size - 1) && !iscntrl(data->key))
      {
        cp += i;
        cp[1] = '\0';
        cp[0] = data->key;
      }
    else
      W_Beep();
    break;
  }
    }

  /* Toggle int, if it exists */
  if (op->op_array)
    {
      if (data->key == W_RBUTTON)
  {
    (*op->op_option)++;
    if (*(op->op_array)[*op->op_option] == '\0')
      {
        *op->op_option = 0;
      }
  }
      else if (data->key == W_MBUTTON)
  {
    /* set option number to zero on the middle key to ease shutoff */
    *op->op_option = 0;
  }
      else if (data->key == W_LBUTTON)
  {
    /* if left button, decrease option  */
    (*op->op_option)--;
    /* if decreased too far, set to top option */
    if (*(op->op_option) < 0)
      {
        *op->op_option = 0;
        while (*(op->op_array)[*op->op_option] != '\0')
    {
      (*op->op_option)++;
    }
        (*op->op_option)--;
      }
  }


      /* Actions to be taken when certain options are selected. (Yes, this is
       * * * a hack). */

      if (op->op_option == &plistStyle)
  {
    if (plistCustomLayout == 0 && plistStyle == 0)
      plistStyle = (data->key == W_LBUTTON) ? PLISTLASTSTYLE : 1;

    RedrawPlayerList();
  }
      else if (op->op_option == &showgalactic)
  {
    redrawall = 1;
  }

#ifdef ROTATERACE
      else if (rotate != old_rotate)
  {
    register i;
    register struct planet *l;
    register struct player *j;

    redrawall = 1;
    reinitPlanets = 1;

    for (i = 0, l = planets; i < MAXPLANETS; i++, l++)
      {
        if (rotate)
    {
      rotate_deg = -old_rotate_deg + rotate * 64;
      rotate_coord(&l->pl_x, &l->pl_y, rotate_deg, GWIDTH / 2, GWIDTH / 2);
      rotate_deg = rotate * 64;
    }
        else
    {
      rotate_deg = -old_rotate_deg;
      rotate_coord(&l->pl_x, &l->pl_y, rotate_deg, GWIDTH / 2, GWIDTH / 2);
      rotate_deg = 0;
    }
      }

    /* we could wait for the server to do this but looks better if we *
     *
     * * do it now. */
    for (i = 0, j = players; i < MAXPLAYER; i++, j++)
      {
        if (j->p_status != PALIVE)
    continue;
        if (rotate)
    {
      rotate_deg = -old_rotate_deg + rotate * 64;
      rotate_coord(&j->p_x, &j->p_y, rotate_deg,
             GWIDTH / 2, GWIDTH / 2);
      rotate_dir(&j->p_dir, rotate_deg);

      rotate_deg = rotate * 64;
    }
        else
    {
      rotate_deg = -old_rotate_deg;
      rotate_coord(&j->p_x, &j->p_y, rotate_deg,
             GWIDTH / 2, GWIDTH / 2);
      rotate_dir(&j->p_dir, rotate_deg);
      rotate_deg = 0;
    }
      }
    /* phasers/torps/etc .. wait for server */

    old_rotate = rotate;
    old_rotate_deg = rotate_deg;
  }
#endif

    }


  /* Does the button have a range of values? */

  else if (op->op_range)
    {
      if (data->key == W_RBUTTON)
  {
    (*op->op_option) += op->op_range->increment;
  }
      else if (data->key == W_MBUTTON)
  {
    (*op->op_option) = op->op_range->min_value;
  }
      else if (data->key == W_LBUTTON)
  {
    (*op->op_option) -= op->op_range->increment;
  }
      /* wrap value around within option range */
      if (*(op->op_option) > op->op_range->max_value)
  *(op->op_option) = op->op_range->min_value;
      if (*(op->op_option) < op->op_range->min_value)
  *(op->op_option) = op->op_range->max_value;
    }


  /* Is the option a toggle? */

#ifdef HAVE_XPM
  /* Bitwise Toggle  */

  else if ((op->op_option) && (op->op_size))
    {
      if (!(pixMissing & op->op_size))
  {
    *op->op_option ^= op->op_size;

    if (op->op_size & (NO_MAP_PIX | NO_BG_PIX | NO_HALOS))
      redrawall = 1;
  }
    }
#endif

  else if (op->op_option)
    {
      *op->op_option = !*op->op_option;

      /* Actions to be taken when certain options are selected. * (Yes, this
       * * is a hack). */

      if (op->op_option == &showPlanetOwner)
  redrawall = 1;
      else if (op->op_option == &partitionPlist)
  RedrawPlayerList();
      else if (op->op_option == &sortPlayers)
  RedrawPlayerList();
      else if (op->op_option == &sortMyTeamFirst)
  RedrawPlayerList();
    }

  /* Map/unmap window, if it exists */

  if (op->op_targetwin)
    {
      if (W_IsMapped(*op->op_targetwin))
  W_UnmapWindow(*op->op_targetwin);
      else
  {
    W_MapWindow(*op->op_targetwin);

    if (*op->op_targetwin == udpWin)
      udpwindow();
    if (*op->op_targetwin == pStats)
      redrawPStats();
    if (*op->op_targetwin == netstatWin)
      nswindow();
    if (*op->op_targetwin == spWin)
      spwindow();

#ifdef XTREKRC_HELP
    if (defWin && *op->op_targetwin == defWin)
      showdef();
#endif

#ifdef SOUND
    if (*op->op_targetwin == soundWin)
      soundwindow();
#endif

#ifdef DOC_WIN
    if (docwin && *op->op_targetwin == docwin)
      showdocs(0);

    if (xtrekrcwin && *op->op_targetwin == xtrekrcwin)
      showxtrekrc(0);
#endif
  }
    }

  /* deal with possible menu change */
  if (MenuPage != CurrentMenu->page_num)
    {
      SetMenuPage(MenuPage);
      RefreshOptions();
    }
  else if (notdone)
    optionrefresh(op);
  else
    {
      optionrefresh(op);
      optiondone();
    }

  return;
}
Пример #3
0
/* This is the gateway function between MATLAB and SSPROPVC.  It
 * serves as the main(). */
void mexFunction(int nlhs, mxArray *plhs[],
                 int nrhs, const mxArray *prhs[])
{ 
  COMPLEX *u0a, *u0b, *uafft, *ubfft, *uahalf, *ubhalf,
          *uva, *uvb, *u1a, *u1b;
  
  COMPLEX *ha, *hb;  /* exp{ (-Alpha(w)/2-jBeta(w)) z} */
  COMPLEX *h11, *h12,/* linear propgation coefficients */
          *h21, *h22;
    
  REAL dt;           /* time step */
  REAL dz;           /* propagation stepsize */
  int nz;            /* number of z steps to take */
  REAL gamma;        /* nonlinearity coefficient */
  REAL chi = 0.0;    /* degree of ellipticity  */
  REAL psi = 0.0;    /* angular orientation to x-axis  */
  int maxiter = 4;   /* max number of iterations */
  REAL tol = 1e-5;   /* convergence tolerance */

  int nt;            /* number of fft points */
  
  REAL* w;           /* vector of angular frequencies */

  PLAN p1a,p1b,ip1a,ip1b;   /* fft plans for 1st linear half */
  PLAN p2a,p2b,ip2a,ip2b;   /* fft plans for 2nd linear half */
  
  int converged;            /* holds the return of is_converged */
  char methodstr[11];       /* method name: 'circular or 'elliptical' */
  int elliptical = 1;       /* if elliptical method, then != 0 */

  char argstr[100];	 /* string argument */
  
  int iz,ii,jj;      /* loop counters */
  
  if (nrhs == 1) {
	if (mxGetString(prhs[0],argstr,100)) 
	  mexErrMsgTxt("Unrecognized option.");
	
	if (!strcmp(argstr,"-savewisdom")) {
	  sspropvc_save_wisdom();
	}
	else if (!strcmp(argstr,"-forgetwisdom")) {
	  FORGET_WISDOM();
	}
	else if (!strcmp(argstr,"-loadwisdom")) {
	  sspropvc_load_wisdom();
	}
	else if (!strcmp(argstr,"-patient")) {
	  method = FFTW_PATIENT;
	}
	else if (!strcmp(argstr,"-exhaustive")) {
	  method = FFTW_EXHAUSTIVE;
	}
	else if (!strcmp(argstr,"-measure")) {
	  method = FFTW_MEASURE;
	}
	else if (!strcmp(argstr,"-estimate")) {
	  method = FFTW_ESTIMATE;
	}
	else
	  mexErrMsgTxt("Unrecognized option.");
	return;
  }
  
  if (nrhs < 10) 
    mexErrMsgTxt("Not enough input arguments provided.");
  if (nlhs > 2)
    mexErrMsgTxt("Too many output arguments.");
  
  if (firstcall) {  /* attempt to load wisdom file on first call */
	sspropvc_load_wisdom();
    firstcall = 0;
  }

  /* parse input arguments */
  dt = (REAL) mxGetScalar(prhs[2]);
  dz = (REAL) mxGetScalar(prhs[3]);
  nz = round(mxGetScalar(prhs[4]));
  gamma = (REAL) mxGetScalar(prhs[9]);

  if (nrhs > 10) { /* default is chi = psi = 0.0 */
    psi = (REAL) mxGetScalar(prhs[10]); 
	if (mxGetNumberOfElements(prhs[10]) > 1)
	  chi = (REAL) (mxGetPr(prhs[10])[1]); 
  } 
 
  if (nrhs > 11) { /* default method is elliptical */
    if (mxGetString(prhs[11],methodstr,11)) /* fail */
      mexErrMsgTxt("incorrect method: elliptical or ciruclar only");
    else { /* success */
      if (!strcmp(methodstr,"circular"))
        elliptical = 0;
      else if(!strcmp(methodstr,"elliptical"))
        elliptical = 1;
      else
         mexErrMsgTxt("incorrect method: elliptical or ciruclar only");
    }
  }
    
  if (nrhs > 12) /* default = 4 */
	maxiter = round(mxGetScalar(prhs[12]));
  
  if (nrhs > 13) /* default = 1e-5 */
	tol = (REAL) mxGetScalar(prhs[13]);

  nt = mxGetNumberOfElements(prhs[0]);  /* # of points in vectors */
  
  /* allocate memory */
  u0a = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  u0b = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  uafft = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  ubfft = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  uahalf = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  ubhalf = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  uva = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  uvb = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  u1a = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  u1b = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  ha = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  hb = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  h11 = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  h12 = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  h21 = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  h22 = (COMPLEX*) mxMalloc(sizeof(COMPLEX)*nt);
  w = (REAL*)mxMalloc(sizeof(REAL)*nt);
  plhs[0] = mxCreateDoubleMatrix(nt,1,mxCOMPLEX);
  plhs[1] = mxCreateDoubleMatrix(nt,1,mxCOMPLEX);
  
  /* fftw3 plans */
  p1a = MAKE_PLAN(nt, u0a, uafft, FFTW_FORWARD, method);
  p1b = MAKE_PLAN(nt, u0b, ubfft, FFTW_FORWARD, method);
  ip1a = MAKE_PLAN(nt, uahalf, uahalf, FFTW_BACKWARD, method);
  ip1b = MAKE_PLAN(nt, ubhalf, ubhalf, FFTW_BACKWARD, method);
  p2a = MAKE_PLAN(nt, uva, uva, FFTW_FORWARD, method);
  p2b = MAKE_PLAN(nt, uvb, uvb, FFTW_FORWARD, method);
  ip2a = MAKE_PLAN(nt, uafft, uva, FFTW_BACKWARD, method);
  ip2b = MAKE_PLAN(nt, ubfft, uvb, FFTW_BACKWARD, method);

  allocated = 1;
  
  /* Compute vector of angular frequency components
   * MATLAB equivalent:  w = wspace(tv); */
  compute_w(w,dt,nt);
  
  /* Compute ha & hb vectors
   * ha = exp[(-alphaa(w)/2 - j*betaa(w))*dz/2])
   * hb = exp[(-alphab(w)/2 - j*betab(w))*dz/2]) 
   * prhs[5]=alphaa  prhs[6]=alphab  prhs[7]=betaa  prhs[8]=betab */
  compute_hahb(ha,hb,prhs[5],prhs[6],prhs[7],prhs[8],w,dz,nt);
  
  mexPrintf("Performing split-step iterations ... ");
  
  if (elliptical) { /* Elliptical Method */
    
    /* Rotate to eignestates of fiber 
     *   u0a = ( cos(psi)*cos(chi) - j*sin(psi)*sin(chi))*u0x + ...
     *         ( sin(psi)*cos(chi) + j*cos(psi)*sin(chi))*u0y;
     *   u0b = (-sin(psi)*cos(chi) + j*cos(psi)*sin(chi))*u0x + ...
     *         ( cos(psi)*cos(chi) + j*sin(psi)*sin(chi))*u0y;
     */
    rotate_coord(u0a,u0b,prhs[0],prhs[1],chi,psi,nt);
      
    cscale(u1a,u0a,u1b,u0b,1.0,nt); /* u1a=u0a  u1b=u0b */
    
    EXECUTE(p1a);  /* uafft = fft(u0a) */
    EXECUTE(p1b);  /* ubfft = fft(u0b) */
    
    for(iz=1; iz <= nz; iz++)
    {
      /* Linear propagation (1st half):
       * uahalf = ha .* uafft
       * ubhalf = hb .* ubfft */
      prop_linear_ellipt(uahalf,ubhalf,ha,hb,uafft,ubfft,nt);
      
      EXECUTE(ip1a);  /* uahalf = ifft(uahalf) */
      EXECUTE(ip1b);  /* ubhalf = ifft(ubhalf) */
      
      /* uahalf=uahalf/nt  ubhalf=ubhalf/nt */
      cscale(uahalf,uahalf,ubhalf,ubhalf,1.0/nt,nt);
  
      ii = 0;
      do
      {
        /* Calculate nonlinear section: output=uva,uvb */
        nonlinear_propagate(uva,uvb,uahalf,ubhalf,u0a,u0b,u1a,u1b,
                            gamma,dz,chi,nt);
        
      
        EXECUTE(p2a);  /* uva = fft(uva) */
        EXECUTE(p2b);  /* uvb = fft(uvb) */
      
        /* Linear propagation (2nd half):
         * uafft = ha .* uva
         * ubfft = hb .* uvb */
         prop_linear_ellipt(uafft,ubfft,ha,hb,uva,uvb,nt);
     
        EXECUTE(ip2a);  /* uva = ifft(uafft) */
        EXECUTE(ip2b);  /* uvb = ifft(ubfft) */
        
        /* Check if uva & u1a  and  uvb & u1b converged 
         * converged = ( ( sqrt(norm(uva-u1a,2).^2+norm(uvb-u1b,2).^2) /...
         *                 sqrt(norm(u1a,2).^2+norm(u1b,2).^2) ) < tol )
         */
        converged = is_converged(uva,u1a,uvb,u1b,tol,nt);
      
        /* u1a=uva/nt  u1b=uvb/nt */
        cscale(u1a,uva,u1b,uvb,1.0/nt,nt);
      
        ii++;
      } while(!converged && ii < maxiter);  /* end convergence loop */
    
      if(ii == maxiter)
        mexPrintf("Warning: Failed to converge to %f in %d iterations\n",
                  tol,maxiter);
    
      /* u0a=u1a  u0b=u1b */
      cscale(u0a,u1a,u0b,u1b,1.0,nt);

    } /* end step loop */
    
    /* Rotate back to original x-y basis
     *  u1x = ( cos(psi)*cos(chi) + j*sin(psi)*sin(chi))*u1a + ...
     *        (-sin(psi)*cos(chi) - j*cos(psi)*sin(chi))*u1b;
     *  u1y = ( sin(psi)*cos(chi) - j*cos(psi)*sin(chi))*u1a + ...
     *        ( cos(psi)*cos(chi) - j*sin(psi)*sin(chi))*u1b;
     */
    inv_rotate_coord(plhs[0],plhs[1],u1a,u1b,chi,psi,nt);
    
  } 
  else {  /* Circular method */ 
    
    /* Compute H matrix = [ h11 h12 
     *                      h21 h22 ] for linear propagation
     *   h11 = ( (1+sin(2*chi))*ha + (1-sin(2*chi))*hb )/2;
     *   h12 = -j*exp(+j*2*psi)*cos(2*chi)*(ha-hb)/2;
     *   h21 = +j*exp(-j*2*psi)*cos(2*chi)*(ha-hb)/2;
     *   h22 = ( (1-sin(2*chi))*ha + (1+sin(2*chi))*hb )/2;
     */
    compute_H(h11,h12,h21,h22,ha,hb,chi,psi,nt);
      
    /* Rotate to circular coordinate system 
     *   u0a = (1/sqrt(2)).*(u0x + j*u0y);
     *   u0b = (1/sqrt(2)).*(j*u0x + u0y); */
    rotate_coord(u0a,u0b,prhs[0],prhs[1],pi/4,0,nt);
      
    cscale(u1a,u0a,u1b,u0b,1.0,nt); /* u1a=u0a  u1b=u0b */
    
    EXECUTE(p1a);  /* uafft = fft(u0a) */
    EXECUTE(p1b);  /* ubfft = fft(u0b) */
      
    for(iz=1; iz <= nz; iz++)
    {
      /* Linear propagation (1st half):
       * uahalf = h11 .* uafft + h12 .* ubfft
       * ubhalf = h21 .* uafft + h22 .* ubfft */
      prop_linear_circ(uahalf,ubhalf,h11,h12,h21,h22,uafft,ubfft,nt);
      
      EXECUTE(ip1a);  /* uahalf = ifft(uahalf) */
      EXECUTE(ip1b);  /* ubhalf = ifft(ubhalf) */
      
      /* uahalf=uahalf/nt  ubhalf=ubhalf/nt */
      cscale(uahalf,uahalf,ubhalf,ubhalf,1.0/nt,nt);
  
      ii = 0;
      do
      {
        /* Calculate nonlinear section: output=uva,uvb */
         nonlinear_propagate(uva,uvb,uahalf,ubhalf,u0a,u0b,u1a,u1b,
                             gamma,dz,pi/4,nt);
      
        EXECUTE(p2a);  /* uva = fft(uva) */
        EXECUTE(p2b);  /* uvb = fft(uvb) */
      
        /* Linear propagation (2nd half):
         * uafft = h11 .* uva + h12 .* uvb
         * ubfft = h21 .* uva + h22 .* uvb */
        prop_linear_circ(uafft,ubfft,h11,h12,h21,h22,uva,uvb,nt);
     
        EXECUTE(ip2a);  /* uva = ifft(uafft) */
        EXECUTE(ip2b);  /* uvb = ifft(ubfft) */
      
        /* Check if uva & u1a  and  uvb & u1b converged 
         *   ( sqrt(norm(uva-u1a,2).^2+norm(uvb-u1b,2).^2) /...
         *     sqrt(norm(u1a,2).^2+norm(u1b,2).^2) ) < tol
         */
        converged = is_converged(uva,u1a,uvb,u1b,tol,nt);
      
        /* u1a=uva/nt  u1b=uvb/nt */
        cscale(u1a,uva,u1b,uvb,1.0/nt,nt);
      
        ii++;
      } while(!converged && ii < maxiter);  /* end convergence loop */
    
      if(ii == maxiter)
        mexPrintf("Warning: Failed to converge to %f in %d iterations\n",
                  tol,maxiter);
    
      /* u0a=u1a  u0b=u1b */
      cscale(u0a,u1a,u0b,u1b,1.0,nt);

    } /* end step loop */
    
    /* Rotate back to orignal x-y basis
     *   u1x = (1/sqrt(2)).*(u1a-j*u1b) ;
     *   u1y = (1/sqrt(2)).*(-j*u1a+u1b) ; */
    inv_rotate_coord(plhs[0],plhs[1],u1a,u1b,pi/4,0,nt);
    
  } /* end circular method */      
  

  mexPrintf("done.\n");

  if (allocated) {
    /* destroy fftw3 plans */
    DESTROY_PLAN(p1a);
    DESTROY_PLAN(p1b);
    DESTROY_PLAN(ip1a);
    DESTROY_PLAN(ip1b);
    DESTROY_PLAN(p2a);
    DESTROY_PLAN(p2b);
    DESTROY_PLAN(ip2a);
    DESTROY_PLAN(ip2b);

    /* de-allocate memory */
    mxFree(u0a);
    mxFree(u0b);
    mxFree(uafft);
    mxFree(ubfft);
    mxFree(uahalf);
    mxFree(ubhalf);
    mxFree(uva);
    mxFree(uvb);
    mxFree(u1a);
    mxFree(u1b);
    mxFree(ha);
    mxFree(hb);
    mxFree(h11);
    mxFree(h12);
    mxFree(h21);
    mxFree(h22);
    mxFree(w);
    
    allocated = 0;
  }
} /* end mexFunction */
Пример #4
0
void
rotate_gcenter(int *x, int *y)
{
    rotate_coord(x, y, rotate_deg, blk_gwidth / 2, blk_gwidth / 2);
}