Back to index

radiance  4R0+20100331
Functions
rayopt.h File Reference
#include "vect.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void opt_set_format (int format)
void opt_set_fname (char *pov_name, char *inc_name)
void opt_set_quiet (int quiet)
void opt_set_bound (int bound)
void opt_set_smooth (float smooth)
void opt_set_vert (unsigned vert)
void opt_set_dec (int dec)
void opt_set_color (float red, float green, float blue)
void opt_set_texture (char *texture_name)
void opt_set_transform (Matrix mat)
void opt_clear_transform ()
int opt_add_tri (float ax, float ay, float az, float bx, float by, float bz, float cx, float cy, float cz)
void opt_write_pov (char *obj_name)
void opt_write_file (char *obj_name)
void opt_write_box (char *obj_name)
void opt_finish (void)
void opt_get_limits (float *min_x, float *min_y, float *min_z, float *max_x, float *max_y, float *max_z)
void opt_get_glimits (float *min_x, float *min_y, float *min_z, float *max_x, float *max_y, float *max_z)
unsigned opt_get_vert_cnt (void)
unsigned opt_get_tri_cnt (void)
float opt_get_index (void)
unsigned opt_get_bounds (void)
void abortmsg (char *msg, int exit_code)
void add_ext (char *fname, char *ext, int force)
void cleanup_name (char *name)

Function Documentation

void abortmsg ( char *  msg,
int  exit_code 
)

Definition at line 2397 of file rayopt.c.

{
    printf ("\n%s\n", msg);
    exit (exit_code);
}

Here is the caller graph for this function:

void add_ext ( char *  fname,
char *  ext,
int  force 
)

Definition at line 2422 of file rayopt.c.

{
    int i;

    for (i = 0; i < strlen(fname); i++)
       if (fname[i] == '.') break;

    if (fname[i] == '\0' || force) {
       if (strlen(ext) > 0)
           fname[i++] = '.';

       strcpy (&fname[i], ext);
    }
}

Here is the caller graph for this function:

void cleanup_name ( char *  name)

Definition at line 2438 of file rayopt.c.

{
    char *tmp = malloc (strlen(name)+1);
    int  i;

    /* Remove any leading blanks or quotes */
    i = 0;
    while ((name[i] == ' ' || name[i] == '"') && name[i] != '\0')
       i++;

    strcpy (tmp, &name[i]);

    /* Remove any trailing blanks or quotes */
    for (i = strlen(tmp)-1; i >= 0; i--) {
       if (isprint(tmp[i]) && !isspace(tmp[i]) && tmp[i] != '"')
           break;
       else
           tmp[i] = '\0';
    }

    strcpy (name, tmp);

    /* Prefix the letter 'N' to materials that begin with a digit */
    if (!isdigit (name[0]))
       strcpy (tmp, name);
    else {
       tmp[0] = 'N';
       strcpy (&tmp[1], name);
    }

    /* Replace all illegal charaters in name with underscores */
    for (i = 0; tmp[i] != '\0'; i++) {
       if (!isalnum(tmp[i]))
          tmp[i] = '_';
    }

    strcpy (name, tmp);

    free (tmp);
}

Here is the caller graph for this function:

int opt_add_tri ( float  ax,
float  ay,
float  az,
float  bx,
float  by,
float  bz,
float  cx,
float  cy,
float  cz 
)

Definition at line 379 of file rayopt.c.

{
    TriList2 *new_node;
    Triangle *new_tri;
    int      i;

    /* Check if the triangle is degenerate (zero area), if so return -1 */
    if (degen_tri (ax, ay, az, bx, by, bz, cx, cy, cz))
       return -1;

    if (!initialized)
       init_object();

    /* Allocate memory for the new triangle */
    new_tri = malloc (sizeof(Triangle));
    if (new_tri == NULL)
       abortmsg ("Insufficient memory for new triangles.", 1);

    /* Look up the vertex and texture indexes */
    new_tri->vert[0] = vert_lookup (ax, ay, az);
    new_tri->vert[1] = vert_lookup (bx, by, bz);
    new_tri->vert[2] = vert_lookup (cx, cy, cz);

    new_tri->text_index = texture_index;
    new_tri->text_type  = texture_type;

    new_tri->flag = 0;

    for (i = 0; i < 3; i++) {
       /* Create a new index node */
       new_node = malloc (sizeof(TriList2));
       if (new_node == NULL)
           abortmsg ("Insufficient memory for triangles.", 1);

       /* Point the index entry to the new triangle */
       new_node->tri = new_tri;

       /* Insert the new index node into the list */
       new_node->next = groot->index[i];
       new_node->prev = groot->index[i]->prev;
       groot->index[i]->prev->next = new_node;
       groot->index[i]->prev = new_node;
    }

    ++(groot->obj_cnt);

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 372 of file rayopt.c.

{
    use_transform = 0;
}
void opt_finish ( void  )

Definition at line 539 of file rayopt.c.

{
    FILE *f;

    f = fopen (out_file, "a");

    switch (out_format) {
       case POV10:
            if (object_cnt > 2 && bound_mode == 0)
               fprintf (f, "composite {  /* All Objects */\n    ");

           fprintf (f, "#include \"%s\"\n", inc_file);

           if (object_cnt > 2 && bound_mode == 0) {
              fprintf (f, "\n");
              fprintf (f, "    bounded_by {\n");
              fprintf (f, "        box { <%.4f %.4f %.4f> <%.4f %.4f %.4f> }\n",
                                    gmin[X], gmin[Y], gmin[Z],
                                    gmax[X], gmax[Y], gmax[Z]);
              fprintf (f, "    }\n");
               fprintf (f, "}\n\n");
            }
           break;

       case POV20:
            if (object_cnt > 2 && bound_mode == 0)
                fprintf (f, "union {\n    ");

           fprintf (f, "#include \"%s\"\n", inc_file);

           if (object_cnt > 2 && bound_mode == 0) {
              fprintf (f, "\n");
              fprintf (f, "    bounded_by {\n");
              fprintf (f, "        box { <%.4f, %.4f, %.4f>, <%.4f, %.4f, %.4f> }\n",
                                    gmin[X], gmin[Y], gmin[Z],
                                    gmax[X], gmax[Y], gmax[Z]);
              fprintf (f, "    }\n");
                fprintf (f, "}\n\n");
            }
           break;

       case VIVID:
           fprintf (f, "#include %s\n\n", inc_file);
           break;

       case POLYRAY:
           fprintf (f, "include \"%s\"\n\n", inc_file);
           break;

       case MGF:
           fprintf (f, "i %s\n", inc_file);
           break;
    }

    fclose (f);
}

Here is the caller graph for this function:

unsigned opt_get_bounds ( void  )

Definition at line 642 of file rayopt.c.

{
    return last_bounds;
}
void opt_get_glimits ( float *  min_x,
float *  min_y,
float *  min_z,
float *  max_x,
float *  max_y,
float *  max_z 
)

Definition at line 611 of file rayopt.c.

{
    *min_x = gmin[X];
    *min_y = gmin[Y];
    *min_z = gmin[Z];

    *max_x = gmax[X];
    *max_y = gmax[Y];
    *max_z = gmax[Z];
}
float opt_get_index ( void  )

Definition at line 636 of file rayopt.c.

{
    return last_index;
}
void opt_get_limits ( float *  min_x,
float *  min_y,
float *  min_z,
float *  max_x,
float *  max_y,
float *  max_z 
)

Definition at line 598 of file rayopt.c.

{
    *min_x = last_vmin[X];
    *min_y = last_vmin[Y];
    *min_z = last_vmin[Z];

    *max_x = last_vmax[X];
    *max_y = last_vmax[Y];
    *max_z = last_vmax[Z];
}
unsigned opt_get_tri_cnt ( void  )

Definition at line 630 of file rayopt.c.

{
    return last_tri_cnt;
}
unsigned opt_get_vert_cnt ( void  )

Definition at line 624 of file rayopt.c.

{
    return last_vert_cnt;
}
void opt_set_bound ( int  bound)

Definition at line 287 of file rayopt.c.

{
    if (bound != 0 && bound != 1 && bound != 2)
       abortmsg ("ERROR: Invalid parameter passed to opt_set_bound.", 1);

    bound_mode = bound;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void opt_set_color ( float  red,
float  green,
float  blue 
)

Definition at line 320 of file rayopt.c.

{
    if (!initialized)
       init_object();

    if (last_pal.red != red || last_pal.green != green ||
                            last_pal.blue != blue || psize == 0)
    {
       last_pal.red   = red;
       last_pal.green = green;
       last_pal.blue  = blue;

       texture_index = pal_lookup (red, green, blue);
    }

    texture_type = 0;   /* An RGB texture */
}

Here is the call graph for this function:

void opt_set_dec ( int  dec)

Definition at line 311 of file rayopt.c.

{
    if (dec < 0 || dec > 9)
       abortmsg ("ERROR: Invalid parameter passed to opt_set_dec.", 1);

    dec_point = dec;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void opt_set_fname ( char *  pov_name,
char *  inc_name 
)

Definition at line 235 of file rayopt.c.

{
    FILE *f;

    strcpy (out_file, out_name);

    if (strlen(inc_name) > 0)
       strcpy (inc_file, inc_name);
    else {
       strcpy (inc_file, out_file);

       switch (out_format) {
           case POV10:
           case POV20:   add_ext (inc_file, "inc", 1);
                       break;
           case VIVID:   add_ext (inc_file, "vo", 1);
                       break;
           case POLYRAY: add_ext (inc_file, "inc", 1);
                       break;
           case MGF:     add_ext (inc_file, "inc", 1);
                       break;
       }
    }

    if (strcmp (out_file, inc_file) == 0)
       abortmsg ("Main file and include file cannot have the same name", 1);

    if ((f = fopen (out_file, "w")) == NULL) {
       printf ("Cannot open output file %s\n", out_file);
       exit (1);
    }

    fclose (f);

    if ((f = fopen (inc_file, "w")) == NULL) {
       printf ("Cannot open output file %s\n", inc_file);
       exit (1);
    }

    fclose (f);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void opt_set_format ( int  format)

Definition at line 225 of file rayopt.c.

{
    if (format != POV10 && format != POV20 && format != VIVID
              && format != POLYRAY && format != MGF)
       abortmsg ("ERROR: Invalid parameter passed to opt_set_format.", 1);

    out_format = format;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void opt_set_quiet ( int  quiet)

Definition at line 278 of file rayopt.c.

{
    if (quiet != 0 && quiet != 1)
       abortmsg ("ERROR: Invalid parameter passed to opt_set_quiet.", 1);

    quiet_mode = quiet;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void opt_set_smooth ( float  smooth)

Definition at line 296 of file rayopt.c.

{
    if (smooth < 0.0 || smooth > 180.0)
       abortmsg ("ERROR: Invalid parameter passed to opt_set_smooth.", 1);

    smooth_angle = smooth;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void opt_set_texture ( char *  texture_name)

Definition at line 339 of file rayopt.c.

{
    char new_texture[64];

    if (!initialized)
       init_object();

    strcpy (new_texture, texture_name);
    cleanup_name (new_texture);

    if (strcmp (last_texture, new_texture) != 0) {
       strcpy (last_texture, new_texture);
       texture_index = texture_lookup (new_texture);
    }

    texture_type = 1;   /* A named texture */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void opt_set_transform ( Matrix  mat)

Definition at line 359 of file rayopt.c.

{
    int i, j;

    for (i = 0; i < 4; i++) {
       for (j = 0; j < 3; j++)
           trans_matrix[i][j] = mat[i][j];
    }

    use_transform = 1;
}

Here is the caller graph for this function:

void opt_set_vert ( unsigned  vert)

Definition at line 305 of file rayopt.c.

{
    vert_init = vert;
}

Here is the caller graph for this function:

void opt_write_box ( char *  obj_name)

Definition at line 503 of file rayopt.c.

{
    VertList *temp;
    int i;

    if (!initialized || groot->obj_cnt == 0) {
       orig_tpr = 1.0;
       final_tpr = 0.0;
       tot_bounds = 0;
       return;   /* No triangles where ever added, nothing to write */
    }

    strcpy (object_name, obj_name);
    cleanup_name (object_name);

    ++object_cnt;

    /* Dump the hash table, don't need it any more */
    for (i = 0; i < HASHSIZE; i++) {
       while (vert_hash[i] != NULL) {
           temp = vert_hash[i];
           vert_hash[i] = vert_hash[i]->next;
           free (temp);
       }
    }

    orig_tpr = final_tpr = 1.0;

    update_node (groot);

    write_box (groot->vmin, groot->vmax, groot->index[0]->next->tri);

    cleanup_object();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void opt_write_file ( char *  obj_name)

Definition at line 439 of file rayopt.c.

{
    VertList *temp;
    int      i;

    if (out_format != POV10 && out_format != POV20)
       bound_mode = 2;

    if (!initialized || groot->obj_cnt == 0) {
       orig_tpr = 1.0;
       final_tpr = 0.0;
       tot_bounds = 0;
       return;   /* No triangles where ever added, nothing to write */
    }

    strcpy (object_name, obj_name);
    cleanup_name (object_name);

    ++object_cnt;

    /* Dump the hash table, don't need it any more */
    for (i = 0; i < HASHSIZE; i++) {
       while (vert_hash[i] != NULL) {
           temp = vert_hash[i];
           vert_hash[i] = vert_hash[i]->next;
           free (temp);
       }
    }

    /* Build the vertice index */
    build_tri_index();

    if (bound_mode != 2) {
       if (!quiet_mode)
           printf ("Building indexes\n");

       sort_indexes (groot);
    }

    update_node (groot);

    if (!quiet_mode) {
       printf ("Adding bounds (1)\r");
       fflush(stdout);;
    }

    /* Optimize the tree */
    orig_tpr = calc_tpr (groot);

    if (bound_mode != 2)
       optimize_tree (groot);

    final_tpr = calc_tpr (groot);

    /* Write the file */
    write_file();

    /* Free up the vertex index */
    dump_tri_index();

    cleanup_object();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void opt_write_pov ( char *  obj_name)

Definition at line 432 of file rayopt.c.

Here is the call graph for this function: