Пример #1
0
        List <List <DenseMatrix> > ReshapeDataToMatrices(DenseMatrix dmRawDataByColumns, SlicingVariable varSliceBy)
        {
            List <List <DenseMatrix> >  retSurficesDataMatricesList = new List <List <DenseMatrix> >();
            List <DataValuesOver3DGrid> lDataList = new List <DataValuesOver3DGrid>();

            foreach (Vector <double> vec in dmRawDataByColumns.EnumerateRows())
            {
                lDataList.Add(new DataValuesOver3DGrid(vec.ToArray()));
            }

            List <IGrouping <double, DataValuesOver3DGrid> > groupingByLeadingVar =
                new List <IGrouping <double, DataValuesOver3DGrid> >(lDataList.GroupBy(dvog =>
            {
                switch (varSliceBy)
                {
                case SlicingVariable.x:
                    {
                        return(dvog.x);

                        break;
                    }

                case SlicingVariable.y:
                    {
                        return(dvog.y);

                        break;
                    }

                case SlicingVariable.z:
                    {
                        return(dvog.z);

                        break;
                    }

                default:
                    {
                        return(dvog.z);

                        break;
                    }
                }
            }));

            foreach (IGrouping <double, DataValuesOver3DGrid> currGrouping in groupingByLeadingVar)
            {
                // собрать матрицы для значений x, y, отображаемых значений
                // на забыть, что матрица (идентичных) значений z тоже должна быть на выходе - третьей
                // посчитаем, сколько колонок и столбцов должно быть во всех матрицах
                List <DenseMatrix> currSurfDataMatricesList = new List <DenseMatrix>();

                List <DataValuesOver3DGrid> currLeadingValueData = new List <DataValuesOver3DGrid>(currGrouping);
                List <IGrouping <double, DataValuesOver3DGrid> > groupingBy2ndVar = new List <IGrouping <double, DataValuesOver3DGrid> >(currLeadingValueData.GroupBy(dvog =>
                {
                    switch (varSliceBy)
                    {
                    case SlicingVariable.x:
                        {
                            return(dvog.y);

                            break;
                        }

                    case SlicingVariable.y:
                        {
                            return(dvog.z);

                            break;
                        }

                    case SlicingVariable.z:
                        {
                            return(dvog.x);

                            break;
                        }

                    default:
                        {
                            return(dvog.x);

                            break;
                        }
                    }
                }));

                //columns count
                int columnCount = groupingBy2ndVar.Count;
                //rows count
                int rowCount = groupingBy2ndVar[0].Count();

                DenseMatrix dmLeadingValues = DenseMatrix.Create(rowCount, columnCount, currGrouping.Key);

                DenseMatrix var2Values = DenseMatrix.Create(rowCount, columnCount, (r, c) => groupingBy2ndVar[c].Key);
                currSurfDataMatricesList.Add(var2Values);
                DenseMatrix var3Values = DenseMatrix.Create(rowCount, columnCount, (r, c) =>
                {
                    switch (varSliceBy)
                    {
                    case SlicingVariable.x:
                        {
                            return(groupingBy2ndVar[0].ElementAt(r).z);

                            break;
                        }

                    case SlicingVariable.y:
                        {
                            return(groupingBy2ndVar[0].ElementAt(r).x);

                            break;
                        }

                    case SlicingVariable.z:
                        {
                            return(groupingBy2ndVar[0].ElementAt(r).y);

                            break;
                        }

                    default:
                        {
                            return(groupingBy2ndVar[0].ElementAt(r).y);

                            break;
                        }
                    }
                });
                currSurfDataMatricesList.Add(var3Values);

                currSurfDataMatricesList.Add(dmLeadingValues);

                //ILArray<double> tmpLeadingValuesMatrix = (ILArray<double>) dmLeadingValues.ToArray();
                //ILArray<double> tmpvar2ValuesMatrix = (ILArray<double>)var2Values.ToArray();
                //ILArray<double> tmpvar3ValuesMatrix = (ILArray<double>)var3Values.ToArray();

                //ILArray<double> tmparr = tmpLeadingValuesMatrix + tmpvar2ValuesMatrix + tmpvar3ValuesMatrix;

                int valuesCount = lDataList[0].values.Count();
                for (int i = 0; i < valuesCount; i++)
                {
                    DenseMatrix tmpDM = DenseMatrix.Create(rowCount, columnCount, (r, c) => groupingBy2ndVar[c].ElementAt(r).values[i]);
                    currSurfDataMatricesList.Add(tmpDM);
                }

                retSurficesDataMatricesList.Add(currSurfDataMatricesList);
            }

            return(retSurficesDataMatricesList);
        }
Пример #2
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;
        }