public override bool Run(FeatureContext context)
        {
            // Split box with two spheres.
            TopoShape box     = GlobalInstance.BrepTools.MakeBox(Vector3.ZERO, Vector3.UNIT_Z, new Vector3(150f, 150f, 150f));
            TopoShape sphere  = GlobalInstance.BrepTools.MakeSphere(Vector3.ZERO, 100f);
            TopoShape sphere2 = GlobalInstance.BrepTools.MakeSphere(Vector3.ZERO, 50f);

            TopoShapeGroup tools = new TopoShapeGroup();

            tools.Add(sphere);
            tools.Add(sphere2);
            TopoShape split = GlobalInstance.BrepTools.MakeSplit(box, tools);

            // Display the results with customized face styles.
            TopoExplor     expo   = new TopoExplor();
            TopoShapeGroup bodies = expo.ExplorSolids(split);


            Random random = new Random();

            for (int ii = 0; ii < bodies.Size(); ++ii)
            {
                SceneNode node = context.ShowGeometry(bodies.GetTopoShape(ii));
                FaceStyle fs   = new FaceStyle();
                fs.SetColor(new ColorValue((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 0.5f));
                fs.SetTransparent(true);
                node.SetFaceStyle(fs);
            }

            return(true);
        }
Exemple #2
0
        public override bool Run(FeatureContext context)
        {
            context.RenderView.SetDisplayMode((int)(EnumDisplayStyle.DS_ShadeEdge | EnumDisplayStyle.DS_Vertex));
            // construct a wire;
            TopoShape TS = GlobalInstance.BrepTools.MakeEllipse(Vector3.ZERO, 100D, 50D, Vector3.UNIT_Z);

            context.ShowGeometry(TS);

            TopoShape line = GlobalInstance.BrepTools.MakeLine(new Vector3(0, -200, 0), new Vector3(200, 200, 0));

            context.ShowGeometry(line);

            IntersectionLineCurve intersector = new IntersectionLineCurve();

            TopoExplor     tp = new TopoExplor();
            TopoShapeGroup tg = tp.ExplorEdges(TS);

            intersector.SetCurve(tg.GetAt(0));

            if (intersector.Perform(line))
            {
                int nCount = intersector.GetPointCount();

                List <Vector3> LV = new List <Vector3>();

                for (int ii = 0; ii < nCount; ++ii)
                {
                    Vector3 pt = intersector.GetPoint(ii + 1);
                    LV.Add(pt);

                    context.ShowGeometry(GlobalInstance.BrepTools.MakePoint(pt));
                }


                MessageBox.Show(String.Format("{0}", nCount));
            }



            return(true);
        }
Exemple #3
0
        public override bool Run(FeatureContext context)
        {
            TopoShape arc  = GlobalInstance.BrepTools.MakeArc(new Vector3(-100, 0, 0), new Vector3(100, 0, 0), Vector3.ZERO, Vector3.UNIT_Z);
            TopoShape line = GlobalInstance.BrepTools.MakeLine(new Vector3(100, 0, 0), new Vector3(100, 200, 0));

            TopoShapeGroup group = new TopoShapeGroup();

            group.Add(arc);
            group.Add(line);

            TopoShape wire = GlobalInstance.BrepTools.MakeSpline(group);

            TopoShape splitter1 = GlobalInstance.BrepTools.MakePoint(new Vector3(0, -100, 0));
            TopoShape splitter2 = GlobalInstance.BrepTools.MakePoint(new Vector3(100, 100, 0));

            TopoShapeGroup spliterGroup = new TopoShapeGroup();

            spliterGroup.Add(splitter1);
            spliterGroup.Add(splitter2);
            TopoShape result = GlobalInstance.BrepTools.MakeSplit(wire, spliterGroup);

            TopoExplor     exp   = new TopoExplor();
            TopoShapeGroup itmes = exp.ExplorSubShapes(result);

            for (int ii = 0; ii < itmes.Size(); ++ii)
            {
                SceneNode node = context.ShowGeometry(itmes.GetAt(ii));
                LineStyle ls   = new LineStyle();
                ls.SetLineWidth(3.0f);
                ls.SetColor((ii + 1) * 50, ii * 20, ii * 10);
                node.SetLineStyle(ls);
            }


            return(true);
        }
Exemple #4
0
        private void solidToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "STL (*.stl)|*.stl|IGES (*.igs;*.iges)|*.igs;*.iges|STEP (*.stp;*.step)|*.stp;*.step|BREP (*.brep)|*.brep|All Files(*.*)|*.*";

            if (DialogResult.OK != dlg.ShowDialog())
                return;


            TopoShape shape = GlobalInstance.BrepTools.LoadFile(new AnyCAD.Platform.Path(dlg.FileName));
            renderView.ShowGeometry(shape, 100);

            //TopoExplor explor = new TopoExplor();
            //TopoShapeGroup solids = explor.ExplorSolids(shape);
            //float vol = 0;
            //for(int ii=0; ii<solids.Size(); ++ii)
            //{
            //    TopoShapeProperty property = new TopoShapeProperty();
            //    property.SetShape(solids.GetAt(ii));
            //    vol += property.SolidVolume();
            //}
            TopoExplor explor = new TopoExplor();
            TopoShapeGroup faces = explor.ExplorFaces(shape);
            TopoShape solid = GlobalInstance.BrepTools.MakeSolid(faces);
            TopoShapeProperty property = new TopoShapeProperty();
            property.SetShape(solid);
            float vol = property.SolidVolume();

            MessageBox.Show(String.Format("{0}", vol));
        }
Exemple #5
0
        private void splitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            TopoShape box = GlobalInstance.BrepTools.MakeBox(Vector3.ZERO, Vector3.UNIT_Z, new Vector3(150f, 150f, 150f));
            TopoShape sphere = GlobalInstance.BrepTools.MakeSphere(Vector3.ZERO, 100f);
            TopoShape sphere2 = GlobalInstance.BrepTools.MakeSphere(Vector3.ZERO, 50f);

            TopoShapeGroup tools = new TopoShapeGroup();
            tools.Add(sphere);
            tools.Add(sphere2);
            TopoShape split = GlobalInstance.BrepTools.MakeSplit(box, tools);


            TopoExplor expo = new TopoExplor();
            TopoShapeGroup faces = expo.ExplorFaces(split);
            TopoShapeGroup bodies = expo.ExplorSolids(split);


            Random random = new Random();
            for (int ii = 0; ii < bodies.Size(); ++ii)
            {
                SceneNode node = renderView.ShowGeometry(bodies.GetTopoShape(ii), ++shapeId);
                FaceStyle fs = new FaceStyle();
                fs.SetColor(new ColorValue((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 0.5f));
                fs.SetTransparent(true);
                node.SetFaceStyle(fs);
            }


            renderView.RequestDraw();

            MessageBox.Show(String.Format("Face: {0} Solid: {1}", faces.Size(), bodies.Size()));

        }
        private void TransOnMax(TopoShape shape)
        {
            double         areaM  = 0;
            Vector3        dirN   = new Vector3();
            Vector3        pos    = new Vector3();
            TopoExplor     topo   = new TopoExplor();
            TopoShapeGroup group2 = topo.ExplorFaces(shape);

            for (int i = 0; i < group2.Size(); i++)
            {
                TopoShape face = group2.GetTopoShape(i);

                #region 计算面积
                TopoShapeProperty property = new TopoShapeProperty();
                property.SetShape(face);
                Console.WriteLine("Face {0}:\n\tArea {1}\n\tOrientation {2}", i, property.SurfaceArea(), face.GetOrientation());
                #endregion
                #region 计算法向量
                GeomSurface surface = new GeomSurface();
                surface.Initialize(face);
                //参数域UV范围
                double uFirst = surface.FirstUParameter();
                double uLast  = surface.LastUParameter();
                double vFirst = surface.FirstVParameter();
                double vLast  = surface.LastVParameter();
                //取中点
                double umid = uFirst + (uLast - uFirst) * 0.5f;
                double vmid = vFirst + (vLast - vFirst) * 0.5f;
                //计算法向量
                var     data = surface.D1(umid, vmid);
                Vector3 dirU = data[1];
                Vector3 dirV = data[2];
                Vector3 dir  = dirV.CrossProduct(dirU);
                dir.Normalize();
                Console.WriteLine("\tDir {0}", dir);
                #endregion

                #region 取最大的面
                if (property.SurfaceArea() > areaM)
                {
                    areaM = property.SurfaceArea();
                    pos   = data[0];
                    Console.WriteLine(data[0]);
                    if (face.GetOrientation() == EnumShapeOrientation.ShapeOrientation_REVERSED)
                    {
                        dirN = dir * -1;
                    }
                    else
                    {
                        dirN = dir;
                    }
                }
                #endregion
            }

            #region 坐标变换
            //Translation
            shape = GlobalInstance.BrepTools.Translate(shape, -pos);
            //Rotation
            Vector3 dirZ = new Vector3(0, 0, -1);
            shape = GlobalInstance.BrepTools.Rotation(shape, dirN.CrossProduct(dirZ), dirN.AngleBetween(dirZ));
            #endregion

            if (shape != null)
            {
                topoShape = shape;
                renderView.ClearScene();
                renderView.ShowGeometry(shape, shapeId);
            }
            renderView.FitAll();
            renderView.RequestDraw(EnumRenderHint.RH_LoadScene);
        }