Esempio n. 1
0
        /// <summary>
        /// Compute missing edges at each scale of the slimMtg. It is based
        /// on the explicit edges that are defined at finer scales and
        /// decomposition relantionships.
        /// </summary>
        /// <param name="slimMtg"></param>
        /// <param name="preserveOrder"> If true, the order of the children at the coarsest scales
        /// is deduced from the order of children at finest scale. </param>
        /// <returns> Computed tree. </returns>
        public mtg FatMtg(mtg slimMtg, bool preserveOrder = false)
        {
            int maxScale = slimMtg.MaxScale();

            Dictionary <int, dynamic> edgeTypeProperty = slimMtg.Property("Edge_Type");

            for (int scale = maxScale - 1; scale > 0; scale--)
            {
                ComputeMissingEdges(slimMtg, scale, edgeTypeProperty);

                if (preserveOrder)
                {
                    foreach (int v in slimMtg.Vertices(scale))
                    {
                        List <int> cref = slimMtg.Children(v);

                        if (cref.Count > 1)
                        {
                            List <int> cmp = new List <int>();
                            foreach (int x in cref)
                            {
                                cmp.Add(slimMtg.ComponentRoots(x)[0]);
                            }

                            Dictionary <int, int> cmpDic = cmp.Zip(cref, (K, V) => new { Key = K, Value = V }).ToDictionary(x => x.Key, x => x.Value);

                            traversal t = new traversal();

                            List <int> descendants = t.IterativePostOrder(slimMtg, slimMtg.ComponentRoots(v)[0]).ToList();

                            List <int> orderedChildren = new List <int>();

                            foreach (int x in descendants)
                            {
                                if (cmp.Contains(x))
                                {
                                    orderedChildren.Add(x);
                                }
                            }

                            List <int> ch = new List <int>();

                            foreach (int c in orderedChildren)
                            {
                                if (cmpDic.ContainsKey(c))
                                {
                                    ch.Add(cmpDic[c]);
                                }
                            }

                            if (slimMtg.children.ContainsKey(v))
                            {
                                slimMtg.children[v] = ch;
                            }
                            else
                            {
                                slimMtg.children.Add(v, ch);
                            }
                        }
                    }
                }
            }

            return(slimMtg);
        }