Example #1
0
        public void CreateChart3D(ArrayList ary, CSType csType, string capt)
        {
            Chart3D chart3D = new Chart3D();

            chart3D.caption = capt;
            int vertNum = ary.Count;
            int trigNum = (int)(vertNum / 3);

            chart3D.SetDataNo(vertNum);
            double phi, theta;
            double alpha, beta, r;

            for (int i = 0; i < vertNum; i++)
            {
                switch (csType)
                {
                case CSType.DEC: { } break;

                case CSType.CALC:
                {
                    phi   = ((Point3D)ary[i]).X;
                    theta = ((Point3D)ary[i]).Y;
                    r     = ((Point3D)ary[i]).Z;
                    chart3D.vertices[i]   = new Vertex3D();
                    chart3D.vertices[i].x = r * Math.Cos(phi) * Math.Sin(theta);
                    chart3D.vertices[i].y = r * Math.Sin(phi) * Math.Sin(theta);
                    chart3D.vertices[i].z = r * Math.Cos(theta);
                } break;

                case CSType.TOPO:
                {
                    alpha = ((Point3D)ary[i]).X;
                    beta  = ((Point3D)ary[i]).Y;
                    r     = ((Point3D)ary[i]).Z;
                    chart3D.vertices[i]   = new Vertex3D();
                    chart3D.vertices[i].x = r * Math.Sin(alpha) * Math.Cos(beta);
                    chart3D.vertices[i].y = r * Math.Sin(beta);
                    chart3D.vertices[i].z = r * Math.Cos(alpha) * Math.Cos(beta);
                } break;
                }
            }
            chart3D.GetDataRange();

            for (int i = 0; i < vertNum; i++)
            {
                Vertex3D vert = chart3D[i];
                r  = Math.Pow((vert.x - xC) / (xMax - xMin), 2);
                r += Math.Pow((vert.y - yC) / (yMax - yMin), 2);
                r += Math.Pow((vert.z - zC) / (zMax - zMin), 2);
                r  = 1.8 * Math.Sqrt(r);

                Color color = TextureMapping.PseudoColor(r);
                chart3D[i].color = color;
            }
            chart3D.SetAxes(0.0, 0.0, 0.0, 1.2f, 1.2f, 1.2f);
            chart3DList.Add(chart3D);
        }
Example #2
0
        public void ShowChart3D(int ind)
        {
            if (chart3DList.Count == 0)
            {
                return;
            }
            // 4. Get the Mesh3D array from surface chart
            chart3DInd = ind;
            Chart3D chart3D = ((Chart3D)chart3DList[ind]);

            this.Title = chart3D.caption;
            int         vertNum     = chart3D.GetDataNo();
            int         trigNum     = (int)(vertNum / 3);
            ArrayList   meshs       = new ArrayList();
            ColorMesh3D surfaceMesh = new ColorMesh3D();

            surfaceMesh.SetSize(vertNum, (int)(vertNum / 3));

            double x, y, z, r;
            double rMinLog = 0.0;
            double rMaxLog = 1.0;
            double rMin    = Math.Pow(10.0, chartPrm.logMin / 10.0);
            double rMax    = 1.0;
            double logR;

            for (int i = 0; i < vertNum; i++)
            {
                x = chart3D.vertices[i].x;
                y = chart3D.vertices[i].y;
                z = chart3D.vertices[i].z;
                if (chartPrm.coordinateScale == CoordinateScale.Log)
                {
                    r = Math.Sqrt(x * x + y * y + z * z);
                    if (r > rMin)
                    {
                        logR = rMinLog + (rMaxLog - rMinLog) * (Math.Log10(r / rMin) / Math.Log10(rMax / rMin));
                        x    = x * logR / r;
                        y    = y * logR / r;
                        z    = z * logR / r;
                    }
                    else
                    {
                        z = y = x = 0.0;
                    }
                }
                surfaceMesh.SetPoint(i, new Point3D(x, y, z));
                surfaceMesh.SetColor(i, chart3D.vertices[i].color);
            }
            for (int i = 0; i < trigNum; i++)
            {
                surfaceMesh.SetTriangle(i, 3 * i, 3 * i + 1, 3 * i + 2);
            }
            meshs.Add(surfaceMesh);
            chart3D.AddAxesMeshes(meshs);

            // 5. display vertex no and triangle no of this surface chart
            UpdateModelSizeInfo(meshs);

            // 6. Set the model display of surface chart
            Model3D  model3d      = new Model3D();
            Material backMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.Gray));

            chartModelIndex = model3d.UpdateModel(meshs, backMaterial, chartModelIndex, this.mainViewport);

            // 7. set projection matrix, so the data is in the display region
            //float xMin = chart3D.XMin();
            //float xMax = chart3D.XMax();
            transformMatrix.CalculateProjectionMatrix(xMin, xMax, xMin, xMax, zMin, zMax, 0.5);
            TransformChart();
        }