protected override void OnDoWork(DoWorkEventArgs e) { if (this.Paths == null) { this.Paths = new Dictionary <Tuple <int, int>, List <Point> >(); } if (this.ControlPointIndices == null) { this.ControlPointIndices = new Dictionary <Tuple <int, int>, List <int> >(); } if (this.Mode == WorkMode.Work) { int current = 0; int total = TerminalPairs.Count; foreach (Tuple <int, int> terminalPair in TerminalPairs) { List <int> indices = null; List <Point> path = null; TargetPathPoint unusedPoint; LiveWireSegmentation.DijkstraBetweenPoints(Graph, DistanceMap, out path, out indices, out unusedPoint, null, TerminalCollection[terminalPair.Item1].Position, TerminalCollection[terminalPair.Item2].Position); this.Paths.Add(terminalPair, path); this.ControlPointIndices.Add(terminalPair, indices); // Signal progress changed base.OnProgressChanged(new ProgressChangedEventArgs((int)(++current * 100.0 / total), null)); } } else if (this.Mode == WorkMode.ReWork) { int current = 0; int total = ReWorkPaths.Count; for (int i = 0; i < ReWorkPaths.Count; i++) { LiveWirePrimaryPath currentPath = ReWorkPaths[i]; List <Point> pathKeyPoints = new List <Point>(); pathKeyPoints.Add(TerminalCollection[currentPath.SourceIndex].Position); foreach (Point p in currentPath.IntermediatePoints) { pathKeyPoints.Add(p); } pathKeyPoints.Add(TerminalCollection[currentPath.TipIndex].Position); List <Point> newPoints = null; List <int> newIndices = null; TargetPathPoint unusedPoint; LiveWireSegmentation.DijkstraBetweenPoints(Graph, DistanceMap, out newPoints, out newIndices, out unusedPoint, null, pathKeyPoints.ToArray()); currentPath.Path = newPoints; currentPath.Indices = newIndices; // Signal progress changed base.OnProgressChanged(new ProgressChangedEventArgs((int)(++current * 100.0 / total), null)); } } }
public LiveWireWeightDescriptor(LiveWirePrimaryPath path, double[] probabilityMap, int width, int height) { List <Point> points = path.Path; LiveWirePathWeights.CalculatePathLengths(points, out this.length, out this.pixelLength); this.mapWeight = LiveWirePathWeights.CalculatePathMapWeight(points, probabilityMap, width, height); this.lengthweight = this.length / this.pixelLength; this.curvatureWeight = LiveWirePathWeights.CalculatePathCurvatureWeight(points, 25, out this.angleWeights); }
public void ReRun() { // 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 <LiveWireLateralPath> > workerLateralPaths = new List <List <LiveWireLateralPath> >(); for (int t = 0; t < ThreadCount; t++) { workerLateralPaths.Add(new List <LiveWireLateralPath>()); } int currentThreadIndex = 0; foreach (LiveWireLateralPath p in ReWorkPaths) { // Assign patch to a worker thread workerLateralPaths[currentThreadIndex].Add(p); 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.Graph = Graph; w.Mode = LiveWireWorker.WorkMode.ReWork; w.TerminalCollection = Terminals; w.CurrentPathIndexes = endPoints; w.ReWorkPaths = workerLateralPaths[worker]; w.DistanceMap = DistanceMap; w.RunWorkerAsync(); } }