BRL-CAD
sh_prj.c File Reference
#include "common.h"
#include <stddef.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h>
#include "vmath.h"
#include "raytrace.h"
#include "optical.h"
#include "plot3.h"
Include dependency graph for sh_prj.c:

Go to the source code of this file.

Data Structures

struct  img_specific
 
struct  prj_specific
 

Macros

#define prj_MAGIC   0x70726a00 /* "prj" */
 
#define CK_prj_SP(_p)   BU_CKMAG(_p, prj_MAGIC, "prj_specific")
 
#define IMG_SRC_FILE   'f'
 
#define IMG_SRC_OBJECT   'o'
 
#define IMG_SRC_AUTO   0
 
#define IMG_MAGIC   0x696d6700 /* "img" */
 
#define IMG_SPECIFIC_INIT_ZERO   {BU_LIST_INIT_ZERO, 0, BU_VLS_INIT_ZERO, '\0', NULL, NULL, NULL, 0, 0, 0.0, VINIT_ZERO, HINIT_ZERO, MAT_INIT_IDN, MAT_INIT_IDN, HINIT_ZERO, MAT_INIT_IDN, '\0', '\0', '\0', 0.0}
 
#define IMG_O(m)   bu_offsetof(struct img_specific, m)
 

Functions

HIDDEN void img_source_hook (const struct bu_structparse *sdp, const char *sp_name, void *base, const char *value, void *data)
 
HIDDEN int img_load_datasource (struct img_specific *image, struct db_i *dbInstance, const unsigned long int size)
 
HIDDEN void persp_hook (const struct bu_structparse *sdp, const char *name, void *base, const char *value, void *data)
 
HIDDEN void dimen_hook (const struct bu_structparse *sdp, const char *name, void *base, const char *value, void *data)
 
HIDDEN int prj_setup (register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
 
HIDDEN int prj_render (struct application *ap, const struct partition *pp, struct shadework *swp, void *dp)
 
HIDDEN void prj_print (register struct region *rp, void *dp)
 
HIDDEN void prj_free (void *cp)
 
HIDDEN int project_point (point_t sh_color, struct img_specific *img_sp, struct prj_specific *prj_sp, point_t r_pt)
 

Variables

struct bu_structparse img_parse_tab []
 
struct bu_structparse img_print_tab []
 
struct mfuncs prj_mfuncs []
 
HIDDEN const double cs = (1.0/255.0)
 
HIDDEN const point_t delta = {0.5, 0.5, 0.0}
 

Detailed Description

Projection shader

The one parameter to this shader is a filename. The named file contains the REAL parameters to the shader. The v4 database format is far too anemic to support this sort of shader.

Definition in file sh_prj.c.

Macro Definition Documentation

#define prj_MAGIC   0x70726a00 /* "prj" */

Definition at line 47 of file sh_prj.c.

Referenced by prj_setup().

#define CK_prj_SP (   _p)    BU_CKMAG(_p, prj_MAGIC, "prj_specific")

Definition at line 48 of file sh_prj.c.

Referenced by prj_render().

#define IMG_SRC_FILE   'f'

Definition at line 54 of file sh_prj.c.

Referenced by img_load_datasource(), img_source_hook(), and prj_setup().

#define IMG_SRC_OBJECT   'o'

Definition at line 55 of file sh_prj.c.

Referenced by img_load_datasource(), img_source_hook(), and prj_setup().

#define IMG_SRC_AUTO   0

Definition at line 56 of file sh_prj.c.

Referenced by img_load_datasource(), img_source_hook(), and prj_setup().

#define IMG_MAGIC   0x696d6700 /* "img" */

Definition at line 75 of file sh_prj.c.

#define IMG_SPECIFIC_INIT_ZERO   {BU_LIST_INIT_ZERO, 0, BU_VLS_INIT_ZERO, '\0', NULL, NULL, NULL, 0, 0, 0.0, VINIT_ZERO, HINIT_ZERO, MAT_INIT_IDN, MAT_INIT_IDN, HINIT_ZERO, MAT_INIT_IDN, '\0', '\0', '\0', 0.0}

Definition at line 76 of file sh_prj.c.

Referenced by prj_setup().

#define IMG_O (   m)    bu_offsetof(struct img_specific, m)

Definition at line 384 of file sh_prj.c.

Function Documentation

HIDDEN void img_source_hook ( const struct bu_structparse sdp,
const char *  sp_name,
void *  base,
const char *  value,
void *  data 
)

img_source_hook() is used to record where the image datasource is coming from so that the image may be loaded automatically as needed from either a file or from a database-embedded binary object.

Definition at line 97 of file sh_prj.c.

References bu_strncmp(), img_specific::i_datasrc, IMG_SRC_AUTO, IMG_SRC_FILE, and IMG_SRC_OBJECT.

Here is the call graph for this function:

HIDDEN int img_load_datasource ( struct img_specific image,
struct db_i dbInstance,
const unsigned long int  size 
)

This is a helper routine used in prj_setup() to load a projection image either from a file or from a db object.

Definition at line 119 of file sh_prj.c.

References BU_ALLOC, bu_bomb(), bu_free(), bu_log(), bu_open_mapped_file_with_path(), bu_vls_addr(), bu_mapped_file::buf, bu_mapped_file::buflen, rt_binunif_internal::count, db_lookup(), db_i::dbi_filepath, img_specific::i_binunifp, img_specific::i_data, img_specific::i_datasrc, img_specific::i_img, img_specific::i_name, rt_db_internal::idb_ptr, IMG_SRC_AUTO, IMG_SRC_FILE, IMG_SRC_OBJECT, LOOKUP_QUIET, RT_CK_BINUNIF, RT_CK_DB_INTERNAL, RT_CK_DBI, RT_CK_DIR, rt_db_get_internal(), RT_DB_INTERNAL_INIT, RT_DIR_NULL, rt_binunif_internal::u, and rt_binunif_internal::uint8.

Referenced by prj_setup().

Here is the call graph for this function:

HIDDEN void persp_hook ( const struct bu_structparse sdp,
const char *  name,
void *  base,
const char *  value,
void *  data 
)

Bounds checking on perspective angle

Definition at line 209 of file sh_prj.c.

References bu_bomb(), bu_log(), img_specific::i_perspective, and ZERO.

Here is the call graph for this function:

HIDDEN void dimen_hook ( const struct bu_structparse sdp,
const char *  name,
void *  base,
const char *  value,
void *  data 
)

Check for value < 0.0

Definition at line 240 of file sh_prj.c.

References bu_bomb(), bu_log(), BU_STR_EQUAL, bu_structparse::sp_fmt, bu_structparse::sp_name, and bu_structparse::sp_offset.

Here is the call graph for this function:

HIDDEN int prj_setup ( register struct region rp,
struct bu_vls matparm,
void **  dpp,
const struct mfuncs *  mfp,
struct rt_i rtip 
)
int prj_render ( struct application ap,
const struct partition pp,
struct shadework *  swp,
void *  dp 
)

This is called (from viewshade() in shade.c) once for each hit point to be shaded. The purpose here is to fill in values in the shadework structure.

Definition at line 693 of file sh_prj.c.

References application::a_pixelext, application::a_rt_i, bn_isect_line3_plane(), BU_CK_PIXEL_EXT, BU_LIST_FOR, bu_log(), CK_prj_SP, pixel_ext::corner, CORNER_PTS, img_specific::i_plane, img_specific::i_through, img_specific::l, pdv_3cont(), pdv_3move(), pl_color(), prj_specific::prj_images, prj_specific::prj_m_to_sh, prj_specific::prj_plfd, prj_print(), project_point(), partition::pt_regionp, xray::r_dir, xray::r_pt, rdebug, RT_AP_CHECK, RT_CHECK_PT, rt_i::rti_tol, V3ARGS, and VSET.

Here is the call graph for this function:

HIDDEN void prj_print ( register struct region rp,
void *  dp 
)

Definition at line 578 of file sh_prj.c.

References BU_LIST_FOR, bu_struct_print(), img_specific::l, prj_specific::prj_images, and region::reg_name.

Referenced by prj_render(), and prj_setup().

Here is the call graph for this function:

HIDDEN void prj_free ( void *  cp)

Definition at line 590 of file sh_prj.c.

References bu_close_mapped_file(), BU_LIST_DEQUEUE, BU_LIST_WHILE, BU_PUT, BU_SEM_SYSCALL, bu_semaphore_acquire(), bu_semaphore_release(), bu_vls_vlsfree(), img_specific::i_binunifp, img_specific::i_data, img_specific::i_img, img_specific::i_name, img_specific::l, prj_specific::prj_images, prj_specific::prj_plfd, and rt_binunif_free().

Here is the call graph for this function:

HIDDEN int project_point ( point_t  sh_color,
struct img_specific img_sp,
struct prj_specific prj_sp,
point_t  r_pt 
)

Definition at line 622 of file sh_prj.c.

References bu_log(), rt_binunif_internal::count, img_specific::i_behind, img_specific::i_height, img_specific::i_img, img_specific::i_plane, img_specific::i_sh_to_img, img_specific::i_width, pdv_3cont(), pdv_3move(), pl_color(), prj_specific::prj_plfd, rdebug, V3ARGS, VPRINT, X, Y, and Z.

Referenced by prj_render().

Here is the call graph for this function:

Variable Documentation

struct bu_structparse img_parse_tab[]
Initial value:
= {
{"%V", 1, "image", IMG_O(i_name), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%V", 1, "file", IMG_O(i_name), img_source_hook, NULL, NULL },
{"%V", 1, "obj", IMG_O(i_name), img_source_hook, NULL, NULL },
{"%V", 1, "object", IMG_O(i_name), img_source_hook, NULL, NULL },
{"%d", 1, "w", IMG_O(i_width), dimen_hook, NULL, NULL },
{"%d", 1, "n", IMG_O(i_height), dimen_hook, NULL, NULL },
{"%f", 1, "viewsize", IMG_O(i_viewsize), dimen_hook, NULL, NULL },
{"%f", 3, "eye_pt", IMG_O(i_eye_pt), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 4, "orientation", IMG_O(i_orient), orient_hook, NULL, NULL },
{"%c", 1, "through", IMG_O(i_through), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%c", 1, "antialias", IMG_O(i_antialias), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%c", 1, "behind", IMG_O(i_behind), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 1, "perspective", IMG_O(i_perspective), persp_hook, NULL, NULL },
{"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
}
#define IMG_O(m)
Definition: sh_prj.c:384
HIDDEN void img_source_hook(const struct bu_structparse *sdp, const char *sp_name, void *base, const char *value, void *data)
Definition: sh_prj.c:97
HIDDEN void dimen_hook(const struct bu_structparse *sdp, const char *name, void *base, const char *value, void *data)
Definition: sh_prj.c:240
HIDDEN void persp_hook(const struct bu_structparse *sdp, const char *name, void *base, const char *value, void *data)
Definition: sh_prj.c:209
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:153

description of how to parse/print the arguments to the shader. There is at least one line here for each variable in the shader specific structure above

Definition at line 391 of file sh_prj.c.

struct bu_structparse img_print_tab[]
Initial value:
= {
{"%p", 1, "img_parse_tab", bu_byteoffset(img_parse_tab[0]), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 4, "i_plane", IMG_O(i_plane), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
}
#define bu_byteoffset(_i)
Definition: parse.h:81
#define IMG_O(m)
Definition: sh_prj.c:384
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:153
struct bu_structparse img_parse_tab[]
Definition: sh_prj.c:391

Definition at line 407 of file sh_prj.c.

struct mfuncs prj_mfuncs[]
Initial value:
= {
{MF_MAGIC, "prj", 0, MFI_NORMAL|MFI_HIT|MFI_UV, 0,
{0, (char *)0, 0, 0, 0,
0, 0, 0, 0 }
}
HIDDEN int prj_setup(register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
Definition: sh_prj.c:443
HIDDEN void prj_free(void *cp)
Definition: sh_prj.c:590
#define MF_MAGIC
Definition: magic.h:205
HIDDEN int prj_render(struct application *ap, const struct partition *pp, struct shadework *swp, void *dp)
Definition: sh_prj.c:693
HIDDEN void prj_print(register struct region *rp, void *dp)
Definition: sh_prj.c:578

The "mfuncs" structure defines the external interface to the shader. Note that more than one shader "name" can be associated with a given shader by defining more than one mfuncs struct in this array. See sh_phong.c for an example of building more than one shader "name" from a set of source functions. There you will find that "glass" "mirror" and "plastic" are all names for the same shader with different default values for the parameters.

Definition at line 428 of file sh_prj.c.

Referenced by optical_shader_init().