コード例 #1
0
        public override void Render(IFractal fractal, IControlPanel controlPanel)
        {
            //Copy for the closure
            RectangleF rectangle     = controlPanel.Rectangle;
            PointF     rotationPoint = controlPanel.RotationPoint;
            PointF     zoomPoint     = controlPanel.ZoomPoint;

            ITransformation transformation = controlPanel.CreateTransformation();

            _rendererThread.Enqueue((cancellableArg) =>
            {
                try
                {
                    using (Graphics g = _fractalView.CreateViewGraphic())
                    {
                        g.Clear(Color.White);
                        using (Brush brush = new SolidBrush(Color.Yellow))
                        {
                            PointF p = transformation.Apply(zoomPoint);
                            g.FillRectangle(brush, p.X, p.Y, 5, 5);
                        }
                        using (Brush brush = new SolidBrush(Color.Orange))
                        {
                            PointF p = transformation.Apply(rotationPoint);
                            g.FillRectangle(brush, p.X, p.Y, 5, 5);
                        }
                        using (Brush brush = new SolidBrush(Color.Black))
                        {
                            DrawFractalPoints(brush, transformation, rectangle, fractal, g, cancellableArg);
                        }
                        using (Brush brush = new SolidBrush(Color.Green))
                        {
                            PointF p = transformation.Apply(zoomPoint);
                            g.FillRectangle(brush, p.X, p.Y, 5, 5);
                        }
                        using (Brush brush = new SolidBrush(Color.DarkOrange))
                        {
                            PointF p = transformation.Apply(rotationPoint);
                            g.FillRectangle(brush, p.X, p.Y, 5, 5);
                        }
                    }
                }
                catch (Exception e)//Catching exception in case the view is closed while still drawing in the panel
                {
                }
            });
        }
コード例 #2
0
        protected override void ZoomIn(object sender, FractalRendererLibrary.Events.ZoomEventArgs ze)
        {
            try
            {
                _controlPanel.BeginTransaction();
                ITransformation fromPixelTransformation = _controlPanel.CreateInverseTransformation();
                PointF          toScreen = fromPixelTransformation.Apply(ze.ZoomPoint);

                _controlPanel.XTranslation = ze.ZoomPoint.X;
                _controlPanel.YTranslation = ze.ZoomPoint.Y;
                //PointF currentZoomPoint = toPixelTransformation.Apply(_controlPanel.ZoomPoint);
                _controlPanel.Zoom     += 50;
                _controlPanel.ZoomPoint = toScreen;// new System.Drawing.PointF(ze.ZoomPoint.X, ze.ZoomPoint.Y);
            }
            finally
            {
                _controlPanel.CommitTransaction();
            }
        }
        protected override void DrawFractalPoints(Brush brush,
                                                  ITransformation transformation, RectangleF viewPort, IFractal fractal, Graphics g, CancellableRenderingEventArg cancellableArg)
        {
            //Less memory used, transforming and painting
            //foreach (var point in fractal.Points)
            //{
            //    if (cancellableArg.IsCancelled())
            //        return;
            //    PointF p = transformation.Apply(point);
            //    if (rectangle.Contains(p))
            //        g.FillRectangle(brush, p.X, p.Y, 2, 2);
            //}
            //Parallelize this
            DateTime start            = DateTime.Now;
            var      resultCollection = new ConcurrentBag <PointF>();
            var      points           = fractal.Points;

            Parallel.ForEach(fractal.Points, (point) =>
            {
                resultCollection.Add(transformation.Apply(point));
            });

            DateTime stop = DateTime.Now;
            TimeSpan ts   = stop - start;

            LoggerProvider.Instance.Trace(fractal.Name + ": " + points.Count + "->" + ts.TotalMilliseconds);
            foreach (var p in resultCollection)
            {
                if (cancellableArg.IsCancelled())
                {
                    return;
                }
                if (viewPort.Contains(p))
                {
                    g.FillRectangle(brush, p.X, p.Y, 1, 1);
                }
            }
        }
 protected override void DrawFractalPoints(Brush brush,
                                           ITransformation transformation, RectangleF viewPort, IFractal fractal, Graphics g, CancellableRenderingEventArg cancellableArg)
 {
     //Less memory used, transforming and painting
     try
     {
         foreach (var point in fractal.Points)
         {
             if (cancellableArg.IsCancelled())
             {
                 return;
             }
             PointF p = transformation.Apply(point);
             if (viewPort.Contains(p))
             {
                 g.FillRectangle(brush, p.X, p.Y, 1, 1);
             }
         }
     }
     catch (Exception e)//If closing the view while still drawing,
     {
     }
 }
コード例 #5
0
 public virtual PointF Apply(PointF point)
 {
     return(_transformation.Apply(point));
 }