public GraphicsEngine.CanvasPointF[] ToCoords() { GraphicsEngine.CanvasPointF[] points = new GraphicsEngine.CanvasPointF[4]; points[0] = new GraphicsEngine.CanvasPointF((float)_x1, (float)_y1); points[1] = new GraphicsEngine.CanvasPointF(points[0].X + (float)(cos_a * _width), points[0].Y + (float)(sin_a * _width)); points[2] = new GraphicsEngine.CanvasPointF(points[1].X + (float)(-sin_a * _height), points[1].Y + (float)(cos_a * _height)); points[3] = new GraphicsEngine.CanvasPointF(points[0].X + (float)(-sin_a * _height), points[0].Y + (float)(cos_a * _height)); return(points); }
private static void MinMaxAreaForOrhtoSepLine(GraphicsEngine.CanvasPointF p1, Vector2dF ortho, AnnotationPolygon lp, ref float min, ref float max) { for (int j = 0; j < lp._points.Length; j++) { Vector2dF rc = new Vector2dF(lp[j], p1); float prod = ortho.DotProduct(rc); if (j == 0) { min = max = prod; } else { min = Math.Min(min, prod); max = Math.Max(max, prod); } } }
private static bool HasSeperateLine(AnnotationPolygon tester, AnnotationPolygon cand) { for (int i = 1; i <= tester._points.Length; i++) { GraphicsEngine.CanvasPointF p1 = tester[i]; Vector2dF ortho = new Vector2dF(p1, tester._points[i - 1]); ortho.ToOrtho(); ortho.Normalize(); float t_min = 0f, t_max = 0f, c_min = 0f, c_max = 0f; MinMaxAreaForOrhtoSepLine(p1, ortho, tester, ref t_min, ref t_max); MinMaxAreaForOrhtoSepLine(p1, ortho, cand, ref c_min, ref c_max); if ((t_min <= c_max && t_max <= c_min) || (c_min <= t_max && c_max <= t_min)) { return(true); } } return(false); }
// Thread async public Task Render() { GraphicsEngine.Abstraction.IBitmap _filteredBitmap = null; try { if (_layer == null || _map == null || _cancelTracker == null) { return; } if (_layer.RasterClass.Polygon == null) { return; } IEnvelope env = _layer.RasterClass.Polygon.Envelope; double minx = env.minx, miny = env.miny, maxx = env.maxx, maxy = env.maxy; _map.World2Image(ref minx, ref miny); _map.World2Image(ref maxx, ref maxy); int iWidth = 0, iHeight = 0; int min_x = Math.Max(0, (int)Math.Min(minx, maxx) - 1); int min_y = Math.Max(0, (int)Math.Min(miny, maxy) - 1); int max_x = Math.Min(iWidth = _map.iWidth, (int)Math.Max(minx, maxx) + 1); int max_y = Math.Min(iHeight = _map.iHeight, (int)Math.Max(miny, maxy) + 1); using (var paintContext = await _layer.RasterClass.BeginPaint(_map.Display, _cancelTracker)) { if (_filter != FilterImplementations.Default) { _filteredBitmap = BaseFilter.ApplyFilter(paintContext.Bitmap, _filter); } if (paintContext.Bitmap == null && _filteredBitmap == null) { return; } //System.Windows.Forms.MessageBox.Show("begin"); double W = (_map.Envelope.maxx - _map.Envelope.minx); double H = (_map.Envelope.maxy - _map.Envelope.miny); double MinX = _map.Envelope.minx; double MinY = _map.Envelope.miny; //_lastRasterLayer = _layer; var canvas = _map.Display.Canvas; if (canvas == null) { return; } canvas.InterpolationMode = (GraphicsEngine.InterpolationMode)_interpolMethod; // Transformation berechnen GraphicsEngine.CanvasRectangleF rect; switch (canvas.InterpolationMode) { case GraphicsEngine.InterpolationMode.Bilinear: case GraphicsEngine.InterpolationMode.Bicubic: rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width - 1f, paintContext.Bitmap.Height - 1f); break; case GraphicsEngine.InterpolationMode.NearestNeighbor: rect = new GraphicsEngine.CanvasRectangleF(-0.5f, -0.5f, paintContext.Bitmap.Width, paintContext.Bitmap.Height); //rect = new GraphicsEngine.CanvasRectangleF(0f, 0f, _layer.RasterClass.Bitmap.Width, _layer.RasterClass.Bitmap.Height); break; default: rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width, paintContext.Bitmap.Height); break; } var points = new GraphicsEngine.CanvasPointF[3]; if (_layer.RasterClass is IRasterClass2) { IPoint p1 = ((IRasterClass2)_layer.RasterClass).PicPoint1; IPoint p2 = ((IRasterClass2)_layer.RasterClass).PicPoint2; IPoint p3 = ((IRasterClass2)_layer.RasterClass).PicPoint3; if (_map.Display.GeometricTransformer != null) { p1 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p1); p2 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p2); p3 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p3); } double X = p1.X, Y = p1.Y; _map.Display.World2Image(ref X, ref Y); points[0] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = p2.X; Y = p2.Y; _map.Display.World2Image(ref X, ref Y); points[1] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = p3.X; Y = p3.Y; _map.Display.World2Image(ref X, ref Y); points[2] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); RoundGraphicPixelPoints(points); } else { double X1 = _layer.RasterClass.oX - _layer.RasterClass.dx1 / 2.0 - _layer.RasterClass.dy1 / 2.0; double Y1 = _layer.RasterClass.oY - _layer.RasterClass.dx2 / 2.0 - _layer.RasterClass.dy2 / 2.0; double X = X1; double Y = Y1; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[0] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = X1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx1; Y = Y1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx2; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[1] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = X1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy1; Y = Y1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy2; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[2] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); } if (_transColor.ToArgb() != System.Drawing.Color.Transparent.ToArgb()) { try { // kann OutOfMemoryException auslösen... paintContext.Bitmap.MakeTransparent(_transColor); } catch (Exception ex) { if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null) { await((IServiceMap)_map).MapServer.LogAsync( ((IServiceMap)_map).Name, "RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty), loggingMethod.error, ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace); } if (_map != null) { if (_map != null) { _map.AddRequestException(new Exception("RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty) + "\n" + ex.Message, ex)); } } } } //var comQual = gr.CompositingQuality; //gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; float opaque = 1.0f - _transparency; canvas.DrawBitmap(_filteredBitmap ?? paintContext.Bitmap, points, rect, opacity: opaque); _map.FireRefreshMapView(); } } catch (Exception ex) { if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null) { await((IServiceMap)_map).MapServer.LogAsync( ((IServiceMap)_map).Name, "RenderRasterLayerThread:" + ((_layer != null) ? _layer.Title : String.Empty), loggingMethod.error, ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace); } if (_map != null) { if (_map != null) { _map.AddRequestException(new Exception("RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty) + "\n" + ex.Message, ex)); } } } finally { if (_filteredBitmap != null) { _filteredBitmap.Dispose(); } } }
public Vector2dF(GraphicsEngine.CanvasPointF p1, GraphicsEngine.CanvasPointF p0) { _x = p1.X - p0.X; _y = p1.Y - p0.Y; }
async public Task Render() { try { if (_layer == null || _map == null || _cancelTracker == null) { return; } if (_layer.RasterClass.Polygon == null) { return; } IEnvelope env = _layer.RasterClass.Polygon.Envelope; double minx = env.minx, miny = env.miny, maxx = env.maxx, maxy = env.maxy; _map.World2Image(ref minx, ref miny); _map.World2Image(ref maxx, ref maxy); int iWidth = 0, iHeight = 0; int min_x = Math.Max(0, (int)Math.Min(minx, maxx) - 1); int min_y = Math.Max(0, (int)Math.Min(miny, maxy) - 1); int max_x = Math.Min(iWidth = _map.iWidth, (int)Math.Max(minx, maxx) + 1); int max_y = Math.Min(iHeight = _map.iHeight, (int)Math.Max(miny, maxy) + 1); using (var paintContext = await _layer.RasterClass.BeginPaint(_map.Display, _cancelTracker)) { if (paintContext.Bitmap == null) { return; } //System.Windows.Forms.MessageBox.Show("begin"); double W = (_map.Envelope.maxx - _map.Envelope.minx); double H = (_map.Envelope.maxy - _map.Envelope.miny); double MinX = _map.Envelope.minx; double MinY = _map.Envelope.miny; //_lastRasterLayer = _layer; var canvas = _map.Display.Canvas; if (canvas == null) { return; } canvas.InterpolationMode = (GraphicsEngine.InterpolationMode)_interpolMethod; // Transformation berechnen GraphicsEngine.CanvasRectangleF rect; switch (canvas.InterpolationMode) { case GraphicsEngine.InterpolationMode.Bilinear: case GraphicsEngine.InterpolationMode.Bicubic: rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width - 1f, paintContext.Bitmap.Height - 1f); break; case GraphicsEngine.InterpolationMode.NearestNeighbor: rect = new GraphicsEngine.CanvasRectangleF(-0.5f, -0.5f, paintContext.Bitmap.Width, paintContext.Bitmap.Height); break; default: rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width, paintContext.Bitmap.Height); break; } var points = new GraphicsEngine.CanvasPointF[3]; if (_layer.RasterClass is IRasterClass2) { IPoint p1 = ((IRasterClass2)_layer.RasterClass).PicPoint1; IPoint p2 = ((IRasterClass2)_layer.RasterClass).PicPoint2; IPoint p3 = ((IRasterClass2)_layer.RasterClass).PicPoint3; if (_map.Display.GeometricTransformer != null) { p1 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p1); p2 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p2); p3 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p3); } double X = p1.X, Y = p1.Y; _map.Display.World2Image(ref X, ref Y); points[0] = new GraphicsEngine.CanvasPointF((float)X, (float)Y); X = p2.X; Y = p2.Y; _map.Display.World2Image(ref X, ref Y); points[1] = new GraphicsEngine.CanvasPointF((float)X, (float)Y); X = p3.X; Y = p3.Y; _map.Display.World2Image(ref X, ref Y); points[2] = new GraphicsEngine.CanvasPointF((float)X, (float)Y); } else { double X1 = _layer.RasterClass.oX - _layer.RasterClass.dx1 / 2.0 - _layer.RasterClass.dy1 / 2.0; double Y1 = _layer.RasterClass.oY - _layer.RasterClass.dx2 / 2.0 - _layer.RasterClass.dy2 / 2.0; double X = X1; double Y = Y1; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[0] = new GraphicsEngine.CanvasPointF((float)X, (float)Y); X = X1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx1; Y = Y1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx2; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[1] = new GraphicsEngine.CanvasPointF((float)X, (float)Y); X = X1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy1; Y = Y1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy2; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[2] = new GraphicsEngine.CanvasPointF((float)X, (float)Y); } if (!GraphicsEngine.ArgbColor.Transparent.Equals(_transColor)) { try { // kann OutOfMemoryException auslösen... paintContext.Bitmap.MakeTransparent(_transColor); } catch { } } float opaque = 1.0f - _transparency; canvas.DrawBitmap(paintContext.Bitmap, points, rect, opacity: opaque); } } catch (Exception ex) { } }
public void AddPoint(GraphicsEngine.CanvasPointF point) { _points.Add(point); }