private void OnGetQueryPart(ILevel level, int levelSequence, IPart part) { lock (layers) { PositionSetEdit_ImplementByICollectionTemplate partSet = new PositionSetEdit_ImplementByICollectionTemplate(); partSet.AddPosition(part); Layer_M2MPartSetInSpecificLevel layer = new Layer_M2MPartSetInSpecificLevel(level, partSet); layer.MainColor = Color.FromArgb(255, 0, 0); layer.Active = true; layers.Add(layer); } flowControlerForm.BeginInvoke(Update); flowControlerForm.SuspendAndRecordWorkerThread(); }
private void OnGetLinePositionSetInSpecificLevel(ILevel level, int levelSequence, IPositionSet positionSet) { lock (layers) { if (linePartSetLayer == null) { linePartSetLayer = new Layer_M2MPartSetInSpecificLevel(level, positionSet); linePartSetLayer.MainColor = Settings.Default.LinePositionSetInSpecificLevelColor; linePartSetLayer.Alpha = 50; //linePartSetLayer.LineColor = Color.Red; linePartSetLayer.Active = true; layers.Add(linePartSetLayer); positionSetSet = new PositionSetSet(); BottonLevelPositionSetLayer = new Layer_PositionSet_Point(positionSetSet); BottonLevelPositionSetLayer.Point.IsDrawPointBorder = true; BottonLevelPositionSetLayer.Point.PointRadius = 2; BottonLevelPositionSetLayer.Point.PointColor = Settings.Default.BottonLevelPositionSetColor; layers.Add(BottonLevelPositionSetLayer); } else { linePartSetLayer.SpringLayerRepresentationChangedEvent(linePartSetLayer); } positionSetSet.Clear(); positionSet.InitToTraverseSet(); while (positionSet.NextPosition()) { IPart tempPart = level.GetPartRefByPartIndex((int)positionSet.GetPosition().GetX(), (int)positionSet.GetPosition().GetY()); if (tempPart != null) { positionSetSet.AddPositionSet(m2mStructure.GetBottonLevelPositionSetByAncestorPart(( tempPart), levelSequence)); } } BottonLevelPositionSetLayer.SpringLayerRepresentationChangedEvent(BottonLevelPositionSetLayer); } flowControlerForm.BeginInvoke(Update); flowControlerForm.SuspendAndRecordWorkerThread(); }
private void OnGetSearchPart(ILevel level, int levelSequence, IPart part) { lock (layers) { if (SearchPartSetLayer == null) { SearchPartSet = new PositionSetEdit_ImplementByICollectionTemplate(); SearchPartSetLayer = new Layer_M2MPartSetInSpecificLevel(level, SearchPartSet); SearchPartSetLayer.MainColor = Color.Blue; SearchPartSetLayer.Active = true; layers.Add(SearchPartSetLayer); } SearchPartSet.AddPosition(part); SearchPartSetLayer.PositionSet = SearchPartSet; } flowControlerForm.BeginInvoke(Update); flowControlerForm.SuspendAndRecordWorkerThread(); }
private void pathFindingToolStripMenuItem_Click(object sender, EventArgs e) { IPositionSet_Connected positionSet_Connected = (IPositionSet_Connected)positionSetContainer.GetPositionSet(); Dijkstra dijkstra = new Dijkstra(); AStar astar = new AStar(); M2M_PF m2m_PF = new M2M_PF(); IM2MStructure m2mStructure = null; List <IPosition_Connected> m2mPath = null; List <IPosition_Connected> path = null; //计算算法运行时间用 //IPosition_Connected start = null; //IPosition_Connected end = null; ISearchPathEngine searchPathEngine1 = m2m_PF; ISearchPathEngine searchPathEngine2 = dijkstra; m2m_PF.GetM2MStructure += delegate(IM2MStructure m2mS) { m2mStructure = m2mS; }; m2m_PF.GetM2MStructureInPreprocess += delegate(IM2MStructure m2mS) { m2mStructure = m2mS; }; List <ushort> timeStampList = new List <ushort>(); m2m_PF.GetTimeStamp += delegate(ushort timeStamp) { timeStampList.Add(timeStamp); }; searchPathEngine1.InitEngineForMap(positionSet_Connected); searchPathEngine2.InitEngineForMap(positionSet_Connected); //以下代码必须在UI线程中调用,即不能在另开的线程中调用 LayersExOptDlg layers = new LayersExOptDlg(); LayersPainterForm layersPainterForm = new LayersPainterForm(layers); LayersPaintedControl layersPaintedControl = layersPainterForm.LayersPaintedControl; LayersEditedControl layersEditedControl = new LayersEditedControl(); layersEditedControl.Dock = DockStyle.Top; layersEditedControl.LayersPaintedControl = layersPaintedControl; layersPainterForm.Controls.Add(layersEditedControl); layersPainterForm.Show(); //打开一个Worker线程来进行算法流程的演示(否则会阻塞UI线程以至于演示不能进行) IAsyncResult result = new dDemoProcess(delegate { Layer_PositionSet_Connected layer_PositionSet_Connected = new Layer_PositionSet_Connected(positionSet_Connected); layer_PositionSet_Connected.Point.PointColor = Color.Yellow; layer_PositionSet_Connected.Connection.LineColor = Color.Blue; layer_PositionSet_Connected.Connection.LineWidth = 0.6f; layer_PositionSet_Connected.Point.PointRadius = 1.2f; layers.Add(layer_PositionSet_Connected); layer_PositionSet_Connected.SpringLayerRepresentationChangedEvent(layer_PositionSet_Connected); for (int levelSequence = 1; levelSequence < m2mStructure.GetLevelNum(); levelSequence++) { Layer_PartSet_Connected layer_PartSet_Connected = new Layer_PartSet_Connected(m2mStructure, levelSequence); layer_PartSet_Connected.Visible = false; layers.Add(layer_PartSet_Connected); } while (true) { IPosition_Connected start = (IPosition_Connected)layersEditedControl.GetMouseDoubleChickedNearestPositionInCurrentPositionSet(positionSet_Connected); PositionSet_ConnectedEdit startPointSet = new PositionSet_ConnectedEdit(); startPointSet.AddPosition_Connected(start); Layer_PositionSet_Point layerStartPoint = new Layer_PositionSet_Point(startPointSet); layerStartPoint.Active = true; layerStartPoint.Point.IsDrawPointBorder = true; layerStartPoint.Point.PointRadius = 5; layerStartPoint.Point.PointColor = Color.PaleGreen; layers.Add(layerStartPoint); layerStartPoint.SpringLayerRepresentationChangedEvent(layerStartPoint); IPosition_Connected end = (IPosition_Connected)layersEditedControl.GetMouseDoubleChickedNearestPositionInCurrentPositionSet(positionSet_Connected); PositionSet_ConnectedEdit endPointSet = new PositionSet_ConnectedEdit(); endPointSet.AddPosition_Connected(end); Layer_PositionSet_Point layerEndPoint = new Layer_PositionSet_Point(endPointSet); layerEndPoint.Active = true; layerEndPoint.Point.IsDrawPointBorder = true; layerEndPoint.Point.PointRadius = 5; layerEndPoint.Point.PointColor = Color.Cyan; layers.Add(layerEndPoint); layerEndPoint.SpringLayerRepresentationChangedEvent(layerEndPoint); CountTimeTool.TimeCounter timeCounter = new CountTimeTool.TimeCounter(); searchPathEngine2.InitEngineForMap(positionSet_Connected); double time2 = timeCounter.CountTimeForRepeatableMethod(delegate { searchPathEngine2.SearchPath(start, end); }); path = searchPathEngine2.SearchPath(start, end); float pathLength2 = ((Dijkstra)searchPathEngine2).GetPathLength(); Console.WriteLine("Dijkstra consume time: " + time2 + " path Length = " + pathLength2); searchPathEngine1.InitEngineForMap(positionSet_Connected); //清空timeStampList以记录寻径过程各层的timeStamp double time1 = timeCounter.CountTimeForRepeatableMethod(delegate { searchPathEngine1.SearchPath(start, end); }); timeStampList.Clear(); m2mPath = searchPathEngine1.SearchPath(start, end); float pathLength1 = ((M2M_PF)searchPathEngine1).GetPathLength(); Console.WriteLine("M2M_PF consume time: " + time1 + " path Length = " + pathLength1); //searchPathEngine1.SearchPath(start, end); if (searchPathEngine1 is M2M_PF && m2mStructure != null) { for (int levelSequence = 1; levelSequence < m2mStructure.GetLevelNum(); levelSequence++) { ILevel level = m2mStructure.GetLevel(levelSequence); IPart rootPart = m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0); IPositionSet positionSet = m2mStructure.GetDescendentPositionSetByAncestorPart(levelSequence, rootPart, 0); List <IPosition_Connected> position_ConnectedList = new List <IPosition_Connected>(); positionSet.InitToTraverseSet(); while (positionSet.NextPosition()) { if (positionSet.GetPosition() is IPart_Multi) { IPart_Multi partMulti = (IPart_Multi)positionSet.GetPosition(); IEnumerable <IPart_Connected> part_ConnectedEnumerable = partMulti.GetSubPartSet(); foreach (IPart_Connected part in part_ConnectedEnumerable) { IPosition_Connected tempPartConnected = (IPosition_Connected)part; if (((Tag_M2M_Part)tempPartConnected.GetAttachment()).isNeedToSearch == true) { if (timeStampList[levelSequence - 1] == ((Tag_M2M_Part)tempPartConnected.GetAttachment()).timeStamp) { position_ConnectedList.Add(tempPartConnected); } } } } else { IPosition_Connected tempPartConnected = (IPosition_Connected)positionSet.GetPosition(); if (((Tag_M2M_Part)tempPartConnected.GetAttachment()).isNeedToSearch == true) { if (timeStampList[levelSequence - 1] == ((Tag_M2M_Part)tempPartConnected.GetAttachment()).timeStamp) { position_ConnectedList.Add(tempPartConnected); } } } } IPositionSet partSet = new PositionSet_Connected(position_ConnectedList); Layer_M2MPartSetInSpecificLevel layer_M2MPartSetInSpecificLevel = new Layer_M2MPartSetInSpecificLevel(m2mStructure.GetLevel(levelSequence), partSet); layer_M2MPartSetInSpecificLevel.Active = true; layer_M2MPartSetInSpecificLevel.Alpha = 100; //layer_M2MPartSetInSpecificLevel. layers.Add(layer_M2MPartSetInSpecificLevel); //PositionSet_Connected partSet_Connected = new PositionSet_Connected(position_ConnectedList); //Layer_PositionSet_Connected layer_PartSet_Connected = new Layer_PositionSet_Connected(partSet_Connected); ////layer_PartSet_Connected.MainColor ////layer_PartSet_Connected.Active = true; //layer_PartSet_Connected.SetPositionSetTransformByM2MLevel(level); //layers.Add(layer_PartSet_Connected); } } if (path != null) { Layer_PositionSet_Path layer = new Layer_PositionSet_Path(new PositionSet_Connected(path)); layer.Active = true; layer.PathLine.LineColor = Color.Black; layer.PathLine.LineWidth = 2; layer.PathPoint.PointRadius = 2; layer.PathPoint.IsDrawPointBorder = true; //layer.EditAble = true; //layer.Point.PointColor = Color.Yellow; //layer.Point.PointRadius = 2; //layer.Point.IsDrawPointBorder = true; layers.Add(layer); layer.SpringLayerRepresentationChangedEvent(layer); } else { this.BeginInvoke(new dShow(MessageBox.Show), new object[] { "There is no path between two node" }); } if (m2mPath != null) { Layer_PositionSet_Path layer = new Layer_PositionSet_Path(new PositionSet_Connected(m2mPath)); layer.Active = true; layer.PathLine.LineColor = Color.Red; layer.PathLine.LineWidth = 2; layer.PathPoint.PointRadius = 2; layer.PathPoint.IsDrawPointBorder = true; //layer.EditAble = true; //layer.Point.PointColor = Color.Yellow; //layer.Point.PointRadius = 2; //layer.Point.IsDrawPointBorder = true; layers.Add(layer); layer.SpringLayerRepresentationChangedEvent(layer); } else { this.BeginInvoke(new dShow(MessageBox.Show), new object[] { "There is no path between two node by M2M_PF" }); } } }).BeginInvoke(null, null); }
private void OnTheEndOfGetLinePositionSetInSpecificLevel() { linePartSetLayer = null; }
public AlgorithmDemo_M2M_CD(M2M_CD M2M_CD, Layers layers, FlowControlerForm flowControlerForm, dUpdate update) { this.M2M_CD = M2M_CD; this.layers = layers; this.flowControlerForm = flowControlerForm; this.Update = update; M2M_CD.GetCollision += delegate(IPositionSet positionSet) { System.Diagnostics.Debug.WriteLine("Collision!"); if (objLayer != null) { layers.Remove(objLayer); } { objLayer = new Layer_PositionSet_Polygon(new PositionSet_Cloned(positionSet)); objLayer.PolygonLine.LineColor = Color.Red; objLayer.PolygonLine.LineWidth = 1; layers.Add(objLayer); } flowControlerForm.BeginInvoke(Update); flowControlerForm.SuspendAndRecordWorkerThread(); }; M2M_CD.GetNoCollision += delegate(IPositionSet positionSet) { System.Diagnostics.Debug.WriteLine("NoCollision!"); if (objLayer != null) { layers.Remove(objLayer); } { objLayer = new Layer_PositionSet_Polygon(new PositionSet_Cloned(positionSet)); objLayer.PolygonLine.LineColor = Color.Green; objLayer.PolygonLine.LineWidth = 1; layers.Add(objLayer); } flowControlerForm.BeginInvoke(Update); flowControlerForm.SuspendAndRecordWorkerThread(); }; M2M_CD.GetIntersectPart += delegate(ILevel level, IPositionSet positionSet) { if (linePartSetLayer == null) { linePartSetLayer = new Layer_M2MPartSetInSpecificLevel(level, positionSet); linePartSetLayer.MainColor = Settings.Default.LinePositionSetInSpecificLevelColor; linePartSetLayer.Alpha = 50; //linePartSetLayer.LineColor = Color.Red; linePartSetLayer.Active = true; layers.Add(linePartSetLayer); } else { linePartSetLayer.SpringLayerRepresentationChangedEvent(linePartSetLayer); } }; M2M_CD.GetM2MStructure += delegate(IM2MStructure m2mStructure) { this.m2mStructure = m2mStructure; }; IsGetM2MStructure = true; IsGetPositionSetToGetConvexHull = true; flowControlerForm.SelectConfiguratoinObject(this); flowControlerForm.SuspendAndRecordWorkerThread(); }