HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>


lod_type.h

00001 #ifndef MXTYPE_INCLUDED 
00002 #define MXTYPE_INCLUDED
00003 
00004 /************************************************************************
00005 
00006   MxType.h
00007 
00008   This file contains most of the data types needed by the LOD module:
00009   Block, Heap
00010   Vertex, Face, Edge
00011   VertexList, FaceList, EdgeList
00012 
00013   Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
00014   
00015   $Id: lod__type_8h-source.html,v 1.4 2008-02-21 21:41:00 stage Exp $
00016 
00017  ************************************************************************/
00018 
00019 #include "mxmath.h"
00020 #include <stdlib.h>
00021 
00022 /* 
00023  * blocks are arrays that automatically resize
00024  */
00025 typedef struct Block_TAG
00026 {
00027     int allocated;
00028     int used;
00029     int size_each;
00030     void *data;
00031 
00032 } Block;
00033 
00034 
00035 /*
00036  * function declarations for manipulating blocks
00037  */
00038 extern void block_init    (Block *, int size_each_in);
00039 extern void block_cleanup (Block *);
00040 extern void resetb  (Block *);
00041 extern int  addb    (Block *, const void *elem);
00042 extern int  addpb   (Block *, const void *elem);
00043 extern void clobberb(Block *, const void *elem, int i);
00044 extern void swapb   (Block *, int i, int j);
00045 extern void removeb (Block *, int which);
00046 extern void resizeb (Block *, int size_in);
00047 extern void chopb   (Block *);
00048 extern int  isvalidb(const Block *, int which);
00049 
00050 #define lengthb(b) ((b)->used)
00051 #define getb(b,i)  ((char *)(b)->data + ((i) * (b)->size_each))
00052 #define getpb(b,i) (*((void **) getb ((b), (i))))
00053 
00054 
00055 /* heap nodes */
00056 typedef struct MxHeapable_TAG
00057 {
00058     double import;  /* priority */
00059     int token;      /* place in heap */
00060     void *payload;  /* data */
00061 
00062 } MxHeapable;
00063 
00064 /*
00065  * functions for manipulating mxheapables
00066  */
00067 /* inline bool is_in_heap(MxHeapable *h) { return h->token != -47; } */
00068 /* inline void not_in_heap(MxHeapable *h) { h->token = -47; } */
00069 /* inline int get_heap_pos(MxHeapable *h) { return h->token; } */
00070 /* inline void set_heap_pos(MxHeapable *h, int t) { h->token=t; } */
00071 /* inline void  set_heap_key(MxHeapable *h, double k) { h->import=k; } */
00072 /* inline double get_heap_key(const MxHeapable *h) { return h->import; } */
00073 /* inline void mxheapable_init(MxHeapable *h) { h->import = 0.0f; h->token = -47; h->payload = NULL; } */
00074 
00075 #define is_in_heap(h) ((h)->token != -47)
00076 #define not_in_heap(h) ((h)->token = -47)
00077 #define get_heap_pos(h) ((h)->token)
00078 #define set_heap_pos(h,t) ((h)->token = t)
00079 #define set_heap_key(h,k) ((h)->import = k)
00080 #define get_heap_key(h) ((h)->import)
00081 #define mxheapable_init(h) { (h)->import = 0.0f; (h)->token = -47; (h)->payload = NULL; }
00082 
00083 
00084 
00085 /* the heap */
00086 typedef struct MxHeap_TAG
00087 {
00088     Block data; /* a dynamically growable array of heapables. */
00089 
00090 } MxHeap;
00091 
00092 
00093 extern void mxheap_init   (MxHeap *);
00094 extern void mxheap_cleanup(MxHeap *); 
00095 extern void inserth       (MxHeap *, MxHeapable *);
00096 extern void updateh       (MxHeap *, MxHeapable *);
00097 extern void *extracth     (MxHeap *);
00098 extern void removeh       (MxHeap *, MxHeapable *);
00099 extern void *itemh        (MxHeap *, int);
00100 
00101 /* inline int sizeh(MxHeap *m)  { return lengthb(&(m->data)); } */
00102 #define sizeh(m) (lengthb(&((m)->data)))
00103 
00104 
00105 
00106 
00107 typedef int MxVertexID;
00108 typedef int MxFaceID;
00109 
00110 
00111 /* 
00112  *  Type declarations for MxVertex, MxProxy, MxFace, MxEdge
00113  *  and associated helper functions
00114  */
00115 
00116 typedef Vec3 MxVertex;
00117 
00118 /* needed for storing multiple vertices with different attributes */
00119 typedef struct MxProxy_TAG
00120 {
00121     MxVertexID prev, next; 
00122 
00123 } MxProxy;
00124 
00125 typedef struct MxEdge_TAG
00126 {
00127     MxVertexID v1, v2;
00128 
00129 } MxEdge ;
00130 
00131 typedef struct MxFace_TAG
00132 {
00133     MxVertexID v[3];
00134 
00135 } MxFace;
00136 
00137 
00138 /* inline MxVertexID opposite_vertex(MxEdge *e, MxVertexID v)
00139 {
00140     if (v == e->v1) return e->v2;
00141     else { return e->v1; }
00142 }*/
00143 #define opposite_vertex(e,v) (((v)==(e)->v1)?(e)->v2:(e)->v1)
00144 
00145 
00146 extern void       mxface_init(MxFace *, MxVertexID, MxVertexID, MxVertexID);
00147 extern int        face_find_vertex(const MxFace *, MxVertexID);
00148 extern MxVertexID face_opposite_vertex(const MxFace *, MxVertexID, MxVertexID);
00149 extern MxBool     face_is_inorder(const MxFace *, MxVertexID, MxVertexID);
00150 extern int        face_remap_vertex(MxFace *, MxVertexID, MxVertexID);
00151 
00152 
00153 
00154 /* 
00155  *  Type declarations for MxColor, MxNormal, and MxTexcoord 
00156  *  (all are optionally included in MxModel)
00157  *  and associated helper functions
00158  */
00159 
00160 typedef struct MxColor_TAG
00161 {
00162     unsigned char r, g, b, a;
00163     unsigned int word;
00164 
00165 } MxColor;
00166 
00167 typedef struct MxNormal_TAG
00168 {
00169     double dir[3];
00170 
00171 } MxNormal;
00172 
00173 typedef struct MxTexCoord_TAG
00174 {
00175     double u[2];
00176 
00177 } MxTexCoord;
00178 
00179 
00180 #define ftop(x) ((unsigned char)(((x)>1.0f?1.0f:(x))*255.0f))
00181 #define ptof(x) ((x) / 255.0f)
00182 
00183 extern void mxcolor_init(MxColor *, double, double, double );
00184 extern void mxtexcoord_init(MxTexCoord *, double, double);
00185 extern void mxnormal_init(MxNormal *, double, double, double);
00186 
00187 /*
00188  * Vertex, Face, and Edge lists, plus associated utility functions 
00189  */
00190 
00191 typedef Block MxFaceList;      /* holds type MxFaceID */
00192 typedef Block MxVertexList;    /* holds type MxVertexID */
00193 
00194 /* inline MxFaceID fl_get_face(MxFaceList *fl, int i) {return *((MxFaceID *) getb(fl, i));} */
00195 /* inline MxVertexID vl_get_vertex(MxVertexList *vl, int i) {   return *((MxVertexID *) getb(vl, i));} */
00196 #define fl_get_face(fl,i) (*((MxFaceID *) getb(fl, i)))
00197 #define vl_get_vertex(vl,i) (*((MxVertexID *) getb(vl, i)))
00198 
00199 extern MxBool fl_find_face(MxFaceList *fl, MxFaceID fid, int *index);
00200 extern MxBool vl_find_vertex(MxVertexList *vl, MxFaceID vid, int *index);
00201                         
00202 #endif
Main Index
HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>