예제 #1
0
GraphicsUnrootedBranchItem::GraphicsUnrootedBranchItem(QGraphicsItem* parent, qreal angle, GraphicsRectangularBranchItem* from, double nodeValue)
: GraphicsBranchItem(true, nodeValue) {
    setParentItem(parent);
    qreal w = from->getWidth();
    settings = from->getSettings();
    setWidthW(w);
    setDist(from->getDist());
    setPos(w, 0);
    angle = from->getDirection() == GraphicsBranchItem::up ? angle : -angle;
    setTransform(QTransform().translate(-w, 0).rotate(angle).translate(w, 0));
//    setTransformOriginPoint(-w, 0);
//    setRotation(angle);

    if (from->getNameText() != NULL) {
        nameText = new QGraphicsSimpleTextItem(from->getNameText()->text(), this);
        nameText->setFont(from->getNameText()->font());
        nameText->setBrush(from->getNameText()->brush());
    }
    if (from->getDistanceText() != NULL) {
        distanceText = new QGraphicsSimpleTextItem(from->getDistanceText()->text(), this);
        distanceText->setFont(from->getDistanceText()->font());
        distanceText->setBrush(from->getDistanceText()->brush());
    }
    setLabelPositions();
    setPen(from->pen());
}
예제 #2
0
파일: mouse.c 프로젝트: dmaricon/Micromouse
void floodLevel(int n,int d,Queue *q) {
   int i;
   for (i = 0;i < n;i++) {
      setDist(q->contents[(getFront(q) + i) % QSIZE],d);
   }
}
예제 #3
0
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] )
{
    mxLogical *image;
	mxLogical *path;
	bool *track;
	double *dist, *idx;
    mwSize w, h, size, sizeIdx, i, x, y;
	long conn;
	double inf = mxGetInf();
	double nan = mxGetNaN();
	
	if (nrhs < 2){
		mexErrMsgIdAndTxt( "Image:distgeodesic:wrongInputCount",
				"At least two input (image, startPoints) expected.");
	}
	if (nrhs > 3){
		mexErrMsgIdAndTxt( "Image:distgeodesic:wrongInputCount",
				"Too may input parameter.");
	}
	
	if (!mxIsDouble(prhs[1])){
		mexErrMsgIdAndTxt( "Image:distgeodesic:wrongInputType",
				"Index parameter has to be doubles.");
	}
	
	if (nrhs < 3 || mxGetM(prhs[2]) * mxGetN(prhs[2]) == 0){
		conn = 6;
	}
	else {
		if (mxIsDouble(prhs[2])){
			if (mxGetM(prhs[2]) * mxGetN(prhs[2]) == 1){
				conn = (long) mxGetPr(prhs[2])[0];
			}
			else {
				mexErrMsgIdAndTxt( "Image:distgeodesic:wrongInputType",
					"Connection parameter has to be a scalar.");
			}
		}
		else {
			mexErrMsgIdAndTxt( "Image:distgeodesic:wrongInputType",
				"Connection parameter has to be a double.");
		}
	}
	
    h = mxGetM(prhs[0]);
    w = mxGetN(prhs[0]);
	size = h*w;
	/* The input must be a logical.*/
	if (!mxIsLogical(prhs[0])){
        image = mxGetLogicals(mxCreateLogicalMatrix(h, w));
        double *data = mxGetPr(prhs[0]);
        for (int i = 0; i < size; i += 1){
			image[i] = (mxLogical) data[i];
        }
	}
    else {
        image = mxGetLogicals(prhs[0]);
    }
	
	/* Create matrix for the return argument. */
	plhs[0] = mxCreateDoubleMatrix(h, w, mxREAL);
	dist = mxGetPr(plhs[0]);
	
	track = new bool[size];
	
	for (i = 0; i < size; i += 1){
		track[i] = false;
		dist[i] = image[i]? inf: nan;
	}
	
	idx = mxGetPr(prhs[1]);
	sizeIdx = mxGetM(prhs[1]) * mxGetN(prhs[1]);
	bool any = false;
	for (i = 0; i < sizeIdx; i += 1){
		mwSize startIdx = (long) idx[i];
		if (idx[i] != startIdx){
			mexErrMsgIdAndTxt( "Image:distgeodesic:idxNotIntegral",
					"Startindex has to be an integral number.");
		}
		if (startIdx <= 0 || startIdx > size){
			mexErrMsgIdAndTxt( "Image:distgeodesic:idxOutOfRange",
					"Startindex is out of range.");
		}
		track[startIdx - 1] = true;
		dist[startIdx - 1] = 0;
		any = true;
	}
	
	bool *trackCopy = new bool[size];
	while (any){
		any = false;
		for (i = 0; i < size; i += 1){
			trackCopy[i] = track[i];
		}
		
		for (i = 0; i < size; i += 1){ // cityblock
			if (trackCopy[i]){
				track[i] = false;
				y = i % h;
				x = (i - y) / h;
				setDist(x - 1, y, i, 1);
				setDist(x + 1, y, i, 1);
				setDist(x, y - 1, i, 1);
				setDist(x, y + 1, i, 1);
			}
		}
		if (conn == 6){ // chessboard
			for (i = 0; i < size; i += 1){
				if (trackCopy[i]){
					y = i % h;
					x = (i - y) / h;
					setDist(x - 1, y - 1, i, 1);
					setDist(x - 1, y + 1, i, 1);
					setDist(x + 1, y - 1, i, 1);
					setDist(x + 1, y + 1, i, 1);
				}
			}
		}
		if (conn == 8){ // quasi-euclidean
			for (i = 0; i < size; i += 1){
				if (trackCopy[i]){
					y = i % h;
					x = (i - y) / h;
					setDist(x - 1, y - 1, i, M_SQRT2);
					setDist(x - 1, y + 1, i, M_SQRT2);
					setDist(x + 1, y - 1, i, M_SQRT2);
					setDist(x + 1, y + 1, i, M_SQRT2);
				}
			}
		}
	}
	
	delete[] trackCopy;
	trackCopy = nullptr;
	
	
	/* free memory */
	delete[] track;
	track = nullptr;
}