Back to index

radiance  4R0+20100331
Defines | Functions
plocate.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define EPSILON   FTINY /* acceptable location error */
#define XPOS   03 /* x position mask */
#define YPOS   014 /* y position mask */
#define ZPOS   060 /* z position mask */
#define position(i)   (3<<((i)<<1)) /* macro version */
#define BELOW   025 /* below bits */
#define ABOVE   052 /* above bits */

Functions

int clip (RREAL *ep1, RREAL *ep2, FVECT min, FVECT max)
int plocate (FVECT p, FVECT min, FVECT max)

Define Documentation

#define ABOVE   052 /* above bits */

Definition at line 22 of file plocate.h.

#define BELOW   025 /* below bits */

Definition at line 21 of file plocate.h.

#define EPSILON   FTINY /* acceptable location error */

Definition at line 13 of file plocate.h.

#define position (   i)    (3<<((i)<<1)) /* macro version */

Definition at line 19 of file plocate.h.

#define XPOS   03 /* x position mask */

Definition at line 15 of file plocate.h.

#define YPOS   014 /* y position mask */

Definition at line 16 of file plocate.h.

#define ZPOS   060 /* z position mask */

Definition at line 17 of file plocate.h.


Function Documentation

int clip ( RREAL ep1,
RREAL ep2,
FVECT  min,
FVECT  max 
)

Definition at line 18 of file clip.c.

{
       int  itlim = MAXITER;
       int  loc1, loc2;
       int  accept;
       RREAL  *dp;
       double  d;
       register int  i, j;

       /*
        *     The Cohen-Sutherland algorithm is used to determine
        *  what part (if any) of the given line segment is contained
        *  in the box specified by the min and max vectors.
        *     The routine returns non-zero if any segment is left.
        */
       
       loc1 = plocate(ep1, min, max);
       loc2 = plocate(ep2, min, max);

                     /* check for trivial accept and reject */
                     /* trivial accept is both points inside */
                     /* trivial reject is both points to one side */
       
       while (!((accept = !(loc1 | loc2)) || (loc1 & loc2))) {
       
              if (itlim-- <= 0)    /* past theoretical limit? */
                     return(0);    /* quit fooling around */

              if (!loc1) {         /* make sure first point is outside */
                     dp = ep1; ep1 = ep2; ep2 = dp;
                     i = loc1; loc1 = loc2; loc2 = i;
              }
              
              for (i = 0; i < 3; i++) {          /* chop segment */
                     
                     if (loc1 & position(i) & BELOW) {
                            d = (min[i] - ep1[i])/(ep2[i] - ep1[i]);
                            ep1[i] = min[i];
                     } else if (loc1 & position(i) & ABOVE) {
                            d = (max[i] - ep1[i])/(ep2[i] - ep1[i]);
                            ep1[i] = max[i];
                     } else
                            continue;
                     
                     for (j = 0; j < 3; j++)
                            if (j != i)
                                   ep1[j] += (ep2[j] - ep1[j])*d;
                     break;
              }
              loc1 = plocate(ep1, min, max);
       }
       return(accept);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int plocate ( FVECT  p,
FVECT  min,
FVECT  max 
)

Definition at line 16 of file plocate.c.

{
       register int  loc = 0;

       if (p[0] < min[0] - EPSILON)
              loc |= XPOS & BELOW;
       else if (p[0] > max[0] + EPSILON)
              loc |= XPOS & ABOVE;
       if (p[1] < min[1] - EPSILON)
              loc |= YPOS & BELOW;
       else if (p[1] > max[1] + EPSILON)
              loc |= YPOS & ABOVE;
       if (p[2] < min[2] - EPSILON)
              loc |= ZPOS & BELOW;
       else if (p[2] > max[2] + EPSILON)
              loc |= ZPOS & ABOVE;
       
       return(loc);
}

Here is the caller graph for this function: