public void RepresentDensityField3D() { ILScene scene = new ILScene(); currSurfPlotCube = new ILPlotCube(); currSurfPlotCube.TwoDMode = false; ILInArray <double> ilaDataMeshToShow = dmDensityMesh.ToArray(); ILInArray <double> ilaXvalues = dmDensityMeshXcoord.Row(0).ToArray(); ILInArray <double> ilaYvalues = dmDensityMeshYcoord.Column(0).ToArray(); ILSurface surf = new ILSurface(ilaDataMeshToShow, ilaXvalues, ilaYvalues); 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 void PlotSurface(ILArray <float> array) { //float max=array.Max(); float scale = 1; float.TryParse(cmbZScale.Text, out scale); if (btnRemoveExisted.Checked) { _PlotCube.Children.Clear(); } // _PlotCube.Axes.ZAxis.Scale(1, 1, scale); var sf = new ILSurface(array) { Colormap = EnumHelper.FromString <Colormaps>(cmbColorMap.ComboBox.SelectedItem.ToString()) }; sf.Fill.Markable = false; sf.Wireframe.Markable = false; if (scale != 1) { var newsf = sf.Scale(1, 1, scale); _PlotCube.Add(newsf); } else { _PlotCube.Add(sf); } // _PlotCube.Axes.ZAxis.Max = max; PopulateLegend(); ilPanel1.Refresh(); }
public ILSurfaceWrapper(ILSurface source, ILPanelEditor editor, string path, string name = null, string label = null) : base(source, editor, path, BuildName(name, editor.Panel, source, ILLinePlot.LinePlotTag), String.IsNullOrEmpty(label) ? GetSurfaceLabelFromLegend(source, editor.Panel) : label) { this.source = source; fill = new ILTrianglesWrapper(source.Fill, editor, Path, ILSurface.FillTag, "Fill"); wireframe = new ILLinesWrapper(source.Wireframe, editor, Path, ILSurface.WireframeTag, "Wireframe"); positions = new ReadOnlyCollection<float>(source.Positions.ToList()); }
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; }
void RenderFunction() { var function = _population.OptimizationFunction; var surface = new ILSurface((x, y) => (float)function.Calculate(x, y), xmin: (float)function.MinX, xmax: (float)function.MaxX, ymin: (float)function.MinX, ymax: (float)function.MaxX, xlen: 100, ylen: 100); if (_currentSurface != null) { _plotCube.Remove(_currentSurface); _currentSurface.Dispose(); } _currentSurface = surface; _plotCube.Add(surface); renderContainer.Refresh(); }
private void GenerateGraph() { Invoke(new Action(() => ilgraf.Visible = true)); MaxEpoch = new Populacja(MaxEpochSize, Funkcje.FunctionName.type); MaxEpoch.SetRangeOfPopulation(); MaxEpoch.GenerateGraphPopulation(); MaxEpoch.ObliczPopulFitness(); population = new Populacja(PopulationSize, dim, Funkcje.FunctionName.type); population.SetRangeOfPopulation(); population.GeneratePopulation(dim); population.ObliczPopulFitness(); float[] newData = new float[MaxEpoch.population.Count * 3]; Parallel.For(0, MaxEpoch.population.Count, i => { newData[i] = (float)MaxEpoch.population[i].fitnessValue; // Z newData[i + MaxEpoch.population.Count] = (float)MaxEpoch.population[i].position[0]; // X newData[i + 2 * MaxEpoch.population.Count] = (float)MaxEpoch.population[i].position[1]; // Y }); int size = (int)Math.Sqrt(MaxEpoch.population.Count); data = ILNumerics.ILMath.array(newData, size, size, 3); surface = new ILSurface(data); surface.Fill.Markable = false; surface.Wireframe.Markable = false; //surface.Colormap = Colormaps.Copper; ILColorbar color = new ILColorbar() { Location = new PointF(.96f, 0.1f) }; surface.Children.Add(color); this.ShowParticleOnGraph(population); //this.ShowGraphChart(population); //this.ShowCharts(population); //this.RefreshModel(); }
private static void DrawFunctions(ILPanel panel, NeuralNetwork ann) { int xmin = (int)ann.Instance.Samples[0].Variables[0]; int xmax = (int)ann.Instance.Samples[ann.Instance.NumSamples - 1].Variables[0]; int ymin = (int)ann.Instance.Samples[0].Variables[1]; int ymax = (int)ann.Instance.Samples[ann.Instance.NumSamples - 1].Variables[0]; var approximatedFunction = new ILSurface((x, y) => (float)Convert(ann.GetOutput, x, y)[0], xmin, xmax, 50, ymin, ymax, 50, (x, y) => x * y, colormap: Colormaps.Autumn) { UseLighting = true }; panel.Invoke((Action) delegate { panel.Scene.Remove(panel.Scene.First <ILSurface>()); panel.Scene.First <ILPlotCubeDataGroup>().Insert(0, approximatedFunction); panel.Refresh(); }); }
/*static double Error(double x) * { * double trueMin = 0, y = 0; * switch (funkcja) * { * * case "2*x^2+x-2": * trueMin = -2.125; // @x=-0.25 * y = 2 * Math.Pow(x, 2) + x - 2; * break; * case "x^2+sin(3 cos(5x))": * trueMin = 0.14112;//@x=0 * //trueMin=-0.82205 @x =~= -0.41935 * y = Math.Pow(x, 2) + Math.Sin(3 * Math.Cos(5 * x)); * break; * case "x^4+x^3-7x^2-5x+10": * trueMin = -5.4686;//@x=1.7153 * y = Math.Pow(x, 4) + Math.Pow(x, 3) - 7 * Math.Pow(x, 2) - 5 * x + 10; * break; * case "sin(2 x)+ln(x^2)": * //BRAK GLOBALNEGO MINIMUM !!! * trueMin = double.MaxValue; * y = Math.Sin(2 * x) + Math.Log(Math.Pow(x, 2)); * break; * case "|(log_{10}(x^2)|": * //BRAK GLOBALNEGO MINIMUM !!! * trueMin = double.MaxValue; * y = Math.Abs(Math.Log10(Math.Pow(x, 2))); * break; * * * } * return (y - trueMin) * (y - trueMin); * }*/ /* * static double Solve(int numParticles, double minX, double maxX, int maxEpochs, double exitError) * { * * Random rnd = new Random(0); * * Particle[] swarm = new Particle[numParticles]; * double bestGlobalPosition= double.MaxValue; ; // Najlepsza pozycja znaleziona przez którąkolwiek cząstkę roju * double bestGlobalError = double.MaxValue; // im mniejsza tym lepsza * * // Inicjalizacja roju * for (int i = 0; i < swarm.Length; ++i) * { * double randomPosition; * randomPosition = (maxX - minX) * rnd.NextDouble() + minX; // * * double error = Error(randomPosition); * double randomVelocity; * * double lo = minX * 0.1; * double hi = maxX * 0.1; * randomVelocity = (hi - lo) * rnd.NextDouble() + lo; * * swarm[i] = new Particle(randomPosition, error, randomVelocity, randomPosition, error); * * // Sprawdzenie, czy cząstka ma najlepszą pozycję / rozwiązanie * if (swarm[i].error < bestGlobalError) * { * bestGlobalError = swarm[i].error; * bestGlobalPosition=swarm[i].pozycja; * } * } * * // parametry literaturowe * double w = 0.729; * double c1 = 1.49445; * double c2 = 1.49445; * double r1, r2; * double probDeath = 0.01; * int epoch = 0; * * double newVelocity; * double newPosition; * double newError; * * // główna pętla PSO * while (epoch < maxEpochs) * { * for (int i = 0; i < swarm.Length; ++i) // dla każdej cząstki * { * Particle currP = swarm[i]; * * * r1 = rnd.NextDouble(); * r2 = rnd.NextDouble(); * * newVelocity = (w * currP.predkosc) + * (c1 * r1 * (currP.najlPozycja - currP.pozycja)) + * (c2 * r2 * (bestGlobalPosition - currP.pozycja)); * * currP.predkosc = newVelocity; * * // new position * * newPosition = currP.pozycja + newVelocity; * if (newPosition < minX) * newPosition = minX; * else if (newPosition > maxX) * newPosition = maxX; * * currP.pozycja = newPosition; * * newError = Error(newPosition); * currP.error = newError; * * if (newError < currP.bestError) * { * currP.najlPozycja=newPosition; * currP.bestError = newError; * } * * if (newError < bestGlobalError) * { * bestGlobalPosition = newPosition; * bestGlobalError = newError; * } * * // Czy uśmiercić cząstkę? * double die = rnd.NextDouble(); * if (die < probDeath) * { * * for (int j = 0; j < currP.position.Length; ++j) * currP.position[j] = (maxX - minX) * rnd.NextDouble() + minX; * currP.error = Error(currP.pozycja); * currP.position.CopyTo(currP.bestPosition, 0); * currP.bestError = currP.error; * * if (currP.error < bestGlobalError) //przypadkowe trafienie w globalne minimum? * { * bestGlobalError = currP.error; * bestGlobalPosition=currP.pozycja; * } * } * * } ++epoch; * } // while * * // Rój po przejściu wszystkich iteracji * for (int i = 0; i < swarm.Length; ++i) * Console.WriteLine(swarm[i].ToString()); * * double result; * result=bestGlobalPosition; * return result; * // Solve * } * * * private void ParticleSwarm() * { * Console.WriteLine("\nSetting problem dimension to " + dim); * Console.WriteLine("Setting numParticles = " + numParticles); * Console.WriteLine("Setting maxEpochs = " + maxEpochs); * Console.WriteLine("Setting early exit error = " + exitError.ToString("F4")); * Console.WriteLine("Setting minX, maxX = " + minX.ToString("F1") + " " + maxX.ToString("F1")); * * double bestPosition = Solve(dim, numParticles, minX, maxX, maxEpochs, exitError); * double bestError = Error(bestPosition); * * Console.WriteLine("Best position/solution found:"); * * Console.Write("x" + " = "); * Console.WriteLine(bestPosition.ToString("F6") + " "); * * Console.WriteLine(""); * Console.Write("Final best error = "); * Console.WriteLine(bestError.ToString("F5")); * } */ public void ShowParticleMove(object obj) { List <Populacja> list = (List <Populacja>)obj; int i = 0; foreach (Populacja item in list) { surface = new ILSurface(data); surface.Fill.Markable = false; surface.Wireframe.Markable = false; this.ShowParticleOnGraph(item, 8); //this.ShowGraphChart(item); //this.ShowCharts(item); //this.RefreshModel(); if (i < nrIteracji) { int k = i + 1; for (int j = 0; j < item.NajlepszaPozycja.Length; ++j) { Invoke(new Action(() => richTextBox1.AppendText("Iteracja: " + k.ToString() + " x" + "[" + j + "]" + " " + item.NajlepszaPozycja[j] + "\n"))); } Invoke(new Action(() => richTextBox1.AppendText(" Minimum: " + item.NajlepszaFitness + "\n"))); Invoke(new Action(() => richTextBox1.ScrollToCaret())); } // Thread.Sleep(1000); if (_threadPaused) { wh.WaitOne(); } ++i; } //Invoke(new Action(() => playPausePictureBox.Visible = false)); }
private void RepresentData() { ThreadSafeOperations.SetText(lblFileName, dataFileName, false); ILInArray <double> dataValues = dmDataToShow.ToArray(); ILScene scene = new ILScene(); ILPlotCube currSurfPlotCube = new ILPlotCube(); currSurfPlotCube.TwoDMode = false; ILSurface surf = new ILSurface(dataValues); surf.UseLighting = true; surf.Colormap = Colormaps.Jet; 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); //scene.First<ILSurface>().MouseClick += (s, arg) => //{ // // we start at the mouse event target -> this will be the // // surface group node (the parent of "Fill" and "Wireframe") // var group = arg.Target.Parent; // if (group != null) // { // // walk up to the next camera node // Matrix4 trans = group.Transform; // while (!(group is ILCamera) && group != null) // { // group = group.Parent; // // collect all nodes on the path up // trans = group.Transform * trans; // } // if (group != null && (group is ILCamera)) // { // // convert args.LocationF to world coords // // The Z coord is not provided by the mouse! -> choose arbitrary value // var pos = new Vector3(arg.LocationF.X * 2 - 1, arg.LocationF.Y * -2 + 1, 0); // // invert the matrix. // trans = Matrix4.Invert(trans); // // trans now converts from the world coord system (at the camera) to // // the local coord system in the 'target' group node (surface). // // In order to transform the mouse (viewport) position, we // // left multiply the transformation matrix. // pos = trans * pos; // // view result in the window title // //Text = "Model Position: " + pos.ToString(); // ThreadSafeOperations.SetText(lblStatus, pos.ToString(), false); // } // } //}; ilPanel1.Scene = scene; }
private void UpdatePlotEy(int iteration) { var dvalues = (from node in net.Nodes orderby node.j ascending orderby node.i ascending select (node.GetEy(node, iteration))).ToArray(); var values = ILMath.tosingle((ILArray<double>)dvalues); values = ILMath.reshape(values, new int[] { net.shape[0], net.shape[1] }); double time = iteration * net.dT * 1E10; int T = Convert.ToInt32(Math.Floor(time)); maxVEy = (maxVEy < Convert.ToSingle(Math.Round(dvalues.Max(), 2))) ? Convert.ToSingle(Math.Round(dvalues.Max(), 2)) : maxVEy; ResultSeekerEy.ToolTip = string.Format("Iteration(k):{0} - Period(T):{1} - Max. Value:{2}", iteration, T, maxVEy); plotEy.Children.Clear(); var signal = ILMath.ones<float>(10, 10); ILSurface surf = new ILSurface(values) { Wireframe = { Color = System.Drawing.Color.FromArgb(50, 60, 60, 60) }, Colormap = Colormaps.Jet, }; plotEy.Add(surf); //plotEy.Limits.Set(new Vector3(0, 0, -maxVEy), // new Vector3(net.shape[1], net.shape[0], maxVEy)); ilPanelEy.Refresh(); }
public MainWindow() { InitializeComponent(); CBMat.ItemsSource = net.matList.Where(mat => mat.Name != ""); Designer.MatList.ItemsSource = net.matList.Where(mat => mat.Name != ""); Designer.TrackNode += Designer_TrackNode; CBMode.Items.Add("Paralelo"); CBMode.Items.Add("Série"); DGMatList.ItemsSource = net.matList; DGMatList.RowEditEnding += DGMatList_RowEditEnding; var scene = new ILScene(); plot = new ILPlotCube(twoDMode: false); scene.Add(plot); var signal = ILMath.ones<float>(10, 10); ILSurface surf = new ILSurface(signal) { Wireframe = { Color = System.Drawing.Color.FromArgb(50, 60, 60, 60) }, Colormap = Colormaps.Jet, }; plot.AllowPan = false; plot.AllowZoom = false; plot.Projection = Projection.Orthographic; plot.Position = new Vector3(1, 3, .5); plot.AllowRotation = false; plot.Add(surf); scene.First<ILPlotCube>().AspectRatioMode = AspectRatioMode.MaintainRatios; scene.First<ILPlotCube>().Rotation = Matrix4.Rotation(new Vector3(0.1, 0, 0), ILMath.pi / 2); ilPanel.Scene.Add(scene); ResultSeeker.ValueChanged += ResultSeeker_ValueChanged; var sceneHx = new ILScene(); plotHx = new ILPlotCube(twoDMode: false); sceneHx.Add(plotHx); var signalHx = ILMath.ones<float>(10, 10); ILSurface surfHx = new ILSurface(signalHx) { Wireframe = { Color = System.Drawing.Color.FromArgb(50, 60, 60, 60) }, Colormap = Colormaps.Jet, }; plotHx.Projection = Projection.Orthographic; plotHx.Position = new Vector3(1, 3, .5); plotHx.AllowRotation = false; plotHx.Add(surfHx); sceneHx.First<ILPlotCube>().AspectRatioMode = AspectRatioMode.MaintainRatios; sceneHx.First<ILPlotCube>().Rotation = Matrix4.Rotation(new Vector3(0.1, 0, 0), ILMath.pi / 2); ilPanelHx.Scene.Add(sceneHx); ResultSeekerHx.ValueChanged += ResultSeekerHx_ValueChanged; var sceneHy = new ILScene(); plotHy = new ILPlotCube(twoDMode: false); sceneHy.Add(plotHy); var signalHy = ILMath.ones<float>(10, 10); ILSurface surfHy = new ILSurface(signalHy) { Wireframe = { Color = System.Drawing.Color.FromArgb(50, 60, 60, 60) }, Colormap = Colormaps.Jet, }; plotHy.Projection = Projection.Orthographic; plotHy.Position = new Vector3(1, 3, .5); plotHy.AllowRotation = false; plotHy.Add(surfHy); sceneHy.First<ILPlotCube>().AspectRatioMode = AspectRatioMode.MaintainRatios; sceneHy.First<ILPlotCube>().Rotation = Matrix4.Rotation(new Vector3(0.1, 0, 0), ILMath.pi / 2); ilPanelHy.Scene.Add(sceneHy); ResultSeekerHy.ValueChanged += ResultSeekerHy_ValueChanged; var sceneHz = new ILScene(); plotHz = new ILPlotCube(twoDMode: false); sceneHz.Add(plotHz); var signalHz = ILMath.ones<float>(10, 10); ILSurface surfHz = new ILSurface(signalHz) { Wireframe = { Color = System.Drawing.Color.FromArgb(50, 60, 60, 60) }, Colormap = Colormaps.Jet, }; plotHz.Projection = Projection.Orthographic; plotHz.Position = new Vector3(1, 3, .5); //plotHz.AllowRotation = false; plotHz.Add(surfHz); sceneHz.First<ILPlotCube>().AspectRatioMode = AspectRatioMode.MaintainRatios; sceneHz.First<ILPlotCube>().Rotation = Matrix4.Rotation(new Vector3(0.1, 0, 0), ILMath.pi / 2); ilPanelHz.Scene.Add(sceneHz); ResultSeekerHz.ValueChanged += ResultSeekerHz_ValueChanged; var sceneEx = new ILScene(); plotEx = new ILPlotCube(twoDMode: false); sceneEx.Add(plotEx); var signalEx = ILMath.ones<float>(10, 10); ILSurface surfEx = new ILSurface(signalEx) { Wireframe = { Color = System.Drawing.Color.FromArgb(50, 60, 60, 60) }, Colormap = Colormaps.Jet, }; plotEx.Projection = Projection.Orthographic; plotEx.Position = new Vector3(1, 3, .5); //plotEx.AllowRotation = false; plotEx.Add(surfEx); sceneEx.First<ILPlotCube>().AspectRatioMode = AspectRatioMode.MaintainRatios; sceneEx.First<ILPlotCube>().Rotation = Matrix4.Rotation(new Vector3(0.1, 0, 0), ILMath.pi / 2); ilPanelEx.Scene.Add(sceneEx); ResultSeekerEx.ValueChanged += ResultSeekerEx_ValueChanged; var sceneEy = new ILScene(); plotEy = new ILPlotCube(twoDMode: false); sceneEy.Add(plotEy); var signalEy = ILMath.ones<float>(10, 10); ILSurface surfEy = new ILSurface(signalEy) { Wireframe = { Color = System.Drawing.Color.FromArgb(50, 60, 60, 60) }, Colormap = Colormaps.Jet, }; plotEy.Projection = Projection.Orthographic; plotEy.Position = new Vector3(1, 3, .5); //plotEy.AllowRotation = false; plotEy.Add(surfEy); sceneHy.First<ILPlotCube>().AspectRatioMode = AspectRatioMode.MaintainRatios; sceneHy.First<ILPlotCube>().Rotation = Matrix4.Rotation(new Vector3(0.1, 0, 0), ILMath.pi / 2); ilPanelEy.Scene.Add(sceneEy); ResultSeekerEy.ValueChanged += ResultSeekerEy_ValueChanged; }
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; }
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; }
public void SetSurface() { points = new ILPoints(); points.Size = 10; points.Color = null; scene = new ILScene(); plotCube = new ILPlotCube(twoDMode: false); surface = new ILSurface( (x, y) => { return Calculate(new double[] { x, y }); }, xmin: Min, xmax: Max, xlen: 100, ymin: YMin, ymax: YMax, ylen: 100, colormap: Colormaps.ILNumerics ); plotCube.Add(surface); }
private static string GetSurfaceLabelFromLegend(ILSurface source, ILPanel panel) { int index = GetNodeIndex(panel, source); var legend = panel.Scene.First<ILLegend>(); if (legend != null) { // Get text from ILLegendItem at the index if (legend.Items.Children.Count() > index) return String.Format("{0} (\"{1}\")", ILSurface.SurfaceDefaultTag, legend.Items.Find<ILLegendItem>().ElementAt(index).Text); } return null; }