Example #1
0
 internal Class21(ConvexHull3d convexHull3d_0)
 {
     //System.ComponentModel.LicenseManager.Validate(typeof(Class21));
     //base..ctor();
     this.list_0 = new List <Class25>();
     this.list_1 = new List <Class13>();
     this.method_5(convexHull3d_0);
 }
Example #2
0
        public void LoadCommand()
        {
            Database arg_05_0 = HostApplicationServices.WorkingDatabase;
            Editor   editor   = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                //LicenseManager.CheckValid("FULL");
                ObjectId[]          objectIDs           = CommandLineQuerries.GetObjectIDs(CommandLineQuerries.EntityType.SOLID3D, "Select 3d solids", false);
                double              num                 = this.method_1(objectIDs);
                PromptDoubleOptions promptDoubleOptions = new PromptDoubleOptions("Maximum node spacing");
                promptDoubleOptions.DefaultValue = (num / 100.0);
                double   value    = editor.GetDouble(promptDoubleOptions).Value;
                string   text     = CommandLineQuerries.KeywordYesNo("Show generated nodes", "N", false, false);
                PointSet pointSet = this.method_0(objectIDs, value);
                editor.WriteMessage("\n" + pointSet.Count + " points generated on solids.");
                ConvexHull3d convexHull3d = new ConvexHull3d();
                convexHull3d.InitialPoints = pointSet;
                convexHull3d.ComputeHull();
                BoundingBox     boundingBox = convexHull3d.PrincipalAxesBoundingBox();
                List <Triangle> surface     = boundingBox.GetSurface();
                if (text.Trim().ToUpper() == "Y")
                {
                    DBManager.WriteListInDatabase <Point>(pointSet.ToList(), null, DBManager.EntityPropertiesAssignment.ByDialog, ObjectId.Null, ObjectId.Null);
                }
                DBManager.WriteListInDatabase <Triangle>(surface, null, DBManager.EntityPropertiesAssignment.ByDialog, ObjectId.Null, ObjectId.Null);
                editor.WriteMessage("\nPrincipal axes bounding box properties:");
                editor.WriteMessage("\n---------------------------------------");
                editor.WriteMessage("\nWidth              : " + boundingBox.Width.ToString(DBManager.GetFormatFromLUPREC()));
                editor.WriteMessage("\nLength             : " + boundingBox.Length.ToString(DBManager.GetFormatFromLUPREC()));
                editor.WriteMessage("\nHeight             : " + boundingBox.Height.ToString(DBManager.GetFormatFromLUPREC()));
                editor.WriteMessage("\nVolume             : " + boundingBox.Volume().ToString(DBManager.GetFormatFromLUPREC()));
                editor.WriteMessage("\nCenter             : " + boundingBox.CoordinateSystem.Origin.ToString());
                editor.WriteMessage("\nFirst basis vector : " + boundingBox.CoordinateSystem.BasisVector[0].ToString());
                editor.WriteMessage("\nSecond basis vector: " + boundingBox.CoordinateSystem.BasisVector[1].ToString());
                editor.WriteMessage("\nThird basis vector : " + boundingBox.CoordinateSystem.BasisVector[2].ToString());
            }
            catch (System.Exception ex)
            {
                editor.WriteMessage("\n" + ex.Message);
            }
        }
        public void ComputePrincipalAxisBoundingBox(ObjectId[] idArray)
        {
            Editor   editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database workingDatabase = HostApplicationServices.WorkingDatabase;

            DBManager.SetEpsilon();
            this.progressMeter_0 = new ProgressMeter();
            this.messageFilter_0 = new MessageFilter();
            System.Windows.Forms.Application.AddMessageFilter(this.messageFilter_0);
            this.int_0 = 0;
            try
            {
                using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                {
                    this.progressMeter_0.SetLimit(3 * idArray.Length);
                    if ((double)idArray.Length > 10000.0)
                    {
                        this.progressMeter_0.Start("Computing bounding box...");
                    }
                    BlockTable       blockTable       = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1);
                    BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1);
                    ObjectId         layerId          = DBManager.CurrentLayerId();
                    DBManager.CurrentLayerName();
                    PointSet pointSet = new PointSet();
                    for (int i = 0; i < idArray.Length; i++)
                    {
                        DBPoint dBPoint = (DBPoint)transaction.GetObject(idArray[i], (OpenMode)0, true);
                        Point   point   = new Point(dBPoint.Position.X, dBPoint.Position.Y, dBPoint.Position.Z);
                        pointSet.Add(point);
                        this.vmethod_0(null, null);
                    }
                    ConvexHull3d convexHull3d = new ConvexHull3d();
                    convexHull3d.PointInsertionHandler += new HullPointInsertionEventHandler(this.vmethod_0);
                    convexHull3d.InitialPoints          = pointSet;
                    convexHull3d.ComputeHull();
                    BoundingBox     boundingBox = convexHull3d.PrincipalAxesBoundingBox();
                    List <Triangle> surface     = boundingBox.GetSurface();
                    for (int j = 0; j < surface.Count; j++)
                    {
                        Point   vertex   = surface[j].Vertex1;
                        Point   vertex2  = surface[j].Vertex2;
                        Point   vertex3  = surface[j].Vertex3;
                        Point3d point3d  = new Point3d(vertex.X, vertex.Y, vertex.Z);
                        Point3d point3d2 = new Point3d(vertex2.X, vertex2.Y, vertex2.Z);
                        Point3d point3d3 = new Point3d(vertex3.X, vertex3.Y, vertex3.Z);
                        Face    face     = new Face(point3d, point3d2, point3d3, true, true, true, true);
                        face.LayerId = (layerId);
                        blockTableRecord.AppendEntity(face);
                        transaction.AddNewlyCreatedDBObject(face, true);
                    }
                    editor.WriteMessage("\nPrincipal axes bounding box properties:");
                    editor.WriteMessage("\n---------------------------------------");
                    editor.WriteMessage("\nWidth              : " + boundingBox.Width.ToString(DBManager.GetFormatFromLUPREC()));
                    editor.WriteMessage("\nLength             : " + boundingBox.Length.ToString(DBManager.GetFormatFromLUPREC()));
                    editor.WriteMessage("\nHeight             : " + boundingBox.Height.ToString(DBManager.GetFormatFromLUPREC()));
                    editor.WriteMessage("\nVolume             : " + boundingBox.Volume().ToString(DBManager.GetFormatFromLUPREC()));
                    editor.WriteMessage("\nCenter             : " + boundingBox.CoordinateSystem.Origin.ToString());
                    editor.WriteMessage("\nFirst basis vector : " + boundingBox.CoordinateSystem.BasisVector[0].ToString());
                    editor.WriteMessage("\nSecond basis vector: " + boundingBox.CoordinateSystem.BasisVector[1].ToString());
                    editor.WriteMessage("\nThird basis vector : " + boundingBox.CoordinateSystem.BasisVector[2].ToString());
                    transaction.Commit();
                }
                this.progressMeter_0.Stop();
            }
            catch (System.Exception ex)
            {
                this.progressMeter_0.Stop();
                throw;
            }
        }
Example #4
0
        public void Compute3dHull(ObjectId[] idArray)
        {
            Editor   editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database workingDatabase = HostApplicationServices.WorkingDatabase;

            DBManager.SetEpsilon();
            this.progressMeter_0 = new ProgressMeter();
            this.messageFilter_0 = new MessageFilter();
            System.Windows.Forms.Application.AddMessageFilter(this.messageFilter_0);
            this.int_0 = 0;
            try
            {
                using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                {
                    this.progressMeter_0.SetLimit(3 * idArray.Length);
                    if ((double)idArray.Length > 10000.0)
                    {
                        this.progressMeter_0.Start("Computing 3d hull...");
                    }
                    BlockTable       blockTable       = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)1);
                    BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1);
                    ObjectId         layerId          = DBManager.CurrentLayerId();
                    DBManager.CurrentLayerName();
                    PointSet pointSet = new PointSet();
                    for (int i = 0; i < idArray.Length; i++)
                    {
                        DBPoint dBPoint = (DBPoint)transaction.GetObject(idArray[i], (OpenMode)0, true);
                        Point   point   = new Point(dBPoint.Position.X, dBPoint.Position.Y, dBPoint.Position.Z);
                        pointSet.Add(point);
                        this.vmethod_0(null, null);
                    }
                    ConvexHull3d convexHull3d = new ConvexHull3d();
                    convexHull3d.PointInsertionHandler += new HullPointInsertionEventHandler(this.vmethod_0);
                    convexHull3d.InitialPoints          = pointSet;
                    convexHull3d.ComputeHull();
                    PointSet        vertices  = convexHull3d.Vertices;
                    List <Triangle> triangles = convexHull3d.Triangles;
                    for (int j = 0; j < triangles.Count; j++)
                    {
                        Point   vertex   = triangles[j].Vertex1;
                        Point   vertex2  = triangles[j].Vertex2;
                        Point   vertex3  = triangles[j].Vertex3;
                        Point3d point3d  = new Point3d(vertex.X, vertex.Y, vertex.Z);
                        Point3d point3d2 = new Point3d(vertex2.X, vertex2.Y, vertex2.Z);
                        Point3d point3d3 = new Point3d(vertex3.X, vertex3.Y, vertex3.Z);
                        Face    face     = new Face(point3d, point3d2, point3d3, true, true, true, true);
                        face.LayerId = (layerId);
                        blockTableRecord.AppendEntity(face);
                        transaction.AddNewlyCreatedDBObject(face, true);
                    }
                    editor.WriteMessage("\n3d convex hull properties:");
                    editor.WriteMessage("\n--------------------------");
                    editor.WriteMessage("\nNumber of vertices on hull: " + vertices.Count);
                    editor.WriteMessage("\nNumber of invalid vertices: " + convexHull3d.BadPoints.Count);
                    editor.WriteMessage("\nNumber of faces on hull   : " + triangles.Count);
                    editor.WriteMessage("\nNumber of degenerate faces: " + convexHull3d.NumberOfDegenerateTriangles);
                    editor.WriteMessage("\nHull surface area         : " + convexHull3d.Area().ToString(DBManager.GetFormatFromLUPREC()));
                    editor.WriteMessage("\nHull volume               : " + convexHull3d.Volume().ToString(DBManager.GetFormatFromLUPREC()));
                    editor.WriteMessage("\nCenter of mass            : " + convexHull3d.CenterOfMass().ToString());
                    transaction.Commit();
                }
                this.progressMeter_0.Stop();
            }
            catch (System.Exception ex)
            {
                this.progressMeter_0.Stop();
                throw;
            }
        }
Example #5
0
    internal void method_5(ConvexHull3d convexHull3d_0)
    {
        PointSet initialPoints = convexHull3d_0.InitialPoints;

        if (initialPoints == null)
        {
            throw new InvalidOperationException("Can not compute convex hull: no point set defined.");
        }
        if (initialPoints.Count < 4)
        {
            throw new ArgumentException("Can not compute 3d convex hull for less than four points.");
        }
        if (!Class20.bool_0)
        {
            Class20.smethod_0();
        }
        PointSet pointSet = initialPoints.DeepCopy();

        pointSet.RandomPermute();
        Point center = pointSet.Center;

        int[] array = new int[4];
        array[0] = 0;
        Point point = pointSet[array[0]];

        array[1] = 1;
        Point point2 = pointSet[array[1]];

        while (Math.Abs(Predicate.Orient2d_exact(point, point2, center)) < 1E-07 | point2 == point)
        {
            array[1]++;
            if (array[1] > pointSet.Count - 1)
            {
                throw new ArithmeticException("Failed compute 3d convex hull: need at least four non-coplanar points.");
            }
            point2 = pointSet[array[1]];
        }
        array[2] = 1;
        Point point3 = pointSet[array[2]];

        while (Predicate.Orient3d_exact(point, point2, point3, center) < 1E-06 | point3 == point | point3 == point2)
        {
            array[2]++;
            if (array[2] > pointSet.Count - 1)
            {
                throw new ArithmeticException("Failed compute 3d convex hull: need at least four non-coplanar points.");
            }
            point3 = pointSet[array[2]];
        }
        array[3] = 1;
        Point point4 = pointSet[array[3]];

        while (Predicate.Orient3d_exact(point, point2, point3, point4) < 1E-06 | point4 == point | point4 == point2 | point4 == point3)
        {
            array[3]++;
            if (array[3] > pointSet.Count - 1)
            {
                throw new ArithmeticException("Failed compute 3d convex hull: need at least four non-coplanar points.");
            }
            point4 = pointSet[array[3]];
        }
        List <int> list = new List <int>();

        list.AddRange(array);
        list.Sort();
        pointSet.RemoveAt(list[3]);
        pointSet.RemoveAt(list[2]);
        pointSet.RemoveAt(list[1]);
        pointSet.RemoveAt(list[0]);
        Class25 @class = new Class25(point);
        Class25 class2 = new Class25(point2);
        Class25 class3 = new Class25(point3);
        Class25 class4 = new Class25(point4);

        @class.method_5(true);
        class2.method_5(true);
        class3.method_5(true);
        class4.method_5(true);
        this.list_1.Add(new Class13(@class, class2, class3));
        this.list_1.Add(new Class13(@class, class4, class2));
        this.list_1.Add(new Class13(@class, class3, class4));
        this.list_1.Add(new Class13(class3, class2, class4));
        this.list_1[0].method_8()[0] = this.list_1[3];
        this.list_1[0].method_8()[1] = this.list_1[2];
        this.list_1[0].method_8()[2] = this.list_1[1];
        this.list_1[1].method_8()[0] = this.list_1[3];
        this.list_1[1].method_8()[1] = this.list_1[0];
        this.list_1[1].method_8()[2] = this.list_1[2];
        this.list_1[2].method_8()[0] = this.list_1[3];
        this.list_1[2].method_8()[1] = this.list_1[1];
        this.list_1[2].method_8()[2] = this.list_1[0];
        this.list_1[3].method_8()[0] = this.list_1[1];
        this.list_1[3].method_8()[1] = this.list_1[2];
        this.list_1[3].method_8()[2] = this.list_1[0];
        for (int i = 0; i < pointSet.Count; i++)
        {
            this.list_0.Add(new Class25(pointSet[i]));
        }
        this.list_0.Add(@class);
        this.list_0.Add(class2);
        this.list_0.Add(class3);
        this.list_0.Add(class4);
        for (int j = 0; j < this.list_0.Count; j++)
        {
            convexHull3d_0.vmethod_0(null, null);
            for (int k = 0; k < this.list_1.Count; k++)
            {
                if (this.list_1[k].method_15(this.list_0[j]))
                {
                    this.list_1[k].method_10().Add(this.list_0[j]);
                    this.list_0[j].method_2().Add(this.list_1[k]);
                }
            }
        }
    }