Example #1
0
        public override void Run(RenderControl render)
        {
            if (!ReadData())
            {
                return;
            }

            var matplot = Matplot.Create("MyMatlab 2020");

            var xRange = new PlotRange(mMinX, mMaxX - 1, 1);
            var yRange = new PlotRange(mMinY, mMaxY - 1, 1);

            matplot.AddSurface(xRange, yRange, (idxU, idxV, u, v) =>
            {
                double x = u;
                double y = v;
                double z = mData[idxU + 1][idxV + 1];

                return(new GPnt(x, y, z));
            });

            var node = matplot.Build(ColorMapKeyword.Create(EnumSystemColorMap.Cooltowarm));

            node.SetPickable(false);

            var pw = new PaletteWidget();

            pw.Update(matplot.GetColorTable());

            render.ShowSceneNode(pw);
            render.ShowSceneNode(node);

            var material = MeshPhongMaterial.Create("font-x");

            material.SetColor(Vector3.Red);
            var shape = FontManager.Instance().CreateMesh("Create a better world!");

            shape.SetMaterial(material);
            var text = new TextSceneNode(shape, 24, true);
            //var text = new TextSceneNode("Wow", 24, new Vector3(1, 1, 0), Vector3.Red, false);
            var tag = TagNode2D.Create(text, new Vector3(15), new Vector3(0));

            render.ShowSceneNode(tag);
        }
Example #2
0
        bool ReadData()
        {
            if (mPositions != null)
            {
                return(true);
            }

            string fileName = GetResourcePath("pressure.json");

            using (StreamReader reader = File.OpenText(fileName))
            {
                JObject obj           = JObject.Parse(reader.ReadToEnd());
                var     postionsToken = obj["data"]["attributes"]["position"]["array"].Children().ToList();
                mPositions = new Float32Buffer(0);

                mPositions.Reserve((uint)postionsToken.Count);
                foreach (var token in postionsToken)
                {
                    float val = token.ToObject <float>();
                    mPositions.Append(val);
                }

                mColorTable = new ColorLookupTable();
                mColorTable.SetMaxValue(2000);
                mColorTable.SetColorMap(ColorMapKeyword.Create(EnumSystemColorMap.Rainbow));
                mColors = new Float32Buffer((uint)postionsToken.Count);

                var pressureToken = obj["data"]["attributes"]["pressure"]["array"].Children().ToList();
                mPressures = new Float32Buffer(0);
                mPressures.Reserve((uint)pressureToken.Count);
                uint idx = 0;
                foreach (var token in pressureToken)
                {
                    float val = token.ToObject <float>();
                    mPressures.Append(val);

                    var clr = mColorTable.GetColor(val);
                    mColors.SetValue(idx * 3, clr);
                    ++idx;
                }
            }

            return(true);
        }
        public override void Run(RenderControl render)
        {
            var matplot = Matplot.Create("MyMatlab");

            var xRange = new PlotRange(0, 3.14f * 2, 0.1f);
            var yRange = new PlotRange(0, 3.14f * 2, 0.1f);

            matplot.AddSurface(xRange, yRange, (idxU, idxV, u, v) =>
            {
                double x = u;
                double y = v;
                double z = Math.Sin(u) + Math.Cos(v);

                return(new GPnt(x, y, z));
            });

            var node = matplot.Build(ColorMapKeyword.Create(EnumSystemColorMap.Rainbow));

            node.SetPickable(false);
            render.ShowSceneNode(node);
        }
Example #4
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);
        }