/// <summary> /// find link from main triangle of line-hub to another line hub /// </summary> /// <param name="analyzingHub"></param> /// <param name="hubs"></param> static void LinkEachLineHubTogether(CentroidLineHub analyzingHub, List <CentroidLineHub> hubs) { int j = hubs.Count; for (int i = 0; i < j; ++i) { CentroidLineHub otherHub = hubs[i]; if (otherHub == analyzingHub) { continue; } CentroidLine foundOnBr; GlyphBoneJoint foundOnJoint; //from a given hub, //find bone joint that close to the main triangle for of the analyzingHub if (otherHub.FindBoneJoint(analyzingHub.StartTriangle, out foundOnBr, out foundOnJoint)) { //create a new bone joint // FindNearestEdge(analyzingHub.MainTriangle, foundOnJoint); //add connection from analyzingHub to otherHub otherHub.AddLineHubConnection(analyzingHub); //also set head connection from joint to this analyzing hub analyzingHub.SetHeadConnnection(foundOnBr, foundOnJoint); // //TODO: review this, why return here? return; } } }
public void AddLineHubConnection(CentroidLineHub anotherHub) { if (otherConnectedLineHubs == null) { otherConnectedLineHubs = new List <CentroidLineHub>(); } otherConnectedLineHubs.Add(anotherHub); }
public static Vector2 CalculateAvgHeadPosition(this CentroidLineHub lineHub) { Dictionary <GlyphTriangle, CentroidLine> _lines = lineHub.GetAllCentroidLines(); int j = _lines.Count; if (j == 0) { return(Vector2.Zero); } //--------------------------------- double cx = 0; double cy = 0; foreach (CentroidLine line in _lines.Values) { Vector2 headpos = line.GetHeadPosition(); cx += headpos.X; cy += headpos.Y; } return(new Vector2((float)(cx / j), (float)(cy / j))); }
static void CreateCentroidLineHubs(Polygon polygon, List <GlyphTriangle> triangles, List <CentroidLineHub> outputLineHubs) { //create triangle list from given DelaunayTriangle polygon. // Generate GlyphTriangle triangle from DelaunayTriangle foreach (DelaunayTriangle delnTri in polygon.Triangles) { delnTri.MarkAsActualTriangle(); triangles.Add(new GlyphTriangle(delnTri)); //all triangles are created from Triangulation process } //---------------------------- //create centroid line hub //---------------------------- //1. var centroidLineHubs = new Dictionary <GlyphTriangle, CentroidLineHub>(); CentroidLineHub currentCentroidLineHub = null; //2. temporary list of used triangles List <GlyphTriangle> usedTriList = new List <GlyphTriangle>(); GlyphTriangle latestTri = null; //we may walk forward and backward on each tri //so we record the used triangle into a usedTriList. int triCount = triangles.Count; for (int i = 0; i < triCount; ++i) { GlyphTriangle tri = triangles[i]; if (i == 0) { centroidLineHubs[tri] = currentCentroidLineHub = new CentroidLineHub(tri); usedTriList.Add(latestTri = tri); } else { //at a branch //one tri may connect with 3 NB triangle int foundIndex = FindLatestConnectedTri(usedTriList, tri); if (foundIndex < 0) { //? throw new NotSupportedException(); } else { //record used triangle usedTriList.Add(tri); GlyphTriangle connectWithPrevTri = usedTriList[foundIndex]; if (connectWithPrevTri != latestTri) { //branch CentroidLineHub lineHub; if (!centroidLineHubs.TryGetValue(connectWithPrevTri, out lineHub)) { //if not found then=> //start new CentroidLineHub centroidLineHubs[connectWithPrevTri] = lineHub = new CentroidLineHub(connectWithPrevTri); //create linehub to line hub connection //TODO: review here //create centroid pair at link point } else { //this is multiple facets triangle for CentroidLineHub } currentCentroidLineHub = lineHub; //ensure start triangle of the branch lineHub.SetCurrentCentroidLine(tri); //create centroid line and add to currrent hub currentCentroidLineHub.AddCentroidPair(new GlyphCentroidPair(connectWithPrevTri, tri)); } else { //add centroid line to current multifacet joint if (currentCentroidLineHub.LineCount == 0) { //ensure start triangle of the branch currentCentroidLineHub.SetCurrentCentroidLine(tri); } //create centroid line and add to currrent hub currentCentroidLineHub.AddCentroidPair(new GlyphCentroidPair(connectWithPrevTri, tri)); } latestTri = tri; } } } //-------------------------------------------------------------- //copy to list, we not use the centroidLineHubs anymore outputLineHubs.AddRange(centroidLineHubs.Values); }