コード例 #1
0
 public void Draw(ref Bitmap bitmap, PlotProperties plotprops)
 {
     foreach (IShape shape in ShapeList)
     {
         shape.Draw(ref bitmap, plotprops);
     }
 }
コード例 #2
0
        public static Coordinate CalculateImageXYmin(Bitmap b, PlotProperties PlotProps)
        {
            //Calculate Bottom Corner Point after scaling
            double w = Convert.ToDouble(b.Width);
            double h = Convert.ToDouble(b.Height);

            double xmin = PlotProps.Xmin;
            double xmax = PlotProps.Xmax;
            double ymin = PlotProps.Ymin;
            double ymax = PlotProps.Ymax;

            double delX = xmax - xmin;
            double delY = ymax - ymin;

            double SF = CalculateScaleFactor(b, PlotProps);

            //calculate empty space -- one of these will be zero
            double cx = 0.5 * (w / SF - delX);
            double cy = 0.5 * (h / SF - delY);

            //Image bottom corner coordinate
            double _xmin = xmin - cx;
            double _ymin = ymin - cy;

            Coordinate coord = new Coordinate {
                x = _xmin, y = _ymin
            };

            return(coord);
        }
コード例 #3
0
            public override void Draw(ref Bitmap bitmap, PlotProperties plotprops)
            {
                double theta_degree = theta * 180 / Math.PI;
                double SF           = ImageUtil.CalculateScaleFactor(bitmap, plotprops);

                int _b1 = (int)(b1 * SF);
                int _b2 = (int)(b2 * SF);
                int _t  = (int)(t * SF);
                int _r  = (int)(r * SF);
                int _R  = (_r + _t);

                if (_r < 1)
                {
                    _r = 1;
                }                      //_r must be at least one pixel
                if (_R < 1)
                {
                    _R = 1;
                }                      //_R must also be at least one pixel (not an issue as long as t isn't super small)

                int wdth = bitmap.Width;
                int hght = bitmap.Height;

                Graphics g = Graphics.FromImage(bitmap);

                GraphicsPath path = new GraphicsPath();

                path.AddLine(0, _R, 0, _b2);
                path.AddLine(0, _b2, _t, _b2);
                path.AddLine(_t, _b2, _t, _t + _r);
                path.AddArc(new System.Drawing.Rectangle(_t, _t, 2 * _r, 2 * _r), 180, 90);
                path.AddLine(_t + _r, _t, _b1, _t);
                path.AddLine(_b1, _t, _b1, 0);
                path.AddLine(_b1, 0, _R, 0);
                path.AddArc(new System.Drawing.Rectangle(0, 0, 2 * _R, 2 * _R), 270, -90);
                path.CloseFigure();

                PointF pnt = CreateImagePoint(SF);

                Coordinate xy_min = ImageUtil.CalculateImageXYmin(bitmap, plotprops);

                double Xdel = xp - xy_min.x;
                double Ydel = yp - xy_min.y;

                Matrix mtrx = ImageUtil.ImageTransformationMatrix(bitmap, pnt, theta_degree, Xdel, Ydel, SF, mirrorX, mirrorY);

                path.Transform(mtrx);

                Color _fillColor = Material.ConvertFillColor();

                Pen _pen = new Pen(borderColor, borderThickness);

                _pen.Alignment = PenAlignment.Inset;
                g.FillPath(new SolidBrush(_fillColor), path);
                g.DrawPath(_pen, path);

                _pen.Dispose();
                g.Dispose();
            }
コード例 #4
0
        public PlotProperties GetPlotProperties(double plotpadding)
        {
            PlotProperties pp = new PlotProperties
            {
                Xmin = Min.x - plotpadding,
                Xmax = Max.x + plotpadding,
                Ymin = Min.y - plotpadding,
                Ymax = Max.y + plotpadding
            };

            return(pp);
        }
コード例 #5
0
            private double _R; //outer radius

            public override void Draw(ref Bitmap bitmap, PlotProperties plotprops)
            {
                double theta_degree = theta * 180 / Math.PI;
                double SF           = ImageUtil.CalculateScaleFactor(bitmap, plotprops);

                int int_r     = (int)(r * SF);
                int int_R     = (int)(_R * SF);
                int int_t     = (int)(t * SF);
                int deg_alpha = (int)(alpha * 180 / Math.PI);

                double cos = (Math.Cos(alpha));
                double sin = (Math.Sin(alpha));


                int wdth = bitmap.Width;
                int hght = bitmap.Height;

                Graphics g = Graphics.FromImage(bitmap);

                GraphicsPath path = new GraphicsPath();

                path.AddLine((int)(int_r * cos), (int)(int_r * sin), (int)(int_R * cos), (int)(int_R * sin));
                path.AddArc(new System.Drawing.Rectangle(-int_R, -int_R, 2 * int_R, 2 * int_R), deg_alpha, -2 * deg_alpha);
                path.AddLine((int)(int_R * cos), (int)(-int_R * sin), (int)(int_r * cos), (int)(-int_r * sin));
                path.AddArc(new System.Drawing.Rectangle(-int_r, -int_r, 2 * int_r, 2 * int_r), -deg_alpha, 2 * deg_alpha);
                path.CloseFigure();

                PointF pnt = CreateImagePoint(SF);

                Coordinate xy_min = ImageUtil.CalculateImageXYmin(bitmap, plotprops);

                double Xdel = xp - xy_min.x;
                double Ydel = yp - xy_min.y;

                Matrix mtrx = ImageUtil.ImageTransformationMatrix(bitmap, pnt, theta_degree, Xdel, Ydel, SF, mirrorX, mirrorY);

                path.Transform(mtrx);

                Color _fillColor = Material.ConvertFillColor();

                Pen _pen = new Pen(borderColor, borderThickness);

                _pen.Alignment = PenAlignment.Inset;
                g.FillPath(new SolidBrush(_fillColor), path);
                g.DrawPath(_pen, path);

                _pen.Dispose();
                g.Dispose();
            }
コード例 #6
0
            public override void Draw(ref Bitmap bitmap, PlotProperties plotprops)
            {
                double theta_degree = theta * 180 / Math.PI;
                double SF           = ImageUtil.CalculateScaleFactor(bitmap, plotprops);

                int _r = (int)(r * SF);

                if (_r <= 2)
                {
                    //throws error if shape doesn't take up enough pixels
                    return;
                }

                int wdth = bitmap.Width;
                int hght = bitmap.Height;

                Graphics g = Graphics.FromImage(bitmap);

                GraphicsPath path = new GraphicsPath();

                path.AddLine(0, 0, 0, _r);
                path.AddArc(new System.Drawing.Rectangle(0, 0, 2 * _r, 2 * _r), 180, 90);
                path.AddLine(_r, 0, 0, 0);
                path.CloseFigure();

                PointF pnt = CreateImagePoint(SF);

                Coordinate xy_min = ImageUtil.CalculateImageXYmin(bitmap, plotprops);

                double Xdel = xp - xy_min.x;
                double Ydel = yp - xy_min.y;

                Matrix mtrx = ImageUtil.ImageTransformationMatrix(bitmap, pnt, theta_degree, Xdel, Ydel, SF, mirrorX, mirrorY);

                path.Transform(mtrx);

                Color _fillColor = Material.ConvertFillColor();

                Pen _pen = new Pen(borderColor, borderThickness);

                _pen.Alignment = PenAlignment.Inset;
                g.FillPath(new SolidBrush(_fillColor), path);
                g.DrawPath(_pen, path);

                _pen.Dispose();
                g.Dispose();
            }
コード例 #7
0
            public override void Draw(ref Bitmap bitmap, PlotProperties plotprops)
            {
                double theta_degree = theta * 180 / Math.PI;
                double SF           = ImageUtil.CalculateScaleFactor(bitmap, plotprops);

                float _b = (float)(b * SF);
                float _t = (float)(t * SF);

                int wdth = bitmap.Width;
                int hght = bitmap.Height;

                Graphics g = Graphics.FromImage(bitmap);

                GraphicsPath path = new GraphicsPath();

                path.AddLine(0, 0, 0, _t);
                path.AddLine(0, _t, _b, _t);
                path.AddLine(_b, _t, _b, 0);
                path.AddLine(_b, 0, 0, 0);
                path.CloseFigure();

                PointF pnt = CreateImagePoint(SF);

                Coordinate xy_min = ImageUtil.CalculateImageXYmin(bitmap, plotprops);

                double Xdel = xp - xy_min.x;
                double Ydel = yp - xy_min.y;

                Matrix mtrx = ImageUtil.ImageTransformationMatrix(bitmap, pnt, theta_degree, Xdel, Ydel, SF, mirrorX, mirrorY);

                path.Transform(mtrx);

                Color _fillColor = Material.ConvertFillColor();

                Pen _pen = new Pen(borderColor, borderThickness);

                _pen.Alignment = PenAlignment.Inset;
                g.FillPath(new SolidBrush(_fillColor), path);
                g.DrawPath(_pen, path);

                _pen.Dispose();
                g.Dispose();
            }
コード例 #8
0
        public static double CalculateScaleFactor(Bitmap b, PlotProperties PlotProps)
        {
            double w = Convert.ToDouble(b.Width);
            double h = Convert.ToDouble(b.Height);

            double xmin = PlotProps.Xmin;
            double xmax = PlotProps.Xmax;
            double ymin = PlotProps.Ymin;
            double ymax = PlotProps.Ymax;

            double delX = xmax - xmin;
            double delY = ymax - ymin;

            double SFX = w / delX;
            double SFY = h / delY;

            double SF;

            SF = (SFX < SFY) ? SFX : SFY;

            return(SF);
        }
コード例 #9
0
            public override void Draw(ref Bitmap bitmap, PlotProperties plotprops)
            {
                double theta_degree = theta * 180 / Math.PI;
                double SF           = ImageUtil.CalculateScaleFactor(bitmap, plotprops);

                int _b1 = (int)(b1 * SF);
                int _t1 = (int)(t1 * SF);
                int _b2 = (int)(b2 * SF);
                int _t2 = (int)(t2 * SF);
                int _r1 = (int)(r1 * SF);
                int _r2 = (int)(r2 * SF);
                int _h  = (int)(h * SF);
                int _tw = (int)(tw * SF);

                int wdth = bitmap.Width;
                int hght = bitmap.Height;

                if (_r1 < 1)
                {
                    _r1 = 1;
                }
                if (_r2 < 1)
                {
                    _r2 = 1;
                }

                Graphics g = Graphics.FromImage(bitmap);

                GraphicsPath path = new GraphicsPath();

                path.AddLine(0, 0, 0, _h - _t2 - _r2);
                path.AddArc(new System.Drawing.Rectangle(-_r2 * 2, _h - _t2 - _r2 * 2, _r2 * 2, _r2 * 2), 0, 90);
                path.AddLine(-_r2, _h - _t2, -_b2 + _tw, _h - _t2);
                path.AddLine(-_b2 + _tw, _h - _t2, -_b2 + _tw, _h);
                path.AddLine(-_b2 + _tw, _h, _tw, _h);
                path.AddLine(_tw, _h, _tw, _t1 + _r1);
                path.AddArc(new System.Drawing.Rectangle(_tw, _t1, _r1 * 2, _r1 * 2), 180, 90);
                path.AddLine(_tw + _r1, _t1, _b1, _t1);
                path.AddLine(_b1, _t1, _b1, 0);
                path.AddLine(_b1, 0, 0, 0);
                path.CloseFigure();

                PointF pnt = CreateImagePoint(SF);

                Coordinate xy_min = ImageUtil.CalculateImageXYmin(bitmap, plotprops);

                double Xdel = xp - xy_min.x;
                double Ydel = yp - xy_min.y;

                Matrix mtrx = ImageUtil.ImageTransformationMatrix(bitmap, pnt, theta_degree, Xdel, Ydel, SF, mirrorX, mirrorY);

                path.Transform(mtrx);

                Color _fillColor = Material.ConvertFillColor();

                Pen _pen = new Pen(borderColor, borderThickness);

                _pen.Alignment = PenAlignment.Inset;
                g.FillPath(new SolidBrush(_fillColor), path);
                g.DrawPath(_pen, path);

                _pen.Dispose();
                g.Dispose();
            }
コード例 #10
0
 public abstract void Draw(ref Bitmap bitmap, PlotProperties plotprops);