- Timestamp:
- 09/04/07 13:06:39 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoMeshStripifier.h
r2341 r2549 15 15 #include "GeoMesh.h" 16 16 17 typedef int BOOL; 18 typedef void * PVOID; 19 17 #define MAX_ADJ 60 20 18 21 19 namespace Geometry 22 20 { 23 24 #define TRIANGLE 3 25 #define MAGNITUDE 1000000 26 #define MAX_TIE 60 27 28 #define FALSE 0 29 #define TRUE 1 30 #define LISTHEAD 0 31 #define LISTTAIL 1 21 typedef struct 22 { 23 int array[3]; 24 } 25 vector3; 32 26 33 27 typedef struct 34 28 { 35 void *Next;36 void *Previous;37 38 myNode, * PNODE;29 int finish; 30 int NumAdj; 31 } 32 adj; 39 33 40 typedef struct List 41 { 42 /* link to the next Listinfo Structure */ 43 myNode ListNode; 44 45 /* user definable data */ 46 } 47 ListInfo, *PLISTINFO; 48 49 typedef struct LHead 50 { 51 PLISTINFO LHeaders[2]; 52 int NumList; 53 } 54 ListHead, *PLISTHEAD; 55 56 #define PEEKFROMHEAD( lh, ind ) ( PeekList( (lh), LISTHEAD, (ind) ) ) 57 #define PEEKFROMTAIL( lh, ind ) ( PeekList( (lh), LISTTAIL, (ind) ) ) 58 #define EMPTYLIST( lh ) ( ( (lh)->LHeaders[LISTHEAD] == NULL ) ) 59 #define NumOnList(lh) ( ((lh)->NumList) ) 60 #define GetNextNode(pli) ( ((pli)->ListNode.Next) ) 61 #define GetPrevNode(pli) ( ((pli)->ListNode.Previous) ) 62 63 //----- 64 65 /** polverts.h 66 */ 67 typedef struct adjacencies 68 { 69 myNode ListNode; 70 int face_id; 71 }ADJACENCIES,*P_ADJACENCIES; 72 73 typedef struct FVerts 74 { 75 myNode ListNode; 76 int *pPolygon; 77 int nPolSize; 78 int nId; 79 } F_VERTS, *PF_VERTS; 80 81 /*Every time we need to use this, cast it ( ListInfo*)*/ 82 typedef struct FEdges 83 { 84 myNode ListNode; 85 int edge[3]; 86 }F_EDGES,*PF_EDGES; 87 88 typedef struct FFaces 89 { 90 myNode ListNode; 91 int *pPolygon; 92 int *pNorms; 93 int seen; 94 int seen2; 95 int seen3; 96 int nPolSize; 97 int nOrgSize; 98 F_EDGES **VertandId; 99 int *marked; 100 int *walked; 101 }F_FACES,*PF_FACES; 34 typedef std::vector<int> vector_int; 35 typedef std::vector<vector3> vector_vector3; 102 36 103 typedef struct FVertices104 {105 myNode ListNode;106 PF_FACES face;107 }F_VERTICES, *PF_VERTICES;108 109 typedef struct Strips110 {111 myNode ListNode;112 int face_id;113 }Strips,*P_STRIPS;114 115 116 struct vert_added117 {118 int num;119 int *normal;120 };121 122 typedef struct face_adjacencies123 {124 P_ADJACENCIES pfNode;125 int bucket;126 ListHead *head;127 }128 FACE_ADJACENCIES, *P_FACE_ADJACENCIES;129 130 /** global.h131 */132 typedef std::vector<int> mi_vector_tipo;133 //std::vector<mi_vector_tipo> mi_vector;134 enum swap_type {ON,OFF};135 136 #define VRDATA double137 #define MAX1 60138 139 #define GEO_PI 3.1415926573140 #define ATOI(C) (C -'0')141 #define EVEN(x) (((x) & 1) == 0)142 #define MAX_BAND 10000143 144 struct vert_struct145 {146 VRDATA x, y, z; /* point coordinates */147 };148 149 37 /// Stripifier interface class. 150 38 /** This module implements methods that extract triangle strips from triangle meshes. … … 201 89 private: 202 90 203 /* Globals */ 204 int mError; // 0 OK. 205 // 1 Error: The mesh is not Manifold. 91 // Globals 92 int mError; 206 93 int num_faces; 207 ListHead **PolFaces; 208 ListHead **PolEdges; 209 ListHead *array[60]; 210 P_FACE_ADJACENCIES face_array; /* Pointers from face_id to face */ 211 ListHead **Vertices; /* Pointers from vertex_id to face */ 212 ListHead *strips[1]; 213 int orient; 94 95 std::vector<vector3> StripFaces; 96 std::vector<vector_vector3> StripEdges; 97 98 vector_int StripArray[MAX_ADJ]; 99 100 adj* StripFaceAdj; 101 102 std::vector<vector_int> StripVertices; 103 104 vector_int Strips; 105 214 106 int num_tiras; 215 int ids[MAX1]; 216 int norms[MAX1]; 217 int *vert_norms; 218 int *vert_texture; 219 int out1;//= -1; // static. 220 int out2;//= -1; // static. 221 int ties_array[60]; // static. 222 int last;//= 0; // static. 223 int out1Ex;// = -1; // static. 224 int out2Ex;// = -1; // static. 225 int *vn; 226 int *vt; 227 int norm; // static. 228 int text; // static. 229 BOOL resetting;// = FALSE; // static. 230 int added_quad;// = 0; // static. 231 BOOL reversed;// = FALSE; // static. 232 int patch;// = 0; // static. 107 int ids[3]; 108 int lastTri[3]; 109 int ties_array[60]; 110 int last; 233 111 234 /** global.h 235 */ 236 std::vector<mi_vector_tipo> mi_vector; 112 std::vector<vector_int> my_vector; 237 113 238 /** auxiliar.h239 */240 114 Geometry::Mesh *MeshGlobal; 241 // Structures for the object.242 vert_struct *vertices;243 vert_struct *nvertices;244 vert_struct *pvertices;245 vert_struct *pnvertices;246 115 247 /* General utility routines */ 248 /* %%s QueRoutines */ 249 BOOL InitList ( PLISTHEAD ); 116 int stripify( Geometry::Mesh *geoMesh); 250 117 251 /***************************************************************** 252 InitList : Initialize a new list structure for use with the List 253 routines 118 void GetLower(int *x, int *y); 119 int Different(int id1,int id2,int id3,int id4,int id5, int id6, int *x, int *y); 120 void Orient(int vertex1,int vertex2,int vertex3); 121 void StoreAdjacencies(int num_faces); 122 void ReadData(Geometry::SubMesh *geoSubMesh,int num_faces, int num_vert); 123 void Stripification(); 124 void AddTri(int id1, int id2, int id3, int flag, int where); 125 void GoBack(int face_id, int *ties,int tie); 126 void StoreTri(int face_id,int NumAdj, int original_adj, int *ties, int tie, int where); 254 127 255 INPUTS : LHead : a pointer to a ListHead structure. 256 OUTPUT : a boolean value TRUE if no errors occured FALSE 257 otherwise 258 ******************************************************************/ 128 int GetNumAdjacencies(int id1, int id2, int curr_id); 129 int MinimumAd(int id); 130 int Find_Face(int current_face, int id1,int id2, int *NumAdj); 131 int Look_Up(int id1,int id2,int face_id); 132 void StoreStrip(int id, int where); 133 int NumAdj(int id1, int id2); 134 void FindAdjacencies(int num_faces, int num_verts); 135 void StoreAdjacency(int NumAdj,int face_id); 136 int Prediction(); 137 void AddNewFace(int ids[3],int face_id); 138 void AddAdjEdge(int v1,int v2, int fnum); 139 int GetEdge( int *edge1,int *edge2,int *index,int face_id); 140 void DeleteAdj(int id1, int id2, int *next_NumAdj,int *min_face, 141 int current_face,int *e1,int *e2,int *ties); 142 int UpdateAdjacencies(int face_id,int *next_NumAdj, int *e1, int *e2,int *ties); 143 void UpdateFaces(int *next_NumAdj,int *min_face, int face_id, int *e1,int *e2,int temp1, int temp2,int *ties); 144 int Finished(); 259 145 260 146 261 PLISTINFO PeekList( PLISTHEAD, int, int );262 263 /*****************************************************************264 PeekList : This funciton peeks down a list for the N'th element265 from the HEAD or TAIL of the list266 267 INPUTS : LHead : a pointer to a List head structure.268 from : can either search from the HEAD or TAIL269 of the list270 where : how many nodes from the begining should the271 List routines look.272 OUTPUT : a pointer to a ListInfo structure identified by273 from/where or NULL if an error occurred.274 ******************************************************************/275 276 277 PLISTINFO RemoveList( PLISTHEAD LHead, PLISTINFO LInfo );278 279 280 /*****************************************************************281 RemoveList: Remove a ListInfo structure from a List.282 283 INPUTS : LHead : a pointer to a ListHead structure.284 LInfo : a pointer to the ListInfo structure to remove285 from the list.286 OUTPUT : a pointer to the ListInfo structure that was removed or287 NULL if an error occurred.288 ******************************************************************/289 290 BOOL InsertNode( PLISTHEAD LHead, int nPos, PLISTINFO LInfo );291 292 /*****************************************************************293 InsertNode: add a node to a list after a given node294 295 INPUTS : LHead : a pointer to a ListHead structure.296 nPos : the position to insert the node into297 LInfo : a pointer to the new node to add to the list.298 OUTPUT: a boolean value TRUE if all goes well false otherwise299 *****************************************************************/300 301 BOOL AddHead ( PLISTHEAD, PLISTINFO );302 303 /*****************************************************************304 AddHead : add a ListInfo structure to the HEAD of a list.305 306 INPUTS : LHead : a pointer to a ListHead structure of the list307 to add to.308 LInfo : a pointer to the ListInfo structure to add to309 the list.310 OUTPUT : A boolean value TRUE if no errors occurred FALSE311 otherwise.312 ******************************************************************/313 314 315 BOOL AddTail ( PLISTHEAD, PLISTINFO );316 317 /*****************************************************************318 AddTail : Add a ListInfo structure to the TAIL of a list.319 320 INPUTS : LHead : a pointer to a ListHead structure of the List321 to add to.322 LInfo : a pointer to the ListInfo structure to add to323 the List.324 OUTPUT : a boolean value TRUE if no errors occurred FALSE325 otherwise.326 ******************************************************************/327 328 329 PLISTINFO RemTail ( PLISTHEAD );330 331 /*****************************************************************332 RemTail : Remove a ListInfo structure from the TAIL of a List.333 334 INPUTS : LHead : a pointer to a ListHead structure of the List335 to remove from.336 OUTPUT : a pointer to the ListInfo structure that was removed337 or NULL if an error occurred.338 ******************************************************************/339 340 341 PLISTINFO RemHead ( PLISTHEAD );342 343 /*****************************************************************344 RemHead : Remove a ListInfo structure from the Head of a List.345 346 INPUTS : LHead : a pointer to a ListHead structure of the List347 to remove from.348 OUTPUT : a pointer to the ListInfo structure that was removed or349 NULL if an error occurred.350 ******************************************************************/351 352 PLISTINFO SearchList(353 PLISTHEAD lpListHead,354 PVOID lpSKey,355 int ( * CompareCallBack) ( PVOID, PVOID ) );356 357 /*****************************************************************358 SearchList:359 Try to find a specific node in the queue whose key matches with360 searching key. Return the pointer to that node if found, return NULL361 otherwise362 363 Input:364 lpHashTbl => a far pointer to the hash table365 lpKey => a far poniter to searching key366 CompareCallBack => comparision function367 368 Output: a far pointer to the node to be found369 370 ******************************************************************/371 372 /** init.h373 */374 BOOL InitVertexTable(int nSize);375 BOOL InitFaceTable(int nSize);376 BOOL InitEdgeTable(int nSize);377 void BuildFaceTable(int nSize);378 void BuildVertexTable(int nSize);379 void BuildEdgeTable(int nSize);380 void init_vert_norms(int num_vert);381 void init_vert_texture(int num_vert);382 void InitStripTable();383 void Init_Table_SGI(int numfaces);384 void Start_Vertex_Struct(int numverts);385 void Start_Face_Struct(int numfaces);386 void Start_Edge_Struct(int numverts);387 388 /** util.h389 */390 void switch_lower(int *x, int *y);391 BOOL member(int x , int id1, int id2, int id3);392 BOOL Exist(int face_id, int id1, int id2);393 int Different( int id1,int id2,int id3,int id4,int id5,394 int id6, int *x, int *y);395 int Return_Other(int *index,int e1,int e2);396 int Get_Other_Vertex(int id1,int id2,int id3,int *index);397 PLISTINFO Done(int face_id, int *bucket);398 void First_Edge(int *id1,int *id2, int *id3);399 void Last_Edge(int *id1, int *id2, int *id3, BOOL save);400 401 void preserve_strip_orientation_with_normal(402 int vertex1,403 int normal1,404 int vertex2,405 int normal2,406 int vertex3,407 int normal3);408 409 void preserve_strip_orientation_with_texture(410 int vertex1,411 int texture1,412 int vertex2,413 int texture2,414 int vertex3,415 int texture3);416 417 void preserve_strip_orientation_with_texture_and_normal(418 int vertex1,419 int texture1,420 int normal1,421 int vertex2,422 int texture2,423 int normal2,424 int vertex3,425 int texture3,426 int normal3);427 428 void preserve_strip_orientation(429 int vertex1,430 int vertex2,431 int vertex3);432 433 void find_triangle_orientation( int vertex1,434 int vertex2,435 int vertex3,436 int *original_vertex);437 438 /** local.h439 */440 void Find_StripsEx(int *ties, int tie, int triangulate, int swaps, int *next_id);441 void SGI_Strip(int num_faces,int ties,int triangulate);442 443 /** outputex.h444 */445 void Output_TriEx(int id1, int id2, int id3, int flag,int where);446 void Extend_BackwardsEx(int face_id, int *ties,447 int tie, int triangulate,448 int swaps,int *next_id);449 void Polygon_OutputEx(P_ADJACENCIES temp,int face_id,int bucket,450 ListHead *pListHead,451 int *ties, int tie,int triangulate, int swaps,452 int *next_id, int where);453 454 /** sgi_triang.h455 */456 int Adjacent(int id2,int id1, int *list, int size);457 void Build_SGI_Table(int num_faces);458 void Non_Blind_Triangulate( int size,int *index,459 int next_face_id,460 int face_id,int where,461 int color1,int color2,int color3);462 void Blind_Triangulate(int size, int *index, BOOL begin, int where);463 void Rearrange_Index(int *index, int size); // static.464 void Delete_From_List(int id,int *list, int *size); // static.465 void Triangulate_Quad(int out_edge1,int out_edge2,int in_edge1,466 int in_edge2,int size,int *index,467 int reversed,int where); // static.468 void Triangulate_Polygon( int out_edge1,int out_edge2,469 int in_edge1, int in_edge2,470 int size, int *index,471 int reversed,472 int face_id, int where,473 int color1, int color2,474 int color3); // static.475 476 void Triangulate( int out_edge1,int out_edge2,int in_edge1,477 int in_edge2,int size,int *index,478 int reversed,int face_id, int where,479 int color1, int color2,int color3); // static.480 481 /** struct.h482 */483 int Get_Edge( int *edge1,int *edge2,484 int *index,int face_id,485 int size, int id1, int id2);486 int Update_Adjacencies( int face_id,int *next_bucket,487 int *e1,int *e2,int *ties);488 void Update_Face( int *next_bucket, int *min_face,489 int face_id, int *e1,490 int *e2, int temp1,491 int temp2, int *ties); // static.492 void Delete_Adj(int id1, int id2,int *next_bucket,493 int *min_face,int current_face,int *e1,494 int *e2,int *ties); // static.495 /** common.h496 */497 int Old_Adj(int face_id);498 int Number_Adj(int id1, int id2, int curr_id);499 int Min_Adj(int id);500 void Check_In_Polygon(int face_id, int *min, int size);501 void New_Face (int face_id, int v1, int v2, int v3);502 void New_Size_Face(int face_id);503 void Check_In_Quad(int face_id,int *min);504 int Get_Output_Edge(int face_id, int size, int *index,int id2,int id3);505 void Get_Input_Edge(int *index,int id1,506 int id2,int id3,507 int *new1,int *new2,508 int size,int face_id);509 int Find_Face(int current_face, int id1,510 int id2, int *bucket);511 BOOL Look_Up(int id1,int id2,int face_id);512 void Add_Id_Strips(int id, int where);513 int Num_Adj(int id1, int id2);514 void Add_Sgi_Adj(int bucket,int face_id);515 void Find_Adjacencies(int num_faces);516 void Edge_Least(int *index,int *new1,517 int *new2,int face_id,int size); // static.518 519 /** ties.h520 */521 void Clear_Ties();522 void Add_Ties(int id);523 int Get_Next_Face(int t, int face_id, int triangulate);524 int Alternate_Tie(); // static.525 int Random_Tie(); // static.526 int Look_Ahead(int id); // static.527 int Random_Look(int id[],int count); // static.528 int Look_Ahead_Tie(); // static.529 int Sequential_Tri(int *index); // static.530 int Sequential_Quad(int *index, int triangulate); // static.531 void Whole_Output(int in1, int *index, int size,532 int *out1,int *out2); // static.533 int Sequential_Poly(int size,int *index,int triangulate); // static.534 int Sequential_Tie(int face_id,int triangulate); // static.535 536 /** add.h537 */538 BOOL norm_array(int id,int vertex,539 double normal_difference,540 struct vert_struct *n,int num_vert);541 void add_texture(int id,BOOL vertex);542 int add_vert_id(int id, int index_count);543 void add_norm_id(int id, int index_count);544 void AddNewFace(int ids[MAX1],int vert_count,545 int face_id,int norms[MAX1]);546 void CopyFace(int ids[MAX1],int vert_count,547 int face_id,int norms[MAX1]);548 void Add_AdjEdge( int v1,int v2,549 int fnum,int index1);550 BOOL new_vertex(double difference,int id1,551 int id2,struct vert_struct *n); // static.552 BOOL Check_VN(int vertex,int normal, struct vert_added *added); // static.553 554 /** options.h555 */556 enum file_options {ASCII,BINARY};557 enum tie_options {FIRST, RANDOM, ALTERNA, LOOK, SEQUENTIAL};558 enum triangulation_options {PARTIAL,WHOLE};559 560 void print_usage(void);561 float get_options(int argc, char **argv,562 int *f, int *t,563 int *tr, int *group,564 int *orientation);565 int power_10(int power); // static.566 float power_negative(int power); // static.567 float convert_array(int num[],int stack_size); // static.568 569 /** sgi_triangex.h570 */571 int AdjacentEx(int id2,int id1, int *list, int size);572 void Delete_From_ListEx(int id,int *list, int size);573 void Triangulate_PolygonEx( int out_edge1,int out_edge2,int in_edge1,574 int in_edge2,int size,int *index,575 int reversed,int face_id,576 int where);577 void Non_Blind_TriangulateEx( int size,int *index,578 int next_face_id,579 int face_id,int where);580 void Rearrange_IndexEx(int *index, int size);581 void Blind_TriangulateEx( int size, int *index,582 BOOL begin, int where);583 void Triangulate_QuadEx(int out_edge1,int out_edge2,int in_edge1,584 int in_edge2, int size, int *index,585 int reversed, int where); // static.586 void TriangulateEx( int out_edge1,int out_edge2,587 int in_edge1, int in_edge2,588 int size, int *index,589 int reversed,590 int face_id, int where); // static.591 592 /** structex.h593 */594 int Get_EdgeEx( int *edge1,int *edge2,int *index,int face_id,595 int size, int id1, int id2);596 void Delete_AdjEx(int id1, int id2,597 int *next_bucket,int *min_face,598 int current_face,int *e1,599 int *e2,int *ties);600 int Change_FaceEx(int face_id,int in1,int in2,601 ListHead *pListHead, BOOL no_check);602 int Update_AdjacenciesEx( int face_id,int *next_bucket,603 int *e1, int *e2,604 int *ties);605 int Min_Face_AdjEx(int face_id,int *next_bucket,int *ties);606 607 void Update_FaceEx( int *next_bucket,int *min_face,608 int face_id, int *e1,609 int *e2,int temp1,610 int temp2,int *ties); // static.611 612 void Find_Adj_TallyEx(int id1, int id2,613 int *next_bucket, int *min_face,614 int current_face, int *ties); // static.615 616 /** partial.h617 */618 void Partial_Triangulate(int size, int *index,619 int next_face_id,620 int face_id, int *next_id,621 ListHead *pListHead,622 P_ADJACENCIES temp, int where);623 624 625 void Inside_Polygon(int size, int *index,626 int face_id, ListHead *pListHead,627 int where);628 629 void P_Triangulate_Quad(int out_edge1,int out_edge2,630 int in_edge1, int in_edge2,631 int size, int *index,632 int reversed, int face_id,633 ListHead *pListHead,634 P_ADJACENCIES temp,635 int where); // static.636 void P_Triangulate_Polygon( int out_edge1,int out_edge2,637 int in_edge1, int in_edge2,638 int size, int *index,639 int reversed,640 int face_id, int *next_id,641 ListHead *pListHead,642 P_ADJACENCIES temp2,643 int where); // static.644 void P_Triangulate( int out_edge1,int out_edge2,int in_edge1,645 int in_edge2, int size, int *index,646 int reversed, int face_id,647 int *next_id, ListHead *pListHead,648 P_ADJACENCIES temp,int where); // static.649 void Input_Edge(int face_id, int *index,650 int size, int in_edge1,651 int in_edge2, ListHead *pListHead,652 int where); // static.653 654 /** output.h655 */656 int Finished(int *swap, int startnewstrip);657 void Output_Tri(int id1, int id2, int id3,BOOL end);658 int Extend_Face(int face_id,int e1,int e2,int *swaps,659 int color1,int color2,int color3,int *vert_norm,660 int normals,int *vert_texture,int texture);661 int Polygon_Output( P_ADJACENCIES temp, int face_id,662 int bucket, ListHead *pListHead,663 BOOL first, int *swaps,664 int color1, int color2,665 int color3,666 BOOL global, BOOL end); // static.667 /** free.h668 */669 void Free_Strips();670 void End_Face_Struct(int numfaces);671 void End_Edge_Struct(int numverts);672 void ParseAndFreeList( ListHead *pListHead ); // static.673 void FreeFaceTable(int nSize); // static.674 void FreeEdgeTable(int nSize); // static.675 676 /** newpolve.h677 */678 void Find_Bands(int numfaces, int *swaps, int *bands,679 int *cost, int *tri, int norms, int *vert_norms,680 int texture, int *vert_texture);681 void Save_Walks(int numfaces);682 void Save_Rest(int *numfaces);683 int Calculate_Walks(int lastvert,int y, PF_FACES temp2); // static.684 BOOL Check_Right( int last_seen,PF_FACES temp2,685 int y,int face_id); // static.686 int Update_and_Test(PF_FACES temp2,int y,687 BOOL first,int distance,688 int lastvert, int val); // static.689 int Test_Adj( PF_FACES temp2,int x,690 int north,int distance,691 int lastvert, int value); // static.692 int Find_Max( PF_FACES temp2, int lastvert,693 int north, int left,694 int *lastminup, int *lastminleft); // static.695 void Mark_Face( PF_FACES temp2, int color1,696 int color2, int color3,697 BOOL end,698 int *edge1, int *edge2,699 int *face_id, int norms,700 int texture); // static.701 void Assign_Walk( int lastvert, PF_FACES temp2,702 int front_walk, int y,703 int back_walk); // static.704 void Fast_Reset(int x); // static.705 void Reset_Max( PF_FACES temp2,int face_id,706 int north,int last_north,707 int orientation,int last_left,708 int color1,709 int color2,int color3,710 BOOL start); // static.711 int Peel_Max( PF_FACES temp2,int face_id,712 int north,int last_north,713 int orientation,int last_left,714 int color1,715 int color2,int color3,716 BOOL start, int *swaps_added,717 int norms, int texture); // static.718 719 /** auxiliar.h720 */721 // FILE *OpenOutputFile(char *fname);722 void AllocateStruct(int num_faces,723 int num_vert,724 int num_nvert,725 int num_texture);726 void miReadFile(char *fname, char *file_open, Geometry::SubMesh *geoSubMesh);727 int stripify( char *fname,728 Geometry::Mesh *geoMesh);729 147 730 148 public:
Note: See TracChangeset
for help on using the changeset viewer.