Пример #1
0
void FboBlending::buildImage(){
	//TODO: do all of this on graphics card without having to read it back
	
	
	if(backgroundImage != NULL){
		/*
		 bool valid =
		 containsRect(ofRectangle(0, 0, backgroundImage->width, backgroundImage->height), rect) &&
		 blendImage.height >= rect.height && blendImage.width >= rect.width;
		 */
		
		float srcX = ofClamp(rect.x, 0, backgroundImage->width-1);
		float srcY = ofClamp(rect.y, 0, backgroundImage->height-1);
		float srcX2 = ofClamp(rect.x + rect.width, 0, backgroundImage->width-1);
		float srcY2 = ofClamp(rect.y + rect.height, 0, backgroundImage->height-1);
		float srcWidth = srcX2 - srcX;
		float srcHeight = srcY2 - srcY;
		bool valid = (srcWidth > 0) && (srcHeight > 0);
		
		if(valid){ 
			ImageUtil::copyPixel(*backgroundImage, srcX, srcY, srcWidth, srcHeight, blendImage, 0, 0, false);
			//ImageUtil::copyPixel(*backgroundImage, rect.x, rect.y, rect.width, rect.height, blendImage, 0, 0, false);
			ImageUtil::flipVertically(blendImage);
		} else {
			unsigned char color[4];
			color[0] = 255;
			color[1] = 255;
			color[2] = 255;
			color[3] = 255;
			ImageUtil::setPixels(blendImage.getPixels(), blendImage.width, blendImage.height, 0, 0, blendImage.width, blendImage.height, color);
		}
	} else {
		
		unsigned char color[4];
		color[0] = 255;
		color[1] = 255;
		color[2] = 255;
		color[3] = 255;
		ImageUtil::setPixels(blendImage.getPixels(), blendImage.width, blendImage.height, 0, 0, blendImage.width, blendImage.height, color);
	}
	
	/*
	 unsigned char color[4];
	 color[0] = 255;
	 color[1] = 255;
	 color[2] = 255;
	 color[3] = 255;
	 
	 ImageUtil::setPixels(blendImage.getPixels(), blendImage.width, blendImage.height, 0, 0, blendImage.width, blendImage.height, color);
	 */
	
	buildEdge(_top);
	buildEdge(_bottom);
	buildEdge(_left);
	buildEdge(_right);
	
	buildLevelsMap();
	
	blendImage.update();
}
void
NLEdgeControlBuilder::beginEdgeParsing(
    const std::string& id, const MSEdge::EdgeBasicFunction function,
    const std::string& streetName) {
    myActiveEdge = buildEdge(id, function, streetName);
    if (MSEdge::dictionary(id) != 0) {
        throw InvalidArgument("Another edge with the id '" + id + "' exists.");
    }
    myEdges.push_back(myActiveEdge);
}
void
NLEdgeControlBuilder::beginEdgeParsing(const std::string &id,
                                       MSEdge::EdgeBasicFunction function) throw(InvalidArgument) {
    myActiveEdge = buildEdge(id);
    if (!MSEdge::dictionary(id, myActiveEdge)) {
        throw InvalidArgument("Another edge with the id '" + id + "' exists.");
    }
    myEdges.push_back(myActiveEdge);
    m_pDepartLane = (MSLane*) 0;
    m_Function = function;
}
Пример #4
0
std::istream &Graph::read (std::istream &is)
{
	std::vector <std::string> result;
	char line[1024];

	clear ();

	while (true) {

		unsigned int pos = is.tellg ();
		if (! is.getline (line, 1024))
			break;
		result.clear ();
		tokenize<std::string>(line, std::back_inserter (result));

		if (result.empty()) {
			// do nothing
		} else if (result[0] == "t") {
			if (! empty()) { // use as delimiter
				is.seekg (pos, std::ios_base::beg);
				break;
			} else {
				/*
				 * y = atoi (result[3].c_str());
				 */
			}
		} else if (result[0] == "v" && result.size() >= 3) {
			unsigned int id    = atoi (result[1].c_str());
			this->resize (id + 1);
			(*this)[id].label = atoi (result[2].c_str());
		} else if (result[0] == "e" && result.size() >= 4) {
			int from   = atoi (result[1].c_str());
			int to     = atoi (result[2].c_str());
			int elabel = atoi (result[3].c_str());

			if ((int)size () <= from || (int)size () <= to) {
				std::cerr << "Format Error:  define vertex lists before edges" << std::endl;
				exit (-1);
			}

			(*this)[from].push (from, to, elabel);
			if (directed == false)
				(*this)[to].push (to, from, elabel);
		}
	}

	buildEdge ();

	return is;
}
Пример #5
0
/* Convert a Matlab graph structure into the graph object. --sn
 */
void Graph::read (const mxArray* graph)
{
	mxArray* nodelabels = mxGetField (graph, 0, "nodelabels");
	mxArray* edges = mxGetField (graph, 0, "edges");

	if (nodelabels == NULL || edges == NULL) {
		mexPrintf ("Graph structures are missing the \"nodelabels\" "
			"or \"edges\" fields.\n");

		return;
	}

	if (mxIsUint32 (nodelabels) == 0 || mxIsUint32 (edges) == 0) {
		mexPrintf ("\"nodelabels\" or \"edges\" not of type Uint32.\n");

		return;
	}

	uint32_T* nmat = (uint32_T*) mxGetData (nodelabels);
	assert (nmat != NULL);
	unsigned int nodes = mxGetM (nodelabels);
	this->resize (nodes);
	for (unsigned int i = 0 ; i < nodes ; ++i) {
		(*this)[i].label = nmat[i];
#ifdef	DEBUG
		mexPrintf ("inserting node %d with label %d\n", i, nmat[i]);
#endif
	}

	/* emat is column organised.
	 */
	unsigned int edgecount = mxGetM (edges);
	if (edgecount > 0) {
		uint32_T* emat = (uint32_T*) mxGetData (edges);
#ifdef	DEBUG
		mexPrintf ("edges M, N: %d, %d\n", mxGetM (edges), mxGetN (edges));
#endif
		assert (emat != NULL);

		for (unsigned int i = 0 ; i < edgecount ; ++i) {
			unsigned int from = emat[i+0*edgecount] - 1;	// index correction
			unsigned int to = emat[i+1*edgecount] - 1;	// index correction
			unsigned int elabel = emat[i+2*edgecount];

			assert (from < nodes && to < nodes);
			if (from >= nodes || to >= nodes) {
				mexErrMsgTxt ("Edge from/to indices out of bounds.");
				return;
			}

			/* Warning: this makes edges undirected, which is not what we want (or
			 * do we?).
			 */
	#ifdef	DEBUG
			mexPrintf ("inserting edge from %d to %d, label %d\n",
				from, to, elabel);
	#endif
			(*this)[from].push (from, to, elabel);
			if (directed == false) {
	#ifdef	DEBUG
				mexPrintf ("  reverse: inserting edge from %d to %d, label %d\n",
					to, from, elabel);
	#endif
				(*this)[to].push (to, from, elabel);
			}
		}
	}
	buildEdge ();
}
Пример #6
0
int main() {
    int n, step;
    scanf("%d", &n);
    scanf("%d", &step);
    
    List* graph[n + 2];
    graph[0] = createNode(0, NULL);
    graph[n + 1] = createNode(n + 1, NULL);
    
    float x[n + 2];
    float y[n + 2];
    
    x[0] = 0;
    y[0] = 0;
    x[n + 1] = LAKE_SIZE;
    y[n + 1] = LAKE_SIZE;
    
    for(int i = 1; i <= n; i++) {
        scanf("%f", &x[i]);
        scanf("%f", &y[i]);
        graph[i] = createNode(i, NULL);
        
        // connect to vertex[0]
        if(squareFast(x[i], y[i]) <= (LAND_RADIUS + step) * (LAND_RADIUS + step)) { // jump please!
            buildEdge(0, i, graph, x, y);
        }
        // connect to other vertices
        for(int j = 1; j < i; j++) {
            if(squareFast(x[i] - x[j], y[i] - y[j]) <= step * step) { // jump! Be quick!
                buildEdge(i, j, graph, x, y);
            }
        }
    }
    
    // connect to escape location
    for(int i = 0; i <= n; i++) {
        int xx = x[i];
        int yy = y[i];
        if(xx < 0)
            xx = -xx;
        if(yy < 0)
            yy = -yy;
        int larger = xx > yy ? xx : yy;
        
        if(LAKE_SIZE - larger <= step) {
            buildEdge(i, n + 1, graph, x, y);
        }
    }
    
    int prePath[n + 2];
    int level[n + 2];
    prePath[0] = 0;
    level[0] = 0;
    for(int i = 1; i < n + 2; i++) {
        prePath[i] = -1;
        level[i] = -1;
    }
    
    int flag = 0;
    BFS(0, graph, n, prePath, &flag, x, y);
    
    if(flag) {
        List* stack = createNode(-1, NULL);
        int counter = 0;
        int value = n + 1;
        while(value != 0) {
            counter++;
            push(stack, value);
            value = prePath[value];
        }
        
        printf("%d\n", counter);
        while(1) {
            value = pop(stack);
            if(value != n + 1) {
                printf("%d %d\n", (int)x[value], (int)y[value]);
            }
            else
                break;
        }
    }
    else {
        printf("0\n");
    }
    
//    for(int i = 0; i < n + 2; i++) {
//        printf("%d ", prePath[i]);
//    }
    
//    for(int i = 0; i < n + 2; i++) {
//    List* glast = graph[i];
//    while(glast->next) {
//        int val = glast->next->value;
//        printf("%d %d\n", (int)x[val], (int)y[val]);
//        glast = glast->next;
//    }
//        printf("\n");
//    }
    
    return 0;
}