00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _BT_TRIANGLE_INFO_MAP_H
00017 #define _BT_TRIANGLE_INFO_MAP_H
00018
00019
00020 #include "LinearMath/btHashMap.h"
00021 #include "LinearMath/btSerializer.h"
00022
00023
00025 #define TRI_INFO_V0V1_CONVEX 1
00026 #define TRI_INFO_V1V2_CONVEX 2
00027 #define TRI_INFO_V2V0_CONVEX 4
00028
00029 #define TRI_INFO_V0V1_SWAP_NORMALB 8
00030 #define TRI_INFO_V1V2_SWAP_NORMALB 16
00031 #define TRI_INFO_V2V0_SWAP_NORMALB 32
00032
00033
00036 struct btTriangleInfo
00037 {
00038 btTriangleInfo()
00039 {
00040 m_edgeV0V1Angle = SIMD_2_PI;
00041 m_edgeV1V2Angle = SIMD_2_PI;
00042 m_edgeV2V0Angle = SIMD_2_PI;
00043 m_flags=0;
00044 }
00045
00046 int m_flags;
00047
00048 btScalar m_edgeV0V1Angle;
00049 btScalar m_edgeV1V2Angle;
00050 btScalar m_edgeV2V0Angle;
00051
00052 };
00053
00054 typedef btHashMap<btHashInt,btTriangleInfo> btInternalTriangleInfoMap;
00055
00056
00058 struct btTriangleInfoMap : public btInternalTriangleInfoMap
00059 {
00060 btScalar m_convexEpsilon;
00061 btScalar m_planarEpsilon;
00062 btScalar m_equalVertexThreshold;
00063 btScalar m_edgeDistanceThreshold;
00064 btScalar m_zeroAreaThreshold;
00065
00066
00067 btTriangleInfoMap()
00068 {
00069 m_convexEpsilon = 0.00f;
00070 m_planarEpsilon = 0.0001f;
00071 m_equalVertexThreshold = btScalar(0.0001)*btScalar(0.0001);
00072 m_edgeDistanceThreshold = btScalar(0.1);
00073 m_zeroAreaThreshold = btScalar(0.0001)*btScalar(0.0001);
00074 }
00075 virtual ~btTriangleInfoMap() {}
00076
00077 virtual int calculateSerializeBufferSize() const;
00078
00080 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
00081
00082 void deSerialize(struct btTriangleInfoMapData& data);
00083
00084 };
00085
00086 struct btTriangleInfoData
00087 {
00088 int m_flags;
00089 float m_edgeV0V1Angle;
00090 float m_edgeV1V2Angle;
00091 float m_edgeV2V0Angle;
00092 };
00093
00094 struct btTriangleInfoMapData
00095 {
00096 int *m_hashTablePtr;
00097 int *m_nextPtr;
00098 btTriangleInfoData *m_valueArrayPtr;
00099 int *m_keyArrayPtr;
00100
00101 float m_convexEpsilon;
00102 float m_planarEpsilon;
00103 float m_equalVertexThreshold;
00104 float m_edgeDistanceThreshold;
00105 float m_zeroAreaThreshold;
00106
00107 int m_nextSize;
00108 int m_hashTableSize;
00109 int m_numValues;
00110 int m_numKeys;
00111 char m_padding[4];
00112 };
00113
00114 SIMD_FORCE_INLINE int btTriangleInfoMap::calculateSerializeBufferSize() const
00115 {
00116 return sizeof(btTriangleInfoMapData);
00117 }
00118
00120 SIMD_FORCE_INLINE const char* btTriangleInfoMap::serialize(void* dataBuffer, btSerializer* serializer) const
00121 {
00122 btTriangleInfoMapData* tmapData = (btTriangleInfoMapData*) dataBuffer;
00123 tmapData->m_convexEpsilon = m_convexEpsilon;
00124 tmapData->m_planarEpsilon = m_planarEpsilon;
00125 tmapData->m_equalVertexThreshold = m_equalVertexThreshold;
00126 tmapData->m_edgeDistanceThreshold = m_edgeDistanceThreshold;
00127 tmapData->m_zeroAreaThreshold = m_zeroAreaThreshold;
00128
00129 tmapData->m_hashTableSize = m_hashTable.size();
00130 tmapData->m_hashTablePtr = tmapData->m_hashTableSize ? (int*)&m_hashTable[0] : 0;
00131 if (tmapData->m_hashTablePtr)
00132 {
00133
00134 int sz = sizeof(int);
00135 int numElem = tmapData->m_hashTableSize;
00136 btChunk* chunk = serializer->allocate(sz,numElem);
00137 int* memPtr = (int*)chunk->m_oldPtr;
00138 for (int i=0;i<numElem;i++,memPtr++)
00139 {
00140 *memPtr = m_hashTable[i];
00141 }
00142 serializer->finalizeChunk(chunk,"int",BT_ARRAY_CODE,(void*)&m_hashTable[0]);
00143
00144 }
00145
00146 tmapData->m_nextSize = m_next.size();
00147 tmapData->m_nextPtr = tmapData->m_nextSize? (int*)&m_next[0]: 0;
00148 if (tmapData->m_nextPtr)
00149 {
00150 int sz = sizeof(int);
00151 int numElem = tmapData->m_nextSize;
00152 btChunk* chunk = serializer->allocate(sz,numElem);
00153 int* memPtr = (int*)chunk->m_oldPtr;
00154 for (int i=0;i<numElem;i++,memPtr++)
00155 {
00156 *memPtr = m_next[i];
00157 }
00158 serializer->finalizeChunk(chunk,"int",BT_ARRAY_CODE,(void*)&m_next[0]);
00159 }
00160
00161 tmapData->m_numValues = m_valueArray.size();
00162 tmapData->m_valueArrayPtr = tmapData->m_numValues ? (btTriangleInfoData*)&m_valueArray[0]: 0;
00163 if (tmapData->m_valueArrayPtr)
00164 {
00165 int sz = sizeof(btTriangleInfoData);
00166 int numElem = tmapData->m_numValues;
00167 btChunk* chunk = serializer->allocate(sz,numElem);
00168 btTriangleInfoData* memPtr = (btTriangleInfoData*)chunk->m_oldPtr;
00169 for (int i=0;i<numElem;i++,memPtr++)
00170 {
00171 memPtr->m_edgeV0V1Angle = m_valueArray[i].m_edgeV0V1Angle;
00172 memPtr->m_edgeV1V2Angle = m_valueArray[i].m_edgeV1V2Angle;
00173 memPtr->m_edgeV2V0Angle = m_valueArray[i].m_edgeV2V0Angle;
00174 memPtr->m_flags = m_valueArray[i].m_flags;
00175 }
00176 serializer->finalizeChunk(chunk,"btTriangleInfoData",BT_ARRAY_CODE,(void*) &m_valueArray[0]);
00177 }
00178
00179 tmapData->m_numKeys = m_keyArray.size();
00180 tmapData->m_keyArrayPtr = tmapData->m_numKeys ? (int*)&m_keyArray[0] : 0;
00181 if (tmapData->m_keyArrayPtr)
00182 {
00183 int sz = sizeof(int);
00184 int numElem = tmapData->m_numValues;
00185 btChunk* chunk = serializer->allocate(sz,numElem);
00186 int* memPtr = (int*)chunk->m_oldPtr;
00187 for (int i=0;i<numElem;i++,memPtr++)
00188 {
00189 *memPtr = m_keyArray[i].getUid1();
00190 }
00191 serializer->finalizeChunk(chunk,"int",BT_ARRAY_CODE,(void*) &m_keyArray[0]);
00192
00193 }
00194 return "btTriangleInfoMapData";
00195 }
00196
00197
00198
00200 SIMD_FORCE_INLINE void btTriangleInfoMap::deSerialize(btTriangleInfoMapData& tmapData )
00201 {
00202
00203
00204 m_convexEpsilon = tmapData.m_convexEpsilon;
00205 m_planarEpsilon = tmapData.m_planarEpsilon;
00206 m_equalVertexThreshold = tmapData.m_equalVertexThreshold;
00207 m_edgeDistanceThreshold = tmapData.m_edgeDistanceThreshold;
00208 m_zeroAreaThreshold = tmapData.m_zeroAreaThreshold;
00209 m_hashTable.resize(tmapData.m_hashTableSize);
00210 int i =0;
00211 for (i=0;i<tmapData.m_hashTableSize;i++)
00212 {
00213 m_hashTable[i] = tmapData.m_hashTablePtr[i];
00214 }
00215 m_next.resize(tmapData.m_nextSize);
00216 for (i=0;i<tmapData.m_nextSize;i++)
00217 {
00218 m_next[i] = tmapData.m_nextPtr[i];
00219 }
00220 m_valueArray.resize(tmapData.m_numValues);
00221 for (i=0;i<tmapData.m_numValues;i++)
00222 {
00223 m_valueArray[i].m_edgeV0V1Angle = tmapData.m_valueArrayPtr[i].m_edgeV0V1Angle;
00224 m_valueArray[i].m_edgeV1V2Angle = tmapData.m_valueArrayPtr[i].m_edgeV1V2Angle;
00225 m_valueArray[i].m_edgeV2V0Angle = tmapData.m_valueArrayPtr[i].m_edgeV2V0Angle;
00226 m_valueArray[i].m_flags = tmapData.m_valueArrayPtr[i].m_flags;
00227 }
00228
00229 m_keyArray.resize(tmapData.m_numKeys,btHashInt(0));
00230 for (i=0;i<tmapData.m_numKeys;i++)
00231 {
00232 m_keyArray[i].setUid1(tmapData.m_keyArrayPtr[i]);
00233 }
00234 }
00235
00236
00237 #endif //_BT_TRIANGLE_INFO_MAP_H