Vertices * GenTree(int nVertex) { int i; int weight; Vertices * vertex; Vertices * graph; Edges * edge; graph = NewVertex(); NEXT_VERTEX(graph) = graph; for(i = 1; i < nVertex; i++) { vertex = NewVertex(); edge = NewEdge(); /* * The newly created vertex has one edge ... */ EDGES(vertex) = edge; /* * ... which is connected to the graph so far generated. The connection * point in the graph is picked at random. */ VERTEX(edge) = PickVertex(graph, random() % i); weight = GET_WEIGHT; WEIGHT(edge) = weight; SOURCE(edge) = vertex; /* * Link the new vertex into the graph. */ NEXT_VERTEX(vertex) = NEXT_VERTEX(graph); NEXT_VERTEX(graph) = vertex; /* * Add an edge to the vertex randomly picked as the connection point. */ edge = NewEdge(); WEIGHT(edge) = weight; SOURCE(edge) = VERTEX(EDGES(vertex)); VERTEX(edge) = vertex; NEXT_EDGE(edge) = EDGES(VERTEX(EDGES(vertex))); EDGES(VERTEX(EDGES(vertex))) = edge; } return(graph); }
int Mesh::NewPoint(int a, int b, Scalar c) { Point P; P.vertex = NewVertex(a, b, c); P.texCoord = NewTexCoord(a, b, c); P.normal = NewNormal(a, b, c); P.color = NewColor(a, b, c); return AddPoint(P); }
// // NewVertexFromSplitSeg // vertex_t *NewVertexFromSplitSeg(seg_t *seg, float_g x, float_g y) { vertex_t *vert = NewVertex(); vert->x = x; vert->y = y; vert->ref_count = seg->partner ? 4 : 2; if (lev_doing_normal && cur_info->spec_version == 1) { vert->index = num_normal_vert; num_normal_vert++; } else { vert->index = num_gl_vert | IS_GL_VERTEX; num_gl_vert++; } // compute wall_tip info VertexAddWallTip(vert, -seg->pdx, -seg->pdy, seg->sector, seg->partner ? seg->partner->sector : NULL); VertexAddWallTip(vert, seg->pdx, seg->pdy, seg->partner ? seg->partner->sector : NULL, seg->sector); // create a duplex vertex if needed if (lev_doing_normal && cur_info->spec_version != 1) { vert->normal_dup = NewVertex(); vert->normal_dup->x = x; vert->normal_dup->y = y; vert->normal_dup->ref_count = vert->ref_count; vert->normal_dup->index = num_normal_vert; num_normal_vert++; } return vert; }
_TMESH_TMPL_TYPE VOID _TMESH_TMPL_DECL::GetFacetVertices(iFACET facetIndex, eCOORD coord, REAL coordVal, iVERTEX v[2]) { cHALF_EDGE* facetHes[2] = { NULL, NULL }; BOOL verticesAreNew[2] = { false, false }; cHALF_EDGE *startingHe = Facet(facetIndex)->FindMinHalfEdge(coord); cHALF_EDGE *currHe = startingHe; INT i = 0; do { cPOINT3 tailPoint = currHe->Tail()->Point(); cPOINT3 headPoint = currHe->Head()->Point(); REAL heTailCoord = tailPoint[coord]; REAL heHeadCoord = headPoint[coord]; REAL diff1 = coordVal - heTailCoord; REAL diff2 = heHeadCoord - coordVal; if(fabs(diff2) < cLIMITS::Tolerance()) { currHe = currHe->Next(); continue; } if(fabs(diff1) < cLIMITS::Tolerance()) v[i++] = currHe->Tail()->Index(); else if(diff1 * diff2 > 0.0) { cPOINT3 newPoint = ((tailPoint*diff2) + (headPoint*diff1))/(diff1+diff2); v[i++] = NewVertex(newPoint); facetHes[i-1] = currHe; verticesAreNew[i-1] = true; } if(i == 2) break; currHe = currHe->Next(); } while( currHe != startingHe); if(verticesAreNew[0]) SplitEdge(v[0], facetHes[0]->Tail()->Index(), facetHes[0]->Head()->Index()); if(verticesAreNew[1]) SplitEdge(v[1], facetHes[1]->Tail()->Index(), facetHes[1]->Head()->Index()); }
// // NewVertexDegenerate // vertex_t *NewVertexDegenerate(vertex_t *start, vertex_t *end) { float_g dx = end->x - start->x; float_g dy = end->y - start->y; float_g dlen = UtilComputeDist(dx, dy); vertex_t *vert = NewVertex(); vert->ref_count = start->ref_count; if (lev_doing_normal) { vert->index = num_normal_vert; num_normal_vert++; } else { vert->index = num_gl_vert | IS_GL_VERTEX; num_gl_vert++; } // compute new coordinates vert->x = start->x; vert->y = start->x; if (dlen == 0) InternalError("NewVertexDegenerate: bad delta !"); dx /= dlen; dy /= dlen; while (I_ROUND(vert->x) == I_ROUND(start->x) && I_ROUND(vert->y) == I_ROUND(start->y)) { vert->x += dx; vert->y += dy; } return vert; }
_TMESH_TMPL_TYPE iFACET _TMESH_TMPL_DECL::Clip(iFACET facetIndex, const cSEGMENT3 &cut) { cFACET* facet = Facet(facetIndex); if(facet == NULL || facet->IsDeleted()) return INVALID_IFACET; iVERTEX cutVertices[2] = { INVALID_IVERTEX, INVALID_IVERTEX }; BOOL insertCutVertices[2] = { false, false }; cPOINT3 points[2]; cEDGE splitEdges[2]; const cPOINT3 &cutTail = cut.Source(); const cPOINT3 &cutHead = cut.Target(); typename cFACET::half_edge_circulator currFacetHe = facet->HalfEdgesBegin(); typename cFACET::half_edge_circulator lastFacetHe = facet->HalfEdgesEnd(); INT numCuts = 0; for( ; currFacetHe != lastFacetHe ; currFacetHe++) { cSEGMENT3 heSegment = currFacetHe->Segment(); if(heSegment.HasOn(cutTail)) { if(!(heSegment.Target() == cutTail)) { if(heSegment.Source() == cutTail) { cutVertices[numCuts++] = currFacetHe->Tail()->Index(); } else { insertCutVertices[numCuts] = true; splitEdges[numCuts].v1 = currFacetHe->Tail()->Index(); splitEdges[numCuts].v2 = currFacetHe->Head()->Index(); points[numCuts] = cutTail; numCuts++; } } } if(heSegment.HasOn(cutHead)) { if(!(heSegment.Target() == cutHead)) { if(heSegment.Source() == cutHead) { cutVertices[numCuts++] = currFacetHe->Tail()->Index(); } else { insertCutVertices[numCuts] = true; splitEdges[numCuts].v1 = currFacetHe->Tail()->Index(); splitEdges[numCuts].v2 = currFacetHe->Head()->Index(); points[numCuts] = cutHead; numCuts++; } } } if(numCuts == 2) break; } //Cuts found. assert(numCuts == 2); if(numCuts != 2) return INVALID_IFACET; if(insertCutVertices[0]) { cutVertices[0] = NewVertex(points[0]); SplitEdge(cutVertices[0], splitEdges[0].v1, splitEdges[0].v2); } if(insertCutVertices[1]) { cutVertices[1] = NewVertex(points[1]); SplitEdge(cutVertices[1], splitEdges[1].v1, splitEdges[1].v2); } return InsertDiagonal(facetIndex, cutVertices[0], cutVertices[1]); }
bool FVertexSnappingImpl::GetClosestVertexOnComponent( const FSnapActor& SnapActor, UPrimitiveComponent* Component, const FVertexSnappingArgs& InArgs, FSnappingVertex& OutClosestLocation ) { // Current closest distance float ClosestDistance = FLT_MAX; bool bHasAnyVerts = false; const FPlane& ActorPlane = InArgs.ActorPlane; EAxisList::Type CurrentAxis = InArgs.CurrentAxis; const FSceneView* View = InArgs.SceneView; const FVector& CurrentLocation = InArgs.CurrentLocation; const FVector2D& MousePosition = InArgs.MousePosition; // If no close vertex is found, do not snap OutClosestLocation.Position = CurrentLocation; TSharedPtr<FVertexIterator> VertexGetter = MakeVertexIterator( Component ); if( VertexGetter.IsValid() ) { FVertexIterator& VertexGetterRef = *VertexGetter; for( ; VertexGetterRef; ++VertexGetterRef ) { bHasAnyVerts = true; FVector Position = VertexGetterRef.Position(); FVector Normal = VertexGetterRef.Normal(); if( CurrentAxis == EAxisList::Screen && View->IsPerspectiveProjection() && !SnapActor.AllowedSnappingBox.IsInside( Position ) ) { // Vertex is outside the snapping bounding box continue; } // Ignore backface vertices when translating in screen space bool bIsBackface = false; bool bOutside = false; float Distance = 0; float DistanceFromCamera = 0; if( CurrentAxis != EAxisList::Screen ) { // Compute the distance to the plane the actor is on Distance = ActorPlane.PlaneDot( Position ); } else { // When moving in screen space compute the vertex closest to the mouse location for more accuracy FVector ViewToVertex = View->ViewMatrices.ViewOrigin - Position; // Ignore backface vertices if( View->IsPerspectiveProjection() && Normal != FVector::ZeroVector && FVector::DotProduct( ViewToVertex, Normal ) < 0 ) { bIsBackface = true; } if( !bIsBackface ) { FVector2D PixelPos; View->WorldToPixel( Position, PixelPos ); // Ensure the vertex is inside the view bOutside = PixelPos.X < 0.0f || PixelPos.X > View->ViewRect.Width() || PixelPos.Y < 0.0f || PixelPos.Y > View->ViewRect.Height(); if( !bOutside ) { DistanceFromCamera = View->IsPerspectiveProjection() ? FVector::DistSquared( Position, View->ViewMatrices.ViewOrigin ) : 0; Distance = FVector::DistSquared( FVector( MousePosition, 0 ), FVector( PixelPos, 0 ) ); } } if( !bIsBackface && !bOutside && DistanceFromCamera <= VertexSnappingConstants::MaxSquaredDistanceFromCamera ) { // Draw a snapping helper for visible vertices FSnappingVertex NewVertex( Position, Normal ); } } if( // Vertex cannot be facing away from the camera !bIsBackface // Vertex cannot be outside the view && !bOutside // In screen space the distance of the vertex must not be too far from the camera. In any other axis the vertex cannot be beind the actor && ( ( CurrentAxis == EAxisList::Screen && DistanceFromCamera <= VertexSnappingConstants::MaxSquaredDistanceFromCamera ) || ( CurrentAxis != EAxisList::Screen && !FMath::IsNegativeFloat( Distance ) ) ) // The vertex must be closer than the current closest vertex && Distance < ClosestDistance ) { // Update the closest point ClosestDistance = Distance; OutClosestLocation.Position = Position; OutClosestLocation.Normal = Normal; } } } return bHasAnyVerts; }
int TopologicalGraph::MakeConnectedVertex() //returns the initial number of connected components {if(debug())DebugPrintf(" CheckPropConnected"); if(Set().exist(PROP_CONNECTED))return 1; Prop1<int>is_connected(Set(),PROP_CONNECTED); if(!nv()) return 0; if(debug())DebugPrintf("Executing MakeConnectedVertex"); bool simple = Set().exist(PROP_SIMPLE); bool bipartite = Set().exist(PROP_BIPARTITE); tvertex v,w; tbrin b,b0; int ncc = 0; svector<tvertex> stack(1,nv()); stack.SetName("TP:stack"); svector<tvertex> comp(0,nv()+1); comp.clear(); comp.SetName("TP:Comp"); int rank =0; int max_rank = 0; tvertex v0 = 1; tvertex previous_root = 1; int n = nv(); int m = ne(); tvertex vv = NewVertex(); NewEdge(vv,v0); comp[vv] = v0; while (max_rank < n) {while (comp[v0]!=0) v0++; comp[v0] = v0; ++ncc; if(ncc > 1) NewEdge(vv,v0); previous_root = v0; ++max_rank; stack[rank + 1] = v0; while(rank < max_rank) {v = stack[++rank]; b = b0 = pbrin[v]; if (b0!=0) do {w = vin[-b]; if(!comp[w]) {comp[w] = previous_root; stack[++max_rank] = w; } }while((b = cir[b])!= b0); } } if(ne() == m+1)// the graph was connected { DeleteVertex(vv); if(debug())DebugPrintf("End MakeConnectedVertex m=%d",ne()); return 1; } if(simple)Prop1<int> simple(Set(),PROP_SIMPLE); if(bipartite)Prop1<int> bipartite(Set(),PROP_BIPARTITE); if(Set(tvertex()).exist(PROP_COORD)) // Geometric Graph {Prop<Tpoint> vcoord(Set(tvertex()),PROP_COORD); int deg; tvertex w; Tpoint p(.0,.0); deg = 0; Forall_adj_brins_of_G(b,vv) {w = vin[-b]; ++deg; p += vcoord[w]; }