Exemple #1
0
        /// <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;
                }

                //from a given hub,
                //find bone joint that close to the main triangle for of the analyzingHub
                if (otherHub.FindBoneJoint(analyzingHub.StartTriangle, out CentroidLine foundOnBr, out Joint 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;
                }
            }
        }
Exemple #2
0
 public void AddLineHubConnection(CentroidLineHub anotherHub)
 {
     if (_otherConnectedLineHubs == null)
     {
         _otherConnectedLineHubs = new List <CentroidLineHub>();
     }
     _otherConnectedLineHubs.Add(anotherHub);
 }
Exemple #3
0
        public static Vector2f CalculateAvgHeadPosition(this CentroidLineHub lineHub)
        {
            Dictionary <AnalyzedTriangle, CentroidLine> _lines = lineHub.GetAllCentroidLines();
            int j = _lines.Count;

            if (j == 0)
            {
                return(Vector2f.Zero);
            }
            //---------------------------------
            double cx = 0;
            double cy = 0;

            foreach (CentroidLine line in _lines.Values)
            {
                Vector2f headpos = line.GetHeadPosition();
                cx += headpos.X;
                cy += headpos.Y;
            }
            return(new Vector2f((float)(cx / j), (float)(cy / j)));
        }
Exemple #4
0
        static void CreateCentroidLineHubs(Polygon polygon, List <AnalyzedTriangle> triangles, List <CentroidLineHub> outputLineHubs)
        {
            int id = 0;

            foreach (DelaunayTriangle delnTri in polygon.Triangles)
            {
                delnTri.MarkAsActualTriangle();
                triangles.Add(new AnalyzedTriangle(id, delnTri)); //all triangles are created from Triangulation process
                id++;
            }

            //----------------------------
            //create centroid line hub
            //----------------------------
            //1.
            var             centroidLineHubs       = new Dictionary <AnalyzedTriangle, CentroidLineHub>();
            CentroidLineHub currentCentroidLineHub = null;

            //2. temporary list of used triangles
            List <AnalyzedTriangle> usedTriList = new List <AnalyzedTriangle>();
            AnalyzedTriangle        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)
            {
                AnalyzedTriangle 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);

                        AnalyzedTriangle 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 CentroidPair(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 CentroidPair(connectWithPrevTri, tri));
                        }
                        latestTri = tri;
                    }
                }
            }

            //--------------------------------------------------------------
            //copy to list, we not use the centroidLineHubs anymore
            outputLineHubs.AddRange(centroidLineHubs.Values);
        }