public static Range <double> GetMinMax(this IDataSource2D <Vector> dataSource, Func <Vector, double> extractor) { double min = Double.PositiveInfinity; double max = Double.NegativeInfinity; var data = dataSource.Data; int width = dataSource.Width; int height = dataSource.Height; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { var vector = data[ix, iy]; var value = extractor(vector); if (value < min) { min = value; } if (value > max) { max = value; } } } if (min > max) { min = max = 0; } return(new Range <double>(min, max)); }
public static Range <double> GetMinMaxLength(this IDataSource2D <Vector> dataSource) { double minLength = double.PositiveInfinity; double maxLength = double.NegativeInfinity; int width = dataSource.Width; int height = dataSource.Height; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { var vector = dataSource.Data[ix, iy]; var length = vector.Length; if (length < minLength) { minLength = length; } if (length > maxLength) { maxLength = length; } } } if (minLength > maxLength) { minLength = maxLength = 0; } return(new Range <double>(minLength, maxLength)); }
protected virtual void DetachDataSource(IDataSource2D <double> dataSource) { if (dataSource != null) { dataSource.Changed -= OnDataSourceChanged; } }
public ProbesDataSource(Guid guid, IDataSource2D <double> field, Host host) : base(guid) { // set up the Ontology, a description of the kind of data we contain. // See DataSource sample for more details. 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.wfield = field; System.Windows.Point[,] grid = wfield.Grid; Coordinate2D minCoordinate = new Coordinate2D(grid[0, 0].X, grid[0, 0].Y); Coordinate2D maxCoordinate = new Coordinate2D(grid[field.Width - 1, field.Height - 1].X, grid[field.Width - 1, field.Height - 1].Y); for (int j = 0; j < field.Height; j++) { for (int i = 0; i < field.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); dataType = DSDataType.TwoDim; this.host = host; probesHelper = new ProbesHelper("ProbeSample.png", false); }
private void OnDataSourceReplaced(IDataSource2D<Vector> prevDataSource, IDataSource2D<Vector> currDataSource) { if (prevDataSource != null) prevDataSource.Changed -= DataSource_OnChanged; if (currDataSource != null) currDataSource.Changed += DataSource_OnChanged; RebuildUI(); }
public GenericDataSource2D(IDataSource2D <T> dataSource) { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } this.dataSource = dataSource; }
public TransformedGridDataSource2D(IDataSource2D <T> child, Func <int, int, Point, Point> gridFunc) : base(child) { if (gridFunc == null) { throw new ArgumentNullException("gridFunc"); } this.gridFunc = gridFunc; }
protected DecoratorDataSource2D(IDataSource2D <T> child) { if (child == null) { throw new ArgumentNullException("child"); } this.child = child; child.Changed += OnChildChanged; }
public VectorToMagnitudeDataSource(IDataSource2D <Vector> dataSource) { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } this.dataSource = dataSource; dataSource.Changed += OnDataSource_Changed; Update(); }
private void AddDataSource(IDataSource2D <double> field, Guid guid) { probesLayers.Add(new ProbesLayer { Guid = guid, IsVisible = true, DataSource = new ProbesDataSource(guid, field, host), LayerID = Guid.NewGuid().ToString(), LayerName = Guid.NewGuid().ToString() }); AddLayerToHost(probesLayers[probesLayers.Count - 1]); }
private void OnDataSourceReplaced(IDataSource2D <Vector> prevDataSource, IDataSource2D <Vector> currDataSource) { if (prevDataSource != null) { prevDataSource.Changed -= DataSource_OnChanged; } if (currDataSource != null) { currDataSource.Changed += DataSource_OnChanged; } RebuildUI(); }
private void OnDataSourceReplaced(IDataSource2D <double> prevDataSource, IDataSource2D <double> currDataSource) { if (prevDataSource != null) { prevDataSource.Changed -= OnDataSourceChanged; } if (currDataSource != null) { currDataSource.Changed += OnDataSourceChanged; } FillVertexBuffer(); }
private void OnDataSourceReplaced(IDataSource2D<double> prevDataSource, IDataSource2D<double> currDataSource) { if (prevDataSource != null) { prevDataSource.Changed -= OnDataSourceChanged; } if (currDataSource != null) { currDataSource.Changed += OnDataSourceChanged; } FillVertexBuffer(); }
public static IDataSource2D <T> ChangeGrid <T>(this IDataSource2D <T> dataSource, Func <int, int, Point> gridFunc) where T : struct { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } if (gridFunc == null) { throw new ArgumentNullException("gridFunc"); } Func <int, int, Point, Point> func = (ix, iy, oldPoint) => gridFunc(ix, iy); return(new TransformedGridDataSource2D <T>(dataSource, func)); }
protected virtual void OnDataSourceChanged(IDataSource2D <double> prevDataSource, IDataSource2D <double> currDataSource) { if (prevDataSource != null) { prevDataSource.Changed -= OnDataSourceChanged; } if (currDataSource != null) { currDataSource.Changed += OnDataSourceChanged; } UpdateDataSource(); CreateUIRepresentation(); RaiseEvent(new RoutedEventArgs(BackgroundRenderer.UpdateRequested)); }
private void OnDataSourceReplaced(IDataSource2D<Vector> prevDataSource, IDataSource2D<Vector> currDataSource) { var dataSource = this.GetValueSync<IDataSource2D<Vector>>(DataSourceProperty); var contentBounds = dataSource.Grid.GetGridBounds(); if (Parent != null) Viewport2D.SetContentBounds(Parent, contentBounds); ViewportPanel.SetViewportBounds(this, contentBounds); int width = currDataSource.Width; int height = currDataSource.Height; bmp = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, null); Source = bmp; Task task = new Task(() => CreateConvolutionBmp(width, height)); task.Start(); }
public static Range <double> GetMinMax(this IDataSource2D <double> dataSource, DataRect area) { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } double min = Double.PositiveInfinity; double max = Double.NegativeInfinity; int width = dataSource.Width; int height = dataSource.Height; var grid = dataSource.Grid; var data = dataSource.Data; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { if (area.Contains(grid[ix, iy])) { var value = data[ix, iy]; if (value < min) { min = value; } if (value > max) { max = value; } } } } if (min < max) { return(new Range <double>(min, max)); } else { return(new Range <double>()); } }
private void OnDataSourceReplaced(IDataSource2D <Vector> prevDataSource, IDataSource2D <Vector> currDataSource) { var dataSource = this.GetValueSync <IDataSource2D <Vector> >(DataSourceProperty); var contentBounds = dataSource.Grid.GetGridBounds(); if (Parent != null) { Viewport2D.SetContentBounds(Parent, contentBounds); } ViewportPanel.SetViewportBounds(this, contentBounds); int width = currDataSource.Width; int height = currDataSource.Height; bmp = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, null); Source = bmp; Task task = new Task(() => CreateConvolutionBmp(width, height)); task.Start(); }
private void AddDataSource(IDataSource2D <double> field, Guid guid) { List <PolylineGeometry> geometry = new List <PolylineGeometry>(); List <VisualPushpin> labels = new List <VisualPushpin>(); isolineBuilder.DataSource = field; IsolineCollection collection = isolineBuilder.Build(); annotater.WayBeforeText = 20.0; foreach (LevelLine segment in collection.Lines) { 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; Color color = palette.GetColor(segment.Value01); style.LineColor = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B); geometry.Add(new PolylineGeometry(guid.ToString(), Guid.NewGuid().ToString(), new Polyline2(Wgs84CoordinateReferenceSystem.Instance, Coordinate2DCollection.CreateUnsafe(points.ToArray())), style)); } foreach (IsolineTextLabel label in annotater.Annotate(collection, new Rect())) { labels.Add(new VisualPushpin(30, 30, label.Text, LatLonAlt.CreateUsingDegrees(label.Position.Y, label.Position.X, 0), this, Guid.NewGuid().ToString())); } layers.Add(new IsolinesLayer() { Geometry = geometry, IsVisible = true, Guid = guid, Labels = labels }); AddLayerToHost(layers[layers.Count - 1]); }
private void AddDataSource(IDataSource2D<double> field, Guid guid) { List<PolylineGeometry> geometry = new List<PolylineGeometry>(); List<VisualPushpin> labels = new List<VisualPushpin>(); isolineBuilder.DataSource = field; IsolineCollection collection = isolineBuilder.Build(); annotater.WayBeforeText = 20.0; foreach (LevelLine segment in collection.Lines) { 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; Color color = palette.GetColor(segment.Value01); style.LineColor = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B); geometry.Add(new PolylineGeometry(guid.ToString(), Guid.NewGuid().ToString(), new Polyline2(Wgs84CoordinateReferenceSystem.Instance, Coordinate2DCollection.CreateUnsafe(points.ToArray())), style)); } foreach (IsolineTextLabel label in annotater.Annotate(collection, new Rect())) { labels.Add(new VisualPushpin(30, 30, label.Text, LatLonAlt.CreateUsingDegrees(label.Position.Y, label.Position.X, 0), this, Guid.NewGuid().ToString())); } layers.Add(new IsolinesLayer() { Geometry = geometry, IsVisible = true, Guid = guid, Labels = labels }); AddLayerToHost(layers[layers.Count - 1]); }
private void AddDataSource(IDataSource2D<double> field, Guid guid) { double minT, maxT; //if (colorMapControl.PaletteType == PaletteType.FromMaxMin) //{ // minT = colorMapControl.MinValue; // maxT = colorMapControl.MaxValue; //} //else //{ MathHelper.GetMaxMin(field.Data, out maxT, out minT); //colorMapControl.MinValue = minT; //colorMapControl.MaxValue = maxT; //} double k = 1.0 / (maxT - minT); List<Vertex.PositionColored> vertices = new List<Vertex.PositionColored>(); double altitude = layerHelper.GetNewAltitude(); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { float x = (float)field.Grid[i, j].X; float y = (float)field.Grid[i, j].Y; LatLonAlt position = LatLonAlt.CreateUsingDegrees(y, x, altitude); Vector3F vec = new Vector3F(position.GetVector()); System.Windows.Media.Color color = palette.GetColor((field.Data[i, j] - minT) * k); vertices.Add(new Vertex.PositionColored(vec, Color.FromArgb(opacity, color.R, color.G, color.B).ToArgb())); } } MeshGraphicsObject<Vertex.PositionColored, ushort> mesh = new MeshGraphicsObject<Vertex.PositionColored, ushort>( GraphicsBufferUsage.Static, GraphicsBufferUsage.Static, vertices.Count, vertices.Count * 6, true); Material material = new Material { AmbientColor = Color.White, DiffuseColor = Color.White, SpecularColor = Color.White }; int id = mesh.Materials.Add(material); mesh.Vertices.AddData(vertices.ToArray()); for (int i = 0; i < field.Width - 1; i++) { for (int j = 0; j < field.Height - 1; j++) { mesh.Indices.AddData( (ushort)(i * field.Height + j), (ushort)(i * field.Height + j + 1), (ushort)((i + 1) * field.Height + j), PrimitiveType.TriangleList, id); mesh.Indices.AddData( (ushort)(i * field.Height + j + 1), (ushort)((i + 1) * field.Height + j + 1), (ushort)((i + 1) * field.Height + j), PrimitiveType.TriangleList, id); } } mesh.RenderState.Lighting.Enabled = false; mesh.RenderState.Alpha.Enabled = true; mesh.RenderState.Alpha.AlphaTestEnable = true; mesh.RenderState.Alpha.SourceBlend = Blend.BothInvSourceAlpha; mesh.RenderState.Alpha.DestinationBlend = Blend.BothInvSourceAlpha; mesh.RenderState.Cull.Enabled = false; meshLayers.Add(new MeshLayer { LayerAltitude = altitude, Mesh = mesh, Guid = guid, IsVisible = true, ScalarField = field }); }
public bool CheckIntersection(LatLonAlt location) { bool hasIntersections = false; foreach (VisualPushpin pin in intersectedValues) { host.Geometry.RemoveGeometry(pin.Pushpin.LayerId, pin.Pushpin.Id); } intersectedValues.Clear(); lock (probesLayers) { foreach (ProbesLayer probesLayer in probesLayers) { if (probesLayer.IsVisible) { if (probesLayer.DataSource.Field is IDataSource2D <double> ) { //for warped grids IDataSource2D <double> field = probesLayer.DataSource.Field as IDataSource2D <double>; System.Windows.Point[,] grid = field.Grid; Coordinate2D minCoordinate = new Coordinate2D(grid[0, 0].X, grid[0, 0].Y); Coordinate2D maxCoordinate = new Coordinate2D(grid[field.Width - 1, field.Height - 1].X, grid[field.Width - 1, field.Height - 1].Y); bool intersectionFound = false; for (int j = 0; j < field.Height; j++) { for (int i = 0; i < field.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; } } } if (location.LatitudeDegrees > minCoordinate.Y && location.LongitudeDegrees > minCoordinate.X && location.LongitudeDegrees < maxCoordinate.X && location.LatitudeDegrees < maxCoordinate.Y) { for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { LatLonAlt gridPos = LatLonAlt.CreateUsingDegrees(field.Grid[i, j].Y, field.Grid[i, j].X, 0); if (CheckEnvirons(gridPos, location, probesLayer.DataSource.Step)) { if (!hasIntersections) { hasIntersections = true; } intersectedValues.Add(new VisualPushpin(60, 60, field.Data[i, j].ToString(), gridPos, null, Guid.NewGuid().ToString())); intersectionFound = true; break; } } if (intersectionFound) { break; } } } } else if (probesLayer.DataSource.Field is PointSet) { PointSet pointSet = probesLayer.DataSource.Field as PointSet; if (probesLayer.IsVisible) { for (int i = 0; i < pointSet.Data.Count; i++) { LatLonAlt gridPos = LatLonAlt.CreateUsingDegrees(pointSet.Data[i].Latitude, pointSet.Data[i].Longitude, 0); if (CheckEnvirons(gridPos, location, probesLayer.DataSource.Step)) { if (!hasIntersections) { hasIntersections = true; } intersectedValues.Add(new VisualPushpin(60, 60, pointSet.Data[i].Value.ToString(), gridPos, null, Guid.NewGuid().ToString())); break; } } } } } } } return(hasIntersections); }
public RasterPatch2 GetTilePatch(IDataSource2D<double> field, Box2 regionBox, double iconSize) { System.Windows.Point[,] grid = field.Grid; Coordinate2D minCoordinate = new Coordinate2D(grid[0, 0].X, grid[0, 0].Y); Coordinate2D maxCoordinate = new Coordinate2D(grid[field.Width - 1, field.Height - 1].X, grid[field.Width - 1, field.Height - 1].Y); for (int j = 0; j < field.Height; j++) { for (int i = 0; i < field.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; } } GeoRect gridBox = new GeoRect( minCoordinate.X, minCoordinate.Y, maxCoordinate.X - minCoordinate.X, maxCoordinate.Y - minCoordinate.Y); GeoRect tileBox = new GeoRect( regionBox.MinCoordinate.X, regionBox.MinCoordinate.Y, regionBox.MaxCoordinate.X - regionBox.MinCoordinate.X, regionBox.MaxCoordinate.Y - regionBox.MinCoordinate.Y); GeoRect intersectionRect = GeoRect.Intersect(gridBox, tileBox); if (intersectionRect != null) { int width = 256; int height = 256; Bitmap resultBitmap = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(resultBitmap); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { GeoRect workingRect = new GeoRect( field.Grid[i, j].X - iconSize / 2.0, field.Grid[i, j].Y - iconSize / 2.0, iconSize, iconSize); if (GeoRect.IntersectionExist(workingRect, intersectionRect)) { int x0 = (int)(Math.Min(width, Math.Max(0, field.Grid[i, j].X - iconSize / 2.0 - tileBox.Left) / tileBox.Width * width)); int y0 = (int)(Math.Min(height, Math.Max(0, tileBox.Top - field.Grid[i, j].Y - iconSize / 2.0) / tileBox.Height * height)); int x1 = (int)(Math.Min(width, Math.Max(0, field.Grid[i, j].X + iconSize / 2.0 - tileBox.Left) / tileBox.Width * width)); int y1 = (int)(Math.Min(height, Math.Max(0, tileBox.Top - field.Grid[i, j].Y + iconSize / 2.0) / tileBox.Height * height)); double widthX = Math.Min(tileBox.Width, iconSize); double heightY = Math.Min(tileBox.Height, iconSize); lock (icon) { int x2 = 0; if (field.Grid[i, j].X - iconSize / 2.0 < tileBox.Left) { x2 = icon.Width - (int)((double)(x1 - x0) * icon.Width / (widthX / tileBox.Width * width)); } int y2 = 0; if (tileBox.Top - field.Grid[i, j].Y - iconSize / 2.0 < 0) { y2 = icon.Height - (int)((double)(y1 - y0) * icon.Height / (heightY / tileBox.Height * height)); } graphics.DrawImage( icon, new Rectangle(x0, y0, x1 - x0, y1 - y0), x2, y2, (int)((double)(x1 - x0) * icon.Width / (widthX / tileBox.Width * width)), (int)((double)(y1 - y0) * icon.Height / (heightY / tileBox.Height * height)), GraphicsUnit.Pixel); } } } } return new RasterPatch2( regionBox, resultBitmap, Wgs84CoordinateReferenceSystem.Instance); } else { return null; } }
public ProbesDataSource(Guid guid, IDataSource2D<double> field, Host host) : base(guid) { // set up the Ontology, a description of the kind of data we contain. // See DataSource sample for more details. 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.wfield = field; System.Windows.Point[,] grid = wfield.Grid; Coordinate2D minCoordinate = new Coordinate2D(grid[0, 0].X, grid[0, 0].Y); Coordinate2D maxCoordinate = new Coordinate2D(grid[field.Width - 1, field.Height - 1].X, grid[field.Width - 1, field.Height - 1].Y); for (int j = 0; j < field.Height; j++) { for (int i = 0; i < field.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); dataType = DSDataType.TwoDim; this.host = host; probesHelper = new ProbesHelper("ProbeSample.png", false); }
private void AddDataSource(IDataSource2D <double> field, Guid guid) { double minT, maxT; //if (colorMapControl.PaletteType == PaletteType.FromMaxMin) //{ // minT = colorMapControl.MinValue; // maxT = colorMapControl.MaxValue; //} //else //{ MathHelper.GetMaxMin(field.Data, out maxT, out minT); //colorMapControl.MinValue = minT; //colorMapControl.MaxValue = maxT; //} double k = 1.0 / (maxT - minT); List <Vertex.PositionColored> vertices = new List <Vertex.PositionColored>(); double altitude = layerHelper.GetNewAltitude(); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { float x = (float)field.Grid[i, j].X; float y = (float)field.Grid[i, j].Y; LatLonAlt position = LatLonAlt.CreateUsingDegrees(y, x, altitude); Vector3F vec = new Vector3F(position.GetVector()); System.Windows.Media.Color color = palette.GetColor((field.Data[i, j] - minT) * k); vertices.Add(new Vertex.PositionColored(vec, Color.FromArgb(opacity, color.R, color.G, color.B).ToArgb())); } } MeshGraphicsObject <Vertex.PositionColored, ushort> mesh = new MeshGraphicsObject <Vertex.PositionColored, ushort>( GraphicsBufferUsage.Static, GraphicsBufferUsage.Static, vertices.Count, vertices.Count * 6, true); Material material = new Material { AmbientColor = Color.White, DiffuseColor = Color.White, SpecularColor = Color.White }; int id = mesh.Materials.Add(material); mesh.Vertices.AddData(vertices.ToArray()); for (int i = 0; i < field.Width - 1; i++) { for (int j = 0; j < field.Height - 1; j++) { mesh.Indices.AddData( (ushort)(i * field.Height + j), (ushort)(i * field.Height + j + 1), (ushort)((i + 1) * field.Height + j), PrimitiveType.TriangleList, id); mesh.Indices.AddData( (ushort)(i * field.Height + j + 1), (ushort)((i + 1) * field.Height + j + 1), (ushort)((i + 1) * field.Height + j), PrimitiveType.TriangleList, id); } } mesh.RenderState.Lighting.Enabled = false; mesh.RenderState.Alpha.Enabled = true; mesh.RenderState.Alpha.AlphaTestEnable = true; mesh.RenderState.Alpha.SourceBlend = Blend.BothInvSourceAlpha; mesh.RenderState.Alpha.DestinationBlend = Blend.BothInvSourceAlpha; mesh.RenderState.Cull.Enabled = false; meshLayers.Add(new MeshLayer { LayerAltitude = altitude, Mesh = mesh, Guid = guid, IsVisible = true, ScalarField = field }); }
public static Range <double> GetMinMax(this IDataSource2D <double> dataSource, double missingValue) { dataSource.VerifyNotNull("dataSource"); return(GetMinMax(dataSource.Data, missingValue)); }
private void OnDataSourceReplaced(IDataSource2D <Vector> prevDataSource, IDataSource2D <Vector> currDataSource) { whiteNoizeBmp = CreateWhiteNoizeBmp(currDataSource.Width, currDataSource.Height); }
public GenericDataSource2D(IDataSource2D <T> dataSource) { Contract.Assert(dataSource != null); this.dataSource = dataSource; }
public static Rect GetGridBounds <T>(this IDataSource2D <T> dataSource) { return(dataSource.Grid.GetGridBounds()); }
protected virtual void DetachDataSource(IDataSource2D<double> dataSource) { if (dataSource != null) { dataSource.Changed -= OnDataSourceChanged; } }
private void AddDataSource(IDataSource2D <double> field, Guid guid) { // Get data and min/max. double[,] data = field.Data; double minT, maxT; MathHelper.GetMaxMin(data, out maxT, out minT); double k = 1.0 / (maxT - minT); double altitude = layerAltitude; //TODO: Perform right calculation depending on grid step = 0.3; List <Vertex.PositionColored> vertices = new List <Vertex.PositionColored>(); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { float x = (float)field.Grid[i, j].X; float y = (float)field.Grid[i, j].Y; LatLonAlt position = LatLonAlt.CreateUsingDegrees(y + step, x + step, altitude); Vector3F vec = new Vector3F(position.GetVector()); vertices.Add(new Vertex.PositionColored(vec, Color.Red.ToArgb())); position = LatLonAlt.CreateUsingDegrees(y - step, x - step, altitude); vec = new Vector3F(position.GetVector()); vertices.Add(new Vertex.PositionColored(vec, Color.Red.ToArgb())); position = LatLonAlt.CreateUsingDegrees(y + step, x - step, altitude); vec = new Vector3F(position.GetVector()); vertices.Add(new Vertex.PositionColored(vec, Color.Red.ToArgb())); position = LatLonAlt.CreateUsingDegrees(y - step, x + step, altitude); vec = new Vector3F(position.GetVector()); vertices.Add(new Vertex.PositionColored(vec, Color.Red.ToArgb())); } } MeshGraphicsObject <Vertex.PositionColored, ushort> mesh = new MeshGraphicsObject <Vertex.PositionColored, ushort>( GraphicsBufferUsage.Static, GraphicsBufferUsage.Static, vertices.Count, vertices.Count, true); Material material = new Material { AmbientColor = Color.White, DiffuseColor = Color.White, SpecularColor = Color.White }; int id = mesh.Materials.Add(material); mesh.Vertices.AddData(vertices.ToArray()); List <ushort> indexData = new List <ushort>(); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { indexData.Add((ushort)((i * field.Height + j) * 4)); indexData.Add((ushort)((i * field.Height + j) * 4 + 1)); indexData.Add((ushort)((i * field.Height + j) * 4 + 2)); indexData.Add((ushort)((i * field.Height + j) * 4 + 3)); } } mesh.Indices.AddData(indexData.ToArray(), PrimitiveType.LineList, id); mesh.RenderState.Lighting.Enabled = false; mesh.RenderState.Cull.Enabled = false; meshLayers.Add(new MeshLayer { LayerAltitude = altitude, Mesh = mesh, Guid = guid, IsVisible = true, ScalarField = field, Step = step }); }
protected virtual void OnDataSourceChanged(IDataSource2D<double> prevDataSource, IDataSource2D<double> currDataSource) { if (prevDataSource != null) prevDataSource.Changed -= OnDataSourceChanged; if (currDataSource != null) currDataSource.Changed += OnDataSourceChanged; UpdateDataSource(); CreateUIRepresentation(); RaiseEvent(new RoutedEventArgs(BackgroundRenderer.UpdateRequested)); }
public RasterPatch2 GetTilePatch(IDataSource2D <double> field, Box2 regionBox, double iconSize) { System.Windows.Point[,] grid = field.Grid; Coordinate2D minCoordinate = new Coordinate2D(grid[0, 0].X, grid[0, 0].Y); Coordinate2D maxCoordinate = new Coordinate2D(grid[field.Width - 1, field.Height - 1].X, grid[field.Width - 1, field.Height - 1].Y); for (int j = 0; j < field.Height; j++) { for (int i = 0; i < field.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; } } } GeoRect gridBox = new GeoRect( minCoordinate.X, minCoordinate.Y, maxCoordinate.X - minCoordinate.X, maxCoordinate.Y - minCoordinate.Y); GeoRect tileBox = new GeoRect( regionBox.MinCoordinate.X, regionBox.MinCoordinate.Y, regionBox.MaxCoordinate.X - regionBox.MinCoordinate.X, regionBox.MaxCoordinate.Y - regionBox.MinCoordinate.Y); GeoRect intersectionRect = GeoRect.Intersect(gridBox, tileBox); if (intersectionRect != null) { int width = 256; int height = 256; Bitmap resultBitmap = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(resultBitmap); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { GeoRect workingRect = new GeoRect( field.Grid[i, j].X - iconSize / 2.0, field.Grid[i, j].Y - iconSize / 2.0, iconSize, iconSize); if (GeoRect.IntersectionExist(workingRect, intersectionRect)) { int x0 = (int)(Math.Min(width, Math.Max(0, field.Grid[i, j].X - iconSize / 2.0 - tileBox.Left) / tileBox.Width * width)); int y0 = (int)(Math.Min(height, Math.Max(0, tileBox.Top - field.Grid[i, j].Y - iconSize / 2.0) / tileBox.Height * height)); int x1 = (int)(Math.Min(width, Math.Max(0, field.Grid[i, j].X + iconSize / 2.0 - tileBox.Left) / tileBox.Width * width)); int y1 = (int)(Math.Min(height, Math.Max(0, tileBox.Top - field.Grid[i, j].Y + iconSize / 2.0) / tileBox.Height * height)); double widthX = Math.Min(tileBox.Width, iconSize); double heightY = Math.Min(tileBox.Height, iconSize); lock (icon) { int x2 = 0; if (field.Grid[i, j].X - iconSize / 2.0 < tileBox.Left) { x2 = icon.Width - (int)((double)(x1 - x0) * icon.Width / (widthX / tileBox.Width * width)); } int y2 = 0; if (tileBox.Top - field.Grid[i, j].Y - iconSize / 2.0 < 0) { y2 = icon.Height - (int)((double)(y1 - y0) * icon.Height / (heightY / tileBox.Height * height)); } graphics.DrawImage( icon, new Rectangle(x0, y0, x1 - x0, y1 - y0), x2, y2, (int)((double)(x1 - x0) * icon.Width / (widthX / tileBox.Width * width)), (int)((double)(y1 - y0) * icon.Height / (heightY / tileBox.Height * height)), GraphicsUnit.Pixel); } } } } return(new RasterPatch2( regionBox, resultBitmap, Wgs84CoordinateReferenceSystem.Instance)); } else { return(null); } }
public static Range <double> GetMinMax(this IDataSource2D <double> dataSource) { dataSource.VerifyNotNull("data"); return(GetMinMax(dataSource.Data)); }
public ColorMapServer(IDataSource2D <double> dataSource) { Contract.Requires(dataSource != null); this.dataSource = dataSource; }
/// <summary> /// Initializes a new instance of the <see cref="IsolineBuilder"/> class for specified 2d scalar data source. /// </summary> /// <param name="dataSource">The data source with 2d scalar data.</param> public IsolineBuilder(IDataSource2D <double> dataSource) { DataSource = dataSource; }
public static DataRect GetGridBounds <T>(this IDataSource2D <T> dataSource) where T : struct { return(dataSource.Grid.GetGridBounds()); }
private void AddDataSource(IDataSource2D<double> field, Guid guid) { // Get data and min/max. double[,] data = field.Data; double minT, maxT; MathHelper.GetMaxMin(data, out maxT, out minT); double k = 1.0 / (maxT - minT); double altitude = layerAltitude; //TODO: Perform right calculation depending on grid step = 0.3; List<Vertex.PositionColored> vertices = new List<Vertex.PositionColored>(); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { float x = (float)field.Grid[i, j].X; float y = (float)field.Grid[i, j].Y; LatLonAlt position = LatLonAlt.CreateUsingDegrees(y + step, x + step, altitude); Vector3F vec = new Vector3F(position.GetVector()); vertices.Add(new Vertex.PositionColored(vec, Color.Red.ToArgb())); position = LatLonAlt.CreateUsingDegrees(y - step, x - step, altitude); vec = new Vector3F(position.GetVector()); vertices.Add(new Vertex.PositionColored(vec, Color.Red.ToArgb())); position = LatLonAlt.CreateUsingDegrees(y + step, x - step, altitude); vec = new Vector3F(position.GetVector()); vertices.Add(new Vertex.PositionColored(vec, Color.Red.ToArgb())); position = LatLonAlt.CreateUsingDegrees(y - step, x + step, altitude); vec = new Vector3F(position.GetVector()); vertices.Add(new Vertex.PositionColored(vec, Color.Red.ToArgb())); } } MeshGraphicsObject<Vertex.PositionColored, ushort> mesh = new MeshGraphicsObject<Vertex.PositionColored, ushort>( GraphicsBufferUsage.Static, GraphicsBufferUsage.Static, vertices.Count, vertices.Count, true); Material material = new Material { AmbientColor = Color.White, DiffuseColor = Color.White, SpecularColor = Color.White }; int id = mesh.Materials.Add(material); mesh.Vertices.AddData(vertices.ToArray()); List<ushort> indexData = new List<ushort>(); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { indexData.Add((ushort)((i * field.Height + j) * 4)); indexData.Add((ushort)((i * field.Height + j) * 4 + 1)); indexData.Add((ushort)((i * field.Height + j) * 4 + 2)); indexData.Add((ushort)((i * field.Height + j) * 4 + 3)); } } mesh.Indices.AddData(indexData.ToArray(), PrimitiveType.LineList, id); mesh.RenderState.Lighting.Enabled = false; mesh.RenderState.Cull.Enabled = false; meshLayers.Add(new MeshLayer { LayerAltitude = altitude, Mesh = mesh, Guid = guid, IsVisible = true, ScalarField = field, Step = step }); }
public static IDataSource2D <double> GetMagnitudeDataSource(this IDataSource2D <Vector> dataSource) { return(new VectorToMagnitudeDataSource(dataSource)); }
private void AddDataSource(IDataSource2D<double> field, Guid guid) { probesLayers.Add(new ProbesLayer { Guid = guid, IsVisible = true, DataSource = new ProbesDataSource(guid, field, host), LayerID = Guid.NewGuid().ToString(), LayerName = Guid.NewGuid().ToString() }); AddLayerToHost(probesLayers[probesLayers.Count - 1]); }
private void OnDataSourceReplaced(IDataSource2D<Vector> prevDataSource, IDataSource2D<Vector> currDataSource) { whiteNoizeBmp = CreateWhiteNoizeBmp(currDataSource.Width, currDataSource.Height); }
/// <summary> /// Initializes a new instance of the <see cref="IsolineBuilder"/> class for specified 2d scalar data source. /// </summary> /// <param name="dataSource">The data source with 2d scalar data.</param> public IsolineBuilder(IDataSource2D<double> dataSource) { DataSource = dataSource; }
public ColorMapServer(IDataSource2D<double> dataSource) { Contract.Requires(dataSource != null); this.dataSource = dataSource; }