00001 /* 00002 * Copyright (c) 2006 by Tech Soft 3D, 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: bf819e8c935a8ec0ff350bf4bae2ec2a5d846aeb $ 00013 */ 00014 00015 00016 00017 #ifndef _HIO_INDEX_MANAGER_ 00018 #define _HIO_INDEX_MANAGER_ 00019 00020 #ifdef H_PACK_8 00021 #pragma pack(push) 00022 #pragma pack(8) 00023 #endif 00024 00025 #include "HTools.h" 00026 00027 #define VI_BITS (16) //number of bits per section of vertex indices 00028 #define VI_MASK ((1<<VI_BITS)-1) 00029 #define MAX_SI_INDEX ((0x1 << (31-VI_BITS))-1) 00030 00031 00032 typedef struct { 00033 HC_KEY key; 00034 MVO_POINTER_SIZED_INT offset; //pointer-sized to maintain alignment 00035 } ShellInfo; 00036 00037 00038 typedef struct { 00039 HC_KEY key; 00040 int *bigIndices; 00041 } PairToIndex; 00042 00043 00044 #define UNUSED_INDEX_TO_PAIR 0xffffffff 00045 /* interpretation of IndexToPair (stored as unsigned int) values: 00046 if (HIGHBIT) 00047 if (0xffffffff) 00048 unused entry 00049 else 00050 use the remaining 31 bits as an index into m_SharedVertices 00051 else 00052 use the remaining upper 31-VI_INDEX bits as in index into the m_ShellLookup 00053 add the ShellInfo.offset to the lower VI_INDEX bits to form the shell's vertex index 00054 grab the shell's key out of the ShellInfo 00055 */ 00056 00057 00058 typedef struct { 00059 //first int is the count, subsequent ints are interpreted as IndexToPair 00060 unsigned int *IndexToPair; 00061 } SharedVertex; 00062 00063 /* STORAGE REQUIREMENTS: 00064 IndexToPair: 00065 1 int per unshared vertex 00066 1 ptr + (2+N) ints for a vertex shared N times 00067 1 ptr + 1 int per shell 00068 00069 PairToIndex 00070 1 ptr per shell 00071 1 int per shell vertex 00072 00073 RESTRICTIONS: 00074 there can be no more than 2^15 ShellInfo structures. Thus there can be 00075 no more than 32k shells. For these purposes, a shell with more than 2^VI_BITS 00076 vertices counts as point_count >> VI_BITS. 00077 */ 00078 00079 00080 class MVO_API HIndexManager 00081 { 00082 private: 00083 void ExpandSharedVertices(); 00084 void ExpandShellLookup(int count); 00085 void ExpandPairToIndices(); 00086 00087 HPoint const *m_OldPoints; //needed for AddOneTrnslation 00088 HPoint * m_NewPoints; //temporary scratch space 00089 00090 protected: 00091 bool m_p2i; 00092 bool m_i2p; 00093 00094 unsigned int *m_IndexToPairs; 00095 int m_IndexToPairsAllocated; 00096 int m_IndexToPairsUsed; 00097 00098 SharedVertex *m_SharedVertices; 00099 int m_SharedVerticesAllocated; 00100 int m_SharedVerticesUsed; 00101 00102 ShellInfo *m_ShellLookup; 00103 int m_ShellLookupAllocated; 00104 int m_ShellLookupUsed; 00105 00106 PairToIndex *m_PairToIndex; 00107 int m_PairToIndexAllocated; 00108 int m_PairToIndexUsed; 00109 00110 void AddOneIndexToPair (int bigIndex, int littleIndex); 00111 void RemoveOneTranslation (HC_KEY key, int littleIndex); 00112 void RemoveTranslations (HC_KEY key, int face_list_length, const int *face_list); 00113 00114 static void AddOneTranslation (void *arg1, void *arg2, void *arg3); 00115 public: 00116 HIndexManager (bool needPairToIndex, bool needIndexToPair); 00117 virtual ~HIndexManager (); 00118 00128 HC_KEY KInsertShell (int point_count, const HPoint *points, int face_list_length, const int *face_list); 00129 00134 void DeleteByKey (HC_KEY key); 00135 00136 void EditShellPoints (HC_KEY key, int littleIndexOffset, int ndelete, int insert, const HPoint *points); 00137 00140 void EditShellFaces (HC_KEY key, int ioffset, int ndelete, int insert_list_length, const int *insert_list) { 00141 HC_Edit_Shell_Faces (key, ioffset, ndelete, insert_list_length, insert_list); 00142 } 00143 00145 int GetPairCount (int bigIndex) const; 00152 bool GetPair (int bigIndex, int n, HC_KEY *key, int *littleIndex) const; 00158 bool GetPairs (int bigIndex, HC_KEY *keys, int *littleIndices) const; 00160 bool GetIndex (HC_KEY key, int littleIndex, int *bigIndex) const; 00161 }; 00162 00163 00164 00165 #ifdef H_PACK_8 00166 #pragma pack(pop) 00167 #endif 00168 00169 #endif 00170 00171 00172 00173 00174 00175