Example #1
0
GNEEdge*
GNENet::addReversedEdge(GNEEdge* edge, GNEUndoList* undoList) {
    undoList->p_begin("add reversed edge");
    GNEEdge* reversed = 0;
    if (edge->getNBEdge()->getLaneSpreadFunction() == LANESPREAD_RIGHT) {
        GNEEdge* reversed = createEdge(edge->getDest(), edge->getSource(), edge, undoList, "-" + edge->getID(), false, true);
        assert(reversed != 0);
        reversed->setAttribute(SUMO_ATTR_SHAPE, toString(edge->getNBEdge()->getInnerGeometry().reverse()), undoList);
    } else {
        // if the edge is centered it should probably connect somewhere else
        // make it easy to move and reconnect it
        PositionVector orig = edge->getNBEdge()->getGeometry();
        PositionVector origInner = edge->getNBEdge()->getInnerGeometry();
        const SUMOReal tentativeShift = edge->getNBEdge()->getTotalWidth() + 2;
        orig.move2side(-tentativeShift);
        origInner.move2side(-tentativeShift);
        GNEJunction* src = createJunction(orig.back(), undoList);
        GNEJunction* dest = createJunction(orig.front(), undoList);
        GNEEdge* reversed = createEdge(src, dest, edge, undoList, "-" + edge->getID(), false, true);
        assert(reversed != 0);
        reversed->setAttribute(SUMO_ATTR_SHAPE, toString(origInner.reverse()), undoList);
        // select the new edge and its nodes
        std::set<GUIGlID> toSelect;
        toSelect.insert(reversed->getGlID());
        toSelect.insert(src->getGlID());
        toSelect.insert(dest->getGlID());
        undoList->add(new GNEChange_Selection(toSelect, gSelected.getSelected(), true), true);
    }
    undoList->p_end();
    return reversed;
}
Graph* fileRead(FILE* file)
{
	char *token;
	char line[MAX_LENGTH], src[MAX_LENGTH], dst[MAX_LENGTH];
	int numOfVertex, edgeWeight, numOfEdges=0;
	Graph *graph;
	Vertex *newVer1, *newVer2;
	Edge *newEdge1, *newEdge2;

	// Checking how many edges we have.
	while (fgets(line, MAX_LENGTH, file) != NULL)
		numOfEdges++;
	numOfEdges = (numOfEdges-1)*2;	// numOfEdges = number of lines in file -1 (first line not included) * 2 
									// because an edge needed to be in both ways.
	rewind(file);	// Re-positioning to the begining of the file. 

	// Reading the first line
	if (fgets(line, MAX_LENGTH, file) != NULL)
	{
		token = strtok(line, " ");
		numOfVertex = atoi(token);
	}

	// Creating Graph struct
	graph = createGraph(numOfVertex, numOfEdges);
	if (graph == NULL) {
		printf("ERROR creating the Graph\n");
		return NULL;
	}

	// Continue reading the rest of the file, while creating, checking if exists and 
	// add new vertices and new edges to the graph.
	while (fgets(line, MAX_LENGTH, file) != NULL)
	{
		// Reading a line and put each parameter to a different temporary variable.
		token = strtok(line, " ");
		strcpy(src, token);
		token = strtok(NULL, " ");
		strcpy(dst, token);
		token = strtok(NULL, " ");
		edgeWeight = atoi(token);

		// Create 2 vertices.
		newVer1 = createVertex(src);
		newVer2 = createVertex(dst);
		
		// Checking if those vertices exists within the graph and adds them if needed.
		newVer1 = addVertexToGraph(newVer1, graph);
		newVer2 = addVertexToGraph(newVer2, graph);

		// Creating 2 edges, the given one and its vice versa.
		newEdge1 = createEdge(newVer1, newVer2, edgeWeight);
		newEdge2 = createEdge(newVer2, newVer1, edgeWeight);

		// Adding the edges to the graph.
		addEdgeToGraph(newEdge1, graph);
		addEdgeToGraph(newEdge2, graph);
	}
	return graph;
}
Example #3
0
/*
    Adds an edge between two nodes.
    @params
    timer : time to traverse path between nodes.
    direction: direction from node1 to node2.
*/  
void addEdge(graph * area, int nodeId1, int nodeId2, int timer,orientation direction ){
    edge *EdgeAToB,*EdgeBToA;
    node * node1 = findNode(area, nodeId1);
    node * node2 = findNode(area, nodeId2);    

    EdgeAToB = createEdge();
    EdgeAToB -> dest = node2;
    EdgeAToB -> timer = timer;
    EdgeAToB -> turn = direction;
    addToSet_graph (&(node1 -> edges),EdgeAToB);

    switch(direction)
    {
        case Straight : direction = Back; break;
        case Back : direction = Straight; break;
        case Right : direction = Left; break;
        case Left : direction = Right; break;
        default: break;
    }

    EdgeBToA = createEdge();
    EdgeBToA -> dest = node1;
    EdgeBToA -> timer = timer;
    EdgeBToA -> turn = direction;
    addToSet_graph (&(node2 -> edges),EdgeBToA);
}
Example #4
0
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;
    struct pam pam;
    tuple * tupleRow;
    tuple * leftEdge;
    tuple * rightEdge;
    unsigned int row;
    
    pnm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    pam.size             = sizeof pam;
    pam.len              = PAM_STRUCT_SIZE(tuple_type);
    pam.file             = stdout;
    pam.plainformat      = 0;
    pam.width            = cmdline.cols;
    pam.height           = cmdline.rows;
    pam.maxval           = cmdline.maxval;
    pam.bytes_per_sample = pnm_bytespersample(pam.maxval);
    pam.format           = PAM_FORMAT;
    if (isgray(&pam, cmdline.colorTopLeft)
            && isgray(&pam, cmdline.colorTopRight)
            && isgray(&pam, cmdline.colorBottomLeft)
            && isgray(&pam, cmdline.colorBottomRight)) {
        pam.depth = 1;
        strcpy(pam.tuple_type, PAM_PGM_TUPLETYPE);
    } else {
        pam.depth = 3;
        strcpy(pam.tuple_type, PAM_PPM_TUPLETYPE);
    }

    pnm_writepaminit(&pam);
    
    tupleRow = pnm_allocpamrow(&pam);

    leftEdge  = createEdge(&pam,
                           cmdline.colorTopLeft, cmdline.colorBottomLeft);
    rightEdge = createEdge(&pam,
                           cmdline.colorTopRight, cmdline.colorBottomRight);

    /* interpolate each row between the left edge and the right edge */
    for (row = 0; row < pam.height; ++row) {
        interpolate(&pam, tupleRow, leftEdge[row], rightEdge[row]);
        pnm_writepamrow(&pam, tupleRow); 
    }

    pm_close(stdout);
    pnm_freepamrow(rightEdge);
    pnm_freepamrow(leftEdge);
    pnm_freepamrow(tupleRow);

    freeCmdline(cmdline);

    return 0;
}
Example #5
0
static void drawASTNode(ASTNode *Node) {
  PtrVector *Child    = &(Node->Child);
  PtrVectorIterator I = beginPtrVector(Child), 
                    E = endPtrVector(Child);
  void *Value = Node->Value;
  switch (Node->Kind) {
    case IntLit:
      createLeaf(Node, "Int: %d", *((int*)Value)); 
      break;
    case FloatLit:
      createLeaf(Node, "Float: %f", *((float*)Value)); 
      break;
    case StringLit:
      createLeaf(Node, "String: %s", (char*)Value); 
      break;
    case IdLval:
      createLeaf(Node, "Id: %s", (char*)Value); 
      break;
    case IntTy:
      createLeaf(Node, "Type: int"); 
      break;
    case FloatTy:
      createLeaf(Node, "Type: float"); 
      break;
    case StringTy:
      createLeaf(Node, "Type: string"); 
      break;
    case AnswerTy:
      createLeaf(Node, "Type: answer"); 
      break;
    case ContTy:
      createLeaf(Node, "Type: cont"); 
      break;
    case StrConsumerTy:
      createLeaf(Node, "Type: strConsumer"); 
      break;
    case IdTy:
      createLeaf(Node, "TypeId: %s", (char*)Value); 
      break;
    case NilExpr:
      createLeaf(Node, "Nil");
      break;
    default:
      createNode(Node, Name[Node->Kind]);
      if (Value) {
        createLeaf(Value, "Id: %s", (char*)Value);
        createEdge(Node, Value);
      }
      for (; I != E; ++I) 
        if (*I) {
          createEdge(Node, *I);
          drawASTNode(*I); 
        }
      
      break;
  }
}
Example #6
0
// subdivide the 3 lateral faces of each prism
static void phase1(GRegion *gr, MVertexRTree &pos,
                   std::set<std::pair<MVertex*, MVertex*> > &edges)
{
  ExtrudeParams *ep = gr->meshAttributes.extrude;
  GFace *from = gr->model()->getFaceByTag(std::abs(ep->geo.Source));
  if(!from) return;

  for(unsigned int i = 0; i < from->triangles.size(); i++){
    for(int j = 0; j < ep->mesh.NbLayer; j++) {
      for(int k = 0; k < ep->mesh.NbElmLayer[j]; k++) {
        std::vector<MVertex*> v;
        if(getExtrudedVertices(from->triangles[i], ep, j, k, pos, v) == 6){
#if 0 // old
          if(!edgeExists(v[0], v[4], edges))
            createEdge(v[1], v[3], edges);
          if(!edgeExists(v[4], v[2], edges))
            createEdge(v[1], v[5], edges);
          if(!edgeExists(v[3], v[2], edges))
            createEdge(v[0], v[5], edges);
#else // new from Michel Benhamou
          if(v[1] < v[0]) createEdge(v[1], v[3], edges);
          else createEdge(v[0], v[4], edges);
          if(v[1] < v[2]) createEdge(v[1], v[5], edges);
          else createEdge(v[4], v[2], edges);
          if(v[0] < v[2]) createEdge(v[0], v[5], edges);
          else createEdge(v[3], v[2], edges);
#endif
        }
      }
    }
  }
}
Example #7
0
void testBetweennessCentrality(int bucketsNumber, int bucketSize) {
    //create small graph for testing betweenness Centrality
    Graph* gBetw = createGraph(bucketsNumber, bucketSize);

    Node* n1Betw = createNode(1, NULL);
    Node* n2Betw = createNode(2, NULL);
    Node* n3Betw = createNode(3, NULL);
    Node* n4Betw = createNode(4, NULL);
    Node* n5Betw = createNode(5, NULL);

    insertNode(n1Betw, gBetw);
    insertNode(n2Betw, gBetw);
    insertNode(n3Betw, gBetw);
    insertNode(n4Betw, gBetw);
    insertNode(n5Betw, gBetw);

    /* Create edges and set properties */
    Edge* e1Betw = createEdge(1, 2, NULL);
    Edge* e2Betw = createEdge(2, 1, NULL);
    Edge* e3Betw = createEdge(2, 3, NULL);
    Edge* e4Betw = createEdge(2, 4, NULL);
    Edge* e5Betw = createEdge(3, 2, NULL);
    Edge* e6Betw = createEdge(3, 5, NULL);
    Edge* e7Betw = createEdge(4, 2, NULL);
    Edge* e8Betw = createEdge(4, 5, NULL);
    Edge* e9Betw = createEdge(5, 3, NULL);
    Edge* e10Betw = createEdge(5, 4, NULL);

    /* Insert edges in graph */
    insertEdge(1, e1Betw, gBetw);
    insertEdge(2, e2Betw, gBetw);
    insertEdge(2, e3Betw, gBetw);
    insertEdge(2, e4Betw, gBetw);
    insertEdge(3, e5Betw, gBetw);
    insertEdge(3, e6Betw, gBetw);
    insertEdge(4, e7Betw, gBetw);
    insertEdge(4, e8Betw, gBetw);
    insertEdge(5, e9Betw, gBetw);
    insertEdge(5, e10Betw, gBetw);

    double betwCentrty1 = betweennessCentrality(n1Betw, gBetw);
    CHECKDOUBLE("Small Graph betweenness centrality node:1 ", betwCentrty1, 0.0 / 6.0);

    double betwCentrty2 = betweennessCentrality(n2Betw, gBetw);
    CHECKDOUBLE("Small Graph betweenness centrality node:2 ", betwCentrty2, 0.583);

    double betwCentrty3 = betweennessCentrality(n3Betw, gBetw);
    CHECKDOUBLE("Small Graph betweenness centrality node:3 ", betwCentrty3, 1.0 / 6.0);

    double betwCentrty4 = betweennessCentrality(n4Betw, gBetw);
    CHECKDOUBLE("Small Graph betweenness centrality node:4 ", betwCentrty4, 1.0 / 6.0);

    double betwCentrty5 = betweennessCentrality(n5Betw, gBetw);
    CHECKDOUBLE("Small Graph betweenness centrality node:5 ", betwCentrty5, 0.5 / 6.0);
}
Example #8
0
GNEJunction*
GNENet::splitEdge(GNEEdge* edge, const Position& pos, GNEUndoList* undoList, GNEJunction* newJunction) {
    undoList->p_begin("split edge");
    deleteEdge(edge, undoList); // still exists. we delete it so we can reuse the name in case of resplit
    // compute geometry
    const PositionVector& oldGeom = edge->getNBEdge()->getGeometry();
    const SUMOReal linePos = oldGeom.nearest_offset_to_point2D(pos, false);
    std::pair<PositionVector, PositionVector> newGeoms = oldGeom.splitAt(linePos);
    // figure out the new name
    int posBase = 0;
    std::string baseName = edge->getMicrosimID();
    if (edge->wasSplit()) {
        size_t sep_index = baseName.rfind('.');
        if (sep_index != std::string::npos) { // edge may have been renamed in between
            std::string posString = baseName.substr(sep_index + 1);
            try {
                posBase = TplConvert::_2int(posString.c_str());
                baseName = baseName.substr(0, sep_index); // includes the .
            } catch (NumberFormatException) {
            }
        }
    }
    baseName += '.';
    // create edges
    if (newJunction == 0) {
        newJunction = createJunction(pos, undoList);
    }
    GNEEdge* firstPart = createEdge(edge->getSource(), newJunction, edge,
                                    undoList, baseName + toString(posBase), true);
    GNEEdge* secondPart = createEdge(newJunction, edge->getDest(), edge,
                                     undoList, baseName + toString(posBase + (int)linePos), true);
    // fix geometry
    firstPart->setAttribute(GNE_ATTR_SHAPE_START, toString(newGeoms.first[0]), undoList);
    firstPart->setAttribute(GNE_ATTR_SHAPE_END, toString(newGeoms.first[-1]), undoList);
    newGeoms.first.pop_back();
    newGeoms.first.erase(newGeoms.first.begin());
    firstPart->setAttribute(SUMO_ATTR_SHAPE, toString(newGeoms.first), undoList);

    secondPart->setAttribute(GNE_ATTR_SHAPE_START, toString(newGeoms.second[0]), undoList);
    secondPart->setAttribute(GNE_ATTR_SHAPE_END, toString(newGeoms.second[-1]), undoList);
    newGeoms.second.pop_back();
    newGeoms.second.erase(newGeoms.second.begin());
    secondPart->setAttribute(SUMO_ATTR_SHAPE, toString(newGeoms.second), undoList);
    // fix connections
    std::vector<NBEdge::Connection>& connections = edge->getNBEdge()->getConnections();
    for (std::vector<NBEdge::Connection>::iterator con_it = connections.begin(); con_it != connections.end(); con_it++) {
        undoList->add(new GNEChange_Connection(
                          secondPart, con_it->fromLane, con_it->toEdge->getID(), con_it->toLane, false, true), true);
    }
    undoList->p_end();
    return newJunction;
}
Example #9
0
void InitGL()
{
	glClearColor( 1.0,1.0,1.0,1.0 );
	glClearDepth(1.0);

	GLenum err = glewInit();
	if (GLEW_OK != err)
		printf( "%s\n", glewGetErrorString(err) );

	if ( GLEW_ARB_vertex_buffer_object )
		printf( "VBO extersion is supported!\n");
	if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GL_EXT_geometry_shader4)
		printf("Ready for GLSL - vertex, fragment, and geometry units.\n");
	else {
		printf("Not totally ready :( \n");
	}

	glClearColor( 1.0,1.0,1.0,1.0);
	glClearDepth(1.0);
 
	vboVertex = -1;
	vboList = -1;	

	if(test_mode == 1)
		initVBO();
	else if(test_mode == 2)
	{
		if(test_type == 1)
			DLpoint = createPoint();
		else if(test_type == 2)
			DLedge = createEdge();
		else if(test_type == 3)
			DLtriangle = createTriangle();
	}
}
Example #10
0
/*
 * Takes all the wiki pages and creates edges between each page
 */
list<Edge> createAllEdges(list<WikiPage>& pages){
	list<Edge> edges;

	//Iterate through the list of pages
	for (WikiPage firstPage : pages){
		int idFirst = firstPage.ID;

		//Find an adjacent page for each page
		for (WikiPage secondPage : pages){
			int idSecond = secondPage.ID;

			//If the first page matches the second page, skip
			if (idFirst == idSecond) continue;

			//Else, create an edge between the pages
			Edge newEdge = createEdge(firstPage, secondPage);

			//Only add the edge if its weight > 0
			if (newEdge.weight != 0){
				edges.push_back(newEdge);
			}
		}
	}

	return edges;
}
Example #11
0
/**
 * Given a number of vertices and a number of edges, generates a graph
 * connecting random pairs of vertices. The edges are unique, and thus their is
 * a maximum number of edges allowed in proportion to the number of vertices.
 * numEdges must be in the interval [0, numVertices * (numVertices + 1) / 2].
 * @param numVertices
 * @param numEdges
 * @return
 */
Graph* randomGraph(int numVertices, int numEdges)
{
    assert(numVertices > 0);
    assert(numEdges >= 0);
    assert(numEdges <= numVertices * (numVertices - 1) / 2);
    
    Graph* graph = malloc(sizeof(Graph));
    graph->numVertices = numVertices;
    graph->numEdges = numEdges;
    graph->vertexSet = malloc(sizeof(Vertex) * numVertices);
    
    // Initialize vertices
    for (int i = 0; i < graph->numVertices; ++i)
    {
        Vertex* vertex = &graph->vertexSet[i];
        vertex->label = i;
        vertex->isVisited = 0;
        vertex->numNeighbors = 0;
        vertex->neighbors = NULL;
    }
    
    // Randomly connect vertices
    Edge* edges = randomEdges(numVertices, numEdges);
    for (int i = 0; i < numEdges; ++i)
    {
        Vertex* v1 = &graph->vertexSet[edges[i].i];
        Vertex* v2 = &graph->vertexSet[edges[i].j];
        createEdge(v1, v2);
    }
    free(edges);
    
    return graph;
}
Example #12
0
/* draw figure what was chosen from the buttons */
void mouse(int button, int state, int x, int y)
{
  int new_y = mapState.window_height - y;
  int a;
  Point* new_point ;
  a = (x > PANEL_BORD_PADDING);

  initFlag(x, new_y);

  if (mapState.drawing_state == DRAWING_RECT && a) {
    drawRectangle(x, new_y);

  } else if (mapState.drawing_state == DRAWING_CIRCLE && a) {
    drawCircle(x, new_y, CIRCLE_DIAMETER);

  } else if (mapState.drawing_state == DRAWING_LINE && a) {

    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
      mapState.DrawingLine = START;
      mapState.new_point = createPoint(x, new_y, mapState.points_storage, mapState.marked_point);
      createEdge(mapState.edges_storage, mapState.new_point, mapState.marked_point, mapState.previous_point);
      mapState.previous_point = mapState.new_point;
    }  
    draw();
  }
}
//Lecture d'une matrice et transformation en arêtes.
static void readMatrixAndCreateEdges(Matrix m){
  // On crée un tableau contenant toutes les arêtes.
  ensemble = malloc(sizeof(Edge)*somme(getMatrixLength(m)));
  tailleEnsemble = somme(getMatrixLength(m));
  int numCase = 0;
  Edge tmp;
  caseActuelleEnsemble = 0;

  for (int i=0; i<getMatrixLength(m); i++){
    for (int j=i+1; j<getMatrixLength(m); j++){
      ensemble[numCase] = createEdge(i, j, getMatrixValue(m, i, j));

      if (numCase > 0){
        // Si la case actuelle a un poids plus léger que la précédente
        if (ensemble[numCase]->weightEdge < ensemble[numCase-1]->weightEdge){
          int n = numCase;
          // On la fait reculer tant qu'elle est plus légère que la case précédente, qui effectue un tri du tableau en le remplissant.
          while (n > 0 && ensemble[n]->weightEdge < ensemble[n-1]->weightEdge){
            tmp = ensemble[n];
            ensemble[n] = ensemble[n-1];
            ensemble[n-1] = tmp;
            n--;
          }
        }
      }
      numCase++;
    }
  }

  //Affiche le tableau des arêtes de la matrice, trié.
  //for (int i=0; i<tailleEnsemble; i++){
  //  printEdgeValues(ensemble[i]);
  //}
}
Example #14
0
void Voronoi::onInit()
{
	assert((vertices.size() == 0) && (edges.size() == 0) && "container should be empty");

	// should check if p_boundary is empty.

	//create boundary
	p_boundary = { Vec2(0,0),Vec2(1,0),Vec2(1,1),Vec2(0,1) };
	for (auto& p : p_boundary)
		p = Vec2(
			((p.x - 0.5) * 10 + 0.5)*boundary_rect.width + boundary_rect.left,
			((p.y - 0.5) * 10 + 0.5)*boundary_rect.height + boundary_rect.top);

	for (int i = 0; i < p_boundary.size(); i++)
	{
		auto v = createVertex(p_boundary[i]);
	}
	auto it_back_v = std::prev(vertices.end());
	for (auto it = vertices.begin(); it != vertices.end(); it++)
	{
		QuadEdge* e = createEdge();
		e->SetEndPoints(&*it_back_v, &*it);
		(&*it_back_v)->e = &edges.back().e[0];
		it_back_v = it;
	}

	auto it_back_e = std::prev(edges.end());
	for (auto it = edges.begin(); it != edges.end(); it++)
	{
		QuadEdge::Splice((*it_back_e).e[0].Sym(), &(*it).e[0]);
		it_back_e = it;
	}

	//triangulation
	if (p_boundary.size() >= 4)
	{
		QuadEdge* e = &edges.begin()->e[0];
		QuadEdge* e_end = e->Lprev()->Lprev();
		e = e->Lnext();
		do
		{
			QuadEdge* et = e->Lnext();
			QuadEdge::Connect(createEdge(), e, e->Lprev());
			e = et;
		} while (e != e_end);
	}
}
Example #15
0
File: Graph.c Project: dejarc/Graph
void addEdge(vertex mySource, vertex myDestination, int myCost) {
    edge myEdge = createEdge(myDestination, myCost);
    mySource->myEdges[mySource->num_edges++] = myEdge;
    if(mySource->num_edges == mySource->max_edges - 1) {
        mySource->max_edges *= 2;
        mySource->myEdges = realloc(mySource->myEdges, sizeof(edge) * mySource->max_edges);
    }
}
Edge* setEdgeTrustProperties(int startNodeID, int endNodeID, double trust) {
    Properties* propEdge = createProperties(TRUST_GRAPH_REL_PROPERTIES_NUM);
    setDoubleProperty(trust, 0, propEdge);


    Edge* e = createEdge(startNodeID, endNodeID, propEdge);
    return e;
}
/**
 * Atualiza o vértice
 * @param orig vértice de origem
 * @param dest vértice de destino
 * @param stat tipo de operação
 */
void update_aresta(int orig, int dest, int stat) {
    int i = getVertexIndex(orig),
        j = getVertexIndex(dest);

    if(i == count) {
        puts("Vérice origem não existe");
        return;
    }

    if(j == count) {
        puts("Vertice de destino não encontrado");
        return;
    }

    t_edge *here, *aux, *before;

    here = aux = before = NULL;

    here = edges[i];

    while (here != NULL)
        if (here->dest == j) {
            if(stat) {
                puts("Aresta repetida");
                return;
            } else
                break;
        } else {
            before = here;
            here = here->next;
        }

    if(stat) {
        aux = createEdge(j);

        if(before == NULL)
            edges[i] = aux;
        else
            before->next = aux;

        puts("Aresta inserida com sucesso");
    } else {

        if(before == NULL) {
            aux = here;
            edges[i] = here->next;
        } else {
            aux = before->next;
            before->next = aux->next;
        }

        free(aux);
        aux = NULL;

        puts("Aresta removida com sucesso");
    }

}
Example #18
0
Vertex* Voronoi::InsertPoint(const Vec2& p)
{
	QuadEdge* e = LocateTriangleEdge(p);
	if (e == nullptr ||
		p == e->Org()->p || p == e->Dest()->p)
		return nullptr;
	else if (VoronoiMath::Collinear(e, p))
	{
		e = e->Oprev();
		QuadEdge* et = e->Onext();
		QuadEdge::Disconnect(et);
		deleteEdge(et->RootEdge());
	}
	Vertex* v = createVertex(p);
	v->e = e;
	
	QuadEdge* e_begin = createEdge();
	e_begin->SetEndPoints(e->Org(), v);
	QuadEdge* et = e_begin;
	QuadEdge::Splice(e_begin, e);
	do
	{
		QuadEdge* et2 = createEdge();
		QuadEdge::Connect(et2, e, et->Sym());
		et = et2;
		e = et->Oprev();
	} while (e->Lnext() != e_begin);

	do
	{
		et = e->Oprev();
		if (VoronoiMath::OnRight(e, et->Dest()->p) &&
			VoronoiMath::InCircle(e->Org()->p, et->Dest()->p, e->Dest()->p, p))
		{
			QuadEdge::Flip(e);
			e = e->Oprev();
		}
		else if (e->Onext() == e_begin)
			break;
		else
			e = e->Onext()->Lprev();
	} while (true);

	return v;
}
Example #19
0
 void construct (int iCPX, bool A_CPX_exists, bool B_CPX_exists, int iA_CPX, int iB_CPX, int iA, int iB, vector<FrontMember>& frontList,
          vector<Edge>& edges, vector<Triangle>& triangles, TriangleADT& triangleADT, EdgeADT& edgeADT, int newGridId, vector<Point>& points, CircleADT& circleADT, int iFrontEdge)
 {
     //int iFrontEdge = frontList.front().edge;
     
     if (!A_CPX_exists)
     {
         Edge tmpEdge = createEdge (iA, iCPX, newGridId, true);
         addToEdgeList (tmpEdge, iA, iCPX, edges, edgeADT, points);
         iA_CPX = edges.size() - 1;
         addToFrontList (iA_CPX, frontList, points, edges);
         
         Point cntPoint;
         cntPoint.belonging = newGridId;
         cntPoint.dim = 0.5 * (points[tmpEdge.t[0]].dim + points[tmpEdge.t[1]].dim);
         //addToPointList (cntPoint, edgeCenters, edgeCenterADT);
     }
     else
     {
         eraseExistingEdgeFromFrontList (iA_CPX, frontList);
     }
     
     if (!B_CPX_exists)
     {
         Edge tmpEdge = createEdge (iB, iCPX, newGridId, true);
         addToEdgeList (tmpEdge, iB, iCPX, edges, edgeADT, points);
         iB_CPX = edges.size() - 1;
         addToFrontList (iB_CPX, frontList, points, edges);
         
         Point cntPoint;
         cntPoint.belonging = newGridId;
         cntPoint.dim = 0.5 * (points[tmpEdge.t[0]].dim + points[tmpEdge.t[1]].dim);
         //addToPointList (cntPoint, edgeCenters, edgeCenterADT);
     }
     else
     {
         eraseExistingEdgeFromFrontList (iB_CPX, frontList);
     }
     
     Triangle tmpTriangle = createTriangle (iFrontEdge, iA_CPX, iB_CPX, edges, points);
     addToTriangleList (triangles, tmpTriangle, triangleADT, points, circleADT, edges, frontList);
     
     eraseFromFrontList (frontList, iFrontEdge);
     //sortFrontList (frontList, points, edges);
 }
Example #20
0
void
GNENet::reverseEdge(GNEEdge* edge, GNEUndoList* undoList) {
    undoList->p_begin("reverse edge");
    deleteEdge(edge, undoList); // still exists. we delete it so we can reuse the name in case of resplit
    GNEEdge* reversed = createEdge(edge->getDest(), edge->getSource(), edge, undoList, edge->getID(), false, true);
    assert(reversed != 0);
    reversed->setAttribute(SUMO_ATTR_SHAPE, toString(edge->getNBEdge()->getInnerGeometry().reverse()), undoList);
    undoList->p_end();
}
Example #21
0
Edge* setEdgeDoubleProperties(int startNodeID, int endNodeID,double prop){
    Properties* propEdge = createProperties(1);

	setDoubleProperty(prop,0,propEdge);

    /*create an edge*/
    Edge* e = createEdge(startNodeID, endNodeID, propEdge);
    return e	;
	
}
Edge* setEdgeProperties(int startNodeID, int endNodeID, char* type, double weight) {

    /*create edge properties*/
    Properties* propEdge = createProperties(PERSON_REL_PROPERTIES_NUM);
    setStringProperty(type, 0, propEdge);
    setDoubleProperty(weight, 1, propEdge);

    /*create an edge*/
    Edge* e = createEdge(startNodeID, endNodeID, propEdge);
    return e;
}
Example #23
0
 /*  Creates the edge of the graph using the provided overlaps,
  *  for each overlap 2 edges are created as described in the string graph paper
  */
 void createEdges(std::vector<Overlap*>& overlaps){
     std::map<int, Vertex*> map;
     for(Vertex *v:vertices){
         map[v->hashCode()]=v;
     }
     for(Overlap *overlap:overlaps){
         if(overlap!=NULL){
             createEdge(overlap, map);   
         }
     }
 }
Edge* setEdgeProperties(int startNodeID, int endNodeID, char* type, int weight, Graph* g) {

    /*create edge properties*/
    Properties* propEdge = createProperties(PERSON_REL_PROPERTIES_NUM);
    setStringProperty(type, 0, propEdge);
    setIntegerProperty(weight, 1, propEdge);

    /*create an edge*/
    Node* endNode = g->lookUpItem(endNodeID);
    Edge* e = createEdge(endNode, propEdge);
    return e;
}
Example #25
0
/**
 * Loads a graph from the given file. The file's first line must be the number
 * of vertices in the graph and each consecutive line must be a list of numbers
 * separated by spaces. The first number is the next vertex and the following
 * numbers are its neighbors.
 * @param fileName
 * @return
 */
Graph* loadGraph(const char* fileName)
{
    FILE* file = fopen(fileName, "r");
    char buffer[512];
    
    // Get the number of vertices
    fgets(buffer, sizeof buffer, file);
    int numVertices = (int) strtol(buffer, NULL, 10);
    Graph* graph = malloc(sizeof(Graph));
    graph->numVertices = numVertices;
    graph->numEdges = 0;
    
    // Initialize vertices
    graph->vertexSet = malloc(sizeof(Vertex) * numVertices);
    for (int i = 0; i < numVertices; ++i)
    {
        Vertex* vertex = &graph->vertexSet[i];
        vertex->isVisited = 0;
        vertex->label = i;
        vertex->neighbors = NULL;
        vertex->numNeighbors = 0;
    }
    
    // Create edges
    while (fgets(buffer, sizeof buffer, file) != NULL)
    {
        char* begin = buffer;
        char* end = NULL;
        
        // Get vertex
        int i = (int) strtol(begin, &end, 10);
        Vertex* vertex = &graph->vertexSet[i];
        begin = end;
        
        // Create edges
        for (int i = (int) strtol(begin, &end, 10);
             end != begin;
             i = (int) strtol(begin, &end, 10))
        {
            Vertex* neighbor = &graph->vertexSet[i];
            if (!isAdjacent(vertex, neighbor))
            {
                createEdge(vertex, neighbor);
                ++(graph->numEdges);
            }
            begin = end;
        }
    }
    fclose(file);
    
    return graph;
}
Example #26
0
void
GNENet::remapEdge(GNEEdge* oldEdge, GNEJunction* from, GNEJunction* to, GNEUndoList* undoList, bool keepEndpoints) {
    deleteEdge(oldEdge, undoList); // delete first so we can reuse the name, reference stays valid
    if (from != to) {
        GNEEdge* newEdge = createEdge(from, to, oldEdge, undoList, oldEdge->getMicrosimID(), false, true);
        newEdge->setAttribute(SUMO_ATTR_SHAPE, oldEdge->getAttribute(SUMO_ATTR_SHAPE), undoList);
        if (keepEndpoints) {
            newEdge->setAttribute(GNE_ATTR_SHAPE_START, oldEdge->getAttribute(GNE_ATTR_SHAPE_START), undoList);
            newEdge->setAttribute(GNE_ATTR_SHAPE_END, oldEdge->getAttribute(GNE_ATTR_SHAPE_END), undoList);
        }
    }
    // @todo remap connectivity as well
}
Example #27
0
Edge* setEdgeProperties(int startNodeID, int endNodeID, char** property,const int* type, int properties ) {
    int i ;
    /*create edge properties*/
    Properties* propEdge = createProperties(properties);

    for (i=0;i<properties;i++)
    	if (type[i]==1)
    		 setStringProperty(property[i], i, propEdge);
		else if (type[i]==2)
			  setIntegerProperty(property[i], i, propEdge);

    /*create an edge*/
    Edge* e = createEdge(startNodeID, endNodeID, propEdge);
    return e;
}
	void SolventAccessibleSurface::get()
	{
		for (Position i = 0; i < number_of_vertices_; i++)
		{
			createVertex(i);
		}

		for (Position i = 0; i < number_of_edges_; i++)
		{
			createEdge(i);
		}

		for (Position i = 0; i < number_of_faces_; i++)
		{
			createFace(i);
		}
	}
Example #29
0
void
GNENet::replaceJunctionByGeometry(GNEJunction* junction, GNEUndoList* undoList) {
    undoList->p_begin("Replace junction by geometry");
    assert(junction->getNBNode()->checkIsRemovable());
    std::vector<std::pair<NBEdge*, NBEdge*> > toJoin = junction->getNBNode()->getEdgesToJoin();
    for (std::vector<std::pair<NBEdge*, NBEdge*> >::iterator j = toJoin.begin(); j != toJoin.end(); j++) {
        GNEEdge* begin = myEdges[(*j).first->getID()];
        GNEEdge* continuation = myEdges[(*j).second->getID()];
        deleteEdge(begin, undoList);
        deleteEdge(continuation, undoList);
        GNEEdge* newEdge = createEdge(begin->getSource(), continuation->getDest(), begin, undoList, begin->getMicrosimID(), false, true);
        PositionVector newShape = begin->getNBEdge()->getInnerGeometry();
        newShape.push_back(junction->getNBNode()->getPosition());
        newShape.append(continuation->getNBEdge()->getInnerGeometry());
        newEdge->setAttribute(SUMO_ATTR_SHAPE, toString(newShape), undoList);
        // @todo what about trafficlights at the end of oontinuation?
    }
    deleteJunction(junction, undoList);
    undoList->p_end();
}
Example #30
0
void Map::loadElements() {
    MapVertex * v0 = createVertex(100, 0);
    MapVertex * v1 = createVertex(10, 300);
    MapVertex * v2 = createVertex(175, 420);
    //MapVertex * v3 = createVertex(250, 420);
    MapVertex * v4 = createVertex(400, 350);
    MapVertex * v5 = createVertex(450, 375);
    MapVertex * v6 = createVertex(500, 350);
    MapVertex * v7 = createVertex(800, 400);
    MapVertex * v8 = createVertex(750, 0);
    
    createEdge(v1, v0, false, false, 1);
    createEdge(v2, v1, true, 2);
    //createEdge(v3, v2, true, 2);
    createEdge(v4, v2, true, 2);
    createEdge(v5, v4, true, 2);
    createEdge(v6, v5, true, 2);
    createEdge(v7, v6, true, 2);
    createEdge(v8, v7, false, false, 1);
}