Example #1
0
        public Field4Drepresentation(
            DenseMatrix dmListOfData,
            Dictionary <string, object> properties,
            Dictionary <string, int> valuesColumnsIndeces = null,
            SlicingVariable varSliceBy = SlicingVariable.z,
            string description         = "")
        {
            InitializeComponent();

            variableSliceBy = varSliceBy;

            if (valuesColumnsIndeces == null)
            {
                valuesColumnsIndeces = new Dictionary <string, int>();
                valuesColumnsIndeces.Add("x", 0);
                valuesColumnsIndeces.Add("y", 1);
                valuesColumnsIndeces.Add("z", 2);
                valuesColumnsIndeces.Add("values", 3);
            }

            strDataDescription = description;
            ThreadSafeOperations.SetText(lblDescription, strDataDescription, false);

            defaultProperties  = properties;
            strOutputDirectory = (string)defaultProperties["DefaultDataFilesLocation"];
            if (!ServiceTools.CheckIfDirectoryExists(strOutputDirectory))
            {
                strOutputDirectory = "";
            }

            dmDataList = dmListOfData.Copy();
            double dataMaxVal = dmDataList.Column(3).Max();
            double dataMinVal = dmDataList.Column(3).Min();

            ILScene scene = new ILScene();

            currSurfPlotCube          = new ILPlotCube();
            currSurfPlotCube.TwoDMode = false;



            List <List <DenseMatrix> > lDataMatricesForSurfices = ReshapeDataToMatrices(dmDataList, variableSliceBy);



            foreach (List <DenseMatrix> currSurfMatricesList in lDataMatricesForSurfices)
            {
                ILInArray <double> ilaXvalues = currSurfMatricesList[0].ToArray();
                ILInArray <double> ilaYvalues = currSurfMatricesList[1].ToArray();
                ILInArray <double> ilaZvalues = currSurfMatricesList[2].ToArray();

                MathNet.Numerics.LinearAlgebra.Single.DenseMatrix floatDMcolors =
                    MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.Create(currSurfMatricesList[0].RowCount,
                                                                             currSurfMatricesList[0].ColumnCount, 0.0f);
                currSurfMatricesList[3].MapConvert <Single>(dval => Convert.ToSingle(dval), floatDMcolors,
                                                            MathNet.Numerics.LinearAlgebra.Zeros.Include);
                ILInArray <float> ilaForColorValues = floatDMcolors.ToArray();


                ILSurface currSurf = new ILSurface(ilaZvalues, ilaXvalues, ilaYvalues);
                currSurf.ColorMode = ILSurface.ColorModes.RBGA;

                ColorScheme newCS = new ColorScheme("");
                //ColorSchemeRuler newCSR = new ColorSchemeRuler(newCS, dataMinVal, dataMaxVal);
                double[,] dmRvalues = DenseMatrix.Create(floatDMcolors.RowCount, floatDMcolors.ColumnCount,
                                                         (r, c) =>
                {
                    Bgr currColor = newCS.GetColorByValueAndRange(currSurfMatricesList[3][r, c], dataMinVal, dataMaxVal);
                    return(currColor.Red / 255.0d);
                }).ToArray();
                double[,] dmGvalues = DenseMatrix.Create(floatDMcolors.RowCount, floatDMcolors.ColumnCount,
                                                         (r, c) =>
                {
                    Bgr currColor = newCS.GetColorByValueAndRange(currSurfMatricesList[3][r, c], dataMinVal, dataMaxVal);
                    return(currColor.Green / 255.0d);
                }).ToArray();
                double[,] dmBvalues = DenseMatrix.Create(floatDMcolors.RowCount, floatDMcolors.ColumnCount,
                                                         (r, c) =>
                {
                    Bgr currColor = newCS.GetColorByValueAndRange(currSurfMatricesList[3][r, c], dataMinVal, dataMaxVal);
                    return(currColor.Blue / 255.0d);
                }).ToArray();
                float[, ,] rgbaArrData = new float[4, dmRvalues.GetLength(0), dmRvalues.GetLength(1)];
                for (int i = 0; i < dmRvalues.GetLength(0); i++)
                {
                    for (int j = 0; j < dmRvalues.GetLength(1); j++)
                    {
                        rgbaArrData[0, i, j] = Convert.ToSingle(dmRvalues[i, j]);
                        rgbaArrData[1, i, j] = Convert.ToSingle(dmGvalues[i, j]);
                        rgbaArrData[2, i, j] = Convert.ToSingle(dmBvalues[i, j]);
                        rgbaArrData[3, i, j] = 0.3f;
                    }
                }

                currSurf.UpdateRGBA(null, rgbaArrData);

                currSurf.UseLighting = true;

                currSurfPlotCube.Children.Add(currSurf);

                //if (currSurfPlotCube.Children.Count() > 4)
                //{
                //    currSurfPlotCube.Children.Add(new ILColorbar());
                //}


                //if (currSurfPlotCube.Children.Count() > 4)
                //{
                //    break;
                //}
            }

            // surf.Children.Add(new ILColorbar());

            //currSurfPlotCube.Children.Add(new ILColorbar());

            //currSurfPlotCube.Rotation = Matrix4.Rotation(new Vector3(1, 0, 0), 1.2f) *
            //                    Matrix4.Rotation(new Vector3(0, 0, 1), Math.PI);

            currSurfPlotCube.Projection = Projection.Orthographic;

            currSurfPlotCube.Plots.Reset();

            scene.Add(currSurfPlotCube);

            ilPanel1.Scene = scene;
        }