public override bool Run(FeatureContext context)
        {
            var points = new List <Vector3>();

            points.Add(new Vector3(0, 0, 0));
            points.Add(new Vector3(50, 0, 0));
            points.Add(new Vector3(100, 0, 0));

            points.Add(new Vector3(0, 50, 0));
            points.Add(new Vector3(50, 50, 5));
            points.Add(new Vector3(100, 50, -5));

            points.Add(new Vector3(0, 150, 5));
            points.Add(new Vector3(50, 150, -5));
            points.Add(new Vector3(100, 150, 0));

            TopoShape face = GlobalInstance.BrepTools.MakeSurfaceFromPoints(points, 3, 3);

            context.ShowGeometry(face);

            TopoShapeProperty property = new TopoShapeProperty();

            property.SetShape(face);

            MessageBox.Show(String.Format("Area: {0}", property.SurfaceArea()));

            return(true);
        }
Example #2
0
        public Solid(TopoShape solid)
        {
            BoundingBox = solid.GetBBox();

            var faces = GlobalInstance.TopoExplor.ExplorFaces(solid);
            TopoShapeProperty prop           = new TopoShapeProperty();
            List <FaceInfo>   dictFaceByArea = new List <FaceInfo>();

            for (int ii = 0; ii < faces.Size(); ++ii)
            {
                var face = faces.GetAt(ii);
                prop.SetShape(face);
                double area = prop.SurfaceArea();

                var faceInfo = new FaceInfo(face, ii, area);
                dictFaceByArea.Add(faceInfo);

                Faces.Add(ii, faceInfo);
            }
            dictFaceByArea.Sort((a, b) =>
            {
                return((int)((b.Area - a.Area) * 1000));
            });

            var baseFace = dictFaceByArea[0];

            foreach (var item in baseFace.Edges)
            {
                EdgeGroup eg = new EdgeGroup(item.Value);
                EdgeGroups.Add(eg);
            }

            for (int ii = 2; ii < dictFaceByArea.Count; ++ii)
            {
                var faceInfo = dictFaceByArea[ii];
                if (AddLongFace(faceInfo))
                {
                    continue;
                }

                AddSideFace(faceInfo);
            }
        }
Example #3
0
        private void surfaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LineStyle lineStyle = new LineStyle();

            lineStyle.SetLineWidth(0.5f);
            lineStyle.SetColor(ColorValue.RED);

            Vector3List points = new Vector3List();

            points.Add(new Vector3(0, 0, 0));
            points.Add(new Vector3(50, 0, 0));
            points.Add(new Vector3(100, 0, 0));

            points.Add(new Vector3(0, 50, 0));
            points.Add(new Vector3(50, 50, 5));
            points.Add(new Vector3(100, 50, -5));

            points.Add(new Vector3(0, 150, 5));
            points.Add(new Vector3(50, 150, -5));
            points.Add(new Vector3(100, 150, 0));

            TopoShape face = GlobalInstance.BrepTools.MakeSurfaceFromPoints(points, 3, 3);

            renderView.ShowGeometry(face, ++shapeId);

            GeomeSurface surface = new GeomeSurface();

            surface.Initialize(face);
            float ufirst = surface.FirstUParameter();
            float uLarst = surface.LastUParameter();
            float vfirst = surface.FirstVParameter();
            float vLast  = surface.LastVParameter();

            float ustep = (uLarst - ufirst) * 0.1f;
            float vstep = (vLast - vfirst) * 0.1f;

            for (float ii = ufirst; ii <= uLarst; ii += ustep)
            {
                for (float jj = vfirst; jj <= vLast; jj += vstep)
                {
                    Vector3List data = surface.D1(ii, jj);

                    Vector3 pos  = data.Get(0);
                    Vector3 dirU = data.Get(1);
                    Vector3 dirV = data.Get(2);
                    Vector3 dir  = dirV.CrossProduct(dirU);
                    dir.Normalize();
                    {
                        TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir * 10.0f);
                        SceneNode node = renderView.ShowGeometry(line, ++shapeId);

                        node.SetLineStyle(lineStyle);
                    }
                }
            }

            TopoShapeProperty property = new TopoShapeProperty();

            property.SetShape(face);

            float area = property.SurfaceArea();

            TextNode text = new TextNode();

            text.SetText(String.Format("Surface Area: {0}", area));
            text.SetPosition(new Vector3(100, 100, 0));
            renderView.SceneManager.ClearNodes2d();
            renderView.SceneManager.AddNode2d(text);

            renderView.RequestDraw();
        }
Example #4
0
        private void surfaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Platform.LineStyle lineStyle = new Platform.LineStyle();
            lineStyle.SetLineWidth(0.5f);
            lineStyle.SetColor(ColorValue.RED);

            var points = new System.Collections.Generic.List<Vector3>();
            points.Add(new Vector3(0, 0, 0));
            points.Add(new Vector3(50, 0, 0));
            points.Add(new Vector3(100, 0, 0));

            points.Add(new Vector3(0, 50, 0));
            points.Add(new Vector3(50, 50, 5));
            points.Add(new Vector3(100, 50, -5));

            points.Add(new Vector3(0, 150, 5));
            points.Add(new Vector3(50, 150, -5));
            points.Add(new Vector3(100, 150, 0));

            TopoShape face = GlobalInstance.BrepTools.MakeSurfaceFromPoints(points, 3, 3);

            renderView.ShowGeometry(face, 101);

            GeomSurface surface = new GeomSurface();
            surface.Initialize(face);
            float ufirst = surface.FirstUParameter();
            float uLarst = surface.LastUParameter();
            float vfirst = surface.FirstVParameter();
            float vLast = surface.LastVParameter();

            float ustep = (uLarst - ufirst) * 0.1f;
            float vstep = (vLast - vfirst) * 0.1f;
            for(float ii=ufirst; ii<=uLarst; ii+= ustep)
                for (float jj = vfirst; jj <= vLast; jj += vstep)
                {
                    var data = surface.D1(ii, jj);

                    Vector3 pos = data[0];
                    Vector3 dirU = data[1];
                    Vector3 dirV = data[2];
                    Vector3 dir = dirV.CrossProduct(dirU);
                    dir.Normalize();
                    {
                        Platform.TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir*10.0f);
                        Platform.SceneNode node = renderView.ShowGeometry(line, 101);

                        node.SetLineStyle(lineStyle);
                    }
                }

            TopoShapeProperty property = new TopoShapeProperty();
            property.SetShape(face);

            float area = property.SurfaceArea();

            TextNode text = new TextNode();
            text.SetText(String.Format("Surface Area: {0}", area));
            text.SetPosition(new Vector3(100, 100, 0));
            renderView.SceneManager.ClearNodes2d();
            renderView.SceneManager.AddNode2d(text);

            renderView.RequestDraw();
        }
Example #5
0
        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);
        }