public void Run() { // Assign width and height and other properties this.Width = Graph.Width; this.Height = Graph.Height; // Create thread workers currentWorkers = new List <LiveWireWorker>(); currentWorkersCompleted = new List <bool>(); currentWorkersProgress = new List <int>(); currentProgress = 0; for (int worker = 0; worker < ThreadCount; worker++) { LiveWireLateralWorker thread = new LiveWireLateralWorker(); thread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(OnWorkerProgressCompleted); thread.ProgressChanged += new ProgressChangedEventHandler(OnWorkerProgressChanged); currentWorkers.Add(thread); currentWorkersCompleted.Add(false); currentWorkersProgress.Add(0); } // Create data objects for workers List <List <int> > workerLateralIndices = new List <List <int> >(); for (int t = 0; t < ThreadCount; t++) { workerLateralIndices.Add(new List <int>()); } List <int> lateralIndices = new List <int>(); foreach (RootTerminal lateralTerminal in (from terminal in Terminals where terminal.Type == TerminalType.Lateral select terminal)) { lateralIndices.Add(Terminals.IndexOf(lateralTerminal)); } int currentThreadIndex = 0; foreach (int lateral in lateralIndices) { // Assign patch to a worker thread workerLateralIndices[currentThreadIndex].Add(lateral); currentThreadIndex = (currentThreadIndex + 1) % ThreadCount; } // Dictionary of end points Dictionary <Int32Point, int> endPoints = new Dictionary <Int32Point, int>(); for (int i = 0; i < CurrentPaths.Count; i++) { LiveWirePrimaryPath currentPath = CurrentPaths[i]; foreach (Point p in currentPath.Path) { Int32Point key = (Int32Point)p; if (!endPoints.ContainsKey(key)) { endPoints.Add(key, i); } } } // Launch workers for (int worker = 0; worker < currentWorkers.Count; worker++) { LiveWireLateralWorker w = currentWorkers[worker] as LiveWireLateralWorker; w.LateralTerminals = workerLateralIndices[worker]; w.Mode = LiveWireWorker.WorkMode.Work; w.TerminalCollection = Terminals; w.CurrentPathIndexes = endPoints; w.DistanceMap = DistanceMap; w.Graph = Graph; w.RunWorkerAsync(); } }
public void Run() { // Assign width and height and other properties this.Width = Graph.Width; this.Height = Graph.Height; // Create thread workers currentWorkers = new List <LiveWireWorker>(); currentWorkersCompleted = new List <bool>(); currentWorkersProgress = new List <int>(); currentProgress = 0; for (int worker = 0; worker < ThreadCount; worker++) { LiveWirePrimaryWorker thread = new LiveWirePrimaryWorker(); thread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(OnWorkerProgressCompleted); thread.ProgressChanged += new ProgressChangedEventHandler(OnWorkerProgressChanged); currentWorkers.Add(thread); currentWorkersCompleted.Add(false); currentWorkersProgress.Add(0); } // Create data objects for workers List <List <Tuple <int, int> > > workerPointPairs = new List <List <Tuple <int, int> > >(); for (int t = 0; t < ThreadCount; t++) { workerPointPairs.Add(new List <Tuple <int, int> >()); } List <Tuple <int, int> > terminalPairs = new List <Tuple <int, int> >(); foreach (RootTerminal sourceTerminal in Terminals.UnlinkedSources) { foreach (RootTerminal tipTerminal in Terminals.UnlinkedPrimaries) { terminalPairs.Add(new Tuple <int, int>(Terminals.IndexOf(sourceTerminal), Terminals.IndexOf(tipTerminal))); } } if (Terminals.TerminalLinks != null && Terminals.TerminalLinks.Count > 0) { foreach (var link in Terminals.TerminalLinks) { terminalPairs.Add(new Tuple <int, int>(Terminals.IndexOf(link.Item1), Terminals.IndexOf(link.Item2))); } } int currentThreadIndex = 0; foreach (Tuple <int, int> terminalPair in terminalPairs) { // Assign patch to a worker thread workerPointPairs[currentThreadIndex].Add(terminalPair); currentThreadIndex = (currentThreadIndex + 1) % ThreadCount; } // Launch workers for (int worker = 0; worker < currentWorkers.Count; worker++) { LiveWirePrimaryWorker w = currentWorkers[worker] as LiveWirePrimaryWorker; w.Mode = LiveWireWorker.WorkMode.Work; w.TerminalPairs = workerPointPairs[worker]; w.TerminalCollection = Terminals; w.Graph = Graph; w.DistanceMap = DistanceMap; w.RunWorkerAsync(); } }