public object getSquarePolygonsAroundCoordinates(ColorMapper cmap, Color colorFactor)
        {
            List <Polygon> polygons = new List <Polygon>();

            for (int xi = 0; xi <= x.Length - 2; xi++)
            {
                for (int yi = 0; yi <= y.Length - 2; yi++)
                {
                    // Compute quad making a polygon
                    Point[] p = getEstimatedQuadSurroundingPoint(xi, yi);
                    if ((!validZ(p)))
                    {
                        continue;
                        // ignore non valid set of points
                    }
                    if (((cmap != null)))
                    {
                        p[0].Color = cmap.Color(p[0].xyz);
                        p[1].Color = cmap.Color(p[1].xyz);
                        p[2].Color = cmap.Color(p[2].xyz);
                        p[3].Color = cmap.Color(p[3].xyz);
                    }
                    if (((colorFactor != null)))
                    {
                        p[0].rgb.mul(colorFactor);
                        p[1].rgb.mul(colorFactor);
                        p[2].rgb.mul(colorFactor);
                        p[3].rgb.mul(colorFactor);
                    }
                    // Store quad
                    Polygon quad = new Polygon();
                    for (int pi = 0; pi <= p.Length - 1; pi++)
                    {
                        quad.Add(p[pi]);
                    }
                    polygons.Add(quad);
                }
            }
            return(polygons);
        }
示例#2
0
 public override void Draw(Rendering.View.Camera cam)
 {
     if ((_transform != null))
     {
         _transform.Execute();
     }
     if (_facestatus)
     {
         ApplyPolygonModeFill();
         if (_wfstatus & _polygonOffsetFillEnable)
         {
             EnablePolygonOffsetFill();
         }
         GL.Begin(BeginMode.Polygon);
         foreach (Point p in _points)
         {
             if ((_mapper != null))
             {
                 p.Color = _mapper.Color(p.xyz);
             }
             GL.Color4(p.Color.r, p.Color.g, p.Color.b, p.Color.a);
             GL.Vertex3(p.xyz.x, p.xyz.y, p.xyz.z);
         }
         GL.End();
         if (_wfstatus & _polygonOffsetFillEnable)
         {
             DisablePolygonOffsetFill();
         }
     }
     if (_wfstatus)
     {
         ApplyPolygonModeLine();
         if (_polygonOffsetFillEnable)
         {
             EnablePolygonOffsetFill();
         }
         GL.Color4(_wfcolor.r, _wfcolor.g, _wfcolor.b, _wfcolor.a);
         GL.LineWidth(_wfwidth);
         GL.Begin(BeginMode.Polygon);
         foreach (Point p in _points)
         {
             GL.Vertex3(p.xyz.x, p.xyz.y, p.xyz.z);
         }
         GL.End();
         if (_polygonOffsetFillEnable)
         {
             DisablePolygonOffsetFill();
         }
     }
 }
示例#3
0
        public System.Drawing.Bitmap toImage(int width, int height, int barWidth)
        {
            if ((barWidth > width))
            {
                return(null);
            }
            // Init image output
            System.Drawing.Bitmap   image   = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(image);
            int txtSize = 12;

            // Draw background
            if (_hasBackground)
            {
                graphic.FillRectangle(new System.Drawing.SolidBrush(_backgroundColor.toColor()), 0, 0, width, height);
            }
            // Draw colorbar centering in half the Legend text height
            for (int h = txtSize / 2; h <= (height - txtSize / 2); h++)
            {
                // Compute value & color
                float v = _min + (_max - _min) * h / (height - txtSize);
                //			Color c = mapper.getColor(new Coord3d(0,0,v));
                Color c = _mapper.Color(v);
                //To allow the Color to be a variable independent of the coordinates
                // Draw line
                graphic.DrawLine(new System.Drawing.Pen(new System.Drawing.SolidBrush(c.toColor())), 0, height - h, barWidth, height - h);
            }
            // Contour of bar
            graphic.FillRectangle(new System.Drawing.SolidBrush(_foregroundColor.toColor()), 0, Convert.ToSingle(txtSize / 2), barWidth, height - txtSize);
            // Text annotation
            if (((_provider != null)))
            {
                float[] ticks = _provider.generateTicks(_min, _max);
                float   ypos  = 0;
                string  txt   = null;
                for (int t = 0; t <= ticks.Length - 1; t++)
                {
                    //			ypos = (int)(height-height*((ticks[t]-min)/(max-min)));
                    ypos = txtSize + (height - txtSize - (height - txtSize) * ((ticks[t] - _min) / (_max - _min)));
                    //Making sure that the first and last tick appear in the colorbar
                    txt = _renderer.Format(ticks[t]);
                    graphic.DrawString(txt, new System.Drawing.Font("Arial", txtSize, System.Drawing.GraphicsUnit.Pixel), new System.Drawing.SolidBrush(_foregroundColor.toColor()), barWidth + 1, ypos);
                }
            }
            return(image);
        }
示例#4
0
        public override void Draw(Camera cam)
        {
            _transform?.Execute();

            GL.PointSize(_width);
            GL.Begin(BeginMode.Points);

            if (_coordinates != null)
            {
                foreach (Coord3d c in _coordinates)
                {
                    var color = _mapper.Color(c); // TODO: should store result in the point color
                    GL.Color4(color.r, color.g, color.b, color.a);
                    GL.Vertex3(c.x, c.y, c.z);
                }
            }
            GL.End();

            // doDrawBounds (MISSING)
        }
示例#5
0
        /// <summary>
        /// Load data standing on an orthonormal grid.
        /// <br/>
        /// Each input point (i.e. the association of x(i), y(j), z(i)(j)) will be
        /// represented by a polygon centered on this point. The default coordinates
        /// of this polygon will be:
        /// <ul>
        /// <li>x(i-1), y(j+1), z(i-1)(j+1)</li>
        /// <li>x(i-1), y(j-1), z(i-1)(j-1)</li>
        /// <li>x(i+1), y(j-1), z(i+1)(j-1)</li>
        /// <li>x(i+1), y(j+1), z(i+1)(j+1)</li>
        /// </ul>
        /// There are thus three types of polygons:
        /// <ul>
        /// <li>those that stand completely inside the ringMin and ringMax radius and
        /// that have the previous coordinates.</li>
        /// <li>those that stand completely outside the ringMin and ringMax radius and
        /// that won't be added to the list of polygons.</li>
        /// <li>those that have some points in and some points out of the ringMin and
        /// ringMax radius. These polygons are recomputed so that "out" points are replaced
        /// by two points that make the smooth contour. According to the number of "out"
        /// points, the modified polygon will gather 3, 4, or 5 points.</li>
        /// </ul>
        /// <br/>
        /// As a consequence, it is suggested to provide data ranging outside of ringMin
        /// and ringMax, in order to be sure to have a perfect round surface.
        /// </summary>
        public List <Polygon> getInterpolatedRingPolygons()
        {
            List <Polygon> polygons = new List <Polygon>();

            bool[] isIn = null;
            for (int xi = 0; xi <= x.Length - 2; xi++)
            {
                for (int yi = 0; yi <= y.Length - 2; yi++)
                {
                    // Compute points surrounding current point
                    Point[] p = getRealQuadStandingOnPoint(xi, yi);
                    p[0].Color = _cmap.Color(p[0].xyz);
                    p[1].Color = _cmap.Color(p[1].xyz);
                    p[2].Color = _cmap.Color(p[2].xyz);
                    p[3].Color = _cmap.Color(p[3].xyz);
                    p[0].rgb.mul(_factor);
                    p[1].rgb.mul(_factor);
                    p[2].rgb.mul(_factor);
                    p[3].rgb.mul(_factor);
                    float[] radius = new float[p.Length];
                    for (int i = 0; i <= p.Length - 1; i++)
                    {
                        radius[i] = radius2d(p[i]);
                    }
                    // Compute status of each point according to there radius, or NaN status
                    isIn = isInside(p, radius, _ringMin, _ringMax);
                    // Ignore polygons that are out
                    if (((!isIn[0]) & (!isIn[1]) & (!isIn[2]) & (!isIn[3])))
                    {
                        continue;
                    }
                    if ((isIn[0] & isIn[1] & isIn[2] & isIn[3]))
                    {
                        // Directly store polygons that have non NaN values for all points
                        Polygon quad = new Polygon();
                        for (int pi = 0; pi <= p.Length - 1; pi++)
                        {
                            quad.Add(p[pi]);
                        }
                        polygons.Add(quad);
                    }
                    else
                    {
                        // Partly inside: generate points that intersect a radius
                        Polygon polygon      = new Polygon();
                        Point   intersection = default(Point);
                        // generated point
                        float ringRadius = 0;
                        int[] seq        =
                        {
                            0,
                            1,
                            2,
                            3,
                            0
                        };
                        bool[] done = new bool[4];
                        for (int pi = 0; pi <= done.Length - 1; pi++)
                        {
                            done[pi] = false;
                        }
                        // Handle all square edges and shift "out" points
                        for (int s = 0; s <= seq.Length - 2; s++)
                        {
                            // Case of point s "in" and point s+1 "in"
                            if ((isIn[seq[s]] & isIn[seq[s + 1]]))
                            {
                                if ((!done[seq[s]]))
                                {
                                    polygon.Add(p[seq[s]]);
                                    done[seq[s]] = true;
                                }
                                if ((!done[seq[s + 1]]))
                                {
                                    polygon.Add(p[seq[s + 1]]);
                                    done[seq[s + 1]] = true;
                                }
                            }
                            else if ((isIn[seq[s]] & (!isIn[seq[s + 1]])))
                            {
                                // Case of point s "in" and point s+1 "out"
                                if ((!done[seq[s]]))
                                {
                                    polygon.Add(p[seq[s]]);
                                    done[seq[s]] = true;
                                }
                                // Select the radius on which the point is supposed to stand
                                if ((Math.Abs(radius[seq[s + 1]] - _ringMin) < Math.Abs(radius[seq[s + 1]] - _ringMax)))
                                {
                                    ringRadius = _ringMin;
                                }
                                else
                                {
                                    ringRadius = _ringMax;
                                }
                                // Generate a point on the circle that replaces s+1
                                intersection       = findPoint(p[seq[s]], p[seq[s + 1]], ringRadius);
                                intersection.Color = _cmap.Color(intersection.xyz);
                                intersection.rgb.mul(_factor);
                                polygon.Add(intersection);
                            }
                            else if (((!isIn[seq[s]]) & isIn[seq[s + 1]]))
                            {
                                //Case of point s "out" and point s+1 "in"
                                // Select the radius on which the point is supposed to stand
                                if ((Math.Abs(radius[seq[s + 1]] - _ringMin) < Math.Abs(radius[seq[s + 1]] - _ringMax)))
                                {
                                    ringRadius = _ringMin;
                                }
                                else
                                {
                                    ringRadius = _ringMax;
                                }
                                // Generate a point on the circle that replaces s
                                intersection       = findPoint(p[seq[s]], p[seq[s + 1]], ringRadius);
                                intersection.Color = _cmap.Color(intersection.xyz);
                                intersection.rgb.mul(_factor);
                                polygon.Add(intersection);
                                if ((!done[seq[s + 1]]))
                                {
                                    polygon.Add(p[seq[s + 1]]);
                                    done[seq[s + 1]] = true;
                                }
                            }
                            // end case 3
                        }
                        // end polygon construction loop
                        polygons.Add(polygon);
                    }
                    // end switch quad/polygon
                }
                // end for y
            }
            // end for x
            return(polygons);
        }