public static IDataSource2D<Vector> CreateSectionXZ(this IUniformDataSource3D<Vector3D> dataSource, double ratio) { if (dataSource == null) throw new ArgumentNullException("dataSource"); if (ratio < 0 || ratio > 1) throw new IndexOutOfRangeException("ratio should be in [0..1]."); int y0 = (int)Math.Floor(dataSource.Height * ratio); int y1 = Math.Min(y0 + 1, dataSource.Height - 1); double yRatio = dataSource.Height * ratio - y0; if (yRatio < 0 || yRatio > 1) throw new ArgumentOutOfRangeException(); int width = dataSource.Width; int depth = dataSource.Depth; var data = dataSource.Data; Vector[,] dataArray = new Vector[width, depth]; for (int ix = 0; ix < width; ix++) { for (int iz = 0; iz < depth; iz++) { Vector3D vec3D = data[ix, y0, iz] * (1 - yRatio) + data[ix, y1, iz] * yRatio; dataArray[ix, iz] = new Vector(vec3D.X, vec3D.Z); } } NonUniformDataSource2D<Vector> result = new NonUniformDataSource2D<Vector>(dataSource.XCoordinates, dataSource.ZCoordinates, dataArray); return result; }
public static IDataSource2D<Vector> CreateSectionXY(this IUniformDataSource3D<Vector3D> dataSource, double ratio) { if (dataSource == null) throw new ArgumentNullException("dataSource"); if (ratio < 0 || ratio > 1) throw new IndexOutOfRangeException("ratio should be in [0..1]."); int z0 = (int)Math.Floor(dataSource.Depth * ratio); int z1 = Math.Min(z0 + 1, dataSource.Depth - 1); double zRatio = dataSource.Depth * ratio - z0; if (zRatio < 0 || zRatio > 1) throw new ArgumentOutOfRangeException(); int width = dataSource.Width; int height = dataSource.Height; var data = dataSource.Data; Vector[,] dataArray = new Vector[width, height]; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { Vector3D vec3D = data[ix, iy, z0] * (1 - zRatio) + data[ix, iy, z1] * zRatio; dataArray[ix, iy] = new Vector(vec3D.X, vec3D.Y); } } NonUniformDataSource2D<Vector> result = new NonUniformDataSource2D<Vector>(dataSource.XCoordinates, dataSource.YCoordinates, dataArray); return result; }
private static IDataSource2D <Vector2> CreateField() { double[] xs = new double[size]; double[] ys = new double[size]; Vector2[,] data; //CreateCircularField(data); data = CreateField( (x, y) => (x / 40) % 2 - (y / 40) % 2 == 0 ? new Vector2(1, 0) : new Vector2(0, 1) //(x, y) => CreateCircularField(x, y) //(x, y) => //{ // Vector2 result; // double xc = x - size / 2; // double yc = y - size / 2; // if (xc != 0) // { // double beta = Math.Sqrt(1.0 / (1 + yc * yc / (xc * xc))); // double alpha = -beta * yc / xc; // result = new Vector2((float)alpha, (float)beta); // } // else // { // double alpha = Math.Sqrt(1.0 / (1 + xc * xc / (yc * yc))); // double beta = -alpha * xc / yc; // result = new Vector2((float)alpha, (float)beta); // } // if (Double.IsNaN(result.X)) // { // result = new Vector2(0, 0); // } // result *= 2; // return result; //} //(x, y) => ((int)(x / 20)) % 2 == 0 && ((int)(y / 20)) % 2 == 0 ? new Vector2(1, 0) : new Vector2(0, 1) //(x, y) => new Vector2((float)Math.Sin(x / 10.0), (float)Math.Cos(y / 10.0)) //(x, y) => new Vector2((float)Math.Sin(x/10), y) //(x, y) => new Vector2((float)((x - 10) / (y - 12.1)), (float)((x + 12) / (y - 14.2))) ); NonUniformDataSource2D <Vector2> dataSource = new NonUniformDataSource2D <Vector2>(xs, ys, data); return(dataSource); }
private void Window_Loaded(object sender, RoutedEventArgs e) { Vector[,] data = //CreateCheсkerboard(); //DataSource2DHelper.CreateVectorData(width, height, (ix, iy) => new Vector(Math.Sin(((double)ix) / 30), Math.Cos(((double)iy) / 30))); //CreateCircleField(); CreateCircleField2(); //CreatePotentialField(); double[] xs = Enumerable.Range(0, width).Select(i => (double)i).ToArray(); double[] ys = Enumerable.Range(0, height).Select(i => (double)i).ToArray(); var dataSource = new NonUniformDataSource2D<Vector>(xs, ys, data); DataContext = dataSource; }
private void Window_Loaded(object sender, RoutedEventArgs e) { Vector[,] data = //CreateCheсkerboard(); //DataSource2DHelper.CreateVectorData(width, height, (ix, iy) => new Vector(Math.Sin(((double)ix) / 30), Math.Cos(((double)iy) / 30))); //CreateCircleField(); CreateCircleField2(); //CreatePotentialField(); double[] xs = Enumerable.Range(0, width).Select(i => (double)i).ToArray(); double[] ys = Enumerable.Range(0, height).Select(i => (double)i).ToArray(); var dataSource = new NonUniformDataSource2D <Vector>(xs, ys, data); DataContext = dataSource; }
public ColorMapDataSource(NonUniformDataSource2D<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.minT = minT; this.maxT = maxT; this.field = field; //colorMapHelper = new ColorMapHelper(this.field, null); isWarped = false; }
private void Window_Loaded(object sender, RoutedEventArgs e) { int width = 200; int height = 200; Vector[,] data = DataSource2DHelper.CreateVectorData(width, height, (x, y) => ((int)(x / 40)) % 2 == 0 && ((int)(y / 40)) % 2 == 0 ? new Vector(1, 0) : new Vector(0, 1)); //DataSource2DHelper.CreateVectorData(width, height, (ix, iy) => new Vector(Math.Sin(((double)ix) / 30), Math.Cos(((double)iy) / 30))); //DataSource2DHelper.CreateVectorData(width, height, (x, y) => //{ // Vector result; // double xc = x - width / 2; // double yc = y - height / 2; // if (xc != 0) // { // double beta = Math.Sqrt(1.0 / (1 + yc * yc / (xc * xc))); // double alpha = -beta * yc / xc; // result = new Vector(alpha, beta); // } // else // { // double alpha = Math.Sqrt(1.0 / (1 + xc * xc / (yc * yc))); // double beta = -alpha * xc / yc; // result = new Vector(alpha, beta); // } // if (Double.IsNaN(result.X)) // { // result = new Vector(0, 0); // } // return result; //}); double[] xs = Enumerable.Range(0, width).Select(i => (double)i).ToArray(); double[] ys = Enumerable.Range(0, height).Select(i => (double)i).ToArray(); var dataSource = new NonUniformDataSource2D <Vector>(xs, ys, data); DataContext = dataSource; }
public ColorMapDataSource(NonUniformDataSource2D <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.minT = minT; this.maxT = maxT; this.field = field; //colorMapHelper = new ColorMapHelper(this.field, null); isWarped = false; }
public static IDataSource2D <Vector> CreateSectionXZ(this IUniformDataSource3D <Vector3D> dataSource, double ratio) { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } if (ratio < 0 || ratio > 1) { throw new IndexOutOfRangeException("ratio should be in [0..1]."); } int y0 = (int)Math.Floor(dataSource.Height * ratio); int y1 = Math.Min(y0 + 1, dataSource.Height - 1); double yRatio = dataSource.Depth * ratio - y0; if (yRatio < 0 || yRatio > 1) { throw new ArgumentOutOfRangeException(); } int width = dataSource.Width; int depth = dataSource.Depth; var data = dataSource.Data; Vector[,] dataArray = new Vector[width, depth]; for (int ix = 0; ix < width; ix++) { for (int iz = 0; iz < depth; iz++) { Vector3D vec3D = data[ix, y0, iz] * (1 - yRatio) + data[ix, y1, iz] * yRatio; dataArray[ix, iz] = new Vector(vec3D.X, vec3D.Z); } } NonUniformDataSource2D <Vector> result = new NonUniformDataSource2D <Vector>(dataSource.XCoordinates, dataSource.ZCoordinates, dataArray); return(result); }
public static IDataSource2D <Vector> CreateSectionYZ(this IUniformDataSource3D <Vector3D> dataSource, double ratio) { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } if (ratio < 0 || ratio > 1) { throw new IndexOutOfRangeException("ratio should be in [0..1]."); } int x0 = (int)Math.Floor(dataSource.Width * ratio); int x1 = Math.Min(x0 + 1, dataSource.Width - 1); double xRatio = dataSource.Width * ratio - x0; if (xRatio < 0 || xRatio > 1) { throw new ArgumentOutOfRangeException(); } int height = dataSource.Height; int depth = dataSource.Depth; var data = dataSource.Data; Vector[,] dataArray = new Vector[height, depth]; for (int iy = 0; iy < height; iy++) { for (int iz = 0; iz < depth; iz++) { Vector3D vec3D = data[x0, iy, iz] * (1 - xRatio) + data[x1, iy, iz] * xRatio; dataArray[iy, iz] = new Vector(vec3D.Y, vec3D.Z); } } NonUniformDataSource2D <Vector> result = new NonUniformDataSource2D <Vector>(dataSource.YCoordinates, dataSource.ZCoordinates, dataArray); return(result); }
private void Window_Loaded(object sender, RoutedEventArgs e) { int width = 200; int height = 200; Vector[,] data = DataSource2DHelper.CreateVectorData(width, height, (x, y) => ((int)(x / 40)) % 2 == 0 && ((int)(y / 40)) % 2 == 0 ? new Vector(1, 0) : new Vector(0, 1)); //DataSource2DHelper.CreateVectorData(width, height, (ix, iy) => new Vector(Math.Sin(((double)ix) / 30), Math.Cos(((double)iy) / 30))); //DataSource2DHelper.CreateVectorData(width, height, (x, y) => //{ // Vector result; // double xc = x - width / 2; // double yc = y - height / 2; // if (xc != 0) // { // double beta = Math.Sqrt(1.0 / (1 + yc * yc / (xc * xc))); // double alpha = -beta * yc / xc; // result = new Vector(alpha, beta); // } // else // { // double alpha = Math.Sqrt(1.0 / (1 + xc * xc / (yc * yc))); // double beta = -alpha * xc / yc; // result = new Vector(alpha, beta); // } // if (Double.IsNaN(result.X)) // { // result = new Vector(0, 0); // } // return result; //}); double[] xs = Enumerable.Range(0, width).Select(i => (double)i).ToArray(); double[] ys = Enumerable.Range(0, height).Select(i => (double)i).ToArray(); var dataSource = new NonUniformDataSource2D<Vector>(xs, ys, data); DataContext = dataSource; }
public static IDataSource2D <Vector> CreateSectionXY(this IUniformDataSource3D <Vector3D> dataSource, double ratio) { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } if (ratio < 0 || ratio > 1) { throw new IndexOutOfRangeException("ratio should be in [0..1]."); } int z0 = (int)Math.Floor(dataSource.Depth * ratio); int z1 = Math.Min(z0 + 1, dataSource.Depth - 1); double zRatio = dataSource.Depth * ratio - z0; if (zRatio < 0 || zRatio > 1) { throw new ArgumentOutOfRangeException(); } int width = dataSource.Width; int height = dataSource.Height; var data = dataSource.Data; Vector[,] dataArray = new Vector[width, height]; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { Vector3D vec3D = data[ix, iy, z0] * (1 - zRatio) + data[ix, iy, z1] * zRatio; dataArray[ix, iy] = new Vector(vec3D.X, vec3D.Y); } } NonUniformDataSource2D <Vector> result = new NonUniformDataSource2D <Vector>(dataSource.XCoordinates, dataSource.YCoordinates, dataArray); return(result); }
public ColorMapHelper(NonUniformDataSource2D <double> field, Box2 regionBox, double minT, double maxT) { this.minT = minT; this.maxT = maxT; this.gridBox = new GeoRect( Math.Min(field.X[0], field.X[field.Width - 1]), Math.Min(field.Y[0], field.Y[field.Height - 1]), Math.Abs(field.X[field.Width - 1] - field.X[0]), Math.Abs(field.Y[field.Height - 1] - field.Y[0])); 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); } palette = new LinearPalette(swm.Colors.Blue, swm.Colors.Green, swm.Colors.Red); this.field = field; }
public ColorMapHelper(NonUniformDataSource2D<double> field, Box2 regionBox, double minT, double maxT) { this.minT = minT; this.maxT = maxT; this.gridBox = new GeoRect( Math.Min(field.X[0], field.X[field.Width - 1]), Math.Min(field.Y[0], field.Y[field.Height - 1]), Math.Abs(field.X[field.Width - 1] - field.X[0]), Math.Abs(field.Y[field.Height - 1] - field.Y[0])); 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); } palette = new LinearPalette(swm.Colors.Blue, swm.Colors.Green, swm.Colors.Red); this.field = field; }
public static IDataSource2D<Vector> CreateSectionYZ(this IUniformDataSource3D<Vector3D> dataSource, double ratio) { if (dataSource == null) throw new ArgumentNullException("dataSource"); if (ratio < 0 || ratio > 1) throw new IndexOutOfRangeException("ratio should be in [0..1]."); int x0 = (int)Math.Floor(dataSource.Width * ratio); int x1 = Math.Min(x0 + 1, dataSource.Width - 1); double xRatio = dataSource.Width * ratio - x0; if (xRatio < 0 || xRatio > 1) throw new ArgumentOutOfRangeException(); int height = dataSource.Height; int depth = dataSource.Depth; var data = dataSource.Data; Vector[,] dataArray = new Vector[height, depth]; for (int iy = 0; iy < height; iy++) { for (int iz = 0; iz < depth; iz++) { Vector3D vec3D = data[x0, iy, iz] * (1 - xRatio) + data[x1, iy, iz] * xRatio; dataArray[iy, iz] = new Vector(vec3D.Y, vec3D.Z); } } NonUniformDataSource2D<Vector> result = new NonUniformDataSource2D<Vector>(dataSource.YCoordinates, dataSource.ZCoordinates, dataArray); return result; }
private object AnalyzeData(object sourceData) { if (sourceData is NonUniformDataSource2D<double>) { NonUniformDataSource2D<double> field = sourceData as NonUniformDataSource2D<double>; double[] lats = new double[field.Height]; double[] lons = new double[field.Width]; double[,] data = new double[field.Width, field.Height]; if (field.X[field.Width - 1] < field.X[0]) { if (field.Y[field.Height - 1] < field.Y[0]) { for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { lats[j] = field.Y[field.Height - 1 - j]; lons[i] = field.X[field.Width - 1 - i]; data[i, j] = field.Data[field.Width - 1 - i, field.Height - 1 - j]; } } field = new NonUniformDataSource2D<double>(data, lats, lons); } else { for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { lats[j] = field.Y[j]; lons[i] = field.X[field.Width - 1 - i]; data[i, j] = field.Data[field.Width - 1 - i, j]; } } field = new NonUniformDataSource2D<double>(data, lats, lons); } } else { if (field.Y[field.Height - 1] < field.Y[0]) { for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { lats[j] = field.Y[field.Height - 1 - j]; lons[i] = field.X[i]; data[i, j] = field.Data[i, field.Height - 1 - j]; } } field = new NonUniformDataSource2D<double>(data, lats, lons); } } int workIndex = field.Width; for (int i = 0; i < field.Width; i++) { if (field.X[i] > 180) { workIndex = i; break; } } if (workIndex < field.Width) { double[] lats2 = new double[field.Height]; double[] lons2 = new double[field.Width]; double[,] data2 = new double[field.Width, field.Height]; for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { if (i < field.Width + 1 - workIndex) { lons2[i] = field.X[workIndex + i - 1] - 360; lats2[j] = field.Y[j]; data2[i, j] = field.Data[workIndex + i - 1, j]; } else { lons2[i] = field.X[i - (field.Width + 1 - workIndex)]; lats2[j] = field.Y[j]; data2[i, j] = field.Data[i - (field.Width + 1 - workIndex), j]; } } } field = new NonUniformDataSource2D<double>(data2, lats2, lons2); TryToCircle(ref field); } return field; } else return sourceData; }
private static IDataSource2D<Vector2> CreateField() { double[] xs = new double[size]; double[] ys = new double[size]; Vector2[,] data; //CreateCircularField(data); data = CreateField( (x, y) => (x / 40) % 2 - (y / 40) % 2 == 0 ? new Vector2(1, 0) : new Vector2(0, 1) //(x, y) => CreateCircularField(x, y) //(x, y) => //{ // Vector2 result; // double xc = x - size / 2; // double yc = y - size / 2; // if (xc != 0) // { // double beta = Math.Sqrt(1.0 / (1 + yc * yc / (xc * xc))); // double alpha = -beta * yc / xc; // result = new Vector2((float)alpha, (float)beta); // } // else // { // double alpha = Math.Sqrt(1.0 / (1 + xc * xc / (yc * yc))); // double beta = -alpha * xc / yc; // result = new Vector2((float)alpha, (float)beta); // } // if (Double.IsNaN(result.X)) // { // result = new Vector2(0, 0); // } // result *= 2; // return result; //} //(x, y) => ((int)(x / 20)) % 2 == 0 && ((int)(y / 20)) % 2 == 0 ? new Vector2(1, 0) : new Vector2(0, 1) //(x, y) => new Vector2((float)Math.Sin(x / 10.0), (float)Math.Cos(y / 10.0)) //(x, y) => new Vector2((float)Math.Sin(x/10), y) //(x, y) => new Vector2((float)((x - 10) / (y - 12.1)), (float)((x + 12) / (y - 14.2))) ); NonUniformDataSource2D<Vector2> dataSource = new NonUniformDataSource2D<Vector2>(xs, ys, data); return dataSource; }
private void TryToCircle(ref NonUniformDataSource2D<double> nfield) { double[] lons = nfield.X; if (lons.Length <= 2) return; if (lons[0] > lons[1]) return; // we're supporting now only increaing values double delta0 = lons[1] - lons[0]; double delta1 = 360.0 - (lons[lons.Length - 1] - lons[0]); if (delta1 > 0 && (delta1 <= 1.2 * delta0)) { // Hooray! Circling it.... double[] lats = nfield.Y; double[,] data = new double[nfield.Width + 1, nfield.Height]; double[,] sdata = nfield.Data; Array.Resize(ref lons, lons.Length + 1); lons[lons.Length - 1] = lons[0] + 360.0; int i; for (i = 0; i < lons.Length - 1; i++) for (int j = 0; j < lats.Length; j++) data[i, j] = sdata[i, j]; for (int j = 0; j < lats.Length; j++) data[i, j] = sdata[0, j]; nfield = new NonUniformDataSource2D<double>(data,lats,lons); } }