Back to index

radiance  4R0+20100331
Defines | Functions | Variables
dircode.c File Reference
#include "rtmath.h"

Go to the source code of this file.

Defines

#define DCSCALE   11585.2 /* (1<<13)*sqrt(2) */
#define FXNEG   01
#define FYNEG   02
#define FZNEG   04
#define F1X   010
#define F2Z   020
#define F1SFT   5
#define F2SFT   18
#define FMASK   0x1fff

Functions

int32 encodedir (FVECT dv)
void decodedir (FVECT dv, int32 dc)
double dir2diff (int32 dc1, int32 dc2)
double fdir2diff (int32 dc1, FVECT v2)

Variables

static const char RCSid [] = "$Id: dircode.c,v 2.7 2003/06/27 06:53:21 greg Exp $"

Define Documentation

#define DCSCALE   11585.2 /* (1<<13)*sqrt(2) */

Definition at line 12 of file dircode.c.

#define F1SFT   5

Definition at line 18 of file dircode.c.

#define F1X   010

Definition at line 16 of file dircode.c.

#define F2SFT   18

Definition at line 19 of file dircode.c.

#define F2Z   020

Definition at line 17 of file dircode.c.

#define FMASK   0x1fff

Definition at line 20 of file dircode.c.

#define FXNEG   01

Definition at line 13 of file dircode.c.

#define FYNEG   02

Definition at line 14 of file dircode.c.

#define FZNEG   04

Definition at line 15 of file dircode.c.


Function Documentation

void decodedir ( FVECT  dv,
int32  dc 
)

Definition at line 56 of file dircode.c.

{
       double d1, d2, der;

       if (!dc) {           /* special code for zero normal */
              dv[0] = dv[1] = dv[2] = 0.;
              return;
       }
       d1 = ((dc>>F1SFT & FMASK)+.5)*(1./DCSCALE);
       d2 = ((dc>>F2SFT & FMASK)+.5)*(1./DCSCALE);
       der = sqrt(1. - d1*d1 - d2*d2);
       if (dc & F1X) {
              dv[0] = d1;
              if (dc & F2Z) { dv[1] = der; dv[2] = d2; }
              else { dv[1] = d2; dv[2] = der; }
       } else {
              dv[1] = d1;
              if (dc & F2Z) { dv[0] = der; dv[2] = d2; }
              else { dv[0] = d2; dv[2] = der; }
       }
       if (dc & FXNEG) dv[0] = -dv[0];
       if (dc & FYNEG) dv[1] = -dv[1];
       if (dc & FZNEG) dv[2] = -dv[2];
}

Here is the caller graph for this function:

double dir2diff ( int32  dc1,
int32  dc2 
)

Definition at line 85 of file dircode.c.

{
       FVECT  v1, v2;

       decodedir(v1, dc1);
       decodedir(v2, dc2);

       return(2. - 2.*DOT(v1,v2));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int32 encodedir ( FVECT  dv)

Definition at line 23 of file dircode.c.

{
       register int32       dc = 0;
       int    cd[3], cm;
       register int  i;

       for (i = 0; i < 3; i++)
              if (dv[i] < 0.) {
                     cd[i] = (int)(dv[i] * -DCSCALE);
                     dc |= FXNEG<<i;
              } else
                     cd[i] = (int)(dv[i] * DCSCALE);
       if (!(cd[0] | cd[1] | cd[2]))
              return(0);           /* zero normal */
       if (cd[0] <= cd[1]) {
              dc |= F1X | cd[0] << F1SFT;
              cm = cd[1];
       } else {
              dc |= cd[1] << F1SFT;
              cm = cd[0];
       }
       if (cd[2] <= cm)
              dc |= F2Z | cd[2] << F2SFT;
       else
              dc |= cm << F2SFT;
       if (!dc)      /* don't generate 0 code normally */
              dc = F1X;
       return(dc);
}

Here is the caller graph for this function:

double fdir2diff ( int32  dc1,
FVECT  v2 
)

Definition at line 98 of file dircode.c.

{
       FVECT  v1;

       decodedir(v1, dc1);

       return(2. - 2.*DOT(v1,v2));
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char RCSid[] = "$Id: dircode.c,v 2.7 2003/06/27 06:53:21 greg Exp $" [static]

Definition at line 2 of file dircode.c.