BEdgeBreaker.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 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  * $Header: //DWF/Working_Area/Willie.Zhu/w3dtk/BEdgeBreaker.h#1 $
00013  *
00014  *
00015  *
00016  * HEdgeBreaker.h
00017  *
00018  * This file describes the public interface to the edgebreaker module, plus some internal 
00019  * definitions that are shared between one or more edgebreaker source code files
00020  * 
00021  * Some notes about the interface:
00022  * in_out
00023  *   Parameters with names ending in "in_out" are used for both input and output.
00024  *   On the way in they say how much was allocated.  On the way out, they say
00025  *   how much was used.
00026  * faces
00027  *   The following is a description of the HOOPS face list (taken from the
00028  *   standard HOOPS reference manual)...
00029  *   "The face_list is an array of integers. The first integer is the
00030  *    number of vertices that should be connected to form the first face. For 
00031  *    example, "3" for a triangle. The next three integers (in this example) 
00032  *    are the offsets into the points array at which the three x-y-z's can 
00033  *    be found. The first point in the points array is considered to be at 
00034  *    offset zero, so "0, 1, 2" in the face_list array would form the triangle 
00035  *    from the first three entries in points."
00036  *   a face list by tristrips is (again from the HOOPS 3dgs reference manual)
00037  *   "an array of integers that describes the triangle strips. It is a list of an 
00038  *    unlimited number of independent triangle strips placed contiguously in memory, 
00039  *    one after another. Each triangle strip begins with the number of vertices 
00040  *    referenced, and then the list of vertices. Vertices 0-2 form one triangle. 
00041  *    For every n such that 2 < n <= number of vertices, a new triangle is introduced. 
00042  *    This new triangle will be [n-2, n-1, n] for even n, and [n-1, n-2, n] for odd n 
00043  *    (to maintain consistent handedness of the triangles). Degenerate triangles 
00044  *    (triangles which reference the same vertex more than once) are allowed. The 
00045  *    length of this array should be given as a number of integers, the number of 
00046  *    triangles plus 3 per independent triangle strip. "
00047  * pointmap
00048  *   Vertex id's, sorted by order of appearance in the compressed stream.  This
00049  *   array is needed for transmitting vertex attributes (e.g. normals or texture
00050  *   coordinates) in parallel with their locations.  For example:
00051  *   for( i = 0 ; i < pointmap_len ; i++ ) {
00052  *      *out++ = texcoords[ pointmap[i] ].u;
00053  *      *out++ = texcoords[ pointmap[i] ].v;
00054  *   }
00055  * pcount
00056  *   the **number** of xyz triplets in the array of vertex locations.
00057  * flen
00058  *   the number of integers in the face list
00059  */
00060 #ifndef __BEDGEBREAKER_H__
00061 #define __BEDGEBREAKER_H__
00062 
00066 
00067 #ifndef BSTREAM_DISABLE_EDGEBREAKER
00068 
00069 
00070 #define EB_DEFAULT (-1)
00071 
00072 typedef struct ET_Bounding_TAG {
00073     float x1, y1, z1;
00074     float x2, y2, z2;
00075 } ET_Bounding;
00076 
00077 typedef void *(*ET_Malloc_Action)(size_t size, void *user_data);
00078 typedef void(*ET_Free_Action)(void *ptr, void *user_data);
00079 typedef void(*ET_New_Vertex_Action)(int a, int b, int c, void *user_data);
00080 
00081 #define HINT_ONE_PIECE              0x0001
00082 #define HINT_WATERTIGHT             0x0002
00083 #define HINT_MANIFOLD               0x0004
00084 #define HINT_NO_HANDLES             0x0008
00085 #define HINT_NO_BACKWARDS_OR_HOLES  0x0010
00086 #define HINT_INPUT_BY_TRISTRIPS     0x0020
00087 
00088 #define STATUS_ERROR            0
00089 #define STATUS_NORMAL           1
00090 #define STATUS_COMPLETE         2
00091 #define STATUS_WATERTIGHT       3
00092 #define STATUS_TRY_AGAIN        4
00093 
00094 
00095 
00096 typedef struct eb_compress_configs_TAG {
00097     
00098     int x_quantization, y_quantization, z_quantization;
00099     
00100     int x_quantization_normals, y_quantization_normals, z_quantization_normals;
00101     
00102     float point_factor;         
00103     
00104     ET_Bounding *bounding;
00105     int hints;
00106     
00107     ET_Malloc_Action malloc_action;
00108     ET_Free_Action free_action;
00109     ET_New_Vertex_Action new_vertex_action;
00110     void *user_data;
00111     
00112     int target_version;
00113 } eb_compress_configs;
00114 extern int show_edgebreaker_compress_size( 
00115                         int pcount, 
00116                         int flen, 
00117                         int const *face_data, 
00118                         int *stream_len_out,
00119                         int *pointmap_count_out,
00120                         
00121                         eb_compress_configs const *configs
00122                         );
00123 extern int edgebreaker_compress( 
00124                         int pcount, 
00125                         float const *points, 
00126                         float const *normals, 
00127                         int flen, 
00128                         
00129                         int const *fdata_in,            
00130                         int *stream_len_in_out,
00131                         
00132                         void *stream_out,               
00133                         int *pointmap_len_in_out,
00134                         
00135                         int *pointmap_out,              
00136                         
00137                         eb_compress_configs const *configs      
00138                         );
00139 
00140 typedef struct eb_decompress_configs_TAG {
00141                         
00142     ET_Bounding const *bounding;
00143     
00144     ET_Malloc_Action malloc_action;
00145     ET_Free_Action free_action;
00146     ET_New_Vertex_Action new_vertex_action;
00147     void *user_data;
00148 } eb_decompress_configs;
00149 extern int show_edgebreaker_decompress_size( 
00150                         int stream_len, 
00151                         void const *stream, 
00152                         int *pcount_out, 
00153                         int *normal_count_out, 
00154                         int *flen_out 
00155                         );
00156 extern int edgebreaker_decompress( 
00157                         int stream_len, 
00158                         
00159                         void const *stream,             
00160                         int *pcount_in_out, 
00161                         float *points_out, 
00162                         float *normals_out, 
00163                         
00164                         bool *by_tristrips_out,
00165                         
00166                         int *flen_in_out,
00167                         
00168                         int *faces_out,
00169                         
00170                         eb_decompress_configs const *configs            
00171                         );
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179     
00180 
00181 
00182 typedef struct {
00183     char scheme;    
00184     char mtable_scheme;
00185     char points_scheme;
00186     char normals_scheme; 
00187     int opslen;     
00188     int mtablelen;  
00189     int pointslen;  
00190     int pcount;     
00191 } edgebreaker_header0;
00192 
00193 
00194 typedef struct {
00195     edgebreaker_header0 v0;
00196     int normalslen;
00197 } edgebreaker_header1;
00198 
00199 
00200 typedef struct EDGEBREAKER_HEADER_TAG {
00201     char scheme;    
00202     char mtable_scheme;
00203     char points_scheme;
00204     char normals_scheme; 
00205     int opslen;     
00206     int mtablelen;  
00207     int pointslen;  
00208     int pcount;     
00209     int normalslen;
00210 } edgebreaker_header;
00211 
00212 
00213 #define MTABLE_HAS_LENGTHS                  0x1
00214 #define MTABLE_HAS_M2STACKOFFSETS           0x2
00215 #define MTABLE_HAS_M2GATEOFFSETS            0x4
00216 #define MTABLE_HAS_DUMMIES                  0x8
00217 #define MTABLE_HAS_PATCHES                  0x10
00218 #define MTABLE_HAS_BOUNDING                 0x20
00219 #define MTABLE_HAS_QUANTIZATION             0x40
00220 #define MTABLE_HAS_QUANTIZATION_NORMALS     0x80
00221 
00222 typedef struct {
00223     int flags;
00224     
00225     int *mlengths;
00226     int mlengths_used;
00227     int mlengths_allocated;
00228     
00229     int *m2stackoffsets;
00230     int m2stackoffsets_used;
00231     int m2stackoffsets_allocated;
00232     
00233     int *m2gateoffsets;
00234     int m2gateoffsets_used;
00235     int m2gateoffsets_allocated;
00236     
00237     int *dummies;
00238     int dummies_used;
00239     int dummies_allocated;
00240     
00241     int *patches;
00242     int patches_used;
00243     int patches_allocated;
00244     
00245     ET_Bounding *bounding;
00246     
00247     int x_quantization;
00248     int y_quantization;
00249     int z_quantization;
00250     
00251     int x_quantization_normals;
00252     int y_quantization_normals;
00253     int z_quantization_normals;
00254 } mtable_info;
00255 
00256 
00257 
00258 typedef struct HALF_EDGE_TAG {
00259     int start;
00260     int twin;
00261 } half_edge;
00262 
00263 
00264 typedef struct {
00265     half_edge *edges;
00266     int allocated;
00267     int used;
00268     int *visitations;  
00269     
00270     int visitations_used;
00271 } half_edge_array;
00272 
00273 typedef struct {
00274     int *data;
00275     int allocated;
00276     int used;
00277 } int_stack;
00278 
00279 typedef struct ACTION_TABLE_TAG {
00280     ET_Malloc_Action malloc_action;
00281     ET_Free_Action free_action;
00282     ET_New_Vertex_Action new_vertex_action;
00283     void *user_data;
00284 } ET_Action_Table;
00285 #define EA_FREE(ptr) (actions->free_action(ptr,actions->user_data))
00286 #define EA_MALLOC(size) (actions->malloc_action(size,actions->user_data))
00287 
00288 typedef struct {
00289     unsigned int *data; 
00290     unsigned int *rdata;
00291     int allocated;      
00292     int used;           
00293     int bit;            
00294     int rused;          
00295     int rbit;           
00296     int can_reallocate; 
00297     int status;         
00298     
00299     unsigned int mask[33]; 
00300     
00301     unsigned int range[33]; 
00302 } varstream;
00303 
00304 
00305 typedef struct {
00306     int *loops;          
00307     int *loops_edges;    
00308     int loops_used;      
00309     int loops_edges_allocated; 
00310 
00311     int np_allocated;
00312     int *P;              
00313     int *N;              
00314 } loop_table;
00315 
00316 
00317 
00318 typedef short INT16;
00319 typedef int INT32;
00320 
00321     
00322 #define CASE_C 0
00323 #define CASE_L 1
00324 #define CASE_E 2
00325 #define CASE_R 3
00326 #define CASE_S 4
00327 #define CASE_M 5
00328 #define CASE_M2 6
00329 
00330 #define TONEXT4(i) (3 - (((i)-1)%4))
00331 
00332 #define MAXVAL(bits) ((1<<(bits))-1)
00333 
00334 #define BIG_FLOAT (1e20f)
00335 #define DEFAULT_QUANTIZATION (11)
00336 #define DEFAULT_POINT_FACTOR (1.5f)
00337 #define DEFAULT_HINTS (0)
00338 
00339 #define POINTSIZE 12 
00340 
00341 #define GARBAGE_VERTEX  ((int)0x80808080)
00342 #define DUMMY_VERTEX    ((int)0x80000003)
00343 #define GARBAGE ((int)0x80808080)           
00344 #define VERTEX_SPECIAL(x) ((unsigned int)(x) & 0x80000000)
00345 #define INVALIDATE_VERTEX(x) ((x) |= 0x80000000) 
00346 #define EA_VERTEX_INDEX(x) ((x) & ~0x80000000)
00347 #define PROXY_VERTEX_INDEX(proxy_hash,v) (VERTEX_SPECIAL(v)?lookup_vertex((proxy_hash),(v)):v)
00348 
00349 #define GARBAGE_EDGE ((int)0x80808080)
00350 #define MULTIPLE_EDGE ((int)0x80000001)
00351 #define EDGE_SPECIAL(x) ((unsigned int)(x) & 0x80000000)
00352 #define EDGE_INVALID(x) ((unsigned int)(x) & 0x80000000)
00353 #define INVALIDATE_EDGE(x) ((x) |= 0x80000000) 
00354 #define REAL_EDGE_INDEX(x) ((x) & ~0x80000000)
00355 
00356 
00357 #define I2V(x) ((void *)(POINTER_SIZED_INT)(x))
00358 #define V2I(x) ((int)(POINTER_SIZED_INT)(void *)(x))
00359 
00360 
00361 
00362 
00363 #define HALF_EDGE_INIT(h) ((h)->start=(h)->twin=GARBAGE_EDGE)
00364 
00365 
00366 #define HNEXT(i) (3*((i)/3) + ((i)+1)%3)
00367 #define HPREV(i) (3*((i)/3) + ((i)+2)%3)
00368 
00369 
00370     
00371 extern void mtable_info_init( mtable_info *m );
00372 extern void mtable_info_free( mtable_info *m );
00373 extern int lookup_vertex(const struct vhash_s *proxy_hash, int v);
00374 extern void predict( 
00375     half_edge_array const *ea, 
00376     int ei,                     
00377     int third_vertex_unknown,   
00378     char const *touched,
00379     struct vhash_s const *proxy_hash,
00380     int const *quantized_points,
00381     int *prediction_out );
00382 extern int old_predict( 
00383     int const *associations, 
00384     int const *points, 
00385     ET_Bounding const *bounding, 
00386     int x_quantization,
00387     int y_quantization,
00388     int z_quantization,
00389     int *out );
00390 extern int old_pack_points( 
00391     mtable_info *mtable, int *associations, edgebreaker_header *hptr,
00392     int original_pointcount, int const *pointmap, float const *points, 
00393     int buffsize, void *buffer_out, 
00394     eb_compress_configs const *configs );
00395 extern int old_unpack_points( 
00396     int const *associations, 
00397     edgebreaker_header const *hptr,
00398     void const *diffs_in, 
00399     float *points_out, 
00400     ET_Bounding const *bounding, 
00401     int x_quantization, int y_quantization, int z_quantization );
00402 extern int old_unpack_normals( 
00403     int const *associations, 
00404     edgebreaker_header const *hptr,
00405     void const *diffs_in, 
00406     float *normals_out, 
00407     int x_quantization_normals, int y_quantization_normals, int z_quantization_normals );
00408 extern int int_stack_init( int_stack *s );
00409 extern int int_stack_expand( int_stack *s );
00410 extern void int_stack_free( int_stack *s );
00411 extern int int_stack_pop( int_stack *s );
00412 extern int int_stack_pop_internal( int_stack *s, int offset, int *out );
00413 extern void int_stack_push( int_stack *s, int n );
00414 extern void int_stack_push_if_unique( int_stack *s, int n );
00415 extern int validate_associations( 
00416         int const *associations, 
00417         int pointcount );
00418 extern int half_edge_array_init( half_edge_array *ea, int initial_size );
00419 extern void half_edge_array_free( half_edge_array *ea );
00420 extern int half_edge_array_expand( half_edge_array *ea );
00421 extern int half_edge_array_append( half_edge_array *ea, half_edge **out );
00422 extern int validate_edge ( half_edge_array const *ea, half_edge const *a, loop_table const *loops );
00423 extern void *default_malloc( size_t size, void *user_data );
00424 extern void default_free( void *ptr, void *user_data );
00425 extern void default_new_vertex( int a, int b, int c, void *user_data );
00426 extern void vsinit_write( varstream *vs, int size, void *pointer );
00427 
00428 extern void vsinit_read( varstream *vs, int size, void *pointer );
00429 extern void vsfree( varstream *vs );
00430 extern void vsswap( varstream *vs );
00431 extern void vsput( varstream *vs, const int *numbits_array, int val );
00432 extern int vsget( varstream *vs, const int *numbits_array );
00433 
00434 
00435 
00436 extern ET_Action_Table *actions;
00437 extern int g_hints;
00438 
00439 #endif 
00440 #endif 
00441 
00442 

Generated on Tue Jan 6 22:41:34 2009 for Autodesk DWF 3D Toolkit by  doxygen 1.4.5