Exemplo n.º 1
0
        protected override void OnContentRendered(EventArgs e)
        {
            // adjusts viewport grid size and step
            model1.GetGrid().Min  = new Point3D(-5, -5);
            model1.GetGrid().Max  = new Point3D(+5, +5);
            model1.GetGrid().Step = .5;

            // declare the function to be used to evaluate the 3D scalar field
            ScalarField3D func = new ScalarField3D(myScalarField);

            // initialize marching cube algorithm
            mc = new MarchingCubes(new Point3D(0, -2.5, 0), 50, .1f, 25, .1f, 25, .1f, func);

            mc.IsoLevel = trackBar1.Value;

            mc.DoWork();

            // iso surface generation
            Mesh isoSurf = mc.Result;

            // adds the surface to the entities collection with Magenta color
            model1.Entities.Add(isoSurf, System.Drawing.Color.Magenta);

            // updates the iso level label
            isoLevelLabel.Content = "Iso level = " + mc.IsoLevel;

            // sets trimetric view
            model1.SetView(viewType.Trimetric);

            // fits the model in the viewport
            model1.ZoomFit();

            // refresh the viewport
            model1.Invalidate();

            base.OnContentRendered(e);
        }
Exemplo n.º 2
0
        private void TestMC()
        {
            eyeshot.GetGrid().Visible = true;

            eyeshot.GetGrid().Min = new Point3D(-5, -5);

            eyeshot.GetGrid().Max = new Point3D(+5, +5);

            eyeshot.GetGrid().Step = .5;

            ScalarField3D func = new ScalarField3D(ScalarFieldFunc);

            double resolution = 0.5;

            int span = 100;

            MarchingCubes mc = new MarchingCubes(new Point3D(-5, -5, -5), span, resolution, span, resolution, span, resolution, func);

            mc.IsoLevel = 4;

            eyeshot.DoWork(mc);

            Mesh res = mc.Result;

            res.FlipNormal();

            Mesh sphere = Mesh.CreateSphere(Math.Sqrt(mc.IsoLevel), 16, 32);

            // eyeshot.Entities.Add(sphere, 0, Color.FromArgb(170, Color.Blue));

            eyeshot.Entities.Add(res, 0, Color.FromArgb(170, Color.Red));

            eyeshot.Invalidate();

            eyeshot.ZoomFit();
        }