00001 /* 00002 * Copyright (c) 1998 by Tech Soft 3D, LLC. 00003 * The information contained herein is confidential and proprietary to 00004 * Tech Soft 3D, LLC., and considered a trade secret as defined under 00005 * civil and criminal statutes. Tech Soft 3D shall pursue its civil 00006 * and criminal remedies in the event of unauthorized use or misappropriation 00007 * of its trade secrets. Use of this information by anyone other than 00008 * authorized employees of Tech Soft 3D, LLC. is granted only under a 00009 * written non-disclosure agreement, expressly prescribing the scope and 00010 * manner of such use. 00011 * 00012 * $Id: csutil_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $ 00013 */ 00014 00015 #ifndef __CSBSHELL_H__ 00016 #define __CSBSHELL_H__ 00017 00018 #include "hoops.h" 00019 #include "adt.h" 00020 #include "database.h" 00021 00022 /*------------data structure definitions------------------*/ 00023 00024 #define HK_FACE_NODE 1 00025 #define HK_POLYCYLINDER_SECTION_NODE 2 00026 #define HK_PHON_INFO_NODE 3 /* see csbshell.c */ 00027 #define HK_POLYCYLINDER_INFO_NODE 4 /* see csbshell.c */ 00028 #define HK_CYLINDER_INFO_NODE 5 /* see csbshell.c */ 00029 #define HK_POLYGON_INFO_NODE 6 /* see csbshell.c */ 00030 #define HK_GRID_INFO_NODE 7 /* see csbshell.c */ 00031 #define HK_SPHERE_INFO_NODE 8 /* see csbshell.c */ 00032 #define HK_VERTEX_NODE 9 /* see csbshell.c */ 00033 00034 EXTERNAL { 00035 00036 typedef struct node_header_tag { 00037 float bbox[6]; /* pretransformed bounding box around the object */ 00038 char type; 00039 char flags; /* type specific */ 00040 float min_cd, max_cd; 00041 } csnode_header_t, nh_t; 00042 00043 00044 #define FN_OWNS_FACE_PTR 0x1 /* memory for face_ptr is locally owned (and thus must be deleted at some point) */ 00045 #define FN_OWNS_PLANE 0x2 /* memory for face (plane) is locally owned (and thus must be deleted at some point) */ 00046 typedef struct face_node_tag { 00047 /* first 3 entries match nh_t */ 00048 float bbox[6]; /* pretransformed bounding box around the face */ 00049 char type; 00050 char flags; 00051 short len; 00052 int const *face_ptr; /* pointer into the face list (or tristrips' 00053 vertex index array) -- does not include length. */ 00054 float *plane; /* pretransformed plane of the face */ 00055 int index; 00056 } face_node_t, fnode_t; 00057 00058 00059 typedef struct vertex_node_tag { 00060 /* first 3 entries match nh_t */ 00061 float bbox[6]; /* pretransformed bounding box around the face */ 00062 char type; 00063 char flags; 00064 int pnum; 00065 HT_Point vertex; 00066 } vertex_node_t, vnode_t; 00067 00068 00069 typedef struct face_face_node_tag { 00070 face_node_t *f1; 00071 face_node_t *f2; 00072 float min; 00073 float max; 00074 void * env; 00075 } face_face_node_t, ffnode_t; 00076 00077 00078 #define PCSN_LOOSE_BOUNDS 0x1 00079 typedef struct { 00080 /* first 3 entries match nh_t */ 00081 float bbox[6]; /* pretransformed bounding box around this section of the polycylinder */ 00082 char type; 00083 char flags; 00084 int start; 00085 int end; 00086 } polycylinder_section_node_t, pcsnode_t; 00087 00088 00089 face_node_t *cs_new_face_node( 00090 int flags, 00091 int len, 00092 const int *iptr, 00093 const float *points, 00094 const float *matrix, 00095 const float *transformed_plane_ptr, 00096 int index 00097 ); 00098 00099 vertex_node_t *cs_new_vertex_node( 00100 const HT_Point *point, 00101 float tolerance, 00102 int pnum); 00103 00104 polycylinder_section_node_t *cs_new_polycylinder_section_node( 00105 int start, 00106 int end, 00107 HT_PolyCylinder *pc, 00108 const float *matrix ); 00109 00110 /* signature matches HI_BSP_Map_Function. 00111 * Looks at type in header to determine which destructor to call */ 00112 int cs_delete_node( void *ptr, void *ptr2 ); 00113 00114 void cs_compute_intersection( 00115 const float *pt1, 00116 const float *pt2, 00117 const float *halfspace, 00118 float *out ); 00119 #define CS_OUT 0 /* must be zero */ 00120 #define CS_IN 1 00121 #define CS_MAYBE 2 00122 int cs_point_inside_all_edges( 00123 const float *pt, 00124 const float *points1, 00125 int len1, 00126 const int *face1, 00127 const float *plane1, 00128 float tolerance ); 00129 int cs_final_accurate_test_polygon_polygon( 00130 const float *points1, 00131 int len1, 00132 const int *face1, 00133 const float *plane1, 00134 const float *points2, 00135 int len2, 00136 const int *face2, 00137 const float *plane2, 00138 float * intersecton 00139 ); 00140 int cs_test_face_plane( 00141 const float *points, 00142 int len, 00143 const int *iptr, 00144 const float *plane ); 00145 void cs_get_fbbox( 00146 int point_count, 00147 float *points, 00148 float *bbox_out); 00149 void cs_build_face_BSP( 00150 HT_VBSP *tree, 00151 int point_count, 00152 const float *points, 00153 int face_list_length, 00154 const int *face_list ); 00155 00156 void cs_build_vertex_BSP( 00157 HT_VBSP *tree, 00158 int point_count, 00159 const HT_Point *points, 00160 float tolerance); 00161 00162 void cs_calc_face_bbox( 00163 float const *points, 00164 float const *matrix, 00165 int len, 00166 int const *indices, 00167 float *bbox_out ); 00168 00169 void cs_calc_vertex_bbox( 00170 const HT_Point *point, 00171 float tolerance, 00172 float *bbox_out ); 00173 00174 int cs_compute_one_face_plane( 00175 float const *points_in, 00176 int len, 00177 int const *iptr, 00178 float alter *plane_out ); 00179 int cs_test_face_ray( 00180 HT_Point const *points, 00181 face_node_t const *face, 00182 HT_Point const *start, 00183 HT_Vector const *direction, 00184 float alter *t_out ); 00185 int cs_test_face_line( 00186 HT_Point const *points, 00187 face_node_t const *face, 00188 HT_Point const *p1, 00189 HT_Point const *p2 ); 00190 00191 00192 00193 /*------------utility macros------------------*/ 00194 00195 00196 #define TEST_FBBOX_FBBOX(bbox1,bbox2) (\ 00197 ( /* (X OVERLAPS) */\ 00198 ( (bbox1[3] >= bbox2[0]) && (bbox1[0] <= bbox2[3]) ) ||\ 00199 ( (bbox2[3] >= bbox1[0]) && (bbox2[0] <= bbox1[3]) ) \ 00200 ) &&\ 00201 ( /* (Y OVERLAPS) */\ 00202 ( (bbox1[4] >= bbox2[1]) && (bbox1[1] <= bbox2[4]) ) ||\ 00203 ( (bbox2[4] >= bbox1[1]) && (bbox2[1] <= bbox1[4]) )\ 00204 ) &&\ 00205 ( /* (Z OVERLAPS) */\ 00206 ( (bbox1[5] >= bbox2[2]) && (bbox1[2] <= bbox2[5]) ) ||\ 00207 ( (bbox2[5] >= bbox1[2]) && (bbox2[2] <= bbox1[5]) )\ 00208 ) \ 00209 ) 00210 00211 00212 /* ax + by + cz + d > 0 */ 00213 #define TEST_POINT_PLANE(pt,plane) ((((pt)[0]*(plane)[0])+((pt)[1]*(plane)[1])+((pt)[2]*(plane)[2])+(plane)[3]) > 0) 00214 00215 #define DOT_FPOINT_FPLANE(pt,plane) (((pt)[0]*(plane)[0])+((pt)[1]*(plane)[1])+((pt)[2]*(plane)[2])+(plane)[3]) 00216 00217 #define DOT_POINT_PLANE(pt,plane) (((pt)->x*(plane)->a)+((pt)->y*(plane)->b)+((pt)->z*(plane)->c)+(plane)->d) 00218 00219 #define XYZDIFF2(p1,p2) \ 00220 ( \ 00221 (p1[0]-p2[0])*(p1[0]-p2[0]) + \ 00222 (p1[1]-p2[1])*(p1[1]-p2[1]) + \ 00223 (p1[2]-p2[2])*(p1[2]-p2[2]) \ 00224 ) \ 00225 00226 00227 #define TEST_POINT_FBBOX(pt,bbox) (\ 00228 ( /* (X OVERLAPS) */\ 00229 ( ((pt)[0] >= bbox[0]) && ((pt)[0] <= bbox[3]) ) \ 00230 ) &&\ 00231 ( /* (Y OVERLAPS) */\ 00232 ( ((pt)[1] >= bbox[1]) && ((pt)[1] <= bbox[4]) ) \ 00233 ) &&\ 00234 ( /* (Z OVERLAPS) */\ 00235 ( ((pt)[2] >= bbox[2]) && ((pt)[2] <= bbox[5]) ) \ 00236 ) \ 00237 ) 00238 00239 #define TEST_BBOX_BBOX(bbox1,bbox2) ( \ 00240 ( /* (X OVERLAPS) */\ 00241 ( (bbox1[3] >= bbox2[0]) && (bbox1[0] <= bbox2[3]) ) ||\ 00242 ( (bbox2[3] >= bbox1[0]) && (bbox2[0] <= bbox1[3]) ) \ 00243 ) &&\ 00244 ( /* (Y OVERLAPS) */\ 00245 ( (bbox1[4] >= bbox2[1]) && (bbox1[1] <= bbox2[4]) ) ||\ 00246 ( (bbox2[4] >= bbox1[1]) && (bbox2[1] <= bbox1[4]) )\ 00247 ) &&\ 00248 ( /* (Z OVERLAPS) */\ 00249 ( (bbox1[5] >= bbox2[2]) && (bbox1[2] <= bbox2[5]) ) ||\ 00250 ( (bbox2[5] >= bbox1[2]) && (bbox2[2] <= bbox1[5]) )\ 00251 )\ 00252 ) 00253 00254 #define TEST_POINT_FBBOX_EPS(pt,bbox,eps) (\ 00255 ( /* (X OVERLAPS) */\ 00256 ((pt)[0] >= bbox[0] - eps) && ((pt)[0] <= bbox[3] + eps) \ 00257 ) &&\ 00258 ( /* (Y OVERLAPS) */\ 00259 ((pt)[1] >= bbox[1] - eps) && ((pt)[1] <= bbox[4] + eps) \ 00260 ) &&\ 00261 ( /* (Z OVERLAPS) */\ 00262 ((pt)[2] >= bbox[2] - eps) && ((pt)[2] <= bbox[5] + eps) \ 00263 ) \ 00264 ) 00265 00266 } //EXTERNAL 00267 00268 #endif