Exemple #1
0
static void edit_layout(void)
{
    char *cmd;
    int editing = 1;
    
    do {
	show_layout();
    	
	printf("\nLayout options:  D)imensions, P)osition, B)ack:  ");

	cmd = getLine();
	switch(toupper(*cmd)) {
	    case 'D':
		number("\nNumber of columns", &mn.ncol, 1, 80/MAX_IMAGE_NAME);
		number("Entries per column", &mn.maxcol, 1, 30);
		if (mn.ncol > 1) {
		    getXY("Column pitch", &mn.xpitch, 8, 0);
		    number("Spill threshold", &mn.mincol, 1, mn.maxcol);
		}
		break;
	    case 'P':
		getXY("\nTable UL column", &mn.col, 8, 1);
		getXY("Table UL row", &mn.row, 16, 1);
		break;
	    case 'B':
	    	editing = 0;
	    	break;
	    default:
	    	printf("???");
	}
	free(cmd);
	printf("\n");
    } while (editing);
}
void CMapProjectionManagerUTM::drawLongitude(float l,float b0,float b1,CDC* pDC)
{
	CPoint pt;
	getXY(l,b0,pt.x,pt.y);
	pDC->MoveTo(pt);
	for (float bt=b0;bt<b1;bt=bt+0.5)
	{
		CGeographicalPoint gpt(l,bt);
		getXY(gpt.L,gpt.B,pt.x,pt.y);
		pDC->LineTo(pt);
	}
}
void CMapProjectionManagerUTM::drawLatitude(float b,float l0,float l1,CDC* pDC)
{
	CPoint pt;
	getXY(l0,b,pt.x,pt.y);
	pDC->MoveTo(pt);
	for (float lt=l0;lt<l1;lt=lt+0.5)
	{
		CGeographicalPoint gpt(lt,b);
		getXY(gpt.L,gpt.B,pt.x,pt.y);
		pDC->LineTo(pt);
	}
}
Exemple #4
0
static void edit_timer(void)
{
    char *cmd;
    int editing = 1;
    
    do {
    	if (timer) printf("\nTimer colors:\n");
    	show_timer();
    	printf("\nTimer setup:  ");
    	
	if (timer) printf("C)olors, P)osition, D)isable");
	else printf("E)nable");
	
	printf(", B)ack:  ");
	
	cmd = getLine();
	
	if (timer) switch(toupper(*cmd)) {
	    case 'C':
		get3colors("Timer", &mn.t_fg);
		break;
	    case 'D':
		while (timer) {
		    mn.t_row -= 480;
		}
		break;
	    case 'P':
		getXY("\nTimer col", &mn.t_col, 8, 1);
		getXY("Timer row", &mn.t_row, 16, 1);
		break;
	    case 'B':
		editing = 0;
		break;
	    default:
	    	printf("???");
	}
	else switch(toupper(*cmd)) {
	    case 'E':
		while (!timer) {
		    mn.t_row += 480;
		}
		break;
	    case 'B':
		editing = 0;
		break;
	    default:
	    	printf("???");
	}
	free(cmd);
	printf("\n");
    } while (editing);
}
QString Perfboard::genFZP(const QString & moduleid)
{
	QString ConnectorFzpTemplate = "";
	QString FzpTemplate = "";

	if (ConnectorFzpTemplate.isEmpty()) {
		QFile file(":/resources/templates/perfboard_connectorFzpTemplate.txt");
		file.open(QFile::ReadOnly);
		ConnectorFzpTemplate = file.readAll();
		file.close();
	}
	if (FzpTemplate.isEmpty()) {
		QFile file(":/resources/templates/perfboard_fzpTemplate.txt");
		file.open(QFile::ReadOnly);
		FzpTemplate = file.readAll();
		file.close();
	}

	QString size = moduleid;
	size.remove(ModuleIDNames::PerfboardModuleIDName);
	int x, y;
	getXY(x, y, size);

	QString middle;

	for (int iy = 0; iy < y; iy++) {
		for (int jx = 0; jx < x; jx++) {
			middle += ConnectorFzpTemplate.arg(jx).arg(iy).arg(QString::number((iy * ConnectorIDJump) + jx));
		}
	}

	return FzpTemplate.arg(x).arg(y).arg(middle);
}
/*
 * Wrap the getQChi function so that it can be called from python
 */
static PyObject * DiffractionAnalysisWrap_getXY(PyObject *self, PyObject *args) {
    double centerX, centerY,distance,energy,alpha,beta,rotation;
    double q,chi;
    double pixelLength,pixelHeight;
    double cos_beta,sin_beta,cos_alpha,sin_alpha,cos_rotation,sin_rotation;
    double xPixel,yPixel;

    cos_beta = sin_beta=-10;
    cos_alpha=sin_alpha = -10;
    cos_rotation=sin_rotation= -10;

    PyArg_ParseTuple(args,"ddddddddddd|dddddd",&centerX,
            &centerY,&distance,&energy,&alpha,&beta,&rotation,&q,
            &chi,&pixelLength,&pixelHeight,&cos_beta,
            &sin_beta,&cos_alpha,&sin_alpha,&cos_rotation,&sin_rotation);

    if (cos_beta == -10) cos_beta  = cos(beta*PI/180.0);
    if (sin_beta == -10) sin_beta  = sin(beta*PI/180.0);
    if (cos_alpha == -10) cos_alpha = cos(alpha*PI/180.0);
    if (sin_alpha == -10) sin_alpha = sin(alpha*PI/180.0);
    if (cos_rotation == -10) cos_rotation = cos(rotation*PI/180.0);
    if (sin_rotation == -10) sin_rotation = sin(rotation*PI/180.0);
    
    getXY(centerX,centerY,distance,energy,q,chi,
            pixelLength,pixelHeight,rotation,cos_beta,sin_beta,
            cos_alpha,sin_alpha,cos_rotation,sin_rotation,
            &xPixel,&yPixel);

    return Py_BuildValue("dd",xPixel,yPixel);
}
void nextLine()
{
	unsigned short x, y;
	getXY(&x, &y);
	setXY(0, y + 1);
	if(position > SCREEN_WIDTH * SCREEN_HEIGHT - 1)
		scrollScreen();
}
QString Perfboard::makeBreadboardSvg(const QString & size) 
{
	QString BreadboardLayerTemplate = "";
	QString ConnectorTemplate = "";

	if (BreadboardLayerTemplate.isEmpty()) {
		QFile file(":/resources/templates/perfboard_boardLayerTemplate.txt");
		file.open(QFile::ReadOnly);
		BreadboardLayerTemplate = file.readAll();
		file.close();
	}
	if (ConnectorTemplate.isEmpty()) {
		QFile file(":/resources/templates/perfboard_connectorTemplate.txt");
		file.open(QFile::ReadOnly);
		ConnectorTemplate = file.readAll();
		file.close();
	}

	int x, y;
	getXY(x, y, size);

	QString middle;
	QString holes;
	double radius = 17.5;
	int sweepflag = 0;

	int top = 100;
	for (int iy = 0; iy < y; iy++) {
		int left = 100;
		for (int jx = 0; jx < x; jx++) {
			middle += ConnectorTemplate.arg(left).arg(top).arg(jx).arg(iy).arg(QString::number((iy * ConnectorIDJump) + jx));
			holes += OneHole				
				.arg(left - radius)
				.arg(top)
				.arg(radius)
				.arg(2 * radius)
				.arg(sweepflag);

			left += 100;
		}
		top += 100;
	}

	QString svg = BreadboardLayerTemplate
					.arg((x / 10.0) + 0.1)
					.arg((y / 10.0) + 0.1)
					.arg((x * 100) + 100)
					.arg((y * 100) + 100)
					.arg(holes)
					.arg(x * 100 - 8 + 100)
					.arg(y * 100 - 8 + 100)
					.arg(middle);

	return svg;
}
void Perfboard::enableSetButton() {
	QLineEdit * edit = qobject_cast<QLineEdit *>(sender());
	if (edit == NULL) return;

	int x, y;
	getXY(x, y, m_size);

	int vx = m_xEdit->text().toInt();
	int vy = m_yEdit->text().toInt();

	m_setButton->setEnabled(vx != x || vy != y);
}
Exemple #10
0
int best(int x=0,int y=0)
{
	int o = getXY(x,y);
	
	if (o>=sizeof(t)/sizeof(*t)) return 0;
	
	if (bests[o] != -1) return bests[o];
	
	int a1 = best(x+1,y);
	int a2 = best(x+1,y+1);
	
	int r = (a1<a2 ? a2 : a1)+t[o];
	
	bests[o] = r;
	
	return r;
}
Exemple #11
0
bool Map::movePlayer (Player* player, char step)
{
	int x;
	int y;
	getXY(step, x, y);
	debug(LOG_SERVER, String::format("move player %i:%i (current: %i:%i)", x, y, player->getCol(), player->getRow()));
	// move player and move touching packages
	const int targetCol = player->getCol() + x;
	const int targetRow = player->getRow() + y;
	MapTile* package = getPackage(targetCol, targetRow);
	if (package != nullptr) {
		const int pCol = targetCol + x;
		const int pRow = targetRow + y;
		if (!isFree(pCol, pRow)) {
			debug(LOG_SERVER, "can't move here - can't move package. target field is blocked");
			return false;
		}
		if (!package->setPos(pCol, pRow)) {
			debug(LOG_SERVER, "failed to move the package - thus can't move the player");
			return false;
		}
		debug(LOG_SERVER, String::format("moved package %i", package->getID()));
		increasePushes();
		rebuildField();
		if (isTarget(pCol, pRow)) {
			package->setState(CavePackerEntityStates::DELIVERED);
			debug(LOG_SERVER, String::format("mark package as delivered %i", package->getID()));
		} else if (package->getState() == CavePackerEntityStates::DELIVERED) {
			debug(LOG_SERVER, String::format("reset package state %i", package->getID()));
			package->setState(CavePackerEntityStates::NONE);
		}
		// sokoban standard - if a package was moved, the move char is uppercase
		step = toupper(step);
	}
	if (!player->setPos(targetCol, targetRow)) {
		debug(LOG_SERVER, "failed to move the player");
		return false;
	}

	player->storeStep(step);
	increaseMoves();
	return true;
}
Exemple #12
0
void Robot::resetRobot()
{
    resetSpeeds();
    dBodySetLinearVel(chassis->body,0,0,0);
    dBodySetAngularVel(chassis->body,0,0,0);
    dBodySetLinearVel(dummy->body,0,0,0);
    dBodySetAngularVel(dummy->body,0,0,0);
    dBodySetLinearVel(kicker->box->body,0,0,0);
    dBodySetAngularVel(kicker->box->body,0,0,0);
    for (int i=0;i<4;i++)
    {
        dBodySetLinearVel(wheels[i]->cyl->body,0,0,0);
        dBodySetAngularVel(wheels[i]->cyl->body,0,0,0);
    }
    float x,y;
    getXY(x,y);
    setXY(x,y);
    if (m_dir==-1) setDir(180);
    else setDir(0);
}
Exemple #13
0
void Perfboard::changeBoardSize() 
{
	if (!m_gotWarning) {
		int x = m_xEdit->text().toInt();
		int y = m_yEdit->text().toInt();
		if (x * y >= WarningSize) {
			m_gotWarning = true;
			QMessageBox messageBox(NULL);
			messageBox.setWindowTitle(tr("Performance Warning"));
			messageBox.setText(tr("Performance of perfboards and stripboards with more than approximately 2000 holes can be slow. Are you sure ?\n"
				"\nNote: this warning will not be repeated during this session."
				));
			messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
			messageBox.setDefaultButton(QMessageBox::Cancel);
			messageBox.setIcon(QMessageBox::Warning);
			messageBox.setWindowModality(Qt::WindowModal);
			messageBox.setButtonText(QMessageBox::Ok, tr("Set new size"));
			messageBox.setButtonText(QMessageBox::Cancel, tr("Cancel"));
			QMessageBox::StandardButton answer = (QMessageBox::StandardButton) messageBox.exec();

			if (answer != QMessageBox::Ok) {
				getXY(x, y, m_size);
				m_xEdit->setText(QString::number(x));
				m_yEdit->setText(QString::number(y));
				return;
			}
		}
	}


	QString newSize = QString("%1.%2").arg(m_xEdit->text()).arg(m_yEdit->text());
    m_propsMap.insert("size", newSize);

    InfoGraphicsView * infoGraphicsView = InfoGraphicsView::getInfoGraphicsView(this);
    if (infoGraphicsView != NULL) {
        infoGraphicsView->swap(family(), "size", m_propsMap, this);
    }
}
int fitPeak(double xCenter,double yCenter,double distance,double energy,
        double pixelLength,double pixelHeight,double alpha,double beta,double rotation,
        double * sliceQ,double * sliceVal,int numValues,
        double qLower,double qUpper,double chi,double allowedStddevRatio,double *x,double *y,double * qFit,double * deviationFit) {

    double avgVal,maxVal;
    int index;
    double p[4];
    int status;
    double cos_beta,sin_beta,cos_alpha,sin_alpha,cos_rotation,sin_rotation;
    double stddev,sum;
    int i,num;
    //double chiSquare,fit;

    double heightFit,bgFit;
    double covar[4][4];

    int VERBOSE;

    VERBOSE = 0;

    // can't fit unless you have several values
    if (numValues < 10) 
        return 0;

    avgVal = average(sliceVal,numValues);
    index = maxIndex(sliceVal,numValues);
    maxVal = sliceVal[index];

    // 'real' parameters
    p[0]=maxVal-avgVal;
    p[1]=sliceQ[index];
    p[2]= (qUpper-qLower)/15.0;
    p[3]= avgVal;

    status=dlevmar_dif(gaussian, p, sliceVal, 4, numValues, 
            1000,NULL, NULL, NULL,*covar,(void *)sliceQ);

    // check to see if fit is good.
    // if not, return 0 to tell the code that no fit was found

    if (status <= 0) // for successful operation status > 0
        return 0;

    heightFit = p[0];
    *qFit = p[1];
    *deviationFit = p[2]; // pass pack to caller
    bgFit = p[3];
    sum = 0;
    num = 0;

    /*
    if (sqrt(covar[0][0]) > heightFit) {
        if (VERBOSE) printf("Uncertanty in height large compared to height.\n");
        return 0;
    }
    */

    /*
    if (sqrt(covar[1][1]) > *deviationFit) {
        if (VERBOSE) printf("Uncertanty in postion large compared to width of peak.\n");
        return 0;
    }
    */


    // I am not sure this is a good thing to test, b/c there could be a good fit even with a weird b/g
    /*
    if (sqrt(covar[3][3]) > .3*heightFit) {
        if (VERBOSE) printf("Uncertanty in backgound too much\n");
        return 0;
    }
    */
        

    // peak must be signifigantly larger then background
    /*
    if (heightFit < 0.05*bgFit) {
        if (VERBOSE) printf("Peak is not tall enough to count\n");
        return 0;
    }
    */
    
    // make sure fit does not fall too far off the data
    if (*qFit-2* (*deviationFit) < qLower || *qFit+2* (*deviationFit) > qUpper) {
        if (VERBOSE) printf("Fit is too far off the data.\n");
        return 0;
    }

    stddev = 0;
    sum = 0;
    num = 0;

    // calculate variation of background outsize 2 sigma of fit
    for (i=0;i<numValues;i++) {
        if (sliceQ[i] > *qFit+2* (*deviationFit) || sliceQ[i] < *qFit-2* (*deviationFit) ) {
            sum+=(sliceVal[i]-bgFit)*(sliceVal[i]-bgFit);
            num+=1;
        }
    }
    stddev = sqrt(sum*1.0/num);

    // make sure height is bigger then deviation of background by user specified ratio
    if (heightFit < allowedStddevRatio*stddev) {
        if (VERBOSE) printf("Background stddev is too large.\n");
        return 0;
    }

    // good fit, calc x,y cordinates of it.
    cos_beta  = cos(beta*PI/180.0);
    sin_beta  = sin(beta*PI/180.0);
    cos_alpha = cos(alpha*PI/180.0);
    sin_alpha = sin(alpha*PI/180.0);
    cos_rotation = cos(rotation*PI/180.0);
    sin_rotation = sin(rotation*PI/180.0);

    // get physical pixel cordinates
    getXY(xCenter,yCenter,distance,energy,*qFit,chi,
        pixelLength,pixelHeight,rotation,cos_beta,sin_beta,
        cos_alpha,sin_alpha,cos_rotation,sin_rotation,x,y);

    return 1; // success!
}
 int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
     return (D-B)*(C-A)+(G-E)*(H-F)-getXY(D,B,H,F)*getXY(C,A,G,E);
 }
/* 
 * Finds one particular peak and returns the x,y cordinates of it 
 * by modifying peakX and peakY
 */
struct both * constantChiSlice(PyArrayObject * diffractionData,double xCenter,
        double yCenter,double distance,double energy,double pixelLength,
        double pixelHeight,double alpha,double beta,double rotation,double qLower,
        double qUpper, double chi,int * numValues) {

    double x1,y1;
    double x2,y2;
    double cos_beta,sin_beta,cos_alpha,sin_alpha,cos_rotation,sin_rotation;
    double m;
    int xSize,ySize;
    double xUpperFirst,yUpperFirst,xLowerFirst,yLowerFirst;
    double xUpperSecond,yUpperSecond,xLowerSecond,yLowerSecond;
    double xCurrent,yCurrent;
    int dataLow,dataHigh;
    int xLow,xHigh,yLow,yHigh;
    int counter;
    double qCurrent,chiCurrent;
    double dataInterpolate;

    struct both * vals;

    cos_beta  = cos(beta*PI/180.0);
    sin_beta  = sin(beta*PI/180.0);
    cos_alpha = cos(alpha*PI/180.0);
    sin_alpha = sin(alpha*PI/180.0);
    cos_rotation = cos(rotation*PI/180.0);
    sin_rotation = sin(rotation*PI/180.0);

    // find the beginning & ending pixel values for our Q,chi range.
    getXY(xCenter,yCenter,distance,energy,qLower,chi,
        pixelLength,pixelHeight,rotation,cos_beta,sin_beta,
        cos_alpha,sin_alpha,cos_rotation,sin_rotation,&x1,&y1);
   
    getXY(xCenter,yCenter,distance,energy,qUpper,chi,
        pixelLength,pixelHeight,rotation,cos_beta,sin_beta,
        cos_alpha,sin_alpha,cos_rotation,sin_rotation,&x2,&y2);

    xSize = diffractionData->dimensions[0];
    ySize = diffractionData->dimensions[0];
    
    // If the two points to find values between are off the image, 
    // Point the answer to nothing.
    if (ceil(x1)<0 || floor(x1)>xSize || ceil(y1)<0 || 
        floor(y1)>=ySize || ceil(x2)<0 || 
        floor(x2) >= xSize || ceil(y2)<0 || floor(y2)>=ySize) {
        return NULL;
    }

    // Make sure that xLower < xUpper for our first sweep
    if (x1>x2) {
        xUpperFirst=x1;yUpperFirst=y1;
        xLowerFirst=x2;yLowerFirst=y2;
    } else {
        xLowerFirst=x1;yLowerFirst=y1;
        xUpperFirst=x2;yUpperFirst=y2;
    }

    // Make sure that yLower < yUpperfor our second sweep
    if (y1 > y2) {
        xUpperSecond=x1;yUpperSecond=y1;
        xLowerSecond=x2;yLowerSecond=y2;
    } else {
        xLowerSecond=x1;yLowerSecond=y1;
        xUpperSecond=x2;yUpperSecond=y2;
    }

    // figure out all the data points to sample 
    *numValues = ( (int)floor(xUpperFirst)-(int)ceil(xLowerFirst) +1 );
    if (yUpperSecond != yLowerSecond)
        *numValues += ( (int)floor(yUpperSecond)-(int)ceil(yLowerSecond) +1 );

    vals=malloc( sizeof(struct both) );
    vals->first = malloc( (*numValues)*sizeof(double) );
    vals->second = malloc( (*numValues)*sizeof(double) );

    m=(yUpperFirst-yLowerFirst)*1.0/(xUpperFirst-xLowerFirst);

    counter=0;

    for(xCurrent=ceil(xLowerFirst);xCurrent<=floor(xUpperFirst);xCurrent++) {
        // get all points that lie on constant integer y values in the image
        yCurrent=yLowerFirst +m*(xCurrent-xLowerFirst);

        yHigh = (int)ceil(yCurrent);
        yLow = (int)floor(yCurrent);

        dataLow=*(int *)(diffractionData->data + ((int)xCurrent)*diffractionData->strides[0] + 
                yLow*diffractionData->strides[1]);
        dataHigh=*(int *)(diffractionData->data + ((int)xCurrent)*diffractionData->strides[0] + 
                yHigh*diffractionData->strides[1]);

        dataInterpolate = dataLow + (yCurrent-yLow)*(dataHigh-dataLow);

        getQChi(xCenter,yCenter,distance,energy,xCurrent,yCurrent,
                pixelLength,pixelHeight,rotation,cos_beta,sin_beta,cos_alpha,
                sin_alpha,cos_rotation,sin_rotation,&qCurrent,&chiCurrent);

        vals->first[counter] = qCurrent;
        vals->second[counter] = dataInterpolate;
        counter++;
    }

    if (yUpperSecond - yLowerSecond > .00001 ) {
        m=(xUpperSecond-xLowerSecond)*1.0/(yUpperSecond-yLowerSecond);

        for (yCurrent=(int)ceil(yLowerSecond);yCurrent<=(int)floor(yUpperSecond);yCurrent++) {
            // get all points that lie on constant integer x values in the image
            
            xCurrent = xLowerSecond + m*(yCurrent-yLowerSecond);

            xHigh=(int)ceil(xCurrent);
            xLow=(int)floor(xCurrent);

            dataLow=*(int *)(diffractionData->data + xLow*diffractionData->strides[0] + 
                    ((int)yCurrent)*diffractionData->strides[1]);
            dataHigh=*(int *)(diffractionData->data + xHigh*diffractionData->strides[0] + 
                    ((int)yCurrent)*diffractionData->strides[1]);

            dataInterpolate = dataLow + (xCurrent-xLow)*(dataHigh-dataLow);

            getQChi(xCenter,yCenter,distance,energy,xCurrent,yCurrent,
                    pixelLength,pixelHeight,rotation,cos_beta,sin_beta,cos_alpha,
                    sin_alpha,cos_rotation,sin_rotation,&qCurrent,&chiCurrent);

            vals->first[counter] = qCurrent;
            vals->second[counter] = dataInterpolate;
            counter++;
        }
    }

    // now, counter must equal *numValues. Return success
    return vals;
}
bool Perfboard::collectExtraInfo(QWidget * parent, const QString & family, const QString & prop, const QString & value, bool swappingEnabled, QString & returnProp, QString & returnValue, QWidget * & returnWidget)
{
	if (prop.compare("size", Qt::CaseInsensitive) == 0) {
		returnProp = tr("size");
		returnValue = m_size;
		m_propsMap.insert("size", m_size);

		int x, y;
		getXY(x, y, m_size);

		QFrame * frame = new QFrame();
		QVBoxLayout * vboxLayout = new QVBoxLayout();
		vboxLayout->setAlignment(Qt::AlignLeft);
		vboxLayout->setSpacing(1);
		vboxLayout->setContentsMargins(0, 3, 0, 0);
		vboxLayout->setMargin(0);

		QFrame * subframe1 = new QFrame();
		QHBoxLayout * hboxLayout1 = new QHBoxLayout();
		hboxLayout1->setAlignment(Qt::AlignLeft);
		hboxLayout1->setContentsMargins(0, 0, 0, 0);
		hboxLayout1->setSpacing(2);

		QLabel * l1 = new QLabel(getRowLabel());	
		l1->setMargin(0);
		l1->setObjectName("infoViewLabel");	
		m_xEdit = new QLineEdit();
		m_xEdit->setEnabled(swappingEnabled);
		QIntValidator * validator = new QIntValidator(m_xEdit);
		validator->setRange(MinXDimension, MaxXDimension);
		m_xEdit->setObjectName("infoViewLineEdit");	
		m_xEdit->setValidator(validator);
		m_xEdit->setMaxLength(5);
		m_xEdit->setText(QString::number(x));

		QFrame * subframe2 = new QFrame();
		QHBoxLayout * hboxLayout2 = new QHBoxLayout();
		hboxLayout2->setAlignment(Qt::AlignLeft);
		hboxLayout2->setContentsMargins(0, 0, 0, 0);
		hboxLayout2->setSpacing(2);

		QLabel * l2 = new QLabel(getColumnLabel());
		l2->setMargin(0);
		l2->setObjectName("infoViewLabel");	
		m_yEdit = new QLineEdit();
		m_yEdit->setEnabled(swappingEnabled);
		validator = new QIntValidator(m_yEdit);
		validator->setRange(MinYDimension, MaxYDimension);
		m_yEdit->setObjectName("infoViewLineEdit");	
		m_yEdit->setValidator(validator);
		m_yEdit->setMaxLength(5);
		m_yEdit->setText(QString::number(y));

		hboxLayout1->addWidget(l1);
		hboxLayout1->addWidget(m_xEdit);

		hboxLayout2->addWidget(l2);
		hboxLayout2->addWidget(m_yEdit);

		subframe1->setLayout(hboxLayout1);
		subframe2->setLayout(hboxLayout2);

		if (returnWidget != NULL) vboxLayout->addWidget(qobject_cast<QWidget *>(returnWidget));
		vboxLayout->addWidget(subframe1);
		vboxLayout->addWidget(subframe2);

		m_setButton = new QPushButton (tr("set board size"));
		m_setButton->setObjectName("infoViewButton");
		connect(m_setButton, SIGNAL(pressed()), this, SLOT(changeBoardSize()));
		m_setButton->setEnabled(false);

		vboxLayout->addWidget(m_setButton);

		connect(m_xEdit, SIGNAL(editingFinished()), this, SLOT(enableSetButton()));
		connect(m_yEdit, SIGNAL(editingFinished()), this, SLOT(enableSetButton()));

		frame->setLayout(vboxLayout);

		returnWidget = frame;

		return true;
	}

	return Capacitor::collectExtraInfo(parent, family, prop, value, swappingEnabled, returnProp, returnValue, returnWidget);
}
/*
 * This function does the caking.
 */
static PyObject * DiffractionAnalysisWrap_cake(PyObject *self, PyObject *args) {
    PyArrayObject *diffractionData;
    PyArrayObject *cake;
    // the dimensions of the caked data
    int dimensions[2];

    double centerX,centerY,distance,energy,alpha,beta,rotation;
    double qOrTwoThetaLower,qOrTwoThetaUpper;
    int numQOrTwoTheta;
    double chiLower,chiUpper;
    int numChi;
    double pixelLength,pixelHeight;
    double cos_beta,sin_beta,cos_alpha,sin_alpha,cos_rotation,sin_rotation;
    double x,y;
    double q,chi; 
    double qOrTwoTheta; 
    int qOrTwoThetaBin,chiBin;
    double qOrTwoThetaStep,chiStep;
    double intensity;
    int doPolarizationCorrection;
    double P,twoTheta;
    int doGreaterThanMask;
    double greaterThanMask;
    int doLessThanMask;
    double lessThanMask;

    int doPolygonMask;
    PyArrayObject * polygonsX;
    PyArrayObject * polygonsY;
    PyArrayObject * polygonBeginningsIndex;
    PyArrayObject * polygonNumberOfItems;

    char *type;

    // get all of the parameters out of the python call
    PyArg_ParseTuple(args,"O!dddddddddiddiidididiO!O!O!O!dds",&PyArray_Type,&diffractionData,
        &centerX,&centerY,&distance,&energy,&alpha,&beta,&rotation,
        &qOrTwoThetaLower,&qOrTwoThetaUpper,&numQOrTwoTheta,
        &chiLower,&chiUpper,&numChi,
        &doPolarizationCorrection,&P,
        &doGreaterThanMask,&greaterThanMask,&doLessThanMask,&lessThanMask,
        &doPolygonMask,
        &PyArray_Type,&polygonsX,
        &PyArray_Type,&polygonsY,
        &PyArray_Type,&polygonBeginningsIndex,
        &PyArray_Type,&polygonNumberOfItems,
        &pixelLength,&pixelHeight,&type);


    // the types of integration
    // Remeber, strcmp returns 0 when they equal 
    if (strcmp(type,"Q") != 0 && strcmp(type,"2theta") != 0) {
        PyErr_SetString( PyExc_Exception, 
                "The type of integration must be Q, or 2theta");
        return 0;
    }

    // passed array has the diffraction data
    if (diffractionData->nd != 2 || 
            diffractionData->descr->type_num != PyArray_INT) {
        PyErr_SetString(PyExc_ValueError,
            "diffractionData must be two-dimensional and of type integer");
        return 0;
    }

    // create a new Numeric data structure to hold the cake
    dimensions[0]=numChi;
    dimensions[1]=numQOrTwoTheta;
    cake=(PyArrayObject *)PyArray_FromDims(2,dimensions,PyArray_DOUBLE);

    // calculate sin & cos for later use.
    cos_beta  = cos(beta*PI/180.0);
    sin_beta  = sin(beta*PI/180.0);
    cos_alpha = cos(alpha*PI/180.0);
    sin_alpha = sin(alpha*PI/180.0);
    cos_rotation = cos(rotation*PI/180.0);
    sin_rotation = sin(rotation*PI/180.0); 

    // calulate the step size between different bins
    qOrTwoThetaStep = (qOrTwoThetaUpper-qOrTwoThetaLower)/(numQOrTwoTheta-1);
    chiStep = (chiUpper-chiLower)/(numChi-1);

    // for each bin
    for (qOrTwoThetaBin = 0; qOrTwoThetaBin < numQOrTwoTheta; qOrTwoThetaBin += 1) {
        for (chiBin = 0; chiBin < numChi; chiBin += 1) {

            // get into the middle of the cell
            qOrTwoTheta = qOrTwoThetaLower + qOrTwoThetaBin*qOrTwoThetaStep + 
                    qOrTwoThetaStep/2.0;
            chi = chiLower + chiBin*chiStep + chiStep/2.0;

            if (strcmp(type,"Q")==0) {
                q = qOrTwoTheta;
            } else {
                q = convertTwoThetaToQ(qOrTwoTheta,convertEnergyToWavelength(energy)); 
            }

            getXY(centerX,centerY,distance,energy,q,chi,
                    pixelLength,pixelHeight,rotation,
                    cos_beta,sin_beta,cos_alpha,sin_alpha,
                    cos_rotation,sin_rotation,&x,&y);

            // if the qOrTwoTheta,chi value is in the diffraction 
            // image, then find the intensity. Note that there is 
            // only diffraction data up to (dimension-1)
            if (x >= 0 && x <= (diffractionData->dimensions[0]-1) &&
                    y >= 0 && y <= (diffractionData->dimensions[1]-1)) {

                intensity = bilinearInterpolation(diffractionData, x, y);

                // possibly do the polarization correction
                if (doPolarizationCorrection) {

                    twoTheta = convertQToTwoTheta(q,
                            convertEnergyToWavelength(energy));

                    intensity = polarizationCorrection(intensity,P,twoTheta,chi);
                }

                // clip all intensity values to be at least 0.
                if (intensity < 0) intensity = 0;
                
                if (doPolygonMask && isInPolygons(polygonsX,polygonsY,
                        polygonBeginningsIndex,polygonNumberOfItems,x,y)) {

                // if we are doing a polygon mask and our pixel is 
                // in one of the polygons, then we should assign its 
                // value to be -4 (by convention)
                *(double *)(cake->data + chiBin*cake->strides[0] + 
                        qOrTwoThetaBin*cake->strides[1]) = -4;

                } else if (doGreaterThanMask && intensity > greaterThanMask) {
                    // if we are doing the greater than mask, if the 
                    // current pixel is greater then the threshold, 
                    // then we should assign its value to be -2 
                    // (by convention).
                    *(double *)(cake->data + chiBin*cake->strides[0] + 
                            qOrTwoThetaBin*cake->strides[1]) = -2;
                } else if (doLessThanMask && intensity < lessThanMask) {
                    // if we are doing the lower than mask, if the 
                    // current pixel is less then the threshold, then 
                    // we should assign its value to be -3 (by convention)
                    *(double *)(cake->data + chiBin*cake->strides[0] + 
                            qOrTwoThetaBin*cake->strides[1]) = -3;
                } else {
                    *(double *)(cake->data + chiBin*cake->strides[0] + 
                            qOrTwoThetaBin*cake->strides[1]) = intensity;
                }

            } else { // otherwise, define outside the image as -1 intensity.
                *(double *)(cake->data + chiBin*cake->strides[0] + 
                        qOrTwoThetaBin*cake->strides[1]) = -1;
            }
        }
    }
    return Py_BuildValue("N",cake);
}
void Clothoid::getTrajectory() {

    double s = 0, tempS;
    double x, y;
    path.path.clear();
    double x0, y_zero;
    double k0 = 0, theta0 = start.theta;
    getXY(path.lengthOfPath / 2, path.sigma / 2, k0, theta0, x0, y_zero);
    double k1 = path.sigma * path.lengthOfPath / 2 + k0;
    double theta1 = path.sigma / 2 * path.lengthOfPath * path.lengthOfPath / 4 + k0 * path.lengthOfPath / 2 + theta0;
    for (s = 0; s < path.lengthOfPath; s += path.lengthOfPath / 1000) {

        tempS = s;

        if (s <= path.lengthOfPath / 2) {
            if (path.sigma * s < kMax) {
                double a = path.sigma / 2, b = k0, c = theta0;
                getXY(s, a, b, c, x, y);
            } else {
                x = sin(kMax * s + theta0) / kMax - sin(theta0) / kMax;
                y = cos(theta0) / kMax - cos(kMax * s + theta0) / kMax;

            }

            path.path.push_back(State(start.x + x, start.y + y, 0));

        } else {
            s = tempS;
            tempS = s - path.lengthOfPath / 2;

            if (path.sigma * s < kMax) {


                double a = -path.sigma / 2, c = theta1;
                double b = path.sigma * path.lengthOfPath / 2 + k0;
                double X1, Y1;

                getXY(tempS, a, b, c, X1, Y1);
                //   std::cout<<"X "<<X1<<" Y "<<Y1;

                getXY(0, a, b, c, x, y);
                X1 -= x;
                Y1 -= y;
                x = x0 + X1;
                y = y_zero + Y1;

                //  std::cout<<"Hello 3 theta "<<theta1+a*tempS*tempS+b*tempS<<" s "<<s<<" k "<<sigma*(larc/2-tempS)<<" x "<<x<<" y "<<y<<std::endl;

            } else {

                x = sin(kMax * s + theta0) / kMax - sin(theta0) / kMax;
                y = cos(theta0) / kMax - cos(kMax * s + theta0) / kMax;

            }
            path.path.push_back(State(start.x + x, start.y + y, 0));


        }


    }

}