Example #1
0
        /// <summary>
        /// ビットマップにベクトル図を描画します。
        /// </summary>
        /// <param name="bmp">描画先の System.Drawing.Bitmap</param>
        /// <param name="data">元となる 2 次元配列データ</param>
        /// <exception cref="Visualization.VectorDataNotFoundException">ベクトルデータがないときに投げられます。</exception>
        public override void DrawTo( Canvas canvas, IDataSheet data )
        {
            Bitmap bmp = canvas.Bitmap;
            if( !this.Setting.Show )
            {
                return;
            }
            if( !data.HasVectorData )
            {
                throw new VectorDataNotFoundException( "ベクトルデータがありません" );
            }
            if( !this.Setting.IsLengthFixed )
            {
                this.Setting.ReferredLength = data.MaxVector;
            }
            Graphics g = Graphics.FromImage( bmp );
            Pen p = new Pen( Setting.LineColor );
            Brush b = new SolidBrush( Setting.InnerColor );

            ArrowDrawer d = new ArrowDrawer( g, this.Setting, data.MaxVector, data.MinVector );

            int start = (this.Setting.Interval > 1) ? this.Setting.Offset : 0;
            int step = this.Setting.Interval;

            HashSet<int> iSet = new HashSet<int>();
            HashSet<int> jSet = new HashSet<int>();

            if( this.Setting.FixedBound )
            {
                iSet.Add( 0 );
                jSet.Add( 0 );
            }
            for( int i=start; i<data.Columns; i += step )
            {
                iSet.Add( i );
            }
            for( int j=start; j<data.Rows; j += step )
            {
                jSet.Add( j );
            }
            if( this.Setting.FixedBound )
            {
                iSet.Add( data.Columns-1 );
                jSet.Add( data.Rows-1 );
            }

            foreach( var i in iSet )
            {
                foreach( var j in jSet )
                {
                    Point pt = canvas.AsBitmapCoord( data.GetX( i ), data.GetY( j ) );
                    double u = data.GetU( i, j );
                    double v = data.GetV( i, j );
                    double len = Math.Sqrt( u*u + v*v );
                    d.DrawArrow( pt, u, v );
                }
            }
        }
Example #2
0
 public override void DrawTo( Canvas canvas, IDataSheet data )
 {
     if( !Setting.Show )
     {
         return;
     }
     Graphics g = Graphics.FromImage( canvas.Bitmap );
     Pen p = new Pen( Color.Black );
     for( int i=0; i<data.Columns; i++ )
     {
         for( int j=0; j<data.Rows; j++ )
         {
             Point pt = canvas.AsBitmapCoord( data.GetX( i ), data.GetY( j ) );
             g.DrawRectangle( p, pt.X - 1, pt.Y -1, 2, 2 );
         }
     }
 }
Example #3
0
 public abstract void DrawTo( Canvas canvas, IDataSheet data );
Example #4
0
        public override void DrawTo( Canvas canvas, IDataSheet data )
        {
            Bitmap bmp = canvas.Bitmap;
            if( !this.Setting.Show )
            {
                return;
            }
            if( this.Setting.AutoScaleColor )
            {
                this.Setting.MaxValue = data.MaxZ;
                this.Setting.MinValue = data.MinZ;
            }
            this.Setting.PropertyChanged = false;
            double max = this.Setting.MaxValue;
            double min = this.Setting.MinValue;
            BitmapData bd = canvas.Bitmap.LockBits( new Rectangle( 0, 0, canvas.Bitmap.Width, canvas.Bitmap.Height ), ImageLockMode.WriteOnly, canvas.Bitmap.PixelFormat );
            try
            {
                IntPtr scan0 = bd.Scan0;
                byte[] bytes = new byte[canvas.Bitmap.Width*canvas.Bitmap.Height*4];
                for( int i=0; i<bytes.Length; i+=4 )	// 白で初期化
                {
                    bytes[i+0] = 255; // as B
                    bytes[i+1] = 255; // as G
                    bytes[i+2] = 255; // as R
                    bytes[i+3] = 255; // as A
                }
                int width = canvas.DrawingWidth;	// コンターの幅
                int height = canvas.DrawingHeight;	// コンターの高さ

                double xBtoDRate = 1.0 / (width - 1);		// bmp 座標 → データ座標変換用
                double yBtoDRate = 1.0 / (height - 1);

                double newValue = 0;	// バイリニア補間されたデータ
                int index = 0;			// バイト配列アクセス用
                int hue = 0;			// 色相

                int dataYIndex = 0;

                for( int j=0; j<height; j++ )
                {
                    index = 4*(((height+canvas.Setting.Margin.Top)-1-j)*bmp.Width + canvas.Setting.Margin.Left);
                    double y = yBtoDRate*j;	// j のピクセル位置をデータ座標で表す
                    while( !(data.GetY( dataYIndex ) <= y && y <= data.GetY( dataYIndex+1 )) )
                    {
                        dataYIndex++;
                    }
                    double y0 = data.GetY( dataYIndex );
                    double y1 = data.GetY( dataYIndex+1 );

                    int dataXIndex = 0;

                    for( int i=0; i<width; i++ )
                    {
                        // bilinear interporation
                        double x = xBtoDRate*i;
                        while( !(data.GetX( dataXIndex ) <= x && x <= data.GetX( dataXIndex+1 )) )
                        {
                            dataXIndex++;
                        }
                        double x0 = data.GetX( dataXIndex );
                        double x1 = data.GetX( dataXIndex+1 );

                        double vx0y0 = data.GetZ( dataXIndex, dataYIndex );
                        double vx0y1 = data.GetZ( dataXIndex, dataYIndex+1 );
                        double vx1y0 = data.GetZ( dataXIndex+1, dataYIndex );
                        double vx1y1 = data.GetZ( dataXIndex+1, dataYIndex+1 );

                        newValue = bilinearInterpolation( x0, x, x1, y0, y, y1, vx0y0, vx0y1, vx1y0, vx1y1 );

                        hue = (int)((newValue - min) / (max - min) * 359.0);
                        if( hue >= 360 ) hue = 359;
                        if( hue < 0 ) hue = 0;
                        bytes[index+0] = ColorBar.FromHue( hue ).B;
                        bytes[index+1] = ColorBar.FromHue( hue ).G;
                        bytes[index+2] = ColorBar.FromHue( hue ).R;
                        bytes[index+3] = 255;		// as A
                        index += 4;
                    }
                }
                Marshal.Copy( bytes, 0, scan0, bytes.Length );
            }
            finally
            {
                bmp.UnlockBits( bd );
            }
        }
Example #5
0
        public override void DrawTo( Canvas canvas, IDataSheet data )
        {
            Bitmap bmp = canvas.Bitmap;
            if( !this.Setting.Show )
            {
                return;
            }
            if( !this.Setting.IsLengthFixed )
            {
                double absMax = (Math.Abs( data.MaxZ ) > Math.Abs( data.MinZ ))	? Math.Abs( data.MaxZ )
                                                                                : Math.Abs( data.MinZ );
                if( absMax == 0 ) absMax = 1;
                this.Setting.ReferredLength = absMax;
            }

            Graphics g = Graphics.FromImage( bmp );

            SolidBrush plotBlush = new SolidBrush( Setting.PlotColor );
            Pen plotPen = new Pen( Setting.PlotFrameColor );
            Pen linePen = new Pen( Setting.LineColor, Setting.LineWidth );
            Pen axisPen = new Pen( Setting.AxisColor, Setting.AxisWidth );

            Point lefttop = canvas.AsBitmapCoord( 0, 1 );
            Point rightbottom = canvas.AsBitmapCoord( 1, 0 );

            g.DrawRectangle( axisPen, lefttop.X, lefttop.Y, canvas.DrawingWidth, canvas.DrawingHeight );

            if( Setting.ReferenceI >= data.Columns ) Setting.ReferenceI = data.Columns - 1;
            if( Setting.ReferenceJ >= data.Rows ) Setting.ReferenceJ = data.Rows - 1;

            if( this.Setting.Horizontal )
            {
                double refY = data.GetY( this.Setting.ReferenceJ );
                g.DrawLine( axisPen, canvas.AsBitmapCoord( 0, refY ), canvas.AsBitmapCoord( 1, refY ) );
                List<Point> pt = new List<Point>();
                pt.Add( canvas.AsBitmapCoord( 0, refY ) );
                Func<int, int, double> value = (Setting.VectorMode)	? new Func<int, int, double>( data.GetV )
                                                                    : new Func<int, int, double>( data.GetZ );
                for( int i=0; i<data.Columns; i++ )
                {
                    int h = (int)(value( i, Setting.ReferenceJ )/this.Setting.ReferredLength*Setting.Scale + 0.5);
                    Point gridPt = canvas.AsBitmapCoord( data.GetX( i ), refY );
                    pt.Add( new Point( gridPt.X, gridPt.Y-h ) );
                }
                pt.Add( canvas.AsBitmapCoord( 1, refY ) );
                g.DrawLines( linePen, pt.ToArray() );
                int s = Setting.PlotSize;
                for( int i=1; i<pt.Count-1; i++ )
                {
                    g.FillEllipse( plotBlush, pt[i].X - s/2, pt[i].Y - s/2, s, s );
                    g.DrawEllipse( plotPen, pt[i].X - s/2, pt[i].Y - s/2, s, s );
                }

            }
            if( this.Setting.Vertical )
            {
                double refX = data.GetX( this.Setting.ReferenceI );
                g.DrawLine( axisPen, canvas.AsBitmapCoord( refX, 0 ), canvas.AsBitmapCoord( refX, 1 ) );
                List<Point> pt = new List<Point>();
                pt.Add( canvas.AsBitmapCoord( refX, 0 ) );
                Func<int, int, double> value = (Setting.VectorMode)	? new Func<int, int, double>( data.GetU )
                                                                    : new Func<int, int, double>( data.GetZ );
                for( int j=0; j<data.Rows; j++ )
                {
                    int h = (int)(value( Setting.ReferenceI, j )/this.Setting.ReferredLength*Setting.Scale + 0.5);
                    Point gridPt = canvas.AsBitmapCoord( refX, data.GetY( j ) );
                    pt.Add( new Point( gridPt.X+h, gridPt.Y ) );
                }
                pt.Add( canvas.AsBitmapCoord( refX, 1 ) );
                g.DrawLines( linePen, pt.ToArray() );
                int s = Setting.PlotSize;
                for( int i=1; i<pt.Count-1; i++ )
                {
                    g.FillEllipse( plotBlush, pt[i].X - s/2, pt[i].Y - s/2, s, s );
                    g.DrawEllipse( plotPen, pt[i].X - s/2, pt[i].Y - s/2, s, s );
                }
            }
        }
Example #6
0
 public Bitmap CreateBmp( int width, int height )
 {
     this.canvas = new Canvas( width, height, this.data.AspectRatio );
     foreach( var field in fields )
     {
         field.DrawTo( this.canvas, this.data );
     }
     return this.canvas.Bitmap;
 }