btTriangleInfoMap.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2010 Erwin Coumans  http://bulletphysics.org
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
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_maxEdgeAngleThreshold; //ignore edges that connect triangles at an angle larger than this m_maxEdgeAngleThreshold
00065         btScalar        m_zeroAreaThreshold; 
00066         
00067         
00068         btTriangleInfoMap()
00069         {
00070                 m_convexEpsilon = 0.00f;
00071                 m_planarEpsilon = 0.0001f;
00072                 m_equalVertexThreshold = btScalar(0.0001)*btScalar(0.0001);
00073                 m_edgeDistanceThreshold = btScalar(0.1);
00074                 m_zeroAreaThreshold = btScalar(0.0001)*btScalar(0.0001);
00075                 m_maxEdgeAngleThreshold = SIMD_2_PI;
00076         }
00077         virtual ~btTriangleInfoMap() {}
00078 
00079         virtual int     calculateSerializeBufferSize() const;
00080 
00082         virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
00083 
00084         void    deSerialize(struct btTriangleInfoMapData& data);
00085 
00086 };
00087 
00088 struct  btTriangleInfoData
00089 {
00090         int                     m_flags;
00091         float   m_edgeV0V1Angle;
00092         float   m_edgeV1V2Angle;
00093         float   m_edgeV2V0Angle;
00094 };
00095 
00096 struct  btTriangleInfoMapData
00097 {
00098         int                                     *m_hashTablePtr;
00099         int                                     *m_nextPtr;
00100         btTriangleInfoData      *m_valueArrayPtr;
00101         int                                     *m_keyArrayPtr;
00102 
00103         float   m_convexEpsilon;
00104         float   m_planarEpsilon;
00105         float   m_equalVertexThreshold; 
00106         float   m_edgeDistanceThreshold;
00107         float   m_zeroAreaThreshold;
00108 
00109         int             m_nextSize;
00110         int             m_hashTableSize;
00111         int             m_numValues;
00112         int             m_numKeys;
00113         char    m_padding[4];
00114 };
00115 
00116 SIMD_FORCE_INLINE       int     btTriangleInfoMap::calculateSerializeBufferSize() const
00117 {
00118         return sizeof(btTriangleInfoMapData);
00119 }
00120 
00122 SIMD_FORCE_INLINE       const char*     btTriangleInfoMap::serialize(void* dataBuffer, btSerializer* serializer) const
00123 {
00124         btTriangleInfoMapData* tmapData = (btTriangleInfoMapData*) dataBuffer;
00125         tmapData->m_convexEpsilon = m_convexEpsilon;
00126         tmapData->m_planarEpsilon = m_planarEpsilon;
00127         tmapData->m_equalVertexThreshold = m_equalVertexThreshold;
00128         tmapData->m_edgeDistanceThreshold = m_edgeDistanceThreshold;
00129         tmapData->m_zeroAreaThreshold = m_zeroAreaThreshold;
00130         
00131         tmapData->m_hashTableSize = m_hashTable.size();
00132 
00133         tmapData->m_hashTablePtr = tmapData->m_hashTableSize ? (int*)serializer->getUniquePointer((void*)&m_hashTable[0]) : 0;
00134         if (tmapData->m_hashTablePtr)
00135         { 
00136                 //serialize an int buffer
00137                 int sz = sizeof(int);
00138                 int numElem = tmapData->m_hashTableSize;
00139                 btChunk* chunk = serializer->allocate(sz,numElem);
00140                 int* memPtr = (int*)chunk->m_oldPtr;
00141                 for (int i=0;i<numElem;i++,memPtr++)
00142                 {
00143                         *memPtr = m_hashTable[i];
00144                 }
00145                 serializer->finalizeChunk(chunk,"int",BT_ARRAY_CODE,(void*)&m_hashTable[0]);
00146 
00147         }
00148 
00149         tmapData->m_nextSize = m_next.size();
00150         tmapData->m_nextPtr = tmapData->m_nextSize? (int*)serializer->getUniquePointer((void*)&m_next[0]): 0;
00151         if (tmapData->m_nextPtr)
00152         {
00153                 int sz = sizeof(int);
00154                 int numElem = tmapData->m_nextSize;
00155                 btChunk* chunk = serializer->allocate(sz,numElem);
00156                 int* memPtr = (int*)chunk->m_oldPtr;
00157                 for (int i=0;i<numElem;i++,memPtr++)
00158                 {
00159                         *memPtr = m_next[i];
00160                 }
00161                 serializer->finalizeChunk(chunk,"int",BT_ARRAY_CODE,(void*)&m_next[0]);
00162         }
00163         
00164         tmapData->m_numValues = m_valueArray.size();
00165         tmapData->m_valueArrayPtr = tmapData->m_numValues ? (btTriangleInfoData*)serializer->getUniquePointer((void*)&m_valueArray[0]): 0;
00166         if (tmapData->m_valueArrayPtr)
00167         {
00168                 int sz = sizeof(btTriangleInfoData);
00169                 int numElem = tmapData->m_numValues;
00170                 btChunk* chunk = serializer->allocate(sz,numElem);
00171                 btTriangleInfoData* memPtr = (btTriangleInfoData*)chunk->m_oldPtr;
00172                 for (int i=0;i<numElem;i++,memPtr++)
00173                 {
00174                         memPtr->m_edgeV0V1Angle = m_valueArray[i].m_edgeV0V1Angle;
00175                         memPtr->m_edgeV1V2Angle = m_valueArray[i].m_edgeV1V2Angle;
00176                         memPtr->m_edgeV2V0Angle = m_valueArray[i].m_edgeV2V0Angle;
00177                         memPtr->m_flags = m_valueArray[i].m_flags;
00178                 }
00179                 serializer->finalizeChunk(chunk,"btTriangleInfoData",BT_ARRAY_CODE,(void*) &m_valueArray[0]);
00180         }
00181         
00182         tmapData->m_numKeys = m_keyArray.size();
00183         tmapData->m_keyArrayPtr = tmapData->m_numKeys ? (int*)serializer->getUniquePointer((void*)&m_keyArray[0]) : 0;
00184         if (tmapData->m_keyArrayPtr)
00185         {
00186                 int sz = sizeof(int);
00187                 int numElem = tmapData->m_numValues;
00188                 btChunk* chunk = serializer->allocate(sz,numElem);
00189                 int* memPtr = (int*)chunk->m_oldPtr;
00190                 for (int i=0;i<numElem;i++,memPtr++)
00191                 {
00192                         *memPtr = m_keyArray[i].getUid1();
00193                 }
00194                 serializer->finalizeChunk(chunk,"int",BT_ARRAY_CODE,(void*) &m_keyArray[0]);
00195 
00196         }
00197         return "btTriangleInfoMapData";
00198 }
00199 
00200 
00201 
00203 SIMD_FORCE_INLINE       void    btTriangleInfoMap::deSerialize(btTriangleInfoMapData& tmapData )
00204 {
00205 
00206 
00207         m_convexEpsilon = tmapData.m_convexEpsilon;
00208         m_planarEpsilon = tmapData.m_planarEpsilon;
00209         m_equalVertexThreshold = tmapData.m_equalVertexThreshold;
00210         m_edgeDistanceThreshold = tmapData.m_edgeDistanceThreshold;
00211         m_zeroAreaThreshold = tmapData.m_zeroAreaThreshold;
00212         m_hashTable.resize(tmapData.m_hashTableSize);
00213         int i =0;
00214         for (i=0;i<tmapData.m_hashTableSize;i++)
00215         {
00216                 m_hashTable[i] = tmapData.m_hashTablePtr[i];
00217         }
00218         m_next.resize(tmapData.m_nextSize);
00219         for (i=0;i<tmapData.m_nextSize;i++)
00220         {
00221                 m_next[i] = tmapData.m_nextPtr[i];
00222         }
00223         m_valueArray.resize(tmapData.m_numValues);
00224         for (i=0;i<tmapData.m_numValues;i++)
00225         {
00226                 m_valueArray[i].m_edgeV0V1Angle = tmapData.m_valueArrayPtr[i].m_edgeV0V1Angle;
00227                 m_valueArray[i].m_edgeV1V2Angle = tmapData.m_valueArrayPtr[i].m_edgeV1V2Angle;
00228                 m_valueArray[i].m_edgeV2V0Angle = tmapData.m_valueArrayPtr[i].m_edgeV2V0Angle;
00229                 m_valueArray[i].m_flags = tmapData.m_valueArrayPtr[i].m_flags;
00230         }
00231         
00232         m_keyArray.resize(tmapData.m_numKeys,btHashInt(0));
00233         for (i=0;i<tmapData.m_numKeys;i++)
00234         {
00235                 m_keyArray[i].setUid1(tmapData.m_keyArrayPtr[i]);
00236         }
00237 }
00238 
00239 
00240 #endif //_BT_TRIANGLE_INFO_MAP_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


bullet
Author(s): Erwin Coumans, ROS package maintained by Tully Foote
autogenerated on Wed Oct 31 2012 07:54:31