Exemplo n.º 1
0
void OrientedBoxShape::ToConvex(ConvexPolygonShape* pPoly)const
{
	pPoly->SetPointC(4);
	(*pPoly)[0] = GetCorner(0);
	(*pPoly)[1] = GetCorner(1);
	(*pPoly)[2] = GetCorner(2);
	(*pPoly)[3] = GetCorner(3);
}
Exemplo n.º 2
0
bool CControl::HitTest( float x, float y )
{
    CVec2 leftTopConner;
    GetCorner( eCP_TopLeft, leftTopConner.x, leftTopConner.y);
    CVec2 rightBottom;
    GetCorner( eCP_BottomRight, rightBottom.x, rightBottom.y );
    bool bRet = x > leftTopConner.x && x < rightBottom.x 
        && y > leftTopConner.y && y < rightBottom.y;
    return bRet;
}
Exemplo n.º 3
0
Arquivo: box.cpp Projeto: garinh/cs
bool csBox3::ProjectBoxAndOutline (const csTransform& trans, float fov,
                                   float sx, float sy, csBox2& sbox, csPoly2D& poly,
                                   float& min_z, float& max_z) const
{
    const csVector3& origin = trans.GetOrigin ();
    int idx = CalculatePointSegment (origin);
    const Outline &ol = outlines[idx];
    int num_array = MIN (ol.num, 6);
    poly.SetVertexCount (num_array);

    min_z = 100000000.0;
    max_z = 0;
    sbox.StartBoundingBox ();
    int i;
    // We go to 8 so that we can calculate the correct min_z/max_z.
    // If we only go to num_array we will only calculate min_z/max_z
    // for the outine vertices.
    for (i = 0 ; i < 8 ; i++)
    {
        csVector3 v = trans * GetCorner (ol.vertices[i]);
        if (v.z > max_z) max_z = v.z;
        if (v.z < min_z) min_z = v.z;
        if (i < num_array)
        {
            if (v.z < .1)
                PerspectiveWrong (v, poly[i], fov, sx, sy);
            else
                Perspective (v, poly[i], fov, sx, sy);
            sbox.AddBoundingVertex (poly[i]);
        }
    }
    return max_z >= .1;
}
Exemplo n.º 4
0
Arquivo: box.cpp Projeto: garinh/cs
bool csBox3::ProjectOutline (const csVector3& origin,
                             int axis, float where, csPoly2D& poly) const
{
    int idx = CalculatePointSegment (origin);
    const Outline &ol = outlines[idx];
    int num_array = MIN (ol.num, 6);
    poly.SetVertexCount (num_array);

    int i;
    for (i = 0 ; i < num_array ; i++)
    {
        csVector3 isect;
        if (!csIntersect3::SegmentAxisPlane (origin, GetCorner (ol.vertices[i]),
                                             axis, where, isect))
            return false;
        switch (axis)
        {
        case CS_AXIS_X:
            poly[i].x = isect.y;
            poly[i].y = isect.z;
            break;
        case CS_AXIS_Y:
            poly[i].x = isect.x;
            poly[i].y = isect.z;
            break;
        case CS_AXIS_Z:
            poly[i].x = isect.x;
            poly[i].y = isect.y;
            break;
        }
    }
    return true;
}
Exemplo n.º 5
0
Arquivo: box.cpp Projeto: garinh/cs
bool csBox3::ProjectOutline (const csVector3& origin,
                             int axis, float where, csArray<csVector2>& poly) const
{
    int idx = CalculatePointSegment (origin);
    const Outline &ol = outlines[idx];
    int num_array = MIN (ol.num, 6);

    int i;
    for (i = 0 ; i < num_array ; i++)
    {
        csVector3 isect;
        if (!csIntersect3::SegmentAxisPlane (origin, GetCorner (ol.vertices[i]),
                                             axis, where, isect))
            return false;
        csVector2 v;
        switch (axis)
        {
        case CS_AXIS_X:
            v.x = isect.y;
            v.y = isect.z;
            break;
        case CS_AXIS_Y:
            v.x = isect.x;
            v.y = isect.z;
            break;
        case CS_AXIS_Z:
            v.x = isect.x;
            v.y = isect.y;
            break;
        }
        poly.Push (v);
    }
    return true;
}
Exemplo n.º 6
0
inline void sreBoundingVolumeBox::ConstructVerticesTemplate(T *P, int& n) const {
    P[0] = GetCorner(0.5f, 0.5f, 0.5f);
    P[1] = GetCorner(- 0.5f, 0.5f, 0.5f);
    P[2] = GetCorner(- 0.5f, - 0.5f, 0.5f);
    P[3] = GetCorner(0.5f, - 0.5f, 0.5f);
    if (PCA[2].SizeIsZero()) {
        n = 4;
        return;
    }
    P[4] = GetCorner(0.5f, 0.5f, - 0.5f);
    P[5] = GetCorner(- 0.5f, 0.5f, - 0.5f);
    P[6] = GetCorner(- 0.5f, - 0.5f, - 0.5f);
    P[7] = GetCorner(0.5f, - 0.5f, - 0.5f);
    n = 8;
}
Exemplo n.º 7
0
GfRange3f
GfRange3f::GetOctant(size_t i) const
{
    if (i > 7) {
        TF_CODING_ERROR("Invalid octant %zu > 7.", i);
        return GfRange3f();
    }

    GfVec3f a = GetCorner(i);
    GfVec3f b = .5 * (_min + _max);

    return GfRange3f(
        GfVec3f(GfMin(a[0], b[0]), GfMin(a[1], b[1]), GfMin(a[2], b[2])),
        GfVec3f(GfMax(a[0], b[0]), GfMax(a[1], b[1]), GfMax(a[2], b[2])));
}
Exemplo n.º 8
0
GfRange2d
GfRange2d::GetQuadrant(size_t i) const
{
    if (i > 3) {
        TF_CODING_ERROR("Invalid quadrant %zu > 3.", i);
        return GfRange2d();
    }

    GfVec2d a = GetCorner(i);
    GfVec2d b = .5 * (_min + _max);

    return GfRange2d(
        GfVec2d(GfMin(a[0], b[0]), GfMin(a[1], b[1])),
        GfVec2d(GfMax(a[0], b[0]), GfMax(a[1], b[1])));
}
Exemplo n.º 9
0
void OrientedBoxShape::GetAlignedHull(AlignedBoxShape* pHull)const
{
	AlignedBoxShape Result(m_Center, sf::Vector2f(0, 0));

	pHull->SetCornerPosition(m_Center);
	pHull->SetSize(sf::Vector2f(0.0f, 0.0f));

	sf::Vector2f Corner;

	for(int CornerIdx = 0; CornerIdx < 4; ++CornerIdx)
	{
		Corner = GetCorner(CornerIdx);
		pHull->Extend(Corner);
	}
}
Exemplo n.º 10
0
void CSprite::Draw(float x, float y)
{
	RECT src_rect;

	src_rect.left = (index % sprite_texture->num_cols) * (sprite_texture->frame_width);
	src_rect.top = (index / sprite_texture->num_cols) * (sprite_texture->frame_height);
	src_rect.right = src_rect.left + sprite_texture->frame_width;
	src_rect.bottom = src_rect.top + sprite_texture->frame_height;

	D3DXVECTOR3 pos = GetCorner((int)x, (int)y, sprite_texture->frame_width, sprite_texture->frame_height);
	
	kSpriteHandler->Draw(
		sprite_texture->picture,
		&src_rect,
		NULL,
		&pos,
		D3DCOLOR_XRGB(255, 255, 255));
}
Exemplo n.º 11
0
void CSprite::DrawTransform(float x, float y, D3DXVECTOR2 scale, float degRotate, float depth)
{
	RECT src_rect;

	src_rect.left = (index % sprite_texture->num_cols) * (sprite_texture->frame_width);
	src_rect.top = (index / sprite_texture->num_cols) * (sprite_texture->frame_height);
	src_rect.right = src_rect.left + sprite_texture->frame_width;
	src_rect.bottom = src_rect.top + sprite_texture->frame_height;

	D3DXMATRIX old_matrix;
	kSpriteHandler->GetTransform(&old_matrix);

	D3DXMATRIX new_natrix;
	D3DXVECTOR2 center = D3DXVECTOR2(x, y);

	D3DXMatrixTransformation2D(
		&new_natrix,
		&center,
		0.0f,
		&scale,
		&center,
		D3DXToRadian(degRotate),
		NULL);

	D3DXMATRIX final_matrix = new_natrix * old_matrix;
	kSpriteHandler->SetTransform(&final_matrix);
	D3DXVECTOR3 pos = GetCorner(x, y, sprite_texture->frame_width, sprite_texture->frame_height);

	kSpriteHandler->Draw(
		sprite_texture->picture,
		&src_rect,
		NULL,
		&D3DXVECTOR3(pos.x, pos.y, depth),
		0xFFFFFFFF);

	kSpriteHandler->SetTransform(&old_matrix);
}
Exemplo n.º 12
0
Arquivo: box.cpp Projeto: garinh/cs
bool csBox3::ProjectBox (const csTransform& trans, float fov,
                         float sx, float sy, csBox2& sbox, float& min_z, float& max_z) const
{
    const csVector3& origin = trans.GetOrigin ();
    int idx = CalculatePointSegment (origin);
    const Outline &ol = outlines[idx];
    int num_array = MIN (ol.num, 6);

    min_z = 100000000.0;
    max_z = 0;
    csBox3 cbox (trans * GetCorner (ol.vertices[0]));
    int i;
    // We go to 8 so that we can calculate the correct min_z/max_z.
    // If we only go to num_array we will only calculate min_z/max_z
    // for the outine vertices.
    for (i = 1; i < 8; i++)
    {
        csVector3 v = trans * GetCorner (ol.vertices[i]);
        if (i < num_array)
        {
            cbox.AddBoundingVertexSmart (v);
            min_z = cbox.MinZ ();
            max_z = cbox.MaxZ ();
        }
        else
        {
            if (v.z < min_z) min_z = v.z;
            if (v.z > max_z) max_z = v.z;
        }
    }

    if (max_z < 0.01) return false;

// @@@ In theory we can optimize here again by calling CalculatePointSegment
// again for the new box and the 0,0,0 point. By doing that we could
// avoid doing four perspective projections.

    // If z < .1 we do conservative clipping. Not correct but it will generate
    // a box that is bigger then the real one which is ok for testing culling.
    csVector2 oneCorner;
    if (cbox.Max ().z < .1)
        PerspectiveWrong (cbox.Max (), oneCorner, fov, sx, sy);
    else
        Perspective (cbox.Max (), oneCorner, fov, sx, sy);
    sbox.StartBoundingBox (oneCorner);

    csVector3 v (cbox.MinX (), cbox.MinY (), cbox.MaxZ ());
    if (v.z < .1)
        PerspectiveWrong (v, oneCorner, fov, sx, sy);
    else
        Perspective (v, oneCorner, fov, sx, sy);
    sbox.AddBoundingVertexSmart (oneCorner);

    if (cbox.Min ().z < .1)
        PerspectiveWrong (cbox.Min (), oneCorner, fov, sx, sy);
    else
        Perspective (cbox.Min (), oneCorner, fov, sx, sy);
    sbox.AddBoundingVertexSmart (oneCorner);

    v.Set (cbox.MaxX (), cbox.MaxY (), cbox.MinZ ());
    if (v.z < .1)
        PerspectiveWrong (v, oneCorner, fov, sx, sy);
    else
        Perspective (v, oneCorner, fov, sx, sy);
    sbox.AddBoundingVertexSmart (oneCorner);

    return true;
}
Exemplo n.º 13
0
int GetGrpInfo1 (StisInfo1 *sts, Hdr *hdr) {

/* arguments:
StisInfo1 *sts   io: calibration switches and info
Hdr *hdr         i: header of current extension
*/

	int status;

	char *buf;			/* scratch for keyword value */
	int sdqflags;			/* serious data quality flags */
	int rsize;			/* 1 for CCD, 2 for MAMA */
	int corner[2];		/* subarray start points, detector coords */
	double cd11, cd12, cd21, cd22;	/* CD matrix */
	int doppon;			/* Doppler correction done on-board? */
	int use_def = 1;		/* use default if missing keyword */
	int no_default = 0;		/* missing keyword is fatal error */
	int GetDetTemp (Hdr *, int, double *);
	int GetEPCTab (StisInfo1 *, float);

	/* Get generic parameters. */

	/* Check whether we're processing a science file or wavecal,
	   based on ASN_MTYP.  Note that we won't reset the wavecal flag
	   to false (it may have been set in GetKeyInfo1) if ASN_MTYP
	   doesn't indicate that the observation is a wavecal, because
	   this file might not be part of an association.
	*/
	if ((buf = calloc (STIS_FNAME+1, sizeof(char))) == NULL)
	    return (OUT_OF_MEMORY);
	if ((status = Get_KeyS (hdr, "ASN_MTYP",
                                use_def, "unknown", buf, STIS_FNAME)))
	    return (status);
	/* Possible values for wavecals are "AUTO-WAVECAL" and "GO-WAVECAL" */
	if (strstr (buf, "WAVECAL") != NULL)
	    sts->wavecal = 1;
	free (buf);

	if ((status = Get_KeyD (hdr, "EXPTIME", no_default, 0., &sts->exptime)))
	    return (status);
	if (sts->exptime < 0.) {
	    printf ("ERROR    Exposure time is invalid:  %14.6g.\n",
		sts->exptime);
	    return (GENERIC_ERROR_CODE);
	}
	if ((status = Get_KeyD (hdr, "EXPSTART", no_default, 0., &sts->expstart)))
	    return (status);
	if ((status = Get_KeyD (hdr, "EXPEND", no_default, 0., &sts->expend)))
	    return (status);

	/* Find out which data quality bits are considered serious;
	   default value means all bits are serious.
	*/
	if ((status = Get_KeyI (hdr, "SDQFLAGS", use_def, 32767, &sdqflags)))
	    return (status);
	sts->sdqflags = (short) sdqflags;

	/* Get the pixel size (ignore corner location) from ltm & ltv. */
	rsize = (sts->detector == CCD_DETECTOR) ? 1 : 2;
	if ((status = GetCorner (hdr, rsize, sts->bin, corner)))
	    return (status);

	/* For spectroscopic data, we want the dispersion axis and the
	   sign of the dispersion.  We'll get the latter from one element
	   of the CD matrix.
	   We also want the pixel size, which we compute from the CD matrix.
	*/
	sts->dispaxis = 1;		/* initial values */
	sts->dispsign = 1;

	if (strcmp (sts->obstype, "IMAGING") == 0) {

	    if ((status = Get_KeyD (hdr, "CD1_1", use_def, 1., &cd11)))
		return (status);
	    if ((status = Get_KeyD (hdr, "CD1_2", use_def, 0., &cd12)))
		return (status);
	    if ((status = Get_KeyD (hdr, "CD2_1", use_def, 0., &cd21)))
		return (status);
	    if ((status = Get_KeyD (hdr, "CD2_2", use_def, 1., &cd22)))
		return (status);
	    sts->cdelt[0] = sqrt (cd11 * cd11 + cd21 * cd21);
	    sts->cdelt[1] = sqrt (cd12 * cd12 + cd22 * cd22);

	} else if (strcmp (sts->obstype, "SPECTROSCOPIC") == 0) {

	    if ((status = Get_KeyI (hdr, "DISPAXIS", use_def, 1, &sts->dispaxis)))
		return (status);
	    if ((status = Get_KeyD (hdr, "CD1_1", use_def, 1., &cd11)))
		return (status);
	    if ((status = Get_KeyD (hdr, "CD2_2", use_def, 1., &cd22)))
		return (status);
	    if (sts->dispaxis == 1) {
		if (cd11 >= 0.)
		    sts->dispsign = 1;
		else
		    sts->dispsign = -1;
		sts->cdelt[0] = cd22;		/* assume square pixels */
		sts->cdelt[1] = cd22;
	    } else if (sts->dispaxis == 2) {
		if (cd22 >= 0.)
		    sts->dispsign = 1;
		else
		    sts->dispsign = -1;
		sts->cdelt[0] = cd11;
		sts->cdelt[1] = cd11;
	    }
	}

	sts->detector_temp = -1.;	/* initial value (not defined) */

	/* Get MAMA-specific parameters. */

	if (sts->detector == NUV_MAMA_DETECTOR ||
	    sts->detector == FUV_MAMA_DETECTOR) {

	    if ((status = Get_KeyD (hdr, "GLOBRATE",
                                    no_default, 0., &sts->globrate)))
		return (status);

	    /* Get info if we need to do Doppler convolution of ref files. */

	    if (sts->doppcorr == PERFORM) {

		/* Was Doppler correction done on-board? */
		if ((status = Get_KeyI (hdr, "DOPPON", use_def, 0, &doppon)))
		    return (status);

		/* doppon could be False in timetag mode. */
		if (!doppon) {
		    if (strcmp (sts->obsmode, "TIME-TAG") == 0) {
			if ((status = Get_KeyD (hdr, "DOPPMAG", use_def, -1.,
                                                &sts->doppmag)))
			    return (status);
			doppon = (sts->doppmag > 0.);
		    }
		}

		if (doppon) {
		    if ((status = Get_KeyD (hdr, "DOPPZERO", no_default, 0.,
                                            &sts->doppzero)))
			return (status);
		    if ((status = Get_KeyD (hdr, "DOPPMAG", no_default, 0.,
                                            &sts->doppmag)))
			return (status);
		    if ((status = Get_KeyD (hdr, "ORBITPER", no_default, 0.,
                                            &sts->orbitper)))
			return (status);
		} else {
		    /* Silently reset the switch. */
		    sts->doppcorr = OMIT;
		}
	    }
	}

	/* Get CCD-specific parameters. */

        if (sts->detector == CCD_DETECTOR) {
	    float occdhtav = -1.;

	    /*  if OCCDHTAV is present and > 0, then data is from Side B,
	     *  so look for EPC file.  Otherwise, data is from Side A and
	     *  EPC file and temperature can be ignored.
	     */

	    if (((status = Get_KeyF(hdr, "OCCDHTAV", use_def, -1.,
				    &occdhtav)) == 0) && (occdhtav >= 0.)) {
		char expname[81], epcname[81];
		expname[0] = epcname[0] = '\0';
		if ((status = Get_KeyS(hdr, "EXPNAME", no_default, "",
                                       expname, 80)))
		    return (status);
		if (sts->crcorr != COMPLETE) {
		    strncpy(epcname, expname, 8); epcname[8] = '\0';
		    sprintf(sts->epctab.name, "%sj_epc.fits", epcname);
		    PrFileName("epcfile", sts->epctab.name);
		    status = GetEPCTab(sts, 0.40);
		    if (status && status != OPEN_FAILED)
			return (status);
		}
		if ((status = UpdateCCDTemperature(sts, hdr)))
		    return (status);
	    }
        }

	/* Get the detector temperature (or housing temperature, if CCD).
	   Note that for side-2 CCD data this function must be called after
	   calling UpdateCCDTemperature.
	*/
	if ((status = GetDetTemp (hdr, sts->detector, &sts->detector_temp))) {
	    return (status);
	}

	/* If images have been combined (e.g. by cosmic-ray rejection),
	   then determine the number of images that were combined together;
	   we need this for bias image subtraction.
	   (This isn't really a CCD-specific keyword, but it does only affect
	   CCD data in the context of calstis1.)
	*/
	if ((status = Get_KeyI (hdr, "NCOMBINE", use_def, 1, &sts->ncombine)))
	    return (status);

	if (sts->ncombine < 1) {
	    printf ("Warning  NCOMBINE = %d, reset to one.\n", sts->ncombine);
	    sts->ncombine = 1;
	}

	return (0);
}
Exemplo n.º 14
0
int FindBin (StisInfo1 *sts, SingleGroup *x, SingleGroup *y,
	int *same_size, int *high_res,
	int *rx, int *ry, int *x0, int *y0) {

/* arguments:
StisInfo1 *sts    i: calibration switches and info
SingleGroup *x    i: science image
SingleGroup *y    i: reference image
int *same_size    o: true if zero offset and same size and binning
int *high_res     o: true if bin size is one in dispersion direction
int *rx, *ry      o: ratio of bin sizes
int *x0, *y0      o: location of start of subimage in ref image
*/

	int status;

	int sci_bin[2];			/* bin size of science image */
	int sci_corner[2];		/* science image corner location */
	int ref_bin[2];			/* bin size of reference image */
	int ref_corner[2];		/* ref image corner location */
	int rsize;			/* 1 for CCD, 2 for MAMA */
	int cshift[2];			/* shift of sci relative to ref */
	int ratiox, ratioy;		/* local variables for rx, ry */
	int xzero, yzero;		/* local variables for x0, y0 */

	/* Get bin sizes of science and reference images from headers. */
	rsize = (sts->detector == CCD_DETECTOR) ? 1 : 2;
	if ((status = GetCorner (&x->sci.hdr, rsize, sci_bin, sci_corner)))
	    return (status);
	if ((status = GetCorner (&y->sci.hdr, rsize, ref_bin, ref_corner)))
	    return (status);

	/* High-res is really only relevant for the MAMA detectors. */
	*high_res = (sts->dispaxis == 1 && ref_bin[0] == 1) ||
                    (sts->dispaxis == 2 && ref_bin[1] == 1);

	if (sci_corner[0] == ref_corner[0] &&
	    sci_corner[1] == ref_corner[1] &&
	    sci_bin[0] == ref_bin[0] &&
	    sci_bin[1] == ref_bin[1] &&
	    x->sci.data.nx == y->sci.data.nx &&
	    x->sci.data.ny == y->sci.data.ny) {

	    /* We can use the reference image directly, without binning
		and without extracting a subset.
	    */
	    *same_size = 1;
	    *rx = 1;
	    *ry = 1;
	    *x0 = 0;
	    *y0 = 0;

	} else if (ref_bin[0] > sci_bin[0] ||
		   ref_bin[1] > sci_bin[1]) {

	    /* Reference image is binned more than the science image. */
	    *same_size = 0;

	    *rx = ref_bin[0] / sci_bin[0];
	    *ry = ref_bin[1] / sci_bin[1];
	    *x0 = (sci_corner[0] - ref_corner[0]) / ref_bin[0];
	    *y0 = (sci_corner[1] - ref_corner[1]) / ref_bin[1];

	    return (REF_TOO_SMALL);

	} else {

	    /* We must bin, extract subset, or both. */
	    *same_size = 0;

	    /* ratio of bin sizes */
	    ratiox = sci_bin[0] / ref_bin[0];
	    ratioy = sci_bin[1] / ref_bin[1];
	    if (ratiox * ref_bin[0] != sci_bin[0] ||
		ratioy * ref_bin[1] != sci_bin[1])
		return (SIZE_MISMATCH);

	    /* cshift is the offset in units of unbinned (or low-res)
		pixels.  Divide by ref_bin to convert to units of pixels
		in the reference image.
	    */
	    cshift[0] = sci_corner[0] - ref_corner[0];
	    cshift[1] = sci_corner[1] - ref_corner[1];
	    xzero = cshift[0] / ref_bin[0];
	    yzero = cshift[1] / ref_bin[1];
	    if (xzero * ref_bin[0] != cshift[0] ||
		yzero * ref_bin[1] != cshift[1]) {
		printf (
		"Warning  Subimage offset not divisible by bin size.\n");
	    }
	    *rx = ratiox;
	    *ry = ratioy;
	    *x0 = xzero;
	    *y0 = yzero;
	}

	return (0);
}
Exemplo n.º 15
0
static int nlincorr (WF3Info *wf3, SingleNicmosGroup *input, NlinData *nlin,
		     SingleNicmosGroup *zsig) {

/* Arguments:
**	wf3	 i: WFC3 info structure
**	input	io: input image to be corrected
**	nlin	 i: nonlinearity reference data
**	zsig	 i: MULTIACCUM zero-read signal image
*/

	/* Local variables */
	int i, j, li, lj, k;	/* pixel indexes */
	int ibeg, iend;		/* loop limits */
	int jbeg, jend;		/* loop limits */
	int li_beg, lj_beg;	/* loop limits */
	int rsize = 1;		/* for use by GetCorner */
	int sci_bin[2];		/* bin size of science image */
	int sci_corner[2];	/* science image corner location */
	int ref_bin[2];		/* bin size of reference image */
	int ref_corner[2];	/* ref image corner location */
	int nsatpix;		/* number of saturated pixels */
	float sval, eval;	/* science and err image values */
	float corr;		/* correction value */
	float n1;		/* node value */

	/* Function definitions */
	int GetCorner (Hdr *, int, int *, int*);

	/* Compute subarray offsets, if any, between ref data
	** science data. */
	if ( (status = GetCorner(&input->sci.hdr, rsize, sci_bin, sci_corner)))
	    return (status);
	if ( (status = GetCorner(&nlin->coeff[0].hdr, rsize, ref_bin, ref_corner)))
	    return (status);

	/* Initialize saturated pixel counter */
	nsatpix = 0;

	/* Loop through science image */
	ibeg = wf3->trimx[0]; iend = input->sci.data.nx - wf3->trimx[1];
	jbeg = wf3->trimy[0]; jend = input->sci.data.ny - wf3->trimy[1];
	li_beg = (sci_corner[0] - ref_corner[0]) + ibeg;
	lj_beg = (sci_corner[1] - ref_corner[1]) + jbeg;

	for (j = jbeg, lj = lj_beg; j < jend; j++, lj++) {
	for (i = ibeg, li = li_beg; i < iend; i++, li++) {

	     /* Get the science and error image values */
	     sval = Pix(input->sci.data,i,j);
	     eval = Pix(input->err.data,i,j);

	     /* Temporarily add the MULTIACCUM zero-read signal back into the
	     ** the pixel value, but only if ZSIG step is turned on and only 
	     ** for groups other than the zeroth-read itself */
	     if (wf3->zsigcorr == PERFORM && wf3->group != wf3->ngroups) {
		 sval += Pix(zsig->sci.data,i,j);
		 if (DQPix(zsig->dq.data,i,j) & ZEROSIG) {
		     DQSetPix(input->dq.data,i,j,
			DQPix(input->dq.data,i,j) | ZEROSIG);
		 }
	     }

	     /* Get the node values for this pixel */
	     n1 = Pix(nlin->nodes[0].data,li,lj);

	     /* Propagate the DQ value from the NLIN ref data */
	     DQSetPix(input->dq.data,i,j,
		DQPix(input->dq.data,i,j) | DQPix(nlin->dqual[0].data,li,lj));

	     /* If it's already flagged as saturated,
	     ** skip the correction */
	     if (DQPix(input->dq.data,i,j) & SATPIXEL) {
		 nsatpix++;

	     /* Apply the correction for the non-linear region */
	     /*} else if (sval >= n1 && sval <= n2) {*/
	     } else if (sval <= n1) {

	       /* Compute the new science image pixel value */
	       corr = 1.0;
	       for (k=0; k < nlin->ncoeff; k++)
		    corr += Pix(nlin->coeff[k].data,li,lj) * (pow(sval,k));
	       Pix(input->sci.data,i,j) = sval * corr;

	       /* Remove the MULTIACCUM zero-read signal that was added in
	       ** above, but only if ZSIG step is turned on and only for 
	       ** groups other than the zeroth-read itself */
	       if (wf3->zsigcorr == PERFORM && wf3->group != wf3->ngroups)
		   Pix(input->sci.data,i,j) -= Pix(zsig->sci.data,i,j);

	     /* Above the saturation node, just mark the pixel as saturated */
	     } else if (sval > n1) {
	       nsatpix++;
	       DQSetPix(input->dq.data,i,j,
		  DQPix(input->dq.data,i,j) | SATPIXEL);
	     }
	}}

	/* Report the number of saturated pixels */
	sprintf (MsgText, "NLINCORR detected %d saturated pixels in imset %d",
		 nsatpix, wf3->group);
	trlmessage (MsgText);

	/* Successful return */
	return (status = 0);
}