private static void SearchWalls(List <LineSegment3d> outLines, List <LineSegment3d> allLines) { WallInfor wallInfo = null; using (var tolerance = new Utils.SafeToleranceOverride()) { wallInfo = WallRecognizer.getWallinfors(outLines, allLines); } if (wallInfo == null) { return; } // Test Code! var visited = new HashSet <WallInfor>(); var database = Application.DocumentManager.MdiActiveDocument.Database; using (var transaction = database.TransactionManager.StartTransaction()) { var modelspaceId = SymbolUtilityServices.GetBlockModelSpaceId(database); var modelspace = (BlockTableRecord)transaction.GetObject(modelspaceId, OpenMode.ForWrite); var color = Color.FromColorIndex(ColorMethod.ByAci, 4); // Cyan ObjectId layerId = LayerUtils.AddNewLayer(database, "temp-poly2", "Continuous", color); var currentInfo = wallInfo; var count = 0; while (currentInfo != null && currentInfo.outline != null) { if (visited.Contains(currentInfo)) { break; } var line = new Line(currentInfo.outline.StartPoint, currentInfo.outline.EndPoint); line.Color = color; line.LayerId = layerId; modelspace.AppendEntity(line); transaction.AddNewlyCreatedDBObject(line, add: true); foreach (var innerSeg in currentInfo.innerlines) { var innerLine = new Line(innerSeg.StartPoint, innerSeg.EndPoint); innerLine.Color = color; innerLine.LayerId = layerId; modelspace.AppendEntity(innerLine); transaction.AddNewlyCreatedDBObject(innerLine, add: true); } visited.Add(currentInfo); count++; currentInfo = currentInfo.next; if (currentInfo == wallInfo) { break; } } transaction.Commit(); } }
public static void updateInnerLines(LineSegment3d line, LineSegment3d prepareline, double dist, List <LineSegment3d> innerlines) { bool haveLinesOverlapped = false; foreach (LineSegment3d innerLine in innerlines) { if (WallRecognizer.isSegmentsProjectionOverlapped(prepareline, innerLine)) { haveLinesOverlapped = true; break; } } if (haveLinesOverlapped) { // update the innerlines List <LineSegment3d> preparelines = new List <LineSegment3d>(); foreach (LineSegment3d innerLine in innerlines) { if (WallRecognizer.isSegmentsProjectionOverlapped(prepareline, innerLine)) { Line3d innerline3d = WallRecognizer.toLine3d(innerLine.StartPoint, innerLine.EndPoint); double innerDist = innerline3d.GetDistanceTo(line.StartPoint); if (DoubleExtensions.Larger(innerDist, dist)) { if (!preparelines.Contains(prepareline)) { preparelines.Add(prepareline); } } else { if (!preparelines.Contains(innerLine)) { preparelines.Add(innerLine); } } } else { if (!preparelines.Contains(innerLine)) { preparelines.Add(innerLine); } } } // copy preparelines to innerlines innerlines.Clear(); foreach (LineSegment3d innerLine in preparelines) { innerlines.Add(innerLine); } } else { innerlines.Add(prepareline); } }
public static List <LineSegment3d> getWallline(LineSegment3d line, IEnumerable <LineSegment3d> entities) { double width = maxWallWidth + 1; // step 1: get the parallel lines in the loop: skip the colinear line var dir = line.Direction; var parallelLines = new List <LineSegment3d>(); foreach (LineSegment3d tmpLine in entities) { if (line != tmpLine) { if (dir.IsParallelTo(tmpLine.Direction) && (!tmpLine.IsOn(line.StartPoint) || tmpLine.IsOn(line.EndPoint))) // check if colinear line { parallelLines.Add(WallRecognizer.toLineSegment3d(tmpLine.StartPoint, tmpLine.EndPoint)); } } } List <LineSegment3d> innerlines = new List <LineSegment3d>(); // step 2: get poper innerlines foreach (LineSegment3d line1 in parallelLines) { Line3d line3d = WallRecognizer.toLine3d(line1.StartPoint, line1.EndPoint); // skip the colinear line and the two lines should be projection overlapped if (!line3d.IsOn(line.StartPoint) && WallRecognizer.isSegmentsProjectionOverlapped(line1, line)) { double dist = line3d.GetDistanceTo(line.StartPoint); if (DoubleExtensions.Larger(500, dist)) { updateInnerLines(line, line1, dist, innerlines); } /*// pixel to millemeter * dist = (dist * MILLIMETER_TO_METER) / PIXEL_TO_M_FACTOR; * // the dist should > minWallWidth & < maxWallWidth * if (DoubleExtensions.Larger(dist, minWallWidth) && DoubleExtensions.Larger(maxWallWidth, dist)) * { * //width = Math.Round(dist); * updateInnerLines(line1, dist, innerlines); * }*/ } } return(innerlines); }
public static WallInfor getWallinfors(List <LineSegment3d> outLines, List <LineSegment3d> allLines) { WallInfor wallInfor = new WallInfor(); // step1: get the biggest length of outline var index = 0; var length = outLines[index].Length; int size = outLines.Count; for (int i = 1; i < size; i++) { if (DoubleExtensions.Larger(outLines[i].Length, length)) { index = i; length = outLines[index].Length; } } var currentWallInfor = wallInfor; // step2: get the outline wall infor for (int i = 0; i < size; i++) { var line = outLines[(i + index) % size]; // skip the line if it is in part exist wall infor if (!isPartOfWallinfor(line, wallInfor)) { List <LineSegment3d> innerlines = WallRecognizer.getWallline(line, allLines); // set the wall infor currentWallInfor.outline = line; currentWallInfor.innerlines = innerlines; currentWallInfor.next = new WallInfor(); currentWallInfor = currentWallInfor.next; } } return(wallInfor); }