private List <List <LINE> > DataPreProcessing(Level targetLevel, Level targetLevelCol, List <LINE> BEAMs) { ///// 取得所有梁平均寬度 double SHIFTs_Width_Of_Beam = 0; foreach (LINE item in BEAMs) { SHIFTs_Width_Of_Beam += item.Width; } SHIFTs_Width_Of_Beam = SHIFTs_Width_Of_Beam / BEAMs.Count; ///// 取得目標樓層所有的柱 Dictionary <string, List <LINE> > columns = GetAllColumnsBoundary(targetLevelCol); int kk = 0; double SHIFTs = 0; List <XYZ> colCenterPoints = new List <XYZ>(); foreach (KeyValuePair <string, List <LINE> > item in columns) { foreach (LINE line in item.Value) { SHIFTs += line.GetLength(); kk = kk + 1; } if (item.Value.Count != 0) { double All_X = item.Value.Sum(t => t.GetStartPoint().X) / item.Value.Count; double All_Y = item.Value.Sum(t => t.GetStartPoint().Y) / item.Value.Count; colCenterPoints.Add(new XYZ(All_X, All_Y, 0)); } } SHIFTs = SHIFTs / kk; ////// 延伸梁的邊緣線至柱中心 /// 找出subBeam,將不做延伸處理 List <int> NonePo = new List <int>(); for (int i = 0; i < BEAMs.Count; i++) { for (int j = 0; j < BEAMs.Count; j++) { if (i == j) { continue; } LINE b1 = BEAMs[i]; LINE b2 = BEAMs[j]; if (Math.Round(b1.GetSlope(), 3) == Math.Round(b2.GetSlope(), 3)) { continue; } try { XYZ crossPoint = b1.GetCrossPoint(b2); if (IsCloseEndsPoint(b1, crossPoint, SHIFTs_Width_Of_Beam) && b2.IsPointInLine(crossPoint)) { NonePo.Add(i); break; } ; } catch (Exception) { } } } List <LINE> Beams_Connect = new List <LINE>(); for (int i = 0; i < BEAMs.Count; i++) { if (NonePo.Contains(i)) { Beams_Connect.Add(BEAMs[i]); continue; } ; List <XYZ> col = GetClosedColumn(colCenterPoints, BEAMs[i]); XYZ newStartPoint = GetNewEndedPoint(col[0], BEAMs[i].GetStartPoint(), BEAMs[i]); XYZ newEndPoint = GetNewEndedPoint(col[1], BEAMs[i].GetEndPoint(), BEAMs[i]); if (newStartPoint.X == newEndPoint.X && newStartPoint.Y == newEndPoint.Y) { Beams_Connect.Add(BEAMs[i]); continue; } LINE newBeam = new LINE(newStartPoint, newEndPoint); newBeam.Name = BEAMs[i].Name; newBeam.Width = BEAMs[i].Width; newBeam.LevelName = BEAMs[i].LevelName; Beams_Connect.Add(newBeam); } /// 將所有的梁轉換至各樓板邊緣線 List <LINE> nonSelected = new List <LINE>(); List <List <LINE> > BeamGroup = GetBeamGroup(Beams_Connect, ref nonSelected, SHIFTs); SaveTmp(BeamGroup); /// 將樓板邊緣線偏移並連接 List <List <LINE> > NewBeamGroup = BeamConnectAndShiftProcessing(BeamGroup); SaveTmp(NewBeamGroup); if (NewBeamGroup.Count == 0) { return(NewBeamGroup); } double newHeight = NewBeamGroup[0][0].GetStartPoint().Z; ///// 重設目標樓層所有的柱的高度 Dictionary <string, List <LINE> > columns2 = new Dictionary <string, List <LINE> >(); foreach (KeyValuePair <string, List <LINE> > item in columns) { SaveTmp(item.Value); List <LINE> newFloor = new List <LINE>(); foreach (LINE floor in item.Value) { XYZ newSt = new XYZ(floor.GetStartPoint().X, floor.GetStartPoint().Y, newHeight); XYZ newEn = new XYZ(floor.GetEndPoint().X, floor.GetEndPoint().Y, newHeight); newFloor.Add(new LINE(newSt, newEn)); } columns2[item.Key] = newFloor; } List <List <LINE> > Result = new List <List <LINE> >(); foreach (List <LINE> item in NewBeamGroup) { Result.Add(TakeOffColumnEdge(columns2, item)); } SaveTmp(Result); Result = ConnectedEdgeFromMiddleColumns(Result); SaveTmp(Result); /// 拿掉第一輪subBeam List <List <LINE> > Res = TakeOffSubBeams(Result, nonSelected, SHIFTs_Width_Of_Beam); List <List <LINE> > Res2 = TakeOffSubBeams(Res, nonSelected, SHIFTs_Width_Of_Beam); SaveTmp(Res2); return(Res2); }
/// <summary> /// Get Beam parameter Lines using to Create beam those lines is the center line of beam /// </summary> /// <param name="Collect"></param> /// <param name="H_Direction_Lines"></param> /// <param name="V_Direction_Lines"></param> /// <param name="H_Beams"></param> /// <param name="V_Beams"></param> public static List <LINE> GetBeamDrawLines(List <List <LINE> > Collect, List <LINE> H_Direction_Lines, List <LINE> V_Direction_Lines) { List <LINE> RESULT = new List <LINE>(); /// Collect Part foreach (List <LINE> co in Collect) { if (co.Count() <= 4) { LINE line1 = co[0]; LINE line2 = co[1]; XYZ p1 = null; XYZ p2 = null; double ll1 = GeometryResult.Get_Length(line1); double ll2 = GeometryResult.Get_Length(line2); if (ll1 > ll2) { if (line1.GetStartPoint().Y == line1.GetEndPoint().Y) { p1 = new XYZ(line1.GetStartPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0); p2 = new XYZ(line1.GetEndPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0); } else if (line1.GetStartPoint().X == line1.GetEndPoint().X) { p1 = new XYZ((line1.GetStartPoint().X + line2.GetEndPoint().X) / 2, line1.GetStartPoint().Y, 0); p2 = new XYZ((line1.GetStartPoint().X + line2.GetEndPoint().X) / 2, line1.GetEndPoint().Y, 0); } } else { if (line2.GetStartPoint().Y == line2.GetEndPoint().Y) { p1 = new XYZ(line2.GetStartPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0); p2 = new XYZ(line2.GetEndPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0); } else if (line2.GetStartPoint().X == line2.GetEndPoint().X) { p1 = new XYZ((line1.GetStartPoint().X + line1.GetEndPoint().X) / 2, line2.GetStartPoint().Y, 0); p2 = new XYZ((line1.GetStartPoint().X + line1.GetEndPoint().X) / 2, line2.GetEndPoint().Y, 0); } } if (p1 != null) { RESULT.Add(new LINE(p1, p2)); } } } /// H-Beam Part List <LINE> sorted_H = H_Direction_Lines.OrderBy(e => e.GetStartPoint().Y).ToList(); List <LINE> H_Beams = new List <LINE>(); int[] is_pickup = new int[sorted_H.Count()]; for (int i = 0; i < sorted_H.Count(); i++) { if (is_pickup[i] == 1) { continue; } LINE baseLine = sorted_H[i]; for (int j = 0; j < sorted_H.Count(); j++) { if (j == i || is_pickup[j] == 1) { continue; } LINE cmpLine = sorted_H[j]; if (baseLine.GetSlope() == -cmpLine.GetSlope()) { cmpLine = new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint()); } if (baseLine.GetStartPoint().X == cmpLine.GetStartPoint().X&& baseLine.GetEndPoint().X == cmpLine.GetEndPoint().X) { is_pickup[i] = 1; is_pickup[j] = 1; XYZ p1 = new XYZ((baseLine.GetStartPoint().X + cmpLine.GetStartPoint().X) / 2, (baseLine.GetStartPoint().Y + cmpLine.GetStartPoint().Y) / 2, 0); XYZ p2 = new XYZ((baseLine.GetEndPoint().X + cmpLine.GetEndPoint().X) / 2, (baseLine.GetEndPoint().Y + cmpLine.GetEndPoint().Y) / 2, 0); H_Beams.Add(new LINE(p1, p2)); RESULT.Add(new LINE(p1, p2)); break; } } } /// V-Beam Part List <LINE> V_Beams = new List <LINE>(); List <LINE> sorted_V = V_Direction_Lines.OrderBy(e => e.GetStartPoint().X).ToList(); is_pickup = new int[sorted_V.Count()]; for (int i = 0; i < sorted_V.Count(); i++) { if (is_pickup[i] == 1) { continue; } LINE baseLine = sorted_V[i]; for (int j = 0; j < sorted_V.Count(); j++) { if (j == i || is_pickup[j] == 1) { continue; } LINE cmpLine = sorted_V[j]; if (baseLine.GetSlope() == -cmpLine.GetSlope()) { cmpLine = new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint()); } if (baseLine.GetStartPoint().Y == cmpLine.GetStartPoint().Y&& baseLine.GetEndPoint().Y == cmpLine.GetEndPoint().Y) { is_pickup[i] = 1; is_pickup[j] = 1; XYZ p1 = new XYZ((baseLine.GetStartPoint().X + cmpLine.GetStartPoint().X) / 2, (baseLine.GetStartPoint().Y + cmpLine.GetStartPoint().Y) / 2, 0); XYZ p2 = new XYZ((baseLine.GetEndPoint().X + cmpLine.GetEndPoint().X) / 2, (baseLine.GetEndPoint().Y + cmpLine.GetEndPoint().Y) / 2, 0); V_Beams.Add(new LINE(p1, p2)); RESULT.Add(new LINE(p1, p2)); break; } } } return(RESULT); }
private List <LINE> TakeOffColumnEdge(Dictionary <string, List <LINE> > columns, List <LINE> floor) { foreach (KeyValuePair <string, List <LINE> > column in columns) { List <LINE> newFloor = new List <LINE>(); Dictionary <int, List <LINE> > tmpData = new Dictionary <int, List <LINE> >(); for (int ii = 0; ii < column.Value.Count; ii++) { LINE columnEdge = column.Value[ii]; for (int jj = 0; jj < floor.Count; jj++) { LINE floorEdge = floor[jj]; if (Math.Round(floorEdge.GetSlope(), 3) == Math.Round(columnEdge.GetSlope(), 3)) { continue; } if (Math.Abs(Math.Round(floorEdge.GetDirection().X, 3)) == Math.Abs(Math.Round(columnEdge.GetDirection().X, 3)) && Math.Abs(Math.Round(floorEdge.GetDirection().Y, 3)) == Math.Abs(Math.Round(columnEdge.GetDirection().Y, 3))) { continue; } XYZ crossPoint = floorEdge.GetCrossPoint(columnEdge); try { if (floorEdge.IsPointInLine(crossPoint) && columnEdge.IsPointInLine(crossPoint)) { XYZ innerPoint = IsInner(columnEdge.GetStartPoint(), floor) ? columnEdge.GetStartPoint() : columnEdge.GetEndPoint(); double dis1 = (crossPoint - floorEdge.GetStartPoint()).GetLength(); double dis2 = (crossPoint - floorEdge.GetEndPoint()).GetLength(); LINE newLine = null; List <LINE> newList = new List <LINE>(); if (dis1 > dis2) { floorEdge.ResetParameters(crossPoint, "EndPoint"); newLine = new LINE(crossPoint, innerPoint); newList.Add(floorEdge); if (dis2 != 0) { newList.Add(newLine); } } else { newLine = new LINE(innerPoint, crossPoint); floorEdge.ResetParameters(crossPoint, "StartPoint"); if (dis1 != 0) { newList.Add(newLine); } newList.Add(floorEdge); } tmpData[jj] = newList; } } catch (Exception) { } } } for (int kk = 0; kk < floor.Count; kk++) { if (tmpData.ContainsKey(kk)) { foreach (LINE item in tmpData[kk]) { newFloor.Add(item); } } else { newFloor.Add(floor[kk]); } } floor = new List <LINE>(); floor = newFloor; } return(floor); }
private List <FloorEdges> SplitFloorBySubBeam(List <LINE> floor, LINE subbeam) { List <FloorEdges> Floors = new List <FloorEdges>(); /////// 檢查subBeam與板邊界是否有兩個交點 List <int> CrossPo = new List <int>(); for (int i = 0; i < floor.Count; i++) { LINE floorEdge = floor[i]; if (Math.Abs(Math.Round(floorEdge.GetSlope(), 3)) == Math.Abs(Math.Round(subbeam.GetSlope(), 3))) { continue; } XYZ crossPoint = floorEdge.GetCrossPoint(subbeam); if (IsCloseEndsPoint(subbeam, crossPoint) && floorEdge.IsPointInLine(crossPoint)) { CrossPo.Add(i); } } /////// 沒有兩個交點則不處理直接回傳 if (CrossPo.Count != 2) { FloorEdges Floor = new FloorEdges(floor); Floors.Add(Floor); return(Floors); } /////// 有兩個交點則開始處理梁的分離 /// 將板轉換成節點 List <XYZ> nodes = new List <XYZ>(); foreach (LINE item in floor) { nodes.Add(item.GetStartPoint()); } nodes.Add(floor[floor.Count - 1].GetEndPoint()); /// 取的偏移後的交點 XYZ targetPoint = floor[CrossPo[0]].GetStartPoint(); LINE offSetLine_1 = subbeam.GetShiftLines(floor[CrossPo[0]].GetStartPoint(), subbeam.Width / 2, "IN")[0]; LINE offSetLine_2 = subbeam.GetShiftLines(floor[CrossPo[0]].GetEndPoint(), subbeam.Width / 2, "IN")[0]; XYZ crossPoint1 = offSetLine_1.GetCrossPoint(floor[CrossPo[0]]); XYZ crossPoint2 = offSetLine_1.GetCrossPoint(floor[CrossPo[1]]); XYZ crossPoint3 = offSetLine_2.GetCrossPoint(floor[CrossPo[0]]); XYZ crossPoint4 = offSetLine_2.GetCrossPoint(floor[CrossPo[1]]); List <XYZ> crossPoint_1 = new List <XYZ>() { crossPoint1, crossPoint2 }; List <XYZ> crossPoint_2 = new List <XYZ>() { crossPoint3, crossPoint4 }; /// Part 1 int kk = 0; List <XYZ> part_1 = new List <XYZ>(); for (int i = 0; i < nodes.Count; i++) { if (i > CrossPo[0] && i <= CrossPo[1] && kk < 2) { part_1.Add(crossPoint_1[kk]); kk = kk + 1; } else if (i <= CrossPo[0] || i > CrossPo[1]) { part_1.Add(nodes[i]); } } /// Part 2 kk = 0; List <XYZ> part_2 = new List <XYZ>(); for (int i = 0; i < nodes.Count; i++) { if (i > CrossPo[0] && i <= CrossPo[1]) { part_2.Add(nodes[i]); } else if ((i == CrossPo[0] || i == CrossPo[1] + 1) && kk < 2) { part_2.Add(crossPoint_2[kk]); kk = kk + 1; } } part_2.Add(crossPoint_2[0]); try { /// 將節點轉換成LINE List <LINE> newFloor_1 = new List <LINE>(); for (int i = 0; i < part_1.Count() - 1; i++) { newFloor_1.Add(new LINE(part_1[i], part_1[i + 1])); } List <LINE> newFloor_2 = new List <LINE>(); for (int i = 0; i < part_2.Count() - 1; i++) { newFloor_2.Add(new LINE(part_2[i], part_2[i + 1])); } Floors.Add(new FloorEdges(newFloor_1)); Floors.Add(new FloorEdges(newFloor_2)); } catch (Exception) { return(new List <FloorEdges>() { new FloorEdges(floor) }); } return(Floors); }