public static DenseMatrix ReadDenseMatrixFromFile(string fileName)
        {
            double[,] res = null;

            if (!ServiceTools.CheckIfDirectoryExists(fileName))
            {
                return(null);
            }
            NetCDFDataSet ds = null;

            try
            {
                ds = new NetCDFDataSet("msds:nc?file=" + fileName + "&enableRollback=false",
                                       ResourceOpenMode.ReadOnly);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //Variable<double> thDataVar = ds.AddVariable<double>("dataMatrix", dmData.ToArray(), "y", "x");
            //Variable<double> thDataVar = ds.Variables
            foreach (Variable theVar in ds)
            {
                res = (double[, ])theVar.GetData();
            }

            return(DenseMatrix.OfArray(res));
        }
        public void SwapLog(string filename)
        {
            if (!ServiceTools.CheckIfDirectoryExists(filename))
            {
                return;
            }

            ServiceTools.logToTextFile(filename, textBox1.Text, false);

            ThreadSafeOperations.SetTextTB(textBox1, "", false);
        }
        public static DenseMatrix ReadDenseMatrixFromFile(string fileName, string varName = "DataMatrix")
        {
            double[,] res = null;
            DenseMatrix dmRes = null;

            if (!ServiceTools.CheckIfDirectoryExists(fileName))
            {
                return(null);
            }

            NetCDFDataSet ds = null;

            try
            {
                ds = new NetCDFDataSet("msds:nc?file=" + fileName + "&enableRollback=false", ResourceOpenMode.ReadOnly);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //Variable<double> thDataVar = ds.AddVariable<double>("dataMatrix", dmData.ToArray(), "y", "x");
            //Variable<double> thDataVar = ds.Variables
            foreach (Variable theVar in ds)
            {
                if (theVar.Name != varName)
                {
                    continue;
                }
                else
                {
                    if (theVar.TypeOfData == typeof(double))
                    {
                        res   = (double[, ])theVar.GetData();
                        dmRes = DenseMatrix.OfArray(res);
                    }
                    else if (theVar.TypeOfData == typeof(Single))
                    {
                        Single[,] res1 = (Single[, ])theVar.GetData();
                        dmRes          = DenseMatrix.Create(theVar.Dimensions[0].Length, theVar.Dimensions[1].Length, ((i, j) =>
                        {
                            return(Convert.ToDouble(res1[i, j]));
                        }));
                    }

                    break;
                }
            }

            return(dmRes);
        }
示例#4
0
        public Field3Drepresentation(DenseMatrix dmDataToRepresent, Dictionary <string, object> properties, string description = "")
        {
            InitializeComponent();

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

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

            dmData = dmDataToRepresent.Copy();


            ILScene scene = new ILScene();

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

            ILInArray <double> ilaDataMeshToShow = dmData.ToArray();

            if ((dmDataXcoord != null) && (dmDataYcoord != null))
            {
                ILInArray <double> ilaXvalues = dmDataXcoord.Row(0).ToArray();
                ILInArray <double> ilaYvalues = dmDataYcoord.Column(0).ToArray();
                surf = new ILSurface(ilaDataMeshToShow, ilaXvalues, ilaYvalues);
            }
            else
            {
                surf = new ILSurface(ilaDataMeshToShow);
            }

            surf.UseLighting = true;
            surf.Colormap    = Colormaps.ILNumerics;
            surf.Children.Add(new ILColorbar());

            currSurfPlotCube.Children.Add(surf);
            currSurfPlotCube.Rotation = Matrix4.Rotation(new Vector3(1, 0, 0), 1.2f) *
                                        Matrix4.Rotation(new Vector3(0, 0, 1), Math.PI);
            currSurfPlotCube.Projection = Projection.Perspective;

            scene.Add(currSurfPlotCube);

            ilPanel1.Scene = scene;
        }
        public static void AddDataMatrixToFile(DenseMatrix dmData, string fileName, TextBox tbLog,
                                               bool absolutePath = false, string varName = "dataMatrix")
        {
            string baseDir          = "G:\\_gulevlab\\SkyIndexAnalyzerSolo_appData\\_dataDirectory\\";
            string connectionString = "msds:nc?file=";

            if (absolutePath)
            {
                if (!ServiceTools.CheckIfDirectoryExists(fileName))
                {
                    return;
                }
                connectionString += fileName;
            }
            else
            {
                if (!ServiceTools.CheckIfDirectoryExists(baseDir + fileName))
                {
                    return;
                }
                connectionString += baseDir + fileName;
            }

            NetCDFDataSet ds = null;

            try
            {
                ds = new NetCDFDataSet(connectionString, ResourceOpenMode.OpenOrCreate);
            }
            catch (Exception ex)
            {
                if (tbLog != null)
                {
                    ThreadSafeOperations.SetTextTB(tbLog, "Не получилось :( " + Environment.NewLine + ex.Message, true);
                }
                else
                {
                    throw ex;
                }
            }


            Variable <double> thDataVar;

            if (!ds.Variables.Contains(varName))
            {
                thDataVar = ds.AddVariable <double>(varName, dmData.ToArray(), "y", "x");
            }
            else
            {
                thDataVar = (Variable <double>)ds.Variables[varName];
                thDataVar.Append(dmData.ToArray());
            }


            try
            {
                ds.TryCommit();
            }
            catch (Exception ex)
            {
                if (tbLog != null)
                {
                    ThreadSafeOperations.SetTextTB(tbLog, "Не получилось :( " + Environment.NewLine + ex.Message, true);
                }
                else
                {
                    throw ex;
                }
            }

            ds.Dispose();
        }
        public static void AddVariousDataToFile(Dictionary <string, object> dataToWrite, string fileName)
        {
            if (!ServiceTools.CheckIfDirectoryExists(fileName))
            {
                return;
            }

            string connectionString = "msds:nc?file=";

            connectionString += fileName;
            NetCDFDataSet ds = null;

            try
            {
                ds = new NetCDFDataSet(connectionString, ResourceOpenMode.OpenOrCreate);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            foreach (KeyValuePair <string, object> keyValuePair in dataToWrite)
            {
                if (keyValuePair.Value.GetType() == typeof(DenseMatrix))
                {
                    if (ds.Variables.Contains(keyValuePair.Key))
                    {
                        Variable <double> theDataVar = (Variable <double>)ds.Variables[keyValuePair.Key];
                        theDataVar.Append(((DenseMatrix)keyValuePair.Value).ToArray());
                    }
                    else
                    {
                        Variable <double> theDataVar = ds.AddVariable <double>(keyValuePair.Key,
                                                                               ((DenseMatrix)(keyValuePair.Value)).ToArray(), "y", "x");
                    }
                }

                if (keyValuePair.Value.GetType() == typeof(DenseVector))
                {
                    if (ds.Variables.Contains(keyValuePair.Key))
                    {
                        Variable <double> theDataVar = (Variable <double>)ds.Variables[keyValuePair.Key];
                        theDataVar.Append(((DenseVector)keyValuePair.Value).ToArray());
                    }
                    else
                    {
                        Variable <double> theDataVar = ds.AddVariable <double>(keyValuePair.Key,
                                                                               ((DenseVector)(keyValuePair.Value)).ToArray(), keyValuePair.Key);
                    }
                }

                if (keyValuePair.Value.GetType() == typeof(long[]))
                {
                    if (ds.Variables.Contains(keyValuePair.Key))
                    {
                        Variable <long> theDataVar = (Variable <long>)ds.Variables[keyValuePair.Key];
                        theDataVar.Append((long[])(keyValuePair.Value));
                    }
                    else
                    {
                        Variable <long> theDataVar = ds.AddVariable <long>(keyValuePair.Key, (long[])(keyValuePair.Value),
                                                                           keyValuePair.Key);
                    }
                }

                if (keyValuePair.Value.GetType() == typeof(int[]))
                {
                    if (ds.Variables.Contains(keyValuePair.Key))
                    {
                        Variable <int> theDataVar = (Variable <int>)ds.Variables[keyValuePair.Key];
                        theDataVar.Append((int[])(keyValuePair.Value));
                    }
                    else
                    {
                        Variable <int> theDataVar = ds.AddVariable <int>(keyValuePair.Key, (int[])(keyValuePair.Value),
                                                                         keyValuePair.Key);
                    }
                }

                if (keyValuePair.Value.GetType() == typeof(string[]))
                {
                    if (ds.Variables.Contains(keyValuePair.Key))
                    {
                        Variable <string> theDataVar = (Variable <string>)ds.Variables[keyValuePair.Key];
                        theDataVar.Append((string[])(keyValuePair.Value));
                    }
                    else
                    {
                        Variable <string> theDataVar = ds.AddVariable <string>(keyValuePair.Key, (string[])(keyValuePair.Value),
                                                                               keyValuePair.Key);
                    }
                }
            }

            try
            {
                ds.TryCommit();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            ds.Dispose();
        }
        public static void SaveVariousDataToFile(Dictionary <string, object> dataToWrite, string fileName)
        {
            if (!ServiceTools.CheckIfDirectoryExists(fileName))
            {
                return;
            }

            string connectionString = "msds:nc?file=";

            connectionString += fileName;
            // connectionString += "&deflate=best";
            NetCDFDataSet ds = null;

            try
            {
                ds = new NetCDFDataSet(connectionString, ResourceOpenMode.Create);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            foreach (KeyValuePair <string, object> keyValuePair in dataToWrite)
            {
                if (keyValuePair.Value.GetType() == typeof(DenseMatrix))
                {
                    try
                    {
                        Variable <double> theDataVar = ds.AddVariable <double>(keyValuePair.Key, ((DenseMatrix)(keyValuePair.Value)).ToArray(), "y", "x");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }

                if (keyValuePair.Value.GetType() == typeof(DenseVector))
                {
                    try
                    {
                        Variable <double> theDataVar = ds.AddVariable <double>(keyValuePair.Key, ((DenseVector)(keyValuePair.Value)).ToArray(), keyValuePair.Key);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }

                if (keyValuePair.Value.GetType() == typeof(long[]))
                {
                    try
                    {
                        Variable <long> theDataVar = ds.AddVariable <long>(keyValuePair.Key, (long[])(keyValuePair.Value), keyValuePair.Key);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }


                if (keyValuePair.Value.GetType() == typeof(long[, ]))
                {
                    try
                    {
                        Variable <long> theDataVar = ds.AddVariable <long>(keyValuePair.Key, (long[, ])(keyValuePair.Value), "y", "x");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }


                if (keyValuePair.Value.GetType() == typeof(int[]))
                {
                    try
                    {
                        Variable <int> theDataVar = ds.AddVariable <int>(keyValuePair.Key, (int[])(keyValuePair.Value), keyValuePair.Key);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }


                if (keyValuePair.Value.GetType() == typeof(int[, ]))
                {
                    try
                    {
                        Variable <int> theDataVar = ds.AddVariable <int>(keyValuePair.Key, (int[, ])(keyValuePair.Value), "y", "x");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }


                if (keyValuePair.Value.GetType() == typeof(short[]))
                {
                    try
                    {
                        Variable <short> theDataVar = ds.AddVariable <short>(keyValuePair.Key, (short[])(keyValuePair.Value), keyValuePair.Key);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }


                if (keyValuePair.Value.GetType() == typeof(short[, ]))
                {
                    try
                    {
                        Variable <short> theDataVar = ds.AddVariable <short>(keyValuePair.Key, (short[, ])(keyValuePair.Value), "y", "x");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }



                if (keyValuePair.Value.GetType() == typeof(byte[]))
                {
                    try
                    {
                        Variable <byte> theDataVar = ds.AddVariable <byte>(keyValuePair.Key, (byte[])(keyValuePair.Value), keyValuePair.Key);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }


                if (keyValuePair.Value.GetType() == typeof(byte[, ]))
                {
                    try
                    {
                        Variable <byte> theDataVar = ds.AddVariable <byte>(keyValuePair.Key, (byte[, ])(keyValuePair.Value), "y", "x");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }



                if (keyValuePair.Value.GetType() == typeof(byte[, , ]))
                {
                    try
                    {
                        Variable <byte> theDataVar = ds.AddVariable <byte>(keyValuePair.Key, (byte[, , ])(keyValuePair.Value), "y", "x", "z");
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }



                if (keyValuePair.Value.GetType() == typeof(string[]))
                {
                    Variable <string> theDataVar = ds.AddVariable <string>(keyValuePair.Key, (string[])(keyValuePair.Value), keyValuePair.Key);
                }
            }



            try
            {
                ds.TryCommit();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            ds.Dispose();
        }
        public static Dictionary <string, object> ReadDataFromFile(string fileName, List <string> varNames = null)
        {
            if (!ServiceTools.CheckIfDirectoryExists(fileName))
            {
                return(null);
            }

            Dictionary <string, object> retDict = new Dictionary <string, object>();

            double[,] res = null;
            NetCDFDataSet ds = null;

            try
            {
                ds = new NetCDFDataSet("msds:nc?file=" + fileName + "&enableRollback=false", ResourceOpenMode.ReadOnly);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            foreach (Variable theVar in ds)
            {
                bool loadThisVar = false;
                if (varNames == null)
                {
                    loadThisVar = true;
                }
                else if (varNames.Contains(theVar.Name))
                {
                    loadThisVar = true;
                }
                if (!loadThisVar)
                {
                    continue;
                }

                if (theVar.TypeOfData == typeof(double))
                {
                    if (theVar.Dimensions.Count == 1)
                    {
                        double[] res1 = (double[])theVar.GetData();
                        retDict.Add(theVar.Name, DenseVector.OfEnumerable(res1));
                    }
                    else if (theVar.Dimensions.Count == 2)
                    {
                        double[,] res1 = (double[, ])theVar.GetData();
                        retDict.Add(theVar.Name, DenseMatrix.OfArray(res1));
                    }
                }



                if (theVar.TypeOfData == typeof(Single))
                {
                    if (theVar.Dimensions.Count == 1)
                    {
                        Single[]    res1   = (Single[])theVar.GetData();
                        DenseVector dvRes1 = DenseVector.Create(theVar.Dimensions[0].Length,
                                                                i => Convert.ToDouble(res1[i]));
                        retDict.Add(theVar.Name, dvRes1);
                    }
                    else if (theVar.Dimensions.Count == 2)
                    {
                        Single[,] res1 = (Single[, ])theVar.GetData();
                        DenseMatrix dmRes = DenseMatrix.Create(theVar.Dimensions[0].Length, theVar.Dimensions[1].Length,
                                                               ((i, j) =>
                        {
                            return(Convert.ToDouble(res1[i, j]));
                        }));
                        retDict.Add(theVar.Name, dmRes);
                    }
                }



                if (theVar.TypeOfData == typeof(long))
                {
                    if (theVar.Dimensions.Count == 1)
                    {
                        long[] res1 = (long[])theVar.GetData();
                        retDict.Add(theVar.Name, res1);
                    }
                    else if (theVar.Dimensions.Count == 2)
                    {
                        long[,] res1 = (long[, ])theVar.GetData();
                        retDict.Add(theVar.Name, res1);
                    }
                }


                if (theVar.TypeOfData == typeof(int))
                {
                    if (theVar.Dimensions.Count == 1)
                    {
                        int[] res1 = (int[])theVar.GetData();
                        retDict.Add(theVar.Name, res1);
                    }
                    else if (theVar.Dimensions.Count == 2)
                    {
                        int[,] res1 = (int[, ])theVar.GetData();
                        retDict.Add(theVar.Name, res1);
                    }
                }


                if (theVar.TypeOfData == typeof(string))
                {
                    string[] res1 = (string[])theVar.GetData();
                    retDict.Add(theVar.Name, res1);
                }
            }

            return(retDict);
        }
示例#9
0
        private void PlotByIsolines(
            DenseMatrix dmListOfData,
            Dictionary <string, object> properties,
            string description = "")
        {
            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> > llDataMatricesSlicedByZ = ReshapeDataToMatrices(dmDataList, SlicingVariable.z);
            DenseMatrix dmXvalues = llDataMatricesSlicedByZ[0][0].Copy();
            DenseMatrix dmYvalues = llDataMatricesSlicedByZ[0][1].Copy();

            List <List <DataValuesOver3DGrid> > lDataVectorsForSurfices = Group_DVOG_DataByValues(dmDataList);

            foreach (List <DataValuesOver3DGrid> currSurfVectorsList in lDataVectorsForSurfices)
            {
                //ILInArray<float> ilaXvalues =
                //    currSurfVectorsList.ConvertAll<float>(dvog => Convert.ToSingle(dvog.x)).ToArray();
                //ILInArray<float> ilaYvalues =
                //    currSurfVectorsList.ConvertAll<float>(dvog => Convert.ToSingle(dvog.y)).ToArray();
                //ILInArray<float> ilaZvalues =
                //    currSurfVectorsList.ConvertAll<float>(dvog => Convert.ToSingle(dvog.z)).ToArray();
                //ILSurface currSurf = new ILSurface(ilaZvalues, ilaXvalues, ilaYvalues);
                // не катит - надо, чтобы сетка z была m*n, сетка x = m*[1|n], сетка y - [1|m]*n
                // поэтому просто список точек, которые должны составить поверхность, - не катят
                //  => или отрисовывать множества точек, без привязки именно к понятию поверхности. Это пока не получилось
                //  => или переформировать список точек так, чтобы они составили m*n поверхность

                // скомпоновать матрицу значений Z, соответствующих значениям x и y
                DenseMatrix dmZvalues = DenseMatrix.Create(dmXvalues.RowCount, dmXvalues.ColumnCount, (r, c) =>
                {
                    double x = dmXvalues[r, c];
                    double y = dmYvalues[r, c];
                    int idx  = currSurfVectorsList.FindIndex(dvog => ((dvog.x == x) && (dvog.y == y)));
                    if (idx == -1) // ничего нужного нет
                    {
                        return(double.NaN);
                    }
                    else
                    {
                        return(currSurfVectorsList[idx].z);
                    }
                });
                ILArray <double> arrXvalues = (ILArray <double>)(dmXvalues.ToArray());
                ILArray <double> arrYvalues = (ILArray <double>)(dmYvalues.ToArray());
                ILArray <double> arrZvalues = (ILArray <double>)(dmZvalues.ToArray());

                // сформируем colors array
                ColorScheme newCS    = new ColorScheme("");
                DenseMatrix dmValues = DenseMatrix.Create(dmXvalues.RowCount, dmXvalues.ColumnCount, (r, c) =>
                {
                    double x = dmXvalues[r, c];
                    double y = dmYvalues[r, c];
                    int idx  = currSurfVectorsList.FindIndex(dvog => ((dvog.x == x) && (dvog.y == y)));
                    if (idx == -1) // ничего нужного нет
                    {
                        return(double.NaN);
                    }
                    else
                    {
                        return(currSurfVectorsList[idx].values[0]);
                    }
                });

                double[,] dmRvalues = DenseMatrix.Create(dmValues.RowCount, dmValues.ColumnCount,
                                                         (r, c) =>
                {
                    Bgr currColor = newCS.GetColorByValueAndRange(dmValues[r, c], dataMinVal, dataMaxVal);
                    return(currColor.Red / 255.0d);
                }).ToArray();
                double[,] dmGvalues = DenseMatrix.Create(dmValues.RowCount, dmValues.ColumnCount,
                                                         (r, c) =>
                {
                    Bgr currColor = newCS.GetColorByValueAndRange(dmValues[r, c], dataMinVal, dataMaxVal);
                    return(currColor.Green / 255.0d);
                }).ToArray();
                double[,] dmBvalues = DenseMatrix.Create(dmValues.RowCount, dmValues.ColumnCount,
                                                         (r, c) =>
                {
                    Bgr currColor = newCS.GetColorByValueAndRange(dmValues[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;
                    }
                }



                ILSurface currSurf = new ILSurface(ILMath.convert <double, float>(arrZvalues),
                                                   ILMath.convert <double, float>(arrXvalues), ILMath.convert <double, float>(arrYvalues), rgbaArrData);

                currSurf.UseLighting = true;

                currSurfPlotCube.Children.Add(currSurf);
            }

            currSurfPlotCube.Projection = Projection.Orthographic;

            currSurfPlotCube.Plots.Reset();

            scene.Add(currSurfPlotCube);

            ilPanel1.Scene = scene;
        }
示例#10
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;
        }
示例#11
0
        private void PlotByNodesPoints(
            DenseMatrix dmListOfData,
            Dictionary <string, object> properties,
            string description = "")
        {
            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;

            ILArray <float> A =
                ILMath.tosingle((ILArray <double>)(dmDataList.SubMatrix(0, dmDataList.RowCount, 0, 3).ToArray()));

            ILArray <float> colors = ILMath.zeros <float>(4, dmDataList.RowCount);

            ColorScheme newCS = new ColorScheme("");


            double[] dvRvalues = DenseVector.Create(dmDataList.RowCount, (r) =>
            {
                Bgr currColor = newCS.GetColorByValueAndRange(dmDataList[r, 3], dataMinVal, dataMaxVal);
                return(currColor.Red / 255.0d);
            }).ToArray();
            double[] dvGvalues = DenseVector.Create(dmDataList.RowCount, (r) =>
            {
                Bgr currColor = newCS.GetColorByValueAndRange(dmDataList[r, 3], dataMinVal, dataMaxVal);
                return(currColor.Green / 255.0d);
            }).ToArray();
            double[] dvBvalues = DenseVector.Create(dmDataList.RowCount, (r) =>
            {
                Bgr currColor = newCS.GetColorByValueAndRange(dmDataList[r, 3], dataMinVal, dataMaxVal);
                return(currColor.Blue / 255.0d);
            }).ToArray();
            colors["0;:"] = ILMath.tosingle((ILArray <double>)dvRvalues);
            colors["1;:"] = ILMath.tosingle((ILArray <double>)dvGvalues);
            colors["2;:"] = ILMath.tosingle((ILArray <double>)dvBvalues);
            colors["3;:"] = 0.5f;

            ILPoints pts = new ILPoints
            {
                Positions = A,
                Colors    = colors,
            };

            pts.Color = null;
            currSurfPlotCube.Add(pts);

            currSurfPlotCube.Projection = Projection.Orthographic;
            currSurfPlotCube.Rotation   = Matrix4.Rotation(new Vector3(1, 1, 1), 0.5f);
            currSurfPlotCube.Plots.Reset();
            scene.Add(currSurfPlotCube);

            ilPanel1.Scene = scene;
        }