public static void Draw(Image image, float x, float y, Graphics g, TransformParams t, BoundingArea.ReadOnly boundingArea) { //#if !NO_PARTIAL_RENDERING // Utils.ThrowException(g == null ? new ArgumentNullException("g") : null); // Utils.ThrowException(t == null ? new ArgumentNullException("t") : null); // // TODO: throw other exceptions // float width = t.Transform(image.Width); // float height = t.Transform(image.Height); // Vector2DF pos = t.Transform(new Vector2DF(x, y)); // BoundingArea inflatedArea = boundingArea.GetWritableCopy(); // inflatedArea.Inflate(5f, 5f); // // *** the following code is using relatively slow GDI+ clipping :-/ // GraphicsPath gPath = new GraphicsPath(); // foreach (RectangleF rect in inflatedArea.Rectangles) // { // gPath.AddRectangle(rect); // } // g.SetClip(gPath, CombineMode.Union); // PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode; // g.PixelOffsetMode = PixelOffsetMode.Half; // g.DrawImage(image, pos.X, pos.Y, width, height); // g.ResetClip(); // g.PixelOffsetMode = pixelOffsetMode; //#else Draw(image, x, y, g, t); //#endif }
public virtual BoundingArea GetBoundingArea(TransformParams tr) { Utils.ThrowException(tr == null ? new ArgumentNullException("tr") : null); if (mBoundingArea == null) { mBoundingArea = GetBoundingArea(); } BoundingArea boundingArea = mBoundingArea.Clone(); boundingArea.Transform(tr); lock (mPen) { boundingArea.Inflate(mPen.Width / 2f + 5f, mPen.Width / 2f + 5f); } return boundingArea; }
public static ArrayList<RectangleF> FullyOptimizeBoundingArea(BoundingArea boundingArea) { int rectCount = boundingArea.Rectangles.Count; ArrayList<RectangleF> rects = OptimizeBoundingArea(boundingArea.Rectangles); while (rects.Count < rectCount) { rectCount = rects.Count; rects = OptimizeBoundingArea(rects); } return rects; }
private void LoadPoints() { this.points = new List <Point>(); this.area = new BoundingArea(); this.area.x = 0; this.area.y = 0; this.area.width = 1200; this.area.height = 800; displayImage = new Bitmap(this.area.width, this.area.height, PixelFormat.Format24bppRgb); //There are three bytes per pixel in format PixelFormat.Format24bppRgb bytesPerPixel = 3; //Rgb byte data for the image int rgbDataSize = this.area.width * this.area.height * bytesPerPixel; imageRgbData = new byte[rgbDataSize]; GenerateRandomPoints(); UpdateBitmap(); }
public override void Draw(Graphics g, TransformParams t, BoundingArea.ReadOnly boundingArea) { Draw(mImage, mX, mY, g, t, boundingArea); // throws ArgumentNullException }
public virtual IDrawableObject[] GetObjectsIn(BoundingArea.ReadOnly area, TransformParams tr) { Utils.ThrowException(area == null ? new ArgumentNullException("area") : null); Utils.ThrowException(tr == null ? new ArgumentNullException("tr") : null); if (GetBoundingArea(tr).IntersectsWith(area)) { return new IDrawableObject[] { this }; } else { return new IDrawableObject[] { }; } }
public virtual void Draw(Graphics gfx, TransformParams tr, BoundingArea.ReadOnly boundingArea) { Draw(gfx, tr); }
protected void InvalidateBoundingArea() { mBoundingArea = null; }
public override void Draw(Graphics g, TransformParams t, BoundingArea.ReadOnly boundingArea) { Draw(mX1, mY1, mX2, mY2, g, mPen, t, boundingArea); // throws ArgumentNullException }
public static BoundingArea GetBoundingArea(float x1, float y1, float x2, float y2) { #if !SIMPLE_BOUNDING_AREA if (x1 == x2 || y1 == y2) { return new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)); } float delta = Math.Abs((x2 - x1) / (y2 - y1)); float stepMax = (float)Math.Sqrt(mMaxBoxArea / delta + delta * mMaxBoxArea); Vector2DF line = new Vector2DF(x1, y1, x2, y2); float lineLen = line.GetLength(); if (stepMax >= lineLen) { return new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)); } BoundingArea boundingArea = new BoundingArea(); int steps = (int)Math.Ceiling(lineLen / stepMax); Vector2DF stepVec = line; stepVec.SetLength(lineLen / (float)steps); Vector2DF pt1 = new Vector2DF(x1, y1); Vector2DF pt2; for (int i = 0; i < steps - 1; i++) { pt2 = pt1 + stepVec; boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y)); pt1 = pt2; } pt2 = new Vector2DF(x2, y2); boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y)); return boundingArea; #else BoundingArea boundingArea = new BoundingArea(); boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)); return boundingArea; #endif }
public static void Draw(float x1, float y1, float x2, float y2, Graphics g, Pen pen, TransformParams t, BoundingArea.ReadOnly boundingArea) { #if !NO_PARTIAL_RENDERING Utils.ThrowException(g == null ? new ArgumentNullException("g") : null); Utils.ThrowException(pen == null ? new ArgumentNullException("pen") : null); Utils.ThrowException(t == null ? new ArgumentNullException("t") : null); Utils.ThrowException(boundingArea == null ? new ArgumentNullException("boundingArea") : null); Vector2DF pt1 = t.Transform(new Vector2DF(x1, y1)); Vector2DF pt2 = t.Transform(new Vector2DF(x2, y2)); Vector2DF isectPt1 = new Vector2DF(); Vector2DF isectPt2 = new Vector2DF(); BoundingArea inflatedArea = boundingArea.GetWritableCopy(); inflatedArea.Inflate(pen.Width / 2f + 5f, pen.Width / 2f + 5f); ArrayList<KeyDat<float, PointInfo>> points = new ArrayList<KeyDat<float, PointInfo>>(); foreach (RectangleF rect in inflatedArea.Rectangles) { if (LineIntersectRectangle(pt1, pt2, rect, ref isectPt1, ref isectPt2)) { float distPt1 = (pt1 - isectPt1).GetLength(); float distPt2 = (pt1 - isectPt2).GetLength(); bool startPt1 = distPt1 < distPt2; points.Add(new KeyDat<float, PointInfo>(distPt1, new PointInfo(isectPt1, startPt1))); points.Add(new KeyDat<float, PointInfo>(distPt2, new PointInfo(isectPt2, !startPt1))); } } points.Sort(); int refCount = 0; int startIdx = 0; for (int i = 0; i < points.Count; i++) { PointInfo pointInfo = points[i].Dat; if (pointInfo.IsStartPoint) { refCount++; } else { refCount--; if (refCount == 0) { g.DrawLine(pen, points[startIdx].Dat.Point, pointInfo.Point); startIdx = i + 1; } } } #else Draw(x1, y1, x2, y2, g, pen, t); #endif }
/// <summary> /// Clears the collection of points and replaces it with the newly provided points. /// </summary> /// <param name="points">The points.</param> public void ResetPoints(IEnumerable <Vector2> points) { this._points.Clear(); this._points.AddRange(points); this._boundingArea = this.CreateBoundingArea(); }
public static ArrayList<RectangleF> OptimizeBoundingArea(BoundingArea boundingArea) { return OptimizeBoundingArea(boundingArea.Rectangles); }