Back to index

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

Go to the source code of this file.

Classes

struct  MSGHEAD

Defines

#define DR_NOOP   0 /* to release from vain DR_ATTEN */
#define DR_BUNDLE   1 /* lone bundle request */
#define DR_ATTEN   2 /* request for attention */
#define DR_SHUTDOWN   3 /* shutdown request */
#define DR_NEWSET   4 /* new bundle set */
#define DR_ADDSET   5 /* add to current set */
#define DR_ADJSET   6 /* adjust set quantities */
#define DR_DELSET   7 /* delete from current set */
#define DR_KILL   8 /* kill rtrace process(es) */
#define DR_RESTART   9 /* restart rtrace */
#define DR_CLOBBER   10 /* clobber holodeck */
#define DR_VIEWPOINT   11 /* set desired eye position */
#define DS_BUNDLE   32 /* computed bundle */
#define DS_ACKNOW   33 /* acknowledge request for attention */
#define DS_SHUTDOWN   34 /* end process and close connection */
#define DS_ADDHOLO   35 /* register new holodeck */
#define DS_STARTIMM   36 /* begin immediate bundle set */
#define DS_ENDIMM   37 /* end immediate bundle set */
#define DS_OUTSECT   38 /* render from outside sections */
#define DS_EYESEP   39 /* eye separation distance */
#define BIGREQSIZ   512 /* big request size (bytes) */

Functions

void serv_request (int type, int nbytes, char *p)
int serv_result (void)
int beam_sync (int all)
void beam_init (int fresh)
void gridlines (void(*f)(FVECT wp[2]))
int new_ctab (int ncolors)
int get_pixel (BYTE rgb[3], void(*set_pixel)(int h, int r, int g, int b))

Class Documentation

struct MSGHEAD

Definition at line 52 of file rhdisp.h.

Class Members
int32 nbytes
int16 type

Define Documentation

#define BIGREQSIZ   512 /* big request size (bytes) */

Definition at line 49 of file rhdisp.h.

#define DR_ADDSET   5 /* add to current set */

Definition at line 20 of file rhdisp.h.

#define DR_ADJSET   6 /* adjust set quantities */

Definition at line 21 of file rhdisp.h.

#define DR_ATTEN   2 /* request for attention */

Definition at line 17 of file rhdisp.h.

#define DR_BUNDLE   1 /* lone bundle request */

Definition at line 16 of file rhdisp.h.

#define DR_CLOBBER   10 /* clobber holodeck */

Definition at line 25 of file rhdisp.h.

#define DR_DELSET   7 /* delete from current set */

Definition at line 22 of file rhdisp.h.

#define DR_KILL   8 /* kill rtrace process(es) */

Definition at line 23 of file rhdisp.h.

#define DR_NEWSET   4 /* new bundle set */

Definition at line 19 of file rhdisp.h.

#define DR_NOOP   0 /* to release from vain DR_ATTEN */

Definition at line 15 of file rhdisp.h.

#define DR_RESTART   9 /* restart rtrace */

Definition at line 24 of file rhdisp.h.

#define DR_SHUTDOWN   3 /* shutdown request */

Definition at line 18 of file rhdisp.h.

#define DR_VIEWPOINT   11 /* set desired eye position */

Definition at line 26 of file rhdisp.h.

#define DS_ACKNOW   33 /* acknowledge request for attention */

Definition at line 30 of file rhdisp.h.

#define DS_ADDHOLO   35 /* register new holodeck */

Definition at line 32 of file rhdisp.h.

#define DS_BUNDLE   32 /* computed bundle */

Definition at line 29 of file rhdisp.h.

#define DS_ENDIMM   37 /* end immediate bundle set */

Definition at line 34 of file rhdisp.h.

#define DS_EYESEP   39 /* eye separation distance */

Definition at line 36 of file rhdisp.h.

#define DS_OUTSECT   38 /* render from outside sections */

Definition at line 35 of file rhdisp.h.

#define DS_SHUTDOWN   34 /* end process and close connection */

Definition at line 31 of file rhdisp.h.

#define DS_STARTIMM   36 /* begin immediate bundle set */

Definition at line 33 of file rhdisp.h.


Function Documentation

void beam_init ( int  fresh)

Definition at line 153 of file rhdisp2.c.

{
       register int  i;

       if (fresh)                  /* discard old beams? */
              ncbeams = xcbeams = 0;
       else                        /* else clear sample requests */
              for (i = ncbeams+xcbeams; i--; )
                     cbeam[i].nr = 0;
       cureye.rng = 0.;
}

Here is the caller graph for this function:

int beam_sync ( int  all)

Definition at line 220 of file rhdisp2.c.

{
                                   /* set new eye position */
       serv_request(DR_VIEWPOINT, sizeof(VIEWPOINT), (char *)&cureye);
                                   /* sort list (put orphans at end) */
       cbeamsort(all < 0);
                                   /* send beam request */
       if (all) {
              if (ncbeams > 0)
                     serv_request(DR_NEWSET,
                                   ncbeams*sizeof(PACKHEAD), (char *)cbeam);
       } else {
              if (ncbeams+xcbeams > 0)
                     serv_request(DR_ADJSET,
                            (ncbeams+xcbeams)*sizeof(PACKHEAD), (char *)cbeam);
       }
       xcbeams = 0;                /* truncate our list */
       return(ncbeams);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int get_pixel ( BYTE  rgb[3],
void(*)(int h, int r, int g, int b)  set_pixel 
)

Definition at line 92 of file rhd_ctab.c.

{
       int    r, g, b;
       int    cv[3];
       register CNODE       *tp;
       register int  h;
                                          /* get desired color */
       r = rgb[RED];
       g = rgb[GRN];
       b = rgb[BLU];
                                          /* reduce resolution */
       cv[RED] = (r*NRED)>>8;
       cv[GRN] = (g*NGRN)>>8;
       cv[BLU] = (b*NBLU)>>8;
                                          /* add to histogram */
       histo[cv[RED]][cv[GRN]][cv[BLU]]++;
                                          /* find pixel in tree */
       for (tp = ctree, h = 0; is_branch(*tp); h++)
              if (cv[prim(*tp)] < part(*tp))
                     tp += 1<<h;          /* left branch */
              else
                     tp += 1<<(h+1);             /* right branch */
       h = pval(*tp);
                                          /* add to color table */
       clrtab[h].sum[RED] += r;
       clrtab[h].sum[GRN] += g;
       clrtab[h].sum[BLU] += b;
       clrtab[h].n++;
                                   /* recompute average */
       r = clrtab[h].sum[RED] / clrtab[h].n;
       g = clrtab[h].sum[GRN] / clrtab[h].n;
       b = clrtab[h].sum[BLU] / clrtab[h].n;
                                   /* check for movement */
       if (clrtab[h].n == 1 ||
                     (r-clrtab[h].ent[RED])*(r-clrtab[h].ent[RED]) +
                     (g-clrtab[h].ent[GRN])*(g-clrtab[h].ent[GRN]) +
                     (b-clrtab[h].ent[BLU])*(b-clrtab[h].ent[BLU]) > MAXDST2) {
              clrtab[h].ent[RED] = r;
              clrtab[h].ent[GRN] = g; /* reassign pixel */
              clrtab[h].ent[BLU] = b;
#ifdef DEBUG
              {
                     extern char   errmsg[];
                     sprintf(errmsg, "pixel %d = (%d,%d,%d) (%d refs)\n",
                                   h, r, g, b, clrtab[h].n);
                     eputs(errmsg);
              }
#endif
              (*set_pixel)(h, r, g, b);
       }
       return(h);                         /* return pixel value */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gridlines ( void(*)(FVECT wp[2])  f)

Definition at line 244 of file rhdisp2.c.

{
       register int  hd, w, i;
       int    g0, g1;
       FVECT  wp[2], mov;
       double d;
                                   /* do each wall on each section */
       for (hd = 0; hdlist[hd] != NULL; hd++)
              for (w = 0; w < 6; w++) {
                     g0 = hdwg0[w];
                     g1 = hdwg1[w];
                     d = 1.0/hdlist[hd]->grid[g0];
                     mov[0] = d * hdlist[hd]->xv[g0][0];
                     mov[1] = d * hdlist[hd]->xv[g0][1];
                     mov[2] = d * hdlist[hd]->xv[g0][2];
                     if (w & 1) {
                            VSUM(wp[0], hdlist[hd]->orig,
                                          hdlist[hd]->xv[w>>1], 1.);
                            VSUM(wp[0], wp[0], mov, 1.);
                     } else
                            VCOPY(wp[0], hdlist[hd]->orig);
                     VSUM(wp[1], wp[0], hdlist[hd]->xv[g1], 1.);
                     for (i = hdlist[hd]->grid[g0]; ; ) {      /* g0 lines */
                            (*f)(wp);
                            if (!--i) break;
                            wp[0][0] += mov[0]; wp[0][1] += mov[1];
                            wp[0][2] += mov[2]; wp[1][0] += mov[0];
                            wp[1][1] += mov[1]; wp[1][2] += mov[2];
                     }
                     d = 1.0/hdlist[hd]->grid[g1];
                     mov[0] = d * hdlist[hd]->xv[g1][0];
                     mov[1] = d * hdlist[hd]->xv[g1][1];
                     mov[2] = d * hdlist[hd]->xv[g1][2];
                     if (w & 1)
                            VSUM(wp[0], hdlist[hd]->orig,
                                          hdlist[hd]->xv[w>>1], 1.);
                     else
                            VSUM(wp[0], hdlist[hd]->orig, mov, 1.);
                     VSUM(wp[1], wp[0], hdlist[hd]->xv[g0], 1.);
                     for (i = hdlist[hd]->grid[g1]; ; ) {      /* g1 lines */
                            (*f)(wp);
                            if (!--i) break;
                            wp[0][0] += mov[0]; wp[0][1] += mov[1];
                            wp[0][2] += mov[2]; wp[1][0] += mov[0];
                            wp[1][1] += mov[1]; wp[1][2] += mov[2];
                     }
              }
}

Here is the caller graph for this function:

int new_ctab ( int  ncolors)

Definition at line 61 of file rhd_ctab.c.

{
       int    treesize;

       if (ncolors < 1)
              return(0);
                            /* free old tables */
       if (clrtab != NULL)
              free((void *)clrtab);
       if (ctree != NULL)
              free((void *)ctree);
                            /* get new tables */
       for (treesize = 1; treesize < ncolors; treesize <<= 1)
              ;
       treesize <<= 1;
       clrtab = (struct tabent *)calloc(ncolors, sizeof(struct tabent));
       ctree = (CNODE *)malloc(treesize*sizeof(CNODE));
       if (clrtab == NULL || ctree == NULL)
              return(0);
                            /* partition color space */
       cut(ctree, 0, CLRCUBE, 0, ncolors);
                            /* clear histogram */
       memset((void *)histo, '\0', sizeof(histo));
                            /* return number of colors used */
       return(ncolors);
}
void serv_request ( int  type,
int  nbytes,
char *  p 
)

Definition at line 580 of file rhdisp.c.

{
       MSGHEAD       msg;
       int    m;
                            /* consistency checks */
       DCHECK(nbytes < 0 || nbytes > 0 & p == NULL,
                     CONSISTENCY, "bad buffer handed to serv_request");
                            /* get server's attention for big request */
       if (nbytes >= BIGREQSIZ-sizeof(MSGHEAD)) {
              serv_request(DR_ATTEN, 0, NULL);
              while ((m = serv_result()) != DS_ACKNOW)
                     if (m == DS_SHUTDOWN)       /* the bugger quit on us */
                            quit(0);
       }
       msg.type = type;     /* write and flush the message */
       msg.nbytes = nbytes;
       fwrite((char *)&msg, sizeof(MSGHEAD), 1, stdout);
       if (nbytes > 0)
              fwrite(p, 1, nbytes, stdout);
       if (fflush(stdout) < 0)
              error(SYSTEM, "write error in serv_request");
}

Here is the call graph for this function:

Here is the caller graph for this function:

int serv_result ( void  )

Definition at line 503 of file rhdisp.c.

{
       static char   *buf = NULL;
       static int    bufsiz = 0;
       MSGHEAD       msg;
                                   /* read message header */
       if (fread((char *)&msg, sizeof(MSGHEAD), 1, stdin) != 1)
              goto readerr;
       if (msg.nbytes > 0) {              /* get the message body */
              if (msg.nbytes > bufsiz) {
                     if (buf == NULL)
                            buf = (char *)malloc(bufsiz=msg.nbytes);
                     else
                            buf = (char *)realloc((void *)buf,
                                          bufsiz=msg.nbytes);
                     if (buf == NULL)
                            error(SYSTEM, "out of memory in serv_result");
              }
              if (fread(buf, 1, msg.nbytes, stdin) != msg.nbytes)
                     goto readerr;
       }
       switch (msg.type) {         /* process results */
       case DS_BUNDLE:
              if (msg.nbytes < sizeof(PACKHEAD) ||
                            msg.nbytes != packsiz(((PACKHEAD *)buf)->nr))
                     error(INTERNAL, "bad display packet from server");
              disp_bundle((PACKHEAD *)buf);
              break;
       case DS_ADDHOLO:
              if (msg.nbytes < sizeof(HDGRID)+2)
                     error(INTERNAL, "bad holodeck record from server");
              add_holo((HDGRID *)buf, buf+sizeof(HDGRID),
                     buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1);
              break;
       case DS_OUTSECT:
              do_outside = 1;
              goto noargs;
       case DS_EYESEP:
              if (msg.nbytes <= 1 || (eyesepdist = atof(buf)) <= FTINY)
                     error(INTERNAL, "bad eye separation from server");
              break;
       case DS_STARTIMM:
       case DS_ENDIMM:
              if (!(imm_mode = msg.type==DS_STARTIMM))
                     dev_flush();
#ifdef DEBUG
              {
                     time_t tnow = time(NULL);
                     if (msg.type==DS_STARTIMM) tadd += tnow - tmodesw;
                     else timm += tnow - tmodesw;
                     tmodesw = tnow;
              }
#endif
              goto noargs;
       case DS_ACKNOW:
       case DS_SHUTDOWN:
              goto noargs;
       default:
              error(INTERNAL, "unrecognized result from server process");
       }
       return(msg.type);           /* return message type */
noargs:
       if (msg.nbytes) {
              sprintf(errmsg, "unexpected body with server message %d",
                            msg.type);
              error(INTERNAL, errmsg);
       }
       return(msg.type);
readerr:
       if (feof(stdin))
              error(SYSTEM, "server process died");
       error(SYSTEM, "error reading from server process");
       return -1;  
}

Here is the call graph for this function:

Here is the caller graph for this function: