예제 #1
0
        private void method_0(ObjectId[] objectId_0, ref ProgressMeter progressMeter_0, CoordinateSystem coordinateSystem_0)
        {
            Database      workingDatabase = HostApplicationServices.WorkingDatabase;
            Editor        editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            List <Region> list            = new List <Region>();
            double        epsilon         = Convert.ToDouble(CMD_Silhouette.string_1);

            DBManager.SetEpsilon();
            List <Triangle> list2 = Conversions.ToCeometricAcDbTriangleList(objectId_0);

            if (!Conversions.IsWCS(coordinateSystem_0))
            {
                Triangle.TransformCoordinates(list2, CoordinateSystem.Global(), coordinateSystem_0);
            }
            list2.Sort(new Triangle.CompareMinX());
            int    num  = 0;
            double num2 = -1.7976931348623157E+308;
            double num3 = -1.7976931348623157E+308;
            double num4 = 1.7976931348623157E+308;
            double num5 = 1.7976931348623157E+308;

            for (int i = list2.Count - 1; i >= 0; i--)
            {
                if (list2[i].NormalVector.IsOrthogonalTo(new ngeometry.VectorGeometry.Vector3d(0.0, 0.0, 1.0)))
                {
                    list2.RemoveAt(i);
                    num++;
                }
                else
                {
                    Global.SuspendEpsilon(0.0, 0.0);
                    list2[i].Vertex1.Z = 0.0;
                    list2[i].Vertex2.Z = 0.0;
                    list2[i].Vertex3.Z = 0.0;
                    Global.ResumeEpsilon();
                    double minimumX = list2[i].MinimumX;
                    if (minimumX < num4)
                    {
                        num4 = minimumX;
                    }
                    double maximumX = list2[i].MaximumX;
                    if (maximumX > num2)
                    {
                        num2 = maximumX;
                    }
                    double minimumY = list2[i].MinimumY;
                    if (minimumY < num5)
                    {
                        num5 = minimumY;
                    }
                    double maximumY = list2[i].MaximumY;
                    if (maximumY > num3)
                    {
                        num3 = maximumY;
                    }
                }
            }
            ngeometry.VectorGeometry.Vector3d vector3d = new ngeometry.VectorGeometry.Vector3d(0.5 * (num4 + num2), 0.5 * (num5 + num3), 0.0);
            double num6 = 0.5 * Math.Max(Math.Abs(num2 - num4), Math.Abs(num3 - num5));
            double num7 = Math.Ceiling(100000.0 / num6);

            for (int j = 0; j < list2.Count; j++)
            {
                list2[j] = list2[j].Move(-1.0 * vector3d);
            }
            SubDMeshHandler subDMeshHandler = new SubDMeshHandler(list2);

            subDMeshHandler.BuildDataStructure(false);
            int k = 2147483647;

            while (k > 0)
            {
                this.messageFilter_0.CheckMessageFilter();
                k    = subDMeshHandler.Heal(epsilon);
                num += k;
            }
            editor.WriteMessage("\nDegenerate projections healed: " + num);
            Autodesk.AutoCAD.Geometry.Matrix3d matrix3d  = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(num7, new Point3d(0.0, 0.0, 0.0));
            Autodesk.AutoCAD.Geometry.Matrix3d matrix3d2 = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(1.0 / num7, new Point3d(0.0, 0.0, 0.0));
            Autodesk.AutoCAD.Geometry.Matrix3d matrix3d3 = Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(new Autodesk.AutoCAD.Geometry.Vector3d(vector3d.X, vector3d.Y, 0.0));
            progressMeter_0 = new ProgressMeter();
            progressMeter_0.SetLimit(subDMeshHandler.FaceVertexIndex1.Count);
            progressMeter_0.Start("Generating projections");
            int num8 = 0;

            for (int l = 0; l < subDMeshHandler.FaceVertexIndex1.Count; l++)
            {
                try
                {
                    progressMeter_0.MeterProgress();
                    this.messageFilter_0.CheckMessageFilter((long)l, 1000);
                }
                catch (System.Exception ex)
                {
                    for (int m = 0; m < list.Count; m++)
                    {
                        list[m].Dispose();
                    }
                    progressMeter_0.Stop();
                    throw;
                }
                Region region = this.method_2(subDMeshHandler, l);
                if (region == null)
                {
                    num8++;
                }
                else
                {
                    region.TransformBy(matrix3d);
                    list.Add(region);
                }
            }
            editor.WriteMessage("\nNumber of failed projections: " + num8.ToString());
            progressMeter_0.Stop();
            progressMeter_0 = new ProgressMeter();
            int limit = (int)Math.Ceiling(Math.Log((double)list.Count) / Math.Log(2.0));

            progressMeter_0.SetLimit(limit);
            progressMeter_0.Start("Computing silhouette");
            if (list.Count > 1)
            {
                this.method_1(ref list, ref progressMeter_0);
            }
            list[0].TransformBy(matrix3d2);
            list[0].TransformBy(matrix3d3);
            CoordinateTransformator coordinateTransformator = new CoordinateTransformator(coordinateSystem_0, CoordinateSystem.Global());

            if (!coordinateTransformator.bool_0)
            {
                list[0].TransformBy(coordinateTransformator.ToAcadTransformation());
            }
            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                BlockTable       blockTable       = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1);
                BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1);
                blockTableRecord.AppendEntity(list[0]);
                transaction.AddNewlyCreatedDBObject(list[0], true);
                transaction.Commit();
            }
            progressMeter_0.Stop();
        }
예제 #2
0
        private void method_0(ObjectId[] objectId_0, ProgressMeter progressMeter_0, CoordinateSystem coordinateSystem_0)
        {
            Database       workingDatabase = HostApplicationServices.WorkingDatabase;
            Editor         editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            List <Solid3d> list            = new List <Solid3d>();
            double         epsilon         = Convert.ToDouble(CMD_FacesToSolid.string_2);
            bool           flag            = true;

            if (CMD_FacesToSolid.string_0 == "N")
            {
                flag = false;
            }
            DBManager.SetEpsilon();
            List <Triangle> list2 = Conversions.ToCeometricAcDbTriangleList(objectId_0);

            if (!Conversions.IsWCS(coordinateSystem_0))
            {
                Triangle.TransformCoordinates(list2, CoordinateSystem.Global(), coordinateSystem_0);
            }
            list2.Sort(new Triangle.CompareMinX());
            int    num  = 0;
            double num2 = -1.7976931348623157E+308;
            double num3 = -1.7976931348623157E+308;
            double num4 = 1.7976931348623157E+308;
            double num5 = 1.7976931348623157E+308;

            for (int i = list2.Count - 1; i >= 0; i--)
            {
                if (list2[i].NormalVector.IsOrthogonalTo(new ngeometry.VectorGeometry.Vector3d(0.0, 0.0, 1.0)))
                {
                    list2.RemoveAt(i);
                    num++;
                }
                else
                {
                    double minimumX = list2[i].MinimumX;
                    if (minimumX < num4)
                    {
                        num4 = minimumX;
                    }
                    double maximumX = list2[i].MaximumX;
                    if (maximumX > num2)
                    {
                        num2 = maximumX;
                    }
                    double minimumY = list2[i].MinimumY;
                    if (minimumY < num5)
                    {
                        num5 = minimumY;
                    }
                    double maximumY = list2[i].MaximumY;
                    if (maximumY > num3)
                    {
                        num3 = maximumY;
                    }
                }
            }
            ngeometry.VectorGeometry.Vector3d vector3d = new ngeometry.VectorGeometry.Vector3d(0.5 * (num4 + num2), 0.5 * (num5 + num3), 0.0);
            double num6 = 0.5 * Math.Max(Math.Abs(num2 - num4), Math.Abs(num3 - num5));
            double num7 = Math.Ceiling(100000.0 / num6);

            for (int j = 0; j < list2.Count; j++)
            {
                list2[j] = list2[j].Move(-1.0 * vector3d);
            }
            SubDMeshHandler subDMeshHandler = new SubDMeshHandler(list2);

            subDMeshHandler.BuildDataStructure(false);
            int k = 2147483647;

            while (k > 0)
            {
                this.messageFilter_0.CheckMessageFilter();
                k    = subDMeshHandler.HealXY(epsilon);
                num += k;
            }
            editor.WriteMessage("\nDegenerate projections healed: " + num);
            Autodesk.AutoCAD.Geometry.Matrix3d matrix3d  = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(num7, new Point3d(0.0, 0.0, 0.0));
            Autodesk.AutoCAD.Geometry.Matrix3d matrix3d2 = Autodesk.AutoCAD.Geometry.Matrix3d.Scaling(1.0 / num7, new Point3d(0.0, 0.0, 0.0));
            Autodesk.AutoCAD.Geometry.Matrix3d matrix3d3 = Autodesk.AutoCAD.Geometry.Matrix3d.Displacement(new Autodesk.AutoCAD.Geometry.Vector3d(vector3d.X, vector3d.Y, 0.0));
            progressMeter_0 = new ProgressMeter();
            progressMeter_0.SetLimit(objectId_0.Length);
            progressMeter_0.Start("Extruding objects");
            int num8 = 0;
            int num9 = 0;

            for (int l = 0; l < subDMeshHandler.FaceVertexIndex1.Count; l++)
            {
                try
                {
                    progressMeter_0.MeterProgress();
                    this.messageFilter_0.CheckMessageFilter((long)l, 1000);
                }
                catch (System.Exception ex)
                {
                    for (int m = 0; m < list.Count; m++)
                    {
                        list[m].Dispose();
                    }
                    progressMeter_0.Stop();
                    throw;
                }
                try
                {
                    Face   face = new Face(new Point3d(subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex1[l]].X, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex1[l]].Y, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex1[l]].Z), new Point3d(subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex2[l]].X, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex2[l]].Y, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex2[l]].Z), new Point3d(subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex3[l]].X, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex3[l]].Y, subDMeshHandler.Vertices[subDMeshHandler.FaceVertexIndex3[l]].Z), false, false, false, false);
                    double z    = face.GetVertexAt(0).Z;
                    double z2   = face.GetVertexAt(1).Z;
                    double z3   = face.GetVertexAt(2).Z;
                    short  num10;
                    if (CMD_FacesToSolid.double_0 < 0.0)
                    {
                        if (z <= z2 && z <= z3)
                        {
                            num10 = 0;
                        }
                        else if (z2 <= z && z2 <= z3)
                        {
                            num10 = 1;
                        }
                        else
                        {
                            num10 = 2;
                        }
                    }
                    else if (z >= z2 && z >= z3)
                    {
                        num10 = 0;
                    }
                    else if (z2 >= z && z2 >= z3)
                    {
                        num10 = 1;
                    }
                    else
                    {
                        num10 = 2;
                    }
                    Point3d vertexAt = face.GetVertexAt(num10);
                    Point3d point3d  = new Point3d(vertexAt.X, vertexAt.Y, vertexAt.Z + CMD_FacesToSolid.double_0);
                    //point3d..ctor(vertexAt.X, vertexAt.Y, vertexAt.Z + CMD_FacesToSolid.double_0);
                    Autodesk.AutoCAD.DatabaseServices.Line line = new Autodesk.AutoCAD.DatabaseServices.Line(vertexAt, point3d);
                    Region region = this.method_2(subDMeshHandler, l);
                    if (region == null)
                    {
                        num8++;
                    }
                    else
                    {
                        region.TransformBy(matrix3d);
                        line.TransformBy(matrix3d);
                        try
                        {
                            Solid3d solid3d = new Solid3d();
                            solid3d.ExtrudeAlongPath(region, line, 0.0);
                            solid3d.SetPropertiesFrom(face);
                            list.Add(solid3d);
                        }
                        catch (System.Exception ex)
                        {
                            num9++;
                        }
                        line.Dispose();
                        region.Dispose();
                    }
                }
                catch (System.Exception ex)
                {
                }
            }
            editor.WriteMessage("\nNumber of failed projections: " + num8.ToString());
            editor.WriteMessage("\nNumber of failed extrusions : " + num8.ToString());
            progressMeter_0.Stop();
            if (flag && list.Count > 1)
            {
                progressMeter_0 = new ProgressMeter();
                int limit = (int)Math.Ceiling(Math.Log((double)list.Count) / Math.Log(2.0));
                progressMeter_0.SetLimit(limit);
                progressMeter_0.Start("Building solid");
                this.method_1(ref list, ref progressMeter_0);
            }
            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                BlockTable       blockTable       = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1);
                BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1);
                for (int n = 0; n < list.Count; n++)
                {
                    list[n].TransformBy(matrix3d2);
                    list[n].TransformBy(matrix3d3);
                    CoordinateTransformator coordinateTransformator = new CoordinateTransformator(coordinateSystem_0, CoordinateSystem.Global());
                    if (!coordinateTransformator.bool_0)
                    {
                        list[n].TransformBy(coordinateTransformator.ToAcadTransformation());
                    }
                    blockTableRecord.AppendEntity(list[n]);
                    transaction.AddNewlyCreatedDBObject(list[n], true);
                }
                transaction.Commit();
            }
            progressMeter_0.Stop();
        }
예제 #3
0
        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;
            }
        }