예제 #1
0
파일: matplot.c 프로젝트: B-Rich/tcoffee
/* rainbow_ramp: converts a double value X to a colour in RGB
 * representation according to the following approx. scheme:
 * 
 * Colour  <--Black  Blue  Cyan   Green  Yellow  Red  White-->
 *                    |	    |       |       |      |
 * X (relative)       0 ...1/4.....1/2.....3/4.....1
 * X (absolute)      Lowval.....................Upval
 * Return value: a 32-bit integer that contains the RGB info
 * in the SGI order: MSB:alpha, blue, green, red:LSB where
 * the alpha byte is always FF (maximal transparency).
 * If Upval==Lowval, then black is returned.
 */
static unsigned long rainbow_ramp(double X, double Lowval, double Upval)
{
    const unsigned long PURE_WHITE=0xFFFFFFFFL, 
			PURE_BLACK=0xFF000000L, 
			GREEN_SHIFT=0x00000100L, 
			BLUE_SHIFT=0x00010000L;

    unsigned long Col=PURE_BLACK;
    
    if (Upval==Lowval) return(PURE_BLACK);
    
    /* rescale: Lowval=0, Upval=1 */
    X=(X-Lowval)/(Upval-Lowval);
    if (X<0) return(PURE_BLACK);    /* outside range */
    if (X>1) return(PURE_WHITE);
    
    /* find ranges, set colours */
    if (X<=0.25)    /* blue...cyan: full blue+green grows */
	Col+=255*BLUE_SHIFT+(char)round_id(1020*X)*GREEN_SHIFT;
    else if (X>0.25 && X<=0.5)	/* cyan..green: full green+blue shrinks */
	Col+=255*GREEN_SHIFT+(char)round_id(1020*(0.5-X))*BLUE_SHIFT;
    else if (X>0.5 && X<=0.75)	/* green..yellow: full green+red grows */
	Col+=255*GREEN_SHIFT+(char)round_id(1020*(X-0.5));
    else			/* yellow..red: full red+green shrinks */
	Col+=255+(char)round_id(1020*(1.0-X))*GREEN_SHIFT;

    return(Col);
}
예제 #2
0
  void Session::HandlePrepare(const Request &notification)
  {
    if(_prepare_waiting) {
      _prepare_waiting = false;
    }

    QVariantHash msg = notification.GetData().toHash();

    if(_current_round && !_current_round->Stopped() && _current_round->Started()) {
      _prepare_waiting = true;
      _prepare_notification = notification;
      if(msg.value("interrupt").toBool()) {
        _current_round->Stop("Round interrupted.");
      }
      return;
    }

    QByteArray brid = msg.value("round_id").toByteArray();
    if(brid.isEmpty()) {
      qDebug() << "HandlePrepare: Invalid round id";
      return;
    }

    Id round_id(brid);

    if(msg.contains("group")) {
      QDataStream stream(msg.value("group").toByteArray());
      Group group;
      stream >> group;
      qDebug() << "Prepare contains new group. I am present:" <<
        group.Contains(GetPrivateIdentity().GetLocalId());
      _group_holder->UpdateGroup(group);
    }
예제 #3
0
파일: matplot.c 프로젝트: B-Rich/tcoffee
/* init_matplot: initialises distmat plotting. The matrix size should
 * be Row x Col (which is the min. size in pixels). Title is put on the top
 * of the window by the window manager. Xorig and Yorig specify
 * the lower left corner position of the window: if either of them
 * is negative, then the window will be positioned interactively.
 * Return value: the 'gid' window ID number.
 */
long init_matplot(unsigned int Row, unsigned int Col, char *Title, 
	long Xorig, long Yorig)
{
    const unsigned int MINSIZE=500;
    
    long Gid, Xsize, Ysize, Xmax, Ymax;
    float Xmagnif, Ymagnif;
    unsigned int Rs, Cs;
    
    if (!Row) Row=MINSIZE;
    if (!Col) Col=MINSIZE;
    
    Xmagnif=(float)Col/MINSIZE;
    Ymagnif=(float)Row/MINSIZE;
    Rs=Row; Cs=Col;
    if (Col<=Row)
    {
	if (Xmagnif<1.0)
	{
	    Cs=MINSIZE;
	    Rs=round_id(Row/Xmagnif);
	}
    }
    else
    {
	if (Ymagnif<1.0)
	{
	    Rs=MINSIZE;
	    Cs=round_id(Col/Ymagnif);
	}
    }
    
    foreground();	/* enable signal catch etc. */
    Xmax=getgdesc(GD_XPMAX); Ymax=getgdesc(GD_YPMAX);
    keepaspect(Col, Row);

    /* Xmax,Ymax: the maximal screen coordinates */
    Xmax=getgdesc(GD_XPMAX); Ymax=getgdesc(GD_YPMAX);
    if (Xorig+Cs>Xmax) Xorig=Xmax-Cs;
    if (Yorig+Rs>Ymax) Yorig=Ymax-Rs;
    if (Xorig>=0 && Yorig>=0)
	prefposition(Xorig, Xorig+Cs, Yorig, Yorig+Rs);
    iconsize(84, 67);
    Gid=winopen(Title);	/* create window */
    
    RGBmode();
    /* check if double buffering is available */
    if (Dblbuffer=getgdesc(GD_BITS_NORM_DBL_BLUE))
    { doublebuffer(); gconfig(); }
    else fputs("init_matplot: single-buffer mode\n", stderr);

    /* enable resize */
    winconstraints();
    keepaspect(Col, Row);
    winconstraints();
    
    getsize(&Xsize, &Ysize);    /* scale drawing into window */
    Xmagnif=(float)Xsize/Col;
    Ymagnif=(float)Ysize/Row;
    pushmatrix();
    scale(Xmagnif, Ymagnif, 1.0);
    cpack(RGB_BLACK); clear();          /* clears window to black */
    if (Dblbuffer) { swapbuffers(); cpack(RGB_BLACK); clear(); }
    
    /* queue input events */
    qdevice(ESCKEY); qdevice(WINFREEZE); qdevice(WINTHAW);
    qdevice(REDRAWICONIC); qdevice(WINQUIT);
    
    return(Gid);
}