예제 #1
0
void scanFill (struct Object2D * object, struct Window *window, struct BufferDevice *device)
{
    int i;
    struct Point2D *pts = malloc(sizeof(object->points));
    struct Point2D *pn1, *pd1;

    int cor = object->fillColor;

    for (i = 0; i < object->curr_point; i++) {
        struct Point2D * p = &object->points[i];

        pn1 = sru2srn(p, window);
        pd1 = srn2srd(pn1, device);
        pts[i].x = pd1->x;
        pts[i].y = pd1->y;
        //pts[i].color = pd1->color;
    }

    int cnt = object->curr_point;
    int height = device->ymax;

    Edge * edges[height], * active;
    int scan;

    for (i=0; i<height; i++) {
        edges[i] = (Edge *) malloc (sizeof (Edge));
        edges[i]->next = NULL;
    }
    buildEdgeList (cnt, pts, edges);
    active = (Edge *) malloc (sizeof (Edge));
    active->next = NULL;

    for (scan=0; scan<height; scan++) {
        buildActiveList (scan, active, edges);
        if (active->next) {
            fillScan (scan, active, window, device, cor);
            updateActiveList (scan, active);
            resortActiveList (active);
        }
    }
    /* Free edge records that have been malloc'ed ... */
}
예제 #2
0
void rscnfll ( int *np, int ix[], int iy[], int *iret )
/************************************************************************
 * rscnfll								*
 *									*
 * This function draws a filled polygon on a raster bitmap.		*
 *									*
 * void rscnfll ( np, ix, iy, iret )					*
 *									*
 * Input parameters:							*
 *	*np		int		Number of points in the polygon	*
 *	ix []		int		Array of x coordinates		*
 *	iy []		int		Array of y coordinates		*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 **									*
 * Log:									*
 * E. Wehner/EAi	 4/96	Created					*
 * E. Safford/GSC	 3/97	Modified to use new cgr_ routintes 	*
 * E. Wehner/EAi	 3/97	change xsize/ysize to scanlines		*
 * M. Linda/GSC		 7/97	Added a call to RLINE following fill	*
 * S. Jacobs/NCEP	 7/97	Cleaned up header files and global vars	*
 * D.W.Plummer/NCEP	 8/97	Rewrite					*
 ***********************************************************************/
{

	int	npts, *ixarr, *iyarr, iymin, iymax, i, j, index,
		nx1, nx2, ny2;
	float	tau, xout[100];

/*---------------------------------------------------------------------*/

	*iret = G_NORMAL;

/*
 *	Get the number of points and make sure that the polygon
 *	is closed.
 */
	npts = *np;
	if ( ix[0] != ix[npts-1] || iy[0] != iy[npts-1] )  npts++;

/*
 *	Allocate space for the working arrays.
 */
	ixarr = (int *) malloc ( npts * sizeof(int) );
	iyarr = (int *) malloc ( npts * sizeof(int) );

	iymin =  INT_MAX;
	iymax = -INT_MAX;

/*
 *	Double the dimensions for easier computations. Find the min
 *	and max in the Y direction.
 */
	for ( i = 0; i < npts-1; i++ )  {
	    ixarr[i] = ix[i] * 2;
	    iyarr[i] = iy[i] * 2;
	    iymin = G_MIN ( iyarr[i], iymin );
	    iymax = G_MAX ( iyarr[i], iymax );
	}

	ixarr[npts-1] = ixarr[0];
	iyarr[npts-1] = iyarr[0];

/*
 *	For each scan line, compute intersections and fill.
 */
	for ( j = iymin+1; j < iymax; j = j+2 )  {
	
	    index = 0;

	    for ( i = 0; i < npts-1; i++ )  {

		if  ( iyarr[i] != iyarr[i+1] )  {

		    tau = (float) ( j - iyarr[i] ) /
			  (float) ( iyarr[i+1] - iyarr[i] );

		    if ( tau >= 0.0 && tau <= 1.0 ) {

			xout[index] = tau * ( ixarr[i+1] - ixarr[i] ) +
				      ixarr[i];
			index++;

		    }
		}
	    }

/*
 *	    Sort the values of the X coordinate.
 *  Added (int(*)(const void*, const void*)) cast to satisfy qsort
 */
	    qsort ( xout, index, sizeof(float), 
		    (int(*)(const void*, const void*))_cmp_xout );

/*
 *	    Loop over all the scan lines, filling the pixels
 *	    in the pattern.
 */
	    for ( i = 0; i < index; i=i+2 ) {
		ny2 = j / 2;
		nx1 = xout[i  ] / 2;
		nx2 = xout[i+1] / 2;
		fillScan ( ny2, nx1, nx2, iret );
	    }

	}

/*
 *	Free the working arrays.
 */
	free ( ixarr );
	free ( iyarr );

}