Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

lod.h

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

Generated on Tue May 17 12:06:00 2005 for Autodesk DWF 3D Toolkit by  doxygen 1.4.1