Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }