public void BuildDataStructure(bool showProgress) { PointSet pointSet = new PointSet(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); ProgressMeter progressMeter = new ProgressMeter(); if (!showProgress) { progressMeter.Dispose(); } if (showProgress) { progressMeter.SetLimit(4); } if (showProgress) { progressMeter.Start("Building data structure"); } try { for (int i = 0; i < this.list_4.Count; i++) { messageFilter.CheckMessageFilter((long)i, 1000); pointSet.Add(this.list_4[i].Vertex1); pointSet.Add(this.list_4[i].Vertex2); pointSet.Add(this.list_4[i].Vertex3); } if (showProgress) { progressMeter.MeterProgress(); } Global.SuspendEpsilon(0.0, 0.0); pointSet.RemoveMultiplePoints3d(); if (showProgress) { progressMeter.MeterProgress(); } pointSet.Sort(); if (showProgress) { progressMeter.MeterProgress(); } this.list_0 = pointSet.ToList(); for (int j = 0; j < this.list_4.Count; j++) { messageFilter.CheckMessageFilter((long)j, 1000); int num = this.list_0.BinarySearch(this.list_4[j].Vertex1); if (num < 0) { throw new System.Exception("Invalid vertex index."); } this.list_1.Add(num); int num2 = this.list_0.BinarySearch(this.list_4[j].Vertex2); if (num2 < 0) { throw new System.Exception("Invalid vertex index."); } this.list_2.Add(num2); int num3 = this.list_0.BinarySearch(this.list_4[j].Vertex3); if (num3 < 0) { throw new System.Exception("Invalid vertex index."); } this.list_3.Add(num3); } if (showProgress) { progressMeter.MeterProgress(); } if (showProgress) { progressMeter.Stop(); } Global.ResumeEpsilon(); } catch { if (showProgress) { progressMeter.Stop(); } Global.ResumeEpsilon(); throw; } }
public static void Colorize(MyDB2 mydb, List <System.Drawing.Color> cl, FaceColorizeType type) { TEDictionary ted = mydb.TEDicList[mydb.Resolution]; Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); try { ObjectId[] faceIDs = Selection.getFaceIds(mydb.getFaceLayerName()); List <Triangle> triList = Conversions.ToCeometricAcDbTriangleList(faceIDs); Global.SuspendEpsilon(0.0, 0.0); //List<Triangle> triList = ted.TriangleList; Global.ResumeEpsilon(); double num = 1.7976931348623157E+308; double num2 = -1.7976931348623157E+308; string formatFromLUPREC = DBManager.GetFormatFromLUPREC(); string a; double range; if (type == FaceColorizeType.CenterZ) { range = ted.maxCZ - ted.minCZ; } else if (type == FaceColorizeType.MaxZ) { range = ted.maxMaxZ - ted.minMaxZ; } else { throw new System.Exception("无效的颜色类型"); } double sec = range / cl.Count; progressMeter.SetLimit(triList.Count); progressMeter.Start("Colorizing property"); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord arg_3D7_0 = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); int i = 0; while (i < triList.Count) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); } catch (System.Exception ex) { progressMeter.Stop(); throw; } int colorIndex; if (type == FaceColorizeType.CenterZ) { colorIndex = (int)Math.Floor((triList[i].Center.Z - ted.minCZ) / sec); } else if (type == FaceColorizeType.MaxZ) { colorIndex = (int)Math.Floor((Math.Max(Math.Max(triList[i].Vertex1.Z, triList[i].Vertex2.Z), triList[i].Vertex3.Z) - ted.minMaxZ) / sec); } else { throw new System.Exception("无效的类型"); } if (colorIndex >= cl.Count) { colorIndex = cl.Count - 1; } Face face = (Face)transaction.GetObject(triList[i].AcDbFace.ObjectId, (OpenMode)1); face.Color = Autodesk.AutoCAD.Colors.Color.FromColor(cl[colorIndex]); i++; continue; } transaction.Commit(); } progressMeter.Stop(); return; throw new System.Exception("Invalid target property"); } catch (System.Exception ex) { progressMeter.Stop(); editor.WriteMessage("\n" + ex.Message); } }
public void ReconstructSurface(ProgressMeter pm, int relevantDecimals) { Editor arg_0F_0 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); PointSet pointSet = new PointSet(); for (int i = 0; i < this.Edges.Count; i++) { messageFilter.CheckMessageFilter((long)i, 10000); this.Edges[i].StartPoint.Round(relevantDecimals); this.Edges[i].EndPoint.Round(relevantDecimals); pointSet.Add(this.Edges[i].StartPoint); pointSet.Add(this.Edges[i].EndPoint); } pointSet.RemoveMultiplePoints3d(); pointSet.Sort(); this.Vertices = pointSet.ToList(); List <SurfaceReconstruction.IndexedEdge> list = new List <SurfaceReconstruction.IndexedEdge>(); for (int j = 0; j < this.Edges.Count; j++) { messageFilter.CheckMessageFilter((long)j, 10000); int num = this.Vertices.BinarySearch(this.Edges[j].StartPoint); if (num < 0) { num = ~num; int num2 = Math.Max(0, num - 1); if (this.Edges[num].DistanceTo(this.Edges[j].StartPoint) > this.Edges[num2].DistanceTo(this.Edges[j].StartPoint)) { num = num2; } } int num3 = this.Vertices.BinarySearch(this.Edges[j].EndPoint); if (num3 < 0) { num3 = ~num3; int num4 = Math.Max(0, num3 - 1); if (this.Edges[num3].DistanceTo(this.Edges[j].EndPoint) > this.Edges[num4].DistanceTo(this.Edges[j].EndPoint)) { num3 = num4; } } list.Add(new SurfaceReconstruction.IndexedEdge(num, num3)); } list = SurfaceReconstruction.IndexedEdge.RemoveDuplicates(list); list = SurfaceReconstruction.IndexedEdge.RemoveZeros(list); SurfaceReconstruction.DirectedCyclicGraph directedCyclicGraph = new SurfaceReconstruction.DirectedCyclicGraph(); for (int k = 0; k < list.Count; k++) { directedCyclicGraph.Add(list[k]); } pm.SetLimit(directedCyclicGraph.Count); if (directedCyclicGraph.Count > 10000) { pm.Start("Scanning for faces"); } int num5 = 0; foreach (int current in directedCyclicGraph.Keys) { messageFilter.CheckMessageFilter((long)num5, 1000); if (directedCyclicGraph.Count > 10000) { pm.MeterProgress(); } num5++; SurfaceReconstruction.Node node = directedCyclicGraph[current]; foreach (SurfaceReconstruction.Node current2 in node.Children) { foreach (SurfaceReconstruction.Node current3 in current2.Children) { if (current3.Number != node.Number) { bool flag = false; foreach (SurfaceReconstruction.Node current4 in current3.Children) { if (current4.Number != current2.Number && current4.Number == node.Number) { this.Tris.Add(new SurfaceReconstruction.Tri(node.Number, current2.Number, current3.Number)); flag = true; break; } } if (!flag) { foreach (SurfaceReconstruction.Node current5 in current3.Children) { if (current5.Number != current2.Number && !current5.Children.Contains(current2)) { foreach (SurfaceReconstruction.Node current6 in current5.Children) { if (current6.Number != current3.Number && current6.Number == node.Number) { this.Quads.Add(new SurfaceReconstruction.Quad(node.Number, current2.Number, current3.Number, current5.Number)); break; } } } } } } } } } SurfaceReconstruction.Tri.RemoveDuplicates(ref this.Tris); SurfaceReconstruction.Quad.RemoveDuplicates(ref this.Quads); pm.Stop(); }
public void ColorizeFacesCommand() { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); try { ObjectId[] faceIDs = CommandLineQuerries.SelectFaces(false); CMD_Colorize.string_0 = CommandLineQuerries.SpecifyTargetProperty(CMD_Colorize.string_0); CMD_Colorize.string_1 = CommandLineQuerries.KeywordYesNo("Reverse color order", CMD_Colorize.string_1, false, false); CMD_Colorize.int_0 = CommandLineQuerries.SpecifyInteger("Specify number of colors", CMD_Colorize.int_0, 2, 32768, false, false); CMD_Colorize.double_0 = CommandLineQuerries.SpecifyDouble("Specify lower cutoff percentage", CMD_Colorize.double_0, false, true, false, true); CMD_Colorize.double_1 = CommandLineQuerries.SpecifyDouble("Specify upper cutoff percentage", CMD_Colorize.double_1, false, false, false, false); Global.SuspendEpsilon(0.0, 0.0); List <Triangle> list = Conversions.ToCeometricAcDbTriangleList(faceIDs); Global.ResumeEpsilon(); double num = 1.7976931348623157E+308; double num2 = -1.7976931348623157E+308; string formatFromLUPREC = DBManager.GetFormatFromLUPREC(); string a; if ((a = CMD_Colorize.string_0) != null) { if (!(a == "AN")) { if (!(a == "AR")) { if (!(a == "CZ")) { if (!(a == "MINZ")) { if (!(a == "MAXZ")) { goto IL_714; } Triangle.Sort(list, Triangle.SortOrder.MaxZ); num = list[0].MaximumZ; num2 = list[list.Count - 1].MaximumZ; editor.WriteMessage("\nMinimum maximum Z: " + num.ToString(formatFromLUPREC)); editor.WriteMessage("\nMaximum maximum Z: " + num2.ToString(formatFromLUPREC)); } else { Triangle.Sort(list, Triangle.SortOrder.MinZ); num = list[0].MinimumZ; num2 = list[list.Count - 1].MinimumZ; editor.WriteMessage("\nMinimum minimum Z: " + num.ToString(formatFromLUPREC)); editor.WriteMessage("\nMaximum minimum Z: " + num2.ToString(formatFromLUPREC)); } } else { Triangle.Sort(list, Triangle.SortOrder.CenterZ); num = list[0].Center.Z; num2 = list[list.Count - 1].Center.Z; editor.WriteMessage("\nMinimum center Z: " + num.ToString(formatFromLUPREC)); editor.WriteMessage("\nMaximum center Z: " + num2.ToString(formatFromLUPREC)); } } else { Triangle.Sort(list, Triangle.SortOrder.Area); num = list[0].Area; num2 = list[list.Count - 1].Area; editor.WriteMessage("\nMinimum area: " + num.ToString(formatFromLUPREC)); editor.WriteMessage("\nMaximum area: " + num2.ToString(formatFromLUPREC)); } } else { Triangle.Sort(list, Triangle.SortOrder.MinimumAngle); num = list[0].MinimumAngle; num2 = list[list.Count - 1].MinimumAngle; editor.WriteMessage("\nMinimum minimum angle: " + (num * 180.0 / 3.1415926535897931).ToString(formatFromLUPREC) + " deg."); editor.WriteMessage("\nMaximum minimum angle: " + (num2 * 180.0 / 3.1415926535897931).ToString(formatFromLUPREC) + " deg."); } progressMeter.SetLimit(list.Count); progressMeter.Start("Colorizing property"); using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1); BlockTableRecord arg_3D7_0 = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1); int i = 0; while (i < list.Count) { try { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)i, 1000); } catch (System.Exception ex) { progressMeter.Stop(); throw; } string a2; if ((a2 = CMD_Colorize.string_0) != null) { double num3; if (!(a2 == "AN")) { if (!(a2 == "AR")) { if (!(a2 == "CZ")) { if (!(a2 == "MINZ")) { if (!(a2 == "MAXZ")) { goto IL_6F4; } num3 = list[i].MaximumZ; } else { num3 = list[i].MinimumZ; } } else { num3 = list[i].Center.Z; } } else { num3 = list[i].Area; } } else { num3 = list[i].MinimumAngle; } int num4 = CMD_Colorize.int_0 - 1; double num5 = Math.Abs((num3 - num) / (num2 - num)); if (100.0 * num5 <= CMD_Colorize.double_0) { num5 = 0.0; } else if (100.0 * num5 >= CMD_Colorize.double_1) { num5 = 1.0; } else { num5 = num5 * 100.0 / (CMD_Colorize.double_1 - CMD_Colorize.double_0) - CMD_Colorize.double_0 / (CMD_Colorize.double_1 - CMD_Colorize.double_0); } num5 = Math.Round((double)num4 * num5, 0) / (double)num4; if (CMD_Colorize.string_1 == "Y") { num5 = 1.0 - num5; } double num6 = 0.2; byte b = 0; byte b2 = 0; byte b3 = 0; if (num5 < 0.2) { b3 = (byte)(255.0 * (num5 - 0.0 * num6) / num6); b2 = 255; } else if (num5 < 2.0 * num6) { b3 = 255; b2 = (byte)(255.0 - 255.0 * (num5 - 1.0 * num6) / num6); } else if (num5 < 3.0 * num6) { b = (byte)(255.0 * (num5 - 2.0 * num6) / num6); b3 = 255; } else if (num5 < 4.0 * num6) { b = 255; b3 = (byte)(255.0 - 255.0 * (num5 - 3.0 * num6) / num6); } else { b = 255; b2 = (byte)(255.0 * (num5 - 4.0 * num6) / num6); } Face face = (Face)transaction.GetObject(list[i].AcDbFace.ObjectId, (OpenMode)1); face.Color = (Color.FromRgb(b, b3, b2)); i++; continue; } IL_6F4: throw new System.Exception("Invalid target property"); } transaction.Commit(); goto IL_71F; } goto IL_714; IL_71F: progressMeter.Stop(); return; } IL_714: throw new System.Exception("Invalid target property"); } catch (System.Exception ex) { progressMeter.Stop(); editor.WriteMessage("\n" + ex.Message); } }
public static void EraseDublicates2d(ObjectId[] pointIDs, double epsilon, string keepMultiple, ref int numberOfPointsErased) { Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); IComparer <IdPoint> comparer = new Class2(); double num = epsilon * epsilon; try { using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { CoordinateSystem ceometricUcs = Conversions.GetCeometricUcs(); CoordinateSystem actualCS = CoordinateSystem.Global(); CoordinateTransformator coordinateTransformator = new CoordinateTransformator(actualCS, ceometricUcs); List <IdPoint> list = new List <IdPoint>(); for (int i = 0; i < pointIDs.Length; i++) { DBPoint dbPoint = (DBPoint)transaction.GetObject(pointIDs[i], (OpenMode)1, true); IdPoint idPoint = new IdPoint(dbPoint); coordinateTransformator.Transform(idPoint.Point); list.Add(idPoint); } list.Sort(comparer); List <IdPoint> list2 = new List <IdPoint>(); for (int j = 0; j < list.Count; j++) { list2.Add(list[j]); } if (keepMultiple == "H") { list.Reverse(); } progressMeter.SetLimit(list.Count); if ((double)list.Count > 10000.0) { progressMeter.Start("Eliminating points"); } for (int k = 0; k < list.Count; k++) { progressMeter.MeterProgress(); messageFilter.CheckMessageFilter((long)k, 1000); IdPoint idPoint2 = list[k]; if (!idPoint2.IsErased) { Point point = new Point(idPoint2.Point.X - epsilon, -1.7976931348623157E+308, -1.7976931348623157E+308); Point point2 = new Point(idPoint2.Point.X + epsilon, 1.7976931348623157E+308, 1.7976931348623157E+308); IdPoint item = new IdPoint(point, ObjectId.Null); IdPoint item2 = new IdPoint(point2, ObjectId.Null); int num2 = list2.BinarySearch(item, comparer); int num3 = list2.BinarySearch(item2, comparer); if (num2 < 0) { num2 = Math.Abs(num2) - 2; } if (num2 < 0) { num2 = 0; } if (num2 >= list.Count) { num2 = list.Count - 1; } if (num3 < 0) { num3 = Math.Abs(num3) - 1; } if (num3 < 0) { num3 = 0; } if (num3 >= list.Count) { num3 = list.Count - 1; } for (int l = num2; l <= num3; l++) { if (!list2[l].IsErased && list2[l] != idPoint2 && IdPoint.smethod_0(idPoint2.Point, list2[l].Point) < num) { list2[l].IsErased = true; list2[l].DBPoint.Erase(); numberOfPointsErased++; } } } } transaction.Commit(); } progressMeter.Stop(); } catch { progressMeter.Stop(); throw; } }
internal PointSet method_0(ObjectId[] objectId_0, double double_0) { Database workingDatabase = HostApplicationServices.WorkingDatabase; ProgressMeter progressMeter = new ProgressMeter(); progressMeter.SetLimit(objectId_0.Length); if (objectId_0.Length > 1) { progressMeter.Start("Generating points..."); } MessageFilter messageFilter = new MessageFilter(); System.Windows.Forms.Application.AddMessageFilter(messageFilter); int num = 0; PointSet pointSet = new PointSet(); PointSet result; try { using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { List <Entity> list = new List <Entity>(); for (int i = 0; i < objectId_0.Length; i++) { list.Add((Entity)transaction.GetObject(objectId_0[i], (OpenMode)0)); } Mesh2dControl mesh2dControl = new Mesh2dControl(); mesh2dControl.MaxNodeSpacing = (double_0); mesh2dControl.ElementShape = (0); for (int j = 0; j < objectId_0.Length; j++) { Brep brep = new Brep(list[j]); Mesh2dFilter mesh2dFilter = new Mesh2dFilter(); mesh2dFilter.Insert(brep, mesh2dControl); Mesh2d mesh2d = new Mesh2d(mesh2dFilter); using (Mesh2dElement2dEnumerator enumerator = mesh2d.Element2ds.GetEnumerator()) { while (enumerator.MoveNext()) { Element2d current = enumerator.Current; messageFilter.CheckMessageFilter((long)num, 100); num++; using (Element2dNodeEnumerator enumerator2 = current.Nodes.GetEnumerator()) { while (enumerator2.MoveNext()) { Node current2 = enumerator2.Current; pointSet.Add(new Point(current2.Point.X, current2.Point.Y, current2.Point.Z)); current2.Dispose(); } } current.Dispose(); } } progressMeter.MeterProgress(); } pointSet.RemoveMultiplePoints3d(); } progressMeter.Stop(); result = pointSet; } catch { progressMeter.Stop(); throw; } return(result); }