Exemplo n.º 1
0
        GroupSceneNode CreateFrames(double width, double height, double deep, double radius)
        {
            var baseSketch = CreateSketch(radius, deep);

            //TopLeft
            var s11 = Project(baseSketch, new GPnt(0, 0, height), new GDir(-1, 0, -1), GP.DZ());
            //BottomLeft
            var s20 = Project(baseSketch, GP.Origin(), new GDir(-1, 0, 1), GP.DZ());
            //BottomRight
            var s12 = Project(s20, new GPnt(width, 0, 0), new GDir(1, 0, 1), GP.DX());
            //TopRight
            var s21 = Project(s11, new GPnt(width, 0, height), new GDir(-1, 0, 1), GP.DX());

            var frame1 = FeatureTool.Loft(s11, s20, false);
            var frame2 = FeatureTool.Loft(s20, s12, false);
            var frame3 = FeatureTool.Loft(s12, s21, false);
            var frame4 = FeatureTool.Loft(s21, s11, false);

            var frameMaterial = MeshStandardMaterial.Create("window-frame");

            frameMaterial.SetColor(Vector3.LightGray);
            frameMaterial.SetMetalness(0.5f);
            frameMaterial.SetFaceSide(EnumFaceSide.DoubleSide);

            var group = new GroupSceneNode();

            group.AddNode(BrepSceneNode.Create(frame1, frameMaterial, null));
            group.AddNode(BrepSceneNode.Create(frame2, frameMaterial, null));
            group.AddNode(BrepSceneNode.Create(frame3, frameMaterial, null));
            group.AddNode(BrepSceneNode.Create(frame4, frameMaterial, null));

            return(group);
        }
        public override void Run(RenderControl render)
        {
            var sketch = SketchBuilder.MakeEllipse(GP.Origin(), 5, 3, GP.DX(), GP.DZ());

            // 1. Sweep
            {
                GPntList points = new GPntList {
                    GP.Origin(), new GPnt(20, 10, 30), new GPnt(50, 50, 50),
                };
                var path = SketchBuilder.MakeBSpline(points);
                render.ShowShape(path, Vector3.Green);

                var feature = FeatureTool.Sweep(sketch, path, EnumGeomFillTrihedron.ConstantNormal);
                render.ShowShape(feature, Vector3.Blue);
            }

            // 2. Revol
            {
                var feature = FeatureTool.Revol(sketch, new GAx1(new GPnt(-20, 0, 0), GP.DY()), 90);

                render.ShowShape(feature, Vector3.Green);
            }
            // 3. Loft
            {
                var baseWire = SketchBuilder.MakeRectangle(new GAx2(new GPnt(50, -50, 0), GP.DZ()), 20, 20, 5, false);
                var topWire  = SketchBuilder.MakeCircle(new GPnt(60, -40, 40), 5, GP.DZ());

                var loft = FeatureTool.Loft(baseWire, topWire, true);
                render.ShowShape(loft, Vector3.Red);
            }
        }
        public override void Run(RenderControl render)
        {
            var baseSketch = SketchBuilder.MakeRectangle(GP.XOY(), 10, 20, 2, false);

            // project to plane
            var topSketch = ProjectionTool.ProjectOnPlane(baseSketch, new GPnt(0, 0, 30), new GDir(0, -0.5, 0.5), GP.DZ());

            // make loft
            var shape = FeatureTool.Loft(baseSketch, topSketch, true);

            render.ShowShape(shape, ColorTable.Green);
        }
Exemplo n.º 4
0
        public override void Run(RenderControl render)
        {
            TopoShapeList tg     = new TopoShapeList();
            GPntList      points = new GPntList();

            using (var sr = new StreamReader(GetResourcePath("data/Stage4_Rotor4_Profile.curve")))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.StartsWith("# Profile"))
                    {
                        if (points.Count > 0)
                        {
                            var temp2 = SketchBuilder.MakeBSpline(points);
                            if (temp2 != null)
                            {
                                tg.Add(temp2);
                            }
                        }

                        points = new GPntList();
                    }
                    else
                    {
                        var temp = line.Split('\t');
                        points.Add(new GPnt(double.Parse(temp[0]), double.Parse(temp[1]), double.Parse(temp[2])));
                    }
                }
            }


            var temp1 = FeatureTool.Loft(tg, true, true);

            render.ShowShape(temp1, ColorTable.Hex(0xFF0000));
        }
Exemplo n.º 5
0
        public override void Run(RenderControl render)
        {
            //1. Create Shape
            TopoShapeList tg     = new TopoShapeList();
            GPntList      points = new GPntList();

            using (var sr = new StreamReader(GetResourcePath("data/Stage4_Rotor4_Profile.curve")))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.StartsWith("# Profile"))
                    {
                        if (points.Count > 0)
                        {
                            var temp2 = SketchBuilder.MakeBSpline(points);
                            if (temp2 != null)
                            {
                                tg.Add(temp2);
                            }
                        }

                        points = new GPntList();
                    }
                    else
                    {
                        var temp = line.Split('\t');
                        points.Add(new GPnt(double.Parse(temp[0]), double.Parse(temp[1]), double.Parse(temp[2])));
                    }
                }
            }


            var shape = FeatureTool.Loft(tg, true, true);

            //2. Compute Curvature
            var material = BasicMaterial.Create("vertex-color");

            material.SetVertexColors(true);
            material.SetFaceSide(EnumFaceSide.DoubleSide);

            var bs = new BufferShape(shape, material, null, 0.01f);

            bs.Build();

            ColorLookupTable clt = new ColorLookupTable();

            clt.SetColorMap(ColorMapKeyword.Create(EnumSystemColorMap.Rainbow));

            float scale = 100;

            clt.SetMinValue(-0.2f * scale);
            clt.SetMaxValue(scale);

            for (uint ii = 0; ii < bs.GetFaceCount(); ++ii)
            {
                var sc = new SurfaceCurvature(bs);
                if (sc.Compute(ii, EnumCurvatureType.MeanCurvature))
                {
                    Console.WriteLine("{0}, {1}", sc.GetMinValue(), sc.GetMaxValue());
                    var colorBuffer = sc.ComputeColors(clt, scale);
                    bs.SetVertexColors(ii, colorBuffer);
                }
            }

            // 3. Show it!
            var node = new BrepSceneNode(bs);

            render.ShowSceneNode(node);
        }
        public override void Run(RenderControl render)
        {
            string filepathp = GetResourcePath(@"data\blade_p.dat");             // p侧字符型数据

            string[] data_p    = File.ReadAllLines(filepathp, Encoding.Default); // 1行    2401列,
            string   filepaths = GetResourcePath(@"data\blade_s.dat");           // s侧字符型数据

            string[] data_s = File.ReadAllLines(filepaths, Encoding.Default);
            //
            // p侧的曲线
            double[,] curvee = new double[(data_p.GetUpperBound(data_p.Rank - 1) + 1), 3]; //建立数组,n行3列,
            for (int i = 0; i < (data_p.GetUpperBound(data_p.Rank - 1) + 1); i++)          //
            {
                data_p[i].Split();
                string[] split = data_p[i].Split(new Char[] { ' ' });
                curvee[i, 0] = double.Parse(split[0]);
                curvee[i, 1] = double.Parse(split[1]);
                curvee[i, 2] = double.Parse(split[2]);
            }
            //
            // s侧的曲线,
            double[,] curvee1 = new double[(data_p.GetUpperBound(data_p.Rank - 1) + 1), 3]; //建立数组,n行3列,
            for (int i = 0; i < (data_p.GetUpperBound(data_p.Rank - 1) + 1); i++)           //
            {
                data_s[i].Split();
                string[] split = data_s[i].Split(new Char[] { ' ' });
                curvee1[i, 0] = double.Parse(split[0]);
                curvee1[i, 1] = double.Parse(split[1]);
                curvee1[i, 2] = double.Parse(split[2]);
            }
            int n_jie    = (int)curvee1[0, 1];          // 截面数
            int n_points = (int)curvee1[0, 0];          // 点数
            // topolist
            TopoShapeList spline = new TopoShapeList(); //进行拓扑list的生成,

            for (int nn = 0; nn < n_jie; nn++)          // 循环截面数,
            {
                //int nn = 0;
                GPntList points = new GPntList();
                // s侧
                for (int mm = nn * n_points + 1; mm < (nn + 1) * n_points; mm++)     // 循环截面所对应的点数范围,
                {
                    GPnt P0 = new GPnt(curvee[mm, 0], curvee[mm, 1], curvee[mm, 2]); //   需要进行添加的点,
                    points.Add(P0);
                }
                // p侧
                for (int mm = (nn + 1) * n_points; mm > nn * n_points + 1; mm--)        // 循环截面所对应的点数范围,
                {
                    GPnt P0 = new GPnt(curvee1[mm, 0], curvee1[mm, 1], curvee1[mm, 2]); //   需要进行添加的点,
                    points.Add(P0);
                }
                // var quxian = SketchBuilder.MakePolygon(points, true);  //生成拓扑,
                var quxian = SketchBuilder.MakeBSpline(points, true);
                //mRenderView.ShowShape(quxian, Vector3.Red);
                spline.Add(quxian);
            }
            var shape = FeatureTool.Loft(spline, true, false);

            //创建一个体进行布尔运算
            GPntList points_shroud = new GPntList();
            GPnt     P10           = new GPnt(170, 0, 0);
            GPnt     P11           = new GPnt(170, 0, 200);
            GPnt     P12           = new GPnt(250, 0, 200);
            GPnt     P13           = new GPnt(250, 0, 0);

            points_shroud.Add(P10);
            points_shroud.Add(P11);
            points_shroud.Add(P12);
            points_shroud.Add(P13);
            var quxian1 = SketchBuilder.MakePolygon(points_shroud, true);
            var face    = SketchBuilder.MakePlanarFace(quxian1);
            var feature = FeatureTool.Revol(face, new GAx1(new GPnt(0, 0, 0), GP.DZ()), 0);

            var cut = BooleanTool.Cut(shape, feature);   // 求差  保留前面的一个

            if (cut != null)
            {
                render.ShowShape(cut, Vector3.Green);
            }

            //var cut2 = BooleanTool.Cut(feature, shape);
            //if (cut2 != null)
            //    render.ShowShape(cut2, Vector3.Blue);
        }