예제 #1
0
        /// <summary>
        /// implements the Bresenham's line algorithm
        /// </summary>
        /// <param name="vertices">ArrayList of points (shape2grid.pixel struct) in grid coordinates</param>
        /// <param name="gridPixels">ArrayList of pixels on the rasterized line</param>
        private void LineBresenham(ArrayList vertices, ArrayList gridPixels)
        {
            //declaration of local variables
            GridPixel px, pxOne, pxTwo;
            int       index        = 0;
            int       num_vertices = vertices.Count;
            int       num_edges    = num_vertices - 1;
            LineEdge  curEdge;

            if (num_vertices < 2)
            {
                //in this case, handle the line as a single point
                gridPixels.Add((GridPixel)vertices[0]);
                return;
            }

            curEdge = new LineEdge((GridPixel)vertices[0], (GridPixel)vertices[1]);
            // add the first pixel
            px.col = curEdge.CurX;
            px.row = curEdge.CurY;
            gridPixels.Add(px);

            // loop through all line edges
            while (index < num_edges)
            {
                // initialize edge
                pxOne = (GridPixel)vertices[index];
                pxTwo = (GridPixel)vertices[index + 1];
                curEdge.Reset(pxOne.col, pxOne.row, pxTwo.col, pxTwo.row);

                // loop through all pixels on the edge
                while (curEdge.NextPixel())
                {
                    // set the value of current pixel
                    px.col = curEdge.CurX;
                    px.row = curEdge.CurY;
                    gridPixels.Add(px);
                }
                ++index;
            }
        }
예제 #2
0
파일: Rasterizer.cs 프로젝트: qlands/GOBLET
        /// <summary>
        /// implements the Bresenham's line algorithm
        /// </summary>
        /// <param name="vertices">ArrayList of points (shape2grid.pixel struct) in grid coordinates</param>
        /// <param name="gridPixels">ArrayList of pixels on the rasterized line</param>
        private void LineBresenham(ArrayList vertices, ArrayList gridPixels)
        {
            //declaration of local variables
            GridPixel px, pxOne, pxTwo;
            int index = 0;
            int num_vertices = vertices.Count;
            int num_edges = num_vertices - 1;
            LineEdge curEdge;
            if (num_vertices < 2)
            {
            //in this case, handle the line as a single point
            gridPixels.Add((GridPixel)vertices[0]);
            return;
            }

            curEdge = new LineEdge((GridPixel)vertices[0], (GridPixel)vertices[1]);
            // add the first pixel
            px.col = curEdge.CurX;
            px.row = curEdge.CurY;
            gridPixels.Add(px);

            // loop through all line edges
            while (index < num_edges)
            {
            // initialize edge
            pxOne = (GridPixel) vertices[index];
            pxTwo = (GridPixel)vertices[index + 1];
            curEdge.Reset(pxOne.col, pxOne.row, pxTwo.col, pxTwo.row);

            // loop through all pixels on the edge
            while (curEdge.NextPixel())
            {
                // set the value of current pixel
                px.col = curEdge.CurX;
                px.row = curEdge.CurY;
                gridPixels.Add(px);
            }
            ++index;
            }
        }