--- ray/src/hd/sm.h 1998/09/11 11:52:25 3.2 +++ ray/src/hd/sm.h 1999/01/10 10:27:47 3.8 @@ -10,7 +10,7 @@ #define _SM_H_ #include "rhd_sample.h" -#include "sm_stree.h" +#define NEWSETS #ifndef TRUE @@ -18,19 +18,37 @@ #define FALSE 0 #endif -#define P_REPLACE_EPS 0.5 -#define SQRT3_2 0.8660254 -#define MAX_EDGES 200 +#define ON_V 1 +#define ON_P 2 +#define ON_E 3 +#define IN_T 4 -#define SM_INVALID -1 -#define SM_DEFAULT 0 -#define SM_EXTRA_POINTS 5 +#define S_REPLACE_EPS 0.04 /* if (distance on sphere between sample + and a base point) < S_REPLACE_EPS, + replace base: + */ +#define S_REPLACE_SCALE (5.*5.) /* if (distance to new point squared) is + > (triangle edge length squared* + S_REPLACE_SCALE):for all edges/triangle + vertices: new point is puncture + point: dont add + */ +#define S_REPLACE_TRI 2e-8 /* .052 radians to the sixth power */ + +#define SQRT3_2 0.8660254 + +#define SM_DEFAULT 0 +#define SM_EXTRA_POINTS 162 +#define SM_BASE_TRIS 320 #define SM_EXTRA_VERTS SM_EXTRA_POINTS -#define SM_POINTSIZ (3*sizeof(float)+ sizeof(int4)) -#define SM_POINT_SPACE SM_EXTRA_POINTS * SM_POINTSIZ -#define SM_INC_PERCENT 0.60 +#define SM_INC_PERCENT 0.60 /* If number of new triangles added + since last full redraw is > + (SM_INC_PERCENT * total triangles) + do full redraw instead of incremental + */ + #define SM_VIEW_FRAC 0.1 @@ -41,13 +59,13 @@ typedef struct _EDGE { int verts[2]; int tris[2]; } EDGE; + #define E_NTH_VERT(e,i) ((e>0)?Edges[(e)].verts[(i)]:Edges[-(e)].verts[(1-i)]) #define SET_E_NTH_VERT(e,i,v) if(e>0) Edges[(e)].verts[(i)]=(v); \ else Edges[-(e)].verts[(1-i)]=(v) #define E_NTH_TRI(e,i) ((e>0)?Edges[(e)].tris[(i)]:Edges[-(e)].tris[(1-i)]) #define SET_E_NTH_TRI(e,i,v) if(e>0) Edges[(e)].tris[(i)]=(v); \ else Edges[-(e)].tris[(1-i)]=(v) -#define eNew_edge() (((Ecnt) < MAX_EDGES)?(++Ecnt):SM_INVALID) #define eClear_edges() (Ecnt = 0) #define FOR_ALL_EDGES(i) for((i)=1; (i) <= Ecnt; i++) @@ -67,118 +85,101 @@ typedef struct _TRI { #define T_NTH_V(t,i) ((t)->verts[(i)]) #define T_WHICH_V(t,i) \ (T_NTH_V(t,0)==(i)?0:T_NTH_V(t,1)==(i)?1:T_NTH_V(t,2)==(i)?2:-1) -#define T_NEXT_FREE(t) ((t)->verts[0]) -#define T_VALID_FLAG(t) ((t)->verts[1]) +#define T_NEXT_FREE(t) ((t)->nbrs[0]) +#define T_NEXT_AVAILABLE(t) ((t)->nbrs[0]) +#define T_VALID_FLAG(t) ((t)->nbrs[1]) #define T_IS_VALID(t) (T_VALID_FLAG(t)!=-1) #define T_FLAGS 4 -#define T_FLAG_BYTES T_FLAGS/8.0 -#define T_TOTAL_FLAG_BYTES(c) ((((c)+31)>>5)*sizeof(int4)) typedef struct _SM { FVECT view_center; /* Canonical view center defining unit sphere */ - RSAMP *samples; /* Sample point information */ - STREE locator; /* spherical quadtree for point/triangle location */ + SAMP *samples; /* Sample point information */ + STREE locator; /* spherical quadtree for point/triangle location */ int max_tris; /* Maximum number of triangles */ - int tri_cnt; /* Total number of tris ever alloc at one time*/ - int num_tris; /* Current number of sample (nonbase)triangles */ + int num_tri; /* Current number of triangles */ + int sample_tris; /* Current number of non-base triangles*/ int free_tris; /* pointer to free_list */ + int available_tris; /* pointer to available_list */ int max_verts; /* Maximum number of vertices in the mesh */ TRI *tris; /* Pointer to list of triangle structs */ VERT *verts; /* List of vertices */ int4 *flags[T_FLAGS]; /* Bit 0 set if active(in current frustum) */ - /* Bit 1 set if not rendered since created */ - /* Bit 2 set if base triangle */ - /* Bit 3 set used for LRU replacement */ - char *base; /* Allocated space */ + /* Bit 1 set if not rendered since created */ + /* Bit 2 set if base triangle */ }SM; #define T_ACTIVE_FLAG 0 #define T_NEW_FLAG 1 #define T_BASE_FLAG 2 -#define T_LRU_FLAG 3 +#define T_BG_FLAG 3 #define SM_VIEW_CENTER(m) ((m)->view_center) #define SM_SAMP(m) ((m)->samples) #define SM_LOCATOR(m) (&((m)->locator)) #define SM_MAX_TRIS(m) ((m)->max_tris) -#define SM_TRI_CNT(m) ((m)->tri_cnt) -#define SM_NUM_TRIS(m) ((m)->num_tris) +#define SM_NUM_TRI(m) ((m)->num_tri) +#define SM_SAMPLE_TRIS(m) ((m)->sample_tris) #define SM_FREE_TRIS(m) ((m)->free_tris) +#define SM_AVAILABLE_TRIS(m) ((m)->available_tris) #define SM_MAX_VERTS(m) ((m)->max_verts) #define SM_TRIS(m) ((m)->tris) #define SM_VERTS(m) ((m)->verts) #define SM_NTH_FLAGS(m,n) ((m)->flags[(n)]) -#define SM_BASE(m) ((m)->base) +#define SM_FLAGS(m) ((m)->flags) -#define TF_OFFSET(n) ((n) >> 5) -#define TF_BIT(n) ((n) & 0x1f) -#define SM_IS_NTH_T_FLAG(sm,n,f) (SM_NTH_FLAGS(sm,f)[TF_OFFSET(n)] & (0x1 <= SM_MAX_SAMP(sm))) -#define SM_INVALID_POINT_ID(sm,id) (((id) < 0) || ((id) >= SM_MAX_AUX_PT(sm))) -#define SM_T_CENTROID(sm,t,c) tri_centroid(SM_NTH_WV(sm,T_NTH_V(t,0)),SM_NTH_WV(sm,T_NTH_V(t,1)),SM_NTH_WV(sm,T_NTH_V(t,2)),c) +#define SM_INVALID_POINT_ID(sm,id) (((id) < 0) || ((id) >= SM_MAX_POINTS(sm))) #define SM_T_NTH_WV(sm,t,i) (SM_NTH_WV(sm,T_NTH_V(t,i))) #define SM_BASE_ID(s,i) \ - ((i) >= RS_MAX_SAMP(SM_SAMP(s)) && (i) < RS_MAX_AUX_PT(SM_SAMP(s))) + ((i) >= S_MAX_SAMP(SM_SAMP(s)) && (i) < S_MAX_BASE_PT(SM_SAMP(s))) #define SM_BG_SAMPLE(sm,i) (SM_NTH_W_DIR(sm,i)==-1) @@ -191,30 +192,93 @@ t!=SM_NTH_TRI(sm,SM_NTH_VERT(sm,id)); t=smTri_next_ccw #define SM_FOR_ALL_SAMPLES(sm,i) for((i)=0;i < SM_NUM_SAMP(sm);(i)++) -typedef struct _T_DEPTH { - int tri; - double depth; -}T_DEPTH; +#define smInit_locator(sm,c) (stInit(SM_LOCATOR(sm)), \ + ST_SET_CENTER(SM_LOCATOR(sm),c)) +#define smClear_locator(sm) stClear(SM_LOCATOR(sm)) +#define smAlloc_locator(sm) stAlloc(SM_LOCATOR(sm)) +#define smFree_locator(sm) stClear(SM_LOCATOR(sm)) +#define smPointLocateCell(sm,pt) stPoint_locate(SM_LOCATOR(sm),pt) +#define smUnalloc_samp(sm,id) sUnalloc_samp(SM_SAMP(sm),id) +#define smFree_samples(sm) sFree(SM_SAMP(sm)) +#define smClear_samples(sm) sClear(SM_SAMP(sm)) +#define smInit_samples(sm) sInit(SM_SAMP(sm)) +#define smClear_vert(sm,id) (SM_NTH_VERT(sm,id) = INVALID) + +typedef struct _RT_ARGS_{ + FVECT orig,dir; + int t_id; + OBJECT *os; +}RT_ARGS; + + +typedef struct _ADD_ARGS { + int t_id; + OBJECT *del_set; +}ADD_ARGS; + extern SM *smMesh; extern int smNew_tri_cnt; extern double smDist_sum; + #ifdef TEST_DRIVER extern VIEW View; extern VIEW Current_View; extern int Pick_tri,Picking,Pick_samp; extern FVECT Pick_point[500],Pick_origin,Pick_dir; extern FVECT Pick_v0[500],Pick_v1[500],Pick_v2[500]; +extern int Pick_q[500]; extern FVECT P0,P1,P2; extern int Pick_cnt; extern FVECT FrustumNear[4],FrustumFar[4]; #endif -#ifdef DEBUG -extern int Malloc_cnt; -#endif + +/* + * int + * smInit(n) : Initialize/clear data structures for n entries + * int n; + * + * Initialize sampL and other data structures for at least n samples. + * If n is 0, then free data structures. Return number actually allocated. + * + * + * int + * smNewSamp(c, p, v) : register new sample point and return index + * COLR c; : pixel color (RGBE) + * FVECT p; : world intersection point + * FVECT v; : ray direction vector + * + * Add new sample point to data structures, removing old values as necessary. + * New sample representation will be output in next call to smUpdate(). + * + * + * int + * smFindSamp(orig, dir): intersect ray with 3D rep. and find closest sample + * FVECT orig, dir; + * + * Find the closest sample to the given ray. Return -1 on failure. + * + * + * smClean() : display has been wiped clean + * + * Called after display has been effectively cleared, meaning that all + * geometry must be resent down the pipeline in the next call to smUpdate(). + * + * + * smUpdate(vp, qua) : update OpenGL output geometry for view vp + * VIEW *vp; : desired view + * int qua; : quality level (percentage on linear time scale) + * + * Draw new geometric representation using OpenGL calls. Assume that the + * view has already been set up and the correct frame buffer has been + * selected for drawing. The quality level is on a linear scale, where 100% + * is full (final) quality. It is not necessary to redraw geometry that has + * been output since the last call to smClean(). (The last view drawn will + * be vp==&odev.v each time.) + */ #endif