Exemple #1
0
        void Apply(SurfacePlotModel model)
        {
            var nx      = model.Nx;
            var ny      = model.Ny;
            var surface = new UniformSurfaceChart3D();

            _3dChart = surface;
            _3dChart.SetDataNo(nx * ny);
            surface.SetGrid(nx, ny);
            _wireframes.Thickness = model.Data.Thickness;
            _wireframes.Color     = model.Data.Color.Convert();

            var x      = model.Data.Xs;
            var y      = model.Data.Ys;
            var z      = model.Data.Zs;
            var length = x.Length;

            for (var i = 0; i < length; i++)
            {
                _3dChart[i] = new Vertex3D
                {
                    X = (Single)x[i],
                    Y = (Single)y[i],
                    Z = (Single)z[i]
                };
            }

            SetView(model.XAxis, model.YAxis, model.ZAxis);
            SetColors(model.ZAxis, model.Colors);

            var meshs        = ((UniformSurfaceChart3D)_3dChart).GetMeshes();
            var backMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.Gray));

            _model3d.UpdateModel(meshs, backMaterial);
            Project(model.XAxis, model.YAxis, model.ZAxis);
            TransformChart();

            if (model.IsWireframeShown)
            {
                _wireframes.MakeWireframe(_model3d.Content);
            }
            else
            {
                _wireframes.Points.Clear();
            }

            if (!model.IsSurfaceShown)
            {
                MainViewport.Children.Remove(_model3d);
            }
            else if (!MainViewport.Children.Contains(_model3d))
            {
                MainViewport.Children.Add(_model3d);
            }

            if (IsAxisShown)
            {
                ShowAxis();
            }
        }
Exemple #2
0
        void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            if (coeffWidth > 2)
            {
                coeffWidth = 0.1;
            }

            this.viewPort.Children.Remove(curveModel);
            this.viewPort.Children.Remove(pntsModel);
            this.viewPort.Children.Remove(wireframe);


            DataGenerator gen = new DataGenerator();

            coeffWidth         += 0.1;
            gen.MouthWidthcoeff = coeffWidth;

            //if (!dicPoints.ContainsKey(gen.MouthWidthcoeff))
            //    dicPoints.Add(gen.MouthWidthcoeff, gen.GenerateData(Convert.ToDouble(this.textBox1.Text)));

            Surface3D curve3D = new Surface3D();

            Data = gen.GenerateData(Convert.ToInt32(this.textBox1.Text));
            AutoAdjustCoordinate();

            curveModel = curve3D.CreateSurfaceModel(Data);

            pntsModel = curve3D.CreateSurfacePoints(Data);

            if (!showPoints)
            {
                this.viewPort.Children.Add(curveModel);
                wireframe.MakeWireframe(curveModel.Content);
                this.viewPort.Children.Add(wireframe);
                wireframe.OnRender(null, null);
            }
            if (showPoints)
            {
                this.viewPort.Children.Add(pntsModel);
            }



            this.textBlock1.Text = this.watch.ElapsedMilliseconds.ToString();
            this.watch.Reset();
            this.watch.Start();
        }
Exemple #3
0
        void ShowAxis()
        {
            var geo  = new GeometryModel3D();
            var cube = new MeshGeometry3D();
            var xmin = _3dChart.XMin();
            var xmax = _3dChart.XMax();
            var ymin = _3dChart.YMin();
            var ymax = _3dChart.YMax();
            var zmin = _3dChart.ZMin();
            var zmax = _3dChart.ZMax();

            var p1 = new Point3D(xmin, ymin, zmin);
            var p2 = new Point3D(xmax, ymin, zmin);
            var p5 = new Point3D(xmax, ymax, zmin);
            var p3 = new Point3D(xmin, ymax, zmin);

            var p4 = new Point3D(xmin, ymin, zmax);
            var p6 = new Point3D(xmax, ymin, zmax);
            var p8 = new Point3D(xmin, ymax, zmax);
            var p7 = new Point3D(xmax, ymax, zmax);

            cube.Positions.Add(p1); //0 - 0 0 0
            cube.Positions.Add(p2); //1 - 1 0 0
            cube.Positions.Add(p3); //2 - 0 1 0
            cube.Positions.Add(p5); //3 - 1 1 0

            cube.Positions.Add(p4); //4 - 0 0 1
            cube.Positions.Add(p6); //5 - 1 0 1
            cube.Positions.Add(p8); //6 - 0 1 1
            cube.Positions.Add(p7); //7 - 1 1 1

            var xh = _3dChart.XRange() * 0.5;
            var yh = _3dChart.YRange() * 0.5;
            var zh = _3dChart.ZRange() * 0.5;

            var pc1 = new Point3D(xmin, ymin, zh);
            var pc2 = new Point3D(xmax, ymin, zh);
            var pc5 = new Point3D(xmax, ymax, zh);
            var pc3 = new Point3D(xmin, ymax, zh);

            var pc4 = new Point3D(xh, ymin, zmax);
            var pc6 = new Point3D(xmax, yh, zmax);
            var pc8 = new Point3D(xmin, yh, zmax);
            var pc7 = new Point3D(xh, ymax, zmax);

            var pc9  = new Point3D(xh, ymin, zmin);
            var pc10 = new Point3D(xmax, yh, zmin);
            var pc11 = new Point3D(xmin, yh, zmin);
            var pc12 = new Point3D(xh, ymax, zmin);

            cube.Positions.Add(pc1);  //8
            cube.Positions.Add(pc2);  //9
            cube.Positions.Add(pc3);  //10
            cube.Positions.Add(pc5);  //11

            cube.Positions.Add(pc4);  //12
            cube.Positions.Add(pc6);  //13
            cube.Positions.Add(pc8);  //14
            cube.Positions.Add(pc7);  //15

            cube.Positions.Add(pc9);  //16
            cube.Positions.Add(pc10); //17
            cube.Positions.Add(pc11); //18
            cube.Positions.Add(pc12); //19

            cube.TriangleIndices.Add(0);
            cube.TriangleIndices.Add(4);
            cube.TriangleIndices.Add(8);

            cube.TriangleIndices.Add(1);
            cube.TriangleIndices.Add(5);
            cube.TriangleIndices.Add(9);

            cube.TriangleIndices.Add(2);
            cube.TriangleIndices.Add(6);
            cube.TriangleIndices.Add(10);

            cube.TriangleIndices.Add(3);
            cube.TriangleIndices.Add(7);
            cube.TriangleIndices.Add(11);

            cube.TriangleIndices.Add(4);
            cube.TriangleIndices.Add(5);
            cube.TriangleIndices.Add(12);

            cube.TriangleIndices.Add(4);
            cube.TriangleIndices.Add(6);
            cube.TriangleIndices.Add(14);

            cube.TriangleIndices.Add(5);
            cube.TriangleIndices.Add(7);
            cube.TriangleIndices.Add(13);

            cube.TriangleIndices.Add(6);
            cube.TriangleIndices.Add(7);
            cube.TriangleIndices.Add(15);

            cube.TriangleIndices.Add(0);
            cube.TriangleIndices.Add(1);
            cube.TriangleIndices.Add(16);

            cube.TriangleIndices.Add(0);
            cube.TriangleIndices.Add(2);
            cube.TriangleIndices.Add(18);

            cube.TriangleIndices.Add(1);
            cube.TriangleIndices.Add(3);
            cube.TriangleIndices.Add(17);

            cube.TriangleIndices.Add(2);
            cube.TriangleIndices.Add(3);
            cube.TriangleIndices.Add(19);

            geo.Geometry = cube;
            _axis.MakeWireframe(geo);
            _axis.Transform = new MatrixTransform3D(_transformMatrix.TotalMatrix);
        }