Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            // selection rect
            m_selectRect.SetRect(new Point(-0.5, -0.5), new Point(-0.5, -0.5));
            GridExplorer.Model3D model3d = new GridExplorer.Model3D();
            ArrayList            meshs   = m_selectRect.GetMeshes();

            m_nRectModelIndex = model3d.UpdateModel(meshs, null, m_nRectModelIndex, this.mainViewport);

            // display the 3d chart data no.
            dataNo_x.Text = String.Format("{0:d}", m_nNumElemts_x);
            dataNo_y.Text = String.Format("{0:d}", m_nNumElemts_y);
            dataNo_z.Text = String.Format("{0:d}", m_nNumElemts_z);
            basis_x.Text  = "1";
            basis_y.Text  = "1";
            basis_z.Text  = "1";

            // display surface chart
            BuildGrid();
            TransformChart();
        }
Ejemplo n.º 2
0
        // function for set a scatter plot, every dot is just a simple pyramid.
        public void BuildGrid(SHAPE shape = SHAPE.CYLINDER)
        {
            int nElem_x = Int32.Parse(dataNo_x.Text);
            int nElem_y = Int32.Parse(dataNo_y.Text);
            int nElem_z = Int32.Parse(dataNo_z.Text);

            if ((nElem_x <= 0) || (nElem_y <= 0) || (nElem_z <= 0))
            {
                MessageBox.Show("Add at least 1 point to each axis");
                return;
            }
            if ((nElem_x > 10000) || (nElem_y > 10000) || (nElem_z > 10000))
            {
                MessageBox.Show("Too many elements");
                return;
            }

            long bas_x = Int64.Parse(basis_x.Text);
            long bas_y = Int64.Parse(basis_y.Text);
            long bas_z = Int64.Parse(basis_z.Text);

            // 1. set the scatter plot size
            m_3dChart = new ScatterChart3D();
            m_3dChart.SetDataNo(nElem_x * nElem_y * nElem_z);

            // 2. set the properties of each dot
            Random randomObject = new Random();
            int    nDataRange   = 200;

            for (int i = 0; i < nElem_x; i++)
            {
                for (int j = 0; j < nElem_y; j++)
                {
                    for (int k = 0; k < nElem_z; k++)
                    {
                        ScatterPlotItem plotItem = new ScatterPlotItem();

                        plotItem.w = 2;
                        plotItem.h = 2;

                        plotItem.x = (float)i * bas_x * m_nscale_factor;
                        plotItem.y = (float)j * bas_y * m_nscale_factor;
                        plotItem.z = (float)k * bas_z * m_nscale_factor;

                        plotItem.shape = (int)shape;

                        Byte nR = (Byte)randomObject.Next(256);
                        Byte nG = (Byte)randomObject.Next(256);
                        Byte nB = (Byte)randomObject.Next(256);

                        plotItem.color = Color.FromRgb(nR, nG, nB);

                        // convert [,,] -> []
                        //x + WIDTH * (y + DEPTH * z)
                        ((ScatterChart3D)m_3dChart).SetVertex(i + nElem_x * (j + nElem_y * k), plotItem);
                    }
                }
            }

            // 3. set axes
            m_3dChart.GetDataRange();
            m_3dChart.SetAxes();

            // 4. Get Mesh3D array from scatter plot
            ArrayList meshs = ((ScatterChart3D)m_3dChart).GetMeshes();

            // 5. display vertex no and triangle no.
            UpdateModelSizeInfo(meshs);

            // 6. show 3D scatter plot in Viewport3d
            GridExplorer.Model3D model3d = new GridExplorer.Model3D();
            m_nChartModelIndex = model3d.UpdateModel(meshs, null, m_nChartModelIndex, this.mainViewport);

            // 7. set projection matrix
            float viewRange = (float)nDataRange;

            m_transformMatrix.CalculateProjectionMatrix(0, viewRange, 0, viewRange, 0, viewRange, 0.5);
            TransformChart();
        }