Exemplo n.º 1
0
        // Returns a list of paths. Each path is a sequence of objects, starting
        // on an object of type 'type' and ending on a root.
        public PathTree GetRoots(IProgressListener listener, int type)
        {
            RootInfo rootInfo = new RootInfo();
            PathTree pathTree = new PathTree(this);

            foreach (int obj in GetObjectsByType(type))
            {
                rootInfo.BaseObjects [obj] = obj;
            }

            int nc = 0;

            foreach (int obj in GetObjectsByType(type))
            {
                if (listener.Cancelled)
                {
                    return(null);
                }

                rootInfo.nc = 0;

                FindRoot(rootInfo, pathTree, obj);

                // Register partial paths to the root, to avoid having to
                // recalculate them again

//				if (nc % 100 == 0)
//					Console.WriteLine ("NC: " + nc + " " + rootInfo.Roots.Count);

                pathTree.AddBaseObject(obj);
                foreach (KeyValuePair <int, int[]> e in rootInfo.Roots)
                {
                    pathTree.AddPath(e.Value);
                }
                rootInfo.Visited.Clear();
                rootInfo.Roots.Clear();
                nc++;

                double newp = (double)nc / (double)rootInfo.BaseObjects.Count;
                listener.ReportProgress("Looking for roots", newp);
            }

            pathTree.Flush();
            return(pathTree);
        }