lod.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1998 by Tech Soft America, LLC.
00003  * The information contained herein is confidential and proprietary to
00004  * Tech Soft America, LLC., and considered a trade secret as defined under
00005  * civil and criminal statutes.  Tech Soft America 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 America, LLC. is granted only under a
00009  * written non-disclosure agreement, expressly prescribing the scope and
00010  * manner of such use.
00011  *
00012  * $Id: //DWF/Working_Area/Willie.Zhu/w3dtk/hoops/lod.h#1 $
00013  */
00014 
00015 /*
00016  * This file consolidated from the separate files we had before.
00017  */
00018 
00019 
00020 /************************************************************************
00021 
00022   MxMain.h
00023 
00024   This file contains the structures and function prototypes needed for 
00025   communication with the outside world.  In converting between HOOPS and
00026   non-hoops versions of the LOD module, this is the only file that should
00027   need changes (for non-HOOPS representations of 3d models, MxMain.c may
00028   also need some changes).
00029 
00030   Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
00031   
00032  ************************************************************************/
00033 
00034 
00035 #ifndef MXMAIN_INCLUDED 
00036 #define MXMAIN_INCLUDED
00037 
00041 
00042 #ifdef MX_DEBUG
00043 #include <assert.h>
00044 #define MX_ASSERT(x) assert(x)
00045 #else
00046 #define MX_ASSERT(x) do if (x) {} while (0)
00047 #endif
00048 
00049 #include <stdlib.h>
00050 #include <string.h>
00051 
00052 #include "hoops_tools.h"
00053 
00054 /* some wrappers to use around memory allocation and freeing */
00055 #define MX_ALLOC(size) malloc (size)
00056 #define MX_FREE(ptr,size) free (ptr)
00057 #define MX_COPY(src,size,dest) (memcpy ((dest), (src),(size)))
00058 #define MX_REALLOC(ptr,oldsize,newsize)         \
00059 {                                               \
00060     /* brute force. reallocate from scratch */  \
00061     void *tmp = (ptr);                          \
00062     ((void *)ptr) = MX_ALLOC((newsize));        \
00063     MX_COPY((ptr),  tmp, (oldsize));            \
00064     MX_FREE(tmp, (oldsize));                    \
00065 }
00066 #define ALLOC_ARRAY(p,c,t) p = (t *) MX_ALLOC (c * sizeof (t))
00067 
00068 #define local static
00069 #define null 0
00070 #define until(x) while(!(x))
00071 //#define POINTER_SIZED_INT   long    /* fix for 64 bit */
00072 #ifdef _WIN64
00073 #   define POINTER_SIZED_INT __int64
00074 #else
00075 #   define POINTER_SIZED_INT long
00076 #endif
00077 
00078 /*
00079  * LOD-specific error codes
00080  */
00081 #define HEC_LOD_MODULE                  111 /* must match hpserror.h */
00082 #define ERR_INSUFFICIENT_MEMORY           1
00083 
00084 #define MX_ERROR(code,explanation)  /*  \
00085     (HI_Error( HEC_LOD_MODULE, code, explanation ) ) */
00086 
00087 
00088 #define MX_USE_DEFAULT          -1
00089 
00090 /* for placement policy */
00091 #define MX_PLACE_ENDPOINTS  0
00092 #define MX_PLACE_ENDORMID   1 
00093 #define MX_PLACE_LINE       2
00094 #define MX_PLACE_OPTIMAL    3
00095 #define MX_PLACE_OPTIMAL_BB 4
00096 
00097 /* for weighting policy */
00098 #define MX_WEIGHT_UNIFORM       0
00099 #define MX_WEIGHT_AREA          1
00100 #define MX_WEIGHT_ANGLE         2
00101 #define MX_WEIGHT_AVERAGE       3
00102 #define MX_WEIGHT_AREA_UNSCALED 4
00103 #define MX_WEIGHT_RAWNORMALS    5
00104 
00105 /* for target units */
00106 #define MX_PERCENT      1
00107 #define MX_LEVEL        2
00108 
00109 /* a "-1" in any of these fields indicates that the default should be used */
00110 typedef struct MxConfig_TAG
00111 {
00112     int     placement_policy;
00113     int     weighting_policy;
00114     float   boundary_weight;
00115     float   compactness_ratio;
00116     float   meshing_penalty;
00117     int     will_join_only;
00118     float   ratio;
00119     int     max_degree;
00120 
00121 } MxConfig;
00122 
00123 typedef struct MxShell_TAG {
00124     float  *points;
00125     int    pcount;
00126     int    *faces; /* hoops HC_Insert_Shell() format, but w/o the negative faces */
00127     int    flen; 
00128 } MxShell;
00129 
00130 typedef struct MxShellChain_TAG {
00131     MxShell         sh;
00132     int             pointmap_count;
00133     int             *pointmap;
00134     struct MxShellChain_TAG *next;
00135 } MxShellChain;
00136 
00137 
00138 /*
00139  *  LOD module entry points
00140  */
00141 
00142 #ifdef __cplusplus
00143 extern "C" {
00144 #endif
00145 #ifdef __HP_aCC
00146 extern "C" {
00147 #endif
00148 
00149 /* needed by Compute_Optimized_Shell */
00150 extern void HU_LOD_Execute(
00151     int plist_len, const float *plist,
00152     int flist_len, const int *flist, 
00153     MxConfig *cfg_ptr,                  /* pass NULL for all default values */
00154     int *plist_len_out, float *plist_out, 
00155     int *flist_len_out, int *flist_out, 
00156     int *pmap, int *fmap     
00157 );
00158 
00159 
00160 /* needed by Std_Draw_3d_Polyhedron */
00161 extern MxShellChain *HU_Compute_LOD_Fast(
00162     int pcount,
00163     const float *points,
00164     int flen, 
00165     const int *faces,
00166     float ratio,
00167     int depth 
00168 );
00169 
00170 extern MxShellChain *HU_LOD_Chain_Execute(
00171         int point_count, const float *points, int flistlen, int *flist,
00172                 float ratio, int depth );
00173 
00174 
00175 
00176 extern int  HU_Triangulate_Face (
00177     float const *points,
00178     float const *normal,
00179     int const   *face_list,
00180     int const   *face_list_end,
00181     void        ( * triangle_action)
00182                     (void * info, int convex_triangulation, int v1, int v2, int v3),
00183     void        *action_info);
00184 
00185 
00186 #ifdef __cplusplus
00187 }
00188 #endif
00189 #ifdef __HP_aCC
00190 }
00191 #endif
00192 
00193 #endif
00194 
00195 
00196 
00197 
00198 
00199 /************************************************************************
00200 
00201   Standard math include file for the MixKit library.
00202   Also, type definitions for various vectors and matrices
00203 
00204   Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
00205   
00206  ************************************************************************/
00207 
00208 #ifndef MXMATH_INCLUDED
00209 #define MXMATH_INCLUDED
00210 
00211 #include <math.h>
00212 
00213 
00214 typedef struct Vec4_TAG
00215 {
00216     double elt[4];
00217 } Vec4;
00218 
00219 typedef struct Vec3_TAG
00220 {
00221     double elt[3];
00222 } Vec3;
00223 
00224 typedef struct Vec2_TAG
00225 {
00226     double elt[2];
00227 } Vec2;
00228 
00229 typedef struct Mat4_TAG
00230 {
00231     Vec4 row[4];
00232 } Mat4;
00233 
00234 typedef struct Mat3_TAG
00235 {
00236     Vec3 row[3];
00237 } Mat3;
00238 
00239 typedef struct Mat2_TAG
00240 {
00241     Vec2 row[2];
00242 } Mat2;
00243 
00244 typedef int MxBool;
00245 
00246 
00247 /* some operations specific to 3x3 matrices */
00248 extern double invert33( Mat3 *, const Mat3 * );
00249 extern void col33( Vec3 *v_out, const Mat3 *m1, int i );
00250 extern void vecmul33( Vec3 *v_out, const Mat3 *m1, const Vec3 *v1);
00251 
00252 /* some operations specific to 4x4 matrices */
00253 extern void adjoint44( Mat4 *out, const Mat4 *in );
00254 extern void matmul44( Mat4 *out, const Mat4 *m1, const Mat4 *m2 );
00255 extern void vecmul44( Vec4 *, const Mat4 * m1, const Vec4 * v);
00256 
00257 
00258 /* variable length vector operations */
00259 
00260 extern void   mxv_add( double *r, const double *u, const double *v, int dim );
00261 extern void   mxv_sub( double *r, const double *u, const double *v, int dim );
00262 extern void   mxv_mul( double *r, const double *u, const double d, int dim );
00263 extern void   mxv_div( double *r, const double *u, const double d, int dim );
00264 extern void   mxv_neg ( double *r, const double *u, int dim);
00265 extern void   mxv_set ( double *r, const double d, int dim);
00266 extern void   mxv_setv ( double *r, const double *u, int dim);
00267 extern double  mxv_dot(const double *u, const double *v, int dim);
00268 extern void   mxv_cross(double *r, const double *u, const double *v, int dim);
00269 extern double  mxv_len(const double *v, int dim);
00270 extern double  mxv_len2(const double *v, int dim); 
00271 extern int  mxv_unitize(double *v, int dim);
00272 extern MxBool mxv_exact_equal(const double *u, const double *v, int dim);
00273 extern MxBool mxv_equal(const double *u, const double *v, int dim);
00274 extern void   mxv_basis(double *r, int b, int dim);
00275 
00276 
00277 
00278 /* test for "not a number" (assumes type double coming in) */
00279 #define isNaN(x) (!((x)==(volatile double)(x)))
00280 
00281 /*
00282  * constants and definitions for cross-platform
00283  */
00284 
00285 /* Some systems use HUGE_VAL instead of HUGE*/
00286 #if !defined(HUGE) && defined(HUGE_VAL)
00287 #define HUGE HUGE_VAL
00288 #endif
00289 
00290 /* Handle platforms, such as Win32, which don't define M_PI in <math.h>*/
00291 #ifndef M_PI
00292 #define M_PI 3.141592653589793238462643383279502884197169399375105820974944592308
00293 #endif
00294 
00295 /* inline bool FEQ(double a,double b,double eps) { return fabs(a-b)<eps; } */
00296 #define MxFEQ(a,b,eps) ((fabs((a)-(b))<(eps)))
00297 
00298 #ifndef MIX_NO_AXIS_NAMES
00299 enum Axis {X=0, Y=1, Z=2, W=3};
00300 #endif
00301 
00302 
00303 /* from the old mxgeom3d.h */
00304 extern double triangle_area(const Vec3 *, const Vec3 *, const Vec3 * );
00305 extern void  triangle_raw_normal( Vec3 *, const Vec3 *, const Vec3 *, const Vec3 * );
00306 extern int  triangle_normal( Vec3 *, const Vec3 *, const Vec3 *, const Vec3 * );
00307 extern int  triangle_plane( Vec4 *, const Vec3 *, const Vec3 *, const Vec3 * );
00308 extern void  triangle_raw_plane( Vec4 *, const Vec3 *, const Vec3 *, const Vec3 * );
00309 extern double triangle_compactness( const Vec3 *, const Vec3 *, const Vec3 * );
00310 extern void  mx3d_box_corners( Vec3 [], const Vec3 *, const Vec3 * );
00311 
00312 
00313 
00314 /* MXMATH_INCLUDED*/
00315 #endif
00316 
00317 
00318 
00319 
00320 
00321 /************************************************************************
00322 
00323   MxType.h
00324 
00325   This file contains most of the data types needed by the LOD module:
00326   Block, Heap
00327   Vertex, Face, Edge
00328   VertexList, FaceList, EdgeList
00329 
00330   Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
00331   
00332  ************************************************************************/
00333 
00334 #ifndef MXTYPE_INCLUDED 
00335 #define MXTYPE_INCLUDED
00336 
00337 #include <stdlib.h>
00338 
00339 /* 
00340  * blocks are arrays that automatically resize
00341  */
00342 typedef struct Block_TAG
00343 {
00344     int allocated;
00345     int used;
00346     int size_each;
00347     void *data;
00348 
00349 } Block;
00350 
00351 
00352 /*
00353  * function declarations for manipulating blocks
00354  */
00355 extern void block_init    ( Block *, int size_each_in );
00356 extern void block_cleanup ( Block * );
00357 extern void resetb  ( Block * );
00358 extern int  addb    ( Block *, const void *elem );
00359 extern int  addpb   ( Block *, const void *elem );
00360 extern void clobberb( Block *, const void *elem, int i );
00361 extern void swapb   ( Block *, int i, int j );
00362 extern void removeb ( Block *, int which );
00363 extern void resizeb ( Block *, int size_in );
00364 extern void chopb   ( Block * );
00365 extern int  isvalidb( const Block *, int which );
00366 
00367 #define lengthb(b) ((b)->used)
00368 #define getb(b,i)  ( (char *)(b)->data + ((i) * (b)->size_each) )
00369 #define getpb(b,i) ( *( (void **) getb ( (b), (i) ) ) )
00370 
00371 
00372 /* heap nodes */
00373 typedef struct MxHeapable_TAG
00374 {
00375     double import;  /* priority */
00376     int token;      /* place in heap */
00377     void *payload;  /* data */
00378 
00379 } MxHeapable;
00380 
00381 /*
00382  * functions for manipulating mxheapables
00383  */
00384 /* inline bool is_in_heap( MxHeapable *h ) { return h->token != -47; } */
00385 /* inline void not_in_heap( MxHeapable *h ) { h->token = -47; } */
00386 /* inline int get_heap_pos( MxHeapable *h ) { return h->token; } */
00387 /* inline void set_heap_pos( MxHeapable *h, int t ) { h->token=t; } */
00388 /* inline void  set_heap_key( MxHeapable *h, double k ) { h->import=k; } */
00389 /* inline double get_heap_key( const MxHeapable *h ) { return h->import; } */
00390 /* inline void mxheapable_init( MxHeapable *h ) { h->import = 0.0f; h->token = -47; h->payload = NULL; } */
00391 
00392 #define is_in_heap(h) ( (h)->token != -47 )
00393 #define not_in_heap(h) ( (h)->token = -47 )
00394 #define get_heap_pos(h) ( (h)->token )
00395 #define set_heap_pos(h,t) ( (h)->token = t )
00396 #define set_heap_key(h,k) ( (h)->import = k )
00397 #define get_heap_key(h) ( (h)->import )
00398 #define mxheapable_init(h) { (h)->import = 0.0f; (h)->token = -47; (h)->payload = NULL; }
00399 
00400 
00401 
00402 /* the heap */
00403 typedef struct MxHeap_TAG
00404 {
00405     Block data; /* a dynamically growable array of heapables. */
00406 
00407 } MxHeap;
00408 
00409 
00410 extern void mxheap_init   ( MxHeap * );
00411 extern void mxheap_cleanup( MxHeap * ) ; 
00412 extern void inserth       ( MxHeap *, MxHeapable * );
00413 extern void updateh       ( MxHeap *, MxHeapable * );
00414 extern void *extracth     ( MxHeap * );
00415 extern void removeh       ( MxHeap *, MxHeapable * );
00416 extern void *itemh        ( MxHeap *, int );
00417 
00418 /* inline int sizeh( MxHeap *m )  { return lengthb( &(m->data) ); } */
00419 #define sizeh(m) ( lengthb( &((m)->data) ) )
00420 
00421 
00422 
00423 
00424 typedef int MxVertexID;
00425 typedef int MxFaceID;
00426 
00427 
00428 /* 
00429  *  Type declarations for MxVertex, MxProxy, MxFace, MxEdge
00430  *  and associated helper functions
00431  */
00432 
00433 typedef Vec3 MxVertex;
00434 
00435 /* needed for storing multiple vertices with different attributes */
00436 typedef struct MxProxy_TAG
00437 {
00438     MxVertexID prev, next; 
00439 
00440 } MxProxy;
00441 
00442 typedef struct MxEdge_TAG
00443 {
00444     MxVertexID v1, v2;
00445 
00446 } MxEdge ;
00447 
00448 typedef struct MxFace_TAG
00449 {
00450     MxVertexID v[3];
00451 
00452 } MxFace;
00453 
00454 
00455 /* inline MxVertexID opposite_vertex( MxEdge *e, MxVertexID v )
00456 {
00457     if( v == e->v1 ) return e->v2;
00458     else { return e->v1; }
00459 }*/
00460 #define opposite_vertex(e,v) (((v)==(e)->v1)?(e)->v2:(e)->v1)
00461 
00462 
00463 extern void       mxface_init( MxFace *, MxVertexID, MxVertexID, MxVertexID );
00464 extern int        face_find_vertex( const MxFace *, MxVertexID );
00465 extern MxVertexID face_opposite_vertex( const MxFace *, MxVertexID, MxVertexID );
00466 extern MxBool     face_is_inorder( const MxFace *, MxVertexID, MxVertexID );
00467 extern int        face_remap_vertex( MxFace *, MxVertexID, MxVertexID );
00468 
00469 
00470 
00471 /* 
00472  *  Type declarations for MxColor, MxNormal, and MxTexcoord 
00473  *  (all are optionally included in MxModel )
00474  *  and associated helper functions
00475  */
00476 
00477 typedef struct MxColor_TAG
00478 {
00479     unsigned char r, g, b, a;
00480     unsigned int word;
00481 
00482 } MxColor;
00483 
00484 typedef struct MxNormal_TAG
00485 {
00486     double dir[3];
00487 
00488 } MxNormal;
00489 
00490 typedef struct MxTexCoord_TAG
00491 {
00492     double u[2];
00493 
00494 } MxTexCoord;
00495 
00496 
00497 #define ftop(x) ( (unsigned char)(((x)>1.0f?1.0f:(x))*255.0f) )
00498 #define ptof(x) ( (x) / 255.0f )
00499 
00500 extern void mxcolor_init( MxColor *, double, double, double  );
00501 extern void mxtexcoord_init( MxTexCoord *, double, double );
00502 extern void mxnormal_init( MxNormal *, double, double, double );
00503 
00504 /*
00505  * Vertex, Face, and Edge lists, plus associated utility functions 
00506  */
00507 
00508 typedef Block MxFaceList;      /* holds type MxFaceID */
00509 typedef Block MxVertexList;    /* holds type MxVertexID */
00510 
00511 /* inline MxFaceID fl_get_face( MxFaceList *fl, int i ){return *((MxFaceID *) getb( fl, i ));} */
00512 /* inline MxVertexID vl_get_vertex( MxVertexList *vl, int i ){  return *((MxVertexID *) getb( vl, i ));} */
00513 #define fl_get_face(fl,i) ( *( (MxFaceID *) getb( fl, i ) ) )
00514 #define vl_get_vertex(vl,i) ( *( (MxVertexID *) getb( vl, i ) ) )
00515 
00516 extern MxBool fl_find_face( MxFaceList *fl, MxFaceID fid, int *index );
00517 extern MxBool vl_find_vertex( MxVertexList *vl, MxFaceID vid, int *index );
00518                         
00519 #endif
00520 
00521 
00522 
00523 
00524 
00525 /************************************************************************
00526 
00527   MxModel
00528 
00529   Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
00530   
00531  ************************************************************************/
00532 
00533 #ifndef MXSTDMODEL_INCLUDED 
00534 #define MXSTDMODEL_INCLUDED
00535 
00536 
00537 /* 
00538  * some useful definitions for the model type 
00539  */
00540 #define MX_UNBOUND 0x0
00541 #define MX_PERFACE 0x1
00542 #define MX_PERVERTEX 0x2
00543 #define MX_MAX_BINDING 0x2
00544 
00545 #define MX_NORMAL_MASK   0x3
00546 #define MX_COLOR_MASK    (0x3<<2)
00547 #define MX_TEXTURE_MASK  (0x3<<4)
00548 #define MX_ALL_MASK      (MX_NORMAL_MASK|MX_COLOR_MASK|MX_TEXTURE_MASK)
00549 
00550 
00551 
00552 
00553 typedef struct vertex_data_TAG  
00554 {
00555     unsigned char mark, tag;             /* Internal tag bits*/
00556     unsigned char user_mark, user_tag;   /* External tag bits*/
00557 
00558 } vertex_data;
00559 
00560 
00561 typedef struct face_data_TAG  
00562 {
00563     unsigned char mark, tag;             /* Internal tag bits*/
00564     unsigned char user_mark, user_tag;   /* External tag bits*/
00565 
00566 } face_data;
00567 
00568 
00569 typedef struct MxPairContraction_TAG
00570 {
00571     MxVertexID v1, v2;
00572     double dv1[3], dv2[3];  /* dv2 is not really necessary*/
00573 
00574     Block delta_faces; /* holds type int */
00575     Block dead_faces; /* holds type int */
00576 
00577 } MxPairContraction;
00578 
00579 extern void mxpaircontraction_init( MxPairContraction *mpc );
00580 extern void mxpaircontraction_cleanup( MxPairContraction *mpc );
00581 
00582 /* inline int get_delta_faces( MxPairContraction *mpc, int i ) { return *((int *) getb (&(mpc->delta_faces), i ) ); } */
00583 /* inline int get_dead_faces( MxPairContraction *mpc, int i ) { return *((int *) getb (&(mpc->dead_faces), i ) ); } */
00584 #define get_delta_faces(mpc,i) ( *((int *) getb (&((mpc)->delta_faces), (i) ) ) )
00585 #define get_dead_faces(mpc,i) ( *((int *) getb (&((mpc)->dead_faces), (i) ) ) )
00586 
00587 
00588 typedef MxPairContraction MxPairExpansion;
00589 
00590 /* Masks for internal tag bits*/
00591 #define MX_VALID_FLAG 0x01
00592 #define MX_PROXY_FLAG 0x02
00593 #define MX_TOUCHED_FLAG 0x04
00594 
00595 typedef struct MxModel_TAG
00596 {
00597     unsigned char cbinding, nbinding, tbinding;
00598     unsigned int flags;
00599     
00600     /* all mapping lists hold type int */
00601     Block face_map1;    /* maps original polygons to this model's original triangles */
00602     Block face_map2;    /* maps this model's original triangles to output triangles */
00603     Block vertex_map;   /* maps original vertices to output vertices */
00604 
00605     /* Required blocks*/
00606     Block vertices;     /* stores type MxVertex */
00607     Block faces;        /* stores type MxFace */
00608     /* Optional blocks*/
00609     Block *normals;     /* stores type MxNormal */
00610     Block *colors;      /* stores type MxColor */
00611     Block *tcoords;     /* stores type MxTexCoord */
00612 
00613     int binding_mask;
00614     Block v_data; /* holds type vertex_data */
00615     Block f_data; /* holds type face_data */
00616     Block face_links;
00617 
00618 } MxModel;
00619 
00620 extern void mxmodel_init( MxModel *m, int nvert, int nface);
00621 extern void mxmodel_cleanup( MxModel *m );
00622 
00623 
00624 /*
00625  * Simple access routines
00626  */
00627 /* inline MxVertex *model_vertex( MxModel *m, int i ) { return (MxVertex *) getb ( &(m->vertices), i ); } */
00628 /* inline MxFace *model_face( MxModel *m, int i ) { return (MxFace *) getb ( &(m->faces), i ); } */
00629 /* inline MxVertex *model_corner( MxModel *m, MxFaceID f, short i) { return model_vertex( m, model_face(m, f)->v[i]); } */
00630 /* inline MxNormal *model_normal( MxModel *m, int i ) { return (MxNormal *) getb ( m->normals, i ); } */
00631 /* inline MxColor *model_color( MxModel *m, int i ) { return (MxColor *) getb ( m->colors, i ); } */
00632 /* inline MxTexCoord *model_texcoord( MxModel *m, int i ) { return (MxTexCoord *) getb ( m->tcoords, i ); } */
00633 /* inline int model_vertex_count(MxModel *m) { return lengthb( &(m->vertices) ); } */
00634 /* inline int model_face_count(MxModel *m) { return lengthb( &(m->faces) ); } */
00635 #define model_vertex(m,i)   ( (MxVertex *) getb ( &((m)->vertices), (i) ) )
00636 #define model_face(m,i)     ( (MxFace *) getb ( &((m)->faces), (i) ) ) 
00637 #define model_corner(m,f,i) ( model_vertex( (m), model_face((m), (f))->v[(i)]) )
00638 #define model_normal(m,i)   ( (MxNormal *) getb ( (m)->normals, (i) ) )
00639 #define model_color(m,i)    ( (MxColor *) getb ( m->colors, i ) )
00640 #define model_texcoord(m,i) ( (MxTexCoord *) getb ( m->tcoords, i ) )
00641 #define model_vertex_count(m) ( lengthb( &((m)->vertices) ) )
00642 #define model_face_count(m) ( lengthb( &((m)->faces) ) )
00643 #define model_vertex_map_entry(m,i)  ( (POINTER_SIZED_INT) getpb ( &((m)->vertex_map), (i) ) )
00644 extern int model_valid_face_count( MxModel *m );
00645 extern int model_valid_vertex_count( MxModel *m );
00646 
00647 
00648 /* 
00649  * Accessors for internal tag and mark bits 
00650  */
00651 /* inline vertex_data *get_v_data( MxModel *m, int i ) { return (vertex_data *) getb ( &(m->v_data), i ); }; */
00652 /* inline int v_check_tag( MxModel *m, MxVertexID i, int tag ) { return get_v_data( m,i )->tag & tag; } */
00653 /* inline void v_set_tag( MxModel *m, MxVertexID i, int tag ) { get_v_data( m, i )->tag |= tag; } */
00654 /* inline void v_unset_tag( MxModel *m, MxVertexID i, int tag ) { get_v_data( m, i )->tag &= ~tag; } */
00655 /* inline unsigned char get_vmark( MxModel *m, MxVertexID i )  { return get_v_data( m, i )->mark; } */
00656 /* inline void vmarkc( MxModel *m, MxVertexID i, unsigned char c ) { get_v_data( m, i )->mark = c; } */
00657 #define get_v_data(m,i)    ( (vertex_data *) getb ( &((m)->v_data), (i) ) )
00658 #define v_check_tag(m,i,t) ( get_v_data( (m), (i) )->tag & (t) )
00659 #define v_set_tag(m,i,t)   ( get_v_data( (m), (i) )->tag |= (t) )
00660 #define v_unset_tag(m,i,t) ( get_v_data( (m), (i) )->tag &= ~(t) )
00661 #define get_vmark(m,i)     ( get_v_data( (m), (i) )->mark )
00662 #define vmarkc(m,i,c)      ( get_v_data( (m), (i) )->mark = (c) )
00663 
00664 /* inline face_data *get_f_data( MxModel *m, int i ) { return (face_data *) getb ( &(m->f_data), i ); }; */
00665 /* inline int f_check_tag( MxModel *m, MxFaceID i, int tag )  { return get_f_data( m, i )->tag & tag; } */
00666 /* inline void f_set_tag( MxModel *m, MxFaceID i, int tag ) { get_f_data( m, i )->tag |= tag; } */
00667 /* inline void f_unset_tag( MxModel *m, MxFaceID i, int tag ) { get_f_data( m, i )->tag &= ~tag; } */
00668 /* inline unsigned char get_fmark( MxModel *m, MxFaceID i )  { return get_f_data( m, i )->mark; } */
00669 /* inline void fmark( MxModel *m, MxFaceID i, unsigned char c ) { get_f_data( m, i )->mark = c; } */
00670 #define get_f_data(m,i)    ( (face_data *) getb ( &((m)->f_data), (i) ) )
00671 #define f_check_tag(m,i,t) ( get_f_data( (m), (i) )->tag & (t) )
00672 #define f_set_tag(m,i,t)   ( get_f_data( (m), (i) )->tag |= (t) )
00673 #define f_unset_tag(m,i,t) ( get_f_data( (m), (i) )->tag &= ~(t) )
00674 #define get_fmark(m,i)     ( get_f_data( (m), (i) )->mark )
00675 #define fmark(m,i,c)       ( get_f_data( (m), (i) )->mark = (c) )
00676 
00677 
00678 /* 
00679  * exported access for tagging and marking 
00680  */
00681 /* inline int vertex_is_valid( MxModel *m, MxVertexID i ) { return v_check_tag(m,i,MX_VALID_FLAG); } */
00682 /* inline void vertex_mark_valid( MxModel *m, MxVertexID i ) { v_set_tag(m,i,MX_VALID_FLAG); } */
00683 /* inline void vertex_mark_invalid( MxModel *m, MxVertexID i ) { v_unset_tag(m,i,MX_VALID_FLAG); } */
00684 /* inline int face_is_valid( MxModel *m, MxFaceID i )  { return f_check_tag(m,i,MX_VALID_FLAG);} */
00685 /* inline void face_mark_valid( MxModel *m, MxFaceID i ) { f_set_tag(m,i,MX_VALID_FLAG); } */
00686 /* inline void face_mark_invalid( MxModel *m, MxFaceID i ) { f_unset_tag(m,i,MX_VALID_FLAG); } */
00687 #define vertex_is_valid(m,i)     ( v_check_tag((m),(i),MX_VALID_FLAG) )
00688 #define vertex_mark_valid(m,i)   ( v_set_tag((m),(i),MX_VALID_FLAG) )
00689 #define vertex_mark_invalid(m,i) ( v_unset_tag((m),(i),MX_VALID_FLAG) )
00690 #define face_is_valid(m,i)       ( f_check_tag((m),(i),MX_VALID_FLAG) )
00691 #define face_mark_valid(m,i)     ( f_set_tag((m),(i),MX_VALID_FLAG) )
00692 #define face_mark_invalid(m,i)   ( f_unset_tag((m),(i),MX_VALID_FLAG) )
00693 
00694 /* 
00695  * Accessors for external tag and mark bits 
00696  */
00697 /* inline int vertex_check_tag( MxModel *m, MxVertexID i, int tag ) { return get_v_data( m, i )->user_tag & tag; } */
00698 /* inline void vertex_set_tag( MxModel *m, MxVertexID i, int tag ) { get_v_data( m, i )->user_tag |= tag; } */
00699 /* inline void vertex_unset_tag( MxModel *m, MxVertexID i, int tag ) { get_v_data( m, i )->user_tag &= ~tag;} */
00700 /* inline unsigned char get_vertex_mark( MxModel *m, MxVertexID i ) { return get_v_data( m, i )->user_mark; } */
00701 /* inline void vertex_mark( MxModel *m, MxVertexID i, unsigned char c ) { get_v_data( m, i )->user_mark=c; } */
00702 #define vertex_check_tag(m,i,t) ( get_v_data( (m), (i) )->user_tag & (t) )
00703 #define vertex_set_tag(m,i,t)   ( get_v_data( (m), (i) )->user_tag |= (t) )
00704 #define vertex_unset_tag(m,i,t) ( get_v_data( (m), (i) )->user_tag &= ~(t) )
00705 #define get_vertex_mark(m,i)    ( get_v_data( (m), (i) )->user_mark )
00706 #define vertex_mark(m,i,c )     ( get_v_data( (m), (i) )->user_mark=(c) )
00707 
00708 /* inline int face_check_tag( MxModel *m, MxFaceID i, int tag ) { return get_f_data( m, i )->user_tag & tag; } */
00709 /* inline void face_set_tag( MxModel *m, MxFaceID i, int tag ) { get_f_data( m, i )->user_tag |= tag; } */
00710 /* inline void face_unset_tag( MxModel *m, MxFaceID i, int tag ) { get_f_data( m, i )->user_tag &= ~tag;} */
00711 /* inline unsigned char face_mark( MxModel *m, MxFaceID i ) { return get_f_data( m, i )->user_mark; } */
00712 /* inline void face_mark( MxModel *m, MxFaceID i, unsigned char c ) { get_f_data( m, i )->user_mark = c; } */
00713 #define face_check_tag(m,i,t) ( get_f_data( (m), (i) )->user_tag & (t) )
00714 #define face_set_tag(m,i,t)   ( get_f_data( (m), (i) )->user_tag |= (t) )
00715 #define face_unset_tag(m,i,t) ( get_f_data( (m), i )->user_tag &= ~(t) )
00716 #define get_face_mark(m,i)    ( get_f_data( (m), (i) )->user_mark )
00717 #define face_mark(m,i,c)      ( get_f_data( (m), (i) )->user_mark = (c) )
00718 
00719 
00720 /*
00721  *  Vertex management
00722  */
00723 
00724 extern MxVertexID add_vertex   ( MxModel *m, double, double, double);
00725 extern MxFaceID   add_face     ( MxModel *m, int, int, int);
00726 extern int        add_color    ( MxModel *m, double, double, double);
00727 extern int        add_normal   ( MxModel *m, double, double, double);
00728 extern int        add_texcoord ( MxModel *m, double, double);
00729 extern void       remove_vertex( MxModel *m, MxVertexID v);
00730 extern void       free_vertex  ( MxModel *m, MxVertexID );
00731 extern MxFaceID   alloc_face   ( MxModel *m, MxVertexID, MxVertexID, MxVertexID );
00732 extern void       init_face    ( MxModel *m, MxFaceID );
00733 
00734 
00735 
00736 /* inline int normal_binding(MxModel *m) { return ( m->nbinding & m->binding_mask ); } */
00737 /* inline int color_binding(MxModel *m) { return ( m->cbinding & (m->binding_mask >> 2) ); } */
00738 /* inline int texcoord_binding(MxModel *m) { return ( m->tbinding & (m->binding_mask >> 4) ); } */
00739 #define normal_binding(m) ( ( (m)->nbinding & (m)->binding_mask ) )
00740 #define color_binding(m) ( ( (m)->cbinding & ((m)->binding_mask >> 2) ) )
00741 #define texcoord_binding(m) ( ( (m)->tbinding & ((m)->binding_mask >> 4) ) )
00742 
00743 extern const char *binding_name( MxModel *m, int );
00744 extern int parse_binding( MxModel *m, const char * );
00745 
00746 extern int   compute_face_normal   ( MxModel *m, MxFaceID, double *, MxBool will_unitize );
00747 extern double compute_face_area     ( MxModel *m, MxFaceID );
00748 extern double compute_face_perimeter( MxModel *m, MxFaceID, MxBool *edge_flags );
00749 
00750 extern double compute_corner_angle( MxModel *m, MxFaceID, int );
00751 
00752 
00753 /*
00754  *  Neighborhood collection and management, vertex normal calculations
00755  */
00756 extern void mark_neighborhood( MxModel *m, MxVertexID, unsigned short );
00757 extern void collect_unmarked_neighbors( MxModel *m, MxVertexID, MxFaceList * );
00758 extern void partition_marked_neighbors( MxModel *m, MxVertexID, unsigned short pivot,
00759         MxFaceList *below, MxFaceList *above );
00760 
00761 extern void mark_corners( MxModel *m, MxFaceList *faces, unsigned short mark );
00762 extern void collect_unmarked_corners(MxModel *m, MxFaceList *faces,MxVertexList *verts );
00763 
00764 extern void collect_edge_neighbors( MxModel *m, MxVertexID, MxVertexID, MxFaceList * );
00765 extern void collect_vertex_star( MxModel *m, MxVertexID v, MxVertexList *verts );
00766 
00767 /* extern MxFaceList *neighbors( MxModel *m, MxVertexID v ); */
00768 #define neighbors(m,v) ((MxFaceList *) getpb( &((m)->face_links), (v) ))
00769 
00770 extern void compute_vertex_normal( MxModel *m, MxVertexID v, double * );
00771 
00772 /*
00773  * Primitive transformation operations
00774  */
00775 extern void model_remap_vertex( MxModel *m, MxVertexID from, MxVertexID to );
00776 extern MxVertexID split_edge( MxModel *m, MxVertexID v1, MxVertexID v2, double x, double y, double z );
00777 extern MxVertexID split_edge_simple( MxModel *m, MxVertexID v1, MxVertexID v2 );
00778 
00779 extern void flip_edge( MxModel *m, MxVertexID v1, MxVertexID v2 );
00780 extern void split_face4( MxModel *m, MxFaceID f, MxVertexID *newverts );
00781 extern void unlink_face( MxModel *m, MxFaceID f);
00782 
00783 
00784 
00785 /*
00786  * Contraction and related operations
00787  */
00788 extern void compact_vertices( MxModel * );
00789 extern void remove_degeneracy( MxModel *, MxFaceList * );
00790 
00791 /* Pair contraction interface*/
00792 extern void compute_pair_contraction( MxModel *, MxVertexID, MxVertexID, MxPairContraction *);
00793 extern void apply_pair_contraction( MxModel *, MxPairContraction *);
00794 extern void apply_pair_expansion( MxModel *, MxPairExpansion *);
00795 extern void pair_contract( MxModel *, MxVertexID v1, MxVertexID v2,
00796         const double *, MxPairContraction *);
00797 
00798 
00799 /* MXSTDMODEL_INCLUDED*/
00800 #endif
00801 
00802 
00803 
00804 
00805 
00806 /************************************************************************
00807 
00808   Surface simplification using quadric error metrics
00809 
00810   Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
00811   
00812  ************************************************************************/
00813 
00814 #ifndef MXQSLIM_INCLUDED 
00815 #define MXQSLIM_INCLUDED
00816 
00817 typedef struct MxQSlimEdge_TAG
00818 {
00819     MxHeapable h;
00820     MxEdge e;
00821     double vnew[3];
00822 
00823 } MxQSlimEdge;
00824 
00825 extern void mxqslimedge_init( MxQSlimEdge *qse );
00826 
00827 
00828 typedef Block MxEdgeList;   /* holds type MxQSlimEdge* */
00829 
00830 /* inline MxQSlimEdge *el_get_edge( MxEdgeList *el, int i ) { return (MxQSlimEdge *) getpb( el, i ); } */
00831 /* inline int el_add_edge( MxEdgeList *el, MxQSlimEdge *q ) { return addpb( el, q ); } */
00832 #define el_get_edge(el,i) ( (MxQSlimEdge *) getpb( el, i ) )
00833 #define el_add_edge(el,q) ( addpb( el, q ) )
00834 
00835 extern MxBool find_edge( MxEdgeList *el, const MxQSlimEdge *t, int *index );
00836 
00837 
00838 
00839 
00840 
00841 typedef struct MxQSlim_TAG
00842 {
00843     MxEdgeList edge_array;
00844     Block edge_links; /* stores type MxEdgeList, links to elements of edge_array */
00845     MxModel *m;
00846     Block quadrics; /* stores type MxQuadric3 */
00847     MxHeap heap;
00848 
00849     int valid_verts;
00850     int valid_faces;
00851 
00852     /* to be copied from MxConfig at initialization */
00853     int placement_policy;
00854     int weighting_policy;
00855     double boundary_weight;
00856     double compactness_ratio;
00857     double meshing_penalty;
00858     MxBool will_join_only;
00859     int max_degree;
00860 
00861     double local_validity_threshold;
00862     Mat4 *object_transform;
00863 
00864     void (*contraction_callback)(const MxPairContraction *, double);
00865 
00866 } MxQSlim;
00867 
00868 extern void   mxqslim_init( MxQSlim *, MxModel *, MxConfig * );
00869 extern void   mxqslim_cleanup( MxQSlim * );
00870 
00871 extern MxBool qs_decimate( MxQSlim *, int );
00872 extern void   qs_apply_contraction( MxQSlim *, MxPairContraction * );
00873 
00874 extern void   discontinuity_constraint( MxQSlim *, MxVertexID, MxVertexID, MxFaceList *);
00875 extern void   collect_quadrics( MxQSlim * );
00876 extern void   transform_quadrics( MxQSlim *, const Mat4 *);
00877 extern void   constrain_boundaries( MxQSlim * );
00878 
00879 extern double  check_local_compactness( MxQSlim *, int v1, int v2, const double *vnew );
00880 extern double  check_local_inversion( MxQSlim *, int v1, const double *vnew );
00881 extern int    check_local_validity( MxQSlim *, int v1, int v2, const double *vnew );
00882 extern void   apply_penalties( MxQSlim *, MxQSlimEdge * );
00883 extern void   create_edge( MxQSlim *, MxVertexID i, MxVertexID j );
00884 extern void   collect_edges( MxQSlim * );
00885 
00886 extern void compute_target_placement( MxQSlim *, MxQSlimEdge * );
00887 
00888 extern void compute_edge_info( MxQSlim *, MxQSlimEdge * );
00889 extern void update_pre_contract( MxQSlim *, const MxPairContraction * );
00890 extern void update_post_expand( MxQSlim *, const MxPairContraction * );
00891 
00892 
00893 /* inline MxQuadric3 *qs_get_quadrics( MxQSlim *q, int i ) { return (MxQuadric3 *) getpb ( &(q->quadrics), i ); } */
00894 /* inline MxEdgeList *qs_get_edge_links( MxQSlim *q, int i ) {  return (MxEdgeList *) getpb ( &(q->edge_links), i ); } */
00895 /* inline int edge_count( MxQSlim *q )  { return sizeh( &(q->heap) ); } */
00896 #define qs_get_quadrics(q,i) ( (MxQuadric3 *) getpb ( &((q)->quadrics), (i) ) )
00897 #define qs_get_edge_links(q,i) ( (MxEdgeList *) getpb ( &((q)->edge_links), (i) ) )
00898 /* #define edge_count(q) ( sizeh( &((q)->heap) ) ) */
00899 
00900 
00901 
00902 /* MXQSLIM_INCLUDED*/
00903 #endif
00904 
00905 
00906 
00907 
00908 
00909 /************************************************************************
00910 
00911   3D Quadric Error Metric
00912 
00913   Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
00914   
00915  ************************************************************************/
00916 
00917 #ifndef MXQMETRIC3_INCLUDED 
00918 #define MXQMETRIC3_INCLUDED
00919 
00920 typedef struct MxQuadric3_TAG
00921 {
00922     double a2, ab, ac, ad;
00923     double     b2, bc, bd;
00924     double         c2, cd;
00925     double             d2;
00926 
00927     double r;
00928 
00929 } MxQuadric3;
00930 
00931 /* initialization */
00932 void mxquadric3_init( MxQuadric3 *, double a, double b, double c, double d, double area );
00933 void mxquadric3_init_by_matrix( MxQuadric3 *, const Mat4 *Q, double area ); 
00934 
00935 /* manipulation utilities */
00936 extern void quad_copy( MxQuadric3 *, const MxQuadric3 *Q );
00937 extern void quad_add( MxQuadric3 *, const MxQuadric3 *, const MxQuadric3 * );
00938 extern void quad_sub( MxQuadric3 *, const MxQuadric3 *, const MxQuadric3 * );
00939 extern void quad_mul( MxQuadric3 *, const MxQuadric3 *, const double );
00940 extern void quad_scale( MxQuadric3 *, double s ); /* multiply in place */
00941 extern void quad_clear( MxQuadric3 *q );
00942 extern void quad_transform( MxQuadric3 *, const MxQuadric3 *, const Mat4 * );
00943 /*inline void quad_set_area( MxQuadric3 *q, double a ) { q->r=a; }*/
00944 #define quad_set_area(q,a) { (q)->r=(a); }
00945 
00946 /* access utilities */
00947 extern double quad_offset( const MxQuadric3 * ); 
00948 extern double quad_area( const MxQuadric3 * );
00949 
00950 /* evaluation and optimization */
00951 extern MxBool optimizev ( const MxQuadric3 *, Vec3 *v ); 
00952 extern MxBool optimize3f( const MxQuadric3 *, double *x, double *y, double *z ); 
00953 extern MxBool optimize2v( const MxQuadric3 *, Vec3 *v, const Vec3 *v1, const Vec3 *v2 ); 
00954 extern MxBool optimize3v( const MxQuadric3 *, Vec3 *v, const Vec3 *v1, const Vec3 *v2, const Vec3 *v3 );
00955 extern double quad_evaluate( const MxQuadric3 *, double x, double y, double z );
00956 extern double quad_evaluatev( const MxQuadric3 *q, const double *v );
00957 
00958 
00959 
00960 /* MXQMETRIC3_INCLUDED*/
00961 #endif

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