void SoColorShape::storeTriangle(const SbVec3f& point1, const SbVec3f& point2, const SbVec3f& point3, const SbVec3f& normal1, const SbVec3f& normal2, const SbVec3f& normal3, const int& colorIndex1) { // liegt das Dreieck komplett draußen, wenn ja, nicht speichern! if (colorIndex1 != 0) { // Schwerpunkt und Position im Array bestimmen SbVec3f barycenter; float baryX, baryY, baryZ; barycenter = point1 - _offSet; barycenter += point2 - _offSet; barycenter += point3 - _offSet; // durch 3 weil bestehend aus 3 Vektoren barycenter = barycenter / 3.0; // durch HASH_PARTITION weil aufteilen barycenter = barycenter / float(HASH_PARTITION); barycenter.getValue(baryX, baryY, baryZ); int arrayPosition; arrayPosition = ((int)fabs(baryX)) + ((int)fabs(baryY)) * _extentX + ((int)fabs(baryZ)) * _extentX * _extentY; // Eckpunkte abspeichern und Indices besorgen const Vertex *vertex1, *vertex2, *vertex3; vertex1 = insertVertex(point1, normal1, colorIndex1, arrayPosition); vertex2 = insertVertex(point2, normal2, colorIndex1, arrayPosition); vertex3 = insertVertex(point3, normal3, colorIndex1, arrayPosition); // Kanten finden bzw. anlegen Edge *edge1, *edge2, *edge3; edge3 = generateEdge(vertex1, vertex2, arrayPosition); edge1 = generateEdge(vertex2, vertex3, arrayPosition); edge2 = generateEdge(vertex3, vertex1, arrayPosition); // Dreieck ablegen Triangle* tri = new Triangle; tri->vertex1 = vertex1; tri->vertex2 = vertex2; tri->vertex3 = vertex3; tri->edge1 = edge1; tri->edge2 = edge2; tri->edge3 = edge3; _triangleSet[arrayPosition].insert(tri); // Den Kanten die Dreiecke zuweisen if (edge1->triangle1 == 0) edge1->triangle1 = tri; else edge1->triangle2 = tri; if (edge2->triangle1 == 0) edge2->triangle1 = tri; else edge2->triangle2 = tri; if (edge3->triangle1 == 0) edge3->triangle1 = tri; else edge3->triangle2 = tri; } }
void insertPhraseVertices( HSentenceVertices & topLeft, HSentenceVertices & topRight, HSentenceVertices & bottomLeft, HSentenceVertices & bottomRight, int startF, int startE, int endF, int endE) { insertVertex(topLeft, startF, startE); insertVertex(topRight, endF, startE); insertVertex(bottomLeft, startF, endE); insertVertex(bottomRight, endF, endE); }
// inserts a new edge joining u to v // pre: 1<=u<=getOrder(), 1<=v<=getOrder() void addEdge(Graph G, int u, int v){ if( 1>u || u>getOrder(G) ){ printf("Graph Error: vertex u is not in |V(G)|"); exit(1); } if( 1>v || v>getOrder(G) ){ printf("Graph Error: vertex v is not in |V(G)|"); exit(1); } insertVertex(G->adj[u], v); insertVertex(G->adj[v], u); G->size++; }
void OptimizedPolyList::vertex(const Point3F& p, const Point3F& normal, const Point2F& uv0, const Point2F& uv1) { mIndexList.push_back(insertVertex(p, normal, uv0, uv1)); }
Graph::Graph(const vector<double> &V, const vector<double> &E) { for(unsigned v = 0; v < V.size(); v += 2) insertVertex(V[v], V[v+1], v/2); for(unsigned e = 0; e < E.size(); e += 2) insertEdge(E[e], E[e+1]); }
void My3DViewer::setAztec(MyGLWidget* m){ aztec=m; connect(splitQuad, SIGNAL(clicked()), aztec, SLOT(splitQuad())); connect(deleteVertex, SIGNAL(clicked()), aztec, SLOT(deleteVertex())); connect(insertEdge, SIGNAL(clicked()), aztec, SLOT(insertEdge())); connect(incrementSharpness, SIGNAL(clicked()), aztec, SLOT(incSharpness())); connect(decrementSharpness, SIGNAL(clicked()), aztec, SLOT(decSharpness())); connect(forcePlanarity, SIGNAL(clicked()), aztec, SLOT(toggleForcePlanarity())); connect(insertVertex, SIGNAL(clicked()), aztec, SLOT(insertVertex())); connect(smooth, SIGNAL(clicked()), aztec, SLOT(smooth())); connect(extrude, SIGNAL(clicked()), aztec, SLOT(extrude2())); connect(faceButton, SIGNAL(clicked()), aztec, SLOT(enterFaceMode())); connect(objectButton, SIGNAL(clicked()), aztec, SLOT(enterObjectMode())); connect(vertexButton, SIGNAL(clicked()), aztec, SLOT(enterVertexMode())); connect(edgeButton, SIGNAL(clicked()), aztec, SLOT(enterEdgeMode())); connect(cpButton, SIGNAL(clicked()), aztec, SLOT(enterCPMode())); connect(snapToFace, SIGNAL(clicked()), aztec, SLOT(snapToFace())); connect(snapToEdge, SIGNAL(clicked()), aztec, SLOT(snapToEdge())); connect(snapToVertex, SIGNAL(clicked()), aztec, SLOT(snapToVertex())); //Connect mouse move events connect(aztec, SIGNAL(sendMouseEvent(QMouseEvent*)), this, SLOT(moveEvent(QMouseEvent*))); //errors connect(aztec, SIGNAL(error(char*)), this, SLOT(throwError(char*))); }
void AdjecencyList::fileRead(string fileName) { ifstream file; string currentLine; file.open(fileName.c_str()); //open the file assert(file.is_open()); //make sure file is open //insert all vertices and edges into matrix while(!file.eof()) { vector<string> data; getline(file, currentLine); //split contents up into a vector, splitting them on a space stringstream str; str << currentLine; int counter = 0; int edgeWeight = 0; while (getline(str, currentLine, ' ')) { counter++; if (counter != 3) { data.push_back(currentLine); } else { edgeWeight = atoi(currentLine.c_str()); } } /** now that we have the data, we need to insert it into the matrix & reference */ //add all new vertices, it will do nothing if the vertex already exists for (int i = 0; i < data.size(); i++) { GraphNode node; node.value = data.at(i); insertVertex(node); } //also insert the first node's connections (edges) for (int i = 1; i < data.size(); i++) { //loop will not even be entered if there is only 1 vertex input, (a point) GraphNode headNode; headNode.value = data.at(0); GraphNode connectionNode; connectionNode.value = data.at(i); insertEdge(headNode, connectionNode, edgeWeight); } } file.close(); } //read a graph from a file, and assemble it into a list
main() { int choice,u,origin,destin; while(1) { printf("1.Insert a Vertex\n"); printf("2.Insert an Edge\n"); printf("3.Delete a Vertex\n"); printf("4.Delete an Edge\n"); printf("5.Display\n"); printf("6.Exit\n"); printf("Enter your choice : "); scanf("%d",&choice); system("cls"); switch(choice) { case 1: printf("Enter a vertex to be inserted : "); scanf("%d",&u); insertVertex(u); break; case 2: printf("Enter an Edge to be inserted : "); scanf("%d %d",&origin,&destin); insertEdge(origin,destin); break; case 3: printf("Enter a vertex to be deleted : "); scanf("%d",&u); /*This function deletes all edges coming to this vertex*/ deleteIncomingEdges(u); /*This function deletes the vertex from the vertex list*/ deleteVertex(u); break; case 4: printf("Enter an edge to be deleted : "); scanf("%d %d",&origin,&destin); deleteEdge(origin,destin); break; case 5: display(); break; case 6: exit(1); default: printf("Wrong choice\n"); break; }/*End of switch*/ }/*End of while*/ }/*End of main()*/
/** * Constructor to create a random, connected graph. * @param isWeighted - specifies whether the graph is a weighted graph or not * @param numVertices - the number of vertices the graph will have * @param seed - a random seed to create the graph with */ Graph::Graph(bool isWeighted, int numVertices, unsigned long seed) : graph(VertexMap()), vertexLabels(VertexLabelMap()), random(Random(seed)), weighted(isWeighted), vertexCounter(0) { if (numVertices < 2) error("numVertices too low"); vector<Vertex> vertices; for (int i = 0; i < numVertices; ++i) { Vertex next = insertVertex(); vertices.push_back(next); } // make sure all vertices are connected random.shuffle(vertices); Vertex cur = vertices[0]; for (size_t i = 0; i < vertices.size() - 1; ++i) { Vertex next = vertices[i + 1]; insertEdge(cur, next); if (weighted) { int weight = random.nextInt(); setEdgeWeight(cur, next, weight); } cur = next; } // keep the graph from being overpopulated with edges, // while still maintaining a little randomness int numFailures = 0; int idx = 0; random.shuffle(vertices); while (numFailures < 2) { if (!insertEdge(vertices[idx], vertices[idx + 1])) { ++numFailures; } else { // if insertEdge() succeeded... if (isWeighted) setEdgeWeight(vertices[idx], vertices[idx + 1], random.nextInt()); ++idx; if (idx >= numVertices - 2) { idx = 0; random.shuffle(vertices); } } } }
int main() { int i, j; printf("Enter the number of vertices in the graph :\n"); scanf("%d", &V); vertex *graph = createGraph(V); insertEdge(1, 2, graph); insertEdge(2, 3, graph); printf("Number of edges in the graph : %d\n", E); printList(graph); insertVertex(&graph); insertEdge(4, 1, graph); printf("Number of edges in the graph : %d\n", E); printList(graph); }
void Graph::addArc(Edge* e) { // Cria uma lista de ponteiro para Edge e pega o vertice fonte vector<Edge*>* list; Vertex *v = e->getSource(); // Se o vertice não está na lista de adjacencia, insere-o if(edges->find(v) == edges->end()) { insertVertex(v); } list = edges->find(v)->second; // Insere o Edge no local correto list->push_back(e); }
//-------------------------------------------------------------------------- //Summary: // insert vertex and relative edge //Parameter: // _vertexList[in]: vertex list and create edge //------------------------------------------------------------------------ void CLandsideGraph::insertVertexAndEdge( LandsideTrafficGraphVertexList& _vertexList ) { int iSourceIndex,iDestIndex; double weight; LandsideTrafficGraphEdge edgeS2D; ////////////////////////////////////////////////////////////////////////// // because is undirect graph, so shall add two edge between two vertex LandsideTrafficGraphVertex vertexS = _vertexList[0]; LandsideTrafficGraphVertex vertexD = _vertexList[1]; weight = GetWeight(vertexS,vertexD); { insertVertex( vertexS, iSourceIndex ); insertVertex( vertexD, iDestIndex ); edgeS2D.SetSourceSegment(iSourceIndex); edgeS2D.SetDestSegment(iDestIndex); edgeS2D.SetWeight(weight); insertEdge( edgeS2D ); } for( unsigned i=1; i<_vertexList.size()-1; i++ ) { vertexS = vertexD; vertexD = _vertexList[i+1]; weight = GetWeight(vertexS,vertexD); iSourceIndex = iDestIndex; insertVertex( vertexD, iDestIndex ); edgeS2D.SetSourceSegment(iSourceIndex); edgeS2D.SetDestSegment(iDestIndex); edgeS2D.SetWeight(weight); insertEdge( edgeS2D ); } }
Graph::Graph(const vector<const Intersection> &isecns, const vector<const Road> &roads) { for(unsigned i = 0; i < isecns.size(); i++) insertVertex(isecns[i][0], isecns[i][1], i); for(unsigned i = 0; i < roads.size(); i++) { int i1 = roads[i].getIntersection(0); int i2 = roads[i].getIntersection(1); /* if(i1 == i2) { printf("lol\n"); continue; } */ insertEdge(i1, i2); } }
int QgsVectorLayerEditUtils::insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults ) { if ( !L->hasGeometryType() ) return 1; int returnval = 0; QgsPoint layerPoint; QList<QgsSnappingResult>::const_iterator it = snapResults.constBegin(); for ( ; it != snapResults.constEnd(); ++it ) { if ( it->snappedVertexNr == -1 ) // segment snap { layerPoint = it->snappedVertex; if ( !insertVertex( layerPoint.x(), layerPoint.y(), it->snappedAtGeometry, it->afterVertexNr ) ) { returnval = 3; } } } return returnval; }
U32 OptimizedPolyList::addPoint(const Point3F& p) { return insertVertex(p); }
//main///////////////////////////////////////////////////////////////////////////////////////////////////////// int main(){ mapa m; grafo g = inicializaGrafo(&g, &m); int i, i1, i2, i3; char esc[20]; //comando a ser digitado int FM = 1; while (FM == 1){ scanf("%s", esc); //lerá o comando até o primeiro espaço, para depois ler até o proximo espaço, e assim por diante int escI = identificaComando(esc); //identifica o comando digitado switch(escI){ case _CV: //cria vértice scanf("%d", &i1); insertVertex(&g, &m, i1); break; case _DV: //destrói vértice scanf("%d", &i1); removeVertex(&g, i1, &m); break; case _CA: //cria aresta scanf("%d %d %d", &i1, &i2, &i3); insertEdge(&g, i1, i2, &m, i3); break; case _DA: //destrói aresta scanf("%d", &i1); removeEdge(&g, i1, &m); break; case _TV: //troca vértice scanf("%d %d", &i1, &i2); replaceVertex(i1, i2, m); break; case _TA: //troca aresta scanf("%d %d", &i1, &i2); replaceEdge(i1, i2, m); break; case _IG: //imprime grafo printf("%d\n", g.nvertices); for (i = 0; i < m.indiceVert; i++){ vertice *v = pegaVertRef(m, i+1); if (v != NULL){ printf("%d ", i+1); printf("%d\n", v->conteudo); } } printf("%d\n", g.narestas); for (i = 0; i < m.indiceAres; i++){ aresta *a = pegaAresRef(m, i+1); if (a != NULL){ printf("%d ", i+1); vertice *vT = a->dir; printf("%d ", pegaVertInd(m, vT)); vT = a->esq; printf("%d ", pegaVertInd(m, vT)); printf("%d\n", a->conteudo); } } break; case _CM: //caminho mínimo scanf("%d %d", &i1, &i2); dijkstra(&g, m, i1, i2); break; case _FM: //fim FM = 0; break; } } return 0; }
int main(int argc, char const *argv[]) { int running = 1, cost = 0, i, j; char input[BUFFER_SIZE], *aft; char vertex, dest, option; Graph *g = NULL; createGraph(&g); #ifdef DEV insertVertex(g, 'a'); insertVertex(g, 'b'); insertVertex(g, 'c'); insertVertex(g, 'd'); insertVertex(g, 'e'); insertVertex(g, 'f'); insertEdge(g, 'a', 'b', 100); insertEdge(g, 'a', 'c', 300); insertEdge(g, 'a', 'a', 100); insertEdge(g, 'd', 'b', 70); insertEdge(g, 'f', 'c', 10); insertEdge(g, 'a', 'f', 10); insertEdge(g, 'a', 'f', 20); insertEdge(g, 'a', 'a', 100); displayGraph(g); greedySearch(g, 'a'); destroyGraph(g); #else while (running) { memset(input, 0, BUFFER_SIZE); printf("\n1 - inserir vertice\n"); printf("2 - inserir aresta\n"); printf("3 - remover vertice\n"); printf("4 - remover aresta\n"); printf("5 - imprimir grafo\n"); printf("6 - Busca Gulosa\n"); printf("7 - sair\n"); printf("\n$"); scanf(" %c", &option); switch (option) { case '1': printf("Digite um id para o novo no (apenas um caracter)\n"); printf(">>"); scanf(" %c", &vertex); if (!insertVertex(g, vertex)) { printf("Vertice inserido!\n"); printf("Digite os vizinhos (exemplo:b10 c20 d30) obs: caso o valor nao seja indicado o default sera 0\n"); getchar(); fgets(input, BUFFER_SIZE, stdin); for(i = 0; i < strlen(input); i++) { if(isalpha(input[i])) { dest = input[i]; for(j = i+1; j <= strlen(input); j++) { if(isdigit(input[j])) { cost = strtod(&input[j], &aft); i = (aft - input) -1; if(!insertEdge(g, vertex, dest, cost)) printf("Aresta inserida [%c] - [%c] com custo %d!\n", vertex, dest, cost); break; } if(isalpha(input[j]) || input[j] == '\0') { if(!insertEdge(g, vertex, dest, 0)) printf("Aresta inserida [%c] - [%c] com custo 0!\n", vertex, dest); break; } } } } } break; case '2': printf("Digite um par de vertices e um custo para a nova aresta (exemplo: A B 100)\n"); printf(">>"); scanf(" %c %c %d", &vertex, &dest, &cost); if(!insertEdge(g, vertex, dest, cost)) printf("Aresta inserida!\n"); break; case '3': printf("Digite o id do vertice a ser deletado\n"); printf(">>"); scanf(" %c", &vertex); if(!removeVertex(g, vertex)) printf("vertice removido\n"); break; case '4': printf("Digite o par de vertices e o custo da aresta (exemplo: A B 100)\n"); printf(">>"); scanf(" %c %c %d", &vertex, &dest, &cost); if(!removeEdge(g, vertex, dest, cost)) printf("aresta removida!\n"); break; case '5': displayGraph(g); break; case '6': printf("Digite um vertice para inicio da busca\n"); printf(">>"); scanf(" %c", &vertex); greedySearch(g, vertex); break; case '7': printf("Ate logo\n"); running = 0; destroyGraph(g); break; default: printf("Opcao invalida\n"); break; } } #endif return 0; }
bool DVRClipGeometry::buildTriangledGeometry(void) { // create triangles for(TriangleIterator triangleIt = geometry->beginTriangles(); triangleIt != geometry->endTriangles (); ++triangleIt) { DVRTriangle newTriangle; for(UInt32 i = 0; i < 3; i++) { Int32 vertexIndex = triangleIt.getPositionIndex(i); vertexIndex = insertVertex(vertexIndex); newTriangle.vertices[i] = vertexIndex; _mfVertices[vertexIndex].adjacentTriangles.push_back( _mfTriangles.size()); newTriangle.cutPnt [i] = 0.0; newTriangle.cutPoint[i] = 0.0; } // compute normal and check orientation newTriangle.normal = (_mfVertices[newTriangle.vertices[0]].pos - _mfVertices[newTriangle.vertices[1]].pos).cross( _mfVertices[newTriangle.vertices[0]].pos - _mfVertices[newTriangle.vertices[2]].pos); newTriangle.normal.normalize(); if(newTriangle.normal.dot(triangleIt.getNormal(0)) < 0.0) newTriangle.normal.negate(); _mfTriangles.push_back(newTriangle); } // find neighbouring triangles for(UInt32 i = 0; i < _mfTriangles.size(); i++) { Int32 *vertices = _mfTriangles[i].vertices; for(UInt32 l = 0; l < 3; l++) { const DVRVertex &v0 = _mfVertices[vertices[l]]; const DVRVertex &v1 = _mfVertices[vertices[(l + 1) % 3]]; for(UInt32 j = 0; j < v0.adjacentTriangles.size(); j++) { for(UInt32 k = 0; k < v1.adjacentTriangles.size(); k++) { if(v0.adjacentTriangles[j] == v1.adjacentTriangles[k] && v0.adjacentTriangles[j] != i && v1.adjacentTriangles[k] != i ) { if(_mfTriangles[i].neighbours[l] != -1) { SLOG << "Error: Could not build clip geometry" << std::endl << " one triangle edge shared by more " << "than two triangles" << std::endl; return false; } _mfTriangles[i].neighbours[l] = v1.adjacentTriangles[k]; } } } } } // check for non-closed geometry UInt32 checkCount = 0; for(UInt32 i = 0; i < _mfTriangles.size(); i++) { for(UInt32 j = 0; j < 3; j++) { if(_mfTriangles[i].neighbours[j] == -1) { checkCount++; } } } if(checkCount > 0) { SLOG << "Error: Could not build clip geometry" << std::endl << checkCount << "open edges found!" << std::endl; return false; } return true; }
//---------------------------------------------------------- void ofPolyline::insertVertex(float x, float y, float z, int index) { insertVertex(ofPoint(x, y, z), index); }