public static DataSource Create(Func <int, int, Point> gridFunc, Func <int, int, Vector> dataFunc, int width = 100, int height = 100) { if (gridFunc == null) { throw new ArgumentNullException("gridFunc"); } if (dataFunc == null) { throw new ArgumentNullException("dataFunc"); } if (width < 2) { throw new ArgumentOutOfRangeException("width"); } if (height < 2) { throw new ArgumentOutOfRangeException("height"); } Point[,] grid = new Point[width, height]; Vector[,] data = new Vector[width, height]; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { grid[ix, iy] = gridFunc(ix, iy); data[ix, iy] = dataFunc(ix, iy); } } WarpedDataSource2D <Vector> dataSource = new WarpedDataSource2D <Vector>(data, grid); return(dataSource); }
public static DataSource Create(Func<int, int, Point> gridFunc, Func<int, int, Vector> dataFunc, int width = 100, int height = 100) { if (gridFunc == null) throw new ArgumentNullException("gridFunc"); if (dataFunc == null) throw new ArgumentNullException("dataFunc"); if (width < 2) throw new ArgumentOutOfRangeException("width"); if (height < 2) throw new ArgumentOutOfRangeException("height"); Point[,] grid = new Point[width, height]; Vector[,] data = new Vector[width, height]; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { grid[ix, iy] = gridFunc(ix, iy); data[ix, iy] = dataFunc(ix, iy); } } WarpedDataSource2D<Vector> dataSource = new WarpedDataSource2D<Vector>(data, grid); return dataSource; }
public ColorMapHelper(WarpedDataSource2D <double> field, Box2 regionBox, double minT, double maxT) { this.minT = minT; this.maxT = maxT; warpedField = field; if (regionBox != null) { this.tileBox = new GeoRect( regionBox.MinCoordinate.X, regionBox.MinCoordinate.Y, regionBox.MaxCoordinate.X - regionBox.MinCoordinate.X, regionBox.MaxCoordinate.Y - regionBox.MinCoordinate.Y); this.regionBox = regionBox; } System.Windows.Point[,] grid = warpedField.Grid; Coordinate2D minCoordinate = new Coordinate2D(grid[0, 0].X, grid[0, 0].Y); Coordinate2D maxCoordinate = new Coordinate2D(grid[warpedField.Width - 1, warpedField.Height - 1].X, grid[warpedField.Width - 1, warpedField.Height - 1].Y); for (int j = 0; j < warpedField.Height; j++) { for (int i = 0; i < warpedField.Width; i++) { if (grid[i, j].X < minCoordinate.X) { minCoordinate.X = grid[i, j].X; } if (grid[i, j].X > maxCoordinate.X) { maxCoordinate.X = grid[i, j].X; } if (grid[i, j].Y < minCoordinate.Y) { minCoordinate.Y = grid[i, j].Y; } if (grid[i, j].Y > maxCoordinate.Y) { maxCoordinate.Y = grid[i, j].Y; } } } gridBox = new GeoRect( minCoordinate.X, minCoordinate.Y, maxCoordinate.X - minCoordinate.X, maxCoordinate.Y - minCoordinate.Y); palette = new LinearPalette(swm.Colors.Blue, swm.Colors.Green, swm.Colors.Red); workingTriangle = new RasterTriangle(); }
private WarpedDataSource2D<Vector> LoadVectorField() { Random rnd = new Random(); const int count = 20; var grid = DataSource2DHelper.CreateUniformGrid(count, count, 1, 1); var data = DataSource2DHelper.CreateVectorData(count, count, (x, y) => { const double scale = Math.PI; return new Vector(Math.Sin(scale * rnd.NextDouble()), Math.Sin(scale * rnd.NextDouble())) / count / 2; }); WarpedDataSource2D<Vector> dataSource = new WarpedDataSource2D<Vector>(data, grid); return dataSource; }
public ColorMapHelper(WarpedDataSource2D<double> field, Box2 regionBox, double minT, double maxT) { this.minT = minT; this.maxT = maxT; warpedField = field; if (regionBox != null) { this.tileBox = new GeoRect( regionBox.MinCoordinate.X, regionBox.MinCoordinate.Y, regionBox.MaxCoordinate.X - regionBox.MinCoordinate.X, regionBox.MaxCoordinate.Y - regionBox.MinCoordinate.Y); this.regionBox = regionBox; } System.Windows.Point[,] grid = warpedField.Grid; Coordinate2D minCoordinate = new Coordinate2D(grid[0, 0].X, grid[0, 0].Y); Coordinate2D maxCoordinate = new Coordinate2D(grid[warpedField.Width - 1, warpedField.Height - 1].X, grid[warpedField.Width - 1, warpedField.Height - 1].Y); for (int j = 0; j < warpedField.Height; j++) { for (int i = 0; i < warpedField.Width; i++) { if (grid[i, j].X < minCoordinate.X) minCoordinate.X = grid[i, j].X; if (grid[i, j].X > maxCoordinate.X) maxCoordinate.X = grid[i, j].X; if (grid[i, j].Y < minCoordinate.Y) minCoordinate.Y = grid[i, j].Y; if (grid[i, j].Y > maxCoordinate.Y) maxCoordinate.Y = grid[i, j].Y; } } gridBox = new GeoRect( minCoordinate.X, minCoordinate.Y, maxCoordinate.X - minCoordinate.X, maxCoordinate.Y - minCoordinate.Y); palette = new LinearPalette(swm.Colors.Blue, swm.Colors.Green, swm.Colors.Red); workingTriangle = new RasterTriangle(); }
private WarpedDataSource2D <Vector> LoadVectorField() { Random rnd = new Random(); const int count = 20; var grid = DataSource2DHelper.CreateUniformGrid(count, count, 1, 1); var data = DataSource2DHelper.CreateVectorData(count, count, (x, y) => { const double scale = Math.PI; return(new Vector(Math.Sin(scale * rnd.NextDouble()), Math.Sin(scale * rnd.NextDouble())) / count / 2); }); WarpedDataSource2D <Vector> dataSource = new WarpedDataSource2D <Vector>(data, grid); return(dataSource); }
private void LoadField() { Circuit cir = new Circuit(); cir.ReadCircuit("Circuits/RCL.net"); cir2 = (Circuit)cir.Clone(); cir2.Setup.RemoveAt(0); ComplexPlainAnalysis ac1 = new ComplexPlainAnalysis(); cir2.Setup.Add(ac1); ACSweepSolver.Optimize(cir2); cir2.Solve(); sol1 = (ComplexPlainSolver)ac1.Solver; int Rows = ac1.Points; int Columns = ac1.Points; double[,] data = new double[Rows, Columns]; Point[,] gridData = new Point[Rows, Columns]; MathNet.Numerics.Complex32 W; for (int i = 0; i < Rows; i++) { for (int j = 0; j < Columns; j++) { W = sol1.WfromIndexes[new Tuple <int, int>(i, j)]; foreach (var node in sol1.Voltages[W]) { if (node.Key == "out") { data[i, j] = 20 * Math.Log10(node.Value.Magnitude); //data[i, j] = 180 * node.Value.Phase / Math.PI; gridData[i, j] = new Point(W.Real, W.Imaginary); } } } } WarpedDataSource2D <double> dataSource = new WarpedDataSource2D <double>(data, gridData); isolineGraph.DataSource = dataSource; trackingGraph.DataSource = dataSource; }
public bool CheckIntersection(LatLonAlt location) { if (layers.Count == 0) { return(false); } if (layers[layers.Count - 1] == null) { return(false); } WarpedDataSource2D <double> dataSource = null;//layers[layers.Count - 1].dataSource; if (dataSource == null) { return(false); } double isolineLayer; bool foundVal = Search(dataSource, new Point(location.LongitudeDegrees, location.LatitudeDegrees), out isolineLayer); if (foundVal) { host.Geometry.RemoveGeometry("RunningLine", "rl"); IsolineCollection collection = isolineBuilder.Build(isolineLayer); LevelLine segment = collection.Lines[0]; //runningIsoline.LineColor = palette.GetColor(segment.Value01); //runningIsoline.Segment = segment; //List<Coordinate2D> points = new List<Coordinate2D>(); //points.Add(new Coordinate2D(segment.StartPoint.X, segment.StartPoint.Y)); //foreach (Point point in segment.OtherPoints) //{ // points.Add(new Coordinate2D(point.X, point.Y)); //} //PolyInfo style = PolyInfo.DefaultPolyline; //style.LineColor = palette.GetColor(segment.Value01); //style.LineWidth = 5; //runningLine = new PolylineGeometry("RunningLine", "rl", new Polyline2(Wgs84CoordinateReferenceSystem.Instance, // Coordinate2DCollection.CreateUnsafe(points.ToArray())), style); } return(foundVal); }
private WarpedDataSource2D<double> LoadDataSource() { int size = 10; Point[,] grid = new Point[size, size]; double[,] data = new double[size, size]; for (int iy = 0; iy < size; iy++) { for (int ix = 0; ix < size; ix++) { Point pt = new Point(ix * 0.02, iy * 0.02); grid[ix, iy] = pt; data[ix, iy] = ix + iy; } } WarpedDataSource2D<double> ds = new WarpedDataSource2D<double>(data, grid); return ds; }
public ColorMapDataSource(WarpedDataSource2D<double> field, Host host, double minT, double maxT) : base(Guid.NewGuid()) { OntologySpecification o = this.Ontology.Edit(); o.PrimitiveTypes.Create("RasterPatch", "GeoEntity", typeof(RasterPatch2)); this.UpdateOntology(o); EntitySpecification entitySpec = new EntitySpecification(this.Ontology.EntityTypes["GeoEntity"]); // the default entity type entity = this.EntityAuthorityReference.EntityAuthority.CreateEntity(true, entitySpec); this.host = host; this.wfield = field; this.minT = minT; this.maxT = maxT; //colorMapHelper = new ColorMapHelper(field, null); isWarped = true; }
private WarpedDataSource2D<double> LoadDataSourceRhw() { int size = 100; Point[,] grid = new Point[size, size]; double[,] data = new double[size, size]; for (int iy = 0; iy < size; iy++) { for (int ix = 0; ix < size; ix++) { Point pt = new Point(50 + 50 * ix, 50 + 50 * iy); grid[ix, iy] = pt; data[ix, iy] = Math.Cos(ix / 3) + Math.Sin(iy / 9); } } WarpedDataSource2D<double> ds = new WarpedDataSource2D<double>(data, grid); return ds; }
private WarpedDataSource2D <double> LoadDataSourceRhw() { int size = 100; Point[,] grid = new Point[size, size]; double[,] data = new double[size, size]; for (int iy = 0; iy < size; iy++) { for (int ix = 0; ix < size; ix++) { Point pt = new Point(50 + 50 * ix, 50 + 50 * iy); grid[ix, iy] = pt; data[ix, iy] = Math.Cos(ix / 3) + Math.Sin(iy / 9); } } WarpedDataSource2D <double> ds = new WarpedDataSource2D <double>(data, grid); return(ds); }
public ColorMapDataSource(WarpedDataSource2D <double> field, Host host, double minT, double maxT) : base(Guid.NewGuid()) { OntologySpecification o = this.Ontology.Edit(); o.PrimitiveTypes.Create("RasterPatch", "GeoEntity", typeof(RasterPatch2)); this.UpdateOntology(o); EntitySpecification entitySpec = new EntitySpecification(this.Ontology.EntityTypes["GeoEntity"]); // the default entity type entity = this.EntityAuthorityReference.EntityAuthority.CreateEntity(true, entitySpec); this.host = host; this.wfield = field; this.minT = minT; this.maxT = maxT; //colorMapHelper = new ColorMapHelper(field, null); isWarped = true; }
private WarpedDataSource2D <double> LoadDataSource() { int size = 10; Point[,] grid = new Point[size, size]; double[,] data = new double[size, size]; for (int iy = 0; iy < size; iy++) { for (int ix = 0; ix < size; ix++) { Point pt = new Point(ix * 0.02, iy * 0.02); grid[ix, iy] = pt; data[ix, iy] = ix + iy; } } WarpedDataSource2D <double> ds = new WarpedDataSource2D <double>(data, grid); return(ds); }
private void LoadField() { Circuit cir = new Circuit(); cir.ReadCircuit("Circuits/RCL.net"); cir2 = (Circuit)cir.Clone(); cir2.Setup.RemoveAt(0); ComplexPlainAnalysis ac1 = new ComplexPlainAnalysis(); cir2.Setup.Add(ac1); ACSweepSolver.Optimize(cir2); cir2.Solve(); sol1 = (ComplexPlainSolver)ac1.Solver; int Rows = ac1.Points; int Columns = ac1.Points; double[,] data = new double[Rows, Columns]; Point[,] gridData = new Point[Rows, Columns]; MathNet.Numerics.Complex32 W; for (int i = 0; i < Rows; i++) for (int j = 0; j < Columns; j++) { W = sol1.WfromIndexes[new Tuple<int, int>(i, j)]; foreach (var node in sol1.Voltages[W]) { if (node.Key == "out") { data[i, j] = 20 * Math.Log10(node.Value.Magnitude); //data[i, j] = 180 * node.Value.Phase / Math.PI; gridData[i, j] = new Point(W.Real, W.Imaginary); } } } WarpedDataSource2D<double> dataSource = new WarpedDataSource2D<double>(data, gridData); isolineGraph.DataSource = dataSource; trackingGraph.DataSource = dataSource; }
public static WarpedDataSource2D <double> ReadDataSource() { short min, max; double latMin = -90; double latMax = 90; double lonMin = -180; double lonMax = 180; int width = 512; int height = 512; short[,] elev = ReliefReader.ReadElevationMap(latMin, latMax, (int)width, lonMin, lonMax, (int)height, out min, out max); double[,] data = new double[width, height]; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { data[ix, iy] = elev[ix, iy]; } } Point[,] grid = new Point[width, height]; double xStep = (lonMax - lonMin) / width; double yStep = (latMax - latMin) / height; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { grid[iy, ix] = new Point(lonMin + xStep * ix, latMin + yStep * (height - iy - 1)); } } WarpedDataSource2D <double> dataSource = new WarpedDataSource2D <double>(data, grid); return(dataSource); }
private void LoadField() { List<string> strings = new List<string>(); using (FileStream fs = new FileStream(@"SampleData.txt", FileMode.Open, FileAccess.Read)) { using (StreamReader reader = new StreamReader(fs)) { while (!reader.EndOfStream) { string str = reader.ReadLine(); if (str == "Data:") { // do nothing } else if (str == "Grid:") { // do nothing too } else { strings.Add(str); } } } } // data string[] nums = ParseDataString(strings[0]); int width = nums.Length; int height = strings.Count / 2; CultureInfo culture = new CultureInfo("ru-RU"); double[,] data = new double[width, height]; for (int row = 0; row < height; row++) { nums = ParseDataString(strings[row]); for (int column = 0; column < width; column++) { double d = Double.Parse(nums[column], culture); data[column, row] = d; } } Point[,] gridData = new Point[width, height]; for (int row = 0; row < height; row++) { string str = strings[row + height]; nums = ParseGridString(str); for (int column = 0; column < width; column++) { string[] vecStrs = nums[column].Split(new string[] { "; " }, StringSplitOptions.None); gridData[column, row] = new Point( Double.Parse(vecStrs[0], culture), Double.Parse(vecStrs[1], culture)); } } WarpedDataSource2D<double> dataSource = new WarpedDataSource2D<double>(data, gridData); isolineGraph.DataSource = dataSource; trackingGraph.DataSource = dataSource; Rect visible = dataSource.GetGridBounds(); plotter.Viewport.Visible = visible; }
private void LoadField() { List <string> strings = new List <string>(); using (FileStream fs = new FileStream(@"SampleData.txt", FileMode.Open, FileAccess.Read)) { using (StreamReader reader = new StreamReader(fs)) { while (!reader.EndOfStream) { string str = reader.ReadLine(); if (str == "Data:") { // do nothing } else if (str == "Grid:") { // do nothing too } else { strings.Add(str); } } } } // data string[] nums = ParseDataString(strings[0]); int width = nums.Length; int height = strings.Count / 2; CultureInfo culture = new CultureInfo("ru-RU"); double[,] data = new double[width, height]; for (int row = 0; row < height; row++) { nums = ParseDataString(strings[row]); for (int column = 0; column < width; column++) { double d = Double.Parse(nums[column], culture); data[column, row] = d; } } Point[,] gridData = new Point[width, height]; for (int row = 0; row < height; row++) { string str = strings[row + height]; nums = ParseGridString(str); for (int column = 0; column < width; column++) { string[] vecStrs = nums[column].Split(new string[] { "; " }, StringSplitOptions.None); gridData[column, row] = new Point( Double.Parse(vecStrs[0], culture), Double.Parse(vecStrs[1], culture)); } } WarpedDataSource2D <double> dataSource = new WarpedDataSource2D <double>(data, gridData); isolineGraph.DataSource = dataSource; trackingGraph.DataSource = dataSource; Rect visible = dataSource.GetGridBounds(); plotter.Viewport.Visible = visible; }
private bool Search(WarpedDataSource2D<double> dataSource, Point pt, out double foundVal) { var grid = dataSource.Grid; foundVal = 0; int width = dataSource.Width; int height = dataSource.Height; bool found = false; int i = 0, j = 0; for (i = 0; i < width - 1; i++) { for (j = 0; j < height - 1; j++) { Quad quad = new Quad( grid[i, j], grid[i, j + 1], grid[i + 1, j + 1], grid[i + 1, j]); if (quad.Contains(pt)) { found = true; foundQuad = quad; foundI = i; foundJ = j; break; } } if (found) break; } if (!found) { foundQuad = null; return false; } var data = dataSource.Data; double x = pt.X; double y = pt.Y; Vector2D A = new Vector2D(grid[i, j + 1].X, grid[i, j + 1].Y); // @TODO: in common case add a sorting of points: Vector2D B = new Vector2D(grid[i + 1, j + 1].X, grid[i + 1, j + 1].Y); // maxA ___K___ B Vector2D C = new Vector2D(grid[i + 1, j].X, grid[i + 1, j].Y); // | | Vector2D D = new Vector2D(grid[i, j].X, grid[i, j].Y); // M P N double a = data[i, j + 1]; // | | double b = data[i + 1, j + 1]; // В ___L____Сmin double c = data[i + 1, j]; double d = data[i, j]; Vector2D K, L; double k, l; if (x >= A.X) k = Interpolate(A, B, a, b, K = new Vector2D(x, GetY(A, B, x))); else k = Interpolate(D, A, d, a, K = new Vector2D(x, GetY(D, A, x))); if (x >= C.X) l = Interpolate(C, B, c, b, L = new Vector2D(x, GetY(C, B, x))); else l = Interpolate(D, C, d, c, L = new Vector2D(x, GetY(D, C, x))); foundVal = Interpolate(L, K, l, k, new Vector2D(x, y)); return !Double.IsNaN(foundVal); }
private void Page_Loaded(object sender, RoutedEventArgs e) { WarpedDataSource2D <Vector> vectorField = LoadVectorField(); vectorChart.ItemsSource = vectorField; }
private void LoadField() { var assembly = Assembly.GetExecutingAssembly(); List <string> strings = new List <string>(); using (Stream stream = assembly.GetManifestResourceStream("DynamicDataDisplay.Samples.Demos.v03.Isolines.SampleData.txt")) { using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { string str = reader.ReadLine(); if (str == "Data:") { // do nothing } else if (str == "Grid:") { // do nothing too } else { strings.Add(str); } } } } // data string[] nums = ParseDataString(strings[0]); int width = nums.Length; int height = strings.Count / 2; CultureInfo culture = new CultureInfo("ru-RU"); double[,] data = new double[width, height]; for (int row = 0; row < height; row++) { nums = ParseDataString(strings[row]); for (int column = 0; column < width; column++) { double d = double.Parse(nums[column], culture); data[column, row] = d; } } Point[,] gridData = new Point[width, height]; for (int row = 0; row < height; row++) { string str = strings[row + height]; nums = ParseGridString(str); for (int column = 0; column < width; column++) { string[] vecStrs = nums[column].Split(new string[] { "; " }, StringSplitOptions.None); gridData[column, row] = new Point( double.Parse(vecStrs[0], culture), double.Parse(vecStrs[1], culture)); } } WarpedDataSource2D <double> dataSource = new WarpedDataSource2D <double>(data, gridData); isolineGraph.DataSource = dataSource; trackingGraph.DataSource = dataSource; Rect visible = dataSource.GetGridBounds(); plotter.Viewport.Visible = visible; }
public static WarpedDataSource2D <double> LoadField() { var assembly = Assembly.GetExecutingAssembly(); List <string> strings = new List <string>(); using (Stream stream = assembly.GetManifestResourceStream("IsolineSampleApp.SampleData.txt")) { using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { string str = reader.ReadLine(); if (str == "Data:") { // do nothing } else if (str == "Grid:") { // do nothing too } else { strings.Add(str); } } } } // data string[] nums = ParseDataString(strings[0]); int width = nums.Length; int height = strings.Count / 2; CultureInfo culture = new CultureInfo("ru-RU"); double[,] data = new double[width, height]; for (int row = 0; row < height; row++) { nums = ParseDataString(strings[row]); for (int column = 0; column < width; column++) { double d = Double.Parse(nums[column], culture); data[column, row] = d; } } Point[,] gridData = new Point[width, height]; for (int row = 0; row < height; row++) { string str = strings[row + height]; nums = ParseGridString(str); for (int column = 0; column < width; column++) { string[] vecStrs = nums[column].Split(new string[] { "; " }, StringSplitOptions.None); gridData[column, row] = new Point( Double.Parse(vecStrs[0], culture), Double.Parse(vecStrs[1], culture)); } } WarpedDataSource2D <double> dataSource = new WarpedDataSource2D <double>(data, gridData); return(dataSource); }
public static WarpedDataSource2D<double> LoadField() { var assembly = Assembly.GetExecutingAssembly(); List<string> strings = new List<string>(); using (Stream stream = assembly.GetManifestResourceStream("IsolineSampleApp.SampleData.txt")) { using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { string str = reader.ReadLine(); if (str == "Data:") { // do nothing } else if (str == "Grid:") { // do nothing too } else { strings.Add(str); } } } } // data string[] nums = ParseDataString(strings[0]); int width = nums.Length; int height = strings.Count / 2; CultureInfo culture = new CultureInfo("ru-RU"); double[,] data = new double[width, height]; for (int row = 0; row < height; row++) { nums = ParseDataString(strings[row]); for (int column = 0; column < width; column++) { double d = Double.Parse(nums[column], culture); data[column, row] = d; } } Point[,] gridData = new Point[width, height]; for (int row = 0; row < height; row++) { string str = strings[row + height]; nums = ParseGridString(str); for (int column = 0; column < width; column++) { string[] vecStrs = nums[column].Split(new string[] { "; " }, StringSplitOptions.None); gridData[column, row] = new Point( Double.Parse(vecStrs[0], culture), Double.Parse(vecStrs[1], culture)); } } WarpedDataSource2D<double> dataSource = new WarpedDataSource2D<double>(data, gridData); return dataSource; }
private void LoadField() { var assembly = Assembly.GetExecutingAssembly(); List<string> strings = new List<string>(); using (Stream stream = assembly.GetManifestResourceStream("Microsoft.Research.DynamicDataDisplay.Xbap.Samples.Demos.v03.Isolines.SampleData.txt")) { using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { string str = reader.ReadLine(); if (str == "Data:") { // do nothing } else if (str == "Grid:") { // do nothing too } else { strings.Add(str); } } } } // data string[] nums = ParseDataString(strings[0]); int width = nums.Length; int height = strings.Count / 2; CultureInfo culture = new CultureInfo("ru-RU"); double[,] data = new double[width, height]; for (int row = 0; row < height; row++) { nums = ParseDataString(strings[row]); for (int column = 0; column < width; column++) { double d = Double.Parse(nums[column], culture); data[column, row] = d; } } Point[,] gridData = new Point[width, height]; for (int row = 0; row < height; row++) { string str = strings[row + height]; nums = ParseGridString(str); for (int column = 0; column < width; column++) { string[] vecStrs = nums[column].Split(new string[] { "; " }, StringSplitOptions.None); gridData[column, row] = new Point( Double.Parse(vecStrs[0], culture), Double.Parse(vecStrs[1], culture)); } } WarpedDataSource2D<double> dataSource = new WarpedDataSource2D<double>(data, gridData); isolineGraph.DataSource = dataSource; trackingGraph.DataSource = dataSource; Rect visible = dataSource.GetGridBounds(); plotter.Viewport.Visible = visible; }
private bool Search(WarpedDataSource2D <double> dataSource, Point pt, out double foundVal) { var grid = dataSource.Grid; foundVal = 0; int width = dataSource.Width; int height = dataSource.Height; bool found = false; int i = 0, j = 0; for (i = 0; i < width - 1; i++) { for (j = 0; j < height - 1; j++) { Quad quad = new Quad( grid[i, j], grid[i, j + 1], grid[i + 1, j + 1], grid[i + 1, j]); if (quad.Contains(pt)) { found = true; foundQuad = quad; foundI = i; foundJ = j; break; } } if (found) { break; } } if (!found) { foundQuad = null; return(false); } var data = dataSource.Data; double x = pt.X; double y = pt.Y; Vector2D A = new Vector2D(grid[i, j + 1].X, grid[i, j + 1].Y); // @TODO: in common case add a sorting of points: Vector2D B = new Vector2D(grid[i + 1, j + 1].X, grid[i + 1, j + 1].Y); // maxA ___K___ B Vector2D C = new Vector2D(grid[i + 1, j].X, grid[i + 1, j].Y); // | | Vector2D D = new Vector2D(grid[i, j].X, grid[i, j].Y); // M P N double a = data[i, j + 1]; // | | double b = data[i + 1, j + 1]; // В ___L____Сmin double c = data[i + 1, j]; double d = data[i, j]; Vector2D K, L; double k, l; if (x >= A.X) { k = Interpolate(A, B, a, b, K = new Vector2D(x, GetY(A, B, x))); } else { k = Interpolate(D, A, d, a, K = new Vector2D(x, GetY(D, A, x))); } if (x >= C.X) { l = Interpolate(C, B, c, b, L = new Vector2D(x, GetY(C, B, x))); } else { l = Interpolate(D, C, d, c, L = new Vector2D(x, GetY(D, C, x))); } foundVal = Interpolate(L, K, l, k, new Vector2D(x, y)); return(!Double.IsNaN(foundVal)); }