From 2cf7806c87a46e1935b3c5db07a1a093e9b27fd3 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Wed, 7 May 2014 08:54:08 -0700 Subject: [PATCH] add the 'extras' and Bullet 2 tests, to make it easier to create a new intermediate release --- Extras/CMakeLists.txt | 7 + Extras/ConvexDecomposition/CMakeLists.txt | 64 + Extras/ConvexDecomposition/ConvexBuilder.cpp | 373 ++ Extras/ConvexDecomposition/ConvexBuilder.h | 112 + .../ConvexDecomposition.cpp | 375 ++ .../ConvexDecomposition/ConvexDecomposition.h | 220 ++ Extras/ConvexDecomposition/bestfit.cpp | 466 +++ Extras/ConvexDecomposition/bestfit.h | 65 + Extras/ConvexDecomposition/bestfitobb.cpp | 173 + Extras/ConvexDecomposition/bestfitobb.h | 43 + Extras/ConvexDecomposition/cd_hull.cpp | 3261 +++++++++++++++++ Extras/ConvexDecomposition/cd_hull.h | 153 + Extras/ConvexDecomposition/cd_vector.h | 1185 ++++++ Extras/ConvexDecomposition/cd_wavefront.cpp | 860 +++++ Extras/ConvexDecomposition/cd_wavefront.h | 62 + Extras/ConvexDecomposition/concavity.cpp | 795 ++++ Extras/ConvexDecomposition/concavity.h | 60 + Extras/ConvexDecomposition/fitsphere.cpp | 202 + Extras/ConvexDecomposition/fitsphere.h | 43 + Extras/ConvexDecomposition/float_math.cpp | 257 ++ Extras/ConvexDecomposition/float_math.h | 72 + Extras/ConvexDecomposition/meshvolume.cpp | 128 + Extras/ConvexDecomposition/meshvolume.h | 45 + Extras/ConvexDecomposition/planetri.cpp | 238 ++ Extras/ConvexDecomposition/planetri.h | 58 + Extras/ConvexDecomposition/premake4.lua | 9 + Extras/ConvexDecomposition/raytri.cpp | 134 + Extras/ConvexDecomposition/raytri.h | 45 + Extras/ConvexDecomposition/splitplane.cpp | 306 ++ Extras/ConvexDecomposition/splitplane.h | 59 + Extras/ConvexDecomposition/vlookup.cpp | 326 ++ Extras/ConvexDecomposition/vlookup.h | 119 + Extras/GIMPACTUtils/CMakeLists.txt | 37 + .../btGImpactConvexDecompositionShape.cpp | 240 ++ .../btGImpactConvexDecompositionShape.h | 87 + Extras/HACD/CMakeLists.txt | 51 + Extras/HACD/hacdCircularList.h | 80 + Extras/HACD/hacdCircularList.inl | 163 + Extras/HACD/hacdGraph.cpp | 292 ++ Extras/HACD/hacdGraph.h | 120 + Extras/HACD/hacdHACD.cpp | 847 +++++ Extras/HACD/hacdHACD.h | 282 ++ Extras/HACD/hacdICHull.cpp | 1010 +++++ Extras/HACD/hacdICHull.h | 120 + Extras/HACD/hacdManifoldMesh.cpp | 577 +++ Extras/HACD/hacdManifoldMesh.h | 250 ++ Extras/HACD/hacdVector.h | 67 + Extras/HACD/hacdVector.inl | 178 + Extras/HACD/hacdVersion.h | 20 + Extras/HACD/premake4.lua | 9 + Extras/Makefile.am | 95 + .../Serialize/BlenderSerialize/CMakeLists.txt | 7 + .../BlenderSerialize/bBlenderFile.cpp | 225 ++ .../Serialize/BlenderSerialize/bBlenderFile.h | 63 + Extras/Serialize/BlenderSerialize/bMain.cpp | 392 ++ Extras/Serialize/BlenderSerialize/bMain.h | 110 + .../BlenderSerialize/dna249-64bit.cpp | 1411 +++++++ Extras/Serialize/BlenderSerialize/dna249.cpp | 1411 +++++++ .../Serialize/BulletFileLoader/CMakeLists.txt | 49 + .../BulletFileLoader/autogenerated/bullet.h | 1228 +++++++ Extras/Serialize/BulletFileLoader/bChunk.cpp | 75 + Extras/Serialize/BulletFileLoader/bChunk.h | 92 + Extras/Serialize/BulletFileLoader/bCommon.h | 39 + Extras/Serialize/BulletFileLoader/bDNA.cpp | 644 ++++ Extras/Serialize/BulletFileLoader/bDNA.h | 110 + Extras/Serialize/BulletFileLoader/bDefines.h | 140 + Extras/Serialize/BulletFileLoader/bFile.cpp | 1757 +++++++++ Extras/Serialize/BulletFileLoader/bFile.h | 165 + .../BulletFileLoader/btBulletFile.cpp | 423 +++ .../Serialize/BulletFileLoader/btBulletFile.h | 83 + .../Serialize/BulletFileLoader/premake4.lua | 12 + .../BulletWorldImporter/CMakeLists.txt | 40 + .../btBulletWorldImporter.cpp | 362 ++ .../btBulletWorldImporter.h | 68 + .../BulletWorldImporter/btWorldImporter.cpp | 1922 ++++++++++ .../BulletWorldImporter/btWorldImporter.h | 212 ++ .../BulletWorldImporter/premake4.lua | 13 + .../BulletXmlWorldImporter/CMakeLists.txt | 47 + .../btBulletXmlWorldImporter.cpp | 871 +++++ .../btBulletXmlWorldImporter.h | 87 + .../BulletXmlWorldImporter/premake4.lua | 14 + .../BulletXmlWorldImporter/string_split.cpp | 250 ++ .../BulletXmlWorldImporter/string_split.h | 49 + .../BulletXmlWorldImporter/tinystr.cpp | 111 + .../BulletXmlWorldImporter/tinystr.h | 305 ++ .../BulletXmlWorldImporter/tinyxml.cpp | 1886 ++++++++++ .../BulletXmlWorldImporter/tinyxml.h | 1805 +++++++++ .../BulletXmlWorldImporter/tinyxmlerror.cpp | 52 + .../BulletXmlWorldImporter/tinyxmlparser.cpp | 1638 +++++++++ Extras/Serialize/CMakeLists.txt | 20 + .../Serialize/HeaderGenerator/CMakeLists.txt | 32 + Extras/Serialize/HeaderGenerator/apiGen.cpp | 464 +++ .../HeaderGenerator/blenderGenerate.py | 111 + .../HeaderGenerator/bulletGenerate.py | 83 + .../HeaderGenerator/createDnaString.bat | 7 + .../ReadBulletSample/BulletDataExtractor.cpp | 345 ++ .../ReadBulletSample/BulletDataExtractor.h | 32 + .../Serialize/ReadBulletSample/CMakeLists.txt | 33 + Extras/Serialize/ReadBulletSample/main.cpp | 63 + Extras/Serialize/makesdna/CMakeLists.txt | 37 + Extras/Serialize/makesdna/DNA_rigidbody.h | 29 + Extras/Serialize/makesdna/makesdna.cpp | 1255 +++++++ Extras/premake4.lua | 8 + test/Bullet2/Info.plist | 47 + test/Bullet2/README.txt | 28 + test/Bullet2/Source/TestList.cpp | 97 + test/Bullet2/Source/TestList.h | 28 + test/Bullet2/Source/Tests/Test_3x3getRot.cpp | 158 + test/Bullet2/Source/Tests/Test_3x3getRot.h | 22 + test/Bullet2/Source/Tests/Test_3x3mulM.cpp | 169 + test/Bullet2/Source/Tests/Test_3x3mulM.h | 22 + test/Bullet2/Source/Tests/Test_3x3mulM1M2.cpp | 164 + test/Bullet2/Source/Tests/Test_3x3mulM1M2.h | 22 + test/Bullet2/Source/Tests/Test_3x3mulMV.cpp | 112 + test/Bullet2/Source/Tests/Test_3x3mulMV.h | 23 + test/Bullet2/Source/Tests/Test_3x3mulVM.cpp | 112 + test/Bullet2/Source/Tests/Test_3x3mulVM.h | 22 + test/Bullet2/Source/Tests/Test_3x3setRot.cpp | 171 + test/Bullet2/Source/Tests/Test_3x3setRot.h | 22 + .../Source/Tests/Test_3x3timesTranspose.cpp | 117 + .../Source/Tests/Test_3x3timesTranspose.h | 22 + .../Source/Tests/Test_3x3transpose.cpp | 116 + test/Bullet2/Source/Tests/Test_3x3transpose.h | 22 + .../Source/Tests/Test_3x3transposeTimes.cpp | 168 + .../Source/Tests/Test_3x3transposeTimes.h | 22 + test/Bullet2/Source/Tests/Test_btDbvt.cpp | 495 +++ test/Bullet2/Source/Tests/Test_btDbvt.h | 21 + test/Bullet2/Source/Tests/Test_dot3.cpp | 153 + test/Bullet2/Source/Tests/Test_dot3.h | 22 + test/Bullet2/Source/Tests/Test_maxdot.cpp | 281 ++ test/Bullet2/Source/Tests/Test_maxdot.h | 22 + test/Bullet2/Source/Tests/Test_mindot.cpp | 269 ++ test/Bullet2/Source/Tests/Test_mindot.h | 22 + test/Bullet2/Source/Tests/Test_qtdot.cpp | 162 + test/Bullet2/Source/Tests/Test_qtdot.h | 22 + test/Bullet2/Source/Tests/Test_qtmul.cpp | 183 + test/Bullet2/Source/Tests/Test_qtmul.h | 22 + test/Bullet2/Source/Tests/Test_qtmulQV3.cpp | 162 + test/Bullet2/Source/Tests/Test_qtmulQV3.h | 22 + test/Bullet2/Source/Tests/Test_qtmulV3Q.cpp | 161 + test/Bullet2/Source/Tests/Test_qtmulV3Q.h | 22 + test/Bullet2/Source/Tests/Test_qtnorm.cpp | 176 + test/Bullet2/Source/Tests/Test_qtnorm.h | 22 + .../Source/Tests/Test_quat_aos_neon.cpp | 599 +++ .../Bullet2/Source/Tests/Test_quat_aos_neon.h | 21 + test/Bullet2/Source/Tests/Test_v3cross.cpp | 181 + test/Bullet2/Source/Tests/Test_v3cross.h | 22 + test/Bullet2/Source/Tests/Test_v3div.cpp | 178 + test/Bullet2/Source/Tests/Test_v3div.h | 22 + test/Bullet2/Source/Tests/Test_v3dot.cpp | 164 + test/Bullet2/Source/Tests/Test_v3dot.h | 22 + test/Bullet2/Source/Tests/Test_v3interp.cpp | 195 + test/Bullet2/Source/Tests/Test_v3interp.h | 22 + test/Bullet2/Source/Tests/Test_v3lerp.cpp | 198 + test/Bullet2/Source/Tests/Test_v3lerp.h | 22 + test/Bullet2/Source/Tests/Test_v3norm.cpp | 170 + test/Bullet2/Source/Tests/Test_v3norm.h | 22 + test/Bullet2/Source/Tests/Test_v3rotate.cpp | 194 + test/Bullet2/Source/Tests/Test_v3rotate.h | 22 + test/Bullet2/Source/Tests/Test_v3sdiv.cpp | 181 + test/Bullet2/Source/Tests/Test_v3sdiv.h | 22 + test/Bullet2/Source/Tests/Test_v3skew.cpp | 197 + test/Bullet2/Source/Tests/Test_v3skew.h | 22 + test/Bullet2/Source/Tests/Test_v3triple.cpp | 180 + test/Bullet2/Source/Tests/Test_v3triple.h | 22 + test/Bullet2/Source/Utils.cpp | 272 ++ test/Bullet2/Source/Utils.h | 72 + test/Bullet2/Source/btIntDefines.h | 19 + test/Bullet2/Source/main.cpp | 326 ++ test/Bullet2/Source/main.h | 25 + test/Bullet2/Source/vector.h | 70 + test/Bullet2/premake4.lua | 23 + 172 files changed, 42937 insertions(+) create mode 100644 Extras/CMakeLists.txt create mode 100644 Extras/ConvexDecomposition/CMakeLists.txt create mode 100644 Extras/ConvexDecomposition/ConvexBuilder.cpp create mode 100644 Extras/ConvexDecomposition/ConvexBuilder.h create mode 100644 Extras/ConvexDecomposition/ConvexDecomposition.cpp create mode 100644 Extras/ConvexDecomposition/ConvexDecomposition.h create mode 100644 Extras/ConvexDecomposition/bestfit.cpp create mode 100644 Extras/ConvexDecomposition/bestfit.h create mode 100644 Extras/ConvexDecomposition/bestfitobb.cpp create mode 100644 Extras/ConvexDecomposition/bestfitobb.h create mode 100644 Extras/ConvexDecomposition/cd_hull.cpp create mode 100644 Extras/ConvexDecomposition/cd_hull.h create mode 100644 Extras/ConvexDecomposition/cd_vector.h create mode 100644 Extras/ConvexDecomposition/cd_wavefront.cpp create mode 100644 Extras/ConvexDecomposition/cd_wavefront.h create mode 100644 Extras/ConvexDecomposition/concavity.cpp create mode 100644 Extras/ConvexDecomposition/concavity.h create mode 100644 Extras/ConvexDecomposition/fitsphere.cpp create mode 100644 Extras/ConvexDecomposition/fitsphere.h create mode 100644 Extras/ConvexDecomposition/float_math.cpp create mode 100644 Extras/ConvexDecomposition/float_math.h create mode 100644 Extras/ConvexDecomposition/meshvolume.cpp create mode 100644 Extras/ConvexDecomposition/meshvolume.h create mode 100644 Extras/ConvexDecomposition/planetri.cpp create mode 100644 Extras/ConvexDecomposition/planetri.h create mode 100644 Extras/ConvexDecomposition/premake4.lua create mode 100644 Extras/ConvexDecomposition/raytri.cpp create mode 100644 Extras/ConvexDecomposition/raytri.h create mode 100644 Extras/ConvexDecomposition/splitplane.cpp create mode 100644 Extras/ConvexDecomposition/splitplane.h create mode 100644 Extras/ConvexDecomposition/vlookup.cpp create mode 100644 Extras/ConvexDecomposition/vlookup.h create mode 100644 Extras/GIMPACTUtils/CMakeLists.txt create mode 100644 Extras/GIMPACTUtils/btGImpactConvexDecompositionShape.cpp create mode 100644 Extras/GIMPACTUtils/btGImpactConvexDecompositionShape.h create mode 100644 Extras/HACD/CMakeLists.txt create mode 100644 Extras/HACD/hacdCircularList.h create mode 100644 Extras/HACD/hacdCircularList.inl create mode 100644 Extras/HACD/hacdGraph.cpp create mode 100644 Extras/HACD/hacdGraph.h create mode 100644 Extras/HACD/hacdHACD.cpp create mode 100644 Extras/HACD/hacdHACD.h create mode 100644 Extras/HACD/hacdICHull.cpp create mode 100644 Extras/HACD/hacdICHull.h create mode 100644 Extras/HACD/hacdManifoldMesh.cpp create mode 100644 Extras/HACD/hacdManifoldMesh.h create mode 100644 Extras/HACD/hacdVector.h create mode 100644 Extras/HACD/hacdVector.inl create mode 100644 Extras/HACD/hacdVersion.h create mode 100644 Extras/HACD/premake4.lua create mode 100644 Extras/Makefile.am create mode 100644 Extras/Serialize/BlenderSerialize/CMakeLists.txt create mode 100644 Extras/Serialize/BlenderSerialize/bBlenderFile.cpp create mode 100644 Extras/Serialize/BlenderSerialize/bBlenderFile.h create mode 100644 Extras/Serialize/BlenderSerialize/bMain.cpp create mode 100644 Extras/Serialize/BlenderSerialize/bMain.h create mode 100644 Extras/Serialize/BlenderSerialize/dna249-64bit.cpp create mode 100644 Extras/Serialize/BlenderSerialize/dna249.cpp create mode 100644 Extras/Serialize/BulletFileLoader/CMakeLists.txt create mode 100644 Extras/Serialize/BulletFileLoader/autogenerated/bullet.h create mode 100644 Extras/Serialize/BulletFileLoader/bChunk.cpp create mode 100644 Extras/Serialize/BulletFileLoader/bChunk.h create mode 100644 Extras/Serialize/BulletFileLoader/bCommon.h create mode 100644 Extras/Serialize/BulletFileLoader/bDNA.cpp create mode 100644 Extras/Serialize/BulletFileLoader/bDNA.h create mode 100644 Extras/Serialize/BulletFileLoader/bDefines.h create mode 100644 Extras/Serialize/BulletFileLoader/bFile.cpp create mode 100644 Extras/Serialize/BulletFileLoader/bFile.h create mode 100644 Extras/Serialize/BulletFileLoader/btBulletFile.cpp create mode 100644 Extras/Serialize/BulletFileLoader/btBulletFile.h create mode 100644 Extras/Serialize/BulletFileLoader/premake4.lua create mode 100644 Extras/Serialize/BulletWorldImporter/CMakeLists.txt create mode 100644 Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp create mode 100644 Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h create mode 100644 Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp create mode 100644 Extras/Serialize/BulletWorldImporter/btWorldImporter.h create mode 100644 Extras/Serialize/BulletWorldImporter/premake4.lua create mode 100644 Extras/Serialize/BulletXmlWorldImporter/CMakeLists.txt create mode 100644 Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.cpp create mode 100644 Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.h create mode 100644 Extras/Serialize/BulletXmlWorldImporter/premake4.lua create mode 100644 Extras/Serialize/BulletXmlWorldImporter/string_split.cpp create mode 100644 Extras/Serialize/BulletXmlWorldImporter/string_split.h create mode 100644 Extras/Serialize/BulletXmlWorldImporter/tinystr.cpp create mode 100644 Extras/Serialize/BulletXmlWorldImporter/tinystr.h create mode 100644 Extras/Serialize/BulletXmlWorldImporter/tinyxml.cpp create mode 100644 Extras/Serialize/BulletXmlWorldImporter/tinyxml.h create mode 100644 Extras/Serialize/BulletXmlWorldImporter/tinyxmlerror.cpp create mode 100644 Extras/Serialize/BulletXmlWorldImporter/tinyxmlparser.cpp create mode 100644 Extras/Serialize/CMakeLists.txt create mode 100644 Extras/Serialize/HeaderGenerator/CMakeLists.txt create mode 100644 Extras/Serialize/HeaderGenerator/apiGen.cpp create mode 100644 Extras/Serialize/HeaderGenerator/blenderGenerate.py create mode 100644 Extras/Serialize/HeaderGenerator/bulletGenerate.py create mode 100644 Extras/Serialize/HeaderGenerator/createDnaString.bat create mode 100644 Extras/Serialize/ReadBulletSample/BulletDataExtractor.cpp create mode 100644 Extras/Serialize/ReadBulletSample/BulletDataExtractor.h create mode 100644 Extras/Serialize/ReadBulletSample/CMakeLists.txt create mode 100644 Extras/Serialize/ReadBulletSample/main.cpp create mode 100644 Extras/Serialize/makesdna/CMakeLists.txt create mode 100644 Extras/Serialize/makesdna/DNA_rigidbody.h create mode 100644 Extras/Serialize/makesdna/makesdna.cpp create mode 100644 Extras/premake4.lua create mode 100644 test/Bullet2/Info.plist create mode 100644 test/Bullet2/README.txt create mode 100644 test/Bullet2/Source/TestList.cpp create mode 100644 test/Bullet2/Source/TestList.h create mode 100644 test/Bullet2/Source/Tests/Test_3x3getRot.cpp create mode 100644 test/Bullet2/Source/Tests/Test_3x3getRot.h create mode 100644 test/Bullet2/Source/Tests/Test_3x3mulM.cpp create mode 100644 test/Bullet2/Source/Tests/Test_3x3mulM.h create mode 100644 test/Bullet2/Source/Tests/Test_3x3mulM1M2.cpp create mode 100644 test/Bullet2/Source/Tests/Test_3x3mulM1M2.h create mode 100644 test/Bullet2/Source/Tests/Test_3x3mulMV.cpp create mode 100644 test/Bullet2/Source/Tests/Test_3x3mulMV.h create mode 100644 test/Bullet2/Source/Tests/Test_3x3mulVM.cpp create mode 100644 test/Bullet2/Source/Tests/Test_3x3mulVM.h create mode 100644 test/Bullet2/Source/Tests/Test_3x3setRot.cpp create mode 100644 test/Bullet2/Source/Tests/Test_3x3setRot.h create mode 100644 test/Bullet2/Source/Tests/Test_3x3timesTranspose.cpp create mode 100644 test/Bullet2/Source/Tests/Test_3x3timesTranspose.h create mode 100644 test/Bullet2/Source/Tests/Test_3x3transpose.cpp create mode 100644 test/Bullet2/Source/Tests/Test_3x3transpose.h create mode 100644 test/Bullet2/Source/Tests/Test_3x3transposeTimes.cpp create mode 100644 test/Bullet2/Source/Tests/Test_3x3transposeTimes.h create mode 100644 test/Bullet2/Source/Tests/Test_btDbvt.cpp create mode 100644 test/Bullet2/Source/Tests/Test_btDbvt.h create mode 100644 test/Bullet2/Source/Tests/Test_dot3.cpp create mode 100644 test/Bullet2/Source/Tests/Test_dot3.h create mode 100644 test/Bullet2/Source/Tests/Test_maxdot.cpp create mode 100644 test/Bullet2/Source/Tests/Test_maxdot.h create mode 100644 test/Bullet2/Source/Tests/Test_mindot.cpp create mode 100644 test/Bullet2/Source/Tests/Test_mindot.h create mode 100644 test/Bullet2/Source/Tests/Test_qtdot.cpp create mode 100644 test/Bullet2/Source/Tests/Test_qtdot.h create mode 100644 test/Bullet2/Source/Tests/Test_qtmul.cpp create mode 100644 test/Bullet2/Source/Tests/Test_qtmul.h create mode 100644 test/Bullet2/Source/Tests/Test_qtmulQV3.cpp create mode 100644 test/Bullet2/Source/Tests/Test_qtmulQV3.h create mode 100644 test/Bullet2/Source/Tests/Test_qtmulV3Q.cpp create mode 100644 test/Bullet2/Source/Tests/Test_qtmulV3Q.h create mode 100644 test/Bullet2/Source/Tests/Test_qtnorm.cpp create mode 100644 test/Bullet2/Source/Tests/Test_qtnorm.h create mode 100644 test/Bullet2/Source/Tests/Test_quat_aos_neon.cpp create mode 100644 test/Bullet2/Source/Tests/Test_quat_aos_neon.h create mode 100644 test/Bullet2/Source/Tests/Test_v3cross.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3cross.h create mode 100644 test/Bullet2/Source/Tests/Test_v3div.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3div.h create mode 100644 test/Bullet2/Source/Tests/Test_v3dot.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3dot.h create mode 100644 test/Bullet2/Source/Tests/Test_v3interp.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3interp.h create mode 100644 test/Bullet2/Source/Tests/Test_v3lerp.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3lerp.h create mode 100644 test/Bullet2/Source/Tests/Test_v3norm.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3norm.h create mode 100644 test/Bullet2/Source/Tests/Test_v3rotate.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3rotate.h create mode 100644 test/Bullet2/Source/Tests/Test_v3sdiv.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3sdiv.h create mode 100644 test/Bullet2/Source/Tests/Test_v3skew.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3skew.h create mode 100644 test/Bullet2/Source/Tests/Test_v3triple.cpp create mode 100644 test/Bullet2/Source/Tests/Test_v3triple.h create mode 100644 test/Bullet2/Source/Utils.cpp create mode 100644 test/Bullet2/Source/Utils.h create mode 100644 test/Bullet2/Source/btIntDefines.h create mode 100644 test/Bullet2/Source/main.cpp create mode 100644 test/Bullet2/Source/main.h create mode 100644 test/Bullet2/Source/vector.h create mode 100644 test/Bullet2/premake4.lua diff --git a/Extras/CMakeLists.txt b/Extras/CMakeLists.txt new file mode 100644 index 0000000000..a92f647208 --- /dev/null +++ b/Extras/CMakeLists.txt @@ -0,0 +1,7 @@ +SUBDIRS( Serialize ConvexDecomposition HACD GIMPACTUtils ) + +#Maya Dynamica plugin is moved to http://dynamica.googlecode.com + +IF (USE_GLUT AND GLUT_FOUND) + SUBDIRS (glui) +ENDIF () diff --git a/Extras/ConvexDecomposition/CMakeLists.txt b/Extras/ConvexDecomposition/CMakeLists.txt new file mode 100644 index 0000000000..693e9d26a4 --- /dev/null +++ b/Extras/ConvexDecomposition/CMakeLists.txt @@ -0,0 +1,64 @@ +INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexDecomposition ${BULLET_PHYSICS_SOURCE_DIR}/src +) + +SET(ConvexDecomposition_SRCS + bestfitobb.cpp + ConvexBuilder.cpp + cd_wavefront.cpp + fitsphere.cpp + meshvolume.cpp + raytri.cpp + vlookup.cpp + bestfit.cpp + cd_hull.cpp + ConvexDecomposition.cpp + concavity.cpp + float_math.cpp + planetri.cpp + splitplane.cpp +) + +SET(ConvexDecomposition_HDRS + ConvexDecomposition.h + cd_vector.h + concavity.h + bestfitobb.h + ConvexBuilder.h + cd_wavefront.h + fitsphere.h + meshvolume.h + raytri.h + vlookup.h + bestfit.h + cd_hull.h +) + +ADD_LIBRARY(ConvexDecomposition ${ConvexDecomposition_SRCS} ${ConvexDecomposition_HDRS}) +SET_TARGET_PROPERTIES(ConvexDecomposition PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(ConvexDecomposition PROPERTIES SOVERSION ${BULLET_VERSION}) + +IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(ConvexDecomposition BulletCollision LinearMath) +ENDIF (BUILD_SHARED_LIBS) + +IF (INSTALL_EXTRA_LIBS) + IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) + #FILES_MATCHING requires CMake 2.6 + IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS ConvexDecomposition DESTINATION .) + ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS ConvexDecomposition DESTINATION lib${LIB_SUFFIX}) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN +".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE) + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + SET_TARGET_PROPERTIES(ConvexDecomposition PROPERTIES FRAMEWORK true) + SET_TARGET_PROPERTIES(ConvexDecomposition PROPERTIES PUBLIC_HEADER "${ConvexDecomposition_HDRS}") + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) +ENDIF (INSTALL_EXTRA_LIBS) diff --git a/Extras/ConvexDecomposition/ConvexBuilder.cpp b/Extras/ConvexDecomposition/ConvexBuilder.cpp new file mode 100644 index 0000000000..bf576af6f3 --- /dev/null +++ b/Extras/ConvexDecomposition/ConvexBuilder.cpp @@ -0,0 +1,373 @@ +#include "float_math.h" +#include "ConvexBuilder.h" +#include "meshvolume.h" +#include "bestfit.h" +#include +#include "cd_hull.h" + +#include "fitsphere.h" +#include "bestfitobb.h" + +unsigned int MAXDEPTH = 8 ; +float CONCAVE_PERCENT = 1.0f ; +float MERGE_PERCENT = 2.0f ; + +CHull::CHull(const ConvexResult &result) +{ + mResult = new ConvexResult(result); + mVolume = computeMeshVolume( result.mHullVertices, result.mHullTcount, result.mHullIndices ); + + mDiagonal = getBoundingRegion( result.mHullVcount, result.mHullVertices, sizeof(float)*3, mMin, mMax ); + + float dx = mMax[0] - mMin[0]; + float dy = mMax[1] - mMin[1]; + float dz = mMax[2] - mMin[2]; + + dx*=0.1f; // inflate 1/10th on each edge + dy*=0.1f; // inflate 1/10th on each edge + dz*=0.1f; // inflate 1/10th on each edge + + mMin[0]-=dx; + mMin[1]-=dy; + mMin[2]-=dz; + + mMax[0]+=dx; + mMax[1]+=dy; + mMax[2]+=dz; + + +} + +CHull::~CHull(void) +{ + delete mResult; +} + +bool CHull::overlap(const CHull &h) const +{ + return overlapAABB(mMin,mMax, h.mMin, h.mMax ); +} + + + + +ConvexBuilder::ConvexBuilder(ConvexDecompInterface *callback) +{ + mCallback = callback; +} + +ConvexBuilder::~ConvexBuilder(void) +{ + int i; + for (i=0;ioverlap(*b) ) return 0; // if their AABB's (with a little slop) don't overlap, then return. + + CHull *ret = 0; + + // ok..we are going to combine both meshes into a single mesh + // and then we are going to compute the concavity... + + VertexLookup vc = Vl_createVertexLookup(); + + UintVector indices; + + getMesh( *a->mResult, vc, indices ); + getMesh( *b->mResult, vc, indices ); + + unsigned int vcount = Vl_getVcount(vc); + const float *vertices = Vl_getVertices(vc); + unsigned int tcount = indices.size()/3; + + //don't do anything if hull is empty + if (!tcount) + { + Vl_releaseVertexLookup (vc); + return 0; + } + + HullResult hresult; + HullLibrary hl; + HullDesc desc; + + desc.SetHullFlag(QF_TRIANGLES); + + desc.mVcount = vcount; + desc.mVertices = vertices; + desc.mVertexStride = sizeof(float)*3; + + HullError hret = hl.CreateConvexHull(desc,hresult); + + if ( hret == QE_OK ) + { + + float combineVolume = computeMeshVolume( hresult.mOutputVertices, hresult.mNumFaces, hresult.mIndices ); + float sumVolume = a->mVolume + b->mVolume; + + float percent = (sumVolume*100) / combineVolume; + if ( percent >= (100.0f-MERGE_PERCENT) ) + { + ConvexResult cr(hresult.mNumOutputVertices, hresult.mOutputVertices, hresult.mNumFaces, hresult.mIndices); + ret = new CHull(cr); + } + } + + + Vl_releaseVertexLookup(vc); + + return ret; +} + +bool ConvexBuilder::combineHulls(void) +{ + + bool combine = false; + + sortChulls(mChulls); // sort the convex hulls, largest volume to least... + + CHullVector output; // the output hulls... + + + int i; + + for (i=0;imResult; // the high resolution hull... + + HullResult result; + HullLibrary hl; + HullDesc hdesc; + + hdesc.SetHullFlag(QF_TRIANGLES); + + hdesc.mVcount = c.mHullVcount; + hdesc.mVertices = c.mHullVertices; + hdesc.mVertexStride = sizeof(float)*3; + hdesc.mMaxVertices = desc.mMaxVertices; // maximum number of vertices allowed in the output + + if ( desc.mSkinWidth ) + { + hdesc.mSkinWidth = desc.mSkinWidth; + hdesc.SetHullFlag(QF_SKIN_WIDTH); // do skin width computation. + } + + HullError ret = hl.CreateConvexHull(hdesc,result); + + if ( ret == QE_OK ) + { + ConvexResult r(result.mNumOutputVertices, result.mOutputVertices, result.mNumFaces, result.mIndices); + + r.mHullVolume = computeMeshVolume( result.mOutputVertices, result.mNumFaces, result.mIndices ); // the volume of the hull. + + // compute the best fit OBB + computeBestFitOBB( result.mNumOutputVertices, result.mOutputVertices, sizeof(float)*3, r.mOBBSides, r.mOBBTransform ); + + r.mOBBVolume = r.mOBBSides[0] * r.mOBBSides[1] *r.mOBBSides[2]; // compute the OBB volume. + + fm_getTranslation( r.mOBBTransform, r.mOBBCenter ); // get the translation component of the 4x4 matrix. + + fm_matrixToQuat( r.mOBBTransform, r.mOBBOrientation ); // extract the orientation as a quaternion. + + r.mSphereRadius = computeBoundingSphere( result.mNumOutputVertices, result.mOutputVertices, r.mSphereCenter ); + r.mSphereVolume = fm_sphereVolume( r.mSphereRadius ); + + + mCallback->ConvexDecompResult(r); + } + + hl.ReleaseResult (result); + + + delete cr; + } + + ret = mChulls.size(); + + mChulls.clear(); + + return ret; +} + + +void ConvexBuilder::ConvexDebugTri(const float *p1,const float *p2,const float *p3,unsigned int color) +{ + mCallback->ConvexDebugTri(p1,p2,p3,color); +} + +void ConvexBuilder::ConvexDebugOBB(const float *sides, const float *matrix,unsigned int color) +{ + mCallback->ConvexDebugOBB(sides,matrix,color); +} +void ConvexBuilder::ConvexDebugPoint(const float *p,float dist,unsigned int color) +{ + mCallback->ConvexDebugPoint(p,dist,color); +} + +void ConvexBuilder::ConvexDebugBound(const float *bmin,const float *bmax,unsigned int color) +{ + mCallback->ConvexDebugBound(bmin,bmax,color); +} + +void ConvexBuilder::ConvexDecompResult(ConvexResult &result) +{ + CHull *ch = new CHull(result); + mChulls.push_back(ch); +} + +void ConvexBuilder::sortChulls(CHullVector &hulls) +{ + hulls.quickSort(CHullSort()); + //hulls.heapSort(CHullSort()); +} + + diff --git a/Extras/ConvexDecomposition/ConvexBuilder.h b/Extras/ConvexDecomposition/ConvexBuilder.h new file mode 100644 index 0000000000..b1d98cb67c --- /dev/null +++ b/Extras/ConvexDecomposition/ConvexBuilder.h @@ -0,0 +1,112 @@ +#ifndef CONVEX_BUILDER_H +#define CONVEX_BUILDER_H + +/*---------------------------------------------------------------------- +Copyright (c) 2004 Open Dynamics Framework Group +www.physicstools.org +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided +that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions +and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +Neither the name of the Open Dynamics Framework Group nor the names of its contributors may +be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + +#include "ConvexDecomposition.h" +#include "vlookup.h" +#include "LinearMath/btAlignedObjectArray.h" + +using namespace ConvexDecomposition; + + +class CHull +{ +public: + CHull(const ConvexResult &result); + + ~CHull(void); + + bool overlap(const CHull &h) const; + + float mMin[3]; + float mMax[3]; + float mVolume; + float mDiagonal; // long edge.. + ConvexResult *mResult; +}; + +// Usage: std::sort( list.begin(), list.end(), StringSortRef() ); +class CHullSort +{ +public: + + inline bool operator()(const CHull *a,const CHull *b) const + { + return a->mVolume < b->mVolume; + } +}; + + +typedef btAlignedObjectArray< CHull * > CHullVector; + + + +class ConvexBuilder : public ConvexDecompInterface +{ +public: + ConvexBuilder(ConvexDecompInterface *callback); + + virtual ~ConvexBuilder(void); + + bool isDuplicate(unsigned int i1,unsigned int i2,unsigned int i3, + unsigned int ci1,unsigned int ci2,unsigned int ci3); + + void getMesh(const ConvexResult &cr,VertexLookup vc,UintVector &indices); + + CHull * canMerge(CHull *a,CHull *b); + + bool combineHulls(void); + + unsigned int process(const DecompDesc &desc); + + virtual void ConvexDebugTri(const float *p1,const float *p2,const float *p3,unsigned int color); + + virtual void ConvexDebugOBB(const float *sides, const float *matrix,unsigned int color); + virtual void ConvexDebugPoint(const float *p,float dist,unsigned int color); + + virtual void ConvexDebugBound(const float *bmin,const float *bmax,unsigned int color); + + virtual void ConvexDecompResult(ConvexResult &result); + + void sortChulls(CHullVector &hulls); + + CHullVector mChulls; + ConvexDecompInterface *mCallback; +}; + +#endif //CONVEX_BUILDER_H + diff --git a/Extras/ConvexDecomposition/ConvexDecomposition.cpp b/Extras/ConvexDecomposition/ConvexDecomposition.cpp new file mode 100644 index 0000000000..572d25f5bf --- /dev/null +++ b/Extras/ConvexDecomposition/ConvexDecomposition.cpp @@ -0,0 +1,375 @@ +#include "float_math.h" + +#include +#include +#include +#include + + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + +#include "ConvexDecomposition.h" +#include "cd_vector.h" +#include "cd_hull.h" +#include "bestfit.h" +#include "planetri.h" +#include "vlookup.h" +#include "splitplane.h" +#include "meshvolume.h" +#include "concavity.h" +#include "bestfitobb.h" +#include "float_math.h" +#include "fitsphere.h" + +#define SHOW_MESH 0 +#define MAKE_MESH 1 + + +using namespace ConvexDecomposition; + + + +namespace ConvexDecomposition +{ + +class FaceTri +{ +public: + FaceTri(void) { }; + FaceTri(const float *vertices,unsigned int i1,unsigned int i2,unsigned int i3) + { + mP1.Set( &vertices[i1*3] ); + mP2.Set( &vertices[i2*3] ); + mP3.Set( &vertices[i3*3] ); + } + + Vector3d mP1; + Vector3d mP2; + Vector3d mP3; + Vector3d mNormal; + +}; + + +void addTri(VertexLookup vl,UintVector &list,const Vector3d &p1,const Vector3d &p2,const Vector3d &p3) +{ + unsigned int i1 = Vl_getIndex(vl, p1.Ptr() ); + unsigned int i2 = Vl_getIndex(vl, p2.Ptr() ); + unsigned int i3 = Vl_getIndex(vl, p3.Ptr() ); + + // do *not* process degenerate triangles! + + if ( i1 != i2 && i1 != i3 && i2 != i3 ) + { + list.push_back(i1); + list.push_back(i2); + list.push_back(i3); + } +} + + +void calcConvexDecomposition(unsigned int vcount, + const float *vertices, + unsigned int tcount, + const unsigned int *indices, + ConvexDecompInterface *callback, + float masterVolume, + unsigned int depth) + +{ + + float plane[4]; + + bool split = false; + + + if ( depth < MAXDEPTH ) + { + + float volume; + float c = computeConcavity( vcount, vertices, tcount, indices, callback, plane, volume ); + + if ( depth == 0 ) + { + masterVolume = volume; + } + + float percent = (c*100.0f)/masterVolume; + + if ( percent > CONCAVE_PERCENT ) // if great than 5% of the total volume is concave, go ahead and keep splitting. + { + split = true; + } + + } + + if ( depth >= MAXDEPTH || !split ) + { + +#if 1 + + HullResult result; + HullLibrary hl; + HullDesc desc; + + desc.SetHullFlag(QF_TRIANGLES); + + desc.mVcount = vcount; + desc.mVertices = vertices; + desc.mVertexStride = sizeof(float)*3; + + HullError ret = hl.CreateConvexHull(desc,result); + + if ( ret == QE_OK ) + { + + ConvexResult r(result.mNumOutputVertices, result.mOutputVertices, result.mNumFaces, result.mIndices); + + + callback->ConvexDecompResult(r); + } + + +#else + + static unsigned int colors[8] = + { + 0xFF0000, + 0x00FF00, + 0x0000FF, + 0xFFFF00, + 0x00FFFF, + 0xFF00FF, + 0xFFFFFF, + 0xFF8040 + }; + + static int count = 0; + + count++; + + if ( count == 8 ) count = 0; + + assert( count >= 0 && count < 8 ); + + unsigned int color = colors[count]; + + const unsigned int *source = indices; + + for (unsigned int i=0; iConvexDebugTri( t.mP1.Ptr(), t.mP2.Ptr(), t.mP3.Ptr(), color ); + + } +#endif + + hl.ReleaseResult (result); + return; + + } + + UintVector ifront; + UintVector iback; + + VertexLookup vfront = Vl_createVertexLookup(); + VertexLookup vback = Vl_createVertexLookup(); + + + bool showmesh = false; + #if SHOW_MESH + showmesh = true; + #endif + + if ( 0 ) + { + showmesh = true; + for (float x=-1; x<1; x+=0.10f) + { + for (float y=0; y<1; y+=0.10f) + { + for (float z=-1; z<1; z+=0.04f) + { + float d = x*plane[0] + y*plane[1] + z*plane[2] + plane[3]; + Vector3d p(x,y,z); + if ( d >= 0 ) + callback->ConvexDebugPoint(p.Ptr(), 0.02f, 0x00FF00); + else + callback->ConvexDebugPoint(p.Ptr(), 0.02f, 0xFF0000); + } + } + } + } + + if ( 1 ) + { + // ok..now we are going to 'split' all of the input triangles against this plane! + const unsigned int *source = indices; + for (unsigned int i=0; i 4 || bcount > 4 ) + { + result = planeTriIntersection(plane,t.mP1.Ptr(),sizeof(Vector3d),0.00001f,front[0].Ptr(),fcount,back[0].Ptr(),bcount ); + } + + switch ( result ) + { + case PTR_FRONT: + + assert( fcount == 3 ); + + if ( showmesh ) + callback->ConvexDebugTri( front[0].Ptr(), front[1].Ptr(), front[2].Ptr(), 0x00FF00 ); + + #if MAKE_MESH + + addTri( vfront, ifront, front[0], front[1], front[2] ); + + + #endif + + break; + case PTR_BACK: + assert( bcount == 3 ); + + if ( showmesh ) + callback->ConvexDebugTri( back[0].Ptr(), back[1].Ptr(), back[2].Ptr(), 0xFFFF00 ); + + #if MAKE_MESH + + addTri( vback, iback, back[0], back[1], back[2] ); + + #endif + + break; + case PTR_SPLIT: + + assert( fcount >= 3 && fcount <= 4); + assert( bcount >= 3 && bcount <= 4); + + #if MAKE_MESH + + addTri( vfront, ifront, front[0], front[1], front[2] ); + addTri( vback, iback, back[0], back[1], back[2] ); + + + if ( fcount == 4 ) + { + addTri( vfront, ifront, front[0], front[2], front[3] ); + } + + if ( bcount == 4 ) + { + addTri( vback, iback, back[0], back[2], back[3] ); + } + + #endif + + if ( showmesh ) + { + callback->ConvexDebugTri( front[0].Ptr(), front[1].Ptr(), front[2].Ptr(), 0x00D000 ); + callback->ConvexDebugTri( back[0].Ptr(), back[1].Ptr(), back[2].Ptr(), 0xD0D000 ); + + if ( fcount == 4 ) + { + callback->ConvexDebugTri( front[0].Ptr(), front[2].Ptr(), front[3].Ptr(), 0x00D000 ); + } + if ( bcount == 4 ) + { + callback->ConvexDebugTri( back[0].Ptr(), back[2].Ptr(), back[3].Ptr(), 0xD0D000 ); + } + } + + break; + } + } + + // ok... here we recursively call + if ( ifront.size() ) + { + unsigned int vcount = Vl_getVcount(vfront); + const float *vertices = Vl_getVertices(vfront); + unsigned int tcount = ifront.size()/3; + + calcConvexDecomposition(vcount, vertices, tcount, &ifront[0], callback, masterVolume, depth+1); + + } + + ifront.clear(); + + Vl_releaseVertexLookup(vfront); + + if ( iback.size() ) + { + unsigned int vcount = Vl_getVcount(vback); + const float *vertices = Vl_getVertices(vback); + unsigned int tcount = iback.size()/3; + + calcConvexDecomposition(vcount, vertices, tcount, &iback[0], callback, masterVolume, depth+1); + + } + + iback.clear(); + Vl_releaseVertexLookup(vback); + + } +} + + + + +} diff --git a/Extras/ConvexDecomposition/ConvexDecomposition.h b/Extras/ConvexDecomposition/ConvexDecomposition.h new file mode 100644 index 0000000000..2886c39a49 --- /dev/null +++ b/Extras/ConvexDecomposition/ConvexDecomposition.h @@ -0,0 +1,220 @@ +#ifndef CONVEX_DECOMPOSITION_H + +#define CONVEX_DECOMPOSITION_H + +/*---------------------------------------------------------------------- +Copyright (c) 2004 Open Dynamics Framework Group +www.physicstools.org +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided +that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions +and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +Neither the name of the Open Dynamics Framework Group nor the names of its contributors may +be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + +#ifdef _WIN32 +#include //memcpy +#endif +#include +#include +#include "LinearMath/btAlignedObjectArray.h" + + + +extern unsigned int MAXDEPTH ; +extern float CONCAVE_PERCENT ; +extern float MERGE_PERCENT ; + + +typedef btAlignedObjectArray< unsigned int > UintVector; + + + +namespace ConvexDecomposition +{ + + class ConvexResult + { + public: + ConvexResult(void) + { + mHullVcount = 0; + mHullVertices = 0; + mHullTcount = 0; + mHullIndices = 0; + } + + ConvexResult(unsigned int hvcount,const float *hvertices,unsigned int htcount,const unsigned int *hindices) + { + mHullVcount = hvcount; + if ( mHullVcount ) + { + mHullVertices = new float[mHullVcount*sizeof(float)*3]; + memcpy(mHullVertices, hvertices, sizeof(float)*3*mHullVcount ); + } + else + { + mHullVertices = 0; + } + + mHullTcount = htcount; + + if ( mHullTcount ) + { + mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3]; + memcpy(mHullIndices,hindices, sizeof(unsigned int)*mHullTcount*3 ); + } + else + { + mHullIndices = 0; + } + + } + + ConvexResult(const ConvexResult &r) + { + mHullVcount = r.mHullVcount; + if ( mHullVcount ) + { + mHullVertices = new float[mHullVcount*sizeof(float)*3]; + memcpy(mHullVertices, r.mHullVertices, sizeof(float)*3*mHullVcount ); + } + else + { + mHullVertices = 0; + } + mHullTcount = r.mHullTcount; + if ( mHullTcount ) + { + mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3]; + memcpy(mHullIndices, r.mHullIndices, sizeof(unsigned int)*mHullTcount*3 ); + } + else + { + mHullIndices = 0; + } + } + + ~ConvexResult(void) + { + delete [] mHullVertices; + delete [] mHullIndices; + } + + // the convex hull. + unsigned int mHullVcount; + float * mHullVertices; + unsigned int mHullTcount; + unsigned int *mHullIndices; + + float mHullVolume; // the volume of the convex hull. + + float mOBBSides[3]; // the width, height and breadth of the best fit OBB + float mOBBCenter[3]; // the center of the OBB + float mOBBOrientation[4]; // the quaternion rotation of the OBB. + float mOBBTransform[16]; // the 4x4 transform of the OBB. + float mOBBVolume; // the volume of the OBB + + float mSphereRadius; // radius and center of best fit sphere + float mSphereCenter[3]; + float mSphereVolume; // volume of the best fit sphere + + + + }; + + class ConvexDecompInterface + { + public: + virtual ~ConvexDecompInterface() {}; + virtual void ConvexDebugTri(const float *p1,const float *p2,const float *p3,unsigned int color) { }; + virtual void ConvexDebugPoint(const float *p,float dist,unsigned int color) { }; + virtual void ConvexDebugBound(const float *bmin,const float *bmax,unsigned int color) { }; + virtual void ConvexDebugOBB(const float *sides, const float *matrix,unsigned int color) { }; + + virtual void ConvexDecompResult(ConvexResult &result) = 0; + + + + }; + + // just to avoid passing a zillion parameters to the method the + // options are packed into this descriptor. + class DecompDesc + { + public: + DecompDesc(void) + { + mVcount = 0; + mVertices = 0; + mTcount = 0; + mIndices = 0; + mDepth = 5; + mCpercent = 5; + mPpercent = 5; + mMaxVertices = 32; + mSkinWidth = 0; + mCallback = 0; + } + + // describes the input triangle. + unsigned int mVcount; // the number of vertices in the source mesh. + const float *mVertices; // start of the vertex position array. Assumes a stride of 3 floats. + unsigned int mTcount; // the number of triangles in the source mesh. + unsigned int *mIndices; // the indexed triangle list array (zero index based) + + // options + unsigned int mDepth; // depth to split, a maximum of 10, generally not over 7. + float mCpercent; // the concavity threshold percentage. 0=20 is reasonable. + float mPpercent; // the percentage volume conservation threshold to collapse hulls. 0-30 is reasonable. + + // hull output limits. + unsigned int mMaxVertices; // maximum number of vertices in the output hull. Recommended 32 or less. + float mSkinWidth; // a skin width to apply to the output hulls. + + ConvexDecompInterface *mCallback; // the interface to receive back the results. + + }; + + // perform approximate convex decomposition on a mesh. + unsigned int performConvexDecomposition(const DecompDesc &desc); // returns the number of hulls produced. + + + void calcConvexDecomposition(unsigned int vcount, + const float *vertices, + unsigned int tcount, + const unsigned int *indices, + ConvexDecompInterface *callback, + float masterVolume, + unsigned int depth); + + +} + + +#endif diff --git a/Extras/ConvexDecomposition/bestfit.cpp b/Extras/ConvexDecomposition/bestfit.cpp new file mode 100644 index 0000000000..e6469f6fb4 --- /dev/null +++ b/Extras/ConvexDecomposition/bestfit.cpp @@ -0,0 +1,466 @@ +#include "float_math.h" +#include +#include +#include +#include +#include + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// +// Geometric Tools, Inc. +// http://www.geometrictools.com +// Copyright (c) 1998-2006. All Rights Reserved +// +// The Wild Magic Library (WM3) source code is supplied under the terms of +// the license agreement +// http://www.geometrictools.com/License/WildMagic3License.pdf +// and may not be copied or disclosed except in accordance with the terms +// of that agreement. + +#include "bestfit.h" + +namespace BestFit +{ + +class Vec3 +{ +public: + Vec3(void) { }; + Vec3(float _x,float _y,float _z) { x = _x; y = _y; z = _z; }; + + + float dot(const Vec3 &v) + { + return x*v.x + y*v.y + z*v.z; // the dot product + } + + float x; + float y; + float z; +}; + + +class Eigen +{ +public: + + + void DecrSortEigenStuff(void) + { + Tridiagonal(); //diagonalize the matrix. + QLAlgorithm(); // + DecreasingSort(); + GuaranteeRotation(); + } + + void Tridiagonal(void) + { + float fM00 = mElement[0][0]; + float fM01 = mElement[0][1]; + float fM02 = mElement[0][2]; + float fM11 = mElement[1][1]; + float fM12 = mElement[1][2]; + float fM22 = mElement[2][2]; + + m_afDiag[0] = fM00; + m_afSubd[2] = 0; + if (fM02 != (float)0.0) + { + float fLength = sqrtf(fM01*fM01+fM02*fM02); + float fInvLength = ((float)1.0)/fLength; + fM01 *= fInvLength; + fM02 *= fInvLength; + float fQ = ((float)2.0)*fM01*fM12+fM02*(fM22-fM11); + m_afDiag[1] = fM11+fM02*fQ; + m_afDiag[2] = fM22-fM02*fQ; + m_afSubd[0] = fLength; + m_afSubd[1] = fM12-fM01*fQ; + mElement[0][0] = (float)1.0; + mElement[0][1] = (float)0.0; + mElement[0][2] = (float)0.0; + mElement[1][0] = (float)0.0; + mElement[1][1] = fM01; + mElement[1][2] = fM02; + mElement[2][0] = (float)0.0; + mElement[2][1] = fM02; + mElement[2][2] = -fM01; + m_bIsRotation = false; + } + else + { + m_afDiag[1] = fM11; + m_afDiag[2] = fM22; + m_afSubd[0] = fM01; + m_afSubd[1] = fM12; + mElement[0][0] = (float)1.0; + mElement[0][1] = (float)0.0; + mElement[0][2] = (float)0.0; + mElement[1][0] = (float)0.0; + mElement[1][1] = (float)1.0; + mElement[1][2] = (float)0.0; + mElement[2][0] = (float)0.0; + mElement[2][1] = (float)0.0; + mElement[2][2] = (float)1.0; + m_bIsRotation = true; + } + } + + bool QLAlgorithm(void) + { + const int iMaxIter = 32; + + for (int i0 = 0; i0 <3; i0++) + { + int i1; + for (i1 = 0; i1 < iMaxIter; i1++) + { + int i2; + for (i2 = i0; i2 <= (3-2); i2++) + { + float fTmp = fabsf(m_afDiag[i2]) + fabsf(m_afDiag[i2+1]); + if ( fabsf(m_afSubd[i2]) + fTmp == fTmp ) + break; + } + if (i2 == i0) + { + break; + } + + float fG = (m_afDiag[i0+1] - m_afDiag[i0])/(((float)2.0) * m_afSubd[i0]); + float fR = sqrtf(fG*fG+(float)1.0); + if (fG < (float)0.0) + { + fG = m_afDiag[i2]-m_afDiag[i0]+m_afSubd[i0]/(fG-fR); + } + else + { + fG = m_afDiag[i2]-m_afDiag[i0]+m_afSubd[i0]/(fG+fR); + } + float fSin = (float)1.0, fCos = (float)1.0, fP = (float)0.0; + for (int i3 = i2-1; i3 >= i0; i3--) + { + float fF = fSin*m_afSubd[i3]; + float fB = fCos*m_afSubd[i3]; + if (fabsf(fF) >= fabsf(fG)) + { + fCos = fG/fF; + fR = sqrtf(fCos*fCos+(float)1.0); + m_afSubd[i3+1] = fF*fR; + fSin = ((float)1.0)/fR; + fCos *= fSin; + } + else + { + fSin = fF/fG; + fR = sqrtf(fSin*fSin+(float)1.0); + m_afSubd[i3+1] = fG*fR; + fCos = ((float)1.0)/fR; + fSin *= fCos; + } + fG = m_afDiag[i3+1]-fP; + fR = (m_afDiag[i3]-fG)*fSin+((float)2.0)*fB*fCos; + fP = fSin*fR; + m_afDiag[i3+1] = fG+fP; + fG = fCos*fR-fB; + for (int i4 = 0; i4 < 3; i4++) + { + fF = mElement[i4][i3+1]; + mElement[i4][i3+1] = fSin*mElement[i4][i3]+fCos*fF; + mElement[i4][i3] = fCos*mElement[i4][i3]-fSin*fF; + } + } + m_afDiag[i0] -= fP; + m_afSubd[i0] = fG; + m_afSubd[i2] = (float)0.0; + } + if (i1 == iMaxIter) + { + return false; + } + } + return true; + } + + void DecreasingSort(void) + { + //sort eigenvalues in decreasing order, e[0] >= ... >= e[iSize-1] + for (int i0 = 0, i1; i0 <= 3-2; i0++) + { + // locate maximum eigenvalue + i1 = i0; + float fMax = m_afDiag[i1]; + int i2; + for (i2 = i0+1; i2 < 3; i2++) + { + if (m_afDiag[i2] > fMax) + { + i1 = i2; + fMax = m_afDiag[i1]; + } + } + + if (i1 != i0) + { + // swap eigenvalues + m_afDiag[i1] = m_afDiag[i0]; + m_afDiag[i0] = fMax; + // swap eigenvectors + for (i2 = 0; i2 < 3; i2++) + { + float fTmp = mElement[i2][i0]; + mElement[i2][i0] = mElement[i2][i1]; + mElement[i2][i1] = fTmp; + m_bIsRotation = !m_bIsRotation; + } + } + } + } + + + void GuaranteeRotation(void) + { + if (!m_bIsRotation) + { + // change sign on the first column + for (int iRow = 0; iRow <3; iRow++) + { + mElement[iRow][0] = -mElement[iRow][0]; + } + } + } + + float mElement[3][3]; + float m_afDiag[3]; + float m_afSubd[3]; + bool m_bIsRotation; +}; + +} + + +using namespace BestFit; + + +bool getBestFitPlane(unsigned int vcount, + const float *points, + unsigned int vstride, + const float *weights, + unsigned int wstride, + float *plane) +{ + bool ret = false; + + Vec3 kOrigin(0,0,0); + + float wtotal = 0; + + if ( 1 ) + { + const char *source = (const char *) points; + const char *wsource = (const char *) weights; + + for (unsigned int i=0; i bmax[0] ) bmax[0] = p[0]; + if ( p[1] > bmax[1] ) bmax[1] = p[1]; + if ( p[2] > bmax[2] ) bmax[2] = p[2]; + + } + + float dx = bmax[0] - bmin[0]; + float dy = bmax[1] - bmin[1]; + float dz = bmax[2] - bmin[2]; + + return sqrtf( dx*dx + dy*dy + dz*dz ); + +} + + +bool overlapAABB(const float *bmin1,const float *bmax1,const float *bmin2,const float *bmax2) // return true if the two AABB's overlap. +{ + if ( bmax2[0] < bmin1[0] ) return false; // if the maximum is less than our minimum on any axis + if ( bmax2[1] < bmin1[1] ) return false; + if ( bmax2[2] < bmin1[2] ) return false; + + if ( bmin2[0] > bmax1[0] ) return false; // if the minimum is greater than our maximum on any axis + if ( bmin2[1] > bmax1[1] ) return false; // if the minimum is greater than our maximum on any axis + if ( bmin2[2] > bmax1[2] ) return false; // if the minimum is greater than our maximum on any axis + + + return true; // the extents overlap +} + + diff --git a/Extras/ConvexDecomposition/bestfit.h b/Extras/ConvexDecomposition/bestfit.h new file mode 100644 index 0000000000..f2e78e5a60 --- /dev/null +++ b/Extras/ConvexDecomposition/bestfit.h @@ -0,0 +1,65 @@ +#ifndef BEST_FIT_H + +#define BEST_FIT_H + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + +// This routine was released in 'snippet' form +// by John W. Ratcliff mailto:jratcliff@infiniplex.net +// on March 22, 2006. +// +// This routine computes the 'best fit' plane equation to +// a set of input data points with an optional per vertex +// weighting component. +// +// The implementation for this was lifted directly from +// David Eberly's Magic Software implementation. + +// computes the best fit plane to a collection of data points. +// returns the plane equation as A,B,C,D format. (Ax+By+Cz+D) + +bool getBestFitPlane(unsigned int vcount, // number of input data points + const float *points, // starting address of points array. + unsigned int vstride, // stride between input points. + const float *weights, // *optional point weighting values. + unsigned int wstride, // weight stride for each vertex. + float *plane); + + +float getBoundingRegion(unsigned int vcount,const float *points,unsigned int pstride,float *bmin,float *bmax); // returns the diagonal distance +bool overlapAABB(const float *bmin1,const float *bmax1,const float *bmin2,const float *bmax2); // return true if the two AABB's overlap. + +#endif diff --git a/Extras/ConvexDecomposition/bestfitobb.cpp b/Extras/ConvexDecomposition/bestfitobb.cpp new file mode 100644 index 0000000000..2d60fd0450 --- /dev/null +++ b/Extras/ConvexDecomposition/bestfitobb.cpp @@ -0,0 +1,173 @@ +#include "float_math.h" + +#include +#include +#include +#include +#include + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + +#include "bestfitobb.h" +#include "float_math.h" + +// computes the OBB for this set of points relative to this transform matrix. +void computeOBB(unsigned int vcount,const float *points,unsigned int pstride,float *sides,const float *matrix) +{ + const char *src = (const char *) points; + + float bmin[3] = { 1e9, 1e9, 1e9 }; + float bmax[3] = { -1e9, -1e9, -1e9 }; + + for (unsigned int i=0; i bmax[0] ) bmax[0] = t[0]; + if ( t[1] > bmax[1] ) bmax[1] = t[1]; + if ( t[2] > bmax[2] ) bmax[2] = t[2]; + + src+=pstride; + } + + + sides[0] = bmax[0]; + sides[1] = bmax[1]; + sides[2] = bmax[2]; + + if ( fabsf(bmin[0]) > sides[0] ) sides[0] = fabsf(bmin[0]); + if ( fabsf(bmin[1]) > sides[1] ) sides[1] = fabsf(bmin[1]); + if ( fabsf(bmin[2]) > sides[2] ) sides[2] = fabsf(bmin[2]); + + sides[0]*=2.0f; + sides[1]*=2.0f; + sides[2]*=2.0f; + +} + +void computeBestFitOBB(unsigned int vcount,const float *points,unsigned int pstride,float *sides,float *matrix) +{ + + float bmin[3]; + float bmax[3]; + + fm_getAABB(vcount,points,pstride,bmin,bmax); + + float center[3]; + + center[0] = (bmax[0]-bmin[0])*0.5f + bmin[0]; + center[1] = (bmax[1]-bmin[1])*0.5f + bmin[1]; + center[2] = (bmax[2]-bmin[2])*0.5f + bmin[2]; + + float ax = 0; + float ay = 0; + float az = 0; + + float sweep = 45.0f; // 180 degree sweep on all three axes. + float steps = 8.0f; // 16 steps on each axis. + + float bestVolume = 1e9; + float angle[3]={0.f,0.f,0.f}; + + while ( sweep >= 1 ) + { + + bool found = false; + + float stepsize = sweep / steps; + + for (float x=ax-sweep; x<=ax+sweep; x+=stepsize) + { + for (float y=ay-sweep; y<=ay+sweep; y+=stepsize) + { + for (float z=az-sweep; z<=az+sweep; z+=stepsize) + { + float pmatrix[16]; + + fm_eulerMatrix( x*FM_DEG_TO_RAD, y*FM_DEG_TO_RAD, z*FM_DEG_TO_RAD, pmatrix ); + + pmatrix[3*4+0] = center[0]; + pmatrix[3*4+1] = center[1]; + pmatrix[3*4+2] = center[2]; + + float psides[3]; + + computeOBB( vcount, points, pstride, psides, pmatrix ); + + float volume = psides[0]*psides[1]*psides[2]; // the volume of the cube + + if ( volume <= bestVolume ) + { + bestVolume = volume; + + sides[0] = psides[0]; + sides[1] = psides[1]; + sides[2] = psides[2]; + + angle[0] = ax; + angle[1] = ay; + angle[2] = az; + + memcpy(matrix,pmatrix,sizeof(float)*16); + found = true; // yes, we found an improvement. + } + } + } + } + + if ( found ) + { + + ax = angle[0]; + ay = angle[1]; + az = angle[2]; + + sweep*=0.5f; // sweep 1/2 the distance as the last time. + } + else + { + break; // no improvement, so just + } + + } + +} diff --git a/Extras/ConvexDecomposition/bestfitobb.h b/Extras/ConvexDecomposition/bestfitobb.h new file mode 100644 index 0000000000..3141f5874d --- /dev/null +++ b/Extras/ConvexDecomposition/bestfitobb.h @@ -0,0 +1,43 @@ +#ifndef BEST_FIT_OBB_H + +#define BEST_FIT_OBB_H + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + + +void computeBestFitOBB(unsigned int vcount,const float *points,unsigned int pstride,float *sides,float *matrix); + +#endif diff --git a/Extras/ConvexDecomposition/cd_hull.cpp b/Extras/ConvexDecomposition/cd_hull.cpp new file mode 100644 index 0000000000..0fc8b51e04 --- /dev/null +++ b/Extras/ConvexDecomposition/cd_hull.cpp @@ -0,0 +1,3261 @@ +#include "float_math.h" + +#include +#include +#include +#include +#include +#include + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + +#include "cd_hull.h" + +using namespace ConvexDecomposition; + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +#define PI 3.14159264f + +//***************************************************** +//***************************************************** +//********* Stan Melax's vector math template needed +//********* to use his hull building code. +//***************************************************** +//***************************************************** + +#define DEG2RAD (PI / 180.0f) +#define RAD2DEG (180.0f / PI) +#define SQRT_OF_2 (1.4142135f) +#define OFFSET(Class,Member) (((char*) (&(((Class*)NULL)-> Member )))- ((char*)NULL)) + +namespace ConvexDecomposition +{ + + +int argmin(float a[],int n); +float sqr(float a); +float clampf(float a) ; +float Round(float a,float precision); +float Interpolate(const float &f0,const float &f1,float alpha) ; + +template +void Swap(T &a,T &b) +{ + T tmp = a; + a=b; + b=tmp; +} + + + +template +T Max(const T &a,const T &b) +{ + return (a>b)?a:b; +} + +template +T Min(const T &a,const T &b) +{ + return (a=0&&i<2);return ((float*)this)[i];} + const float& operator[](int i) const {assert(i>=0&&i<2);return ((float*)this)[i];} +}; +inline float2 operator-( const float2& a, const float2& b ){return float2(a.x-b.x,a.y-b.y);} +inline float2 operator+( const float2& a, const float2& b ){return float2(a.x+b.x,a.y+b.y);} + +//--------- 3D --------- + +class float3 // 3D +{ + public: + float x,y,z; + float3(){x=0;y=0;z=0;}; + float3(float _x,float _y,float _z){x=_x;y=_y;z=_z;}; + //operator float *() { return &x;}; + float& operator[](int i) {assert(i>=0&&i<3);return ((float*)this)[i];} + const float& operator[](int i) const {assert(i>=0&&i<3);return ((float*)this)[i];} +# ifdef PLUGIN_3DSMAX + float3(const Point3 &p):x(p.x),y(p.y),z(p.z){} + operator Point3(){return *((Point3*)this);} +# endif +}; + + +float3& operator+=( float3 &a, const float3& b ); +float3& operator-=( float3 &a ,const float3& b ); +float3& operator*=( float3 &v ,const float s ); +float3& operator/=( float3 &v, const float s ); + +float magnitude( const float3& v ); +float3 normalize( const float3& v ); +float3 safenormalize(const float3 &v); +float3 vabs(const float3 &v); +float3 operator+( const float3& a, const float3& b ); +float3 operator-( const float3& a, const float3& b ); +float3 operator-( const float3& v ); +float3 operator*( const float3& v, const float s ); +float3 operator*( const float s, const float3& v ); +float3 operator/( const float3& v, const float s ); +inline int operator==( const float3 &a, const float3 &b ) { return (a.x==b.x && a.y==b.y && a.z==b.z); } +inline int operator!=( const float3 &a, const float3 &b ) { return (a.x!=b.x || a.y!=b.y || a.z!=b.z); } +// due to ambiguity and inconsistent standards ther are no overloaded operators for mult such as va*vb. +float dot( const float3& a, const float3& b ); +float3 cmul( const float3 &a, const float3 &b); +float3 cross( const float3& a, const float3& b ); +float3 Interpolate(const float3 &v0,const float3 &v1,float alpha); +float3 Round(const float3& a,float precision); +float3 VectorMax(const float3 &a, const float3 &b); +float3 VectorMin(const float3 &a, const float3 &b); + + + +class float3x3 +{ + public: + float3 x,y,z; // the 3 rows of the Matrix + float3x3(){} + float3x3(float xx,float xy,float xz,float yx,float yy,float yz,float zx,float zy,float zz):x(xx,xy,xz),y(yx,yy,yz),z(zx,zy,zz){} + float3x3(float3 _x,float3 _y,float3 _z):x(_x),y(_y),z(_z){} + float3& operator[](int i) {assert(i>=0&&i<3);return (&x)[i];} + const float3& operator[](int i) const {assert(i>=0&&i<3);return (&x)[i];} + float& operator()(int r, int c) {assert(r>=0&&r<3&&c>=0&&c<3);return ((&x)[r])[c];} + const float& operator()(int r, int c) const {assert(r>=0&&r<3&&c>=0&&c<3);return ((&x)[r])[c];} +}; +float3x3 Transpose( const float3x3& m ); +float3 operator*( const float3& v , const float3x3& m ); +float3 operator*( const float3x3& m , const float3& v ); +float3x3 operator*( const float3x3& m , const float& s ); +float3x3 operator*( const float3x3& ma, const float3x3& mb ); +float3x3 operator/( const float3x3& a, const float& s ) ; +float3x3 operator+( const float3x3& a, const float3x3& b ); +float3x3 operator-( const float3x3& a, const float3x3& b ); +float3x3 &operator+=( float3x3& a, const float3x3& b ); +float3x3 &operator-=( float3x3& a, const float3x3& b ); +float3x3 &operator*=( float3x3& a, const float& s ); +float Determinant(const float3x3& m ); +float3x3 Inverse(const float3x3& a); // its just 3x3 so we simply do that cofactor method + + +//-------- 4D Math -------- + +class float4 +{ +public: + float x,y,z,w; + float4(){x=0;y=0;z=0;w=0;}; + float4(float _x,float _y,float _z,float _w){x=_x;y=_y;z=_z;w=_w;} + float4(const float3 &v,float _w){x=v.x;y=v.y;z=v.z;w=_w;} + //operator float *() { return &x;}; + float& operator[](int i) {assert(i>=0&&i<4);return ((float*)this)[i];} + const float& operator[](int i) const {assert(i>=0&&i<4);return ((float*)this)[i];} + const float3& xyz() const { return *((float3*)this);} + float3& xyz() { return *((float3*)this);} +}; + + +struct D3DXMATRIX; + +class float4x4 +{ + public: + float4 x,y,z,w; // the 4 rows + float4x4(){} + float4x4(const float4 &_x, const float4 &_y, const float4 &_z, const float4 &_w):x(_x),y(_y),z(_z),w(_w){} + float4x4(float m00, float m01, float m02, float m03, + float m10, float m11, float m12, float m13, + float m20, float m21, float m22, float m23, + float m30, float m31, float m32, float m33 ) + :x(m00,m01,m02,m03),y(m10,m11,m12,m13),z(m20,m21,m22,m23),w(m30,m31,m32,m33){} + float& operator()(int r, int c) {assert(r>=0&&r<4&&c>=0&&c<4);return ((&x)[r])[c];} + const float& operator()(int r, int c) const {assert(r>=0&&r<4&&c>=0&&c<4);return ((&x)[r])[c];} + operator float* () {return &x.x;} + operator const float* () const {return &x.x;} + operator struct D3DXMATRIX* () { return (struct D3DXMATRIX*) this;} + operator const struct D3DXMATRIX* () const { return (struct D3DXMATRIX*) this;} +}; + + +int operator==( const float4 &a, const float4 &b ); +float4 Homogenize(const float3 &v3,const float &w=1.0f); // Turns a 3D float3 4D vector4 by appending w +float4 cmul( const float4 &a, const float4 &b); +float4 operator*( const float4 &v, float s); +float4 operator*( float s, const float4 &v); +float4 operator+( const float4 &a, const float4 &b); +float4 operator-( const float4 &a, const float4 &b); +float4x4 operator*( const float4x4& a, const float4x4& b ); +float4 operator*( const float4& v, const float4x4& m ); +float4x4 Inverse(const float4x4 &m); +float4x4 MatrixRigidInverse(const float4x4 &m); +float4x4 MatrixTranspose(const float4x4 &m); +float4x4 MatrixPerspectiveFov(float fovy, float Aspect, float zn, float zf ); +float4x4 MatrixTranslation(const float3 &t); +float4x4 MatrixRotationZ(const float angle_radians); +float4x4 MatrixLookAt(const float3& eye, const float3& at, const float3& up); +int operator==( const float4x4 &a, const float4x4 &b ); + + +//-------- Quaternion ------------ + +class Quaternion :public float4 +{ + public: + Quaternion() { x = y = z = 0.0f; w = 1.0f; } + Quaternion( float3 v, float t ) { v = normalize(v); w = cosf(t/2.0f); v = v*sinf(t/2.0f); x = v.x; y = v.y; z = v.z; } + Quaternion(float _x, float _y, float _z, float _w){x=_x;y=_y;z=_z;w=_w;} + float angle() const { return acosf(w)*2.0f; } + float3 axis() const { float3 a(x,y,z); if(fabsf(angle())<0.0000001f) return float3(1,0,0); return a*(1/sinf(angle()/2.0f)); } + float3 xdir() const { return float3( 1-2*(y*y+z*z), 2*(x*y+w*z), 2*(x*z-w*y) ); } + float3 ydir() const { return float3( 2*(x*y-w*z),1-2*(x*x+z*z), 2*(y*z+w*x) ); } + float3 zdir() const { return float3( 2*(x*z+w*y), 2*(y*z-w*x),1-2*(x*x+y*y) ); } + float3x3 getmatrix() const { return float3x3( xdir(), ydir(), zdir() ); } + operator float3x3() { return getmatrix(); } + void Normalize(); +}; + +Quaternion& operator*=(Quaternion& a, float s ); +Quaternion operator*( const Quaternion& a, float s ); +Quaternion operator*( const Quaternion& a, const Quaternion& b); +Quaternion operator+( const Quaternion& a, const Quaternion& b ); +Quaternion normalize( Quaternion a ); +float dot( const Quaternion &a, const Quaternion &b ); +float3 operator*( const Quaternion& q, const float3& v ); +float3 operator*( const float3& v, const Quaternion& q ); +Quaternion slerp( Quaternion a, const Quaternion& b, float interp ); +Quaternion Interpolate(const Quaternion &q0,const Quaternion &q1,float alpha); +Quaternion RotationArc(float3 v0, float3 v1 ); // returns quat q where q*v0=v1 +Quaternion Inverse(const Quaternion &q); +float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v); + + +//------ Euler Angle ----- + +Quaternion YawPitchRoll( float yaw, float pitch, float roll ); +float Yaw( const Quaternion& q ); +float Pitch( const Quaternion& q ); +float Roll( Quaternion q ); +float Yaw( const float3& v ); +float Pitch( const float3& v ); + + +//------- Plane ---------- + +class Plane +{ + public: + float3 normal; + float dist; // distance below origin - the D from plane equasion Ax+By+Cz+D=0 + Plane(const float3 &n,float d):normal(n),dist(d){} + Plane():normal(),dist(0){} + void Transform(const float3 &position, const Quaternion &orientation); +}; + +inline Plane PlaneFlip(const Plane &plane){return Plane(-plane.normal,-plane.dist);} +inline int operator==( const Plane &a, const Plane &b ) { return (a.normal==b.normal && a.dist==b.dist); } +inline int coplanar( const Plane &a, const Plane &b ) { return (a==b || a==PlaneFlip(b)); } + + +//--------- Utility Functions ------ + +float3 PlaneLineIntersection(const Plane &plane, const float3 &p0, const float3 &p1); +float3 PlaneProject(const Plane &plane, const float3 &point); +float3 LineProject(const float3 &p0, const float3 &p1, const float3 &a); // projects a onto infinite line p0p1 +float LineProjectTime(const float3 &p0, const float3 &p1, const float3 &a); +float3 ThreePlaneIntersection(const Plane &p0,const Plane &p1, const Plane &p2); +int PolyHit(const float3 *vert,const int n,const float3 &v0, const float3 &v1, float3 *impact=NULL, float3 *normal=NULL); +int BoxInside(const float3 &p,const float3 &bmin, const float3 &bmax) ; +int BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const float3 &bmax, float3 *impact); +float DistanceBetweenLines(const float3 &ustart, const float3 &udir, const float3 &vstart, const float3 &vdir, float3 *upoint=NULL, float3 *vpoint=NULL); +float3 TriNormal(const float3 &v0, const float3 &v1, const float3 &v2); +float3 NormalOf(const float3 *vert, const int n); +Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &dir0, const float3 &dir1); + + +float sqr(float a) {return a*a;} +float clampf(float a) {return Min(1.0f,Max(0.0f,a));} + + +float Round(float a,float precision) +{ + return floorf(0.5f+a/precision)*precision; +} + + +float Interpolate(const float &f0,const float &f1,float alpha) +{ + return f0*(1-alpha) + f1*alpha; +} + + +int argmin(float a[],int n) +{ + int r=0; + for(int i=1;i=1.0) { + return a; + } + float theta = acosf(d); + if(theta==0.0f) { return(a);} + return a*(sinf(theta-interp*theta)/sinf(theta)) + b*(sinf(interp*theta)/sinf(theta)); +} + + +Quaternion Interpolate(const Quaternion &q0,const Quaternion &q1,float alpha) { + return slerp(q0,q1,alpha); +} + + +Quaternion YawPitchRoll( float yaw, float pitch, float roll ) +{ + roll *= DEG2RAD; + yaw *= DEG2RAD; + pitch *= DEG2RAD; + return Quaternion(float3(0.0f,0.0f,1.0f),yaw)*Quaternion(float3(1.0f,0.0f,0.0f),pitch)*Quaternion(float3(0.0f,1.0f,0.0f),roll); +} + +float Yaw( const Quaternion& q ) +{ + float3 v; + v=q.ydir(); + return (v.y==0.0&&v.x==0.0) ? 0.0f: atan2f(-v.x,v.y)*RAD2DEG; +} + +float Pitch( const Quaternion& q ) +{ + float3 v; + v=q.ydir(); + return atan2f(v.z,sqrtf(sqr(v.x)+sqr(v.y)))*RAD2DEG; +} + +float Roll( Quaternion q ) +{ + q = Quaternion(float3(0.0f,0.0f,1.0f),-Yaw(q)*DEG2RAD) *q; + q = Quaternion(float3(1.0f,0.0f,0.0f),-Pitch(q)*DEG2RAD) *q; + return atan2f(-q.xdir().z,q.xdir().x)*RAD2DEG; +} + +float Yaw( const float3& v ) +{ + return (v.y==0.0&&v.x==0.0) ? 0.0f: atan2f(-v.x,v.y)*RAD2DEG; +} + +float Pitch( const float3& v ) +{ + return atan2f(v.z,sqrtf(sqr(v.x)+sqr(v.y)))*RAD2DEG; +} + + +//------------- Plane -------------- + + +void Plane::Transform(const float3 &position, const Quaternion &orientation) { + // Transforms the plane to the space defined by the + // given position/orientation. + float3 newnormal; + float3 origin; + + newnormal = Inverse(orientation)*normal; + origin = Inverse(orientation)*(-normal*dist - position); + + normal = newnormal; + dist = -dot(newnormal, origin); +} + + + + +//--------- utility functions ------------- + +// RotationArc() +// Given two vectors v0 and v1 this function +// returns quaternion q where q*v0==v1. +// Routine taken from game programming gems. +Quaternion RotationArc(float3 v0,float3 v1){ + Quaternion q; + v0 = normalize(v0); // Comment these two lines out if you know its not needed. + v1 = normalize(v1); // If vector is already unit length then why do it again? + float3 c = cross(v0,v1); + float d = dot(v0,v1); + if(d<=-1.0f) { return Quaternion(1,0,0,0);} // 180 about x axis + float s = sqrtf((1+d)*2); + q.x = c.x / s; + q.y = c.y / s; + q.z = c.z / s; + q.w = s /2.0f; + return q; +} + + +float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v) +{ + // builds a 4x4 transformation matrix based on orientation q and translation v + float qx2 = q.x*q.x; + float qy2 = q.y*q.y; + float qz2 = q.z*q.z; + + float qxqy = q.x*q.y; + float qxqz = q.x*q.z; + float qxqw = q.x*q.w; + float qyqz = q.y*q.z; + float qyqw = q.y*q.w; + float qzqw = q.z*q.w; + + return float4x4( + 1-2*(qy2+qz2), + 2*(qxqy+qzqw), + 2*(qxqz-qyqw), + 0 , + 2*(qxqy-qzqw), + 1-2*(qx2+qz2), + 2*(qyqz+qxqw), + 0 , + 2*(qxqz+qyqw), + 2*(qyqz-qxqw), + 1-2*(qx2+qy2), + 0 , + v.x , + v.y , + v.z , + 1.0f ); +} + + +float3 PlaneLineIntersection(const Plane &plane, const float3 &p0, const float3 &p1) +{ + // returns the point where the line p0-p1 intersects the plane n&d + float3 dif; + dif = p1-p0; + float dn= dot(plane.normal,dif); + float t = -(plane.dist+dot(plane.normal,p0) )/dn; + return p0 + (dif*t); +} + +float3 PlaneProject(const Plane &plane, const float3 &point) +{ + return point - plane.normal * (dot(point,plane.normal)+plane.dist); +} + +float3 LineProject(const float3 &p0, const float3 &p1, const float3 &a) +{ + float3 w; + w = p1-p0; + float t= dot(w,(a-p0)) / (sqr(w.x)+sqr(w.y)+sqr(w.z)); + return p0+ w*t; +} + + +float LineProjectTime(const float3 &p0, const float3 &p1, const float3 &a) +{ + float3 w; + w = p1-p0; + float t= dot(w,(a-p0)) / (sqr(w.x)+sqr(w.y)+sqr(w.z)); + return t; +} + + + +float3 TriNormal(const float3 &v0, const float3 &v1, const float3 &v2) +{ + // return the normal of the triangle + // inscribed by v0, v1, and v2 + float3 cp=cross(v1-v0,v2-v1); + float m=magnitude(cp); + if(m==0) return float3(1,0,0); + return cp*(1.0f/m); +} + + + +int BoxInside(const float3 &p, const float3 &bmin, const float3 &bmax) +{ + return (p.x >= bmin.x && p.x <=bmax.x && + p.y >= bmin.y && p.y <=bmax.y && + p.z >= bmin.z && p.z <=bmax.z ); +} + + +int BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const float3 &bmax,float3 *impact) +{ + if(BoxInside(v0,bmin,bmax)) + { + *impact=v0; + return 1; + } + if(v0.x<=bmin.x && v1.x>=bmin.x) + { + float a = (bmin.x-v0.x)/(v1.x-v0.x); + //v.x = bmin.x; + float vy = (1-a) *v0.y + a*v1.y; + float vz = (1-a) *v0.z + a*v1.z; + if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z) + { + impact->x = bmin.x; + impact->y = vy; + impact->z = vz; + return 1; + } + } + else if(v0.x >= bmax.x && v1.x <= bmax.x) + { + float a = (bmax.x-v0.x)/(v1.x-v0.x); + //v.x = bmax.x; + float vy = (1-a) *v0.y + a*v1.y; + float vz = (1-a) *v0.z + a*v1.z; + if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z) + { + impact->x = bmax.x; + impact->y = vy; + impact->z = vz; + return 1; + } + } + if(v0.y<=bmin.y && v1.y>=bmin.y) + { + float a = (bmin.y-v0.y)/(v1.y-v0.y); + float vx = (1-a) *v0.x + a*v1.x; + //v.y = bmin.y; + float vz = (1-a) *v0.z + a*v1.z; + if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z) + { + impact->x = vx; + impact->y = bmin.y; + impact->z = vz; + return 1; + } + } + else if(v0.y >= bmax.y && v1.y <= bmax.y) + { + float a = (bmax.y-v0.y)/(v1.y-v0.y); + float vx = (1-a) *v0.x + a*v1.x; + // vy = bmax.y; + float vz = (1-a) *v0.z + a*v1.z; + if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z) + { + impact->x = vx; + impact->y = bmax.y; + impact->z = vz; + return 1; + } + } + if(v0.z<=bmin.z && v1.z>=bmin.z) + { + float a = (bmin.z-v0.z)/(v1.z-v0.z); + float vx = (1-a) *v0.x + a*v1.x; + float vy = (1-a) *v0.y + a*v1.y; + // v.z = bmin.z; + if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x) + { + impact->x = vx; + impact->y = vy; + impact->z = bmin.z; + return 1; + } + } + else if(v0.z >= bmax.z && v1.z <= bmax.z) + { + float a = (bmax.z-v0.z)/(v1.z-v0.z); + float vx = (1-a) *v0.x + a*v1.x; + float vy = (1-a) *v0.y + a*v1.y; + // v.z = bmax.z; + if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x) + { + impact->x = vx; + impact->y = vy; + impact->z = bmax.z; + return 1; + } + } + return 0; +} + + +float DistanceBetweenLines(const float3 &ustart, const float3 &udir, const float3 &vstart, const float3 &vdir, float3 *upoint, float3 *vpoint) +{ + float3 cp; + cp = normalize(cross(udir,vdir)); + + float distu = -dot(cp,ustart); + float distv = -dot(cp,vstart); + float dist = (float)fabs(distu-distv); + if(upoint) + { + Plane plane; + plane.normal = normalize(cross(vdir,cp)); + plane.dist = -dot(plane.normal,vstart); + *upoint = PlaneLineIntersection(plane,ustart,ustart+udir); + } + if(vpoint) + { + Plane plane; + plane.normal = normalize(cross(udir,cp)); + plane.dist = -dot(plane.normal,ustart); + *vpoint = PlaneLineIntersection(plane,vstart,vstart+vdir); + } + return dist; +} + + +Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &dir1, const float3 &dir2) +{ + // routine taken from game programming gems. + // Implement track ball functionality to spin stuf on the screen + // cop center of projection + // cor center of rotation + // dir1 old mouse direction + // dir2 new mouse direction + // pretend there is a sphere around cor. Then find the points + // where dir1 and dir2 intersect that sphere. Find the + // rotation that takes the first point to the second. + float m; + // compute plane + float3 nrml = cor - cop; + float fudgefactor = 1.0f/(magnitude(nrml) * 0.25f); // since trackball proportional to distance from cop + nrml = normalize(nrml); + float dist = -dot(nrml,cor); + float3 u= PlaneLineIntersection(Plane(nrml,dist),cop,cop+dir1); + u=u-cor; + u=u*fudgefactor; + m= magnitude(u); + if(m>1) + { + u/=m; + } + else + { + u=u - (nrml * sqrtf(1-m*m)); + } + float3 v= PlaneLineIntersection(Plane(nrml,dist),cop,cop+dir2); + v=v-cor; + v=v*fudgefactor; + m= magnitude(v); + if(m>1) + { + v/=m; + } + else + { + v=v - (nrml * sqrtf(1-m*m)); + } + return RotationArc(u,v); +} + + +int countpolyhit=0; +int PolyHit(const float3 *vert, const int n, const float3 &v0, const float3 &v1, float3 *impact, float3 *normal) +{ + countpolyhit++; + int i; + float3 nrml(0,0,0); + for(i=0;i0) + { + return 0; + } + + float3 the_point; + // By using the cached plane distances d0 and d1 + // we can optimize the following: + // the_point = planelineintersection(nrml,dist,v0,v1); + float a = d0/(d0-d1); + the_point = v0*(1-a) + v1*a; + + + int inside=1; + for(int j=0;inside && j= 0.0); + } + if(inside) + { + if(normal){*normal=nrml;} + if(impact){*impact=the_point;} + } + return inside; +} + +//************************************************************************** +//************************************************************************** +//*** Stan Melax's array template, needed to compile his hull generation code +//************************************************************************** +//************************************************************************** + +template class ArrayRet; +template class Array { + public: + Array(int s=0); + Array(Array &array); + Array(ArrayRet &array); + ~Array(); + void allocate(int s); + void SetSize(int s); + void Pack(); + Type& Add(Type); + void AddUnique(Type); + int Contains(Type); + void Insert(Type,int); + int IndexOf(Type); + void Remove(Type); + void DelIndex(int i); + Type * element; + int count; + int array_size; + const Type &operator[](int i) const { assert(i>=0 && i=0 && i &operator=(Array &array); + Array &operator=(ArrayRet &array); + // operator ArrayRet &() { return *(ArrayRet *)this;} // this worked but i suspect could be dangerous +}; + +template class ArrayRet:public Array +{ +}; + +template Array::Array(int s) +{ + count=0; + array_size = 0; + element = NULL; + if(s) + { + allocate(s); + } +} + + +template Array::Array(Array &array) +{ + count=0; + array_size = 0; + element = NULL; + for(int i=0;i Array::Array(ArrayRet &array) +{ + *this = array; +} +template Array &Array::operator=(ArrayRet &array) +{ + count=array.count; + array_size = array.array_size; + element = array.element; + array.element=NULL; + array.count=0; + array.array_size=0; + return *this; +} + + +template Array &Array::operator=(Array &array) +{ + count=0; + for(int i=0;i Array::~Array() +{ + if (element != NULL) + { + free(element); + } + count=0;array_size=0;element=NULL; +} + +template void Array::allocate(int s) +{ + assert(s>0); + assert(s>=count); + Type *old = element; + array_size =s; + element = (Type *) malloc( sizeof(Type)*array_size); + assert(element); + for(int i=0;i void Array::SetSize(int s) +{ + if(s==0) + { + if(element) + { + free(element); + element = NULL; + } + array_size = s; + } + else + { + allocate(s); + } + count=s; +} + +template void Array::Pack() +{ + allocate(count); +} + +template Type& Array::Add(Type t) +{ + assert(count<=array_size); + if(count==array_size) + { + allocate((array_size)?array_size *2:16); + } + element[count++] = t; + return element[count-1]; +} + +template int Array::Contains(Type t) +{ + int i; + int found=0; + for(i=0;i void Array::AddUnique(Type t) +{ + if(!Contains(t)) Add(t); +} + + +template void Array::DelIndex(int i) +{ + assert(i void Array::Remove(Type t) +{ + int i; + for(i=0;i void Array::Insert(Type t,int k) +{ + int i=count; + Add(t); // to allocate space + while(i>k) + { + element[i]=element[i-1]; + i--; + } + assert(i==k); + element[k]=t; +} + + +template int Array::IndexOf(Type t) +{ + int i; + for(i=0;i vertices; + Array edges; + Array facets; + ConvexH(int vertices_size,int edges_size,int facets_size); +}; + +typedef ConvexH::HalfEdge HalfEdge; + +ConvexH::ConvexH(int vertices_size,int edges_size,int facets_size) + :vertices(vertices_size) + ,edges(edges_size) + ,facets(facets_size) +{ + vertices.count=vertices_size; + edges.count = edges_size; + facets.count = facets_size; +} + +ConvexH *ConvexHDup(ConvexH *src) { + ConvexH *dst = new ConvexH(src->vertices.count,src->edges.count,src->facets.count); + memcpy(dst->vertices.element,src->vertices.element,sizeof(float3)*src->vertices.count); + memcpy(dst->edges.element,src->edges.element,sizeof(HalfEdge)*src->edges.count); + memcpy(dst->facets.element,src->facets.element,sizeof(Plane)*src->facets.count); + return dst; +} + + +int PlaneTest(const Plane &p, const REAL3 &v) { + REAL a = dot(v,p.normal)+p.dist; + int flag = (a>planetestepsilon)?OVER:((a<-planetestepsilon)?UNDER:COPLANAR); + return flag; +} + +int SplitTest(ConvexH &convex,const Plane &plane) { + int flag=0; + for(int i=0;i= convex.edges.count || convex.edges[inext].p != convex.edges[i].p) { + inext = estart; + } + assert(convex.edges[inext].p == convex.edges[i].p); + int nb = convex.edges[i].ea; + assert(nb!=255); + if(nb==255 || nb==-1) return 0; + assert(nb!=-1); + assert(i== convex.edges[nb].ea); + } + for(i=0;i= convex.edges.count || convex.edges[i1].p != convex.edges[i].p) { + i1 = estart; + } + int i2 = i1+1; + if(i2>= convex.edges.count || convex.edges[i2].p != convex.edges[i].p) { + i2 = estart; + } + if(i==i2) continue; // i sliced tangent to an edge and created 2 meaningless edges + REAL3 localnormal = TriNormal(convex.vertices[convex.edges[i ].v], + convex.vertices[convex.edges[i1].v], + convex.vertices[convex.edges[i2].v]); + assert(dot(localnormal,convex.facets[convex.edges[i].p].normal)>0); + if(dot(localnormal,convex.facets[convex.edges[i].p].normal)<=0)return 0; + } + return 1; +} + +// back to back quads +ConvexH *test_btbq() { + ConvexH *convex = new ConvexH(4,8,2); + convex->vertices[0] = REAL3(0,0,0); + convex->vertices[1] = REAL3(1,0,0); + convex->vertices[2] = REAL3(1,1,0); + convex->vertices[3] = REAL3(0,1,0); + convex->facets[0] = Plane(REAL3(0,0,1),0); + convex->facets[1] = Plane(REAL3(0,0,-1),0); + convex->edges[0] = HalfEdge(7,0,0); + convex->edges[1] = HalfEdge(6,1,0); + convex->edges[2] = HalfEdge(5,2,0); + convex->edges[3] = HalfEdge(4,3,0); + + convex->edges[4] = HalfEdge(3,0,1); + convex->edges[5] = HalfEdge(2,3,1); + convex->edges[6] = HalfEdge(1,2,1); + convex->edges[7] = HalfEdge(0,1,1); + AssertIntact(*convex); + return convex; +} +ConvexH *test_cube() { + ConvexH *convex = new ConvexH(8,24,6); + convex->vertices[0] = REAL3(0,0,0); + convex->vertices[1] = REAL3(0,0,1); + convex->vertices[2] = REAL3(0,1,0); + convex->vertices[3] = REAL3(0,1,1); + convex->vertices[4] = REAL3(1,0,0); + convex->vertices[5] = REAL3(1,0,1); + convex->vertices[6] = REAL3(1,1,0); + convex->vertices[7] = REAL3(1,1,1); + + convex->facets[0] = Plane(REAL3(-1,0,0),0); + convex->facets[1] = Plane(REAL3(1,0,0),-1); + convex->facets[2] = Plane(REAL3(0,-1,0),0); + convex->facets[3] = Plane(REAL3(0,1,0),-1); + convex->facets[4] = Plane(REAL3(0,0,-1),0); + convex->facets[5] = Plane(REAL3(0,0,1),-1); + + convex->edges[0 ] = HalfEdge(11,0,0); + convex->edges[1 ] = HalfEdge(23,1,0); + convex->edges[2 ] = HalfEdge(15,3,0); + convex->edges[3 ] = HalfEdge(16,2,0); + + convex->edges[4 ] = HalfEdge(13,6,1); + convex->edges[5 ] = HalfEdge(21,7,1); + convex->edges[6 ] = HalfEdge( 9,5,1); + convex->edges[7 ] = HalfEdge(18,4,1); + + convex->edges[8 ] = HalfEdge(19,0,2); + convex->edges[9 ] = HalfEdge( 6,4,2); + convex->edges[10] = HalfEdge(20,5,2); + convex->edges[11] = HalfEdge( 0,1,2); + + convex->edges[12] = HalfEdge(22,3,3); + convex->edges[13] = HalfEdge( 4,7,3); + convex->edges[14] = HalfEdge(17,6,3); + convex->edges[15] = HalfEdge( 2,2,3); + + convex->edges[16] = HalfEdge( 3,0,4); + convex->edges[17] = HalfEdge(14,2,4); + convex->edges[18] = HalfEdge( 7,6,4); + convex->edges[19] = HalfEdge( 8,4,4); + + convex->edges[20] = HalfEdge(10,1,5); + convex->edges[21] = HalfEdge( 5,5,5); + convex->edges[22] = HalfEdge(12,7,5); + convex->edges[23] = HalfEdge( 1,3,5); + + + return convex; +} +ConvexH *ConvexHMakeCube(const REAL3 &bmin, const REAL3 &bmax) { + ConvexH *convex = test_cube(); + convex->vertices[0] = REAL3(bmin.x,bmin.y,bmin.z); + convex->vertices[1] = REAL3(bmin.x,bmin.y,bmax.z); + convex->vertices[2] = REAL3(bmin.x,bmax.y,bmin.z); + convex->vertices[3] = REAL3(bmin.x,bmax.y,bmax.z); + convex->vertices[4] = REAL3(bmax.x,bmin.y,bmin.z); + convex->vertices[5] = REAL3(bmax.x,bmin.y,bmax.z); + convex->vertices[6] = REAL3(bmax.x,bmax.y,bmin.z); + convex->vertices[7] = REAL3(bmax.x,bmax.y,bmax.z); + + convex->facets[0] = Plane(REAL3(-1,0,0), bmin.x); + convex->facets[1] = Plane(REAL3(1,0,0), -bmax.x); + convex->facets[2] = Plane(REAL3(0,-1,0), bmin.y); + convex->facets[3] = Plane(REAL3(0,1,0), -bmax.y); + convex->facets[4] = Plane(REAL3(0,0,-1), bmin.z); + convex->facets[5] = Plane(REAL3(0,0,1), -bmax.z); + return convex; +} +ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice) +{ + int i; + int vertcountunder=0; + int vertcountover =0; + Array vertscoplanar; // existing vertex members of convex that are coplanar + vertscoplanar.count=0; + Array edgesplit; // existing edges that members of convex that cross the splitplane + edgesplit.count=0; + + assert(convex.edges.count<480); + + EdgeFlag edgeflag[512]; + VertFlag vertflag[256]; + PlaneFlag planeflag[128]; + HalfEdge tmpunderedges[512]; + Plane tmpunderplanes[128]; + Coplanar coplanaredges[512]; + int coplanaredges_num=0; + + Array createdverts; + // do the side-of-plane tests + for(i=0;i= convex.edges.count || convex.edges[e1].p!=currentplane) { + enextface = e1; + e1=estart; + } + HalfEdge &edge0 = convex.edges[e0]; + HalfEdge &edge1 = convex.edges[e1]; + HalfEdge &edgea = convex.edges[edge0.ea]; + + + planeside |= vertflag[edge0.v].planetest; + //if((vertflag[edge0.v].planetest & vertflag[edge1.v].planetest) == COPLANAR) { + // assert(ecop==-1); + // ecop=e; + //} + + + if(vertflag[edge0.v].planetest == OVER && vertflag[edge1.v].planetest == OVER){ + // both endpoints over plane + edgeflag[e0].undermap = -1; + } + else if((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == UNDER) { + // at least one endpoint under, the other coplanar or under + + edgeflag[e0].undermap = under_edge_count; + tmpunderedges[under_edge_count].v = vertflag[edge0.v].undermap; + tmpunderedges[under_edge_count].p = underplanescount; + if(edge0.ea < e0) { + // connect the neighbors + assert(edgeflag[edge0.ea].undermap !=-1); + tmpunderedges[under_edge_count].ea = edgeflag[edge0.ea].undermap; + tmpunderedges[edgeflag[edge0.ea].undermap].ea = under_edge_count; + } + under_edge_count++; + } + else if((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == COPLANAR) { + // both endpoints coplanar + // must check a 3rd point to see if UNDER + int e2 = e1+1; + if(e2>=convex.edges.count || convex.edges[e2].p!=currentplane) { + e2 = estart; + } + assert(convex.edges[e2].p==currentplane); + HalfEdge &edge2 = convex.edges[e2]; + if(vertflag[edge2.v].planetest==UNDER) { + + edgeflag[e0].undermap = under_edge_count; + tmpunderedges[under_edge_count].v = vertflag[edge0.v].undermap; + tmpunderedges[under_edge_count].p = underplanescount; + tmpunderedges[under_edge_count].ea = -1; + // make sure this edge is added to the "coplanar" list + coplanaredge = under_edge_count; + vout = vertflag[edge0.v].undermap; + vin = vertflag[edge1.v].undermap; + under_edge_count++; + } + else { + edgeflag[e0].undermap = -1; + } + } + else if(vertflag[edge0.v].planetest == UNDER && vertflag[edge1.v].planetest == OVER) { + // first is under 2nd is over + + edgeflag[e0].undermap = under_edge_count; + tmpunderedges[under_edge_count].v = vertflag[edge0.v].undermap; + tmpunderedges[under_edge_count].p = underplanescount; + if(edge0.ea < e0) { + assert(edgeflag[edge0.ea].undermap !=-1); + // connect the neighbors + tmpunderedges[under_edge_count].ea = edgeflag[edge0.ea].undermap; + tmpunderedges[edgeflag[edge0.ea].undermap].ea = under_edge_count; + vout = tmpunderedges[edgeflag[edge0.ea].undermap].v; + } + else { + Plane &p0 = convex.facets[edge0.p]; + Plane &pa = convex.facets[edgea.p]; + createdverts.Add(ThreePlaneIntersection(p0,pa,slice)); + //createdverts.Add(PlaneProject(slice,PlaneLineIntersection(slice,convex.vertices[edge0.v],convex.vertices[edgea.v]))); + //createdverts.Add(PlaneLineIntersection(slice,convex.vertices[edge0.v],convex.vertices[edgea.v])); + vout = vertcountunder++; + } + under_edge_count++; + /// hmmm something to think about: i might be able to output this edge regarless of + // wheter or not we know v-in yet. ok i;ll try this now: + tmpunderedges[under_edge_count].v = vout; + tmpunderedges[under_edge_count].p = underplanescount; + tmpunderedges[under_edge_count].ea = -1; + coplanaredge = under_edge_count; + under_edge_count++; + + if(vin!=-1) { + // we previously processed an edge where we came under + // now we know about vout as well + + // ADD THIS EDGE TO THE LIST OF EDGES THAT NEED NEIGHBOR ON PARTITION PLANE!! + } + + } + else if(vertflag[edge0.v].planetest == COPLANAR && vertflag[edge1.v].planetest == OVER) { + // first is coplanar 2nd is over + + edgeflag[e0].undermap = -1; + vout = vertflag[edge0.v].undermap; + // I hate this but i have to make sure part of this face is UNDER before ouputting this vert + int k=estart; + assert(edge0.p == currentplane); + while(!(planeside&UNDER) && k= vertcountunderold); // for debugging only + } + if(vout!=-1) { + // we previously processed an edge where we went over + // now we know vin too + // ADD THIS EDGE TO THE LIST OF EDGES THAT NEED NEIGHBOR ON PARTITION PLANE!! + } + // output edge + tmpunderedges[under_edge_count].v = vin; + tmpunderedges[under_edge_count].p = underplanescount; + edgeflag[e0].undermap = under_edge_count; + if(e0>edge0.ea) { + assert(edgeflag[edge0.ea].undermap !=-1); + // connect the neighbors + tmpunderedges[under_edge_count].ea = edgeflag[edge0.ea].undermap; + tmpunderedges[edgeflag[edge0.ea].undermap].ea = under_edge_count; + } + assert(edgeflag[e0].undermap == under_edge_count); + under_edge_count++; + } + else if(vertflag[edge0.v].planetest == OVER && vertflag[edge1.v].planetest == COPLANAR) { + // first is over next is coplanar + + edgeflag[e0].undermap = -1; + vin = vertflag[edge1.v].undermap; + assert(vin!=-1); + if(vout!=-1) { + // we previously processed an edge where we came under + // now we know both endpoints + // ADD THIS EDGE TO THE LIST OF EDGES THAT NEED NEIGHBOR ON PARTITION PLANE!! + } + + } + else { + assert(0); + } + + + e0=e1; + e1++; // do the modulo at the beginning of the loop + + } while(e0!=estart) ; + e0 = enextface; + if(planeside&UNDER) { + planeflag[currentplane].undermap = underplanescount; + tmpunderplanes[underplanescount] = convex.facets[currentplane]; + underplanescount++; + } + else { + planeflag[currentplane].undermap = 0; + } + if(vout>=0 && (planeside&UNDER)) { + assert(vin>=0); + assert(coplanaredge>=0); + assert(coplanaredge!=511); + coplanaredges[coplanaredges_num].ea = coplanaredge; + coplanaredges[coplanaredges_num].v0 = vin; + coplanaredges[coplanaredges_num].v1 = vout; + coplanaredges_num++; + } + } + + // add the new plane to the mix: + if(coplanaredges_num>0) { + tmpunderplanes[underplanescount++]=slice; + } + for(i=0;i=coplanaredges_num) + { + assert(jvertices.count;j++) + { + d = Max(d,dot(convex->vertices[j],planes[i].normal)+planes[i].dist); + } + if(i==0 || d>md) + { + p=i; + md=d; + } + } + return (md>epsilon)?p:-1; +} + +template +inline int maxdir(const T *p,int count,const T &dir) +{ + assert(count); + int m=0; + float currDotm = dot(p[0], dir); + for(int i=1;i currDotm) + { + currDotm = currDoti; + m=i; + } + } + return m; +} + + +template +int maxdirfiltered(const T *p,int count,const T &dir,Array &allow) +{ + assert(count); + int m=-1; + float currDotm = dot(p[0], dir); + for(int i=0;icurrDotm) + { + currDotm = currDoti; + m=i; + } + } + } + } + assert(m!=-1); + return m; +} + +float3 orth(const float3 &v) +{ + float3 a=cross(v,float3(0,0,1)); + float3 b=cross(v,float3(0,1,0)); + return normalize((magnitude(a)>magnitude(b))?a:b); +} + + +template +int maxdirsterid(const T *p,int count,const T &dir,Array &allow) +{ + int m=-1; + while(m==-1) + { + m = maxdirfiltered(p,count,dir,allow); + if(allow[m]==3) return m; + T u = orth(dir); + T v = cross(u,dir); + int ma=-1; + for(float x = 0.0f ; x<= 360.0f ; x+= 45.0f) + { + float s = sinf(DEG2RAD*(x)); + float c = cosf(DEG2RAD*(x)); + int mb = maxdirfiltered(p,count,dir+(u*s+v*c)*0.025f,allow); + if(ma==m && mb==m) + { + allow[m]=3; + return m; + } + if(ma!=-1 && ma!=mb) // Yuck - this is really ugly + { + int mc = ma; + for(float xx = x-40.0f ; xx <= x ; xx+= 5.0f) + { + float s = sinf(DEG2RAD*(xx)); + float c = cosf(DEG2RAD*(xx)); + int md = maxdirfiltered(p,count,dir+(u*s+v*c)*0.025f,allow); + if(mc==m && md==m) + { + allow[m]=3; + return m; + } + mc=md; + } + } + ma=mb; + } + allow[m]=0; + m=-1; + } + assert(0); + return m; +} + + + + +int operator ==(const int3 &a,const int3 &b) +{ + for(int i=0;i<3;i++) + { + if(a[i]!=b[i]) return 0; + } + return 1; +} + +int3 roll3(int3 a) +{ + int tmp=a[0]; + a[0]=a[1]; + a[1]=a[2]; + a[2]=tmp; + return a; +} +int isa(const int3 &a,const int3 &b) +{ + return ( a==b || roll3(a)==b || a==roll3(b) ); +} +int b2b(const int3 &a,const int3 &b) +{ + return isa(a,int3(b[2],b[1],b[0])); +} +int above(float3* vertices,const int3& t, const float3 &p, float epsilon) +{ + float3 n=TriNormal(vertices[t[0]],vertices[t[1]],vertices[t[2]]); + return (dot(n,p-vertices[t[0]]) > epsilon); // EPSILON??? +} +int hasedge(const int3 &t, int a,int b) +{ + for(int i=0;i<3;i++) + { + int i1= (i+1)%3; + if(t[i]==a && t[i1]==b) return 1; + } + return 0; +} +int hasvert(const int3 &t, int v) +{ + return (t[0]==v || t[1]==v || t[2]==v) ; +} +int shareedge(const int3 &a,const int3 &b) +{ + int i; + for(i=0;i<3;i++) + { + int i1= (i+1)%3; + if(hasedge(a,b[i1],b[i])) return 1; + } + return 0; +} + +class btHullTriangle; + +//Array tris; + +class btHullTriangle : public int3 +{ +public: + int3 n; + int id; + int vmax; + float rise; + Array* tris; + btHullTriangle(int a,int b,int c, Array* pTris):int3(a,b,c),n(-1,-1,-1) + { + tris = pTris; + id = tris->count; + tris->Add(this); + vmax=-1; + rise = 0.0f; + } + ~btHullTriangle() + { + assert((*tris)[id]==this); + (*tris)[id]=NULL; + } + int &neib(int a,int b); +}; + + +int &btHullTriangle::neib(int a,int b) +{ + static int er=-1; + int i; + for(i=0;i<3;i++) + { + int i1=(i+1)%3; + int i2=(i+2)%3; + if((*this)[i]==a && (*this)[i1]==b) return n[i2]; + if((*this)[i]==b && (*this)[i1]==a) return n[i2]; + } + assert(0); + return er; +} +void b2bfix(btHullTriangle* s,btHullTriangle*t, Array& tris) +{ + int i; + for(i=0;i<3;i++) + { + int i1=(i+1)%3; + int i2=(i+2)%3; + int a = (*s)[i1]; + int b = (*s)[i2]; + assert(tris[s->neib(a,b)]->neib(b,a) == s->id); + assert(tris[t->neib(a,b)]->neib(b,a) == t->id); + tris[s->neib(a,b)]->neib(b,a) = t->neib(b,a); + tris[t->neib(b,a)]->neib(a,b) = s->neib(a,b); + } +} + +void removeb2b(btHullTriangle* s,btHullTriangle*t, Array& tris) +{ + b2bfix(s,t, tris); + delete s; + delete t; +} + +void checkit(btHullTriangle *t, Array& tris) +{ + int i; + assert(tris[t->id]==t); + for(i=0;i<3;i++) + { + int i1=(i+1)%3; + int i2=(i+2)%3; + int a = (*t)[i1]; + int b = (*t)[i2]; + assert(a!=b); + assert( tris[t->n[i]]->neib(b,a) == t->id); + } +} +void extrude(btHullTriangle *t0,int v, Array& tris) +{ + int3 t= *t0; + int n = tris.count; + btHullTriangle* ta = new btHullTriangle(v,t[1],t[2], &tris); + ta->n = int3(t0->n[0],n+1,n+2); + tris[t0->n[0]]->neib(t[1],t[2]) = n+0; + btHullTriangle* tb = new btHullTriangle(v,t[2],t[0], &tris); + tb->n = int3(t0->n[1],n+2,n+0); + tris[t0->n[1]]->neib(t[2],t[0]) = n+1; + btHullTriangle* tc = new btHullTriangle(v,t[0],t[1], &tris); + tc->n = int3(t0->n[2],n+0,n+1); + tris[t0->n[2]]->neib(t[0],t[1]) = n+2; + checkit(ta, tris); + checkit(tb, tris); + checkit(tc, tris); + if(hasvert(*tris[ta->n[0]],v)) removeb2b(ta,tris[ta->n[0]], tris); + if(hasvert(*tris[tb->n[0]],v)) removeb2b(tb,tris[tb->n[0]], tris); + if(hasvert(*tris[tc->n[0]],v)) removeb2b(tc,tris[tc->n[0]], tris); + delete t0; + +} + +btHullTriangle *extrudable(float epsilon, Array& tris) +{ + int i; + btHullTriangle *t=NULL; + for(i=0;iriserise)) + { + t = tris[i]; + } + } + return (t->rise >epsilon)?t:NULL ; +} + +class int4 +{ +public: + int x,y,z,w; + int4(){}; + int4(int _x,int _y, int _z,int _w){x=_x;y=_y;z=_z;w=_w;} + const int& operator[](int i) const {return (&x)[i];} + int& operator[](int i) {return (&x)[i];} +}; + + + +int4 FindSimplex(float3 *verts,int verts_count,Array &allow) +{ + float3 basis[3]; + basis[0] = float3( 0.01f, 0.02f, 1.0f ); + int p0 = maxdirsterid(verts,verts_count, basis[0],allow); + int p1 = maxdirsterid(verts,verts_count,-basis[0],allow); + basis[0] = verts[p0]-verts[p1]; + if(p0==p1 || basis[0]==float3(0,0,0)) + return int4(-1,-1,-1,-1); + basis[1] = cross(float3( 1, 0.02f, 0),basis[0]); + basis[2] = cross(float3(-0.02f, 1, 0),basis[0]); + basis[1] = normalize( (magnitude(basis[1])>magnitude(basis[2])) ? basis[1]:basis[2]); + int p2 = maxdirsterid(verts,verts_count,basis[1],allow); + if(p2 == p0 || p2 == p1) + { + p2 = maxdirsterid(verts,verts_count,-basis[1],allow); + } + if(p2 == p0 || p2 == p1) + return int4(-1,-1,-1,-1); + basis[1] = verts[p2] - verts[p0]; + basis[2] = normalize(cross(basis[1],basis[0])); + int p3 = maxdirsterid(verts,verts_count,basis[2],allow); + if(p3==p0||p3==p1||p3==p2) p3 = maxdirsterid(verts,verts_count,-basis[2],allow); + if(p3==p0||p3==p1||p3==p2) + return int4(-1,-1,-1,-1); + assert(!(p0==p1||p0==p2||p0==p3||p1==p2||p1==p3||p2==p3)); + if(dot(verts[p3]-verts[p0],cross(verts[p1]-verts[p0],verts[p2]-verts[p0])) <0) {Swap(p2,p3);} + return int4(p0,p1,p2,p3); +} + +int calchullgen(float3 *verts,int verts_count, int vlimit,Array& tris) +{ + if(verts_count <4) return 0; + if(vlimit==0) vlimit=1000000000; + int j; + float3 bmin(*verts),bmax(*verts); + Array isextreme(verts_count); + Array allow(verts_count); + for(j=0;jn=int3(2,3,1); + btHullTriangle *t1 = new btHullTriangle(p[3],p[2],p[0], &tris); t1->n=int3(3,2,0); + btHullTriangle *t2 = new btHullTriangle(p[0],p[1],p[3], &tris); t2->n=int3(0,1,3); + btHullTriangle *t3 = new btHullTriangle(p[1],p[0],p[2], &tris); t3->n=int3(1,0,2); + isextreme[p[0]]=isextreme[p[1]]=isextreme[p[2]]=isextreme[p[3]]=1; + checkit(t0, tris);checkit(t1, tris);checkit(t2, tris);checkit(t3, tris); + + for(j=0;jvmax<0); + float3 n=TriNormal(verts[(*t)[0]],verts[(*t)[1]],verts[(*t)[2]]); + t->vmax = maxdirsterid(verts,verts_count,n,allow); + t->rise = dot(n,verts[t->vmax]-verts[(*t)[0]]); + } + btHullTriangle *te; + vlimit-=4; + while(vlimit >0 && (te=extrudable(epsilon, tris))) + { + // int3 ti=*te; + int v=te->vmax; + assert(!isextreme[v]); // wtf we've already done this vertex + isextreme[v]=1; + //if(v==p0 || v==p1 || v==p2 || v==p3) continue; // done these already + j=tris.count; + while(j--) { + if(!tris[j]) continue; + int3 t=*tris[j]; + if(above(verts,t,verts[v],0.01f*epsilon)) + { + extrude(tris[j],v, tris); + } + } + // now check for those degenerate cases where we have a flipped triangle or a really skinny triangle + j=tris.count; + while(j--) + { + if(!tris[j]) continue; + if(!hasvert(*tris[j],v)) break; + int3 nt=*tris[j]; + if(above(verts,nt,center,0.01f*epsilon) || magnitude(cross(verts[nt[1]]-verts[nt[0]],verts[nt[2]]-verts[nt[1]]))< epsilon*epsilon*0.1f ) + { + btHullTriangle *nb = tris[tris[j]->n[0]]; + assert(nb);assert(!hasvert(*nb,v));assert(nb->idvmax>=0) break; + float3 n=TriNormal(verts[(*t)[0]],verts[(*t)[1]],verts[(*t)[2]]); + t->vmax = maxdirsterid(verts,verts_count,n,allow); + if(isextreme[t->vmax]) + { + t->vmax=-1; // already done that vertex - algorithm needs to be able to terminate. + } + else + { + t->rise = dot(n,verts[t->vmax]-verts[(*t)[0]]); + } + } + vlimit --; + } + return 1; +} + +int calchull(float3 *verts,int verts_count, int *&tris_out, int &tris_count,int vlimit, Array& tris) +{ + int rc=calchullgen(verts,verts_count, vlimit, tris) ; + if(!rc) return 0; + Array ts; + for(int i=0;i &planes,float bevangle, Array& tris) +{ + int i,j; + planes.count=0; + int rc = calchullgen(verts,verts_count,vlimit, tris); + if(!rc) return 0; + for(i=0;in[j]id) continue; + btHullTriangle *s = tris[t->n[j]]; + REAL3 snormal = TriNormal(verts[(*s)[0]],verts[(*s)[1]],verts[(*s)[2]]); + if(dot(snormal,p.normal)>=cos(bevangle*DEG2RAD)) continue; + REAL3 n = normalize(snormal+p.normal); + planes.Add(Plane(n,-dot(n,verts[maxdir(verts,verts_count,n)]))); + } + } + + for(i=0;i=0) + { + ConvexH *tmp = c; + c = ConvexHCrop(*tmp,planes[k]); + if(c==NULL) {c=tmp; break;} // might want to debug this case better!!! + if(!AssertIntact(*c)) {c=tmp; break;} // might want to debug this case better too!!! + delete tmp; + } + + assert(AssertIntact(*c)); + //return c; + faces_out = (int*)malloc(sizeof(int)*(1+c->facets.count+c->edges.count)); // new int[1+c->facets.count+c->edges.count]; + faces_count_out=0; + i=0; + faces_out[faces_count_out++]=-1; + k=0; + while(iedges.count) + { + j=1; + while(j+iedges.count && c->edges[i].p==c->edges[i+j].p) { j++; } + faces_out[faces_count_out++]=j; + while(j--) + { + faces_out[faces_count_out++] = c->edges[i].v; + i++; + } + k++; + } + faces_out[0]=k; // number of faces. + assert(k==c->facets.count); + assert(faces_count_out == 1+c->facets.count+c->edges.count); + verts_out = c->vertices.element; // new float3[c->vertices.count]; + verts_count_out = c->vertices.count; + for(i=0;ivertices.count;i++) + { + verts_out[i] = float3(c->vertices[i]); + } + c->vertices.count=c->vertices.array_size=0; c->vertices.element=NULL; + delete c; + return 1; +} + +int overhullv(float3 *verts, int verts_count,int maxplanes, + float3 *&verts_out, int &verts_count_out, int *&faces_out, int &faces_count_out ,float inflate,float bevangle,int vlimit, Array& tris) +{ + if(!verts_count) return 0; + extern int calchullpbev(float3 *verts,int verts_count,int vlimit, Array &planes,float bevangle, Array& tris) ; + Array planes; + int rc=calchullpbev(verts,verts_count,vlimit,planes,bevangle, tris) ; + if(!rc) return 0; + return overhull(planes.element,planes.count,verts,verts_count,maxplanes,verts_out,verts_count_out,faces_out,faces_count_out,inflate); +} + + +bool ComputeHull(unsigned int vcount,const float *vertices,PHullResult &result,unsigned int vlimit,float inflate, Array& arrtris) +{ + + int index_count; + int *faces; + float3 *verts_out; + int verts_count_out; + + if(inflate==0.0f) + { + int *tris_out; + int tris_count; + int ret = calchull( (float3 *) vertices, (int) vcount, tris_out, tris_count, vlimit, arrtris ); + if(!ret) return false; + result.mIndexCount = (unsigned int) (tris_count*3); + result.mFaceCount = (unsigned int) tris_count; + result.mVertices = (float*) vertices; + result.mVcount = (unsigned int) vcount; + result.mIndices = (unsigned int *) tris_out; + return true; + } + + int ret = overhullv((float3*)vertices,vcount,35,verts_out,verts_count_out,faces,index_count,inflate,120.0f,vlimit, arrtris); + if(!ret) return false; + + Array tris; + int n=faces[0]; + int k=1; + for(int i=0;i tris; + ok = ComputeHull(ovcount,vsource,hr,desc.mMaxVertices,skinwidth, tris); + + if ( ok ) + { + + // re-index triangle mesh so it refers to only used vertices, rebuild a new vertex table. + float *vscratch = (float *) malloc( sizeof(float)*hr.mVcount*3); + BringOutYourDead(hr.mVertices,hr.mVcount, vscratch, ovcount, hr.mIndices, hr.mIndexCount ); + + ret = QE_OK; + + if ( desc.HasHullFlag(QF_TRIANGLES) ) // if he wants the results as triangle! + { + result.mPolygons = false; + result.mNumOutputVertices = ovcount; + result.mOutputVertices = (float *)malloc( sizeof(float)*ovcount*3); + result.mNumFaces = hr.mFaceCount; + result.mNumIndices = hr.mIndexCount; + + result.mIndices = (unsigned int *) malloc( sizeof(unsigned int)*hr.mIndexCount); + + memcpy(result.mOutputVertices, vscratch, sizeof(float)*3*ovcount ); + + if ( desc.HasHullFlag(QF_REVERSE_ORDER) ) + { + + const unsigned int *source = hr.mIndices; + unsigned int *dest = result.mIndices; + + for (unsigned int i=0; i bmax[j] ) bmax[j] = p[j]; + } + } + } + + float dx = bmax[0] - bmin[0]; + float dy = bmax[1] - bmin[1]; + float dz = bmax[2] - bmin[2]; + + float center[3]; + + center[0] = dx*0.5f + bmin[0]; + center[1] = dy*0.5f + bmin[1]; + center[2] = dz*0.5f + bmin[2]; + + if ( dx < EPSILON || dy < EPSILON || dz < EPSILON || svcount < 3 ) + { + + float len = FLT_MAX; + + if ( dx > EPSILON && dx < len ) len = dx; + if ( dy > EPSILON && dy < len ) len = dy; + if ( dz > EPSILON && dz < len ) len = dz; + + if ( len == FLT_MAX ) + { + dx = dy = dz = 0.01f; // one centimeter + } + else + { + if ( dx < EPSILON ) dx = len * 0.05f; // 1/5th the shortest non-zero edge. + if ( dy < EPSILON ) dy = len * 0.05f; + if ( dz < EPSILON ) dz = len * 0.05f; + } + + float x1 = center[0] - dx; + float x2 = center[0] + dx; + + float y1 = center[1] - dy; + float y2 = center[1] + dy; + + float z1 = center[2] - dz; + float z2 = center[2] + dz; + + addPoint(vcount,vertices,x1,y1,z1); + addPoint(vcount,vertices,x2,y1,z1); + addPoint(vcount,vertices,x2,y2,z1); + addPoint(vcount,vertices,x1,y2,z1); + addPoint(vcount,vertices,x1,y1,z2); + addPoint(vcount,vertices,x2,y1,z2); + addPoint(vcount,vertices,x2,y2,z2); + addPoint(vcount,vertices,x1,y2,z2); + + return true; // return cube + + + } + else + { + if ( scale ) + { + scale[0] = dx; + scale[1] = dy; + scale[2] = dz; + + recip[0] = 1 / dx; + recip[1] = 1 / dy; + recip[2] = 1 / dz; + + center[0]*=recip[0]; + center[1]*=recip[1]; + center[2]*=recip[2]; + + } + + } + + + + vtx = (const char *) svertices; + + for (unsigned int i=0; i dist2 ) + { + v[0] = px; + v[1] = py; + v[2] = pz; + } + + break; + } + } + + if ( j == vcount ) + { + float *dest = &vertices[vcount*3]; + dest[0] = px; + dest[1] = py; + dest[2] = pz; + vcount++; + } + } + } + + // ok..now make sure we didn't prune so many vertices it is now invalid. + if ( 1 ) + { + float bmin[3] = { FLT_MAX, FLT_MAX, FLT_MAX }; + float bmax[3] = { -FLT_MAX, -FLT_MAX, -FLT_MAX }; + + for (unsigned int i=0; i bmax[j] ) bmax[j] = p[j]; + } + } + + float dx = bmax[0] - bmin[0]; + float dy = bmax[1] - bmin[1]; + float dz = bmax[2] - bmin[2]; + + if ( dx < EPSILON || dy < EPSILON || dz < EPSILON || vcount < 3) + { + float cx = dx*0.5f + bmin[0]; + float cy = dy*0.5f + bmin[1]; + float cz = dz*0.5f + bmin[2]; + + float len = FLT_MAX; + + if ( dx >= EPSILON && dx < len ) len = dx; + if ( dy >= EPSILON && dy < len ) len = dy; + if ( dz >= EPSILON && dz < len ) len = dz; + + if ( len == FLT_MAX ) + { + dx = dy = dz = 0.01f; // one centimeter + } + else + { + if ( dx < EPSILON ) dx = len * 0.05f; // 1/5th the shortest non-zero edge. + if ( dy < EPSILON ) dy = len * 0.05f; + if ( dz < EPSILON ) dz = len * 0.05f; + } + + float x1 = cx - dx; + float x2 = cx + dx; + + float y1 = cy - dy; + float y2 = cy + dy; + + float z1 = cz - dz; + float z2 = cz + dz; + + vcount = 0; // add box + + addPoint(vcount,vertices,x1,y1,z1); + addPoint(vcount,vertices,x2,y1,z1); + addPoint(vcount,vertices,x2,y2,z1); + addPoint(vcount,vertices,x1,y2,z1); + addPoint(vcount,vertices,x1,y1,z2); + addPoint(vcount,vertices,x2,y1,z2); + addPoint(vcount,vertices,x2,y2,z2); + addPoint(vcount,vertices,x1,y2,z2); + + return true; + } + } + + return true; +} + +void HullLibrary::BringOutYourDead(const float *verts,unsigned int vcount, float *overts,unsigned int &ocount,unsigned int *indices,unsigned indexcount) +{ + unsigned int *used = (unsigned int *)malloc(sizeof(unsigned int)*vcount); + memset(used,0,sizeof(unsigned int)*vcount); + + ocount = 0; + + for (unsigned int i=0; i= 0 && v < vcount ); + + if ( used[v] ) // if already remapped + { + indices[i] = used[v]-1; // index to new array + } + else + { + + indices[i] = ocount; // new index mapping + + overts[ocount*3+0] = verts[v*3+0]; // copy old vert to new vert array + overts[ocount*3+1] = verts[v*3+1]; + overts[ocount*3+2] = verts[v*3+2]; + + ocount++; // increment output vert count + + assert( ocount >=0 && ocount <= vcount ); + + used[v] = ocount; // assign new index remapping + } + } + + free(used); +} + +} diff --git a/Extras/ConvexDecomposition/cd_hull.h b/Extras/ConvexDecomposition/cd_hull.h new file mode 100644 index 0000000000..420e241b2e --- /dev/null +++ b/Extras/ConvexDecomposition/cd_hull.h @@ -0,0 +1,153 @@ +#ifndef CD_HULL_H + +#define CD_HULL_H + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +namespace ConvexDecomposition +{ + +class HullResult +{ +public: + HullResult(void) + { + mPolygons = true; + mNumOutputVertices = 0; + mOutputVertices = 0; + mNumFaces = 0; + mNumIndices = 0; + mIndices = 0; + } + bool mPolygons; // true if indices represents polygons, false indices are triangles + unsigned int mNumOutputVertices; // number of vertices in the output hull + float *mOutputVertices; // array of vertices, 3 floats each x,y,z + unsigned int mNumFaces; // the number of faces produced + unsigned int mNumIndices; // the total number of indices + unsigned int *mIndices; // pointer to indices. + +// If triangles, then indices are array indexes into the vertex list. +// If polygons, indices are in the form (number of points in face) (p1, p2, p3, ..) etc.. +}; + +enum HullFlag +{ + QF_TRIANGLES = (1<<0), // report results as triangles, not polygons. + QF_REVERSE_ORDER = (1<<1), // reverse order of the triangle indices. + QF_SKIN_WIDTH = (1<<2), // extrude hull based on this skin width + QF_DEFAULT = 0 +}; + + +class HullDesc +{ +public: + HullDesc(void) + { + mFlags = QF_DEFAULT; + mVcount = 0; + mVertices = 0; + mVertexStride = sizeof(float)*3; + mNormalEpsilon = 0.001f; + mMaxVertices = 4096; // maximum number of points to be considered for a convex hull. + mMaxFaces = 4096; + mSkinWidth = 0.01f; // default is one centimeter + }; + + HullDesc(HullFlag flag, + unsigned int vcount, + const float *vertices, + unsigned int stride) + { + mFlags = flag; + mVcount = vcount; + mVertices = vertices; + mVertexStride = stride; + mNormalEpsilon = 0.001f; + mMaxVertices = 4096; + mSkinWidth = 0.01f; // default is one centimeter + } + + bool HasHullFlag(HullFlag flag) const + { + if ( mFlags & flag ) return true; + return false; + } + + void SetHullFlag(HullFlag flag) + { + mFlags|=flag; + } + + void ClearHullFlag(HullFlag flag) + { + mFlags&=~flag; + } + + unsigned int mFlags; // flags to use when generating the convex hull. + unsigned int mVcount; // number of vertices in the input point cloud + const float *mVertices; // the array of vertices. + unsigned int mVertexStride; // the stride of each vertex, in bytes. + float mNormalEpsilon; // the epsilon for removing duplicates. This is a normalized value, if normalized bit is on. + float mSkinWidth; + unsigned int mMaxVertices; // maximum number of vertices to be considered for the hull! + unsigned int mMaxFaces; +}; + +enum HullError +{ + QE_OK, // success! + QE_FAIL // failed. +}; + +class HullLibrary +{ +public: + + HullError CreateConvexHull(const HullDesc &desc, // describes the input request + HullResult &result); // contains the resulst + + HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it. + +private: + + void BringOutYourDead(const float *verts,unsigned int vcount, float *overts,unsigned int &ocount,unsigned int *indices,unsigned indexcount); + + bool CleanupVertices(unsigned int svcount, + const float *svertices, + unsigned int stride, + unsigned int &vcount, // output number of vertices + float *vertices, // location to store the results. + float normalepsilon, + float *scale); +}; + +} + +#endif + diff --git a/Extras/ConvexDecomposition/cd_vector.h b/Extras/ConvexDecomposition/cd_vector.h new file mode 100644 index 0000000000..bd1eff25b3 --- /dev/null +++ b/Extras/ConvexDecomposition/cd_vector.h @@ -0,0 +1,1185 @@ +#ifndef CD_VECTOR_H + +#define CD_VECTOR_H + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + +#pragma warning(disable:4786) + +#include +#include +#include + +namespace ConvexDecomposition +{ + + +const float DEG_TO_RAD = ((2.0f * 3.14152654f) / 360.0f); +const float RAD_TO_DEG = (360.0f / (2.0f * 3.141592654f)); + +class Vector3d +{ +public: + Vector3d(void) { }; // null constructor, does not inialize point. + + Vector3d(const Vector3d &a) // constructor copies existing vector. + { + x = a.x; + y = a.y; + z = a.z; + }; + + Vector3d(float a,float b,float c) // construct with initial point. + { + x = a; + y = b; + z = c; + }; + + Vector3d(const float *t) + { + x = t[0]; + y = t[1]; + z = t[2]; + }; + + Vector3d(const int *t) + { + x = t[0]; + y = t[1]; + z = t[2]; + }; + + bool operator==(const Vector3d &a) const + { + return( a.x == x && a.y == y && a.z == z ); + }; + + bool operator!=(const Vector3d &a) const + { + return( a.x != x || a.y != y || a.z != z ); + }; + +// Operators + Vector3d& operator = (const Vector3d& A) // ASSIGNMENT (=) + { x=A.x; y=A.y; z=A.z; + return(*this); }; + + Vector3d operator + (const Vector3d& A) const // ADDITION (+) + { Vector3d Sum(x+A.x, y+A.y, z+A.z); + return(Sum); }; + + Vector3d operator - (const Vector3d& A) const // SUBTRACTION (-) + { Vector3d Diff(x-A.x, y-A.y, z-A.z); + return(Diff); }; + + Vector3d operator * (const float s) const // MULTIPLY BY SCALAR (*) + { Vector3d Scaled(x*s, y*s, z*s); + return(Scaled); }; + + + Vector3d operator + (const float s) const // ADD CONSTANT TO ALL 3 COMPONENTS (*) + { Vector3d Scaled(x+s, y+s, z+s); + return(Scaled); }; + + + + + Vector3d operator / (const float s) const // DIVIDE BY SCALAR (/) + { + float r = 1.0f / s; + Vector3d Scaled(x*r, y*r, z*r); + return(Scaled); + }; + + void operator /= (float A) // ACCUMULATED VECTOR ADDITION (/=) + { x/=A; y/=A; z/=A; }; + + void operator += (const Vector3d A) // ACCUMULATED VECTOR ADDITION (+=) + { x+=A.x; y+=A.y; z+=A.z; }; + void operator -= (const Vector3d A) // ACCUMULATED VECTOR SUBTRACTION (+=) + { x-=A.x; y-=A.y; z-=A.z; }; + void operator *= (const float s) // ACCUMULATED SCALAR MULTIPLICATION (*=) (bpc 4/24/2000) + {x*=s; y*=s; z*=s;} + + void operator += (const float A) // ACCUMULATED VECTOR ADDITION (+=) + { x+=A; y+=A; z+=A; }; + + + Vector3d operator - (void) const // NEGATION (-) + { Vector3d Negated(-x, -y, -z); + return(Negated); }; + + float operator [] (const int i) const // ALLOWS VECTOR ACCESS AS AN ARRAY. + { return( (i==0)?x:((i==1)?y:z) ); }; + float & operator [] (const int i) + { return( (i==0)?x:((i==1)?y:z) ); }; +// + + // accessor methods. + float GetX(void) const { return x; }; + float GetY(void) const { return y; }; + float GetZ(void) const { return z; }; + + float X(void) const { return x; }; + float Y(void) const { return y; }; + float Z(void) const { return z; }; + + void SetX(float t) { x = t; }; + void SetY(float t) { y = t; }; + void SetZ(float t) { z = t; }; + + bool IsSame(const Vector3d &v,float epsilon) const + { + float dx = fabsf( x - v.x ); + if ( dx > epsilon ) return false; + float dy = fabsf( y - v.y ); + if ( dy > epsilon ) return false; + float dz = fabsf( z - v.z ); + if ( dz > epsilon ) return false; + return true; + } + + + float ComputeNormal(const Vector3d &A, + const Vector3d &B, + const Vector3d &C) + { + float vx,vy,vz,wx,wy,wz,vw_x,vw_y,vw_z,mag; + + vx = (B.x - C.x); + vy = (B.y - C.y); + vz = (B.z - C.z); + + wx = (A.x - B.x); + wy = (A.y - B.y); + wz = (A.z - B.z); + + vw_x = vy * wz - vz * wy; + vw_y = vz * wx - vx * wz; + vw_z = vx * wy - vy * wx; + + mag = sqrtf((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z)); + + if ( mag < 0.000001f ) + { + mag = 0; + } + else + { + mag = 1.0f/mag; + } + + x = vw_x * mag; + y = vw_y * mag; + z = vw_z * mag; + + return mag; + } + + + void ScaleSumScale(float c0,float c1,const Vector3d &pos) + { + x = (x*c0) + (pos.x*c1); + y = (y*c0) + (pos.y*c1); + z = (z*c0) + (pos.z*c1); + } + + void SwapYZ(void) + { + float t = y; + y = z; + z = t; + }; + + void Get(float *v) const + { + v[0] = x; + v[1] = y; + v[2] = z; + }; + + void Set(const int *p) + { + x = (float) p[0]; + y = (float) p[1]; + z = (float) p[2]; + } + + void Set(const float *p) + { + x = (float) p[0]; + y = (float) p[1]; + z = (float) p[2]; + } + + + void Set(float a,float b,float c) + { + x = a; + y = b; + z = c; + }; + + void Zero(void) + { + x = y = z = 0; + }; + + const float* Ptr() const { return &x; } + float* Ptr() { return &x; } + + +// return -(*this). + Vector3d negative(void) const + { + Vector3d result; + result.x = -x; + result.y = -y; + result.z = -z; + return result; + } + + float Magnitude(void) const + { + return float(sqrt(x * x + y * y + z * z)); + }; + + float FastMagnitude(void) const + { + return float(sqrtf(x * x + y * y + z * z)); + }; + + float FasterMagnitude(void) const + { + return float(sqrtf(x * x + y * y + z * z)); + }; + + void Lerp(const Vector3d& from,const Vector3d& to,float slerp) + { + x = ((to.x - from.x) * slerp) + from.x; + y = ((to.y - from.y) * slerp) + from.y; + z = ((to.z - from.z) * slerp) + from.z; + }; + + // Highly specialized interpolate routine. Will compute the interpolated position + // shifted forward or backwards along the ray defined between (from) and (to). + // Reason for existance is so that when a bullet collides with a wall, for + // example, you can generate a graphic effect slightly *before* it hit the + // wall so that the effect doesn't sort into the wall itself. + void Interpolate(const Vector3d &from,const Vector3d &to,float offset) + { + x = to.x-from.x; + y = to.y-from.y; + z = to.z-from.z; + float d = sqrtf( x*x + y*y + z*z ); + float recip = 1.0f / d; + x*=recip; + y*=recip; + z*=recip; // normalize vector + d+=offset; // shift along ray + x = x*d + from.x; + y = y*d + from.y; + z = z*d + from.z; + }; + + bool BinaryEqual(const Vector3d &p) const + { + const int *source = (const int *) &x; + const int *dest = (const int *) &p.x; + + if ( source[0] == dest[0] && + source[1] == dest[1] && + source[2] == dest[2] ) return true; + + return false; + }; + + /*bool BinaryEqual(const Vector3d &p) const + { + if ( x == p.x && y == p.y && z == p.z ) return true; + return false; + } + */ + + + +/** Computes the reflection vector between two vectors.*/ + void Reflection(const Vector3d &a,const Vector3d &b)// compute reflection vector. + { + Vector3d c; + Vector3d d; + + float dot = a.Dot(b) * 2.0f; + + c = b * dot; + + d = c - a; + + x = -d.x; + y = -d.y; + z = -d.z; + }; + + void AngleAxis(float angle,const Vector3d& axis) + { + x = axis.x*angle; + y = axis.y*angle; + z = axis.z*angle; + }; + + float Length(void) const // length of vector. + { + return float(sqrt( x*x + y*y + z*z )); + }; + + + float ComputePlane(const Vector3d &A, + const Vector3d &B, + const Vector3d &C) + { + float vx,vy,vz,wx,wy,wz,vw_x,vw_y,vw_z,mag; + + vx = (B.x - C.x); + vy = (B.y - C.y); + vz = (B.z - C.z); + + wx = (A.x - B.x); + wy = (A.y - B.y); + wz = (A.z - B.z); + + vw_x = vy * wz - vz * wy; + vw_y = vz * wx - vx * wz; + vw_z = vx * wy - vy * wx; + + mag = sqrtf((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z)); + + if ( mag < 0.000001f ) + { + mag = 0; + } + else + { + mag = 1.0f/mag; + } + + x = vw_x * mag; + y = vw_y * mag; + z = vw_z * mag; + + + float D = 0.0f - ((x*A.x)+(y*A.y)+(z*A.z)); + + return D; + } + + + float FastLength(void) const // length of vector. + { + return float(sqrtf( x*x + y*y + z*z )); + }; + + + float FasterLength(void) const // length of vector. + { + return float(sqrtf( x*x + y*y + z*z )); + }; + + float Length2(void) const // squared distance, prior to square root. + { + float l2 = x*x+y*y+z*z; + return l2; + }; + + float Distance(const Vector3d &a) const // distance between two points. + { + Vector3d d(a.x-x,a.y-y,a.z-z); + return d.Length(); + } + + float FastDistance(const Vector3d &a) const // distance between two points. + { + Vector3d d(a.x-x,a.y-y,a.z-z); + return d.FastLength(); + } + + float FasterDistance(const Vector3d &a) const // distance between two points. + { + Vector3d d(a.x-x,a.y-y,a.z-z); + return d.FasterLength(); + } + + + float DistanceXY(const Vector3d &a) const + { + float dx = a.x - x; + float dy = a.y - y; + float dist = dx*dx + dy*dy; + return dist; + } + + float Distance2(const Vector3d &a) const // squared distance. + { + float dx = a.x - x; + float dy = a.y - y; + float dz = a.z - z; + return dx*dx + dy*dy + dz*dz; + }; + + float Partial(const Vector3d &p) const + { + return (x*p.y) - (p.x*y); + } + + float Area(const Vector3d &p1,const Vector3d &p2) const + { + float A = Partial(p1); + A+= p1.Partial(p2); + A+= p2.Partial(*this); + return A*0.5f; + } + + inline float Normalize(void) // normalize to a unit vector, returns distance. + { + float d = sqrtf( static_cast< float >( x*x + y*y + z*z ) ); + if ( d > 0 ) + { + float r = 1.0f / d; + x *= r; + y *= r; + z *= r; + } + else + { + x = y = z = 1; + } + return d; + }; + + inline float FastNormalize(void) // normalize to a unit vector, returns distance. + { + float d = sqrt( static_cast< float >( x*x + y*y + z*z ) ); + if ( d > 0 ) + { + float r = 1.0f / d; + x *= r; + y *= r; + z *= r; + } + else + { + x = y = z = 1; + } + return d; + }; + + inline float FasterNormalize(void) // normalize to a unit vector, returns distance. + { + float d = sqrtf( static_cast< float >( x*x + y*y + z*z ) ); + if ( d > 0 ) + { + float r = 1.0f / d; + x *= r; + y *= r; + z *= r; + } + else + { + x = y = z = 1; + } + return d; + }; + + + + + float Dot(const Vector3d &a) const // computes dot product. + { + return (x * a.x + y * a.y + z * a.z ); + }; + + + Vector3d Cross( const Vector3d& other ) const + { + Vector3d result( y*other.z - z*other.y, z*other.x - x*other.z, x*other.y - y*other.x ); + + return result; + } + + void Cross(const Vector3d &a,const Vector3d &b) // cross two vectors result in this one. + { + x = a.y*b.z - a.z*b.y; + y = a.z*b.x - a.x*b.z; + z = a.x*b.y - a.y*b.x; + }; + + /******************************************/ + // Check if next edge (b to c) turns inward + // + // Edge from a to b is already in face + // Edge from b to c is being considered for addition to face + /******************************************/ + bool Concave(const Vector3d& a,const Vector3d& b) + { + float vx,vy,vz,wx,wy,wz,vw_x,vw_y,vw_z,mag,nx,ny,nz,mag_a,mag_b; + + wx = b.x - a.x; + wy = b.y - a.y; + wz = b.z - a.z; + + mag_a = (float) sqrtf((wx * wx) + (wy * wy) + (wz * wz)); + + vx = x - b.x; + vy = y - b.y; + vz = z - b.z; + + mag_b = (float) sqrtf((vx * vx) + (vy * vy) + (vz * vz)); + + vw_x = (vy * wz) - (vz * wy); + vw_y = (vz * wx) - (vx * wz); + vw_z = (vx * wy) - (vy * wx); + + mag = (float) sqrtf((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z)); + + // Check magnitude of cross product, which is a sine function + // i.e., mag (a x b) = mag (a) * mag (b) * sin (theta); + // If sin (theta) small, then angle between edges is very close to + // 180, which we may want to call a concavity. Setting the + // CONCAVITY_TOLERANCE value greater than about 0.01 MAY cause + // face consolidation to get stuck on particular face. Most meshes + // convert properly with a value of 0.0 + + if (mag/(mag_a*mag_b) <= 0.0f ) return true; + + mag = 1.0f / mag; + + nx = vw_x * mag; + ny = vw_y * mag; + nz = vw_z * mag; + + // Dot product of tri normal with cross product result will + // yield positive number if edges are convex (+1.0 if two tris + // are coplanar), negative number if edges are concave (-1.0 if + // two tris are coplanar.) + + mag = ( x * nx) + ( y * ny) + ( z * nz); + + if (mag > 0.0f ) return false; + + return(true); + }; + + bool PointTestXY(const Vector3d &i,const Vector3d &j) const + { + if (((( i.y <= y ) && ( y < j.y )) || + (( j.y <= y ) && ( y < i.y ))) && + ( x < (j.x - i.x) * (y - i.y) / (j.y - i.y) + i.x)) return true; + return false; + } + + // test to see if this point is inside the triangle specified by + // these three points on the X/Y plane. + bool PointInTriXY(const Vector3d &p1, + const Vector3d &p2, + const Vector3d &p3) const + { + float ax = p3.x - p2.x; + float ay = p3.y - p2.y; + float bx = p1.x - p3.x; + float by = p1.y - p3.y; + float cx = p2.x - p1.x; + float cy = p2.y - p1.y; + float apx = x - p1.x; + float apy = y - p1.y; + float bpx = x - p2.x; + float bpy = y - p2.y; + float cpx = x - p3.x; + float cpy = y - p3.y; + + float aCROSSbp = ax*bpy - ay*bpx; + float cCROSSap = cx*apy - cy*apx; + float bCROSScp = bx*cpy - by*cpx; + + return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); + }; + + // test to see if this point is inside the triangle specified by + // these three points on the X/Y plane. + bool PointInTriYZ(const Vector3d &p1, + const Vector3d &p2, + const Vector3d &p3) const + { + float ay = p3.y - p2.y; + float az = p3.z - p2.z; + float by = p1.y - p3.y; + float bz = p1.z - p3.z; + float cy = p2.y - p1.y; + float cz = p2.z - p1.z; + float apy = y - p1.y; + float apz = z - p1.z; + float bpy = y - p2.y; + float bpz = z - p2.z; + float cpy = y - p3.y; + float cpz = z - p3.z; + + float aCROSSbp = ay*bpz - az*bpy; + float cCROSSap = cy*apz - cz*apy; + float bCROSScp = by*cpz - bz*cpy; + + return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); + }; + + + // test to see if this point is inside the triangle specified by + // these three points on the X/Y plane. + bool PointInTriXZ(const Vector3d &p1, + const Vector3d &p2, + const Vector3d &p3) const + { + float az = p3.z - p2.z; + float ax = p3.x - p2.x; + float bz = p1.z - p3.z; + float bx = p1.x - p3.x; + float cz = p2.z - p1.z; + float cx = p2.x - p1.x; + float apz = z - p1.z; + float apx = x - p1.x; + float bpz = z - p2.z; + float bpx = x - p2.x; + float cpz = z - p3.z; + float cpx = x - p3.x; + + float aCROSSbp = az*bpx - ax*bpz; + float cCROSSap = cz*apx - cx*apz; + float bCROSScp = bz*cpx - bx*cpz; + + return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); + }; + + // Given a point and a line (defined by two points), compute the closest point + // in the line. (The line is treated as infinitely long.) + void NearestPointInLine(const Vector3d &point, + const Vector3d &line0, + const Vector3d &line1) + { + Vector3d &nearestPoint = *this; + Vector3d lineDelta = line1 - line0; + + // Handle degenerate lines + if ( lineDelta == Vector3d(0, 0, 0) ) + { + nearestPoint = line0; + } + else + { + float delta = (point-line0).Dot(lineDelta) / (lineDelta).Dot(lineDelta); + nearestPoint = line0 + lineDelta*delta; + } + } + + // Given a point and a line segment (defined by two points), compute the closest point + // in the line. Cap the point at the endpoints of the line segment. + void NearestPointInLineSegment(const Vector3d &point, + const Vector3d &line0, + const Vector3d &line1) + { + Vector3d &nearestPoint = *this; + Vector3d lineDelta = line1 - line0; + + // Handle degenerate lines + if ( lineDelta == Vector3d(0, 0, 0) ) + { + nearestPoint = line0; + } + else + { + float delta = (point-line0).Dot(lineDelta) / (lineDelta).Dot(lineDelta); + + // Clamp the point to conform to the segment's endpoints + if ( delta < 0 ) + delta = 0; + else if ( delta > 1 ) + delta = 1; + + nearestPoint = line0 + lineDelta*delta; + } + } + + // Given a point and a plane (defined by three points), compute the closest point + // in the plane. (The plane is unbounded.) + void NearestPointInPlane(const Vector3d &point, + const Vector3d &triangle0, + const Vector3d &triangle1, + const Vector3d &triangle2) + { + Vector3d &nearestPoint = *this; + Vector3d lineDelta0 = triangle1 - triangle0; + Vector3d lineDelta1 = triangle2 - triangle0; + Vector3d pointDelta = point - triangle0; + Vector3d normal; + + // Get the normal of the polygon (doesn't have to be a unit vector) + normal.Cross(lineDelta0, lineDelta1); + + float delta = normal.Dot(pointDelta) / normal.Dot(normal); + nearestPoint = point - normal*delta; + } + + // Given a point and a plane (defined by a coplanar point and a normal), compute the closest point + // in the plane. (The plane is unbounded.) + void NearestPointInPlane(const Vector3d &point, + const Vector3d &planePoint, + const Vector3d &planeNormal) + { + Vector3d &nearestPoint = *this; + Vector3d pointDelta = point - planePoint; + + float delta = planeNormal.Dot(pointDelta) / planeNormal.Dot(planeNormal); + nearestPoint = point - planeNormal*delta; + } + + // Given a point and a triangle (defined by three points), compute the closest point + // in the triangle. Clamp the point so it's confined to the area of the triangle. + void NearestPointInTriangle(const Vector3d &point, + const Vector3d &triangle0, + const Vector3d &triangle1, + const Vector3d &triangle2) + { + static const Vector3d zeroVector(0, 0, 0); + + Vector3d &nearestPoint = *this; + + Vector3d lineDelta0 = triangle1 - triangle0; + Vector3d lineDelta1 = triangle2 - triangle0; + + // Handle degenerate triangles + if ( (lineDelta0 == zeroVector) || (lineDelta1 == zeroVector) ) + { + nearestPoint.NearestPointInLineSegment(point, triangle1, triangle2); + } + else if ( lineDelta0 == lineDelta1 ) + { + nearestPoint.NearestPointInLineSegment(point, triangle0, triangle1); + } + + else + { + Vector3d axis[3]; + axis[0].NearestPointInLine(triangle0, triangle1, triangle2); + axis[1].NearestPointInLine(triangle1, triangle0, triangle2); + axis[2].NearestPointInLine(triangle2, triangle0, triangle1); + + float axisDot[3]; + axisDot[0] = (triangle0-axis[0]).Dot(point-axis[0]); + axisDot[1] = (triangle1-axis[1]).Dot(point-axis[1]); + axisDot[2] = (triangle2-axis[2]).Dot(point-axis[2]); + + bool bForce = true; + float bestMagnitude2 = 0; + float closeMagnitude2; + Vector3d closePoint; + + if ( axisDot[0] < 0 ) + { + closePoint.NearestPointInLineSegment(point, triangle1, triangle2); + closeMagnitude2 = point.Distance2(closePoint); + if ( bForce || (bestMagnitude2 > closeMagnitude2) ) + { + bForce = false; + bestMagnitude2 = closeMagnitude2; + nearestPoint = closePoint; + } + } + if ( axisDot[1] < 0 ) + { + closePoint.NearestPointInLineSegment(point, triangle0, triangle2); + closeMagnitude2 = point.Distance2(closePoint); + if ( bForce || (bestMagnitude2 > closeMagnitude2) ) + { + bForce = false; + bestMagnitude2 = closeMagnitude2; + nearestPoint = closePoint; + } + } + if ( axisDot[2] < 0 ) + { + closePoint.NearestPointInLineSegment(point, triangle0, triangle1); + closeMagnitude2 = point.Distance2(closePoint); + if ( bForce || (bestMagnitude2 > closeMagnitude2) ) + { + bForce = false; + bestMagnitude2 = closeMagnitude2; + nearestPoint = closePoint; + } + } + + // If bForce is true at this point, it means the nearest point lies + // inside the triangle; use the nearest-point-on-a-plane equation + if ( bForce ) + { + Vector3d normal; + + // Get the normal of the polygon (doesn't have to be a unit vector) + normal.Cross(lineDelta0, lineDelta1); + + Vector3d pointDelta = point - triangle0; + float delta = normal.Dot(pointDelta) / normal.Dot(normal); + + nearestPoint = point - normal*delta; + } + } + } + + +//private: + + float x; + float y; + float z; +}; + + +class Vector2d +{ +public: + Vector2d(void) { }; // null constructor, does not inialize point. + + Vector2d(const Vector2d &a) // constructor copies existing vector. + { + x = a.x; + y = a.y; + }; + + Vector2d(const float *t) + { + x = t[0]; + y = t[1]; + }; + + + Vector2d(float a,float b) // construct with initial point. + { + x = a; + y = b; + }; + + const float* Ptr() const { return &x; } + float* Ptr() { return &x; } + + Vector2d & operator+=(const Vector2d &a) // += operator. + { + x+=a.x; + y+=a.y; + return *this; + }; + + Vector2d & operator-=(const Vector2d &a) + { + x-=a.x; + y-=a.y; + return *this; + }; + + Vector2d & operator*=(const Vector2d &a) + { + x*=a.x; + y*=a.y; + return *this; + }; + + Vector2d & operator/=(const Vector2d &a) + { + x/=a.x; + y/=a.y; + return *this; + }; + + bool operator==(const Vector2d &a) const + { + if ( a.x == x && a.y == y ) return true; + return false; + }; + + bool operator!=(const Vector2d &a) const + { + if ( a.x != x || a.y != y ) return true; + return false; + }; + + Vector2d operator+(Vector2d a) const + { + a.x+=x; + a.y+=y; + return a; + }; + + Vector2d operator-(Vector2d a) const + { + a.x = x-a.x; + a.y = y-a.y; + return a; + }; + + Vector2d operator - (void) const + { + return negative(); + }; + + Vector2d operator*(Vector2d a) const + { + a.x*=x; + a.y*=y; + return a; + }; + + Vector2d operator*(float c) const + { + Vector2d a; + + a.x = x * c; + a.y = y * c; + + return a; + }; + + Vector2d operator/(Vector2d a) const + { + a.x = x/a.x; + a.y = y/a.y; + return a; + }; + + + float Dot(const Vector2d &a) const // computes dot product. + { + return (x * a.x + y * a.y ); + }; + + float GetX(void) const { return x; }; + float GetY(void) const { return y; }; + + void SetX(float t) { x = t; }; + void SetY(float t) { y = t; }; + + void Set(float a,float b) + { + x = a; + y = b; + }; + + void Zero(void) + { + x = y = 0; + }; + + Vector2d negative(void) const + { + Vector2d result; + result.x = -x; + result.y = -y; + return result; + } + + float magnitude(void) const + { + return (float) sqrtf(x * x + y * y ); + } + + float fastmagnitude(void) const + { + return (float) sqrtf(x * x + y * y ); + } + + float fastermagnitude(void) const + { + return (float) sqrtf( x * x + y * y ); + } + + void Reflection(Vector2d &a,Vector2d &b); // compute reflection vector. + + float Length(void) const // length of vector. + { + return float(sqrtf( x*x + y*y )); + }; + + float FastLength(void) const // length of vector. + { + return float(sqrtf( x*x + y*y )); + }; + + float FasterLength(void) const // length of vector. + { + return float(sqrtf( x*x + y*y )); + }; + + float Length2(void) // squared distance, prior to square root. + { + return x*x+y*y; + } + + float Distance(const Vector2d &a) const // distance between two points. + { + float dx = a.x - x; + float dy = a.y - y; + float d = dx*dx+dy*dy; + return sqrtf(d); + }; + + float FastDistance(const Vector2d &a) const // distance between two points. + { + float dx = a.x - x; + float dy = a.y - y; + float d = dx*dx+dy*dy; + return sqrtf(d); + }; + + float FasterDistance(const Vector2d &a) const // distance between two points. + { + float dx = a.x - x; + float dy = a.y - y; + float d = dx*dx+dy*dy; + return sqrtf(d); + }; + + float Distance2(Vector2d &a) // squared distance. + { + float dx = a.x - x; + float dy = a.y - y; + return dx*dx + dy *dy; + }; + + void Lerp(const Vector2d& from,const Vector2d& to,float slerp) + { + x = ((to.x - from.x)*slerp) + from.x; + y = ((to.y - from.y)*slerp) + from.y; + }; + + + void Cross(const Vector2d &a,const Vector2d &b) // cross two vectors result in this one. + { + x = a.y*b.x - a.x*b.y; + y = a.x*b.x - a.x*b.x; + }; + + float Normalize(void) // normalize to a unit vector, returns distance. + { + float l = Length(); + if ( l != 0 ) + { + l = float( 1 ) / l; + x*=l; + y*=l; + } + else + { + x = y = 0; + } + return l; + }; + + float FastNormalize(void) // normalize to a unit vector, returns distance. + { + float l = FastLength(); + if ( l != 0 ) + { + l = float( 1 ) / l; + x*=l; + y*=l; + } + else + { + x = y = 0; + } + return l; + }; + + float FasterNormalize(void) // normalize to a unit vector, returns distance. + { + float l = FasterLength(); + if ( l != 0 ) + { + l = float( 1 ) / l; + x*=l; + y*=l; + } + else + { + x = y = 0; + } + return l; + }; + + + float x; + float y; +}; + +class Line +{ +public: + Line(const Vector3d &from,const Vector3d &to) + { + mP1 = from; + mP2 = to; + }; + // JWR Test for the intersection of two lines. + + bool Intersect(const Line& src,Vector3d §); +private: + Vector3d mP1; + Vector3d mP2; + +}; + + +typedef std::vector< Vector3d > Vector3dVector; +typedef std::vector< Vector2d > Vector2dVector; + +inline Vector3d operator * (float s, const Vector3d &v ) +{ + Vector3d Scaled(v.x*s, v.y*s, v.z*s); + return(Scaled); +} + +inline Vector2d operator * (float s, const Vector2d &v ) + { + Vector2d Scaled(v.x*s, v.y*s); + return(Scaled); + } + +} + +#endif diff --git a/Extras/ConvexDecomposition/cd_wavefront.cpp b/Extras/ConvexDecomposition/cd_wavefront.cpp new file mode 100644 index 0000000000..54e8bdf68e --- /dev/null +++ b/Extras/ConvexDecomposition/cd_wavefront.cpp @@ -0,0 +1,860 @@ +#include +#include +#include +#include +#include + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// +#include "float_math.h" + +#include "cd_wavefront.h" + + +using namespace ConvexDecomposition; + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +#include + +namespace ConvexDecomposition +{ + +typedef std::vector< int > IntVector; +typedef std::vector< float > FloatVector; + +#if defined(__APPLE__) || defined(__CELLOS_LV2__) +#define stricmp(a, b) strcasecmp((a), (b)) +#endif + +/*******************************************************************/ +/******************** InParser.h ********************************/ +/*******************************************************************/ +class InPlaceParserInterface +{ +public: + virtual ~InPlaceParserInterface () {} ; + + virtual int ParseLine(int lineno,int argc,const char **argv) =0; // return TRUE to continue parsing, return FALSE to abort parsing process +}; + +enum SeparatorType +{ + ST_DATA, // is data + ST_HARD, // is a hard separator + ST_SOFT, // is a soft separator + ST_EOS // is a comment symbol, and everything past this character should be ignored +}; + +class InPlaceParser +{ +public: + InPlaceParser(void) + { + Init(); + } + + InPlaceParser(char *data,int len) + { + Init(); + SetSourceData(data,len); + } + + InPlaceParser(const char *fname) + { + Init(); + SetFile(fname); + } + + ~InPlaceParser(void); + + void Init(void) + { + mQuoteChar = 34; + mData = 0; + mLen = 0; + mMyAlloc = false; + for (int i=0; i<256; i++) + { + mHard[i] = ST_DATA; + mHardString[i*2] = i; + mHardString[i*2+1] = 0; + } + mHard[0] = ST_EOS; + mHard[32] = ST_SOFT; + mHard[9] = ST_SOFT; + mHard[13] = ST_SOFT; + mHard[10] = ST_SOFT; + } + + void SetFile(const char *fname); // use this file as source data to parse. + + void SetSourceData(char *data,int len) + { + mData = data; + mLen = len; + mMyAlloc = false; + }; + + int Parse(InPlaceParserInterface *callback); // returns true if entire file was parsed, false if it aborted for some reason + + int ProcessLine(int lineno,char *line,InPlaceParserInterface *callback); + + const char ** GetArglist(char *source,int &count); // convert source string into an arg list, this is a destructive parse. + + void SetHardSeparator(char c) // add a hard separator + { + mHard[(int)c] = ST_HARD; + } + + void SetHard(char c) // add a hard separator + { + mHard[(int)c] = ST_HARD; + } + + + void SetCommentSymbol(char c) // comment character, treated as 'end of string' + { + mHard[(int)c] = ST_EOS; + } + + void ClearHardSeparator(char c) + { + mHard[(int)c] = ST_DATA; + } + + + void DefaultSymbols(void); // set up default symbols for hard seperator and comment symbol of the '#' character. + + bool EOS(char c) + { + if ( mHard[(int)c] == ST_EOS ) + { + return true; + } + return false; + } + + void SetQuoteChar(char c) + { + mQuoteChar = c; + } + +private: + + + inline char * AddHard(int &argc,const char **argv,char *foo); + inline bool IsHard(char c); + inline char * SkipSpaces(char *foo); + inline bool IsWhiteSpace(char c); + inline bool IsNonSeparator(char c); // non seperator,neither hard nor soft + + bool mMyAlloc; // whether or not *I* allocated the buffer and am responsible for deleting it. + char *mData; // ascii data to parse. + int mLen; // length of data + SeparatorType mHard[256]; + char mHardString[256*2]; + char mQuoteChar; +}; + +/*******************************************************************/ +/******************** InParser.cpp ********************************/ +/*******************************************************************/ +void InPlaceParser::SetFile(const char *fname) +{ + if ( mMyAlloc ) + { + free(mData); + } + mData = 0; + mLen = 0; + mMyAlloc = false; + + + FILE *fph = fopen(fname,"rb"); + if ( fph ) + { + fseek(fph,0L,SEEK_END); + mLen = ftell(fph); + fseek(fph,0L,SEEK_SET); + if ( mLen ) + { + mData = (char *) malloc(sizeof(char)*(mLen+1)); + int ok = fread(mData, mLen, 1, fph); + if ( !ok ) + { + free(mData); + mData = 0; + } + else + { + mData[mLen] = 0; // zero byte terminate end of file marker. + mMyAlloc = true; + } + } + fclose(fph); + } +} + +InPlaceParser::~InPlaceParser(void) +{ + if ( mMyAlloc ) + { + free(mData); + } +} + +#define MAXARGS 512 + +bool InPlaceParser::IsHard(char c) +{ + return mHard[(int)c] == ST_HARD; +} + +char * InPlaceParser::AddHard(int &argc,const char **argv,char *foo) +{ + while ( IsHard(*foo) ) + { + const char *hard = &mHardString[*foo*2]; + if ( argc < MAXARGS ) + { + argv[argc++] = hard; + } + foo++; + } + return foo; +} + +bool InPlaceParser::IsWhiteSpace(char c) +{ + return mHard[(int)c] == ST_SOFT; +} + +char * InPlaceParser::SkipSpaces(char *foo) +{ + while ( !EOS(*foo) && IsWhiteSpace(*foo) ) foo++; + return foo; +} + +bool InPlaceParser::IsNonSeparator(char c) +{ + if ( !IsHard(c) && !IsWhiteSpace(c) && c != 0 ) return true; + return false; +} + + +int InPlaceParser::ProcessLine(int lineno,char *line,InPlaceParserInterface *callback) +{ + int ret = 0; + + const char *argv[MAXARGS]; + int argc = 0; + + char *foo = line; + + while ( !EOS(*foo) && argc < MAXARGS ) + { + + foo = SkipSpaces(foo); // skip any leading spaces + + if ( EOS(*foo) ) break; + + if ( *foo == mQuoteChar ) // if it is an open quote + { + foo++; + if ( argc < MAXARGS ) + { + argv[argc++] = foo; + } + while ( !EOS(*foo) && *foo != mQuoteChar ) foo++; + if ( !EOS(*foo) ) + { + *foo = 0; // replace close quote with zero byte EOS + foo++; + } + } + else + { + + foo = AddHard(argc,argv,foo); // add any hard separators, skip any spaces + + if ( IsNonSeparator(*foo) ) // add non-hard argument. + { + bool quote = false; + if ( *foo == mQuoteChar ) + { + foo++; + quote = true; + } + + if ( argc < MAXARGS ) + { + argv[argc++] = foo; + } + + if ( quote ) + { + while (*foo && *foo != mQuoteChar ) foo++; + if ( *foo ) *foo = 32; + } + + // continue..until we hit an eos .. + while ( !EOS(*foo) ) // until we hit EOS + { + if ( IsWhiteSpace(*foo) ) // if we hit a space, stomp a zero byte, and exit + { + *foo = 0; + foo++; + break; + } + else if ( IsHard(*foo) ) // if we hit a hard separator, stomp a zero byte and store the hard separator argument + { + const char *hard = &mHardString[*foo*2]; + *foo = 0; + if ( argc < MAXARGS ) + { + argv[argc++] = hard; + } + foo++; + break; + } + foo++; + } // end of while loop... + } + } + } + + if ( argc ) + { + ret = callback->ParseLine(lineno, argc, argv ); + } + + return ret; +} + +int InPlaceParser::Parse(InPlaceParserInterface *callback) // returns true if entire file was parsed, false if it aborted for some reason +{ + assert( callback ); + if ( !mData ) return 0; + + int ret = 0; + + int lineno = 0; + + char *foo = mData; + char *begin = foo; + + + while ( *foo ) + { + if ( *foo == 10 || *foo == 13 ) + { + lineno++; + *foo = 0; + + if ( *begin ) // if there is any data to parse at all... + { + int v = ProcessLine(lineno,begin,callback); + if ( v ) ret = v; + } + + foo++; + if ( *foo == 10 ) foo++; // skip line feed, if it is in the carraige-return line-feed format... + begin = foo; + } + else + { + foo++; + } + } + + lineno++; // lasst line. + + int v = ProcessLine(lineno,begin,callback); + if ( v ) ret = v; + return ret; +} + + +void InPlaceParser::DefaultSymbols(void) +{ + SetHardSeparator(','); + SetHardSeparator('('); + SetHardSeparator(')'); + SetHardSeparator('='); + SetHardSeparator('['); + SetHardSeparator(']'); + SetHardSeparator('{'); + SetHardSeparator('}'); + SetCommentSymbol('#'); +} + + +const char ** InPlaceParser::GetArglist(char *line,int &count) // convert source string into an arg list, this is a destructive parse. +{ + const char **ret = 0; + + const char *argv[MAXARGS]; + int argc = 0; + + char *foo = line; + + while ( !EOS(*foo) && argc < MAXARGS ) + { + + foo = SkipSpaces(foo); // skip any leading spaces + + if ( EOS(*foo) ) break; + + if ( *foo == mQuoteChar ) // if it is an open quote + { + foo++; + if ( argc < MAXARGS ) + { + argv[argc++] = foo; + } + while ( !EOS(*foo) && *foo != mQuoteChar ) foo++; + if ( !EOS(*foo) ) + { + *foo = 0; // replace close quote with zero byte EOS + foo++; + } + } + else + { + + foo = AddHard(argc,argv,foo); // add any hard separators, skip any spaces + + if ( IsNonSeparator(*foo) ) // add non-hard argument. + { + bool quote = false; + if ( *foo == mQuoteChar ) + { + foo++; + quote = true; + } + + if ( argc < MAXARGS ) + { + argv[argc++] = foo; + } + + if ( quote ) + { + while (*foo && *foo != mQuoteChar ) foo++; + if ( *foo ) *foo = 32; + } + + // continue..until we hit an eos .. + while ( !EOS(*foo) ) // until we hit EOS + { + if ( IsWhiteSpace(*foo) ) // if we hit a space, stomp a zero byte, and exit + { + *foo = 0; + foo++; + break; + } + else if ( IsHard(*foo) ) // if we hit a hard separator, stomp a zero byte and store the hard separator argument + { + const char *hard = &mHardString[*foo*2]; + *foo = 0; + if ( argc < MAXARGS ) + { + argv[argc++] = hard; + } + foo++; + break; + } + foo++; + } // end of while loop... + } + } + } + + count = argc; + if ( argc ) + { + ret = argv; + } + + return ret; +} + +/*******************************************************************/ +/******************** Geometry.h ********************************/ +/*******************************************************************/ + +class GeometryVertex +{ +public: + float mPos[3]; + float mNormal[3]; + float mTexel[2]; +}; + + +class GeometryInterface +{ +public: + + virtual void NodeTriangle(const GeometryVertex *v1,const GeometryVertex *v2,const GeometryVertex *v3) {} + + virtual ~GeometryInterface () {} +}; + + +/*******************************************************************/ +/******************** Obj.h ********************************/ +/*******************************************************************/ + + +class OBJ : public InPlaceParserInterface +{ +public: + int LoadMesh(const char *fname,GeometryInterface *callback); + int ParseLine(int lineno,int argc,const char **argv); // return TRUE to continue parsing, return FALSE to abort parsing process +private: + + void getVertex(GeometryVertex &v,const char *face) const; + + FloatVector mVerts; + FloatVector mTexels; + FloatVector mNormals; + + GeometryInterface *mCallback; +}; + + +/*******************************************************************/ +/******************** Obj.cpp ********************************/ +/*******************************************************************/ + +int OBJ::LoadMesh(const char *fname,GeometryInterface *iface) +{ + int ret = 0; + + mVerts.clear(); + mTexels.clear(); + mNormals.clear(); + + mCallback = iface; + + InPlaceParser ipp(fname); + + ipp.Parse(this); + + + return ret; +} + +//static const char * GetArg(const char **argv,int i,int argc) +//{ + // const char * ret = 0; + // if ( i < argc ) ret = argv[i]; + // return ret; +//} + +void OBJ::getVertex(GeometryVertex &v,const char *face) const +{ + v.mPos[0] = 0; + v.mPos[1] = 0; + v.mPos[2] = 0; + + v.mTexel[0] = 0; + v.mTexel[1] = 0; + + v.mNormal[0] = 0; + v.mNormal[1] = 1; + v.mNormal[2] = 0; + + int index = atoi( face )-1; + + const char *texel = strstr(face,"/"); + + if ( texel ) + { + int tindex = atoi( texel+1) - 1; + + if ( tindex >=0 && tindex < (int)(mTexels.size()/2) ) + { + const float *t = &mTexels[tindex*2]; + + v.mTexel[0] = t[0]; + v.mTexel[1] = t[1]; + + } + + const char *normal = strstr(texel+1,"/"); + if ( normal ) + { + int nindex = atoi( normal+1 ) - 1; + + if (nindex >= 0 && nindex < (int)(mNormals.size()/3) ) + { + const float *n = &mNormals[nindex*3]; + + v.mNormal[0] = n[0]; + v.mNormal[1] = n[1]; + v.mNormal[2] = n[2]; + } + } + } + + if ( index >= 0 && index < (int)(mVerts.size()/3) ) + { + + const float *p = &mVerts[index*3]; + + v.mPos[0] = p[0]; + v.mPos[1] = p[1]; + v.mPos[2] = p[2]; + } + +} + +int OBJ::ParseLine(int lineno,int argc,const char **argv) // return TRUE to continue parsing, return FALSE to abort parsing process +{ + int ret = 0; + + if ( argc >= 1 ) + { + const char *foo = argv[0]; + if ( *foo != '#' ) + { + if ( strcmp(argv[0],"v") == 0 && argc == 4 ) + + //if ( stricmp(argv[0],"v") == 0 && argc == 4 ) + { + float vx = (float) atof( argv[1] ); + float vy = (float) atof( argv[2] ); + float vz = (float) atof( argv[3] ); + mVerts.push_back(vx); + mVerts.push_back(vy); + mVerts.push_back(vz); + } + else if ( strcmp(argv[0],"vt") == 0 && argc == 3 ) + + // else if ( stricmp(argv[0],"vt") == 0 && argc == 3 ) + { + float tx = (float) atof( argv[1] ); + float ty = (float) atof( argv[2] ); + mTexels.push_back(tx); + mTexels.push_back(ty); + } + // else if ( stricmp(argv[0],"vn") == 0 && argc == 4 ) + + else if ( strcmp(argv[0],"vn") == 0 && argc == 4 ) + { + float normalx = (float) atof(argv[1]); + float normaly = (float) atof(argv[2]); + float normalz = (float) atof(argv[3]); + mNormals.push_back(normalx); + mNormals.push_back(normaly); + mNormals.push_back(normalz); + } +// else if ( stricmp(argv[0],"f") == 0 && argc >= 4 ) + + else if ( strcmp(argv[0],"f") == 0 && argc >= 4 ) + { + GeometryVertex v[32]; + + int vcount = argc-1; + + for (int i=1; i p1( v[0].mPos ); + Vector3d p2( v[1].mPos ); + Vector3d p3( v[2].mPos ); + + Vector3d n; + n.ComputeNormal(p3,p2,p1); + + for (int i=0; iNodeTriangle(&v[0],&v[1],&v[2]); + + if ( vcount >=3 ) // do the fan + { + for (int i=2; i<(vcount-1); i++) + { + mCallback->NodeTriangle(&v[0],&v[i],&v[i+1]); + } + } + + } + } + } + + return ret; +} + + + + +class BuildMesh : public GeometryInterface +{ +public: + + int getIndex(const float *p) + { + + int vcount = mVertices.size()/3; + + if(vcount>0) + { + //New MS STL library checks indices in debug build, so zero causes an assert if it is empty. + const float *v = &mVertices[0]; + + for (int i=0; imPos) ); + mIndices.push_back( getIndex(v2->mPos) ); + mIndices.push_back( getIndex(v3->mPos) ); + } + + const FloatVector& GetVertices(void) const { return mVertices; }; + const IntVector& GetIndices(void) const { return mIndices; }; + +private: + FloatVector mVertices; + IntVector mIndices; +}; + + +WavefrontObj::WavefrontObj(void) +{ + mVertexCount = 0; + mTriCount = 0; + mIndices = 0; + mVertices = 0; +} + +WavefrontObj::~WavefrontObj(void) +{ + delete [] mIndices; + delete [] mVertices; +} + +unsigned int WavefrontObj::loadObj(const char *fname) // load a wavefront obj returns number of triangles that were loaded. Data is persists until the class is destructed. +{ + + unsigned int ret = 0; + + delete [] mVertices; + mVertices = 0; + delete [] mIndices; + mIndices = 0; + mVertexCount = 0; + mTriCount = 0; + + + BuildMesh bm; + + OBJ obj; + + obj.LoadMesh(fname,&bm); + + + const FloatVector &vlist = bm.GetVertices(); + const IntVector &indices = bm.GetIndices(); + if ( vlist.size() ) + { + mVertexCount = vlist.size()/3; + mVertices = new float[mVertexCount*3]; + memcpy( mVertices, &vlist[0], sizeof(float)*mVertexCount*3 ); + mTriCount = indices.size()/3; + mIndices = new int[mTriCount*3*sizeof(int)]; + memcpy(mIndices, &indices[0], sizeof(int)*mTriCount*3); + ret = mTriCount; + } + + + return ret; +} + +} diff --git a/Extras/ConvexDecomposition/cd_wavefront.h b/Extras/ConvexDecomposition/cd_wavefront.h new file mode 100644 index 0000000000..ba5f90bd55 --- /dev/null +++ b/Extras/ConvexDecomposition/cd_wavefront.h @@ -0,0 +1,62 @@ +#ifndef CD_WAVEFRONT_OBJ_H + + +#define CD_WAVEFRONT_OBJ_H + + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + +namespace ConvexDecomposition +{ + +class WavefrontObj +{ +public: + + WavefrontObj(void); + ~WavefrontObj(void); + + unsigned int loadObj(const char *fname); // load a wavefront obj returns number of triangles that were loaded. Data is persists until the class is destructed. + + int mVertexCount; + int mTriCount; + int *mIndices; + float *mVertices; +}; + +} + +#endif diff --git a/Extras/ConvexDecomposition/concavity.cpp b/Extras/ConvexDecomposition/concavity.cpp new file mode 100644 index 0000000000..f1a4660017 --- /dev/null +++ b/Extras/ConvexDecomposition/concavity.cpp @@ -0,0 +1,795 @@ +#include "float_math.h" +#include +#include +#include +#include + +#include + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + +#include "concavity.h" +#include "raytri.h" +#include "bestfit.h" +#include "cd_hull.h" +#include "meshvolume.h" +#include "cd_vector.h" +#include "splitplane.h" +#include "ConvexDecomposition.h" + + +#define WSCALE 4 +#define CONCAVE_THRESH 0.05f + +namespace ConvexDecomposition +{ + +unsigned int getDebugColor(void) +{ + static unsigned int colors[8] = + { + 0xFF0000, + 0x00FF00, + 0x0000FF, + 0xFFFF00, + 0x00FFFF, + 0xFF00FF, + 0xFFFFFF, + 0xFF8040 + }; + + static int count = 0; + + count++; + + if ( count == 8 ) count = 0; + + assert( count >= 0 && count < 8 ); + + unsigned int color = colors[count]; + + return color; + +} + +class Wpoint +{ +public: + Wpoint(const Vector3d &p,float w) + { + mPoint = p; + mWeight = w; + } + + Vector3d mPoint; + float mWeight; +}; + +typedef std::vector< Wpoint > WpointVector; + + +static inline float DistToPt(const float *p,const float *plane) +{ + float x = p[0]; + float y = p[1]; + float z = p[2]; + float d = x*plane[0] + y*plane[1] + z*plane[2] + plane[3]; + return d; +} + + +static void intersect(const float *p1,const float *p2,float *split,const float *plane) +{ + + float dp1 = DistToPt(p1,plane); + + float dir[3]; + + dir[0] = p2[0] - p1[0]; + dir[1] = p2[1] - p1[1]; + dir[2] = p2[2] - p1[2]; + + float dot1 = dir[0]*plane[0] + dir[1]*plane[1] + dir[2]*plane[2]; + float dot2 = dp1 - plane[3]; + + float t = -(plane[3] + dot2 ) / dot1; + + split[0] = (dir[0]*t)+p1[0]; + split[1] = (dir[1]*t)+p1[1]; + split[2] = (dir[2]*t)+p1[2]; +} + + +class CTri +{ +public: + CTri(void) { }; + + CTri(const float *p1,const float *p2,const float *p3,unsigned int i1,unsigned int i2,unsigned int i3) + { + mProcessed = 0; + mI1 = i1; + mI2 = i2; + mI3 = i3; + + mP1.Set(p1); + mP2.Set(p2); + mP3.Set(p3); + + mPlaneD = mNormal.ComputePlane(mP1,mP2,mP3); + } + + float Facing(const CTri &t) + { + float d = mNormal.Dot(t.mNormal); + return d; + } + + // clip this line segment against this triangle. + bool clip(const Vector3d &start,Vector3d &end) const + { + Vector3d sect; + + bool hit = lineIntersectsTriangle(start.Ptr(), end.Ptr(), mP1.Ptr(), mP2.Ptr(), mP3.Ptr(), sect.Ptr() ); + + if ( hit ) + { + end = sect; + } + return hit; + } + + bool Concave(const Vector3d &p,float &distance,Vector3d &n) const + { + n.NearestPointInTriangle(p,mP1,mP2,mP3); + distance = p.Distance(n); + return true; + } + + void addTri(unsigned int *indices,unsigned int i1,unsigned int i2,unsigned int i3,unsigned int &tcount) const + { + indices[tcount*3+0] = i1; + indices[tcount*3+1] = i2; + indices[tcount*3+2] = i3; + tcount++; + } + + float getVolume(ConvexDecompInterface *callback) const + { + unsigned int indices[8*3]; + + + unsigned int tcount = 0; + + addTri(indices,0,1,2,tcount); + addTri(indices,3,4,5,tcount); + + addTri(indices,0,3,4,tcount); + addTri(indices,0,4,1,tcount); + + addTri(indices,1,4,5,tcount); + addTri(indices,1,5,2,tcount); + + addTri(indices,0,3,5,tcount); + addTri(indices,0,5,2,tcount); + + const float *vertices = mP1.Ptr(); + + if ( callback ) + { + unsigned int color = getDebugColor(); + +#if 0 + Vector3d d1 = mNear1; + Vector3d d2 = mNear2; + Vector3d d3 = mNear3; + + callback->ConvexDebugPoint(mP1.Ptr(),0.01f,0x00FF00); + callback->ConvexDebugPoint(mP2.Ptr(),0.01f,0x00FF00); + callback->ConvexDebugPoint(mP3.Ptr(),0.01f,0x00FF00); + callback->ConvexDebugPoint(d1.Ptr(),0.01f,0xFF0000); + callback->ConvexDebugPoint(d2.Ptr(),0.01f,0xFF0000); + callback->ConvexDebugPoint(d3.Ptr(),0.01f,0xFF0000); + + callback->ConvexDebugTri(mP1.Ptr(), d1.Ptr(), d1.Ptr(),0x00FF00); + callback->ConvexDebugTri(mP2.Ptr(), d2.Ptr(), d2.Ptr(),0x00FF00); + callback->ConvexDebugTri(mP3.Ptr(), d3.Ptr(), d3.Ptr(),0x00FF00); + +#else + for (unsigned int i=0; iConvexDebugTri(p1,p2,p3,color); + + } +#endif + } + + float v = computeMeshVolume(mP1.Ptr(), tcount, indices ); + + return v; + + } + + float raySect(const Vector3d &p,const Vector3d &dir,Vector3d §) const + { + float plane[4]; + + plane[0] = mNormal.x; + plane[1] = mNormal.y; + plane[2] = mNormal.z; + plane[3] = mPlaneD; + + Vector3d dest = p+dir*100000; + + intersect( p.Ptr(), dest.Ptr(), sect.Ptr(), plane ); + + return sect.Distance(p); // return the intersection distance. + + } + + float planeDistance(const Vector3d &p) const + { + float plane[4]; + + plane[0] = mNormal.x; + plane[1] = mNormal.y; + plane[2] = mNormal.z; + plane[3] = mPlaneD; + + return DistToPt( p.Ptr(), plane ); + + } + + bool samePlane(const CTri &t) const + { + const float THRESH = 0.001f; + float dd = fabsf( t.mPlaneD - mPlaneD ); + if ( dd > THRESH ) return false; + dd = fabsf( t.mNormal.x - mNormal.x ); + if ( dd > THRESH ) return false; + dd = fabsf( t.mNormal.y - mNormal.y ); + if ( dd > THRESH ) return false; + dd = fabsf( t.mNormal.z - mNormal.z ); + if ( dd > THRESH ) return false; + return true; + } + + bool hasIndex(unsigned int i) const + { + if ( i == mI1 || i == mI2 || i == mI3 ) return true; + return false; + } + + bool sharesEdge(const CTri &t) const + { + bool ret = false; + unsigned int count = 0; + + if ( t.hasIndex(mI1) ) count++; + if ( t.hasIndex(mI2) ) count++; + if ( t.hasIndex(mI3) ) count++; + + if ( count >= 2 ) ret = true; + + return ret; + } + + void debug(unsigned int color,ConvexDecompInterface *callback) + { + callback->ConvexDebugTri( mP1.Ptr(), mP2.Ptr(), mP3.Ptr(), color ); + callback->ConvexDebugTri( mP1.Ptr(), mP1.Ptr(), mNear1.Ptr(), 0xFF0000 ); + callback->ConvexDebugTri( mP2.Ptr(), mP2.Ptr(), mNear2.Ptr(), 0xFF0000 ); + callback->ConvexDebugTri( mP2.Ptr(), mP3.Ptr(), mNear3.Ptr(), 0xFF0000 ); + callback->ConvexDebugPoint( mNear1.Ptr(), 0.01f, 0xFF0000 ); + callback->ConvexDebugPoint( mNear2.Ptr(), 0.01f, 0xFF0000 ); + callback->ConvexDebugPoint( mNear3.Ptr(), 0.01f, 0xFF0000 ); + } + + float area(void) + { + float a = mConcavity*mP1.Area(mP2,mP3); + return a; + } + + void addWeighted(WpointVector &list,ConvexDecompInterface *callback) + { + + Wpoint p1(mP1,mC1); + Wpoint p2(mP2,mC2); + Wpoint p3(mP3,mC3); + + Vector3d d1 = mNear1 - mP1; + Vector3d d2 = mNear2 - mP2; + Vector3d d3 = mNear3 - mP3; + + d1*=WSCALE; + d2*=WSCALE; + d3*=WSCALE; + + d1 = d1 + mP1; + d2 = d2 + mP2; + d3 = d3 + mP3; + + Wpoint p4(d1,mC1); + Wpoint p5(d2,mC2); + Wpoint p6(d3,mC3); + + list.push_back(p1); + list.push_back(p2); + list.push_back(p3); + + list.push_back(p4); + list.push_back(p5); + list.push_back(p6); + +#if 0 + callback->ConvexDebugPoint(mP1.Ptr(),0.01f,0x00FF00); + callback->ConvexDebugPoint(mP2.Ptr(),0.01f,0x00FF00); + callback->ConvexDebugPoint(mP3.Ptr(),0.01f,0x00FF00); + callback->ConvexDebugPoint(d1.Ptr(),0.01f,0xFF0000); + callback->ConvexDebugPoint(d2.Ptr(),0.01f,0xFF0000); + callback->ConvexDebugPoint(d3.Ptr(),0.01f,0xFF0000); + + callback->ConvexDebugTri(mP1.Ptr(), d1.Ptr(), d1.Ptr(),0x00FF00); + callback->ConvexDebugTri(mP2.Ptr(), d2.Ptr(), d2.Ptr(),0x00FF00); + callback->ConvexDebugTri(mP3.Ptr(), d3.Ptr(), d3.Ptr(),0x00FF00); + + Vector3d np1 = mP1 + mNormal*0.05f; + Vector3d np2 = mP2 + mNormal*0.05f; + Vector3d np3 = mP3 + mNormal*0.05f; + + callback->ConvexDebugTri(mP1.Ptr(), np1.Ptr(), np1.Ptr(), 0xFF00FF ); + callback->ConvexDebugTri(mP2.Ptr(), np2.Ptr(), np2.Ptr(), 0xFF00FF ); + callback->ConvexDebugTri(mP3.Ptr(), np3.Ptr(), np3.Ptr(), 0xFF00FF ); + + callback->ConvexDebugPoint( np1.Ptr(), 0.01F, 0XFF00FF ); + callback->ConvexDebugPoint( np2.Ptr(), 0.01F, 0XFF00FF ); + callback->ConvexDebugPoint( np3.Ptr(), 0.01F, 0XFF00FF ); + +#endif + + + + } + + Vector3d mP1; + Vector3d mP2; + Vector3d mP3; + Vector3d mNear1; + Vector3d mNear2; + Vector3d mNear3; + Vector3d mNormal; + float mPlaneD; + float mConcavity; + float mC1; + float mC2; + float mC3; + unsigned int mI1; + unsigned int mI2; + unsigned int mI3; + int mProcessed; // already been added... +}; + +typedef std::vector< CTri > CTriVector; + +bool featureMatch(CTri &m,const CTriVector &tris,ConvexDecompInterface *callback,const CTriVector &input_mesh) +{ + + bool ret = false; + + float neardot = 0.707f; + + m.mConcavity = 0; + + //gLog->Display("*********** FEATURE MATCH *************\r\n"); + //gLog->Display("Plane: %0.4f,%0.4f,%0.4f %0.4f\r\n", m.mNormal.x, m.mNormal.y, m.mNormal.z, m.mPlaneD ); + //gLog->Display("*********************************************\r\n"); + + CTriVector::const_iterator i; + + CTri nearest; + + + for (i=tris.begin(); i!=tris.end(); ++i) + { + const CTri &t = (*i); + + + //gLog->Display(" HullPlane: %0.4f,%0.4f,%0.4f %0.4f\r\n", t.mNormal.x, t.mNormal.y, t.mNormal.z, t.mPlaneD ); + + if ( t.samePlane(m) ) + { + //gLog->Display("*** PLANE MATCH!!!\r\n"); + ret = false; + break; + } + + float dot = t.mNormal.Dot(m.mNormal); + + if ( dot > neardot ) + { + + float d1 = t.planeDistance( m.mP1 ); + float d2 = t.planeDistance( m.mP2 ); + float d3 = t.planeDistance( m.mP3 ); + + if ( d1 > 0.001f || d2 > 0.001f || d3 > 0.001f ) // can't be near coplaner! + { + + neardot = dot; + + Vector3d n1,n2,n3; + + t.raySect( m.mP1, m.mNormal, m.mNear1 ); + t.raySect( m.mP2, m.mNormal, m.mNear2 ); + t.raySect( m.mP3, m.mNormal, m.mNear3 ); + + nearest = t; + + ret = true; + } + + } + } + + if ( ret ) + { + if ( 0 ) + { + CTriVector::const_iterator i; + for (i=input_mesh.begin(); i!=input_mesh.end(); ++i) + { + const CTri &c = (*i); + if ( c.mI1 != m.mI1 && c.mI2 != m.mI2 && c.mI3 != m.mI3 ) + { + c.clip( m.mP1, m.mNear1 ); + c.clip( m.mP2, m.mNear2 ); + c.clip( m.mP3, m.mNear3 ); + } + } + } + + //gLog->Display("*********************************************\r\n"); + //gLog->Display(" HullPlaneNearest: %0.4f,%0.4f,%0.4f %0.4f\r\n", nearest.mNormal.x, nearest.mNormal.y, nearest.mNormal.z, nearest.mPlaneD ); + + m.mC1 = m.mP1.Distance( m.mNear1 ); + m.mC2 = m.mP2.Distance( m.mNear2 ); + m.mC3 = m.mP3.Distance( m.mNear3 ); + + m.mConcavity = m.mC1; + + if ( m.mC2 > m.mConcavity ) m.mConcavity = m.mC2; + if ( m.mC3 > m.mConcavity ) m.mConcavity = m.mC3; + + #if 0 + callback->ConvexDebugTri( m.mP1.Ptr(), m.mP2.Ptr(), m.mP3.Ptr(), 0x00FF00 ); + callback->ConvexDebugTri( m.mNear1.Ptr(), m.mNear2.Ptr(), m.mNear3.Ptr(), 0xFF0000 ); + + callback->ConvexDebugTri( m.mP1.Ptr(), m.mP1.Ptr(), m.mNear1.Ptr(), 0xFFFF00 ); + callback->ConvexDebugTri( m.mP2.Ptr(), m.mP2.Ptr(), m.mNear2.Ptr(), 0xFFFF00 ); + callback->ConvexDebugTri( m.mP3.Ptr(), m.mP3.Ptr(), m.mNear3.Ptr(), 0xFFFF00 ); + #endif + + } + else + { + //gLog->Display("No match\r\n"); + } + + //gLog->Display("*********************************************\r\n"); + return ret; +} + +bool isFeatureTri(CTri &t,CTriVector &flist,float fc,ConvexDecompInterface *callback,unsigned int color) +{ + bool ret = false; + + if ( t.mProcessed == 0 ) // if not already processed + { + + float c = t.mConcavity / fc; // must be within 80% of the concavity of the parent. + + if ( c > 0.85f ) + { + // see if this triangle is a 'feature' triangle. Meaning it shares an + // edge with any existing feature triangle and is within roughly the same + // concavity of the parent. + if ( flist.size() ) + { + CTriVector::iterator i; + for (i=flist.begin(); i!=flist.end(); ++i) + { + CTri &ftri = (*i); + if ( ftri.sharesEdge(t) ) + { + t.mProcessed = 2; // it is now part of a feature. + flist.push_back(t); // add it to the feature list. +// callback->ConvexDebugTri( t.mP1.Ptr(), t.mP2.Ptr(),t.mP3.Ptr(), color ); + ret = true; + break; + } + } + } + else + { + t.mProcessed = 2; + flist.push_back(t); // add it to the feature list. +// callback->ConvexDebugTri( t.mP1.Ptr(), t.mP2.Ptr(),t.mP3.Ptr(), color ); + ret = true; + } + } + else + { + t.mProcessed = 1; // eliminated for this feature, but might be valid for the next one.. + } + + } + return ret; +} + +float computeConcavity(unsigned int vcount, + const float *vertices, + unsigned int tcount, + const unsigned int *indices, + ConvexDecompInterface *callback, + float *plane, // plane equation to split on + float &volume) +{ + + + float cret = 0; + volume = 1; + + HullResult result; + HullLibrary hl; + HullDesc desc; + + desc.mMaxFaces = 256; + desc.mMaxVertices = 256; + desc.SetHullFlag(QF_TRIANGLES); + + + desc.mVcount = vcount; + desc.mVertices = vertices; + desc.mVertexStride = sizeof(float)*3; + + HullError ret = hl.CreateConvexHull(desc,result); + + if ( ret == QE_OK ) + { +#if 0 + float bmin[3]; + float bmax[3]; + + float dx = bmax[0] - bmin[0]; + float dy = bmax[1] - bmin[1]; + float dz = bmax[2] - bmin[2]; + + Vector3d center; + + center.x = bmin[0] + dx*0.5f; + center.y = bmin[1] + dy*0.5f; + center.z = bmin[2] + dz*0.5f; +#endif + + volume = computeMeshVolume2( result.mOutputVertices, result.mNumFaces, result.mIndices ); + +#if 1 + // ok..now..for each triangle on the original mesh.. + // we extrude the points to the nearest point on the hull. + const unsigned int *source = result.mIndices; + + CTriVector tris; + + for (unsigned int i=0; iConvexDebugTri(p1,p2,p3,0xFFFFFF); + + CTri t(p1,p2,p3,i1,i2,i3); // + tris.push_back(t); + } + + // we have not pre-computed the plane equation for each triangle in the convex hull.. + + float totalVolume = 0; + + CTriVector ftris; // 'feature' triangles. + + const unsigned int *src = indices; + + + float maxc=0; + + + if ( 1 ) + { + CTriVector input_mesh; + if ( 1 ) + { + const unsigned int *src = indices; + for (unsigned int i=0; i CONCAVE_THRESH ) + { + + if ( t.mConcavity > maxc ) + { + maxc = t.mConcavity; + maxctri = t; + } + + float v = t.getVolume(0); + totalVolume+=v; + ftris.push_back(t); + } + + } + } + + if ( ftris.size() && 0 ) + { + + // ok..now we extract the triangles which form the maximum concavity. + CTriVector major_feature; + float maxarea = 0; + + while ( maxc > CONCAVE_THRESH ) + { + + unsigned int color = getDebugColor(); // + + CTriVector flist; + + bool found; + + float totalarea = 0; + + do + { + found = false; + CTriVector::iterator i; + for (i=ftris.begin(); i!=ftris.end(); ++i) + { + CTri &t = (*i); + if ( isFeatureTri(t,flist,maxc,callback,color) ) + { + found = true; + totalarea+=t.area(); + } + } + } while ( found ); + + + if ( totalarea > maxarea ) + { + major_feature = flist; + maxarea = totalarea; + } + + maxc = 0; + + for (unsigned int i=0; i maxc ) + { + maxc = t.mConcavity; + } + } + } + } + + unsigned int color = getDebugColor(); + + WpointVector list; + for (unsigned int i=0; i +#include +#include +#include +#include + +#include "fitsphere.h" + + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// +/* +An Efficient Bounding Sphere +by Jack Ritter +from "Graphics Gems", Academic Press, 1990 +*/ + +/* Routine to calculate tight bounding sphere over */ +/* a set of points in 3D */ +/* This contains the routine find_bounding_sphere(), */ +/* the struct definition, and the globals used for parameters. */ +/* The abs() of all coordinates must be < BIGNUMBER */ +/* Code written by Jack Ritter and Lyle Rains. */ + +#define BIGNUMBER 100000000.0 /* hundred million */ + +static inline void Set(float *n,float x,float y,float z) +{ + n[0] = x; + n[1] = y; + n[2] = z; +} + +static inline void Copy(float *dest,const float *source) +{ + dest[0] = source[0]; + dest[1] = source[1]; + dest[2] = source[2]; +} + +float computeBoundingSphere(unsigned int vcount,const float *points,float *center) +{ + + float mRadius; + float mRadius2; + + float xmin[3]; + float xmax[3]; + float ymin[3]; + float ymax[3]; + float zmin[3]; + float zmax[3]; + float dia1[3]; + float dia2[3]; + + /* FIRST PASS: find 6 minima/maxima points */ + Set(xmin,BIGNUMBER,BIGNUMBER,BIGNUMBER); + Set(xmax,-BIGNUMBER,-BIGNUMBER,-BIGNUMBER); + Set(ymin,BIGNUMBER,BIGNUMBER,BIGNUMBER); + Set(ymax,-BIGNUMBER,-BIGNUMBER,-BIGNUMBER); + Set(zmin,BIGNUMBER,BIGNUMBER,BIGNUMBER); + Set(zmax,-BIGNUMBER,-BIGNUMBER,-BIGNUMBER); + + for (unsigned i=0; ixmax[0]) + Copy(xmax,caller_p); + if (caller_p[1]ymax[1]) + Copy(ymax,caller_p); + if (caller_p[2]zmax[2]) + Copy(zmax,caller_p); + } + + /* Set xspan = distance between the 2 points xmin & xmax (squared) */ + float dx = xmax[0] - xmin[0]; + float dy = xmax[1] - xmin[1]; + float dz = xmax[2] - xmin[2]; + float xspan = dx*dx + dy*dy + dz*dz; + + /* Same for y & z spans */ + dx = ymax[0] - ymin[0]; + dy = ymax[1] - ymin[1]; + dz = ymax[2] - ymin[2]; + float yspan = dx*dx + dy*dy + dz*dz; + + dx = zmax[0] - zmin[0]; + dy = zmax[1] - zmin[1]; + dz = zmax[2] - zmin[2]; + float zspan = dx*dx + dy*dy + dz*dz; + + /* Set points dia1 & dia2 to the maximally separated pair */ + Copy(dia1,xmin); + Copy(dia2,xmax); /* assume xspan biggest */ + float maxspan = xspan; + + if (yspan>maxspan) + { + maxspan = yspan; + Copy(dia1,ymin); + Copy(dia2,ymax); + } + + if (zspan>maxspan) + { + Copy(dia1,zmin); + Copy(dia2,zmax); + } + + + /* dia1,dia2 is a diameter of initial sphere */ + /* calc initial center */ + center[0] = (dia1[0]+dia2[0])*0.5f; + center[1] = (dia1[1]+dia2[1])*0.5f; + center[2] = (dia1[2]+dia2[2])*0.5f; + + /* calculate initial radius**2 and radius */ + + dx = dia2[0]-center[0]; /* x component of radius vector */ + dy = dia2[1]-center[1]; /* y component of radius vector */ + dz = dia2[2]-center[2]; /* z component of radius vector */ + + mRadius2 = dx*dx + dy*dy + dz*dz; + mRadius = float(sqrt(mRadius2)); + + /* SECOND PASS: increment current sphere */ + + if ( 1 ) + { + for (unsigned i=0; i mRadius2) /* do r**2 test first */ + { /* this point is outside of current sphere */ + float old_to_p = float(sqrt(old_to_p_sq)); + /* calc radius of new sphere */ + mRadius = (mRadius + old_to_p) * 0.5f; + mRadius2 = mRadius*mRadius; /* for next r**2 compare */ + float old_to_new = old_to_p - mRadius; + + /* calc center of new sphere */ + + float recip = 1.0f /old_to_p; + + float cx = (mRadius*center[0] + old_to_new*caller_p[0]) * recip; + float cy = (mRadius*center[1] + old_to_new*caller_p[1]) * recip; + float cz = (mRadius*center[2] + old_to_new*caller_p[2]) * recip; + + Set(center,cx,cy,cz); + } + } + } + + return mRadius; +} + + diff --git a/Extras/ConvexDecomposition/fitsphere.h b/Extras/ConvexDecomposition/fitsphere.h new file mode 100644 index 0000000000..cd4a565c5e --- /dev/null +++ b/Extras/ConvexDecomposition/fitsphere.h @@ -0,0 +1,43 @@ +#ifndef FIT_SPHERE_H + +#define FIT_SPHERE_H + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + + +float computeBoundingSphere(unsigned int vcount,const float *points,float *center); + +#endif diff --git a/Extras/ConvexDecomposition/float_math.cpp b/Extras/ConvexDecomposition/float_math.cpp new file mode 100644 index 0000000000..38c699b59a --- /dev/null +++ b/Extras/ConvexDecomposition/float_math.cpp @@ -0,0 +1,257 @@ +#include "float_math.h" + +#include +#include +#include +#include +#include + + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + +void fm_inverseRT(const float *matrix,const float *pos,float *t) // inverse rotate translate the point. +{ + + float _x = pos[0] - matrix[3*4+0]; + float _y = pos[1] - matrix[3*4+1]; + float _z = pos[2] - matrix[3*4+2]; + + // Multiply inverse-translated source vector by inverted rotation transform + + t[0] = (matrix[0*4+0] * _x) + (matrix[0*4+1] * _y) + (matrix[0*4+2] * _z); + t[1] = (matrix[1*4+0] * _x) + (matrix[1*4+1] * _y) + (matrix[1*4+2] * _z); + t[2] = (matrix[2*4+0] * _x) + (matrix[2*4+1] * _y) + (matrix[2*4+2] * _z); + +} + + +void fm_identity(float *matrix) // set 4x4 matrix to identity. +{ + matrix[0*4+0] = 1; + matrix[1*4+1] = 1; + matrix[2*4+2] = 1; + matrix[3*4+3] = 1; + + matrix[1*4+0] = 0; + matrix[2*4+0] = 0; + matrix[3*4+0] = 0; + + matrix[0*4+1] = 0; + matrix[2*4+1] = 0; + matrix[3*4+1] = 0; + + matrix[0*4+2] = 0; + matrix[1*4+2] = 0; + matrix[3*4+2] = 0; + + matrix[0*4+3] = 0; + matrix[1*4+3] = 0; + matrix[2*4+3] = 0; + +} + +void fm_eulerMatrix(float ax,float ay,float az,float *matrix) // convert euler (in radians) to a dest 4x4 matrix (translation set to zero) +{ + float quat[4]; + fm_eulerToQuat(ax,ay,az,quat); + fm_quatToMatrix(quat,matrix); +} + +void fm_getAABB(unsigned int vcount,const float *points,unsigned int pstride,float *bmin,float *bmax) +{ + + const unsigned char *source = (const unsigned char *) points; + + bmin[0] = points[0]; + bmin[1] = points[1]; + bmin[2] = points[2]; + + bmax[0] = points[0]; + bmax[1] = points[1]; + bmax[2] = points[2]; + + + for (unsigned int i=1; i bmax[0] ) bmax[0] = p[0]; + if ( p[1] > bmax[1] ) bmax[1] = p[1]; + if ( p[2] > bmax[2] ) bmax[2] = p[2]; + + } +} + + +void fm_eulerToQuat(float roll,float pitch,float yaw,float *quat) // convert euler angles to quaternion. +{ + roll *= 0.5f; + pitch *= 0.5f; + yaw *= 0.5f; + + float cr = cosf(roll); + float cp = cosf(pitch); + float cy = cosf(yaw); + + float sr = sinf(roll); + float sp = sinf(pitch); + float sy = sinf(yaw); + + float cpcy = cp * cy; + float spsy = sp * sy; + float spcy = sp * cy; + float cpsy = cp * sy; + + quat[0] = ( sr * cpcy - cr * spsy); + quat[1] = ( cr * spcy + sr * cpsy); + quat[2] = ( cr * cpsy - sr * spcy); + quat[3] = cr * cpcy + sr * spsy; +} + +void fm_quatToMatrix(const float *quat,float *matrix) // convert quaterinion rotation to matrix, zeros out the translation component. +{ + + float xx = quat[0]*quat[0]; + float yy = quat[1]*quat[1]; + float zz = quat[2]*quat[2]; + float xy = quat[0]*quat[1]; + float xz = quat[0]*quat[2]; + float yz = quat[1]*quat[2]; + float wx = quat[3]*quat[0]; + float wy = quat[3]*quat[1]; + float wz = quat[3]*quat[2]; + + matrix[0*4+0] = 1 - 2 * ( yy + zz ); + matrix[1*4+0] = 2 * ( xy - wz ); + matrix[2*4+0] = 2 * ( xz + wy ); + + matrix[0*4+1] = 2 * ( xy + wz ); + matrix[1*4+1] = 1 - 2 * ( xx + zz ); + matrix[2*4+1] = 2 * ( yz - wx ); + + matrix[0*4+2] = 2 * ( xz - wy ); + matrix[1*4+2] = 2 * ( yz + wx ); + matrix[2*4+2] = 1 - 2 * ( xx + yy ); + + matrix[3*4+0] = matrix[3*4+1] = matrix[3*4+2] = 0.0f; + matrix[0*4+3] = matrix[1*4+3] = matrix[2*4+3] = 0.0f; + matrix[3*4+3] = 1.0f; + +} + + +void fm_quatRotate(const float *quat,const float *v,float *r) // rotate a vector directly by a quaternion. +{ + float left[4]; + + left[0] = quat[3]*v[0] + quat[1]*v[2] - v[1]*quat[2]; + left[1] = quat[3]*v[1] + quat[2]*v[0] - v[2]*quat[0]; + left[2] = quat[3]*v[2] + quat[0]*v[1] - v[0]*quat[1]; + left[3] = - quat[0]*v[0] - quat[1]*v[1] - quat[2]*v[2]; + + r[0] = (left[3]*-quat[0]) + (quat[3]*left[0]) + (left[1]*-quat[2]) - (-quat[1]*left[2]); + r[1] = (left[3]*-quat[1]) + (quat[3]*left[1]) + (left[2]*-quat[0]) - (-quat[2]*left[0]); + r[2] = (left[3]*-quat[2]) + (quat[3]*left[2]) + (left[0]*-quat[1]) - (-quat[0]*left[1]); + +} + + +void fm_getTranslation(const float *matrix,float *t) +{ + t[0] = matrix[3*4+0]; + t[1] = matrix[3*4+1]; + t[2] = matrix[3*4+2]; +} + +void fm_matrixToQuat(const float *matrix,float *quat) // convert the 3x3 portion of a 4x4 matrix into a quaterion as x,y,z,w +{ + + float tr = matrix[0*4+0] + matrix[1*4+1] + matrix[2*4+2]; + + // check the diagonal + + if (tr > 0.0f ) + { + float s = (float) sqrt ( (double) (tr + 1.0f) ); + quat[3] = s * 0.5f; + s = 0.5f / s; + quat[0] = (matrix[1*4+2] - matrix[2*4+1]) * s; + quat[1] = (matrix[2*4+0] - matrix[0*4+2]) * s; + quat[2] = (matrix[0*4+1] - matrix[1*4+0]) * s; + + } + else + { + // diagonal is negative + int nxt[3] = {1, 2, 0}; + float qa[4]; + + int i = 0; + + if (matrix[1*4+1] > matrix[0*4+0]) i = 1; + if (matrix[2*4+2] > matrix[i*4+i]) i = 2; + + int j = nxt[i]; + int k = nxt[j]; + + float s = sqrtf ( ((matrix[i*4+i] - (matrix[j*4+j] + matrix[k*4+k])) + 1.0f) ); + + qa[i] = s * 0.5f; + + if (s != 0.0f ) s = 0.5f / s; + + qa[3] = (matrix[j*4+k] - matrix[k*4+j]) * s; + qa[j] = (matrix[i*4+j] + matrix[j*4+i]) * s; + qa[k] = (matrix[i*4+k] + matrix[k*4+i]) * s; + + quat[0] = qa[0]; + quat[1] = qa[1]; + quat[2] = qa[2]; + quat[3] = qa[3]; + } + + +} + + +float fm_sphereVolume(float radius) // return's the volume of a sphere of this radius (4/3 PI * R cubed ) +{ + return (4.0f / 3.0f ) * FM_PI * radius * radius * radius; +} diff --git a/Extras/ConvexDecomposition/float_math.h b/Extras/ConvexDecomposition/float_math.h new file mode 100644 index 0000000000..d6046d3b05 --- /dev/null +++ b/Extras/ConvexDecomposition/float_math.h @@ -0,0 +1,72 @@ +#ifndef FLOAT_MATH_H + +#define FLOAT_MATH_H + +#ifdef _WIN32 + #pragma warning(disable : 4324) // disable padding warning + #pragma warning(disable : 4244) // disable padding warning + #pragma warning(disable : 4267) // possible loss of data + #pragma warning(disable:4530) // Disable the exception disable but used in MSCV Stl warning. + #pragma warning(disable:4996) //Turn off warnings about deprecated C routines + #pragma warning(disable:4786) // Disable the "debug name too long" warning +#endif + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + +// a set of routines that last you do common 3d math +// operations without any vector, matrix, or quaternion +// classes or templates. +// +// a vector (or point) is a 'float *' to 3 floating point numbers. +// a matrix is a 'float *' to an array of 16 floating point numbers representing a 4x4 transformation matrix compatible with D3D or OGL +// a quaternion is a 'float *' to 4 floats representing a quaternion x,y,z,w + +const float FM_PI = 3.141592654f; +const float FM_DEG_TO_RAD = ((2.0f * FM_PI) / 360.0f); +const float FM_RAD_TO_DEG = (360.0f / (2.0f * FM_PI)); + +void fm_identity(float *matrix); // set 4x4 matrix to identity. +void fm_inverseRT(const float *matrix,const float *pos,float *t); // inverse rotate translate the point. +void fm_eulerMatrix(float ax,float ay,float az,float *matrix); // convert euler (in radians) to a dest 4x4 matrix (translation set to zero) +void fm_getAABB(unsigned int vcount,const float *points,unsigned int pstride,float *bmin,float *bmax); +void fm_eulerToQuat(float roll,float pitch,float yaw,float *quat); // convert euler angles to quaternion. +void fm_quatToMatrix(const float *quat,float *matrix); // convert quaterinion rotation to matrix, translation set to zero. +void fm_quatRotate(const float *quat,const float *v,float *r); // rotate a vector directly by a quaternion. +void fm_getTranslation(const float *matrix,float *t); +void fm_matrixToQuat(const float *matrix,float *quat); // convert the 3x3 portion of a 4x4 matrix into a quaterion as x,y,z,w +float fm_sphereVolume(float radius); // return's the volume of a sphere of this radius (4/3 PI * R cubed ) + +#endif diff --git a/Extras/ConvexDecomposition/meshvolume.cpp b/Extras/ConvexDecomposition/meshvolume.cpp new file mode 100644 index 0000000000..b9dfa174d3 --- /dev/null +++ b/Extras/ConvexDecomposition/meshvolume.cpp @@ -0,0 +1,128 @@ +#include "float_math.h" +#include "meshvolume.h" + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + +inline float det(const float *p1,const float *p2,const float *p3) +{ + return p1[0]*p2[1]*p3[2] + p2[0]*p3[1]*p1[2] + p3[0]*p1[1]*p2[2] -p1[0]*p3[1]*p2[2] - p2[0]*p1[1]*p3[2] - p3[0]*p2[1]*p1[2]; +} + +float computeMeshVolume(const float *vertices,unsigned int tcount,const unsigned int *indices) +{ + float volume = 0; + + for (unsigned int i=0; i +#include +#include +#include + +#include "planetri.h" + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + +static inline float DistToPt(const float *p,const float *plane) +{ + float x = p[0]; + float y = p[1]; + float z = p[2]; + float d = x*plane[0] + y*plane[1] + z*plane[2] + plane[3]; + return d; +} + + +static PlaneTriResult getSidePlane(const float *p,const float *plane,float epsilon) +{ + + float d = DistToPt(p,plane); + + if ( (d+epsilon) > 0 ) + return PTR_FRONT; // it is 'in front' within the provided epsilon value. + + return PTR_BACK; +} + +static void add(const float *p,float *dest,unsigned int tstride,unsigned int &pcount) +{ + char *d = (char *) dest; + d = d + pcount*tstride; + dest = (float *) d; + dest[0] = p[0]; + dest[1] = p[1]; + dest[2] = p[2]; + pcount++; + assert( pcount <= 4 ); +} + + +// assumes that the points are on opposite sides of the plane! +static void intersect(const float *p1,const float *p2,float *split,const float *plane) +{ + + float dp1 = DistToPt(p1,plane); + + float dir[3]; + + dir[0] = p2[0] - p1[0]; + dir[1] = p2[1] - p1[1]; + dir[2] = p2[2] - p1[2]; + + float dot1 = dir[0]*plane[0] + dir[1]*plane[1] + dir[2]*plane[2]; + float dot2 = dp1 - plane[3]; + + float t = -(plane[3] + dot2 ) / dot1; + + split[0] = (dir[0]*t)+p1[0]; + split[1] = (dir[1]*t)+p1[1]; + split[2] = (dir[2]*t)+p1[2]; + +} + +PlaneTriResult planeTriIntersection(const float *plane, // the plane equation in Ax+By+Cz+D format + const float *triangle, // the source triangle. + unsigned int tstride, // stride in bytes of the input and output triangles + float epsilon, // the co-planer epsilon value. + float *front, // the triangle in front of the + unsigned int &fcount, // number of vertices in the 'front' triangle + float *back, // the triangle in back of the plane + unsigned int &bcount) // the number of vertices in the 'back' triangle. +{ + fcount = 0; + bcount = 0; + + const char *tsource = (const char *) triangle; + + // get the three vertices of the triangle. + const float *p1 = (const float *) (tsource); + const float *p2 = (const float *) (tsource+tstride); + const float *p3 = (const float *) (tsource+tstride*2); + + + PlaneTriResult r1 = getSidePlane(p1,plane,epsilon); // compute the side of the plane each vertex is on + PlaneTriResult r2 = getSidePlane(p2,plane,epsilon); + PlaneTriResult r3 = getSidePlane(p3,plane,epsilon); + + if ( r1 == r2 && r1 == r3 ) // if all three vertices are on the same side of the plane. + { + if ( r1 == PTR_FRONT ) // if all three are in front of the plane, then copy to the 'front' output triangle. + { + add(p1,front,tstride,fcount); + add(p2,front,tstride,fcount); + add(p3,front,tstride,fcount); + } + else + { + add(p1,back,tstride,bcount); // if all three are in 'abck' then copy to the 'back' output triangle. + add(p2,back,tstride,bcount); + add(p3,back,tstride,bcount); + } + return r1; // if all three points are on the same side of the plane return result + } + + // ok.. we need to split the triangle at the plane. + + // First test ray segment P1 to P2 + if ( r1 == r2 ) // if these are both on the same side... + { + if ( r1 == PTR_FRONT ) + { + add( p1, front, tstride, fcount ); + add( p2, front, tstride, fcount ); + } + else + { + add( p1, back, tstride, bcount ); + add( p2, back, tstride, bcount ); + } + } + else + { + float split[3]; // split the point + intersect(p1,p2,split,plane); + + if ( r1 == PTR_FRONT ) + { + + add(p1, front, tstride, fcount ); + add(split, front, tstride, fcount ); + + add(split, back, tstride, bcount ); + add(p2, back, tstride, bcount ); + + } + else + { + add(p1, back, tstride, bcount ); + add(split, back, tstride, bcount ); + + add(split, front, tstride, fcount ); + add(p2, front, tstride, fcount ); + } + + } + + // Next test ray segment P2 to P3 + if ( r2 == r3 ) // if these are both on the same side... + { + if ( r3 == PTR_FRONT ) + { + add( p3, front, tstride, fcount ); + } + else + { + add( p3, back, tstride, bcount ); + } + } + else + { + float split[3]; // split the point + intersect(p2,p3,split,plane); + + if ( r3 == PTR_FRONT ) + { + add(split, front, tstride, fcount ); + add(split, back, tstride, bcount ); + + add(p3, front, tstride, fcount ); + } + else + { + add(split, front, tstride, fcount ); + add(split, back, tstride, bcount ); + + add(p3, back, tstride, bcount ); + } + } + + // Next test ray segment P3 to P1 + if ( r3 != r1 ) // if these are both on the same side... + { + float split[3]; // split the point + + intersect(p3,p1,split,plane); + + if ( r1 == PTR_FRONT ) + { + add(split, front, tstride, fcount ); + add(split, back, tstride, bcount ); + } + else + { + add(split, front, tstride, fcount ); + add(split, back, tstride, bcount ); + } + } + + + + return PTR_SPLIT; +} diff --git a/Extras/ConvexDecomposition/planetri.h b/Extras/ConvexDecomposition/planetri.h new file mode 100644 index 0000000000..780ac854aa --- /dev/null +++ b/Extras/ConvexDecomposition/planetri.h @@ -0,0 +1,58 @@ +#ifndef PLANE_TRI_H + +#define PLANE_TRI_H + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + + +enum PlaneTriResult +{ + PTR_FRONT, + PTR_BACK, + PTR_SPLIT +}; + +PlaneTriResult planeTriIntersection(const float *plane, // the plane equation in Ax+By+Cz+D format + const float *triangle, // the source position triangle. + unsigned int tstride, // stride in bytes between vertices of the triangle. + float epsilon, // the co-planer epsilon value. + float *front, // the triangle in front of the + unsigned int &fcount, // number of vertices in the 'front' triangle. + float *back, // the triangle in back of the plane + unsigned int &bcount); // the number of vertices in the 'back' triangle. + + +#endif diff --git a/Extras/ConvexDecomposition/premake4.lua b/Extras/ConvexDecomposition/premake4.lua new file mode 100644 index 0000000000..cfed4521e7 --- /dev/null +++ b/Extras/ConvexDecomposition/premake4.lua @@ -0,0 +1,9 @@ + project "ConvexDecomposition" + + kind "StaticLib" + targetdir "../../lib" + includedirs {".","../../src"} + files { + "**.cpp", + "**.h" + } \ No newline at end of file diff --git a/Extras/ConvexDecomposition/raytri.cpp b/Extras/ConvexDecomposition/raytri.cpp new file mode 100644 index 0000000000..83b076a20d --- /dev/null +++ b/Extras/ConvexDecomposition/raytri.cpp @@ -0,0 +1,134 @@ +#include "float_math.h" +#include +#include +#include +#include +#include + +#include "raytri.h" + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + +/* a = b - c */ +#define vector(a,b,c) \ + (a)[0] = (b)[0] - (c)[0]; \ + (a)[1] = (b)[1] - (c)[1]; \ + (a)[2] = (b)[2] - (c)[2]; + + + +#define innerProduct(v,q) \ + ((v)[0] * (q)[0] + \ + (v)[1] * (q)[1] + \ + (v)[2] * (q)[2]) + +#define crossProduct(a,b,c) \ + (a)[0] = (b)[1] * (c)[2] - (c)[1] * (b)[2]; \ + (a)[1] = (b)[2] * (c)[0] - (c)[2] * (b)[0]; \ + (a)[2] = (b)[0] * (c)[1] - (c)[0] * (b)[1]; + +bool rayIntersectsTriangle(const float *p,const float *d,const float *v0,const float *v1,const float *v2,float &t) +{ + + float e1[3],e2[3],h[3],s[3],q[3]; + float a,f,u,v; + + vector(e1,v1,v0); + vector(e2,v2,v0); + crossProduct(h,d,e2); + a = innerProduct(e1,h); + + if (a > -0.00001 && a < 0.00001) + return(false); + + f = 1/a; + vector(s,p,v0); + u = f * (innerProduct(s,h)); + + if (u < 0.0 || u > 1.0) + return(false); + + crossProduct(q,s,e1); + v = f * innerProduct(d,q); + if (v < 0.0 || u + v > 1.0) + return(false); + // at this stage we can compute t to find out where + // the intersection point is on the line + t = f * innerProduct(e2,q); + if (t > 0) // ray intersection + return(true); + else // this means that there is a line intersection + // but not a ray intersection + return (false); +} + + +bool lineIntersectsTriangle(const float *rayStart,const float *rayEnd,const float *p1,const float *p2,const float *p3,float *sect) +{ + float dir[3]; + + dir[0] = rayEnd[0] - rayStart[0]; + dir[1] = rayEnd[1] - rayStart[1]; + dir[2] = rayEnd[2] - rayStart[2]; + + float d = sqrtf(dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2]); + float r = 1.0f / d; + + dir[0]*=r; + dir[1]*=r; + dir[2]*=r; + + + float t; + + bool ret = rayIntersectsTriangle(rayStart, dir, p1, p2, p3, t ); + + if ( ret ) + { + if ( t > d ) + { + sect[0] = rayStart[0] + dir[0]*t; + sect[1] = rayStart[1] + dir[1]*t; + sect[2] = rayStart[2] + dir[2]*t; + } + else + { + ret = false; + } + } + + return ret; +} diff --git a/Extras/ConvexDecomposition/raytri.h b/Extras/ConvexDecomposition/raytri.h new file mode 100644 index 0000000000..76370c6d75 --- /dev/null +++ b/Extras/ConvexDecomposition/raytri.h @@ -0,0 +1,45 @@ +#ifndef RAY_TRI_H + +#define RAY_TRI_H + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + + +// returns true if the ray intersects the triangle. +bool lineIntersectsTriangle(const float *rayStart,const float *rayEnd,const float *p1,const float *p2,const float *p3,float *sect); +bool rayIntersectsTriangle(const float *p,const float *d,const float *v0,const float *v1,const float *v2,float &t); + +#endif diff --git a/Extras/ConvexDecomposition/splitplane.cpp b/Extras/ConvexDecomposition/splitplane.cpp new file mode 100644 index 0000000000..2ae408e601 --- /dev/null +++ b/Extras/ConvexDecomposition/splitplane.cpp @@ -0,0 +1,306 @@ +#include "float_math.h" +#include +#include +#include +#include +#include +#include + + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + +#include "splitplane.h" +#include "ConvexDecomposition.h" +#include "cd_vector.h" +#include "cd_hull.h" +#include "cd_wavefront.h" +#include "bestfit.h" +#include "planetri.h" +#include "vlookup.h" +#include "meshvolume.h" + +namespace ConvexDecomposition +{ + +static void computePlane(const float *A,const float *B,const float *C,float *plane) +{ + + float vx = (B[0] - C[0]); + float vy = (B[1] - C[1]); + float vz = (B[2] - C[2]); + + float wx = (A[0] - B[0]); + float wy = (A[1] - B[1]); + float wz = (A[2] - B[2]); + + float vw_x = vy * wz - vz * wy; + float vw_y = vz * wx - vx * wz; + float vw_z = vx * wy - vy * wx; + + float mag = sqrtf((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z)); + + if ( mag < 0.000001f ) + { + mag = 0; + } + else + { + mag = 1.0f/mag; + } + + float x = vw_x * mag; + float y = vw_y * mag; + float z = vw_z * mag; + + + float D = 0.0f - ((x*A[0])+(y*A[1])+(z*A[2])); + + plane[0] = x; + plane[1] = y; + plane[2] = z; + plane[3] = D; + +} + +class Rect3d +{ +public: + Rect3d(void) { }; + + Rect3d(const float *bmin,const float *bmax) + { + + mMin[0] = bmin[0]; + mMin[1] = bmin[1]; + mMin[2] = bmin[2]; + + mMax[0] = bmax[0]; + mMax[1] = bmax[1]; + mMax[2] = bmax[2]; + + } + + void SetMin(const float *bmin) + { + mMin[0] = bmin[0]; + mMin[1] = bmin[1]; + mMin[2] = bmin[2]; + } + + void SetMax(const float *bmax) + { + mMax[0] = bmax[0]; + mMax[1] = bmax[1]; + mMax[2] = bmax[2]; + } + + void SetMin(float x,float y,float z) + { + mMin[0] = x; + mMin[1] = y; + mMin[2] = z; + } + + void SetMax(float x,float y,float z) + { + mMax[0] = x; + mMax[1] = y; + mMax[2] = z; + } + + float mMin[3]; + float mMax[3]; +}; + +void splitRect(unsigned int axis, + const Rect3d &source, + Rect3d &b1, + Rect3d &b2, + const float *midpoint) +{ + switch ( axis ) + { + case 0: + b1.SetMin(source.mMin); + b1.SetMax( midpoint[0], source.mMax[1], source.mMax[2] ); + + b2.SetMin( midpoint[0], source.mMin[1], source.mMin[2] ); + b2.SetMax(source.mMax); + + break; + case 1: + b1.SetMin(source.mMin); + b1.SetMax( source.mMax[0], midpoint[1], source.mMax[2] ); + + b2.SetMin( source.mMin[0], midpoint[1], source.mMin[2] ); + b2.SetMax(source.mMax); + + break; + case 2: + b1.SetMin(source.mMin); + b1.SetMax( source.mMax[0], source.mMax[1], midpoint[2] ); + + b2.SetMin( source.mMin[0], source.mMin[1], midpoint[2] ); + b2.SetMax(source.mMax); + + break; + } +} + +bool computeSplitPlane(unsigned int vcount, + const float *vertices, + unsigned int tcount, + const unsigned int *indices, + ConvexDecompInterface *callback, + float *plane) +{ + float bmin[3] = { 1e9, 1e9, 1e9 }; + float bmax[3] = { -1e9, -1e9, -1e9 }; + + for (unsigned int i=0; i bmax[0] ) bmax[0] = p[0]; + if ( p[1] > bmax[1] ) bmax[1] = p[1]; + if ( p[2] > bmax[2] ) bmax[2] = p[2]; + + } + + float dx = bmax[0] - bmin[0]; + float dy = bmax[1] - bmin[1]; + float dz = bmax[2] - bmin[2]; + + + float laxis = dx; + + unsigned int axis = 0; + + if ( dy > dx ) + { + axis = 1; + laxis = dy; + } + + if ( dz > dx && dz > dy ) + { + axis = 2; + laxis = dz; + } + + float p1[3]; + float p2[3]; + float p3[3]; + + p3[0] = p2[0] = p1[0] = bmin[0] + dx*0.5f; + p3[1] = p2[1] = p1[1] = bmin[1] + dy*0.5f; + p3[2] = p2[2] = p1[2] = bmin[2] + dz*0.5f; + + Rect3d b(bmin,bmax); + + Rect3d b1,b2; + + splitRect(axis,b,b1,b2,p1); + + +// callback->ConvexDebugBound(b1.mMin,b1.mMax,0x00FF00); +// callback->ConvexDebugBound(b2.mMin,b2.mMax,0xFFFF00); + + switch ( axis ) + { + case 0: + p2[1] = bmin[1]; + p2[2] = bmin[2]; + + if ( dz > dy ) + { + p3[1] = bmax[1]; + p3[2] = bmin[2]; + } + else + { + p3[1] = bmin[1]; + p3[2] = bmax[2]; + } + + break; + case 1: + p2[0] = bmin[0]; + p2[2] = bmin[2]; + + if ( dx > dz ) + { + p3[0] = bmax[0]; + p3[2] = bmin[2]; + } + else + { + p3[0] = bmin[0]; + p3[2] = bmax[2]; + } + + break; + case 2: + p2[0] = bmin[0]; + p2[1] = bmin[1]; + + if ( dx > dy ) + { + p3[0] = bmax[0]; + p3[1] = bmin[1]; + } + else + { + p3[0] = bmin[0]; + p3[1] = bmax[1]; + } + + break; + } + +// callback->ConvexDebugTri(p1,p2,p3,0xFF0000); + + computePlane(p1,p2,p3,plane); + + return true; + +} + + +} diff --git a/Extras/ConvexDecomposition/splitplane.h b/Extras/ConvexDecomposition/splitplane.h new file mode 100644 index 0000000000..26fe2e33ed --- /dev/null +++ b/Extras/ConvexDecomposition/splitplane.h @@ -0,0 +1,59 @@ +#ifndef SPLIT_PLANE_H + +#define SPLIT_PLANE_H + +//** Computes an 'optimal' split plane for the supplied mesh. +//** needs much improvement since it currently just splits along +//** the longest side of the AABB. +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + + +namespace ConvexDecomposition +{ + +class ConvexDecompInterface; + +bool computeSplitPlane(unsigned int vcount, + const float *vertices, + unsigned int tcount, + const unsigned int *indices, + ConvexDecompInterface *callback, + float *plane); + + +} + +#endif diff --git a/Extras/ConvexDecomposition/vlookup.cpp b/Extras/ConvexDecomposition/vlookup.cpp new file mode 100644 index 0000000000..3b9e928ca0 --- /dev/null +++ b/Extras/ConvexDecomposition/vlookup.cpp @@ -0,0 +1,326 @@ +#include "float_math.h" +#include +#include +#include +#include + +#pragma warning(disable:4786) + +#include +#include +#include + + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + +// CodeSnippet provided by John W. Ratcliff +// on March 23, 2006. +// +// mailto: jratcliff@infiniplex.net +// +// Personal website: http://jratcliffscarab.blogspot.com +// Coding Website: http://codesuppository.blogspot.com +// FundRaising Blog: http://amillionpixels.blogspot.com +// Fundraising site: http://www.amillionpixels.us +// New Temple Site: http://newtemple.blogspot.com +// +// This snippet shows how to 'hide' the complexity of +// the STL by wrapping some useful piece of functionality +// around a handful of discrete API calls. +// +// This API allows you to create an indexed triangle list +// from a collection of raw input triangles. Internally +// it uses an STL set to build the lookup table very rapidly. +// +// Here is how you would use it to build an indexed triangle +// list from a raw list of triangles. +// +// (1) create a 'VertexLookup' interface by calling +// +// VertexLook vl = Vl_createVertexLookup(); +// +// (2) For each vertice in each triangle call: +// +// unsigned int i1 = Vl_getIndex(vl,p1); +// unsigned int i2 = Vl_getIndex(vl,p2); +// unsigned int i3 = Vl_getIndex(vl,p3); +// +// save the 3 indices into your triangle list array. +// +// (3) Get the vertex array by calling: +// +// const float *vertices = Vl_getVertices(vl); +// +// (4) Get the number of vertices so you can copy them into +// your own buffer. +// unsigned int vcount = Vl_getVcount(vl); +// +// (5) Release the VertexLookup interface when you are done with it. +// Vl_releaseVertexLookup(vl); +// +// Teaches the following lessons: +// +// How to wrap the complexity of STL and C++ classes around a +// simple API interface. +// +// How to use an STL set and custom comparator operator for +// a complex data type. +// +// How to create a template class. +// +// How to achieve significant performance improvements by +// taking advantage of built in STL containers in just +// a few lines of code. +// +// You could easily modify this code to support other vertex +// formats with any number of interpolants. + + + + +#include "vlookup.h" + +namespace Vlookup +{ + +class VertexPosition +{ +public: + VertexPosition(void) { }; + VertexPosition(const float *p) + { + mPos[0] = p[0]; + mPos[1] = p[1]; + mPos[2] = p[2]; + }; + + void Set(int index,const float *pos) + { + const float * p = &pos[index*3]; + + mPos[0] = p[0]; + mPos[1] = p[1]; + mPos[2] = p[2]; + + }; + + float GetX(void) const { return mPos[0]; }; + float GetY(void) const { return mPos[1]; }; + float GetZ(void) const { return mPos[2]; }; + + float mPos[3]; +}; + +typedef std::vector< VertexPosition > VertexVector; + +struct Tracker +{ + VertexPosition mFind; // vertice to locate. + VertexVector *mList; + + Tracker() + { + mList = 0; + } + + void SetSearch(const VertexPosition& match,VertexVector *list) + { + mFind = match; + mList = list; + }; +}; + +struct VertexID +{ + int mID; + Tracker* mTracker; + + VertexID(int ID, Tracker* Tracker) + { + mID = ID; + mTracker = Tracker; + } +}; + +class VertexLess +{ +public: + + bool operator()(VertexID v1,VertexID v2) const; + +private: + const VertexPosition& Get(VertexID index) const + { + if ( index.mID == -1 ) return index.mTracker->mFind; + VertexVector &vlist = *index.mTracker->mList; + return vlist[index.mID]; + } +}; + +template class VertexPool +{ +public: + typedef std::set VertexSet; + typedef std::vector< Type > VertexVector; + + int getVertex(const Type& vtx) + { + mTracker.SetSearch(vtx,&mVtxs); + VertexSet::iterator found; + found = mVertSet.find( VertexID(-1,&mTracker) ); + if ( found != mVertSet.end() ) + { + return found->mID; + } + int idx = (int)mVtxs.size(); + mVtxs.push_back( vtx ); + mVertSet.insert( VertexID(idx,&mTracker) ); + return idx; + }; + + + const float * GetPos(int idx) const + { + return mVtxs[idx].mPos; + } + + const Type& Get(int idx) const + { + return mVtxs[idx]; + }; + + unsigned int GetSize(void) const + { + return mVtxs.size(); + }; + + void Clear(int reservesize) // clear the vertice pool. + { + mVertSet.clear(); + mVtxs.clear(); + mVtxs.reserve(reservesize); + }; + + const VertexVector& GetVertexList(void) const { return mVtxs; }; + + void Set(const Type& vtx) + { + mVtxs.push_back(vtx); + } + + unsigned int GetVertexCount(void) const + { + return mVtxs.size(); + }; + + + Type * getBuffer(void) + { + return &mVtxs[0]; + }; + +private: + VertexSet mVertSet; // ordered list. + VertexVector mVtxs; // set of vertices. + Tracker mTracker; +}; + + +bool VertexLess::operator()(VertexID v1,VertexID v2) const +{ + + const VertexPosition& a = Get(v1); + const VertexPosition& b = Get(v2); + + int ixA = (int) (a.GetX()*10000.0f); + int ixB = (int) (b.GetX()*10000.0f); + + if ( ixA < ixB ) return true; + if ( ixA > ixB ) return false; + + int iyA = (int) (a.GetY()*10000.0f); + int iyB = (int) (b.GetY()*10000.0f); + + if ( iyA < iyB ) return true; + if ( iyA > iyB ) return false; + + int izA = (int) (a.GetZ()*10000.0f); + int izB = (int) (b.GetZ()*10000.0f); + + if ( izA < izB ) return true; + if ( izA > izB ) return false; + + + return false; +} + + + + +} + +using namespace Vlookup; + +VertexLookup Vl_createVertexLookup(void) +{ + VertexLookup ret = new VertexPool< VertexPosition >; + return ret; +} + +void Vl_releaseVertexLookup(VertexLookup vlook) +{ + VertexPool< VertexPosition > *vp = (VertexPool< VertexPosition > *) vlook; + delete vp; +} + +unsigned int Vl_getIndex(VertexLookup vlook,const float *pos) // get index. +{ + VertexPool< VertexPosition > *vp = (VertexPool< VertexPosition > *) vlook; + VertexPosition p(pos); + return vp->getVertex(p); +} + +const float * Vl_getVertices(VertexLookup vlook) +{ + VertexPool< VertexPosition > *vp = (VertexPool< VertexPosition > *) vlook; + return vp->GetPos(0); +} + + +unsigned int Vl_getVcount(VertexLookup vlook) +{ + VertexPool< VertexPosition > *vp = (VertexPool< VertexPosition > *) vlook; + return vp->GetVertexCount(); +} diff --git a/Extras/ConvexDecomposition/vlookup.h b/Extras/ConvexDecomposition/vlookup.h new file mode 100644 index 0000000000..1a6e0a9e2c --- /dev/null +++ b/Extras/ConvexDecomposition/vlookup.h @@ -0,0 +1,119 @@ +#ifndef VLOOKUP_H + +#define VLOOKUP_H + + +/*---------------------------------------------------------------------- + Copyright (c) 2004 Open Dynamics Framework Group + www.physicstools.org + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided + that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + Neither the name of the Open Dynamics Framework Group nor the names of its contributors may + be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + +// CodeSnippet provided by John W. Ratcliff +// on March 23, 2006. +// +// mailto: jratcliff@infiniplex.net +// +// Personal website: http://jratcliffscarab.blogspot.com +// Coding Website: http://codesuppository.blogspot.com +// FundRaising Blog: http://amillionpixels.blogspot.com +// Fundraising site: http://www.amillionpixels.us +// New Temple Site: http://newtemple.blogspot.com +// +// This snippet shows how to 'hide' the complexity of +// the STL by wrapping some useful piece of functionality +// around a handful of discrete API calls. +// +// This API allows you to create an indexed triangle list +// from a collection of raw input triangles. Internally +// it uses an STL set to build the lookup table very rapidly. +// +// Here is how you would use it to build an indexed triangle +// list from a raw list of triangles. +// +// (1) create a 'VertexLookup' interface by calling +// +// VertexLook vl = Vl_createVertexLookup(); +// +// (2) For each vertice in each triangle call: +// +// unsigned int i1 = Vl_getIndex(vl,p1); +// unsigned int i2 = Vl_getIndex(vl,p2); +// unsigned int i3 = Vl_getIndex(vl,p3); +// +// save the 3 indices into your triangle list array. +// +// (3) Get the vertex array by calling: +// +// const float *vertices = Vl_getVertices(vl); +// +// (4) Get the number of vertices so you can copy them into +// your own buffer. +// unsigned int vcount = Vl_getVcount(vl); +// +// (5) Release the VertexLookup interface when you are done with it. +// Vl_releaseVertexLookup(vl); +// +// Teaches the following lessons: +// +// How to wrap the complexity of STL and C++ classes around a +// simple API interface. +// +// How to use an STL set and custom comparator operator for +// a complex data type. +// +// How to create a template class. +// +// How to achieve significant performance improvements by +// taking advantage of built in STL containers in just +// a few lines of code. +// +// You could easily modify this code to support other vertex +// formats with any number of interpolants. +// +// Hide C++ classes from the rest of your application by +// keeping them in the CPP and wrapping them in a namespace +// Uses an STL set to create an index table for a bunch of vertex positions +// used typically to re-index a collection of raw triangle data. + + +typedef void * VertexLookup; + +VertexLookup Vl_createVertexLookup(void); +void Vl_releaseVertexLookup(VertexLookup vlook); + +unsigned int Vl_getIndex(VertexLookup vlook,const float *pos); // get index. +const float * Vl_getVertices(VertexLookup vlook); +unsigned int Vl_getVcount(VertexLookup vlook); + + +#endif diff --git a/Extras/GIMPACTUtils/CMakeLists.txt b/Extras/GIMPACTUtils/CMakeLists.txt new file mode 100644 index 0000000000..5c9480a979 --- /dev/null +++ b/Extras/GIMPACTUtils/CMakeLists.txt @@ -0,0 +1,37 @@ +INCLUDE_DIRECTORIES( +${BULLET_PHYSICS_SOURCE_DIR}/Extras/GIMPACT/include +${BULLET_PHYSICS_SOURCE_DIR}/src +${BULLET_PHYSICS_SOURCE_DIR}/Extras/GIMPACTUtils +${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexDecomposition +) + +ADD_LIBRARY(GIMPACTUtils +btGImpactConvexDecompositionShape.cpp btGImpactConvexDecompositionShape.h +) +SET_TARGET_PROPERTIES(GIMPACTUtils PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(GIMPACTUtils PROPERTIES SOVERSION ${BULLET_VERSION}) + +IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(GIMPACTUtils ConvexDecomposition BulletCollision) +ENDIF (BUILD_SHARED_LIBS) + +IF (INSTALL_EXTRA_LIBS) + IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) + #FILES_MATCHING requires CMake 2.6 + IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS GIMPACTUtils DESTINATION .) + ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS GIMPACTUtils DESTINATION lib${LIB_SUFFIX}) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN +".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE) + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + SET_TARGET_PROPERTIES(GIMPACTUtils PROPERTIES FRAMEWORK true) + SET_TARGET_PROPERTIES(GIMPACTUtils PROPERTIES PUBLIC_HEADER "btGImpactConvexDecompositionShape.h") + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) +ENDIF (INSTALL_EXTRA_LIBS) diff --git a/Extras/GIMPACTUtils/btGImpactConvexDecompositionShape.cpp b/Extras/GIMPACTUtils/btGImpactConvexDecompositionShape.cpp new file mode 100644 index 0000000000..fc1ce33e20 --- /dev/null +++ b/Extras/GIMPACTUtils/btGImpactConvexDecompositionShape.cpp @@ -0,0 +1,240 @@ +/* +This source file is part of GIMPACT Library. + +For the latest info, see http://gimpact.sourceforge.net/ + +Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371. +email: projectileman@yahoo.com + + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "btGImpactConvexDecompositionShape.h" +#include "BulletCollision/CollisionShapes/btConvexHullShape.h" + +#include "ConvexBuilder.h" + +class GIM_ConvexDecomposition : public ConvexDecomposition::ConvexDecompInterface +{ +protected: + btGImpactConvexDecompositionShape * m_compoundShape; + + btAlignedObjectArray m_convexShapes; + + +public: + int mBaseCount; + int mHullCount; + bool m_transformSubShapes; + + GIM_ConvexDecomposition(btGImpactConvexDecompositionShape * compoundShape,bool transformSubShapes) + { + mBaseCount = 0; + mHullCount = 0; + m_compoundShape = compoundShape; + m_transformSubShapes = transformSubShapes; + } + + virtual ~GIM_ConvexDecomposition() + { + int i; + for (i=0;i vertices; + + if(m_transformSubShapes) + { + + //const unsigned int *src = result.mHullIndices; + for (unsigned int i=0; isetMargin(m_compoundShape->getMargin()); + + if(m_transformSubShapes) + { + btTransform trans; + trans.setIdentity(); + trans.setOrigin(centroid); + + // add convex shape + + m_compoundShape->addChildShape(trans,convexShape); + } + else + { + btTransform trans; + trans.setIdentity(); + //trans.setOrigin(centroid); + + // add convex shape + + m_compoundShape->addChildShape(trans,convexShape); + + //m_compoundShape->addChildShape(convexShape); + } + } + + void processDecomposition(int part) + { + btGImpactMeshShapePart::TrimeshPrimitiveManager * trimeshInterface = + m_compoundShape->getTrimeshInterface(part); + + + trimeshInterface->lock(); + + //collect vertices + btAlignedObjectArray vertices; + vertices.reserve(trimeshInterface->get_vertex_count()*3); + + for(int vi = 0;viget_vertex_count();vi++) + { + btVector3 vec; + trimeshInterface->get_vertex(vi,vec); + vertices.push_back(vec[0]); + vertices.push_back(vec[1]); + vertices.push_back(vec[2]); + } + + + //collect indices + btAlignedObjectArray indices; + indices.reserve(trimeshInterface->get_primitive_count()*3); + + + for(int i = 0;iget_primitive_count();i++) + { + unsigned int i0, i1,i2; + trimeshInterface->get_indices(i,i0,i1,i2); + indices.push_back(i0); + indices.push_back(i1); + indices.push_back(i2); + } + + trimeshInterface->unlock(); + + + + unsigned int depth = 5; + float cpercent = 5; + float ppercent = 15; + unsigned int maxv = 16; + float skinWidth = 0.0f; + + + ConvexDecomposition::DecompDesc desc; + desc.mVcount = trimeshInterface->get_vertex_count(); + desc.mVertices = &vertices[0]; + desc.mTcount = trimeshInterface->get_primitive_count(); + desc.mIndices = &indices[0]; + desc.mDepth = depth; + desc.mCpercent = cpercent; + desc.mPpercent = ppercent; + desc.mMaxVertices = maxv; + desc.mSkinWidth = skinWidth; + desc.mCallback = this; + + //convexDecomposition.performConvexDecomposition(desc); + + ConvexBuilder cb(desc.mCallback); + cb.process(desc); + } + + + + +}; + + + +void btGImpactConvexDecompositionShape::buildConvexDecomposition(bool transformSubShapes) +{ + + m_decomposition = new GIM_ConvexDecomposition(this,transformSubShapes); + + int part_count = m_trimeshInterfaces.size(); + for (int i = 0;iprocessDecomposition(i); + } + + postUpdate(); +} + +btGImpactConvexDecompositionShape::~btGImpactConvexDecompositionShape() +{ + delete m_decomposition; +} +void btGImpactConvexDecompositionShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const +{ + + int part_count = m_trimeshInterfaces.size(); + for (int part = 0;part(ptr); + + trimeshInterface->lock(); + + btPrimitiveTriangle triangle; + + + int i = trimeshInterface->get_primitive_count(); + while(i--) + { + trimeshInterface->get_primitive_triangle(i,triangle); + callback->processTriangle(triangle.m_vertices,part,i); + } + + trimeshInterface->unlock(); + } + + +} diff --git a/Extras/GIMPACTUtils/btGImpactConvexDecompositionShape.h b/Extras/GIMPACTUtils/btGImpactConvexDecompositionShape.h new file mode 100644 index 0000000000..4710861f3e --- /dev/null +++ b/Extras/GIMPACTUtils/btGImpactConvexDecompositionShape.h @@ -0,0 +1,87 @@ +/*! \file btGImpactConvexDecompositionShape.h +\author Francisco León Nájera +*/ +/* +This source file is part of GIMPACT Library. + +For the latest info, see http://gimpact.sourceforge.net/ + +Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371. +email: projectileman@yahoo.com + + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef GIMPACT_CONVEX_DECOMPOSITION_SHAPE_H +#define GIMPACT_CONVEX_DECOMPOSITION_SHAPE_H + + +#include "BulletCollision/Gimpact/btGImpactShape.h" // box tree class + + + +//! This class creates a decomposition from a trimesh. +/*! + +*/ +class btGImpactConvexDecompositionShape : public btGImpactCompoundShape +{ +protected: + btAlignedObjectArray m_trimeshInterfaces; + + class GIM_ConvexDecomposition* m_decomposition; + + void buildConvexDecomposition(bool transformSubShapes); +public: + + btGImpactConvexDecompositionShape( + btStridingMeshInterface * meshInterface, + const btVector3 & mesh_scale, + btScalar margin = btScalar(0.01),bool children_has_transform = true) + :btGImpactCompoundShape(children_has_transform) + { + + m_collisionMargin = margin; + + btGImpactMeshShapePart::TrimeshPrimitiveManager triInterface; + triInterface.m_meshInterface = meshInterface; + triInterface.m_scale = mesh_scale; + triInterface.m_margin = btScalar(1.0); + + //add parts + int part_count = meshInterface->getNumSubParts(); + for (int i=0;i< part_count;i++ ) + { + triInterface.m_part = i; + m_trimeshInterfaces.push_back(triInterface); + } + + m_decomposition = 0; + + buildConvexDecomposition(children_has_transform); + } + + virtual ~btGImpactConvexDecompositionShape(); + + SIMD_FORCE_INLINE btGImpactMeshShapePart::TrimeshPrimitiveManager * getTrimeshInterface(int part) + { + return &m_trimeshInterfaces[part]; + } + + virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const; + +}; + + + + +#endif //GIMPACT_MESH_SHAPE_H diff --git a/Extras/HACD/CMakeLists.txt b/Extras/HACD/CMakeLists.txt new file mode 100644 index 0000000000..e2f3a5672f --- /dev/null +++ b/Extras/HACD/CMakeLists.txt @@ -0,0 +1,51 @@ +INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/HACD +) + +SET(HACD_SRCS + hacdGraph.cpp + hacdHACD.cpp + hacdICHull.cpp + hacdManifoldMesh.cpp +) + +SET(HACD_HDRS + hacdCircularList.h + hacdGraph.h + hacdHACD.h + hacdICHull.h + hacdManifoldMesh.h + hacdVector.h + hacdVersion.h + hacdCircularList.inl + hacdVector.inl +) + +ADD_LIBRARY(HACD ${HACD_SRCS} ${HACD_HDRS}) +SET_TARGET_PROPERTIES(HACD PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(HACD PROPERTIES SOVERSION ${BULLET_VERSION}) + +#IF (BUILD_SHARED_LIBS) +# TARGET_LINK_LIBRARIES(HACD BulletCollision LinearMath) +#ENDIF (BUILD_SHARED_LIBS) + +IF (INSTALL_EXTRA_LIBS) + IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) + #FILES_MATCHING requires CMake 2.6 + IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS HACD DESTINATION .) + ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS HACD DESTINATION lib${LIB_SUFFIX}) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN "*.inl" PATTERN + ".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE) + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + SET_TARGET_PROPERTIES(HACD PROPERTIES FRAMEWORK true) + SET_TARGET_PROPERTIES(HACD PROPERTIES PUBLIC_HEADER "${HACD_HDRS}") + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) +ENDIF (INSTALL_EXTRA_LIBS) diff --git a/Extras/HACD/hacdCircularList.h b/Extras/HACD/hacdCircularList.h new file mode 100644 index 0000000000..a13394cd65 --- /dev/null +++ b/Extras/HACD/hacdCircularList.h @@ -0,0 +1,80 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once +#ifndef HACD_CIRCULAR_LIST_H +#define HACD_CIRCULAR_LIST_H +#include +#include "hacdVersion.h" +namespace HACD +{ + //! CircularListElement class. + template < typename T > class CircularListElement + { + public: + T & GetData() { return m_data; } + const T & GetData() const { return m_data; } + CircularListElement * & GetNext() { return m_next; } + CircularListElement * & GetPrev() { return m_prev; } + const CircularListElement * & GetNext() const { return m_next; } + const CircularListElement * & GetPrev() const { return m_prev; } + //! Constructor + CircularListElement(const T & data) {m_data = data;} + CircularListElement(void){} + //! Destructor + ~CircularListElement(void){} + private: + T m_data; + CircularListElement * m_next; + CircularListElement * m_prev; + + CircularListElement(const CircularListElement & rhs); + }; + + + //! CircularList class. + template < typename T > class CircularList + { + public: + CircularListElement * & GetHead() { return m_head;} + const CircularListElement * GetHead() const { return m_head;} + bool IsEmpty() const { return (m_size == 0);} + size_t GetSize() const { return m_size; } + const T & GetData() const { return m_head->GetData(); } + T & GetData() { return m_head->GetData();} + bool Delete() ; + bool Delete(CircularListElement * element); + CircularListElement * Add(const T * data = 0); + CircularListElement * Add(const T & data); + bool Next(); + bool Prev(); + void Clear() { while(Delete());}; + const CircularList& operator=(const CircularList& rhs); + //! Constructor + CircularList() + { + m_head = 0; + m_size = 0; + } + CircularList(const CircularList& rhs); + //! Destructor + virtual ~CircularList(void) {Clear();}; + private: + CircularListElement * m_head; //!< a pointer to the head of the circular list + size_t m_size; //!< number of element in the circular list + + }; +} +#include "hacdCircularList.inl" +#endif diff --git a/Extras/HACD/hacdCircularList.inl b/Extras/HACD/hacdCircularList.inl new file mode 100644 index 0000000000..471f9ed449 --- /dev/null +++ b/Extras/HACD/hacdCircularList.inl @@ -0,0 +1,163 @@ +#pragma once +#ifndef HACD_CIRCULAR_LIST_INL +#define HACD_CIRCULAR_LIST_INL +#include +#include "hacdVersion.h" +namespace HACD +{ + template < typename T > + inline bool CircularList::Delete(CircularListElement * element) + { + if (!element) + { + return false; + } + if (m_size > 1) + { + CircularListElement * next = element->GetNext(); + CircularListElement * prev = element->GetPrev(); + delete element; + m_size--; + if (element == m_head) + { + m_head = next; + } + next->GetPrev() = prev; + prev->GetNext() = next; + return true; + } + else if (m_size == 1) + { + delete m_head; + m_size--; + m_head = 0; + return true; + } + else + { + return false; + } + } + + template < typename T > + inline bool CircularList::Delete() + { + if (m_size > 1) + { + CircularListElement * next = m_head->GetNext(); + CircularListElement * prev = m_head->GetPrev(); + delete m_head; + m_size--; + m_head = next; + next->GetPrev() = prev; + prev->GetNext() = next; + return true; + } + else if (m_size == 1) + { + delete m_head; + m_size--; + m_head = 0; + return true; + } + else + { + return false; + } + } + template < typename T > + inline CircularListElement * CircularList::Add(const T * data) + { + if (m_size == 0) + { + if (data) + { + m_head = new CircularListElement(*data); + } + else + { + m_head = new CircularListElement(); + } + m_head->GetNext() = m_head->GetPrev() = m_head; + } + else + { + CircularListElement * next = m_head->GetNext(); + CircularListElement * element = m_head; + if (data) + { + m_head = new CircularListElement(*data); + } + else + { + m_head = new CircularListElement; + } + m_head->GetNext() = next; + m_head->GetPrev() = element; + element->GetNext() = m_head; + next->GetPrev() = m_head; + } + m_size++; + return m_head; + } + template < typename T > + inline CircularListElement * CircularList::Add(const T & data) + { + const T * pData = &data; + return Add(pData); + } + template < typename T > + inline bool CircularList::Next() + { + if (m_size == 0) + { + return false; + } + m_head = m_head->GetNext(); + return true; + } + template < typename T > + inline bool CircularList::Prev() + { + if (m_size == 0) + { + return false; + } + m_head = m_head->GetPrev(); + return true; + } + template < typename T > + inline CircularList::CircularList(const CircularList& rhs) + { + if (rhs.m_size > 0) + { + CircularListElement * current = rhs.m_head; + do + { + current = current->GetNext(); + Add(current->GetData()); + } + while ( current != rhs.m_head ); + } + } + template < typename T > + inline const CircularList& CircularList::operator=(const CircularList& rhs) + { + if (&rhs != this) + { + Clear(); + if (rhs.m_size > 0) + { + CircularListElement * current = rhs.m_head; + do + { + current = current->GetNext(); + Add(current->GetData()); + } + while ( current != rhs.m_head ); + } + } + return (*this); + } +} +#endif diff --git a/Extras/HACD/hacdGraph.cpp b/Extras/HACD/hacdGraph.cpp new file mode 100644 index 0000000000..4204f2d677 --- /dev/null +++ b/Extras/HACD/hacdGraph.cpp @@ -0,0 +1,292 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "hacdGraph.h" +namespace HACD +{ + + GraphEdge::GraphEdge() + { + m_convexHull = 0; + m_v1 = -1; + m_v2 = -1; + m_name = -1; + m_error = 0; + m_surf = 0; + m_perimeter = 0; + m_concavity = 0; + m_volume = 0; + m_deleted = false; + } + + GraphVertex::GraphVertex() + { + m_convexHull = 0; + m_name = -1; + m_cc = -1; + m_error = 0; + m_surf = 0; + m_perimeter = 0; + m_concavity = 0; + m_volume = 0; + m_deleted = false; + } + + bool GraphVertex::DeleteEdge(long name) + { + std::set::iterator it = m_edges.find(name); + if (it != m_edges.end() ) + { + m_edges.erase(it); + return true; + } + return false; + } + + Graph::Graph() + { + m_nV = 0; + m_nE = 0; + m_nCCs = 0; + } + + Graph::~Graph() + { + } + + void Graph::Allocate(size_t nV, size_t nE) + { + m_nV = nV; + m_edges.reserve(nE); + m_vertices.resize(nV); + for(size_t i = 0; i < nV; i++) + { + m_vertices[i].m_name = static_cast(i); + } + } + + long Graph::AddVertex() + { + size_t name = m_vertices.size(); + m_vertices.resize(name+1); + m_vertices[name].m_name = static_cast(name); + m_nV++; + return static_cast(name); + } + + long Graph::AddEdge(long v1, long v2) + { + size_t name = m_edges.size(); + m_edges.push_back(GraphEdge()); + m_edges[name].m_name = static_cast(name); + m_edges[name].m_v1 = v1; + m_edges[name].m_v2 = v2; + m_vertices[v1].AddEdge(static_cast(name)); + m_vertices[v2].AddEdge(static_cast(name)); + m_nE++; + return static_cast(name); + } + + bool Graph::DeleteEdge(long name) + { + if (name < static_cast(m_edges.size())) + { + long v1 = m_edges[name].m_v1; + long v2 = m_edges[name].m_v2; + m_edges[name].m_deleted = true; + m_vertices[v1].DeleteEdge(name); + m_vertices[v2].DeleteEdge(name); + delete m_edges[name].m_convexHull; + m_edges[name].m_distPoints.clear(); + m_edges[name].m_boudaryEdges.clear(); + m_edges[name].m_convexHull = 0; + m_nE--; + return true; + } + return false; + } + bool Graph::DeleteVertex(long name) + { + if (name < static_cast(m_vertices.size())) + { + m_vertices[name].m_deleted = true; + m_vertices[name].m_edges.clear(); + m_vertices[name].m_ancestors = std::vector(); + delete m_vertices[name].m_convexHull; + m_vertices[name].m_distPoints.clear(); + m_vertices[name].m_boudaryEdges.clear(); + m_vertices[name].m_convexHull = 0; + m_nV--; + return true; + } + return false; + } + bool Graph::EdgeCollapse(long v1, long v2) + { + long edgeToDelete = GetEdgeID(v1, v2); + if (edgeToDelete >= 0) + { + // delete the edge (v1, v2) + DeleteEdge(edgeToDelete); + // add v2 to v1 ancestors + m_vertices[v1].m_ancestors.push_back(v2); + // add v2's ancestors to v1's ancestors + m_vertices[v1].m_ancestors.insert(m_vertices[v1].m_ancestors.begin(), + m_vertices[v2].m_ancestors.begin(), + m_vertices[v2].m_ancestors.end()); + // update adjacency information + std::set & v1Edges = m_vertices[v1].m_edges; + std::set::const_iterator ed(m_vertices[v2].m_edges.begin()); + std::set::const_iterator itEnd(m_vertices[v2].m_edges.end()); + long b = -1; + for(; ed != itEnd; ++ed) + { + if (m_edges[*ed].m_v1 == v2) + { + b = m_edges[*ed].m_v2; + } + else + { + b = m_edges[*ed].m_v1; + } + if (GetEdgeID(v1, b) >= 0) + { + m_edges[*ed].m_deleted = true; + m_vertices[b].DeleteEdge(*ed); + m_nE--; + } + else + { + m_edges[*ed].m_v1 = v1; + m_edges[*ed].m_v2 = b; + v1Edges.insert(*ed); + } + } + // delete the vertex v2 + DeleteVertex(v2); + return true; + } + return false; + } + + long Graph::GetEdgeID(long v1, long v2) const + { + if (v1 < static_cast(m_vertices.size()) && !m_vertices[v1].m_deleted) + { + std::set::const_iterator ed(m_vertices[v1].m_edges.begin()); + std::set::const_iterator itEnd(m_vertices[v1].m_edges.end()); + for(; ed != itEnd; ++ed) + { + if ( (m_edges[*ed].m_v1 == v2) || + (m_edges[*ed].m_v2 == v2) ) + { + return m_edges[*ed].m_name; + } + } + } + return -1; + } + + void Graph::Print() const + { + std::cout << "-----------------------------" << std::endl; + std::cout << "vertices (" << m_nV << ")" << std::endl; + for (size_t v = 0; v < m_vertices.size(); ++v) + { + const GraphVertex & currentVertex = m_vertices[v]; + if (!m_vertices[v].m_deleted) + { + + std::cout << currentVertex.m_name << "\t"; + std::set::const_iterator ed(currentVertex.m_edges.begin()); + std::set::const_iterator itEnd(currentVertex.m_edges.end()); + for(; ed != itEnd; ++ed) + { + std::cout << "(" << m_edges[*ed].m_v1 << "," << m_edges[*ed].m_v2 << ") "; + } + std::cout << std::endl; + } + } + + std::cout << "vertices (" << m_nE << ")" << std::endl; + for (size_t e = 0; e < m_edges.size(); ++e) + { + const GraphEdge & currentEdge = m_edges[e]; + if (!m_edges[e].m_deleted) + { + std::cout << currentEdge.m_name << "\t(" + << m_edges[e].m_v1 << "," + << m_edges[e].m_v2 << ") "<< std::endl; + } + } + } + void Graph::Clear() + { + m_vertices.clear(); + m_edges.clear(); + m_nV = 0; + m_nE = 0; + } + + long Graph::ExtractCCs() + { + // all CCs to -1 + for (size_t v = 0; v < m_vertices.size(); ++v) + { + if (!m_vertices[v].m_deleted) + { + m_vertices[v].m_cc = -1; + } + } + + // we get the CCs + m_nCCs = 0; + long v2 = -1; + std::vector temp; + for (size_t v = 0; v < m_vertices.size(); ++v) + { + if (!m_vertices[v].m_deleted && m_vertices[v].m_cc == -1) + { + m_vertices[v].m_cc = static_cast(m_nCCs); + temp.clear(); + temp.push_back(m_vertices[v].m_name); + while (temp.size()) + { + long vertex = temp[temp.size()-1]; + temp.pop_back(); + std::set::const_iterator ed(m_vertices[vertex].m_edges.begin()); + std::set::const_iterator itEnd(m_vertices[vertex].m_edges.end()); + for(; ed != itEnd; ++ed) + { + if (m_edges[*ed].m_v1 == vertex) + { + v2 = m_edges[*ed].m_v2; + } + else + { + v2 = m_edges[*ed].m_v1; + } + if ( !m_vertices[v2].m_deleted && m_vertices[v2].m_cc == -1) + { + m_vertices[v2].m_cc = static_cast(m_nCCs); + temp.push_back(v2); + } + } + } + m_nCCs++; + } + } + return static_cast(m_nCCs); + } +} diff --git a/Extras/HACD/hacdGraph.h b/Extras/HACD/hacdGraph.h new file mode 100644 index 0000000000..9b64aac60d --- /dev/null +++ b/Extras/HACD/hacdGraph.h @@ -0,0 +1,120 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once +#ifndef HACD_GRAPH_H +#define HACD_GRAPH_H +#include "hacdVersion.h" +#include "hacdVector.h" +#include "hacdICHull.h" +#include +#include +#include + +namespace HACD +{ + class GraphVertex; + class GraphEdge; + class Graph; + class HACD; + + class GraphVertex + { + public: + bool AddEdge(long name) + { + m_edges.insert(name); + return true; + } + bool DeleteEdge(long name); + GraphVertex(); + ~GraphVertex(){ delete m_convexHull;}; + private: + long m_name; + long m_cc; + std::set m_edges; + bool m_deleted; + std::vector m_ancestors; + std::map m_distPoints; + + Real m_error; + double m_surf; + double m_volume; + double m_perimeter; + double m_concavity; + ICHull * m_convexHull; + std::set m_boudaryEdges; + + + friend class GraphEdge; + friend class Graph; + friend class HACD; + }; + + class GraphEdge + { + public: + GraphEdge(); + ~GraphEdge(){delete m_convexHull;}; + private: + long m_name; + long m_v1; + long m_v2; + std::map m_distPoints; + Real m_error; + double m_surf; + double m_volume; + double m_perimeter; + double m_concavity; + ICHull * m_convexHull; + std::set m_boudaryEdges; + bool m_deleted; + + + + friend class GraphVertex; + friend class Graph; + friend class HACD; + }; + + class Graph + { + public: + size_t GetNEdges() const { return m_nE;} + size_t GetNVertices() const { return m_nV;} + bool EdgeCollapse(long v1, long v2); + long AddVertex(); + long AddEdge(long v1, long v2); + bool DeleteEdge(long name); + bool DeleteVertex(long name); + long GetEdgeID(long v1, long v2) const; + void Clear(); + void Print() const; + long ExtractCCs(); + + Graph(); + virtual ~Graph(); + void Allocate(size_t nV, size_t nE); + + private: + size_t m_nCCs; + size_t m_nV; + size_t m_nE; + std::vector m_edges; + std::vector m_vertices; + + friend class HACD; + }; +} +#endif diff --git a/Extras/HACD/hacdHACD.cpp b/Extras/HACD/hacdHACD.cpp new file mode 100644 index 0000000000..879f7921e4 --- /dev/null +++ b/Extras/HACD/hacdHACD.cpp @@ -0,0 +1,847 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS +#endif //_CRT_SECURE_NO_WARNINGS + +#include +#include "hacdGraph.h" +#include "hacdHACD.h" +#include "hacdICHull.h" +#include +#include +#include +#include + +bool gCancelRequest=false; +namespace HACD +{ + double HACD::Concavity(ICHull & ch, std::map & distPoints) + { + double concavity = 0.0; + double distance = 0.0; + std::map::iterator itDP(distPoints.begin()); + std::map::iterator itDPEnd(distPoints.end()); + for(; itDP != itDPEnd; ++itDP) + { + if (!(itDP->second).m_computed) + { + if (itDP->first >= 0) + { + distance = ch.ComputeDistance(itDP->first, m_points[itDP->first], m_normals[itDP->first], (itDP->second).m_computed, true); + } + else + { + distance = ch.ComputeDistance(itDP->first, m_facePoints[-itDP->first-1], m_faceNormals[-itDP->first-1], (itDP->second).m_computed, true); + } + } + else + { + distance = (itDP->second).m_dist; + } + if (concavity < distance) + { + concavity = distance; + } + } + return concavity; + } + + void HACD::CreateGraph() + { + // vertex to triangle adjacency information + std::vector< std::set > vertexToTriangles; + vertexToTriangles.resize(m_nPoints); + for(size_t t = 0; t < m_nTriangles; ++t) + { + vertexToTriangles[m_triangles[t].X()].insert(static_cast(t)); + vertexToTriangles[m_triangles[t].Y()].insert(static_cast(t)); + vertexToTriangles[m_triangles[t].Z()].insert(static_cast(t)); + } + + m_graph.Clear(); + m_graph.Allocate(m_nTriangles, 5 * m_nTriangles); + unsigned long long tr1[3]; + unsigned long long tr2[3]; + long i1, j1, k1, i2, j2, k2; + long t1, t2; + for (size_t v = 0; v < m_nPoints; v++) + { + std::set::const_iterator it1(vertexToTriangles[v].begin()), itEnd(vertexToTriangles[v].end()); + for(; it1 != itEnd; ++it1) + { + t1 = *it1; + i1 = m_triangles[t1].X(); + j1 = m_triangles[t1].Y(); + k1 = m_triangles[t1].Z(); + tr1[0] = GetEdgeIndex(i1, j1); + tr1[1] = GetEdgeIndex(j1, k1); + tr1[2] = GetEdgeIndex(k1, i1); + std::set::const_iterator it2(it1); + for(++it2; it2 != itEnd; ++it2) + { + t2 = *it2; + i2 = m_triangles[t2].X(); + j2 = m_triangles[t2].Y(); + k2 = m_triangles[t2].Z(); + tr2[0] = GetEdgeIndex(i2, j2); + tr2[1] = GetEdgeIndex(j2, k2); + tr2[2] = GetEdgeIndex(k2, i2); + int shared = 0; + for(int i = 0; i < 3; ++i) + { + for(int j = 0; j < 3; ++j) + { + if (tr1[i] == tr2[j]) + { + shared++; + } + } + } + if (shared == 1) // two triangles are connected if they share exactly one edge + { + m_graph.AddEdge(t1, t2); + } + } + } + } + if (m_ccConnectDist >= 0.0) + { + m_graph.ExtractCCs(); + if (m_graph.m_nCCs > 1) + { + std::vector< std::set > cc2V; + cc2V.resize(m_graph.m_nCCs); + long cc; + for(size_t t = 0; t < m_nTriangles; ++t) + { + cc = m_graph.m_vertices[t].m_cc; + cc2V[cc].insert(m_triangles[t].X()); + cc2V[cc].insert(m_triangles[t].Y()); + cc2V[cc].insert(m_triangles[t].Z()); + } + + for(size_t cc1 = 0; cc1 < m_graph.m_nCCs; ++cc1) + { + for(size_t cc2 = cc1+1; cc2 < m_graph.m_nCCs; ++cc2) + { + std::set::const_iterator itV1(cc2V[cc1].begin()), itVEnd1(cc2V[cc1].end()); + for(; itV1 != itVEnd1; ++itV1) + { + double distC1C2 = std::numeric_limits::max(); + double dist; + t1 = -1; + t2 = -1; + std::set::const_iterator itV2(cc2V[cc2].begin()), itVEnd2(cc2V[cc2].end()); + for(; itV2 != itVEnd2; ++itV2) + { + dist = (m_points[*itV1] - m_points[*itV2]).GetNorm(); + if (dist < distC1C2) + { + distC1C2 = dist; + t1 = *vertexToTriangles[*itV1].begin(); + + std::set::const_iterator it2(vertexToTriangles[*itV2].begin()), + it2End(vertexToTriangles[*itV2].end()); + t2 = -1; + for(; it2 != it2End; ++it2) + { + if (*it2 != t1) + { + t2 = *it2; + break; + } + } + } + } + if (distC1C2 <= m_ccConnectDist && t1 > 0 && t2 > 0) + { + + m_graph.AddEdge(t1, t2); + } + } + } + } + } + } + } + void HACD::InitializeDualGraph() + { + long i, j, k; + Vec3 u, v, w, normal; + delete [] m_normals; + m_normals = new Vec3[m_nPoints]; + if (m_addFacesPoints) + { + delete [] m_facePoints; + delete [] m_faceNormals; + m_facePoints = new Vec3[m_nTriangles]; + m_faceNormals = new Vec3[m_nTriangles]; + } + memset(m_normals, 0, sizeof(Vec3) * m_nPoints); + for(unsigned long f = 0; f < m_nTriangles; f++) + { + if (m_callBack) (*m_callBack)("+ InitializeDualGraph\n", f, m_nTriangles, 0); + + if (gCancelRequest) + return; + + i = m_triangles[f].X(); + j = m_triangles[f].Y(); + k = m_triangles[f].Z(); + + m_graph.m_vertices[f].m_distPoints[i].m_distOnly = false; + m_graph.m_vertices[f].m_distPoints[j].m_distOnly = false; + m_graph.m_vertices[f].m_distPoints[k].m_distOnly = false; + + ICHull * ch = new ICHull; + m_graph.m_vertices[f].m_convexHull = ch; + ch->AddPoint(m_points[i], i); + ch->AddPoint(m_points[j], j); + ch->AddPoint(m_points[k], k); + ch->SetDistPoints(&m_graph.m_vertices[f].m_distPoints); + + u = m_points[j] - m_points[i]; + v = m_points[k] - m_points[i]; + w = m_points[k] - m_points[j]; + normal = u ^ v; + + m_normals[i] += normal; + m_normals[j] += normal; + m_normals[k] += normal; + + m_graph.m_vertices[f].m_surf = normal.GetNorm(); + m_graph.m_vertices[f].m_perimeter = u.GetNorm() + v.GetNorm() + w.GetNorm(); + + normal.Normalize(); + + m_graph.m_vertices[f].m_boudaryEdges.insert(GetEdgeIndex(i,j)); + m_graph.m_vertices[f].m_boudaryEdges.insert(GetEdgeIndex(j,k)); + m_graph.m_vertices[f].m_boudaryEdges.insert(GetEdgeIndex(k,i)); + if(m_addFacesPoints) + { + m_faceNormals[f] = normal; + m_facePoints[f] = (m_points[i] + m_points[j] + m_points[k]) / 3.0; + m_graph.m_vertices[f].m_distPoints[-static_cast(f)-1].m_distOnly = true; + } + if (m_addExtraDistPoints) + {// we need a kd-tree structure to accelerate this part! + long i1, j1, k1; + Vec3 u1, v1, normal1; + normal = -normal; + double distance = 0.0; + double distMin = 0.0; + size_t faceIndex = m_nTriangles; + Vec3 seedPoint((m_points[i] + m_points[j] + m_points[k]) / 3.0); + long nhit = 0; + for(size_t f1 = 0; f1 < m_nTriangles; f1++) + { + i1 = m_triangles[f1].X(); + j1 = m_triangles[f1].Y(); + k1 = m_triangles[f1].Z(); + u1 = m_points[j1] - m_points[i1]; + v1 = m_points[k1] - m_points[i1]; + normal1 = (u1 ^ v1); + if (normal * normal1 > 0.0) + { + nhit = IntersectRayTriangle(Vec3(seedPoint.X(), seedPoint.Y(), seedPoint.Z()), + Vec3(normal.X(), normal.Y(), normal.Z()), + Vec3(m_points[i1].X(), m_points[i1].Y(), m_points[i1].Z()), + Vec3(m_points[j1].X(), m_points[j1].Y(), m_points[j1].Z()), + Vec3(m_points[k1].X(), m_points[k1].Y(), m_points[k1].Z()), + distance); + if ((nhit==1) && ((distMin > distance) || (faceIndex == m_nTriangles))) + { + distMin = distance; + faceIndex = f1; + } + + } + } + if (faceIndex < m_nTriangles ) + { + i1 = m_triangles[faceIndex].X(); + j1 = m_triangles[faceIndex].Y(); + k1 = m_triangles[faceIndex].Z(); + m_graph.m_vertices[f].m_distPoints[i1].m_distOnly = true; + m_graph.m_vertices[f].m_distPoints[j1].m_distOnly = true; + m_graph.m_vertices[f].m_distPoints[k1].m_distOnly = true; + if (m_addFacesPoints) + { + m_graph.m_vertices[f].m_distPoints[-static_cast(faceIndex)-1].m_distOnly = true; + } + } + } + } + for (size_t v = 0; v < m_nPoints; v++) + { + m_normals[v].Normalize(); + } + } + + void HACD::NormalizeData() + { + if (m_nPoints == 0) + { + return; + } + m_barycenter = m_points[0]; + Vec3 min = m_points[0]; + Vec3 max = m_points[0]; + Real x, y, z; + for (size_t v = 1; v < m_nPoints ; v++) + { + m_barycenter += m_points[v]; + x = m_points[v].X(); + y = m_points[v].Y(); + z = m_points[v].Z(); + if ( x < min.X()) min.X() = x; + else if ( x > max.X()) max.X() = x; + if ( y < min.Y()) min.Y() = y; + else if ( y > max.Y()) max.Y() = y; + if ( z < min.Z()) min.Z() = z; + else if ( z > max.Z()) max.Z() = z; + } + m_barycenter /= static_cast(m_nPoints); + m_diag = (max-min).GetNorm(); + const Real invDiag = static_cast(2.0 * m_scale / m_diag); + if (m_diag != 0.0) + { + for (size_t v = 0; v < m_nPoints ; v++) + { + m_points[v] = (m_points[v] - m_barycenter) * invDiag; + } + } + } + void HACD::DenormalizeData() + { + if (m_nPoints == 0) + { + return; + } + if (m_diag != 0.0) + { + const Real diag = static_cast(m_diag / (2.0 * m_scale)); + for (size_t v = 0; v < m_nPoints ; v++) + { + m_points[v] = m_points[v] * diag + m_barycenter; + } + } + } + HACD::HACD(void) + { + m_convexHulls = 0; + m_triangles = 0; + m_points = 0; + m_normals = 0; + m_nTriangles = 0; + m_nPoints = 0; + m_nClusters = 0; + m_concavity = 0.0; + m_diag = 1.0; + m_barycenter = Vec3(0.0, 0.0,0.0); + m_alpha = 0.1; + m_beta = 0.1; + m_nVerticesPerCH = 30; + m_callBack = 0; + m_addExtraDistPoints = false; + m_addNeighboursDistPoints = false; + m_scale = 1000.0; + m_partition = 0; + m_nMinClusters = 3; + m_facePoints = 0; + m_faceNormals = 0; + m_ccConnectDist = 30; + } + HACD::~HACD(void) + { + delete [] m_normals; + delete [] m_convexHulls; + delete [] m_partition; + delete [] m_facePoints; + delete [] m_faceNormals; + } + int iteration = 0; + void HACD::ComputeEdgeCost(size_t e) + { + GraphEdge & gE = m_graph.m_edges[e]; + long v1 = gE.m_v1; + long v2 = gE.m_v2; + + if (m_graph.m_vertices[v2].m_distPoints.size()>m_graph.m_vertices[v1].m_distPoints.size()) + { + gE.m_v1 = v2; + gE.m_v2 = v1; + //std::swap(v1, v2); + std::swap(v1, v2); + } + GraphVertex & gV1 = m_graph.m_vertices[v1]; + GraphVertex & gV2 = m_graph.m_vertices[v2]; + + // delete old convex-hull + delete gE.m_convexHull; + // create the edge's convex-hull + ICHull * ch = new ICHull; + gE.m_convexHull = ch; + (*ch) = (*gV1.m_convexHull); + + // update distPoints + gE.m_distPoints = gV1.m_distPoints; + std::map::iterator itDP(gV2.m_distPoints.begin()); + std::map::iterator itDPEnd(gV2.m_distPoints.end()); + std::map::iterator itDP1; + + for(; itDP != itDPEnd; ++itDP) + { + itDP1 = gE.m_distPoints.find(itDP->first); + if (itDP1 == gE.m_distPoints.end()) + { + gE.m_distPoints[itDP->first].m_distOnly = (itDP->second).m_distOnly; + if ( !(itDP->second).m_distOnly ) + { + ch->AddPoint(m_points[itDP->first], itDP->first); + } + } + else + { + if ( (itDP1->second).m_distOnly && !(itDP->second).m_distOnly) + { + gE.m_distPoints[itDP->first].m_distOnly = false; + ch->AddPoint(m_points[itDP->first], itDP->first); + } + } + } + + ch->SetDistPoints(&gE.m_distPoints); + // create the convex-hull + while (ch->Process() == ICHullErrorInconsistent) // if we face problems when constructing the visual-hull. really ugly!!!! + { +// if (m_callBack) (*m_callBack)("\t Problem with convex-hull construction [HACD::ComputeEdgeCost]\n", 0.0, 0.0, 0); + ch = new ICHull; + CircularList & verticesCH = (gE.m_convexHull)->GetMesh().m_vertices; + size_t nV = verticesCH.GetSize(); + long ptIndex = 0; + verticesCH.Next(); + for(size_t v = 1; v < nV; ++v) + { + ptIndex = verticesCH.GetHead()->GetData().m_name; + ch->AddPoint(m_points[ptIndex], ptIndex); + verticesCH.Next(); + } + delete gE.m_convexHull; + gE.m_convexHull = ch; + } + double volume = 0.0; + double concavity = 0.0; + if (ch->IsFlat()) + { + bool insideHull; + std::map::iterator itDP(gE.m_distPoints.begin()); + std::map::iterator itDPEnd(gE.m_distPoints.end()); + for(; itDP != itDPEnd; ++itDP) + { + if (itDP->first >= 0) + { + concavity = std::max(concavity, ch->ComputeDistance(itDP->first, m_points[itDP->first], m_normals[itDP->first], insideHull, false)); + } + } + } + else + { + if (m_addNeighboursDistPoints) + { // add distance points from adjacent clusters + std::set eEdges; + std::set_union(gV1.m_edges.begin(), + gV1.m_edges.end(), + gV2.m_edges.begin(), + gV2.m_edges.end(), + std::inserter( eEdges, eEdges.begin() ) ); + + std::set::const_iterator ed(eEdges.begin()); + std::set::const_iterator itEnd(eEdges.end()); + long a, b, c; + for(; ed != itEnd; ++ed) + { + a = m_graph.m_edges[*ed].m_v1; + b = m_graph.m_edges[*ed].m_v2; + if ( a != v2 && a != v1) + { + c = a; + } + else if ( b != v2 && b != v1) + { + c = b; + } + else + { + c = -1; + } + if ( c > 0) + { + GraphVertex & gVC = m_graph.m_vertices[c]; + std::map::iterator itDP(gVC.m_distPoints.begin()); + std::map::iterator itDPEnd(gVC.m_distPoints.end()); + std::map::iterator itDP1; + for(; itDP != itDPEnd; ++itDP) + { + itDP1 = gE.m_distPoints.find(itDP->first); + if (itDP1 == gE.m_distPoints.end()) + { + if (itDP->first >= 0 && itDP1 == gE.m_distPoints.end() && ch->IsInside(m_points[itDP->first])) + { + gE.m_distPoints[itDP->first].m_distOnly = true; + } + else if (itDP->first < 0 && ch->IsInside(m_facePoints[-itDP->first-1])) + { + gE.m_distPoints[itDP->first].m_distOnly = true; + } + } + } + } + } + } + concavity = Concavity(*ch, gE.m_distPoints); + } + + // compute boudary edges + double perimeter = 0.0; + double surf = 1.0; + if (m_alpha > 0.0) + { + gE.m_boudaryEdges.clear(); + std::set_symmetric_difference (gV1.m_boudaryEdges.begin(), + gV1.m_boudaryEdges.end(), + gV2.m_boudaryEdges.begin(), + gV2.m_boudaryEdges.end(), + std::inserter( gE.m_boudaryEdges, + gE.m_boudaryEdges.begin() ) ); + + std::set::const_iterator itBE(gE.m_boudaryEdges.begin()); + std::set::const_iterator itBEEnd(gE.m_boudaryEdges.end()); + for(; itBE != itBEEnd; ++itBE) + { + perimeter += (m_points[static_cast((*itBE) >> 32)] - + m_points[static_cast((*itBE) & 0xFFFFFFFFULL)]).GetNorm(); + } + surf = gV1.m_surf + gV2.m_surf; + } + double ratio = perimeter * perimeter / (4.0 * sc_pi * surf); + gE.m_volume = (m_beta == 0.0)?0.0:ch->ComputeVolume()/pow(m_scale, 3.0); // cluster's volume + gE.m_surf = surf; // cluster's area + gE.m_perimeter = perimeter; // cluster's perimeter + gE.m_concavity = concavity; // cluster's concavity + gE.m_error = static_cast(concavity + m_alpha * ratio + m_beta * volume); // cluster's priority + } + bool HACD::InitializePriorityQueue() + { + m_pqueue.reserve(m_graph.m_nE + 100); + for (size_t e=0; e < m_graph.m_nE; ++e) + { + ComputeEdgeCost(static_cast(e)); + m_pqueue.push(GraphEdgePriorityQueue(static_cast(e), m_graph.m_edges[e].m_error)); + } + return true; + } + void HACD::Simplify() + { + long v1 = -1; + long v2 = -1; + double progressOld = -1.0; + double progress = 0.0; + double globalConcavity = 0.0; + char msg[1024]; + double ptgStep = 1.0; + while ( (globalConcavity < m_concavity) && + (m_graph.GetNVertices() > m_nMinClusters) && + (m_graph.GetNEdges() > 0)) + { + progress = 100.0-m_graph.GetNVertices() * 100.0 / m_nTriangles; + if (fabs(progress-progressOld) > ptgStep && m_callBack) + { + sprintf(msg, "%3.2f %% V = %lu \t C = %f \t \t \r", progress, static_cast(m_graph.GetNVertices()), globalConcavity); + (*m_callBack)(msg, progress, globalConcavity, m_graph.GetNVertices()); + progressOld = progress; + if (progress > 99.0) + { + ptgStep = 0.01; + } + else if (progress > 90.0) + { + ptgStep = 0.1; + } + } + + GraphEdgePriorityQueue currentEdge(0,0.0); + bool done = false; + do + { + done = false; + if (m_pqueue.size() == 0) + { + done = true; + break; + } + currentEdge = m_pqueue.top(); + m_pqueue.pop(); + } + while ( m_graph.m_edges[currentEdge.m_name].m_deleted || + m_graph.m_edges[currentEdge.m_name].m_error != currentEdge.m_priority); + + + if (m_graph.m_edges[currentEdge.m_name].m_concavity < m_concavity && !done) + { + globalConcavity = std::max(globalConcavity ,m_graph.m_edges[currentEdge.m_name].m_concavity); + v1 = m_graph.m_edges[currentEdge.m_name].m_v1; + v2 = m_graph.m_edges[currentEdge.m_name].m_v2; + // update vertex info + m_graph.m_vertices[v1].m_error = m_graph.m_edges[currentEdge.m_name].m_error; + m_graph.m_vertices[v1].m_surf = m_graph.m_edges[currentEdge.m_name].m_surf; + m_graph.m_vertices[v1].m_volume = m_graph.m_edges[currentEdge.m_name].m_volume; + m_graph.m_vertices[v1].m_concavity = m_graph.m_edges[currentEdge.m_name].m_concavity; + m_graph.m_vertices[v1].m_perimeter = m_graph.m_edges[currentEdge.m_name].m_perimeter; + m_graph.m_vertices[v1].m_distPoints = m_graph.m_edges[currentEdge.m_name].m_distPoints; + (*m_graph.m_vertices[v1].m_convexHull) = (*m_graph.m_edges[currentEdge.m_name].m_convexHull); + (m_graph.m_vertices[v1].m_convexHull)->SetDistPoints(&(m_graph.m_vertices[v1].m_distPoints)); + m_graph.m_vertices[v1].m_boudaryEdges = m_graph.m_edges[currentEdge.m_name].m_boudaryEdges; + + // We apply the optimal ecol +// std::cout << "v1 " << v1 << " v2 " << v2 << std::endl; + m_graph.EdgeCollapse(v1, v2); + // recompute the adjacent edges costs + std::set::const_iterator itE(m_graph.m_vertices[v1].m_edges.begin()), + itEEnd(m_graph.m_vertices[v1].m_edges.end()); + for(; itE != itEEnd; ++itE) + { + size_t e = *itE; + ComputeEdgeCost(static_cast(e)); + m_pqueue.push(GraphEdgePriorityQueue(static_cast(e), m_graph.m_edges[e].m_error)); + } + } + else + { + break; + } + } + while (!m_pqueue.empty()) + { + m_pqueue.pop(); + } + + m_cVertices.clear(); + m_nClusters = m_graph.GetNVertices(); + m_cVertices.reserve(m_nClusters); + for (size_t p=0, v = 0; v != m_graph.m_vertices.size(); ++v) + { + if (!m_graph.m_vertices[v].m_deleted) + { + if (m_callBack) + { + char msg[1024]; + sprintf(msg, "\t CH \t %lu \t %lf \t %lf\n", static_cast(p), m_graph.m_vertices[v].m_concavity, m_graph.m_vertices[v].m_error); + (*m_callBack)(msg, 0.0, 0.0, m_nClusters); + p++; + } + m_cVertices.push_back(static_cast(v)); + } + } + if (m_callBack) + { + sprintf(msg, "# clusters = %lu \t C = %f\n", static_cast(m_nClusters), globalConcavity); + (*m_callBack)(msg, progress, globalConcavity, m_graph.GetNVertices()); + } + + } + + bool HACD::Compute(bool fullCH, bool exportDistPoints) + { + gCancelRequest = false; + + if ( !m_points || !m_triangles || !m_nPoints || !m_nTriangles) + { + return false; + } + size_t nV = m_nTriangles; + if (m_callBack) + { + std::ostringstream msg; + msg << "+ Mesh" << std::endl; + msg << "\t # vertices \t" << m_nPoints << std::endl; + msg << "\t # triangles \t" << m_nTriangles << std::endl; + msg << "+ Parameters" << std::endl; + msg << "\t min # of clusters \t" << m_nMinClusters << std::endl; + msg << "\t max concavity \t" << m_concavity << std::endl; + msg << "\t compacity weigth \t" << m_alpha << std::endl; + msg << "\t volume weigth \t" << m_beta << std::endl; + msg << "\t # vertices per convex-hull \t" << m_nVerticesPerCH << std::endl; + msg << "\t scale \t" << m_scale << std::endl; + msg << "\t add extra distance points \t" << m_addExtraDistPoints << std::endl; + msg << "\t add neighbours distance points \t" << m_addNeighboursDistPoints << std::endl; + msg << "\t add face distance points \t" << m_addFacesPoints << std::endl; + msg << "\t produce full convex-hulls \t" << fullCH << std::endl; + msg << "\t max. distance to connect CCs \t" << m_ccConnectDist << std::endl; + (*m_callBack)(msg.str().c_str(), 0.0, 0.0, nV); + } + if (m_callBack) (*m_callBack)("+ Normalizing Data\n", 0.0, 0.0, nV); + NormalizeData(); + if (m_callBack) (*m_callBack)("+ Creating Graph\n", 0.0, 0.0, nV); + CreateGraph(); + // Compute the surfaces and perimeters of all the faces + if (m_callBack) (*m_callBack)("+ Initializing Dual Graph\n", 0.0, 0.0, nV); + if (gCancelRequest) + return false; + + InitializeDualGraph(); + if (m_callBack) (*m_callBack)("+ Initializing Priority Queue\n", 0.0, 0.0, nV); + if (gCancelRequest) + return false; + + InitializePriorityQueue(); + // we simplify the graph + if (m_callBack) (*m_callBack)("+ Simplification ...\n", 0.0, 0.0, m_nTriangles); + Simplify(); + if (m_callBack) (*m_callBack)("+ Denormalizing Data\n", 0.0, 0.0, m_nClusters); + DenormalizeData(); + if (m_callBack) (*m_callBack)("+ Computing final convex-hulls\n", 0.0, 0.0, m_nClusters); + delete [] m_convexHulls; + m_convexHulls = new ICHull[m_nClusters]; + delete [] m_partition; + m_partition = new long [m_nTriangles]; + for (size_t p = 0; p != m_cVertices.size(); ++p) + { + size_t v = m_cVertices[p]; + m_partition[v] = static_cast(p); + for(size_t a = 0; a < m_graph.m_vertices[v].m_ancestors.size(); a++) + { + m_partition[m_graph.m_vertices[v].m_ancestors[a]] = static_cast(p); + } + // compute the convex-hull + const std::map & pointsCH = m_graph.m_vertices[v].m_distPoints; + std::map::const_iterator itCH(pointsCH.begin()); + std::map::const_iterator itCHEnd(pointsCH.end()); + for(; itCH != itCHEnd; ++itCH) + { + if (!(itCH->second).m_distOnly) + { + m_convexHulls[p].AddPoint(m_points[itCH->first], itCH->first); + } + } + m_convexHulls[p].SetDistPoints(&m_graph.m_vertices[v].m_distPoints); + if (fullCH) + { + m_convexHulls[p].Process(); + } + else + { + m_convexHulls[p].Process(static_cast(m_nVerticesPerCH)); + } + if (exportDistPoints) + { + itCH = pointsCH.begin(); + for(; itCH != itCHEnd; ++itCH) + { + if ((itCH->second).m_distOnly) + { + if (itCH->first >= 0) + { + m_convexHulls[p].AddPoint(m_points[itCH->first], itCH->first); + } + else + { + m_convexHulls[p].AddPoint(m_facePoints[-itCH->first-1], itCH->first); + } + } + } + } + } + return true; + } + + size_t HACD::GetNTrianglesCH(size_t numCH) const + { + if (numCH >= m_nClusters) + { + return 0; + } + return m_convexHulls[numCH].GetMesh().GetNTriangles(); + } + size_t HACD::GetNPointsCH(size_t numCH) const + { + if (numCH >= m_nClusters) + { + return 0; + } + return m_convexHulls[numCH].GetMesh().GetNVertices(); + } + + bool HACD::GetCH(size_t numCH, Vec3 * const points, Vec3 * const triangles) + { + if (numCH >= m_nClusters) + { + return false; + } + m_convexHulls[numCH].GetMesh().GetIFS(points, triangles); + return true; + } + + bool HACD::Save(const char * fileName, bool uniColor, long numCluster) const + { + std::ofstream fout(fileName); + if (fout.is_open()) + { + if (m_callBack) + { + char msg[1024]; + sprintf(msg, "Saving %s\n", fileName); + (*m_callBack)(msg, 0.0, 0.0, m_graph.GetNVertices()); + } + Material mat; + if (numCluster < 0) + { + for (size_t p = 0; p != m_nClusters; ++p) + { + if (!uniColor) + { + mat.m_diffuseColor.X() = mat.m_diffuseColor.Y() = mat.m_diffuseColor.Z() = 0.0; + while (mat.m_diffuseColor.X() == mat.m_diffuseColor.Y() || + mat.m_diffuseColor.Z() == mat.m_diffuseColor.Y() || + mat.m_diffuseColor.Z() == mat.m_diffuseColor.X() ) + { + mat.m_diffuseColor.X() = (rand()%100) / 100.0; + mat.m_diffuseColor.Y() = (rand()%100) / 100.0; + mat.m_diffuseColor.Z() = (rand()%100) / 100.0; + } + } + m_convexHulls[p].GetMesh().SaveVRML2(fout, mat); + } + } + else if (numCluster < static_cast(m_cVertices.size())) + { + m_convexHulls[numCluster].GetMesh().SaveVRML2(fout, mat); + } + fout.close(); + return true; + } + else + { + if (m_callBack) + { + char msg[1024]; + sprintf(msg, "Error saving %s\n", fileName); + (*m_callBack)(msg, 0.0, 0.0, m_graph.GetNVertices()); + } + return false; + } + } +} diff --git a/Extras/HACD/hacdHACD.h b/Extras/HACD/hacdHACD.h new file mode 100644 index 0000000000..9c496f4e59 --- /dev/null +++ b/Extras/HACD/hacdHACD.h @@ -0,0 +1,282 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once +#ifndef HACD_HACD_H +#define HACD_HACD_H +#include "hacdVersion.h" +#include "hacdVector.h" +#include "hacdGraph.h" +#include "hacdICHull.h" +#include +#include +#include +#include + +namespace HACD +{ + const double sc_pi = 3.14159265; + class HACD; + + // just to be able to set the capcity of the container + + template, class _Pr = std::less > + class reservable_priority_queue: public std::priority_queue<_Ty, _Container, _Pr> + { + typedef typename std::priority_queue<_Ty, _Container, _Pr>::size_type size_type; + public: + reservable_priority_queue(size_type capacity = 0) { reserve(capacity); }; + void reserve(size_type capacity) { this->c.reserve(capacity); } + size_type capacity() const { return this->c.capacity(); } + }; + + //! priority queque element + class GraphEdgePriorityQueue + { + public: + //! Constructor + //! @param name edge's id + //! @param priority edge's priority + GraphEdgePriorityQueue(long name, Real priority) + { + m_name = name; + m_priority = priority; + } + //! Destructor + ~GraphEdgePriorityQueue(void){} + private: + long m_name; //!< edge name + Real m_priority; //!< priority + //! Operator < for GraphEdgePQ + friend bool operator<(const GraphEdgePriorityQueue & lhs, const GraphEdgePriorityQueue & rhs); + //! Operator > for GraphEdgePQ + friend bool operator>(const GraphEdgePriorityQueue & lhs, const GraphEdgePriorityQueue & rhs); + friend class HACD; + }; + inline bool operator<(const GraphEdgePriorityQueue & lhs, const GraphEdgePriorityQueue & rhs) + { + return lhs.m_priority(const GraphEdgePriorityQueue & lhs, const GraphEdgePriorityQueue & rhs) + { + return lhs.m_priority>rhs.m_priority; + } + typedef bool (*CallBackFunction)(const char *, double, double, size_t); + + //! Provides an implementation of the Hierarchical Approximate Convex Decomposition (HACD) technique described in "A Simple and Efficient Approach for 3D Mesh Approximate Convex Decomposition" Game Programming Gems 8 - Chapter 2.8, p.202. A short version of the chapter was published in ICIP09 and is available at ftp://ftp.elet.polimi.it/users/Stefano.Tubaro/ICIP_USB_Proceedings_v2/pdfs/0003501.pdf + class HACD + { + public: + + //! Gives the triangles partitionas an array of size m_nTriangles where the i-th element specifies the cluster to which belong the i-th triangle + //! @return triangles partition + const long * const GetPartition() const { return m_partition;} + //! Sets the scale factor + //! @param scale scale factor + void SetScaleFactor(double scale) { m_scale = scale;} + //! Gives the scale factor + //! @return scale factor + const double GetScaleFactor() const { return m_scale;} + //! Sets the call-back function + //! @param callBack pointer to the call-back function + void SetCallBack(CallBackFunction callBack) { m_callBack = callBack;} + //! Gives the call-back function + //! @return pointer to the call-back function + const CallBackFunction GetCallBack() const { return m_callBack;} + + //! Specifies whether faces points should be added when computing the concavity + //! @param addFacesPoints true = faces points should be added + void SetAddFacesPoints(bool addFacesPoints) { m_addFacesPoints = addFacesPoints;} + //! Specifies wheter faces points should be added when computing the concavity + //! @return true = faces points should be added + const bool GetAddFacesPoints() const { return m_addFacesPoints;} + //! Specifies whether extra points should be added when computing the concavity + //! @param addExteraDistPoints true = extra points should be added + void SetAddExtraDistPoints(bool addExtraDistPoints) { m_addExtraDistPoints = addExtraDistPoints;} + //! Specifies wheter extra points should be added when computing the concavity + //! @return true = extra points should be added + const bool GetAddExtraDistPoints() const { return m_addExtraDistPoints;} + //! Specifies whether extra points should be added when computing the concavity + //! @param addExteraDistPoints true = extra points should be added + void SetAddNeighboursDistPoints(bool addNeighboursDistPoints) { m_addNeighboursDistPoints = addNeighboursDistPoints;} + //! Specifies wheter extra points should be added when computing the concavity + //! @return true = extra points should be added + const bool GetAddNeighboursDistPoints() const { return m_addNeighboursDistPoints;} + //! Sets the points of the input mesh (Remark: the input points will be scaled and shifted. Use DenormalizeData() to invert those operations) + //! @param points pointer to the input points + void SetPoints(Vec3 * points) { m_points = points;} + //! Gives the points of the input mesh (Remark: the input points will be scaled and shifted. Use DenormalizeData() to invert those operations) + //! @return pointer to the input points + const Vec3 * GetPoints() const { return m_points;} + //! Sets the triangles of the input mesh. + //! @param triangles points pointer to the input points + void SetTriangles(Vec3 * triangles) { m_triangles = triangles;} + //! Gives the triangles in the input mesh + //! @return pointer to the input triangles + const Vec3 * GetTriangles() const { return m_triangles;} + //! Sets the number of points in the input mesh. + //! @param nPoints number of points the input mesh + void SetNPoints(size_t nPoints) { m_nPoints = nPoints;} + //! Gives the number of points in the input mesh. + //! @return number of points the input mesh + const size_t GetNPoints() const { return m_nPoints;} + //! Sets the number of triangles in the input mesh. + //! @param nTriangles number of triangles in the input mesh + void SetNTriangles(size_t nTriangles) { m_nTriangles = nTriangles;} + //! Gives the number of triangles in the input mesh. + //! @return number of triangles the input mesh + const size_t GetNTriangles() const { return m_nTriangles;} + //! Sets the minimum number of clusters to be generated. + //! @param nClusters minimum number of clusters + void SetNClusters(size_t nClusters) { m_nMinClusters = nClusters;} + //! Gives the number of generated clusters. + //! @return number of generated clusters + const size_t GetNClusters() const { return m_nClusters;} + //! Sets the maximum allowed concavity. + //! @param concavity maximum concavity + void SetConcavity(double concavity) { m_concavity = concavity;} + //! Gives the maximum allowed concavity. + //! @return maximum concavity + double GetConcavity() const { return m_concavity;} + //! Sets the maximum allowed distance to get CCs connected. + //! @param concavity maximum distance to get CCs connected + void SetConnectDist(double ccConnectDist) { m_ccConnectDist = ccConnectDist;} + //! Gives the maximum allowed distance to get CCs connected. + //! @return maximum distance to get CCs connected + double GetConnectDist() const { return m_ccConnectDist;} + //! Sets the volume weight. + //! @param beta volume weight + void SetVolumeWeight(double beta) { m_beta = beta;} + //! Gives the volume weight. + //! @return volume weight + double GetVolumeWeight() const { return m_beta;} + //! Sets the compacity weight (i.e. parameter alpha in ftp://ftp.elet.polimi.it/users/Stefano.Tubaro/ICIP_USB_Proceedings_v2/pdfs/0003501.pdf). + //! @param alpha compacity weight + void SetCompacityWeight(double alpha) { m_alpha = alpha;} + //! Gives the compacity weight (i.e. parameter alpha in ftp://ftp.elet.polimi.it/users/Stefano.Tubaro/ICIP_USB_Proceedings_v2/pdfs/0003501.pdf). + //! @return compacity weight + double GetCompacityWeight() const { return m_alpha;} + //! Sets the maximum number of vertices for each generated convex-hull. + //! @param nVerticesPerCH maximum # vertices per CH + void SetNVerticesPerCH(size_t nVerticesPerCH) { m_nVerticesPerCH = nVerticesPerCH;} + //! Gives the maximum number of vertices for each generated convex-hull. + //! @return maximum # vertices per CH + const size_t GetNVerticesPerCH() const { return m_nVerticesPerCH;} + //! Gives the number of vertices for the cluster number numCH. + //! @return number of vertices + size_t GetNPointsCH(size_t numCH) const; + //! Gives the number of triangles for the cluster number numCH. + //! @param numCH cluster's number + //! @return number of triangles + size_t GetNTrianglesCH(size_t numCH) const; + //! Gives the vertices and the triangles of the cluster number numCH. + //! @param numCH cluster's number + //! @param points pointer to the vector of points to be filled + //! @param triangles pointer to the vector of triangles to be filled + //! @return true if sucess + bool GetCH(size_t numCH, Vec3 * const points, Vec3 * const triangles); + //! Computes the HACD decomposition. + //! @param fullCH specifies whether to generate convex-hulls with a full or limited (i.e. < m_nVerticesPerCH) number of vertices + //! @param exportDistPoints specifies wheter distance points should ne exported or not (used only for debugging). + //! @return true if sucess + bool Compute(bool fullCH=false, bool exportDistPoints=false); + //! Saves the generated convex-hulls in a VRML 2.0 file. + //! @param fileName the output file name + //! @param uniColor specifies whether the different convex-hulls should have the same color or not + //! @param numCluster specifies the cluster to be saved, if numCluster < 0 export all clusters + //! @return true if sucess + bool Save(const char * fileName, bool uniColor, long numCluster=-1) const; + //! Shifts and scales to the data to have all the coordinates between 0.0 and 1000.0. + void NormalizeData(); + //! Inverse the operations applied by NormalizeData(). + void DenormalizeData(); + //! Constructor. + HACD(void); + //! Destructor. + ~HACD(void); + + private: + //! Gives the edge index. + //! @param a first vertex id + //! @param b second vertex id + //! @return edge's index + static unsigned long long GetEdgeIndex(unsigned long long a, unsigned long long b) + { + if (a > b) return (a << 32) + b; + else return (b << 32) + a; + } + //! Computes the concavity of a cluster. + //! @param ch the cluster's convex-hull + //! @param distPoints the cluster's points + //! @return cluster's concavity + double Concavity(ICHull & ch, std::map & distPoints); + //! Computes the perimeter of a cluster. + //! @param triIndices the cluster's triangles + //! @param distPoints the cluster's points + //! @return cluster's perimeter + double ComputePerimeter(const std::vector & triIndices) const; + //! Creates the Graph by associating to each mesh triangle a vertex in the graph and to each couple of adjacent triangles an edge in the graph. + void CreateGraph(); + //! Initializes the graph costs and computes the vertices normals + void InitializeDualGraph(); + //! Computes the cost of an edge + //! @param e edge's id + void ComputeEdgeCost(size_t e); + //! Initializes the priority queue + //! @param fast specifies whether fast mode is used + //! @return true if success + bool InitializePriorityQueue(); + //! Cleans the intersection between convex-hulls + void CleanClusters(); + //! Computes convex-hulls from partition information + //! @param fullCH specifies whether to generate convex-hulls with a full or limited (i.e. < m_nVerticesPerCH) number of vertices + void ComputeConvexHulls(bool fullCH); + //! Simplifies the graph + //! @param fast specifies whether fast mode is used + void Simplify(); + + private: + double m_scale; //>! scale factor used for NormalizeData() and DenormalizeData() + Vec3 * m_triangles; //>! pointer the triangles array + Vec3 * m_points; //>! pointer the points array + Vec3 * m_facePoints; //>! pointer to the faces points array + Vec3 * m_faceNormals; //>! pointer to the faces normals array + Vec3 * m_normals; //>! pointer the normals array + size_t m_nTriangles; //>! number of triangles in the original mesh + size_t m_nPoints; //>! number of vertices in the original mesh + size_t m_nClusters; //>! number of clusters + size_t m_nMinClusters; //>! minimum number of clusters + double m_ccConnectDist; //>! maximum allowed distance to connect CCs + double m_concavity; //>! maximum concavity + double m_alpha; //>! compacity weigth + double m_beta; //>! volume weigth + double m_diag; //>! length of the BB diagonal + Vec3 m_barycenter; //>! barycenter of the mesh + std::vector< long > m_cVertices; //>! array of vertices each belonging to a different cluster + ICHull * m_convexHulls; //>! convex-hulls associated with the final HACD clusters + Graph m_graph; //>! simplification graph + size_t m_nVerticesPerCH; //>! maximum number of vertices per convex-hull + reservable_priority_queue, + std::greater::value_type> > m_pqueue; //!> priority queue + HACD(const HACD & rhs); + CallBackFunction m_callBack; //>! call-back function + long * m_partition; //>! array of size m_nTriangles where the i-th element specifies the cluster to which belong the i-th triangle + bool m_addFacesPoints; //>! specifies whether to add faces points or not + bool m_addExtraDistPoints; //>! specifies whether to add extra points for concave shapes or not + bool m_addNeighboursDistPoints; //>! specifies whether to add extra points from adjacent clusters or not + + }; +} +#endif diff --git a/Extras/HACD/hacdICHull.cpp b/Extras/HACD/hacdICHull.cpp new file mode 100644 index 0000000000..4f99c4d64a --- /dev/null +++ b/Extras/HACD/hacdICHull.cpp @@ -0,0 +1,1010 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "hacdICHull.h" +#include +namespace HACD +{ + const long ICHull::sc_dummyIndex = std::numeric_limits::max(); + ICHull::ICHull(void) + { + m_distPoints = 0; + m_isFlat = false; + m_dummyVertex = 0; + } + bool ICHull::AddPoints(const Vec3 * points, size_t nPoints) + { + if (!points) + { + return false; + } + CircularListElement * vertex = NULL; + for (size_t i = 0; i < nPoints; i++) + { + vertex = m_mesh.AddVertex(); + vertex->GetData().m_pos.X() = points[i].X(); + vertex->GetData().m_pos.Y() = points[i].Y(); + vertex->GetData().m_pos.Z() = points[i].Z(); + vertex->GetData().m_name = static_cast(i); + } + return true; + } + bool ICHull::AddPoints(std::vector< Vec3 > points) + { + CircularListElement * vertex = NULL; + for (size_t i = 0; i < points.size(); i++) + { + vertex = m_mesh.AddVertex(); + vertex->GetData().m_pos.X() = points[i].X(); + vertex->GetData().m_pos.Y() = points[i].Y(); + vertex->GetData().m_pos.Z() = points[i].Z(); + } + return true; + } + + bool ICHull::AddPoint(const Vec3 & point, long id) + { + if (AddPoints(&point, 1)) + { + m_mesh.m_vertices.GetData().m_name = id; + return true; + } + return false; + } + + ICHullError ICHull::Process() + { + unsigned long addedPoints = 0; + if (m_mesh.GetNVertices() < 3) + { + return ICHullErrorNotEnoughPoints; + } + if (m_mesh.GetNVertices() == 3) + { + m_isFlat = true; + CircularListElement * t1 = m_mesh.AddTriangle(); + CircularListElement * t2 = m_mesh.AddTriangle(); + CircularListElement * v0 = m_mesh.m_vertices.GetHead(); + CircularListElement * v1 = v0->GetNext(); + CircularListElement * v2 = v1->GetNext(); + // Compute the normal to the plane + Vec3 p0 = v0->GetData().m_pos; + Vec3 p1 = v1->GetData().m_pos; + Vec3 p2 = v2->GetData().m_pos; + m_normal = (p1-p0) ^ (p2-p0); + m_normal.Normalize(); + t1->GetData().m_vertices[0] = v0; + t1->GetData().m_vertices[1] = v1; + t1->GetData().m_vertices[2] = v2; + t2->GetData().m_vertices[0] = v1; + t2->GetData().m_vertices[1] = v2; + t2->GetData().m_vertices[2] = v2; + return ICHullErrorOK; + } + if (m_isFlat) + { + m_mesh.m_edges.Clear(); + m_mesh.m_triangles.Clear(); + m_isFlat = false; + } + if (m_mesh.GetNTriangles() == 0) // we have to create the first polyhedron + { + ICHullError res = DoubleTriangle(); + if (res != ICHullErrorOK) + { + return res; + } + else + { + addedPoints += 3; + } + } + CircularList & vertices = m_mesh.GetVertices(); + // go to the first added and not processed vertex + while (!(vertices.GetHead()->GetPrev()->GetData().m_tag)) + { + vertices.Prev(); + } + while (!vertices.GetData().m_tag) // not processed + { + vertices.GetData().m_tag = true; + if (ProcessPoint()) + { + addedPoints++; + CleanUp(addedPoints); + vertices.Next(); + if (!GetMesh().CheckConsistancy()) + { + return ICHullErrorInconsistent; + } + } + } + if (m_isFlat) + { + std::vector< CircularListElement * > trianglesToDuplicate; + size_t nT = m_mesh.GetNTriangles(); + for(size_t f = 0; f < nT; f++) + { + TMMTriangle & currentTriangle = m_mesh.m_triangles.GetHead()->GetData(); + if( currentTriangle.m_vertices[0]->GetData().m_name == sc_dummyIndex || + currentTriangle.m_vertices[1]->GetData().m_name == sc_dummyIndex || + currentTriangle.m_vertices[2]->GetData().m_name == sc_dummyIndex ) + { + m_trianglesToDelete.push_back(m_mesh.m_triangles.GetHead()); + for(int k = 0; k < 3; k++) + { + for(int h = 0; h < 2; h++) + { + if (currentTriangle.m_edges[k]->GetData().m_triangles[h] == m_mesh.m_triangles.GetHead()) + { + currentTriangle.m_edges[k]->GetData().m_triangles[h] = 0; + break; + } + } + } + } + else + { + trianglesToDuplicate.push_back(m_mesh.m_triangles.GetHead()); + } + m_mesh.m_triangles.Next(); + } + size_t nE = m_mesh.GetNEdges(); + for(size_t e = 0; e < nE; e++) + { + TMMEdge & currentEdge = m_mesh.m_edges.GetHead()->GetData(); + if( currentEdge.m_triangles[0] == 0 && currentEdge.m_triangles[1] == 0) + { + m_edgesToDelete.push_back(m_mesh.m_edges.GetHead()); + } + m_mesh.m_edges.Next(); + } + m_mesh.m_vertices.Delete(m_dummyVertex); + m_dummyVertex = 0; + size_t nV = m_mesh.GetNVertices(); + CircularList & vertices = m_mesh.GetVertices(); + for(size_t v = 0; v < nV; ++v) + { + vertices.GetData().m_tag = false; + vertices.Next(); + } + CleanEdges(); + CleanTriangles(); + CircularListElement * newTriangle; + for(size_t t = 0; t < trianglesToDuplicate.size(); t++) + { + newTriangle = m_mesh.AddTriangle(); + newTriangle->GetData().m_vertices[0] = trianglesToDuplicate[t]->GetData().m_vertices[1]; + newTriangle->GetData().m_vertices[1] = trianglesToDuplicate[t]->GetData().m_vertices[0]; + newTriangle->GetData().m_vertices[2] = trianglesToDuplicate[t]->GetData().m_vertices[2]; + } + } + return ICHullErrorOK; + } + ICHullError ICHull::Process(unsigned long nPointsCH) + { + unsigned long addedPoints = 0; + if (nPointsCH < 3 || m_mesh.GetNVertices() < 3) + { + return ICHullErrorNotEnoughPoints; + } + if (m_mesh.GetNVertices() == 3) + { + m_isFlat = true; + CircularListElement * t1 = m_mesh.AddTriangle(); + CircularListElement * t2 = m_mesh.AddTriangle(); + CircularListElement * v0 = m_mesh.m_vertices.GetHead(); + CircularListElement * v1 = v0->GetNext(); + CircularListElement * v2 = v1->GetNext(); + // Compute the normal to the plane + Vec3 p0 = v0->GetData().m_pos; + Vec3 p1 = v1->GetData().m_pos; + Vec3 p2 = v2->GetData().m_pos; + m_normal = (p1-p0) ^ (p2-p0); + m_normal.Normalize(); + t1->GetData().m_vertices[0] = v0; + t1->GetData().m_vertices[1] = v1; + t1->GetData().m_vertices[2] = v2; + t2->GetData().m_vertices[0] = v1; + t2->GetData().m_vertices[1] = v0; + t2->GetData().m_vertices[2] = v2; + return ICHullErrorOK; + } + + if (m_isFlat) + { + m_mesh.m_triangles.Clear(); + m_mesh.m_edges.Clear(); + m_isFlat = false; + } + + if (m_mesh.GetNTriangles() == 0) // we have to create the first polyhedron + { + ICHullError res = DoubleTriangle(); + if (res != ICHullErrorOK) + { + return res; + } + else + { + addedPoints += 3; + } + } + CircularList & vertices = m_mesh.GetVertices(); + while (!vertices.GetData().m_tag && addedPoints < nPointsCH) // not processed + { + if (!FindMaxVolumePoint()) + { + break; + } + vertices.GetData().m_tag = true; + if (ProcessPoint()) + { + addedPoints++; + CleanUp(addedPoints); + if (!GetMesh().CheckConsistancy()) + { + return ICHullErrorInconsistent; + } + vertices.Next(); + } + } + // delete remaining points + while (!vertices.GetData().m_tag) + { + vertices.Delete(); + } + if (m_isFlat) + { + std::vector< CircularListElement * > trianglesToDuplicate; + size_t nT = m_mesh.GetNTriangles(); + for(size_t f = 0; f < nT; f++) + { + TMMTriangle & currentTriangle = m_mesh.m_triangles.GetHead()->GetData(); + if( currentTriangle.m_vertices[0]->GetData().m_name == sc_dummyIndex || + currentTriangle.m_vertices[1]->GetData().m_name == sc_dummyIndex || + currentTriangle.m_vertices[2]->GetData().m_name == sc_dummyIndex ) + { + m_trianglesToDelete.push_back(m_mesh.m_triangles.GetHead()); + for(int k = 0; k < 3; k++) + { + for(int h = 0; h < 2; h++) + { + if (currentTriangle.m_edges[k]->GetData().m_triangles[h] == m_mesh.m_triangles.GetHead()) + { + currentTriangle.m_edges[k]->GetData().m_triangles[h] = 0; + break; + } + } + } + } + else + { + trianglesToDuplicate.push_back(m_mesh.m_triangles.GetHead()); + } + m_mesh.m_triangles.Next(); + } + size_t nE = m_mesh.GetNEdges(); + for(size_t e = 0; e < nE; e++) + { + TMMEdge & currentEdge = m_mesh.m_edges.GetHead()->GetData(); + if( currentEdge.m_triangles[0] == 0 && currentEdge.m_triangles[1] == 0) + { + m_edgesToDelete.push_back(m_mesh.m_edges.GetHead()); + } + m_mesh.m_edges.Next(); + } + m_mesh.m_vertices.Delete(m_dummyVertex); + m_dummyVertex = 0; + size_t nV = m_mesh.GetNVertices(); + CircularList & vertices = m_mesh.GetVertices(); + for(size_t v = 0; v < nV; ++v) + { + vertices.GetData().m_tag = false; + vertices.Next(); + } + CleanEdges(); + CleanTriangles(); + CircularListElement * newTriangle; + for(size_t t = 0; t < trianglesToDuplicate.size(); t++) + { + newTriangle = m_mesh.AddTriangle(); + newTriangle->GetData().m_vertices[0] = trianglesToDuplicate[t]->GetData().m_vertices[1]; + newTriangle->GetData().m_vertices[1] = trianglesToDuplicate[t]->GetData().m_vertices[0]; + newTriangle->GetData().m_vertices[2] = trianglesToDuplicate[t]->GetData().m_vertices[2]; + } + } + return ICHullErrorOK; + } + bool ICHull::FindMaxVolumePoint() + { + CircularList & vertices = m_mesh.GetVertices(); + CircularListElement * vMaxVolume = 0; + CircularListElement * vHeadPrev = vertices.GetHead()->GetPrev(); + + double maxVolume = 0.0; + double volume = 0.0; + + while (!vertices.GetData().m_tag) // not processed + { + if (ComputePointVolume(volume, false)) + { + if ( maxVolume < volume) + { + maxVolume = volume; + vMaxVolume = vertices.GetHead(); + } + vertices.Next(); + } + } + CircularListElement * vHead = vHeadPrev->GetNext(); + vertices.GetHead() = vHead; + + if (!vMaxVolume) + { + return false; + } + + if (vMaxVolume != vHead) + { + Vec3 pos = vHead->GetData().m_pos; + long id = vHead->GetData().m_name; + vHead->GetData().m_pos = vMaxVolume->GetData().m_pos; + vHead->GetData().m_name = vMaxVolume->GetData().m_name; + vMaxVolume->GetData().m_pos = pos; + vHead->GetData().m_name = id; + } + + + return true; + } + ICHullError ICHull::DoubleTriangle() + { + // find three non colinear points + m_isFlat = false; + CircularList & vertices = m_mesh.GetVertices(); + CircularListElement * v0 = vertices.GetHead(); + while( Colinear(v0->GetData().m_pos, + v0->GetNext()->GetData().m_pos, + v0->GetNext()->GetNext()->GetData().m_pos)) + { + if ( (v0 = v0->GetNext()) == vertices.GetHead()) + { + return ICHullErrorCoplanarPoints; + } + } + CircularListElement * v1 = v0->GetNext(); + CircularListElement * v2 = v1->GetNext(); + // mark points as processed + v0->GetData().m_tag = v1->GetData().m_tag = v2->GetData().m_tag = true; + + // create two triangles + CircularListElement * f0 = MakeFace(v0, v1, v2, 0); + MakeFace(v2, v1, v0, f0); + + // find a fourth non-coplanar point to form tetrahedron + CircularListElement * v3 = v2->GetNext(); + vertices.GetHead() = v3; + + double vol = Volume(v0->GetData().m_pos, v1->GetData().m_pos, v2->GetData().m_pos, v3->GetData().m_pos); + while (vol == 0.0 && !v3->GetNext()->GetData().m_tag) + { + v3 = v3->GetNext(); + vol = Volume(v0->GetData().m_pos, v1->GetData().m_pos, v2->GetData().m_pos, v3->GetData().m_pos); + } + if (vol == 0.0) + { + // compute the barycenter + Vec3 bary(0.0,0.0,0.0); + CircularListElement * vBary = v0; + do + { + bary += vBary->GetData().m_pos; + } + while ( (vBary = vBary->GetNext()) != v0); + bary /= static_cast(vertices.GetSize()); + + // Compute the normal to the plane + Vec3 p0 = v0->GetData().m_pos; + Vec3 p1 = v1->GetData().m_pos; + Vec3 p2 = v2->GetData().m_pos; + m_normal = (p1-p0) ^ (p2-p0); + m_normal.Normalize(); + // add dummy vertex placed at (bary + normal) + vertices.GetHead() = v2; + Vec3 newPt = bary + m_normal; + AddPoint(newPt, sc_dummyIndex); + m_dummyVertex = vertices.GetHead(); + m_isFlat = true; + v3 = v2->GetNext(); + vol = Volume(v0->GetData().m_pos, v1->GetData().m_pos, v2->GetData().m_pos, v3->GetData().m_pos); + return ICHullErrorOK; + } + else if (v3 != vertices.GetHead()) + { + TMMVertex temp; + temp.m_name = v3->GetData().m_name; + temp.m_pos = v3->GetData().m_pos; + v3->GetData().m_name = vertices.GetHead()->GetData().m_name; + v3->GetData().m_pos = vertices.GetHead()->GetData().m_pos; + vertices.GetHead()->GetData().m_name = temp.m_name; + vertices.GetHead()->GetData().m_pos = temp.m_pos; + } + return ICHullErrorOK; + } + CircularListElement * ICHull::MakeFace(CircularListElement * v0, + CircularListElement * v1, + CircularListElement * v2, + CircularListElement * fold) + { + CircularListElement * e0; + CircularListElement * e1; + CircularListElement * e2; + long index = 0; + if (!fold) // if first face to be created + { + e0 = m_mesh.AddEdge(); // create the three edges + e1 = m_mesh.AddEdge(); + e2 = m_mesh.AddEdge(); + } + else // otherwise re-use existing edges (in reverse order) + { + e0 = fold->GetData().m_edges[2]; + e1 = fold->GetData().m_edges[1]; + e2 = fold->GetData().m_edges[0]; + index = 1; + } + e0->GetData().m_vertices[0] = v0; e0->GetData().m_vertices[1] = v1; + e1->GetData().m_vertices[0] = v1; e1->GetData().m_vertices[1] = v2; + e2->GetData().m_vertices[0] = v2; e2->GetData().m_vertices[1] = v0; + // create the new face + CircularListElement * f = m_mesh.AddTriangle(); + f->GetData().m_edges[0] = e0; f->GetData().m_edges[1] = e1; f->GetData().m_edges[2] = e2; + f->GetData().m_vertices[0] = v0; f->GetData().m_vertices[1] = v1; f->GetData().m_vertices[2] = v2; + // link edges to face f + e0->GetData().m_triangles[index] = e1->GetData().m_triangles[index] = e2->GetData().m_triangles[index] = f; + return f; + } + CircularListElement * ICHull::MakeConeFace(CircularListElement * e, CircularListElement * p) + { + // create two new edges if they don't already exist + CircularListElement * newEdges[2]; + for(int i = 0; i < 2; ++i) + { + if ( !( newEdges[i] = e->GetData().m_vertices[i]->GetData().m_duplicate ) ) + { // if the edge doesn't exits add it and mark the vertex as duplicated + newEdges[i] = m_mesh.AddEdge(); + newEdges[i]->GetData().m_vertices[0] = e->GetData().m_vertices[i]; + newEdges[i]->GetData().m_vertices[1] = p; + e->GetData().m_vertices[i]->GetData().m_duplicate = newEdges[i]; + } + } + // make the new face + CircularListElement * newFace = m_mesh.AddTriangle(); + newFace->GetData().m_edges[0] = e; + newFace->GetData().m_edges[1] = newEdges[0]; + newFace->GetData().m_edges[2] = newEdges[1]; + MakeCCW(newFace, e, p); + for(int i=0; i < 2; ++i) + { + for(int j=0; j < 2; ++j) + { + if ( ! newEdges[i]->GetData().m_triangles[j] ) + { + newEdges[i]->GetData().m_triangles[j] = newFace; + break; + } + } + } + return newFace; + } + bool ICHull::ComputePointVolume(double &totalVolume, bool markVisibleFaces) + { + // mark visible faces + CircularListElement * fHead = m_mesh.GetTriangles().GetHead(); + CircularListElement * f = fHead; + CircularList & vertices = m_mesh.GetVertices(); + CircularListElement * vertex0 = vertices.GetHead(); + bool visible = false; + Vec3 pos0 = Vec3(vertex0->GetData().m_pos.X(), + vertex0->GetData().m_pos.Y(), + vertex0->GetData().m_pos.Z()); + double vol = 0.0; + totalVolume = 0.0; + Vec3 ver0, ver1, ver2; + do + { + ver0.X() = f->GetData().m_vertices[0]->GetData().m_pos.X(); + ver0.Y() = f->GetData().m_vertices[0]->GetData().m_pos.Y(); + ver0.Z() = f->GetData().m_vertices[0]->GetData().m_pos.Z(); + ver1.X() = f->GetData().m_vertices[1]->GetData().m_pos.X(); + ver1.Y() = f->GetData().m_vertices[1]->GetData().m_pos.Y(); + ver1.Z() = f->GetData().m_vertices[1]->GetData().m_pos.Z(); + ver2.X() = f->GetData().m_vertices[2]->GetData().m_pos.X(); + ver2.Y() = f->GetData().m_vertices[2]->GetData().m_pos.Y(); + ver2.Z() = f->GetData().m_vertices[2]->GetData().m_pos.Z(); + vol = Volume(ver0, ver1, ver2, pos0); + if ( vol < 0.0 ) + { + vol = fabs(vol); + totalVolume += vol; + if (markVisibleFaces) + { + f->GetData().m_visible = true; + m_trianglesToDelete.push_back(f); + } + visible = true; + } + f = f->GetNext(); + } + while (f != fHead); + + if (m_trianglesToDelete.size() == m_mesh.m_triangles.GetSize()) + { + for(size_t i = 0; i < m_trianglesToDelete.size(); i++) + { + m_trianglesToDelete[i]->GetData().m_visible = false; + } + visible = false; + } + // if no faces visible from p then p is inside the hull + if (!visible && markVisibleFaces) + { + vertices.Delete(); + m_trianglesToDelete.clear(); + return false; + } + return true; + } + bool ICHull::ProcessPoint() + { + double totalVolume = 0.0; + if (!ComputePointVolume(totalVolume, true)) + { + return false; + } + // Mark edges in interior of visible region for deletion. + // Create a new face based on each border edge + CircularListElement * v0 = m_mesh.GetVertices().GetHead(); + CircularListElement * eHead = m_mesh.GetEdges().GetHead(); + CircularListElement * e = eHead; + CircularListElement * tmp = 0; + long nvisible = 0; + m_edgesToDelete.clear(); + m_edgesToUpdate.clear(); + do + { + tmp = e->GetNext(); + nvisible = 0; + for(int k = 0; k < 2; k++) + { + if ( e->GetData().m_triangles[k]->GetData().m_visible ) + { + nvisible++; + } + } + if ( nvisible == 2) + { + m_edgesToDelete.push_back(e); + } + else if ( nvisible == 1) + { + e->GetData().m_newFace = MakeConeFace(e, v0); + m_edgesToUpdate.push_back(e); + } + e = tmp; + } + while (e != eHead); + return true; + } + bool ICHull::MakeCCW(CircularListElement * f, + CircularListElement * e, + CircularListElement * v) + { + // the visible face adjacent to e + CircularListElement * fv; + if (e->GetData().m_triangles[0]->GetData().m_visible) + { + fv = e->GetData().m_triangles[0]; + } + else + { + fv = e->GetData().m_triangles[1]; + } + + // set vertex[0] and vertex[1] to have the same orientation as the corresponding vertices of fv. + long i; // index of e->m_vertices[0] in fv + CircularListElement * v0 = e->GetData().m_vertices[0]; + CircularListElement * v1 = e->GetData().m_vertices[1]; + for(i = 0; fv->GetData().m_vertices[i] != v0; i++); + + if ( fv->GetData().m_vertices[(i+1) % 3] != e->GetData().m_vertices[1] ) + { + f->GetData().m_vertices[0] = v1; + f->GetData().m_vertices[1] = v0; + } + else + { + f->GetData().m_vertices[0] = v0; + f->GetData().m_vertices[1] = v1; + // swap edges + CircularListElement * tmp = f->GetData().m_edges[0]; + f->GetData().m_edges[0] = f->GetData().m_edges[1]; + f->GetData().m_edges[1] = tmp; + } + f->GetData().m_vertices[2] = v; + return true; + } + bool ICHull::CleanUp(unsigned long & addedPoints) + { + bool r0 = CleanEdges(); + bool r1 = CleanTriangles(); + bool r2 = CleanVertices(addedPoints); + return r0 && r1 && r2; + } + bool ICHull::CleanEdges() + { + // integrate the new faces into the data structure + CircularListElement * e; + const std::vector *>::iterator itEndUpdate = m_edgesToUpdate.end(); + for(std::vector *>::iterator it = m_edgesToUpdate.begin(); it != itEndUpdate; ++it) + { + e = *it; + if ( e->GetData().m_newFace ) + { + if ( e->GetData().m_triangles[0]->GetData().m_visible) + { + e->GetData().m_triangles[0] = e->GetData().m_newFace; + } + else + { + e->GetData().m_triangles[1] = e->GetData().m_newFace; + } + e->GetData().m_newFace = 0; + } + } + // delete edges maked for deletion + CircularList & edges = m_mesh.GetEdges(); + const std::vector *>::iterator itEndDelete = m_edgesToDelete.end(); + for(std::vector *>::iterator it = m_edgesToDelete.begin(); it != itEndDelete; ++it) + { + edges.Delete(*it); + } + m_edgesToDelete.clear(); + m_edgesToUpdate.clear(); + return true; + } + bool ICHull::CleanTriangles() + { + CircularList & triangles = m_mesh.GetTriangles(); + const std::vector *>::iterator itEndDelete = m_trianglesToDelete.end(); + for(std::vector *>::iterator it = m_trianglesToDelete.begin(); it != itEndDelete; ++it) + { + if (m_distPoints) + { + if (m_isFlat) + { + // to be updated + } + else + { + std::set::const_iterator itPEnd((*it)->GetData().m_incidentPoints.end()); + std::set::const_iterator itP((*it)->GetData().m_incidentPoints.begin()); + std::map::iterator itPoint; + for(; itP != itPEnd; ++itP) + { + itPoint = m_distPoints->find(*itP); + if (itPoint != m_distPoints->end()) + { + itPoint->second.m_computed = false; + } + } + } + } + triangles.Delete(*it); + } + m_trianglesToDelete.clear(); + return true; + } + bool ICHull::CleanVertices(unsigned long & addedPoints) + { + // mark all vertices incident to some undeleted edge as on the hull + CircularList & edges = m_mesh.GetEdges(); + CircularListElement * e = edges.GetHead(); + size_t nE = edges.GetSize(); + for(size_t i = 0; i < nE; i++) + { + e->GetData().m_vertices[0]->GetData().m_onHull = true; + e->GetData().m_vertices[1]->GetData().m_onHull = true; + e = e->GetNext(); + } + // delete all the vertices that have been processed but are not on the hull + CircularList & vertices = m_mesh.GetVertices(); + CircularListElement * vHead = vertices.GetHead(); + CircularListElement * v = vHead; + v = v->GetPrev(); + do + { + if (v->GetData().m_tag && !v->GetData().m_onHull) + { + CircularListElement * tmp = v->GetPrev(); + vertices.Delete(v); + v = tmp; + addedPoints--; + } + else + { + v->GetData().m_duplicate = 0; + v->GetData().m_onHull = false; + v = v->GetPrev(); + } + } + while (v->GetData().m_tag && v != vHead); + return true; + } + void ICHull::Clear() + { + m_mesh.Clear(); + m_edgesToDelete = std::vector *>(); + m_edgesToUpdate = std::vector *>(); + m_trianglesToDelete= std::vector *>(); + m_isFlat = false; + } + const ICHull & ICHull::operator=(ICHull & rhs) + { + if (&rhs != this) + { + m_mesh.Copy(rhs.m_mesh); + m_edgesToDelete = rhs.m_edgesToDelete; + m_edgesToUpdate = rhs.m_edgesToUpdate; + m_trianglesToDelete = rhs.m_trianglesToDelete; + m_isFlat = rhs.m_isFlat; + } + return (*this); + } + double ICHull::ComputeVolume() + { + size_t nV = m_mesh.m_vertices.GetSize(); + if (nV == 0 || m_isFlat) + { + return 0.0; + } + Vec3 bary(0.0, 0.0, 0.0); + for(size_t v = 0; v < nV; v++) + { + bary.X() += m_mesh.m_vertices.GetHead()->GetData().m_pos.X(); + bary.Y() += m_mesh.m_vertices.GetHead()->GetData().m_pos.Y(); + bary.Z() += m_mesh.m_vertices.GetHead()->GetData().m_pos.Z(); + m_mesh.m_vertices.Next(); + } + bary /= static_cast(nV); + + size_t nT = m_mesh.m_triangles.GetSize(); + Vec3 ver0, ver1, ver2; + double totalVolume = 0.0; + for(size_t t = 0; t < nT; t++) + { + ver0.X() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[0]->GetData().m_pos.X(); + ver0.Y() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[0]->GetData().m_pos.Y(); + ver0.Z() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[0]->GetData().m_pos.Z(); + ver1.X() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[1]->GetData().m_pos.X(); + ver1.Y() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[1]->GetData().m_pos.Y(); + ver1.Z() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[1]->GetData().m_pos.Z(); + ver2.X() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[2]->GetData().m_pos.X(); + ver2.Y() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[2]->GetData().m_pos.Y(); + ver2.Z() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[2]->GetData().m_pos.Z(); + totalVolume += Volume(ver0, ver1, ver2, bary); + m_mesh.m_triangles.Next(); + } + return totalVolume; + } + bool ICHull::IsInside(const Vec3 & pt0) + { + const Vec3 pt(pt0.X(), pt0.Y(), pt0.Z()); + if (m_isFlat) + { + size_t nT = m_mesh.m_triangles.GetSize(); + Vec3 ver0, ver1, ver2, a, b, c; + double u,v; + for(size_t t = 0; t < nT; t++) + { + ver0.X() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[0]->GetData().m_pos.X(); + ver0.Y() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[0]->GetData().m_pos.Y(); + ver0.Z() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[0]->GetData().m_pos.Z(); + ver1.X() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[1]->GetData().m_pos.X(); + ver1.Y() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[1]->GetData().m_pos.Y(); + ver1.Z() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[1]->GetData().m_pos.Z(); + ver2.X() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[2]->GetData().m_pos.X(); + ver2.Y() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[2]->GetData().m_pos.Y(); + ver2.Z() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[2]->GetData().m_pos.Z(); + a = ver1 - ver0; + b = ver2 - ver0; + c = pt - ver0; + u = c * a; + v = c * b; + if ( u >= 0.0 && u <= 1.0 && v >= 0.0 && u+v <= 1.0) + { + return true; + } + m_mesh.m_triangles.Next(); + } + return false; + } + else + { + size_t nT = m_mesh.m_triangles.GetSize(); + Vec3 ver0, ver1, ver2; + for(size_t t = 0; t < nT; t++) + { + ver0.X() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[0]->GetData().m_pos.X(); + ver0.Y() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[0]->GetData().m_pos.Y(); + ver0.Z() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[0]->GetData().m_pos.Z(); + ver1.X() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[1]->GetData().m_pos.X(); + ver1.Y() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[1]->GetData().m_pos.Y(); + ver1.Z() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[1]->GetData().m_pos.Z(); + ver2.X() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[2]->GetData().m_pos.X(); + ver2.Y() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[2]->GetData().m_pos.Y(); + ver2.Z() = m_mesh.m_triangles.GetHead()->GetData().m_vertices[2]->GetData().m_pos.Z(); + if (Volume(ver0, ver1, ver2, pt) < 0.0) + { + return false; + } + m_mesh.m_triangles.Next(); + } + return true; + } + } + double ICHull::ComputeDistance(long name, const Vec3 & pt, const Vec3 & normal, bool & insideHull, bool updateIncidentPoints) + { + Vec3 ptNormal(static_cast(normal.X()), + static_cast(normal.Y()), + static_cast(normal.Z())); + Vec3 p0( static_cast(pt.X()), + static_cast(pt.Y()), + static_cast(pt.Z())); + + if (m_isFlat) + { + double distance = 0.0; + Vec3 chNormal(static_cast(m_normal.X()), + static_cast(m_normal.Y()), + static_cast(m_normal.Z())); + ptNormal -= (ptNormal * chNormal) * chNormal; + if (ptNormal.GetNorm() > 0.0) + { + ptNormal.Normalize(); + long nameVE1; + long nameVE2; + Vec3 pa, pb, d0, d1, d2, d3; + Vec3 p1 = p0 + ptNormal; + Vec3 p2, p3; + double mua, mub, s; + const double EPS = 0.00000000001; + size_t nE = m_mesh.GetNEdges(); + for(size_t e = 0; e < nE; e++) + { + TMMEdge & currentEdge = m_mesh.m_edges.GetHead()->GetData(); + nameVE1 = currentEdge.m_vertices[0]->GetData().m_name; + nameVE2 = currentEdge.m_vertices[1]->GetData().m_name; + if (currentEdge.m_triangles[0] == 0 || currentEdge.m_triangles[1] == 0) + { + if ( nameVE1==name || nameVE2==name ) + { + return 0.0; + } + /* + if (debug) std::cout << "V" << name + << " E " << nameVE1 << " " << nameVE2 << std::endl; + */ + + p2.X() = currentEdge.m_vertices[0]->GetData().m_pos.X(); + p2.Y() = currentEdge.m_vertices[0]->GetData().m_pos.Y(); + p2.Z() = currentEdge.m_vertices[0]->GetData().m_pos.Z(); + p3.X() = currentEdge.m_vertices[1]->GetData().m_pos.X(); + p3.Y() = currentEdge.m_vertices[1]->GetData().m_pos.Y(); + p3.Z() = currentEdge.m_vertices[1]->GetData().m_pos.Z(); + d0 = p3 - p2; + if (d0.GetNorm() > 0.0) + { + if (IntersectLineLine(p0, p1, p2, p3, pa, pb, mua, mub)) + { + d1 = pa - p2; + d2 = pa - pb; + d3 = pa - p0; + mua = d1.GetNorm()/d0.GetNorm(); + mub = d1*d0; + s = d3*ptNormal; + if (d2.GetNorm() < EPS && mua <= 1.0 && mub>=0.0 && s>0.0) + { + distance = std::max(distance, d3.GetNorm()); + } + } + } + } + m_mesh.m_edges.Next(); + } + } + return distance; + } + else + { + Vec3 ptNormal(static_cast(normal.X()), + static_cast(normal.Y()), + static_cast(normal.Z())); + + Vec3 impact; + long nhit; + double dist; + double distance = 0.0; + size_t nT = m_mesh.GetNTriangles(); + insideHull = false; + CircularListElement * face = 0; + Vec3 ver0, ver1, ver2; + for(size_t f = 0; f < nT; f++) + { + TMMTriangle & currentTriangle = m_mesh.m_triangles.GetHead()->GetData(); + /* + if (debug) std::cout << "T " << currentTriangle.m_vertices[0]->GetData().m_name << " " + << currentTriangle.m_vertices[1]->GetData().m_name << " " + << currentTriangle.m_vertices[2]->GetData().m_name << std::endl; + */ + if (currentTriangle.m_vertices[0]->GetData().m_name == name || + currentTriangle.m_vertices[1]->GetData().m_name == name || + currentTriangle.m_vertices[2]->GetData().m_name == name) + { + nhit = 1; + dist = 0.0; + } + else + { + ver0.X() = currentTriangle.m_vertices[0]->GetData().m_pos.X(); + ver0.Y() = currentTriangle.m_vertices[0]->GetData().m_pos.Y(); + ver0.Z() = currentTriangle.m_vertices[0]->GetData().m_pos.Z(); + ver1.X() = currentTriangle.m_vertices[1]->GetData().m_pos.X(); + ver1.Y() = currentTriangle.m_vertices[1]->GetData().m_pos.Y(); + ver1.Z() = currentTriangle.m_vertices[1]->GetData().m_pos.Z(); + ver2.X() = currentTriangle.m_vertices[2]->GetData().m_pos.X(); + ver2.Y() = currentTriangle.m_vertices[2]->GetData().m_pos.Y(); + ver2.Z() = currentTriangle.m_vertices[2]->GetData().m_pos.Z(); + nhit = IntersectRayTriangle(p0, ptNormal, ver0, ver1, ver2, dist); + } + + if (nhit == 1 && distance <= dist) + { + distance = dist; + insideHull = true; + face = m_mesh.m_triangles.GetHead(); +/* + std::cout << name << " -> T " << currentTriangle.m_vertices[0]->GetData().m_name << " " + << currentTriangle.m_vertices[1]->GetData().m_name << " " + << currentTriangle.m_vertices[2]->GetData().m_name << " Dist " + << dist << " P " << currentTriangle.m_normal * normal << std::endl; +*/ + if (dist > 0.1) + { + break; + } + } + m_mesh.m_triangles.Next(); + } + if (updateIncidentPoints && face && m_distPoints) + { + (*m_distPoints)[name].m_dist = static_cast(distance); + face->GetData().m_incidentPoints.insert(name); + } + return distance; + } + } +} + diff --git a/Extras/HACD/hacdICHull.h b/Extras/HACD/hacdICHull.h new file mode 100644 index 0000000000..548f992bdb --- /dev/null +++ b/Extras/HACD/hacdICHull.h @@ -0,0 +1,120 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once +#ifndef HACD_ICHULL_H +#define HACD_ICHULL_H +#include "hacdVersion.h" +#include "hacdManifoldMesh.h" +#include "hacdVector.h" +#include +#include +namespace HACD +{ + class DPoint; + class HACD; + //! Incremental Convex Hull algorithm (cf. http://maven.smith.edu/~orourke/books/ftp.html ). + enum ICHullError + { + ICHullErrorOK = 0, + ICHullErrorCoplanarPoints, + ICHullErrorNoVolume, + ICHullErrorInconsistent, + ICHullErrorNotEnoughPoints + }; + class ICHull + { + public: + //! + bool IsFlat() { return m_isFlat;} + //! + std::map * GetDistPoints() const { return m_distPoints;} + //! + void SetDistPoints(std::map * distPoints) { m_distPoints = distPoints;} + //! Returns the computed mesh + TMMesh & GetMesh() { return m_mesh;} + //! Add one point to the convex-hull + bool AddPoint(const Vec3 & point) {return AddPoints(&point, 1);} + //! Add one point to the convex-hull + bool AddPoint(const Vec3 & point, long id); + //! Add points to the convex-hull + bool AddPoints(const Vec3 * points, size_t nPoints); + bool AddPoints(std::vector< Vec3 > points); + //! + ICHullError Process(); + //! + ICHullError Process(unsigned long nPointsCH); + //! + double ComputeVolume(); + //! + bool IsInside(const Vec3 & pt0); + //! + double ComputeDistance(long name, const Vec3 & pt, const Vec3 & normal, bool & insideHull, bool updateIncidentPoints); + //! + const ICHull & operator=(ICHull & rhs); + + //! Constructor + ICHull(void); + //! Destructor + virtual ~ICHull(void) {}; + + private: + //! DoubleTriangle builds the initial double triangle. It first finds 3 noncollinear points and makes two faces out of them, in opposite order. It then finds a fourth point that is not coplanar with that face. The vertices are stored in the face structure in counterclockwise order so that the volume between the face and the point is negative. Lastly, the 3 newfaces to the fourth point are constructed and the data structures are cleaned up. + ICHullError DoubleTriangle(); + //! MakeFace creates a new face structure from three vertices (in ccw order). It returns a pointer to the face. + CircularListElement * MakeFace(CircularListElement * v0, + CircularListElement * v1, + CircularListElement * v2, + CircularListElement * fold); + //! + CircularListElement * MakeConeFace(CircularListElement * e, CircularListElement * v); + //! + bool ProcessPoint(); + //! + bool ComputePointVolume(double &totalVolume, bool markVisibleFaces); + //! + bool FindMaxVolumePoint(); + //! + bool CleanEdges(); + //! + bool CleanVertices(unsigned long & addedPoints); + //! + bool CleanTriangles(); + //! + bool CleanUp(unsigned long & addedPoints); + //! + bool MakeCCW(CircularListElement * f, + CircularListElement * e, + CircularListElement * v); + void Clear(); + private: + static const long sc_dummyIndex; + static const double sc_distMin; + TMMesh m_mesh; + std::vector *> m_edgesToDelete; + std::vector *> m_edgesToUpdate; + std::vector *> m_trianglesToDelete; + std::map * m_distPoints; + CircularListElement * m_dummyVertex; + Vec3 m_normal; + bool m_isFlat; + + + ICHull(const ICHull & rhs); + + friend class HACD; + }; + +} +#endif diff --git a/Extras/HACD/hacdManifoldMesh.cpp b/Extras/HACD/hacdManifoldMesh.cpp new file mode 100644 index 0000000000..22a3576e43 --- /dev/null +++ b/Extras/HACD/hacdManifoldMesh.cpp @@ -0,0 +1,577 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "hacdManifoldMesh.h" +using namespace std; + + +namespace HACD +{ + Material::Material(void) + { + m_diffuseColor.X() = 0.5; + m_diffuseColor.Y() = 0.5; + m_diffuseColor.Z() = 0.5; + m_specularColor.X() = 0.5; + m_specularColor.Y() = 0.5; + m_specularColor.Z() = 0.5; + m_ambientIntensity = 0.4; + m_emissiveColor.X() = 0.0; + m_emissiveColor.Y() = 0.0; + m_emissiveColor.Z() = 0.0; + m_shininess = 0.4; + m_transparency = 0.0; + } + + TMMVertex::TMMVertex(void) + { + m_name = 0; + m_id = 0; + m_duplicate = 0; + m_onHull = false; + m_tag = false; + } + TMMVertex::~TMMVertex(void) + { + } + TMMEdge::TMMEdge(void) + { + m_id = 0; + m_triangles[0] = m_triangles[1] = m_newFace = 0; + m_vertices[0] = m_vertices[1] = 0; + } + TMMEdge::~TMMEdge(void) + { + } + TMMTriangle::TMMTriangle(void) + { + m_id = 0; + for(int i = 0; i < 3; i++) + { + m_edges[i] = 0; + m_vertices[0] = 0; + } + m_visible = false; + } + TMMTriangle::~TMMTriangle(void) + { + } + TMMesh::TMMesh(void) + { + m_barycenter = Vec3(0,0,0); + m_diag = 1; + } + TMMesh::~TMMesh(void) + { + } + + void TMMesh::Print() + { + size_t nV = m_vertices.GetSize(); + std::cout << "-----------------------------" << std::endl; + std::cout << "vertices (" << nV << ")" << std::endl; + for(size_t v = 0; v < nV; v++) + { + const TMMVertex & currentVertex = m_vertices.GetData(); + std::cout << currentVertex.m_id << ", " + << currentVertex.m_pos.X() << ", " + << currentVertex.m_pos.Y() << ", " + << currentVertex.m_pos.Z() << std::endl; + m_vertices.Next(); + } + + + size_t nE = m_edges.GetSize(); + std::cout << "edges (" << nE << ")" << std::endl; + for(size_t e = 0; e < nE; e++) + { + const TMMEdge & currentEdge = m_edges.GetData(); + const CircularListElement * v0 = currentEdge.m_vertices[0]; + const CircularListElement * v1 = currentEdge.m_vertices[1]; + const CircularListElement * f0 = currentEdge.m_triangles[0]; + const CircularListElement * f1 = currentEdge.m_triangles[1]; + + std::cout << "-> (" << v0->GetData().m_name << ", " << v1->GetData().m_name << ")" << std::endl; + std::cout << "-> F0 (" << f0->GetData().m_vertices[0]->GetData().m_name << ", " + << f0->GetData().m_vertices[1]->GetData().m_name << ", " + << f0->GetData().m_vertices[2]->GetData().m_name <<")" << std::endl; + std::cout << "-> F1 (" << f1->GetData().m_vertices[0]->GetData().m_name << ", " + << f1->GetData().m_vertices[1]->GetData().m_name << ", " + << f1->GetData().m_vertices[2]->GetData().m_name << ")" << std::endl; + m_edges.Next(); + } + size_t nT = m_triangles.GetSize(); + std::cout << "triangles (" << nT << ")" << std::endl; + for(size_t t = 0; t < nT; t++) + { + const TMMTriangle & currentTriangle = m_triangles.GetData(); + const CircularListElement * v0 = currentTriangle.m_vertices[0]; + const CircularListElement * v1 = currentTriangle.m_vertices[1]; + const CircularListElement * v2 = currentTriangle.m_vertices[2]; + const CircularListElement * e0 = currentTriangle.m_edges[0]; + const CircularListElement * e1 = currentTriangle.m_edges[1]; + const CircularListElement * e2 = currentTriangle.m_edges[2]; + + std::cout << "-> (" << v0->GetData().m_name << ", " << v1->GetData().m_name << ", "<< v2->GetData().m_name << ")" << std::endl; + + std::cout << "-> E0 (" << e0->GetData().m_vertices[0]->GetData().m_name << ", " + << e0->GetData().m_vertices[1]->GetData().m_name << ")" << std::endl; + std::cout << "-> E1 (" << e1->GetData().m_vertices[0]->GetData().m_name << ", " + << e1->GetData().m_vertices[1]->GetData().m_name << ")" << std::endl; + std::cout << "-> E2 (" << e2->GetData().m_vertices[0]->GetData().m_name << ", " + << e2->GetData().m_vertices[1]->GetData().m_name << ")" << std::endl; + m_triangles.Next(); + } + } + bool TMMesh::Save(const char *fileName) + { + std::ofstream fout(fileName); + std::cout << "Saving " << fileName << std::endl; + if (SaveVRML2(fout)) + { + fout.close(); + return true; + } + return false; + } + bool TMMesh::SaveVRML2(std::ofstream &fout) + { + return SaveVRML2(fout, Material()); + } + bool TMMesh::SaveVRML2(std::ofstream &fout, const Material & material) + { + if (fout.is_open()) + { + size_t nV = m_vertices.GetSize(); + size_t nT = m_triangles.GetSize(); + fout <<"#VRML V2.0 utf8" << std::endl; + fout <<"" << std::endl; + fout <<"# Vertices: " << nV << std::endl; + fout <<"# Triangles: " << nT << std::endl; + fout <<"" << std::endl; + fout <<"Group {" << std::endl; + fout <<" children [" << std::endl; + fout <<" Shape {" << std::endl; + fout <<" appearance Appearance {" << std::endl; + fout <<" material Material {" << std::endl; + fout <<" diffuseColor " << material.m_diffuseColor.X() << " " + << material.m_diffuseColor.Y() << " " + << material.m_diffuseColor.Z() << std::endl; + fout <<" ambientIntensity " << material.m_ambientIntensity << std::endl; + fout <<" specularColor " << material.m_specularColor.X() << " " + << material.m_specularColor.Y() << " " + << material.m_specularColor.Z() << std::endl; + fout <<" emissiveColor " << material.m_emissiveColor.X() << " " + << material.m_emissiveColor.Y() << " " + << material.m_emissiveColor.Z() << std::endl; + fout <<" shininess " << material.m_shininess << std::endl; + fout <<" transparency " << material.m_transparency << std::endl; + fout <<" }" << std::endl; + fout <<" }" << std::endl; + fout <<" geometry IndexedFaceSet {" << std::endl; + fout <<" ccw TRUE" << std::endl; + fout <<" solid TRUE" << std::endl; + fout <<" convex TRUE" << std::endl; + if (GetNVertices() > 0) { + fout <<" coord DEF co Coordinate {" << std::endl; + fout <<" point [" << std::endl; + for(size_t v = 0; v < nV; v++) + { + TMMVertex & currentVertex = m_vertices.GetData(); + fout <<" " << currentVertex.m_pos.X() << " " + << currentVertex.m_pos.Y() << " " + << currentVertex.m_pos.Z() << "," << std::endl; + currentVertex.m_id = v; + m_vertices.Next(); + } + fout <<" ]" << std::endl; + fout <<" }" << std::endl; + } + if (GetNTriangles() > 0) { + fout <<" coordIndex [ " << std::endl; + for(size_t f = 0; f < nT; f++) + { + TMMTriangle & currentTriangle = m_triangles.GetData(); + fout <<" " << currentTriangle.m_vertices[0]->GetData().m_id << ", " + << currentTriangle.m_vertices[1]->GetData().m_id << ", " + << currentTriangle.m_vertices[2]->GetData().m_id << ", -1," << std::endl; + m_triangles.Next(); + } + fout <<" ]" << std::endl; + } + fout <<" }" << std::endl; + fout <<" }" << std::endl; + fout <<" ]" << std::endl; + fout <<"}" << std::endl; + } + return true; + } + void TMMesh::GetIFS(Vec3 * const points, Vec3 * const triangles) + { + size_t nV = m_vertices.GetSize(); + size_t nT = m_triangles.GetSize(); + + for(size_t v = 0; v < nV; v++) + { + points[v] = m_vertices.GetData().m_pos; + m_vertices.GetData().m_id = v; + m_vertices.Next(); + } + for(size_t f = 0; f < nT; f++) + { + TMMTriangle & currentTriangle = m_triangles.GetData(); + triangles[f].X() = static_cast(currentTriangle.m_vertices[0]->GetData().m_id); + triangles[f].Y() = static_cast(currentTriangle.m_vertices[1]->GetData().m_id); + triangles[f].Z() = static_cast(currentTriangle.m_vertices[2]->GetData().m_id); + m_triangles.Next(); + } + } + void TMMesh::Clear() + { + m_vertices.Clear(); + m_edges.Clear(); + m_triangles.Clear(); + } + void TMMesh::Copy(TMMesh & mesh) + { + Clear(); + // updating the id's + size_t nV = mesh.m_vertices.GetSize(); + size_t nE = mesh. m_edges.GetSize(); + size_t nT = mesh.m_triangles.GetSize(); + for(size_t v = 0; v < nV; v++) + { + mesh.m_vertices.GetData().m_id = v; + mesh.m_vertices.Next(); + } + for(size_t e = 0; e < nE; e++) + { + mesh.m_edges.GetData().m_id = e; + mesh.m_edges.Next(); + + } + for(size_t f = 0; f < nT; f++) + { + mesh.m_triangles.GetData().m_id = f; + mesh.m_triangles.Next(); + } + // copying data + m_vertices = mesh.m_vertices; + m_edges = mesh.m_edges; + m_triangles = mesh.m_triangles; + + // generating mapping + CircularListElement ** vertexMap = new CircularListElement * [nV]; + CircularListElement ** edgeMap = new CircularListElement * [nE]; + CircularListElement ** triangleMap = new CircularListElement * [nT]; + for(size_t v = 0; v < nV; v++) + { + vertexMap[v] = m_vertices.GetHead(); + m_vertices.Next(); + } + for(size_t e = 0; e < nE; e++) + { + edgeMap[e] = m_edges.GetHead(); + m_edges.Next(); + } + for(size_t f = 0; f < nT; f++) + { + triangleMap[f] = m_triangles.GetHead(); + m_triangles.Next(); + } + + // updating pointers + for(size_t v = 0; v < nV; v++) + { + if (vertexMap[v]->GetData().m_duplicate) + { + vertexMap[v]->GetData().m_duplicate = edgeMap[vertexMap[v]->GetData().m_duplicate->GetData().m_id]; + } + } + for(size_t e = 0; e < nE; e++) + { + if (edgeMap[e]->GetData().m_newFace) + { + edgeMap[e]->GetData().m_newFace = triangleMap[edgeMap[e]->GetData().m_newFace->GetData().m_id]; + } + if (nT > 0) + { + for(int f = 0; f < 2; f++) + { + if (edgeMap[e]->GetData().m_triangles[f]) + { + edgeMap[e]->GetData().m_triangles[f] = triangleMap[edgeMap[e]->GetData().m_triangles[f]->GetData().m_id]; + } + } + } + for(int v = 0; v < 2; v++) + { + if (edgeMap[e]->GetData().m_vertices[v]) + { + edgeMap[e]->GetData().m_vertices[v] = vertexMap[edgeMap[e]->GetData().m_vertices[v]->GetData().m_id]; + } + } + } + for(size_t f = 0; f < nT; f++) + { + if (nE > 0) + { + for(int e = 0; e < 3; e++) + { + if (triangleMap[f]->GetData().m_edges[e]) + { + triangleMap[f]->GetData().m_edges[e] = edgeMap[triangleMap[f]->GetData().m_edges[e]->GetData().m_id]; + } + } + } + for(int v = 0; v < 3; v++) + { + if (triangleMap[f]->GetData().m_vertices[v]) + { + triangleMap[f]->GetData().m_vertices[v] = vertexMap[triangleMap[f]->GetData().m_vertices[v]->GetData().m_id]; + } + } + } + delete [] vertexMap; + delete [] edgeMap; + delete [] triangleMap; + + } + long IntersectRayTriangle(const Vec3 & P0, const Vec3 & dir, + const Vec3 & V0, const Vec3 & V1, + const Vec3 & V2, double &t) + { + Vec3 edge1, edge2, edge3; + double det, invDet; + edge1 = V1 - V2; + edge2 = V2 - V0; + Vec3 pvec = dir ^ edge2; + det = edge1 * pvec; + if (det == 0.0) + return 0; + invDet = 1.0/det; + Vec3 tvec = P0 - V0; + Vec3 qvec = tvec ^ edge1; + t = (edge2 * qvec) * invDet; + if (t < 0.0) + { + return 0; + } + edge3 = V0 - V1; + Vec3 I(P0 + t * dir); + Vec3 s0 = (I-V0) ^ edge3; + Vec3 s1 = (I-V1) ^ edge1; + Vec3 s2 = (I-V2) ^ edge2; + if (s0*s1 > -1e-9 && s2*s1 > -1e-9) + { + return 1; + } + return 0; + } + + bool IntersectLineLine(const Vec3 & p1, const Vec3 & p2, + const Vec3 & p3, const Vec3 & p4, + Vec3 & pa, Vec3 & pb, + double & mua, double & mub) + { + Vec3 p13,p43,p21; + double d1343,d4321,d1321,d4343,d2121; + double numer,denom; + + p13.X() = p1.X() - p3.X(); + p13.Y() = p1.Y() - p3.Y(); + p13.Z() = p1.Z() - p3.Z(); + p43.X() = p4.X() - p3.X(); + p43.Y() = p4.Y() - p3.Y(); + p43.Z() = p4.Z() - p3.Z(); + if (p43.X()==0.0 && p43.Y()==0.0 && p43.Z()==0.0) + return false; + p21.X() = p2.X() - p1.X(); + p21.Y() = p2.Y() - p1.Y(); + p21.Z() = p2.Z() - p1.Z(); + if (p21.X()==0.0 && p21.Y()==0.0 && p21.Z()==0.0) + return false; + + d1343 = p13.X() * p43.X() + p13.Y() * p43.Y() + p13.Z() * p43.Z(); + d4321 = p43.X() * p21.X() + p43.Y() * p21.Y() + p43.Z() * p21.Z(); + d1321 = p13.X() * p21.X() + p13.Y() * p21.Y() + p13.Z() * p21.Z(); + d4343 = p43.X() * p43.X() + p43.Y() * p43.Y() + p43.Z() * p43.Z(); + d2121 = p21.X() * p21.X() + p21.Y() * p21.Y() + p21.Z() * p21.Z(); + + denom = d2121 * d4343 - d4321 * d4321; + if (denom==0.0) + return false; + numer = d1343 * d4321 - d1321 * d4343; + + mua = numer / denom; + mub = (d1343 + d4321 * (mua)) / d4343; + + pa.X() = p1.X() + mua * p21.X(); + pa.Y() = p1.Y() + mua * p21.Y(); + pa.Z() = p1.Z() + mua * p21.Z(); + pb.X() = p3.X() + mub * p43.X(); + pb.Y() = p3.Y() + mub * p43.Y(); + pb.Z() = p3.Z() + mub * p43.Z(); + + return true; + } + + long IntersectRayTriangle2(const Vec3 & P0, const Vec3 & dir, + const Vec3 & V0, const Vec3 & V1, + const Vec3 & V2, double &r) + { + Vec3 u, v, n; // triangle vectors + Vec3 w0, w; // ray vectors + double a, b; // params to calc ray-plane intersect + + // get triangle edge vectors and plane normal + u = V1 - V0; + v = V2 - V0; + n = u ^ v; // cross product + if (n.GetNorm() == 0.0) // triangle is degenerate + return -1; // do not deal with this case + + w0 = P0 - V0; + a = - n * w0; + b = n * dir; + if (fabs(b) <= 0.0) { // ray is parallel to triangle plane + if (a == 0.0) // ray lies in triangle plane + return 2; + else return 0; // ray disjoint from plane + } + + // get intersect point of ray with triangle plane + r = a / b; + if (r < 0.0) // ray goes away from triangle + return 0; // => no intersect + // for a segment, also test if (r > 1.0) => no intersect + + Vec3 I = P0 + r * dir; // intersect point of ray and plane + + // is I inside T? + double uu, uv, vv, wu, wv, D; + uu = u * u; + uv = u * v; + vv = v * v; + w = I - V0; + wu = w * u; + wv = w * v; + D = uv * uv - uu * vv; + + // get and test parametric coords + double s, t; + s = (uv * wv - vv * wu) / D; + if (s < 0.0 || s > 1.0) // I is outside T + return 0; + t = (uv * wu - uu * wv) / D; + if (t < 0.0 || (s + t) > 1.0) // I is outside T + return 0; + return 1; // I is in T + } + + + bool TMMesh::CheckConsistancy() + { + size_t nE = m_edges.GetSize(); + size_t nT = m_triangles.GetSize(); + for(size_t e = 0; e < nE; e++) + { + for(int f = 0; f < 2; f++) + { + if (!m_edges.GetHead()->GetData().m_triangles[f]) + { + return false; + } + } + m_edges.Next(); + } + + for(size_t f = 0; f < nT; f++) + { + for(int e = 0; e < 3; e++) + { + int found = 0; + for(int k = 0; k < 2; k++) + { + if (m_triangles.GetHead()->GetData().m_edges[e]->GetData().m_triangles[k] == m_triangles.GetHead()) + { + found++; + } + } + if (found != 1) + { + return false; + } + } + m_triangles.Next(); + } + + return true; + } + bool TMMesh::Normalize() + { + size_t nV = m_vertices.GetSize(); + if (nV == 0) + { + return false; + } + m_barycenter = m_vertices.GetHead()->GetData().m_pos; + Vec3 min = m_barycenter; + Vec3 max = m_barycenter; + Real x, y, z; + for(size_t v = 1; v < nV; v++) + { + m_barycenter += m_vertices.GetHead()->GetData().m_pos; + x = m_vertices.GetHead()->GetData().m_pos.X(); + y = m_vertices.GetHead()->GetData().m_pos.Y(); + z = m_vertices.GetHead()->GetData().m_pos.Z(); + if ( x < min.X()) min.X() = x; + else if ( x > max.X()) max.X() = x; + if ( y < min.Y()) min.Y() = y; + else if ( y > max.Y()) max.Y() = y; + if ( z < min.Z()) min.Z() = z; + else if ( z > max.Z()) max.Z() = z; + m_vertices.Next(); + } + m_barycenter /= static_cast(nV); + m_diag = static_cast(0.001 * (max-min).GetNorm()); + const Real invDiag = static_cast(1.0 / m_diag); + if (m_diag != 0.0) + { + for(size_t v = 0; v < nV; v++) + { + m_vertices.GetHead()->GetData().m_pos = (m_vertices.GetHead()->GetData().m_pos - m_barycenter) * invDiag; + m_vertices.Next(); + } + } + return true; + } + bool TMMesh::Denormalize() + { + size_t nV = m_vertices.GetSize(); + if (nV == 0) + { + return false; + } + if (m_diag != 0.0) + { + for(size_t v = 0; v < nV; v++) + { + m_vertices.GetHead()->GetData().m_pos = m_vertices.GetHead()->GetData().m_pos * m_diag + m_barycenter; + m_vertices.Next(); + } + } + return false; + } +} diff --git a/Extras/HACD/hacdManifoldMesh.h b/Extras/HACD/hacdManifoldMesh.h new file mode 100644 index 0000000000..318ecbab6e --- /dev/null +++ b/Extras/HACD/hacdManifoldMesh.h @@ -0,0 +1,250 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) +All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once +#ifndef HACD_MANIFOLD_MESH_H +#define HACD_MANIFOLD_MESH_H +#include +#include +#include "hacdVersion.h" +#include "hacdCircularList.h" +#include "hacdVector.h" +#include +namespace HACD +{ + class TMMTriangle; + class TMMEdge; + class TMMesh; + class ICHull; + class HACD; + + class DPoint + { + public: + DPoint(Real dist=0, bool computed=false, bool distOnly=false) + :m_dist(dist), + m_computed(computed), + m_distOnly(distOnly){}; + ~DPoint(){}; + private: + Real m_dist; + bool m_computed; + bool m_distOnly; + friend class TMMTriangle; + friend class TMMesh; + friend class GraphVertex; + friend class GraphEdge; + friend class Graph; + friend class ICHull; + friend class HACD; + }; + + //! Vertex data structure used in a triangular manifold mesh (TMM). + class TMMVertex + { + public: + TMMVertex(void); + ~TMMVertex(void); + + private: + Vec3 m_pos; + long m_name; + size_t m_id; + CircularListElement * m_duplicate; // pointer to incident cone edge (or NULL) + bool m_onHull; + bool m_tag; + TMMVertex(const TMMVertex & rhs); + + friend class HACD; + friend class ICHull; + friend class TMMesh; + friend class TMMTriangle; + friend class TMMEdge; + }; + + //! Edge data structure used in a triangular manifold mesh (TMM). + class TMMEdge + { + public: + TMMEdge(void); + ~TMMEdge(void); + private: + size_t m_id; + CircularListElement * m_triangles[2]; + CircularListElement * m_vertices[2]; + CircularListElement * m_newFace; + + + TMMEdge(const TMMEdge & rhs); + + friend class HACD; + friend class ICHull; + friend class TMMTriangle; + friend class TMMVertex; + friend class TMMesh; + }; + + //! Triangle data structure used in a triangular manifold mesh (TMM). + class TMMTriangle + { + public: + TMMTriangle(void); + ~TMMTriangle(void); + private: + size_t m_id; + CircularListElement * m_edges[3]; + CircularListElement * m_vertices[3]; + std::set m_incidentPoints; + bool m_visible; + + TMMTriangle(const TMMTriangle & rhs); + + friend class HACD; + friend class ICHull; + friend class TMMesh; + friend class TMMVertex; + friend class TMMEdge; + }; + + class Material + { + public: + Material(void); + ~Material(void){} +// private: + Vec3 m_diffuseColor; + double m_ambientIntensity; + Vec3 m_specularColor; + Vec3 m_emissiveColor; + double m_shininess; + double m_transparency; + + friend class TMMesh; + friend class HACD; + }; + + //! triangular manifold mesh data structure. + class TMMesh + { + public: + + //! Returns the number of vertices> + inline size_t GetNVertices() const { return m_vertices.GetSize();} + //! Returns the number of edges + inline size_t GetNEdges() const { return m_edges.GetSize();} + //! Returns the number of triangles + inline size_t GetNTriangles() const { return m_triangles.GetSize();} + //! Returns the vertices circular list + inline const CircularList & GetVertices() const { return m_vertices;} + //! Returns the edges circular list + inline const CircularList & GetEdges() const { return m_edges;} + //! Returns the triangles circular list + inline const CircularList & GetTriangles() const { return m_triangles;} + //! Returns the vertices circular list + inline CircularList & GetVertices() { return m_vertices;} + //! Returns the edges circular list + inline CircularList & GetEdges() { return m_edges;} + //! Returns the triangles circular list + inline CircularList & GetTriangles() { return m_triangles;} + //! Add vertex to the mesh + CircularListElement * AddVertex() {return m_vertices.Add();} + //! Add vertex to the mesh + CircularListElement * AddEdge() {return m_edges.Add();} + //! Add vertex to the mesh + CircularListElement * AddTriangle() {return m_triangles.Add();} + //! Print mesh information + void Print(); + //! + void GetIFS(Vec3 * const points, Vec3 * const triangles); + //! Save mesh + bool Save(const char *fileName); + //! Save mesh to VRML 2.0 format + bool SaveVRML2(std::ofstream &fout); + //! Save mesh to VRML 2.0 format + bool SaveVRML2(std::ofstream &fout, const Material & material); + //! + void Clear(); + //! + void Copy(TMMesh & mesh); + //! + bool CheckConsistancy(); + //! + bool Normalize(); + //! + bool Denormalize(); + //! Constructor + TMMesh(void); + //! Destructor + virtual ~TMMesh(void); + + private: + CircularList m_vertices; + CircularList m_edges; + CircularList m_triangles; + Real m_diag; //>! length of the BB diagonal + Vec3 m_barycenter; //>! barycenter of the mesh + + // not defined + TMMesh(const TMMesh & rhs); + friend class ICHull; + friend class HACD; + }; + //! IntersectRayTriangle(): intersect a ray with a 3D triangle + //! Input: a ray R, and a triangle T + //! Output: *I = intersection point (when it exists) + //! 0 = disjoint (no intersect) + //! 1 = intersect in unique point I1 + long IntersectRayTriangle( const Vec3 & P0, const Vec3 & dir, + const Vec3 & V0, const Vec3 & V1, + const Vec3 & V2, double &t); + + // intersect_RayTriangle(): intersect a ray with a 3D triangle + // Input: a ray R, and a triangle T + // Output: *I = intersection point (when it exists) + // Return: -1 = triangle is degenerate (a segment or point) + // 0 = disjoint (no intersect) + // 1 = intersect in unique point I1 + // 2 = are in the same plane + long IntersectRayTriangle2(const Vec3 & P0, const Vec3 & dir, + const Vec3 & V0, const Vec3 & V1, + const Vec3 & V2, double &r); + + /* + Calculate the line segment PaPb that is the shortest route between + two lines P1P2 and P3P4. Calculate also the values of mua and mub where + Pa = P1 + mua (P2 - P1) + Pb = P3 + mub (P4 - P3) + Return FALSE if no solution exists. + */ + bool IntersectLineLine(const Vec3 & p1, const Vec3 & p2, + const Vec3 & p3, const Vec3 & p4, + Vec3 & pa, Vec3 & pb, + double & mua, double &mub); +} +#endif diff --git a/Extras/HACD/hacdVector.h b/Extras/HACD/hacdVector.h new file mode 100644 index 0000000000..0c8dd022db --- /dev/null +++ b/Extras/HACD/hacdVector.h @@ -0,0 +1,67 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once +#ifndef HACD_VECTOR_H +#define HACD_VECTOR_H +#include +#include +#include "hacdVersion.h" + +namespace HACD +{ + typedef double Real; + //! Vector dim 3. + template < typename T > class Vec3 + { + public: + T & X(); + T & Y(); + T & Z(); + const T & X() const; + const T & Y() const; + const T & Z() const; + void Normalize(); + T GetNorm() const; + void operator= (const Vec3 & rhs); + void operator+=(const Vec3 & rhs); + void operator-=(const Vec3 & rhs); + void operator-=(T a); + void operator+=(T a); + void operator/=(T a); + void operator*=(T a); + Vec3 operator^ (const Vec3 & rhs) const; + T operator* (const Vec3 & rhs) const; + Vec3 operator+ (const Vec3 & rhs) const; + Vec3 operator- (const Vec3 & rhs) const; + Vec3 operator- () const; + Vec3 operator* (T rhs) const; + Vec3 operator/ (T rhs) const; + Vec3(); + Vec3(T a); + Vec3(T x, T y, T z); + Vec3(const Vec3 & rhs); + /*virtual*/ ~Vec3(void); + + private: + T m_data[3]; + }; + template + const bool Colinear(const Vec3 & a, const Vec3 & b, const Vec3 & c); + template + const T Volume(const Vec3 & a, const Vec3 & b, const Vec3 & c, const Vec3 & d); + +} +#include "hacdVector.inl" // template implementation +#endif diff --git a/Extras/HACD/hacdVector.inl b/Extras/HACD/hacdVector.inl new file mode 100644 index 0000000000..ab0a94ddbe --- /dev/null +++ b/Extras/HACD/hacdVector.inl @@ -0,0 +1,178 @@ +#pragma once +#ifndef HACD_VECTOR_INL +#define HACD_VECTOR_INL +namespace HACD +{ + template + inline Vec3 operator*(T lhs, const Vec3 & rhs) + { + return Vec3(lhs * rhs.X(), lhs * rhs.Y(), lhs * rhs.Z()); + } + template + inline T & Vec3::X() + { + return m_data[0]; + } + template + inline T & Vec3::Y() + { + return m_data[1]; + } + template + inline T & Vec3::Z() + { + return m_data[2]; + } + template + inline const T & Vec3::X() const + { + return m_data[0]; + } + template + inline const T & Vec3::Y() const + { + return m_data[1]; + } + template + inline const T & Vec3::Z() const + { + return m_data[2]; + } + template + inline void Vec3::Normalize() + { + T n = sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]); + if (n != 0.0) (*this) /= n; + } + template + inline T Vec3::GetNorm() const + { + return sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]); + } + template + inline void Vec3::operator= (const Vec3 & rhs) + { + this->m_data[0] = rhs.m_data[0]; + this->m_data[1] = rhs.m_data[1]; + this->m_data[2] = rhs.m_data[2]; + } + template + inline void Vec3::operator+=(const Vec3 & rhs) + { + this->m_data[0] += rhs.m_data[0]; + this->m_data[1] += rhs.m_data[1]; + this->m_data[2] += rhs.m_data[2]; + } + template + inline void Vec3::operator-=(const Vec3 & rhs) + { + this->m_data[0] -= rhs.m_data[0]; + this->m_data[1] -= rhs.m_data[1]; + this->m_data[2] -= rhs.m_data[2]; + } + template + inline void Vec3::operator-=(T a) + { + this->m_data[0] -= a; + this->m_data[1] -= a; + this->m_data[2] -= a; + } + template + inline void Vec3::operator+=(T a) + { + this->m_data[0] += a; + this->m_data[1] += a; + this->m_data[2] += a; + } + template + inline void Vec3::operator/=(T a) + { + this->m_data[0] /= a; + this->m_data[1] /= a; + this->m_data[2] /= a; + } + template + inline void Vec3::operator*=(T a) + { + this->m_data[0] *= a; + this->m_data[1] *= a; + this->m_data[2] *= a; + } + template + inline Vec3 Vec3::operator^ (const Vec3 & rhs) const + { + return Vec3(m_data[1] * rhs.m_data[2] - m_data[2] * rhs.m_data[1], + m_data[2] * rhs.m_data[0] - m_data[0] * rhs.m_data[2], + m_data[0] * rhs.m_data[1] - m_data[1] * rhs.m_data[0]); + } + template + inline T Vec3::operator*(const Vec3 & rhs) const + { + return (m_data[0] * rhs.m_data[0] + m_data[1] * rhs.m_data[1] + m_data[2] * rhs.m_data[2]); + } + template + inline Vec3 Vec3::operator+(const Vec3 & rhs) const + { + return Vec3(m_data[0] + rhs.m_data[0],m_data[1] + rhs.m_data[1],m_data[2] + rhs.m_data[2]); + } + template + inline Vec3 Vec3::operator-(const Vec3 & rhs) const + { + return Vec3(m_data[0] - rhs.m_data[0],m_data[1] - rhs.m_data[1],m_data[2] - rhs.m_data[2]) ; + } + template + inline Vec3 Vec3::operator-() const + { + return Vec3(-m_data[0],-m_data[1],-m_data[2]) ; + } + + template + inline Vec3 Vec3::operator*(T rhs) const + { + return Vec3(rhs * this->m_data[0], rhs * this->m_data[1], rhs * this->m_data[2]); + } + template + inline Vec3 Vec3::operator/ (T rhs) const + { + return Vec3(m_data[0] / rhs, m_data[1] / rhs, m_data[2] / rhs); + } + template + inline Vec3::Vec3(T a) + { + m_data[0] = m_data[1] = m_data[2] = a; + } + template + inline Vec3::Vec3(T x, T y, T z) + { + m_data[0] = x; + m_data[1] = y; + m_data[2] = z; + } + template + inline Vec3::Vec3(const Vec3 & rhs) + { + m_data[0] = rhs.m_data[0]; + m_data[1] = rhs.m_data[1]; + m_data[2] = rhs.m_data[2]; + } + template + inline Vec3::~Vec3(void){}; + + template + inline Vec3::Vec3() {} + + template + inline const bool Colinear(const Vec3 & a, const Vec3 & b, const Vec3 & c) + { + return ((c.Z() - a.Z()) * (b.Y() - a.Y()) - (b.Z() - a.Z()) * (c.Y() - a.Y()) == 0.0 /*EPS*/) && + ((b.Z() - a.Z()) * (c.X() - a.X()) - (b.X() - a.X()) * (c.Z() - a.Z()) == 0.0 /*EPS*/) && + ((b.X() - a.X()) * (c.Y() - a.Y()) - (b.Y() - a.Y()) * (c.X() - a.X()) == 0.0 /*EPS*/); + } + + template + inline const T Volume(const Vec3 & a, const Vec3 & b, const Vec3 & c, const Vec3 & d) + { + return (a-d) * ((b-d) ^ (c-d)); + } +} +#endif //HACD_VECTOR_INL \ No newline at end of file diff --git a/Extras/HACD/hacdVersion.h b/Extras/HACD/hacdVersion.h new file mode 100644 index 0000000000..c9f7f28da9 --- /dev/null +++ b/Extras/HACD/hacdVersion.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) + All rights reserved. + + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once +#ifndef HACD_VERSION_H +#define HACD_VERSION_H +#define HACD_VERSION_MAJOR 0 +#define HACD_VERSION_MINOR 0 +#endif \ No newline at end of file diff --git a/Extras/HACD/premake4.lua b/Extras/HACD/premake4.lua new file mode 100644 index 0000000000..7b82929e6a --- /dev/null +++ b/Extras/HACD/premake4.lua @@ -0,0 +1,9 @@ + project "HACD" + + kind "StaticLib" + targetdir "../../lib" + includedirs {"."} + files { + "**.cpp", + "**.h" + } \ No newline at end of file diff --git a/Extras/Makefile.am b/Extras/Makefile.am new file mode 100644 index 0000000000..f4cd5eac82 --- /dev/null +++ b/Extras/Makefile.am @@ -0,0 +1,95 @@ +noinst_LIBRARIES = libgimpactutils.a libconvexdecomposition.a libHACD.a libglui.a + +libglui_a_CXXFLAGS = ${CXXFLAGS} -Iglui +libglui_a_SOURCES =\ + glui/glui_spinner.cpp\ + glui/glui_treepanel.cpp\ + glui/arcball.cpp\ + glui/glui_scrollbar.cpp\ + glui/glui_filebrowser.cpp\ + glui/glui_node.cpp\ + glui/glui_edittext.cpp\ + glui/glui_statictext.cpp\ + glui/glui_bitmaps.cpp\ + glui/algebra3.cpp\ + glui/glui_string.cpp\ + glui/glui_button.cpp\ + glui/glui_add_controls.cpp\ + glui/glui_control.cpp\ + glui/glui.cpp\ + glui/glui_listbox.cpp\ + glui/glui_checkbox.cpp\ + glui/glui_commandline.cpp\ + glui/glui_textbox.cpp\ + glui/glui_column.cpp\ + glui/glui_mouse_iaction.cpp\ + glui/glui_radio.cpp\ + glui/glui_translation.cpp\ + glui/glui_tree.cpp\ + glui/glui_rotation.cpp\ + glui/glui_panel.cpp\ + glui/glui_rollout.cpp\ + glui/glui_separator.cpp\ + glui/glui_bitmap_img_data.cpp\ + glui/quaternion.cpp\ + glui/glui_window.cpp\ + glui/glui_list.cpp\ + glui/GL/glui.h\ + glui/quaternion.h\ + glui/glui_internal.h\ + glui/glui_internal_control.h\ + glui/arcball.h\ + glui/algebra3.h + +libconvexdecomposition_a_CXXFLAGS = ${CXXFLAGS} -IConvexDecomposition/ -I../src +libconvexdecomposition_a_SOURCES =\ + ConvexDecomposition/concavity.cpp\ + ConvexDecomposition/ConvexDecomposition.cpp\ + ConvexDecomposition/vlookup.cpp\ + ConvexDecomposition/bestfit.cpp\ + ConvexDecomposition/ConvexBuilder.cpp\ + ConvexDecomposition/cd_hull.cpp\ + ConvexDecomposition/raytri.cpp\ + ConvexDecomposition/splitplane.cpp\ + ConvexDecomposition/float_math.cpp\ + ConvexDecomposition/planetri.cpp\ + ConvexDecomposition/cd_wavefront.cpp\ + ConvexDecomposition/bestfitobb.cpp\ + ConvexDecomposition/meshvolume.cpp\ + ConvexDecomposition/fitsphere.cpp\ + ConvexDecomposition/fitsphere.h\ + ConvexDecomposition/vlookup.h\ + ConvexDecomposition/concavity.h\ + ConvexDecomposition/ConvexDecomposition.h\ + ConvexDecomposition/bestfit.h\ + ConvexDecomposition/cd_vector.h\ + ConvexDecomposition/ConvexBuilder.h\ + ConvexDecomposition/cd_hull.h\ + ConvexDecomposition/raytri.h\ + ConvexDecomposition/splitplane.h\ + ConvexDecomposition/float_math.h\ + ConvexDecomposition/planetri.h\ + ConvexDecomposition/cd_wavefront.h\ + ConvexDecomposition/bestfitobb.h\ + ConvexDecomposition/meshvolume.h + +libHACD_a_CXXFLAGS = ${CXXFLAGS} -IHACD/ -I../src +libHACD_a_SOURCES =\ + HACD/hacdGraph.cpp\ + HACD/hacdHACD.cpp\ + HACD/hacdICHull.cpp\ + HACD/hacdManifoldMesh.cpp\ + HACD/hacdCircularList.h\ + HACD/hacdGraph.h\ + HACD/hacdHACD.h\ + HACD/hacdICHull.h\ + HACD/hacdManifoldMesh.h\ + HACD/hacdVector.h\ + HACD/hacdVersion.h\ + HACD/hacdCircularList.inl\ + HACD/hacdVector.inl + + +libgimpactutils_a_CXXFLAGS = ${CXXFLAGS} -I../src -IGIMPACTUtils -IConvexDecomposition +libgimpactutils_a_SOURCES = GIMPACTUtils/btGImpactConvexDecompositionShape.cpp GIMPACTUtils/btGImpactConvexDecompositionShape.h + diff --git a/Extras/Serialize/BlenderSerialize/CMakeLists.txt b/Extras/Serialize/BlenderSerialize/CMakeLists.txt new file mode 100644 index 0000000000..5b74d7447d --- /dev/null +++ b/Extras/Serialize/BlenderSerialize/CMakeLists.txt @@ -0,0 +1,7 @@ +INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src +${BULLET_PHYSICS_SOURCE_DIR}/src +${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader +${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BlenderSerialize +) + +ADD_LIBRARY(BlenderSerialize dna249.cpp dna249-64bit.cpp bBlenderFile.cpp bBlenderFile.h bMain.cpp bMain.h ) diff --git a/Extras/Serialize/BlenderSerialize/bBlenderFile.cpp b/Extras/Serialize/BlenderSerialize/bBlenderFile.cpp new file mode 100644 index 0000000000..9405fe14f1 --- /dev/null +++ b/Extras/Serialize/BlenderSerialize/bBlenderFile.cpp @@ -0,0 +1,225 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "bBlenderFile.h" +#include "bMain.h" +#include "bDefines.h" +#include "bDNA.h" +#include +#include + +// 32 && 64 bit versions +extern unsigned char DNAstr[]; +extern int DNAlen; + +extern unsigned char DNAstr64[]; +extern int DNAlen64; + + +using namespace bParse; + +bBlenderFile::bBlenderFile(const char* fileName) +:bFile(fileName, "BLENDER") +{ + mMain= new bMain(this, fileName, mVersion); +} + + + +bBlenderFile::bBlenderFile(char *memoryBuffer, int len) +:bFile(memoryBuffer,len, "BLENDER"), +mMain(0) +{ + mMain= new bMain(this, "memoryBuf", mVersion); +} + + +bBlenderFile::~bBlenderFile() +{ + delete mMain; +} + + +bMain* bBlenderFile::getMain() +{ + return mMain; +} + +// ----------------------------------------------------- // +void bBlenderFile::parseData() +{ +// printf ("Building datablocks\n"); +// printf ("Chunk size = %d\n",CHUNK_HEADER_LEN); +// printf ("File chunk size = %d\n", ChunkUtils::getOffset(mFlags)); + + const bool swap = (mFlags&FD_ENDIAN_SWAP)!=0; + + + + char *dataPtr = mFileBuffer+mDataStart; + + bChunkInd dataChunk; + dataChunk.code = 0; + + + //dataPtr += ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags); + int seek = getNextBlock(&dataChunk, dataPtr, mFlags); + //dataPtr += ChunkUtils::getOffset(mFlags); + char *dataPtrHead = 0; + + while (dataChunk.code != DNA1) + { + + + + + // one behind + if (dataChunk.code == SDNA) break; + //if (dataChunk.code == DNA1) break; + + // same as (BHEAD+DATA dependency) + dataPtrHead = dataPtr+ChunkUtils::getOffset(mFlags); + char *id = readStruct(dataPtrHead, dataChunk); + + // lookup maps + if (id) + { + m_chunkPtrPtrMap.insert(dataChunk.oldPtr, dataChunk); + mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)id); + + m_chunks.push_back(dataChunk); + // block it + bListBasePtr *listID = mMain->getListBasePtr(dataChunk.code); + if (listID) + listID->push_back((bStructHandle*)id); + } + + if (dataChunk.code == GLOB) + { + m_glob = (bStructHandle*) id; + } + + // next please! + dataPtr += seek; + + seek = getNextBlock(&dataChunk, dataPtr, mFlags); + if (seek < 0) + break; + } + +} + +void bBlenderFile::addDataBlock(char* dataBlock) +{ + mMain->addDatablock(dataBlock); +} + + + + + +// 32 && 64 bit versions +extern unsigned char DNAstr[]; +extern int DNAlen; + +//unsigned char DNAstr[]={0}; +//int DNAlen=0; + + +extern unsigned char DNAstr64[]; +extern int DNAlen64; + + +void bBlenderFile::writeDNA(FILE* fp) +{ + + bChunkInd dataChunk; + dataChunk.code = DNA1; + dataChunk.dna_nr = 0; + dataChunk.nr = 1; + + if (VOID_IS_8) + { + dataChunk.len = DNAlen64; + dataChunk.oldPtr = DNAstr64; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(DNAstr64, DNAlen64,1,fp); + } + else + { + dataChunk.len = DNAlen; + dataChunk.oldPtr = DNAstr; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(DNAstr, DNAlen,1,fp); + } +} + +void bBlenderFile::parse(int verboseMode) +{ + if (VOID_IS_8) + { + parseInternal(verboseMode,(char*)DNAstr64,DNAlen64); + } + else + { + parseInternal(verboseMode,(char*)DNAstr,DNAlen); + } +} + +// experimental +int bBlenderFile::write(const char* fileName, bool fixupPointers) +{ + FILE *fp = fopen(fileName, "wb"); + if (fp) + { + char header[SIZEOFBLENDERHEADER] ; + memcpy(header, m_headerString, 7); + int endian= 1; + endian= ((char*)&endian)[0]; + + if (endian) + { + header[7] = '_'; + } else + { + header[7] = '-'; + } + if (VOID_IS_8) + { + header[8]='V'; + } else + { + header[8]='v'; + } + + header[9] = '2'; + header[10] = '4'; + header[11] = '9'; + + fwrite(header,SIZEOFBLENDERHEADER,1,fp); + + writeChunks(fp, fixupPointers); + + writeDNA(fp); + + fclose(fp); + + } else + { + printf("Error: cannot open file %s for writing\n",fileName); + return 0; + } + return 1; +} \ No newline at end of file diff --git a/Extras/Serialize/BlenderSerialize/bBlenderFile.h b/Extras/Serialize/BlenderSerialize/bBlenderFile.h new file mode 100644 index 0000000000..3c163b9e14 --- /dev/null +++ b/Extras/Serialize/BlenderSerialize/bBlenderFile.h @@ -0,0 +1,63 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef B_BLENDER_FILE_H +#define B_BLENDER_FILE_H + + +#include "bFile.h" + +namespace bParse { + + // ----------------------------------------------------- // + class bBlenderFile : public bFile + { + + protected: + bMain* mMain; + + bStructHandle* m_glob; + + + public: + + bBlenderFile(const char* fileName); + + bBlenderFile(char *memoryBuffer, int len); + + virtual ~bBlenderFile(); + + bMain* getMain(); + + virtual void addDataBlock(char* dataBlock); + + bStructHandle* getFileGlobal() + { + return m_glob; + } + + // experimental + virtual int write(const char* fileName, bool fixupPointers = false); + + virtual void parse(int verboseMode); + + virtual void parseData(); + + virtual void writeDNA(FILE* fp); + + }; +}; + +#endif //B_BLENDER_FILE_H diff --git a/Extras/Serialize/BlenderSerialize/bMain.cpp b/Extras/Serialize/BlenderSerialize/bMain.cpp new file mode 100644 index 0000000000..fa672fbb87 --- /dev/null +++ b/Extras/Serialize/BlenderSerialize/bMain.cpp @@ -0,0 +1,392 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "bMain.h" +#include "bBlenderFile.h" +#include "bDefines.h" +#include "bChunk.h" +#include "bDNA.h" + +using namespace bParse; + + +// ----------------------------------------------------- // +bMain::bMain(bBlenderFile *filePtr, const char *baseName, int fileVersion) + : mFP(filePtr), + mVersion(fileVersion), + mName(baseName) +{ + mData.insert(ID_SCE,bListBasePtr()); + mData.insert(ID_LI,bListBasePtr()); + mData.insert(ID_OB,bListBasePtr()); + mData.insert(ID_ME,bListBasePtr()); + mData.insert(ID_CU,bListBasePtr()); + mData.insert(ID_MB,bListBasePtr()); + mData.insert(ID_MA,bListBasePtr()); + mData.insert(ID_TE,bListBasePtr()); + mData.insert(ID_IM,bListBasePtr()); + mData.insert(ID_WV,bListBasePtr()); + mData.insert(ID_LT,bListBasePtr()); + mData.insert(ID_LA,bListBasePtr()); + mData.insert(ID_CA,bListBasePtr()); + mData.insert(ID_IP,bListBasePtr()); + mData.insert(ID_KE,bListBasePtr()); + mData.insert(ID_WO,bListBasePtr()); + mData.insert(ID_SCR,bListBasePtr()); + mData.insert(ID_VF,bListBasePtr()); + mData.insert(ID_TXT,bListBasePtr()); + mData.insert(ID_SO,bListBasePtr()); + mData.insert(ID_GR,bListBasePtr()); + mData.insert(ID_AR,bListBasePtr()); + mData.insert(ID_AC,bListBasePtr()); + mData.insert(ID_NT,bListBasePtr()); + mData.insert(ID_BR,bListBasePtr()); + mData.insert(ID_SCRIPT, bListBasePtr()); +} + + +// ----------------------------------------------------- // +bMain::~bMain() +{ + // allocated data blocks! + + int sz = mPool.size(); + for (int i=0;ifirst) + return; + + base->first = mFP->findLibPointer(base->first); + if (!base->first) + { + base->last = 0; + return; + } + + void *prev = 0; + Link *l = (Link*)base->first; + while (l) + { + l->next = mFP->findLibPointer(l->next); + l->prev = l->next; + prev = l->next; + l = (Link*)l->next; + } +} + +// ------------------------------------------------------------// +bListBasePtr* bMain::getListBasePtr(int listBaseCode) +{ + bListBasePtr *ptr = _findCode(listBaseCode); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::_findCode(int code) +{ + + bListBasePtr* lbPtr = mData.find(code); + return lbPtr; +} + + +// ------------------------------------------------------------// +bListBasePtr *bMain::getScene() +{ + bListBasePtr *ptr = _findCode(ID_SCE); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getLibrary() +{ + bListBasePtr *ptr = _findCode(ID_LI); + if (!ptr) + return 0; + return ptr; +} +// ------------------------------------------------------------// +bListBasePtr *bMain::getObject() +{ + bListBasePtr *ptr = _findCode(ID_OB); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getMesh() +{ + bListBasePtr *ptr = _findCode(ID_ME); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getCurve() +{ + bListBasePtr *ptr = _findCode(ID_CU); + if (!ptr) + return 0; + return ptr; +} + + + +// ------------------------------------------------------------// +bListBasePtr *bMain::getMball() +{ + bListBasePtr *ptr = _findCode(ID_MB); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getMat() +{ + bListBasePtr *ptr = _findCode(ID_MA); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getTex() +{ + bListBasePtr *ptr = _findCode(ID_TE); + if (!ptr) + return 0; + return ptr; +} + + +// ------------------------------------------------------------// +bListBasePtr *bMain::getImage() +{ + bListBasePtr *ptr = _findCode(ID_IM); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getWave() +{ + bListBasePtr *ptr = _findCode(ID_WV); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getLatt() +{ + bListBasePtr *ptr = _findCode(ID_LT); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getLamp() +{ + bListBasePtr *ptr = _findCode(ID_LA); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getCamera() +{ + bListBasePtr *ptr = _findCode(ID_CA); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getIpo() +{ + bListBasePtr *ptr = _findCode(ID_IP); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getKey() +{ + bListBasePtr *ptr = _findCode(ID_KE); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getWorld() +{ + bListBasePtr *ptr = _findCode(ID_WO); + if (!ptr) + return 0; + return ptr; +} + + +// ------------------------------------------------------------// +bListBasePtr *bMain::getScreen() +{ + bListBasePtr *ptr = _findCode(ID_SCR); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getScript() +{ + bListBasePtr *ptr = _findCode(ID_SCRIPT); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getVfont() +{ + bListBasePtr *ptr = _findCode(ID_VF); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getText() +{ + bListBasePtr *ptr = _findCode(ID_TXT); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getSound() +{ + bListBasePtr *ptr = _findCode(ID_SO); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getGroup() +{ + bListBasePtr *ptr = _findCode(ID_GR); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getArmature() +{ + bListBasePtr *ptr = _findCode(ID_AR); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getAction() +{ + bListBasePtr *ptr = _findCode(ID_AC); + if (!ptr) + return 0; + return ptr; +} + + +// ------------------------------------------------------------// +bListBasePtr *bMain::getNodetree() +{ + bListBasePtr *ptr = _findCode(ID_NT); + if (!ptr) + return 0; + return ptr; +} + +// ------------------------------------------------------------// +bListBasePtr *bMain::getBrush() +{ + bListBasePtr *ptr = _findCode(ID_BR); + if (!ptr) + return 0; + return ptr; +} + + + +//eof diff --git a/Extras/Serialize/BlenderSerialize/bMain.h b/Extras/Serialize/BlenderSerialize/bMain.h new file mode 100644 index 0000000000..f8e9afc5b8 --- /dev/null +++ b/Extras/Serialize/BlenderSerialize/bMain.h @@ -0,0 +1,110 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __BMAIN_H__ +#define __BMAIN_H__ + +#include "bCommon.h" +#include "bChunk.h" +#include "LinearMath/btHashMap.h" + + +namespace bParse +{ + class bDNA; + + class bBlenderFile; +}; + + + +namespace bParse { + + + // ----------------------------------------------------- // + + typedef btHashMap bMainDataMap; + + + + // ----------------------------------------------------- // + class bMain + { + //private: + public: + bBlenderFile* mFP; + bListBasePtr mPool; + + int mVersion; + const char* mName; + + bMainDataMap mData; + + + + + bListBasePtr *_findCode(int code); + + public: + bMain(bBlenderFile *filePtr, const char *baseName, int fileVersion); + ~bMain(); + + int getVersion(); + const char *getName(); + + bListBasePtr *getListBasePtr(int listBaseCode); + + + bListBasePtr *getScene(); + bListBasePtr *getLibrary(); + bListBasePtr *getObject(); + bListBasePtr *getMesh(); + bListBasePtr *getCurve(); + bListBasePtr *getMball(); + bListBasePtr *getMat(); + bListBasePtr *getTex(); + bListBasePtr *getImage(); + bListBasePtr *getWave(); + bListBasePtr *getLatt(); + bListBasePtr *getLamp(); + bListBasePtr *getCamera(); + bListBasePtr *getIpo(); + bListBasePtr *getKey(); + bListBasePtr *getWorld(); + bListBasePtr *getScreen(); + bListBasePtr *getScript(); + bListBasePtr *getVfont(); + bListBasePtr *getText(); + bListBasePtr *getSound(); + bListBasePtr *getGroup(); + bListBasePtr *getArmature(); + bListBasePtr *getAction(); + bListBasePtr *getNodetree(); + bListBasePtr *getBrush(); + + + + // tracking allocated memory + void addDatablock(void *allocated); + + + // -- + + void linkList(void *listBasePtr); + }; +} + + +#endif//__BMAIN_H__ diff --git a/Extras/Serialize/BlenderSerialize/dna249-64bit.cpp b/Extras/Serialize/BlenderSerialize/dna249-64bit.cpp new file mode 100644 index 0000000000..7c56c2c470 --- /dev/null +++ b/Extras/Serialize/BlenderSerialize/dna249-64bit.cpp @@ -0,0 +1,1411 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ +unsigned char DNAstr64[]= { +83,68,78,65,78,65,77,69,119,9,0,0,42,110,101,120,116,0,42,112,114,101,118,0,42,100,97,116,97,0,42,102,105, +114,115,116,0,42,108,97,115,116,0,120,0,121,0,122,0,119,0,120,109,105,110,0,120,109,97,120,0,121,109,105,110, +0,121,109,97,120,0,42,112,111,105,110,116,101,114,0,103,114,111,117,112,0,118,97,108,0,118,97,108,50,0,110,97, +109,101,91,51,50,93,0,116,121,112,101,0,115,117,98,116,121,112,101,0,102,108,97,103,0,115,97,118,101,100,0,100, +97,116,97,0,108,101,110,0,116,111,116,97,108,108,101,110,0,42,110,101,119,105,100,0,42,108,105,98,0,110,97,109, +101,91,50,52,93,0,117,115,0,105,99,111,110,95,105,100,0,42,112,114,111,112,101,114,116,105,101,115,0,105,100,0, +42,105,100,98,108,111,99,107,0,42,102,105,108,101,100,97,116,97,0,110,97,109,101,91,50,52,48,93,0,102,105,108, +101,110,97,109,101,91,50,52,48,93,0,116,111,116,0,112,97,100,0,42,112,97,114,101,110,116,0,119,91,50,93,0, +104,91,50,93,0,99,104,97,110,103,101,100,91,50,93,0,112,97,100,48,0,112,97,100,49,0,42,114,101,99,116,91, +50,93,0,42,111,98,0,98,108,111,99,107,116,121,112,101,0,97,100,114,99,111,100,101,0,110,97,109,101,91,49,50, +56,93,0,42,98,112,0,42,98,101,122,116,0,109,97,120,114,99,116,0,116,111,116,114,99,116,0,118,97,114,116,121, +112,101,0,116,111,116,118,101,114,116,0,105,112,111,0,101,120,116,114,97,112,0,114,116,0,98,105,116,109,97,115,107, +0,115,108,105,100,101,95,109,105,110,0,115,108,105,100,101,95,109,97,120,0,99,117,114,118,97,108,0,42,100,114,105, +118,101,114,0,99,117,114,118,101,0,99,117,114,0,115,104,111,119,107,101,121,0,109,117,116,101,105,112,111,0,112,111, +115,0,114,101,108,97,116,105,118,101,0,116,111,116,101,108,101,109,0,112,97,100,50,0,42,119,101,105,103,104,116,115, +0,118,103,114,111,117,112,91,51,50,93,0,115,108,105,100,101,114,109,105,110,0,115,108,105,100,101,114,109,97,120,0, +42,114,101,102,107,101,121,0,101,108,101,109,115,116,114,91,51,50,93,0,101,108,101,109,115,105,122,101,0,98,108,111, +99,107,0,42,105,112,111,0,42,102,114,111,109,0,116,111,116,107,101,121,0,115,108,117,114,112,104,0,42,42,115,99, +114,105,112,116,115,0,42,102,108,97,103,0,97,99,116,115,99,114,105,112,116,0,116,111,116,115,99,114,105,112,116,0, +42,108,105,110,101,0,42,102,111,114,109,97,116,0,98,108,101,110,0,108,105,110,101,110,111,0,115,116,97,114,116,0, +101,110,100,0,102,108,97,103,115,0,99,111,108,111,114,91,52,93,0,112,97,100,91,52,93,0,42,110,97,109,101,0, +110,108,105,110,101,115,0,108,105,110,101,115,0,42,99,117,114,108,0,42,115,101,108,108,0,99,117,114,99,0,115,101, +108,99,0,109,97,114,107,101,114,115,0,42,117,110,100,111,95,98,117,102,0,117,110,100,111,95,112,111,115,0,117,110, +100,111,95,108,101,110,0,42,99,111,109,112,105,108,101,100,0,109,116,105,109,101,0,115,105,122,101,0,115,101,101,107, +0,112,97,115,115,101,112,97,114,116,97,108,112,104,97,0,97,110,103,108,101,0,99,108,105,112,115,116,97,0,99,108, +105,112,101,110,100,0,108,101,110,115,0,111,114,116,104,111,95,115,99,97,108,101,0,100,114,97,119,115,105,122,101,0, +115,104,105,102,116,120,0,115,104,105,102,116,121,0,89,70,95,100,111,102,100,105,115,116,0,89,70,95,97,112,101,114, +116,117,114,101,0,89,70,95,98,107,104,116,121,112,101,0,89,70,95,98,107,104,98,105,97,115,0,89,70,95,98,107, +104,114,111,116,0,115,99,114,105,112,116,108,105,110,107,0,42,100,111,102,95,111,98,0,102,114,97,109,101,110,114,0, +102,114,97,109,101,115,0,111,102,102,115,101,116,0,115,102,114,97,0,102,105,101,95,105,109,97,0,99,121,99,108,0, +111,107,0,109,117,108,116,105,95,105,110,100,101,120,0,108,97,121,101,114,0,112,97,115,115,0,109,101,110,117,110,114, +0,105,98,117,102,115,0,42,103,112,117,116,101,120,116,117,114,101,0,42,97,110,105,109,0,42,114,114,0,115,111,117, +114,99,101,0,108,97,115,116,102,114,97,109,101,0,116,112,97,103,101,102,108,97,103,0,116,111,116,98,105,110,100,0, +120,114,101,112,0,121,114,101,112,0,116,119,115,116,97,0,116,119,101,110,100,0,98,105,110,100,99,111,100,101,0,42, +114,101,112,98,105,110,100,0,42,112,97,99,107,101,100,102,105,108,101,0,42,112,114,101,118,105,101,119,0,108,97,115, +116,117,112,100,97,116,101,0,108,97,115,116,117,115,101,100,0,97,110,105,109,115,112,101,101,100,0,103,101,110,95,120, +0,103,101,110,95,121,0,103,101,110,95,116,121,112,101,0,97,115,112,120,0,97,115,112,121,0,42,118,110,111,100,101, +0,116,101,120,99,111,0,109,97,112,116,111,0,109,97,112,116,111,110,101,103,0,98,108,101,110,100,116,121,112,101,0, +42,111,98,106,101,99,116,0,42,116,101,120,0,117,118,110,97,109,101,91,51,50,93,0,112,114,111,106,120,0,112,114, +111,106,121,0,112,114,111,106,122,0,109,97,112,112,105,110,103,0,111,102,115,91,51,93,0,115,105,122,101,91,51,93, +0,116,101,120,102,108,97,103,0,99,111,108,111,114,109,111,100,101,108,0,112,109,97,112,116,111,0,112,109,97,112,116, +111,110,101,103,0,110,111,114,109,97,112,115,112,97,99,101,0,119,104,105,99,104,95,111,117,116,112,117,116,0,112,97, +100,91,50,93,0,114,0,103,0,98,0,107,0,100,101,102,95,118,97,114,0,99,111,108,102,97,99,0,110,111,114,102, +97,99,0,118,97,114,102,97,99,0,100,105,115,112,102,97,99,0,119,97,114,112,102,97,99,0,110,97,109,101,91,49, +54,48,93,0,42,104,97,110,100,108,101,0,42,112,110,97,109,101,0,42,115,116,110,97,109,101,115,0,115,116,121,112, +101,115,0,118,97,114,115,0,42,118,97,114,115,116,114,0,42,114,101,115,117,108,116,0,42,99,102,114,97,0,100,97, +116,97,91,51,50,93,0,40,42,100,111,105,116,41,40,41,0,40,42,105,110,115,116,97,110,99,101,95,105,110,105,116, +41,40,41,0,40,42,99,97,108,108,98,97,99,107,41,40,41,0,118,101,114,115,105,111,110,0,97,0,105,112,111,116, +121,112,101,0,42,105,109,97,0,42,99,117,98,101,91,54,93,0,105,109,97,116,91,52,93,91,52,93,0,111,98,105, +109,97,116,91,51,93,91,51,93,0,115,116,121,112,101,0,118,105,101,119,115,99,97,108,101,0,110,111,116,108,97,121, +0,99,117,98,101,114,101,115,0,100,101,112,116,104,0,114,101,99,97,108,99,0,108,97,115,116,115,105,122,101,0,110, +111,105,115,101,115,105,122,101,0,116,117,114,98,117,108,0,98,114,105,103,104,116,0,99,111,110,116,114,97,115,116,0, +114,102,97,99,0,103,102,97,99,0,98,102,97,99,0,102,105,108,116,101,114,115,105,122,101,0,109,103,95,72,0,109, +103,95,108,97,99,117,110,97,114,105,116,121,0,109,103,95,111,99,116,97,118,101,115,0,109,103,95,111,102,102,115,101, +116,0,109,103,95,103,97,105,110,0,100,105,115,116,95,97,109,111,117,110,116,0,110,115,95,111,117,116,115,99,97,108, +101,0,118,110,95,119,49,0,118,110,95,119,50,0,118,110,95,119,51,0,118,110,95,119,52,0,118,110,95,109,101,120, +112,0,118,110,95,100,105,115,116,109,0,118,110,95,99,111,108,116,121,112,101,0,110,111,105,115,101,100,101,112,116,104, +0,110,111,105,115,101,116,121,112,101,0,110,111,105,115,101,98,97,115,105,115,0,110,111,105,115,101,98,97,115,105,115, +50,0,105,109,97,102,108,97,103,0,99,114,111,112,120,109,105,110,0,99,114,111,112,121,109,105,110,0,99,114,111,112, +120,109,97,120,0,99,114,111,112,121,109,97,120,0,120,114,101,112,101,97,116,0,121,114,101,112,101,97,116,0,101,120, +116,101,110,100,0,99,104,101,99,107,101,114,100,105,115,116,0,110,97,98,108,97,0,105,117,115,101,114,0,42,110,111, +100,101,116,114,101,101,0,42,112,108,117,103,105,110,0,42,99,111,98,97,0,42,101,110,118,0,117,115,101,95,110,111, +100,101,115,0,112,97,100,91,55,93,0,108,111,99,91,51,93,0,114,111,116,91,51,93,0,109,97,116,91,52,93,91, +52,93,0,109,105,110,91,51,93,0,109,97,120,91,51,93,0,112,97,100,51,0,109,111,100,101,0,116,111,116,101,120, +0,115,104,100,119,114,0,115,104,100,119,103,0,115,104,100,119,98,0,115,104,100,119,112,97,100,0,101,110,101,114,103, +121,0,100,105,115,116,0,115,112,111,116,115,105,122,101,0,115,112,111,116,98,108,101,110,100,0,104,97,105,110,116,0, +97,116,116,49,0,97,116,116,50,0,42,99,117,114,102,97,108,108,111,102,102,0,102,97,108,108,111,102,102,95,116,121, +112,101,0,115,104,97,100,115,112,111,116,115,105,122,101,0,98,105,97,115,0,115,111,102,116,0,98,117,102,115,105,122, +101,0,115,97,109,112,0,98,117,102,102,101,114,115,0,102,105,108,116,101,114,116,121,112,101,0,98,117,102,102,108,97, +103,0,98,117,102,116,121,112,101,0,114,97,121,95,115,97,109,112,0,114,97,121,95,115,97,109,112,121,0,114,97,121, +95,115,97,109,112,122,0,114,97,121,95,115,97,109,112,95,116,121,112,101,0,97,114,101,97,95,115,104,97,112,101,0, +97,114,101,97,95,115,105,122,101,0,97,114,101,97,95,115,105,122,101,121,0,97,114,101,97,95,115,105,122,101,122,0, +97,100,97,112,116,95,116,104,114,101,115,104,0,114,97,121,95,115,97,109,112,95,109,101,116,104,111,100,0,116,101,120, +97,99,116,0,115,104,97,100,104,97,108,111,115,116,101,112,0,115,117,110,95,101,102,102,101,99,116,95,116,121,112,101, +0,115,107,121,98,108,101,110,100,116,121,112,101,0,104,111,114,105,122,111,110,95,98,114,105,103,104,116,110,101,115,115, +0,115,112,114,101,97,100,0,115,117,110,95,98,114,105,103,104,116,110,101,115,115,0,115,117,110,95,115,105,122,101,0, +98,97,99,107,115,99,97,116,116,101,114,101,100,95,108,105,103,104,116,0,115,117,110,95,105,110,116,101,110,115,105,116, +121,0,97,116,109,95,116,117,114,98,105,100,105,116,121,0,97,116,109,95,105,110,115,99,97,116,116,101,114,105,110,103, +95,102,97,99,116,111,114,0,97,116,109,95,101,120,116,105,110,99,116,105,111,110,95,102,97,99,116,111,114,0,97,116, +109,95,100,105,115,116,97,110,99,101,95,102,97,99,116,111,114,0,115,107,121,98,108,101,110,100,102,97,99,0,115,107, +121,95,101,120,112,111,115,117,114,101,0,115,107,121,95,99,111,108,111,114,115,112,97,99,101,0,112,97,100,52,0,89, +70,95,110,117,109,112,104,111,116,111,110,115,0,89,70,95,110,117,109,115,101,97,114,99,104,0,89,70,95,112,104,100, +101,112,116,104,0,89,70,95,117,115,101,113,109,99,0,89,70,95,98,117,102,115,105,122,101,0,89,70,95,112,97,100, +0,89,70,95,99,97,117,115,116,105,99,98,108,117,114,0,89,70,95,108,116,114,97,100,105,117,115,0,89,70,95,103, +108,111,119,105,110,116,0,89,70,95,103,108,111,119,111,102,115,0,89,70,95,103,108,111,119,116,121,112,101,0,89,70, +95,112,97,100,50,0,42,109,116,101,120,91,49,56,93,0,115,112,101,99,114,0,115,112,101,99,103,0,115,112,101,99, +98,0,109,105,114,114,0,109,105,114,103,0,109,105,114,98,0,97,109,98,114,0,97,109,98,98,0,97,109,98,103,0, +97,109,98,0,101,109,105,116,0,97,110,103,0,115,112,101,99,116,114,97,0,114,97,121,95,109,105,114,114,111,114,0, +97,108,112,104,97,0,114,101,102,0,115,112,101,99,0,122,111,102,102,115,0,97,100,100,0,116,114,97,110,115,108,117, +99,101,110,99,121,0,102,114,101,115,110,101,108,95,109,105,114,0,102,114,101,115,110,101,108,95,109,105,114,95,105,0, +102,114,101,115,110,101,108,95,116,114,97,0,102,114,101,115,110,101,108,95,116,114,97,95,105,0,102,105,108,116,101,114, +0,116,120,95,108,105,109,105,116,0,116,120,95,102,97,108,108,111,102,102,0,114,97,121,95,100,101,112,116,104,0,114, +97,121,95,100,101,112,116,104,95,116,114,97,0,104,97,114,0,115,101,101,100,49,0,115,101,101,100,50,0,103,108,111, +115,115,95,109,105,114,0,103,108,111,115,115,95,116,114,97,0,115,97,109,112,95,103,108,111,115,115,95,109,105,114,0, +115,97,109,112,95,103,108,111,115,115,95,116,114,97,0,97,100,97,112,116,95,116,104,114,101,115,104,95,109,105,114,0, +97,100,97,112,116,95,116,104,114,101,115,104,95,116,114,97,0,97,110,105,115,111,95,103,108,111,115,115,95,109,105,114, +0,100,105,115,116,95,109,105,114,0,102,97,100,101,116,111,95,109,105,114,0,115,104,97,100,101,95,102,108,97,103,0, +109,111,100,101,95,108,0,102,108,97,114,101,99,0,115,116,97,114,99,0,108,105,110,101,99,0,114,105,110,103,99,0, +104,97,115,105,122,101,0,102,108,97,114,101,115,105,122,101,0,115,117,98,115,105,122,101,0,102,108,97,114,101,98,111, +111,115,116,0,115,116,114,97,110,100,95,115,116,97,0,115,116,114,97,110,100,95,101,110,100,0,115,116,114,97,110,100, +95,101,97,115,101,0,115,116,114,97,110,100,95,115,117,114,102,110,111,114,0,115,116,114,97,110,100,95,109,105,110,0, +115,116,114,97,110,100,95,119,105,100,116,104,102,97,100,101,0,115,116,114,97,110,100,95,117,118,110,97,109,101,91,51, +50,93,0,115,98,105,97,115,0,108,98,105,97,115,0,115,104,97,100,95,97,108,112,104,97,0,115,101,112,116,101,120, +0,114,103,98,115,101,108,0,112,114,95,116,121,112,101,0,112,114,95,98,97,99,107,0,112,114,95,108,97,109,112,0, +109,108,95,102,108,97,103,0,100,105,102,102,95,115,104,97,100,101,114,0,115,112,101,99,95,115,104,97,100,101,114,0, +114,111,117,103,104,110,101,115,115,0,114,101,102,114,97,99,0,112,97,114,97,109,91,52,93,0,114,109,115,0,100,97, +114,107,110,101,115,115,0,42,114,97,109,112,95,99,111,108,0,42,114,97,109,112,95,115,112,101,99,0,114,97,109,112, +105,110,95,99,111,108,0,114,97,109,112,105,110,95,115,112,101,99,0,114,97,109,112,98,108,101,110,100,95,99,111,108, +0,114,97,109,112,98,108,101,110,100,95,115,112,101,99,0,114,97,109,112,95,115,104,111,119,0,114,97,109,112,102,97, +99,95,99,111,108,0,114,97,109,112,102,97,99,95,115,112,101,99,0,42,103,114,111,117,112,0,102,114,105,99,116,105, +111,110,0,102,104,0,114,101,102,108,101,99,116,0,102,104,100,105,115,116,0,120,121,102,114,105,99,116,0,100,121,110, +97,109,111,100,101,0,115,115,115,95,114,97,100,105,117,115,91,51,93,0,115,115,115,95,99,111,108,91,51,93,0,115, +115,115,95,101,114,114,111,114,0,115,115,115,95,115,99,97,108,101,0,115,115,115,95,105,111,114,0,115,115,115,95,99, +111,108,102,97,99,0,115,115,115,95,116,101,120,102,97,99,0,115,115,115,95,102,114,111,110,116,0,115,115,115,95,98, +97,99,107,0,115,115,115,95,102,108,97,103,0,115,115,115,95,112,114,101,115,101,116,0,89,70,95,97,114,0,89,70, +95,97,103,0,89,70,95,97,98,0,89,70,95,100,115,99,97,108,101,0,89,70,95,100,112,119,114,0,89,70,95,100, +115,109,112,0,89,70,95,112,114,101,115,101,116,0,89,70,95,100,106,105,116,0,103,112,117,109,97,116,101,114,105,97, +108,0,110,97,109,101,91,50,53,54,93,0,115,99,97,108,101,0,42,98,98,0,105,49,0,106,49,0,107,49,0,105, +50,0,106,50,0,107,50,0,115,101,108,99,111,108,49,0,115,101,108,99,111,108,50,0,113,117,97,116,91,52,93,0, +101,120,112,120,0,101,120,112,121,0,101,120,112,122,0,114,97,100,0,114,97,100,50,0,115,0,42,109,97,116,0,42, +105,109,97,116,0,101,108,101,109,115,0,100,105,115,112,0,42,42,109,97,116,0,116,111,116,99,111,108,0,119,105,114, +101,115,105,122,101,0,114,101,110,100,101,114,115,105,122,101,0,116,104,114,101,115,104,0,118,101,99,91,51,93,91,51, +93,0,97,108,102,97,0,119,101,105,103,104,116,0,114,97,100,105,117,115,0,104,49,0,104,50,0,102,49,0,102,50, +0,102,51,0,104,105,100,101,0,118,101,99,91,52,93,0,109,97,116,95,110,114,0,112,110,116,115,117,0,112,110,116, +115,118,0,114,101,115,111,108,117,0,114,101,115,111,108,118,0,111,114,100,101,114,117,0,111,114,100,101,114,118,0,102, +108,97,103,117,0,102,108,97,103,118,0,42,107,110,111,116,115,117,0,42,107,110,111,116,115,118,0,116,105,108,116,95, +105,110,116,101,114,112,0,114,97,100,105,117,115,95,105,110,116,101,114,112,0,99,104,97,114,105,100,120,0,107,101,114, +110,0,104,0,110,117,114,98,0,42,98,101,118,111,98,106,0,42,116,97,112,101,114,111,98,106,0,42,116,101,120,116, +111,110,99,117,114,118,101,0,42,112,97,116,104,0,42,107,101,121,0,98,101,118,0,112,97,116,104,108,101,110,0,98, +101,118,114,101,115,111,108,0,119,105,100,116,104,0,101,120,116,49,0,101,120,116,50,0,114,101,115,111,108,117,95,114, +101,110,0,114,101,115,111,108,118,95,114,101,110,0,115,112,97,99,101,109,111,100,101,0,115,112,97,99,105,110,103,0, +108,105,110,101,100,105,115,116,0,115,104,101,97,114,0,102,115,105,122,101,0,119,111,114,100,115,112,97,99,101,0,117, +108,112,111,115,0,117,108,104,101,105,103,104,116,0,120,111,102,0,121,111,102,0,108,105,110,101,119,105,100,116,104,0, +42,115,116,114,0,102,97,109,105,108,121,91,50,52,93,0,42,118,102,111,110,116,0,42,118,102,111,110,116,98,0,42, +118,102,111,110,116,105,0,42,118,102,111,110,116,98,105,0,115,101,112,99,104,97,114,0,116,111,116,98,111,120,0,97, +99,116,98,111,120,0,42,116,98,0,115,101,108,115,116,97,114,116,0,115,101,108,101,110,100,0,42,115,116,114,105,110, +102,111,0,99,117,114,105,110,102,111,0,101,102,102,101,99,116,0,42,109,102,97,99,101,0,42,109,116,102,97,99,101, +0,42,116,102,97,99,101,0,42,109,118,101,114,116,0,42,109,101,100,103,101,0,42,100,118,101,114,116,0,42,109,99, +111,108,0,42,109,115,116,105,99,107,121,0,42,116,101,120,99,111,109,101,115,104,0,42,109,115,101,108,101,99,116,0, +118,100,97,116,97,0,101,100,97,116,97,0,102,100,97,116,97,0,116,111,116,101,100,103,101,0,116,111,116,102,97,99, +101,0,116,111,116,115,101,108,101,99,116,0,97,99,116,95,102,97,99,101,0,99,117,98,101,109,97,112,115,105,122,101, +0,115,109,111,111,116,104,114,101,115,104,0,115,117,98,100,105,118,0,115,117,98,100,105,118,114,0,115,117,98,115,117, +114,102,116,121,112,101,0,42,109,114,0,42,112,118,0,42,116,112,97,103,101,0,117,118,91,52,93,91,50,93,0,99, +111,108,91,52,93,0,116,114,97,110,115,112,0,116,105,108,101,0,117,110,119,114,97,112,0,118,49,0,118,50,0,118, +51,0,118,52,0,101,100,99,111,100,101,0,99,114,101,97,115,101,0,98,119,101,105,103,104,116,0,100,101,102,95,110, +114,0,42,100,119,0,116,111,116,119,101,105,103,104,116,0,99,111,91,51,93,0,110,111,91,51,93,0,112,97,100,91, +51,93,0,117,118,91,50,93,0,99,111,91,50,93,0,105,110,100,101,120,0,102,0,105,0,115,91,50,53,54,93,0, +118,91,52,93,0,109,105,100,0,118,91,50,93,0,42,102,97,99,101,115,0,42,99,111,108,102,97,99,101,115,0,42, +101,100,103,101,115,0,42,101,100,103,101,95,98,111,117,110,100,97,114,121,95,115,116,97,116,101,115,0,42,118,101,114, +116,95,101,100,103,101,95,109,97,112,0,42,118,101,114,116,95,102,97,99,101,95,109,97,112,0,42,109,97,112,95,109, +101,109,0,42,118,101,114,116,115,0,108,101,118,101,108,115,0,108,101,118,101,108,95,99,111,117,110,116,0,99,117,114, +114,101,110,116,0,110,101,119,108,118,108,0,101,100,103,101,108,118,108,0,112,105,110,108,118,108,0,114,101,110,100,101, +114,108,118,108,0,117,115,101,95,99,111,108,0,42,101,100,103,101,95,102,108,97,103,115,0,42,101,100,103,101,95,99, +114,101,97,115,101,115,0,42,118,101,114,116,95,109,97,112,0,42,101,100,103,101,95,109,97,112,0,42,111,108,100,95, +102,97,99,101,115,0,42,111,108,100,95,101,100,103,101,115,0,42,101,114,114,111,114,0,109,111,100,105,102,105,101,114, +0,115,117,98,100,105,118,84,121,112,101,0,114,101,110,100,101,114,76,101,118,101,108,115,0,42,101,109,67,97,99,104, +101,0,42,109,67,97,99,104,101,0,100,101,102,97,120,105,115,0,112,97,100,91,54,93,0,108,101,110,103,116,104,0, +114,97,110,100,111,109,105,122,101,0,115,101,101,100,0,42,111,98,95,97,114,109,0,42,115,116,97,114,116,95,99,97, +112,0,42,101,110,100,95,99,97,112,0,42,99,117,114,118,101,95,111,98,0,42,111,102,102,115,101,116,95,111,98,0, +111,102,102,115,101,116,91,51,93,0,115,99,97,108,101,91,51,93,0,109,101,114,103,101,95,100,105,115,116,0,102,105, +116,95,116,121,112,101,0,111,102,102,115,101,116,95,116,121,112,101,0,99,111,117,110,116,0,97,120,105,115,0,116,111, +108,101,114,97,110,99,101,0,42,109,105,114,114,111,114,95,111,98,0,115,112,108,105,116,95,97,110,103,108,101,0,118, +97,108,117,101,0,114,101,115,0,118,97,108,95,102,108,97,103,115,0,108,105,109,95,102,108,97,103,115,0,101,95,102, +108,97,103,115,0,98,101,118,101,108,95,97,110,103,108,101,0,100,101,102,103,114,112,95,110,97,109,101,91,51,50,93, +0,42,116,101,120,116,117,114,101,0,115,116,114,101,110,103,116,104,0,100,105,114,101,99,116,105,111,110,0,109,105,100, +108,101,118,101,108,0,116,101,120,109,97,112,112,105,110,103,0,42,109,97,112,95,111,98,106,101,99,116,0,117,118,108, +97,121,101,114,95,110,97,109,101,91,51,50,93,0,117,118,108,97,121,101,114,95,116,109,112,0,42,112,114,111,106,101, +99,116,111,114,115,91,49,48,93,0,42,105,109,97,103,101,0,110,117,109,95,112,114,111,106,101,99,116,111,114,115,0, +97,115,112,101,99,116,120,0,97,115,112,101,99,116,121,0,112,101,114,99,101,110,116,0,102,97,99,101,67,111,117,110, +116,0,102,97,99,0,114,101,112,101,97,116,0,42,111,98,106,101,99,116,99,101,110,116,101,114,0,115,116,97,114,116, +120,0,115,116,97,114,116,121,0,104,101,105,103,104,116,0,110,97,114,114,111,119,0,115,112,101,101,100,0,100,97,109, +112,0,102,97,108,108,111,102,102,0,116,105,109,101,111,102,102,115,0,108,105,102,101,116,105,109,101,0,100,101,102,111, +114,109,102,108,97,103,0,109,117,108,116,105,0,42,112,114,101,118,67,111,115,0,112,97,114,101,110,116,105,110,118,91, +52,93,91,52,93,0,99,101,110,116,91,51,93,0,42,105,110,100,101,120,97,114,0,116,111,116,105,110,100,101,120,0, +102,111,114,99,101,0,42,99,108,111,116,104,79,98,106,101,99,116,0,42,115,105,109,95,112,97,114,109,115,0,42,99, +111,108,108,95,112,97,114,109,115,0,42,112,111,105,110,116,95,99,97,99,104,101,0,42,120,0,42,120,110,101,119,0, +42,120,111,108,100,0,42,99,117,114,114,101,110,116,95,120,110,101,119,0,42,99,117,114,114,101,110,116,95,120,0,42, +99,117,114,114,101,110,116,95,118,0,42,109,102,97,99,101,115,0,110,117,109,118,101,114,116,115,0,110,117,109,102,97, +99,101,115,0,97,98,115,111,114,112,116,105,111,110,0,116,105,109,101,0,42,98,118,104,116,114,101,101,0,42,100,109, +0,111,112,101,114,97,116,105,111,110,0,118,101,114,116,101,120,0,116,111,116,105,110,102,108,117,101,110,99,101,0,103, +114,105,100,115,105,122,101,0,110,101,101,100,98,105,110,100,0,42,98,105,110,100,119,101,105,103,104,116,115,0,42,98, +105,110,100,99,111,115,0,116,111,116,99,97,103,101,118,101,114,116,0,42,100,121,110,103,114,105,100,0,42,100,121,110, +105,110,102,108,117,101,110,99,101,115,0,42,100,121,110,118,101,114,116,115,0,42,112,97,100,50,0,100,121,110,103,114, +105,100,115,105,122,101,0,100,121,110,99,101,108,108,109,105,110,91,51,93,0,100,121,110,99,101,108,108,119,105,100,116, +104,0,98,105,110,100,109,97,116,91,52,93,91,52,93,0,42,112,115,121,115,0,116,111,116,100,109,118,101,114,116,0, +116,111,116,100,109,101,100,103,101,0,116,111,116,100,109,102,97,99,101,0,112,115,121,115,0,114,116,91,50,93,0,42, +102,97,99,101,112,97,0,118,103,114,111,117,112,0,112,114,111,116,101,99,116,0,42,102,115,115,0,42,116,97,114,103, +101,116,0,42,97,117,120,84,97,114,103,101,116,0,118,103,114,111,117,112,95,110,97,109,101,91,51,50,93,0,107,101, +101,112,68,105,115,116,0,115,104,114,105,110,107,84,121,112,101,0,115,104,114,105,110,107,79,112,116,115,0,112,114,111, +106,65,120,105,115,0,115,117,98,115,117,114,102,76,101,118,101,108,115,0,42,111,114,105,103,105,110,0,102,97,99,116, +111,114,0,108,105,109,105,116,91,50,93,0,111,114,105,103,105,110,79,112,116,115,0,112,110,116,115,119,0,111,112,110, +116,115,117,0,111,112,110,116,115,118,0,111,112,110,116,115,119,0,116,121,112,101,117,0,116,121,112,101,118,0,116,121, +112,101,119,0,102,117,0,102,118,0,102,119,0,100,117,0,100,118,0,100,119,0,42,100,101,102,0,118,101,99,91,56, +93,91,51,93,0,112,97,114,116,121,112,101,0,112,97,114,49,0,112,97,114,50,0,112,97,114,51,0,112,97,114,115, +117,98,115,116,114,91,51,50,93,0,42,116,114,97,99,107,0,42,112,114,111,120,121,0,42,112,114,111,120,121,95,103, +114,111,117,112,0,42,112,114,111,120,121,95,102,114,111,109,0,42,97,99,116,105,111,110,0,42,112,111,115,101,108,105, +98,0,42,112,111,115,101,0,99,111,110,115,116,114,97,105,110,116,67,104,97,110,110,101,108,115,0,100,101,102,98,97, +115,101,0,109,111,100,105,102,105,101,114,115,0,100,108,111,99,91,51,93,0,111,114,105,103,91,51,93,0,100,115,105, +122,101,91,51,93,0,100,114,111,116,91,51,93,0,111,98,109,97,116,91,52,93,91,52,93,0,99,111,110,115,116,105, +110,118,91,52,93,91,52,93,0,108,97,121,0,99,111,108,98,105,116,115,0,116,114,97,110,115,102,108,97,103,0,105, +112,111,102,108,97,103,0,116,114,97,99,107,102,108,97,103,0,117,112,102,108,97,103,0,110,108,97,102,108,97,103,0, +112,114,111,116,101,99,116,102,108,97,103,0,105,112,111,119,105,110,0,115,99,97,102,108,97,103,0,115,99,97,118,105, +115,102,108,97,103,0,98,111,117,110,100,116,121,112,101,0,100,117,112,111,110,0,100,117,112,111,102,102,0,100,117,112, +115,116,97,0,100,117,112,101,110,100,0,115,102,0,99,116,105,109,101,0,109,97,115,115,0,100,97,109,112,105,110,103, +0,105,110,101,114,116,105,97,0,102,111,114,109,102,97,99,116,111,114,0,114,100,97,109,112,105,110,103,0,115,105,122, +101,102,97,99,0,109,97,114,103,105,110,0,109,97,120,95,118,101,108,0,109,105,110,95,118,101,108,0,109,95,99,111, +110,116,97,99,116,80,114,111,99,101,115,115,105,110,103,84,104,114,101,115,104,111,108,100,0,100,116,0,100,116,120,0, +97,99,116,99,111,108,0,101,109,112,116,121,95,100,114,97,119,116,121,112,101,0,112,97,100,49,91,51,93,0,101,109, +112,116,121,95,100,114,97,119,115,105,122,101,0,100,117,112,102,97,99,101,115,99,97,0,112,114,111,112,0,115,101,110, +115,111,114,115,0,99,111,110,116,114,111,108,108,101,114,115,0,97,99,116,117,97,116,111,114,115,0,98,98,115,105,122, +101,91,51,93,0,97,99,116,100,101,102,0,103,97,109,101,102,108,97,103,0,103,97,109,101,102,108,97,103,50,0,42, +98,115,111,102,116,0,115,111,102,116,102,108,97,103,0,97,110,105,115,111,116,114,111,112,105,99,70,114,105,99,116,105, +111,110,91,51,93,0,99,111,110,115,116,114,97,105,110,116,115,0,110,108,97,115,116,114,105,112,115,0,104,111,111,107, +115,0,112,97,114,116,105,99,108,101,115,121,115,116,101,109,0,42,112,100,0,42,115,111,102,116,0,42,100,117,112,95, +103,114,111,117,112,0,102,108,117,105,100,115,105,109,70,108,97,103,0,114,101,115,116,114,105,99,116,102,108,97,103,0, +115,104,97,112,101,110,114,0,115,104,97,112,101,102,108,97,103,0,114,101,99,97,108,99,111,0,98,111,100,121,95,116, +121,112,101,0,42,102,108,117,105,100,115,105,109,83,101,116,116,105,110,103,115,0,42,100,101,114,105,118,101,100,68,101, +102,111,114,109,0,42,100,101,114,105,118,101,100,70,105,110,97,108,0,108,97,115,116,68,97,116,97,77,97,115,107,0, +115,116,97,116,101,0,105,110,105,116,95,115,116,97,116,101,0,103,112,117,108,97,109,112,0,99,117,114,105,110,100,101, +120,0,97,99,116,105,118,101,0,100,101,102,108,101,99,116,0,102,111,114,99,101,102,105,101,108,100,0,112,100,101,102, +95,100,97,109,112,0,112,100,101,102,95,114,100,97,109,112,0,112,100,101,102,95,112,101,114,109,0,112,100,101,102,95, +102,114,105,99,116,0,112,100,101,102,95,114,102,114,105,99,116,0,102,95,115,116,114,101,110,103,116,104,0,102,95,112, +111,119,101,114,0,102,95,100,105,115,116,0,102,95,100,97,109,112,0,109,97,120,100,105,115,116,0,109,105,110,100,105, +115,116,0,109,97,120,114,97,100,0,109,105,110,114,97,100,0,102,95,112,111,119,101,114,95,114,0,112,100,101,102,95, +115,98,100,97,109,112,0,112,100,101,102,95,115,98,105,102,116,0,112,100,101,102,95,115,98,111,102,116,0,99,108,117, +109,112,95,102,97,99,0,99,108,117,109,112,95,112,111,119,0,107,105,110,107,95,102,114,101,113,0,107,105,110,107,95, +115,104,97,112,101,0,107,105,110,107,95,97,109,112,0,102,114,101,101,95,101,110,100,0,116,101,120,95,110,97,98,108, +97,0,116,101,120,95,109,111,100,101,0,107,105,110,107,0,107,105,110,107,95,97,120,105,115,0,114,116,50,0,42,114, +110,103,0,102,95,110,111,105,115,101,0,115,105,109,102,114,97,109,101,0,115,116,97,114,116,102,114,97,109,101,0,101, +110,100,102,114,97,109,101,0,101,100,105,116,102,114,97,109,101,0,108,105,110,83,116,105,102,102,0,97,110,103,83,116, +105,102,102,0,118,111,108,117,109,101,0,118,105,116,101,114,97,116,105,111,110,115,0,112,105,116,101,114,97,116,105,111, +110,115,0,100,105,116,101,114,97,116,105,111,110,115,0,99,105,116,101,114,97,116,105,111,110,115,0,107,83,82,72,82, +95,67,76,0,107,83,75,72,82,95,67,76,0,107,83,83,72,82,95,67,76,0,107,83,82,95,83,80,76,84,95,67, +76,0,107,83,75,95,83,80,76,84,95,67,76,0,107,83,83,95,83,80,76,84,95,67,76,0,107,86,67,70,0,107, +68,80,0,107,68,71,0,107,76,70,0,107,80,82,0,107,86,67,0,107,68,70,0,107,77,84,0,107,67,72,82,0, +107,75,72,82,0,107,83,72,82,0,107,65,72,82,0,99,111,108,108,105,115,105,111,110,102,108,97,103,115,0,110,117, +109,99,108,117,115,116,101,114,105,116,101,114,97,116,105,111,110,115,0,119,101,108,100,105,110,103,0,42,112,97,114,116, +105,99,108,101,115,0,116,111,116,112,111,105,110,116,0,116,111,116,115,112,114,105,110,103,0,42,98,112,111,105,110,116, +0,42,98,115,112,114,105,110,103,0,109,115,103,95,108,111,99,107,0,109,115,103,95,118,97,108,117,101,0,110,111,100, +101,109,97,115,115,0,110,97,109,101,100,86,71,95,77,97,115,115,91,51,50,93,0,103,114,97,118,0,109,101,100,105, +97,102,114,105,99,116,0,114,107,108,105,109,105,116,0,112,104,121,115,105,99,115,95,115,112,101,101,100,0,103,111,97, +108,115,112,114,105,110,103,0,103,111,97,108,102,114,105,99,116,0,109,105,110,103,111,97,108,0,109,97,120,103,111,97, +108,0,100,101,102,103,111,97,108,0,118,101,114,116,103,114,111,117,112,0,110,97,109,101,100,86,71,95,83,111,102,116, +103,111,97,108,91,51,50,93,0,102,117,122,122,121,110,101,115,115,0,105,110,115,112,114,105,110,103,0,105,110,102,114, +105,99,116,0,110,97,109,101,100,86,71,95,83,112,114,105,110,103,95,75,91,51,50,93,0,101,102,114,97,0,105,110, +116,101,114,118,97,108,0,108,111,99,97,108,0,115,111,108,118,101,114,102,108,97,103,115,0,42,42,107,101,121,115,0, +116,111,116,112,111,105,110,116,107,101,121,0,115,101,99,111,110,100,115,112,114,105,110,103,0,99,111,108,98,97,108,108, +0,98,97,108,108,100,97,109,112,0,98,97,108,108,115,116,105,102,102,0,115,98,99,95,109,111,100,101,0,97,101,114, +111,101,100,103,101,0,109,105,110,108,111,111,112,115,0,109,97,120,108,111,111,112,115,0,99,104,111,107,101,0,115,111, +108,118,101,114,95,73,68,0,112,108,97,115,116,105,99,0,115,112,114,105,110,103,112,114,101,108,111,97,100,0,42,115, +99,114,97,116,99,104,0,115,104,101,97,114,115,116,105,102,102,0,105,110,112,117,115,104,0,42,112,111,105,110,116,99, +97,99,104,101,0,115,104,111,119,95,97,100,118,97,110,99,101,100,111,112,116,105,111,110,115,0,114,101,115,111,108,117, +116,105,111,110,120,121,122,0,112,114,101,118,105,101,119,114,101,115,120,121,122,0,114,101,97,108,115,105,122,101,0,103, +117,105,68,105,115,112,108,97,121,77,111,100,101,0,114,101,110,100,101,114,68,105,115,112,108,97,121,77,111,100,101,0, +118,105,115,99,111,115,105,116,121,86,97,108,117,101,0,118,105,115,99,111,115,105,116,121,77,111,100,101,0,118,105,115, +99,111,115,105,116,121,69,120,112,111,110,101,110,116,0,103,114,97,118,120,0,103,114,97,118,121,0,103,114,97,118,122, +0,97,110,105,109,83,116,97,114,116,0,97,110,105,109,69,110,100,0,103,115,116,97,114,0,109,97,120,82,101,102,105, +110,101,0,105,110,105,86,101,108,120,0,105,110,105,86,101,108,121,0,105,110,105,86,101,108,122,0,42,111,114,103,77, +101,115,104,0,42,109,101,115,104,83,117,114,102,97,99,101,0,42,109,101,115,104,66,66,0,115,117,114,102,100,97,116, +97,80,97,116,104,91,50,52,48,93,0,98,98,83,116,97,114,116,91,51,93,0,98,98,83,105,122,101,91,51,93,0, +116,121,112,101,70,108,97,103,115,0,100,111,109,97,105,110,78,111,118,101,99,103,101,110,0,118,111,108,117,109,101,73, +110,105,116,84,121,112,101,0,112,97,114,116,83,108,105,112,86,97,108,117,101,0,103,101,110,101,114,97,116,101,84,114, +97,99,101,114,115,0,103,101,110,101,114,97,116,101,80,97,114,116,105,99,108,101,115,0,115,117,114,102,97,99,101,83, +109,111,111,116,104,105,110,103,0,115,117,114,102,97,99,101,83,117,98,100,105,118,115,0,112,97,114,116,105,99,108,101, +73,110,102,83,105,122,101,0,112,97,114,116,105,99,108,101,73,110,102,65,108,112,104,97,0,102,97,114,70,105,101,108, +100,83,105,122,101,0,42,109,101,115,104,83,117,114,102,78,111,114,109,97,108,115,0,99,112,115,84,105,109,101,83,116, +97,114,116,0,99,112,115,84,105,109,101,69,110,100,0,99,112,115,81,117,97,108,105,116,121,0,97,116,116,114,97,99, +116,102,111,114,99,101,83,116,114,101,110,103,116,104,0,97,116,116,114,97,99,116,102,111,114,99,101,82,97,100,105,117, +115,0,118,101,108,111,99,105,116,121,102,111,114,99,101,83,116,114,101,110,103,116,104,0,118,101,108,111,99,105,116,121, +102,111,114,99,101,82,97,100,105,117,115,0,108,97,115,116,103,111,111,100,102,114,97,109,101,0,109,105,115,116,121,112, +101,0,104,111,114,114,0,104,111,114,103,0,104,111,114,98,0,104,111,114,107,0,122,101,110,114,0,122,101,110,103,0, +122,101,110,98,0,122,101,110,107,0,97,109,98,107,0,102,97,115,116,99,111,108,0,101,120,112,111,115,117,114,101,0, +101,120,112,0,114,97,110,103,101,0,108,105,110,102,97,99,0,108,111,103,102,97,99,0,103,114,97,118,105,116,121,0, +97,99,116,105,118,105,116,121,66,111,120,82,97,100,105,117,115,0,115,107,121,116,121,112,101,0,111,99,99,108,117,115, +105,111,110,82,101,115,0,112,104,121,115,105,99,115,69,110,103,105,110,101,0,116,105,99,114,97,116,101,0,109,97,120, +108,111,103,105,99,115,116,101,112,0,112,104,121,115,117,98,115,116,101,112,0,109,97,120,112,104,121,115,116,101,112,0, +109,105,115,105,0,109,105,115,116,115,116,97,0,109,105,115,116,100,105,115,116,0,109,105,115,116,104,105,0,115,116,97, +114,114,0,115,116,97,114,103,0,115,116,97,114,98,0,115,116,97,114,107,0,115,116,97,114,115,105,122,101,0,115,116, +97,114,109,105,110,100,105,115,116,0,115,116,97,114,100,105,115,116,0,115,116,97,114,99,111,108,110,111,105,115,101,0, +100,111,102,115,116,97,0,100,111,102,101,110,100,0,100,111,102,109,105,110,0,100,111,102,109,97,120,0,97,111,100,105, +115,116,0,97,111,100,105,115,116,102,97,99,0,97,111,101,110,101,114,103,121,0,97,111,98,105,97,115,0,97,111,109, +111,100,101,0,97,111,115,97,109,112,0,97,111,109,105,120,0,97,111,99,111,108,111,114,0,97,111,95,97,100,97,112, +116,95,116,104,114,101,115,104,0,97,111,95,97,100,97,112,116,95,115,112,101,101,100,95,102,97,99,0,97,111,95,97, +112,112,114,111,120,95,101,114,114,111,114,0,97,111,95,97,112,112,114,111,120,95,99,111,114,114,101,99,116,105,111,110, +0,97,111,95,115,97,109,112,95,109,101,116,104,111,100,0,97,111,95,103,97,116,104,101,114,95,109,101,116,104,111,100, +0,97,111,95,97,112,112,114,111,120,95,112,97,115,115,101,115,0,42,97,111,115,112,104,101,114,101,0,42,97,111,116, +97,98,108,101,115,0,104,101,109,105,114,101,115,0,109,97,120,105,116,101,114,0,100,114,97,119,116,121,112,101,0,115, +117,98,115,104,111,111,116,112,0,115,117,98,115,104,111,111,116,101,0,110,111,100,101,108,105,109,0,109,97,120,115,117, +98,108,97,109,112,0,112,97,109,97,0,112,97,109,105,0,101,108,109,97,0,101,108,109,105,0,109,97,120,110,111,100, +101,0,99,111,110,118,101,114,103,101,110,99,101,0,114,97,100,102,97,99,0,103,97,109,109,97,0,115,101,108,99,111, +108,0,115,120,0,115,121,0,42,108,112,70,111,114,109,97,116,0,42,108,112,80,97,114,109,115,0,99,98,70,111,114, +109,97,116,0,99,98,80,97,114,109,115,0,102,99,99,84,121,112,101,0,102,99,99,72,97,110,100,108,101,114,0,100, +119,75,101,121,70,114,97,109,101,69,118,101,114,121,0,100,119,81,117,97,108,105,116,121,0,100,119,66,121,116,101,115, +80,101,114,83,101,99,111,110,100,0,100,119,70,108,97,103,115,0,100,119,73,110,116,101,114,108,101,97,118,101,69,118, +101,114,121,0,97,118,105,99,111,100,101,99,110,97,109,101,91,49,50,56,93,0,42,99,100,80,97,114,109,115,0,42, +112,97,100,0,99,100,83,105,122,101,0,113,116,99,111,100,101,99,110,97,109,101,91,49,50,56,93,0,99,111,100,101, +99,0,97,117,100,105,111,95,99,111,100,101,99,0,118,105,100,101,111,95,98,105,116,114,97,116,101,0,97,117,100,105, +111,95,98,105,116,114,97,116,101,0,103,111,112,95,115,105,122,101,0,114,99,95,109,105,110,95,114,97,116,101,0,114, +99,95,109,97,120,95,114,97,116,101,0,114,99,95,98,117,102,102,101,114,95,115,105,122,101,0,109,117,120,95,112,97, +99,107,101,116,95,115,105,122,101,0,109,117,120,95,114,97,116,101,0,109,105,120,114,97,116,101,0,109,97,105,110,0, +42,109,97,116,95,111,118,101,114,114,105,100,101,0,42,108,105,103,104,116,95,111,118,101,114,114,105,100,101,0,108,97, +121,95,122,109,97,115,107,0,108,97,121,102,108,97,103,0,112,97,115,115,102,108,97,103,0,112,97,115,115,95,120,111, +114,0,42,97,118,105,99,111,100,101,99,100,97,116,97,0,42,113,116,99,111,100,101,99,100,97,116,97,0,102,102,99, +111,100,101,99,100,97,116,97,0,99,102,114,97,0,112,115,102,114,97,0,112,101,102,114,97,0,105,109,97,103,101,115, +0,102,114,97,109,97,112,116,111,0,116,104,114,101,97,100,115,0,102,114,97,109,101,108,101,110,0,98,108,117,114,102, +97,99,0,101,100,103,101,82,0,101,100,103,101,71,0,101,100,103,101,66,0,102,117,108,108,115,99,114,101,101,110,0, +120,112,108,97,121,0,121,112,108,97,121,0,102,114,101,113,112,108,97,121,0,97,116,116,114,105,98,0,114,116,49,0, +115,116,101,114,101,111,109,111,100,101,0,100,105,109,101,110,115,105,111,110,115,112,114,101,115,101,116,0,109,97,120,105, +109,115,105,122,101,0,120,115,99,104,0,121,115,99,104,0,120,112,97,114,116,115,0,121,112,97,114,116,115,0,119,105, +110,112,111,115,0,112,108,97,110,101,115,0,105,109,116,121,112,101,0,115,117,98,105,109,116,121,112,101,0,113,117,97, +108,105,116,121,0,114,112,97,100,0,114,112,97,100,49,0,114,112,97,100,50,0,115,99,101,109,111,100,101,0,114,101, +110,100,101,114,101,114,0,111,99,114,101,115,0,97,108,112,104,97,109,111,100,101,0,111,115,97,0,102,114,115,95,115, +101,99,0,101,100,103,101,105,110,116,0,115,97,102,101,116,121,0,98,111,114,100,101,114,0,100,105,115,112,114,101,99, +116,0,108,97,121,101,114,115,0,97,99,116,108,97,121,0,120,97,115,112,0,121,97,115,112,0,102,114,115,95,115,101, +99,95,98,97,115,101,0,103,97,117,115,115,0,112,111,115,116,109,117,108,0,112,111,115,116,103,97,109,109,97,0,112, +111,115,116,104,117,101,0,112,111,115,116,115,97,116,0,100,105,116,104,101,114,95,105,110,116,101,110,115,105,116,121,0, +98,97,107,101,95,111,115,97,0,98,97,107,101,95,102,105,108,116,101,114,0,98,97,107,101,95,109,111,100,101,0,98, +97,107,101,95,102,108,97,103,0,98,97,107,101,95,110,111,114,109,97,108,95,115,112,97,99,101,0,98,97,107,101,95, +113,117,97,100,95,115,112,108,105,116,0,98,97,107,101,95,109,97,120,100,105,115,116,0,98,97,107,101,95,98,105,97, +115,100,105,115,116,0,98,97,107,101,95,112,97,100,0,71,73,113,117,97,108,105,116,121,0,71,73,99,97,99,104,101, +0,71,73,109,101,116,104,111,100,0,71,73,112,104,111,116,111,110,115,0,71,73,100,105,114,101,99,116,0,89,70,95, +65,65,0,89,70,101,120,112,111,114,116,120,109,108,0,89,70,95,110,111,98,117,109,112,0,89,70,95,99,108,97,109, +112,114,103,98,0,121,102,112,97,100,49,0,71,73,100,101,112,116,104,0,71,73,99,97,117,115,100,101,112,116,104,0, +71,73,112,105,120,101,108,115,112,101,114,115,97,109,112,108,101,0,71,73,112,104,111,116,111,110,99,111,117,110,116,0, +71,73,109,105,120,112,104,111,116,111,110,115,0,71,73,112,104,111,116,111,110,114,97,100,105,117,115,0,89,70,95,114, +97,121,100,101,112,116,104,0,89,70,95,65,65,112,97,115,115,101,115,0,89,70,95,65,65,115,97,109,112,108,101,115, +0,121,102,112,97,100,50,0,71,73,115,104,97,100,111,119,113,117,97,108,105,116,121,0,71,73,114,101,102,105,110,101, +109,101,110,116,0,71,73,112,111,119,101,114,0,71,73,105,110,100,105,114,112,111,119,101,114,0,89,70,95,103,97,109, +109,97,0,89,70,95,101,120,112,111,115,117,114,101,0,89,70,95,114,97,121,98,105,97,115,0,89,70,95,65,65,112, +105,120,101,108,115,105,122,101,0,89,70,95,65,65,116,104,114,101,115,104,111,108,100,0,98,97,99,107,98,117,102,91, +49,54,48,93,0,112,105,99,91,49,54,48,93,0,115,116,97,109,112,0,115,116,97,109,112,95,102,111,110,116,95,105, +100,0,115,116,97,109,112,95,117,100,97,116,97,91,49,54,48,93,0,102,103,95,115,116,97,109,112,91,52,93,0,98, +103,95,115,116,97,109,112,91,52,93,0,115,105,109,112,108,105,102,121,95,115,117,98,115,117,114,102,0,115,105,109,112, +108,105,102,121,95,115,104,97,100,111,119,115,97,109,112,108,101,115,0,115,105,109,112,108,105,102,121,95,112,97,114,116, +105,99,108,101,115,0,115,105,109,112,108,105,102,121,95,97,111,115,115,115,0,99,105,110,101,111,110,119,104,105,116,101, +0,99,105,110,101,111,110,98,108,97,99,107,0,99,105,110,101,111,110,103,97,109,109,97,0,106,112,50,95,112,114,101, +115,101,116,0,106,112,50,95,100,101,112,116,104,0,114,112,97,100,51,0,100,111,109,101,114,101,115,0,100,111,109,101, +109,111,100,101,0,100,111,109,101,97,110,103,108,101,0,100,111,109,101,116,105,108,116,0,100,111,109,101,114,101,115,98, +117,102,0,42,100,111,109,101,116,101,120,116,0,112,97,114,116,105,99,108,101,95,112,101,114,99,0,115,117,98,115,117, +114,102,95,109,97,120,0,115,104,97,100,98,117,102,115,97,109,112,108,101,95,109,97,120,0,97,111,95,101,114,114,111, +114,0,99,111,108,91,51,93,0,102,114,97,109,101,0,110,97,109,101,91,54,52,93,0,42,98,114,117,115,104,0,116, +111,111,108,0,115,101,97,109,95,98,108,101,101,100,0,110,111,114,109,97,108,95,97,110,103,108,101,0,115,116,101,112, +0,105,110,118,101,114,116,0,116,111,116,114,101,107,101,121,0,116,111,116,97,100,100,107,101,121,0,98,114,117,115,104, +116,121,112,101,0,98,114,117,115,104,91,55,93,0,101,109,105,116,116,101,114,100,105,115,116,0,100,114,97,119,95,116, +105,109,101,100,0,110,97,109,101,91,51,54,93,0,109,97,116,91,51,93,91,51,93,0,99,111,114,110,101,114,116,121, +112,101,0,101,100,105,116,98,117,116,102,108,97,103,0,106,111,105,110,116,114,105,108,105,109,105,116,0,100,101,103,114, +0,116,117,114,110,0,101,120,116,114,95,111,102,102,115,0,100,111,117,98,108,105,109,105,116,0,115,101,103,109,101,110, +116,115,0,114,105,110,103,115,0,118,101,114,116,105,99,101,115,0,117,110,119,114,97,112,112,101,114,0,117,118,99,97, +108,99,95,114,97,100,105,117,115,0,117,118,99,97,108,99,95,99,117,98,101,115,105,122,101,0,117,118,99,97,108,99, +95,109,97,114,103,105,110,0,117,118,99,97,108,99,95,109,97,112,100,105,114,0,117,118,99,97,108,99,95,109,97,112, +97,108,105,103,110,0,117,118,99,97,108,99,95,102,108,97,103,0,97,117,116,111,105,107,95,99,104,97,105,110,108,101, +110,0,105,109,97,112,97,105,110,116,0,112,97,114,116,105,99,108,101,0,115,101,108,101,99,116,95,116,104,114,101,115, +104,0,99,108,101,97,110,95,116,104,114,101,115,104,0,114,101,116,111,112,111,95,109,111,100,101,0,114,101,116,111,112, +111,95,112,97,105,110,116,95,116,111,111,108,0,108,105,110,101,95,100,105,118,0,101,108,108,105,112,115,101,95,100,105, +118,0,114,101,116,111,112,111,95,104,111,116,115,112,111,116,0,109,117,108,116,105,114,101,115,95,115,117,98,100,105,118, +95,116,121,112,101,0,115,107,103,101,110,95,114,101,115,111,108,117,116,105,111,110,0,115,107,103,101,110,95,116,104,114, +101,115,104,111,108,100,95,105,110,116,101,114,110,97,108,0,115,107,103,101,110,95,116,104,114,101,115,104,111,108,100,95, +101,120,116,101,114,110,97,108,0,115,107,103,101,110,95,108,101,110,103,116,104,95,114,97,116,105,111,0,115,107,103,101, +110,95,108,101,110,103,116,104,95,108,105,109,105,116,0,115,107,103,101,110,95,97,110,103,108,101,95,108,105,109,105,116, +0,115,107,103,101,110,95,99,111,114,114,101,108,97,116,105,111,110,95,108,105,109,105,116,0,115,107,103,101,110,95,115, +121,109,109,101,116,114,121,95,108,105,109,105,116,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,97,110,103, +108,101,95,119,101,105,103,104,116,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,108,101,110,103,116,104,95, +119,101,105,103,104,116,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,100,105,115,116,97,110,99,101,95,119, +101,105,103,104,116,0,115,107,103,101,110,95,111,112,116,105,111,110,115,0,115,107,103,101,110,95,112,111,115,116,112,114, +111,0,115,107,103,101,110,95,112,111,115,116,112,114,111,95,112,97,115,115,101,115,0,115,107,103,101,110,95,115,117,98, +100,105,118,105,115,105,111,110,115,91,51,93,0,115,107,103,101,110,95,109,117,108,116,105,95,108,101,118,101,108,0,42, +115,107,103,101,110,95,116,101,109,112,108,97,116,101,0,98,111,110,101,95,115,107,101,116,99,104,105,110,103,0,98,111, +110,101,95,115,107,101,116,99,104,105,110,103,95,99,111,110,118,101,114,116,0,115,107,103,101,110,95,115,117,98,100,105, +118,105,115,105,111,110,95,110,117,109,98,101,114,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,111,112,116, +105,111,110,115,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,114,111,108,108,0,115,107,103,101,110,95,115, +105,100,101,95,115,116,114,105,110,103,91,56,93,0,115,107,103,101,110,95,110,117,109,95,115,116,114,105,110,103,91,56, +93,0,101,100,103,101,95,109,111,100,101,0,112,97,100,51,91,50,93,0,100,105,114,0,118,105,101,119,0,42,115,101, +115,115,105,111,110,0,42,99,117,109,97,112,0,100,114,97,119,98,114,117,115,104,0,115,109,111,111,116,104,98,114,117, +115,104,0,112,105,110,99,104,98,114,117,115,104,0,105,110,102,108,97,116,101,98,114,117,115,104,0,103,114,97,98,98, +114,117,115,104,0,108,97,121,101,114,98,114,117,115,104,0,102,108,97,116,116,101,110,98,114,117,115,104,0,112,105,118, +111,116,91,51,93,0,98,114,117,115,104,95,116,121,112,101,0,116,101,120,110,114,0,116,101,120,114,101,112,116,0,116, +101,120,102,97,100,101,0,116,101,120,115,101,112,0,97,118,101,114,97,103,105,110,103,0,116,97,98,108,101,116,95,115, +105,122,101,0,116,97,98,108,101,116,95,115,116,114,101,110,103,116,104,0,115,121,109,109,0,114,97,107,101,0,97,120, +105,115,108,111,99,107,0,42,99,97,109,101,114,97,0,42,119,111,114,108,100,0,42,115,101,116,0,98,97,115,101,0, +42,98,97,115,97,99,116,0,99,117,114,115,111,114,91,51,93,0,116,119,99,101,110,116,91,51,93,0,116,119,109,105, +110,91,51,93,0,116,119,109,97,120,91,51,93,0,101,100,105,116,98,117,116,115,105,122,101,0,115,101,108,101,99,116, +109,111,100,101,0,112,114,111,112,111,114,116,105,111,110,97,108,0,112,114,111,112,95,109,111,100,101,0,97,117,116,111, +109,101,114,103,101,0,112,97,100,53,0,112,97,100,54,0,97,117,116,111,107,101,121,95,109,111,100,101,0,42,101,100, +0,42,114,97,100,105,111,0,102,114,97,109,105,110,103,0,42,116,111,111,108,115,101,116,116,105,110,103,115,0,97,117, +100,105,111,0,116,114,97,110,115,102,111,114,109,95,115,112,97,99,101,115,0,106,117,109,112,102,114,97,109,101,0,115, +110,97,112,95,109,111,100,101,0,115,110,97,112,95,102,108,97,103,0,115,110,97,112,95,116,97,114,103,101,116,0,42, +116,104,101,68,97,103,0,100,97,103,105,115,118,97,108,105,100,0,100,97,103,102,108,97,103,115,0,115,99,117,108,112, +116,100,97,116,97,0,102,114,97,109,101,95,115,116,101,112,0,122,111,111,109,0,98,108,101,110,100,0,120,105,109,0, +121,105,109,0,115,112,97,99,101,116,121,112,101,0,98,108,111,99,107,115,99,97,108,101,0,42,97,114,101,97,0,98, +108,111,99,107,104,97,110,100,108,101,114,91,56,93,0,118,105,101,119,109,97,116,91,52,93,91,52,93,0,118,105,101, +119,105,110,118,91,52,93,91,52,93,0,112,101,114,115,109,97,116,91,52,93,91,52,93,0,112,101,114,115,105,110,118, +91,52,93,91,52,93,0,119,105,110,109,97,116,49,91,52,93,91,52,93,0,118,105,101,119,109,97,116,49,91,52,93, +91,52,93,0,118,105,101,119,113,117,97,116,91,52,93,0,122,102,97,99,0,108,97,121,95,117,115,101,100,0,112,101, +114,115,112,0,42,111,98,95,99,101,110,116,114,101,0,42,98,103,112,105,99,0,42,108,111,99,97,108,118,100,0,42, +114,105,0,42,114,101,116,111,112,111,95,118,105,101,119,95,100,97,116,97,0,42,100,101,112,116,104,115,0,111,98,95, +99,101,110,116,114,101,95,98,111,110,101,91,51,50,93,0,108,111,99,97,108,118,105,101,119,0,108,97,121,97,99,116, +0,115,99,101,110,101,108,111,99,107,0,97,114,111,117,110,100,0,99,97,109,122,111,111,109,0,112,105,118,111,116,95, +108,97,115,116,0,103,114,105,100,0,103,114,105,100,118,105,101,119,0,112,105,120,115,105,122,101,0,110,101,97,114,0, +102,97,114,0,99,97,109,100,120,0,99,97,109,100,121,0,103,114,105,100,108,105,110,101,115,0,118,105,101,119,98,117, +116,0,103,114,105,100,102,108,97,103,0,109,111,100,101,115,101,108,101,99,116,0,116,119,116,121,112,101,0,116,119,109, +111,100,101,0,116,119,102,108,97,103,0,116,119,100,114,97,119,102,108,97,103,0,116,119,109,97,116,91,52,93,91,52, +93,0,99,108,105,112,91,52,93,91,52,93,0,42,99,108,105,112,98,98,0,97,102,116,101,114,100,114,97,119,0,122, +98,117,102,0,120,114,97,121,0,102,108,97,103,50,0,103,114,105,100,115,117,98,100,105,118,0,107,101,121,102,108,97, +103,115,0,110,100,111,102,109,111,100,101,0,110,100,111,102,102,105,108,116,101,114,0,42,112,114,111,112,101,114,116,105, +101,115,95,115,116,111,114,97,103,101,0,42,103,112,100,0,108,118,105,101,119,113,117,97,116,91,52,93,0,108,112,101, +114,115,112,0,108,118,105,101,119,0,118,101,114,116,0,104,111,114,0,109,97,115,107,0,109,105,110,91,50,93,0,109, +97,120,91,50,93,0,109,105,110,122,111,111,109,0,109,97,120,122,111,111,109,0,115,99,114,111,108,108,0,107,101,101, +112,116,111,116,0,107,101,101,112,97,115,112,101,99,116,0,107,101,101,112,122,111,111,109,0,111,108,100,119,105,110,120, +0,111,108,100,119,105,110,121,0,99,117,114,115,111,114,91,50,93,0,114,111,119,98,117,116,0,118,50,100,0,42,101, +100,105,116,105,112,111,0,105,112,111,107,101,121,0,97,99,116,110,97,109,101,91,51,50,93,0,99,111,110,115,116,110, +97,109,101,91,51,50,93,0,98,111,110,101,110,97,109,101,91,51,50,93,0,116,111,116,105,112,111,0,112,105,110,0, +98,117,116,111,102,115,0,99,104,97,110,110,101,108,0,108,111,99,107,0,109,101,100,105,97,110,91,51,93,0,99,117, +114,115,101,110,115,0,99,117,114,97,99,116,0,97,108,105,103,110,0,116,97,98,111,0,109,97,105,110,98,0,109,97, +105,110,98,111,0,42,108,111,99,107,112,111,105,110,0,116,101,120,102,114,111,109,0,115,104,111,119,103,114,111,117,112, +0,109,111,100,101,108,116,121,112,101,0,115,99,114,105,112,116,98,108,111,99,107,0,114,101,95,97,108,105,103,110,0, +111,108,100,107,101,121,112,114,101,115,115,0,116,97,98,91,55,93,0,114,101,110,100,101,114,95,115,105,122,101,0,99, +104,97,110,115,104,111,119,110,0,122,101,98,114,97,0,42,102,105,108,101,108,105,115,116,0,116,111,116,102,105,108,101, +0,116,105,116,108,101,91,50,52,93,0,100,105,114,91,50,52,48,93,0,102,105,108,101,91,56,48,93,0,111,102,115, +0,115,111,114,116,0,109,97,120,110,97,109,101,108,101,110,0,99,111,108,108,117,109,115,0,102,95,102,112,0,102,112, +95,115,116,114,91,56,93,0,42,108,105,98,102,105,108,101,100,97,116,97,0,114,101,116,118,97,108,0,109,101,110,117, +0,97,99,116,0,40,42,114,101,116,117,114,110,102,117,110,99,41,40,41,0,40,42,114,101,116,117,114,110,102,117,110, +99,95,101,118,101,110,116,41,40,41,0,40,42,114,101,116,117,114,110,102,117,110,99,95,97,114,103,115,41,40,41,0, +42,97,114,103,49,0,42,97,114,103,50,0,42,109,101,110,117,112,0,42,112,117,112,109,101,110,117,0,111,111,112,115, +0,118,105,115,105,102,108,97,103,0,116,114,101,101,0,42,116,114,101,101,115,116,111,114,101,0,115,101,97,114,99,104, +95,115,116,114,105,110,103,91,51,50,93,0,115,101,97,114,99,104,95,116,115,101,0,115,101,97,114,99,104,95,102,108, +97,103,115,0,100,111,95,0,111,117,116,108,105,110,101,118,105,115,0,115,116,111,114,101,102,108,97,103,0,100,101,112, +115,95,102,108,97,103,115,0,105,109,97,110,114,0,99,117,114,116,105,108,101,0,105,109,116,121,112,101,110,114,0,100, +116,95,117,118,0,115,116,105,99,107,121,0,100,116,95,117,118,115,116,114,101,116,99,104,0,112,97,100,91,53,93,0, +99,101,110,116,120,0,99,101,110,116,121,0,97,117,116,111,115,110,97,112,0,42,116,101,120,116,0,116,111,112,0,118, +105,101,119,108,105,110,101,115,0,102,111,110,116,95,105,100,0,108,104,101,105,103,104,116,0,108,101,102,116,0,115,104, +111,119,108,105,110,101,110,114,115,0,116,97,98,110,117,109,98,101,114,0,99,117,114,114,116,97,98,95,115,101,116,0, +115,104,111,119,115,121,110,116,97,120,0,111,118,101,114,119,114,105,116,101,0,112,105,120,95,112,101,114,95,108,105,110, +101,0,116,120,116,115,99,114,111,108,108,0,116,120,116,98,97,114,0,119,111,114,100,119,114,97,112,0,100,111,112,108, +117,103,105,110,115,0,42,112,121,95,100,114,97,119,0,42,112,121,95,101,118,101,110,116,0,42,112,121,95,98,117,116, +116,111,110,0,42,112,121,95,98,114,111,119,115,101,114,99,97,108,108,98,97,99,107,0,42,112,121,95,103,108,111,98, +97,108,100,105,99,116,0,108,97,115,116,115,112,97,99,101,0,115,99,114,105,112,116,110,97,109,101,91,50,53,54,93, +0,115,99,114,105,112,116,97,114,103,91,50,53,54,93,0,42,115,99,114,105,112,116,0,42,98,117,116,95,114,101,102, +115,0,114,101,100,114,97,119,115,0,42,105,100,0,97,115,112,101,99,116,0,42,99,117,114,102,111,110,116,0,42,101, +100,105,116,116,114,101,101,0,116,114,101,101,116,121,112,101,0,42,102,105,108,101,115,0,97,99,116,105,118,101,95,102, +105,108,101,0,110,117,109,116,105,108,101,115,120,0,110,117,109,116,105,108,101,115,121,0,115,101,108,115,116,97,116,101, +0,118,105,101,119,114,101,99,116,0,98,111,111,107,109,97,114,107,114,101,99,116,0,115,99,114,111,108,108,112,111,115, +0,115,99,114,111,108,108,104,101,105,103,104,116,0,115,99,114,111,108,108,97,114,101,97,0,97,99,116,105,118,101,95, +98,111,111,107,109,97,114,107,0,112,114,118,95,119,0,112,114,118,95,104,0,42,105,109,103,0,111,117,116,108,105,110, +101,91,52,93,0,110,101,117,116,114,97,108,91,52,93,0,97,99,116,105,111,110,91,52,93,0,115,101,116,116,105,110, +103,91,52,93,0,115,101,116,116,105,110,103,49,91,52,93,0,115,101,116,116,105,110,103,50,91,52,93,0,110,117,109, +91,52,93,0,116,101,120,116,102,105,101,108,100,91,52,93,0,116,101,120,116,102,105,101,108,100,95,104,105,91,52,93, +0,112,111,112,117,112,91,52,93,0,116,101,120,116,91,52,93,0,116,101,120,116,95,104,105,91,52,93,0,109,101,110, +117,95,98,97,99,107,91,52,93,0,109,101,110,117,95,105,116,101,109,91,52,93,0,109,101,110,117,95,104,105,108,105, +116,101,91,52,93,0,109,101,110,117,95,116,101,120,116,91,52,93,0,109,101,110,117,95,116,101,120,116,95,104,105,91, +52,93,0,98,117,116,95,100,114,97,119,116,121,112,101,0,105,99,111,110,102,105,108,101,91,56,48,93,0,98,97,99, +107,91,52,93,0,104,101,97,100,101,114,91,52,93,0,112,97,110,101,108,91,52,93,0,115,104,97,100,101,49,91,52, +93,0,115,104,97,100,101,50,91,52,93,0,104,105,108,105,116,101,91,52,93,0,103,114,105,100,91,52,93,0,119,105, +114,101,91,52,93,0,115,101,108,101,99,116,91,52,93,0,108,97,109,112,91,52,93,0,97,99,116,105,118,101,91,52, +93,0,103,114,111,117,112,91,52,93,0,103,114,111,117,112,95,97,99,116,105,118,101,91,52,93,0,116,114,97,110,115, +102,111,114,109,91,52,93,0,118,101,114,116,101,120,91,52,93,0,118,101,114,116,101,120,95,115,101,108,101,99,116,91, +52,93,0,101,100,103,101,91,52,93,0,101,100,103,101,95,115,101,108,101,99,116,91,52,93,0,101,100,103,101,95,115, +101,97,109,91,52,93,0,101,100,103,101,95,115,104,97,114,112,91,52,93,0,101,100,103,101,95,102,97,99,101,115,101, +108,91,52,93,0,102,97,99,101,91,52,93,0,102,97,99,101,95,115,101,108,101,99,116,91,52,93,0,102,97,99,101, +95,100,111,116,91,52,93,0,110,111,114,109,97,108,91,52,93,0,98,111,110,101,95,115,111,108,105,100,91,52,93,0, +98,111,110,101,95,112,111,115,101,91,52,93,0,115,116,114,105,112,91,52,93,0,115,116,114,105,112,95,115,101,108,101, +99,116,91,52,93,0,99,102,114,97,109,101,91,52,93,0,118,101,114,116,101,120,95,115,105,122,101,0,102,97,99,101, +100,111,116,95,115,105,122,101,0,98,112,97,100,91,50,93,0,115,121,110,116,97,120,108,91,52,93,0,115,121,110,116, +97,120,110,91,52,93,0,115,121,110,116,97,120,98,91,52,93,0,115,121,110,116,97,120,118,91,52,93,0,115,121,110, +116,97,120,99,91,52,93,0,109,111,118,105,101,91,52,93,0,105,109,97,103,101,91,52,93,0,115,99,101,110,101,91, +52,93,0,97,117,100,105,111,91,52,93,0,101,102,102,101,99,116,91,52,93,0,112,108,117,103,105,110,91,52,93,0, +116,114,97,110,115,105,116,105,111,110,91,52,93,0,109,101,116,97,91,52,93,0,101,100,105,116,109,101,115,104,95,97, +99,116,105,118,101,91,52,93,0,104,97,110,100,108,101,95,118,101,114,116,101,120,91,52,93,0,104,97,110,100,108,101, +95,118,101,114,116,101,120,95,115,101,108,101,99,116,91,52,93,0,104,97,110,100,108,101,95,118,101,114,116,101,120,95, +115,105,122,101,0,104,112,97,100,91,55,93,0,115,111,108,105,100,91,52,93,0,116,117,105,0,116,98,117,116,115,0, +116,118,51,100,0,116,102,105,108,101,0,116,105,112,111,0,116,105,110,102,111,0,116,115,110,100,0,116,97,99,116,0, +116,110,108,97,0,116,115,101,113,0,116,105,109,97,0,116,105,109,97,115,101,108,0,116,101,120,116,0,116,111,111,112, +115,0,116,116,105,109,101,0,116,110,111,100,101,0,116,97,114,109,91,50,48,93,0,98,112,97,100,91,52,93,0,98, +112,97,100,49,91,52,93,0,115,112,101,99,91,52,93,0,100,117,112,102,108,97,103,0,115,97,118,101,116,105,109,101, +0,116,101,109,112,100,105,114,91,49,54,48,93,0,102,111,110,116,100,105,114,91,49,54,48,93,0,114,101,110,100,101, +114,100,105,114,91,49,54,48,93,0,116,101,120,116,117,100,105,114,91,49,54,48,93,0,112,108,117,103,116,101,120,100, +105,114,91,49,54,48,93,0,112,108,117,103,115,101,113,100,105,114,91,49,54,48,93,0,112,121,116,104,111,110,100,105, +114,91,49,54,48,93,0,115,111,117,110,100,100,105,114,91,49,54,48,93,0,121,102,101,120,112,111,114,116,100,105,114, +91,49,54,48,93,0,118,101,114,115,105,111,110,115,0,118,114,109,108,102,108,97,103,0,103,97,109,101,102,108,97,103, +115,0,119,104,101,101,108,108,105,110,101,115,99,114,111,108,108,0,117,105,102,108,97,103,0,108,97,110,103,117,97,103, +101,0,117,115,101,114,112,114,101,102,0,118,105,101,119,122,111,111,109,0,99,111,110,115,111,108,101,95,98,117,102,102, +101,114,0,99,111,110,115,111,108,101,95,111,117,116,0,109,105,120,98,117,102,115,105,122,101,0,102,111,110,116,115,105, +122,101,0,101,110,99,111,100,105,110,103,0,116,114,97,110,115,111,112,116,115,0,109,101,110,117,116,104,114,101,115,104, +111,108,100,49,0,109,101,110,117,116,104,114,101,115,104,111,108,100,50,0,102,111,110,116,110,97,109,101,91,50,53,54, +93,0,116,104,101,109,101,115,0,117,110,100,111,115,116,101,112,115,0,117,110,100,111,109,101,109,111,114,121,0,103,112, +95,109,97,110,104,97,116,116,101,110,100,105,115,116,0,103,112,95,101,117,99,108,105,100,101,97,110,100,105,115,116,0, +103,112,95,101,114,97,115,101,114,0,103,112,95,115,101,116,116,105,110,103,115,0,116,98,95,108,101,102,116,109,111,117, +115,101,0,116,98,95,114,105,103,104,116,109,111,117,115,101,0,108,105,103,104,116,91,51,93,0,116,119,95,104,111,116, +115,112,111,116,0,116,119,95,102,108,97,103,0,116,119,95,104,97,110,100,108,101,115,105,122,101,0,116,119,95,115,105, +122,101,0,116,101,120,116,105,109,101,111,117,116,0,116,101,120,99,111,108,108,101,99,116,114,97,116,101,0,109,101,109, +99,97,99,104,101,108,105,109,105,116,0,112,114,101,102,101,116,99,104,102,114,97,109,101,115,0,102,114,97,109,101,115, +101,114,118,101,114,112,111,114,116,0,112,97,100,95,114,111,116,95,97,110,103,108,101,0,111,98,99,101,110,116,101,114, +95,100,105,97,0,114,118,105,115,105,122,101,0,114,118,105,98,114,105,103,104,116,0,114,101,99,101,110,116,95,102,105, +108,101,115,0,115,109,111,111,116,104,95,118,105,101,119,116,120,0,103,108,114,101,115,108,105,109,105,116,0,110,100,111, +102,95,112,97,110,0,110,100,111,102,95,114,111,116,97,116,101,0,99,117,114,115,115,105,122,101,0,112,97,100,91,56, +93,0,118,101,114,115,101,109,97,115,116,101,114,91,49,54,48,93,0,118,101,114,115,101,117,115,101,114,91,49,54,48, +93,0,103,108,97,108,112,104,97,99,108,105,112,0,97,117,116,111,107,101,121,95,102,108,97,103,0,99,111,98,97,95, +119,101,105,103,104,116,0,118,101,114,116,98,97,115,101,0,101,100,103,101,98,97,115,101,0,97,114,101,97,98,97,115, +101,0,42,115,99,101,110,101,0,101,110,100,120,0,101,110,100,121,0,115,105,122,101,120,0,115,105,122,101,121,0,115, +99,101,110,101,110,114,0,115,99,114,101,101,110,110,114,0,102,117,108,108,0,109,97,105,110,119,105,110,0,119,105,110, +97,107,116,0,104,97,110,100,108,101,114,91,56,93,0,42,110,101,119,118,0,118,101,99,0,42,118,49,0,42,118,50, +0,112,97,110,101,108,110,97,109,101,91,54,52,93,0,116,97,98,110,97,109,101,91,54,52,93,0,100,114,97,119,110, +97,109,101,91,54,52,93,0,111,102,115,120,0,111,102,115,121,0,99,111,110,116,114,111,108,0,115,110,97,112,0,111, +108,100,95,111,102,115,120,0,111,108,100,95,111,102,115,121,0,115,111,114,116,99,111,117,110,116,101,114,0,42,112,97, +110,101,108,116,97,98,0,42,118,51,0,42,118,52,0,42,102,117,108,108,0,119,105,110,109,97,116,91,52,93,91,52, +93,0,104,101,97,100,114,99,116,0,119,105,110,114,99,116,0,104,101,97,100,119,105,110,0,119,105,110,0,104,101,97, +100,101,114,116,121,112,101,0,98,117,116,115,112,97,99,101,116,121,112,101,0,119,105,110,120,0,119,105,110,121,0,104, +101,97,100,95,115,119,97,112,0,104,101,97,100,95,101,113,117,97,108,0,119,105,110,95,115,119,97,112,0,119,105,110, +95,101,113,117,97,108,0,104,101,97,100,98,117,116,108,101,110,0,104,101,97,100,98,117,116,111,102,115,0,99,117,114, +115,111,114,0,115,112,97,99,101,100,97,116,97,0,117,105,98,108,111,99,107,115,0,112,97,110,101,108,115,0,115,117, +98,118,115,116,114,91,52,93,0,115,117,98,118,101,114,115,105,111,110,0,112,97,100,115,0,109,105,110,118,101,114,115, +105,111,110,0,109,105,110,115,117,98,118,101,114,115,105,111,110,0,100,105,115,112,108,97,121,109,111,100,101,0,42,99, +117,114,115,99,114,101,101,110,0,42,99,117,114,115,99,101,110,101,0,102,105,108,101,102,108,97,103,115,0,103,108,111, +98,97,108,102,0,110,97,109,101,91,56,48,93,0,42,105,98,117,102,0,42,105,98,117,102,95,99,111,109,112,0,42, +115,101,49,0,42,115,101,50,0,42,115,101,51,0,110,114,0,98,111,116,116,111,109,0,114,105,103,104,116,0,120,111, +102,115,0,121,111,102,115,0,108,105,102,116,91,51,93,0,103,97,109,109,97,91,51,93,0,103,97,105,110,91,51,93, +0,115,97,116,117,114,97,116,105,111,110,0,42,103,117,105,0,100,105,114,91,49,54,48,93,0,100,111,110,101,0,115, +116,97,114,116,115,116,105,108,108,0,101,110,100,115,116,105,108,108,0,42,115,116,114,105,112,100,97,116,97,0,111,114, +120,0,111,114,121,0,42,99,114,111,112,0,42,116,114,97,110,115,102,111,114,109,0,42,99,111,108,111,114,95,98,97, +108,97,110,99,101,0,42,116,115,116,114,105,112,100,97,116,97,0,42,116,115,116,114,105,112,100,97,116,97,95,115,116, +97,114,116,115,116,105,108,108,0,42,116,115,116,114,105,112,100,97,116,97,95,101,110,100,115,116,105,108,108,0,42,105, +98,117,102,95,115,116,97,114,116,115,116,105,108,108,0,42,105,98,117,102,95,101,110,100,115,116,105,108,108,0,42,105, +110,115,116,97,110,99,101,95,112,114,105,118,97,116,101,95,100,97,116,97,0,42,42,99,117,114,114,101,110,116,95,112, +114,105,118,97,116,101,95,100,97,116,97,0,42,116,109,112,0,115,116,97,114,116,111,102,115,0,101,110,100,111,102,115, +0,109,97,99,104,105,110,101,0,115,116,97,114,116,100,105,115,112,0,101,110,100,100,105,115,112,0,109,117,108,0,104, +97,110,100,115,105,122,101,0,97,110,105,109,95,112,114,101,115,101,101,107,0,42,115,116,114,105,112,0,102,97,99,102, +48,0,102,97,99,102,49,0,42,115,101,113,49,0,42,115,101,113,50,0,42,115,101,113,51,0,115,101,113,98,97,115, +101,0,42,115,111,117,110,100,0,42,104,100,97,117,100,105,111,0,108,101,118,101,108,0,112,97,110,0,115,116,114,111, +98,101,0,42,101,102,102,101,99,116,100,97,116,97,0,97,110,105,109,95,115,116,97,114,116,111,102,115,0,97,110,105, +109,95,101,110,100,111,102,115,0,98,108,101,110,100,95,109,111,100,101,0,98,108,101,110,100,95,111,112,97,99,105,116, +121,0,42,111,108,100,98,97,115,101,112,0,42,112,97,114,115,101,113,0,42,115,101,113,98,97,115,101,112,0,109,101, +116,97,115,116,97,99,107,0,101,100,103,101,87,105,100,116,104,0,102,111,114,119,97,114,100,0,119,105,112,101,116,121, +112,101,0,102,77,105,110,105,0,102,67,108,97,109,112,0,102,66,111,111,115,116,0,100,68,105,115,116,0,100,81,117, +97,108,105,116,121,0,98,78,111,67,111,109,112,0,83,99,97,108,101,120,73,110,105,0,83,99,97,108,101,121,73,110, +105,0,83,99,97,108,101,120,70,105,110,0,83,99,97,108,101,121,70,105,110,0,120,73,110,105,0,120,70,105,110,0, +121,73,110,105,0,121,70,105,110,0,114,111,116,73,110,105,0,114,111,116,70,105,110,0,105,110,116,101,114,112,111,108, +97,116,105,111,110,0,42,102,114,97,109,101,77,97,112,0,103,108,111,98,97,108,83,112,101,101,100,0,108,97,115,116, +86,97,108,105,100,70,114,97,109,101,0,98,108,101,110,100,70,114,97,109,101,115,0,98,117,116,116,121,112,101,0,117, +115,101,114,106,105,116,0,115,116,97,0,116,111,116,112,97,114,116,0,110,111,114,109,102,97,99,0,111,98,102,97,99, +0,114,97,110,100,102,97,99,0,116,101,120,102,97,99,0,114,97,110,100,108,105,102,101,0,102,111,114,99,101,91,51, +93,0,118,101,99,116,115,105,122,101,0,109,97,120,108,101,110,0,100,101,102,118,101,99,91,51,93,0,109,117,108,116, +91,52,93,0,108,105,102,101,91,52,93,0,99,104,105,108,100,91,52,93,0,109,97,116,91,52,93,0,116,101,120,109, +97,112,0,99,117,114,109,117,108,116,0,115,116,97,116,105,99,115,116,101,112,0,111,109,97,116,0,116,105,109,101,116, +101,120,0,115,112,101,101,100,116,101,120,0,102,108,97,103,50,110,101,103,0,118,101,114,116,103,114,111,117,112,95,118, +0,118,103,114,111,117,112,110,97,109,101,91,51,50,93,0,118,103,114,111,117,112,110,97,109,101,95,118,91,51,50,93, +0,42,107,101,121,115,0,109,105,110,102,97,99,0,117,115,101,100,0,117,115,101,100,101,108,101,109,0,100,120,0,100, +121,0,108,105,110,107,0,111,116,121,112,101,0,111,108,100,0,42,112,111,105,110,0,42,111,108,100,112,111,105,110,0, +114,101,115,101,116,100,105,115,116,0,108,97,115,116,118,97,108,0,42,109,97,0,107,101,121,0,113,117,97,108,0,113, +117,97,108,50,0,116,97,114,103,101,116,78,97,109,101,91,51,50,93,0,116,111,103,103,108,101,78,97,109,101,91,51, +50,93,0,118,97,108,117,101,91,51,50,93,0,109,97,120,118,97,108,117,101,91,51,50,93,0,100,101,108,97,121,0, +100,117,114,97,116,105,111,110,0,109,97,116,101,114,105,97,108,78,97,109,101,91,51,50,93,0,100,97,109,112,116,105, +109,101,114,0,112,114,111,112,110,97,109,101,91,51,50,93,0,109,97,116,110,97,109,101,91,51,50,93,0,97,120,105, +115,102,108,97,103,0,42,102,114,111,109,79,98,106,101,99,116,0,115,117,98,106,101,99,116,91,51,50,93,0,98,111, +100,121,91,51,50,93,0,112,117,108,115,101,0,102,114,101,113,0,116,111,116,108,105,110,107,115,0,42,42,108,105,110, +107,115,0,116,97,112,0,106,111,121,105,110,100,101,120,0,97,120,105,115,95,115,105,110,103,108,101,0,97,120,105,115, +102,0,98,117,116,116,111,110,0,104,97,116,0,104,97,116,102,0,112,114,101,99,105,115,105,111,110,0,115,116,114,91, +49,50,56,93,0,109,111,100,117,108,101,91,54,52,93,0,42,109,121,110,101,119,0,105,110,112,117,116,115,0,116,111, +116,115,108,105,110,107,115,0,42,42,115,108,105,110,107,115,0,118,97,108,111,0,115,116,97,116,101,95,109,97,115,107, +0,42,97,99,116,0,102,114,97,109,101,80,114,111,112,91,51,50,93,0,98,108,101,110,100,105,110,0,112,114,105,111, +114,105,116,121,0,101,110,100,95,114,101,115,101,116,0,115,116,114,105,100,101,97,120,105,115,0,115,116,114,105,100,101, +108,101,110,103,116,104,0,115,110,100,110,114,0,112,97,100,49,91,50,93,0,109,97,107,101,99,111,112,121,0,99,111, +112,121,109,97,100,101,0,112,97,100,50,91,49,93,0,116,114,97,99,107,0,42,109,101,0,108,105,110,86,101,108,111, +99,105,116,121,91,51,93,0,97,110,103,86,101,108,111,99,105,116,121,91,51,93,0,108,111,99,97,108,102,108,97,103, +0,100,121,110,95,111,112,101,114,97,116,105,111,110,0,102,111,114,99,101,108,111,99,91,51,93,0,102,111,114,99,101, +114,111,116,91,51,93,0,108,105,110,101,97,114,118,101,108,111,99,105,116,121,91,51,93,0,97,110,103,117,108,97,114, +118,101,108,111,99,105,116,121,91,51,93,0,42,114,101,102,101,114,101,110,99,101,0,98,117,116,115,116,97,0,98,117, +116,101,110,100,0,109,105,110,0,109,97,120,0,118,105,115,105,102,97,99,0,114,111,116,100,97,109,112,0,109,105,110, +108,111,99,91,51,93,0,109,97,120,108,111,99,91,51,93,0,109,105,110,114,111,116,91,51,93,0,109,97,120,114,111, +116,91,51,93,0,109,97,116,112,114,111,112,91,51,50,93,0,100,105,115,116,114,105,98,117,116,105,111,110,0,105,110, +116,95,97,114,103,95,49,0,105,110,116,95,97,114,103,95,50,0,102,108,111,97,116,95,97,114,103,95,49,0,102,108, +111,97,116,95,97,114,103,95,50,0,116,111,80,114,111,112,78,97,109,101,91,51,50,93,0,42,116,111,79,98,106,101, +99,116,0,98,111,100,121,84,121,112,101,0,102,105,108,101,110,97,109,101,91,54,52,93,0,108,111,97,100,97,110,105, +110,97,109,101,91,54,52,93,0,105,110,116,95,97,114,103,0,102,108,111,97,116,95,97,114,103,0,103,111,0,97,99, +99,101,108,108,101,114,97,116,105,111,110,0,109,97,120,115,112,101,101,100,0,109,97,120,114,111,116,115,112,101,101,100, +0,109,97,120,116,105,108,116,115,112,101,101,100,0,116,105,108,116,100,97,109,112,0,115,112,101,101,100,100,97,109,112, +0,42,115,97,109,112,108,101,0,42,115,116,114,101,97,109,0,42,110,101,119,112,97,99,107,101,100,102,105,108,101,0, +42,115,110,100,95,115,111,117,110,100,0,112,97,110,110,105,110,103,0,97,116,116,101,110,117,97,116,105,111,110,0,112, +105,116,99,104,0,109,105,110,95,103,97,105,110,0,109,97,120,95,103,97,105,110,0,100,105,115,116,97,110,99,101,0, +115,116,114,101,97,109,108,101,110,0,99,104,97,110,110,101,108,115,0,104,105,103,104,112,114,105,111,0,112,97,100,91, +49,48,93,0,103,97,105,110,0,100,111,112,112,108,101,114,102,97,99,116,111,114,0,100,111,112,112,108,101,114,118,101, +108,111,99,105,116,121,0,110,117,109,115,111,117,110,100,115,98,108,101,110,100,101,114,0,110,117,109,115,111,117,110,100, +115,103,97,109,101,101,110,103,105,110,101,0,42,108,97,109,112,114,101,110,0,103,111,98,106,101,99,116,0,100,117,112, +108,105,95,111,102,115,91,51,93,0,99,104,105,108,100,98,97,115,101,0,114,111,108,108,0,104,101,97,100,91,51,93, +0,116,97,105,108,91,51,93,0,98,111,110,101,95,109,97,116,91,51,93,91,51,93,0,97,114,109,95,104,101,97,100, +91,51,93,0,97,114,109,95,116,97,105,108,91,51,93,0,97,114,109,95,109,97,116,91,52,93,91,52,93,0,120,119, +105,100,116,104,0,122,119,105,100,116,104,0,101,97,115,101,49,0,101,97,115,101,50,0,114,97,100,95,104,101,97,100, +0,114,97,100,95,116,97,105,108,0,98,111,110,101,98,97,115,101,0,99,104,97,105,110,98,97,115,101,0,112,97,116, +104,102,108,97,103,0,108,97,121,101,114,95,112,114,111,116,101,99,116,101,100,0,103,104,111,115,116,101,112,0,103,104, +111,115,116,115,105,122,101,0,103,104,111,115,116,116,121,112,101,0,112,97,116,104,115,105,122,101,0,103,104,111,115,116, +115,102,0,103,104,111,115,116,101,102,0,112,97,116,104,115,102,0,112,97,116,104,101,102,0,112,97,116,104,98,99,0, +112,97,116,104,97,99,0,99,111,110,115,116,102,108,97,103,0,105,107,102,108,97,103,0,115,101,108,101,99,116,102,108, +97,103,0,97,103,114,112,95,105,110,100,101,120,0,42,98,111,110,101,0,42,99,104,105,108,100,0,105,107,116,114,101, +101,0,42,98,95,98,111,110,101,95,109,97,116,115,0,42,100,117,97,108,95,113,117,97,116,0,42,98,95,98,111,110, +101,95,100,117,97,108,95,113,117,97,116,115,0,99,104,97,110,95,109,97,116,91,52,93,91,52,93,0,112,111,115,101, +95,109,97,116,91,52,93,91,52,93,0,112,111,115,101,95,104,101,97,100,91,51,93,0,112,111,115,101,95,116,97,105, +108,91,51,93,0,108,105,109,105,116,109,105,110,91,51,93,0,108,105,109,105,116,109,97,120,91,51,93,0,115,116,105, +102,102,110,101,115,115,91,51,93,0,105,107,115,116,114,101,116,99,104,0,42,99,117,115,116,111,109,0,99,104,97,110, +98,97,115,101,0,112,114,111,120,121,95,108,97,121,101,114,0,115,116,114,105,100,101,95,111,102,102,115,101,116,91,51, +93,0,99,121,99,108,105,99,95,111,102,102,115,101,116,91,51,93,0,97,103,114,111,117,112,115,0,97,99,116,105,118, +101,95,103,114,111,117,112,0,99,117,115,116,111,109,67,111,108,0,99,115,0,42,103,114,112,0,114,101,115,101,114,118, +101,100,49,0,103,114,111,117,112,115,0,97,99,116,105,118,101,95,109,97,114,107,101,114,0,97,99,116,110,114,0,97, +99,116,119,105,100,116,104,0,116,105,109,101,115,108,105,100,101,0,110,97,109,101,91,51,48,93,0,111,119,110,115,112, +97,99,101,0,116,97,114,115,112,97,99,101,0,101,110,102,111,114,99,101,0,104,101,97,100,116,97,105,108,0,42,116, +97,114,0,115,117,98,116,97,114,103,101,116,91,51,50,93,0,109,97,116,114,105,120,91,52,93,91,52,93,0,115,112, +97,99,101,0,42,112,114,111,112,0,116,97,114,110,117,109,0,116,97,114,103,101,116,115,0,105,116,101,114,97,116,105, +111,110,115,0,114,111,111,116,98,111,110,101,0,109,97,120,95,114,111,111,116,98,111,110,101,0,42,112,111,108,101,116, +97,114,0,112,111,108,101,115,117,98,116,97,114,103,101,116,91,51,50,93,0,112,111,108,101,97,110,103,108,101,0,111, +114,105,101,110,116,119,101,105,103,104,116,0,103,114,97,98,116,97,114,103,101,116,91,51,93,0,114,101,115,101,114,118, +101,100,50,0,109,105,110,109,97,120,102,108,97,103,0,115,116,117,99,107,0,99,97,99,104,101,91,51,93,0,108,111, +99,107,102,108,97,103,0,102,111,108,108,111,119,102,108,97,103,0,118,111,108,109,111,100,101,0,112,108,97,110,101,0, +111,114,103,108,101,110,103,116,104,0,98,117,108,103,101,0,112,105,118,88,0,112,105,118,89,0,112,105,118,90,0,97, +120,88,0,97,120,89,0,97,120,90,0,109,105,110,76,105,109,105,116,91,54,93,0,109,97,120,76,105,109,105,116,91, +54,93,0,101,120,116,114,97,70,122,0,105,110,118,109,97,116,91,52,93,91,52,93,0,102,114,111,109,0,116,111,0, +109,97,112,91,51,93,0,101,120,112,111,0,102,114,111,109,95,109,105,110,91,51,93,0,102,114,111,109,95,109,97,120, +91,51,93,0,116,111,95,109,105,110,91,51,93,0,116,111,95,109,97,120,91,51,93,0,122,109,105,110,0,122,109,97, +120,0,112,97,100,91,57,93,0,99,104,97,110,110,101,108,91,51,50,93,0,110,111,95,114,111,116,95,97,120,105,115, +0,115,116,114,105,100,101,95,97,120,105,115,0,99,117,114,109,111,100,0,97,99,116,115,116,97,114,116,0,97,99,116, +101,110,100,0,97,99,116,111,102,102,115,0,115,116,114,105,100,101,108,101,110,0,98,108,101,110,100,111,117,116,0,115, +116,114,105,100,101,99,104,97,110,110,101,108,91,51,50,93,0,111,102,102,115,95,98,111,110,101,91,51,50,93,0,104, +97,115,105,110,112,117,116,0,104,97,115,111,117,116,112,117,116,0,100,97,116,97,116,121,112,101,0,115,111,99,107,101, +116,116,121,112,101,0,42,110,101,119,95,115,111,99,107,0,110,115,0,108,105,109,105,116,0,115,116,97,99,107,95,105, +110,100,101,120,0,105,110,116,101,114,110,0,115,116,97,99,107,95,105,110,100,101,120,95,101,120,116,0,108,111,99,120, +0,108,111,99,121,0,111,119,110,95,105,110,100,101,120,0,116,111,95,105,110,100,101,120,0,42,116,111,115,111,99,107, +0,42,108,105,110,107,0,42,110,101,119,95,110,111,100,101,0,117,115,101,114,110,97,109,101,91,51,50,93,0,108,97, +115,116,121,0,111,117,116,112,117,116,115,0,42,115,116,111,114,97,103,101,0,109,105,110,105,119,105,100,116,104,0,99, +117,115,116,111,109,49,0,99,117,115,116,111,109,50,0,99,117,115,116,111,109,51,0,99,117,115,116,111,109,52,0,110, +101,101,100,95,101,120,101,99,0,101,120,101,99,0,116,111,116,114,0,98,117,116,114,0,112,114,118,114,0,42,116,121, +112,101,105,110,102,111,0,42,102,114,111,109,110,111,100,101,0,42,116,111,110,111,100,101,0,42,102,114,111,109,115,111, +99,107,0,110,111,100,101,115,0,108,105,110,107,115,0,42,115,116,97,99,107,0,42,116,104,114,101,97,100,115,116,97, +99,107,0,105,110,105,116,0,115,116,97,99,107,115,105,122,101,0,99,117,114,95,105,110,100,101,120,0,97,108,108,116, +121,112,101,115,0,42,111,119,110,116,121,112,101,0,42,115,101,108,105,110,0,42,115,101,108,111,117,116,0,40,42,116, +105,109,101,99,117,114,115,111,114,41,40,41,0,40,42,115,116,97,116,115,95,100,114,97,119,41,40,41,0,40,42,116, +101,115,116,95,98,114,101,97,107,41,40,41,0,99,121,99,108,105,99,0,109,111,118,105,101,0,115,97,109,112,108,101, +115,0,109,105,110,115,112,101,101,100,0,112,101,114,99,101,110,116,120,0,112,101,114,99,101,110,116,121,0,98,111,107, +101,104,0,99,117,114,118,101,100,0,105,109,97,103,101,95,105,110,95,119,105,100,116,104,0,105,109,97,103,101,95,105, +110,95,104,101,105,103,104,116,0,99,101,110,116,101,114,95,120,0,99,101,110,116,101,114,95,121,0,115,112,105,110,0, +105,116,101,114,0,119,114,97,112,0,115,105,103,109,97,95,99,111,108,111,114,0,115,105,103,109,97,95,115,112,97,99, +101,0,104,117,101,0,115,97,116,0,116,49,0,116,50,0,116,51,0,102,115,116,114,101,110,103,116,104,0,102,97,108, +112,104,97,0,107,101,121,91,52,93,0,120,49,0,120,50,0,121,49,0,121,50,0,99,111,108,110,97,109,101,91,51, +50,93,0,98,107,116,121,112,101,0,114,111,116,97,116,105,111,110,0,112,114,101,118,105,101,119,0,103,97,109,99,111, +0,110,111,95,122,98,117,102,0,102,115,116,111,112,0,109,97,120,98,108,117,114,0,98,116,104,114,101,115,104,0,42, +100,105,99,116,0,42,110,111,100,101,0,97,110,103,108,101,95,111,102,115,0,99,111,108,109,111,100,0,109,105,120,0, +116,104,114,101,115,104,111,108,100,0,102,97,100,101,0,109,0,99,0,106,105,116,0,112,114,111,106,0,102,105,116,0, +115,104,111,114,116,121,0,109,105,110,116,97,98,108,101,0,109,97,120,116,97,98,108,101,0,101,120,116,95,105,110,91, +50,93,0,101,120,116,95,111,117,116,91,50,93,0,42,99,117,114,118,101,0,42,116,97,98,108,101,0,42,112,114,101, +109,117,108,116,97,98,108,101,0,99,117,114,114,0,99,108,105,112,114,0,99,109,91,52,93,0,98,108,97,99,107,91, +51,93,0,119,104,105,116,101,91,51,93,0,98,119,109,117,108,91,51,93,0,115,97,109,112,108,101,91,51,93,0,111, +102,102,115,101,116,91,50,93,0,105,110,110,101,114,114,97,100,105,117,115,0,114,97,116,101,0,114,103,98,91,51,93, +0,99,108,111,110,101,0,97,99,116,105,118,101,95,114,110,100,0,97,99,116,105,118,101,95,99,108,111,110,101,0,97, +99,116,105,118,101,95,109,97,115,107,0,42,108,97,121,101,114,115,0,116,111,116,108,97,121,101,114,0,109,97,120,108, +97,121,101,114,0,116,111,116,115,105,122,101,0,42,112,111,111,108,0,101,100,105,116,102,108,97,103,0,118,101,108,91, +51,93,0,114,111,116,91,52,93,0,97,118,101,91,51,93,0,110,117,109,0,112,97,114,101,110,116,0,112,97,91,52, +93,0,119,91,52,93,0,102,117,118,91,52,93,0,102,111,102,102,115,101,116,0,114,97,110,100,91,51,93,0,42,115, +116,105,99,107,95,111,98,0,112,114,101,118,95,115,116,97,116,101,0,42,104,97,105,114,0,105,95,114,111,116,91,52, +93,0,114,95,114,111,116,91,52,93,0,114,95,97,118,101,91,51,93,0,114,95,118,101,91,51,93,0,100,105,101,116, +105,109,101,0,98,97,110,107,0,115,105,122,101,109,117,108,0,110,117,109,95,100,109,99,97,99,104,101,0,98,112,105, +0,97,108,105,118,101,0,108,111,111,112,0,100,105,115,116,114,0,112,104,121,115,116,121,112,101,0,114,111,116,109,111, +100,101,0,97,118,101,109,111,100,101,0,114,101,97,99,116,101,118,101,110,116,0,100,114,97,119,0,100,114,97,119,95, +97,115,0,100,114,97,119,95,115,105,122,101,0,99,104,105,108,100,116,121,112,101,0,100,114,97,119,95,115,116,101,112, +0,114,101,110,95,115,116,101,112,0,104,97,105,114,95,115,116,101,112,0,107,101,121,115,95,115,116,101,112,0,97,100, +97,112,116,95,97,110,103,108,101,0,97,100,97,112,116,95,112,105,120,0,114,111,116,102,114,111,109,0,105,110,116,101, +103,114,97,116,111,114,0,110,98,101,116,119,101,101,110,0,98,111,105,100,110,101,105,103,104,98,111,117,114,115,0,98, +98,95,97,108,105,103,110,0,98,98,95,117,118,95,115,112,108,105,116,0,98,98,95,97,110,105,109,0,98,98,95,115, +112,108,105,116,95,111,102,102,115,101,116,0,98,98,95,116,105,108,116,0,98,98,95,114,97,110,100,95,116,105,108,116, +0,98,98,95,111,102,102,115,101,116,91,50,93,0,115,105,109,112,108,105,102,121,95,102,108,97,103,0,115,105,109,112, +108,105,102,121,95,114,101,102,115,105,122,101,0,115,105,109,112,108,105,102,121,95,114,97,116,101,0,115,105,109,112,108, +105,102,121,95,116,114,97,110,115,105,116,105,111,110,0,115,105,109,112,108,105,102,121,95,118,105,101,119,112,111,114,116, +0,116,105,109,101,116,119,101,97,107,0,106,105,116,102,97,99,0,107,101,121,101,100,95,116,105,109,101,0,101,102,102, +95,104,97,105,114,0,103,114,105,100,95,114,101,115,0,112,97,114,116,102,97,99,0,116,97,110,102,97,99,0,116,97, +110,112,104,97,115,101,0,114,101,97,99,116,102,97,99,0,97,118,101,102,97,99,0,112,104,97,115,101,102,97,99,0, +114,97,110,100,114,111,116,102,97,99,0,114,97,110,100,112,104,97,115,101,102,97,99,0,114,97,110,100,115,105,122,101, +0,114,101,97,99,116,115,104,97,112,101,0,97,99,99,91,51,93,0,100,114,97,103,102,97,99,0,98,114,111,119,110, +102,97,99,0,100,97,109,112,102,97,99,0,97,98,115,108,101,110,103,116,104,0,114,97,110,100,108,101,110,103,116,104, +0,99,104,105,108,100,95,110,98,114,0,114,101,110,95,99,104,105,108,100,95,110,98,114,0,112,97,114,101,110,116,115, +0,99,104,105,108,100,115,105,122,101,0,99,104,105,108,100,114,97,110,100,115,105,122,101,0,99,104,105,108,100,114,97, +100,0,99,104,105,108,100,102,108,97,116,0,99,104,105,108,100,115,112,114,101,97,100,0,99,108,117,109,112,102,97,99, +0,99,108,117,109,112,112,111,119,0,114,111,117,103,104,49,0,114,111,117,103,104,49,95,115,105,122,101,0,114,111,117, +103,104,50,0,114,111,117,103,104,50,95,115,105,122,101,0,114,111,117,103,104,50,95,116,104,114,101,115,0,114,111,117, +103,104,95,101,110,100,0,114,111,117,103,104,95,101,110,100,95,115,104,97,112,101,0,98,114,97,110,99,104,95,116,104, +114,101,115,0,100,114,97,119,95,108,105,110,101,91,50,93,0,109,97,120,95,108,97,116,95,97,99,99,0,109,97,120, +95,116,97,110,95,97,99,99,0,97,118,101,114,97,103,101,95,118,101,108,0,98,97,110,107,105,110,103,0,109,97,120, +95,98,97,110,107,0,103,114,111,117,110,100,122,0,98,111,105,100,102,97,99,91,56,93,0,98,111,105,100,114,117,108, +101,91,56,93,0,42,101,102,102,95,103,114,111,117,112,0,42,100,117,112,95,111,98,0,42,98,98,95,111,98,0,42, +112,100,50,0,42,112,97,114,116,0,42,101,100,105,116,0,42,42,112,97,116,104,99,97,99,104,101,0,42,42,99,104, +105,108,100,99,97,99,104,101,0,112,97,116,104,99,97,99,104,101,98,117,102,115,0,99,104,105,108,100,99,97,99,104, +101,98,117,102,115,0,42,116,97,114,103,101,116,95,111,98,0,42,107,101,121,101,100,95,111,98,0,42,108,97,116,116, +105,99,101,0,101,102,102,101,99,116,111,114,115,0,114,101,97,99,116,101,118,101,110,116,115,0,116,111,116,99,104,105, +108,100,0,116,111,116,99,97,99,104,101,100,0,116,111,116,99,104,105,108,100,99,97,99,104,101,0,116,97,114,103,101, +116,95,112,115,121,115,0,107,101,121,101,100,95,112,115,121,115,0,116,111,116,107,101,121,101,100,0,98,97,107,101,115, +112,97,99,101,0,98,98,95,117,118,110,97,109,101,91,51,93,91,51,50,93,0,118,103,114,111,117,112,91,49,50,93, +0,118,103,95,110,101,103,0,114,116,51,0,42,114,101,110,100,101,114,100,97,116,97,0,42,99,97,99,104,101,0,67, +100,105,115,0,67,118,105,0,91,51,93,0,115,116,114,117,99,116,117,114,97,108,0,98,101,110,100,105,110,103,0,109, +97,120,95,98,101,110,100,0,109,97,120,95,115,116,114,117,99,116,0,109,97,120,95,115,104,101,97,114,0,97,118,103, +95,115,112,114,105,110,103,95,108,101,110,0,116,105,109,101,115,99,97,108,101,0,101,102,102,95,102,111,114,99,101,95, +115,99,97,108,101,0,101,102,102,95,119,105,110,100,95,115,99,97,108,101,0,115,105,109,95,116,105,109,101,95,111,108, +100,0,115,116,101,112,115,80,101,114,70,114,97,109,101,0,112,114,101,114,111,108,108,0,109,97,120,115,112,114,105,110, +103,108,101,110,0,115,111,108,118,101,114,95,116,121,112,101,0,118,103,114,111,117,112,95,98,101,110,100,0,118,103,114, +111,117,112,95,109,97,115,115,0,118,103,114,111,117,112,95,115,116,114,117,99,116,0,112,114,101,115,101,116,115,0,42, +99,111,108,108,105,115,105,111,110,95,108,105,115,116,0,101,112,115,105,108,111,110,0,115,101,108,102,95,102,114,105,99, +116,105,111,110,0,115,101,108,102,101,112,115,105,108,111,110,0,115,101,108,102,95,108,111,111,112,95,99,111,117,110,116, +0,108,111,111,112,95,99,111,117,110,116,0,112,114,101,115,115,117,114,101,0,42,112,111,105,110,116,115,0,116,111,116, +112,111,105,110,116,115,0,116,104,105,99,107,110,101,115,115,0,115,116,114,111,107,101,115,0,102,114,97,109,101,110,117, +109,0,42,97,99,116,102,114,97,109,101,0,103,115,116,101,112,0,105,110,102,111,91,49,50,56,93,0,115,98,117,102, +102,101,114,95,115,105,122,101,0,115,98,117,102,102,101,114,95,115,102,108,97,103,0,42,115,98,117,102,102,101,114,0, +0,0,0,84,89,80,69,100,1,0,0,99,104,97,114,0,117,99,104,97,114,0,115,104,111,114,116,0,117,115,104,111, +114,116,0,105,110,116,0,108,111,110,103,0,117,108,111,110,103,0,102,108,111,97,116,0,100,111,117,98,108,101,0,118, +111,105,100,0,76,105,110,107,0,76,105,110,107,68,97,116,97,0,76,105,115,116,66,97,115,101,0,118,101,99,50,115, +0,118,101,99,50,105,0,118,101,99,50,102,0,118,101,99,50,100,0,118,101,99,51,105,0,118,101,99,51,102,0,118, +101,99,51,100,0,118,101,99,52,105,0,118,101,99,52,102,0,118,101,99,52,100,0,114,99,116,105,0,114,99,116,102, +0,73,68,80,114,111,112,101,114,116,121,68,97,116,97,0,73,68,80,114,111,112,101,114,116,121,0,73,68,0,76,105, +98,114,97,114,121,0,70,105,108,101,68,97,116,97,0,80,114,101,118,105,101,119,73,109,97,103,101,0,73,112,111,68, +114,105,118,101,114,0,79,98,106,101,99,116,0,73,112,111,67,117,114,118,101,0,66,80,111,105,110,116,0,66,101,122, +84,114,105,112,108,101,0,73,112,111,0,75,101,121,66,108,111,99,107,0,75,101,121,0,83,99,114,105,112,116,76,105, +110,107,0,84,101,120,116,76,105,110,101,0,84,101,120,116,77,97,114,107,101,114,0,84,101,120,116,0,80,97,99,107, +101,100,70,105,108,101,0,67,97,109,101,114,97,0,73,109,97,103,101,85,115,101,114,0,73,109,97,103,101,0,71,80, +85,84,101,120,116,117,114,101,0,97,110,105,109,0,82,101,110,100,101,114,82,101,115,117,108,116,0,77,84,101,120,0, +84,101,120,0,80,108,117,103,105,110,84,101,120,0,67,66,68,97,116,97,0,67,111,108,111,114,66,97,110,100,0,69, +110,118,77,97,112,0,73,109,66,117,102,0,98,78,111,100,101,84,114,101,101,0,84,101,120,77,97,112,112,105,110,103, +0,76,97,109,112,0,67,117,114,118,101,77,97,112,112,105,110,103,0,87,97,118,101,0,77,97,116,101,114,105,97,108, +0,71,114,111,117,112,0,86,70,111,110,116,0,86,70,111,110,116,68,97,116,97,0,77,101,116,97,69,108,101,109,0, +66,111,117,110,100,66,111,120,0,77,101,116,97,66,97,108,108,0,78,117,114,98,0,67,104,97,114,73,110,102,111,0, +84,101,120,116,66,111,120,0,67,117,114,118,101,0,80,97,116,104,0,77,101,115,104,0,77,70,97,99,101,0,77,84, +70,97,99,101,0,84,70,97,99,101,0,77,86,101,114,116,0,77,69,100,103,101,0,77,68,101,102,111,114,109,86,101, +114,116,0,77,67,111,108,0,77,83,116,105,99,107,121,0,77,83,101,108,101,99,116,0,67,117,115,116,111,109,68,97, +116,97,0,77,117,108,116,105,114,101,115,0,80,97,114,116,105,97,108,86,105,115,105,98,105,108,105,116,121,0,77,68, +101,102,111,114,109,87,101,105,103,104,116,0,77,84,101,120,80,111,108,121,0,77,76,111,111,112,85,86,0,77,76,111, +111,112,67,111,108,0,77,70,108,111,97,116,80,114,111,112,101,114,116,121,0,77,73,110,116,80,114,111,112,101,114,116, +121,0,77,83,116,114,105,110,103,80,114,111,112,101,114,116,121,0,79,114,105,103,83,112,97,99,101,70,97,99,101,0, +77,117,108,116,105,114,101,115,67,111,108,0,77,117,108,116,105,114,101,115,67,111,108,70,97,99,101,0,77,117,108,116, +105,114,101,115,70,97,99,101,0,77,117,108,116,105,114,101,115,69,100,103,101,0,77,117,108,116,105,114,101,115,76,101, +118,101,108,0,77,117,108,116,105,114,101,115,77,97,112,78,111,100,101,0,77,111,100,105,102,105,101,114,68,97,116,97, +0,83,117,98,115,117,114,102,77,111,100,105,102,105,101,114,68,97,116,97,0,76,97,116,116,105,99,101,77,111,100,105, +102,105,101,114,68,97,116,97,0,67,117,114,118,101,77,111,100,105,102,105,101,114,68,97,116,97,0,66,117,105,108,100, +77,111,100,105,102,105,101,114,68,97,116,97,0,77,97,115,107,77,111,100,105,102,105,101,114,68,97,116,97,0,65,114, +114,97,121,77,111,100,105,102,105,101,114,68,97,116,97,0,77,105,114,114,111,114,77,111,100,105,102,105,101,114,68,97, +116,97,0,69,100,103,101,83,112,108,105,116,77,111,100,105,102,105,101,114,68,97,116,97,0,66,101,118,101,108,77,111, +100,105,102,105,101,114,68,97,116,97,0,66,77,101,115,104,77,111,100,105,102,105,101,114,68,97,116,97,0,68,105,115, +112,108,97,99,101,77,111,100,105,102,105,101,114,68,97,116,97,0,85,86,80,114,111,106,101,99,116,77,111,100,105,102, +105,101,114,68,97,116,97,0,68,101,99,105,109,97,116,101,77,111,100,105,102,105,101,114,68,97,116,97,0,83,109,111, +111,116,104,77,111,100,105,102,105,101,114,68,97,116,97,0,67,97,115,116,77,111,100,105,102,105,101,114,68,97,116,97, +0,87,97,118,101,77,111,100,105,102,105,101,114,68,97,116,97,0,65,114,109,97,116,117,114,101,77,111,100,105,102,105, +101,114,68,97,116,97,0,72,111,111,107,77,111,100,105,102,105,101,114,68,97,116,97,0,83,111,102,116,98,111,100,121, +77,111,100,105,102,105,101,114,68,97,116,97,0,67,108,111,116,104,77,111,100,105,102,105,101,114,68,97,116,97,0,67, +108,111,116,104,0,67,108,111,116,104,83,105,109,83,101,116,116,105,110,103,115,0,67,108,111,116,104,67,111,108,108,83, +101,116,116,105,110,103,115,0,80,111,105,110,116,67,97,99,104,101,0,67,111,108,108,105,115,105,111,110,77,111,100,105, +102,105,101,114,68,97,116,97,0,66,86,72,84,114,101,101,0,83,117,114,102,97,99,101,77,111,100,105,102,105,101,114, +68,97,116,97,0,68,101,114,105,118,101,100,77,101,115,104,0,66,86,72,84,114,101,101,70,114,111,109,77,101,115,104, +0,66,111,111,108,101,97,110,77,111,100,105,102,105,101,114,68,97,116,97,0,77,68,101,102,73,110,102,108,117,101,110, +99,101,0,77,68,101,102,67,101,108,108,0,77,101,115,104,68,101,102,111,114,109,77,111,100,105,102,105,101,114,68,97, +116,97,0,80,97,114,116,105,99,108,101,83,121,115,116,101,109,77,111,100,105,102,105,101,114,68,97,116,97,0,80,97, +114,116,105,99,108,101,83,121,115,116,101,109,0,80,97,114,116,105,99,108,101,73,110,115,116,97,110,99,101,77,111,100, +105,102,105,101,114,68,97,116,97,0,69,120,112,108,111,100,101,77,111,100,105,102,105,101,114,68,97,116,97,0,70,108, +117,105,100,115,105,109,77,111,100,105,102,105,101,114,68,97,116,97,0,70,108,117,105,100,115,105,109,83,101,116,116,105, +110,103,115,0,83,104,114,105,110,107,119,114,97,112,77,111,100,105,102,105,101,114,68,97,116,97,0,83,105,109,112,108, +101,68,101,102,111,114,109,77,111,100,105,102,105,101,114,68,97,116,97,0,76,97,116,116,105,99,101,0,98,68,101,102, +111,114,109,71,114,111,117,112,0,98,65,99,116,105,111,110,0,98,80,111,115,101,0,66,117,108,108,101,116,83,111,102, +116,66,111,100,121,0,80,97,114,116,68,101,102,108,101,99,116,0,83,111,102,116,66,111,100,121,0,79,98,72,111,111, +107,0,82,78,71,0,83,66,86,101,114,116,101,120,0,66,111,100,121,80,111,105,110,116,0,66,111,100,121,83,112,114, +105,110,103,0,83,66,83,99,114,97,116,99,104,0,87,111,114,108,100,0,82,97,100,105,111,0,66,97,115,101,0,65, +118,105,67,111,100,101,99,68,97,116,97,0,81,117,105,99,107,116,105,109,101,67,111,100,101,99,68,97,116,97,0,70, +70,77,112,101,103,67,111,100,101,99,68,97,116,97,0,65,117,100,105,111,68,97,116,97,0,83,99,101,110,101,82,101, +110,100,101,114,76,97,121,101,114,0,82,101,110,100,101,114,68,97,116,97,0,82,101,110,100,101,114,80,114,111,102,105, +108,101,0,71,97,109,101,70,114,97,109,105,110,103,0,84,105,109,101,77,97,114,107,101,114,0,73,109,97,103,101,80, +97,105,110,116,83,101,116,116,105,110,103,115,0,66,114,117,115,104,0,80,97,114,116,105,99,108,101,66,114,117,115,104, +68,97,116,97,0,80,97,114,116,105,99,108,101,69,100,105,116,83,101,116,116,105,110,103,115,0,84,114,97,110,115,102, +111,114,109,79,114,105,101,110,116,97,116,105,111,110,0,84,111,111,108,83,101,116,116,105,110,103,115,0,66,114,117,115, +104,68,97,116,97,0,83,99,117,108,112,116,68,97,116,97,0,83,99,117,108,112,116,83,101,115,115,105,111,110,0,83, +99,101,110,101,0,68,97,103,70,111,114,101,115,116,0,66,71,112,105,99,0,86,105,101,119,51,68,0,83,112,97,99, +101,76,105,110,107,0,83,99,114,65,114,101,97,0,82,101,110,100,101,114,73,110,102,111,0,82,101,116,111,112,111,86, +105,101,119,68,97,116,97,0,86,105,101,119,68,101,112,116,104,115,0,98,71,80,100,97,116,97,0,86,105,101,119,50, +68,0,83,112,97,99,101,73,110,102,111,0,83,112,97,99,101,73,112,111,0,83,112,97,99,101,66,117,116,115,0,83, +112,97,99,101,83,101,113,0,83,112,97,99,101,70,105,108,101,0,100,105,114,101,110,116,114,121,0,66,108,101,110,100, +72,97,110,100,108,101,0,83,112,97,99,101,79,111,112,115,0,84,114,101,101,83,116,111,114,101,0,84,114,101,101,83, +116,111,114,101,69,108,101,109,0,83,112,97,99,101,73,109,97,103,101,0,83,112,97,99,101,78,108,97,0,83,112,97, +99,101,84,101,120,116,0,83,99,114,105,112,116,0,83,112,97,99,101,83,99,114,105,112,116,0,83,112,97,99,101,84, +105,109,101,0,83,112,97,99,101,78,111,100,101,0,83,112,97,99,101,73,109,97,83,101,108,0,70,105,108,101,76,105, +115,116,0,84,104,101,109,101,85,73,0,84,104,101,109,101,83,112,97,99,101,0,84,104,101,109,101,87,105,114,101,67, +111,108,111,114,0,98,84,104,101,109,101,0,83,111,108,105,100,76,105,103,104,116,0,85,115,101,114,68,101,102,0,98, +83,99,114,101,101,110,0,83,99,114,86,101,114,116,0,83,99,114,69,100,103,101,0,80,97,110,101,108,0,70,105,108, +101,71,108,111,98,97,108,0,83,116,114,105,112,69,108,101,109,0,84,83,116,114,105,112,69,108,101,109,0,83,116,114, +105,112,67,114,111,112,0,83,116,114,105,112,84,114,97,110,115,102,111,114,109,0,83,116,114,105,112,67,111,108,111,114, +66,97,108,97,110,99,101,0,83,116,114,105,112,67,111,108,111,114,66,97,108,97,110,99,101,71,85,73,72,101,108,112, +101,114,0,83,116,114,105,112,80,114,111,120,121,0,83,116,114,105,112,0,80,108,117,103,105,110,83,101,113,0,83,101, +113,117,101,110,99,101,0,98,83,111,117,110,100,0,104,100,97,117,100,105,111,0,77,101,116,97,83,116,97,99,107,0, +69,100,105,116,105,110,103,0,87,105,112,101,86,97,114,115,0,71,108,111,119,86,97,114,115,0,84,114,97,110,115,102, +111,114,109,86,97,114,115,0,83,111,108,105,100,67,111,108,111,114,86,97,114,115,0,83,112,101,101,100,67,111,110,116, +114,111,108,86,97,114,115,0,69,102,102,101,99,116,0,66,117,105,108,100,69,102,102,0,80,97,114,116,69,102,102,0, +80,97,114,116,105,99,108,101,0,87,97,118,101,69,102,102,0,79,111,112,115,0,98,80,114,111,112,101,114,116,121,0, +98,78,101,97,114,83,101,110,115,111,114,0,98,77,111,117,115,101,83,101,110,115,111,114,0,98,84,111,117,99,104,83, +101,110,115,111,114,0,98,75,101,121,98,111,97,114,100,83,101,110,115,111,114,0,98,80,114,111,112,101,114,116,121,83, +101,110,115,111,114,0,98,65,99,116,117,97,116,111,114,83,101,110,115,111,114,0,98,68,101,108,97,121,83,101,110,115, +111,114,0,98,67,111,108,108,105,115,105,111,110,83,101,110,115,111,114,0,98,82,97,100,97,114,83,101,110,115,111,114, +0,98,82,97,110,100,111,109,83,101,110,115,111,114,0,98,82,97,121,83,101,110,115,111,114,0,98,77,101,115,115,97, +103,101,83,101,110,115,111,114,0,98,83,101,110,115,111,114,0,98,67,111,110,116,114,111,108,108,101,114,0,98,74,111, +121,115,116,105,99,107,83,101,110,115,111,114,0,98,69,120,112,114,101,115,115,105,111,110,67,111,110,116,0,98,80,121, +116,104,111,110,67,111,110,116,0,98,65,99,116,117,97,116,111,114,0,98,65,100,100,79,98,106,101,99,116,65,99,116, +117,97,116,111,114,0,98,65,99,116,105,111,110,65,99,116,117,97,116,111,114,0,98,83,111,117,110,100,65,99,116,117, +97,116,111,114,0,98,67,68,65,99,116,117,97,116,111,114,0,98,69,100,105,116,79,98,106,101,99,116,65,99,116,117, +97,116,111,114,0,98,83,99,101,110,101,65,99,116,117,97,116,111,114,0,98,80,114,111,112,101,114,116,121,65,99,116, +117,97,116,111,114,0,98,79,98,106,101,99,116,65,99,116,117,97,116,111,114,0,98,73,112,111,65,99,116,117,97,116, +111,114,0,98,67,97,109,101,114,97,65,99,116,117,97,116,111,114,0,98,67,111,110,115,116,114,97,105,110,116,65,99, +116,117,97,116,111,114,0,98,71,114,111,117,112,65,99,116,117,97,116,111,114,0,98,82,97,110,100,111,109,65,99,116, +117,97,116,111,114,0,98,77,101,115,115,97,103,101,65,99,116,117,97,116,111,114,0,98,71,97,109,101,65,99,116,117, +97,116,111,114,0,98,86,105,115,105,98,105,108,105,116,121,65,99,116,117,97,116,111,114,0,98,84,119,111,68,70,105, +108,116,101,114,65,99,116,117,97,116,111,114,0,98,80,97,114,101,110,116,65,99,116,117,97,116,111,114,0,98,83,116, +97,116,101,65,99,116,117,97,116,111,114,0,70,114,101,101,67,97,109,101,114,97,0,98,83,97,109,112,108,101,0,98, +83,111,117,110,100,76,105,115,116,101,110,101,114,0,83,112,97,99,101,83,111,117,110,100,0,71,114,111,117,112,79,98, +106,101,99,116,0,66,111,110,101,0,98,65,114,109,97,116,117,114,101,0,98,80,111,115,101,67,104,97,110,110,101,108, +0,98,65,99,116,105,111,110,71,114,111,117,112,0,98,65,99,116,105,111,110,67,104,97,110,110,101,108,0,83,112,97, +99,101,65,99,116,105,111,110,0,98,67,111,110,115,116,114,97,105,110,116,67,104,97,110,110,101,108,0,98,67,111,110, +115,116,114,97,105,110,116,0,98,67,111,110,115,116,114,97,105,110,116,84,97,114,103,101,116,0,98,80,121,116,104,111, +110,67,111,110,115,116,114,97,105,110,116,0,98,75,105,110,101,109,97,116,105,99,67,111,110,115,116,114,97,105,110,116, +0,98,84,114,97,99,107,84,111,67,111,110,115,116,114,97,105,110,116,0,98,82,111,116,97,116,101,76,105,107,101,67, +111,110,115,116,114,97,105,110,116,0,98,76,111,99,97,116,101,76,105,107,101,67,111,110,115,116,114,97,105,110,116,0, +98,77,105,110,77,97,120,67,111,110,115,116,114,97,105,110,116,0,98,83,105,122,101,76,105,107,101,67,111,110,115,116, +114,97,105,110,116,0,98,65,99,116,105,111,110,67,111,110,115,116,114,97,105,110,116,0,98,76,111,99,107,84,114,97, +99,107,67,111,110,115,116,114,97,105,110,116,0,98,70,111,108,108,111,119,80,97,116,104,67,111,110,115,116,114,97,105, +110,116,0,98,83,116,114,101,116,99,104,84,111,67,111,110,115,116,114,97,105,110,116,0,98,82,105,103,105,100,66,111, +100,121,74,111,105,110,116,67,111,110,115,116,114,97,105,110,116,0,98,67,108,97,109,112,84,111,67,111,110,115,116,114, +97,105,110,116,0,98,67,104,105,108,100,79,102,67,111,110,115,116,114,97,105,110,116,0,98,84,114,97,110,115,102,111, +114,109,67,111,110,115,116,114,97,105,110,116,0,98,76,111,99,76,105,109,105,116,67,111,110,115,116,114,97,105,110,116, +0,98,82,111,116,76,105,109,105,116,67,111,110,115,116,114,97,105,110,116,0,98,83,105,122,101,76,105,109,105,116,67, +111,110,115,116,114,97,105,110,116,0,98,68,105,115,116,76,105,109,105,116,67,111,110,115,116,114,97,105,110,116,0,98, +83,104,114,105,110,107,119,114,97,112,67,111,110,115,116,114,97,105,110,116,0,98,65,99,116,105,111,110,77,111,100,105, +102,105,101,114,0,98,65,99,116,105,111,110,83,116,114,105,112,0,98,78,111,100,101,83,116,97,99,107,0,98,78,111, +100,101,83,111,99,107,101,116,0,98,78,111,100,101,76,105,110,107,0,98,78,111,100,101,0,98,78,111,100,101,80,114, +101,118,105,101,119,0,98,78,111,100,101,84,121,112,101,0,78,111,100,101,73,109,97,103,101,65,110,105,109,0,78,111, +100,101,66,108,117,114,68,97,116,97,0,78,111,100,101,68,66,108,117,114,68,97,116,97,0,78,111,100,101,66,105,108, +97,116,101,114,97,108,66,108,117,114,68,97,116,97,0,78,111,100,101,72,117,101,83,97,116,0,78,111,100,101,73,109, +97,103,101,70,105,108,101,0,78,111,100,101,67,104,114,111,109,97,0,78,111,100,101,84,119,111,88,89,115,0,78,111, +100,101,84,119,111,70,108,111,97,116,115,0,78,111,100,101,71,101,111,109,101,116,114,121,0,78,111,100,101,86,101,114, +116,101,120,67,111,108,0,78,111,100,101,68,101,102,111,99,117,115,0,78,111,100,101,83,99,114,105,112,116,68,105,99, +116,0,78,111,100,101,71,108,97,114,101,0,78,111,100,101,84,111,110,101,109,97,112,0,78,111,100,101,76,101,110,115, +68,105,115,116,0,84,101,120,78,111,100,101,79,117,116,112,117,116,0,67,117,114,118,101,77,97,112,80,111,105,110,116, +0,67,117,114,118,101,77,97,112,0,66,114,117,115,104,67,108,111,110,101,0,67,117,115,116,111,109,68,97,116,97,76, +97,121,101,114,0,72,97,105,114,75,101,121,0,80,97,114,116,105,99,108,101,75,101,121,0,67,104,105,108,100,80,97, +114,116,105,99,108,101,0,80,97,114,116,105,99,108,101,68,97,116,97,0,80,97,114,116,105,99,108,101,83,101,116,116, +105,110,103,115,0,80,97,114,116,105,99,108,101,69,100,105,116,0,80,97,114,116,105,99,108,101,67,97,99,104,101,75, +101,121,0,76,105,110,107,78,111,100,101,0,98,71,80,68,115,112,111,105,110,116,0,98,71,80,68,115,116,114,111,107, +101,0,98,71,80,68,102,114,97,109,101,0,98,71,80,68,108,97,121,101,114,0,0,84,76,69,78,1,0,1,0,2, +0,2,0,4,0,4,0,4,0,4,0,8,0,0,0,16,0,24,0,16,0,4,0,8,0,8,0,16,0,12,0,12, +0,24,0,16,0,16,0,32,0,16,0,16,0,32,0,96,0,72,0,72,2,0,0,40,0,-112,0,48,4,112,0,36, +0,56,0,112,0,-128,0,-96,0,24,0,40,0,48,0,-80,0,24,0,-88,0,32,0,-72,1,0,0,0,0,0,0,-112, +0,64,1,120,1,24,0,8,3,-56,0,0,0,-56,0,-120,0,-16,1,56,1,80,0,-16,2,104,0,96,1,0,0,-128, +0,104,0,-72,0,80,0,8,0,16,0,-96,1,0,0,-112,1,20,0,48,0,64,0,24,0,12,0,16,0,4,0,8, +0,8,0,32,0,112,0,48,0,8,0,16,0,8,0,8,0,4,0,4,0,0,1,32,0,16,0,64,0,24,0,12, +0,96,0,0,0,64,0,88,0,104,0,112,0,80,0,112,0,-112,0,80,0,72,0,120,0,72,0,-88,0,-48,0,72, +0,104,0,120,0,-48,0,120,0,-56,0,64,0,96,0,0,0,-120,0,32,0,20,0,-112,0,0,0,80,0,0,0,0, +0,80,0,8,0,8,0,0,1,96,0,-104,1,80,0,80,0,80,0,-72,1,-128,0,120,0,-104,0,48,0,-128,0,72, +0,120,0,-120,0,16,1,-32,0,0,0,16,0,0,0,0,0,0,0,-32,1,40,0,40,0,-72,0,-104,0,56,0,16, +0,88,0,-24,3,64,0,16,0,88,0,16,0,24,1,8,0,72,0,88,0,-16,0,8,0,-8,0,0,0,64,6,0, +0,64,0,88,3,48,0,8,1,0,0,0,0,0,0,32,0,-120,0,48,0,120,1,-16,0,-40,0,-8,1,0,0,0, +0,48,1,16,0,16,0,32,1,-64,0,-112,0,120,2,56,0,-80,0,0,1,-72,2,0,0,-104,0,-48,0,16,0,64, +14,56,0,40,12,-88,0,32,0,40,0,-16,0,40,0,80,0,48,0,16,0,8,0,64,0,0,0,0,1,32,1,-56, +1,8,1,72,1,0,0,32,0,48,0,12,0,24,0,48,0,16,0,32,0,24,0,32,0,72,1,0,0,64,0,64, +0,80,0,48,0,8,0,48,0,72,0,104,0,40,0,8,0,72,0,44,0,40,0,108,0,72,0,96,0,104,0,60, +0,-128,0,80,0,80,0,16,0,96,0,32,0,20,0,88,0,24,0,80,0,112,0,84,0,32,0,96,0,64,0,56, +0,112,0,-116,0,4,0,24,0,16,0,8,0,40,0,0,0,88,0,-64,0,40,0,24,1,-104,0,-48,1,88,0,88, +0,-48,0,56,0,80,0,-128,0,80,0,112,0,56,0,48,0,48,0,72,0,48,0,72,0,48,0,24,0,56,0,104, +0,16,0,112,0,96,0,28,0,28,0,28,0,56,0,24,0,72,0,-88,0,40,0,-112,0,48,0,-8,0,0,0,0, +0,16,0,40,0,28,0,12,0,12,0,16,1,40,0,8,0,8,0,64,0,32,0,24,0,16,0,24,0,32,0,8, +0,32,0,12,0,56,0,24,0,72,0,24,0,56,0,72,0,8,1,16,2,0,0,0,0,0,0,16,0,32,0,40, +0,-64,0,83,84,82,67,57,1,0,0,10,0,2,0,10,0,0,0,10,0,1,0,11,0,3,0,11,0,0,0,11, +0,1,0,9,0,2,0,12,0,2,0,9,0,3,0,9,0,4,0,13,0,2,0,2,0,5,0,2,0,6,0,14, +0,2,0,4,0,5,0,4,0,6,0,15,0,2,0,7,0,5,0,7,0,6,0,16,0,2,0,8,0,5,0,8, +0,6,0,17,0,3,0,4,0,5,0,4,0,6,0,4,0,7,0,18,0,3,0,7,0,5,0,7,0,6,0,7, +0,7,0,19,0,3,0,8,0,5,0,8,0,6,0,8,0,7,0,20,0,4,0,4,0,5,0,4,0,6,0,4, +0,7,0,4,0,8,0,21,0,4,0,7,0,5,0,7,0,6,0,7,0,7,0,7,0,8,0,22,0,4,0,8, +0,5,0,8,0,6,0,8,0,7,0,8,0,8,0,23,0,4,0,4,0,9,0,4,0,10,0,4,0,11,0,4, +0,12,0,24,0,4,0,7,0,9,0,7,0,10,0,7,0,11,0,7,0,12,0,25,0,4,0,9,0,13,0,12, +0,14,0,4,0,15,0,4,0,16,0,26,0,10,0,26,0,0,0,26,0,1,0,0,0,17,0,0,0,18,0,0, +0,19,0,2,0,20,0,4,0,21,0,25,0,22,0,4,0,23,0,4,0,24,0,27,0,9,0,9,0,0,0,9, +0,1,0,27,0,25,0,28,0,26,0,0,0,27,0,2,0,28,0,2,0,20,0,4,0,29,0,26,0,30,0,28, +0,8,0,27,0,31,0,27,0,32,0,29,0,33,0,0,0,34,0,0,0,35,0,4,0,36,0,4,0,37,0,28, +0,38,0,30,0,6,0,4,0,39,0,4,0,40,0,2,0,41,0,2,0,42,0,2,0,43,0,4,0,44,0,31, +0,6,0,32,0,45,0,2,0,46,0,2,0,47,0,2,0,18,0,2,0,20,0,0,0,48,0,33,0,21,0,33, +0,0,0,33,0,1,0,34,0,49,0,35,0,50,0,24,0,51,0,24,0,52,0,2,0,46,0,2,0,47,0,2, +0,53,0,2,0,54,0,2,0,55,0,2,0,56,0,2,0,20,0,2,0,57,0,7,0,11,0,7,0,12,0,4, +0,58,0,7,0,59,0,7,0,60,0,7,0,61,0,31,0,62,0,36,0,7,0,27,0,31,0,12,0,63,0,24, +0,64,0,2,0,46,0,2,0,65,0,2,0,66,0,2,0,37,0,37,0,16,0,37,0,0,0,37,0,1,0,7, +0,67,0,7,0,61,0,2,0,18,0,2,0,47,0,2,0,68,0,2,0,20,0,4,0,69,0,4,0,70,0,9, +0,2,0,7,0,71,0,0,0,17,0,0,0,72,0,7,0,73,0,7,0,74,0,38,0,12,0,27,0,31,0,37, +0,75,0,0,0,76,0,4,0,77,0,7,0,61,0,12,0,78,0,36,0,79,0,27,0,80,0,2,0,18,0,2, +0,81,0,2,0,82,0,2,0,20,0,39,0,5,0,27,0,83,0,2,0,84,0,2,0,85,0,2,0,86,0,4, +0,37,0,40,0,6,0,40,0,0,0,40,0,1,0,0,0,87,0,0,0,88,0,4,0,23,0,4,0,89,0,41, +0,10,0,41,0,0,0,41,0,1,0,4,0,90,0,4,0,91,0,4,0,92,0,4,0,43,0,4,0,14,0,4, +0,93,0,0,0,94,0,0,0,95,0,42,0,15,0,27,0,31,0,0,0,96,0,4,0,93,0,4,0,97,0,12, +0,98,0,40,0,99,0,40,0,100,0,4,0,101,0,4,0,102,0,12,0,103,0,0,0,104,0,4,0,105,0,4, +0,106,0,9,0,107,0,8,0,108,0,43,0,5,0,4,0,109,0,4,0,110,0,4,0,93,0,4,0,37,0,9, +0,2,0,44,0,20,0,27,0,31,0,2,0,18,0,2,0,20,0,7,0,111,0,7,0,112,0,7,0,113,0,7, +0,114,0,7,0,115,0,7,0,116,0,7,0,117,0,7,0,118,0,7,0,119,0,7,0,120,0,7,0,121,0,2, +0,122,0,2,0,123,0,7,0,124,0,36,0,79,0,39,0,125,0,32,0,126,0,45,0,12,0,4,0,127,0,4, +0,-128,0,4,0,-127,0,4,0,-126,0,2,0,-125,0,2,0,-124,0,2,0,20,0,2,0,-123,0,2,0,-122,0,2, +0,-121,0,2,0,-120,0,2,0,-119,0,46,0,32,0,27,0,31,0,0,0,34,0,12,0,-118,0,47,0,-117,0,48, +0,-116,0,49,0,-115,0,2,0,-123,0,2,0,20,0,2,0,-114,0,2,0,18,0,2,0,37,0,2,0,43,0,4, +0,-113,0,2,0,-112,0,2,0,-111,0,2,0,-110,0,2,0,-109,0,2,0,-108,0,2,0,-107,0,4,0,-106,0,4, +0,-105,0,43,0,-104,0,30,0,-103,0,7,0,-102,0,4,0,-101,0,2,0,-100,0,2,0,-99,0,2,0,-98,0,2, +0,-97,0,7,0,-96,0,7,0,-95,0,9,0,-94,0,50,0,31,0,2,0,-93,0,2,0,-92,0,2,0,-91,0,2, +0,-90,0,32,0,-89,0,51,0,-88,0,0,0,-87,0,0,0,-86,0,0,0,-85,0,0,0,-84,0,0,0,-83,0,7, +0,-82,0,7,0,-81,0,2,0,-80,0,2,0,-79,0,2,0,-78,0,2,0,-77,0,2,0,-76,0,2,0,-75,0,2, +0,-74,0,7,0,-73,0,7,0,-72,0,7,0,-71,0,7,0,-70,0,7,0,-69,0,7,0,57,0,7,0,-68,0,7, +0,-67,0,7,0,-66,0,7,0,-65,0,7,0,-64,0,52,0,15,0,0,0,-63,0,9,0,-62,0,0,0,-61,0,0, +0,-60,0,4,0,-59,0,4,0,-58,0,9,0,-57,0,7,0,-56,0,7,0,-55,0,7,0,-54,0,4,0,-53,0,9, +0,-52,0,9,0,-51,0,4,0,-50,0,4,0,37,0,53,0,6,0,7,0,-73,0,7,0,-72,0,7,0,-71,0,7, +0,-49,0,7,0,67,0,4,0,64,0,54,0,5,0,2,0,20,0,2,0,36,0,2,0,64,0,2,0,-48,0,53, +0,-54,0,55,0,17,0,32,0,-89,0,46,0,-47,0,56,0,-46,0,7,0,-45,0,7,0,-44,0,2,0,18,0,2, +0,-43,0,7,0,113,0,7,0,114,0,7,0,-42,0,4,0,-41,0,2,0,-40,0,2,0,-39,0,4,0,-123,0,4, +0,-113,0,2,0,-38,0,2,0,-37,0,51,0,56,0,27,0,31,0,7,0,-36,0,7,0,-35,0,7,0,-34,0,7, +0,-33,0,7,0,-32,0,7,0,-31,0,7,0,-30,0,7,0,-29,0,7,0,-28,0,7,0,-27,0,7,0,-26,0,7, +0,-25,0,7,0,-24,0,7,0,-23,0,7,0,-22,0,7,0,-21,0,7,0,-20,0,7,0,-19,0,7,0,-18,0,7, +0,-17,0,2,0,-16,0,2,0,-15,0,2,0,-14,0,2,0,-13,0,2,0,-12,0,2,0,-11,0,2,0,-10,0,2, +0,20,0,2,0,18,0,2,0,-43,0,7,0,-9,0,7,0,-8,0,7,0,-7,0,7,0,-6,0,2,0,-5,0,2, +0,-4,0,2,0,-3,0,2,0,-125,0,4,0,23,0,4,0,-128,0,4,0,-127,0,4,0,-126,0,7,0,-2,0,7, +0,-1,0,7,0,-67,0,45,0,0,1,57,0,1,1,36,0,79,0,46,0,-47,0,52,0,2,1,54,0,3,1,55, +0,4,1,30,0,-103,0,0,0,5,1,0,0,6,1,58,0,8,0,7,0,7,1,7,0,8,1,7,0,-81,0,4, +0,20,0,7,0,9,1,7,0,10,1,7,0,11,1,32,0,45,0,59,0,80,0,27,0,31,0,2,0,18,0,2, +0,12,1,4,0,13,1,2,0,-79,0,2,0,14,1,7,0,-73,0,7,0,-72,0,7,0,-71,0,7,0,-70,0,7, +0,15,1,7,0,16,1,7,0,17,1,7,0,18,1,7,0,19,1,7,0,20,1,7,0,21,1,7,0,22,1,7, +0,23,1,7,0,24,1,7,0,25,1,60,0,26,1,2,0,27,1,2,0,70,0,7,0,113,0,7,0,114,0,7, +0,28,1,7,0,29,1,7,0,30,1,2,0,31,1,2,0,32,1,2,0,33,1,2,0,34,1,0,0,35,1,0, +0,36,1,2,0,37,1,2,0,38,1,2,0,39,1,2,0,40,1,2,0,41,1,7,0,42,1,7,0,43,1,7, +0,44,1,7,0,45,1,2,0,46,1,2,0,43,0,2,0,47,1,2,0,48,1,2,0,49,1,2,0,50,1,7, +0,51,1,7,0,52,1,7,0,53,1,7,0,54,1,7,0,55,1,7,0,56,1,7,0,57,1,7,0,58,1,7, +0,59,1,7,0,60,1,7,0,61,1,7,0,62,1,2,0,63,1,2,0,64,1,4,0,65,1,4,0,66,1,2, +0,67,1,2,0,68,1,2,0,69,1,2,0,70,1,7,0,71,1,7,0,72,1,7,0,73,1,7,0,74,1,2, +0,75,1,2,0,76,1,50,0,77,1,36,0,79,0,30,0,-103,0,39,0,125,0,61,0,2,0,27,0,31,0,36, +0,79,0,62,0,-127,0,27,0,31,0,2,0,-79,0,2,0,20,0,7,0,-73,0,7,0,-72,0,7,0,-71,0,7, +0,78,1,7,0,79,1,7,0,80,1,7,0,81,1,7,0,82,1,7,0,83,1,7,0,84,1,7,0,85,1,7, +0,86,1,7,0,87,1,7,0,88,1,7,0,89,1,7,0,90,1,7,0,91,1,7,0,92,1,7,0,93,1,7, +0,94,1,7,0,95,1,7,0,96,1,7,0,97,1,7,0,98,1,7,0,99,1,7,0,100,1,7,0,101,1,7, +0,102,1,7,0,103,1,7,0,104,1,2,0,105,1,2,0,106,1,2,0,107,1,0,0,108,1,0,0,109,1,7, +0,110,1,7,0,111,1,2,0,112,1,2,0,113,1,7,0,114,1,7,0,115,1,7,0,116,1,7,0,117,1,2, +0,118,1,2,0,119,1,4,0,13,1,4,0,120,1,2,0,121,1,2,0,122,1,2,0,123,1,2,0,124,1,7, +0,125,1,7,0,126,1,7,0,127,1,7,0,-128,1,7,0,-127,1,7,0,-126,1,7,0,-125,1,7,0,-124,1,7, +0,-123,1,7,0,-122,1,0,0,-121,1,7,0,-120,1,7,0,-119,1,7,0,-118,1,4,0,-117,1,0,0,-116,1,0, +0,47,1,0,0,-115,1,0,0,5,1,2,0,-114,1,2,0,-113,1,2,0,64,1,2,0,-112,1,2,0,-111,1,2, +0,-110,1,7,0,-109,1,7,0,-108,1,7,0,-107,1,7,0,-106,1,7,0,-105,1,2,0,-93,0,2,0,-92,0,54, +0,-104,1,54,0,-103,1,0,0,-102,1,0,0,-101,1,0,0,-100,1,0,0,-99,1,2,0,-98,1,2,0,12,1,7, +0,-97,1,7,0,-96,1,50,0,77,1,57,0,1,1,36,0,79,0,63,0,-95,1,30,0,-103,0,7,0,-94,1,7, +0,-93,1,7,0,-92,1,7,0,-91,1,7,0,-90,1,2,0,-89,1,2,0,70,0,7,0,-88,1,7,0,-87,1,7, +0,-86,1,7,0,-85,1,7,0,-84,1,7,0,-83,1,7,0,-82,1,7,0,-81,1,7,0,-80,1,2,0,-79,1,2, +0,-78,1,7,0,-77,1,7,0,-76,1,7,0,-75,1,7,0,-74,1,7,0,-73,1,4,0,-72,1,4,0,-71,1,4, +0,-70,1,39,0,125,0,12,0,-69,1,64,0,6,0,27,0,31,0,0,0,-68,1,7,0,-67,1,7,0,37,0,65, +0,2,0,43,0,-104,0,66,0,26,0,66,0,0,0,66,0,1,0,67,0,-66,1,4,0,-65,1,4,0,-64,1,4, +0,-63,1,4,0,-62,1,4,0,-61,1,4,0,-60,1,2,0,18,0,2,0,20,0,2,0,-59,1,2,0,-58,1,7, +0,5,0,7,0,6,0,7,0,7,0,7,0,-57,1,7,0,-56,1,7,0,-55,1,7,0,-54,1,7,0,-53,1,7, +0,-52,1,7,0,-51,1,7,0,23,0,7,0,-50,1,7,0,-49,1,68,0,15,0,27,0,31,0,67,0,-66,1,12, +0,-48,1,12,0,-47,1,36,0,79,0,62,0,-46,1,2,0,20,0,2,0,-45,1,4,0,-80,0,7,0,7,1,7, +0,-81,0,7,0,8,1,7,0,-44,1,7,0,-43,1,7,0,-42,1,35,0,10,0,7,0,-41,1,7,0,-40,1,7, +0,-39,1,7,0,-38,1,2,0,-37,1,2,0,-36,1,0,0,-35,1,0,0,-34,1,0,0,-33,1,0,0,-32,1,34, +0,7,0,7,0,-31,1,7,0,-40,1,7,0,-39,1,2,0,-35,1,2,0,-32,1,7,0,-38,1,7,0,37,0,69, +0,21,0,69,0,0,0,69,0,1,0,2,0,18,0,2,0,-30,1,2,0,-32,1,2,0,20,0,2,0,-29,1,2, +0,-28,1,2,0,-27,1,2,0,-26,1,2,0,-25,1,2,0,-24,1,2,0,-23,1,2,0,-22,1,7,0,-21,1,7, +0,-20,1,34,0,49,0,35,0,50,0,2,0,-19,1,2,0,-18,1,4,0,-17,1,70,0,5,0,2,0,-16,1,2, +0,-30,1,0,0,20,0,0,0,37,0,2,0,70,0,71,0,4,0,7,0,5,0,7,0,6,0,7,0,8,0,7, +0,-15,1,72,0,57,0,27,0,31,0,67,0,-66,1,12,0,-14,1,12,0,-47,1,32,0,-13,1,32,0,-12,1,32, +0,-11,1,36,0,79,0,73,0,-10,1,38,0,-9,1,62,0,-46,1,12,0,-8,1,7,0,7,1,7,0,-81,0,7, +0,8,1,4,0,-80,0,2,0,-7,1,2,0,-45,1,2,0,20,0,2,0,-6,1,7,0,-5,1,7,0,-4,1,7, +0,-3,1,2,0,-27,1,2,0,-26,1,2,0,-2,1,2,0,-1,1,4,0,70,0,2,0,23,0,2,0,98,0,2, +0,67,0,2,0,0,2,7,0,1,2,7,0,2,2,7,0,3,2,7,0,4,2,7,0,5,2,7,0,6,2,7, +0,7,2,7,0,8,2,7,0,9,2,7,0,10,2,0,0,11,2,0,0,12,2,64,0,13,2,64,0,14,2,64, +0,15,2,64,0,16,2,4,0,17,2,4,0,18,2,4,0,19,2,4,0,37,0,71,0,20,2,4,0,21,2,4, +0,22,2,70,0,23,2,70,0,24,2,74,0,39,0,27,0,31,0,67,0,-66,1,12,0,25,2,36,0,79,0,38, +0,-9,1,62,0,-46,1,75,0,26,2,76,0,27,2,77,0,28,2,78,0,29,2,79,0,30,2,80,0,31,2,81, +0,32,2,82,0,33,2,74,0,34,2,83,0,35,2,84,0,36,2,84,0,37,2,84,0,38,2,4,0,54,0,4, +0,39,2,4,0,40,2,4,0,41,2,4,0,42,2,4,0,-80,0,7,0,7,1,7,0,-81,0,7,0,8,1,7, +0,43,2,7,0,37,0,2,0,44,2,2,0,20,0,2,0,45,2,2,0,46,2,2,0,-45,1,2,0,47,2,85, +0,48,2,86,0,49,2,9,0,-94,0,77,0,8,0,9,0,50,2,7,0,51,2,4,0,52,2,0,0,20,0,0, +0,53,2,2,0,13,1,2,0,54,2,2,0,55,2,75,0,8,0,4,0,56,2,4,0,57,2,4,0,58,2,4, +0,59,2,0,0,37,0,0,0,-30,1,0,0,60,2,0,0,20,0,79,0,5,0,4,0,56,2,4,0,57,2,0, +0,61,2,0,0,62,2,2,0,20,0,87,0,2,0,4,0,63,2,7,0,-39,1,80,0,3,0,87,0,64,2,4, +0,65,2,4,0,20,0,78,0,6,0,7,0,66,2,2,0,67,2,0,0,20,0,0,0,-30,1,0,0,62,2,0, +0,68,2,81,0,4,0,0,0,-49,0,0,0,-73,0,0,0,-72,0,0,0,-71,0,88,0,6,0,46,0,50,2,0, +0,20,0,0,0,53,2,2,0,13,1,2,0,54,2,2,0,55,2,89,0,1,0,7,0,69,2,90,0,5,0,0, +0,-49,0,0,0,-73,0,0,0,-72,0,0,0,-71,0,4,0,37,0,82,0,1,0,7,0,70,2,83,0,2,0,4, +0,71,2,4,0,18,0,76,0,7,0,7,0,51,2,46,0,50,2,0,0,20,0,0,0,53,2,2,0,13,1,2, +0,54,2,2,0,55,2,91,0,1,0,7,0,72,2,92,0,1,0,4,0,73,2,93,0,1,0,0,0,74,2,94, +0,1,0,7,0,51,2,95,0,4,0,7,0,-49,0,7,0,-73,0,7,0,-72,0,7,0,-71,0,96,0,1,0,95, +0,52,2,97,0,5,0,4,0,75,2,4,0,76,2,0,0,20,0,0,0,-30,1,0,0,-74,0,98,0,2,0,4, +0,77,2,4,0,76,2,99,0,14,0,99,0,0,0,99,0,1,0,97,0,78,2,96,0,79,2,98,0,80,2,0, +0,81,2,12,0,82,2,12,0,83,2,100,0,84,2,4,0,54,0,4,0,40,2,4,0,39,2,4,0,37,0,78, +0,85,2,85,0,14,0,12,0,86,2,78,0,85,2,0,0,87,2,0,0,88,2,0,0,89,2,0,0,90,2,0, +0,91,2,0,0,92,2,0,0,93,2,0,0,20,0,84,0,36,2,84,0,38,2,2,0,94,2,0,0,95,2,86, +0,8,0,4,0,96,2,4,0,97,2,75,0,98,2,79,0,99,2,4,0,40,2,4,0,39,2,4,0,54,0,4, +0,37,0,101,0,6,0,101,0,0,0,101,0,1,0,4,0,18,0,4,0,13,1,0,0,17,0,0,0,100,2,102, +0,7,0,101,0,101,2,2,0,102,2,2,0,86,2,2,0,103,2,2,0,93,0,9,0,104,2,9,0,105,2,103, +0,3,0,101,0,101,2,32,0,-89,0,0,0,17,0,104,0,5,0,101,0,101,2,32,0,-89,0,0,0,17,0,2, +0,106,2,0,0,107,2,105,0,5,0,101,0,101,2,7,0,91,0,7,0,108,2,4,0,109,2,4,0,110,2,106, +0,5,0,101,0,101,2,32,0,111,2,0,0,72,0,4,0,13,1,4,0,20,0,107,0,13,0,101,0,101,2,32, +0,112,2,32,0,113,2,32,0,114,2,32,0,115,2,7,0,116,2,7,0,117,2,7,0,108,2,7,0,118,2,4, +0,119,2,4,0,120,2,4,0,93,0,4,0,121,2,108,0,5,0,101,0,101,2,2,0,122,2,2,0,20,0,7, +0,123,2,32,0,124,2,109,0,3,0,101,0,101,2,7,0,125,2,4,0,93,0,110,0,10,0,101,0,101,2,7, +0,126,2,4,0,127,2,4,0,37,0,2,0,93,0,2,0,-128,2,2,0,-127,2,2,0,-126,2,7,0,-125,2,0, +0,-124,2,111,0,3,0,101,0,101,2,7,0,37,0,4,0,18,0,112,0,11,0,101,0,101,2,51,0,-123,2,7, +0,-122,2,4,0,-121,2,0,0,-124,2,7,0,-120,2,4,0,-119,2,32,0,-118,2,0,0,-117,2,4,0,-116,2,4, +0,37,0,113,0,10,0,101,0,101,2,32,0,-115,2,46,0,-114,2,4,0,93,0,4,0,-113,2,7,0,-112,2,7, +0,-111,2,0,0,-117,2,4,0,-116,2,4,0,37,0,114,0,3,0,101,0,101,2,7,0,-110,2,4,0,-109,2,115, +0,5,0,101,0,101,2,7,0,-108,2,0,0,-124,2,2,0,20,0,2,0,-107,2,116,0,8,0,101,0,101,2,32, +0,-89,0,7,0,-108,2,7,0,-38,1,7,0,109,0,0,0,-124,2,2,0,20,0,2,0,18,0,117,0,21,0,101, +0,101,2,32,0,-106,2,0,0,-124,2,51,0,-123,2,32,0,-118,2,2,0,20,0,2,0,37,0,7,0,-105,2,7, +0,-104,2,7,0,-103,2,7,0,-5,1,7,0,-102,2,7,0,-101,2,7,0,-100,2,7,0,-99,2,4,0,-119,2,4, +0,-116,2,0,0,-117,2,7,0,-98,2,7,0,-97,2,7,0,43,0,118,0,7,0,101,0,101,2,2,0,-96,2,2, +0,-95,2,4,0,70,0,32,0,-89,0,7,0,-94,2,0,0,-124,2,119,0,9,0,101,0,101,2,32,0,-89,0,7, +0,-93,2,7,0,-92,2,7,0,-99,2,4,0,-91,2,4,0,-90,2,7,0,-89,2,0,0,17,0,120,0,1,0,101, +0,101,2,121,0,5,0,101,0,101,2,122,0,-88,2,123,0,-87,2,124,0,-86,2,125,0,-85,2,126,0,14,0,101, +0,101,2,78,0,-84,2,78,0,-83,2,78,0,-82,2,78,0,-81,2,78,0,-80,2,78,0,-79,2,75,0,-78,2,4, +0,-77,2,4,0,-76,2,2,0,-75,2,2,0,37,0,7,0,-74,2,127,0,-73,2,-128,0,3,0,101,0,101,2,-127, +0,-72,2,-126,0,-73,2,-125,0,4,0,101,0,101,2,32,0,-89,0,4,0,-71,2,4,0,37,0,-124,0,2,0,4, +0,-70,2,7,0,-39,1,-123,0,2,0,4,0,-127,0,4,0,-69,2,-122,0,20,0,101,0,101,2,32,0,-89,0,0, +0,-124,2,2,0,-68,2,2,0,-67,2,2,0,20,0,2,0,37,0,7,0,-66,2,7,0,-65,2,4,0,54,0,4, +0,-64,2,-123,0,-63,2,-124,0,-62,2,4,0,-61,2,4,0,-60,2,4,0,-59,2,4,0,-69,2,7,0,-58,2,7, +0,-57,2,7,0,-56,2,-121,0,8,0,101,0,101,2,-120,0,-55,2,-127,0,-72,2,4,0,-54,2,4,0,-53,2,4, +0,-52,2,2,0,20,0,2,0,57,0,-119,0,5,0,101,0,101,2,32,0,45,0,2,0,-51,2,2,0,20,0,2, +0,-50,2,-118,0,5,0,101,0,101,2,4,0,-49,2,2,0,20,0,2,0,-48,2,7,0,-47,2,-117,0,3,0,101, +0,101,2,-116,0,-46,2,125,0,-85,2,-115,0,10,0,101,0,101,2,32,0,-45,2,32,0,-44,2,0,0,-43,2,7, +0,-42,2,2,0,-41,2,2,0,-40,2,0,0,-39,2,0,0,-38,2,0,0,107,2,-114,0,9,0,101,0,101,2,32, +0,-37,2,0,0,-43,2,7,0,-36,2,7,0,-35,2,0,0,13,1,0,0,122,2,0,0,-34,2,0,0,37,0,-113, +0,24,0,27,0,31,0,2,0,-29,1,2,0,-28,1,2,0,-33,2,2,0,20,0,2,0,-32,2,2,0,-31,2,2, +0,-30,2,2,0,70,0,0,0,-29,2,0,0,-28,2,0,0,-27,2,0,0,18,0,4,0,37,0,7,0,-26,2,7, +0,-25,2,7,0,-24,2,7,0,-23,2,7,0,-22,2,7,0,-21,2,34,0,-20,2,36,0,79,0,38,0,-9,1,80, +0,31,2,-112,0,3,0,-112,0,0,0,-112,0,1,0,0,0,17,0,67,0,3,0,7,0,-19,2,4,0,20,0,4, +0,37,0,32,0,111,0,27,0,31,0,2,0,18,0,2,0,-18,2,4,0,-17,2,4,0,-16,2,4,0,-15,2,0, +0,-14,2,32,0,38,0,32,0,-13,2,32,0,-12,2,32,0,-11,2,32,0,-10,2,36,0,79,0,73,0,-10,1,67, +0,-66,1,-111,0,-9,2,-111,0,-8,2,-110,0,-7,2,9,0,2,0,12,0,-6,2,12,0,25,2,12,0,-47,1,12, +0,-5,2,12,0,-4,2,62,0,-46,1,7,0,7,1,7,0,-3,2,7,0,-2,2,7,0,-81,0,7,0,-1,2,7, +0,8,1,7,0,0,3,7,0,1,3,7,0,-93,2,7,0,2,3,7,0,-45,0,4,0,3,3,2,0,20,0,2, +0,4,3,2,0,5,3,2,0,6,3,2,0,7,3,2,0,8,3,2,0,9,3,2,0,10,3,2,0,11,3,2, +0,12,3,2,0,13,3,2,0,14,3,4,0,15,3,4,0,16,3,4,0,17,3,4,0,18,3,7,0,19,3,7, +0,20,3,7,0,21,3,7,0,22,3,7,0,23,3,7,0,24,3,7,0,25,3,7,0,26,3,7,0,27,3,7, +0,28,3,7,0,29,3,7,0,30,3,0,0,31,3,0,0,32,3,0,0,-45,1,0,0,33,3,0,0,34,3,0, +0,35,3,7,0,36,3,7,0,37,3,39,0,125,0,12,0,38,3,12,0,39,3,12,0,40,3,12,0,41,3,7, +0,42,3,2,0,71,2,2,0,43,3,7,0,52,2,4,0,44,3,4,0,45,3,-109,0,46,3,2,0,47,3,2, +0,-38,0,7,0,48,3,12,0,49,3,12,0,50,3,12,0,51,3,12,0,52,3,-108,0,53,3,-107,0,54,3,63, +0,55,3,2,0,56,3,2,0,57,3,2,0,58,3,2,0,59,3,7,0,44,2,2,0,60,3,2,0,61,3,-116, +0,62,3,-127,0,63,3,-127,0,64,3,4,0,65,3,4,0,66,3,4,0,67,3,4,0,70,0,9,0,-94,0,12, +0,68,3,-106,0,14,0,-106,0,0,0,-106,0,1,0,32,0,38,0,7,0,-93,2,7,0,9,1,7,0,-92,2,7, +0,-99,2,0,0,17,0,4,0,-91,2,4,0,-90,2,4,0,69,3,2,0,18,0,2,0,70,3,7,0,-89,2,-108, +0,36,0,2,0,71,3,2,0,72,3,2,0,20,0,2,0,-99,2,7,0,73,3,7,0,74,3,7,0,75,3,7, +0,76,3,7,0,77,3,7,0,78,3,7,0,79,3,7,0,80,3,7,0,81,3,7,0,82,3,7,0,83,3,7, +0,84,3,7,0,85,3,7,0,86,3,7,0,87,3,7,0,88,3,7,0,89,3,7,0,90,3,7,0,91,3,7, +0,92,3,7,0,93,3,7,0,94,3,7,0,95,3,7,0,96,3,2,0,97,3,2,0,98,3,2,0,99,3,2, +0,100,3,51,0,-88,0,-105,0,101,3,7,0,102,3,4,0,110,2,125,0,5,0,4,0,20,0,4,0,103,3,4, +0,104,3,4,0,105,3,4,0,106,3,-104,0,1,0,7,0,-31,1,-109,0,30,0,4,0,20,0,7,0,107,3,7, +0,108,3,7,0,109,3,4,0,110,3,4,0,111,3,4,0,112,3,4,0,113,3,7,0,114,3,7,0,115,3,7, +0,116,3,7,0,117,3,7,0,118,3,7,0,119,3,7,0,120,3,7,0,121,3,7,0,122,3,7,0,123,3,7, +0,124,3,7,0,125,3,7,0,126,3,7,0,127,3,7,0,-128,3,7,0,-127,3,7,0,-126,3,7,0,-125,3,4, +0,-124,3,4,0,-123,3,7,0,-122,3,7,0,27,3,-107,0,49,0,-120,0,-121,3,4,0,-120,3,4,0,-119,3,-103, +0,-118,3,-102,0,-117,3,0,0,37,0,0,0,-116,3,2,0,-115,3,7,0,-114,3,0,0,-113,3,7,0,-112,3,7, +0,-111,3,7,0,-110,3,7,0,-109,3,7,0,-108,3,7,0,-107,3,7,0,-106,3,7,0,-105,3,7,0,-104,3,2, +0,-103,3,0,0,-102,3,2,0,-101,3,7,0,-100,3,7,0,-99,3,0,0,-98,3,4,0,-126,0,4,0,-97,3,4, +0,-96,3,2,0,-95,3,2,0,-94,3,-104,0,-93,3,4,0,-92,3,4,0,81,0,7,0,-91,3,7,0,-90,3,7, +0,-89,3,7,0,-88,3,2,0,-87,3,2,0,-86,3,2,0,-85,3,2,0,-84,3,2,0,-83,3,2,0,-82,3,2, +0,-81,3,2,0,-80,3,-101,0,-79,3,7,0,-78,3,7,0,-77,3,125,0,-76,3,-116,0,48,0,2,0,18,0,2, +0,-75,3,2,0,-74,3,2,0,-73,3,7,0,-72,3,2,0,-71,3,2,0,-70,3,7,0,-69,3,2,0,-68,3,2, +0,-67,3,7,0,-66,3,7,0,-65,3,7,0,-64,3,7,0,-63,3,7,0,-62,3,7,0,-61,3,4,0,-60,3,7, +0,-59,3,7,0,-58,3,7,0,-57,3,74,0,-56,3,74,0,-55,3,74,0,-54,3,0,0,-53,3,7,0,-52,3,7, +0,-51,3,36,0,79,0,2,0,-50,3,0,0,-49,3,0,0,-48,3,7,0,-47,3,4,0,-46,3,7,0,-45,3,7, +0,-44,3,4,0,-43,3,4,0,20,0,7,0,-42,3,7,0,-41,3,7,0,-40,3,78,0,-39,3,7,0,-38,3,7, +0,-37,3,7,0,-36,3,7,0,-35,3,7,0,-34,3,7,0,-33,3,7,0,-32,3,4,0,-31,3,-100,0,71,0,27, +0,31,0,2,0,-79,0,2,0,14,1,2,0,47,1,2,0,-30,3,7,0,-29,3,7,0,-28,3,7,0,-27,3,7, +0,-26,3,7,0,-25,3,7,0,-24,3,7,0,-23,3,7,0,-22,3,7,0,84,1,7,0,86,1,7,0,85,1,7, +0,-21,3,4,0,-20,3,7,0,-19,3,7,0,-18,3,7,0,-17,3,7,0,-16,3,7,0,-15,3,7,0,-14,3,7, +0,-13,3,2,0,-12,3,2,0,13,1,2,0,-11,3,2,0,-10,3,2,0,-9,3,2,0,-8,3,2,0,-7,3,2, +0,-6,3,7,0,-5,3,7,0,-4,3,7,0,-3,3,7,0,-2,3,7,0,-1,3,7,0,0,4,7,0,1,4,7, +0,2,4,7,0,3,4,7,0,4,4,7,0,5,4,7,0,6,4,2,0,7,4,2,0,8,4,2,0,9,4,2, +0,10,4,7,0,11,4,7,0,12,4,7,0,13,4,7,0,14,4,2,0,15,4,2,0,16,4,2,0,17,4,2, +0,18,4,7,0,19,4,7,0,20,4,7,0,21,4,7,0,22,4,2,0,23,4,2,0,24,4,2,0,25,4,2, +0,43,0,7,0,26,4,7,0,27,4,36,0,79,0,50,0,77,1,30,0,-103,0,39,0,125,0,-99,0,16,0,2, +0,28,4,2,0,29,4,2,0,30,4,2,0,20,0,2,0,31,4,2,0,32,4,2,0,33,4,2,0,34,4,2, +0,35,4,2,0,36,4,2,0,37,4,2,0,38,4,4,0,39,4,7,0,40,4,7,0,41,4,7,0,42,4,-98, +0,8,0,-98,0,0,0,-98,0,1,0,4,0,3,3,4,0,43,4,4,0,20,0,2,0,44,4,2,0,45,4,32, +0,-89,0,-97,0,13,0,9,0,46,4,9,0,47,4,4,0,48,4,4,0,49,4,4,0,50,4,4,0,51,4,4, +0,52,4,4,0,53,4,4,0,54,4,4,0,55,4,4,0,56,4,4,0,37,0,0,0,57,4,-96,0,5,0,9, +0,58,4,9,0,59,4,4,0,60,4,4,0,70,0,0,0,61,4,-95,0,13,0,4,0,18,0,4,0,62,4,4, +0,63,4,4,0,64,4,4,0,65,4,4,0,66,4,4,0,93,0,4,0,67,4,4,0,68,4,4,0,69,4,4, +0,70,4,4,0,71,4,26,0,30,0,-94,0,4,0,4,0,72,4,7,0,73,4,2,0,20,0,2,0,68,2,-93, +0,11,0,-93,0,0,0,-93,0,1,0,0,0,17,0,62,0,74,4,63,0,75,4,4,0,3,3,4,0,76,4,4, +0,77,4,4,0,37,0,4,0,78,4,4,0,79,4,-92,0,-126,0,-97,0,80,4,-96,0,81,4,-95,0,82,4,4, +0,83,4,4,0,-126,0,4,0,-97,3,4,0,84,4,4,0,85,4,4,0,86,4,4,0,87,4,2,0,20,0,2, +0,88,4,7,0,20,3,7,0,89,4,7,0,90,4,7,0,91,4,7,0,92,4,7,0,93,4,2,0,94,4,2, +0,95,4,2,0,96,4,2,0,97,4,2,0,-39,0,2,0,98,4,2,0,99,4,2,0,100,3,2,0,100,4,2, +0,101,4,2,0,34,1,2,0,109,0,2,0,102,4,2,0,103,4,2,0,104,4,2,0,105,4,2,0,106,4,2, +0,107,4,2,0,108,4,2,0,109,4,2,0,110,4,2,0,35,1,2,0,111,4,2,0,112,4,2,0,113,4,2, +0,114,4,4,0,115,4,4,0,13,1,2,0,116,4,2,0,117,4,2,0,118,4,2,0,119,4,2,0,120,4,2, +0,121,4,24,0,122,4,24,0,123,4,23,0,124,4,12,0,125,4,2,0,126,4,2,0,37,0,7,0,127,4,7, +0,-128,4,7,0,-127,4,7,0,-126,4,7,0,-125,4,7,0,-124,4,7,0,-123,4,7,0,-122,4,7,0,-121,4,2, +0,-120,4,2,0,-119,4,2,0,-118,4,2,0,-117,4,2,0,-116,4,2,0,-115,4,7,0,-114,4,7,0,-113,4,7, +0,-112,4,2,0,-111,4,2,0,-110,4,2,0,-109,4,2,0,-108,4,2,0,-107,4,2,0,-106,4,2,0,-105,4,2, +0,-104,4,2,0,-103,4,2,0,-102,4,4,0,-101,4,4,0,-100,4,4,0,-99,4,4,0,-98,4,4,0,-97,4,7, +0,-96,4,4,0,-95,4,4,0,-94,4,4,0,-93,4,4,0,-92,4,7,0,-91,4,7,0,-90,4,7,0,-89,4,7, +0,-88,4,7,0,-87,4,7,0,-86,4,7,0,-85,4,7,0,-84,4,7,0,-83,4,0,0,-82,4,0,0,-81,4,4, +0,-80,4,2,0,-79,4,2,0,12,1,0,0,-78,4,7,0,-77,4,7,0,-76,4,4,0,-75,4,4,0,-74,4,7, +0,-73,4,7,0,-72,4,2,0,-71,4,2,0,-70,4,7,0,-69,4,2,0,-68,4,2,0,-67,4,4,0,-66,4,2, +0,-65,4,2,0,-64,4,2,0,-63,4,2,0,-62,4,7,0,-61,4,7,0,70,0,42,0,-60,4,-91,0,9,0,-91, +0,0,0,-91,0,1,0,0,0,17,0,2,0,-59,4,2,0,-58,4,2,0,-57,4,2,0,43,0,7,0,-56,4,7, +0,70,0,-90,0,5,0,7,0,-55,4,0,0,18,0,0,0,43,0,0,0,70,0,0,0,12,1,-89,0,5,0,-89, +0,0,0,-89,0,1,0,4,0,-54,4,0,0,-53,4,4,0,20,0,-88,0,5,0,-87,0,-52,4,2,0,20,0,2, +0,-51,4,2,0,-50,4,2,0,-49,4,-86,0,4,0,2,0,109,0,2,0,-122,2,2,0,-48,4,2,0,-47,4,-85, +0,7,0,2,0,20,0,2,0,-46,4,2,0,-45,4,2,0,-44,4,-86,0,-43,4,7,0,-42,4,4,0,-41,4,-84, +0,4,0,-84,0,0,0,-84,0,1,0,0,0,-40,4,7,0,-39,4,-83,0,56,0,2,0,-38,4,2,0,-37,4,7, +0,-36,4,7,0,-35,4,2,0,-48,4,2,0,-34,4,7,0,-33,4,7,0,-32,4,2,0,-31,4,2,0,-30,4,2, +0,-29,4,2,0,-28,4,7,0,-27,4,7,0,-26,4,7,0,-25,4,7,0,37,0,2,0,-24,4,2,0,-23,4,2, +0,-22,4,2,0,-21,4,-88,0,-20,4,-85,0,-19,4,7,0,-18,4,7,0,-17,4,0,0,-16,4,0,0,-15,4,0, +0,-14,4,0,0,-13,4,0,0,-12,4,0,0,-11,4,2,0,-10,4,7,0,-9,4,7,0,-8,4,7,0,-7,4,7, +0,-6,4,7,0,-5,4,7,0,-4,4,7,0,-3,4,7,0,-2,4,7,0,-1,4,7,0,0,5,2,0,1,5,0, +0,2,5,0,0,3,5,0,0,4,5,0,0,5,5,32,0,6,5,0,0,7,5,0,0,8,5,0,0,9,5,0, +0,10,5,0,0,11,5,0,0,12,5,0,0,13,5,0,0,14,5,0,0,15,5,-82,0,6,0,2,0,109,0,0, +0,-122,2,0,0,16,5,0,0,17,5,0,0,20,0,0,0,-74,0,-81,0,26,0,-80,0,18,5,50,0,77,1,60, +0,19,5,-82,0,20,5,-82,0,21,5,-82,0,22,5,-82,0,23,5,-82,0,24,5,-82,0,25,5,-82,0,26,5,7, +0,27,5,2,0,28,5,2,0,47,1,2,0,29,5,2,0,1,2,0,0,30,5,0,0,31,5,0,0,32,5,0, +0,33,5,0,0,93,0,0,0,34,5,0,0,35,5,0,0,36,5,0,0,37,5,0,0,38,5,0,0,-74,0,-79, +0,43,0,27,0,31,0,32,0,39,5,-100,0,40,5,-79,0,41,5,46,0,-47,0,12,0,42,5,-98,0,43,5,7, +0,44,5,7,0,45,5,7,0,46,5,7,0,47,5,4,0,3,3,7,0,48,5,2,0,49,5,2,0,50,5,2, +0,51,5,2,0,52,5,2,0,53,5,2,0,54,5,2,0,55,5,2,0,5,1,57,0,1,1,9,0,56,5,-99, +0,57,5,-90,0,58,5,-83,0,59,5,-92,0,-73,0,-94,0,60,5,39,0,125,0,12,0,103,0,12,0,61,5,2, +0,62,5,2,0,63,5,2,0,64,5,2,0,65,5,-78,0,66,5,2,0,67,5,2,0,68,5,2,0,64,1,2, +0,-38,0,-81,0,69,5,4,0,70,5,4,0,37,0,-77,0,9,0,46,0,-47,0,45,0,0,1,7,0,8,2,7, +0,9,2,7,0,109,0,7,0,71,5,7,0,72,5,2,0,73,5,2,0,74,5,-76,0,75,0,-75,0,0,0,-75, +0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,7,0,79,5,7,0,80,5,7,0,81,5,7, +0,82,5,7,0,83,5,7,0,84,5,7,0,85,5,7,0,20,1,7,0,86,5,4,0,87,5,2,0,88,5,2, +0,17,5,32,0,39,5,32,0,89,5,-77,0,90,5,-76,0,91,5,-73,0,92,5,-72,0,93,5,-71,0,94,5,0, +0,95,5,2,0,30,4,2,0,96,5,4,0,3,3,4,0,97,5,2,0,98,5,2,0,99,5,2,0,100,5,0, +0,101,5,0,0,43,0,7,0,115,0,7,0,102,5,7,0,103,5,7,0,104,5,7,0,105,5,7,0,106,5,7, +0,107,5,7,0,108,5,7,0,-82,0,7,0,44,5,2,0,109,5,2,0,110,5,2,0,111,5,2,0,112,5,2, +0,-119,0,2,0,29,5,2,0,113,5,2,0,114,5,2,0,115,5,2,0,116,5,7,0,117,5,7,0,118,5,67, +0,119,5,12,0,120,5,2,0,121,5,2,0,53,2,2,0,122,5,2,0,20,0,2,0,123,5,2,0,124,5,2, +0,125,5,0,0,126,5,0,0,127,5,9,0,-128,5,-70,0,-127,5,7,0,-126,5,2,0,-125,5,2,0,-124,5,2, +0,53,5,2,0,54,5,-69,0,19,0,24,0,36,0,24,0,64,0,23,0,-123,5,23,0,-122,5,23,0,-121,5,7, +0,-120,5,7,0,-119,5,7,0,-118,5,7,0,-117,5,2,0,-116,5,2,0,-115,5,2,0,-114,5,2,0,-113,5,2, +0,-112,5,2,0,-111,5,4,0,20,0,7,0,-110,5,2,0,99,5,0,0,107,2,-75,0,6,0,-75,0,0,0,-75, +0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-68,0,6,0,-75,0,0,0,-75,0,1,0,4, +0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-67,0,27,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7, +0,76,5,-74,0,77,5,2,0,78,5,4,0,-109,5,4,0,70,0,-69,0,-108,5,9,0,-107,5,12,0,-106,5,36, +0,79,0,27,0,80,0,0,0,-105,5,0,0,-104,5,0,0,-103,5,2,0,-102,5,2,0,-101,5,2,0,-100,5,2, +0,-99,5,2,0,65,0,2,0,46,0,2,0,-119,0,2,0,-98,5,4,0,20,0,7,0,-97,5,24,0,36,0,-66, +0,29,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,-73,0,92,5,2,0,78,5,2, +0,-96,5,2,0,-95,5,2,0,-94,5,2,0,-93,5,-69,0,-108,5,2,0,-92,5,2,0,-119,0,2,0,-101,5,2, +0,-91,5,9,0,-90,5,2,0,29,5,0,0,-89,5,0,0,-88,5,2,0,-87,5,2,0,-86,5,2,0,12,3,2, +0,-85,5,2,0,-84,5,0,0,37,0,0,0,20,0,0,0,47,1,0,0,-83,5,-65,0,16,0,-75,0,0,0,-75, +0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-69,0,-108,5,7,0,8,2,7,0,9,2,2, +0,-92,5,2,0,-82,5,2,0,-81,5,2,0,-80,5,4,0,20,0,7,0,71,5,-70,0,-127,5,-64,0,33,0,-75, +0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-63,0,-79,5,4,0,-78,5,0, +0,-77,5,0,0,-76,5,0,0,-75,5,2,0,18,0,2,0,-74,5,2,0,20,0,2,0,-73,5,2,0,-72,5,2, +0,-71,5,2,0,-70,5,2,0,43,0,4,0,70,0,0,0,-69,5,-62,0,-68,5,2,0,-67,5,2,0,-66,5,2, +0,-65,5,2,0,-48,0,9,0,-64,5,9,0,-63,5,9,0,-62,5,9,0,-61,5,9,0,-60,5,2,0,-59,5,0, +0,-58,5,-61,0,23,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-69, +0,-108,5,12,0,-57,5,2,0,-101,5,2,0,-56,5,2,0,20,0,2,0,57,0,9,0,-90,5,12,0,-55,5,-60, +0,-54,5,0,0,-53,5,-59,0,-52,5,4,0,-51,5,4,0,-50,5,2,0,18,0,2,0,-49,5,2,0,-48,5,2, +0,-47,5,-58,0,29,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-69, +0,-108,5,46,0,-114,2,45,0,0,1,60,0,19,5,2,0,13,1,2,0,-119,0,2,0,-46,5,2,0,-45,5,4, +0,20,0,2,0,49,5,2,0,-44,5,2,0,-98,5,2,0,-101,5,7,0,71,5,0,0,-43,5,0,0,-42,5,0, +0,-41,5,0,0,-40,5,7,0,8,2,7,0,9,2,7,0,-39,5,7,0,-38,5,-70,0,-127,5,-57,0,11,0,-75, +0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,2,0,-119,0,2,0,-98,5,2, +0,-37,5,2,0,20,0,-69,0,-108,5,-56,0,24,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74, +0,77,5,2,0,78,5,42,0,-36,5,4,0,-35,5,4,0,-34,5,2,0,93,0,2,0,-119,0,4,0,-33,5,4, +0,-32,5,4,0,-31,5,4,0,-30,5,4,0,-29,5,4,0,-28,5,4,0,-27,5,4,0,-26,5,7,0,-25,5,23, +0,-24,5,23,0,-23,5,4,0,-22,5,4,0,-21,5,-55,0,10,0,27,0,31,0,9,0,-20,5,9,0,-19,5,9, +0,-18,5,9,0,-17,5,9,0,-16,5,4,0,93,0,4,0,-15,5,0,0,-14,5,0,0,-13,5,-54,0,10,0,-75, +0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,-55,0,-12,5,2,0,93,0,2,0,-119,0,4, +0,43,0,9,0,-11,5,-53,0,8,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,-69, +0,-108,5,4,0,20,0,4,0,-10,5,-52,0,21,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74, +0,77,5,2,0,78,5,-69,0,-108,5,27,0,-9,5,27,0,80,0,2,0,20,0,2,0,-119,0,7,0,-8,5,9, +0,-7,5,7,0,8,2,7,0,9,2,57,0,1,1,57,0,-6,5,4,0,-5,5,2,0,-89,5,2,0,37,0,-70, +0,-127,5,-51,0,42,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-69, +0,-108,5,-50,0,-4,5,0,0,-77,5,0,0,-76,5,0,0,-75,5,2,0,18,0,2,0,-66,5,2,0,20,0,2, +0,-73,5,9,0,-7,5,4,0,-3,5,4,0,-2,5,4,0,-1,5,4,0,0,6,23,0,1,6,23,0,2,6,7, +0,3,6,7,0,4,6,7,0,5,6,7,0,-8,5,2,0,-67,5,2,0,-48,0,2,0,102,1,2,0,6,6,2, +0,37,0,2,0,43,0,2,0,7,6,2,0,8,6,9,0,-64,5,9,0,-63,5,9,0,-62,5,9,0,-61,5,9, +0,-60,5,2,0,-59,5,0,0,-58,5,56,0,9,6,-49,0,20,0,0,0,10,6,0,0,11,6,0,0,12,6,0, +0,13,6,0,0,14,6,0,0,15,6,0,0,16,6,0,0,17,6,0,0,18,6,0,0,19,6,0,0,20,6,0, +0,21,6,0,0,22,6,0,0,23,6,0,0,24,6,0,0,25,6,0,0,26,6,0,0,27,6,0,0,68,2,0, +0,28,6,-48,0,54,0,0,0,29,6,0,0,20,6,0,0,21,6,0,0,30,6,0,0,31,6,0,0,32,6,0, +0,33,6,0,0,34,6,0,0,35,6,0,0,36,6,0,0,37,6,0,0,38,6,0,0,39,6,0,0,40,6,0, +0,41,6,0,0,42,6,0,0,43,6,0,0,44,6,0,0,45,6,0,0,46,6,0,0,47,6,0,0,48,6,0, +0,49,6,0,0,50,6,0,0,51,6,0,0,52,6,0,0,53,6,0,0,54,6,0,0,55,6,0,0,56,6,0, +0,57,6,0,0,58,6,0,0,95,0,0,0,59,6,0,0,60,6,0,0,61,6,0,0,62,6,0,0,63,6,0, +0,64,6,0,0,65,6,0,0,66,6,0,0,67,6,0,0,68,6,0,0,69,6,0,0,70,6,0,0,71,6,0, +0,72,6,0,0,73,6,0,0,74,6,0,0,75,6,0,0,76,6,0,0,77,6,0,0,78,6,0,0,79,6,-47, +0,5,0,0,0,80,6,0,0,37,6,0,0,39,6,2,0,20,0,2,0,37,0,-46,0,22,0,-46,0,0,0,-46, +0,1,0,0,0,17,0,-49,0,81,6,-48,0,82,6,-48,0,83,6,-48,0,84,6,-48,0,85,6,-48,0,86,6,-48, +0,87,6,-48,0,88,6,-48,0,89,6,-48,0,90,6,-48,0,91,6,-48,0,92,6,-48,0,93,6,-48,0,94,6,-48, +0,95,6,-48,0,96,6,-47,0,97,6,0,0,98,6,0,0,99,6,-45,0,5,0,4,0,20,0,4,0,37,0,7, +0,52,2,7,0,100,6,7,0,-31,1,-44,0,66,0,4,0,20,0,4,0,101,6,4,0,102,6,0,0,103,6,0, +0,104,6,0,0,105,6,0,0,106,6,0,0,107,6,0,0,108,6,0,0,109,6,0,0,110,6,0,0,111,6,2, +0,112,6,2,0,113,6,4,0,114,6,4,0,115,6,4,0,116,6,4,0,117,6,2,0,118,6,2,0,119,6,2, +0,120,6,2,0,121,6,4,0,122,6,4,0,123,6,2,0,124,6,2,0,125,6,2,0,126,6,2,0,127,6,0, +0,-128,6,12,0,-127,6,2,0,-126,6,2,0,-125,6,2,0,-124,6,2,0,-123,6,2,0,-122,6,2,0,-121,6,2, +0,-120,6,2,0,-119,6,-45,0,-118,6,2,0,-117,6,2,0,-116,6,2,0,-115,6,2,0,-114,6,4,0,-113,6,4, +0,-112,6,4,0,-111,6,4,0,-110,6,2,0,-109,6,2,0,-108,6,2,0,-107,6,2,0,-106,6,2,0,-105,6,2, +0,-104,6,2,0,-103,6,2,0,-102,6,2,0,-101,6,2,0,-100,6,2,0,-99,6,2,0,37,0,0,0,-98,6,0, +0,-97,6,0,0,-96,6,7,0,-95,6,2,0,55,5,2,0,-94,6,54,0,-93,6,-43,0,18,0,27,0,31,0,12, +0,-92,6,12,0,-91,6,12,0,-90,6,-79,0,-89,6,2,0,-105,2,2,0,-88,6,2,0,-104,2,2,0,-87,6,2, +0,-86,6,2,0,-85,6,2,0,-84,6,2,0,-83,6,2,0,-82,6,2,0,37,0,2,0,-81,6,2,0,-80,6,2, +0,-79,6,-42,0,5,0,-42,0,0,0,-42,0,1,0,-42,0,-78,6,13,0,-77,6,4,0,20,0,-41,0,7,0,-41, +0,0,0,-41,0,1,0,-42,0,-76,6,-42,0,-75,6,2,0,123,4,2,0,20,0,4,0,37,0,-40,0,17,0,-40, +0,0,0,-40,0,1,0,0,0,-74,6,0,0,-73,6,0,0,-72,6,2,0,-71,6,2,0,-70,6,2,0,-86,6,2, +0,-85,6,2,0,20,0,2,0,70,3,2,0,-69,6,2,0,-68,6,2,0,-67,6,2,0,-66,6,4,0,-65,6,-40, +0,-64,6,-74,0,30,0,-74,0,0,0,-74,0,1,0,-42,0,-76,6,-42,0,-75,6,-42,0,-63,6,-42,0,-62,6,-43, +0,-61,6,7,0,-60,6,23,0,52,0,23,0,-59,6,23,0,-58,6,2,0,-57,6,2,0,-56,6,2,0,-55,6,0, +0,75,5,0,0,-54,6,2,0,-53,6,2,0,-52,6,0,0,-51,6,0,0,-50,6,0,0,-49,6,0,0,-48,6,2, +0,-47,6,2,0,-46,6,2,0,-45,6,2,0,20,0,39,0,125,0,12,0,-44,6,12,0,-43,6,12,0,-42,6,-39, +0,11,0,0,0,-41,6,2,0,-40,6,2,0,-39,6,2,0,-38,6,2,0,-37,6,2,0,-36,6,2,0,107,4,9, +0,-35,6,9,0,-34,6,4,0,-33,6,4,0,-32,6,-38,0,1,0,0,0,-31,6,-37,0,8,0,56,0,-30,6,56, +0,-29,6,-37,0,-28,6,-37,0,-27,6,-37,0,-26,6,2,0,-123,0,2,0,20,0,4,0,-25,6,-36,0,4,0,4, +0,-35,5,4,0,-24,6,4,0,-31,5,4,0,-23,6,-35,0,2,0,4,0,-22,6,4,0,-21,6,-34,0,9,0,7, +0,-20,6,7,0,-19,6,7,0,-18,6,4,0,20,0,4,0,13,1,7,0,-19,3,7,0,-17,6,4,0,37,0,-33, +0,-16,6,-32,0,6,0,0,0,-15,6,0,0,-75,5,48,0,-116,0,2,0,109,0,2,0,111,4,4,0,37,0,-31, +0,21,0,-31,0,0,0,-31,0,1,0,4,0,57,0,4,0,23,0,4,0,28,0,4,0,-14,6,4,0,-13,6,4, +0,-12,6,-38,0,-11,6,0,0,-15,6,4,0,-10,6,4,0,-9,6,-32,0,-12,2,-36,0,-8,6,-35,0,-7,6,-34, +0,-6,6,-37,0,-5,6,-37,0,-4,6,-37,0,-3,6,56,0,-2,6,56,0,-1,6,-30,0,12,0,0,0,-68,1,9, +0,-62,0,0,0,-61,0,4,0,-58,0,4,0,-50,0,9,0,-57,0,7,0,-55,0,7,0,-54,0,9,0,0,7,9, +0,1,7,9,0,-53,0,9,0,-51,0,-29,0,43,0,-29,0,0,0,-29,0,1,0,9,0,2,7,9,0,26,0,0, +0,27,0,4,0,20,0,4,0,18,0,4,0,23,0,4,0,91,0,4,0,3,7,4,0,4,7,4,0,-13,6,4, +0,-12,6,4,0,5,7,4,0,-39,0,4,0,6,7,4,0,7,7,7,0,8,7,7,0,9,7,4,0,-126,0,4, +0,10,7,-31,0,11,7,36,0,79,0,-79,0,-89,6,48,0,-116,0,7,0,12,7,7,0,13,7,-30,0,2,1,-29, +0,14,7,-29,0,15,7,-29,0,16,7,12,0,17,7,-28,0,18,7,-27,0,19,7,7,0,20,7,7,0,21,7,4, +0,-84,6,7,0,22,7,9,0,23,7,4,0,24,7,4,0,25,7,4,0,26,7,7,0,27,7,-26,0,4,0,-26, +0,0,0,-26,0,1,0,12,0,28,7,-29,0,29,7,-25,0,6,0,12,0,30,7,12,0,17,7,12,0,31,7,2, +0,20,0,2,0,37,0,4,0,57,0,-24,0,4,0,7,0,32,7,7,0,112,0,2,0,33,7,2,0,34,7,-23, +0,6,0,7,0,35,7,7,0,36,7,7,0,37,7,7,0,38,7,4,0,39,7,4,0,40,7,-22,0,12,0,7, +0,41,7,7,0,42,7,7,0,43,7,7,0,44,7,7,0,45,7,7,0,46,7,7,0,47,7,7,0,48,7,7, +0,49,7,7,0,50,7,4,0,-110,2,4,0,51,7,-21,0,2,0,7,0,-55,4,7,0,37,0,-20,0,7,0,7, +0,52,7,7,0,53,7,4,0,93,0,4,0,108,2,4,0,54,7,4,0,55,7,4,0,37,0,-19,0,6,0,-19, +0,0,0,-19,0,1,0,2,0,18,0,2,0,20,0,2,0,56,7,2,0,57,0,-18,0,8,0,-18,0,0,0,-18, +0,1,0,2,0,18,0,2,0,20,0,2,0,56,7,2,0,57,0,7,0,23,0,7,0,-126,0,-17,0,45,0,-17, +0,0,0,-17,0,1,0,2,0,18,0,2,0,20,0,2,0,56,7,2,0,-43,0,2,0,-103,3,2,0,57,7,7, +0,58,7,7,0,92,0,7,0,-97,2,4,0,59,7,4,0,81,0,4,0,110,2,7,0,60,7,7,0,61,7,7, +0,62,7,7,0,63,7,7,0,64,7,7,0,65,7,7,0,-100,2,7,0,-1,0,7,0,66,7,7,0,67,7,7, +0,37,0,7,0,68,7,7,0,69,7,7,0,70,7,2,0,71,7,2,0,72,7,2,0,73,7,2,0,74,7,2, +0,75,7,2,0,76,7,2,0,77,7,2,0,78,7,2,0,123,5,2,0,79,7,2,0,-47,1,2,0,80,7,0, +0,81,7,0,0,82,7,7,0,-45,0,-16,0,83,7,63,0,-95,1,-15,0,16,0,-15,0,0,0,-15,0,1,0,2, +0,18,0,2,0,20,0,2,0,56,7,2,0,-43,0,7,0,-105,2,7,0,-104,2,7,0,-103,2,7,0,-5,1,7, +0,-102,2,7,0,-101,2,7,0,84,7,7,0,-100,2,7,0,-98,2,7,0,-97,2,-59,0,5,0,2,0,18,0,2, +0,-25,6,2,0,20,0,2,0,85,7,27,0,-9,5,-60,0,3,0,4,0,69,0,4,0,86,7,-59,0,2,0,-14, +0,12,0,-14,0,0,0,-14,0,1,0,2,0,18,0,2,0,20,0,2,0,31,3,2,0,-32,1,7,0,5,0,7, +0,6,0,7,0,87,7,7,0,88,7,27,0,-9,5,12,0,89,7,-13,0,11,0,-13,0,0,0,-13,0,1,0,0, +0,17,0,2,0,18,0,2,0,90,7,4,0,22,0,4,0,91,7,2,0,20,0,2,0,37,0,9,0,92,7,9, +0,93,7,-12,0,5,0,0,0,17,0,7,0,20,1,7,0,94,7,4,0,95,7,4,0,37,0,-11,0,4,0,2, +0,18,0,2,0,20,0,2,0,43,0,2,0,70,0,-10,0,4,0,0,0,17,0,62,0,96,7,7,0,20,1,7, +0,37,0,-9,0,6,0,2,0,97,7,2,0,98,7,2,0,18,0,2,0,99,7,0,0,100,7,0,0,101,7,-8, +0,5,0,4,0,18,0,4,0,37,0,0,0,17,0,0,0,102,7,0,0,103,7,-7,0,3,0,4,0,18,0,4, +0,37,0,0,0,17,0,-6,0,4,0,2,0,104,7,2,0,105,7,2,0,20,0,2,0,37,0,-5,0,6,0,0, +0,17,0,0,0,106,7,2,0,107,7,2,0,-100,2,2,0,13,1,2,0,70,0,-4,0,5,0,0,0,17,0,7, +0,112,0,7,0,-17,3,2,0,20,0,2,0,122,2,-3,0,3,0,0,0,17,0,4,0,110,2,4,0,104,7,-2, +0,7,0,0,0,17,0,7,0,-17,3,0,0,108,7,0,0,109,7,2,0,13,1,2,0,43,0,4,0,110,7,-1, +0,3,0,32,0,111,7,0,0,112,7,0,0,113,7,0,1,18,0,0,1,0,0,0,1,1,0,2,0,18,0,2, +0,90,7,2,0,20,0,2,0,114,7,2,0,115,7,2,0,116,7,2,0,43,0,2,0,70,0,0,0,17,0,9, +0,2,0,1,1,117,7,32,0,45,0,2,0,-47,4,2,0,20,7,2,0,118,7,2,0,37,0,2,1,11,0,0, +0,17,0,0,0,18,0,0,0,119,7,2,0,20,0,2,0,122,2,2,0,120,7,4,0,121,7,4,0,122,7,4, +0,123,7,4,0,124,7,4,0,125,7,3,1,1,0,0,0,126,7,4,1,4,0,42,0,-36,5,0,0,127,7,4, +0,13,1,4,0,20,0,1,1,18,0,1,1,0,0,1,1,1,0,1,1,-128,7,2,0,18,0,2,0,20,0,2, +0,-127,7,2,0,116,7,2,0,90,7,2,0,-126,7,2,0,70,0,2,0,12,1,0,0,17,0,9,0,2,0,5, +1,117,7,0,1,-125,7,2,0,15,0,2,0,-124,7,4,0,-123,7,6,1,3,0,4,0,-74,2,4,0,37,0,32, +0,45,0,7,1,12,0,-111,0,-122,7,2,0,18,0,2,0,20,0,4,0,58,7,4,0,92,0,0,0,17,0,0, +0,-121,7,2,0,-120,7,2,0,-119,7,2,0,-118,7,2,0,-117,7,7,0,-116,7,8,1,10,0,2,0,20,0,2, +0,-115,7,4,0,58,7,4,0,92,0,2,0,-114,7,-28,0,18,7,2,0,18,0,2,0,-113,7,2,0,-112,7,2, +0,-111,7,9,1,7,0,2,0,20,0,2,0,-115,7,4,0,58,7,4,0,92,0,2,0,18,0,2,0,-110,7,7, +0,109,3,10,1,11,0,4,0,-74,2,2,0,18,0,2,0,20,0,32,0,45,0,74,0,-109,7,0,0,17,0,7, +0,-108,7,7,0,-107,7,7,0,21,3,2,0,-106,7,2,0,-105,7,11,1,5,0,2,0,18,0,2,0,20,0,4, +0,37,0,-79,0,-89,6,32,0,39,5,12,1,5,0,4,0,20,0,4,0,18,0,0,0,17,0,0,0,102,7,32, +0,45,0,13,1,13,0,2,0,20,0,2,0,18,0,2,0,90,7,2,0,22,3,7,0,-104,7,7,0,-103,7,7, +0,7,1,7,0,8,1,7,0,-3,2,7,0,0,3,7,0,-102,7,7,0,-101,7,32,0,-100,7,14,1,10,0,2, +0,20,0,2,0,18,0,4,0,58,7,4,0,92,0,0,0,17,0,0,0,-121,7,2,0,43,0,2,0,64,0,2, +0,-99,7,2,0,-98,7,15,1,8,0,32,0,45,0,7,0,-103,2,7,0,-97,7,7,0,-96,7,7,0,-108,2,2, +0,20,0,2,0,122,2,7,0,-95,7,16,1,12,0,2,0,18,0,2,0,13,1,2,0,20,0,2,0,-100,2,2, +0,-74,2,2,0,-94,7,4,0,37,0,7,0,-93,7,7,0,-92,7,7,0,-91,7,7,0,-90,7,0,0,-89,7,17, +1,10,0,2,0,20,0,2,0,18,0,4,0,58,7,4,0,92,0,0,0,17,0,2,0,68,2,2,0,64,0,2, +0,-99,7,2,0,-98,7,63,0,-95,1,18,1,7,0,4,0,110,2,4,0,-88,7,4,0,-87,7,4,0,-86,7,7, +0,-85,7,7,0,-84,7,0,0,108,7,19,1,7,0,0,0,-83,7,32,0,-82,7,0,0,112,7,2,0,-81,7,2, +0,43,0,4,0,70,0,0,0,113,7,20,1,6,0,2,0,20,0,2,0,18,0,4,0,58,7,4,0,92,0,0, +0,-80,7,0,0,-79,7,21,1,1,0,4,0,20,0,22,1,6,0,0,0,95,0,2,0,18,0,2,0,20,0,4, +0,-78,7,7,0,-77,7,42,0,-36,5,23,1,4,0,0,0,-74,0,2,0,20,0,4,0,18,0,32,0,45,0,24, +1,2,0,4,0,18,0,4,0,-121,5,5,1,10,0,5,1,0,0,5,1,1,0,5,1,-128,7,2,0,18,0,2, +0,20,0,2,0,90,7,2,0,-76,7,0,0,17,0,9,0,2,0,32,0,45,0,25,1,10,0,7,0,21,3,7, +0,-75,7,7,0,-74,7,7,0,-73,7,7,0,-72,7,4,0,20,0,7,0,-94,7,7,0,-71,7,7,0,-70,7,7, +0,37,0,-28,0,20,0,27,0,31,0,0,0,-63,0,26,1,-69,7,9,0,-68,7,43,0,-104,0,43,0,-67,7,9, +0,-66,7,36,0,79,0,7,0,109,3,7,0,-65,7,7,0,-64,7,7,0,-63,7,7,0,-62,7,7,0,-61,7,7, +0,-60,7,4,0,93,0,4,0,-59,7,0,0,-58,7,0,0,-57,7,0,0,-56,7,27,1,6,0,27,0,31,0,7, +0,-55,7,7,0,-54,7,7,0,-53,7,2,0,-52,7,2,0,-51,7,28,1,14,0,-75,0,0,0,-75,0,1,0,4, +0,75,5,7,0,76,5,-74,0,77,5,-69,0,-108,5,-28,0,18,7,2,0,13,1,2,0,-115,7,2,0,8,2,2, +0,9,2,2,0,20,0,2,0,-98,5,4,0,70,0,29,1,6,0,29,1,0,0,29,1,1,0,32,0,45,0,9, +0,-50,7,4,0,-38,0,4,0,37,0,63,0,4,0,27,0,31,0,12,0,-49,7,4,0,-121,0,7,0,-48,7,30, +1,25,0,30,1,0,0,30,1,1,0,30,1,38,0,12,0,-47,7,0,0,17,0,7,0,-46,7,7,0,-45,7,7, +0,-44,7,7,0,-43,7,4,0,20,0,7,0,-42,7,7,0,-41,7,7,0,-40,7,7,0,20,1,7,0,-39,1,7, +0,-39,7,7,0,108,2,7,0,-38,7,7,0,-37,7,7,0,-36,7,7,0,-35,7,7,0,-34,7,7,0,-81,0,2, +0,-121,0,2,0,-31,4,31,1,19,0,27,0,31,0,12,0,-33,7,12,0,-32,7,4,0,20,0,4,0,30,4,2, +0,-96,2,2,0,-31,7,2,0,-121,0,2,0,-30,7,2,0,-29,7,2,0,-28,7,2,0,-27,7,2,0,-26,7,4, +0,-25,7,4,0,-24,7,4,0,-23,7,4,0,-22,7,4,0,-21,7,4,0,-20,7,32,1,34,0,32,1,0,0,32, +1,1,0,12,0,49,3,0,0,17,0,2,0,20,0,2,0,-19,7,2,0,-18,7,2,0,-17,7,2,0,10,3,2, +0,-16,7,4,0,-7,1,4,0,-23,7,4,0,-22,7,30,1,-15,7,32,1,38,0,32,1,-14,7,12,0,-13,7,9, +0,-12,7,9,0,-11,7,9,0,-10,7,7,0,7,1,7,0,-81,0,7,0,-57,1,7,0,-9,7,7,0,-8,7,7, +0,2,3,7,0,-7,7,7,0,-6,7,7,0,-5,7,7,0,-4,7,7,0,-3,7,7,0,-2,7,7,0,-10,1,32, +0,-1,7,-110,0,9,0,12,0,0,8,2,0,20,0,2,0,1,8,7,0,20,3,7,0,2,8,7,0,3,8,12, +0,4,8,4,0,5,8,4,0,37,0,33,1,7,0,33,1,0,0,33,1,1,0,12,0,-58,7,4,0,20,0,4, +0,6,8,0,0,17,0,-47,0,7,8,34,1,8,0,34,1,0,0,34,1,1,0,33,1,8,8,36,0,79,0,12, +0,-6,2,4,0,20,0,0,0,17,0,4,0,9,8,-111,0,6,0,27,0,31,0,12,0,0,8,12,0,10,8,12, +0,103,0,4,0,11,8,4,0,37,0,35,1,16,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74, +0,77,5,2,0,78,5,-69,0,-108,5,-111,0,-9,2,0,0,13,1,0,0,-37,5,2,0,20,0,2,0,12,8,2, +0,-101,5,2,0,-98,5,2,0,13,8,7,0,14,8,36,1,5,0,36,1,0,0,36,1,1,0,36,0,79,0,2, +0,20,0,0,0,15,8,37,1,12,0,37,1,0,0,37,1,1,0,9,0,2,0,2,0,18,0,2,0,20,0,0, +0,16,8,0,0,17,8,0,0,15,8,7,0,18,8,7,0,19,8,4,0,37,0,36,0,79,0,38,1,9,0,38, +1,0,0,38,1,1,0,32,0,20,8,0,0,21,8,7,0,22,8,2,0,23,8,2,0,20,0,2,0,18,0,2, +0,37,0,39,1,7,0,42,0,-36,5,26,0,24,8,4,0,20,0,4,0,25,8,12,0,26,8,32,0,20,8,0, +0,21,8,40,1,12,0,32,0,20,8,2,0,27,8,2,0,20,0,2,0,28,8,2,0,29,8,0,0,21,8,32, +0,30,8,0,0,31,8,7,0,32,8,7,0,-39,1,7,0,33,8,7,0,34,8,41,1,6,0,32,0,20,8,4, +0,9,8,4,0,35,8,4,0,93,0,4,0,37,0,0,0,21,8,42,1,4,0,32,0,20,8,4,0,20,0,4, +0,9,8,0,0,21,8,43,1,4,0,32,0,20,8,4,0,20,0,4,0,9,8,0,0,21,8,44,1,10,0,32, +0,20,8,4,0,36,8,7,0,-127,0,4,0,20,0,2,0,-42,5,2,0,37,8,2,0,43,0,2,0,70,0,7, +0,38,8,0,0,21,8,45,1,4,0,32,0,20,8,4,0,20,0,4,0,9,8,0,0,21,8,46,1,10,0,32, +0,20,8,2,0,18,0,2,0,-95,3,4,0,91,0,4,0,92,0,7,0,-97,7,7,0,-96,7,4,0,37,0,-111, +0,-122,7,0,0,21,8,47,1,4,0,32,0,20,8,4,0,7,3,4,0,39,8,0,0,21,8,48,1,5,0,32, +0,20,8,7,0,-127,0,4,0,40,8,4,0,7,3,4,0,8,3,49,1,6,0,32,0,20,8,4,0,41,8,4, +0,42,8,7,0,43,8,7,0,44,8,0,0,21,8,50,1,16,0,32,0,20,8,32,0,-14,7,4,0,18,0,7, +0,45,8,7,0,46,8,7,0,47,8,7,0,48,8,7,0,49,8,7,0,50,8,7,0,51,8,7,0,52,8,7, +0,53,8,2,0,20,0,2,0,37,0,2,0,43,0,2,0,70,0,51,1,3,0,32,0,20,8,4,0,20,0,4, +0,123,5,52,1,5,0,32,0,20,8,4,0,20,0,4,0,37,0,7,0,54,8,0,0,21,8,53,1,10,0,32, +0,20,8,0,0,21,8,2,0,55,8,2,0,56,8,0,0,57,8,0,0,58,8,7,0,59,8,7,0,60,8,7, +0,61,8,7,0,62,8,54,1,8,0,7,0,9,0,7,0,10,0,7,0,11,0,7,0,12,0,7,0,63,8,7, +0,64,8,2,0,20,0,2,0,123,5,55,1,8,0,7,0,9,0,7,0,10,0,7,0,11,0,7,0,12,0,7, +0,63,8,7,0,64,8,2,0,20,0,2,0,123,5,56,1,8,0,7,0,9,0,7,0,10,0,7,0,11,0,7, +0,12,0,7,0,63,8,7,0,64,8,2,0,20,0,2,0,123,5,57,1,7,0,32,0,20,8,0,0,21,8,7, +0,20,1,7,0,30,1,2,0,20,0,2,0,13,1,4,0,37,0,58,1,5,0,32,0,-45,2,7,0,20,1,2, +0,-41,2,0,0,-39,2,0,0,65,8,59,1,10,0,59,1,0,0,59,1,1,0,2,0,18,0,2,0,20,0,0, +0,66,8,7,0,-36,0,7,0,-35,0,2,0,-58,7,2,0,67,8,32,0,45,0,60,1,22,0,60,1,0,0,60, +1,1,0,2,0,20,0,2,0,13,1,2,0,68,8,2,0,69,8,36,0,79,0,-111,0,-122,7,32,0,-89,0,7, +0,91,0,7,0,92,0,7,0,70,8,7,0,71,8,7,0,72,8,7,0,73,8,7,0,-107,2,7,0,-67,1,7, +0,-120,7,7,0,74,8,0,0,75,8,0,0,76,8,12,0,-4,2,61,1,8,0,7,0,-31,1,7,0,-97,7,7, +0,-96,7,9,0,2,0,2,0,77,8,2,0,78,8,2,0,79,8,2,0,80,8,62,1,18,0,62,1,0,0,62, +1,1,0,62,1,81,8,0,0,17,0,61,1,82,8,2,0,18,0,2,0,20,0,2,0,83,8,2,0,84,8,2, +0,85,8,2,0,86,8,4,0,43,0,7,0,87,8,7,0,88,8,4,0,89,8,4,0,90,8,62,1,91,8,63, +1,92,8,64,1,32,0,64,1,0,0,64,1,1,0,64,1,93,8,0,0,17,0,0,0,94,8,2,0,18,0,2, +0,20,0,2,0,-14,6,2,0,20,7,2,0,95,8,2,0,-119,0,2,0,84,8,2,0,-25,6,12,0,-127,7,12, +0,96,8,27,0,-9,5,9,0,97,8,7,0,87,8,7,0,88,8,7,0,-5,1,7,0,98,8,2,0,99,8,2, +0,100,8,7,0,101,8,7,0,102,8,2,0,103,8,2,0,104,8,24,0,105,8,24,0,106,8,24,0,107,8,65, +1,-103,0,66,1,108,8,63,1,6,0,63,1,0,0,63,1,1,0,64,1,109,8,64,1,110,8,62,1,111,8,62, +1,91,8,57,0,16,0,27,0,31,0,12,0,112,8,12,0,113,8,61,1,114,8,12,0,115,8,4,0,18,0,4, +0,116,8,4,0,117,8,4,0,118,8,12,0,119,8,66,1,120,8,62,1,121,8,62,1,122,8,9,0,123,8,9, +0,124,8,4,0,125,8,67,1,6,0,4,0,-128,0,4,0,-126,0,4,0,-25,6,0,0,126,8,0,0,127,8,2, +0,37,0,68,1,16,0,2,0,-86,6,2,0,-85,6,2,0,-128,8,2,0,-74,7,2,0,-127,8,2,0,68,0,7, +0,-108,2,7,0,-126,8,7,0,-125,8,2,0,34,1,0,0,-124,8,0,0,42,4,2,0,-123,8,2,0,37,0,4, +0,-122,8,4,0,-121,8,69,1,9,0,7,0,-120,8,7,0,-119,8,7,0,-60,7,7,0,112,0,7,0,-118,8,7, +0,71,5,2,0,-117,8,0,0,-116,8,0,0,37,0,70,1,4,0,7,0,-115,8,7,0,-114,8,2,0,-117,8,2, +0,37,0,71,1,3,0,7,0,-113,8,7,0,-112,8,7,0,15,0,72,1,7,0,0,0,-68,1,2,0,109,4,2, +0,110,4,2,0,111,4,2,0,62,4,4,0,-126,0,4,0,-97,3,73,1,7,0,7,0,-111,8,7,0,-110,8,7, +0,-109,8,7,0,4,2,7,0,-108,8,7,0,-107,8,7,0,-106,8,74,1,4,0,2,0,-105,8,2,0,-104,8,2, +0,-103,8,2,0,-102,8,75,1,2,0,7,0,5,0,7,0,6,0,76,1,2,0,0,0,-87,0,0,0,-101,8,77, +1,1,0,0,0,17,0,78,1,10,0,0,0,-100,8,0,0,-99,8,0,0,-98,8,0,0,-97,8,2,0,-128,8,2, +0,-96,8,7,0,-95,8,7,0,-94,8,7,0,-93,8,7,0,-67,1,79,1,2,0,9,0,-92,8,9,0,-91,8,80, +1,11,0,0,0,111,4,0,0,18,0,0,0,-117,8,0,0,112,0,0,0,-90,8,0,0,109,0,0,0,-74,0,7, +0,-89,8,7,0,-88,8,7,0,-87,8,7,0,-86,8,81,1,8,0,7,0,97,7,7,0,-127,0,7,0,42,4,7, +0,72,2,7,0,-85,8,7,0,-49,0,7,0,-84,8,4,0,18,0,82,1,4,0,2,0,-83,8,2,0,-82,8,2, +0,-81,8,2,0,37,0,83,1,1,0,0,0,17,0,84,1,4,0,7,0,5,0,7,0,6,0,2,0,20,0,2, +0,-80,8,85,1,10,0,2,0,-120,3,2,0,20,0,7,0,-17,3,7,0,-79,8,7,0,-78,8,7,0,-77,8,7, +0,-76,8,84,1,-75,8,84,1,-74,8,84,1,-73,8,60,0,9,0,4,0,20,0,4,0,64,0,24,0,-72,8,24, +0,-71,8,85,1,-70,8,7,0,-69,8,7,0,-68,8,7,0,-67,8,7,0,-66,8,86,1,4,0,46,0,-114,2,7, +0,-65,8,7,0,92,1,7,0,37,0,-87,0,13,0,27,0,31,0,2,0,20,0,2,0,72,5,4,0,109,0,7, +0,-64,8,7,0,1,2,7,0,-63,8,7,0,-62,8,7,0,92,1,2,0,47,1,2,0,37,0,50,0,77,1,86, +1,-61,8,87,1,10,0,4,0,18,0,4,0,-127,0,4,0,20,0,4,0,70,3,4,0,-60,8,4,0,-59,8,4, +0,-58,8,0,0,95,0,0,0,17,0,9,0,2,0,84,0,6,0,87,1,-57,8,4,0,-56,8,4,0,-55,8,4, +0,-54,8,4,0,37,0,9,0,-53,8,88,1,5,0,7,0,66,2,7,0,-74,2,7,0,-39,1,2,0,-52,8,2, +0,37,0,89,1,5,0,7,0,66,2,7,0,-51,8,7,0,-50,8,7,0,-49,8,7,0,-74,2,90,1,7,0,4, +0,-48,8,4,0,-47,8,4,0,-46,8,7,0,-45,8,7,0,-44,8,7,0,-43,8,7,0,-42,8,91,1,26,0,32, +0,-41,8,89,1,66,3,89,1,-40,8,88,1,-39,8,89,1,83,7,7,0,-38,8,7,0,-37,8,7,0,-36,8,7, +0,-35,8,7,0,-44,8,7,0,-43,8,7,0,-74,2,7,0,-97,2,7,0,-34,8,7,0,-33,8,7,0,109,0,7, +0,-32,8,4,0,-48,8,4,0,-31,8,4,0,37,0,4,0,81,0,4,0,-30,8,2,0,20,0,2,0,-29,8,2, +0,-28,8,2,0,100,3,92,1,112,0,27,0,31,0,4,0,20,0,2,0,18,0,2,0,55,8,2,0,-27,8,2, +0,-26,8,2,0,-25,8,2,0,-24,8,2,0,-23,8,2,0,-22,8,2,0,-21,8,2,0,-20,8,2,0,-19,8,2, +0,-18,8,2,0,-17,8,2,0,-16,8,2,0,-15,8,2,0,-14,8,2,0,-13,8,2,0,-47,1,2,0,76,7,2, +0,51,7,2,0,-12,8,2,0,-11,8,2,0,98,3,2,0,99,3,2,0,-10,8,2,0,-9,8,2,0,-8,8,2, +0,-7,8,2,0,-6,8,2,0,-5,8,7,0,-4,8,7,0,-3,8,7,0,-2,8,2,0,-1,8,2,0,0,9,7, +0,1,9,7,0,2,9,7,0,3,9,7,0,58,7,7,0,92,0,7,0,-97,2,7,0,64,7,7,0,4,9,7, +0,5,9,7,0,6,9,7,0,7,9,7,0,57,0,4,0,59,7,4,0,57,7,4,0,8,9,7,0,60,7,7, +0,61,7,7,0,62,7,7,0,9,9,7,0,10,9,7,0,11,9,7,0,12,9,7,0,13,9,7,0,14,9,7, +0,15,9,7,0,16,9,7,0,21,3,7,0,109,0,7,0,17,9,7,0,18,9,7,0,19,9,7,0,20,9,7, +0,21,9,7,0,22,9,7,0,108,2,7,0,23,9,7,0,24,9,4,0,25,9,4,0,26,9,7,0,27,9,7, +0,28,9,7,0,29,9,7,0,30,9,7,0,31,9,7,0,32,9,7,0,33,9,7,0,34,9,7,0,94,3,7, +0,92,3,7,0,93,3,7,0,35,9,7,0,36,9,7,0,37,9,7,0,38,9,7,0,39,9,7,0,40,9,7, +0,41,9,7,0,42,9,7,0,43,9,7,0,28,3,7,0,44,9,7,0,45,9,7,0,46,9,7,0,47,9,7, +0,48,9,7,0,49,9,7,0,50,9,0,0,51,9,63,0,55,3,63,0,52,9,32,0,53,9,32,0,54,9,36, +0,79,0,-108,0,53,3,-108,0,55,9,-120,0,37,0,-120,0,0,0,-120,0,1,0,92,1,56,9,91,1,-121,3,90, +1,-14,7,93,1,57,9,94,1,58,9,94,1,59,9,12,0,60,9,12,0,61,9,-107,0,54,3,32,0,62,9,32, +0,63,9,32,0,64,9,12,0,65,9,12,0,66,9,7,0,-45,0,7,0,83,4,4,0,110,2,4,0,20,0,4, +0,59,7,4,0,67,9,4,0,68,9,4,0,69,9,4,0,57,0,2,0,-38,0,2,0,70,9,2,0,71,9,2, +0,72,9,2,0,47,3,2,0,73,9,0,0,74,9,2,0,75,9,2,0,76,9,2,0,77,9,9,0,78,9,125, +0,-76,3,123,0,34,0,95,1,79,9,7,0,-106,3,7,0,80,9,7,0,81,9,7,0,-14,3,7,0,82,9,7, +0,31,3,7,0,21,3,7,0,83,9,7,0,3,2,7,0,84,9,7,0,85,9,7,0,86,9,7,0,87,9,7, +0,88,9,7,0,89,9,7,0,-105,3,7,0,90,9,7,0,91,9,7,0,92,9,7,0,-104,3,7,0,-108,3,7, +0,-107,3,4,0,93,9,4,0,93,0,4,0,94,9,4,0,95,9,2,0,96,9,2,0,97,9,2,0,98,9,2, +0,99,9,2,0,100,9,2,0,37,0,4,0,70,0,124,0,8,0,95,1,101,9,7,0,102,9,7,0,103,9,7, +0,-94,1,7,0,104,9,4,0,93,0,2,0,105,9,2,0,106,9,96,1,4,0,7,0,5,0,7,0,6,0,7, +0,7,0,7,0,107,9,97,1,6,0,97,1,0,0,97,1,1,0,96,1,108,9,4,0,109,9,2,0,110,9,2, +0,20,0,98,1,5,0,98,1,0,0,98,1,1,0,12,0,111,9,4,0,112,9,4,0,20,0,99,1,9,0,99, +1,0,0,99,1,1,0,12,0,-128,0,98,1,113,9,4,0,20,0,2,0,110,9,2,0,114,9,7,0,94,0,0, +0,115,9,-70,0,5,0,12,0,125,4,4,0,20,0,2,0,116,9,2,0,117,9,9,0,118,9,69,78,68,66,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +}; +int DNAlen64= sizeof(DNAstr64); diff --git a/Extras/Serialize/BlenderSerialize/dna249.cpp b/Extras/Serialize/BlenderSerialize/dna249.cpp new file mode 100644 index 0000000000..97881b4f7a --- /dev/null +++ b/Extras/Serialize/BlenderSerialize/dna249.cpp @@ -0,0 +1,1411 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ +unsigned char DNAstr[]= { +83,68,78,65,78,65,77,69,119,9,0,0,42,110,101,120,116,0,42,112,114,101,118,0,42,100,97,116,97,0,42,102,105, +114,115,116,0,42,108,97,115,116,0,120,0,121,0,122,0,119,0,120,109,105,110,0,120,109,97,120,0,121,109,105,110, +0,121,109,97,120,0,42,112,111,105,110,116,101,114,0,103,114,111,117,112,0,118,97,108,0,118,97,108,50,0,110,97, +109,101,91,51,50,93,0,116,121,112,101,0,115,117,98,116,121,112,101,0,102,108,97,103,0,115,97,118,101,100,0,100, +97,116,97,0,108,101,110,0,116,111,116,97,108,108,101,110,0,42,110,101,119,105,100,0,42,108,105,98,0,110,97,109, +101,91,50,52,93,0,117,115,0,105,99,111,110,95,105,100,0,42,112,114,111,112,101,114,116,105,101,115,0,105,100,0, +42,105,100,98,108,111,99,107,0,42,102,105,108,101,100,97,116,97,0,110,97,109,101,91,50,52,48,93,0,102,105,108, +101,110,97,109,101,91,50,52,48,93,0,116,111,116,0,112,97,100,0,42,112,97,114,101,110,116,0,119,91,50,93,0, +104,91,50,93,0,99,104,97,110,103,101,100,91,50,93,0,112,97,100,48,0,112,97,100,49,0,42,114,101,99,116,91, +50,93,0,42,111,98,0,98,108,111,99,107,116,121,112,101,0,97,100,114,99,111,100,101,0,110,97,109,101,91,49,50, +56,93,0,42,98,112,0,42,98,101,122,116,0,109,97,120,114,99,116,0,116,111,116,114,99,116,0,118,97,114,116,121, +112,101,0,116,111,116,118,101,114,116,0,105,112,111,0,101,120,116,114,97,112,0,114,116,0,98,105,116,109,97,115,107, +0,115,108,105,100,101,95,109,105,110,0,115,108,105,100,101,95,109,97,120,0,99,117,114,118,97,108,0,42,100,114,105, +118,101,114,0,99,117,114,118,101,0,99,117,114,0,115,104,111,119,107,101,121,0,109,117,116,101,105,112,111,0,112,111, +115,0,114,101,108,97,116,105,118,101,0,116,111,116,101,108,101,109,0,112,97,100,50,0,42,119,101,105,103,104,116,115, +0,118,103,114,111,117,112,91,51,50,93,0,115,108,105,100,101,114,109,105,110,0,115,108,105,100,101,114,109,97,120,0, +42,114,101,102,107,101,121,0,101,108,101,109,115,116,114,91,51,50,93,0,101,108,101,109,115,105,122,101,0,98,108,111, +99,107,0,42,105,112,111,0,42,102,114,111,109,0,116,111,116,107,101,121,0,115,108,117,114,112,104,0,42,42,115,99, +114,105,112,116,115,0,42,102,108,97,103,0,97,99,116,115,99,114,105,112,116,0,116,111,116,115,99,114,105,112,116,0, +42,108,105,110,101,0,42,102,111,114,109,97,116,0,98,108,101,110,0,108,105,110,101,110,111,0,115,116,97,114,116,0, +101,110,100,0,102,108,97,103,115,0,99,111,108,111,114,91,52,93,0,112,97,100,91,52,93,0,42,110,97,109,101,0, +110,108,105,110,101,115,0,108,105,110,101,115,0,42,99,117,114,108,0,42,115,101,108,108,0,99,117,114,99,0,115,101, +108,99,0,109,97,114,107,101,114,115,0,42,117,110,100,111,95,98,117,102,0,117,110,100,111,95,112,111,115,0,117,110, +100,111,95,108,101,110,0,42,99,111,109,112,105,108,101,100,0,109,116,105,109,101,0,115,105,122,101,0,115,101,101,107, +0,112,97,115,115,101,112,97,114,116,97,108,112,104,97,0,97,110,103,108,101,0,99,108,105,112,115,116,97,0,99,108, +105,112,101,110,100,0,108,101,110,115,0,111,114,116,104,111,95,115,99,97,108,101,0,100,114,97,119,115,105,122,101,0, +115,104,105,102,116,120,0,115,104,105,102,116,121,0,89,70,95,100,111,102,100,105,115,116,0,89,70,95,97,112,101,114, +116,117,114,101,0,89,70,95,98,107,104,116,121,112,101,0,89,70,95,98,107,104,98,105,97,115,0,89,70,95,98,107, +104,114,111,116,0,115,99,114,105,112,116,108,105,110,107,0,42,100,111,102,95,111,98,0,102,114,97,109,101,110,114,0, +102,114,97,109,101,115,0,111,102,102,115,101,116,0,115,102,114,97,0,102,105,101,95,105,109,97,0,99,121,99,108,0, +111,107,0,109,117,108,116,105,95,105,110,100,101,120,0,108,97,121,101,114,0,112,97,115,115,0,109,101,110,117,110,114, +0,105,98,117,102,115,0,42,103,112,117,116,101,120,116,117,114,101,0,42,97,110,105,109,0,42,114,114,0,115,111,117, +114,99,101,0,108,97,115,116,102,114,97,109,101,0,116,112,97,103,101,102,108,97,103,0,116,111,116,98,105,110,100,0, +120,114,101,112,0,121,114,101,112,0,116,119,115,116,97,0,116,119,101,110,100,0,98,105,110,100,99,111,100,101,0,42, +114,101,112,98,105,110,100,0,42,112,97,99,107,101,100,102,105,108,101,0,42,112,114,101,118,105,101,119,0,108,97,115, +116,117,112,100,97,116,101,0,108,97,115,116,117,115,101,100,0,97,110,105,109,115,112,101,101,100,0,103,101,110,95,120, +0,103,101,110,95,121,0,103,101,110,95,116,121,112,101,0,97,115,112,120,0,97,115,112,121,0,42,118,110,111,100,101, +0,116,101,120,99,111,0,109,97,112,116,111,0,109,97,112,116,111,110,101,103,0,98,108,101,110,100,116,121,112,101,0, +42,111,98,106,101,99,116,0,42,116,101,120,0,117,118,110,97,109,101,91,51,50,93,0,112,114,111,106,120,0,112,114, +111,106,121,0,112,114,111,106,122,0,109,97,112,112,105,110,103,0,111,102,115,91,51,93,0,115,105,122,101,91,51,93, +0,116,101,120,102,108,97,103,0,99,111,108,111,114,109,111,100,101,108,0,112,109,97,112,116,111,0,112,109,97,112,116, +111,110,101,103,0,110,111,114,109,97,112,115,112,97,99,101,0,119,104,105,99,104,95,111,117,116,112,117,116,0,112,97, +100,91,50,93,0,114,0,103,0,98,0,107,0,100,101,102,95,118,97,114,0,99,111,108,102,97,99,0,110,111,114,102, +97,99,0,118,97,114,102,97,99,0,100,105,115,112,102,97,99,0,119,97,114,112,102,97,99,0,110,97,109,101,91,49, +54,48,93,0,42,104,97,110,100,108,101,0,42,112,110,97,109,101,0,42,115,116,110,97,109,101,115,0,115,116,121,112, +101,115,0,118,97,114,115,0,42,118,97,114,115,116,114,0,42,114,101,115,117,108,116,0,42,99,102,114,97,0,100,97, +116,97,91,51,50,93,0,40,42,100,111,105,116,41,40,41,0,40,42,105,110,115,116,97,110,99,101,95,105,110,105,116, +41,40,41,0,40,42,99,97,108,108,98,97,99,107,41,40,41,0,118,101,114,115,105,111,110,0,97,0,105,112,111,116, +121,112,101,0,42,105,109,97,0,42,99,117,98,101,91,54,93,0,105,109,97,116,91,52,93,91,52,93,0,111,98,105, +109,97,116,91,51,93,91,51,93,0,115,116,121,112,101,0,118,105,101,119,115,99,97,108,101,0,110,111,116,108,97,121, +0,99,117,98,101,114,101,115,0,100,101,112,116,104,0,114,101,99,97,108,99,0,108,97,115,116,115,105,122,101,0,110, +111,105,115,101,115,105,122,101,0,116,117,114,98,117,108,0,98,114,105,103,104,116,0,99,111,110,116,114,97,115,116,0, +114,102,97,99,0,103,102,97,99,0,98,102,97,99,0,102,105,108,116,101,114,115,105,122,101,0,109,103,95,72,0,109, +103,95,108,97,99,117,110,97,114,105,116,121,0,109,103,95,111,99,116,97,118,101,115,0,109,103,95,111,102,102,115,101, +116,0,109,103,95,103,97,105,110,0,100,105,115,116,95,97,109,111,117,110,116,0,110,115,95,111,117,116,115,99,97,108, +101,0,118,110,95,119,49,0,118,110,95,119,50,0,118,110,95,119,51,0,118,110,95,119,52,0,118,110,95,109,101,120, +112,0,118,110,95,100,105,115,116,109,0,118,110,95,99,111,108,116,121,112,101,0,110,111,105,115,101,100,101,112,116,104, +0,110,111,105,115,101,116,121,112,101,0,110,111,105,115,101,98,97,115,105,115,0,110,111,105,115,101,98,97,115,105,115, +50,0,105,109,97,102,108,97,103,0,99,114,111,112,120,109,105,110,0,99,114,111,112,121,109,105,110,0,99,114,111,112, +120,109,97,120,0,99,114,111,112,121,109,97,120,0,120,114,101,112,101,97,116,0,121,114,101,112,101,97,116,0,101,120, +116,101,110,100,0,99,104,101,99,107,101,114,100,105,115,116,0,110,97,98,108,97,0,105,117,115,101,114,0,42,110,111, +100,101,116,114,101,101,0,42,112,108,117,103,105,110,0,42,99,111,98,97,0,42,101,110,118,0,117,115,101,95,110,111, +100,101,115,0,112,97,100,91,55,93,0,108,111,99,91,51,93,0,114,111,116,91,51,93,0,109,97,116,91,52,93,91, +52,93,0,109,105,110,91,51,93,0,109,97,120,91,51,93,0,112,97,100,51,0,109,111,100,101,0,116,111,116,101,120, +0,115,104,100,119,114,0,115,104,100,119,103,0,115,104,100,119,98,0,115,104,100,119,112,97,100,0,101,110,101,114,103, +121,0,100,105,115,116,0,115,112,111,116,115,105,122,101,0,115,112,111,116,98,108,101,110,100,0,104,97,105,110,116,0, +97,116,116,49,0,97,116,116,50,0,42,99,117,114,102,97,108,108,111,102,102,0,102,97,108,108,111,102,102,95,116,121, +112,101,0,115,104,97,100,115,112,111,116,115,105,122,101,0,98,105,97,115,0,115,111,102,116,0,98,117,102,115,105,122, +101,0,115,97,109,112,0,98,117,102,102,101,114,115,0,102,105,108,116,101,114,116,121,112,101,0,98,117,102,102,108,97, +103,0,98,117,102,116,121,112,101,0,114,97,121,95,115,97,109,112,0,114,97,121,95,115,97,109,112,121,0,114,97,121, +95,115,97,109,112,122,0,114,97,121,95,115,97,109,112,95,116,121,112,101,0,97,114,101,97,95,115,104,97,112,101,0, +97,114,101,97,95,115,105,122,101,0,97,114,101,97,95,115,105,122,101,121,0,97,114,101,97,95,115,105,122,101,122,0, +97,100,97,112,116,95,116,104,114,101,115,104,0,114,97,121,95,115,97,109,112,95,109,101,116,104,111,100,0,116,101,120, +97,99,116,0,115,104,97,100,104,97,108,111,115,116,101,112,0,115,117,110,95,101,102,102,101,99,116,95,116,121,112,101, +0,115,107,121,98,108,101,110,100,116,121,112,101,0,104,111,114,105,122,111,110,95,98,114,105,103,104,116,110,101,115,115, +0,115,112,114,101,97,100,0,115,117,110,95,98,114,105,103,104,116,110,101,115,115,0,115,117,110,95,115,105,122,101,0, +98,97,99,107,115,99,97,116,116,101,114,101,100,95,108,105,103,104,116,0,115,117,110,95,105,110,116,101,110,115,105,116, +121,0,97,116,109,95,116,117,114,98,105,100,105,116,121,0,97,116,109,95,105,110,115,99,97,116,116,101,114,105,110,103, +95,102,97,99,116,111,114,0,97,116,109,95,101,120,116,105,110,99,116,105,111,110,95,102,97,99,116,111,114,0,97,116, +109,95,100,105,115,116,97,110,99,101,95,102,97,99,116,111,114,0,115,107,121,98,108,101,110,100,102,97,99,0,115,107, +121,95,101,120,112,111,115,117,114,101,0,115,107,121,95,99,111,108,111,114,115,112,97,99,101,0,112,97,100,52,0,89, +70,95,110,117,109,112,104,111,116,111,110,115,0,89,70,95,110,117,109,115,101,97,114,99,104,0,89,70,95,112,104,100, +101,112,116,104,0,89,70,95,117,115,101,113,109,99,0,89,70,95,98,117,102,115,105,122,101,0,89,70,95,112,97,100, +0,89,70,95,99,97,117,115,116,105,99,98,108,117,114,0,89,70,95,108,116,114,97,100,105,117,115,0,89,70,95,103, +108,111,119,105,110,116,0,89,70,95,103,108,111,119,111,102,115,0,89,70,95,103,108,111,119,116,121,112,101,0,89,70, +95,112,97,100,50,0,42,109,116,101,120,91,49,56,93,0,115,112,101,99,114,0,115,112,101,99,103,0,115,112,101,99, +98,0,109,105,114,114,0,109,105,114,103,0,109,105,114,98,0,97,109,98,114,0,97,109,98,98,0,97,109,98,103,0, +97,109,98,0,101,109,105,116,0,97,110,103,0,115,112,101,99,116,114,97,0,114,97,121,95,109,105,114,114,111,114,0, +97,108,112,104,97,0,114,101,102,0,115,112,101,99,0,122,111,102,102,115,0,97,100,100,0,116,114,97,110,115,108,117, +99,101,110,99,121,0,102,114,101,115,110,101,108,95,109,105,114,0,102,114,101,115,110,101,108,95,109,105,114,95,105,0, +102,114,101,115,110,101,108,95,116,114,97,0,102,114,101,115,110,101,108,95,116,114,97,95,105,0,102,105,108,116,101,114, +0,116,120,95,108,105,109,105,116,0,116,120,95,102,97,108,108,111,102,102,0,114,97,121,95,100,101,112,116,104,0,114, +97,121,95,100,101,112,116,104,95,116,114,97,0,104,97,114,0,115,101,101,100,49,0,115,101,101,100,50,0,103,108,111, +115,115,95,109,105,114,0,103,108,111,115,115,95,116,114,97,0,115,97,109,112,95,103,108,111,115,115,95,109,105,114,0, +115,97,109,112,95,103,108,111,115,115,95,116,114,97,0,97,100,97,112,116,95,116,104,114,101,115,104,95,109,105,114,0, +97,100,97,112,116,95,116,104,114,101,115,104,95,116,114,97,0,97,110,105,115,111,95,103,108,111,115,115,95,109,105,114, +0,100,105,115,116,95,109,105,114,0,102,97,100,101,116,111,95,109,105,114,0,115,104,97,100,101,95,102,108,97,103,0, +109,111,100,101,95,108,0,102,108,97,114,101,99,0,115,116,97,114,99,0,108,105,110,101,99,0,114,105,110,103,99,0, +104,97,115,105,122,101,0,102,108,97,114,101,115,105,122,101,0,115,117,98,115,105,122,101,0,102,108,97,114,101,98,111, +111,115,116,0,115,116,114,97,110,100,95,115,116,97,0,115,116,114,97,110,100,95,101,110,100,0,115,116,114,97,110,100, +95,101,97,115,101,0,115,116,114,97,110,100,95,115,117,114,102,110,111,114,0,115,116,114,97,110,100,95,109,105,110,0, +115,116,114,97,110,100,95,119,105,100,116,104,102,97,100,101,0,115,116,114,97,110,100,95,117,118,110,97,109,101,91,51, +50,93,0,115,98,105,97,115,0,108,98,105,97,115,0,115,104,97,100,95,97,108,112,104,97,0,115,101,112,116,101,120, +0,114,103,98,115,101,108,0,112,114,95,116,121,112,101,0,112,114,95,98,97,99,107,0,112,114,95,108,97,109,112,0, +109,108,95,102,108,97,103,0,100,105,102,102,95,115,104,97,100,101,114,0,115,112,101,99,95,115,104,97,100,101,114,0, +114,111,117,103,104,110,101,115,115,0,114,101,102,114,97,99,0,112,97,114,97,109,91,52,93,0,114,109,115,0,100,97, +114,107,110,101,115,115,0,42,114,97,109,112,95,99,111,108,0,42,114,97,109,112,95,115,112,101,99,0,114,97,109,112, +105,110,95,99,111,108,0,114,97,109,112,105,110,95,115,112,101,99,0,114,97,109,112,98,108,101,110,100,95,99,111,108, +0,114,97,109,112,98,108,101,110,100,95,115,112,101,99,0,114,97,109,112,95,115,104,111,119,0,114,97,109,112,102,97, +99,95,99,111,108,0,114,97,109,112,102,97,99,95,115,112,101,99,0,42,103,114,111,117,112,0,102,114,105,99,116,105, +111,110,0,102,104,0,114,101,102,108,101,99,116,0,102,104,100,105,115,116,0,120,121,102,114,105,99,116,0,100,121,110, +97,109,111,100,101,0,115,115,115,95,114,97,100,105,117,115,91,51,93,0,115,115,115,95,99,111,108,91,51,93,0,115, +115,115,95,101,114,114,111,114,0,115,115,115,95,115,99,97,108,101,0,115,115,115,95,105,111,114,0,115,115,115,95,99, +111,108,102,97,99,0,115,115,115,95,116,101,120,102,97,99,0,115,115,115,95,102,114,111,110,116,0,115,115,115,95,98, +97,99,107,0,115,115,115,95,102,108,97,103,0,115,115,115,95,112,114,101,115,101,116,0,89,70,95,97,114,0,89,70, +95,97,103,0,89,70,95,97,98,0,89,70,95,100,115,99,97,108,101,0,89,70,95,100,112,119,114,0,89,70,95,100, +115,109,112,0,89,70,95,112,114,101,115,101,116,0,89,70,95,100,106,105,116,0,103,112,117,109,97,116,101,114,105,97, +108,0,110,97,109,101,91,50,53,54,93,0,115,99,97,108,101,0,42,98,98,0,105,49,0,106,49,0,107,49,0,105, +50,0,106,50,0,107,50,0,115,101,108,99,111,108,49,0,115,101,108,99,111,108,50,0,113,117,97,116,91,52,93,0, +101,120,112,120,0,101,120,112,121,0,101,120,112,122,0,114,97,100,0,114,97,100,50,0,115,0,42,109,97,116,0,42, +105,109,97,116,0,101,108,101,109,115,0,100,105,115,112,0,42,42,109,97,116,0,116,111,116,99,111,108,0,119,105,114, +101,115,105,122,101,0,114,101,110,100,101,114,115,105,122,101,0,116,104,114,101,115,104,0,118,101,99,91,51,93,91,51, +93,0,97,108,102,97,0,119,101,105,103,104,116,0,114,97,100,105,117,115,0,104,49,0,104,50,0,102,49,0,102,50, +0,102,51,0,104,105,100,101,0,118,101,99,91,52,93,0,109,97,116,95,110,114,0,112,110,116,115,117,0,112,110,116, +115,118,0,114,101,115,111,108,117,0,114,101,115,111,108,118,0,111,114,100,101,114,117,0,111,114,100,101,114,118,0,102, +108,97,103,117,0,102,108,97,103,118,0,42,107,110,111,116,115,117,0,42,107,110,111,116,115,118,0,116,105,108,116,95, +105,110,116,101,114,112,0,114,97,100,105,117,115,95,105,110,116,101,114,112,0,99,104,97,114,105,100,120,0,107,101,114, +110,0,104,0,110,117,114,98,0,42,98,101,118,111,98,106,0,42,116,97,112,101,114,111,98,106,0,42,116,101,120,116, +111,110,99,117,114,118,101,0,42,112,97,116,104,0,42,107,101,121,0,98,101,118,0,112,97,116,104,108,101,110,0,98, +101,118,114,101,115,111,108,0,119,105,100,116,104,0,101,120,116,49,0,101,120,116,50,0,114,101,115,111,108,117,95,114, +101,110,0,114,101,115,111,108,118,95,114,101,110,0,115,112,97,99,101,109,111,100,101,0,115,112,97,99,105,110,103,0, +108,105,110,101,100,105,115,116,0,115,104,101,97,114,0,102,115,105,122,101,0,119,111,114,100,115,112,97,99,101,0,117, +108,112,111,115,0,117,108,104,101,105,103,104,116,0,120,111,102,0,121,111,102,0,108,105,110,101,119,105,100,116,104,0, +42,115,116,114,0,102,97,109,105,108,121,91,50,52,93,0,42,118,102,111,110,116,0,42,118,102,111,110,116,98,0,42, +118,102,111,110,116,105,0,42,118,102,111,110,116,98,105,0,115,101,112,99,104,97,114,0,116,111,116,98,111,120,0,97, +99,116,98,111,120,0,42,116,98,0,115,101,108,115,116,97,114,116,0,115,101,108,101,110,100,0,42,115,116,114,105,110, +102,111,0,99,117,114,105,110,102,111,0,101,102,102,101,99,116,0,42,109,102,97,99,101,0,42,109,116,102,97,99,101, +0,42,116,102,97,99,101,0,42,109,118,101,114,116,0,42,109,101,100,103,101,0,42,100,118,101,114,116,0,42,109,99, +111,108,0,42,109,115,116,105,99,107,121,0,42,116,101,120,99,111,109,101,115,104,0,42,109,115,101,108,101,99,116,0, +118,100,97,116,97,0,101,100,97,116,97,0,102,100,97,116,97,0,116,111,116,101,100,103,101,0,116,111,116,102,97,99, +101,0,116,111,116,115,101,108,101,99,116,0,97,99,116,95,102,97,99,101,0,99,117,98,101,109,97,112,115,105,122,101, +0,115,109,111,111,116,104,114,101,115,104,0,115,117,98,100,105,118,0,115,117,98,100,105,118,114,0,115,117,98,115,117, +114,102,116,121,112,101,0,42,109,114,0,42,112,118,0,42,116,112,97,103,101,0,117,118,91,52,93,91,50,93,0,99, +111,108,91,52,93,0,116,114,97,110,115,112,0,116,105,108,101,0,117,110,119,114,97,112,0,118,49,0,118,50,0,118, +51,0,118,52,0,101,100,99,111,100,101,0,99,114,101,97,115,101,0,98,119,101,105,103,104,116,0,100,101,102,95,110, +114,0,42,100,119,0,116,111,116,119,101,105,103,104,116,0,99,111,91,51,93,0,110,111,91,51,93,0,112,97,100,91, +51,93,0,117,118,91,50,93,0,99,111,91,50,93,0,105,110,100,101,120,0,102,0,105,0,115,91,50,53,54,93,0, +118,91,52,93,0,109,105,100,0,118,91,50,93,0,42,102,97,99,101,115,0,42,99,111,108,102,97,99,101,115,0,42, +101,100,103,101,115,0,42,101,100,103,101,95,98,111,117,110,100,97,114,121,95,115,116,97,116,101,115,0,42,118,101,114, +116,95,101,100,103,101,95,109,97,112,0,42,118,101,114,116,95,102,97,99,101,95,109,97,112,0,42,109,97,112,95,109, +101,109,0,42,118,101,114,116,115,0,108,101,118,101,108,115,0,108,101,118,101,108,95,99,111,117,110,116,0,99,117,114, +114,101,110,116,0,110,101,119,108,118,108,0,101,100,103,101,108,118,108,0,112,105,110,108,118,108,0,114,101,110,100,101, +114,108,118,108,0,117,115,101,95,99,111,108,0,42,101,100,103,101,95,102,108,97,103,115,0,42,101,100,103,101,95,99, +114,101,97,115,101,115,0,42,118,101,114,116,95,109,97,112,0,42,101,100,103,101,95,109,97,112,0,42,111,108,100,95, +102,97,99,101,115,0,42,111,108,100,95,101,100,103,101,115,0,42,101,114,114,111,114,0,109,111,100,105,102,105,101,114, +0,115,117,98,100,105,118,84,121,112,101,0,114,101,110,100,101,114,76,101,118,101,108,115,0,42,101,109,67,97,99,104, +101,0,42,109,67,97,99,104,101,0,100,101,102,97,120,105,115,0,112,97,100,91,54,93,0,108,101,110,103,116,104,0, +114,97,110,100,111,109,105,122,101,0,115,101,101,100,0,42,111,98,95,97,114,109,0,42,115,116,97,114,116,95,99,97, +112,0,42,101,110,100,95,99,97,112,0,42,99,117,114,118,101,95,111,98,0,42,111,102,102,115,101,116,95,111,98,0, +111,102,102,115,101,116,91,51,93,0,115,99,97,108,101,91,51,93,0,109,101,114,103,101,95,100,105,115,116,0,102,105, +116,95,116,121,112,101,0,111,102,102,115,101,116,95,116,121,112,101,0,99,111,117,110,116,0,97,120,105,115,0,116,111, +108,101,114,97,110,99,101,0,42,109,105,114,114,111,114,95,111,98,0,115,112,108,105,116,95,97,110,103,108,101,0,118, +97,108,117,101,0,114,101,115,0,118,97,108,95,102,108,97,103,115,0,108,105,109,95,102,108,97,103,115,0,101,95,102, +108,97,103,115,0,98,101,118,101,108,95,97,110,103,108,101,0,100,101,102,103,114,112,95,110,97,109,101,91,51,50,93, +0,42,116,101,120,116,117,114,101,0,115,116,114,101,110,103,116,104,0,100,105,114,101,99,116,105,111,110,0,109,105,100, +108,101,118,101,108,0,116,101,120,109,97,112,112,105,110,103,0,42,109,97,112,95,111,98,106,101,99,116,0,117,118,108, +97,121,101,114,95,110,97,109,101,91,51,50,93,0,117,118,108,97,121,101,114,95,116,109,112,0,42,112,114,111,106,101, +99,116,111,114,115,91,49,48,93,0,42,105,109,97,103,101,0,110,117,109,95,112,114,111,106,101,99,116,111,114,115,0, +97,115,112,101,99,116,120,0,97,115,112,101,99,116,121,0,112,101,114,99,101,110,116,0,102,97,99,101,67,111,117,110, +116,0,102,97,99,0,114,101,112,101,97,116,0,42,111,98,106,101,99,116,99,101,110,116,101,114,0,115,116,97,114,116, +120,0,115,116,97,114,116,121,0,104,101,105,103,104,116,0,110,97,114,114,111,119,0,115,112,101,101,100,0,100,97,109, +112,0,102,97,108,108,111,102,102,0,116,105,109,101,111,102,102,115,0,108,105,102,101,116,105,109,101,0,100,101,102,111, +114,109,102,108,97,103,0,109,117,108,116,105,0,42,112,114,101,118,67,111,115,0,112,97,114,101,110,116,105,110,118,91, +52,93,91,52,93,0,99,101,110,116,91,51,93,0,42,105,110,100,101,120,97,114,0,116,111,116,105,110,100,101,120,0, +102,111,114,99,101,0,42,99,108,111,116,104,79,98,106,101,99,116,0,42,115,105,109,95,112,97,114,109,115,0,42,99, +111,108,108,95,112,97,114,109,115,0,42,112,111,105,110,116,95,99,97,99,104,101,0,42,120,0,42,120,110,101,119,0, +42,120,111,108,100,0,42,99,117,114,114,101,110,116,95,120,110,101,119,0,42,99,117,114,114,101,110,116,95,120,0,42, +99,117,114,114,101,110,116,95,118,0,42,109,102,97,99,101,115,0,110,117,109,118,101,114,116,115,0,110,117,109,102,97, +99,101,115,0,97,98,115,111,114,112,116,105,111,110,0,116,105,109,101,0,42,98,118,104,116,114,101,101,0,42,100,109, +0,111,112,101,114,97,116,105,111,110,0,118,101,114,116,101,120,0,116,111,116,105,110,102,108,117,101,110,99,101,0,103, +114,105,100,115,105,122,101,0,110,101,101,100,98,105,110,100,0,42,98,105,110,100,119,101,105,103,104,116,115,0,42,98, +105,110,100,99,111,115,0,116,111,116,99,97,103,101,118,101,114,116,0,42,100,121,110,103,114,105,100,0,42,100,121,110, +105,110,102,108,117,101,110,99,101,115,0,42,100,121,110,118,101,114,116,115,0,42,112,97,100,50,0,100,121,110,103,114, +105,100,115,105,122,101,0,100,121,110,99,101,108,108,109,105,110,91,51,93,0,100,121,110,99,101,108,108,119,105,100,116, +104,0,98,105,110,100,109,97,116,91,52,93,91,52,93,0,42,112,115,121,115,0,116,111,116,100,109,118,101,114,116,0, +116,111,116,100,109,101,100,103,101,0,116,111,116,100,109,102,97,99,101,0,112,115,121,115,0,114,116,91,50,93,0,42, +102,97,99,101,112,97,0,118,103,114,111,117,112,0,112,114,111,116,101,99,116,0,42,102,115,115,0,42,116,97,114,103, +101,116,0,42,97,117,120,84,97,114,103,101,116,0,118,103,114,111,117,112,95,110,97,109,101,91,51,50,93,0,107,101, +101,112,68,105,115,116,0,115,104,114,105,110,107,84,121,112,101,0,115,104,114,105,110,107,79,112,116,115,0,112,114,111, +106,65,120,105,115,0,115,117,98,115,117,114,102,76,101,118,101,108,115,0,42,111,114,105,103,105,110,0,102,97,99,116, +111,114,0,108,105,109,105,116,91,50,93,0,111,114,105,103,105,110,79,112,116,115,0,112,110,116,115,119,0,111,112,110, +116,115,117,0,111,112,110,116,115,118,0,111,112,110,116,115,119,0,116,121,112,101,117,0,116,121,112,101,118,0,116,121, +112,101,119,0,102,117,0,102,118,0,102,119,0,100,117,0,100,118,0,100,119,0,42,100,101,102,0,118,101,99,91,56, +93,91,51,93,0,112,97,114,116,121,112,101,0,112,97,114,49,0,112,97,114,50,0,112,97,114,51,0,112,97,114,115, +117,98,115,116,114,91,51,50,93,0,42,116,114,97,99,107,0,42,112,114,111,120,121,0,42,112,114,111,120,121,95,103, +114,111,117,112,0,42,112,114,111,120,121,95,102,114,111,109,0,42,97,99,116,105,111,110,0,42,112,111,115,101,108,105, +98,0,42,112,111,115,101,0,99,111,110,115,116,114,97,105,110,116,67,104,97,110,110,101,108,115,0,100,101,102,98,97, +115,101,0,109,111,100,105,102,105,101,114,115,0,100,108,111,99,91,51,93,0,111,114,105,103,91,51,93,0,100,115,105, +122,101,91,51,93,0,100,114,111,116,91,51,93,0,111,98,109,97,116,91,52,93,91,52,93,0,99,111,110,115,116,105, +110,118,91,52,93,91,52,93,0,108,97,121,0,99,111,108,98,105,116,115,0,116,114,97,110,115,102,108,97,103,0,105, +112,111,102,108,97,103,0,116,114,97,99,107,102,108,97,103,0,117,112,102,108,97,103,0,110,108,97,102,108,97,103,0, +112,114,111,116,101,99,116,102,108,97,103,0,105,112,111,119,105,110,0,115,99,97,102,108,97,103,0,115,99,97,118,105, +115,102,108,97,103,0,98,111,117,110,100,116,121,112,101,0,100,117,112,111,110,0,100,117,112,111,102,102,0,100,117,112, +115,116,97,0,100,117,112,101,110,100,0,115,102,0,99,116,105,109,101,0,109,97,115,115,0,100,97,109,112,105,110,103, +0,105,110,101,114,116,105,97,0,102,111,114,109,102,97,99,116,111,114,0,114,100,97,109,112,105,110,103,0,115,105,122, +101,102,97,99,0,109,97,114,103,105,110,0,109,97,120,95,118,101,108,0,109,105,110,95,118,101,108,0,109,95,99,111, +110,116,97,99,116,80,114,111,99,101,115,115,105,110,103,84,104,114,101,115,104,111,108,100,0,100,116,0,100,116,120,0, +97,99,116,99,111,108,0,101,109,112,116,121,95,100,114,97,119,116,121,112,101,0,112,97,100,49,91,51,93,0,101,109, +112,116,121,95,100,114,97,119,115,105,122,101,0,100,117,112,102,97,99,101,115,99,97,0,112,114,111,112,0,115,101,110, +115,111,114,115,0,99,111,110,116,114,111,108,108,101,114,115,0,97,99,116,117,97,116,111,114,115,0,98,98,115,105,122, +101,91,51,93,0,97,99,116,100,101,102,0,103,97,109,101,102,108,97,103,0,103,97,109,101,102,108,97,103,50,0,42, +98,115,111,102,116,0,115,111,102,116,102,108,97,103,0,97,110,105,115,111,116,114,111,112,105,99,70,114,105,99,116,105, +111,110,91,51,93,0,99,111,110,115,116,114,97,105,110,116,115,0,110,108,97,115,116,114,105,112,115,0,104,111,111,107, +115,0,112,97,114,116,105,99,108,101,115,121,115,116,101,109,0,42,112,100,0,42,115,111,102,116,0,42,100,117,112,95, +103,114,111,117,112,0,102,108,117,105,100,115,105,109,70,108,97,103,0,114,101,115,116,114,105,99,116,102,108,97,103,0, +115,104,97,112,101,110,114,0,115,104,97,112,101,102,108,97,103,0,114,101,99,97,108,99,111,0,98,111,100,121,95,116, +121,112,101,0,42,102,108,117,105,100,115,105,109,83,101,116,116,105,110,103,115,0,42,100,101,114,105,118,101,100,68,101, +102,111,114,109,0,42,100,101,114,105,118,101,100,70,105,110,97,108,0,108,97,115,116,68,97,116,97,77,97,115,107,0, +115,116,97,116,101,0,105,110,105,116,95,115,116,97,116,101,0,103,112,117,108,97,109,112,0,99,117,114,105,110,100,101, +120,0,97,99,116,105,118,101,0,100,101,102,108,101,99,116,0,102,111,114,99,101,102,105,101,108,100,0,112,100,101,102, +95,100,97,109,112,0,112,100,101,102,95,114,100,97,109,112,0,112,100,101,102,95,112,101,114,109,0,112,100,101,102,95, +102,114,105,99,116,0,112,100,101,102,95,114,102,114,105,99,116,0,102,95,115,116,114,101,110,103,116,104,0,102,95,112, +111,119,101,114,0,102,95,100,105,115,116,0,102,95,100,97,109,112,0,109,97,120,100,105,115,116,0,109,105,110,100,105, +115,116,0,109,97,120,114,97,100,0,109,105,110,114,97,100,0,102,95,112,111,119,101,114,95,114,0,112,100,101,102,95, +115,98,100,97,109,112,0,112,100,101,102,95,115,98,105,102,116,0,112,100,101,102,95,115,98,111,102,116,0,99,108,117, +109,112,95,102,97,99,0,99,108,117,109,112,95,112,111,119,0,107,105,110,107,95,102,114,101,113,0,107,105,110,107,95, +115,104,97,112,101,0,107,105,110,107,95,97,109,112,0,102,114,101,101,95,101,110,100,0,116,101,120,95,110,97,98,108, +97,0,116,101,120,95,109,111,100,101,0,107,105,110,107,0,107,105,110,107,95,97,120,105,115,0,114,116,50,0,42,114, +110,103,0,102,95,110,111,105,115,101,0,115,105,109,102,114,97,109,101,0,115,116,97,114,116,102,114,97,109,101,0,101, +110,100,102,114,97,109,101,0,101,100,105,116,102,114,97,109,101,0,108,105,110,83,116,105,102,102,0,97,110,103,83,116, +105,102,102,0,118,111,108,117,109,101,0,118,105,116,101,114,97,116,105,111,110,115,0,112,105,116,101,114,97,116,105,111, +110,115,0,100,105,116,101,114,97,116,105,111,110,115,0,99,105,116,101,114,97,116,105,111,110,115,0,107,83,82,72,82, +95,67,76,0,107,83,75,72,82,95,67,76,0,107,83,83,72,82,95,67,76,0,107,83,82,95,83,80,76,84,95,67, +76,0,107,83,75,95,83,80,76,84,95,67,76,0,107,83,83,95,83,80,76,84,95,67,76,0,107,86,67,70,0,107, +68,80,0,107,68,71,0,107,76,70,0,107,80,82,0,107,86,67,0,107,68,70,0,107,77,84,0,107,67,72,82,0, +107,75,72,82,0,107,83,72,82,0,107,65,72,82,0,99,111,108,108,105,115,105,111,110,102,108,97,103,115,0,110,117, +109,99,108,117,115,116,101,114,105,116,101,114,97,116,105,111,110,115,0,119,101,108,100,105,110,103,0,42,112,97,114,116, +105,99,108,101,115,0,116,111,116,112,111,105,110,116,0,116,111,116,115,112,114,105,110,103,0,42,98,112,111,105,110,116, +0,42,98,115,112,114,105,110,103,0,109,115,103,95,108,111,99,107,0,109,115,103,95,118,97,108,117,101,0,110,111,100, +101,109,97,115,115,0,110,97,109,101,100,86,71,95,77,97,115,115,91,51,50,93,0,103,114,97,118,0,109,101,100,105, +97,102,114,105,99,116,0,114,107,108,105,109,105,116,0,112,104,121,115,105,99,115,95,115,112,101,101,100,0,103,111,97, +108,115,112,114,105,110,103,0,103,111,97,108,102,114,105,99,116,0,109,105,110,103,111,97,108,0,109,97,120,103,111,97, +108,0,100,101,102,103,111,97,108,0,118,101,114,116,103,114,111,117,112,0,110,97,109,101,100,86,71,95,83,111,102,116, +103,111,97,108,91,51,50,93,0,102,117,122,122,121,110,101,115,115,0,105,110,115,112,114,105,110,103,0,105,110,102,114, +105,99,116,0,110,97,109,101,100,86,71,95,83,112,114,105,110,103,95,75,91,51,50,93,0,101,102,114,97,0,105,110, +116,101,114,118,97,108,0,108,111,99,97,108,0,115,111,108,118,101,114,102,108,97,103,115,0,42,42,107,101,121,115,0, +116,111,116,112,111,105,110,116,107,101,121,0,115,101,99,111,110,100,115,112,114,105,110,103,0,99,111,108,98,97,108,108, +0,98,97,108,108,100,97,109,112,0,98,97,108,108,115,116,105,102,102,0,115,98,99,95,109,111,100,101,0,97,101,114, +111,101,100,103,101,0,109,105,110,108,111,111,112,115,0,109,97,120,108,111,111,112,115,0,99,104,111,107,101,0,115,111, +108,118,101,114,95,73,68,0,112,108,97,115,116,105,99,0,115,112,114,105,110,103,112,114,101,108,111,97,100,0,42,115, +99,114,97,116,99,104,0,115,104,101,97,114,115,116,105,102,102,0,105,110,112,117,115,104,0,42,112,111,105,110,116,99, +97,99,104,101,0,115,104,111,119,95,97,100,118,97,110,99,101,100,111,112,116,105,111,110,115,0,114,101,115,111,108,117, +116,105,111,110,120,121,122,0,112,114,101,118,105,101,119,114,101,115,120,121,122,0,114,101,97,108,115,105,122,101,0,103, +117,105,68,105,115,112,108,97,121,77,111,100,101,0,114,101,110,100,101,114,68,105,115,112,108,97,121,77,111,100,101,0, +118,105,115,99,111,115,105,116,121,86,97,108,117,101,0,118,105,115,99,111,115,105,116,121,77,111,100,101,0,118,105,115, +99,111,115,105,116,121,69,120,112,111,110,101,110,116,0,103,114,97,118,120,0,103,114,97,118,121,0,103,114,97,118,122, +0,97,110,105,109,83,116,97,114,116,0,97,110,105,109,69,110,100,0,103,115,116,97,114,0,109,97,120,82,101,102,105, +110,101,0,105,110,105,86,101,108,120,0,105,110,105,86,101,108,121,0,105,110,105,86,101,108,122,0,42,111,114,103,77, +101,115,104,0,42,109,101,115,104,83,117,114,102,97,99,101,0,42,109,101,115,104,66,66,0,115,117,114,102,100,97,116, +97,80,97,116,104,91,50,52,48,93,0,98,98,83,116,97,114,116,91,51,93,0,98,98,83,105,122,101,91,51,93,0, +116,121,112,101,70,108,97,103,115,0,100,111,109,97,105,110,78,111,118,101,99,103,101,110,0,118,111,108,117,109,101,73, +110,105,116,84,121,112,101,0,112,97,114,116,83,108,105,112,86,97,108,117,101,0,103,101,110,101,114,97,116,101,84,114, +97,99,101,114,115,0,103,101,110,101,114,97,116,101,80,97,114,116,105,99,108,101,115,0,115,117,114,102,97,99,101,83, +109,111,111,116,104,105,110,103,0,115,117,114,102,97,99,101,83,117,98,100,105,118,115,0,112,97,114,116,105,99,108,101, +73,110,102,83,105,122,101,0,112,97,114,116,105,99,108,101,73,110,102,65,108,112,104,97,0,102,97,114,70,105,101,108, +100,83,105,122,101,0,42,109,101,115,104,83,117,114,102,78,111,114,109,97,108,115,0,99,112,115,84,105,109,101,83,116, +97,114,116,0,99,112,115,84,105,109,101,69,110,100,0,99,112,115,81,117,97,108,105,116,121,0,97,116,116,114,97,99, +116,102,111,114,99,101,83,116,114,101,110,103,116,104,0,97,116,116,114,97,99,116,102,111,114,99,101,82,97,100,105,117, +115,0,118,101,108,111,99,105,116,121,102,111,114,99,101,83,116,114,101,110,103,116,104,0,118,101,108,111,99,105,116,121, +102,111,114,99,101,82,97,100,105,117,115,0,108,97,115,116,103,111,111,100,102,114,97,109,101,0,109,105,115,116,121,112, +101,0,104,111,114,114,0,104,111,114,103,0,104,111,114,98,0,104,111,114,107,0,122,101,110,114,0,122,101,110,103,0, +122,101,110,98,0,122,101,110,107,0,97,109,98,107,0,102,97,115,116,99,111,108,0,101,120,112,111,115,117,114,101,0, +101,120,112,0,114,97,110,103,101,0,108,105,110,102,97,99,0,108,111,103,102,97,99,0,103,114,97,118,105,116,121,0, +97,99,116,105,118,105,116,121,66,111,120,82,97,100,105,117,115,0,115,107,121,116,121,112,101,0,111,99,99,108,117,115, +105,111,110,82,101,115,0,112,104,121,115,105,99,115,69,110,103,105,110,101,0,116,105,99,114,97,116,101,0,109,97,120, +108,111,103,105,99,115,116,101,112,0,112,104,121,115,117,98,115,116,101,112,0,109,97,120,112,104,121,115,116,101,112,0, +109,105,115,105,0,109,105,115,116,115,116,97,0,109,105,115,116,100,105,115,116,0,109,105,115,116,104,105,0,115,116,97, +114,114,0,115,116,97,114,103,0,115,116,97,114,98,0,115,116,97,114,107,0,115,116,97,114,115,105,122,101,0,115,116, +97,114,109,105,110,100,105,115,116,0,115,116,97,114,100,105,115,116,0,115,116,97,114,99,111,108,110,111,105,115,101,0, +100,111,102,115,116,97,0,100,111,102,101,110,100,0,100,111,102,109,105,110,0,100,111,102,109,97,120,0,97,111,100,105, +115,116,0,97,111,100,105,115,116,102,97,99,0,97,111,101,110,101,114,103,121,0,97,111,98,105,97,115,0,97,111,109, +111,100,101,0,97,111,115,97,109,112,0,97,111,109,105,120,0,97,111,99,111,108,111,114,0,97,111,95,97,100,97,112, +116,95,116,104,114,101,115,104,0,97,111,95,97,100,97,112,116,95,115,112,101,101,100,95,102,97,99,0,97,111,95,97, +112,112,114,111,120,95,101,114,114,111,114,0,97,111,95,97,112,112,114,111,120,95,99,111,114,114,101,99,116,105,111,110, +0,97,111,95,115,97,109,112,95,109,101,116,104,111,100,0,97,111,95,103,97,116,104,101,114,95,109,101,116,104,111,100, +0,97,111,95,97,112,112,114,111,120,95,112,97,115,115,101,115,0,42,97,111,115,112,104,101,114,101,0,42,97,111,116, +97,98,108,101,115,0,104,101,109,105,114,101,115,0,109,97,120,105,116,101,114,0,100,114,97,119,116,121,112,101,0,115, +117,98,115,104,111,111,116,112,0,115,117,98,115,104,111,111,116,101,0,110,111,100,101,108,105,109,0,109,97,120,115,117, +98,108,97,109,112,0,112,97,109,97,0,112,97,109,105,0,101,108,109,97,0,101,108,109,105,0,109,97,120,110,111,100, +101,0,99,111,110,118,101,114,103,101,110,99,101,0,114,97,100,102,97,99,0,103,97,109,109,97,0,115,101,108,99,111, +108,0,115,120,0,115,121,0,42,108,112,70,111,114,109,97,116,0,42,108,112,80,97,114,109,115,0,99,98,70,111,114, +109,97,116,0,99,98,80,97,114,109,115,0,102,99,99,84,121,112,101,0,102,99,99,72,97,110,100,108,101,114,0,100, +119,75,101,121,70,114,97,109,101,69,118,101,114,121,0,100,119,81,117,97,108,105,116,121,0,100,119,66,121,116,101,115, +80,101,114,83,101,99,111,110,100,0,100,119,70,108,97,103,115,0,100,119,73,110,116,101,114,108,101,97,118,101,69,118, +101,114,121,0,97,118,105,99,111,100,101,99,110,97,109,101,91,49,50,56,93,0,42,99,100,80,97,114,109,115,0,42, +112,97,100,0,99,100,83,105,122,101,0,113,116,99,111,100,101,99,110,97,109,101,91,49,50,56,93,0,99,111,100,101, +99,0,97,117,100,105,111,95,99,111,100,101,99,0,118,105,100,101,111,95,98,105,116,114,97,116,101,0,97,117,100,105, +111,95,98,105,116,114,97,116,101,0,103,111,112,95,115,105,122,101,0,114,99,95,109,105,110,95,114,97,116,101,0,114, +99,95,109,97,120,95,114,97,116,101,0,114,99,95,98,117,102,102,101,114,95,115,105,122,101,0,109,117,120,95,112,97, +99,107,101,116,95,115,105,122,101,0,109,117,120,95,114,97,116,101,0,109,105,120,114,97,116,101,0,109,97,105,110,0, +42,109,97,116,95,111,118,101,114,114,105,100,101,0,42,108,105,103,104,116,95,111,118,101,114,114,105,100,101,0,108,97, +121,95,122,109,97,115,107,0,108,97,121,102,108,97,103,0,112,97,115,115,102,108,97,103,0,112,97,115,115,95,120,111, +114,0,42,97,118,105,99,111,100,101,99,100,97,116,97,0,42,113,116,99,111,100,101,99,100,97,116,97,0,102,102,99, +111,100,101,99,100,97,116,97,0,99,102,114,97,0,112,115,102,114,97,0,112,101,102,114,97,0,105,109,97,103,101,115, +0,102,114,97,109,97,112,116,111,0,116,104,114,101,97,100,115,0,102,114,97,109,101,108,101,110,0,98,108,117,114,102, +97,99,0,101,100,103,101,82,0,101,100,103,101,71,0,101,100,103,101,66,0,102,117,108,108,115,99,114,101,101,110,0, +120,112,108,97,121,0,121,112,108,97,121,0,102,114,101,113,112,108,97,121,0,97,116,116,114,105,98,0,114,116,49,0, +115,116,101,114,101,111,109,111,100,101,0,100,105,109,101,110,115,105,111,110,115,112,114,101,115,101,116,0,109,97,120,105, +109,115,105,122,101,0,120,115,99,104,0,121,115,99,104,0,120,112,97,114,116,115,0,121,112,97,114,116,115,0,119,105, +110,112,111,115,0,112,108,97,110,101,115,0,105,109,116,121,112,101,0,115,117,98,105,109,116,121,112,101,0,113,117,97, +108,105,116,121,0,114,112,97,100,0,114,112,97,100,49,0,114,112,97,100,50,0,115,99,101,109,111,100,101,0,114,101, +110,100,101,114,101,114,0,111,99,114,101,115,0,97,108,112,104,97,109,111,100,101,0,111,115,97,0,102,114,115,95,115, +101,99,0,101,100,103,101,105,110,116,0,115,97,102,101,116,121,0,98,111,114,100,101,114,0,100,105,115,112,114,101,99, +116,0,108,97,121,101,114,115,0,97,99,116,108,97,121,0,120,97,115,112,0,121,97,115,112,0,102,114,115,95,115,101, +99,95,98,97,115,101,0,103,97,117,115,115,0,112,111,115,116,109,117,108,0,112,111,115,116,103,97,109,109,97,0,112, +111,115,116,104,117,101,0,112,111,115,116,115,97,116,0,100,105,116,104,101,114,95,105,110,116,101,110,115,105,116,121,0, +98,97,107,101,95,111,115,97,0,98,97,107,101,95,102,105,108,116,101,114,0,98,97,107,101,95,109,111,100,101,0,98, +97,107,101,95,102,108,97,103,0,98,97,107,101,95,110,111,114,109,97,108,95,115,112,97,99,101,0,98,97,107,101,95, +113,117,97,100,95,115,112,108,105,116,0,98,97,107,101,95,109,97,120,100,105,115,116,0,98,97,107,101,95,98,105,97, +115,100,105,115,116,0,98,97,107,101,95,112,97,100,0,71,73,113,117,97,108,105,116,121,0,71,73,99,97,99,104,101, +0,71,73,109,101,116,104,111,100,0,71,73,112,104,111,116,111,110,115,0,71,73,100,105,114,101,99,116,0,89,70,95, +65,65,0,89,70,101,120,112,111,114,116,120,109,108,0,89,70,95,110,111,98,117,109,112,0,89,70,95,99,108,97,109, +112,114,103,98,0,121,102,112,97,100,49,0,71,73,100,101,112,116,104,0,71,73,99,97,117,115,100,101,112,116,104,0, +71,73,112,105,120,101,108,115,112,101,114,115,97,109,112,108,101,0,71,73,112,104,111,116,111,110,99,111,117,110,116,0, +71,73,109,105,120,112,104,111,116,111,110,115,0,71,73,112,104,111,116,111,110,114,97,100,105,117,115,0,89,70,95,114, +97,121,100,101,112,116,104,0,89,70,95,65,65,112,97,115,115,101,115,0,89,70,95,65,65,115,97,109,112,108,101,115, +0,121,102,112,97,100,50,0,71,73,115,104,97,100,111,119,113,117,97,108,105,116,121,0,71,73,114,101,102,105,110,101, +109,101,110,116,0,71,73,112,111,119,101,114,0,71,73,105,110,100,105,114,112,111,119,101,114,0,89,70,95,103,97,109, +109,97,0,89,70,95,101,120,112,111,115,117,114,101,0,89,70,95,114,97,121,98,105,97,115,0,89,70,95,65,65,112, +105,120,101,108,115,105,122,101,0,89,70,95,65,65,116,104,114,101,115,104,111,108,100,0,98,97,99,107,98,117,102,91, +49,54,48,93,0,112,105,99,91,49,54,48,93,0,115,116,97,109,112,0,115,116,97,109,112,95,102,111,110,116,95,105, +100,0,115,116,97,109,112,95,117,100,97,116,97,91,49,54,48,93,0,102,103,95,115,116,97,109,112,91,52,93,0,98, +103,95,115,116,97,109,112,91,52,93,0,115,105,109,112,108,105,102,121,95,115,117,98,115,117,114,102,0,115,105,109,112, +108,105,102,121,95,115,104,97,100,111,119,115,97,109,112,108,101,115,0,115,105,109,112,108,105,102,121,95,112,97,114,116, +105,99,108,101,115,0,115,105,109,112,108,105,102,121,95,97,111,115,115,115,0,99,105,110,101,111,110,119,104,105,116,101, +0,99,105,110,101,111,110,98,108,97,99,107,0,99,105,110,101,111,110,103,97,109,109,97,0,106,112,50,95,112,114,101, +115,101,116,0,106,112,50,95,100,101,112,116,104,0,114,112,97,100,51,0,100,111,109,101,114,101,115,0,100,111,109,101, +109,111,100,101,0,100,111,109,101,97,110,103,108,101,0,100,111,109,101,116,105,108,116,0,100,111,109,101,114,101,115,98, +117,102,0,42,100,111,109,101,116,101,120,116,0,112,97,114,116,105,99,108,101,95,112,101,114,99,0,115,117,98,115,117, +114,102,95,109,97,120,0,115,104,97,100,98,117,102,115,97,109,112,108,101,95,109,97,120,0,97,111,95,101,114,114,111, +114,0,99,111,108,91,51,93,0,102,114,97,109,101,0,110,97,109,101,91,54,52,93,0,42,98,114,117,115,104,0,116, +111,111,108,0,115,101,97,109,95,98,108,101,101,100,0,110,111,114,109,97,108,95,97,110,103,108,101,0,115,116,101,112, +0,105,110,118,101,114,116,0,116,111,116,114,101,107,101,121,0,116,111,116,97,100,100,107,101,121,0,98,114,117,115,104, +116,121,112,101,0,98,114,117,115,104,91,55,93,0,101,109,105,116,116,101,114,100,105,115,116,0,100,114,97,119,95,116, +105,109,101,100,0,110,97,109,101,91,51,54,93,0,109,97,116,91,51,93,91,51,93,0,99,111,114,110,101,114,116,121, +112,101,0,101,100,105,116,98,117,116,102,108,97,103,0,106,111,105,110,116,114,105,108,105,109,105,116,0,100,101,103,114, +0,116,117,114,110,0,101,120,116,114,95,111,102,102,115,0,100,111,117,98,108,105,109,105,116,0,115,101,103,109,101,110, +116,115,0,114,105,110,103,115,0,118,101,114,116,105,99,101,115,0,117,110,119,114,97,112,112,101,114,0,117,118,99,97, +108,99,95,114,97,100,105,117,115,0,117,118,99,97,108,99,95,99,117,98,101,115,105,122,101,0,117,118,99,97,108,99, +95,109,97,114,103,105,110,0,117,118,99,97,108,99,95,109,97,112,100,105,114,0,117,118,99,97,108,99,95,109,97,112, +97,108,105,103,110,0,117,118,99,97,108,99,95,102,108,97,103,0,97,117,116,111,105,107,95,99,104,97,105,110,108,101, +110,0,105,109,97,112,97,105,110,116,0,112,97,114,116,105,99,108,101,0,115,101,108,101,99,116,95,116,104,114,101,115, +104,0,99,108,101,97,110,95,116,104,114,101,115,104,0,114,101,116,111,112,111,95,109,111,100,101,0,114,101,116,111,112, +111,95,112,97,105,110,116,95,116,111,111,108,0,108,105,110,101,95,100,105,118,0,101,108,108,105,112,115,101,95,100,105, +118,0,114,101,116,111,112,111,95,104,111,116,115,112,111,116,0,109,117,108,116,105,114,101,115,95,115,117,98,100,105,118, +95,116,121,112,101,0,115,107,103,101,110,95,114,101,115,111,108,117,116,105,111,110,0,115,107,103,101,110,95,116,104,114, +101,115,104,111,108,100,95,105,110,116,101,114,110,97,108,0,115,107,103,101,110,95,116,104,114,101,115,104,111,108,100,95, +101,120,116,101,114,110,97,108,0,115,107,103,101,110,95,108,101,110,103,116,104,95,114,97,116,105,111,0,115,107,103,101, +110,95,108,101,110,103,116,104,95,108,105,109,105,116,0,115,107,103,101,110,95,97,110,103,108,101,95,108,105,109,105,116, +0,115,107,103,101,110,95,99,111,114,114,101,108,97,116,105,111,110,95,108,105,109,105,116,0,115,107,103,101,110,95,115, +121,109,109,101,116,114,121,95,108,105,109,105,116,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,97,110,103, +108,101,95,119,101,105,103,104,116,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,108,101,110,103,116,104,95, +119,101,105,103,104,116,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,100,105,115,116,97,110,99,101,95,119, +101,105,103,104,116,0,115,107,103,101,110,95,111,112,116,105,111,110,115,0,115,107,103,101,110,95,112,111,115,116,112,114, +111,0,115,107,103,101,110,95,112,111,115,116,112,114,111,95,112,97,115,115,101,115,0,115,107,103,101,110,95,115,117,98, +100,105,118,105,115,105,111,110,115,91,51,93,0,115,107,103,101,110,95,109,117,108,116,105,95,108,101,118,101,108,0,42, +115,107,103,101,110,95,116,101,109,112,108,97,116,101,0,98,111,110,101,95,115,107,101,116,99,104,105,110,103,0,98,111, +110,101,95,115,107,101,116,99,104,105,110,103,95,99,111,110,118,101,114,116,0,115,107,103,101,110,95,115,117,98,100,105, +118,105,115,105,111,110,95,110,117,109,98,101,114,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,111,112,116, +105,111,110,115,0,115,107,103,101,110,95,114,101,116,97,114,103,101,116,95,114,111,108,108,0,115,107,103,101,110,95,115, +105,100,101,95,115,116,114,105,110,103,91,56,93,0,115,107,103,101,110,95,110,117,109,95,115,116,114,105,110,103,91,56, +93,0,101,100,103,101,95,109,111,100,101,0,112,97,100,51,91,50,93,0,100,105,114,0,118,105,101,119,0,42,115,101, +115,115,105,111,110,0,42,99,117,109,97,112,0,100,114,97,119,98,114,117,115,104,0,115,109,111,111,116,104,98,114,117, +115,104,0,112,105,110,99,104,98,114,117,115,104,0,105,110,102,108,97,116,101,98,114,117,115,104,0,103,114,97,98,98, +114,117,115,104,0,108,97,121,101,114,98,114,117,115,104,0,102,108,97,116,116,101,110,98,114,117,115,104,0,112,105,118, +111,116,91,51,93,0,98,114,117,115,104,95,116,121,112,101,0,116,101,120,110,114,0,116,101,120,114,101,112,116,0,116, +101,120,102,97,100,101,0,116,101,120,115,101,112,0,97,118,101,114,97,103,105,110,103,0,116,97,98,108,101,116,95,115, +105,122,101,0,116,97,98,108,101,116,95,115,116,114,101,110,103,116,104,0,115,121,109,109,0,114,97,107,101,0,97,120, +105,115,108,111,99,107,0,42,99,97,109,101,114,97,0,42,119,111,114,108,100,0,42,115,101,116,0,98,97,115,101,0, +42,98,97,115,97,99,116,0,99,117,114,115,111,114,91,51,93,0,116,119,99,101,110,116,91,51,93,0,116,119,109,105, +110,91,51,93,0,116,119,109,97,120,91,51,93,0,101,100,105,116,98,117,116,115,105,122,101,0,115,101,108,101,99,116, +109,111,100,101,0,112,114,111,112,111,114,116,105,111,110,97,108,0,112,114,111,112,95,109,111,100,101,0,97,117,116,111, +109,101,114,103,101,0,112,97,100,53,0,112,97,100,54,0,97,117,116,111,107,101,121,95,109,111,100,101,0,42,101,100, +0,42,114,97,100,105,111,0,102,114,97,109,105,110,103,0,42,116,111,111,108,115,101,116,116,105,110,103,115,0,97,117, +100,105,111,0,116,114,97,110,115,102,111,114,109,95,115,112,97,99,101,115,0,106,117,109,112,102,114,97,109,101,0,115, +110,97,112,95,109,111,100,101,0,115,110,97,112,95,102,108,97,103,0,115,110,97,112,95,116,97,114,103,101,116,0,42, +116,104,101,68,97,103,0,100,97,103,105,115,118,97,108,105,100,0,100,97,103,102,108,97,103,115,0,115,99,117,108,112, +116,100,97,116,97,0,102,114,97,109,101,95,115,116,101,112,0,122,111,111,109,0,98,108,101,110,100,0,120,105,109,0, +121,105,109,0,115,112,97,99,101,116,121,112,101,0,98,108,111,99,107,115,99,97,108,101,0,42,97,114,101,97,0,98, +108,111,99,107,104,97,110,100,108,101,114,91,56,93,0,118,105,101,119,109,97,116,91,52,93,91,52,93,0,118,105,101, +119,105,110,118,91,52,93,91,52,93,0,112,101,114,115,109,97,116,91,52,93,91,52,93,0,112,101,114,115,105,110,118, +91,52,93,91,52,93,0,119,105,110,109,97,116,49,91,52,93,91,52,93,0,118,105,101,119,109,97,116,49,91,52,93, +91,52,93,0,118,105,101,119,113,117,97,116,91,52,93,0,122,102,97,99,0,108,97,121,95,117,115,101,100,0,112,101, +114,115,112,0,42,111,98,95,99,101,110,116,114,101,0,42,98,103,112,105,99,0,42,108,111,99,97,108,118,100,0,42, +114,105,0,42,114,101,116,111,112,111,95,118,105,101,119,95,100,97,116,97,0,42,100,101,112,116,104,115,0,111,98,95, +99,101,110,116,114,101,95,98,111,110,101,91,51,50,93,0,108,111,99,97,108,118,105,101,119,0,108,97,121,97,99,116, +0,115,99,101,110,101,108,111,99,107,0,97,114,111,117,110,100,0,99,97,109,122,111,111,109,0,112,105,118,111,116,95, +108,97,115,116,0,103,114,105,100,0,103,114,105,100,118,105,101,119,0,112,105,120,115,105,122,101,0,110,101,97,114,0, +102,97,114,0,99,97,109,100,120,0,99,97,109,100,121,0,103,114,105,100,108,105,110,101,115,0,118,105,101,119,98,117, +116,0,103,114,105,100,102,108,97,103,0,109,111,100,101,115,101,108,101,99,116,0,116,119,116,121,112,101,0,116,119,109, +111,100,101,0,116,119,102,108,97,103,0,116,119,100,114,97,119,102,108,97,103,0,116,119,109,97,116,91,52,93,91,52, +93,0,99,108,105,112,91,52,93,91,52,93,0,42,99,108,105,112,98,98,0,97,102,116,101,114,100,114,97,119,0,122, +98,117,102,0,120,114,97,121,0,102,108,97,103,50,0,103,114,105,100,115,117,98,100,105,118,0,107,101,121,102,108,97, +103,115,0,110,100,111,102,109,111,100,101,0,110,100,111,102,102,105,108,116,101,114,0,42,112,114,111,112,101,114,116,105, +101,115,95,115,116,111,114,97,103,101,0,42,103,112,100,0,108,118,105,101,119,113,117,97,116,91,52,93,0,108,112,101, +114,115,112,0,108,118,105,101,119,0,118,101,114,116,0,104,111,114,0,109,97,115,107,0,109,105,110,91,50,93,0,109, +97,120,91,50,93,0,109,105,110,122,111,111,109,0,109,97,120,122,111,111,109,0,115,99,114,111,108,108,0,107,101,101, +112,116,111,116,0,107,101,101,112,97,115,112,101,99,116,0,107,101,101,112,122,111,111,109,0,111,108,100,119,105,110,120, +0,111,108,100,119,105,110,121,0,99,117,114,115,111,114,91,50,93,0,114,111,119,98,117,116,0,118,50,100,0,42,101, +100,105,116,105,112,111,0,105,112,111,107,101,121,0,97,99,116,110,97,109,101,91,51,50,93,0,99,111,110,115,116,110, +97,109,101,91,51,50,93,0,98,111,110,101,110,97,109,101,91,51,50,93,0,116,111,116,105,112,111,0,112,105,110,0, +98,117,116,111,102,115,0,99,104,97,110,110,101,108,0,108,111,99,107,0,109,101,100,105,97,110,91,51,93,0,99,117, +114,115,101,110,115,0,99,117,114,97,99,116,0,97,108,105,103,110,0,116,97,98,111,0,109,97,105,110,98,0,109,97, +105,110,98,111,0,42,108,111,99,107,112,111,105,110,0,116,101,120,102,114,111,109,0,115,104,111,119,103,114,111,117,112, +0,109,111,100,101,108,116,121,112,101,0,115,99,114,105,112,116,98,108,111,99,107,0,114,101,95,97,108,105,103,110,0, +111,108,100,107,101,121,112,114,101,115,115,0,116,97,98,91,55,93,0,114,101,110,100,101,114,95,115,105,122,101,0,99, +104,97,110,115,104,111,119,110,0,122,101,98,114,97,0,42,102,105,108,101,108,105,115,116,0,116,111,116,102,105,108,101, +0,116,105,116,108,101,91,50,52,93,0,100,105,114,91,50,52,48,93,0,102,105,108,101,91,56,48,93,0,111,102,115, +0,115,111,114,116,0,109,97,120,110,97,109,101,108,101,110,0,99,111,108,108,117,109,115,0,102,95,102,112,0,102,112, +95,115,116,114,91,56,93,0,42,108,105,98,102,105,108,101,100,97,116,97,0,114,101,116,118,97,108,0,109,101,110,117, +0,97,99,116,0,40,42,114,101,116,117,114,110,102,117,110,99,41,40,41,0,40,42,114,101,116,117,114,110,102,117,110, +99,95,101,118,101,110,116,41,40,41,0,40,42,114,101,116,117,114,110,102,117,110,99,95,97,114,103,115,41,40,41,0, +42,97,114,103,49,0,42,97,114,103,50,0,42,109,101,110,117,112,0,42,112,117,112,109,101,110,117,0,111,111,112,115, +0,118,105,115,105,102,108,97,103,0,116,114,101,101,0,42,116,114,101,101,115,116,111,114,101,0,115,101,97,114,99,104, +95,115,116,114,105,110,103,91,51,50,93,0,115,101,97,114,99,104,95,116,115,101,0,115,101,97,114,99,104,95,102,108, +97,103,115,0,100,111,95,0,111,117,116,108,105,110,101,118,105,115,0,115,116,111,114,101,102,108,97,103,0,100,101,112, +115,95,102,108,97,103,115,0,105,109,97,110,114,0,99,117,114,116,105,108,101,0,105,109,116,121,112,101,110,114,0,100, +116,95,117,118,0,115,116,105,99,107,121,0,100,116,95,117,118,115,116,114,101,116,99,104,0,112,97,100,91,53,93,0, +99,101,110,116,120,0,99,101,110,116,121,0,97,117,116,111,115,110,97,112,0,42,116,101,120,116,0,116,111,112,0,118, +105,101,119,108,105,110,101,115,0,102,111,110,116,95,105,100,0,108,104,101,105,103,104,116,0,108,101,102,116,0,115,104, +111,119,108,105,110,101,110,114,115,0,116,97,98,110,117,109,98,101,114,0,99,117,114,114,116,97,98,95,115,101,116,0, +115,104,111,119,115,121,110,116,97,120,0,111,118,101,114,119,114,105,116,101,0,112,105,120,95,112,101,114,95,108,105,110, +101,0,116,120,116,115,99,114,111,108,108,0,116,120,116,98,97,114,0,119,111,114,100,119,114,97,112,0,100,111,112,108, +117,103,105,110,115,0,42,112,121,95,100,114,97,119,0,42,112,121,95,101,118,101,110,116,0,42,112,121,95,98,117,116, +116,111,110,0,42,112,121,95,98,114,111,119,115,101,114,99,97,108,108,98,97,99,107,0,42,112,121,95,103,108,111,98, +97,108,100,105,99,116,0,108,97,115,116,115,112,97,99,101,0,115,99,114,105,112,116,110,97,109,101,91,50,53,54,93, +0,115,99,114,105,112,116,97,114,103,91,50,53,54,93,0,42,115,99,114,105,112,116,0,42,98,117,116,95,114,101,102, +115,0,114,101,100,114,97,119,115,0,42,105,100,0,97,115,112,101,99,116,0,42,99,117,114,102,111,110,116,0,42,101, +100,105,116,116,114,101,101,0,116,114,101,101,116,121,112,101,0,42,102,105,108,101,115,0,97,99,116,105,118,101,95,102, +105,108,101,0,110,117,109,116,105,108,101,115,120,0,110,117,109,116,105,108,101,115,121,0,115,101,108,115,116,97,116,101, +0,118,105,101,119,114,101,99,116,0,98,111,111,107,109,97,114,107,114,101,99,116,0,115,99,114,111,108,108,112,111,115, +0,115,99,114,111,108,108,104,101,105,103,104,116,0,115,99,114,111,108,108,97,114,101,97,0,97,99,116,105,118,101,95, +98,111,111,107,109,97,114,107,0,112,114,118,95,119,0,112,114,118,95,104,0,42,105,109,103,0,111,117,116,108,105,110, +101,91,52,93,0,110,101,117,116,114,97,108,91,52,93,0,97,99,116,105,111,110,91,52,93,0,115,101,116,116,105,110, +103,91,52,93,0,115,101,116,116,105,110,103,49,91,52,93,0,115,101,116,116,105,110,103,50,91,52,93,0,110,117,109, +91,52,93,0,116,101,120,116,102,105,101,108,100,91,52,93,0,116,101,120,116,102,105,101,108,100,95,104,105,91,52,93, +0,112,111,112,117,112,91,52,93,0,116,101,120,116,91,52,93,0,116,101,120,116,95,104,105,91,52,93,0,109,101,110, +117,95,98,97,99,107,91,52,93,0,109,101,110,117,95,105,116,101,109,91,52,93,0,109,101,110,117,95,104,105,108,105, +116,101,91,52,93,0,109,101,110,117,95,116,101,120,116,91,52,93,0,109,101,110,117,95,116,101,120,116,95,104,105,91, +52,93,0,98,117,116,95,100,114,97,119,116,121,112,101,0,105,99,111,110,102,105,108,101,91,56,48,93,0,98,97,99, +107,91,52,93,0,104,101,97,100,101,114,91,52,93,0,112,97,110,101,108,91,52,93,0,115,104,97,100,101,49,91,52, +93,0,115,104,97,100,101,50,91,52,93,0,104,105,108,105,116,101,91,52,93,0,103,114,105,100,91,52,93,0,119,105, +114,101,91,52,93,0,115,101,108,101,99,116,91,52,93,0,108,97,109,112,91,52,93,0,97,99,116,105,118,101,91,52, +93,0,103,114,111,117,112,91,52,93,0,103,114,111,117,112,95,97,99,116,105,118,101,91,52,93,0,116,114,97,110,115, +102,111,114,109,91,52,93,0,118,101,114,116,101,120,91,52,93,0,118,101,114,116,101,120,95,115,101,108,101,99,116,91, +52,93,0,101,100,103,101,91,52,93,0,101,100,103,101,95,115,101,108,101,99,116,91,52,93,0,101,100,103,101,95,115, +101,97,109,91,52,93,0,101,100,103,101,95,115,104,97,114,112,91,52,93,0,101,100,103,101,95,102,97,99,101,115,101, +108,91,52,93,0,102,97,99,101,91,52,93,0,102,97,99,101,95,115,101,108,101,99,116,91,52,93,0,102,97,99,101, +95,100,111,116,91,52,93,0,110,111,114,109,97,108,91,52,93,0,98,111,110,101,95,115,111,108,105,100,91,52,93,0, +98,111,110,101,95,112,111,115,101,91,52,93,0,115,116,114,105,112,91,52,93,0,115,116,114,105,112,95,115,101,108,101, +99,116,91,52,93,0,99,102,114,97,109,101,91,52,93,0,118,101,114,116,101,120,95,115,105,122,101,0,102,97,99,101, +100,111,116,95,115,105,122,101,0,98,112,97,100,91,50,93,0,115,121,110,116,97,120,108,91,52,93,0,115,121,110,116, +97,120,110,91,52,93,0,115,121,110,116,97,120,98,91,52,93,0,115,121,110,116,97,120,118,91,52,93,0,115,121,110, +116,97,120,99,91,52,93,0,109,111,118,105,101,91,52,93,0,105,109,97,103,101,91,52,93,0,115,99,101,110,101,91, +52,93,0,97,117,100,105,111,91,52,93,0,101,102,102,101,99,116,91,52,93,0,112,108,117,103,105,110,91,52,93,0, +116,114,97,110,115,105,116,105,111,110,91,52,93,0,109,101,116,97,91,52,93,0,101,100,105,116,109,101,115,104,95,97, +99,116,105,118,101,91,52,93,0,104,97,110,100,108,101,95,118,101,114,116,101,120,91,52,93,0,104,97,110,100,108,101, +95,118,101,114,116,101,120,95,115,101,108,101,99,116,91,52,93,0,104,97,110,100,108,101,95,118,101,114,116,101,120,95, +115,105,122,101,0,104,112,97,100,91,55,93,0,115,111,108,105,100,91,52,93,0,116,117,105,0,116,98,117,116,115,0, +116,118,51,100,0,116,102,105,108,101,0,116,105,112,111,0,116,105,110,102,111,0,116,115,110,100,0,116,97,99,116,0, +116,110,108,97,0,116,115,101,113,0,116,105,109,97,0,116,105,109,97,115,101,108,0,116,101,120,116,0,116,111,111,112, +115,0,116,116,105,109,101,0,116,110,111,100,101,0,116,97,114,109,91,50,48,93,0,98,112,97,100,91,52,93,0,98, +112,97,100,49,91,52,93,0,115,112,101,99,91,52,93,0,100,117,112,102,108,97,103,0,115,97,118,101,116,105,109,101, +0,116,101,109,112,100,105,114,91,49,54,48,93,0,102,111,110,116,100,105,114,91,49,54,48,93,0,114,101,110,100,101, +114,100,105,114,91,49,54,48,93,0,116,101,120,116,117,100,105,114,91,49,54,48,93,0,112,108,117,103,116,101,120,100, +105,114,91,49,54,48,93,0,112,108,117,103,115,101,113,100,105,114,91,49,54,48,93,0,112,121,116,104,111,110,100,105, +114,91,49,54,48,93,0,115,111,117,110,100,100,105,114,91,49,54,48,93,0,121,102,101,120,112,111,114,116,100,105,114, +91,49,54,48,93,0,118,101,114,115,105,111,110,115,0,118,114,109,108,102,108,97,103,0,103,97,109,101,102,108,97,103, +115,0,119,104,101,101,108,108,105,110,101,115,99,114,111,108,108,0,117,105,102,108,97,103,0,108,97,110,103,117,97,103, +101,0,117,115,101,114,112,114,101,102,0,118,105,101,119,122,111,111,109,0,99,111,110,115,111,108,101,95,98,117,102,102, +101,114,0,99,111,110,115,111,108,101,95,111,117,116,0,109,105,120,98,117,102,115,105,122,101,0,102,111,110,116,115,105, +122,101,0,101,110,99,111,100,105,110,103,0,116,114,97,110,115,111,112,116,115,0,109,101,110,117,116,104,114,101,115,104, +111,108,100,49,0,109,101,110,117,116,104,114,101,115,104,111,108,100,50,0,102,111,110,116,110,97,109,101,91,50,53,54, +93,0,116,104,101,109,101,115,0,117,110,100,111,115,116,101,112,115,0,117,110,100,111,109,101,109,111,114,121,0,103,112, +95,109,97,110,104,97,116,116,101,110,100,105,115,116,0,103,112,95,101,117,99,108,105,100,101,97,110,100,105,115,116,0, +103,112,95,101,114,97,115,101,114,0,103,112,95,115,101,116,116,105,110,103,115,0,116,98,95,108,101,102,116,109,111,117, +115,101,0,116,98,95,114,105,103,104,116,109,111,117,115,101,0,108,105,103,104,116,91,51,93,0,116,119,95,104,111,116, +115,112,111,116,0,116,119,95,102,108,97,103,0,116,119,95,104,97,110,100,108,101,115,105,122,101,0,116,119,95,115,105, +122,101,0,116,101,120,116,105,109,101,111,117,116,0,116,101,120,99,111,108,108,101,99,116,114,97,116,101,0,109,101,109, +99,97,99,104,101,108,105,109,105,116,0,112,114,101,102,101,116,99,104,102,114,97,109,101,115,0,102,114,97,109,101,115, +101,114,118,101,114,112,111,114,116,0,112,97,100,95,114,111,116,95,97,110,103,108,101,0,111,98,99,101,110,116,101,114, +95,100,105,97,0,114,118,105,115,105,122,101,0,114,118,105,98,114,105,103,104,116,0,114,101,99,101,110,116,95,102,105, +108,101,115,0,115,109,111,111,116,104,95,118,105,101,119,116,120,0,103,108,114,101,115,108,105,109,105,116,0,110,100,111, +102,95,112,97,110,0,110,100,111,102,95,114,111,116,97,116,101,0,99,117,114,115,115,105,122,101,0,112,97,100,91,56, +93,0,118,101,114,115,101,109,97,115,116,101,114,91,49,54,48,93,0,118,101,114,115,101,117,115,101,114,91,49,54,48, +93,0,103,108,97,108,112,104,97,99,108,105,112,0,97,117,116,111,107,101,121,95,102,108,97,103,0,99,111,98,97,95, +119,101,105,103,104,116,0,118,101,114,116,98,97,115,101,0,101,100,103,101,98,97,115,101,0,97,114,101,97,98,97,115, +101,0,42,115,99,101,110,101,0,101,110,100,120,0,101,110,100,121,0,115,105,122,101,120,0,115,105,122,101,121,0,115, +99,101,110,101,110,114,0,115,99,114,101,101,110,110,114,0,102,117,108,108,0,109,97,105,110,119,105,110,0,119,105,110, +97,107,116,0,104,97,110,100,108,101,114,91,56,93,0,42,110,101,119,118,0,118,101,99,0,42,118,49,0,42,118,50, +0,112,97,110,101,108,110,97,109,101,91,54,52,93,0,116,97,98,110,97,109,101,91,54,52,93,0,100,114,97,119,110, +97,109,101,91,54,52,93,0,111,102,115,120,0,111,102,115,121,0,99,111,110,116,114,111,108,0,115,110,97,112,0,111, +108,100,95,111,102,115,120,0,111,108,100,95,111,102,115,121,0,115,111,114,116,99,111,117,110,116,101,114,0,42,112,97, +110,101,108,116,97,98,0,42,118,51,0,42,118,52,0,42,102,117,108,108,0,119,105,110,109,97,116,91,52,93,91,52, +93,0,104,101,97,100,114,99,116,0,119,105,110,114,99,116,0,104,101,97,100,119,105,110,0,119,105,110,0,104,101,97, +100,101,114,116,121,112,101,0,98,117,116,115,112,97,99,101,116,121,112,101,0,119,105,110,120,0,119,105,110,121,0,104, +101,97,100,95,115,119,97,112,0,104,101,97,100,95,101,113,117,97,108,0,119,105,110,95,115,119,97,112,0,119,105,110, +95,101,113,117,97,108,0,104,101,97,100,98,117,116,108,101,110,0,104,101,97,100,98,117,116,111,102,115,0,99,117,114, +115,111,114,0,115,112,97,99,101,100,97,116,97,0,117,105,98,108,111,99,107,115,0,112,97,110,101,108,115,0,115,117, +98,118,115,116,114,91,52,93,0,115,117,98,118,101,114,115,105,111,110,0,112,97,100,115,0,109,105,110,118,101,114,115, +105,111,110,0,109,105,110,115,117,98,118,101,114,115,105,111,110,0,100,105,115,112,108,97,121,109,111,100,101,0,42,99, +117,114,115,99,114,101,101,110,0,42,99,117,114,115,99,101,110,101,0,102,105,108,101,102,108,97,103,115,0,103,108,111, +98,97,108,102,0,110,97,109,101,91,56,48,93,0,42,105,98,117,102,0,42,105,98,117,102,95,99,111,109,112,0,42, +115,101,49,0,42,115,101,50,0,42,115,101,51,0,110,114,0,98,111,116,116,111,109,0,114,105,103,104,116,0,120,111, +102,115,0,121,111,102,115,0,108,105,102,116,91,51,93,0,103,97,109,109,97,91,51,93,0,103,97,105,110,91,51,93, +0,115,97,116,117,114,97,116,105,111,110,0,42,103,117,105,0,100,105,114,91,49,54,48,93,0,100,111,110,101,0,115, +116,97,114,116,115,116,105,108,108,0,101,110,100,115,116,105,108,108,0,42,115,116,114,105,112,100,97,116,97,0,111,114, +120,0,111,114,121,0,42,99,114,111,112,0,42,116,114,97,110,115,102,111,114,109,0,42,99,111,108,111,114,95,98,97, +108,97,110,99,101,0,42,116,115,116,114,105,112,100,97,116,97,0,42,116,115,116,114,105,112,100,97,116,97,95,115,116, +97,114,116,115,116,105,108,108,0,42,116,115,116,114,105,112,100,97,116,97,95,101,110,100,115,116,105,108,108,0,42,105, +98,117,102,95,115,116,97,114,116,115,116,105,108,108,0,42,105,98,117,102,95,101,110,100,115,116,105,108,108,0,42,105, +110,115,116,97,110,99,101,95,112,114,105,118,97,116,101,95,100,97,116,97,0,42,42,99,117,114,114,101,110,116,95,112, +114,105,118,97,116,101,95,100,97,116,97,0,42,116,109,112,0,115,116,97,114,116,111,102,115,0,101,110,100,111,102,115, +0,109,97,99,104,105,110,101,0,115,116,97,114,116,100,105,115,112,0,101,110,100,100,105,115,112,0,109,117,108,0,104, +97,110,100,115,105,122,101,0,97,110,105,109,95,112,114,101,115,101,101,107,0,42,115,116,114,105,112,0,102,97,99,102, +48,0,102,97,99,102,49,0,42,115,101,113,49,0,42,115,101,113,50,0,42,115,101,113,51,0,115,101,113,98,97,115, +101,0,42,115,111,117,110,100,0,42,104,100,97,117,100,105,111,0,108,101,118,101,108,0,112,97,110,0,115,116,114,111, +98,101,0,42,101,102,102,101,99,116,100,97,116,97,0,97,110,105,109,95,115,116,97,114,116,111,102,115,0,97,110,105, +109,95,101,110,100,111,102,115,0,98,108,101,110,100,95,109,111,100,101,0,98,108,101,110,100,95,111,112,97,99,105,116, +121,0,42,111,108,100,98,97,115,101,112,0,42,112,97,114,115,101,113,0,42,115,101,113,98,97,115,101,112,0,109,101, +116,97,115,116,97,99,107,0,101,100,103,101,87,105,100,116,104,0,102,111,114,119,97,114,100,0,119,105,112,101,116,121, +112,101,0,102,77,105,110,105,0,102,67,108,97,109,112,0,102,66,111,111,115,116,0,100,68,105,115,116,0,100,81,117, +97,108,105,116,121,0,98,78,111,67,111,109,112,0,83,99,97,108,101,120,73,110,105,0,83,99,97,108,101,121,73,110, +105,0,83,99,97,108,101,120,70,105,110,0,83,99,97,108,101,121,70,105,110,0,120,73,110,105,0,120,70,105,110,0, +121,73,110,105,0,121,70,105,110,0,114,111,116,73,110,105,0,114,111,116,70,105,110,0,105,110,116,101,114,112,111,108, +97,116,105,111,110,0,42,102,114,97,109,101,77,97,112,0,103,108,111,98,97,108,83,112,101,101,100,0,108,97,115,116, +86,97,108,105,100,70,114,97,109,101,0,98,108,101,110,100,70,114,97,109,101,115,0,98,117,116,116,121,112,101,0,117, +115,101,114,106,105,116,0,115,116,97,0,116,111,116,112,97,114,116,0,110,111,114,109,102,97,99,0,111,98,102,97,99, +0,114,97,110,100,102,97,99,0,116,101,120,102,97,99,0,114,97,110,100,108,105,102,101,0,102,111,114,99,101,91,51, +93,0,118,101,99,116,115,105,122,101,0,109,97,120,108,101,110,0,100,101,102,118,101,99,91,51,93,0,109,117,108,116, +91,52,93,0,108,105,102,101,91,52,93,0,99,104,105,108,100,91,52,93,0,109,97,116,91,52,93,0,116,101,120,109, +97,112,0,99,117,114,109,117,108,116,0,115,116,97,116,105,99,115,116,101,112,0,111,109,97,116,0,116,105,109,101,116, +101,120,0,115,112,101,101,100,116,101,120,0,102,108,97,103,50,110,101,103,0,118,101,114,116,103,114,111,117,112,95,118, +0,118,103,114,111,117,112,110,97,109,101,91,51,50,93,0,118,103,114,111,117,112,110,97,109,101,95,118,91,51,50,93, +0,42,107,101,121,115,0,109,105,110,102,97,99,0,117,115,101,100,0,117,115,101,100,101,108,101,109,0,100,120,0,100, +121,0,108,105,110,107,0,111,116,121,112,101,0,111,108,100,0,42,112,111,105,110,0,42,111,108,100,112,111,105,110,0, +114,101,115,101,116,100,105,115,116,0,108,97,115,116,118,97,108,0,42,109,97,0,107,101,121,0,113,117,97,108,0,113, +117,97,108,50,0,116,97,114,103,101,116,78,97,109,101,91,51,50,93,0,116,111,103,103,108,101,78,97,109,101,91,51, +50,93,0,118,97,108,117,101,91,51,50,93,0,109,97,120,118,97,108,117,101,91,51,50,93,0,100,101,108,97,121,0, +100,117,114,97,116,105,111,110,0,109,97,116,101,114,105,97,108,78,97,109,101,91,51,50,93,0,100,97,109,112,116,105, +109,101,114,0,112,114,111,112,110,97,109,101,91,51,50,93,0,109,97,116,110,97,109,101,91,51,50,93,0,97,120,105, +115,102,108,97,103,0,42,102,114,111,109,79,98,106,101,99,116,0,115,117,98,106,101,99,116,91,51,50,93,0,98,111, +100,121,91,51,50,93,0,112,117,108,115,101,0,102,114,101,113,0,116,111,116,108,105,110,107,115,0,42,42,108,105,110, +107,115,0,116,97,112,0,106,111,121,105,110,100,101,120,0,97,120,105,115,95,115,105,110,103,108,101,0,97,120,105,115, +102,0,98,117,116,116,111,110,0,104,97,116,0,104,97,116,102,0,112,114,101,99,105,115,105,111,110,0,115,116,114,91, +49,50,56,93,0,109,111,100,117,108,101,91,54,52,93,0,42,109,121,110,101,119,0,105,110,112,117,116,115,0,116,111, +116,115,108,105,110,107,115,0,42,42,115,108,105,110,107,115,0,118,97,108,111,0,115,116,97,116,101,95,109,97,115,107, +0,42,97,99,116,0,102,114,97,109,101,80,114,111,112,91,51,50,93,0,98,108,101,110,100,105,110,0,112,114,105,111, +114,105,116,121,0,101,110,100,95,114,101,115,101,116,0,115,116,114,105,100,101,97,120,105,115,0,115,116,114,105,100,101, +108,101,110,103,116,104,0,115,110,100,110,114,0,112,97,100,49,91,50,93,0,109,97,107,101,99,111,112,121,0,99,111, +112,121,109,97,100,101,0,112,97,100,50,91,49,93,0,116,114,97,99,107,0,42,109,101,0,108,105,110,86,101,108,111, +99,105,116,121,91,51,93,0,97,110,103,86,101,108,111,99,105,116,121,91,51,93,0,108,111,99,97,108,102,108,97,103, +0,100,121,110,95,111,112,101,114,97,116,105,111,110,0,102,111,114,99,101,108,111,99,91,51,93,0,102,111,114,99,101, +114,111,116,91,51,93,0,108,105,110,101,97,114,118,101,108,111,99,105,116,121,91,51,93,0,97,110,103,117,108,97,114, +118,101,108,111,99,105,116,121,91,51,93,0,42,114,101,102,101,114,101,110,99,101,0,98,117,116,115,116,97,0,98,117, +116,101,110,100,0,109,105,110,0,109,97,120,0,118,105,115,105,102,97,99,0,114,111,116,100,97,109,112,0,109,105,110, +108,111,99,91,51,93,0,109,97,120,108,111,99,91,51,93,0,109,105,110,114,111,116,91,51,93,0,109,97,120,114,111, +116,91,51,93,0,109,97,116,112,114,111,112,91,51,50,93,0,100,105,115,116,114,105,98,117,116,105,111,110,0,105,110, +116,95,97,114,103,95,49,0,105,110,116,95,97,114,103,95,50,0,102,108,111,97,116,95,97,114,103,95,49,0,102,108, +111,97,116,95,97,114,103,95,50,0,116,111,80,114,111,112,78,97,109,101,91,51,50,93,0,42,116,111,79,98,106,101, +99,116,0,98,111,100,121,84,121,112,101,0,102,105,108,101,110,97,109,101,91,54,52,93,0,108,111,97,100,97,110,105, +110,97,109,101,91,54,52,93,0,105,110,116,95,97,114,103,0,102,108,111,97,116,95,97,114,103,0,103,111,0,97,99, +99,101,108,108,101,114,97,116,105,111,110,0,109,97,120,115,112,101,101,100,0,109,97,120,114,111,116,115,112,101,101,100, +0,109,97,120,116,105,108,116,115,112,101,101,100,0,116,105,108,116,100,97,109,112,0,115,112,101,101,100,100,97,109,112, +0,42,115,97,109,112,108,101,0,42,115,116,114,101,97,109,0,42,110,101,119,112,97,99,107,101,100,102,105,108,101,0, +42,115,110,100,95,115,111,117,110,100,0,112,97,110,110,105,110,103,0,97,116,116,101,110,117,97,116,105,111,110,0,112, +105,116,99,104,0,109,105,110,95,103,97,105,110,0,109,97,120,95,103,97,105,110,0,100,105,115,116,97,110,99,101,0, +115,116,114,101,97,109,108,101,110,0,99,104,97,110,110,101,108,115,0,104,105,103,104,112,114,105,111,0,112,97,100,91, +49,48,93,0,103,97,105,110,0,100,111,112,112,108,101,114,102,97,99,116,111,114,0,100,111,112,112,108,101,114,118,101, +108,111,99,105,116,121,0,110,117,109,115,111,117,110,100,115,98,108,101,110,100,101,114,0,110,117,109,115,111,117,110,100, +115,103,97,109,101,101,110,103,105,110,101,0,42,108,97,109,112,114,101,110,0,103,111,98,106,101,99,116,0,100,117,112, +108,105,95,111,102,115,91,51,93,0,99,104,105,108,100,98,97,115,101,0,114,111,108,108,0,104,101,97,100,91,51,93, +0,116,97,105,108,91,51,93,0,98,111,110,101,95,109,97,116,91,51,93,91,51,93,0,97,114,109,95,104,101,97,100, +91,51,93,0,97,114,109,95,116,97,105,108,91,51,93,0,97,114,109,95,109,97,116,91,52,93,91,52,93,0,120,119, +105,100,116,104,0,122,119,105,100,116,104,0,101,97,115,101,49,0,101,97,115,101,50,0,114,97,100,95,104,101,97,100, +0,114,97,100,95,116,97,105,108,0,98,111,110,101,98,97,115,101,0,99,104,97,105,110,98,97,115,101,0,112,97,116, +104,102,108,97,103,0,108,97,121,101,114,95,112,114,111,116,101,99,116,101,100,0,103,104,111,115,116,101,112,0,103,104, +111,115,116,115,105,122,101,0,103,104,111,115,116,116,121,112,101,0,112,97,116,104,115,105,122,101,0,103,104,111,115,116, +115,102,0,103,104,111,115,116,101,102,0,112,97,116,104,115,102,0,112,97,116,104,101,102,0,112,97,116,104,98,99,0, +112,97,116,104,97,99,0,99,111,110,115,116,102,108,97,103,0,105,107,102,108,97,103,0,115,101,108,101,99,116,102,108, +97,103,0,97,103,114,112,95,105,110,100,101,120,0,42,98,111,110,101,0,42,99,104,105,108,100,0,105,107,116,114,101, +101,0,42,98,95,98,111,110,101,95,109,97,116,115,0,42,100,117,97,108,95,113,117,97,116,0,42,98,95,98,111,110, +101,95,100,117,97,108,95,113,117,97,116,115,0,99,104,97,110,95,109,97,116,91,52,93,91,52,93,0,112,111,115,101, +95,109,97,116,91,52,93,91,52,93,0,112,111,115,101,95,104,101,97,100,91,51,93,0,112,111,115,101,95,116,97,105, +108,91,51,93,0,108,105,109,105,116,109,105,110,91,51,93,0,108,105,109,105,116,109,97,120,91,51,93,0,115,116,105, +102,102,110,101,115,115,91,51,93,0,105,107,115,116,114,101,116,99,104,0,42,99,117,115,116,111,109,0,99,104,97,110, +98,97,115,101,0,112,114,111,120,121,95,108,97,121,101,114,0,115,116,114,105,100,101,95,111,102,102,115,101,116,91,51, +93,0,99,121,99,108,105,99,95,111,102,102,115,101,116,91,51,93,0,97,103,114,111,117,112,115,0,97,99,116,105,118, +101,95,103,114,111,117,112,0,99,117,115,116,111,109,67,111,108,0,99,115,0,42,103,114,112,0,114,101,115,101,114,118, +101,100,49,0,103,114,111,117,112,115,0,97,99,116,105,118,101,95,109,97,114,107,101,114,0,97,99,116,110,114,0,97, +99,116,119,105,100,116,104,0,116,105,109,101,115,108,105,100,101,0,110,97,109,101,91,51,48,93,0,111,119,110,115,112, +97,99,101,0,116,97,114,115,112,97,99,101,0,101,110,102,111,114,99,101,0,104,101,97,100,116,97,105,108,0,42,116, +97,114,0,115,117,98,116,97,114,103,101,116,91,51,50,93,0,109,97,116,114,105,120,91,52,93,91,52,93,0,115,112, +97,99,101,0,42,112,114,111,112,0,116,97,114,110,117,109,0,116,97,114,103,101,116,115,0,105,116,101,114,97,116,105, +111,110,115,0,114,111,111,116,98,111,110,101,0,109,97,120,95,114,111,111,116,98,111,110,101,0,42,112,111,108,101,116, +97,114,0,112,111,108,101,115,117,98,116,97,114,103,101,116,91,51,50,93,0,112,111,108,101,97,110,103,108,101,0,111, +114,105,101,110,116,119,101,105,103,104,116,0,103,114,97,98,116,97,114,103,101,116,91,51,93,0,114,101,115,101,114,118, +101,100,50,0,109,105,110,109,97,120,102,108,97,103,0,115,116,117,99,107,0,99,97,99,104,101,91,51,93,0,108,111, +99,107,102,108,97,103,0,102,111,108,108,111,119,102,108,97,103,0,118,111,108,109,111,100,101,0,112,108,97,110,101,0, +111,114,103,108,101,110,103,116,104,0,98,117,108,103,101,0,112,105,118,88,0,112,105,118,89,0,112,105,118,90,0,97, +120,88,0,97,120,89,0,97,120,90,0,109,105,110,76,105,109,105,116,91,54,93,0,109,97,120,76,105,109,105,116,91, +54,93,0,101,120,116,114,97,70,122,0,105,110,118,109,97,116,91,52,93,91,52,93,0,102,114,111,109,0,116,111,0, +109,97,112,91,51,93,0,101,120,112,111,0,102,114,111,109,95,109,105,110,91,51,93,0,102,114,111,109,95,109,97,120, +91,51,93,0,116,111,95,109,105,110,91,51,93,0,116,111,95,109,97,120,91,51,93,0,122,109,105,110,0,122,109,97, +120,0,112,97,100,91,57,93,0,99,104,97,110,110,101,108,91,51,50,93,0,110,111,95,114,111,116,95,97,120,105,115, +0,115,116,114,105,100,101,95,97,120,105,115,0,99,117,114,109,111,100,0,97,99,116,115,116,97,114,116,0,97,99,116, +101,110,100,0,97,99,116,111,102,102,115,0,115,116,114,105,100,101,108,101,110,0,98,108,101,110,100,111,117,116,0,115, +116,114,105,100,101,99,104,97,110,110,101,108,91,51,50,93,0,111,102,102,115,95,98,111,110,101,91,51,50,93,0,104, +97,115,105,110,112,117,116,0,104,97,115,111,117,116,112,117,116,0,100,97,116,97,116,121,112,101,0,115,111,99,107,101, +116,116,121,112,101,0,42,110,101,119,95,115,111,99,107,0,110,115,0,108,105,109,105,116,0,115,116,97,99,107,95,105, +110,100,101,120,0,105,110,116,101,114,110,0,115,116,97,99,107,95,105,110,100,101,120,95,101,120,116,0,108,111,99,120, +0,108,111,99,121,0,111,119,110,95,105,110,100,101,120,0,116,111,95,105,110,100,101,120,0,42,116,111,115,111,99,107, +0,42,108,105,110,107,0,42,110,101,119,95,110,111,100,101,0,117,115,101,114,110,97,109,101,91,51,50,93,0,108,97, +115,116,121,0,111,117,116,112,117,116,115,0,42,115,116,111,114,97,103,101,0,109,105,110,105,119,105,100,116,104,0,99, +117,115,116,111,109,49,0,99,117,115,116,111,109,50,0,99,117,115,116,111,109,51,0,99,117,115,116,111,109,52,0,110, +101,101,100,95,101,120,101,99,0,101,120,101,99,0,116,111,116,114,0,98,117,116,114,0,112,114,118,114,0,42,116,121, +112,101,105,110,102,111,0,42,102,114,111,109,110,111,100,101,0,42,116,111,110,111,100,101,0,42,102,114,111,109,115,111, +99,107,0,110,111,100,101,115,0,108,105,110,107,115,0,42,115,116,97,99,107,0,42,116,104,114,101,97,100,115,116,97, +99,107,0,105,110,105,116,0,115,116,97,99,107,115,105,122,101,0,99,117,114,95,105,110,100,101,120,0,97,108,108,116, +121,112,101,115,0,42,111,119,110,116,121,112,101,0,42,115,101,108,105,110,0,42,115,101,108,111,117,116,0,40,42,116, +105,109,101,99,117,114,115,111,114,41,40,41,0,40,42,115,116,97,116,115,95,100,114,97,119,41,40,41,0,40,42,116, +101,115,116,95,98,114,101,97,107,41,40,41,0,99,121,99,108,105,99,0,109,111,118,105,101,0,115,97,109,112,108,101, +115,0,109,105,110,115,112,101,101,100,0,112,101,114,99,101,110,116,120,0,112,101,114,99,101,110,116,121,0,98,111,107, +101,104,0,99,117,114,118,101,100,0,105,109,97,103,101,95,105,110,95,119,105,100,116,104,0,105,109,97,103,101,95,105, +110,95,104,101,105,103,104,116,0,99,101,110,116,101,114,95,120,0,99,101,110,116,101,114,95,121,0,115,112,105,110,0, +105,116,101,114,0,119,114,97,112,0,115,105,103,109,97,95,99,111,108,111,114,0,115,105,103,109,97,95,115,112,97,99, +101,0,104,117,101,0,115,97,116,0,116,49,0,116,50,0,116,51,0,102,115,116,114,101,110,103,116,104,0,102,97,108, +112,104,97,0,107,101,121,91,52,93,0,120,49,0,120,50,0,121,49,0,121,50,0,99,111,108,110,97,109,101,91,51, +50,93,0,98,107,116,121,112,101,0,114,111,116,97,116,105,111,110,0,112,114,101,118,105,101,119,0,103,97,109,99,111, +0,110,111,95,122,98,117,102,0,102,115,116,111,112,0,109,97,120,98,108,117,114,0,98,116,104,114,101,115,104,0,42, +100,105,99,116,0,42,110,111,100,101,0,97,110,103,108,101,95,111,102,115,0,99,111,108,109,111,100,0,109,105,120,0, +116,104,114,101,115,104,111,108,100,0,102,97,100,101,0,109,0,99,0,106,105,116,0,112,114,111,106,0,102,105,116,0, +115,104,111,114,116,121,0,109,105,110,116,97,98,108,101,0,109,97,120,116,97,98,108,101,0,101,120,116,95,105,110,91, +50,93,0,101,120,116,95,111,117,116,91,50,93,0,42,99,117,114,118,101,0,42,116,97,98,108,101,0,42,112,114,101, +109,117,108,116,97,98,108,101,0,99,117,114,114,0,99,108,105,112,114,0,99,109,91,52,93,0,98,108,97,99,107,91, +51,93,0,119,104,105,116,101,91,51,93,0,98,119,109,117,108,91,51,93,0,115,97,109,112,108,101,91,51,93,0,111, +102,102,115,101,116,91,50,93,0,105,110,110,101,114,114,97,100,105,117,115,0,114,97,116,101,0,114,103,98,91,51,93, +0,99,108,111,110,101,0,97,99,116,105,118,101,95,114,110,100,0,97,99,116,105,118,101,95,99,108,111,110,101,0,97, +99,116,105,118,101,95,109,97,115,107,0,42,108,97,121,101,114,115,0,116,111,116,108,97,121,101,114,0,109,97,120,108, +97,121,101,114,0,116,111,116,115,105,122,101,0,42,112,111,111,108,0,101,100,105,116,102,108,97,103,0,118,101,108,91, +51,93,0,114,111,116,91,52,93,0,97,118,101,91,51,93,0,110,117,109,0,112,97,114,101,110,116,0,112,97,91,52, +93,0,119,91,52,93,0,102,117,118,91,52,93,0,102,111,102,102,115,101,116,0,114,97,110,100,91,51,93,0,42,115, +116,105,99,107,95,111,98,0,112,114,101,118,95,115,116,97,116,101,0,42,104,97,105,114,0,105,95,114,111,116,91,52, +93,0,114,95,114,111,116,91,52,93,0,114,95,97,118,101,91,51,93,0,114,95,118,101,91,51,93,0,100,105,101,116, +105,109,101,0,98,97,110,107,0,115,105,122,101,109,117,108,0,110,117,109,95,100,109,99,97,99,104,101,0,98,112,105, +0,97,108,105,118,101,0,108,111,111,112,0,100,105,115,116,114,0,112,104,121,115,116,121,112,101,0,114,111,116,109,111, +100,101,0,97,118,101,109,111,100,101,0,114,101,97,99,116,101,118,101,110,116,0,100,114,97,119,0,100,114,97,119,95, +97,115,0,100,114,97,119,95,115,105,122,101,0,99,104,105,108,100,116,121,112,101,0,100,114,97,119,95,115,116,101,112, +0,114,101,110,95,115,116,101,112,0,104,97,105,114,95,115,116,101,112,0,107,101,121,115,95,115,116,101,112,0,97,100, +97,112,116,95,97,110,103,108,101,0,97,100,97,112,116,95,112,105,120,0,114,111,116,102,114,111,109,0,105,110,116,101, +103,114,97,116,111,114,0,110,98,101,116,119,101,101,110,0,98,111,105,100,110,101,105,103,104,98,111,117,114,115,0,98, +98,95,97,108,105,103,110,0,98,98,95,117,118,95,115,112,108,105,116,0,98,98,95,97,110,105,109,0,98,98,95,115, +112,108,105,116,95,111,102,102,115,101,116,0,98,98,95,116,105,108,116,0,98,98,95,114,97,110,100,95,116,105,108,116, +0,98,98,95,111,102,102,115,101,116,91,50,93,0,115,105,109,112,108,105,102,121,95,102,108,97,103,0,115,105,109,112, +108,105,102,121,95,114,101,102,115,105,122,101,0,115,105,109,112,108,105,102,121,95,114,97,116,101,0,115,105,109,112,108, +105,102,121,95,116,114,97,110,115,105,116,105,111,110,0,115,105,109,112,108,105,102,121,95,118,105,101,119,112,111,114,116, +0,116,105,109,101,116,119,101,97,107,0,106,105,116,102,97,99,0,107,101,121,101,100,95,116,105,109,101,0,101,102,102, +95,104,97,105,114,0,103,114,105,100,95,114,101,115,0,112,97,114,116,102,97,99,0,116,97,110,102,97,99,0,116,97, +110,112,104,97,115,101,0,114,101,97,99,116,102,97,99,0,97,118,101,102,97,99,0,112,104,97,115,101,102,97,99,0, +114,97,110,100,114,111,116,102,97,99,0,114,97,110,100,112,104,97,115,101,102,97,99,0,114,97,110,100,115,105,122,101, +0,114,101,97,99,116,115,104,97,112,101,0,97,99,99,91,51,93,0,100,114,97,103,102,97,99,0,98,114,111,119,110, +102,97,99,0,100,97,109,112,102,97,99,0,97,98,115,108,101,110,103,116,104,0,114,97,110,100,108,101,110,103,116,104, +0,99,104,105,108,100,95,110,98,114,0,114,101,110,95,99,104,105,108,100,95,110,98,114,0,112,97,114,101,110,116,115, +0,99,104,105,108,100,115,105,122,101,0,99,104,105,108,100,114,97,110,100,115,105,122,101,0,99,104,105,108,100,114,97, +100,0,99,104,105,108,100,102,108,97,116,0,99,104,105,108,100,115,112,114,101,97,100,0,99,108,117,109,112,102,97,99, +0,99,108,117,109,112,112,111,119,0,114,111,117,103,104,49,0,114,111,117,103,104,49,95,115,105,122,101,0,114,111,117, +103,104,50,0,114,111,117,103,104,50,95,115,105,122,101,0,114,111,117,103,104,50,95,116,104,114,101,115,0,114,111,117, +103,104,95,101,110,100,0,114,111,117,103,104,95,101,110,100,95,115,104,97,112,101,0,98,114,97,110,99,104,95,116,104, +114,101,115,0,100,114,97,119,95,108,105,110,101,91,50,93,0,109,97,120,95,108,97,116,95,97,99,99,0,109,97,120, +95,116,97,110,95,97,99,99,0,97,118,101,114,97,103,101,95,118,101,108,0,98,97,110,107,105,110,103,0,109,97,120, +95,98,97,110,107,0,103,114,111,117,110,100,122,0,98,111,105,100,102,97,99,91,56,93,0,98,111,105,100,114,117,108, +101,91,56,93,0,42,101,102,102,95,103,114,111,117,112,0,42,100,117,112,95,111,98,0,42,98,98,95,111,98,0,42, +112,100,50,0,42,112,97,114,116,0,42,101,100,105,116,0,42,42,112,97,116,104,99,97,99,104,101,0,42,42,99,104, +105,108,100,99,97,99,104,101,0,112,97,116,104,99,97,99,104,101,98,117,102,115,0,99,104,105,108,100,99,97,99,104, +101,98,117,102,115,0,42,116,97,114,103,101,116,95,111,98,0,42,107,101,121,101,100,95,111,98,0,42,108,97,116,116, +105,99,101,0,101,102,102,101,99,116,111,114,115,0,114,101,97,99,116,101,118,101,110,116,115,0,116,111,116,99,104,105, +108,100,0,116,111,116,99,97,99,104,101,100,0,116,111,116,99,104,105,108,100,99,97,99,104,101,0,116,97,114,103,101, +116,95,112,115,121,115,0,107,101,121,101,100,95,112,115,121,115,0,116,111,116,107,101,121,101,100,0,98,97,107,101,115, +112,97,99,101,0,98,98,95,117,118,110,97,109,101,91,51,93,91,51,50,93,0,118,103,114,111,117,112,91,49,50,93, +0,118,103,95,110,101,103,0,114,116,51,0,42,114,101,110,100,101,114,100,97,116,97,0,42,99,97,99,104,101,0,67, +100,105,115,0,67,118,105,0,91,51,93,0,115,116,114,117,99,116,117,114,97,108,0,98,101,110,100,105,110,103,0,109, +97,120,95,98,101,110,100,0,109,97,120,95,115,116,114,117,99,116,0,109,97,120,95,115,104,101,97,114,0,97,118,103, +95,115,112,114,105,110,103,95,108,101,110,0,116,105,109,101,115,99,97,108,101,0,101,102,102,95,102,111,114,99,101,95, +115,99,97,108,101,0,101,102,102,95,119,105,110,100,95,115,99,97,108,101,0,115,105,109,95,116,105,109,101,95,111,108, +100,0,115,116,101,112,115,80,101,114,70,114,97,109,101,0,112,114,101,114,111,108,108,0,109,97,120,115,112,114,105,110, +103,108,101,110,0,115,111,108,118,101,114,95,116,121,112,101,0,118,103,114,111,117,112,95,98,101,110,100,0,118,103,114, +111,117,112,95,109,97,115,115,0,118,103,114,111,117,112,95,115,116,114,117,99,116,0,112,114,101,115,101,116,115,0,42, +99,111,108,108,105,115,105,111,110,95,108,105,115,116,0,101,112,115,105,108,111,110,0,115,101,108,102,95,102,114,105,99, +116,105,111,110,0,115,101,108,102,101,112,115,105,108,111,110,0,115,101,108,102,95,108,111,111,112,95,99,111,117,110,116, +0,108,111,111,112,95,99,111,117,110,116,0,112,114,101,115,115,117,114,101,0,42,112,111,105,110,116,115,0,116,111,116, +112,111,105,110,116,115,0,116,104,105,99,107,110,101,115,115,0,115,116,114,111,107,101,115,0,102,114,97,109,101,110,117, +109,0,42,97,99,116,102,114,97,109,101,0,103,115,116,101,112,0,105,110,102,111,91,49,50,56,93,0,115,98,117,102, +102,101,114,95,115,105,122,101,0,115,98,117,102,102,101,114,95,115,102,108,97,103,0,42,115,98,117,102,102,101,114,0, +0,0,0,84,89,80,69,100,1,0,0,99,104,97,114,0,117,99,104,97,114,0,115,104,111,114,116,0,117,115,104,111, +114,116,0,105,110,116,0,108,111,110,103,0,117,108,111,110,103,0,102,108,111,97,116,0,100,111,117,98,108,101,0,118, +111,105,100,0,76,105,110,107,0,76,105,110,107,68,97,116,97,0,76,105,115,116,66,97,115,101,0,118,101,99,50,115, +0,118,101,99,50,105,0,118,101,99,50,102,0,118,101,99,50,100,0,118,101,99,51,105,0,118,101,99,51,102,0,118, +101,99,51,100,0,118,101,99,52,105,0,118,101,99,52,102,0,118,101,99,52,100,0,114,99,116,105,0,114,99,116,102, +0,73,68,80,114,111,112,101,114,116,121,68,97,116,97,0,73,68,80,114,111,112,101,114,116,121,0,73,68,0,76,105, +98,114,97,114,121,0,70,105,108,101,68,97,116,97,0,80,114,101,118,105,101,119,73,109,97,103,101,0,73,112,111,68, +114,105,118,101,114,0,79,98,106,101,99,116,0,73,112,111,67,117,114,118,101,0,66,80,111,105,110,116,0,66,101,122, +84,114,105,112,108,101,0,73,112,111,0,75,101,121,66,108,111,99,107,0,75,101,121,0,83,99,114,105,112,116,76,105, +110,107,0,84,101,120,116,76,105,110,101,0,84,101,120,116,77,97,114,107,101,114,0,84,101,120,116,0,80,97,99,107, +101,100,70,105,108,101,0,67,97,109,101,114,97,0,73,109,97,103,101,85,115,101,114,0,73,109,97,103,101,0,71,80, +85,84,101,120,116,117,114,101,0,97,110,105,109,0,82,101,110,100,101,114,82,101,115,117,108,116,0,77,84,101,120,0, +84,101,120,0,80,108,117,103,105,110,84,101,120,0,67,66,68,97,116,97,0,67,111,108,111,114,66,97,110,100,0,69, +110,118,77,97,112,0,73,109,66,117,102,0,98,78,111,100,101,84,114,101,101,0,84,101,120,77,97,112,112,105,110,103, +0,76,97,109,112,0,67,117,114,118,101,77,97,112,112,105,110,103,0,87,97,118,101,0,77,97,116,101,114,105,97,108, +0,71,114,111,117,112,0,86,70,111,110,116,0,86,70,111,110,116,68,97,116,97,0,77,101,116,97,69,108,101,109,0, +66,111,117,110,100,66,111,120,0,77,101,116,97,66,97,108,108,0,78,117,114,98,0,67,104,97,114,73,110,102,111,0, +84,101,120,116,66,111,120,0,67,117,114,118,101,0,80,97,116,104,0,77,101,115,104,0,77,70,97,99,101,0,77,84, +70,97,99,101,0,84,70,97,99,101,0,77,86,101,114,116,0,77,69,100,103,101,0,77,68,101,102,111,114,109,86,101, +114,116,0,77,67,111,108,0,77,83,116,105,99,107,121,0,77,83,101,108,101,99,116,0,67,117,115,116,111,109,68,97, +116,97,0,77,117,108,116,105,114,101,115,0,80,97,114,116,105,97,108,86,105,115,105,98,105,108,105,116,121,0,77,68, +101,102,111,114,109,87,101,105,103,104,116,0,77,84,101,120,80,111,108,121,0,77,76,111,111,112,85,86,0,77,76,111, +111,112,67,111,108,0,77,70,108,111,97,116,80,114,111,112,101,114,116,121,0,77,73,110,116,80,114,111,112,101,114,116, +121,0,77,83,116,114,105,110,103,80,114,111,112,101,114,116,121,0,79,114,105,103,83,112,97,99,101,70,97,99,101,0, +77,117,108,116,105,114,101,115,67,111,108,0,77,117,108,116,105,114,101,115,67,111,108,70,97,99,101,0,77,117,108,116, +105,114,101,115,70,97,99,101,0,77,117,108,116,105,114,101,115,69,100,103,101,0,77,117,108,116,105,114,101,115,76,101, +118,101,108,0,77,117,108,116,105,114,101,115,77,97,112,78,111,100,101,0,77,111,100,105,102,105,101,114,68,97,116,97, +0,83,117,98,115,117,114,102,77,111,100,105,102,105,101,114,68,97,116,97,0,76,97,116,116,105,99,101,77,111,100,105, +102,105,101,114,68,97,116,97,0,67,117,114,118,101,77,111,100,105,102,105,101,114,68,97,116,97,0,66,117,105,108,100, +77,111,100,105,102,105,101,114,68,97,116,97,0,77,97,115,107,77,111,100,105,102,105,101,114,68,97,116,97,0,65,114, +114,97,121,77,111,100,105,102,105,101,114,68,97,116,97,0,77,105,114,114,111,114,77,111,100,105,102,105,101,114,68,97, +116,97,0,69,100,103,101,83,112,108,105,116,77,111,100,105,102,105,101,114,68,97,116,97,0,66,101,118,101,108,77,111, +100,105,102,105,101,114,68,97,116,97,0,66,77,101,115,104,77,111,100,105,102,105,101,114,68,97,116,97,0,68,105,115, +112,108,97,99,101,77,111,100,105,102,105,101,114,68,97,116,97,0,85,86,80,114,111,106,101,99,116,77,111,100,105,102, +105,101,114,68,97,116,97,0,68,101,99,105,109,97,116,101,77,111,100,105,102,105,101,114,68,97,116,97,0,83,109,111, +111,116,104,77,111,100,105,102,105,101,114,68,97,116,97,0,67,97,115,116,77,111,100,105,102,105,101,114,68,97,116,97, +0,87,97,118,101,77,111,100,105,102,105,101,114,68,97,116,97,0,65,114,109,97,116,117,114,101,77,111,100,105,102,105, +101,114,68,97,116,97,0,72,111,111,107,77,111,100,105,102,105,101,114,68,97,116,97,0,83,111,102,116,98,111,100,121, +77,111,100,105,102,105,101,114,68,97,116,97,0,67,108,111,116,104,77,111,100,105,102,105,101,114,68,97,116,97,0,67, +108,111,116,104,0,67,108,111,116,104,83,105,109,83,101,116,116,105,110,103,115,0,67,108,111,116,104,67,111,108,108,83, +101,116,116,105,110,103,115,0,80,111,105,110,116,67,97,99,104,101,0,67,111,108,108,105,115,105,111,110,77,111,100,105, +102,105,101,114,68,97,116,97,0,66,86,72,84,114,101,101,0,83,117,114,102,97,99,101,77,111,100,105,102,105,101,114, +68,97,116,97,0,68,101,114,105,118,101,100,77,101,115,104,0,66,86,72,84,114,101,101,70,114,111,109,77,101,115,104, +0,66,111,111,108,101,97,110,77,111,100,105,102,105,101,114,68,97,116,97,0,77,68,101,102,73,110,102,108,117,101,110, +99,101,0,77,68,101,102,67,101,108,108,0,77,101,115,104,68,101,102,111,114,109,77,111,100,105,102,105,101,114,68,97, +116,97,0,80,97,114,116,105,99,108,101,83,121,115,116,101,109,77,111,100,105,102,105,101,114,68,97,116,97,0,80,97, +114,116,105,99,108,101,83,121,115,116,101,109,0,80,97,114,116,105,99,108,101,73,110,115,116,97,110,99,101,77,111,100, +105,102,105,101,114,68,97,116,97,0,69,120,112,108,111,100,101,77,111,100,105,102,105,101,114,68,97,116,97,0,70,108, +117,105,100,115,105,109,77,111,100,105,102,105,101,114,68,97,116,97,0,70,108,117,105,100,115,105,109,83,101,116,116,105, +110,103,115,0,83,104,114,105,110,107,119,114,97,112,77,111,100,105,102,105,101,114,68,97,116,97,0,83,105,109,112,108, +101,68,101,102,111,114,109,77,111,100,105,102,105,101,114,68,97,116,97,0,76,97,116,116,105,99,101,0,98,68,101,102, +111,114,109,71,114,111,117,112,0,98,65,99,116,105,111,110,0,98,80,111,115,101,0,66,117,108,108,101,116,83,111,102, +116,66,111,100,121,0,80,97,114,116,68,101,102,108,101,99,116,0,83,111,102,116,66,111,100,121,0,79,98,72,111,111, +107,0,82,78,71,0,83,66,86,101,114,116,101,120,0,66,111,100,121,80,111,105,110,116,0,66,111,100,121,83,112,114, +105,110,103,0,83,66,83,99,114,97,116,99,104,0,87,111,114,108,100,0,82,97,100,105,111,0,66,97,115,101,0,65, +118,105,67,111,100,101,99,68,97,116,97,0,81,117,105,99,107,116,105,109,101,67,111,100,101,99,68,97,116,97,0,70, +70,77,112,101,103,67,111,100,101,99,68,97,116,97,0,65,117,100,105,111,68,97,116,97,0,83,99,101,110,101,82,101, +110,100,101,114,76,97,121,101,114,0,82,101,110,100,101,114,68,97,116,97,0,82,101,110,100,101,114,80,114,111,102,105, +108,101,0,71,97,109,101,70,114,97,109,105,110,103,0,84,105,109,101,77,97,114,107,101,114,0,73,109,97,103,101,80, +97,105,110,116,83,101,116,116,105,110,103,115,0,66,114,117,115,104,0,80,97,114,116,105,99,108,101,66,114,117,115,104, +68,97,116,97,0,80,97,114,116,105,99,108,101,69,100,105,116,83,101,116,116,105,110,103,115,0,84,114,97,110,115,102, +111,114,109,79,114,105,101,110,116,97,116,105,111,110,0,84,111,111,108,83,101,116,116,105,110,103,115,0,66,114,117,115, +104,68,97,116,97,0,83,99,117,108,112,116,68,97,116,97,0,83,99,117,108,112,116,83,101,115,115,105,111,110,0,83, +99,101,110,101,0,68,97,103,70,111,114,101,115,116,0,66,71,112,105,99,0,86,105,101,119,51,68,0,83,112,97,99, +101,76,105,110,107,0,83,99,114,65,114,101,97,0,82,101,110,100,101,114,73,110,102,111,0,82,101,116,111,112,111,86, +105,101,119,68,97,116,97,0,86,105,101,119,68,101,112,116,104,115,0,98,71,80,100,97,116,97,0,86,105,101,119,50, +68,0,83,112,97,99,101,73,110,102,111,0,83,112,97,99,101,73,112,111,0,83,112,97,99,101,66,117,116,115,0,83, +112,97,99,101,83,101,113,0,83,112,97,99,101,70,105,108,101,0,100,105,114,101,110,116,114,121,0,66,108,101,110,100, +72,97,110,100,108,101,0,83,112,97,99,101,79,111,112,115,0,84,114,101,101,83,116,111,114,101,0,84,114,101,101,83, +116,111,114,101,69,108,101,109,0,83,112,97,99,101,73,109,97,103,101,0,83,112,97,99,101,78,108,97,0,83,112,97, +99,101,84,101,120,116,0,83,99,114,105,112,116,0,83,112,97,99,101,83,99,114,105,112,116,0,83,112,97,99,101,84, +105,109,101,0,83,112,97,99,101,78,111,100,101,0,83,112,97,99,101,73,109,97,83,101,108,0,70,105,108,101,76,105, +115,116,0,84,104,101,109,101,85,73,0,84,104,101,109,101,83,112,97,99,101,0,84,104,101,109,101,87,105,114,101,67, +111,108,111,114,0,98,84,104,101,109,101,0,83,111,108,105,100,76,105,103,104,116,0,85,115,101,114,68,101,102,0,98, +83,99,114,101,101,110,0,83,99,114,86,101,114,116,0,83,99,114,69,100,103,101,0,80,97,110,101,108,0,70,105,108, +101,71,108,111,98,97,108,0,83,116,114,105,112,69,108,101,109,0,84,83,116,114,105,112,69,108,101,109,0,83,116,114, +105,112,67,114,111,112,0,83,116,114,105,112,84,114,97,110,115,102,111,114,109,0,83,116,114,105,112,67,111,108,111,114, +66,97,108,97,110,99,101,0,83,116,114,105,112,67,111,108,111,114,66,97,108,97,110,99,101,71,85,73,72,101,108,112, +101,114,0,83,116,114,105,112,80,114,111,120,121,0,83,116,114,105,112,0,80,108,117,103,105,110,83,101,113,0,83,101, +113,117,101,110,99,101,0,98,83,111,117,110,100,0,104,100,97,117,100,105,111,0,77,101,116,97,83,116,97,99,107,0, +69,100,105,116,105,110,103,0,87,105,112,101,86,97,114,115,0,71,108,111,119,86,97,114,115,0,84,114,97,110,115,102, +111,114,109,86,97,114,115,0,83,111,108,105,100,67,111,108,111,114,86,97,114,115,0,83,112,101,101,100,67,111,110,116, +114,111,108,86,97,114,115,0,69,102,102,101,99,116,0,66,117,105,108,100,69,102,102,0,80,97,114,116,69,102,102,0, +80,97,114,116,105,99,108,101,0,87,97,118,101,69,102,102,0,79,111,112,115,0,98,80,114,111,112,101,114,116,121,0, +98,78,101,97,114,83,101,110,115,111,114,0,98,77,111,117,115,101,83,101,110,115,111,114,0,98,84,111,117,99,104,83, +101,110,115,111,114,0,98,75,101,121,98,111,97,114,100,83,101,110,115,111,114,0,98,80,114,111,112,101,114,116,121,83, +101,110,115,111,114,0,98,65,99,116,117,97,116,111,114,83,101,110,115,111,114,0,98,68,101,108,97,121,83,101,110,115, +111,114,0,98,67,111,108,108,105,115,105,111,110,83,101,110,115,111,114,0,98,82,97,100,97,114,83,101,110,115,111,114, +0,98,82,97,110,100,111,109,83,101,110,115,111,114,0,98,82,97,121,83,101,110,115,111,114,0,98,77,101,115,115,97, +103,101,83,101,110,115,111,114,0,98,83,101,110,115,111,114,0,98,67,111,110,116,114,111,108,108,101,114,0,98,74,111, +121,115,116,105,99,107,83,101,110,115,111,114,0,98,69,120,112,114,101,115,115,105,111,110,67,111,110,116,0,98,80,121, +116,104,111,110,67,111,110,116,0,98,65,99,116,117,97,116,111,114,0,98,65,100,100,79,98,106,101,99,116,65,99,116, +117,97,116,111,114,0,98,65,99,116,105,111,110,65,99,116,117,97,116,111,114,0,98,83,111,117,110,100,65,99,116,117, +97,116,111,114,0,98,67,68,65,99,116,117,97,116,111,114,0,98,69,100,105,116,79,98,106,101,99,116,65,99,116,117, +97,116,111,114,0,98,83,99,101,110,101,65,99,116,117,97,116,111,114,0,98,80,114,111,112,101,114,116,121,65,99,116, +117,97,116,111,114,0,98,79,98,106,101,99,116,65,99,116,117,97,116,111,114,0,98,73,112,111,65,99,116,117,97,116, +111,114,0,98,67,97,109,101,114,97,65,99,116,117,97,116,111,114,0,98,67,111,110,115,116,114,97,105,110,116,65,99, +116,117,97,116,111,114,0,98,71,114,111,117,112,65,99,116,117,97,116,111,114,0,98,82,97,110,100,111,109,65,99,116, +117,97,116,111,114,0,98,77,101,115,115,97,103,101,65,99,116,117,97,116,111,114,0,98,71,97,109,101,65,99,116,117, +97,116,111,114,0,98,86,105,115,105,98,105,108,105,116,121,65,99,116,117,97,116,111,114,0,98,84,119,111,68,70,105, +108,116,101,114,65,99,116,117,97,116,111,114,0,98,80,97,114,101,110,116,65,99,116,117,97,116,111,114,0,98,83,116, +97,116,101,65,99,116,117,97,116,111,114,0,70,114,101,101,67,97,109,101,114,97,0,98,83,97,109,112,108,101,0,98, +83,111,117,110,100,76,105,115,116,101,110,101,114,0,83,112,97,99,101,83,111,117,110,100,0,71,114,111,117,112,79,98, +106,101,99,116,0,66,111,110,101,0,98,65,114,109,97,116,117,114,101,0,98,80,111,115,101,67,104,97,110,110,101,108, +0,98,65,99,116,105,111,110,71,114,111,117,112,0,98,65,99,116,105,111,110,67,104,97,110,110,101,108,0,83,112,97, +99,101,65,99,116,105,111,110,0,98,67,111,110,115,116,114,97,105,110,116,67,104,97,110,110,101,108,0,98,67,111,110, +115,116,114,97,105,110,116,0,98,67,111,110,115,116,114,97,105,110,116,84,97,114,103,101,116,0,98,80,121,116,104,111, +110,67,111,110,115,116,114,97,105,110,116,0,98,75,105,110,101,109,97,116,105,99,67,111,110,115,116,114,97,105,110,116, +0,98,84,114,97,99,107,84,111,67,111,110,115,116,114,97,105,110,116,0,98,82,111,116,97,116,101,76,105,107,101,67, +111,110,115,116,114,97,105,110,116,0,98,76,111,99,97,116,101,76,105,107,101,67,111,110,115,116,114,97,105,110,116,0, +98,77,105,110,77,97,120,67,111,110,115,116,114,97,105,110,116,0,98,83,105,122,101,76,105,107,101,67,111,110,115,116, +114,97,105,110,116,0,98,65,99,116,105,111,110,67,111,110,115,116,114,97,105,110,116,0,98,76,111,99,107,84,114,97, +99,107,67,111,110,115,116,114,97,105,110,116,0,98,70,111,108,108,111,119,80,97,116,104,67,111,110,115,116,114,97,105, +110,116,0,98,83,116,114,101,116,99,104,84,111,67,111,110,115,116,114,97,105,110,116,0,98,82,105,103,105,100,66,111, +100,121,74,111,105,110,116,67,111,110,115,116,114,97,105,110,116,0,98,67,108,97,109,112,84,111,67,111,110,115,116,114, +97,105,110,116,0,98,67,104,105,108,100,79,102,67,111,110,115,116,114,97,105,110,116,0,98,84,114,97,110,115,102,111, +114,109,67,111,110,115,116,114,97,105,110,116,0,98,76,111,99,76,105,109,105,116,67,111,110,115,116,114,97,105,110,116, +0,98,82,111,116,76,105,109,105,116,67,111,110,115,116,114,97,105,110,116,0,98,83,105,122,101,76,105,109,105,116,67, +111,110,115,116,114,97,105,110,116,0,98,68,105,115,116,76,105,109,105,116,67,111,110,115,116,114,97,105,110,116,0,98, +83,104,114,105,110,107,119,114,97,112,67,111,110,115,116,114,97,105,110,116,0,98,65,99,116,105,111,110,77,111,100,105, +102,105,101,114,0,98,65,99,116,105,111,110,83,116,114,105,112,0,98,78,111,100,101,83,116,97,99,107,0,98,78,111, +100,101,83,111,99,107,101,116,0,98,78,111,100,101,76,105,110,107,0,98,78,111,100,101,0,98,78,111,100,101,80,114, +101,118,105,101,119,0,98,78,111,100,101,84,121,112,101,0,78,111,100,101,73,109,97,103,101,65,110,105,109,0,78,111, +100,101,66,108,117,114,68,97,116,97,0,78,111,100,101,68,66,108,117,114,68,97,116,97,0,78,111,100,101,66,105,108, +97,116,101,114,97,108,66,108,117,114,68,97,116,97,0,78,111,100,101,72,117,101,83,97,116,0,78,111,100,101,73,109, +97,103,101,70,105,108,101,0,78,111,100,101,67,104,114,111,109,97,0,78,111,100,101,84,119,111,88,89,115,0,78,111, +100,101,84,119,111,70,108,111,97,116,115,0,78,111,100,101,71,101,111,109,101,116,114,121,0,78,111,100,101,86,101,114, +116,101,120,67,111,108,0,78,111,100,101,68,101,102,111,99,117,115,0,78,111,100,101,83,99,114,105,112,116,68,105,99, +116,0,78,111,100,101,71,108,97,114,101,0,78,111,100,101,84,111,110,101,109,97,112,0,78,111,100,101,76,101,110,115, +68,105,115,116,0,84,101,120,78,111,100,101,79,117,116,112,117,116,0,67,117,114,118,101,77,97,112,80,111,105,110,116, +0,67,117,114,118,101,77,97,112,0,66,114,117,115,104,67,108,111,110,101,0,67,117,115,116,111,109,68,97,116,97,76, +97,121,101,114,0,72,97,105,114,75,101,121,0,80,97,114,116,105,99,108,101,75,101,121,0,67,104,105,108,100,80,97, +114,116,105,99,108,101,0,80,97,114,116,105,99,108,101,68,97,116,97,0,80,97,114,116,105,99,108,101,83,101,116,116, +105,110,103,115,0,80,97,114,116,105,99,108,101,69,100,105,116,0,80,97,114,116,105,99,108,101,67,97,99,104,101,75, +101,121,0,76,105,110,107,78,111,100,101,0,98,71,80,68,115,112,111,105,110,116,0,98,71,80,68,115,116,114,111,107, +101,0,98,71,80,68,102,114,97,109,101,0,98,71,80,68,108,97,121,101,114,0,0,84,76,69,78,1,0,1,0,2, +0,2,0,4,0,4,0,4,0,4,0,8,0,0,0,8,0,12,0,8,0,4,0,8,0,8,0,16,0,12,0,12, +0,24,0,16,0,16,0,32,0,16,0,16,0,20,0,76,0,52,0,40,2,0,0,32,0,-116,0,80,3,92,0,36, +0,56,0,84,0,112,0,120,0,16,0,24,0,40,0,120,0,20,0,-124,0,32,0,-128,1,0,0,0,0,0,0,-120, +0,16,1,84,1,24,0,8,3,-88,0,0,0,124,0,-124,0,-128,1,8,1,56,0,108,2,76,0,68,1,0,0,108, +0,104,0,-120,0,56,0,8,0,16,0,56,1,0,0,24,1,20,0,44,0,60,0,24,0,12,0,12,0,4,0,8, +0,8,0,24,0,76,0,32,0,8,0,12,0,8,0,8,0,4,0,4,0,0,1,32,0,16,0,64,0,24,0,12, +0,56,0,0,0,52,0,68,0,88,0,96,0,68,0,96,0,116,0,64,0,60,0,108,0,60,0,-108,0,-104,0,60, +0,92,0,104,0,-72,0,100,0,-76,0,52,0,68,0,0,0,-124,0,28,0,20,0,100,0,0,0,60,0,0,0,0, +0,64,0,8,0,8,0,-40,0,76,0,64,1,64,0,64,0,60,0,-92,1,108,0,104,0,116,0,40,0,84,0,56, +0,120,0,-128,0,-8,0,-48,0,0,0,16,0,0,0,0,0,0,0,108,1,40,0,28,0,-80,0,-112,0,52,0,16, +0,72,0,-48,3,56,0,16,0,80,0,12,0,-72,0,8,0,72,0,80,0,-24,0,8,0,-88,0,0,0,124,5,0, +0,60,0,28,3,36,0,-52,0,0,0,0,0,0,0,20,0,-120,0,36,0,88,1,-36,0,-56,0,-56,1,0,0,0, +0,8,1,12,0,12,0,8,1,-76,0,-128,0,80,2,36,0,-92,0,-36,0,-124,2,0,0,-104,0,-48,0,16,0,56, +14,56,0,32,12,120,0,20,0,24,0,-28,0,32,0,80,0,28,0,16,0,8,0,60,0,0,0,-4,0,-16,0,-88, +1,-60,0,28,1,0,0,16,0,28,0,12,0,24,0,48,0,16,0,28,0,16,0,24,0,56,1,0,0,56,0,44, +0,64,0,48,0,8,0,44,0,72,0,104,0,40,0,8,0,72,0,44,0,40,0,108,0,68,0,76,0,80,0,60, +0,-128,0,76,0,60,0,12,0,92,0,28,0,20,0,80,0,16,0,76,0,108,0,84,0,28,0,96,0,60,0,56, +0,108,0,-116,0,4,0,20,0,12,0,8,0,40,0,0,0,68,0,-80,0,24,0,4,1,116,0,-104,1,72,0,64, +0,-64,0,44,0,64,0,116,0,60,0,104,0,52,0,44,0,44,0,68,0,44,0,64,0,44,0,20,0,52,0,96, +0,12,0,108,0,92,0,28,0,28,0,28,0,52,0,20,0,60,0,-116,0,36,0,120,0,24,0,-52,0,0,0,0, +0,16,0,40,0,28,0,12,0,12,0,16,1,40,0,8,0,8,0,64,0,32,0,24,0,8,0,24,0,32,0,8, +0,32,0,12,0,44,0,20,0,68,0,24,0,56,0,72,0,-4,0,-32,1,0,0,0,0,0,0,16,0,20,0,24, +0,-84,0,83,84,82,67,57,1,0,0,10,0,2,0,10,0,0,0,10,0,1,0,11,0,3,0,11,0,0,0,11, +0,1,0,9,0,2,0,12,0,2,0,9,0,3,0,9,0,4,0,13,0,2,0,2,0,5,0,2,0,6,0,14, +0,2,0,4,0,5,0,4,0,6,0,15,0,2,0,7,0,5,0,7,0,6,0,16,0,2,0,8,0,5,0,8, +0,6,0,17,0,3,0,4,0,5,0,4,0,6,0,4,0,7,0,18,0,3,0,7,0,5,0,7,0,6,0,7, +0,7,0,19,0,3,0,8,0,5,0,8,0,6,0,8,0,7,0,20,0,4,0,4,0,5,0,4,0,6,0,4, +0,7,0,4,0,8,0,21,0,4,0,7,0,5,0,7,0,6,0,7,0,7,0,7,0,8,0,22,0,4,0,8, +0,5,0,8,0,6,0,8,0,7,0,8,0,8,0,23,0,4,0,4,0,9,0,4,0,10,0,4,0,11,0,4, +0,12,0,24,0,4,0,7,0,9,0,7,0,10,0,7,0,11,0,7,0,12,0,25,0,4,0,9,0,13,0,12, +0,14,0,4,0,15,0,4,0,16,0,26,0,10,0,26,0,0,0,26,0,1,0,0,0,17,0,0,0,18,0,0, +0,19,0,2,0,20,0,4,0,21,0,25,0,22,0,4,0,23,0,4,0,24,0,27,0,9,0,9,0,0,0,9, +0,1,0,27,0,25,0,28,0,26,0,0,0,27,0,2,0,28,0,2,0,20,0,4,0,29,0,26,0,30,0,28, +0,8,0,27,0,31,0,27,0,32,0,29,0,33,0,0,0,34,0,0,0,35,0,4,0,36,0,4,0,37,0,28, +0,38,0,30,0,6,0,4,0,39,0,4,0,40,0,2,0,41,0,2,0,42,0,2,0,43,0,4,0,44,0,31, +0,6,0,32,0,45,0,2,0,46,0,2,0,47,0,2,0,18,0,2,0,20,0,0,0,48,0,33,0,21,0,33, +0,0,0,33,0,1,0,34,0,49,0,35,0,50,0,24,0,51,0,24,0,52,0,2,0,46,0,2,0,47,0,2, +0,53,0,2,0,54,0,2,0,55,0,2,0,56,0,2,0,20,0,2,0,57,0,7,0,11,0,7,0,12,0,4, +0,58,0,7,0,59,0,7,0,60,0,7,0,61,0,31,0,62,0,36,0,7,0,27,0,31,0,12,0,63,0,24, +0,64,0,2,0,46,0,2,0,65,0,2,0,66,0,2,0,37,0,37,0,16,0,37,0,0,0,37,0,1,0,7, +0,67,0,7,0,61,0,2,0,18,0,2,0,47,0,2,0,68,0,2,0,20,0,4,0,69,0,4,0,70,0,9, +0,2,0,7,0,71,0,0,0,17,0,0,0,72,0,7,0,73,0,7,0,74,0,38,0,12,0,27,0,31,0,37, +0,75,0,0,0,76,0,4,0,77,0,7,0,61,0,12,0,78,0,36,0,79,0,27,0,80,0,2,0,18,0,2, +0,81,0,2,0,82,0,2,0,20,0,39,0,5,0,27,0,83,0,2,0,84,0,2,0,85,0,2,0,86,0,4, +0,37,0,40,0,6,0,40,0,0,0,40,0,1,0,0,0,87,0,0,0,88,0,4,0,23,0,4,0,89,0,41, +0,10,0,41,0,0,0,41,0,1,0,4,0,90,0,4,0,91,0,4,0,92,0,4,0,43,0,4,0,14,0,4, +0,93,0,0,0,94,0,0,0,95,0,42,0,15,0,27,0,31,0,0,0,96,0,4,0,93,0,4,0,97,0,12, +0,98,0,40,0,99,0,40,0,100,0,4,0,101,0,4,0,102,0,12,0,103,0,0,0,104,0,4,0,105,0,4, +0,106,0,9,0,107,0,8,0,108,0,43,0,5,0,4,0,109,0,4,0,110,0,4,0,93,0,4,0,37,0,9, +0,2,0,44,0,20,0,27,0,31,0,2,0,18,0,2,0,20,0,7,0,111,0,7,0,112,0,7,0,113,0,7, +0,114,0,7,0,115,0,7,0,116,0,7,0,117,0,7,0,118,0,7,0,119,0,7,0,120,0,7,0,121,0,2, +0,122,0,2,0,123,0,7,0,124,0,36,0,79,0,39,0,125,0,32,0,126,0,45,0,12,0,4,0,127,0,4, +0,-128,0,4,0,-127,0,4,0,-126,0,2,0,-125,0,2,0,-124,0,2,0,20,0,2,0,-123,0,2,0,-122,0,2, +0,-121,0,2,0,-120,0,2,0,-119,0,46,0,32,0,27,0,31,0,0,0,34,0,12,0,-118,0,47,0,-117,0,48, +0,-116,0,49,0,-115,0,2,0,-123,0,2,0,20,0,2,0,-114,0,2,0,18,0,2,0,37,0,2,0,43,0,4, +0,-113,0,2,0,-112,0,2,0,-111,0,2,0,-110,0,2,0,-109,0,2,0,-108,0,2,0,-107,0,4,0,-106,0,4, +0,-105,0,43,0,-104,0,30,0,-103,0,7,0,-102,0,4,0,-101,0,2,0,-100,0,2,0,-99,0,2,0,-98,0,2, +0,-97,0,7,0,-96,0,7,0,-95,0,9,0,-94,0,50,0,31,0,2,0,-93,0,2,0,-92,0,2,0,-91,0,2, +0,-90,0,32,0,-89,0,51,0,-88,0,0,0,-87,0,0,0,-86,0,0,0,-85,0,0,0,-84,0,0,0,-83,0,7, +0,-82,0,7,0,-81,0,2,0,-80,0,2,0,-79,0,2,0,-78,0,2,0,-77,0,2,0,-76,0,2,0,-75,0,2, +0,-74,0,7,0,-73,0,7,0,-72,0,7,0,-71,0,7,0,-70,0,7,0,-69,0,7,0,57,0,7,0,-68,0,7, +0,-67,0,7,0,-66,0,7,0,-65,0,7,0,-64,0,52,0,15,0,0,0,-63,0,9,0,-62,0,0,0,-61,0,0, +0,-60,0,4,0,-59,0,4,0,-58,0,9,0,-57,0,7,0,-56,0,7,0,-55,0,7,0,-54,0,4,0,-53,0,9, +0,-52,0,9,0,-51,0,4,0,-50,0,4,0,37,0,53,0,6,0,7,0,-73,0,7,0,-72,0,7,0,-71,0,7, +0,-49,0,7,0,67,0,4,0,64,0,54,0,5,0,2,0,20,0,2,0,36,0,2,0,64,0,2,0,-48,0,53, +0,-54,0,55,0,17,0,32,0,-89,0,46,0,-47,0,56,0,-46,0,7,0,-45,0,7,0,-44,0,2,0,18,0,2, +0,-43,0,7,0,113,0,7,0,114,0,7,0,-42,0,4,0,-41,0,2,0,-40,0,2,0,-39,0,4,0,-123,0,4, +0,-113,0,2,0,-38,0,2,0,-37,0,51,0,56,0,27,0,31,0,7,0,-36,0,7,0,-35,0,7,0,-34,0,7, +0,-33,0,7,0,-32,0,7,0,-31,0,7,0,-30,0,7,0,-29,0,7,0,-28,0,7,0,-27,0,7,0,-26,0,7, +0,-25,0,7,0,-24,0,7,0,-23,0,7,0,-22,0,7,0,-21,0,7,0,-20,0,7,0,-19,0,7,0,-18,0,7, +0,-17,0,2,0,-16,0,2,0,-15,0,2,0,-14,0,2,0,-13,0,2,0,-12,0,2,0,-11,0,2,0,-10,0,2, +0,20,0,2,0,18,0,2,0,-43,0,7,0,-9,0,7,0,-8,0,7,0,-7,0,7,0,-6,0,2,0,-5,0,2, +0,-4,0,2,0,-3,0,2,0,-125,0,4,0,23,0,4,0,-128,0,4,0,-127,0,4,0,-126,0,7,0,-2,0,7, +0,-1,0,7,0,-67,0,45,0,0,1,57,0,1,1,36,0,79,0,46,0,-47,0,52,0,2,1,54,0,3,1,55, +0,4,1,30,0,-103,0,0,0,5,1,0,0,6,1,58,0,8,0,7,0,7,1,7,0,8,1,7,0,-81,0,4, +0,20,0,7,0,9,1,7,0,10,1,7,0,11,1,32,0,45,0,59,0,80,0,27,0,31,0,2,0,18,0,2, +0,12,1,4,0,13,1,2,0,-79,0,2,0,14,1,7,0,-73,0,7,0,-72,0,7,0,-71,0,7,0,-70,0,7, +0,15,1,7,0,16,1,7,0,17,1,7,0,18,1,7,0,19,1,7,0,20,1,7,0,21,1,7,0,22,1,7, +0,23,1,7,0,24,1,7,0,25,1,60,0,26,1,2,0,27,1,2,0,70,0,7,0,113,0,7,0,114,0,7, +0,28,1,7,0,29,1,7,0,30,1,2,0,31,1,2,0,32,1,2,0,33,1,2,0,34,1,0,0,35,1,0, +0,36,1,2,0,37,1,2,0,38,1,2,0,39,1,2,0,40,1,2,0,41,1,7,0,42,1,7,0,43,1,7, +0,44,1,7,0,45,1,2,0,46,1,2,0,43,0,2,0,47,1,2,0,48,1,2,0,49,1,2,0,50,1,7, +0,51,1,7,0,52,1,7,0,53,1,7,0,54,1,7,0,55,1,7,0,56,1,7,0,57,1,7,0,58,1,7, +0,59,1,7,0,60,1,7,0,61,1,7,0,62,1,2,0,63,1,2,0,64,1,4,0,65,1,4,0,66,1,2, +0,67,1,2,0,68,1,2,0,69,1,2,0,70,1,7,0,71,1,7,0,72,1,7,0,73,1,7,0,74,1,2, +0,75,1,2,0,76,1,50,0,77,1,36,0,79,0,30,0,-103,0,39,0,125,0,61,0,2,0,27,0,31,0,36, +0,79,0,62,0,-127,0,27,0,31,0,2,0,-79,0,2,0,20,0,7,0,-73,0,7,0,-72,0,7,0,-71,0,7, +0,78,1,7,0,79,1,7,0,80,1,7,0,81,1,7,0,82,1,7,0,83,1,7,0,84,1,7,0,85,1,7, +0,86,1,7,0,87,1,7,0,88,1,7,0,89,1,7,0,90,1,7,0,91,1,7,0,92,1,7,0,93,1,7, +0,94,1,7,0,95,1,7,0,96,1,7,0,97,1,7,0,98,1,7,0,99,1,7,0,100,1,7,0,101,1,7, +0,102,1,7,0,103,1,7,0,104,1,2,0,105,1,2,0,106,1,2,0,107,1,0,0,108,1,0,0,109,1,7, +0,110,1,7,0,111,1,2,0,112,1,2,0,113,1,7,0,114,1,7,0,115,1,7,0,116,1,7,0,117,1,2, +0,118,1,2,0,119,1,4,0,13,1,4,0,120,1,2,0,121,1,2,0,122,1,2,0,123,1,2,0,124,1,7, +0,125,1,7,0,126,1,7,0,127,1,7,0,-128,1,7,0,-127,1,7,0,-126,1,7,0,-125,1,7,0,-124,1,7, +0,-123,1,7,0,-122,1,0,0,-121,1,7,0,-120,1,7,0,-119,1,7,0,-118,1,4,0,-117,1,0,0,-116,1,0, +0,47,1,0,0,-115,1,0,0,5,1,2,0,-114,1,2,0,-113,1,2,0,64,1,2,0,-112,1,2,0,-111,1,2, +0,-110,1,7,0,-109,1,7,0,-108,1,7,0,-107,1,7,0,-106,1,7,0,-105,1,2,0,-93,0,2,0,-92,0,54, +0,-104,1,54,0,-103,1,0,0,-102,1,0,0,-101,1,0,0,-100,1,0,0,-99,1,2,0,-98,1,2,0,12,1,7, +0,-97,1,7,0,-96,1,50,0,77,1,57,0,1,1,36,0,79,0,63,0,-95,1,30,0,-103,0,7,0,-94,1,7, +0,-93,1,7,0,-92,1,7,0,-91,1,7,0,-90,1,2,0,-89,1,2,0,70,0,7,0,-88,1,7,0,-87,1,7, +0,-86,1,7,0,-85,1,7,0,-84,1,7,0,-83,1,7,0,-82,1,7,0,-81,1,7,0,-80,1,2,0,-79,1,2, +0,-78,1,7,0,-77,1,7,0,-76,1,7,0,-75,1,7,0,-74,1,7,0,-73,1,4,0,-72,1,4,0,-71,1,4, +0,-70,1,39,0,125,0,12,0,-69,1,64,0,6,0,27,0,31,0,0,0,-68,1,7,0,-67,1,7,0,37,0,65, +0,2,0,43,0,-104,0,66,0,26,0,66,0,0,0,66,0,1,0,67,0,-66,1,4,0,-65,1,4,0,-64,1,4, +0,-63,1,4,0,-62,1,4,0,-61,1,4,0,-60,1,2,0,18,0,2,0,20,0,2,0,-59,1,2,0,-58,1,7, +0,5,0,7,0,6,0,7,0,7,0,7,0,-57,1,7,0,-56,1,7,0,-55,1,7,0,-54,1,7,0,-53,1,7, +0,-52,1,7,0,-51,1,7,0,23,0,7,0,-50,1,7,0,-49,1,68,0,15,0,27,0,31,0,67,0,-66,1,12, +0,-48,1,12,0,-47,1,36,0,79,0,62,0,-46,1,2,0,20,0,2,0,-45,1,4,0,-80,0,7,0,7,1,7, +0,-81,0,7,0,8,1,7,0,-44,1,7,0,-43,1,7,0,-42,1,35,0,10,0,7,0,-41,1,7,0,-40,1,7, +0,-39,1,7,0,-38,1,2,0,-37,1,2,0,-36,1,0,0,-35,1,0,0,-34,1,0,0,-33,1,0,0,-32,1,34, +0,7,0,7,0,-31,1,7,0,-40,1,7,0,-39,1,2,0,-35,1,2,0,-32,1,7,0,-38,1,7,0,37,0,69, +0,21,0,69,0,0,0,69,0,1,0,2,0,18,0,2,0,-30,1,2,0,-32,1,2,0,20,0,2,0,-29,1,2, +0,-28,1,2,0,-27,1,2,0,-26,1,2,0,-25,1,2,0,-24,1,2,0,-23,1,2,0,-22,1,7,0,-21,1,7, +0,-20,1,34,0,49,0,35,0,50,0,2,0,-19,1,2,0,-18,1,4,0,-17,1,70,0,5,0,2,0,-16,1,2, +0,-30,1,0,0,20,0,0,0,37,0,2,0,70,0,71,0,4,0,7,0,5,0,7,0,6,0,7,0,8,0,7, +0,-15,1,72,0,57,0,27,0,31,0,67,0,-66,1,12,0,-14,1,12,0,-47,1,32,0,-13,1,32,0,-12,1,32, +0,-11,1,36,0,79,0,73,0,-10,1,38,0,-9,1,62,0,-46,1,12,0,-8,1,7,0,7,1,7,0,-81,0,7, +0,8,1,4,0,-80,0,2,0,-7,1,2,0,-45,1,2,0,20,0,2,0,-6,1,7,0,-5,1,7,0,-4,1,7, +0,-3,1,2,0,-27,1,2,0,-26,1,2,0,-2,1,2,0,-1,1,4,0,70,0,2,0,23,0,2,0,98,0,2, +0,67,0,2,0,0,2,7,0,1,2,7,0,2,2,7,0,3,2,7,0,4,2,7,0,5,2,7,0,6,2,7, +0,7,2,7,0,8,2,7,0,9,2,7,0,10,2,0,0,11,2,0,0,12,2,64,0,13,2,64,0,14,2,64, +0,15,2,64,0,16,2,4,0,17,2,4,0,18,2,4,0,19,2,4,0,37,0,71,0,20,2,4,0,21,2,4, +0,22,2,70,0,23,2,70,0,24,2,74,0,39,0,27,0,31,0,67,0,-66,1,12,0,25,2,36,0,79,0,38, +0,-9,1,62,0,-46,1,75,0,26,2,76,0,27,2,77,0,28,2,78,0,29,2,79,0,30,2,80,0,31,2,81, +0,32,2,82,0,33,2,74,0,34,2,83,0,35,2,84,0,36,2,84,0,37,2,84,0,38,2,4,0,54,0,4, +0,39,2,4,0,40,2,4,0,41,2,4,0,42,2,4,0,-80,0,7,0,7,1,7,0,-81,0,7,0,8,1,7, +0,43,2,7,0,37,0,2,0,44,2,2,0,20,0,2,0,45,2,2,0,46,2,2,0,-45,1,2,0,47,2,85, +0,48,2,86,0,49,2,9,0,-94,0,77,0,8,0,9,0,50,2,7,0,51,2,4,0,52,2,0,0,20,0,0, +0,53,2,2,0,13,1,2,0,54,2,2,0,55,2,75,0,8,0,4,0,56,2,4,0,57,2,4,0,58,2,4, +0,59,2,0,0,37,0,0,0,-30,1,0,0,60,2,0,0,20,0,79,0,5,0,4,0,56,2,4,0,57,2,0, +0,61,2,0,0,62,2,2,0,20,0,87,0,2,0,4,0,63,2,7,0,-39,1,80,0,3,0,87,0,64,2,4, +0,65,2,4,0,20,0,78,0,6,0,7,0,66,2,2,0,67,2,0,0,20,0,0,0,-30,1,0,0,62,2,0, +0,68,2,81,0,4,0,0,0,-49,0,0,0,-73,0,0,0,-72,0,0,0,-71,0,88,0,6,0,46,0,50,2,0, +0,20,0,0,0,53,2,2,0,13,1,2,0,54,2,2,0,55,2,89,0,1,0,7,0,69,2,90,0,5,0,0, +0,-49,0,0,0,-73,0,0,0,-72,0,0,0,-71,0,4,0,37,0,82,0,1,0,7,0,70,2,83,0,2,0,4, +0,71,2,4,0,18,0,76,0,7,0,7,0,51,2,46,0,50,2,0,0,20,0,0,0,53,2,2,0,13,1,2, +0,54,2,2,0,55,2,91,0,1,0,7,0,72,2,92,0,1,0,4,0,73,2,93,0,1,0,0,0,74,2,94, +0,1,0,7,0,51,2,95,0,4,0,7,0,-49,0,7,0,-73,0,7,0,-72,0,7,0,-71,0,96,0,1,0,95, +0,52,2,97,0,5,0,4,0,75,2,4,0,76,2,0,0,20,0,0,0,-30,1,0,0,-74,0,98,0,2,0,4, +0,77,2,4,0,76,2,99,0,14,0,99,0,0,0,99,0,1,0,97,0,78,2,96,0,79,2,98,0,80,2,0, +0,81,2,12,0,82,2,12,0,83,2,100,0,84,2,4,0,54,0,4,0,40,2,4,0,39,2,4,0,37,0,78, +0,85,2,85,0,14,0,12,0,86,2,78,0,85,2,0,0,87,2,0,0,88,2,0,0,89,2,0,0,90,2,0, +0,91,2,0,0,92,2,0,0,93,2,0,0,20,0,84,0,36,2,84,0,38,2,2,0,94,2,0,0,95,2,86, +0,8,0,4,0,96,2,4,0,97,2,75,0,98,2,79,0,99,2,4,0,40,2,4,0,39,2,4,0,54,0,4, +0,37,0,101,0,6,0,101,0,0,0,101,0,1,0,4,0,18,0,4,0,13,1,0,0,17,0,0,0,100,2,102, +0,7,0,101,0,101,2,2,0,102,2,2,0,86,2,2,0,103,2,2,0,93,0,9,0,104,2,9,0,105,2,103, +0,3,0,101,0,101,2,32,0,-89,0,0,0,17,0,104,0,5,0,101,0,101,2,32,0,-89,0,0,0,17,0,2, +0,106,2,0,0,107,2,105,0,5,0,101,0,101,2,7,0,91,0,7,0,108,2,4,0,109,2,4,0,110,2,106, +0,5,0,101,0,101,2,32,0,111,2,0,0,72,0,4,0,13,1,4,0,20,0,107,0,13,0,101,0,101,2,32, +0,112,2,32,0,113,2,32,0,114,2,32,0,115,2,7,0,116,2,7,0,117,2,7,0,108,2,7,0,118,2,4, +0,119,2,4,0,120,2,4,0,93,0,4,0,121,2,108,0,5,0,101,0,101,2,2,0,122,2,2,0,20,0,7, +0,123,2,32,0,124,2,109,0,3,0,101,0,101,2,7,0,125,2,4,0,93,0,110,0,10,0,101,0,101,2,7, +0,126,2,4,0,127,2,4,0,37,0,2,0,93,0,2,0,-128,2,2,0,-127,2,2,0,-126,2,7,0,-125,2,0, +0,-124,2,111,0,3,0,101,0,101,2,7,0,37,0,4,0,18,0,112,0,11,0,101,0,101,2,51,0,-123,2,7, +0,-122,2,4,0,-121,2,0,0,-124,2,7,0,-120,2,4,0,-119,2,32,0,-118,2,0,0,-117,2,4,0,-116,2,4, +0,37,0,113,0,10,0,101,0,101,2,32,0,-115,2,46,0,-114,2,4,0,93,0,4,0,-113,2,7,0,-112,2,7, +0,-111,2,0,0,-117,2,4,0,-116,2,4,0,37,0,114,0,3,0,101,0,101,2,7,0,-110,2,4,0,-109,2,115, +0,5,0,101,0,101,2,7,0,-108,2,0,0,-124,2,2,0,20,0,2,0,-107,2,116,0,8,0,101,0,101,2,32, +0,-89,0,7,0,-108,2,7,0,-38,1,7,0,109,0,0,0,-124,2,2,0,20,0,2,0,18,0,117,0,21,0,101, +0,101,2,32,0,-106,2,0,0,-124,2,51,0,-123,2,32,0,-118,2,2,0,20,0,2,0,37,0,7,0,-105,2,7, +0,-104,2,7,0,-103,2,7,0,-5,1,7,0,-102,2,7,0,-101,2,7,0,-100,2,7,0,-99,2,4,0,-119,2,4, +0,-116,2,0,0,-117,2,7,0,-98,2,7,0,-97,2,7,0,43,0,118,0,7,0,101,0,101,2,2,0,-96,2,2, +0,-95,2,4,0,70,0,32,0,-89,0,7,0,-94,2,0,0,-124,2,119,0,9,0,101,0,101,2,32,0,-89,0,7, +0,-93,2,7,0,-92,2,7,0,-99,2,4,0,-91,2,4,0,-90,2,7,0,-89,2,0,0,17,0,120,0,1,0,101, +0,101,2,121,0,5,0,101,0,101,2,122,0,-88,2,123,0,-87,2,124,0,-86,2,125,0,-85,2,126,0,14,0,101, +0,101,2,78,0,-84,2,78,0,-83,2,78,0,-82,2,78,0,-81,2,78,0,-80,2,78,0,-79,2,75,0,-78,2,4, +0,-77,2,4,0,-76,2,2,0,-75,2,2,0,37,0,7,0,-74,2,127,0,-73,2,-128,0,3,0,101,0,101,2,-127, +0,-72,2,-126,0,-73,2,-125,0,4,0,101,0,101,2,32,0,-89,0,4,0,-71,2,4,0,37,0,-124,0,2,0,4, +0,-70,2,7,0,-39,1,-123,0,2,0,4,0,-127,0,4,0,-69,2,-122,0,20,0,101,0,101,2,32,0,-89,0,0, +0,-124,2,2,0,-68,2,2,0,-67,2,2,0,20,0,2,0,37,0,7,0,-66,2,7,0,-65,2,4,0,54,0,4, +0,-64,2,-123,0,-63,2,-124,0,-62,2,4,0,-61,2,4,0,-60,2,4,0,-59,2,4,0,-69,2,7,0,-58,2,7, +0,-57,2,7,0,-56,2,-121,0,8,0,101,0,101,2,-120,0,-55,2,-127,0,-72,2,4,0,-54,2,4,0,-53,2,4, +0,-52,2,2,0,20,0,2,0,57,0,-119,0,5,0,101,0,101,2,32,0,45,0,2,0,-51,2,2,0,20,0,2, +0,-50,2,-118,0,5,0,101,0,101,2,4,0,-49,2,2,0,20,0,2,0,-48,2,7,0,-47,2,-117,0,3,0,101, +0,101,2,-116,0,-46,2,125,0,-85,2,-115,0,10,0,101,0,101,2,32,0,-45,2,32,0,-44,2,0,0,-43,2,7, +0,-42,2,2,0,-41,2,2,0,-40,2,0,0,-39,2,0,0,-38,2,0,0,107,2,-114,0,9,0,101,0,101,2,32, +0,-37,2,0,0,-43,2,7,0,-36,2,7,0,-35,2,0,0,13,1,0,0,122,2,0,0,-34,2,0,0,37,0,-113, +0,24,0,27,0,31,0,2,0,-29,1,2,0,-28,1,2,0,-33,2,2,0,20,0,2,0,-32,2,2,0,-31,2,2, +0,-30,2,2,0,70,0,0,0,-29,2,0,0,-28,2,0,0,-27,2,0,0,18,0,4,0,37,0,7,0,-26,2,7, +0,-25,2,7,0,-24,2,7,0,-23,2,7,0,-22,2,7,0,-21,2,34,0,-20,2,36,0,79,0,38,0,-9,1,80, +0,31,2,-112,0,3,0,-112,0,0,0,-112,0,1,0,0,0,17,0,67,0,3,0,7,0,-19,2,4,0,20,0,4, +0,37,0,32,0,111,0,27,0,31,0,2,0,18,0,2,0,-18,2,4,0,-17,2,4,0,-16,2,4,0,-15,2,0, +0,-14,2,32,0,38,0,32,0,-13,2,32,0,-12,2,32,0,-11,2,32,0,-10,2,36,0,79,0,73,0,-10,1,67, +0,-66,1,-111,0,-9,2,-111,0,-8,2,-110,0,-7,2,9,0,2,0,12,0,-6,2,12,0,25,2,12,0,-47,1,12, +0,-5,2,12,0,-4,2,62,0,-46,1,7,0,7,1,7,0,-3,2,7,0,-2,2,7,0,-81,0,7,0,-1,2,7, +0,8,1,7,0,0,3,7,0,1,3,7,0,-93,2,7,0,2,3,7,0,-45,0,4,0,3,3,2,0,20,0,2, +0,4,3,2,0,5,3,2,0,6,3,2,0,7,3,2,0,8,3,2,0,9,3,2,0,10,3,2,0,11,3,2, +0,12,3,2,0,13,3,2,0,14,3,4,0,15,3,4,0,16,3,4,0,17,3,4,0,18,3,7,0,19,3,7, +0,20,3,7,0,21,3,7,0,22,3,7,0,23,3,7,0,24,3,7,0,25,3,7,0,26,3,7,0,27,3,7, +0,28,3,7,0,29,3,7,0,30,3,0,0,31,3,0,0,32,3,0,0,-45,1,0,0,33,3,0,0,34,3,0, +0,35,3,7,0,36,3,7,0,37,3,39,0,125,0,12,0,38,3,12,0,39,3,12,0,40,3,12,0,41,3,7, +0,42,3,2,0,71,2,2,0,43,3,7,0,52,2,4,0,44,3,4,0,45,3,-109,0,46,3,2,0,47,3,2, +0,-38,0,7,0,48,3,12,0,49,3,12,0,50,3,12,0,51,3,12,0,52,3,-108,0,53,3,-107,0,54,3,63, +0,55,3,2,0,56,3,2,0,57,3,2,0,58,3,2,0,59,3,7,0,44,2,2,0,60,3,2,0,61,3,-116, +0,62,3,-127,0,63,3,-127,0,64,3,4,0,65,3,4,0,66,3,4,0,67,3,4,0,70,0,9,0,-94,0,12, +0,68,3,-106,0,14,0,-106,0,0,0,-106,0,1,0,32,0,38,0,7,0,-93,2,7,0,9,1,7,0,-92,2,7, +0,-99,2,0,0,17,0,4,0,-91,2,4,0,-90,2,4,0,69,3,2,0,18,0,2,0,70,3,7,0,-89,2,-108, +0,36,0,2,0,71,3,2,0,72,3,2,0,20,0,2,0,-99,2,7,0,73,3,7,0,74,3,7,0,75,3,7, +0,76,3,7,0,77,3,7,0,78,3,7,0,79,3,7,0,80,3,7,0,81,3,7,0,82,3,7,0,83,3,7, +0,84,3,7,0,85,3,7,0,86,3,7,0,87,3,7,0,88,3,7,0,89,3,7,0,90,3,7,0,91,3,7, +0,92,3,7,0,93,3,7,0,94,3,7,0,95,3,7,0,96,3,2,0,97,3,2,0,98,3,2,0,99,3,2, +0,100,3,51,0,-88,0,-105,0,101,3,7,0,102,3,4,0,110,2,125,0,5,0,4,0,20,0,4,0,103,3,4, +0,104,3,4,0,105,3,4,0,106,3,-104,0,1,0,7,0,-31,1,-109,0,30,0,4,0,20,0,7,0,107,3,7, +0,108,3,7,0,109,3,4,0,110,3,4,0,111,3,4,0,112,3,4,0,113,3,7,0,114,3,7,0,115,3,7, +0,116,3,7,0,117,3,7,0,118,3,7,0,119,3,7,0,120,3,7,0,121,3,7,0,122,3,7,0,123,3,7, +0,124,3,7,0,125,3,7,0,126,3,7,0,127,3,7,0,-128,3,7,0,-127,3,7,0,-126,3,7,0,-125,3,4, +0,-124,3,4,0,-123,3,7,0,-122,3,7,0,27,3,-107,0,49,0,-120,0,-121,3,4,0,-120,3,4,0,-119,3,-103, +0,-118,3,-102,0,-117,3,0,0,37,0,0,0,-116,3,2,0,-115,3,7,0,-114,3,0,0,-113,3,7,0,-112,3,7, +0,-111,3,7,0,-110,3,7,0,-109,3,7,0,-108,3,7,0,-107,3,7,0,-106,3,7,0,-105,3,7,0,-104,3,2, +0,-103,3,0,0,-102,3,2,0,-101,3,7,0,-100,3,7,0,-99,3,0,0,-98,3,4,0,-126,0,4,0,-97,3,4, +0,-96,3,2,0,-95,3,2,0,-94,3,-104,0,-93,3,4,0,-92,3,4,0,81,0,7,0,-91,3,7,0,-90,3,7, +0,-89,3,7,0,-88,3,2,0,-87,3,2,0,-86,3,2,0,-85,3,2,0,-84,3,2,0,-83,3,2,0,-82,3,2, +0,-81,3,2,0,-80,3,-101,0,-79,3,7,0,-78,3,7,0,-77,3,125,0,-76,3,-116,0,48,0,2,0,18,0,2, +0,-75,3,2,0,-74,3,2,0,-73,3,7,0,-72,3,2,0,-71,3,2,0,-70,3,7,0,-69,3,2,0,-68,3,2, +0,-67,3,7,0,-66,3,7,0,-65,3,7,0,-64,3,7,0,-63,3,7,0,-62,3,7,0,-61,3,4,0,-60,3,7, +0,-59,3,7,0,-58,3,7,0,-57,3,74,0,-56,3,74,0,-55,3,74,0,-54,3,0,0,-53,3,7,0,-52,3,7, +0,-51,3,36,0,79,0,2,0,-50,3,0,0,-49,3,0,0,-48,3,7,0,-47,3,4,0,-46,3,7,0,-45,3,7, +0,-44,3,4,0,-43,3,4,0,20,0,7,0,-42,3,7,0,-41,3,7,0,-40,3,78,0,-39,3,7,0,-38,3,7, +0,-37,3,7,0,-36,3,7,0,-35,3,7,0,-34,3,7,0,-33,3,7,0,-32,3,4,0,-31,3,-100,0,71,0,27, +0,31,0,2,0,-79,0,2,0,14,1,2,0,47,1,2,0,-30,3,7,0,-29,3,7,0,-28,3,7,0,-27,3,7, +0,-26,3,7,0,-25,3,7,0,-24,3,7,0,-23,3,7,0,-22,3,7,0,84,1,7,0,86,1,7,0,85,1,7, +0,-21,3,4,0,-20,3,7,0,-19,3,7,0,-18,3,7,0,-17,3,7,0,-16,3,7,0,-15,3,7,0,-14,3,7, +0,-13,3,2,0,-12,3,2,0,13,1,2,0,-11,3,2,0,-10,3,2,0,-9,3,2,0,-8,3,2,0,-7,3,2, +0,-6,3,7,0,-5,3,7,0,-4,3,7,0,-3,3,7,0,-2,3,7,0,-1,3,7,0,0,4,7,0,1,4,7, +0,2,4,7,0,3,4,7,0,4,4,7,0,5,4,7,0,6,4,2,0,7,4,2,0,8,4,2,0,9,4,2, +0,10,4,7,0,11,4,7,0,12,4,7,0,13,4,7,0,14,4,2,0,15,4,2,0,16,4,2,0,17,4,2, +0,18,4,7,0,19,4,7,0,20,4,7,0,21,4,7,0,22,4,2,0,23,4,2,0,24,4,2,0,25,4,2, +0,43,0,7,0,26,4,7,0,27,4,36,0,79,0,50,0,77,1,30,0,-103,0,39,0,125,0,-99,0,16,0,2, +0,28,4,2,0,29,4,2,0,30,4,2,0,20,0,2,0,31,4,2,0,32,4,2,0,33,4,2,0,34,4,2, +0,35,4,2,0,36,4,2,0,37,4,2,0,38,4,4,0,39,4,7,0,40,4,7,0,41,4,7,0,42,4,-98, +0,8,0,-98,0,0,0,-98,0,1,0,4,0,3,3,4,0,43,4,4,0,20,0,2,0,44,4,2,0,45,4,32, +0,-89,0,-97,0,13,0,9,0,46,4,9,0,47,4,4,0,48,4,4,0,49,4,4,0,50,4,4,0,51,4,4, +0,52,4,4,0,53,4,4,0,54,4,4,0,55,4,4,0,56,4,4,0,37,0,0,0,57,4,-96,0,5,0,9, +0,58,4,9,0,59,4,4,0,60,4,4,0,70,0,0,0,61,4,-95,0,13,0,4,0,18,0,4,0,62,4,4, +0,63,4,4,0,64,4,4,0,65,4,4,0,66,4,4,0,93,0,4,0,67,4,4,0,68,4,4,0,69,4,4, +0,70,4,4,0,71,4,26,0,30,0,-94,0,4,0,4,0,72,4,7,0,73,4,2,0,20,0,2,0,68,2,-93, +0,11,0,-93,0,0,0,-93,0,1,0,0,0,17,0,62,0,74,4,63,0,75,4,4,0,3,3,4,0,76,4,4, +0,77,4,4,0,37,0,4,0,78,4,4,0,79,4,-92,0,-126,0,-97,0,80,4,-96,0,81,4,-95,0,82,4,4, +0,83,4,4,0,-126,0,4,0,-97,3,4,0,84,4,4,0,85,4,4,0,86,4,4,0,87,4,2,0,20,0,2, +0,88,4,7,0,20,3,7,0,89,4,7,0,90,4,7,0,91,4,7,0,92,4,7,0,93,4,2,0,94,4,2, +0,95,4,2,0,96,4,2,0,97,4,2,0,-39,0,2,0,98,4,2,0,99,4,2,0,100,3,2,0,100,4,2, +0,101,4,2,0,34,1,2,0,109,0,2,0,102,4,2,0,103,4,2,0,104,4,2,0,105,4,2,0,106,4,2, +0,107,4,2,0,108,4,2,0,109,4,2,0,110,4,2,0,35,1,2,0,111,4,2,0,112,4,2,0,113,4,2, +0,114,4,4,0,115,4,4,0,13,1,2,0,116,4,2,0,117,4,2,0,118,4,2,0,119,4,2,0,120,4,2, +0,121,4,24,0,122,4,24,0,123,4,23,0,124,4,12,0,125,4,2,0,126,4,2,0,37,0,7,0,127,4,7, +0,-128,4,7,0,-127,4,7,0,-126,4,7,0,-125,4,7,0,-124,4,7,0,-123,4,7,0,-122,4,7,0,-121,4,2, +0,-120,4,2,0,-119,4,2,0,-118,4,2,0,-117,4,2,0,-116,4,2,0,-115,4,7,0,-114,4,7,0,-113,4,7, +0,-112,4,2,0,-111,4,2,0,-110,4,2,0,-109,4,2,0,-108,4,2,0,-107,4,2,0,-106,4,2,0,-105,4,2, +0,-104,4,2,0,-103,4,2,0,-102,4,4,0,-101,4,4,0,-100,4,4,0,-99,4,4,0,-98,4,4,0,-97,4,7, +0,-96,4,4,0,-95,4,4,0,-94,4,4,0,-93,4,4,0,-92,4,7,0,-91,4,7,0,-90,4,7,0,-89,4,7, +0,-88,4,7,0,-87,4,7,0,-86,4,7,0,-85,4,7,0,-84,4,7,0,-83,4,0,0,-82,4,0,0,-81,4,4, +0,-80,4,2,0,-79,4,2,0,12,1,0,0,-78,4,7,0,-77,4,7,0,-76,4,4,0,-75,4,4,0,-74,4,7, +0,-73,4,7,0,-72,4,2,0,-71,4,2,0,-70,4,7,0,-69,4,2,0,-68,4,2,0,-67,4,4,0,-66,4,2, +0,-65,4,2,0,-64,4,2,0,-63,4,2,0,-62,4,7,0,-61,4,7,0,70,0,42,0,-60,4,-91,0,9,0,-91, +0,0,0,-91,0,1,0,0,0,17,0,2,0,-59,4,2,0,-58,4,2,0,-57,4,2,0,43,0,7,0,-56,4,7, +0,70,0,-90,0,5,0,7,0,-55,4,0,0,18,0,0,0,43,0,0,0,70,0,0,0,12,1,-89,0,5,0,-89, +0,0,0,-89,0,1,0,4,0,-54,4,0,0,-53,4,4,0,20,0,-88,0,5,0,-87,0,-52,4,2,0,20,0,2, +0,-51,4,2,0,-50,4,2,0,-49,4,-86,0,4,0,2,0,109,0,2,0,-122,2,2,0,-48,4,2,0,-47,4,-85, +0,7,0,2,0,20,0,2,0,-46,4,2,0,-45,4,2,0,-44,4,-86,0,-43,4,7,0,-42,4,4,0,-41,4,-84, +0,4,0,-84,0,0,0,-84,0,1,0,0,0,-40,4,7,0,-39,4,-83,0,56,0,2,0,-38,4,2,0,-37,4,7, +0,-36,4,7,0,-35,4,2,0,-48,4,2,0,-34,4,7,0,-33,4,7,0,-32,4,2,0,-31,4,2,0,-30,4,2, +0,-29,4,2,0,-28,4,7,0,-27,4,7,0,-26,4,7,0,-25,4,7,0,37,0,2,0,-24,4,2,0,-23,4,2, +0,-22,4,2,0,-21,4,-88,0,-20,4,-85,0,-19,4,7,0,-18,4,7,0,-17,4,0,0,-16,4,0,0,-15,4,0, +0,-14,4,0,0,-13,4,0,0,-12,4,0,0,-11,4,2,0,-10,4,7,0,-9,4,7,0,-8,4,7,0,-7,4,7, +0,-6,4,7,0,-5,4,7,0,-4,4,7,0,-3,4,7,0,-2,4,7,0,-1,4,7,0,0,5,2,0,1,5,0, +0,2,5,0,0,3,5,0,0,4,5,0,0,5,5,32,0,6,5,0,0,7,5,0,0,8,5,0,0,9,5,0, +0,10,5,0,0,11,5,0,0,12,5,0,0,13,5,0,0,14,5,0,0,15,5,-82,0,6,0,2,0,109,0,0, +0,-122,2,0,0,16,5,0,0,17,5,0,0,20,0,0,0,-74,0,-81,0,26,0,-80,0,18,5,50,0,77,1,60, +0,19,5,-82,0,20,5,-82,0,21,5,-82,0,22,5,-82,0,23,5,-82,0,24,5,-82,0,25,5,-82,0,26,5,7, +0,27,5,2,0,28,5,2,0,47,1,2,0,29,5,2,0,1,2,0,0,30,5,0,0,31,5,0,0,32,5,0, +0,33,5,0,0,93,0,0,0,34,5,0,0,35,5,0,0,36,5,0,0,37,5,0,0,38,5,0,0,-74,0,-79, +0,43,0,27,0,31,0,32,0,39,5,-100,0,40,5,-79,0,41,5,46,0,-47,0,12,0,42,5,-98,0,43,5,7, +0,44,5,7,0,45,5,7,0,46,5,7,0,47,5,4,0,3,3,7,0,48,5,2,0,49,5,2,0,50,5,2, +0,51,5,2,0,52,5,2,0,53,5,2,0,54,5,2,0,55,5,2,0,5,1,57,0,1,1,9,0,56,5,-99, +0,57,5,-90,0,58,5,-83,0,59,5,-92,0,-73,0,-94,0,60,5,39,0,125,0,12,0,103,0,12,0,61,5,2, +0,62,5,2,0,63,5,2,0,64,5,2,0,65,5,-78,0,66,5,2,0,67,5,2,0,68,5,2,0,64,1,2, +0,-38,0,-81,0,69,5,4,0,70,5,4,0,37,0,-77,0,9,0,46,0,-47,0,45,0,0,1,7,0,8,2,7, +0,9,2,7,0,109,0,7,0,71,5,7,0,72,5,2,0,73,5,2,0,74,5,-76,0,75,0,-75,0,0,0,-75, +0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,7,0,79,5,7,0,80,5,7,0,81,5,7, +0,82,5,7,0,83,5,7,0,84,5,7,0,85,5,7,0,20,1,7,0,86,5,4,0,87,5,2,0,88,5,2, +0,17,5,32,0,39,5,32,0,89,5,-77,0,90,5,-76,0,91,5,-73,0,92,5,-72,0,93,5,-71,0,94,5,0, +0,95,5,2,0,30,4,2,0,96,5,4,0,3,3,4,0,97,5,2,0,98,5,2,0,99,5,2,0,100,5,0, +0,101,5,0,0,43,0,7,0,115,0,7,0,102,5,7,0,103,5,7,0,104,5,7,0,105,5,7,0,106,5,7, +0,107,5,7,0,108,5,7,0,-82,0,7,0,44,5,2,0,109,5,2,0,110,5,2,0,111,5,2,0,112,5,2, +0,-119,0,2,0,29,5,2,0,113,5,2,0,114,5,2,0,115,5,2,0,116,5,7,0,117,5,7,0,118,5,67, +0,119,5,12,0,120,5,2,0,121,5,2,0,53,2,2,0,122,5,2,0,20,0,2,0,123,5,2,0,124,5,2, +0,125,5,0,0,126,5,0,0,127,5,9,0,-128,5,-70,0,-127,5,7,0,-126,5,2,0,-125,5,2,0,-124,5,2, +0,53,5,2,0,54,5,-69,0,19,0,24,0,36,0,24,0,64,0,23,0,-123,5,23,0,-122,5,23,0,-121,5,7, +0,-120,5,7,0,-119,5,7,0,-118,5,7,0,-117,5,2,0,-116,5,2,0,-115,5,2,0,-114,5,2,0,-113,5,2, +0,-112,5,2,0,-111,5,4,0,20,0,7,0,-110,5,2,0,99,5,0,0,107,2,-75,0,6,0,-75,0,0,0,-75, +0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-68,0,6,0,-75,0,0,0,-75,0,1,0,4, +0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-67,0,27,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7, +0,76,5,-74,0,77,5,2,0,78,5,4,0,-109,5,4,0,70,0,-69,0,-108,5,9,0,-107,5,12,0,-106,5,36, +0,79,0,27,0,80,0,0,0,-105,5,0,0,-104,5,0,0,-103,5,2,0,-102,5,2,0,-101,5,2,0,-100,5,2, +0,-99,5,2,0,65,0,2,0,46,0,2,0,-119,0,2,0,-98,5,4,0,20,0,7,0,-97,5,24,0,36,0,-66, +0,29,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,-73,0,92,5,2,0,78,5,2, +0,-96,5,2,0,-95,5,2,0,-94,5,2,0,-93,5,-69,0,-108,5,2,0,-92,5,2,0,-119,0,2,0,-101,5,2, +0,-91,5,9,0,-90,5,2,0,29,5,0,0,-89,5,0,0,-88,5,2,0,-87,5,2,0,-86,5,2,0,12,3,2, +0,-85,5,2,0,-84,5,0,0,37,0,0,0,20,0,0,0,47,1,0,0,-83,5,-65,0,16,0,-75,0,0,0,-75, +0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-69,0,-108,5,7,0,8,2,7,0,9,2,2, +0,-92,5,2,0,-82,5,2,0,-81,5,2,0,-80,5,4,0,20,0,7,0,71,5,-70,0,-127,5,-64,0,33,0,-75, +0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-63,0,-79,5,4,0,-78,5,0, +0,-77,5,0,0,-76,5,0,0,-75,5,2,0,18,0,2,0,-74,5,2,0,20,0,2,0,-73,5,2,0,-72,5,2, +0,-71,5,2,0,-70,5,2,0,43,0,4,0,70,0,0,0,-69,5,-62,0,-68,5,2,0,-67,5,2,0,-66,5,2, +0,-65,5,2,0,-48,0,9,0,-64,5,9,0,-63,5,9,0,-62,5,9,0,-61,5,9,0,-60,5,2,0,-59,5,0, +0,-58,5,-61,0,23,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-69, +0,-108,5,12,0,-57,5,2,0,-101,5,2,0,-56,5,2,0,20,0,2,0,57,0,9,0,-90,5,12,0,-55,5,-60, +0,-54,5,0,0,-53,5,-59,0,-52,5,4,0,-51,5,4,0,-50,5,2,0,18,0,2,0,-49,5,2,0,-48,5,2, +0,-47,5,-58,0,29,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-69, +0,-108,5,46,0,-114,2,45,0,0,1,60,0,19,5,2,0,13,1,2,0,-119,0,2,0,-46,5,2,0,-45,5,4, +0,20,0,2,0,49,5,2,0,-44,5,2,0,-98,5,2,0,-101,5,7,0,71,5,0,0,-43,5,0,0,-42,5,0, +0,-41,5,0,0,-40,5,7,0,8,2,7,0,9,2,7,0,-39,5,7,0,-38,5,-70,0,-127,5,-57,0,11,0,-75, +0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,2,0,-119,0,2,0,-98,5,2, +0,-37,5,2,0,20,0,-69,0,-108,5,-56,0,24,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74, +0,77,5,2,0,78,5,42,0,-36,5,4,0,-35,5,4,0,-34,5,2,0,93,0,2,0,-119,0,4,0,-33,5,4, +0,-32,5,4,0,-31,5,4,0,-30,5,4,0,-29,5,4,0,-28,5,4,0,-27,5,4,0,-26,5,7,0,-25,5,23, +0,-24,5,23,0,-23,5,4,0,-22,5,4,0,-21,5,-55,0,10,0,27,0,31,0,9,0,-20,5,9,0,-19,5,9, +0,-18,5,9,0,-17,5,9,0,-16,5,4,0,93,0,4,0,-15,5,0,0,-14,5,0,0,-13,5,-54,0,10,0,-75, +0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,-55,0,-12,5,2,0,93,0,2,0,-119,0,4, +0,43,0,9,0,-11,5,-53,0,8,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,-69, +0,-108,5,4,0,20,0,4,0,-10,5,-52,0,21,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74, +0,77,5,2,0,78,5,-69,0,-108,5,27,0,-9,5,27,0,80,0,2,0,20,0,2,0,-119,0,7,0,-8,5,9, +0,-7,5,7,0,8,2,7,0,9,2,57,0,1,1,57,0,-6,5,4,0,-5,5,2,0,-89,5,2,0,37,0,-70, +0,-127,5,-51,0,42,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74,0,77,5,2,0,78,5,-69, +0,-108,5,-50,0,-4,5,0,0,-77,5,0,0,-76,5,0,0,-75,5,2,0,18,0,2,0,-66,5,2,0,20,0,2, +0,-73,5,9,0,-7,5,4,0,-3,5,4,0,-2,5,4,0,-1,5,4,0,0,6,23,0,1,6,23,0,2,6,7, +0,3,6,7,0,4,6,7,0,5,6,7,0,-8,5,2,0,-67,5,2,0,-48,0,2,0,102,1,2,0,6,6,2, +0,37,0,2,0,43,0,2,0,7,6,2,0,8,6,9,0,-64,5,9,0,-63,5,9,0,-62,5,9,0,-61,5,9, +0,-60,5,2,0,-59,5,0,0,-58,5,56,0,9,6,-49,0,20,0,0,0,10,6,0,0,11,6,0,0,12,6,0, +0,13,6,0,0,14,6,0,0,15,6,0,0,16,6,0,0,17,6,0,0,18,6,0,0,19,6,0,0,20,6,0, +0,21,6,0,0,22,6,0,0,23,6,0,0,24,6,0,0,25,6,0,0,26,6,0,0,27,6,0,0,68,2,0, +0,28,6,-48,0,54,0,0,0,29,6,0,0,20,6,0,0,21,6,0,0,30,6,0,0,31,6,0,0,32,6,0, +0,33,6,0,0,34,6,0,0,35,6,0,0,36,6,0,0,37,6,0,0,38,6,0,0,39,6,0,0,40,6,0, +0,41,6,0,0,42,6,0,0,43,6,0,0,44,6,0,0,45,6,0,0,46,6,0,0,47,6,0,0,48,6,0, +0,49,6,0,0,50,6,0,0,51,6,0,0,52,6,0,0,53,6,0,0,54,6,0,0,55,6,0,0,56,6,0, +0,57,6,0,0,58,6,0,0,95,0,0,0,59,6,0,0,60,6,0,0,61,6,0,0,62,6,0,0,63,6,0, +0,64,6,0,0,65,6,0,0,66,6,0,0,67,6,0,0,68,6,0,0,69,6,0,0,70,6,0,0,71,6,0, +0,72,6,0,0,73,6,0,0,74,6,0,0,75,6,0,0,76,6,0,0,77,6,0,0,78,6,0,0,79,6,-47, +0,5,0,0,0,80,6,0,0,37,6,0,0,39,6,2,0,20,0,2,0,37,0,-46,0,22,0,-46,0,0,0,-46, +0,1,0,0,0,17,0,-49,0,81,6,-48,0,82,6,-48,0,83,6,-48,0,84,6,-48,0,85,6,-48,0,86,6,-48, +0,87,6,-48,0,88,6,-48,0,89,6,-48,0,90,6,-48,0,91,6,-48,0,92,6,-48,0,93,6,-48,0,94,6,-48, +0,95,6,-48,0,96,6,-47,0,97,6,0,0,98,6,0,0,99,6,-45,0,5,0,4,0,20,0,4,0,37,0,7, +0,52,2,7,0,100,6,7,0,-31,1,-44,0,66,0,4,0,20,0,4,0,101,6,4,0,102,6,0,0,103,6,0, +0,104,6,0,0,105,6,0,0,106,6,0,0,107,6,0,0,108,6,0,0,109,6,0,0,110,6,0,0,111,6,2, +0,112,6,2,0,113,6,4,0,114,6,4,0,115,6,4,0,116,6,4,0,117,6,2,0,118,6,2,0,119,6,2, +0,120,6,2,0,121,6,4,0,122,6,4,0,123,6,2,0,124,6,2,0,125,6,2,0,126,6,2,0,127,6,0, +0,-128,6,12,0,-127,6,2,0,-126,6,2,0,-125,6,2,0,-124,6,2,0,-123,6,2,0,-122,6,2,0,-121,6,2, +0,-120,6,2,0,-119,6,-45,0,-118,6,2,0,-117,6,2,0,-116,6,2,0,-115,6,2,0,-114,6,4,0,-113,6,4, +0,-112,6,4,0,-111,6,4,0,-110,6,2,0,-109,6,2,0,-108,6,2,0,-107,6,2,0,-106,6,2,0,-105,6,2, +0,-104,6,2,0,-103,6,2,0,-102,6,2,0,-101,6,2,0,-100,6,2,0,-99,6,2,0,37,0,0,0,-98,6,0, +0,-97,6,0,0,-96,6,7,0,-95,6,2,0,55,5,2,0,-94,6,54,0,-93,6,-43,0,18,0,27,0,31,0,12, +0,-92,6,12,0,-91,6,12,0,-90,6,-79,0,-89,6,2,0,-105,2,2,0,-88,6,2,0,-104,2,2,0,-87,6,2, +0,-86,6,2,0,-85,6,2,0,-84,6,2,0,-83,6,2,0,-82,6,2,0,37,0,2,0,-81,6,2,0,-80,6,2, +0,-79,6,-42,0,5,0,-42,0,0,0,-42,0,1,0,-42,0,-78,6,13,0,-77,6,4,0,20,0,-41,0,7,0,-41, +0,0,0,-41,0,1,0,-42,0,-76,6,-42,0,-75,6,2,0,123,4,2,0,20,0,4,0,37,0,-40,0,17,0,-40, +0,0,0,-40,0,1,0,0,0,-74,6,0,0,-73,6,0,0,-72,6,2,0,-71,6,2,0,-70,6,2,0,-86,6,2, +0,-85,6,2,0,20,0,2,0,70,3,2,0,-69,6,2,0,-68,6,2,0,-67,6,2,0,-66,6,4,0,-65,6,-40, +0,-64,6,-74,0,30,0,-74,0,0,0,-74,0,1,0,-42,0,-76,6,-42,0,-75,6,-42,0,-63,6,-42,0,-62,6,-43, +0,-61,6,7,0,-60,6,23,0,52,0,23,0,-59,6,23,0,-58,6,2,0,-57,6,2,0,-56,6,2,0,-55,6,0, +0,75,5,0,0,-54,6,2,0,-53,6,2,0,-52,6,0,0,-51,6,0,0,-50,6,0,0,-49,6,0,0,-48,6,2, +0,-47,6,2,0,-46,6,2,0,-45,6,2,0,20,0,39,0,125,0,12,0,-44,6,12,0,-43,6,12,0,-42,6,-39, +0,11,0,0,0,-41,6,2,0,-40,6,2,0,-39,6,2,0,-38,6,2,0,-37,6,2,0,-36,6,2,0,107,4,9, +0,-35,6,9,0,-34,6,4,0,-33,6,4,0,-32,6,-38,0,1,0,0,0,-31,6,-37,0,8,0,56,0,-30,6,56, +0,-29,6,-37,0,-28,6,-37,0,-27,6,-37,0,-26,6,2,0,-123,0,2,0,20,0,4,0,-25,6,-36,0,4,0,4, +0,-35,5,4,0,-24,6,4,0,-31,5,4,0,-23,6,-35,0,2,0,4,0,-22,6,4,0,-21,6,-34,0,9,0,7, +0,-20,6,7,0,-19,6,7,0,-18,6,4,0,20,0,4,0,13,1,7,0,-19,3,7,0,-17,6,4,0,37,0,-33, +0,-16,6,-32,0,6,0,0,0,-15,6,0,0,-75,5,48,0,-116,0,2,0,109,0,2,0,111,4,4,0,37,0,-31, +0,21,0,-31,0,0,0,-31,0,1,0,4,0,57,0,4,0,23,0,4,0,28,0,4,0,-14,6,4,0,-13,6,4, +0,-12,6,-38,0,-11,6,0,0,-15,6,4,0,-10,6,4,0,-9,6,-32,0,-12,2,-36,0,-8,6,-35,0,-7,6,-34, +0,-6,6,-37,0,-5,6,-37,0,-4,6,-37,0,-3,6,56,0,-2,6,56,0,-1,6,-30,0,12,0,0,0,-68,1,9, +0,-62,0,0,0,-61,0,4,0,-58,0,4,0,-50,0,9,0,-57,0,7,0,-55,0,7,0,-54,0,9,0,0,7,9, +0,1,7,9,0,-53,0,9,0,-51,0,-29,0,43,0,-29,0,0,0,-29,0,1,0,9,0,2,7,9,0,26,0,0, +0,27,0,4,0,20,0,4,0,18,0,4,0,23,0,4,0,91,0,4,0,3,7,4,0,4,7,4,0,-13,6,4, +0,-12,6,4,0,5,7,4,0,-39,0,4,0,6,7,4,0,7,7,7,0,8,7,7,0,9,7,4,0,-126,0,4, +0,10,7,-31,0,11,7,36,0,79,0,-79,0,-89,6,48,0,-116,0,7,0,12,7,7,0,13,7,-30,0,2,1,-29, +0,14,7,-29,0,15,7,-29,0,16,7,12,0,17,7,-28,0,18,7,-27,0,19,7,7,0,20,7,7,0,21,7,4, +0,-84,6,7,0,22,7,9,0,23,7,4,0,24,7,4,0,25,7,4,0,26,7,7,0,27,7,-26,0,4,0,-26, +0,0,0,-26,0,1,0,12,0,28,7,-29,0,29,7,-25,0,6,0,12,0,30,7,12,0,17,7,12,0,31,7,2, +0,20,0,2,0,37,0,4,0,57,0,-24,0,4,0,7,0,32,7,7,0,112,0,2,0,33,7,2,0,34,7,-23, +0,6,0,7,0,35,7,7,0,36,7,7,0,37,7,7,0,38,7,4,0,39,7,4,0,40,7,-22,0,12,0,7, +0,41,7,7,0,42,7,7,0,43,7,7,0,44,7,7,0,45,7,7,0,46,7,7,0,47,7,7,0,48,7,7, +0,49,7,7,0,50,7,4,0,-110,2,4,0,51,7,-21,0,2,0,7,0,-55,4,7,0,37,0,-20,0,7,0,7, +0,52,7,7,0,53,7,4,0,93,0,4,0,108,2,4,0,54,7,4,0,55,7,4,0,37,0,-19,0,6,0,-19, +0,0,0,-19,0,1,0,2,0,18,0,2,0,20,0,2,0,56,7,2,0,57,0,-18,0,8,0,-18,0,0,0,-18, +0,1,0,2,0,18,0,2,0,20,0,2,0,56,7,2,0,57,0,7,0,23,0,7,0,-126,0,-17,0,45,0,-17, +0,0,0,-17,0,1,0,2,0,18,0,2,0,20,0,2,0,56,7,2,0,-43,0,2,0,-103,3,2,0,57,7,7, +0,58,7,7,0,92,0,7,0,-97,2,4,0,59,7,4,0,81,0,4,0,110,2,7,0,60,7,7,0,61,7,7, +0,62,7,7,0,63,7,7,0,64,7,7,0,65,7,7,0,-100,2,7,0,-1,0,7,0,66,7,7,0,67,7,7, +0,37,0,7,0,68,7,7,0,69,7,7,0,70,7,2,0,71,7,2,0,72,7,2,0,73,7,2,0,74,7,2, +0,75,7,2,0,76,7,2,0,77,7,2,0,78,7,2,0,123,5,2,0,79,7,2,0,-47,1,2,0,80,7,0, +0,81,7,0,0,82,7,7,0,-45,0,-16,0,83,7,63,0,-95,1,-15,0,16,0,-15,0,0,0,-15,0,1,0,2, +0,18,0,2,0,20,0,2,0,56,7,2,0,-43,0,7,0,-105,2,7,0,-104,2,7,0,-103,2,7,0,-5,1,7, +0,-102,2,7,0,-101,2,7,0,84,7,7,0,-100,2,7,0,-98,2,7,0,-97,2,-59,0,5,0,2,0,18,0,2, +0,-25,6,2,0,20,0,2,0,85,7,27,0,-9,5,-60,0,3,0,4,0,69,0,4,0,86,7,-59,0,2,0,-14, +0,12,0,-14,0,0,0,-14,0,1,0,2,0,18,0,2,0,20,0,2,0,31,3,2,0,-32,1,7,0,5,0,7, +0,6,0,7,0,87,7,7,0,88,7,27,0,-9,5,12,0,89,7,-13,0,11,0,-13,0,0,0,-13,0,1,0,0, +0,17,0,2,0,18,0,2,0,90,7,4,0,22,0,4,0,91,7,2,0,20,0,2,0,37,0,9,0,92,7,9, +0,93,7,-12,0,5,0,0,0,17,0,7,0,20,1,7,0,94,7,4,0,95,7,4,0,37,0,-11,0,4,0,2, +0,18,0,2,0,20,0,2,0,43,0,2,0,70,0,-10,0,4,0,0,0,17,0,62,0,96,7,7,0,20,1,7, +0,37,0,-9,0,6,0,2,0,97,7,2,0,98,7,2,0,18,0,2,0,99,7,0,0,100,7,0,0,101,7,-8, +0,5,0,4,0,18,0,4,0,37,0,0,0,17,0,0,0,102,7,0,0,103,7,-7,0,3,0,4,0,18,0,4, +0,37,0,0,0,17,0,-6,0,4,0,2,0,104,7,2,0,105,7,2,0,20,0,2,0,37,0,-5,0,6,0,0, +0,17,0,0,0,106,7,2,0,107,7,2,0,-100,2,2,0,13,1,2,0,70,0,-4,0,5,0,0,0,17,0,7, +0,112,0,7,0,-17,3,2,0,20,0,2,0,122,2,-3,0,3,0,0,0,17,0,4,0,110,2,4,0,104,7,-2, +0,7,0,0,0,17,0,7,0,-17,3,0,0,108,7,0,0,109,7,2,0,13,1,2,0,43,0,4,0,110,7,-1, +0,3,0,32,0,111,7,0,0,112,7,0,0,113,7,0,1,18,0,0,1,0,0,0,1,1,0,2,0,18,0,2, +0,90,7,2,0,20,0,2,0,114,7,2,0,115,7,2,0,116,7,2,0,43,0,2,0,70,0,0,0,17,0,9, +0,2,0,1,1,117,7,32,0,45,0,2,0,-47,4,2,0,20,7,2,0,118,7,2,0,37,0,2,1,11,0,0, +0,17,0,0,0,18,0,0,0,119,7,2,0,20,0,2,0,122,2,2,0,120,7,4,0,121,7,4,0,122,7,4, +0,123,7,4,0,124,7,4,0,125,7,3,1,1,0,0,0,126,7,4,1,4,0,42,0,-36,5,0,0,127,7,4, +0,13,1,4,0,20,0,1,1,18,0,1,1,0,0,1,1,1,0,1,1,-128,7,2,0,18,0,2,0,20,0,2, +0,-127,7,2,0,116,7,2,0,90,7,2,0,-126,7,2,0,70,0,2,0,12,1,0,0,17,0,9,0,2,0,5, +1,117,7,0,1,-125,7,2,0,15,0,2,0,-124,7,4,0,-123,7,6,1,3,0,4,0,-74,2,4,0,37,0,32, +0,45,0,7,1,12,0,-111,0,-122,7,2,0,18,0,2,0,20,0,4,0,58,7,4,0,92,0,0,0,17,0,0, +0,-121,7,2,0,-120,7,2,0,-119,7,2,0,-118,7,2,0,-117,7,7,0,-116,7,8,1,10,0,2,0,20,0,2, +0,-115,7,4,0,58,7,4,0,92,0,2,0,-114,7,-28,0,18,7,2,0,18,0,2,0,-113,7,2,0,-112,7,2, +0,-111,7,9,1,7,0,2,0,20,0,2,0,-115,7,4,0,58,7,4,0,92,0,2,0,18,0,2,0,-110,7,7, +0,109,3,10,1,11,0,4,0,-74,2,2,0,18,0,2,0,20,0,32,0,45,0,74,0,-109,7,0,0,17,0,7, +0,-108,7,7,0,-107,7,7,0,21,3,2,0,-106,7,2,0,-105,7,11,1,5,0,2,0,18,0,2,0,20,0,4, +0,37,0,-79,0,-89,6,32,0,39,5,12,1,5,0,4,0,20,0,4,0,18,0,0,0,17,0,0,0,102,7,32, +0,45,0,13,1,13,0,2,0,20,0,2,0,18,0,2,0,90,7,2,0,22,3,7,0,-104,7,7,0,-103,7,7, +0,7,1,7,0,8,1,7,0,-3,2,7,0,0,3,7,0,-102,7,7,0,-101,7,32,0,-100,7,14,1,10,0,2, +0,20,0,2,0,18,0,4,0,58,7,4,0,92,0,0,0,17,0,0,0,-121,7,2,0,43,0,2,0,64,0,2, +0,-99,7,2,0,-98,7,15,1,8,0,32,0,45,0,7,0,-103,2,7,0,-97,7,7,0,-96,7,7,0,-108,2,2, +0,20,0,2,0,122,2,7,0,-95,7,16,1,12,0,2,0,18,0,2,0,13,1,2,0,20,0,2,0,-100,2,2, +0,-74,2,2,0,-94,7,4,0,37,0,7,0,-93,7,7,0,-92,7,7,0,-91,7,7,0,-90,7,0,0,-89,7,17, +1,10,0,2,0,20,0,2,0,18,0,4,0,58,7,4,0,92,0,0,0,17,0,2,0,68,2,2,0,64,0,2, +0,-99,7,2,0,-98,7,63,0,-95,1,18,1,7,0,4,0,110,2,4,0,-88,7,4,0,-87,7,4,0,-86,7,7, +0,-85,7,7,0,-84,7,0,0,108,7,19,1,7,0,0,0,-83,7,32,0,-82,7,0,0,112,7,2,0,-81,7,2, +0,43,0,4,0,70,0,0,0,113,7,20,1,6,0,2,0,20,0,2,0,18,0,4,0,58,7,4,0,92,0,0, +0,-80,7,0,0,-79,7,21,1,1,0,4,0,20,0,22,1,6,0,0,0,95,0,2,0,18,0,2,0,20,0,4, +0,-78,7,7,0,-77,7,42,0,-36,5,23,1,4,0,0,0,-74,0,2,0,20,0,4,0,18,0,32,0,45,0,24, +1,2,0,4,0,18,0,4,0,-121,5,5,1,10,0,5,1,0,0,5,1,1,0,5,1,-128,7,2,0,18,0,2, +0,20,0,2,0,90,7,2,0,-76,7,0,0,17,0,9,0,2,0,32,0,45,0,25,1,10,0,7,0,21,3,7, +0,-75,7,7,0,-74,7,7,0,-73,7,7,0,-72,7,4,0,20,0,7,0,-94,7,7,0,-71,7,7,0,-70,7,7, +0,37,0,-28,0,20,0,27,0,31,0,0,0,-63,0,26,1,-69,7,9,0,-68,7,43,0,-104,0,43,0,-67,7,9, +0,-66,7,36,0,79,0,7,0,109,3,7,0,-65,7,7,0,-64,7,7,0,-63,7,7,0,-62,7,7,0,-61,7,7, +0,-60,7,4,0,93,0,4,0,-59,7,0,0,-58,7,0,0,-57,7,0,0,-56,7,27,1,6,0,27,0,31,0,7, +0,-55,7,7,0,-54,7,7,0,-53,7,2,0,-52,7,2,0,-51,7,28,1,14,0,-75,0,0,0,-75,0,1,0,4, +0,75,5,7,0,76,5,-74,0,77,5,-69,0,-108,5,-28,0,18,7,2,0,13,1,2,0,-115,7,2,0,8,2,2, +0,9,2,2,0,20,0,2,0,-98,5,4,0,70,0,29,1,6,0,29,1,0,0,29,1,1,0,32,0,45,0,9, +0,-50,7,4,0,-38,0,4,0,37,0,63,0,4,0,27,0,31,0,12,0,-49,7,4,0,-121,0,7,0,-48,7,30, +1,25,0,30,1,0,0,30,1,1,0,30,1,38,0,12,0,-47,7,0,0,17,0,7,0,-46,7,7,0,-45,7,7, +0,-44,7,7,0,-43,7,4,0,20,0,7,0,-42,7,7,0,-41,7,7,0,-40,7,7,0,20,1,7,0,-39,1,7, +0,-39,7,7,0,108,2,7,0,-38,7,7,0,-37,7,7,0,-36,7,7,0,-35,7,7,0,-34,7,7,0,-81,0,2, +0,-121,0,2,0,-31,4,31,1,19,0,27,0,31,0,12,0,-33,7,12,0,-32,7,4,0,20,0,4,0,30,4,2, +0,-96,2,2,0,-31,7,2,0,-121,0,2,0,-30,7,2,0,-29,7,2,0,-28,7,2,0,-27,7,2,0,-26,7,4, +0,-25,7,4,0,-24,7,4,0,-23,7,4,0,-22,7,4,0,-21,7,4,0,-20,7,32,1,34,0,32,1,0,0,32, +1,1,0,12,0,49,3,0,0,17,0,2,0,20,0,2,0,-19,7,2,0,-18,7,2,0,-17,7,2,0,10,3,2, +0,-16,7,4,0,-7,1,4,0,-23,7,4,0,-22,7,30,1,-15,7,32,1,38,0,32,1,-14,7,12,0,-13,7,9, +0,-12,7,9,0,-11,7,9,0,-10,7,7,0,7,1,7,0,-81,0,7,0,-57,1,7,0,-9,7,7,0,-8,7,7, +0,2,3,7,0,-7,7,7,0,-6,7,7,0,-5,7,7,0,-4,7,7,0,-3,7,7,0,-2,7,7,0,-10,1,32, +0,-1,7,-110,0,9,0,12,0,0,8,2,0,20,0,2,0,1,8,7,0,20,3,7,0,2,8,7,0,3,8,12, +0,4,8,4,0,5,8,4,0,37,0,33,1,7,0,33,1,0,0,33,1,1,0,12,0,-58,7,4,0,20,0,4, +0,6,8,0,0,17,0,-47,0,7,8,34,1,8,0,34,1,0,0,34,1,1,0,33,1,8,8,36,0,79,0,12, +0,-6,2,4,0,20,0,0,0,17,0,4,0,9,8,-111,0,6,0,27,0,31,0,12,0,0,8,12,0,10,8,12, +0,103,0,4,0,11,8,4,0,37,0,35,1,16,0,-75,0,0,0,-75,0,1,0,4,0,75,5,7,0,76,5,-74, +0,77,5,2,0,78,5,-69,0,-108,5,-111,0,-9,2,0,0,13,1,0,0,-37,5,2,0,20,0,2,0,12,8,2, +0,-101,5,2,0,-98,5,2,0,13,8,7,0,14,8,36,1,5,0,36,1,0,0,36,1,1,0,36,0,79,0,2, +0,20,0,0,0,15,8,37,1,12,0,37,1,0,0,37,1,1,0,9,0,2,0,2,0,18,0,2,0,20,0,0, +0,16,8,0,0,17,8,0,0,15,8,7,0,18,8,7,0,19,8,4,0,37,0,36,0,79,0,38,1,9,0,38, +1,0,0,38,1,1,0,32,0,20,8,0,0,21,8,7,0,22,8,2,0,23,8,2,0,20,0,2,0,18,0,2, +0,37,0,39,1,7,0,42,0,-36,5,26,0,24,8,4,0,20,0,4,0,25,8,12,0,26,8,32,0,20,8,0, +0,21,8,40,1,12,0,32,0,20,8,2,0,27,8,2,0,20,0,2,0,28,8,2,0,29,8,0,0,21,8,32, +0,30,8,0,0,31,8,7,0,32,8,7,0,-39,1,7,0,33,8,7,0,34,8,41,1,6,0,32,0,20,8,4, +0,9,8,4,0,35,8,4,0,93,0,4,0,37,0,0,0,21,8,42,1,4,0,32,0,20,8,4,0,20,0,4, +0,9,8,0,0,21,8,43,1,4,0,32,0,20,8,4,0,20,0,4,0,9,8,0,0,21,8,44,1,10,0,32, +0,20,8,4,0,36,8,7,0,-127,0,4,0,20,0,2,0,-42,5,2,0,37,8,2,0,43,0,2,0,70,0,7, +0,38,8,0,0,21,8,45,1,4,0,32,0,20,8,4,0,20,0,4,0,9,8,0,0,21,8,46,1,10,0,32, +0,20,8,2,0,18,0,2,0,-95,3,4,0,91,0,4,0,92,0,7,0,-97,7,7,0,-96,7,4,0,37,0,-111, +0,-122,7,0,0,21,8,47,1,4,0,32,0,20,8,4,0,7,3,4,0,39,8,0,0,21,8,48,1,5,0,32, +0,20,8,7,0,-127,0,4,0,40,8,4,0,7,3,4,0,8,3,49,1,6,0,32,0,20,8,4,0,41,8,4, +0,42,8,7,0,43,8,7,0,44,8,0,0,21,8,50,1,16,0,32,0,20,8,32,0,-14,7,4,0,18,0,7, +0,45,8,7,0,46,8,7,0,47,8,7,0,48,8,7,0,49,8,7,0,50,8,7,0,51,8,7,0,52,8,7, +0,53,8,2,0,20,0,2,0,37,0,2,0,43,0,2,0,70,0,51,1,3,0,32,0,20,8,4,0,20,0,4, +0,123,5,52,1,5,0,32,0,20,8,4,0,20,0,4,0,37,0,7,0,54,8,0,0,21,8,53,1,10,0,32, +0,20,8,0,0,21,8,2,0,55,8,2,0,56,8,0,0,57,8,0,0,58,8,7,0,59,8,7,0,60,8,7, +0,61,8,7,0,62,8,54,1,8,0,7,0,9,0,7,0,10,0,7,0,11,0,7,0,12,0,7,0,63,8,7, +0,64,8,2,0,20,0,2,0,123,5,55,1,8,0,7,0,9,0,7,0,10,0,7,0,11,0,7,0,12,0,7, +0,63,8,7,0,64,8,2,0,20,0,2,0,123,5,56,1,8,0,7,0,9,0,7,0,10,0,7,0,11,0,7, +0,12,0,7,0,63,8,7,0,64,8,2,0,20,0,2,0,123,5,57,1,7,0,32,0,20,8,0,0,21,8,7, +0,20,1,7,0,30,1,2,0,20,0,2,0,13,1,4,0,37,0,58,1,5,0,32,0,-45,2,7,0,20,1,2, +0,-41,2,0,0,-39,2,0,0,65,8,59,1,10,0,59,1,0,0,59,1,1,0,2,0,18,0,2,0,20,0,0, +0,66,8,7,0,-36,0,7,0,-35,0,2,0,-58,7,2,0,67,8,32,0,45,0,60,1,22,0,60,1,0,0,60, +1,1,0,2,0,20,0,2,0,13,1,2,0,68,8,2,0,69,8,36,0,79,0,-111,0,-122,7,32,0,-89,0,7, +0,91,0,7,0,92,0,7,0,70,8,7,0,71,8,7,0,72,8,7,0,73,8,7,0,-107,2,7,0,-67,1,7, +0,-120,7,7,0,74,8,0,0,75,8,0,0,76,8,12,0,-4,2,61,1,8,0,7,0,-31,1,7,0,-97,7,7, +0,-96,7,9,0,2,0,2,0,77,8,2,0,78,8,2,0,79,8,2,0,80,8,62,1,18,0,62,1,0,0,62, +1,1,0,62,1,81,8,0,0,17,0,61,1,82,8,2,0,18,0,2,0,20,0,2,0,83,8,2,0,84,8,2, +0,85,8,2,0,86,8,4,0,43,0,7,0,87,8,7,0,88,8,4,0,89,8,4,0,90,8,62,1,91,8,63, +1,92,8,64,1,32,0,64,1,0,0,64,1,1,0,64,1,93,8,0,0,17,0,0,0,94,8,2,0,18,0,2, +0,20,0,2,0,-14,6,2,0,20,7,2,0,95,8,2,0,-119,0,2,0,84,8,2,0,-25,6,12,0,-127,7,12, +0,96,8,27,0,-9,5,9,0,97,8,7,0,87,8,7,0,88,8,7,0,-5,1,7,0,98,8,2,0,99,8,2, +0,100,8,7,0,101,8,7,0,102,8,2,0,103,8,2,0,104,8,24,0,105,8,24,0,106,8,24,0,107,8,65, +1,-103,0,66,1,108,8,63,1,6,0,63,1,0,0,63,1,1,0,64,1,109,8,64,1,110,8,62,1,111,8,62, +1,91,8,57,0,16,0,27,0,31,0,12,0,112,8,12,0,113,8,61,1,114,8,12,0,115,8,4,0,18,0,4, +0,116,8,4,0,117,8,4,0,118,8,12,0,119,8,66,1,120,8,62,1,121,8,62,1,122,8,9,0,123,8,9, +0,124,8,4,0,125,8,67,1,6,0,4,0,-128,0,4,0,-126,0,4,0,-25,6,0,0,126,8,0,0,127,8,2, +0,37,0,68,1,16,0,2,0,-86,6,2,0,-85,6,2,0,-128,8,2,0,-74,7,2,0,-127,8,2,0,68,0,7, +0,-108,2,7,0,-126,8,7,0,-125,8,2,0,34,1,0,0,-124,8,0,0,42,4,2,0,-123,8,2,0,37,0,4, +0,-122,8,4,0,-121,8,69,1,9,0,7,0,-120,8,7,0,-119,8,7,0,-60,7,7,0,112,0,7,0,-118,8,7, +0,71,5,2,0,-117,8,0,0,-116,8,0,0,37,0,70,1,4,0,7,0,-115,8,7,0,-114,8,2,0,-117,8,2, +0,37,0,71,1,3,0,7,0,-113,8,7,0,-112,8,7,0,15,0,72,1,7,0,0,0,-68,1,2,0,109,4,2, +0,110,4,2,0,111,4,2,0,62,4,4,0,-126,0,4,0,-97,3,73,1,7,0,7,0,-111,8,7,0,-110,8,7, +0,-109,8,7,0,4,2,7,0,-108,8,7,0,-107,8,7,0,-106,8,74,1,4,0,2,0,-105,8,2,0,-104,8,2, +0,-103,8,2,0,-102,8,75,1,2,0,7,0,5,0,7,0,6,0,76,1,2,0,0,0,-87,0,0,0,-101,8,77, +1,1,0,0,0,17,0,78,1,10,0,0,0,-100,8,0,0,-99,8,0,0,-98,8,0,0,-97,8,2,0,-128,8,2, +0,-96,8,7,0,-95,8,7,0,-94,8,7,0,-93,8,7,0,-67,1,79,1,2,0,9,0,-92,8,9,0,-91,8,80, +1,11,0,0,0,111,4,0,0,18,0,0,0,-117,8,0,0,112,0,0,0,-90,8,0,0,109,0,0,0,-74,0,7, +0,-89,8,7,0,-88,8,7,0,-87,8,7,0,-86,8,81,1,8,0,7,0,97,7,7,0,-127,0,7,0,42,4,7, +0,72,2,7,0,-85,8,7,0,-49,0,7,0,-84,8,4,0,18,0,82,1,4,0,2,0,-83,8,2,0,-82,8,2, +0,-81,8,2,0,37,0,83,1,1,0,0,0,17,0,84,1,4,0,7,0,5,0,7,0,6,0,2,0,20,0,2, +0,-80,8,85,1,10,0,2,0,-120,3,2,0,20,0,7,0,-17,3,7,0,-79,8,7,0,-78,8,7,0,-77,8,7, +0,-76,8,84,1,-75,8,84,1,-74,8,84,1,-73,8,60,0,9,0,4,0,20,0,4,0,64,0,24,0,-72,8,24, +0,-71,8,85,1,-70,8,7,0,-69,8,7,0,-68,8,7,0,-67,8,7,0,-66,8,86,1,4,0,46,0,-114,2,7, +0,-65,8,7,0,92,1,7,0,37,0,-87,0,13,0,27,0,31,0,2,0,20,0,2,0,72,5,4,0,109,0,7, +0,-64,8,7,0,1,2,7,0,-63,8,7,0,-62,8,7,0,92,1,2,0,47,1,2,0,37,0,50,0,77,1,86, +1,-61,8,87,1,10,0,4,0,18,0,4,0,-127,0,4,0,20,0,4,0,70,3,4,0,-60,8,4,0,-59,8,4, +0,-58,8,0,0,95,0,0,0,17,0,9,0,2,0,84,0,6,0,87,1,-57,8,4,0,-56,8,4,0,-55,8,4, +0,-54,8,4,0,37,0,9,0,-53,8,88,1,5,0,7,0,66,2,7,0,-74,2,7,0,-39,1,2,0,-52,8,2, +0,37,0,89,1,5,0,7,0,66,2,7,0,-51,8,7,0,-50,8,7,0,-49,8,7,0,-74,2,90,1,7,0,4, +0,-48,8,4,0,-47,8,4,0,-46,8,7,0,-45,8,7,0,-44,8,7,0,-43,8,7,0,-42,8,91,1,26,0,32, +0,-41,8,89,1,66,3,89,1,-40,8,88,1,-39,8,89,1,83,7,7,0,-38,8,7,0,-37,8,7,0,-36,8,7, +0,-35,8,7,0,-44,8,7,0,-43,8,7,0,-74,2,7,0,-97,2,7,0,-34,8,7,0,-33,8,7,0,109,0,7, +0,-32,8,4,0,-48,8,4,0,-31,8,4,0,37,0,4,0,81,0,4,0,-30,8,2,0,20,0,2,0,-29,8,2, +0,-28,8,2,0,100,3,92,1,112,0,27,0,31,0,4,0,20,0,2,0,18,0,2,0,55,8,2,0,-27,8,2, +0,-26,8,2,0,-25,8,2,0,-24,8,2,0,-23,8,2,0,-22,8,2,0,-21,8,2,0,-20,8,2,0,-19,8,2, +0,-18,8,2,0,-17,8,2,0,-16,8,2,0,-15,8,2,0,-14,8,2,0,-13,8,2,0,-47,1,2,0,76,7,2, +0,51,7,2,0,-12,8,2,0,-11,8,2,0,98,3,2,0,99,3,2,0,-10,8,2,0,-9,8,2,0,-8,8,2, +0,-7,8,2,0,-6,8,2,0,-5,8,7,0,-4,8,7,0,-3,8,7,0,-2,8,2,0,-1,8,2,0,0,9,7, +0,1,9,7,0,2,9,7,0,3,9,7,0,58,7,7,0,92,0,7,0,-97,2,7,0,64,7,7,0,4,9,7, +0,5,9,7,0,6,9,7,0,7,9,7,0,57,0,4,0,59,7,4,0,57,7,4,0,8,9,7,0,60,7,7, +0,61,7,7,0,62,7,7,0,9,9,7,0,10,9,7,0,11,9,7,0,12,9,7,0,13,9,7,0,14,9,7, +0,15,9,7,0,16,9,7,0,21,3,7,0,109,0,7,0,17,9,7,0,18,9,7,0,19,9,7,0,20,9,7, +0,21,9,7,0,22,9,7,0,108,2,7,0,23,9,7,0,24,9,4,0,25,9,4,0,26,9,7,0,27,9,7, +0,28,9,7,0,29,9,7,0,30,9,7,0,31,9,7,0,32,9,7,0,33,9,7,0,34,9,7,0,94,3,7, +0,92,3,7,0,93,3,7,0,35,9,7,0,36,9,7,0,37,9,7,0,38,9,7,0,39,9,7,0,40,9,7, +0,41,9,7,0,42,9,7,0,43,9,7,0,28,3,7,0,44,9,7,0,45,9,7,0,46,9,7,0,47,9,7, +0,48,9,7,0,49,9,7,0,50,9,0,0,51,9,63,0,55,3,63,0,52,9,32,0,53,9,32,0,54,9,36, +0,79,0,-108,0,53,3,-108,0,55,9,-120,0,37,0,-120,0,0,0,-120,0,1,0,92,1,56,9,91,1,-121,3,90, +1,-14,7,93,1,57,9,94,1,58,9,94,1,59,9,12,0,60,9,12,0,61,9,-107,0,54,3,32,0,62,9,32, +0,63,9,32,0,64,9,12,0,65,9,12,0,66,9,7,0,-45,0,7,0,83,4,4,0,110,2,4,0,20,0,4, +0,59,7,4,0,67,9,4,0,68,9,4,0,69,9,4,0,57,0,2,0,-38,0,2,0,70,9,2,0,71,9,2, +0,72,9,2,0,47,3,2,0,73,9,0,0,74,9,2,0,75,9,2,0,76,9,2,0,77,9,9,0,78,9,125, +0,-76,3,123,0,34,0,95,1,79,9,7,0,-106,3,7,0,80,9,7,0,81,9,7,0,-14,3,7,0,82,9,7, +0,31,3,7,0,21,3,7,0,83,9,7,0,3,2,7,0,84,9,7,0,85,9,7,0,86,9,7,0,87,9,7, +0,88,9,7,0,89,9,7,0,-105,3,7,0,90,9,7,0,91,9,7,0,92,9,7,0,-104,3,7,0,-108,3,7, +0,-107,3,4,0,93,9,4,0,93,0,4,0,94,9,4,0,95,9,2,0,96,9,2,0,97,9,2,0,98,9,2, +0,99,9,2,0,100,9,2,0,37,0,4,0,70,0,124,0,8,0,95,1,101,9,7,0,102,9,7,0,103,9,7, +0,-94,1,7,0,104,9,4,0,93,0,2,0,105,9,2,0,106,9,96,1,4,0,7,0,5,0,7,0,6,0,7, +0,7,0,7,0,107,9,97,1,6,0,97,1,0,0,97,1,1,0,96,1,108,9,4,0,109,9,2,0,110,9,2, +0,20,0,98,1,5,0,98,1,0,0,98,1,1,0,12,0,111,9,4,0,112,9,4,0,20,0,99,1,9,0,99, +1,0,0,99,1,1,0,12,0,-128,0,98,1,113,9,4,0,20,0,2,0,110,9,2,0,114,9,7,0,94,0,0, +0,115,9,-70,0,5,0,12,0,125,4,4,0,20,0,2,0,116,9,2,0,117,9,9,0,118,9,69,78,68,66,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +}; +int DNAlen= sizeof(DNAstr); diff --git a/Extras/Serialize/BulletFileLoader/CMakeLists.txt b/Extras/Serialize/BulletFileLoader/CMakeLists.txt new file mode 100644 index 0000000000..51e33e44f9 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/CMakeLists.txt @@ -0,0 +1,49 @@ +INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src +) + +SET(BulletFileLoader_SRCS +bChunk.cpp +bDNA.cpp +bFile.cpp +btBulletFile.cpp +) + +SET(BulletFileLoader_HDRS +bChunk.h +bCommon.h +bDefines.h +bDNA.h +bFile.h +btBulletFile.h +) + +ADD_LIBRARY(BulletFileLoader ${BulletFileLoader_SRCS} ${BulletFileLoader_HDRS}) + +IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(BulletFileLoader LinearMath) +ENDIF (BUILD_SHARED_LIBS) + +SET_TARGET_PROPERTIES(BulletFileLoader PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(BulletFileLoader PROPERTIES SOVERSION ${BULLET_VERSION}) + +IF (INSTALL_EXTRA_LIBS) + IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) + #FILES_MATCHING requires CMake 2.6 + IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletFileLoader DESTINATION .) + ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletFileLoader DESTINATION lib${LIB_SUFFIX}) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN +".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE) + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + SET_TARGET_PROPERTIES(BulletFileLoader PROPERTIES FRAMEWORK true) + SET_TARGET_PROPERTIES(BulletFileLoader PROPERTIES PUBLIC_HEADER "${BulletFileLoader_HDRS}") + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) +ENDIF (INSTALL_EXTRA_LIBS) diff --git a/Extras/Serialize/BulletFileLoader/autogenerated/bullet.h b/Extras/Serialize/BulletFileLoader/autogenerated/bullet.h new file mode 100644 index 0000000000..2fe1d7fc9d --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/autogenerated/bullet.h @@ -0,0 +1,1228 @@ +/* Copyright (C) 2011 Erwin Coumans & Charlie C +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 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. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +*/ +// Auto generated from Bullet/Extras/HeaderGenerator/bulletGenerate.py +#ifndef __BULLET_H__ +#define __BULLET_H__ +namespace Bullet { + +// put an empty struct in the case +typedef struct bInvalidHandle { + int unused; +}bInvalidHandle; + + class PointerArray; + class btPhysicsSystem; + class ListBase; + class btVector3FloatData; + class btVector3DoubleData; + class btMatrix3x3FloatData; + class btMatrix3x3DoubleData; + class btTransformFloatData; + class btTransformDoubleData; + class btBvhSubtreeInfoData; + class btOptimizedBvhNodeFloatData; + class btOptimizedBvhNodeDoubleData; + class btQuantizedBvhNodeData; + class btQuantizedBvhFloatData; + class btQuantizedBvhDoubleData; + class btCollisionShapeData; + class btStaticPlaneShapeData; + class btConvexInternalShapeData; + class btPositionAndRadius; + class btMultiSphereShapeData; + class btIntIndexData; + class btShortIntIndexData; + class btShortIntIndexTripletData; + class btCharIndexTripletData; + class btMeshPartData; + class btStridingMeshInterfaceData; + class btTriangleMeshShapeData; + class btScaledTriangleMeshShapeData; + class btCompoundShapeChildData; + class btCompoundShapeData; + class btCylinderShapeData; + class btConeShapeData; + class btCapsuleShapeData; + class btTriangleInfoData; + class btTriangleInfoMapData; + class btGImpactMeshShapeData; + class btConvexHullShapeData; + class btCollisionObjectDoubleData; + class btCollisionObjectFloatData; + class btDynamicsWorldDoubleData; + class btDynamicsWorldFloatData; + class btRigidBodyFloatData; + class btRigidBodyDoubleData; + class btConstraintInfo1; + class btTypedConstraintFloatData; + class btTypedConstraintData; + class btTypedConstraintDoubleData; + class btPoint2PointConstraintFloatData; + class btPoint2PointConstraintDoubleData2; + class btPoint2PointConstraintDoubleData; + class btHingeConstraintDoubleData; + class btHingeConstraintFloatData; + class btHingeConstraintDoubleData2; + class btConeTwistConstraintDoubleData; + class btConeTwistConstraintData; + class btGeneric6DofConstraintData; + class btGeneric6DofConstraintDoubleData2; + class btGeneric6DofSpringConstraintData; + class btGeneric6DofSpringConstraintDoubleData2; + class btSliderConstraintData; + class btSliderConstraintDoubleData; + class btGearConstraintFloatData; + class btGearConstraintDoubleData; + class btContactSolverInfoDoubleData; + class btContactSolverInfoFloatData; + class SoftBodyMaterialData; + class SoftBodyNodeData; + class SoftBodyLinkData; + class SoftBodyFaceData; + class SoftBodyTetraData; + class SoftRigidAnchorData; + class SoftBodyConfigData; + class SoftBodyPoseData; + class SoftBodyClusterData; + class btSoftBodyJointData; + class btSoftBodyFloatData; +// -------------------------------------------------- // + class PointerArray + { + public: + int m_size; + int m_capacity; + void *m_data; + }; + + +// -------------------------------------------------- // + class btPhysicsSystem + { + public: + PointerArray m_collisionShapes; + PointerArray m_collisionObjects; + PointerArray m_constraints; + }; + + +// -------------------------------------------------- // + class ListBase + { + public: + void *first; + void *last; + }; + + +// -------------------------------------------------- // + class btVector3FloatData + { + public: + float m_floats[4]; + }; + + +// -------------------------------------------------- // + class btVector3DoubleData + { + public: + double m_floats[4]; + }; + + +// -------------------------------------------------- // + class btMatrix3x3FloatData + { + public: + btVector3FloatData m_el[3]; + }; + + +// -------------------------------------------------- // + class btMatrix3x3DoubleData + { + public: + btVector3DoubleData m_el[3]; + }; + + +// -------------------------------------------------- // + class btTransformFloatData + { + public: + btMatrix3x3FloatData m_basis; + btVector3FloatData m_origin; + }; + + +// -------------------------------------------------- // + class btTransformDoubleData + { + public: + btMatrix3x3DoubleData m_basis; + btVector3DoubleData m_origin; + }; + + +// -------------------------------------------------- // + class btBvhSubtreeInfoData + { + public: + int m_rootNodeIndex; + int m_subtreeSize; + short m_quantizedAabbMin[3]; + short m_quantizedAabbMax[3]; + }; + + +// -------------------------------------------------- // + class btOptimizedBvhNodeFloatData + { + public: + btVector3FloatData m_aabbMinOrg; + btVector3FloatData m_aabbMaxOrg; + int m_escapeIndex; + int m_subPart; + int m_triangleIndex; + char m_pad[4]; + }; + + +// -------------------------------------------------- // + class btOptimizedBvhNodeDoubleData + { + public: + btVector3DoubleData m_aabbMinOrg; + btVector3DoubleData m_aabbMaxOrg; + int m_escapeIndex; + int m_subPart; + int m_triangleIndex; + char m_pad[4]; + }; + + +// -------------------------------------------------- // + class btQuantizedBvhNodeData + { + public: + short m_quantizedAabbMin[3]; + short m_quantizedAabbMax[3]; + int m_escapeIndexOrTriangleIndex; + }; + + +// -------------------------------------------------- // + class btQuantizedBvhFloatData + { + public: + btVector3FloatData m_bvhAabbMin; + btVector3FloatData m_bvhAabbMax; + btVector3FloatData m_bvhQuantization; + int m_curNodeIndex; + int m_useQuantization; + int m_numContiguousLeafNodes; + int m_numQuantizedContiguousNodes; + btOptimizedBvhNodeFloatData *m_contiguousNodesPtr; + btQuantizedBvhNodeData *m_quantizedContiguousNodesPtr; + btBvhSubtreeInfoData *m_subTreeInfoPtr; + int m_traversalMode; + int m_numSubtreeHeaders; + }; + + +// -------------------------------------------------- // + class btQuantizedBvhDoubleData + { + public: + btVector3DoubleData m_bvhAabbMin; + btVector3DoubleData m_bvhAabbMax; + btVector3DoubleData m_bvhQuantization; + int m_curNodeIndex; + int m_useQuantization; + int m_numContiguousLeafNodes; + int m_numQuantizedContiguousNodes; + btOptimizedBvhNodeDoubleData *m_contiguousNodesPtr; + btQuantizedBvhNodeData *m_quantizedContiguousNodesPtr; + int m_traversalMode; + int m_numSubtreeHeaders; + btBvhSubtreeInfoData *m_subTreeInfoPtr; + }; + + +// -------------------------------------------------- // + class btCollisionShapeData + { + public: + char *m_name; + int m_shapeType; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btStaticPlaneShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btVector3FloatData m_localScaling; + btVector3FloatData m_planeNormal; + float m_planeConstant; + char m_pad[4]; + }; + + +// -------------------------------------------------- // + class btConvexInternalShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btVector3FloatData m_localScaling; + btVector3FloatData m_implicitShapeDimensions; + float m_collisionMargin; + int m_padding; + }; + + +// -------------------------------------------------- // + class btPositionAndRadius + { + public: + btVector3FloatData m_pos; + float m_radius; + }; + + +// -------------------------------------------------- // + class btMultiSphereShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + btPositionAndRadius *m_localPositionArrayPtr; + int m_localPositionArraySize; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btIntIndexData + { + public: + int m_value; + }; + + +// -------------------------------------------------- // + class btShortIntIndexData + { + public: + short m_value; + char m_pad[2]; + }; + + +// -------------------------------------------------- // + class btShortIntIndexTripletData + { + public: + short m_values[3]; + char m_pad[2]; + }; + + +// -------------------------------------------------- // + class btCharIndexTripletData + { + public: + char m_values[3]; + char m_pad; + }; + + +// -------------------------------------------------- // + class btMeshPartData + { + public: + btVector3FloatData *m_vertices3f; + btVector3DoubleData *m_vertices3d; + btIntIndexData *m_indices32; + btShortIntIndexTripletData *m_3indices16; + btCharIndexTripletData *m_3indices8; + btShortIntIndexData *m_indices16; + int m_numTriangles; + int m_numVertices; + }; + + +// -------------------------------------------------- // + class btStridingMeshInterfaceData + { + public: + btMeshPartData *m_meshPartsPtr; + btVector3FloatData m_scaling; + int m_numMeshParts; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btTriangleMeshShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btStridingMeshInterfaceData m_meshInterface; + btQuantizedBvhFloatData *m_quantizedFloatBvh; + btQuantizedBvhDoubleData *m_quantizedDoubleBvh; + btTriangleInfoMapData *m_triangleInfoMap; + float m_collisionMargin; + char m_pad3[4]; + }; + + +// -------------------------------------------------- // + class btScaledTriangleMeshShapeData + { + public: + btTriangleMeshShapeData m_trimeshShapeData; + btVector3FloatData m_localScaling; + }; + + +// -------------------------------------------------- // + class btCompoundShapeChildData + { + public: + btTransformFloatData m_transform; + btCollisionShapeData *m_childShape; + int m_childShapeType; + float m_childMargin; + }; + + +// -------------------------------------------------- // + class btCompoundShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btCompoundShapeChildData *m_childShapePtr; + int m_numChildShapes; + float m_collisionMargin; + }; + + +// -------------------------------------------------- // + class btCylinderShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + int m_upAxis; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btConeShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + int m_upIndex; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btCapsuleShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + int m_upAxis; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btTriangleInfoData + { + public: + int m_flags; + float m_edgeV0V1Angle; + float m_edgeV1V2Angle; + float m_edgeV2V0Angle; + }; + + +// -------------------------------------------------- // + class btTriangleInfoMapData + { + public: + int *m_hashTablePtr; + int *m_nextPtr; + btTriangleInfoData *m_valueArrayPtr; + int *m_keyArrayPtr; + float m_convexEpsilon; + float m_planarEpsilon; + float m_equalVertexThreshold; + float m_edgeDistanceThreshold; + float m_zeroAreaThreshold; + int m_nextSize; + int m_hashTableSize; + int m_numValues; + int m_numKeys; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btGImpactMeshShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btStridingMeshInterfaceData m_meshInterface; + btVector3FloatData m_localScaling; + float m_collisionMargin; + int m_gimpactSubType; + }; + + +// -------------------------------------------------- // + class btConvexHullShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + btVector3FloatData *m_unscaledPointsFloatPtr; + btVector3DoubleData *m_unscaledPointsDoublePtr; + int m_numUnscaledPoints; + char m_padding3[4]; + }; + + +// -------------------------------------------------- // + class btCollisionObjectDoubleData + { + public: + void *m_broadphaseHandle; + void *m_collisionShape; + btCollisionShapeData *m_rootCollisionShape; + char *m_name; + btTransformDoubleData m_worldTransform; + btTransformDoubleData m_interpolationWorldTransform; + btVector3DoubleData m_interpolationLinearVelocity; + btVector3DoubleData m_interpolationAngularVelocity; + btVector3DoubleData m_anisotropicFriction; + double m_contactProcessingThreshold; + double m_deactivationTime; + double m_friction; + double m_rollingFriction; + double m_restitution; + double m_hitFraction; + double m_ccdSweptSphereRadius; + double m_ccdMotionThreshold; + int m_hasAnisotropicFriction; + int m_collisionFlags; + int m_islandTag1; + int m_companionId; + int m_activationState1; + int m_internalType; + int m_checkCollideWith; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btCollisionObjectFloatData + { + public: + void *m_broadphaseHandle; + void *m_collisionShape; + btCollisionShapeData *m_rootCollisionShape; + char *m_name; + btTransformFloatData m_worldTransform; + btTransformFloatData m_interpolationWorldTransform; + btVector3FloatData m_interpolationLinearVelocity; + btVector3FloatData m_interpolationAngularVelocity; + btVector3FloatData m_anisotropicFriction; + float m_contactProcessingThreshold; + float m_deactivationTime; + float m_friction; + float m_rollingFriction; + float m_restitution; + float m_hitFraction; + float m_ccdSweptSphereRadius; + float m_ccdMotionThreshold; + int m_hasAnisotropicFriction; + int m_collisionFlags; + int m_islandTag1; + int m_companionId; + int m_activationState1; + int m_internalType; + int m_checkCollideWith; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btDynamicsWorldDoubleData + { + public: + btContactSolverInfoDoubleData m_solverInfo; + btVector3DoubleData m_gravity; + }; + + +// -------------------------------------------------- // + class btDynamicsWorldFloatData + { + public: + btContactSolverInfoFloatData m_solverInfo; + btVector3FloatData m_gravity; + }; + + +// -------------------------------------------------- // + class btRigidBodyFloatData + { + public: + btCollisionObjectFloatData m_collisionObjectData; + btMatrix3x3FloatData m_invInertiaTensorWorld; + btVector3FloatData m_linearVelocity; + btVector3FloatData m_angularVelocity; + btVector3FloatData m_angularFactor; + btVector3FloatData m_linearFactor; + btVector3FloatData m_gravity; + btVector3FloatData m_gravity_acceleration; + btVector3FloatData m_invInertiaLocal; + btVector3FloatData m_totalForce; + btVector3FloatData m_totalTorque; + float m_inverseMass; + float m_linearDamping; + float m_angularDamping; + float m_additionalDampingFactor; + float m_additionalLinearDampingThresholdSqr; + float m_additionalAngularDampingThresholdSqr; + float m_additionalAngularDampingFactor; + float m_linearSleepingThreshold; + float m_angularSleepingThreshold; + int m_additionalDamping; + }; + + +// -------------------------------------------------- // + class btRigidBodyDoubleData + { + public: + btCollisionObjectDoubleData m_collisionObjectData; + btMatrix3x3DoubleData m_invInertiaTensorWorld; + btVector3DoubleData m_linearVelocity; + btVector3DoubleData m_angularVelocity; + btVector3DoubleData m_angularFactor; + btVector3DoubleData m_linearFactor; + btVector3DoubleData m_gravity; + btVector3DoubleData m_gravity_acceleration; + btVector3DoubleData m_invInertiaLocal; + btVector3DoubleData m_totalForce; + btVector3DoubleData m_totalTorque; + double m_inverseMass; + double m_linearDamping; + double m_angularDamping; + double m_additionalDampingFactor; + double m_additionalLinearDampingThresholdSqr; + double m_additionalAngularDampingThresholdSqr; + double m_additionalAngularDampingFactor; + double m_linearSleepingThreshold; + double m_angularSleepingThreshold; + int m_additionalDamping; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btConstraintInfo1 + { + public: + int m_numConstraintRows; + int nub; + }; + + +// -------------------------------------------------- // + class btTypedConstraintFloatData + { + public: + btRigidBodyFloatData *m_rbA; + btRigidBodyFloatData *m_rbB; + char *m_name; + int m_objectType; + int m_userConstraintType; + int m_userConstraintId; + int m_needsFeedback; + float m_appliedImpulse; + float m_dbgDrawSize; + int m_disableCollisionsBetweenLinkedBodies; + int m_overrideNumSolverIterations; + float m_breakingImpulseThreshold; + int m_isEnabled; + }; + + +// -------------------------------------------------- // + class btTypedConstraintData + { + public: + bInvalidHandle *m_rbA; + bInvalidHandle *m_rbB; + char *m_name; + int m_objectType; + int m_userConstraintType; + int m_userConstraintId; + int m_needsFeedback; + float m_appliedImpulse; + float m_dbgDrawSize; + int m_disableCollisionsBetweenLinkedBodies; + int m_overrideNumSolverIterations; + float m_breakingImpulseThreshold; + int m_isEnabled; + }; + + +// -------------------------------------------------- // + class btTypedConstraintDoubleData + { + public: + btRigidBodyDoubleData *m_rbA; + btRigidBodyDoubleData *m_rbB; + char *m_name; + int m_objectType; + int m_userConstraintType; + int m_userConstraintId; + int m_needsFeedback; + double m_appliedImpulse; + double m_dbgDrawSize; + int m_disableCollisionsBetweenLinkedBodies; + int m_overrideNumSolverIterations; + double m_breakingImpulseThreshold; + int m_isEnabled; + char padding[4]; + }; + + +// -------------------------------------------------- // + class btPoint2PointConstraintFloatData + { + public: + btTypedConstraintData m_typeConstraintData; + btVector3FloatData m_pivotInA; + btVector3FloatData m_pivotInB; + }; + + +// -------------------------------------------------- // + class btPoint2PointConstraintDoubleData2 + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btVector3DoubleData m_pivotInA; + btVector3DoubleData m_pivotInB; + }; + + +// -------------------------------------------------- // + class btPoint2PointConstraintDoubleData + { + public: + btTypedConstraintData m_typeConstraintData; + btVector3DoubleData m_pivotInA; + btVector3DoubleData m_pivotInB; + }; + + +// -------------------------------------------------- // + class btHingeConstraintDoubleData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + int m_useReferenceFrameA; + int m_angularOnly; + int m_enableAngularMotor; + float m_motorTargetVelocity; + float m_maxMotorImpulse; + float m_lowerLimit; + float m_upperLimit; + float m_limitSoftness; + float m_biasFactor; + float m_relaxationFactor; + }; + + +// -------------------------------------------------- // + class btHingeConstraintFloatData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformFloatData m_rbAFrame; + btTransformFloatData m_rbBFrame; + int m_useReferenceFrameA; + int m_angularOnly; + int m_enableAngularMotor; + float m_motorTargetVelocity; + float m_maxMotorImpulse; + float m_lowerLimit; + float m_upperLimit; + float m_limitSoftness; + float m_biasFactor; + float m_relaxationFactor; + }; + + +// -------------------------------------------------- // + class btHingeConstraintDoubleData2 + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + int m_useReferenceFrameA; + int m_angularOnly; + int m_enableAngularMotor; + double m_motorTargetVelocity; + double m_maxMotorImpulse; + double m_lowerLimit; + double m_upperLimit; + double m_limitSoftness; + double m_biasFactor; + double m_relaxationFactor; + char m_padding1[4]; + }; + + +// -------------------------------------------------- // + class btConeTwistConstraintDoubleData + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + double m_swingSpan1; + double m_swingSpan2; + double m_twistSpan; + double m_limitSoftness; + double m_biasFactor; + double m_relaxationFactor; + double m_damping; + }; + + +// -------------------------------------------------- // + class btConeTwistConstraintData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformFloatData m_rbAFrame; + btTransformFloatData m_rbBFrame; + float m_swingSpan1; + float m_swingSpan2; + float m_twistSpan; + float m_limitSoftness; + float m_biasFactor; + float m_relaxationFactor; + float m_damping; + char m_pad[4]; + }; + + +// -------------------------------------------------- // + class btGeneric6DofConstraintData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformFloatData m_rbAFrame; + btTransformFloatData m_rbBFrame; + btVector3FloatData m_linearUpperLimit; + btVector3FloatData m_linearLowerLimit; + btVector3FloatData m_angularUpperLimit; + btVector3FloatData m_angularLowerLimit; + int m_useLinearReferenceFrameA; + int m_useOffsetForConstraintFrame; + }; + + +// -------------------------------------------------- // + class btGeneric6DofConstraintDoubleData2 + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + btVector3DoubleData m_linearUpperLimit; + btVector3DoubleData m_linearLowerLimit; + btVector3DoubleData m_angularUpperLimit; + btVector3DoubleData m_angularLowerLimit; + int m_useLinearReferenceFrameA; + int m_useOffsetForConstraintFrame; + }; + + +// -------------------------------------------------- // + class btGeneric6DofSpringConstraintData + { + public: + btGeneric6DofConstraintData m_6dofData; + int m_springEnabled[6]; + float m_equilibriumPoint[6]; + float m_springStiffness[6]; + float m_springDamping[6]; + }; + + +// -------------------------------------------------- // + class btGeneric6DofSpringConstraintDoubleData2 + { + public: + btGeneric6DofConstraintDoubleData2 m_6dofData; + int m_springEnabled[6]; + double m_equilibriumPoint[6]; + double m_springStiffness[6]; + double m_springDamping[6]; + }; + + +// -------------------------------------------------- // + class btSliderConstraintData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformFloatData m_rbAFrame; + btTransformFloatData m_rbBFrame; + float m_linearUpperLimit; + float m_linearLowerLimit; + float m_angularUpperLimit; + float m_angularLowerLimit; + int m_useLinearReferenceFrameA; + int m_useOffsetForConstraintFrame; + }; + + +// -------------------------------------------------- // + class btSliderConstraintDoubleData + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + double m_linearUpperLimit; + double m_linearLowerLimit; + double m_angularUpperLimit; + double m_angularLowerLimit; + int m_useLinearReferenceFrameA; + int m_useOffsetForConstraintFrame; + }; + + +// -------------------------------------------------- // + class btGearConstraintFloatData + { + public: + btTypedConstraintFloatData m_typeConstraintData; + btVector3FloatData m_axisInA; + btVector3FloatData m_axisInB; + float m_ratio; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btGearConstraintDoubleData + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btVector3DoubleData m_axisInA; + btVector3DoubleData m_axisInB; + double m_ratio; + }; + + +// -------------------------------------------------- // + class btContactSolverInfoDoubleData + { + public: + double m_tau; + double m_damping; + double m_friction; + double m_timeStep; + double m_restitution; + double m_maxErrorReduction; + double m_sor; + double m_erp; + double m_erp2; + double m_globalCfm; + double m_splitImpulsePenetrationThreshold; + double m_splitImpulseTurnErp; + double m_linearSlop; + double m_warmstartingFactor; + double m_maxGyroscopicForce; + double m_singleAxisRollingFrictionThreshold; + int m_numIterations; + int m_solverMode; + int m_restingContactRestitutionThreshold; + int m_minimumSolverBatchSize; + int m_splitImpulse; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btContactSolverInfoFloatData + { + public: + float m_tau; + float m_damping; + float m_friction; + float m_timeStep; + float m_restitution; + float m_maxErrorReduction; + float m_sor; + float m_erp; + float m_erp2; + float m_globalCfm; + float m_splitImpulsePenetrationThreshold; + float m_splitImpulseTurnErp; + float m_linearSlop; + float m_warmstartingFactor; + float m_maxGyroscopicForce; + float m_singleAxisRollingFrictionThreshold; + int m_numIterations; + int m_solverMode; + int m_restingContactRestitutionThreshold; + int m_minimumSolverBatchSize; + int m_splitImpulse; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class SoftBodyMaterialData + { + public: + float m_linearStiffness; + float m_angularStiffness; + float m_volumeStiffness; + int m_flags; + }; + + +// -------------------------------------------------- // + class SoftBodyNodeData + { + public: + SoftBodyMaterialData *m_material; + btVector3FloatData m_position; + btVector3FloatData m_previousPosition; + btVector3FloatData m_velocity; + btVector3FloatData m_accumulatedForce; + btVector3FloatData m_normal; + float m_inverseMass; + float m_area; + int m_attach; + int m_pad; + }; + + +// -------------------------------------------------- // + class SoftBodyLinkData + { + public: + SoftBodyMaterialData *m_material; + int m_nodeIndices[2]; + float m_restLength; + int m_bbending; + }; + + +// -------------------------------------------------- // + class SoftBodyFaceData + { + public: + btVector3FloatData m_normal; + SoftBodyMaterialData *m_material; + int m_nodeIndices[3]; + float m_restArea; + }; + + +// -------------------------------------------------- // + class SoftBodyTetraData + { + public: + btVector3FloatData m_c0[4]; + SoftBodyMaterialData *m_material; + int m_nodeIndices[4]; + float m_restVolume; + float m_c1; + float m_c2; + int m_pad; + }; + + +// -------------------------------------------------- // + class SoftRigidAnchorData + { + public: + btMatrix3x3FloatData m_c0; + btVector3FloatData m_c1; + btVector3FloatData m_localFrame; + bInvalidHandle *m_rigidBody; + int m_nodeIndex; + float m_c2; + }; + + +// -------------------------------------------------- // + class SoftBodyConfigData + { + public: + int m_aeroModel; + float m_baumgarte; + float m_damping; + float m_drag; + float m_lift; + float m_pressure; + float m_volume; + float m_dynamicFriction; + float m_poseMatch; + float m_rigidContactHardness; + float m_kineticContactHardness; + float m_softContactHardness; + float m_anchorHardness; + float m_softRigidClusterHardness; + float m_softKineticClusterHardness; + float m_softSoftClusterHardness; + float m_softRigidClusterImpulseSplit; + float m_softKineticClusterImpulseSplit; + float m_softSoftClusterImpulseSplit; + float m_maxVolume; + float m_timeScale; + int m_velocityIterations; + int m_positionIterations; + int m_driftIterations; + int m_clusterIterations; + int m_collisionFlags; + }; + + +// -------------------------------------------------- // + class SoftBodyPoseData + { + public: + btMatrix3x3FloatData m_rot; + btMatrix3x3FloatData m_scale; + btMatrix3x3FloatData m_aqq; + btVector3FloatData m_com; + btVector3FloatData *m_positions; + float *m_weights; + int m_numPositions; + int m_numWeigts; + int m_bvolume; + int m_bframe; + float m_restVolume; + int m_pad; + }; + + +// -------------------------------------------------- // + class SoftBodyClusterData + { + public: + btTransformFloatData m_framexform; + btMatrix3x3FloatData m_locii; + btMatrix3x3FloatData m_invwi; + btVector3FloatData m_com; + btVector3FloatData m_vimpulses[2]; + btVector3FloatData m_dimpulses[2]; + btVector3FloatData m_lv; + btVector3FloatData m_av; + btVector3FloatData *m_framerefs; + int *m_nodeIndices; + float *m_masses; + int m_numFrameRefs; + int m_numNodes; + int m_numMasses; + float m_idmass; + float m_imass; + int m_nvimpulses; + int m_ndimpulses; + float m_ndamping; + float m_ldamping; + float m_adamping; + float m_matching; + float m_maxSelfCollisionImpulse; + float m_selfCollisionImpulseFactor; + int m_containsAnchor; + int m_collide; + int m_clusterIndex; + }; + + +// -------------------------------------------------- // + class btSoftBodyJointData + { + public: + void *m_bodyA; + void *m_bodyB; + btVector3FloatData m_refs[2]; + float m_cfm; + float m_erp; + float m_split; + int m_delete; + btVector3FloatData m_relPosition[2]; + int m_bodyAtype; + int m_bodyBtype; + int m_jointType; + int m_pad; + }; + + +// -------------------------------------------------- // + class btSoftBodyFloatData + { + public: + btCollisionObjectFloatData m_collisionObjectData; + SoftBodyPoseData *m_pose; + SoftBodyMaterialData **m_materials; + SoftBodyNodeData *m_nodes; + SoftBodyLinkData *m_links; + SoftBodyFaceData *m_faces; + SoftBodyTetraData *m_tetrahedra; + SoftRigidAnchorData *m_anchors; + SoftBodyClusterData *m_clusters; + btSoftBodyJointData *m_joints; + int m_numMaterials; + int m_numNodes; + int m_numLinks; + int m_numFaces; + int m_numTetrahedra; + int m_numAnchors; + int m_numClusters; + int m_numJoints; + SoftBodyConfigData m_config; + }; + + +} +#endif//__BULLET_H__ \ No newline at end of file diff --git a/Extras/Serialize/BulletFileLoader/bChunk.cpp b/Extras/Serialize/BulletFileLoader/bChunk.cpp new file mode 100644 index 0000000000..564e5507e7 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/bChunk.cpp @@ -0,0 +1,75 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "bChunk.h" +#include "bDefines.h" +#include "bFile.h" + +#if !defined( __CELLOS_LV2__) && !defined(__MWERKS__) +#include +#endif +#include + + +using namespace bParse; + + +// ----------------------------------------------------- // +short ChunkUtils::swapShort(short sht) +{ + SWITCH_SHORT(sht); + return sht; +} + +// ----------------------------------------------------- // +int ChunkUtils::swapInt(int inte) +{ + SWITCH_INT(inte); + return inte; +} + +// ----------------------------------------------------- // +long64 ChunkUtils::swapLong64(long64 lng) +{ + SWITCH_LONGINT(lng); + return lng; +} + +// ----------------------------------------------------- // +int ChunkUtils::getOffset(int flags) +{ + // if the file is saved in a + // different format, get the + // file's chunk size + int res = CHUNK_HEADER_LEN; + + if (VOID_IS_8) + { + if (flags &FD_BITS_VARIES) + res = sizeof(bChunkPtr4); + } + else + { + if (flags &FD_BITS_VARIES) + res = sizeof(bChunkPtr8); + } + return res; +} + + + + + +//eof diff --git a/Extras/Serialize/BulletFileLoader/bChunk.h b/Extras/Serialize/BulletFileLoader/bChunk.h new file mode 100644 index 0000000000..77039bcf95 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/bChunk.h @@ -0,0 +1,92 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __BCHUNK_H__ +#define __BCHUNK_H__ + +#if defined (_WIN32) && ! defined (__MINGW32__) + #define long64 __int64 +#elif defined (__MINGW32__) + #include + #define long64 int64_t +#else + #define long64 long long +#endif + + +namespace bParse { + + + // ----------------------------------------------------- // + class bChunkPtr4 + { + public: + bChunkPtr4(){} + int code; + int len; + union + { + int m_uniqueInt; + }; + int dna_nr; + int nr; + }; + + // ----------------------------------------------------- // + class bChunkPtr8 + { + public: + bChunkPtr8(){} + int code, len; + union + { + long64 oldPrev; + int m_uniqueInts[2]; + }; + int dna_nr, nr; + }; + + // ----------------------------------------------------- // + class bChunkInd + { + public: + bChunkInd(){} + int code, len; + void *oldPtr; + int dna_nr, nr; + }; + + + // ----------------------------------------------------- // + class ChunkUtils + { + public: + + // file chunk offset + static int getOffset(int flags); + + // endian utils + static short swapShort(short sht); + static int swapInt(int inte); + static long64 swapLong64(long64 lng); + + }; + + + const int CHUNK_HEADER_LEN = ((sizeof(bChunkInd))); + const bool VOID_IS_8 = ((sizeof(void*)==8)); +} + +#endif//__BCHUNK_H__ diff --git a/Extras/Serialize/BulletFileLoader/bCommon.h b/Extras/Serialize/BulletFileLoader/bCommon.h new file mode 100644 index 0000000000..b01d2b8992 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/bCommon.h @@ -0,0 +1,39 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __BCOMMON_H__ +#define __BCOMMON_H__ + + +#include +//#include "bLog.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "LinearMath/btHashMap.h" + +namespace bParse { + + class bMain; + class bFileData; + class bFile; + class bDNA; + + // delete void* undefined + typedef struct bStructHandle {int unused;}bStructHandle; + typedef btAlignedObjectArray bListBasePtr; + typedef btHashMap bPtrMap; +} + + +#endif//__BCOMMON_H__ diff --git a/Extras/Serialize/BulletFileLoader/bDNA.cpp b/Extras/Serialize/BulletFileLoader/bDNA.cpp new file mode 100644 index 0000000000..a362767bb0 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/bDNA.cpp @@ -0,0 +1,644 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ +#include + +#include "bDNA.h" +#include "bChunk.h" +#include +#include +#include + +//this define will force traversal of structures, to check backward (and forward) compatibility +//#define TEST_BACKWARD_FORWARD_COMPATIBILITY + + +using namespace bParse; + + +// ----------------------------------------------------- // +bDNA::bDNA() + : mPtrLen(0) +{ + // -- +} + +// ----------------------------------------------------- // +bDNA::~bDNA() +{ + // -- +} + +// ----------------------------------------------------- // +bool bDNA::lessThan(bDNA *file) +{ + return ( m_Names.size() < file->m_Names.size()); +} + +// ----------------------------------------------------- // +char *bDNA::getName(int ind) +{ + assert(ind <= (int)m_Names.size()); + return m_Names[ind].m_name; +} + + +// ----------------------------------------------------- // +char *bDNA::getType(int ind) +{ + assert(ind<= (int)mTypes.size()); + return mTypes[ind]; +} + + +// ----------------------------------------------------- // +short *bDNA::getStruct(int ind) +{ + assert(ind <= (int)mStructs.size()); + return mStructs[ind]; +} + + +// ----------------------------------------------------- // +short bDNA::getLength(int ind) +{ + assert(ind <= (int)mTlens.size()); + return mTlens[ind]; +} + + +// ----------------------------------------------------- // +int bDNA::getReverseType(short type) +{ + + int* intPtr = mStructReverse.find(type); + if (intPtr) + return *intPtr; + + return -1; +} + +// ----------------------------------------------------- // +int bDNA::getReverseType(const char *type) +{ + + btHashString key(type); + int* valuePtr = mTypeLookup.find(key); + if (valuePtr) + return *valuePtr; + + return -1; +} + +// ----------------------------------------------------- // +int bDNA::getNumStructs() +{ + return (int)mStructs.size(); +} + +// ----------------------------------------------------- // +bool bDNA::flagNotEqual(int dna_nr) +{ + assert(dna_nr <= (int)mCMPFlags.size()); + return mCMPFlags[dna_nr] == FDF_STRUCT_NEQU; +} + +// ----------------------------------------------------- // +bool bDNA::flagEqual(int dna_nr) +{ + assert(dna_nr <= (int)mCMPFlags.size()); + int flag = mCMPFlags[dna_nr]; + return flag == FDF_STRUCT_EQU; +} + +// ----------------------------------------------------- // +bool bDNA::flagNone(int dna_nr) +{ + assert(dna_nr <= (int)mCMPFlags.size()); + return mCMPFlags[dna_nr] == FDF_NONE; +} + +// ----------------------------------------------------- // +int bDNA::getPointerSize() +{ + return mPtrLen; +} + +// ----------------------------------------------------- // +void bDNA::initRecurseCmpFlags(int iter) +{ + // iter is FDF_STRUCT_NEQU + + short *oldStrc = mStructs[iter]; + short type = oldStrc[0]; + + for (int i=0; i<(int)mStructs.size(); i++) + { + if (i != iter && mCMPFlags[i] == FDF_STRUCT_EQU ) + { + short *curStruct = mStructs[i]; + int eleLen = curStruct[1]; + curStruct+=2; + + for (int j=0; jgetReverseType(typeName); + if (newLookup == -1) + { + mCMPFlags[i] = FDF_NONE; + continue; + } + short *curStruct = memDNA->mStructs[newLookup]; +#else + // memory for file + + if (oldLookup < memDNA->mStructs.size()) + { + short *curStruct = memDNA->mStructs[oldLookup]; +#endif + + + + // rebuild... + mCMPFlags[i] = FDF_STRUCT_NEQU; + +#ifndef TEST_BACKWARD_FORWARD_COMPATIBILITY + + if (curStruct[1] == oldStruct[1]) + { + // type len same ... + if (mTlens[oldStruct[0]] == memDNA->mTlens[curStruct[0]]) + { + bool isSame = true; + int elementLength = oldStruct[1]; + + + curStruct+=2; + oldStruct+=2; + + + for (int j=0; jmTypes[curStruct[0]])!=0) + { + isSame=false; + break; + } + + // name the same + if (strcmp(m_Names[oldStruct[1]].m_name, memDNA->m_Names[curStruct[1]].m_name)!=0) + { + isSame=false; + break; + } + } + // flag valid == + if (isSame) + mCMPFlags[i] = FDF_STRUCT_EQU; + } + } +#endif + } + } + + + + + + // recurse in + for ( i=0; i<(int)mStructs.size(); i++) + { + if (mCMPFlags[i] == FDF_STRUCT_NEQU) + initRecurseCmpFlags(i); + } +} + + + + +static int name_is_array(char* name, int* dim1, int* dim2) { + int len = strlen(name); + /*fprintf(stderr,"[%s]",name);*/ + /*if (len >= 1) { + if (name[len-1] != ']') + return 1; + } + return 0;*/ + char *bp; + int num; + if (dim1) { + *dim1 = 1; + } + if (dim2) { + *dim2 = 1; + } + bp = strchr(name, '['); + if (!bp) { + return 0; + } + num = 0; + while (++bp < name+len-1) { + const char c = *bp; + if (c == ']') { + break; + } + if (c <= '9' && c >= '0') { + num *= 10; + num += (c - '0'); + } else { + printf("array parse error.\n"); + return 0; + } + } + if (dim2) { + *dim2 = num; + } + + /* find second dim, if any. */ + bp = strchr(bp, '['); + if (!bp) { + return 1; /* at least we got the first dim. */ + } + num = 0; + while (++bp < name+len-1) { + const char c = *bp; + if (c == ']') { + break; + } + if (c <= '9' && c >= '0') { + num *= 10; + num += (c - '0'); + } else { + printf("array2 parse error.\n"); + return 1; + } + } + if (dim1) { + if (dim2) { + *dim1 = *dim2; + *dim2 = num; + } else { + *dim1 = num; + } + } + + return 1; +} + + +// ----------------------------------------------------- // +void bDNA::init(char *data, int len, bool swap) +{ + int *intPtr=0;short *shtPtr=0; + char *cp = 0;int dataLen =0;long nr=0; + intPtr = (int*)data; + + /* + SDNA (4 bytes) (magic number) + NAME (4 bytes) + (4 bytes) amount of names (int) + + + */ + + if (strncmp(data, "SDNA", 4)==0) + { + // skip ++ NAME + intPtr++; intPtr++; + } + + + + // Parse names + if (swap) + { + *intPtr = ChunkUtils::swapInt(*intPtr); + } + dataLen = *intPtr; + intPtr++; + + cp = (char*)intPtr; + int i; + for ( i=0; i amount of types (int) + + + */ + + intPtr = (int*)cp; + assert(strncmp(cp, "TYPE", 4)==0); intPtr++; + + if (swap) + { + *intPtr = ChunkUtils::swapInt(*intPtr); + } + dataLen = *intPtr; + intPtr++; + + cp = (char*)intPtr; + for ( i=0; i (short) the lengths of types + + */ + + // Parse type lens + intPtr = (int*)cp; + assert(strncmp(cp, "TLEN", 4)==0); intPtr++; + + dataLen = (int)mTypes.size(); + + shtPtr = (short*)intPtr; + for ( i=0; i amount of structs (int) + + + + + + + */ + + intPtr = (int*)shtPtr; + cp = (char*)intPtr; + assert(strncmp(cp, "STRC", 4)==0); intPtr++; + + if (swap) + { + *intPtr = ChunkUtils::swapInt(*intPtr); + } + dataLen = *intPtr; + intPtr++; + + + shtPtr = (short*)intPtr; + for ( i=0; itypes_count; ++i) { + /* if (!bf->types[i].is_struct)*/ + { + printf("%3d: sizeof(%s%s)=%d", + i, + bf->types[i].is_struct ? "struct " : "atomic ", + bf->types[i].name, bf->types[i].size); + if (bf->types[i].is_struct) { + int j; + printf(", %d fields: { ", bf->types[i].fieldtypes_count); + for (j=0; jtypes[i].fieldtypes_count; ++j) { + printf("%s %s", + bf->types[bf->types[i].fieldtypes[j]].name, + bf->names[bf->types[i].fieldnames[j]]); + if (j == bf->types[i].fieldtypes_count-1) { + printf(";}"); + } else { + printf("; "); + } + } + } + printf("\n\n"); + + } + } +#endif + +} + + + + +//eof + + diff --git a/Extras/Serialize/BulletFileLoader/bDNA.h b/Extras/Serialize/BulletFileLoader/bDNA.h new file mode 100644 index 0000000000..691080bf54 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/bDNA.h @@ -0,0 +1,110 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __BDNA_H__ +#define __BDNA_H__ + + +#include "bCommon.h" + +namespace bParse { + + struct bNameInfo + { + char* m_name; + bool m_isPointer; + int m_dim0; + int m_dim1; + }; + + class bDNA + { + public: + bDNA(); + ~bDNA(); + + void init(char *data, int len, bool swap=false); + + int getArraySize(char* str); + int getArraySizeNew(short name) + { + const bNameInfo& nameInfo = m_Names[name]; + return nameInfo.m_dim0*nameInfo.m_dim1; + } + int getElementSize(short type, short name) + { + const bNameInfo& nameInfo = m_Names[name]; + int size = nameInfo.m_isPointer ? mPtrLen*nameInfo.m_dim0*nameInfo.m_dim1 : mTlens[type]*nameInfo.m_dim0*nameInfo.m_dim1; + return size; + } + + int getNumNames() const + { + return m_Names.size(); + } + + char *getName(int ind); + char *getType(int ind); + short *getStruct(int ind); + short getLength(int ind); + int getReverseType(short type); + int getReverseType(const char *type); + + + int getNumStructs(); + + // + bool lessThan(bDNA* other); + + void initCmpFlags(bDNA *memDNA); + bool flagNotEqual(int dna_nr); + bool flagEqual(int dna_nr); + bool flagNone(int dna_nr); + + + int getPointerSize(); + + void dumpTypeDefinitions(); + + + private: + enum FileDNAFlags + { + FDF_NONE=0, + FDF_STRUCT_NEQU, + FDF_STRUCT_EQU + }; + + void initRecurseCmpFlags(int i); + + btAlignedObjectArray mCMPFlags; + + btAlignedObjectArray m_Names; + btAlignedObjectArray mTypes; + btAlignedObjectArray mStructs; + btAlignedObjectArray mTlens; + btHashMap mStructReverse; + btHashMap mTypeLookup; + + int mPtrLen; + + + + + }; +} + + +#endif//__BDNA_H__ diff --git a/Extras/Serialize/BulletFileLoader/bDefines.h b/Extras/Serialize/BulletFileLoader/bDefines.h new file mode 100644 index 0000000000..238df7d4bb --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/bDefines.h @@ -0,0 +1,140 @@ +/* Copyright (C) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 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. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +*/ +#ifndef __B_DEFINES_H__ +#define __B_DEFINES_H__ + + +// MISC defines, see BKE_global.h, BKE_utildefines.h +#define SIZEOFBLENDERHEADER 12 + + +// ------------------------------------------------------------ +#if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__) +# define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) ) +#else +# define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) ) +#endif + + +// ------------------------------------------------------------ +#if defined(__sgi) || defined(__sparc) || defined(__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__) +# define MAKE_ID2(c, d) ( (c)<<8 | (d) ) +# define MOST_SIG_BYTE 0 +# define BBIG_ENDIAN +#else +# define MAKE_ID2(c, d) ( (d)<<8 | (c) ) +# define MOST_SIG_BYTE 1 +# define BLITTLE_ENDIAN +#endif + +// ------------------------------------------------------------ +#define ID_SCE MAKE_ID2('S', 'C') +#define ID_LI MAKE_ID2('L', 'I') +#define ID_OB MAKE_ID2('O', 'B') +#define ID_ME MAKE_ID2('M', 'E') +#define ID_CU MAKE_ID2('C', 'U') +#define ID_MB MAKE_ID2('M', 'B') +#define ID_MA MAKE_ID2('M', 'A') +#define ID_TE MAKE_ID2('T', 'E') +#define ID_IM MAKE_ID2('I', 'M') +#define ID_IK MAKE_ID2('I', 'K') +#define ID_WV MAKE_ID2('W', 'V') +#define ID_LT MAKE_ID2('L', 'T') +#define ID_SE MAKE_ID2('S', 'E') +#define ID_LF MAKE_ID2('L', 'F') +#define ID_LA MAKE_ID2('L', 'A') +#define ID_CA MAKE_ID2('C', 'A') +#define ID_IP MAKE_ID2('I', 'P') +#define ID_KE MAKE_ID2('K', 'E') +#define ID_WO MAKE_ID2('W', 'O') +#define ID_SCR MAKE_ID2('S', 'R') +#define ID_VF MAKE_ID2('V', 'F') +#define ID_TXT MAKE_ID2('T', 'X') +#define ID_SO MAKE_ID2('S', 'O') +#define ID_SAMPLE MAKE_ID2('S', 'A') +#define ID_GR MAKE_ID2('G', 'R') +#define ID_ID MAKE_ID2('I', 'D') +#define ID_AR MAKE_ID2('A', 'R') +#define ID_AC MAKE_ID2('A', 'C') +#define ID_SCRIPT MAKE_ID2('P', 'Y') +#define ID_FLUIDSIM MAKE_ID2('F', 'S') +#define ID_NT MAKE_ID2('N', 'T') +#define ID_BR MAKE_ID2('B', 'R') + + +#define ID_SEQ MAKE_ID2('S', 'Q') +#define ID_CO MAKE_ID2('C', 'O') +#define ID_PO MAKE_ID2('A', 'C') +#define ID_NLA MAKE_ID2('N', 'L') + +#define ID_VS MAKE_ID2('V', 'S') +#define ID_VN MAKE_ID2('V', 'N') + + +// ------------------------------------------------------------ +#define FORM MAKE_ID('F','O','R','M') +#define DDG1 MAKE_ID('3','D','G','1') +#define DDG2 MAKE_ID('3','D','G','2') +#define DDG3 MAKE_ID('3','D','G','3') +#define DDG4 MAKE_ID('3','D','G','4') +#define GOUR MAKE_ID('G','O','U','R') +#define BLEN MAKE_ID('B','L','E','N') +#define DER_ MAKE_ID('D','E','R','_') +#define V100 MAKE_ID('V','1','0','0') +#define DATA MAKE_ID('D','A','T','A') +#define GLOB MAKE_ID('G','L','O','B') +#define IMAG MAKE_ID('I','M','A','G') +#define TEST MAKE_ID('T','E','S','T') +#define USER MAKE_ID('U','S','E','R') + + +// ------------------------------------------------------------ +#define DNA1 MAKE_ID('D','N','A','1') +#define REND MAKE_ID('R','E','N','D') +#define ENDB MAKE_ID('E','N','D','B') +#define NAME MAKE_ID('N','A','M','E') +#define SDNA MAKE_ID('S','D','N','A') +#define TYPE MAKE_ID('T','Y','P','E') +#define TLEN MAKE_ID('T','L','E','N') +#define STRC MAKE_ID('S','T','R','C') + + +// ------------------------------------------------------------ +#define SWITCH_INT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \ + s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; } + +// ------------------------------------------------------------ +#define SWITCH_SHORT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; } + +// ------------------------------------------------------------ +#define SWITCH_LONGINT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \ + s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \ + s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \ + s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; } + +#endif//__B_DEFINES_H__ diff --git a/Extras/Serialize/BulletFileLoader/bFile.cpp b/Extras/Serialize/BulletFileLoader/bFile.cpp new file mode 100644 index 0000000000..c0e256fc4d --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/bFile.cpp @@ -0,0 +1,1757 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ +#include "bFile.h" +#include "bCommon.h" +#include "bChunk.h" +#include "bDNA.h" +#include +#include +#include +#include "bDefines.h" +#include "LinearMath/btSerializer.h" +#include "LinearMath/btAlignedAllocator.h" +#include "LinearMath/btMinMax.h" + +#define SIZEOFBLENDERHEADER 12 +#define MAX_ARRAY_LENGTH 512 +using namespace bParse; +#define MAX_STRLEN 1024 + +const char* getCleanName(const char* memName, char* buffer) +{ + int slen = strlen(memName); + assert(slen 0) + { + if (strncmp((tempBuffer + ChunkUtils::getOffset(mFlags)), "SDNANAME", 8) ==0) + dna.oldPtr = (tempBuffer + ChunkUtils::getOffset(mFlags)); + else dna.oldPtr = 0; + } + else dna.oldPtr = 0; + } + // Some Bullet files are missing the DNA1 block + // In Blender it's DNA1 + ChunkUtils::getOffset() + SDNA + NAME + // In Bullet tests its SDNA + NAME + else if (strncmp(tempBuffer, "SDNANAME", 8) ==0) + { + dna.oldPtr = blenderData + i; + dna.len = mFileLen-i; + + // Also no REND block, so exit now. + if (mVersion==276) break; + } + + if (mDataStart && dna.oldPtr) break; + tempBuffer++; + } + if (!dna.oldPtr || !dna.len) + { + //printf("Failed to find DNA1+SDNA pair\n"); + mFlags &= ~FD_OK; + return; + } + + + mFileDNA = new bDNA(); + + + ///mFileDNA->init will convert part of DNA file endianness to current CPU endianness if necessary + mFileDNA->init((char*)dna.oldPtr, dna.len, (mFlags & FD_ENDIAN_SWAP)!=0); + + + if (mVersion==276) + { + int i; + for (i=0;igetNumNames();i++) + { + if (strcmp(mFileDNA->getName(i),"int")==0) + { + mFlags |= FD_BROKEN_DNA; + } + } + if ((mFlags&FD_BROKEN_DNA)!=0) + { + //printf("warning: fixing some broken DNA version\n"); + } + } + + + + if (verboseMode & FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS) + mFileDNA->dumpTypeDefinitions(); + + mMemoryDNA = new bDNA(); + int littleEndian= 1; + littleEndian= ((char*)&littleEndian)[0]; + + mMemoryDNA->init(memDna,memDnaLength,littleEndian==0); + + + + + ///@todo we need a better version check, add version/sub version info from FileGlobal into memory DNA/header files + if (mMemoryDNA->getNumNames() != mFileDNA->getNumNames()) + { + mFlags |= FD_VERSION_VARIES; + //printf ("Warning, file DNA is different than built in, performance is reduced. Best to re-export file with a matching version/platform"); + } + + // as long as it kept up to date it will be ok!! + if (mMemoryDNA->lessThan(mFileDNA)) + { + //printf ("Warning, file DNA is newer than built in."); + } + + + mFileDNA->initCmpFlags(mMemoryDNA); + + parseData(); + + resolvePointers(verboseMode); + + updateOldPointers(); + + +} + + + +// ----------------------------------------------------- // +void bFile::swap(char *head, bChunkInd& dataChunk, bool ignoreEndianFlag) +{ + char *data = head; + short *strc = mFileDNA->getStruct(dataChunk.dna_nr); + + + + const char s[] = "SoftBodyMaterialData"; + int szs = sizeof(s); + if (strncmp((char*)&dataChunk.code,"ARAY",4)==0) + { + short *oldStruct = mFileDNA->getStruct(dataChunk.dna_nr); + char *oldType = mFileDNA->getType(oldStruct[0]); + if (strncmp(oldType,s,szs)==0) + { + return; + } + } + + + int len = mFileDNA->getLength(strc[0]); + + for (int i=0; icode & 0xFFFF)==0) + c->code >>=16; + SWITCH_INT(c->len); + SWITCH_INT(c->dna_nr); + SWITCH_INT(c->nr); + } else + { + bChunkPtr8* c = (bChunkPtr8*) dataPtr; + if ((c->code & 0xFFFF)==0) + c->code >>=16; + SWITCH_INT(c->len); + SWITCH_INT(c->dna_nr); + SWITCH_INT(c->nr); + + } + } else + { + if (mFlags &FD_BITS_VARIES) + { + bChunkPtr8*c = (bChunkPtr8*) dataPtr; + if ((c->code & 0xFFFF)==0) + c->code >>=16; + SWITCH_INT(c->len); + SWITCH_INT(c->dna_nr); + SWITCH_INT(c->nr); + + } else + { + bChunkPtr4* c = (bChunkPtr4*) dataPtr; + if ((c->code & 0xFFFF)==0) + c->code >>=16; + SWITCH_INT(c->len); + + SWITCH_INT(c->dna_nr); + SWITCH_INT(c->nr); + + } + } + +} + + +void bFile::swapDNA(char* ptr) +{ + bool swap = ((mFlags & FD_ENDIAN_SWAP)!=0); + + char* data = &ptr[20]; +// void bDNA::init(char *data, int len, bool swap) + int *intPtr=0;short *shtPtr=0; + char *cp = 0;int dataLen =0;long nr=0; + intPtr = (int*)data; + + /* + SDNA (4 bytes) (magic number) + NAME (4 bytes) + (4 bytes) amount of names (int) + + + */ + + if (strncmp(data, "SDNA", 4)==0) + { + // skip ++ NAME + intPtr++; intPtr++; + } + + + + // Parse names + if (swap) + dataLen = ChunkUtils::swapInt(*intPtr); + else + dataLen = *intPtr; + + *intPtr = ChunkUtils::swapInt(*intPtr); + intPtr++; + + cp = (char*)intPtr; + int i; + for ( i=0; i amount of types (int) + + + */ + + intPtr = (int*)cp; + assert(strncmp(cp, "TYPE", 4)==0); intPtr++; + + if (swap) + dataLen = ChunkUtils::swapInt(*intPtr); + else + dataLen = *intPtr; + + *intPtr = ChunkUtils::swapInt(*intPtr); + + intPtr++; + + cp = (char*)intPtr; + for ( i=0; i (short) the lengths of types + + */ + + // Parse type lens + intPtr = (int*)cp; + assert(strncmp(cp, "TLEN", 4)==0); intPtr++; + + + shtPtr = (short*)intPtr; + for ( i=0; i amount of structs (int) + + + + + + + */ + + intPtr = (int*)shtPtr; + cp = (char*)intPtr; + assert(strncmp(cp, "STRC", 4)==0); + intPtr++; + + if (swap) + dataLen = ChunkUtils::swapInt(*intPtr); + else + dataLen = *intPtr; + + *intPtr = ChunkUtils::swapInt(*intPtr); + + intPtr++; + + + shtPtr = (short*)intPtr; + for ( i=0; i=0) + { + swap(dataPtrHead, dataChunk,ignoreEndianFlag); + } else + { + printf("unknown chunk\n"); + } + } + + // next please! + dataPtr += seek; + + seek = getNextBlock(&dataChunk, dataPtr, mFlags); + if (seek < 0) + break; + } + + if (mFlags & FD_ENDIAN_SWAP) + { + mFlags &= ~FD_ENDIAN_SWAP; + } else + { + mFlags |= FD_ENDIAN_SWAP; + } + + + +} + + +// ----------------------------------------------------- // +char* bFile::readStruct(char *head, bChunkInd& dataChunk) +{ + bool ignoreEndianFlag = false; + + if (mFlags & FD_ENDIAN_SWAP) + swap(head, dataChunk, ignoreEndianFlag); + + + + if (!mFileDNA->flagEqual(dataChunk.dna_nr)) + { + // Ouch! need to rebuild the struct + short *oldStruct,*curStruct; + char *oldType, *newType; + int oldLen, curLen, reverseOld; + + + oldStruct = mFileDNA->getStruct(dataChunk.dna_nr); + oldType = mFileDNA->getType(oldStruct[0]); + + oldLen = mFileDNA->getLength(oldStruct[0]); + + if ((mFlags&FD_BROKEN_DNA)!=0) + { + if ((strcmp(oldType,"btQuantizedBvhNodeData")==0)&&oldLen==20) + { + return 0; + } + if ((strcmp(oldType,"btShortIntIndexData")==0)) + { + int allocLen = 2; + char *dataAlloc = new char[(dataChunk.nr*allocLen)+1]; + memset(dataAlloc, 0, (dataChunk.nr*allocLen)+1); + short* dest = (short*) dataAlloc; + const short* src = (short*) head; + for (int i=0;igetReverseType(oldType); + + if ((reverseOld!=-1)) + { + // make sure it's here + //assert(reverseOld!= -1 && "getReverseType() returned -1, struct required!"); + + // + curStruct = mMemoryDNA->getStruct(reverseOld); + newType = mMemoryDNA->getType(curStruct[0]); + curLen = mMemoryDNA->getLength(curStruct[0]); + + + + // make sure it's the same + assert((strcmp(oldType, newType)==0) && "internal error, struct mismatch!"); + + + numallocs++; + // numBlocks * length + + int allocLen = (curLen); + char *dataAlloc = new char[(dataChunk.nr*allocLen)+1]; + memset(dataAlloc, 0, (dataChunk.nr*allocLen)); + + // track allocated + addDataBlock(dataAlloc); + + char *cur = dataAlloc; + char *old = head; + for (int block=0; blockgetStruct(dataChunk.dna_nr); + oldType = mFileDNA->getType(oldStruct[0]); + printf("%s equal structure, just memcpy\n",oldType); +#endif // + } + + + char *dataAlloc = new char[(dataChunk.len)+1]; + memset(dataAlloc, 0, dataChunk.len+1); + + + // track allocated + addDataBlock(dataAlloc); + + memcpy(dataAlloc, head, dataChunk.len); + return dataAlloc; + +} + + +// ----------------------------------------------------- // +void bFile::parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers) +{ + if (old_dna == -1) return; + if (new_dna == -1) return; + + //disable this, because we need to fixup pointers/ListBase + if (0)//mFileDNA->flagEqual(old_dna)) + { + short *strc = mFileDNA->getStruct(old_dna); + int len = mFileDNA->getLength(strc[0]); + + memcpy(strcPtr, dtPtr, len); + return; + } + + // Ok, now build the struct + char *memType, *memName, *cpc, *cpo; + short *fileStruct, *filePtrOld, *memoryStruct, *firstStruct; + int elementLength, size, revType, old_nr, new_nr, fpLen; + short firstStructType; + + + // File to memory lookup + memoryStruct = mMemoryDNA->getStruct(new_dna); + fileStruct = mFileDNA->getStruct(old_dna); + firstStruct = fileStruct; + + + filePtrOld = fileStruct; + firstStructType = mMemoryDNA->getStruct(0)[0]; + + // Get number of elements + elementLength = memoryStruct[1]; + memoryStruct+=2; + + cpc = strcPtr; cpo = 0; + for (int ele=0; elegetType(memoryStruct[0]); + memName = mMemoryDNA->getName(memoryStruct[1]); + + + size = mMemoryDNA->getElementSize(memoryStruct[0], memoryStruct[1]); + revType = mMemoryDNA->getReverseType(memoryStruct[0]); + + if (revType != -1 && memoryStruct[0]>=firstStructType && memName[0] != '*') + { + cpo = getFileElement(firstStruct, memName, memType, dtPtr, &filePtrOld); + if (cpo) + { + int arrayLen = mFileDNA->getArraySizeNew(filePtrOld[1]); + old_nr = mFileDNA->getReverseType(memType); + new_nr = revType; + fpLen = mFileDNA->getElementSize(filePtrOld[0], filePtrOld[1]); + if (arrayLen==1) + { + parseStruct(cpc, cpo, old_nr, new_nr,fixupPointers); + } else + { + char* tmpCpc = cpc; + char* tmpCpo = cpo; + + for (int i=0;i3 && type <8) + { + char c; + char *cp = data; + for (int i=0; igetPointerSize(); + int ptrMem = mMemoryDNA->getPointerSize(); + + if (!src && !dst) + return; + + + if (ptrFile == ptrMem) + { + memcpy(dst, src, ptrMem); + } + else if (ptrMem==4 && ptrFile==8) + { + btPointerUid* oldPtr = (btPointerUid*)src; + btPointerUid* newPtr = (btPointerUid*)dst; + + if (oldPtr->m_uniqueIds[0] == oldPtr->m_uniqueIds[1]) + { + //Bullet stores the 32bit unique ID in both upper and lower part of 64bit pointers + //so it can be used to distinguish between .blend and .bullet + newPtr->m_uniqueIds[0] = oldPtr->m_uniqueIds[0]; + } else + { + //deal with pointers the Blender .blend style way, see + //readfile.c in the Blender source tree + long64 longValue = *((long64*)src); + //endian swap for 64bit pointer otherwise truncation will fail due to trailing zeros + if (mFlags & FD_ENDIAN_SWAP) + SWITCH_LONGINT(longValue); + *((int*)dst) = (int)(longValue>>3); + } + + } + else if (ptrMem==8 && ptrFile==4) + { + btPointerUid* oldPtr = (btPointerUid*)src; + btPointerUid* newPtr = (btPointerUid*)dst; + if (oldPtr->m_uniqueIds[0] == oldPtr->m_uniqueIds[1]) + { + newPtr->m_uniqueIds[0] = oldPtr->m_uniqueIds[0]; + newPtr->m_uniqueIds[1] = 0; + } else + { + *((long64*)dst)= *((int*)src); + } + } + else + { + printf ("%d %d\n", ptrFile,ptrMem); + assert(0 && "Invalid pointer len"); + } + + +} + + +// ----------------------------------------------------- // +void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const char* lookupType, char *strcData, char *data, bool fixupPointers) +{ + // find the matching memory dna data + // to the file being loaded. Fill the + // memory with the file data... + + int len = dna_addr[1]; + dna_addr+=2; + + for (int i=0; igetType(dna_addr[0]); + const char* name = mFileDNA->getName(dna_addr[1]); + + + + int eleLen = mFileDNA->getElementSize(dna_addr[0], dna_addr[1]); + + if ((mFlags&FD_BROKEN_DNA)!=0) + { + if ((strcmp(type,"short")==0)&&(strcmp(name,"int")==0)) + { + eleLen = 0; + } + } + + if (strcmp(lookupName, name)==0) + { + //int arrayLenold = mFileDNA->getArraySize((char*)name.c_str()); + int arrayLen = mFileDNA->getArraySizeNew(dna_addr[1]); + //assert(arrayLenold == arrayLen); + + if (name[0] == '*') + { + // cast pointers + int ptrFile = mFileDNA->getPointerSize(); + int ptrMem = mMemoryDNA->getPointerSize(); + safeSwapPtr(strcData,data); + + if (fixupPointers) + { + if (arrayLen > 1) + { + //void **sarray = (void**)strcData; + //void **darray = (void**)data; + + char *cpc, *cpo; + cpc = (char*)strcData; + cpo = (char*)data; + + for (int a=0; agetStruct(old_nr); + int elementLength = old[1]; + old+=2; + + for (int i=0; igetType(old[0]); + char* name = mFileDNA->getName(old[1]); + int len = mFileDNA->getElementSize(old[0], old[1]); + + if (strcmp(lookupName, name)==0) + { + if (strcmp(type, lookupType)==0) + { + if (foundPos) + *foundPos = old; + return data; + } + return 0; + } + data+=len; + } + return 0; +} + + +// ----------------------------------------------------- // +void bFile::swapStruct(int dna_nr, char *data,bool ignoreEndianFlag) +{ + if (dna_nr == -1) return; + + short *strc = mFileDNA->getStruct(dna_nr); + //short *firstStrc = strc; + + int elementLen= strc[1]; + strc+=2; + + short first = mFileDNA->getStruct(0)[0]; + + char *buf = data; + for (int i=0; igetType(strc[0]); + char *name = mFileDNA->getName(strc[1]); + + int size = mFileDNA->getElementSize(strc[0], strc[1]); + if (strc[0] >= first && name[0]!='*') + { + int old_nr = mFileDNA->getReverseType(type); + int arrayLen = mFileDNA->getArraySizeNew(strc[1]); + if (arrayLen==1) + { + swapStruct(old_nr,buf,ignoreEndianFlag); + } else + { + char* tmpBuf = buf; + for (int i=0;igetArraySize(name); + int arrayLen = mFileDNA->getArraySizeNew(strc[1]); + //assert(arrayLenOld == arrayLen); + swapData(buf, strc[0], arrayLen,ignoreEndianFlag); + } + buf+=size; + } +} + +void bFile::resolvePointersMismatch() +{ +// printf("resolvePointersStructMismatch\n"); + + int i; + + for (i=0;i< m_pointerFixupArray.size();i++) + { + char* cur = m_pointerFixupArray.at(i); + void** ptrptr = (void**) cur; + void* ptr = *ptrptr; + ptr = findLibPointer(ptr); + if (ptr) + { + //printf("Fixup pointer!\n"); + *(ptrptr) = ptr; + } else + { +// printf("pointer not found: %x\n",cur); + } + } + + + for (i=0; igetPointerSize(); + int ptrFile = mFileDNA->getPointerSize(); + + + int blockLen = block->len / ptrFile; + + void *onptr = findLibPointer(*ptrptr); + if (onptr) + { + char *newPtr = new char[blockLen * ptrMem]; + addDataBlock(newPtr); + memset(newPtr, 0, blockLen * ptrMem); + + void **onarray = (void**)onptr; + char *oldPtr = (char*)onarray; + + int p = 0; + while (blockLen-- > 0) + { + btPointerUid dp = {0}; + safeSwapPtr((char*)dp.m_uniqueIds, oldPtr); + + void **tptr = (void**)(newPtr + p * ptrMem); + *tptr = findLibPointer(dp.m_ptr); + + oldPtr += ptrFile; + ++p; + } + + *ptrptr = newPtr; + } + } + } +} + + +///this loop only works fine if the Blender DNA structure of the file matches the headerfiles +void bFile::resolvePointersChunk(const bChunkInd& dataChunk, int verboseMode) +{ + bParse::bDNA* fileDna = mFileDNA ? mFileDNA : mMemoryDNA; + + short int* oldStruct = fileDna->getStruct(dataChunk.dna_nr); + short oldLen = fileDna->getLength(oldStruct[0]); + //char* structType = fileDna->getType(oldStruct[0]); + + char* cur = (char*)findLibPointer(dataChunk.oldPtr); + for (int block=0; blockgetStruct(0)[0]; + + + char* elemPtr= strcPtr; + + short int* oldStruct = fileDna->getStruct(dna_nr); + + int elementLength = oldStruct[1]; + oldStruct+=2; + + int totalSize = 0; + + for (int ele=0; elegetType(oldStruct[0]); + memName = fileDna->getName(oldStruct[1]); + + + + int arrayLen = fileDna->getArraySizeNew(oldStruct[1]); + if (memName[0] == '*') + { + if (arrayLen > 1) + { + void **array= (void**)elemPtr; + for (int a=0; a ",&memName[1]); + printf("%d ", array[a]); + printf("\n",&memName[1]); + } + + array[a] = findLibPointer(array[a]); + } + } + else + { + void** ptrptr = (void**) elemPtr; + void* ptr = *ptrptr; + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + for (int i=0;i ",&memName[1]); + printf("%d ", ptr); + printf("\n",&memName[1]); + } + ptr = findLibPointer(ptr); + + if (ptr) + { + // printf("Fixup pointer at 0x%x from 0x%x to 0x%x!\n",ptrptr,*ptrptr,ptr); + *(ptrptr) = ptr; + if (memName[1] == '*' && ptrptr && *ptrptr) + { + // This will only work if the given **array is continuous + void **array= (void**)*(ptrptr); + void *np= array[0]; + int n=0; + while (np) + { + np= findLibPointer(array[n]); + if (np) array[n]= np; + n++; + } + } + } else + { + // printf("Cannot fixup pointer at 0x%x from 0x%x to 0x%x!\n",ptrptr,*ptrptr,ptr); + } + } + } else + { + int revType = fileDna->getReverseType(oldStruct[0]); + if (oldStruct[0]>=firstStructType) //revType != -1 && + { + char cleanName[MAX_STRLEN]; + getCleanName(memName,cleanName); + + int arrayLen = fileDna->getArraySizeNew(oldStruct[1]); + int byteOffset = 0; + + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + for (int i=0;i1) + { + printf("<%s type=\"%s\" count=%d>\n",cleanName,memType, arrayLen); + } else + { + printf("<%s type=\"%s\">\n",cleanName,memType); + } + } + + for (int i=0;i\n",cleanName); + } + } else + { + //export a simple type + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + + if (arrayLen>MAX_ARRAY_LENGTH) + { + printf("too long\n"); + } else + { + //printf("%s %s\n",memType,memName); + + bool isIntegerType = (strcmp(memType,"char")==0) || (strcmp(memType,"int")==0) || (strcmp(memType,"short")==0); + + if (isIntegerType) + { + const char* newtype="int"; + int dbarray[MAX_ARRAY_LENGTH]; + int* dbPtr = 0; + char* tmp = elemPtr; + dbPtr = &dbarray[0]; + if (dbPtr) + { + char cleanName[MAX_STRLEN]; + getCleanName(memName,cleanName); + + int i; + getElement(arrayLen, newtype,memType, tmp, (char*)dbPtr); + for (i=0;i",cleanName,memType); + else + printf("<%s type=\"%s\" count=%d>",cleanName,memType,arrayLen); + for (i=0;i\n",cleanName); + } + } else + { + const char* newtype="double"; + double dbarray[MAX_ARRAY_LENGTH]; + double* dbPtr = 0; + char* tmp = elemPtr; + dbPtr = &dbarray[0]; + if (dbPtr) + { + int i; + getElement(arrayLen, newtype,memType, tmp, (char*)dbPtr); + for (i=0;i",memName,memType); + } + else + { + printf("<%s type=\"%s\" count=%d>",cleanName,memType,arrayLen); + } + for (i=0;i\n",cleanName); + } + } + } + + } + } + } + + int size = fileDna->getElementSize(oldStruct[0], oldStruct[1]); + totalSize += size; + elemPtr+=size; + + } + + return totalSize; +} + + +///Resolve pointers replaces the original pointers in structures, and linked lists by the new in-memory structures +void bFile::resolvePointers(int verboseMode) +{ + bParse::bDNA* fileDna = mFileDNA ? mFileDNA : mMemoryDNA; + + //char *dataPtr = mFileBuffer+mDataStart; + + if (1) //mFlags & (FD_BITS_VARIES | FD_VERSION_VARIES)) + { + resolvePointersMismatch(); + } + + { + + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + printf("\n"); + int numitems = m_chunks.size(); + printf("\n", btGetVersion(), numitems); + } + for (int i=0;iflagEqual(dataChunk.dna_nr)) + { + //dataChunk.len + short int* oldStruct = fileDna->getStruct(dataChunk.dna_nr); + char* oldType = fileDna->getType(oldStruct[0]); + + if (verboseMode & FD_VERBOSE_EXPORT_XML) + printf(" <%s pointer=%d>\n",oldType,dataChunk.oldPtr); + + resolvePointersChunk(dataChunk, verboseMode); + + if (verboseMode & FD_VERBOSE_EXPORT_XML) + printf(" \n",oldType); + } else + { + //printf("skipping mStruct\n"); + } + } + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + printf("\n"); + } + } + + +} + + +// ----------------------------------------------------- // +void* bFile::findLibPointer(void *ptr) +{ + + bStructHandle** ptrptr = getLibPointers().find(ptr); + if (ptrptr) + return *ptrptr; + return 0; +} + + +void bFile::updateOldPointers() +{ + int i; + + for (i=0;igetStruct(dataChunk.dna_nr); + char* typeName = dna->getType(newStruct[0]); + printf("%3d: %s ",i,typeName); + + printf("code=%s ",codestr); + + printf("ptr=%p ",dataChunk.oldPtr); + printf("len=%d ",dataChunk.len); + printf("nr=%d ",dataChunk.nr); + if (dataChunk.nr!=1) + { + printf("not 1\n"); + } + printf("\n"); + + + + + } + +#if 0 + IDFinderData ifd; + ifd.success = 0; + ifd.IDname = NULL; + ifd.just_print_it = 1; + for (i=0; im_blocks.size(); ++i) + { + BlendBlock* bb = bf->m_blocks[i]; + printf("tag='%s'\tptr=%p\ttype=%s\t[%4d]", bb->tag, bb,bf->types[bb->type_index].name,bb->m_array_entries_.size()); + block_ID_finder(bb, bf, &ifd); + printf("\n"); + } +#endif + +} + + +void bFile::writeChunks(FILE* fp, bool fixupPointers) +{ + bParse::bDNA* fileDna = mFileDNA ? mFileDNA : mMemoryDNA; + + for (int i=0;igetStruct(dataChunk.dna_nr); + oldType = fileDna->getType(oldStruct[0]); + oldLen = fileDna->getLength(oldStruct[0]); + ///don't try to convert Link block data, just memcpy it. Other data can be converted. + reverseOld = mMemoryDNA->getReverseType(oldType); + + + if ((reverseOld!=-1)) + { + // make sure it's here + //assert(reverseOld!= -1 && "getReverseType() returned -1, struct required!"); + // + curStruct = mMemoryDNA->getStruct(reverseOld); + newType = mMemoryDNA->getType(curStruct[0]); + // make sure it's the same + assert((strcmp(oldType, newType)==0) && "internal error, struct mismatch!"); + + + curLen = mMemoryDNA->getLength(curStruct[0]); + dataChunk.dna_nr = reverseOld; + if (strcmp("Link",oldType)!=0) + { + dataChunk.len = curLen * dataChunk.nr; + } else + { +// printf("keep length of link = %d\n",dataChunk.len); + } + + //write the structure header + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + + + + short int* curStruct1; + curStruct1 = mMemoryDNA->getStruct(dataChunk.dna_nr); + assert(curStruct1 == curStruct); + + char* cur = fixupPointers ? (char*)findLibPointer(dataChunk.oldPtr) : (char*)dataChunk.oldPtr; + + //write the actual contents of the structure(s) + fwrite(cur,dataChunk.len,1,fp); + } else + { + printf("serious error, struct mismatch: don't write\n"); + } + } + +} + + +// ----------------------------------------------------- // +int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags) +{ + bool swap = false; + bool varies = false; + + if (flags &FD_ENDIAN_SWAP) + swap = true; + if (flags &FD_BITS_VARIES) + varies = true; + + if (VOID_IS_8) + { + if (varies) + { + bChunkPtr4 head; + memcpy(&head, dataPtr, sizeof(bChunkPtr4)); + + + bChunkPtr8 chunk; + + chunk.code = head.code; + chunk.len = head.len; + chunk.m_uniqueInts[0] = head.m_uniqueInt; + chunk.m_uniqueInts[1] = 0; + chunk.dna_nr = head.dna_nr; + chunk.nr = head.nr; + + if (swap) + { + if ((chunk.code & 0xFFFF)==0) + chunk.code >>=16; + + SWITCH_INT(chunk.len); + SWITCH_INT(chunk.dna_nr); + SWITCH_INT(chunk.nr); + } + + + memcpy(dataChunk, &chunk, sizeof(bChunkInd)); + } + else + { + bChunkPtr8 c; + memcpy(&c, dataPtr, sizeof(bChunkPtr8)); + + if (swap) + { + if ((c.code & 0xFFFF)==0) + c.code >>=16; + + SWITCH_INT(c.len); + SWITCH_INT(c.dna_nr); + SWITCH_INT(c.nr); + } + + memcpy(dataChunk, &c, sizeof(bChunkInd)); + } + } + else + { + if (varies) + { + bChunkPtr8 head; + memcpy(&head, dataPtr, sizeof(bChunkPtr8)); + + + bChunkPtr4 chunk; + chunk.code = head.code; + chunk.len = head.len; + + if (head.m_uniqueInts[0]==head.m_uniqueInts[1]) + { + chunk.m_uniqueInt = head.m_uniqueInts[0]; + } else + { + long64 oldPtr =0; + memcpy(&oldPtr, &head.m_uniqueInts[0], 8); + if (swap) + SWITCH_LONGINT(oldPtr); + chunk.m_uniqueInt = (int)(oldPtr >> 3); + } + + + chunk.dna_nr = head.dna_nr; + chunk.nr = head.nr; + + if (swap) + { + if ((chunk.code & 0xFFFF)==0) + chunk.code >>=16; + + SWITCH_INT(chunk.len); + SWITCH_INT(chunk.dna_nr); + SWITCH_INT(chunk.nr); + } + + memcpy(dataChunk, &chunk, sizeof(bChunkInd)); + } + else + { + bChunkPtr4 c; + memcpy(&c, dataPtr, sizeof(bChunkPtr4)); + + if (swap) + { + if ((c.code & 0xFFFF)==0) + c.code >>=16; + + SWITCH_INT(c.len); + SWITCH_INT(c.dna_nr); + SWITCH_INT(c.nr); + } + memcpy(dataChunk, &c, sizeof(bChunkInd)); + } + } + + if (dataChunk->len < 0) + return -1; + +#if 0 + print ("----------"); + print (dataChunk->code); + print (dataChunk->len); + print (dataChunk->old); + print (dataChunk->dna_nr); + print (dataChunk->nr); +#endif + return (dataChunk->len+ChunkUtils::getOffset(flags)); +} + + + +//eof diff --git a/Extras/Serialize/BulletFileLoader/bFile.h b/Extras/Serialize/BulletFileLoader/bFile.h new file mode 100644 index 0000000000..9df95adf3e --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/bFile.h @@ -0,0 +1,165 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __BFILE_H__ +#define __BFILE_H__ + +#include "bCommon.h" +#include "bChunk.h" +#include + +namespace bParse { + + // ----------------------------------------------------- // + enum bFileFlags + { + FD_INVALID =0, + FD_OK =1, + FD_VOID_IS_8 =2, + FD_ENDIAN_SWAP =4, + FD_FILE_64 =8, + FD_BITS_VARIES =16, + FD_VERSION_VARIES = 32, + FD_DOUBLE_PRECISION =64, + FD_BROKEN_DNA = 128 + }; + + enum bFileVerboseMode + { + FD_VERBOSE_EXPORT_XML = 1, + FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS = 2, + FD_VERBOSE_DUMP_CHUNKS = 4, + FD_VERBOSE_DUMP_FILE_INFO=8, + }; + // ----------------------------------------------------- // + class bFile + { + protected: + + char m_headerString[7]; + + bool mOwnsBuffer; + char* mFileBuffer; + int mFileLen; + int mVersion; + + + bPtrMap mLibPointers; + + int mDataStart; + bDNA* mFileDNA; + bDNA* mMemoryDNA; + + btAlignedObjectArray m_pointerFixupArray; + btAlignedObjectArray m_pointerPtrFixupArray; + + btAlignedObjectArray m_chunks; + btHashMap m_chunkPtrPtrMap; + + // + + bPtrMap mDataPointers; + + + int mFlags; + + // //////////////////////////////////////////////////////////////////////////// + + // buffer offset util + int getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags); + void safeSwapPtr(char *dst, const char *src); + + virtual void parseHeader(); + + virtual void parseData() = 0; + + void resolvePointersMismatch(); + void resolvePointersChunk(const bChunkInd& dataChunk, int verboseMode); + + int resolvePointersStructRecursive(char *strcPtr, int old_dna, int verboseMode, int recursion); + //void swapPtr(char *dst, char *src); + + void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers); + void getMatchingFileDNA(short* old, const char* lookupName, const char* lookupType, char *strcData, char *data, bool fixupPointers); + char* getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos); + + + void swap(char *head, class bChunkInd& ch, bool ignoreEndianFlag); + void swapData(char *data, short type, int arraySize, bool ignoreEndianFlag); + void swapStruct(int dna_nr, char *data, bool ignoreEndianFlag); + void swapLen(char *dataPtr); + void swapDNA(char* ptr); + + + char* readStruct(char *head, class bChunkInd& chunk); + char *getAsString(int code); + + void parseInternal(int verboseMode, char* memDna,int memDnaLength); + + public: + bFile(const char *filename, const char headerString[7]); + + //todo: make memoryBuffer const char + //bFile( const char *memoryBuffer, int len); + bFile( char *memoryBuffer, int len, const char headerString[7]); + virtual ~bFile(); + + bDNA* getFileDNA() + { + return mFileDNA; + } + + virtual void addDataBlock(char* dataBlock) = 0; + + int getFlags() const + { + return mFlags; + } + + bPtrMap& getLibPointers() + { + return mLibPointers; + } + + void* findLibPointer(void *ptr); + + bool ok(); + + virtual void parse(int verboseMode) = 0; + + virtual int write(const char* fileName, bool fixupPointers=false) = 0; + + virtual void writeChunks(FILE* fp, bool fixupPointers ); + + virtual void writeDNA(FILE* fp) = 0; + + void updateOldPointers(); + void resolvePointers(int verboseMode); + + void dumpChunks(bDNA* dna); + + int getVersion() const + { + return mVersion; + } + //pre-swap the endianness, so that data loaded on a target with different endianness doesn't need to be swapped + void preSwap(); + void writeFile(const char* fileName); + + }; +} + + +#endif//__BFILE_H__ diff --git a/Extras/Serialize/BulletFileLoader/btBulletFile.cpp b/Extras/Serialize/BulletFileLoader/btBulletFile.cpp new file mode 100644 index 0000000000..3ecf8851e6 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/btBulletFile.cpp @@ -0,0 +1,423 @@ +/* +bParse +Copyright (c) 2006-2010 Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "btBulletFile.h" +#include "bDefines.h" +#include "bDNA.h" + +#if !defined( __CELLOS_LV2__) && !defined(__MWERKS__) +#include +#endif +#include + + +// 32 && 64 bit versions +#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES +#ifdef _WIN64 +extern char sBulletDNAstr64[]; +extern int sBulletDNAlen64; +#else +extern char sBulletDNAstr[]; +extern int sBulletDNAlen; +#endif //_WIN64 +#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + +extern char sBulletDNAstr64[]; +extern int sBulletDNAlen64; +extern char sBulletDNAstr[]; +extern int sBulletDNAlen; + +#endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + +using namespace bParse; + +btBulletFile::btBulletFile() +:bFile("", "BULLET ") +{ + mMemoryDNA = new bDNA(); //this memory gets released in the bFile::~bFile destructor,@todo not consistent with the rule 'who allocates it, has to deallocate it" + + m_DnaCopy = 0; + + +#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES +#ifdef _WIN64 + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64,16); + memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64); + mMemoryDNA->init(m_DnaCopy,sBulletDNAlen64); +#else//_WIN64 + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen,16); + memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen); + mMemoryDNA->init(m_DnaCopy,sBulletDNAlen); +#endif//_WIN64 +#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { + m_DnaCopy = (char*) btAlignedAlloc(sBulletDNAlen64,16); + memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64); + mMemoryDNA->init(m_DnaCopy,sBulletDNAlen64); + } + else + { + m_DnaCopy =(char*) btAlignedAlloc(sBulletDNAlen,16); + memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen); + mMemoryDNA->init(m_DnaCopy,sBulletDNAlen); + } +#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES +} + + + +btBulletFile::btBulletFile(const char* fileName) +:bFile(fileName, "BULLET ") +{ + m_DnaCopy = 0; +} + + + +btBulletFile::btBulletFile(char *memoryBuffer, int len) +:bFile(memoryBuffer,len, "BULLET ") +{ + m_DnaCopy = 0; +} + + +btBulletFile::~btBulletFile() +{ + if (m_DnaCopy) + btAlignedFree(m_DnaCopy); + + + while (m_dataBlocks.size()) + { + char* dataBlock = m_dataBlocks[m_dataBlocks.size()-1]; + delete[] dataBlock; + m_dataBlocks.pop_back(); + } + +} + + + +// ----------------------------------------------------- // +void btBulletFile::parseData() +{ +// printf ("Building datablocks"); +// printf ("Chunk size = %d",CHUNK_HEADER_LEN); +// printf ("File chunk size = %d",ChunkUtils::getOffset(mFlags)); + + const bool brokenDNA = (mFlags&FD_BROKEN_DNA)!=0; + + //const bool swap = (mFlags&FD_ENDIAN_SWAP)!=0; + + + mDataStart = 12; + + char *dataPtr = mFileBuffer+mDataStart; + + bChunkInd dataChunk; + dataChunk.code = 0; + + + //dataPtr += ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags); + int seek = getNextBlock(&dataChunk, dataPtr, mFlags); + + + if (mFlags &FD_ENDIAN_SWAP) + swapLen(dataPtr); + + //dataPtr += ChunkUtils::getOffset(mFlags); + char *dataPtrHead = 0; + + while (dataChunk.code != DNA1) + { + if (!brokenDNA || (dataChunk.code != BT_QUANTIZED_BVH_CODE) ) + { + + // one behind + if (dataChunk.code == SDNA) break; + //if (dataChunk.code == DNA1) break; + + // same as (BHEAD+DATA dependency) + dataPtrHead = dataPtr+ChunkUtils::getOffset(mFlags); + if (dataChunk.dna_nr>=0) + { + char *id = readStruct(dataPtrHead, dataChunk); + + // lookup maps + if (id) + { + m_chunkPtrPtrMap.insert(dataChunk.oldPtr, dataChunk); + mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)id); + + m_chunks.push_back(dataChunk); + // block it + //bListBasePtr *listID = mMain->getListBasePtr(dataChunk.code); + //if (listID) + // listID->push_back((bStructHandle*)id); + } + + if (dataChunk.code == BT_SOFTBODY_CODE) + { + m_softBodies.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_RIGIDBODY_CODE) + { + m_rigidBodies.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_DYNAMICSWORLD_CODE) + { + m_dynamicsWorldInfo.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_CONSTRAINT_CODE) + { + m_constraints.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_QUANTIZED_BVH_CODE) + { + m_bvhs.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_TRIANLGE_INFO_MAP) + { + m_triangleInfoMaps.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_COLLISIONOBJECT_CODE) + { + m_collisionObjects.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_SHAPE_CODE) + { + m_collisionShapes.push_back((bStructHandle*) id); + } + + // if (dataChunk.code == GLOB) + // { + // m_glob = (bStructHandle*) id; + // } + } else + { + printf("unknown chunk\n"); + + mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)dataPtrHead); + } + } else + { + printf("skipping BT_QUANTIZED_BVH_CODE due to broken DNA\n"); + } + + + dataPtr += seek; + + seek = getNextBlock(&dataChunk, dataPtr, mFlags); + if (mFlags &FD_ENDIAN_SWAP) + swapLen(dataPtr); + + if (seek < 0) + break; + } + +} + +void btBulletFile::addDataBlock(char* dataBlock) +{ + m_dataBlocks.push_back(dataBlock); + +} + + + + +void btBulletFile::writeDNA(FILE* fp) +{ + + bChunkInd dataChunk; + dataChunk.code = DNA1; + dataChunk.dna_nr = 0; + dataChunk.nr = 1; +#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { +#ifdef _WIN64 + dataChunk.len = sBulletDNAlen64; + dataChunk.oldPtr = sBulletDNAstr64; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(sBulletDNAstr64, sBulletDNAlen64,1,fp); +#else + btAssert(0); +#endif + } + else + { +#ifndef _WIN64 + dataChunk.len = sBulletDNAlen; + dataChunk.oldPtr = sBulletDNAstr; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(sBulletDNAstr, sBulletDNAlen,1,fp); +#else//_WIN64 + btAssert(0); +#endif//_WIN64 + } +#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { + dataChunk.len = sBulletDNAlen64; + dataChunk.oldPtr = sBulletDNAstr64; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(sBulletDNAstr64, sBulletDNAlen64,1,fp); + } + else + { + dataChunk.len = sBulletDNAlen; + dataChunk.oldPtr = sBulletDNAstr; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(sBulletDNAstr, sBulletDNAlen,1,fp); + } +#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES +} + + +void btBulletFile::parse(int verboseMode) +{ +#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { +#ifdef _WIN64 + + if (m_DnaCopy) + delete m_DnaCopy; + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64,16); + memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64); + parseInternal(verboseMode,(char*)sBulletDNAstr64,sBulletDNAlen64); +#else + btAssert(0); +#endif + } + else + { +#ifndef _WIN64 + + if (m_DnaCopy) + delete m_DnaCopy; + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen,16); + memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen); + parseInternal(verboseMode,m_DnaCopy,sBulletDNAlen); +#else + btAssert(0); +#endif + } +#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { + if (m_DnaCopy) + delete m_DnaCopy; + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64,16); + memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64); + parseInternal(verboseMode,m_DnaCopy,sBulletDNAlen64); + } + else + { + if (m_DnaCopy) + delete m_DnaCopy; + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen,16); + memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen); + parseInternal(verboseMode,m_DnaCopy,sBulletDNAlen); + } +#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + + //the parsing will convert to cpu endian + mFlags &=~FD_ENDIAN_SWAP; + + int littleEndian= 1; + littleEndian= ((char*)&littleEndian)[0]; + + mFileBuffer[8] = littleEndian?'v':'V'; + +} + +// experimental +int btBulletFile::write(const char* fileName, bool fixupPointers) +{ + FILE *fp = fopen(fileName, "wb"); + if (fp) + { + char header[SIZEOFBLENDERHEADER] ; + memcpy(header, m_headerString, 7); + int endian= 1; + endian= ((char*)&endian)[0]; + + if (endian) + { + header[7] = '_'; + } else + { + header[7] = '-'; + } + if (VOID_IS_8) + { + header[8]='V'; + } else + { + header[8]='v'; + } + + header[9] = '2'; + header[10] = '7'; + header[11] = '5'; + + fwrite(header,SIZEOFBLENDERHEADER,1,fp); + + writeChunks(fp, fixupPointers); + + writeDNA(fp); + + fclose(fp); + + } else + { + printf("Error: cannot open file %s for writing\n",fileName); + return 0; + } + return 1; +} + + + +void btBulletFile::addStruct(const char* structType,void* data, int len, void* oldPtr, int code) +{ + + bParse::bChunkInd dataChunk; + dataChunk.code = code; + dataChunk.nr = 1; + dataChunk.len = len; + dataChunk.dna_nr = mMemoryDNA->getReverseType(structType); + dataChunk.oldPtr = oldPtr; + + ///Perform structure size validation + short* structInfo= mMemoryDNA->getStruct(dataChunk.dna_nr); + int elemBytes; + elemBytes= mMemoryDNA->getLength(structInfo[0]); +// int elemBytes = mMemoryDNA->getElementSize(structInfo[0],structInfo[1]); + assert(len==elemBytes); + + mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)data); + m_chunks.push_back(dataChunk); +} \ No newline at end of file diff --git a/Extras/Serialize/BulletFileLoader/btBulletFile.h b/Extras/Serialize/BulletFileLoader/btBulletFile.h new file mode 100644 index 0000000000..c4d735622c --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/btBulletFile.h @@ -0,0 +1,83 @@ +/* +bParse +Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef BT_BULLET_FILE_H +#define BT_BULLET_FILE_H + + +#include "bFile.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "bDefines.h" + +#include "LinearMath/btSerializer.h" + + + +namespace bParse { + + // ----------------------------------------------------- // + class btBulletFile : public bFile + { + + + protected: + + char* m_DnaCopy; + + public: + + btAlignedObjectArray m_softBodies; + + btAlignedObjectArray m_rigidBodies; + + btAlignedObjectArray m_collisionObjects; + + btAlignedObjectArray m_collisionShapes; + + btAlignedObjectArray m_constraints; + + btAlignedObjectArray m_bvhs; + + btAlignedObjectArray m_triangleInfoMaps; + + btAlignedObjectArray m_dynamicsWorldInfo; + + btAlignedObjectArray m_dataBlocks; + btBulletFile(); + + btBulletFile(const char* fileName); + + btBulletFile(char *memoryBuffer, int len); + + virtual ~btBulletFile(); + + virtual void addDataBlock(char* dataBlock); + + + // experimental + virtual int write(const char* fileName, bool fixupPointers=false); + + virtual void parse(int verboseMode); + + virtual void parseData(); + + virtual void writeDNA(FILE* fp); + + void addStruct(const char* structType,void* data, int len, void* oldPtr, int code); + + }; +}; + +#endif //BT_BULLET_FILE_H diff --git a/Extras/Serialize/BulletFileLoader/premake4.lua b/Extras/Serialize/BulletFileLoader/premake4.lua new file mode 100644 index 0000000000..f4aad3da58 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/premake4.lua @@ -0,0 +1,12 @@ + project "BulletFileLoader" + + kind "StaticLib" + targetdir "../../lib" + includedirs { + "../../../src" + } + + files { + "**.cpp", + "**.h" + } \ No newline at end of file diff --git a/Extras/Serialize/BulletWorldImporter/CMakeLists.txt b/Extras/Serialize/BulletWorldImporter/CMakeLists.txt new file mode 100644 index 0000000000..666ac21c17 --- /dev/null +++ b/Extras/Serialize/BulletWorldImporter/CMakeLists.txt @@ -0,0 +1,40 @@ +INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader +) + +ADD_LIBRARY( +BulletWorldImporter +btBulletWorldImporter.cpp +btBulletWorldImporter.h +btWorldImporter.cpp +btWorldImporter.h +) + +SET_TARGET_PROPERTIES(BulletWorldImporter PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(BulletWorldImporter PROPERTIES SOVERSION ${BULLET_VERSION}) + +IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(BulletWorldImporter BulletDynamics BulletCollision BulletFileLoader LinearMath) +ENDIF (BUILD_SHARED_LIBS) + +IF (INSTALL_EXTRA_LIBS) + IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) + #FILES_MATCHING requires CMake 2.6 + IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletWorldImporter DESTINATION .) + ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletWorldImporter DESTINATION lib${LIB_SUFFIX}) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN +".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE) + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + SET_TARGET_PROPERTIES(BulletWorldImporter PROPERTIES FRAMEWORK true) + SET_TARGET_PROPERTIES(BulletWorldImporter PROPERTIES PUBLIC_HEADER "btBulletWorldImporter.h") + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) +ENDIF (INSTALL_EXTRA_LIBS) diff --git a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp new file mode 100644 index 0000000000..3f3a359374 --- /dev/null +++ b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp @@ -0,0 +1,362 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#include "btBulletWorldImporter.h" +#include "../BulletFileLoader/btBulletFile.h" + +#include "btBulletDynamicsCommon.h" +#include "BulletCollision/Gimpact/btGImpactShape.h" + + + +//#define USE_INTERNAL_EDGE_UTILITY +#ifdef USE_INTERNAL_EDGE_UTILITY +#include "BulletCollision/CollisionDispatch/btInternalEdgeUtility.h" +#endif //USE_INTERNAL_EDGE_UTILITY + +btBulletWorldImporter::btBulletWorldImporter(btDynamicsWorld* world) + :btWorldImporter(world) +{ +} + +btBulletWorldImporter::~btBulletWorldImporter() +{ +} + + +bool btBulletWorldImporter::loadFile( const char* fileName, const char* preSwapFilenameOut) +{ + bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(fileName); + + + bool result = loadFileFromMemory(bulletFile2); + //now you could save the file in 'native' format using + //bulletFile2->writeFile("native.bullet"); + if (result) + { + if (preSwapFilenameOut) + { + bulletFile2->preSwap(); + bulletFile2->writeFile(preSwapFilenameOut); + } + + } + delete bulletFile2; + + return result; + +} + + + +bool btBulletWorldImporter::loadFileFromMemory( char* memoryBuffer, int len) +{ + bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(memoryBuffer,len); + + bool result = loadFileFromMemory(bulletFile2); + + delete bulletFile2; + + return result; +} + + + + +bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFile2) +{ + bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0; + + if (ok) + bulletFile2->parse(m_verboseMode); + else + return false; + + if (m_verboseMode & bParse::FD_VERBOSE_DUMP_CHUNKS) + { + bulletFile2->dumpChunks(bulletFile2->getFileDNA()); + } + + return convertAllObjects(bulletFile2); + +} + +bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile2) +{ + + m_shapeMap.clear(); + m_bodyMap.clear(); + + int i; + + for (i=0;im_bvhs.size();i++) + { + btOptimizedBvh* bvh = createOptimizedBvh(); + + if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) + { + btQuantizedBvhDoubleData* bvhData = (btQuantizedBvhDoubleData*)bulletFile2->m_bvhs[i]; + bvh->deSerializeDouble(*bvhData); + } else + { + btQuantizedBvhFloatData* bvhData = (btQuantizedBvhFloatData*)bulletFile2->m_bvhs[i]; + bvh->deSerializeFloat(*bvhData); + } + m_bvhMap.insert(bulletFile2->m_bvhs[i],bvh); + } + + + + + + for (i=0;im_collisionShapes.size();i++) + { + btCollisionShapeData* shapeData = (btCollisionShapeData*)bulletFile2->m_collisionShapes[i]; + btCollisionShape* shape = convertCollisionShape(shapeData); + if (shape) + { + // printf("shapeMap.insert(%x,%x)\n",shapeData,shape); + m_shapeMap.insert(shapeData,shape); + } + + if (shape&& shapeData->m_name) + { + char* newname = duplicateName(shapeData->m_name); + m_objectNameMap.insert(shape,newname); + m_nameShapeMap.insert(newname,shape); + } + } + + + + + + for (int i=0;im_dynamicsWorldInfo.size();i++) + { + if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) + { + btDynamicsWorldDoubleData* solverInfoData = (btDynamicsWorldDoubleData*)bulletFile2->m_dynamicsWorldInfo[i]; + btContactSolverInfo solverInfo; + + btVector3 gravity; + gravity.deSerializeDouble(solverInfoData->m_gravity); + + solverInfo.m_tau = btScalar(solverInfoData->m_solverInfo.m_tau); + solverInfo.m_damping = btScalar(solverInfoData->m_solverInfo.m_damping); + solverInfo.m_friction = btScalar(solverInfoData->m_solverInfo.m_friction); + solverInfo.m_timeStep = btScalar(solverInfoData->m_solverInfo.m_timeStep); + + solverInfo.m_restitution = btScalar(solverInfoData->m_solverInfo.m_restitution); + solverInfo.m_maxErrorReduction = btScalar(solverInfoData->m_solverInfo.m_maxErrorReduction); + solverInfo.m_sor = btScalar(solverInfoData->m_solverInfo.m_sor); + solverInfo.m_erp = btScalar(solverInfoData->m_solverInfo.m_erp); + + solverInfo.m_erp2 = btScalar(solverInfoData->m_solverInfo.m_erp2); + solverInfo.m_globalCfm = btScalar(solverInfoData->m_solverInfo.m_globalCfm); + solverInfo.m_splitImpulsePenetrationThreshold = btScalar(solverInfoData->m_solverInfo.m_splitImpulsePenetrationThreshold); + solverInfo.m_splitImpulseTurnErp = btScalar(solverInfoData->m_solverInfo.m_splitImpulseTurnErp); + + solverInfo.m_linearSlop = btScalar(solverInfoData->m_solverInfo.m_linearSlop); + solverInfo.m_warmstartingFactor = btScalar(solverInfoData->m_solverInfo.m_warmstartingFactor); + solverInfo.m_maxGyroscopicForce = btScalar(solverInfoData->m_solverInfo.m_maxGyroscopicForce); + solverInfo.m_singleAxisRollingFrictionThreshold = btScalar(solverInfoData->m_solverInfo.m_singleAxisRollingFrictionThreshold); + + solverInfo.m_numIterations = solverInfoData->m_solverInfo.m_numIterations; + solverInfo.m_solverMode = solverInfoData->m_solverInfo.m_solverMode; + solverInfo.m_restingContactRestitutionThreshold = solverInfoData->m_solverInfo.m_restingContactRestitutionThreshold; + solverInfo.m_minimumSolverBatchSize = solverInfoData->m_solverInfo.m_minimumSolverBatchSize; + + solverInfo.m_splitImpulse = solverInfoData->m_solverInfo.m_splitImpulse; + + setDynamicsWorldInfo(gravity,solverInfo); + } else + { + btDynamicsWorldFloatData* solverInfoData = (btDynamicsWorldFloatData*)bulletFile2->m_dynamicsWorldInfo[i]; + btContactSolverInfo solverInfo; + + btVector3 gravity; + gravity.deSerializeFloat(solverInfoData->m_gravity); + + solverInfo.m_tau = solverInfoData->m_solverInfo.m_tau; + solverInfo.m_damping = solverInfoData->m_solverInfo.m_damping; + solverInfo.m_friction = solverInfoData->m_solverInfo.m_friction; + solverInfo.m_timeStep = solverInfoData->m_solverInfo.m_timeStep; + + solverInfo.m_restitution = solverInfoData->m_solverInfo.m_restitution; + solverInfo.m_maxErrorReduction = solverInfoData->m_solverInfo.m_maxErrorReduction; + solverInfo.m_sor = solverInfoData->m_solverInfo.m_sor; + solverInfo.m_erp = solverInfoData->m_solverInfo.m_erp; + + solverInfo.m_erp2 = solverInfoData->m_solverInfo.m_erp2; + solverInfo.m_globalCfm = solverInfoData->m_solverInfo.m_globalCfm; + solverInfo.m_splitImpulsePenetrationThreshold = solverInfoData->m_solverInfo.m_splitImpulsePenetrationThreshold; + solverInfo.m_splitImpulseTurnErp = solverInfoData->m_solverInfo.m_splitImpulseTurnErp; + + solverInfo.m_linearSlop = solverInfoData->m_solverInfo.m_linearSlop; + solverInfo.m_warmstartingFactor = solverInfoData->m_solverInfo.m_warmstartingFactor; + solverInfo.m_maxGyroscopicForce = solverInfoData->m_solverInfo.m_maxGyroscopicForce; + solverInfo.m_singleAxisRollingFrictionThreshold = solverInfoData->m_solverInfo.m_singleAxisRollingFrictionThreshold; + + solverInfo.m_numIterations = solverInfoData->m_solverInfo.m_numIterations; + solverInfo.m_solverMode = solverInfoData->m_solverInfo.m_solverMode; + solverInfo.m_restingContactRestitutionThreshold = solverInfoData->m_solverInfo.m_restingContactRestitutionThreshold; + solverInfo.m_minimumSolverBatchSize = solverInfoData->m_solverInfo.m_minimumSolverBatchSize; + + solverInfo.m_splitImpulse = solverInfoData->m_solverInfo.m_splitImpulse; + + setDynamicsWorldInfo(gravity,solverInfo); + } + } + + + for (i=0;im_rigidBodies.size();i++) + { + if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) + { + btRigidBodyDoubleData* colObjData = (btRigidBodyDoubleData*)bulletFile2->m_rigidBodies[i]; + convertRigidBodyDouble(colObjData); + } else + { + btRigidBodyFloatData* colObjData = (btRigidBodyFloatData*)bulletFile2->m_rigidBodies[i]; + convertRigidBodyFloat(colObjData); + } + + + } + + for (i=0;im_collisionObjects.size();i++) + { + if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) + { + btCollisionObjectDoubleData* colObjData = (btCollisionObjectDoubleData*)bulletFile2->m_collisionObjects[i]; + btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionShape); + if (shapePtr && *shapePtr) + { + btTransform startTransform; + colObjData->m_worldTransform.m_origin.m_floats[3] = 0.f; + startTransform.deSerializeDouble(colObjData->m_worldTransform); + + btCollisionShape* shape = (btCollisionShape*)*shapePtr; + btCollisionObject* body = createCollisionObject(startTransform,shape,colObjData->m_name); + body->setFriction(btScalar(colObjData->m_friction)); + body->setRestitution(btScalar(colObjData->m_restitution)); + +#ifdef USE_INTERNAL_EDGE_UTILITY + if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) + { + btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape; + if (trimesh->getTriangleInfoMap()) + { + body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); + } + } +#endif //USE_INTERNAL_EDGE_UTILITY + m_bodyMap.insert(colObjData,body); + } else + { + printf("error: no shape found\n"); + } + + } else + { + btCollisionObjectFloatData* colObjData = (btCollisionObjectFloatData*)bulletFile2->m_collisionObjects[i]; + btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionShape); + if (shapePtr && *shapePtr) + { + btTransform startTransform; + colObjData->m_worldTransform.m_origin.m_floats[3] = 0.f; + startTransform.deSerializeFloat(colObjData->m_worldTransform); + + btCollisionShape* shape = (btCollisionShape*)*shapePtr; + btCollisionObject* body = createCollisionObject(startTransform,shape,colObjData->m_name); + +#ifdef USE_INTERNAL_EDGE_UTILITY + if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) + { + btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape; + if (trimesh->getTriangleInfoMap()) + { + body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); + } + } +#endif //USE_INTERNAL_EDGE_UTILITY + m_bodyMap.insert(colObjData,body); + } else + { + printf("error: no shape found\n"); + } + } + + } + + + for (i=0;im_constraints.size();i++) + { + btTypedConstraintData2* constraintData = (btTypedConstraintData2*)bulletFile2->m_constraints[i]; + btTypedConstraintFloatData* singleC = (btTypedConstraintFloatData*)bulletFile2->m_constraints[i]; + btTypedConstraintDoubleData* doubleC = (btTypedConstraintDoubleData*)bulletFile2->m_constraints[i]; + + btCollisionObject** colAptr = m_bodyMap.find(constraintData->m_rbA); + btCollisionObject** colBptr = m_bodyMap.find(constraintData->m_rbB); + + btRigidBody* rbA = 0; + btRigidBody* rbB = 0; + + if (colAptr) + { + rbA = btRigidBody::upcast(*colAptr); + if (!rbA) + rbA = &getFixedBody(); + } + if (colBptr) + { + rbB = btRigidBody::upcast(*colBptr); + if (!rbB) + rbB = &getFixedBody(); + } + if (!rbA && !rbB) + continue; + + bool isDoublePrecisionData = (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)!=0; + + if (isDoublePrecisionData) + { + if (bulletFile2->getVersion()>=282) + { + btTypedConstraintDoubleData* dc = (btTypedConstraintDoubleData*)constraintData; + convertConstraintDouble(dc, rbA,rbB, bulletFile2->getVersion()); + } else + { + //double-precision constraints were messed up until 2.82, try to recover data... + + btTypedConstraintData* oldData = (btTypedConstraintData*)constraintData; + + convertConstraintBackwardsCompatible281(oldData, rbA,rbB, bulletFile2->getVersion()); + + } + } + else + { + btTypedConstraintFloatData* dc = (btTypedConstraintFloatData*)constraintData; + convertConstraintFloat(dc, rbA,rbB, bulletFile2->getVersion()); + } + + + } + + return true; +} + diff --git a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h new file mode 100644 index 0000000000..27c1e7e332 --- /dev/null +++ b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h @@ -0,0 +1,68 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#ifndef BULLET_WORLD_IMPORTER_H +#define BULLET_WORLD_IMPORTER_H + + +#include "btWorldImporter.h" + + +class btBulletFile; + + + + +namespace bParse +{ + class btBulletFile; + +}; + + + +///The btBulletWorldImporter is a starting point to import .bullet files. +///note that not all data is converted yet. You are expected to override or modify this class. +///See Bullet/Demos/SerializeDemo for a derived class that extract btSoftBody objects too. +class btBulletWorldImporter : public btWorldImporter +{ + + +public: + + btBulletWorldImporter(btDynamicsWorld* world=0); + + virtual ~btBulletWorldImporter(); + + ///if you pass a valid preSwapFilenameOut, it will save a new file with a different endianness + ///this pre-swapped file can be loaded without swapping on a target platform of different endianness + bool loadFile(const char* fileName, const char* preSwapFilenameOut=0); + + ///the memoryBuffer might be modified (for example if endian swaps are necessary) + bool loadFileFromMemory(char *memoryBuffer, int len); + + bool loadFileFromMemory(bParse::btBulletFile* file); + + //call make sure bulletFile2 has been parsed, either using btBulletFile::parse or btBulletWorldImporter::loadFileFromMemory + virtual bool convertAllObjects(bParse::btBulletFile* file); + + + + +}; + +#endif //BULLET_WORLD_IMPORTER_H + diff --git a/Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp b/Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp new file mode 100644 index 0000000000..982931e0c1 --- /dev/null +++ b/Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp @@ -0,0 +1,1922 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "btWorldImporter.h" +#include "btBulletDynamicsCommon.h" +#include "BulletCollision/Gimpact/btGImpactShape.h" + +btWorldImporter::btWorldImporter(btDynamicsWorld* world) +:m_dynamicsWorld(world), +m_verboseMode(0) +{ + +} + +btWorldImporter::~btWorldImporter() +{ +} + +void btWorldImporter::deleteAllData() +{ + int i; + for (i=0;iremoveConstraint(m_allocatedConstraints[i]); + delete m_allocatedConstraints[i]; + } + m_allocatedConstraints.clear(); + + + for (i=0;iremoveRigidBody(btRigidBody::upcast(m_allocatedRigidBodies[i])); + delete m_allocatedRigidBodies[i]; + } + + m_allocatedRigidBodies.clear(); + + + for (i=0;im_numMeshParts;a++) + { + btMeshPartData* curPart = &curData->m_meshPartsPtr[a]; + if(curPart->m_vertices3f) + delete [] curPart->m_vertices3f; + + if(curPart->m_vertices3d) + delete [] curPart->m_vertices3d; + + if(curPart->m_indices32) + delete [] curPart->m_indices32; + + if(curPart->m_3indices16) + delete [] curPart->m_3indices16; + + if(curPart->m_indices16) + delete [] curPart->m_indices16; + + if (curPart->m_3indices8) + delete [] curPart->m_3indices8; + + } + delete [] curData->m_meshPartsPtr; + delete curData; + } + m_allocatedbtStridingMeshInterfaceDatas.clear(); + + for (i=0;im_shapeType) + { + case STATIC_PLANE_PROXYTYPE: + { + btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*)shapeData; + btVector3 planeNormal,localScaling; + planeNormal.deSerializeFloat(planeData->m_planeNormal); + localScaling.deSerializeFloat(planeData->m_localScaling); + shape = createPlaneShape(planeNormal,planeData->m_planeConstant); + shape->setLocalScaling(localScaling); + + break; + } + case SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE: + { + btScaledTriangleMeshShapeData* scaledMesh = (btScaledTriangleMeshShapeData*) shapeData; + btCollisionShapeData* colShapeData = (btCollisionShapeData*) &scaledMesh->m_trimeshShapeData; + colShapeData->m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE; + btCollisionShape* childShape = convertCollisionShape(colShapeData); + btBvhTriangleMeshShape* meshShape = (btBvhTriangleMeshShape*)childShape; + btVector3 localScaling; + localScaling.deSerializeFloat(scaledMesh->m_localScaling); + + shape = createScaledTrangleMeshShape(meshShape, localScaling); + break; + } + case GIMPACT_SHAPE_PROXYTYPE: + { + btGImpactMeshShapeData* gimpactData = (btGImpactMeshShapeData*) shapeData; + if (gimpactData->m_gimpactSubType == CONST_GIMPACT_TRIMESH_SHAPE) + { + btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&gimpactData->m_meshInterface); + btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData); + + + btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface); + btVector3 localScaling; + localScaling.deSerializeFloat(gimpactData->m_localScaling); + gimpactShape->setLocalScaling(localScaling); + gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin)); + gimpactShape->updateBound(); + shape = gimpactShape; + } else + { + printf("unsupported gimpact sub type\n"); + } + break; + } + + case CYLINDER_SHAPE_PROXYTYPE: + case CONE_SHAPE_PROXYTYPE: + case CAPSULE_SHAPE_PROXYTYPE: + case BOX_SHAPE_PROXYTYPE: + case SPHERE_SHAPE_PROXYTYPE: + case MULTI_SPHERE_SHAPE_PROXYTYPE: + case CONVEX_HULL_SHAPE_PROXYTYPE: + { + btConvexInternalShapeData* bsd = (btConvexInternalShapeData*)shapeData; + btVector3 implicitShapeDimensions; + implicitShapeDimensions.deSerializeFloat(bsd->m_implicitShapeDimensions); + btVector3 localScaling; + localScaling.deSerializeFloat(bsd->m_localScaling); + btVector3 margin(bsd->m_collisionMargin,bsd->m_collisionMargin,bsd->m_collisionMargin); + switch (shapeData->m_shapeType) + { + case BOX_SHAPE_PROXYTYPE: + { + btBoxShape* box= (btBoxShape*)createBoxShape(implicitShapeDimensions/localScaling+margin); + //box->initializePolyhedralFeatures(); + shape = box; + + break; + } + case SPHERE_SHAPE_PROXYTYPE: + { + shape = createSphereShape(implicitShapeDimensions.getX()); + break; + } + case CAPSULE_SHAPE_PROXYTYPE: + { + btCapsuleShapeData* capData = (btCapsuleShapeData*)shapeData; + switch (capData->m_upAxis) + { + case 0: + { + shape = createCapsuleShapeX(implicitShapeDimensions.getY()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getX()); + break; + } + case 1: + { + shape = createCapsuleShapeY(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getY()); + break; + } + case 2: + { + shape = createCapsuleShapeZ(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getZ()); + break; + } + default: + { + printf("error: wrong up axis for btCapsuleShape\n"); + } + bsd->m_collisionMargin = 0.f; + + }; + + break; + } + case CYLINDER_SHAPE_PROXYTYPE: + { + btCylinderShapeData* cylData = (btCylinderShapeData*) shapeData; + btVector3 halfExtents = implicitShapeDimensions+margin; + switch (cylData->m_upAxis) + { + case 0: + { + shape = createCylinderShapeX(halfExtents.getY(),halfExtents.getX()); + break; + } + case 1: + { + shape = createCylinderShapeY(halfExtents.getX(),halfExtents.getY()); + break; + } + case 2: + { + shape = createCylinderShapeZ(halfExtents.getX(),halfExtents.getZ()); + break; + } + default: + { + printf("unknown Cylinder up axis\n"); + } + + }; + + + + break; + } + case CONE_SHAPE_PROXYTYPE: + { + btConeShapeData* conData = (btConeShapeData*) shapeData; + btVector3 halfExtents = implicitShapeDimensions;//+margin; + switch (conData->m_upIndex) + { + case 0: + { + shape = createConeShapeX(halfExtents.getY(),halfExtents.getX()); + break; + } + case 1: + { + shape = createConeShapeY(halfExtents.getX(),halfExtents.getY()); + break; + } + case 2: + { + shape = createConeShapeZ(halfExtents.getX(),halfExtents.getZ()); + break; + } + default: + { + printf("unknown Cone up axis\n"); + } + + }; + + + + break; + } + case MULTI_SPHERE_SHAPE_PROXYTYPE: + { + btMultiSphereShapeData* mss = (btMultiSphereShapeData*)bsd; + int numSpheres = mss->m_localPositionArraySize; + + btAlignedObjectArray tmpPos; + btAlignedObjectArray radii; + radii.resize(numSpheres); + tmpPos.resize(numSpheres); + int i; + for ( i=0;im_localPositionArrayPtr[i].m_pos); + radii[i] = mss->m_localPositionArrayPtr[i].m_radius; + } + shape = createMultiSphereShape(&tmpPos[0],&radii[0],numSpheres); + break; + } + case CONVEX_HULL_SHAPE_PROXYTYPE: + { + // int sz = sizeof(btConvexHullShapeData); + // int sz2 = sizeof(btConvexInternalShapeData); + // int sz3 = sizeof(btCollisionShapeData); + btConvexHullShapeData* convexData = (btConvexHullShapeData*)bsd; + int numPoints = convexData->m_numUnscaledPoints; + + btAlignedObjectArray tmpPoints; + tmpPoints.resize(numPoints); + int i; + for ( i=0;im_unscaledPointsDoublePtr) + tmpPoints[i].deSerialize(convexData->m_unscaledPointsDoublePtr[i]); + if (convexData->m_unscaledPointsFloatPtr) + tmpPoints[i].deSerializeFloat(convexData->m_unscaledPointsFloatPtr[i]); +#else + if (convexData->m_unscaledPointsFloatPtr) + tmpPoints[i].deSerialize(convexData->m_unscaledPointsFloatPtr[i]); + if (convexData->m_unscaledPointsDoublePtr) + tmpPoints[i].deSerializeDouble(convexData->m_unscaledPointsDoublePtr[i]); +#endif //BT_USE_DOUBLE_PRECISION + } + btConvexHullShape* hullShape = createConvexHullShape(); + for (i=0;iaddPoint(tmpPoints[i]); + } + hullShape->setMargin(bsd->m_collisionMargin); + //hullShape->initializePolyhedralFeatures(); + shape = hullShape; + break; + } + default: + { + printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType); + } + } + + if (shape) + { + shape->setMargin(bsd->m_collisionMargin); + + btVector3 localScaling; + localScaling.deSerializeFloat(bsd->m_localScaling); + shape->setLocalScaling(localScaling); + + } + break; + } + case TRIANGLE_MESH_SHAPE_PROXYTYPE: + { + btTriangleMeshShapeData* trimesh = (btTriangleMeshShapeData*)shapeData; + btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&trimesh->m_meshInterface); + btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData); + if (!meshInterface->getNumSubParts()) + { + return 0; + } + + btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling); + meshInterface->setScaling(scaling); + + + btOptimizedBvh* bvh = 0; +#if 1 + if (trimesh->m_quantizedFloatBvh) + { + btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh); + if (bvhPtr && *bvhPtr) + { + bvh = *bvhPtr; + } else + { + bvh = createOptimizedBvh(); + bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh); + } + } + if (trimesh->m_quantizedDoubleBvh) + { + btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedDoubleBvh); + if (bvhPtr && *bvhPtr) + { + bvh = *bvhPtr; + } else + { + bvh = createOptimizedBvh(); + bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh); + } + } +#endif + + + btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface,bvh); + trimeshShape->setMargin(trimesh->m_collisionMargin); + shape = trimeshShape; + + if (trimesh->m_triangleInfoMap) + { + btTriangleInfoMap* map = createTriangleInfoMap(); + map->deSerialize(*trimesh->m_triangleInfoMap); + trimeshShape->setTriangleInfoMap(map); + +#ifdef USE_INTERNAL_EDGE_UTILITY + gContactAddedCallback = btAdjustInternalEdgeContactsCallback; +#endif //USE_INTERNAL_EDGE_UTILITY + + } + + //printf("trimesh->m_collisionMargin=%f\n",trimesh->m_collisionMargin); + break; + } + case COMPOUND_SHAPE_PROXYTYPE: + { + btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData; + btCompoundShape* compoundShape = createCompoundShape(); + + btCompoundShapeChildData* childShapeDataArray = &compoundData->m_childShapePtr[0]; + + + btAlignedObjectArray childShapes; + for (int i=0;im_numChildShapes;i++) + { + btCompoundShapeChildData* ptr = &compoundData->m_childShapePtr[i]; + + btCollisionShapeData* cd = compoundData->m_childShapePtr[i].m_childShape; + + btCollisionShape* childShape = convertCollisionShape(cd); + if (childShape) + { + btTransform localTransform; + localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform); + compoundShape->addChildShape(localTransform,childShape); + } else + { +#ifdef _DEBUG + printf("error: couldn't create childShape for compoundShape\n"); +#endif + } + + } + shape = compoundShape; + + break; + } + case SOFTBODY_SHAPE_PROXYTYPE: + { + return 0; + } + default: + { +#ifdef _DEBUG + printf("unsupported shape type (%d)\n",shapeData->m_shapeType); +#endif + } + } + + return shape; + +} + + + +char* btWorldImporter::duplicateName(const char* name) +{ + if (name) + { + int l = (int)strlen(name); + char* newName = new char[l+1]; + memcpy(newName,name,l); + newName[l] = 0; + m_allocatedNames.push_back(newName); + return newName; + } + return 0; +} + +void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion) +{ + + btTypedConstraint* constraint = 0; + + switch (constraintData->m_objectType) + { + case POINT2POINT_CONSTRAINT_TYPE: + { + btPoint2PointConstraintDoubleData* p2pData = (btPoint2PointConstraintDoubleData*)constraintData; + if (rbA && rbB) + { + btVector3 pivotInA,pivotInB; + pivotInA.deSerializeDouble(p2pData->m_pivotInA); + pivotInB.deSerializeDouble(p2pData->m_pivotInB); + constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); + } else + { + btVector3 pivotInA; + pivotInA.deSerializeDouble(p2pData->m_pivotInA); + constraint = createPoint2PointConstraint(*rbA,pivotInA); + } + break; + } + case HINGE_CONSTRAINT_TYPE: + { + btHingeConstraint* hinge = 0; + + btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); + rbBFrame.deSerializeDouble(hingeData->m_rbBFrame); + hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); + hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); + } + if (hingeData->m_enableAngularMotor) + { + hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse); + } + hinge->setAngularOnly(hingeData->m_angularOnly!=0); + hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor)); + + constraint = hinge; + break; + + } + case CONETWIST_CONSTRAINT_TYPE: + { + btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData; + btConeTwistConstraint* coneTwist = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(coneData->m_rbAFrame); + rbBFrame.deSerializeFloat(coneData->m_rbBFrame); + coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeFloat(coneData->m_rbAFrame); + coneTwist = createConeTwistConstraint(*rbA,rbAFrame); + } + coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness, + (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor); + coneTwist->setDamping((btScalar)coneData->m_damping); + + constraint = coneTwist; + break; + } + + case D6_SPRING_CONSTRAINT_TYPE: + { + + btGeneric6DofSpringConstraintData* dofData = (btGeneric6DofSpringConstraintData*)constraintData; + // int sz = sizeof(btGeneric6DofSpringConstraintData); + btGeneric6DofSpringConstraint* dof = 0; + + if (rbA && rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame); + rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame); + dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n"); + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit); + angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit); + linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit); + linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit); + + angLowerLimit.setW(0.f); + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + + int i; + if (fileVersion>280) + { + for (i=0;i<6;i++) + { + dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]); + dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]); + dof->enableSpring(i,dofData->m_springEnabled[i]!=0); + dof->setDamping(i,(btScalar)dofData->m_springDamping[i]); + } + } + } + + constraint = dof; + break; + + } + case D6_CONSTRAINT_TYPE: + { + btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData; + btGeneric6DofConstraint* dof = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(dofData->m_rbAFrame); + rbBFrame.deSerializeFloat(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + if (rbB) + { + btTransform rbBFrame; + rbBFrame.deSerializeFloat(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n"); + } + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit); + angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit); + linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit); + linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit); + + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + } + + constraint = dof; + break; + } + case SLIDER_CONSTRAINT_TYPE: + { + btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData; + btSliderConstraint* slider = 0; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(sliderData->m_rbAFrame); + rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } else + { + btTransform rbBFrame; + rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } + slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit); + slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit); + slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit); + slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit); + slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0); + constraint = slider; + break; + } + + default: + { + printf("unknown constraint type\n"); + } + }; + + if (constraint) + { + constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize); + ///those fields didn't exist and set to zero for pre-280 versions, so do a check here + if (fileVersion>=280) + { + constraint->setBreakingImpulseThreshold((btScalar)constraintData->m_breakingImpulseThreshold); + constraint->setEnabled(constraintData->m_isEnabled!=0); + constraint->setOverrideNumSolverIterations(constraintData->m_overrideNumSolverIterations); + } + + if (constraintData->m_name) + { + char* newname = duplicateName(constraintData->m_name); + m_nameConstraintMap.insert(newname,constraint); + m_objectNameMap.insert(constraint,newname); + } + if(m_dynamicsWorld) + m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); + } + +} + +void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion) +{ + btTypedConstraint* constraint = 0; + + switch (constraintData->m_objectType) + { + case POINT2POINT_CONSTRAINT_TYPE: + { + btPoint2PointConstraintFloatData* p2pData = (btPoint2PointConstraintFloatData*)constraintData; + if (rbA&& rbB) + { + btVector3 pivotInA,pivotInB; + pivotInA.deSerializeFloat(p2pData->m_pivotInA); + pivotInB.deSerializeFloat(p2pData->m_pivotInB); + constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); + + } else + { + btVector3 pivotInA; + pivotInA.deSerializeFloat(p2pData->m_pivotInA); + constraint = createPoint2PointConstraint(*rbA,pivotInA); + } + break; + } + case HINGE_CONSTRAINT_TYPE: + { + btHingeConstraint* hinge = 0; + btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(hingeData->m_rbAFrame); + rbBFrame.deSerializeFloat(hingeData->m_rbBFrame); + hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeFloat(hingeData->m_rbAFrame); + hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); + } + if (hingeData->m_enableAngularMotor) + { + hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse); + } + hinge->setAngularOnly(hingeData->m_angularOnly!=0); + hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor)); + + constraint = hinge; + break; + + } + case CONETWIST_CONSTRAINT_TYPE: + { + btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData; + btConeTwistConstraint* coneTwist = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(coneData->m_rbAFrame); + rbBFrame.deSerializeFloat(coneData->m_rbBFrame); + coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeFloat(coneData->m_rbAFrame); + coneTwist = createConeTwistConstraint(*rbA,rbAFrame); + } + coneTwist->setLimit(coneData->m_swingSpan1,coneData->m_swingSpan2,coneData->m_twistSpan,coneData->m_limitSoftness,coneData->m_biasFactor,coneData->m_relaxationFactor); + coneTwist->setDamping(coneData->m_damping); + + constraint = coneTwist; + break; + } + + case D6_SPRING_CONSTRAINT_TYPE: + { + + btGeneric6DofSpringConstraintData* dofData = (btGeneric6DofSpringConstraintData*)constraintData; + // int sz = sizeof(btGeneric6DofSpringConstraintData); + btGeneric6DofSpringConstraint* dof = 0; + + if (rbA && rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame); + rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame); + dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n"); + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit); + angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit); + linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit); + linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit); + + angLowerLimit.setW(0.f); + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + + int i; + if (fileVersion>280) + { + for (i=0;i<6;i++) + { + dof->setStiffness(i,dofData->m_springStiffness[i]); + dof->setEquilibriumPoint(i,dofData->m_equilibriumPoint[i]); + dof->enableSpring(i,dofData->m_springEnabled[i]!=0); + dof->setDamping(i,dofData->m_springDamping[i]); + } + } + } + + constraint = dof; + break; + } + case D6_CONSTRAINT_TYPE: + { + btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData; + btGeneric6DofConstraint* dof = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(dofData->m_rbAFrame); + rbBFrame.deSerializeFloat(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + if (rbB) + { + btTransform rbBFrame; + rbBFrame.deSerializeFloat(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n"); + } + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit); + angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit); + linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit); + linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit); + + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + } + + constraint = dof; + break; + } + case SLIDER_CONSTRAINT_TYPE: + { + btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData; + btSliderConstraint* slider = 0; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(sliderData->m_rbAFrame); + rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } else + { + btTransform rbBFrame; + rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } + slider->setLowerLinLimit(sliderData->m_linearLowerLimit); + slider->setUpperLinLimit(sliderData->m_linearUpperLimit); + slider->setLowerAngLimit(sliderData->m_angularLowerLimit); + slider->setUpperAngLimit(sliderData->m_angularUpperLimit); + slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0); + constraint = slider; + break; + } + case GEAR_CONSTRAINT_TYPE: + { + btGearConstraintFloatData* gearData = (btGearConstraintFloatData*) constraintData; + btGearConstraint* gear = 0; + if (rbA&&rbB) + { + btVector3 axisInA,axisInB; + axisInA.deSerializeFloat(gearData->m_axisInA); + axisInB.deSerializeFloat(gearData->m_axisInB); + gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio); + } else + { + btAssert(0); + //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized? + //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f); + } + constraint = gear; + break; + } + default: + { + printf("unknown constraint type\n"); + } + }; + + if (constraint) + { + constraint->setDbgDrawSize(constraintData->m_dbgDrawSize); + ///those fields didn't exist and set to zero for pre-280 versions, so do a check here + if (fileVersion>=280) + { + constraint->setBreakingImpulseThreshold(constraintData->m_breakingImpulseThreshold); + constraint->setEnabled(constraintData->m_isEnabled!=0); + constraint->setOverrideNumSolverIterations(constraintData->m_overrideNumSolverIterations); + } + + if (constraintData->m_name) + { + char* newname = duplicateName(constraintData->m_name); + m_nameConstraintMap.insert(newname,constraint); + m_objectNameMap.insert(constraint,newname); + } + if(m_dynamicsWorld) + m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); + } + + +} + + + +void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion) +{ + btTypedConstraint* constraint = 0; + + switch (constraintData->m_objectType) + { + case POINT2POINT_CONSTRAINT_TYPE: + { + btPoint2PointConstraintDoubleData2* p2pData = (btPoint2PointConstraintDoubleData2*)constraintData; + if (rbA && rbB) + { + btVector3 pivotInA,pivotInB; + pivotInA.deSerializeDouble(p2pData->m_pivotInA); + pivotInB.deSerializeDouble(p2pData->m_pivotInB); + constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); + } else + { + btVector3 pivotInA; + pivotInA.deSerializeDouble(p2pData->m_pivotInA); + constraint = createPoint2PointConstraint(*rbA,pivotInA); + } + break; + } + case HINGE_CONSTRAINT_TYPE: + { + btHingeConstraint* hinge = 0; + + btHingeConstraintDoubleData2* hingeData = (btHingeConstraintDoubleData2*)constraintData; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); + rbBFrame.deSerializeDouble(hingeData->m_rbBFrame); + hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); + hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); + } + if (hingeData->m_enableAngularMotor) + { + hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse); + } + hinge->setAngularOnly(hingeData->m_angularOnly!=0); + hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor)); + + constraint = hinge; + break; + + } + case CONETWIST_CONSTRAINT_TYPE: + { + btConeTwistConstraintDoubleData* coneData = (btConeTwistConstraintDoubleData*)constraintData; + btConeTwistConstraint* coneTwist = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(coneData->m_rbAFrame); + rbBFrame.deSerializeDouble(coneData->m_rbBFrame); + coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeDouble(coneData->m_rbAFrame); + coneTwist = createConeTwistConstraint(*rbA,rbAFrame); + } + coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness, + (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor); + coneTwist->setDamping((btScalar)coneData->m_damping); + + constraint = coneTwist; + break; + } + + case D6_SPRING_CONSTRAINT_TYPE: + { + + btGeneric6DofSpringConstraintDoubleData2* dofData = (btGeneric6DofSpringConstraintDoubleData2*)constraintData; + // int sz = sizeof(btGeneric6DofSpringConstraintData); + btGeneric6DofSpringConstraint* dof = 0; + + if (rbA && rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(dofData->m_6dofData.m_rbAFrame); + rbBFrame.deSerializeDouble(dofData->m_6dofData.m_rbBFrame); + dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n"); + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeDouble(dofData->m_6dofData.m_angularLowerLimit); + angUpperLimit.deSerializeDouble(dofData->m_6dofData.m_angularUpperLimit); + linLowerLimit.deSerializeDouble(dofData->m_6dofData.m_linearLowerLimit); + linUpperlimit.deSerializeDouble(dofData->m_6dofData.m_linearUpperLimit); + + angLowerLimit.setW(0.f); + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + + int i; + if (fileVersion>280) + { + for (i=0;i<6;i++) + { + dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]); + dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]); + dof->enableSpring(i,dofData->m_springEnabled[i]!=0); + dof->setDamping(i,(btScalar)dofData->m_springDamping[i]); + } + } + } + + constraint = dof; + break; + } + case D6_CONSTRAINT_TYPE: + { + btGeneric6DofConstraintDoubleData2* dofData = (btGeneric6DofConstraintDoubleData2*)constraintData; + btGeneric6DofConstraint* dof = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(dofData->m_rbAFrame); + rbBFrame.deSerializeDouble(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + if (rbB) + { + btTransform rbBFrame; + rbBFrame.deSerializeDouble(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n"); + } + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeDouble(dofData->m_angularLowerLimit); + angUpperLimit.deSerializeDouble(dofData->m_angularUpperLimit); + linLowerLimit.deSerializeDouble(dofData->m_linearLowerLimit); + linUpperlimit.deSerializeDouble(dofData->m_linearUpperLimit); + + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + } + + constraint = dof; + break; + } + case SLIDER_CONSTRAINT_TYPE: + { + btSliderConstraintDoubleData* sliderData = (btSliderConstraintDoubleData*)constraintData; + btSliderConstraint* slider = 0; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(sliderData->m_rbAFrame); + rbBFrame.deSerializeDouble(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } else + { + btTransform rbBFrame; + rbBFrame.deSerializeDouble(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } + slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit); + slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit); + slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit); + slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit); + slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0); + constraint = slider; + break; + } + case GEAR_CONSTRAINT_TYPE: + { + btGearConstraintDoubleData* gearData = (btGearConstraintDoubleData*) constraintData; + btGearConstraint* gear = 0; + if (rbA&&rbB) + { + btVector3 axisInA,axisInB; + axisInA.deSerializeDouble(gearData->m_axisInA); + axisInB.deSerializeDouble(gearData->m_axisInB); + gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio); + } else + { + btAssert(0); + //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized? + //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f); + } + constraint = gear; + break; + } + default: + { + printf("unknown constraint type\n"); + } + }; + + if (constraint) + { + constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize); + ///those fields didn't exist and set to zero for pre-280 versions, so do a check here + if (fileVersion>=280) + { + constraint->setBreakingImpulseThreshold((btScalar)constraintData->m_breakingImpulseThreshold); + constraint->setEnabled(constraintData->m_isEnabled!=0); + constraint->setOverrideNumSolverIterations(constraintData->m_overrideNumSolverIterations); + } + + if (constraintData->m_name) + { + char* newname = duplicateName(constraintData->m_name); + m_nameConstraintMap.insert(newname,constraint); + m_objectNameMap.insert(constraint,newname); + } + if(m_dynamicsWorld) + m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); + } + + +} + + + + + + + + + + +btTriangleIndexVertexArray* btWorldImporter::createMeshInterface(btStridingMeshInterfaceData& meshData) +{ + btTriangleIndexVertexArray* meshInterface = createTriangleMeshContainer(); + + for (int i=0;iaddIndexedMesh(meshPart,meshPart.m_indexType); + } + } + + return meshInterface; +} + + +btStridingMeshInterfaceData* btWorldImporter::createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData) +{ + //create a new btStridingMeshInterfaceData that is an exact copy of shapedata and store it in the WorldImporter + btStridingMeshInterfaceData* newData = new btStridingMeshInterfaceData; + + newData->m_scaling = interfaceData->m_scaling; + newData->m_numMeshParts = interfaceData->m_numMeshParts; + newData->m_meshPartsPtr = new btMeshPartData[newData->m_numMeshParts]; + + for(int i = 0;i < newData->m_numMeshParts;i++) + { + btMeshPartData* curPart = &interfaceData->m_meshPartsPtr[i]; + btMeshPartData* curNewPart = &newData->m_meshPartsPtr[i]; + + curNewPart->m_numTriangles = curPart->m_numTriangles; + curNewPart->m_numVertices = curPart->m_numVertices; + + if(curPart->m_vertices3f) + { + curNewPart->m_vertices3f = new btVector3FloatData[curNewPart->m_numVertices]; + memcpy(curNewPart->m_vertices3f,curPart->m_vertices3f,sizeof(btVector3FloatData) * curNewPart->m_numVertices); + } + else + curNewPart->m_vertices3f = NULL; + + if(curPart->m_vertices3d) + { + curNewPart->m_vertices3d = new btVector3DoubleData[curNewPart->m_numVertices]; + memcpy(curNewPart->m_vertices3d,curPart->m_vertices3d,sizeof(btVector3DoubleData) * curNewPart->m_numVertices); + } + else + curNewPart->m_vertices3d = NULL; + + int numIndices = curNewPart->m_numTriangles * 3; + ///the m_3indices8 was not initialized in some Bullet versions, this can cause crashes at loading time + ///we catch it by only dealing with m_3indices8 if none of the other indices are initialized + bool uninitialized3indices8Workaround =false; + + if(curPart->m_indices32) + { + uninitialized3indices8Workaround=true; + curNewPart->m_indices32 = new btIntIndexData[numIndices]; + memcpy(curNewPart->m_indices32,curPart->m_indices32,sizeof(btIntIndexData) * numIndices); + } + else + curNewPart->m_indices32 = NULL; + + if(curPart->m_3indices16) + { + uninitialized3indices8Workaround=true; + curNewPart->m_3indices16 = new btShortIntIndexTripletData[curNewPart->m_numTriangles]; + memcpy(curNewPart->m_3indices16,curPart->m_3indices16,sizeof(btShortIntIndexTripletData) * curNewPart->m_numTriangles); + } + else + curNewPart->m_3indices16 = NULL; + + if(curPart->m_indices16) + { + uninitialized3indices8Workaround=true; + curNewPart->m_indices16 = new btShortIntIndexData[numIndices]; + memcpy(curNewPart->m_indices16,curPart->m_indices16,sizeof(btShortIntIndexData) * numIndices); + } + else + curNewPart->m_indices16 = NULL; + + if(!uninitialized3indices8Workaround && curPart->m_3indices8) + { + curNewPart->m_3indices8 = new btCharIndexTripletData[curNewPart->m_numTriangles]; + memcpy(curNewPart->m_3indices8,curPart->m_3indices8,sizeof(btCharIndexTripletData) * curNewPart->m_numTriangles); + } + else + curNewPart->m_3indices8 = NULL; + + } + + m_allocatedbtStridingMeshInterfaceDatas.push_back(newData); + + return(newData); +} + +#ifdef USE_INTERNAL_EDGE_UTILITY +extern ContactAddedCallback gContactAddedCallback; + +static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) +{ + + btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1); + //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE); + //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED); + return true; +} +#endif //USE_INTERNAL_EDGE_UTILITY + + + + +btCollisionObject* btWorldImporter::createCollisionObject(const btTransform& startTransform,btCollisionShape* shape, const char* bodyName) +{ + return createRigidBody(false,0,startTransform,shape,bodyName); +} + +void btWorldImporter::setDynamicsWorldInfo(const btVector3& gravity, const btContactSolverInfo& solverInfo) +{ + if (m_dynamicsWorld) + { + m_dynamicsWorld->setGravity(gravity); + m_dynamicsWorld->getSolverInfo() = solverInfo; + } + +} + +btRigidBody* btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape,const char* bodyName) +{ + btVector3 localInertia; + localInertia.setZero(); + + if (mass) + shape->calculateLocalInertia(mass,localInertia); + + btRigidBody* body = new btRigidBody(mass,0,shape,localInertia); + body->setWorldTransform(startTransform); + + if (m_dynamicsWorld) + m_dynamicsWorld->addRigidBody(body); + + if (bodyName) + { + char* newname = duplicateName(bodyName); + m_objectNameMap.insert(body,newname); + m_nameBodyMap.insert(newname,body); + } + m_allocatedRigidBodies.push_back(body); + return body; + +} + +btCollisionShape* btWorldImporter::createPlaneShape(const btVector3& planeNormal,btScalar planeConstant) +{ + btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal,planeConstant); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} +btCollisionShape* btWorldImporter::createBoxShape(const btVector3& halfExtents) +{ + btBoxShape* shape = new btBoxShape(halfExtents); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} +btCollisionShape* btWorldImporter::createSphereShape(btScalar radius) +{ + btSphereShape* shape = new btSphereShape(radius); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + + +btCollisionShape* btWorldImporter::createCapsuleShapeX(btScalar radius, btScalar height) +{ + btCapsuleShapeX* shape = new btCapsuleShapeX(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCapsuleShapeY(btScalar radius, btScalar height) +{ + btCapsuleShape* shape = new btCapsuleShape(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCapsuleShapeZ(btScalar radius, btScalar height) +{ + btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCylinderShapeX(btScalar radius,btScalar height) +{ + btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height,radius,radius)); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCylinderShapeY(btScalar radius,btScalar height) +{ + btCylinderShape* shape = new btCylinderShape(btVector3(radius,height,radius)); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCylinderShapeZ(btScalar radius,btScalar height) +{ + btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius,radius,height)); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createConeShapeX(btScalar radius,btScalar height) +{ + btConeShapeX* shape = new btConeShapeX(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createConeShapeY(btScalar radius,btScalar height) +{ + btConeShape* shape = new btConeShape(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createConeShapeZ(btScalar radius,btScalar height) +{ + btConeShapeZ* shape = new btConeShapeZ(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btTriangleIndexVertexArray* btWorldImporter::createTriangleMeshContainer() +{ + btTriangleIndexVertexArray* in = new btTriangleIndexVertexArray(); + m_allocatedTriangleIndexArrays.push_back(in); + return in; +} + +btOptimizedBvh* btWorldImporter::createOptimizedBvh() +{ + btOptimizedBvh* bvh = new btOptimizedBvh(); + m_allocatedBvhs.push_back(bvh); + return bvh; +} + + +btTriangleInfoMap* btWorldImporter::createTriangleInfoMap() +{ + btTriangleInfoMap* tim = new btTriangleInfoMap(); + m_allocatedTriangleInfoMaps.push_back(tim); + return tim; +} + +btBvhTriangleMeshShape* btWorldImporter::createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh) +{ + if (bvh) + { + btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false); + bvhTriMesh->setOptimizedBvh(bvh); + m_allocatedCollisionShapes.push_back(bvhTriMesh); + return bvhTriMesh; + } + + btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh,true); + m_allocatedCollisionShapes.push_back(ts); + return ts; + +} +btCollisionShape* btWorldImporter::createConvexTriangleMeshShape(btStridingMeshInterface* trimesh) +{ + return 0; +} +btGImpactMeshShape* btWorldImporter::createGimpactShape(btStridingMeshInterface* trimesh) +{ + btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh); + m_allocatedCollisionShapes.push_back(shape); + return shape; + +} +btConvexHullShape* btWorldImporter::createConvexHullShape() +{ + btConvexHullShape* shape = new btConvexHullShape(); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCompoundShape* btWorldImporter::createCompoundShape() +{ + btCompoundShape* shape = new btCompoundShape(); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + + +btScaledBvhTriangleMeshShape* btWorldImporter::createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape,const btVector3& localScaling) +{ + btScaledBvhTriangleMeshShape* shape = new btScaledBvhTriangleMeshShape(meshShape,localScaling); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btMultiSphereShape* btWorldImporter::createMultiSphereShape(const btVector3* positions,const btScalar* radi,int numSpheres) +{ + btMultiSphereShape* shape = new btMultiSphereShape(positions, radi, numSpheres); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btRigidBody& btWorldImporter::getFixedBody() +{ + static btRigidBody s_fixed(0, 0,0); + s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.))); + return s_fixed; +} + +btPoint2PointConstraint* btWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB) +{ + btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,rbB,pivotInA,pivotInB); + m_allocatedConstraints.push_back(p2p); + return p2p; +} + +btPoint2PointConstraint* btWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA) +{ + btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,pivotInA); + m_allocatedConstraints.push_back(p2p); + return p2p; +} + + +btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA) +{ + btHingeConstraint* hinge = new btHingeConstraint(rbA,rbB,rbAFrame,rbBFrame,useReferenceFrameA); + m_allocatedConstraints.push_back(hinge); + return hinge; +} + +btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA) +{ + btHingeConstraint* hinge = new btHingeConstraint(rbA,rbAFrame,useReferenceFrameA); + m_allocatedConstraints.push_back(hinge); + return hinge; +} + +btConeTwistConstraint* btWorldImporter::createConeTwistConstraint(btRigidBody& rbA,btRigidBody& rbB,const btTransform& rbAFrame, const btTransform& rbBFrame) +{ + btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbB,rbAFrame,rbBFrame); + m_allocatedConstraints.push_back(cone); + return cone; +} + +btConeTwistConstraint* btWorldImporter::createConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame) +{ + btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbAFrame); + m_allocatedConstraints.push_back(cone); + return cone; +} + + +btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA) +{ + btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(dof); + return dof; +} + +btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB) +{ + btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbB,frameInB,useLinearReferenceFrameB); + m_allocatedConstraints.push_back(dof); + return dof; +} + +btGeneric6DofSpringConstraint* btWorldImporter::createGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA) +{ + btGeneric6DofSpringConstraint* dof = new btGeneric6DofSpringConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(dof); + return dof; +} + + +btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA) +{ + btSliderConstraint* slider = new btSliderConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(slider); + return slider; +} + +btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA) +{ + btSliderConstraint* slider = new btSliderConstraint(rbB,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(slider); + return slider; +} + +btGearConstraint* btWorldImporter::createGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio) +{ + btGearConstraint* gear = new btGearConstraint(rbA,rbB,axisInA,axisInB,ratio); + m_allocatedConstraints.push_back(gear); + return gear; +} + + // query for data +int btWorldImporter::getNumCollisionShapes() const +{ + return m_allocatedCollisionShapes.size(); +} + +btCollisionShape* btWorldImporter::getCollisionShapeByIndex(int index) +{ + return m_allocatedCollisionShapes[index]; +} + +btCollisionShape* btWorldImporter::getCollisionShapeByName(const char* name) +{ + btCollisionShape** shapePtr = m_nameShapeMap.find(name); + if (shapePtr&& *shapePtr) + { + return *shapePtr; + } + return 0; +} + +btRigidBody* btWorldImporter::getRigidBodyByName(const char* name) +{ + btRigidBody** bodyPtr = m_nameBodyMap.find(name); + if (bodyPtr && *bodyPtr) + { + return *bodyPtr; + } + return 0; +} + +btTypedConstraint* btWorldImporter::getConstraintByName(const char* name) +{ + btTypedConstraint** constraintPtr = m_nameConstraintMap.find(name); + if (constraintPtr && *constraintPtr) + { + return *constraintPtr; + } + return 0; +} + +const char* btWorldImporter::getNameForPointer(const void* ptr) const +{ + const char*const * namePtr = m_objectNameMap.find(ptr); + if (namePtr && *namePtr) + return *namePtr; + return 0; +} + + +int btWorldImporter::getNumRigidBodies() const +{ + return m_allocatedRigidBodies.size(); +} + +btCollisionObject* btWorldImporter::getRigidBodyByIndex(int index) const +{ + return m_allocatedRigidBodies[index]; +} +int btWorldImporter::getNumConstraints() const +{ + return m_allocatedConstraints.size(); +} + +btTypedConstraint* btWorldImporter::getConstraintByIndex(int index) const +{ + return m_allocatedConstraints[index]; +} + +int btWorldImporter::getNumBvhs() const +{ + return m_allocatedBvhs.size(); +} + btOptimizedBvh* btWorldImporter::getBvhByIndex(int index) const +{ + return m_allocatedBvhs[index]; +} + +int btWorldImporter::getNumTriangleInfoMaps() const +{ + return m_allocatedTriangleInfoMaps.size(); +} + +btTriangleInfoMap* btWorldImporter::getTriangleInfoMapByIndex(int index) const +{ + return m_allocatedTriangleInfoMaps[index]; +} + + +void btWorldImporter::convertRigidBodyFloat( btRigidBodyFloatData* colObjData) +{ + btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f); + btVector3 localInertia; + localInertia.setZero(); + btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionObjectData.m_collisionShape); + if (shapePtr && *shapePtr) + { + btTransform startTransform; + colObjData->m_collisionObjectData.m_worldTransform.m_origin.m_floats[3] = 0.f; + startTransform.deSerializeFloat(colObjData->m_collisionObjectData.m_worldTransform); + + // startTransform.setBasis(btMatrix3x3::getIdentity()); + btCollisionShape* shape = (btCollisionShape*)*shapePtr; + if (shape->isNonMoving()) + { + mass = 0.f; + } + if (mass) + { + shape->calculateLocalInertia(mass,localInertia); + } + bool isDynamic = mass!=0.f; + btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name); + body->setFriction(colObjData->m_collisionObjectData.m_friction); + body->setRestitution(colObjData->m_collisionObjectData.m_restitution); + btVector3 linearFactor,angularFactor; + linearFactor.deSerializeFloat(colObjData->m_linearFactor); + angularFactor.deSerializeFloat(colObjData->m_angularFactor); + body->setLinearFactor(linearFactor); + body->setAngularFactor(angularFactor); + +#ifdef USE_INTERNAL_EDGE_UTILITY + if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) + { + btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape; + if (trimesh->getTriangleInfoMap()) + { + body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); + } + } +#endif //USE_INTERNAL_EDGE_UTILITY + m_bodyMap.insert(colObjData,body); + } else + { + printf("error: no shape found\n"); + } +} + +void btWorldImporter::convertRigidBodyDouble( btRigidBodyDoubleData* colObjData) +{ + btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f); + btVector3 localInertia; + localInertia.setZero(); + btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionObjectData.m_collisionShape); + if (shapePtr && *shapePtr) + { + btTransform startTransform; + colObjData->m_collisionObjectData.m_worldTransform.m_origin.m_floats[3] = 0.f; + startTransform.deSerializeDouble(colObjData->m_collisionObjectData.m_worldTransform); + + // startTransform.setBasis(btMatrix3x3::getIdentity()); + btCollisionShape* shape = (btCollisionShape*)*shapePtr; + if (shape->isNonMoving()) + { + mass = 0.f; + } + if (mass) + { + shape->calculateLocalInertia(mass,localInertia); + } + bool isDynamic = mass!=0.f; + btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name); + body->setFriction(btScalar(colObjData->m_collisionObjectData.m_friction)); + body->setRestitution(btScalar(colObjData->m_collisionObjectData.m_restitution)); + btVector3 linearFactor,angularFactor; + linearFactor.deSerializeDouble(colObjData->m_linearFactor); + angularFactor.deSerializeDouble(colObjData->m_angularFactor); + body->setLinearFactor(linearFactor); + body->setAngularFactor(angularFactor); + + +#ifdef USE_INTERNAL_EDGE_UTILITY + if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) + { + btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape; + if (trimesh->getTriangleInfoMap()) + { + body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); + } + } +#endif //USE_INTERNAL_EDGE_UTILITY + m_bodyMap.insert(colObjData,body); + } else + { + printf("error: no shape found\n"); + } +} diff --git a/Extras/Serialize/BulletWorldImporter/btWorldImporter.h b/Extras/Serialize/BulletWorldImporter/btWorldImporter.h new file mode 100644 index 0000000000..bcd6405d40 --- /dev/null +++ b/Extras/Serialize/BulletWorldImporter/btWorldImporter.h @@ -0,0 +1,212 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#ifndef BT_WORLD_IMPORTER_H +#define BT_WORLD_IMPORTER_H + +#include "LinearMath/btTransform.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "LinearMath/btHashMap.h" + +class btCollisionShape; +class btCollisionObject; +class btRigidBody; +class btTypedConstraint; +class btDynamicsWorld; +struct ConstraintInput; +class btRigidBodyColladaInfo; +struct btCollisionShapeData; +class btTriangleIndexVertexArray; +class btStridingMeshInterface; +struct btStridingMeshInterfaceData; +class btGImpactMeshShape; +class btOptimizedBvh; +struct btTriangleInfoMap; +class btBvhTriangleMeshShape; +class btPoint2PointConstraint; +class btHingeConstraint; +class btConeTwistConstraint; +class btGeneric6DofConstraint; +class btGeneric6DofSpringConstraint; +class btSliderConstraint; +class btGearConstraint; +struct btContactSolverInfo; +struct btTypedConstraintData; +struct btTypedConstraintFloatData; +struct btTypedConstraintDoubleData; + +struct btRigidBodyDoubleData; +struct btRigidBodyFloatData; + +#ifdef BT_USE_DOUBLE_PRECISION +#define btRigidBodyData btRigidBodyDoubleData +#else +#define btRigidBodyData btRigidBodyFloatData +#endif//BT_USE_DOUBLE_PRECISION + + +class btWorldImporter +{ +protected: + btDynamicsWorld* m_dynamicsWorld; + + int m_verboseMode; + + btAlignedObjectArray m_allocatedCollisionShapes; + btAlignedObjectArray m_allocatedRigidBodies; + btAlignedObjectArray m_allocatedConstraints; + btAlignedObjectArray m_allocatedBvhs; + btAlignedObjectArray m_allocatedTriangleInfoMaps; + btAlignedObjectArray m_allocatedTriangleIndexArrays; + btAlignedObjectArray m_allocatedbtStridingMeshInterfaceDatas; + + btAlignedObjectArray m_allocatedNames; + + btAlignedObjectArray m_indexArrays; + btAlignedObjectArray m_shortIndexArrays; + btAlignedObjectArray m_charIndexArrays; + + btAlignedObjectArray m_floatVertexArrays; + btAlignedObjectArray m_doubleVertexArrays; + + + btHashMap m_bvhMap; + btHashMap m_timMap; + + btHashMap m_nameShapeMap; + btHashMap m_nameBodyMap; + btHashMap m_nameConstraintMap; + btHashMap m_objectNameMap; + + btHashMap m_shapeMap; + btHashMap m_bodyMap; + + + //methods + + static btRigidBody& getFixedBody(); + + char* duplicateName(const char* name); + + btCollisionShape* convertCollisionShape( btCollisionShapeData* shapeData ); + + void convertConstraintBackwardsCompatible281(btTypedConstraintData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion); + void convertConstraintFloat(btTypedConstraintFloatData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion); + void convertConstraintDouble(btTypedConstraintDoubleData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion); + void convertRigidBodyFloat(btRigidBodyFloatData* colObjData); + void convertRigidBodyDouble( btRigidBodyDoubleData* colObjData); + +public: + + btWorldImporter(btDynamicsWorld* world); + + virtual ~btWorldImporter(); + + ///delete all memory collision shapes, rigid bodies, constraints etc. allocated during the load. + ///make sure you don't use the dynamics world containing objects after you call this method + virtual void deleteAllData(); + + void setVerboseMode(int verboseMode) + { + m_verboseMode = verboseMode; + } + + int getVerboseMode() const + { + return m_verboseMode; + } + + // query for data + int getNumCollisionShapes() const; + btCollisionShape* getCollisionShapeByIndex(int index); + int getNumRigidBodies() const; + btCollisionObject* getRigidBodyByIndex(int index) const; + int getNumConstraints() const; + btTypedConstraint* getConstraintByIndex(int index) const; + int getNumBvhs() const; + btOptimizedBvh* getBvhByIndex(int index) const; + int getNumTriangleInfoMaps() const; + btTriangleInfoMap* getTriangleInfoMapByIndex(int index) const; + + // queris involving named objects + btCollisionShape* getCollisionShapeByName(const char* name); + btRigidBody* getRigidBodyByName(const char* name); + btTypedConstraint* getConstraintByName(const char* name); + const char* getNameForPointer(const void* ptr) const; + + ///those virtuals are called by load and can be overridden by the user + + virtual void setDynamicsWorldInfo(const btVector3& gravity, const btContactSolverInfo& solverInfo); + + //bodies + virtual btRigidBody* createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform, btCollisionShape* shape,const char* bodyName); + virtual btCollisionObject* createCollisionObject( const btTransform& startTransform, btCollisionShape* shape,const char* bodyName); + + ///shapes + + virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant); + virtual btCollisionShape* createBoxShape(const btVector3& halfExtents); + virtual btCollisionShape* createSphereShape(btScalar radius); + virtual btCollisionShape* createCapsuleShapeX(btScalar radius, btScalar height); + virtual btCollisionShape* createCapsuleShapeY(btScalar radius, btScalar height); + virtual btCollisionShape* createCapsuleShapeZ(btScalar radius, btScalar height); + + virtual btCollisionShape* createCylinderShapeX(btScalar radius,btScalar height); + virtual btCollisionShape* createCylinderShapeY(btScalar radius,btScalar height); + virtual btCollisionShape* createCylinderShapeZ(btScalar radius,btScalar height); + virtual btCollisionShape* createConeShapeX(btScalar radius,btScalar height); + virtual btCollisionShape* createConeShapeY(btScalar radius,btScalar height); + virtual btCollisionShape* createConeShapeZ(btScalar radius,btScalar height); + virtual class btTriangleIndexVertexArray* createTriangleMeshContainer(); + virtual btBvhTriangleMeshShape* createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh); + virtual btCollisionShape* createConvexTriangleMeshShape(btStridingMeshInterface* trimesh); + virtual btGImpactMeshShape* createGimpactShape(btStridingMeshInterface* trimesh); + virtual btStridingMeshInterfaceData* createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData); + + virtual class btConvexHullShape* createConvexHullShape(); + virtual class btCompoundShape* createCompoundShape(); + virtual class btScaledBvhTriangleMeshShape* createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape,const btVector3& localScalingbtBvhTriangleMeshShape); + + virtual class btMultiSphereShape* createMultiSphereShape(const btVector3* positions,const btScalar* radi,int numSpheres); + + virtual btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData); + + ///acceleration and connectivity structures + virtual btOptimizedBvh* createOptimizedBvh(); + virtual btTriangleInfoMap* createTriangleInfoMap(); + + ///constraints + virtual btPoint2PointConstraint* createPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB); + virtual btPoint2PointConstraint* createPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA); + virtual btHingeConstraint* createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA=false); + virtual btHingeConstraint* createHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA=false); + virtual btConeTwistConstraint* createConeTwistConstraint(btRigidBody& rbA,btRigidBody& rbB,const btTransform& rbAFrame, const btTransform& rbBFrame); + virtual btConeTwistConstraint* createConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame); + virtual btGeneric6DofConstraint* createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); + virtual btGeneric6DofConstraint* createGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB); + virtual btGeneric6DofSpringConstraint* createGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); + virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); + virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA); + virtual btGearConstraint* createGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio); + + + + +}; + + +#endif //BT_WORLD_IMPORTER_H \ No newline at end of file diff --git a/Extras/Serialize/BulletWorldImporter/premake4.lua b/Extras/Serialize/BulletWorldImporter/premake4.lua new file mode 100644 index 0000000000..d847c7a92d --- /dev/null +++ b/Extras/Serialize/BulletWorldImporter/premake4.lua @@ -0,0 +1,13 @@ + project "BulletWorldImporter" + + kind "StaticLib" + targetdir "../../lib" + includedirs { + "../BulletFileLoader", + "../../../src" + } + + files { + "**.cpp", + "**.h" + } \ No newline at end of file diff --git a/Extras/Serialize/BulletXmlWorldImporter/CMakeLists.txt b/Extras/Serialize/BulletXmlWorldImporter/CMakeLists.txt new file mode 100644 index 0000000000..c6a94f8502 --- /dev/null +++ b/Extras/Serialize/BulletXmlWorldImporter/CMakeLists.txt @@ -0,0 +1,47 @@ +INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter +) + +ADD_LIBRARY( + BulletXmlWorldImporter + btBulletXmlWorldImporter.cpp + btBulletXmlWorldImporter.h + string_split.cpp + string_split.h + tinyxml.cpp + tinyxml.h + tinystr.cpp + tinystr.h + tinyxmlerror.cpp + tinyxmlparser.cpp +) + +SET_TARGET_PROPERTIES(BulletXmlWorldImporter PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(BulletXmlWorldImporter PROPERTIES SOVERSION ${BULLET_VERSION}) + +IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(BulletXmlWorldImporter BulletWorldImporter BulletDynamics BulletCollision BulletFileLoader LinearMath) +ENDIF (BUILD_SHARED_LIBS) + +IF (INSTALL_EXTRA_LIBS) + IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) + #FILES_MATCHING requires CMake 2.6 + IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletXmlWorldImporter DESTINATION .) + ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletXmlWorldImporter DESTINATION lib${LIB_SUFFIX}) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN +".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE) + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + SET_TARGET_PROPERTIES(BulletXmlWorldImporter PROPERTIES FRAMEWORK true) + SET_TARGET_PROPERTIES(BulletXmlWorldImporter PROPERTIES PUBLIC_HEADER "btBulletXmlWorldImporter.h") + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) +ENDIF (INSTALL_EXTRA_LIBS) diff --git a/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.cpp b/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.cpp new file mode 100644 index 0000000000..f3615d6aa3 --- /dev/null +++ b/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.cpp @@ -0,0 +1,871 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "btBulletXmlWorldImporter.h" +#include "tinyxml.h" +#include "btBulletDynamicsCommon.h" +#include "string_split.h" + + +btBulletXmlWorldImporter::btBulletXmlWorldImporter(btDynamicsWorld* world) + :btWorldImporter(world), + m_fileVersion(-1), + m_fileOk(false) +{ + +} + +btBulletXmlWorldImporter::~btBulletXmlWorldImporter() +{ + +} + + +static int get_double_attribute_by_name(const TiXmlElement* pElement, const char* attribName,double* value) +{ + if ( !pElement ) + return 0; + + const TiXmlAttribute* pAttrib=pElement->FirstAttribute(); + while (pAttrib) + { + if (pAttrib->Name()==attribName) + if (pAttrib->QueryDoubleValue(value)==TIXML_SUCCESS) + return 1; + pAttrib=pAttrib->Next(); + } + return 0; +} + + +static int get_int_attribute_by_name(const TiXmlElement* pElement, const char* attribName,int* value) +{ + if ( !pElement ) + return 0; + + const TiXmlAttribute* pAttrib=pElement->FirstAttribute(); + while (pAttrib) + { + if (!strcmp(pAttrib->Name(),attribName)) + if (pAttrib->QueryIntValue(value)==TIXML_SUCCESS) + return 1; +// if (pAttrib->QueryDoubleValue(&dval)==TIXML_SUCCESS) printf( " d=%1.1f", dval); + pAttrib=pAttrib->Next(); + } + return 0; +} + +void stringToFloatArray(const std::string& string, btAlignedObjectArray& floats) +{ + btAlignedObjectArray pieces; + + bullet_utils::split( pieces, string, " "); + for ( int i = 0; i < pieces.size(); ++i) + { + assert(pieces[i]!=""); + floats.push_back((float)atof(pieces[i].c_str())); + } + +} + +static btVector3FloatData TextToVector3Data(const char* txt) +{ + btAssert(txt); + btAlignedObjectArray floats; + stringToFloatArray(txt, floats); + assert(floats.size()==4); + + btVector3FloatData vec4; + vec4.m_floats[0] = floats[0]; + vec4.m_floats[1] = floats[1]; + vec4.m_floats[2] = floats[2]; + vec4.m_floats[3] = floats[3]; + return vec4; +} + +void btBulletXmlWorldImporter::deSerializeVector3FloatData(TiXmlNode* pParent,btAlignedObjectArray& vectors) +{ + TiXmlNode* flNode = pParent->FirstChild("m_floats"); + btAssert(flNode); + while (flNode && flNode->FirstChild()) + { + TiXmlText* pText = flNode->FirstChild()->ToText(); +// printf("value = %s\n",pText->Value()); + btVector3FloatData vec4 = TextToVector3Data(pText->Value()); + vectors.push_back(vec4); + flNode = flNode->NextSibling(); + } + +} + + +#define SET_INT_VALUE(xmlnode, targetdata, argname) \ + btAssert((xmlnode)->FirstChild(#argname) && (xmlnode)->FirstChild(#argname)->ToElement());\ + if ((xmlnode)->FirstChild(#argname) && (xmlnode)->FirstChild(#argname)->ToElement())\ + (targetdata)->argname= (int)atof(xmlnode->FirstChild(#argname)->ToElement()->GetText()); + + +#define SET_FLOAT_VALUE(xmlnode, targetdata, argname) \ + btAssert((xmlnode)->FirstChild(#argname) && (xmlnode)->FirstChild(#argname)->ToElement());\ + if ((xmlnode)->FirstChild(#argname) && (xmlnode)->FirstChild(#argname)->ToElement())\ + (targetdata)->argname= (float)atof(xmlnode->FirstChild(#argname)->ToElement()->GetText()); + + +#define SET_POINTER_VALUE(xmlnode, targetdata, argname, pointertype) \ + {\ + TiXmlNode* node = xmlnode->FirstChild(#argname);\ + btAssert(node);\ + if (node)\ + {\ + const char* txt = (node)->ToElement()->GetText();\ + (targetdata).argname= (pointertype) (int) atof(txt);\ + }\ + } + +#define SET_VECTOR4_VALUE(xmlnode, targetdata, argname) \ + {\ + TiXmlNode* flNode = xmlnode->FirstChild(#argname);\ + btAssert(flNode);\ + if (flNode && flNode->FirstChild())\ + {\ + const char* txt= flNode->FirstChild()->ToElement()->GetText();\ + btVector3FloatData vec4 = TextToVector3Data(txt);\ + (targetdata)->argname.m_floats[0] = vec4.m_floats[0];\ + (targetdata)->argname.m_floats[1] = vec4.m_floats[1];\ + (targetdata)->argname.m_floats[2] = vec4.m_floats[2];\ + (targetdata)->argname.m_floats[3] = vec4.m_floats[3];\ + }\ + } + + +#define SET_MATRIX33_VALUE(n, targetdata, argname) \ +{\ + TiXmlNode* xmlnode = n->FirstChild(#argname);\ + btAssert(xmlnode);\ + if (xmlnode)\ + {\ + TiXmlNode* eleNode = xmlnode->FirstChild("m_el");\ + btAssert(eleNode);\ + if (eleNode&& eleNode->FirstChild())\ + {\ + const char* txt= eleNode->FirstChild()->ToElement()->GetText();\ + btVector3FloatData vec4 = TextToVector3Data(txt);\ + (targetdata)->argname.m_el[0].m_floats[0] = vec4.m_floats[0];\ + (targetdata)->argname.m_el[0].m_floats[1] = vec4.m_floats[1];\ + (targetdata)->argname.m_el[0].m_floats[2] = vec4.m_floats[2];\ + (targetdata)->argname.m_el[0].m_floats[3] = vec4.m_floats[3];\ + \ + TiXmlNode* n1 = eleNode->FirstChild()->NextSibling();\ + btAssert(n1);\ + if (n1)\ + {\ + const char* txt= n1->ToElement()->GetText();\ + btVector3FloatData vec4 = TextToVector3Data(txt);\ + (targetdata)->argname.m_el[1].m_floats[0] = vec4.m_floats[0];\ + (targetdata)->argname.m_el[1].m_floats[1] = vec4.m_floats[1];\ + (targetdata)->argname.m_el[1].m_floats[2] = vec4.m_floats[2];\ + (targetdata)->argname.m_el[1].m_floats[3] = vec4.m_floats[3];\ + \ + TiXmlNode* n2 = n1->NextSibling();\ + btAssert(n2);\ + if (n2)\ + {\ + const char* txt= n2->ToElement()->GetText();\ + btVector3FloatData vec4 = TextToVector3Data(txt);\ + (targetdata)->argname.m_el[2].m_floats[0] = vec4.m_floats[0];\ + (targetdata)->argname.m_el[2].m_floats[1] = vec4.m_floats[1];\ + (targetdata)->argname.m_el[2].m_floats[2] = vec4.m_floats[2];\ + (targetdata)->argname.m_el[2].m_floats[3] = vec4.m_floats[3];\ + }\ + }\ + }\ + }\ +}\ + +#define SET_TRANSFORM_VALUE(n, targetdata, argname) \ +{\ + TiXmlNode* trNode = n->FirstChild(#argname);\ + btAssert(trNode);\ + if (trNode)\ + {\ + SET_VECTOR4_VALUE(trNode,&(targetdata)->argname,m_origin)\ + SET_MATRIX33_VALUE(trNode, &(targetdata)->argname,m_basis)\ + }\ +}\ + + +void btBulletXmlWorldImporter::deSerializeCollisionShapeData(TiXmlNode* pParent, btCollisionShapeData* colShapeData) +{ + SET_INT_VALUE(pParent,colShapeData,m_shapeType) + colShapeData->m_name = 0; +} + + + +void btBulletXmlWorldImporter::deSerializeConvexHullShapeData(TiXmlNode* pParent) +{ + int ptr; + get_int_attribute_by_name(pParent->ToElement(),"pointer",&ptr); + + btConvexHullShapeData* convexHullData = (btConvexHullShapeData*)btAlignedAlloc(sizeof(btConvexHullShapeData), 16); + + TiXmlNode* xmlConvexInt = pParent->FirstChild("m_convexInternalShapeData"); + btAssert(xmlConvexInt); + + TiXmlNode* xmlColShape = xmlConvexInt ->FirstChild("m_collisionShapeData"); + btAssert(xmlColShape); + + deSerializeCollisionShapeData(xmlColShape,&convexHullData->m_convexInternalShapeData.m_collisionShapeData); + + SET_FLOAT_VALUE(xmlConvexInt,&convexHullData->m_convexInternalShapeData,m_collisionMargin) + SET_VECTOR4_VALUE(xmlConvexInt,&convexHullData->m_convexInternalShapeData,m_localScaling) + SET_VECTOR4_VALUE(xmlConvexInt,&convexHullData->m_convexInternalShapeData,m_implicitShapeDimensions) + + SET_POINTER_VALUE(pParent,*convexHullData,m_unscaledPointsFloatPtr,btVector3FloatData*); + SET_POINTER_VALUE(pParent,*convexHullData,m_unscaledPointsDoublePtr,btVector3DoubleData*); + SET_INT_VALUE(pParent,convexHullData,m_numUnscaledPoints); + + m_collisionShapeData.push_back((btCollisionShapeData*)convexHullData); + m_pointerLookup.insert((void*)ptr,convexHullData); +} + +void btBulletXmlWorldImporter::deSerializeCompoundShapeChildData(TiXmlNode* pParent) +{ + int ptr; + get_int_attribute_by_name(pParent->ToElement(),"pointer",&ptr); + + int numChildren = 0; + btAlignedObjectArray* compoundChildArrayPtr = new btAlignedObjectArray; + { + TiXmlNode* transNode = pParent->FirstChild("m_transform"); + TiXmlNode* colShapeNode = pParent->FirstChild("m_childShape"); + TiXmlNode* marginNode = pParent->FirstChild("m_childMargin"); + TiXmlNode* childTypeNode = pParent->FirstChild("m_childShapeType"); + + int i=0; + while (transNode && colShapeNode && marginNode && childTypeNode) + { + compoundChildArrayPtr->expandNonInitializing(); + SET_VECTOR4_VALUE (transNode,&compoundChildArrayPtr->at(i).m_transform,m_origin) + SET_MATRIX33_VALUE(transNode,&compoundChildArrayPtr->at(i).m_transform,m_basis) + + const char* txt = (colShapeNode)->ToElement()->GetText(); + compoundChildArrayPtr->at(i).m_childShape = (btCollisionShapeData*) (int) atof(txt); + + btAssert(childTypeNode->ToElement()); + if (childTypeNode->ToElement()) + { + compoundChildArrayPtr->at(i).m_childShapeType = (int)atof(childTypeNode->ToElement()->GetText()); + } + + btAssert(marginNode->ToElement()); + if (marginNode->ToElement()) + { + compoundChildArrayPtr->at(i).m_childMargin = (float)atof(marginNode->ToElement()->GetText()); + } + + transNode = transNode->NextSibling("m_transform"); + colShapeNode = colShapeNode->NextSibling("m_childShape"); + marginNode = marginNode->NextSibling("m_childMargin"); + childTypeNode = childTypeNode->NextSibling("m_childShapeType"); + i++; + } + + numChildren = i; + + } + + btAssert(numChildren); + if (numChildren) + { + m_compoundShapeChildDataArrays.push_back(compoundChildArrayPtr); + btCompoundShapeChildData* cd = &compoundChildArrayPtr->at(0); + m_pointerLookup.insert((void*)ptr,cd); + } + +} + +void btBulletXmlWorldImporter::deSerializeCompoundShapeData(TiXmlNode* pParent) +{ + int ptr; + get_int_attribute_by_name(pParent->ToElement(),"pointer",&ptr); + + btCompoundShapeData* compoundData = (btCompoundShapeData*) btAlignedAlloc(sizeof(btCompoundShapeData),16); + + TiXmlNode* xmlColShape = pParent ->FirstChild("m_collisionShapeData"); + btAssert(xmlColShape); + deSerializeCollisionShapeData(xmlColShape,&compoundData->m_collisionShapeData); + + SET_INT_VALUE(pParent, compoundData,m_numChildShapes); + + TiXmlNode* xmlShapeData = pParent->FirstChild("m_collisionShapeData"); + btAssert(xmlShapeData ); + + { + TiXmlNode* node = pParent->FirstChild("m_childShapePtr");\ + btAssert(node); + while (node) + { + const char* txt = (node)->ToElement()->GetText(); + compoundData->m_childShapePtr = (btCompoundShapeChildData*) (int) atof(txt); + node = node->NextSibling("m_childShapePtr"); + } + //SET_POINTER_VALUE(xmlColShape, *compoundData,m_childShapePtr,btCompoundShapeChildData*); + + } + SET_FLOAT_VALUE(pParent, compoundData,m_collisionMargin); + + m_collisionShapeData.push_back((btCollisionShapeData*)compoundData); + m_pointerLookup.insert((void*)ptr,compoundData); + +} + +void btBulletXmlWorldImporter::deSerializeStaticPlaneShapeData(TiXmlNode* pParent) +{ + int ptr; + get_int_attribute_by_name(pParent->ToElement(),"pointer",&ptr); + + btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*) btAlignedAlloc(sizeof(btStaticPlaneShapeData),16); + + TiXmlNode* xmlShapeData = pParent->FirstChild("m_collisionShapeData"); + btAssert(xmlShapeData ); + deSerializeCollisionShapeData(xmlShapeData,&planeData->m_collisionShapeData); + + SET_VECTOR4_VALUE(pParent, planeData,m_localScaling); + SET_VECTOR4_VALUE(pParent, planeData,m_planeNormal); + SET_FLOAT_VALUE(pParent, planeData,m_planeConstant); + + m_collisionShapeData.push_back((btCollisionShapeData*)planeData); + m_pointerLookup.insert((void*)ptr,planeData); + +} + +void btBulletXmlWorldImporter::deSerializeDynamicsWorldData(TiXmlNode* pParent) +{ + btContactSolverInfo solverInfo; + //btVector3 gravity(0,0,0); + + //setDynamicsWorldInfo(gravity,solverInfo); + + //gravity and world info +} + +void btBulletXmlWorldImporter::deSerializeConvexInternalShapeData(TiXmlNode* pParent) +{ + int ptr=0; + get_int_attribute_by_name(pParent->ToElement(),"pointer",&ptr); + + + btConvexInternalShapeData* convexShape = (btConvexInternalShapeData*) btAlignedAlloc(sizeof(btConvexInternalShapeData),16); + memset(convexShape,0,sizeof(btConvexInternalShapeData)); + + TiXmlNode* xmlShapeData = pParent->FirstChild("m_collisionShapeData"); + btAssert(xmlShapeData ); + + deSerializeCollisionShapeData(xmlShapeData,&convexShape->m_collisionShapeData); + + + SET_FLOAT_VALUE(pParent,convexShape,m_collisionMargin) + SET_VECTOR4_VALUE(pParent,convexShape,m_localScaling) + SET_VECTOR4_VALUE(pParent,convexShape,m_implicitShapeDimensions) + + m_collisionShapeData.push_back((btCollisionShapeData*)convexShape); + m_pointerLookup.insert((void*)ptr,convexShape); + +} + +/* +enum btTypedConstraintType +{ + POINT2POINT_CONSTRAINT_TYPE=3, + HINGE_CONSTRAINT_TYPE, + CONETWIST_CONSTRAINT_TYPE, +// D6_CONSTRAINT_TYPE, + SLIDER_CONSTRAINT_TYPE, + CONTACT_CONSTRAINT_TYPE, + D6_SPRING_CONSTRAINT_TYPE, + GEAR_CONSTRAINT_TYPE, + MAX_CONSTRAINT_TYPE +}; +*/ + + +void btBulletXmlWorldImporter::deSerializeGeneric6DofConstraintData(TiXmlNode* pParent) +{ + int ptr=0; + get_int_attribute_by_name(pParent->ToElement(),"pointer",&ptr); + + btGeneric6DofConstraintData2* dof6Data = (btGeneric6DofConstraintData2*)btAlignedAlloc(sizeof(btGeneric6DofConstraintData2),16); + + + TiXmlNode* n = pParent->FirstChild("m_typeConstraintData"); + if (n) + { + SET_POINTER_VALUE(n,dof6Data->m_typeConstraintData,m_rbA,btRigidBodyData*); + SET_POINTER_VALUE(n,dof6Data->m_typeConstraintData,m_rbB,btRigidBodyData*); + dof6Data->m_typeConstraintData.m_name = 0;//tbd + SET_INT_VALUE(n,&dof6Data->m_typeConstraintData,m_objectType); + SET_INT_VALUE(n,&dof6Data->m_typeConstraintData,m_userConstraintType); + SET_INT_VALUE(n,&dof6Data->m_typeConstraintData,m_userConstraintId); + SET_INT_VALUE(n,&dof6Data->m_typeConstraintData,m_needsFeedback); + SET_FLOAT_VALUE(n,&dof6Data->m_typeConstraintData,m_appliedImpulse); + SET_FLOAT_VALUE(n,&dof6Data->m_typeConstraintData,m_dbgDrawSize); + SET_INT_VALUE(n,&dof6Data->m_typeConstraintData,m_disableCollisionsBetweenLinkedBodies); + SET_INT_VALUE(n,&dof6Data->m_typeConstraintData,m_overrideNumSolverIterations); + SET_FLOAT_VALUE(n,&dof6Data->m_typeConstraintData,m_breakingImpulseThreshold); + SET_INT_VALUE(n,&dof6Data->m_typeConstraintData,m_isEnabled); + + } + + SET_TRANSFORM_VALUE( pParent, dof6Data, m_rbAFrame); + SET_TRANSFORM_VALUE( pParent, dof6Data, m_rbBFrame); + SET_VECTOR4_VALUE(pParent, dof6Data, m_linearUpperLimit); + SET_VECTOR4_VALUE(pParent, dof6Data, m_linearLowerLimit); + SET_VECTOR4_VALUE(pParent, dof6Data, m_angularUpperLimit); + SET_VECTOR4_VALUE(pParent, dof6Data, m_angularLowerLimit); + SET_INT_VALUE(pParent, dof6Data,m_useLinearReferenceFrameA); + SET_INT_VALUE(pParent, dof6Data,m_useOffsetForConstraintFrame); + + m_constraintData.push_back((btTypedConstraintData2*)dof6Data); + m_pointerLookup.insert((void*)ptr,dof6Data); +} + +void btBulletXmlWorldImporter::deSerializeRigidBodyFloatData(TiXmlNode* pParent) +{ + int ptr=0; + if (!get_int_attribute_by_name(pParent->ToElement(),"pointer",&ptr)) + { + m_fileOk = false; + return; + } + + btRigidBodyData* rbData = (btRigidBodyData*)btAlignedAlloc(sizeof(btRigidBodyData),16); + + TiXmlNode* n = pParent->FirstChild("m_collisionObjectData"); + + if (n) + { + SET_POINTER_VALUE(n,rbData->m_collisionObjectData,m_collisionShape, void*); + SET_TRANSFORM_VALUE(n,&rbData->m_collisionObjectData,m_worldTransform); + SET_TRANSFORM_VALUE(n,&rbData->m_collisionObjectData,m_interpolationWorldTransform); + SET_VECTOR4_VALUE(n,&rbData->m_collisionObjectData,m_interpolationLinearVelocity) + SET_VECTOR4_VALUE(n,&rbData->m_collisionObjectData,m_interpolationAngularVelocity) + SET_VECTOR4_VALUE(n,&rbData->m_collisionObjectData,m_anisotropicFriction) + SET_FLOAT_VALUE(n,&rbData->m_collisionObjectData,m_contactProcessingThreshold); + SET_FLOAT_VALUE(n,&rbData->m_collisionObjectData,m_deactivationTime); + SET_FLOAT_VALUE(n,&rbData->m_collisionObjectData,m_friction); + SET_FLOAT_VALUE(n,&rbData->m_collisionObjectData,m_restitution); + SET_FLOAT_VALUE(n,&rbData->m_collisionObjectData,m_hitFraction); + SET_FLOAT_VALUE(n,&rbData->m_collisionObjectData,m_ccdSweptSphereRadius); + SET_FLOAT_VALUE(n,&rbData->m_collisionObjectData,m_ccdMotionThreshold); + SET_INT_VALUE(n,&rbData->m_collisionObjectData,m_hasAnisotropicFriction); + SET_INT_VALUE(n,&rbData->m_collisionObjectData,m_collisionFlags); + SET_INT_VALUE(n,&rbData->m_collisionObjectData,m_islandTag1); + SET_INT_VALUE(n,&rbData->m_collisionObjectData,m_companionId); + SET_INT_VALUE(n,&rbData->m_collisionObjectData,m_activationState1); + SET_INT_VALUE(n,&rbData->m_collisionObjectData,m_internalType); + SET_INT_VALUE(n,&rbData->m_collisionObjectData,m_checkCollideWith); + } + +// SET_VECTOR4_VALUE(pParent,rbData,m_linearVelocity); + + SET_MATRIX33_VALUE(pParent,rbData,m_invInertiaTensorWorld); + + + SET_VECTOR4_VALUE(pParent,rbData,m_linearVelocity) + SET_VECTOR4_VALUE(pParent,rbData,m_angularVelocity) + SET_VECTOR4_VALUE(pParent,rbData,m_angularFactor) + SET_VECTOR4_VALUE(pParent,rbData,m_linearFactor) + SET_VECTOR4_VALUE(pParent,rbData,m_gravity) + SET_VECTOR4_VALUE(pParent,rbData,m_gravity_acceleration ) + SET_VECTOR4_VALUE(pParent,rbData,m_invInertiaLocal) + SET_VECTOR4_VALUE(pParent,rbData,m_totalTorque) + SET_VECTOR4_VALUE(pParent,rbData,m_totalForce) + SET_FLOAT_VALUE(pParent,rbData,m_inverseMass); + SET_FLOAT_VALUE(pParent,rbData,m_linearDamping); + SET_FLOAT_VALUE(pParent,rbData,m_angularDamping); + SET_FLOAT_VALUE(pParent,rbData,m_additionalDampingFactor); + SET_FLOAT_VALUE(pParent,rbData,m_additionalLinearDampingThresholdSqr); + SET_FLOAT_VALUE(pParent,rbData,m_additionalAngularDampingThresholdSqr); + SET_FLOAT_VALUE(pParent,rbData,m_additionalAngularDampingFactor); + SET_FLOAT_VALUE(pParent,rbData,m_angularSleepingThreshold); + SET_FLOAT_VALUE(pParent,rbData,m_linearSleepingThreshold); + SET_INT_VALUE(pParent,rbData,m_additionalDamping); + + + m_rigidBodyData.push_back(rbData); + m_pointerLookup.insert((void*)ptr,rbData); + +// rbData->m_collisionObjectData.m_collisionShape = (void*) (int)atof(txt); +} + +/* + TETRAHEDRAL_SHAPE_PROXYTYPE, + CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE, + , + CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE, + CUSTOM_POLYHEDRAL_SHAPE_TYPE, +//implicit convex shapes +IMPLICIT_CONVEX_SHAPES_START_HERE, + SPHERE_SHAPE_PROXYTYPE, + MULTI_SPHERE_SHAPE_PROXYTYPE, + CAPSULE_SHAPE_PROXYTYPE, + CONE_SHAPE_PROXYTYPE, + CONVEX_SHAPE_PROXYTYPE, + CYLINDER_SHAPE_PROXYTYPE, + UNIFORM_SCALING_SHAPE_PROXYTYPE, + MINKOWSKI_SUM_SHAPE_PROXYTYPE, + MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE, + BOX_2D_SHAPE_PROXYTYPE, + CONVEX_2D_SHAPE_PROXYTYPE, + CUSTOM_CONVEX_SHAPE_TYPE, +//concave shapes +CONCAVE_SHAPES_START_HERE, + //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy! + TRIANGLE_MESH_SHAPE_PROXYTYPE, + SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE, + ///used for demo integration FAST/Swift collision library and Bullet + FAST_CONCAVE_MESH_PROXYTYPE, + //terrain + TERRAIN_SHAPE_PROXYTYPE, +///Used for GIMPACT Trimesh integration + GIMPACT_SHAPE_PROXYTYPE, +///Multimaterial mesh + MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE, + + , + , + CUSTOM_CONCAVE_SHAPE_TYPE, +CONCAVE_SHAPES_END_HERE, + + , + + SOFTBODY_SHAPE_PROXYTYPE, + HFFLUID_SHAPE_PROXYTYPE, + HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE, + INVALID_SHAPE_PROXYTYPE, + + MAX_BROADPHASE_COLLISION_TYPES +*/ + +void btBulletXmlWorldImporter::fixupConstraintData(btTypedConstraintData2* tcd) +{ + if (tcd->m_rbA) + { + btRigidBodyData** ptrptr = (btRigidBodyData**)m_pointerLookup.find(tcd->m_rbA); + btAssert(ptrptr); + tcd->m_rbA = ptrptr? *ptrptr : 0; + } + if (tcd->m_rbB) + { + btRigidBodyData** ptrptr = (btRigidBodyData**)m_pointerLookup.find(tcd->m_rbB); + btAssert(ptrptr); + tcd->m_rbB = ptrptr? *ptrptr : 0; + } + +} + +void btBulletXmlWorldImporter::fixupCollisionDataPointers(btCollisionShapeData* shapeData) +{ + + switch (shapeData->m_shapeType) + { + + case COMPOUND_SHAPE_PROXYTYPE: + { + btCompoundShapeData* compound = (btCompoundShapeData*) shapeData; + + void** cdptr = m_pointerLookup.find((void*)compound->m_childShapePtr); + btCompoundShapeChildData** c = (btCompoundShapeChildData**)cdptr; + btAssert(c); + if (c) + { + compound->m_childShapePtr = *c; + } else + { + compound->m_childShapePtr = 0; + } + break; + } + + case CONVEX_HULL_SHAPE_PROXYTYPE: + { + btConvexHullShapeData* convexData = (btConvexHullShapeData*)shapeData; + btVector3FloatData** ptrptr = (btVector3FloatData**)m_pointerLookup.find((void*)convexData->m_unscaledPointsFloatPtr); + btAssert(ptrptr); + if (ptrptr) + { + convexData->m_unscaledPointsFloatPtr = *ptrptr; + } else + { + convexData->m_unscaledPointsFloatPtr = 0; + } + break; + } + + case BOX_SHAPE_PROXYTYPE: + case TRIANGLE_SHAPE_PROXYTYPE: + case STATIC_PLANE_PROXYTYPE: + case EMPTY_SHAPE_PROXYTYPE: + break; + + default: + { + btAssert(0); + } + } +} + + +void btBulletXmlWorldImporter::auto_serialize_root_level_children(TiXmlNode* pParent) +{ + int numChildren = 0; + btAssert(pParent); + if (pParent) + { + TiXmlNode*pChild; + for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling(), numChildren++) + { +// printf("child Name=%s\n", pChild->Value()); + if (!strcmp(pChild->Value(),"btVector3FloatData")) + { + int ptr; + get_int_attribute_by_name(pChild->ToElement(),"pointer",&ptr); + + btAlignedObjectArray v; + deSerializeVector3FloatData(pChild,v); + int numVectors = v.size(); + btVector3FloatData* vectors= (btVector3FloatData*) btAlignedAlloc(sizeof(btVector3FloatData)*numVectors,16); + for (int i=0;iValue(),"btGeneric6DofConstraintData")) + { + deSerializeGeneric6DofConstraintData(pChild); + continue; + } + + if (!strcmp(pChild->Value(),"btStaticPlaneShapeData")) + { + deSerializeStaticPlaneShapeData(pChild); + continue; + } + + if (!strcmp(pChild->Value(),"btCompoundShapeData")) + { + deSerializeCompoundShapeData(pChild); + continue; + } + + if (!strcmp(pChild->Value(),"btCompoundShapeChildData")) + { + deSerializeCompoundShapeChildData(pChild); + continue; + } + + if (!strcmp(pChild->Value(),"btConvexHullShapeData")) + { + deSerializeConvexHullShapeData(pChild); + continue; + } + + if (!strcmp(pChild->Value(),"btDynamicsWorldFloatData")) + { + deSerializeDynamicsWorldData(pChild); + continue; + } + + + if (!strcmp(pChild->Value(),"btConvexInternalShapeData")) + { + deSerializeConvexInternalShapeData(pChild); + continue; + } + if (!strcmp(pChild->Value(),"btRigidBodyFloatData")) + { + deSerializeRigidBodyFloatData(pChild); + continue; + } + + //printf("Error: btBulletXmlWorldImporter doesn't support %s yet\n", pChild->Value()); + // btAssert(0); + } + } + + ///================================================================= + ///fixup pointers in various places, in the right order + + //fixup compoundshape child data + for (int i=0;i* childDataArray = m_compoundShapeChildDataArrays[i]; + for (int c=0;csize();c++) + { + btCompoundShapeChildData* childData = &childDataArray->at(c); + btCollisionShapeData** ptrptr = (btCollisionShapeData**)m_pointerLookup[childData->m_childShape]; + btAssert(ptrptr); + if (ptrptr) + { + childData->m_childShape = *ptrptr; + } + } + } + + for (int i=0;im_collisionShapeData.size();i++) + { + btCollisionShapeData* shapeData = m_collisionShapeData[i]; + fixupCollisionDataPointers(shapeData); + + } + + ///now fixup pointers + for (int i=0;im_collisionObjectData.m_collisionShape); + //btAssert(ptrptr); + rbData->m_collisionObjectData.m_broadphaseHandle = 0; + rbData->m_collisionObjectData.m_rootCollisionShape = 0; + rbData->m_collisionObjectData.m_name = 0;//tbd + if (ptrptr) + { + rbData->m_collisionObjectData.m_collisionShape = *ptrptr; + } + } + + + + for (int i=0;im_collisionShapeData.size();i++) + { + btCollisionShapeData* shapeData = m_collisionShapeData[i]; + btCollisionShape* shape = convertCollisionShape(shapeData); + if (shape) + { + m_shapeMap.insert(shapeData,shape); + } + if (shape&& shapeData->m_name) + { + char* newname = duplicateName(shapeData->m_name); + m_objectNameMap.insert(shape,newname); + m_nameShapeMap.insert(newname,shape); + } + } + + for (int i=0;im_rbA); + if (ptrptr) + { + rbA = btRigidBody::upcast(*ptrptr); + } + } + { + btCollisionObject** ptrptr = m_bodyMap.find(tcd->m_rbB); + if (ptrptr) + { + rbB = btRigidBody::upcast(*ptrptr); + } + } + if (rbA || rbB) + { + btAssert(0);//todo + //convertConstraint(tcd,rbA,rbB,isDoublePrecision, m_fileVersion); + } + + } +} + +void btBulletXmlWorldImporter::auto_serialize(TiXmlNode* pParent) +{ +// TiXmlElement* root = pParent->FirstChildElement("bullet_physics"); + if (pParent) + { + TiXmlNode*pChild; + for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) + { + if (pChild->Type()==TiXmlNode::TINYXML_ELEMENT) + { +// printf("root Name=%s\n", pChild->Value()); + auto_serialize_root_level_children(pChild); + } + } + } else + { + printf("ERROR: no bullet_physics element\n"); + } +} + + + + +bool btBulletXmlWorldImporter::loadFile(const char* fileName) +{ + TiXmlDocument doc(fileName); + + bool loadOkay = doc.LoadFile(); + //dump_to_stdout(&doc,0); + + + if (loadOkay) + { + if (get_int_attribute_by_name(doc.FirstChildElement()->ToElement(),"version", &m_fileVersion)) + { + if (m_fileVersion==281) + { + m_fileOk = true; + int itemcount; + get_int_attribute_by_name(doc.FirstChildElement()->ToElement(),"itemcount", &itemcount); + + auto_serialize(&doc); + return m_fileOk; + + } + } + } + return false; +} + + + + diff --git a/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.h b/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.h new file mode 100644 index 0000000000..99686c8a09 --- /dev/null +++ b/Extras/Serialize/BulletXmlWorldImporter/btBulletXmlWorldImporter.h @@ -0,0 +1,87 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef BT_BULLET_XML_WORLD_IMPORTER_H +#define BT_BULLET_XML_WORLD_IMPORTER_H + +#include "LinearMath/btScalar.h" + +class btDynamicsWorld; +class TiXmlNode; +struct btConvexInternalShapeData; +struct btCollisionShapeData; +#ifdef BT_USE_DOUBLE_PRECISION +struct btRigidBodyDoubleData; +struct btTypedConstraintDoubleData; +#define btRigidBodyData btRigidBodyDoubleData +#define btTypedConstraintData2 btTypedConstraintDoubleData +#else +struct btRigidBodyFloatData; +struct btTypedConstraintFloatData; +#define btTypedConstraintData2 btTypedConstraintFloatData +#define btRigidBodyData btRigidBodyFloatData +#endif//BT_USE_DOUBLE_PRECISION + + +struct btCompoundShapeChildData; + +#include "LinearMath/btAlignedObjectArray.h" +#include "btWorldImporter.h" + +class btBulletXmlWorldImporter : public btWorldImporter +{ + +protected: + btAlignedObjectArray m_collisionShapeData; + btAlignedObjectArray* > m_compoundShapeChildDataArrays; + btAlignedObjectArray m_rigidBodyData; + btAlignedObjectArray m_constraintData; + btHashMap m_pointerLookup; + int m_fileVersion; + bool m_fileOk; + + void auto_serialize_root_level_children(TiXmlNode* pParent); + void auto_serialize(TiXmlNode* pParent); + + void deSerializeVector3FloatData(TiXmlNode* pParent,btAlignedObjectArray& vectors); + + void fixupCollisionDataPointers(btCollisionShapeData* shapeData); + void fixupConstraintData(btTypedConstraintData2* tcd); + + //collision shapes data + void deSerializeCollisionShapeData(TiXmlNode* pParent,btCollisionShapeData* colShapeData); + void deSerializeConvexInternalShapeData(TiXmlNode* pParent); + void deSerializeStaticPlaneShapeData(TiXmlNode* pParent); + void deSerializeCompoundShapeData(TiXmlNode* pParent); + void deSerializeCompoundShapeChildData(TiXmlNode* pParent); + void deSerializeConvexHullShapeData(TiXmlNode* pParent); + void deSerializeDynamicsWorldData(TiXmlNode* parent); + + ///bodies + void deSerializeRigidBodyFloatData(TiXmlNode* pParent); + + ///constraints + void deSerializeGeneric6DofConstraintData(TiXmlNode* pParent); + + public: + btBulletXmlWorldImporter(btDynamicsWorld* world); + + virtual ~btBulletXmlWorldImporter(); + + bool loadFile(const char* fileName); + +}; + +#endif //BT_BULLET_XML_WORLD_IMPORTER_H diff --git a/Extras/Serialize/BulletXmlWorldImporter/premake4.lua b/Extras/Serialize/BulletXmlWorldImporter/premake4.lua new file mode 100644 index 0000000000..147f3e9515 --- /dev/null +++ b/Extras/Serialize/BulletXmlWorldImporter/premake4.lua @@ -0,0 +1,14 @@ + project "BulletXmlWorldImporter" + + kind "StaticLib" + targetdir "../../lib" + includedirs { + "../BulletWorldImporter", + "../BulletFileLoader", + "../../../src" + } + + files { + "**.cpp", + "**.h" + } \ No newline at end of file diff --git a/Extras/Serialize/BulletXmlWorldImporter/string_split.cpp b/Extras/Serialize/BulletXmlWorldImporter/string_split.cpp new file mode 100644 index 0000000000..424ded32a7 --- /dev/null +++ b/Extras/Serialize/BulletXmlWorldImporter/string_split.cpp @@ -0,0 +1,250 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include +//#include +#include +#include +#include + +#include "string_split.h" + +///todo: remove stl dependency + +namespace bullet_utils +{ + void split( btAlignedObjectArray&pieces, const std::string& vector_str, const std::string& separator) + { + char** strArray = str_split(vector_str.c_str(),separator.c_str()); + int numSubStr = str_array_len(strArray); + for (int i=0;i +#include "LinearMath/btAlignedObjectArray.h" + +#include + +namespace bullet_utils +{ + void split( btAlignedObjectArray&pieces, const std::string& vector_str, const std::string& separator); +}; + +///The string split C code is by Lars Wirzenius +///See http://stackoverflow.com/questions/2531605/how-to-split-a-string-with-a-delimiter-larger-than-one-single-char + + +/* Split a string into substrings. Return dynamic array of dynamically + allocated substrings, or NULL if there was an error. Caller is + expected to free the memory, for example with str_array_free. */ +char** str_split(const char* input, const char* sep); + +/* Free a dynamic array of dynamic strings. */ +void str_array_free(char** array); + +/* Return length of a NULL-delimited array of strings. */ +size_t str_array_len(char** array); + +#endif //STRING_SPLIT_H + diff --git a/Extras/Serialize/BulletXmlWorldImporter/tinystr.cpp b/Extras/Serialize/BulletXmlWorldImporter/tinystr.cpp new file mode 100644 index 0000000000..0665768205 --- /dev/null +++ b/Extras/Serialize/BulletXmlWorldImporter/tinystr.cpp @@ -0,0 +1,111 @@ +/* +www.sourceforge.net/projects/tinyxml + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +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. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TIXML_USE_STL + +#include "tinystr.h" + +// Error value for find primitive +const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1); + + +// Null rep. +TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } }; + + +void TiXmlString::reserve (size_type cap) +{ + if (cap > capacity()) + { + TiXmlString tmp; + tmp.init(length(), cap); + memcpy(tmp.start(), data(), length()); + swap(tmp); + } +} + + +TiXmlString& TiXmlString::assign(const char* str, size_type len) +{ + size_type cap = capacity(); + if (len > cap || cap > 3*(len + 8)) + { + TiXmlString tmp; + tmp.init(len); + memcpy(tmp.start(), str, len); + swap(tmp); + } + else + { + memmove(start(), str, len); + set_size(len); + } + return *this; +} + + +TiXmlString& TiXmlString::append(const char* str, size_type len) +{ + size_type newsize = length() + len; + if (newsize > capacity()) + { + reserve (newsize + capacity()); + } + memmove(finish(), str, len); + set_size(newsize); + return *this; +} + + +TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) +{ + TiXmlString tmp; + tmp.reserve(a.length() + b.length()); + tmp += a; + tmp += b; + return tmp; +} + +TiXmlString operator + (const TiXmlString & a, const char* b) +{ + TiXmlString tmp; + TiXmlString::size_type b_len = static_cast( strlen(b) ); + tmp.reserve(a.length() + b_len); + tmp += a; + tmp.append(b, b_len); + return tmp; +} + +TiXmlString operator + (const char* a, const TiXmlString & b) +{ + TiXmlString tmp; + TiXmlString::size_type a_len = static_cast( strlen(a) ); + tmp.reserve(a_len + b.length()); + tmp.append(a, a_len); + tmp += b; + return tmp; +} + + +#endif // TIXML_USE_STL diff --git a/Extras/Serialize/BulletXmlWorldImporter/tinystr.h b/Extras/Serialize/BulletXmlWorldImporter/tinystr.h new file mode 100644 index 0000000000..89cca33415 --- /dev/null +++ b/Extras/Serialize/BulletXmlWorldImporter/tinystr.h @@ -0,0 +1,305 @@ +/* +www.sourceforge.net/projects/tinyxml + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +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. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TIXML_USE_STL + +#ifndef TIXML_STRING_INCLUDED +#define TIXML_STRING_INCLUDED + +#include +#include + +/* The support for explicit isn't that universal, and it isn't really + required - it is used to check that the TiXmlString class isn't incorrectly + used. Be nice to old compilers and macro it here: +*/ +#if defined(_MSC_VER) && (_MSC_VER >= 1200 ) + // Microsoft visual studio, version 6 and higher. + #define TIXML_EXPLICIT explicit +#elif defined(__GNUC__) && (__GNUC__ >= 3 ) + // GCC version 3 and higher.s + #define TIXML_EXPLICIT explicit +#else + #define TIXML_EXPLICIT +#endif + + +/* + TiXmlString is an emulation of a subset of the std::string template. + Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. + Only the member functions relevant to the TinyXML project have been implemented. + The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase + a string and there's no more room, we allocate a buffer twice as big as we need. +*/ +class TiXmlString +{ + public : + // The size type used + typedef size_t size_type; + + // Error value for find primitive + static const size_type npos; // = -1; + + + // TiXmlString empty constructor + TiXmlString () : rep_(&nullrep_) + { + } + + // TiXmlString copy constructor + TiXmlString ( const TiXmlString & copy) : rep_(0) + { + init(copy.length()); + memcpy(start(), copy.data(), length()); + } + + // TiXmlString constructor, based on a string + TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0) + { + init( static_cast( strlen(copy) )); + memcpy(start(), copy, length()); + } + + // TiXmlString constructor, based on a string + TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0) + { + init(len); + memcpy(start(), str, len); + } + + // TiXmlString destructor + ~TiXmlString () + { + quit(); + } + + TiXmlString& operator = (const char * copy) + { + return assign( copy, (size_type)strlen(copy)); + } + + TiXmlString& operator = (const TiXmlString & copy) + { + return assign(copy.start(), copy.length()); + } + + + // += operator. Maps to append + TiXmlString& operator += (const char * suffix) + { + return append(suffix, static_cast( strlen(suffix) )); + } + + // += operator. Maps to append + TiXmlString& operator += (char single) + { + return append(&single, 1); + } + + // += operator. Maps to append + TiXmlString& operator += (const TiXmlString & suffix) + { + return append(suffix.data(), suffix.length()); + } + + + // Convert a TiXmlString into a null-terminated char * + const char * c_str () const { return rep_->str; } + + // Convert a TiXmlString into a char * (need not be null terminated). + const char * data () const { return rep_->str; } + + // Return the length of a TiXmlString + size_type length () const { return rep_->size; } + + // Alias for length() + size_type size () const { return rep_->size; } + + // Checks if a TiXmlString is empty + bool empty () const { return rep_->size == 0; } + + // Return capacity of string + size_type capacity () const { return rep_->capacity; } + + + // single char extraction + const char& at (size_type index) const + { + assert( index < length() ); + return rep_->str[ index ]; + } + + // [] operator + char& operator [] (size_type index) const + { + assert( index < length() ); + return rep_->str[ index ]; + } + + // find a char in a string. Return TiXmlString::npos if not found + size_type find (char lookup) const + { + return find(lookup, 0); + } + + // find a char in a string from an offset. Return TiXmlString::npos if not found + size_type find (char tofind, size_type offset) const + { + if (offset >= length()) return npos; + + for (const char* p = c_str() + offset; *p != '\0'; ++p) + { + if (*p == tofind) return static_cast< size_type >( p - c_str() ); + } + return npos; + } + + void clear () + { + //Lee: + //The original was just too strange, though correct: + // TiXmlString().swap(*this); + //Instead use the quit & re-init: + quit(); + init(0,0); + } + + /* Function to reserve a big amount of data when we know we'll need it. Be aware that this + function DOES NOT clear the content of the TiXmlString if any exists. + */ + void reserve (size_type cap); + + TiXmlString& assign (const char* str, size_type len); + + TiXmlString& append (const char* str, size_type len); + + void swap (TiXmlString& other) + { + Rep* r = rep_; + rep_ = other.rep_; + other.rep_ = r; + } + + private: + + void init(size_type sz) { init(sz, sz); } + void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; } + char* start() const { return rep_->str; } + char* finish() const { return rep_->str + rep_->size; } + + struct Rep + { + size_type size, capacity; + char str[1]; + }; + + void init(size_type sz, size_type cap) + { + if (cap) + { + // Lee: the original form: + // rep_ = static_cast(operator new(sizeof(Rep) + cap)); + // doesn't work in some cases of new being overloaded. Switching + // to the normal allocation, although use an 'int' for systems + // that are overly picky about structure alignment. + const size_type bytesNeeded = sizeof(Rep) + cap; + const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); + rep_ = reinterpret_cast( new int[ intsNeeded ] ); + + rep_->str[ rep_->size = sz ] = '\0'; + rep_->capacity = cap; + } + else + { + rep_ = &nullrep_; + } + } + + void quit() + { + if (rep_ != &nullrep_) + { + // The rep_ is really an array of ints. (see the allocator, above). + // Cast it back before delete, so the compiler won't incorrectly call destructors. + delete [] ( reinterpret_cast( rep_ ) ); + } + } + + Rep * rep_; + static Rep nullrep_; + +} ; + + +inline bool operator == (const TiXmlString & a, const TiXmlString & b) +{ + return ( a.length() == b.length() ) // optimization on some platforms + && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare +} +inline bool operator < (const TiXmlString & a, const TiXmlString & b) +{ + return strcmp(a.c_str(), b.c_str()) < 0; +} + +inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); } +inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; } +inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); } +inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); } + +inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; } +inline bool operator == (const char* a, const TiXmlString & b) { return b == a; } +inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); } +inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); } + +TiXmlString operator + (const TiXmlString & a, const TiXmlString & b); +TiXmlString operator + (const TiXmlString & a, const char* b); +TiXmlString operator + (const char* a, const TiXmlString & b); + + +/* + TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. + Only the operators that we need for TinyXML have been developped. +*/ +class TiXmlOutStream : public TiXmlString +{ +public : + + // TiXmlOutStream << operator. + TiXmlOutStream & operator << (const TiXmlString & in) + { + *this += in; + return *this; + } + + // TiXmlOutStream << operator. + TiXmlOutStream & operator << (const char * in) + { + *this += in; + return *this; + } + +} ; + +#endif // TIXML_STRING_INCLUDED +#endif // TIXML_USE_STL diff --git a/Extras/Serialize/BulletXmlWorldImporter/tinyxml.cpp b/Extras/Serialize/BulletXmlWorldImporter/tinyxml.cpp new file mode 100644 index 0000000000..9c161dfcb9 --- /dev/null +++ b/Extras/Serialize/BulletXmlWorldImporter/tinyxml.cpp @@ -0,0 +1,1886 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code by Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +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. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include + +#ifdef TIXML_USE_STL +#include +#include +#endif + +#include "tinyxml.h" + +FILE* TiXmlFOpen( const char* filename, const char* mode ); + +bool TiXmlBase::condenseWhiteSpace = true; + +// Microsoft compiler security +FILE* TiXmlFOpen( const char* filename, const char* mode ) +{ + #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) + FILE* fp = 0; + errno_t err = fopen_s( &fp, filename, mode ); + if ( !err && fp ) + return fp; + return 0; + #else + return fopen( filename, mode ); + #endif +} + +void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString ) +{ + int i=0; + + while( i<(int)str.length() ) + { + unsigned char c = (unsigned char) str[i]; + + if ( c == '&' + && i < ( (int)str.length() - 2 ) + && str[i+1] == '#' + && str[i+2] == 'x' ) + { + // Hexadecimal character reference. + // Pass through unchanged. + // © -- copyright symbol, for example. + // + // The -1 is a bug fix from Rob Laveaux. It keeps + // an overflow from happening if there is no ';'. + // There are actually 2 ways to exit this loop - + // while fails (error case) and break (semicolon found). + // However, there is no mechanism (currently) for + // this function to return an error. + while ( i<(int)str.length()-1 ) + { + outString->append( str.c_str() + i, 1 ); + ++i; + if ( str[i] == ';' ) + break; + } + } + else if ( c == '&' ) + { + outString->append( entity[0].str, entity[0].strLength ); + ++i; + } + else if ( c == '<' ) + { + outString->append( entity[1].str, entity[1].strLength ); + ++i; + } + else if ( c == '>' ) + { + outString->append( entity[2].str, entity[2].strLength ); + ++i; + } + else if ( c == '\"' ) + { + outString->append( entity[3].str, entity[3].strLength ); + ++i; + } + else if ( c == '\'' ) + { + outString->append( entity[4].str, entity[4].strLength ); + ++i; + } + else if ( c < 32 ) + { + // Easy pass at non-alpha/numeric/symbol + // Below 32 is symbolic. + char buf[ 32 ]; + + #if defined(TIXML_SNPRINTF) + TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); + #else + sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); + #endif + + //*ME: warning C4267: convert 'size_t' to 'int' + //*ME: Int-Cast to make compiler happy ... + outString->append( buf, (int)strlen( buf ) ); + ++i; + } + else + { + //char realc = (char) c; + //outString->append( &realc, 1 ); + *outString += (char) c; // somewhat more efficient function call. + ++i; + } + } +} + + +TiXmlNode::TiXmlNode( NodeType _type ) : TiXmlBase() +{ + parent = 0; + type = _type; + firstChild = 0; + lastChild = 0; + prev = 0; + next = 0; +} + + +TiXmlNode::~TiXmlNode() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } +} + + +void TiXmlNode::CopyTo( TiXmlNode* target ) const +{ + target->SetValue (value.c_str() ); + target->userData = userData; + target->location = location; +} + + +void TiXmlNode::Clear() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } + + firstChild = 0; + lastChild = 0; +} + + +TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node ) +{ + assert( node->parent == 0 || node->parent == this ); + assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() ); + + if ( node->Type() == TiXmlNode::TINYXML_DOCUMENT ) + { + delete node; + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + node->parent = this; + + node->prev = lastChild; + node->next = 0; + + if ( lastChild ) + lastChild->next = node; + else + firstChild = node; // it was an empty list. + + lastChild = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) +{ + if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) + { + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + + return LinkEndChild( node ); +} + + +TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ) +{ + if ( !beforeThis || beforeThis->parent != this ) { + return 0; + } + if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) + { + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->next = beforeThis; + node->prev = beforeThis->prev; + if ( beforeThis->prev ) + { + beforeThis->prev->next = node; + } + else + { + assert( firstChild == beforeThis ); + firstChild = node; + } + beforeThis->prev = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ) +{ + if ( !afterThis || afterThis->parent != this ) { + return 0; + } + if ( addThis.Type() == TiXmlNode::TINYXML_DOCUMENT ) + { + if ( GetDocument() ) + GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->prev = afterThis; + node->next = afterThis->next; + if ( afterThis->next ) + { + afterThis->next->prev = node; + } + else + { + assert( lastChild == afterThis ); + lastChild = node; + } + afterThis->next = node; + return node; +} + + +TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ) +{ + if ( !replaceThis ) + return 0; + + if ( replaceThis->parent != this ) + return 0; + + if ( withThis.ToDocument() ) { + // A document can never be a child. Thanks to Noam. + TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + TiXmlNode* node = withThis.Clone(); + if ( !node ) + return 0; + + node->next = replaceThis->next; + node->prev = replaceThis->prev; + + if ( replaceThis->next ) + replaceThis->next->prev = node; + else + lastChild = node; + + if ( replaceThis->prev ) + replaceThis->prev->next = node; + else + firstChild = node; + + delete replaceThis; + node->parent = this; + return node; +} + + +bool TiXmlNode::RemoveChild( TiXmlNode* removeThis ) +{ + if ( !removeThis ) { + return false; + } + + if ( removeThis->parent != this ) + { + assert( 0 ); + return false; + } + + if ( removeThis->next ) + removeThis->next->prev = removeThis->prev; + else + lastChild = removeThis->prev; + + if ( removeThis->prev ) + removeThis->prev->next = removeThis->next; + else + firstChild = removeThis->next; + + delete removeThis; + return true; +} + +const TiXmlNode* TiXmlNode::FirstChild( const char * _value ) const +{ + const TiXmlNode* node; + for ( node = firstChild; node; node = node->next ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +const TiXmlNode* TiXmlNode::LastChild( const char * _value ) const +{ + const TiXmlNode* node; + for ( node = lastChild; node; node = node->prev ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +const TiXmlNode* TiXmlNode::IterateChildren( const TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild(); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling(); + } +} + + +const TiXmlNode* TiXmlNode::IterateChildren( const char * val, const TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild( val ); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling( val ); + } +} + + +const TiXmlNode* TiXmlNode::NextSibling( const char * _value ) const +{ + const TiXmlNode* node; + for ( node = next; node; node = node->next ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +const TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) const +{ + const TiXmlNode* node; + for ( node = prev; node; node = node->prev ) + { + if ( strcmp( node->Value(), _value ) == 0 ) + return node; + } + return 0; +} + + +void TiXmlElement::RemoveAttribute( const char * name ) +{ + #ifdef TIXML_USE_STL + TIXML_STRING str( name ); + TiXmlAttribute* node = attributeSet.Find( str ); + #else + TiXmlAttribute* node = attributeSet.Find( name ); + #endif + if ( node ) + { + attributeSet.Remove( node ); + delete node; + } +} + +const TiXmlElement* TiXmlNode::FirstChildElement() const +{ + const TiXmlNode* node; + + for ( node = FirstChild(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const +{ + const TiXmlNode* node; + + for ( node = FirstChild( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const TiXmlElement* TiXmlNode::NextSiblingElement() const +{ + const TiXmlNode* node; + + for ( node = NextSibling(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) const +{ + const TiXmlNode* node; + + for ( node = NextSibling( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +const TiXmlDocument* TiXmlNode::GetDocument() const +{ + const TiXmlNode* node; + + for( node = this; node; node = node->parent ) + { + if ( node->ToDocument() ) + return node->ToDocument(); + } + return 0; +} + + +TiXmlElement::TiXmlElement (const char * _value) + : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} + + +#ifdef TIXML_USE_STL +TiXmlElement::TiXmlElement( const std::string& _value ) + : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} +#endif + + +TiXmlElement::TiXmlElement( const TiXmlElement& copy) + : TiXmlNode( TiXmlNode::TINYXML_ELEMENT ) +{ + firstChild = lastChild = 0; + copy.CopyTo( this ); +} + + +TiXmlElement& TiXmlElement::operator=( const TiXmlElement& base ) +{ + ClearThis(); + base.CopyTo( this ); + return *this; +} + + +TiXmlElement::~TiXmlElement() +{ + ClearThis(); +} + + +void TiXmlElement::ClearThis() +{ + Clear(); + while( attributeSet.First() ) + { + TiXmlAttribute* node = attributeSet.First(); + attributeSet.Remove( node ); + delete node; + } +} + + +const char* TiXmlElement::Attribute( const char* name ) const +{ + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( node ) + return node->Value(); + return 0; +} + + +#ifdef TIXML_USE_STL +const std::string* TiXmlElement::Attribute( const std::string& name ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( attrib ) + return &attrib->ValueStr(); + return 0; +} +#endif + + +const char* TiXmlElement::Attribute( const char* name, int* i ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + const char* result = 0; + + if ( attrib ) { + result = attrib->Value(); + if ( i ) { + attrib->QueryIntValue( i ); + } + } + return result; +} + + +#ifdef TIXML_USE_STL +const std::string* TiXmlElement::Attribute( const std::string& name, int* i ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + const std::string* result = 0; + + if ( attrib ) { + result = &attrib->ValueStr(); + if ( i ) { + attrib->QueryIntValue( i ); + } + } + return result; +} +#endif + + +const char* TiXmlElement::Attribute( const char* name, double* d ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + const char* result = 0; + + if ( attrib ) { + result = attrib->Value(); + if ( d ) { + attrib->QueryDoubleValue( d ); + } + } + return result; +} + + +#ifdef TIXML_USE_STL +const std::string* TiXmlElement::Attribute( const std::string& name, double* d ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + const std::string* result = 0; + + if ( attrib ) { + result = &attrib->ValueStr(); + if ( d ) { + attrib->QueryDoubleValue( d ); + } + } + return result; +} +#endif + + +int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryIntValue( ival ); +} + + +int TiXmlElement::QueryUnsignedAttribute( const char* name, unsigned* value ) const +{ + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + int ival = 0; + int result = node->QueryIntValue( &ival ); + *value = (unsigned)ival; + return result; +} + + +int TiXmlElement::QueryBoolAttribute( const char* name, bool* bval ) const +{ + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + int result = TIXML_WRONG_TYPE; + if ( StringEqual( node->Value(), "true", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "yes", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "1", true, TIXML_ENCODING_UNKNOWN ) ) + { + *bval = true; + result = TIXML_SUCCESS; + } + else if ( StringEqual( node->Value(), "false", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "no", true, TIXML_ENCODING_UNKNOWN ) + || StringEqual( node->Value(), "0", true, TIXML_ENCODING_UNKNOWN ) ) + { + *bval = false; + result = TIXML_SUCCESS; + } + return result; +} + + + +#ifdef TIXML_USE_STL +int TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryIntValue( ival ); +} +#endif + + +int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryDoubleValue( dval ); +} + + +#ifdef TIXML_USE_STL +int TiXmlElement::QueryDoubleAttribute( const std::string& name, double* dval ) const +{ + const TiXmlAttribute* attrib = attributeSet.Find( name ); + if ( !attrib ) + return TIXML_NO_ATTRIBUTE; + return attrib->QueryDoubleValue( dval ); +} +#endif + + +void TiXmlElement::SetAttribute( const char * name, int val ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetIntValue( val ); + } +} + + +#ifdef TIXML_USE_STL +void TiXmlElement::SetAttribute( const std::string& name, int val ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetIntValue( val ); + } +} +#endif + + +void TiXmlElement::SetDoubleAttribute( const char * name, double val ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetDoubleValue( val ); + } +} + + +#ifdef TIXML_USE_STL +void TiXmlElement::SetDoubleAttribute( const std::string& name, double val ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( name ); + if ( attrib ) { + attrib->SetDoubleValue( val ); + } +} +#endif + + +void TiXmlElement::SetAttribute( const char * cname, const char * cvalue ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( cname ); + if ( attrib ) { + attrib->SetValue( cvalue ); + } +} + + +#ifdef TIXML_USE_STL +void TiXmlElement::SetAttribute( const std::string& _name, const std::string& _value ) +{ + TiXmlAttribute* attrib = attributeSet.FindOrCreate( _name ); + if ( attrib ) { + attrib->SetValue( _value ); + } +} +#endif + + +void TiXmlElement::Print( FILE* cfile, int depth ) const +{ + int i; + assert( cfile ); + for ( i=0; iNext() ) + { + fprintf( cfile, " " ); + attrib->Print( cfile, depth ); + } + + // There are 3 different formatting approaches: + // 1) An element without children is printed as a node + // 2) An element with only a text child is printed as text + // 3) An element with children is printed on multiple lines. + TiXmlNode* node; + if ( !firstChild ) + { + fprintf( cfile, " />" ); + } + else if ( firstChild == lastChild && firstChild->ToText() ) + { + fprintf( cfile, ">" ); + firstChild->Print( cfile, depth + 1 ); + fprintf( cfile, "", value.c_str() ); + } + else + { + fprintf( cfile, ">" ); + + for ( node = firstChild; node; node=node->NextSibling() ) + { + if ( !node->ToText() ) + { + fprintf( cfile, "\n" ); + } + node->Print( cfile, depth+1 ); + } + fprintf( cfile, "\n" ); + for( i=0; i", value.c_str() ); + } +} + + +void TiXmlElement::CopyTo( TiXmlElement* target ) const +{ + // superclass: + TiXmlNode::CopyTo( target ); + + // Element class: + // Clone the attributes, then clone the children. + const TiXmlAttribute* attribute = 0; + for( attribute = attributeSet.First(); + attribute; + attribute = attribute->Next() ) + { + target->SetAttribute( attribute->Name(), attribute->Value() ); + } + + TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + target->LinkEndChild( node->Clone() ); + } +} + +bool TiXmlElement::Accept( TiXmlVisitor* visitor ) const +{ + if ( visitor->VisitEnter( *this, attributeSet.First() ) ) + { + for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) + { + if ( !node->Accept( visitor ) ) + break; + } + } + return visitor->VisitExit( *this ); +} + + +TiXmlNode* TiXmlElement::Clone() const +{ + TiXmlElement* clone = new TiXmlElement( Value() ); + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +const char* TiXmlElement::GetText() const +{ + const TiXmlNode* child = this->FirstChild(); + if ( child ) { + const TiXmlText* childText = child->ToText(); + if ( childText ) { + return childText->Value(); + } + } + return 0; +} + + +TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) +{ + tabsize = 4; + useMicrosoftBOM = false; + ClearError(); +} + +TiXmlDocument::TiXmlDocument( const char * documentName ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) +{ + tabsize = 4; + useMicrosoftBOM = false; + value = documentName; + ClearError(); +} + + +#ifdef TIXML_USE_STL +TiXmlDocument::TiXmlDocument( const std::string& documentName ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) +{ + tabsize = 4; + useMicrosoftBOM = false; + value = documentName; + ClearError(); +} +#endif + + +TiXmlDocument::TiXmlDocument( const TiXmlDocument& copy ) : TiXmlNode( TiXmlNode::TINYXML_DOCUMENT ) +{ + copy.CopyTo( this ); +} + + +TiXmlDocument& TiXmlDocument::operator=( const TiXmlDocument& copy ) +{ + Clear(); + copy.CopyTo( this ); + return *this; +} + + +bool TiXmlDocument::LoadFile( TiXmlEncoding encoding ) +{ + return LoadFile( Value(), encoding ); +} + + +bool TiXmlDocument::SaveFile() const +{ + return SaveFile( Value() ); +} + +bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding ) +{ + TIXML_STRING filename( _filename ); + value = filename; + + // reading in binary mode so that tinyxml can normalize the EOL + FILE* file = TiXmlFOpen( value.c_str (), "rb" ); + + if ( file ) + { + bool result = LoadFile( file, encoding ); + fclose( file ); + return result; + } + else + { + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } +} + +bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding ) +{ + if ( !file ) + { + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } + + // Delete the existing data: + Clear(); + location.Clear(); + + // Get the file size, so we can pre-allocate the string. HUGE speed impact. + long length = 0; + fseek( file, 0, SEEK_END ); + length = ftell( file ); + fseek( file, 0, SEEK_SET ); + + // Strange case, but good to handle up front. + if ( length <= 0 ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } + + // Subtle bug here. TinyXml did use fgets. But from the XML spec: + // 2.11 End-of-Line Handling + // + // + // ...the XML processor MUST behave as if it normalized all line breaks in external + // parsed entities (including the document entity) on input, before parsing, by translating + // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to + // a single #xA character. + // + // + // It is not clear fgets does that, and certainly isn't clear it works cross platform. + // Generally, you expect fgets to translate from the convention of the OS to the c/unix + // convention, and not work generally. + + /* + while( fgets( buf, sizeof(buf), file ) ) + { + data += buf; + } + */ + + char* buf = new char[ length+1 ]; + buf[0] = 0; + + if ( fread( buf, length, 1, file ) != 1 ) { + delete [] buf; + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; + } + + // Process the buffer in place to normalize new lines. (See comment above.) + // Copies from the 'p' to 'q' pointer, where p can advance faster if + // a newline-carriage return is hit. + // + // Wikipedia: + // Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A, 10 in decimal) or + // CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, 0x0D 0x0A)... + // * LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others + // * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS + // * CR: Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9 + + const char* p = buf; // the read head + char* q = buf; // the write head + const char CR = 0x0d; + const char LF = 0x0a; + + buf[length] = 0; + while( *p ) { + assert( p < (buf+length) ); + assert( q <= (buf+length) ); + assert( q <= p ); + + if ( *p == CR ) { + *q++ = LF; + p++; + if ( *p == LF ) { // check for CR+LF (and skip LF) + p++; + } + } + else { + *q++ = *p++; + } + } + assert( q <= (buf+length) ); + *q = 0; + + Parse( buf, 0, encoding ); + + delete [] buf; + return !Error(); +} + + +bool TiXmlDocument::SaveFile( const char * filename ) const +{ + // The old c stuff lives on... + FILE* fp = TiXmlFOpen( filename, "w" ); + if ( fp ) + { + bool result = SaveFile( fp ); + fclose( fp ); + return result; + } + return false; +} + + +bool TiXmlDocument::SaveFile( FILE* fp ) const +{ + if ( useMicrosoftBOM ) + { + const unsigned char TIXML_UTF_LEAD_0 = 0xefU; + const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; + const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; + + fputc( TIXML_UTF_LEAD_0, fp ); + fputc( TIXML_UTF_LEAD_1, fp ); + fputc( TIXML_UTF_LEAD_2, fp ); + } + Print( fp, 0 ); + return (ferror(fp) == 0); +} + + +void TiXmlDocument::CopyTo( TiXmlDocument* target ) const +{ + TiXmlNode::CopyTo( target ); + + target->error = error; + target->errorId = errorId; + target->errorDesc = errorDesc; + target->tabsize = tabsize; + target->errorLocation = errorLocation; + target->useMicrosoftBOM = useMicrosoftBOM; + + TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + target->LinkEndChild( node->Clone() ); + } +} + + +TiXmlNode* TiXmlDocument::Clone() const +{ + TiXmlDocument* clone = new TiXmlDocument(); + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void TiXmlDocument::Print( FILE* cfile, int depth ) const +{ + assert( cfile ); + for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) + { + node->Print( cfile, depth ); + fprintf( cfile, "\n" ); + } +} + + +bool TiXmlDocument::Accept( TiXmlVisitor* visitor ) const +{ + if ( visitor->VisitEnter( *this ) ) + { + for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) + { + if ( !node->Accept( visitor ) ) + break; + } + } + return visitor->VisitExit( *this ); +} + + +const TiXmlAttribute* TiXmlAttribute::Next() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} + +/* +TiXmlAttribute* TiXmlAttribute::Next() +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} +*/ + +const TiXmlAttribute* TiXmlAttribute::Previous() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} + +/* +TiXmlAttribute* TiXmlAttribute::Previous() +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} +*/ + +void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const +{ + TIXML_STRING n, v; + + EncodeString( name, &n ); + EncodeString( value, &v ); + + if (value.find ('\"') == TIXML_STRING::npos) { + if ( cfile ) { + fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); + } + if ( str ) { + (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\""; + } + } + else { + if ( cfile ) { + fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); + } + if ( str ) { + (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'"; + } + } +} + + +int TiXmlAttribute::QueryIntValue( int* ival ) const +{ + if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +int TiXmlAttribute::QueryDoubleValue( double* dval ) const +{ + if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +void TiXmlAttribute::SetIntValue( int _value ) +{ + char buf [64]; + #if defined(TIXML_SNPRINTF) + TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value); + #else + sprintf (buf, "%d", _value); + #endif + SetValue (buf); +} + +void TiXmlAttribute::SetDoubleValue( double _value ) +{ + char buf [256]; + #if defined(TIXML_SNPRINTF) + TIXML_SNPRINTF( buf, sizeof(buf), "%g", _value); + #else + sprintf (buf, "%g", _value); + #endif + SetValue (buf); +} + +int TiXmlAttribute::IntValue() const +{ + return atoi (value.c_str ()); +} + +double TiXmlAttribute::DoubleValue() const +{ + return atof (value.c_str ()); +} + + +TiXmlComment::TiXmlComment( const TiXmlComment& copy ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) +{ + copy.CopyTo( this ); +} + + +TiXmlComment& TiXmlComment::operator=( const TiXmlComment& base ) +{ + Clear(); + base.CopyTo( this ); + return *this; +} + + +void TiXmlComment::Print( FILE* cfile, int depth ) const +{ + assert( cfile ); + for ( int i=0; i", value.c_str() ); +} + + +void TiXmlComment::CopyTo( TiXmlComment* target ) const +{ + TiXmlNode::CopyTo( target ); +} + + +bool TiXmlComment::Accept( TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +TiXmlNode* TiXmlComment::Clone() const +{ + TiXmlComment* clone = new TiXmlComment(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void TiXmlText::Print( FILE* cfile, int depth ) const +{ + assert( cfile ); + if ( cdata ) + { + int i; + fprintf( cfile, "\n" ); + for ( i=0; i\n", value.c_str() ); // unformatted output + } + else + { + TIXML_STRING buffer; + EncodeString( value, &buffer ); + fprintf( cfile, "%s", buffer.c_str() ); + } +} + + +void TiXmlText::CopyTo( TiXmlText* target ) const +{ + TiXmlNode::CopyTo( target ); + target->cdata = cdata; +} + + +bool TiXmlText::Accept( TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +TiXmlNode* TiXmlText::Clone() const +{ + TiXmlText* clone = 0; + clone = new TiXmlText( "" ); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +TiXmlDeclaration::TiXmlDeclaration( const char * _version, + const char * _encoding, + const char * _standalone ) + : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} + + +#ifdef TIXML_USE_STL +TiXmlDeclaration::TiXmlDeclaration( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ) + : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} +#endif + + +TiXmlDeclaration::TiXmlDeclaration( const TiXmlDeclaration& copy ) + : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) +{ + copy.CopyTo( this ); +} + + +TiXmlDeclaration& TiXmlDeclaration::operator=( const TiXmlDeclaration& copy ) +{ + Clear(); + copy.CopyTo( this ); + return *this; +} + + +void TiXmlDeclaration::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const +{ + if ( cfile ) fprintf( cfile, "" ); + if ( str ) (*str) += "?>"; +} + + +void TiXmlDeclaration::CopyTo( TiXmlDeclaration* target ) const +{ + TiXmlNode::CopyTo( target ); + + target->version = version; + target->encoding = encoding; + target->standalone = standalone; +} + + +bool TiXmlDeclaration::Accept( TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +TiXmlNode* TiXmlDeclaration::Clone() const +{ + TiXmlDeclaration* clone = new TiXmlDeclaration(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void TiXmlUnknown::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i", value.c_str() ); +} + + +void TiXmlUnknown::CopyTo( TiXmlUnknown* target ) const +{ + TiXmlNode::CopyTo( target ); +} + + +bool TiXmlUnknown::Accept( TiXmlVisitor* visitor ) const +{ + return visitor->Visit( *this ); +} + + +TiXmlNode* TiXmlUnknown::Clone() const +{ + TiXmlUnknown* clone = new TiXmlUnknown(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +TiXmlAttributeSet::TiXmlAttributeSet() +{ + sentinel.next = &sentinel; + sentinel.prev = &sentinel; +} + + +TiXmlAttributeSet::~TiXmlAttributeSet() +{ + assert( sentinel.next == &sentinel ); + assert( sentinel.prev == &sentinel ); +} + + +void TiXmlAttributeSet::Add( TiXmlAttribute* addMe ) +{ + #ifdef TIXML_USE_STL + assert( !Find( TIXML_STRING( addMe->Name() ) ) ); // Shouldn't be multiply adding to the set. + #else + assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. + #endif + + addMe->next = &sentinel; + addMe->prev = sentinel.prev; + + sentinel.prev->next = addMe; + sentinel.prev = addMe; +} + +void TiXmlAttributeSet::Remove( TiXmlAttribute* removeMe ) +{ + TiXmlAttribute* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node == removeMe ) + { + node->prev->next = node->next; + node->next->prev = node->prev; + node->next = 0; + node->prev = 0; + return; + } + } + assert( 0 ); // we tried to remove a non-linked attribute. +} + + +#ifdef TIXML_USE_STL +TiXmlAttribute* TiXmlAttributeSet::Find( const std::string& name ) const +{ + for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node->name == name ) + return node; + } + return 0; +} + +TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const std::string& _name ) +{ + TiXmlAttribute* attrib = Find( _name ); + if ( !attrib ) { + attrib = new TiXmlAttribute(); + Add( attrib ); + attrib->SetName( _name ); + } + return attrib; +} +#endif + + +TiXmlAttribute* TiXmlAttributeSet::Find( const char* name ) const +{ + for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( strcmp( node->name.c_str(), name ) == 0 ) + return node; + } + return 0; +} + + +TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const char* _name ) +{ + TiXmlAttribute* attrib = Find( _name ); + if ( !attrib ) { + attrib = new TiXmlAttribute(); + Add( attrib ); + attrib->SetName( _name ); + } + return attrib; +} + + +#ifdef TIXML_USE_STL +std::istream& operator>> (std::istream & in, TiXmlNode & base) +{ + TIXML_STRING tag; + tag.reserve( 8 * 1000 ); + base.StreamIn( &in, &tag ); + + base.Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING ); + return in; +} +#endif + + +#ifdef TIXML_USE_STL +std::ostream& operator<< (std::ostream & out, const TiXmlNode & base) +{ + TiXmlPrinter printer; + printer.SetStreamPrinting(); + base.Accept( &printer ); + out << printer.Str(); + + return out; +} + + +std::string& operator<< (std::string& out, const TiXmlNode& base ) +{ + TiXmlPrinter printer; + printer.SetStreamPrinting(); + base.Accept( &printer ); + out.append( printer.Str() ); + + return out; +} +#endif + + +TiXmlHandle TiXmlHandle::FirstChild() const +{ + if ( node ) + { + TiXmlNode* child = node->FirstChild(); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChild( const char * value ) const +{ + if ( node ) + { + TiXmlNode* child = node->FirstChild( value ); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChildElement() const +{ + if ( node ) + { + TiXmlElement* child = node->FirstChildElement(); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChildElement( const char * value ) const +{ + if ( node ) + { + TiXmlElement* child = node->FirstChildElement( value ); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::Child( int count ) const +{ + if ( node ) + { + int i; + TiXmlNode* child = node->FirstChild(); + for ( i=0; + child && iNextSibling(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::Child( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlNode* child = node->FirstChild( value ); + for ( i=0; + child && iNextSibling( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::ChildElement( int count ) const +{ + if ( node ) + { + int i; + TiXmlElement* child = node->FirstChildElement(); + for ( i=0; + child && iNextSiblingElement(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::ChildElement( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlElement* child = node->FirstChildElement( value ); + for ( i=0; + child && iNextSiblingElement( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +bool TiXmlPrinter::VisitEnter( const TiXmlDocument& ) +{ + return true; +} + +bool TiXmlPrinter::VisitExit( const TiXmlDocument& ) +{ + return true; +} + +bool TiXmlPrinter::VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) +{ + DoIndent(); + buffer += "<"; + buffer += element.Value(); + + for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() ) + { + buffer += " "; + attrib->Print( 0, 0, &buffer ); + } + + if ( !element.FirstChild() ) + { + buffer += " />"; + DoLineBreak(); + } + else + { + buffer += ">"; + if ( element.FirstChild()->ToText() + && element.LastChild() == element.FirstChild() + && element.FirstChild()->ToText()->CDATA() == false ) + { + simpleTextPrint = true; + // no DoLineBreak()! + } + else + { + DoLineBreak(); + } + } + ++depth; + return true; +} + + +bool TiXmlPrinter::VisitExit( const TiXmlElement& element ) +{ + --depth; + if ( !element.FirstChild() ) + { + // nothing. + } + else + { + if ( simpleTextPrint ) + { + simpleTextPrint = false; + } + else + { + DoIndent(); + } + buffer += ""; + DoLineBreak(); + } + return true; +} + + +bool TiXmlPrinter::Visit( const TiXmlText& text ) +{ + if ( text.CDATA() ) + { + DoIndent(); + buffer += ""; + DoLineBreak(); + } + else if ( simpleTextPrint ) + { + TIXML_STRING str; + TiXmlBase::EncodeString( text.ValueTStr(), &str ); + buffer += str; + } + else + { + DoIndent(); + TIXML_STRING str; + TiXmlBase::EncodeString( text.ValueTStr(), &str ); + buffer += str; + DoLineBreak(); + } + return true; +} + + +bool TiXmlPrinter::Visit( const TiXmlDeclaration& declaration ) +{ + DoIndent(); + declaration.Print( 0, 0, &buffer ); + DoLineBreak(); + return true; +} + + +bool TiXmlPrinter::Visit( const TiXmlComment& comment ) +{ + DoIndent(); + buffer += ""; + DoLineBreak(); + return true; +} + + +bool TiXmlPrinter::Visit( const TiXmlUnknown& unknown ) +{ + DoIndent(); + buffer += "<"; + buffer += unknown.Value(); + buffer += ">"; + DoLineBreak(); + return true; +} + diff --git a/Extras/Serialize/BulletXmlWorldImporter/tinyxml.h b/Extras/Serialize/BulletXmlWorldImporter/tinyxml.h new file mode 100644 index 0000000000..a3589e5b26 --- /dev/null +++ b/Extras/Serialize/BulletXmlWorldImporter/tinyxml.h @@ -0,0 +1,1805 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code by Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +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. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TINYXML_INCLUDED +#define TINYXML_INCLUDED + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4530 ) +#pragma warning( disable : 4786 ) +#endif + +#include +#include +#include +#include +#include + +// Help out windows: +#if defined( _DEBUG ) && !defined( DEBUG ) +#define DEBUG +#endif + +#ifdef TIXML_USE_STL + #include + #include + #include + #define TIXML_STRING std::string +#else + #include "tinystr.h" + #define TIXML_STRING TiXmlString +#endif + +// Deprecated library function hell. Compilers want to use the +// new safe versions. This probably doesn't fully address the problem, +// but it gets closer. There are too many compilers for me to fully +// test. If you get compilation troubles, undefine TIXML_SAFE +#define TIXML_SAFE + +#ifdef TIXML_SAFE + #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) + // Microsoft visual studio, version 2005 and higher. + #define TIXML_SNPRINTF _snprintf_s + #define TIXML_SSCANF sscanf_s + #elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) + // Microsoft visual studio, version 6 and higher. + //#pragma message( "Using _sn* functions." ) + #define TIXML_SNPRINTF _snprintf + #define TIXML_SSCANF sscanf + #elif defined(__GNUC__) && (__GNUC__ >= 3 ) + // GCC version 3 and higher.s + //#warning( "Using sn* functions." ) + #define TIXML_SNPRINTF snprintf + #define TIXML_SSCANF sscanf + #else + #define TIXML_SNPRINTF snprintf + #define TIXML_SSCANF sscanf + #endif +#endif + +class TiXmlDocument; +class TiXmlElement; +class TiXmlComment; +class TiXmlUnknown; +class TiXmlAttribute; +class TiXmlText; +class TiXmlDeclaration; +class TiXmlParsingData; + +const int TIXML_MAJOR_VERSION = 2; +const int TIXML_MINOR_VERSION = 6; +const int TIXML_PATCH_VERSION = 2; + +/* Internal structure for tracking location of items + in the XML file. +*/ +struct TiXmlCursor +{ + TiXmlCursor() { Clear(); } + void Clear() { row = col = -1; } + + int row; // 0 based. + int col; // 0 based. +}; + + +/** + Implements the interface to the "Visitor pattern" (see the Accept() method.) + If you call the Accept() method, it requires being passed a TiXmlVisitor + class to handle callbacks. For nodes that contain other nodes (Document, Element) + you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves + are simply called with Visit(). + + If you return 'true' from a Visit method, recursive parsing will continue. If you return + false, no children of this node or its sibilings will be Visited. + + All flavors of Visit methods have a default implementation that returns 'true' (continue + visiting). You need to only override methods that are interesting to you. + + Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting. + + You should never change the document from a callback. + + @sa TiXmlNode::Accept() +*/ +class TiXmlVisitor +{ +public: + virtual ~TiXmlVisitor() {} + + /// Visit a document. + virtual bool VisitEnter( const TiXmlDocument& /*doc*/ ) { return true; } + /// Visit a document. + virtual bool VisitExit( const TiXmlDocument& /*doc*/ ) { return true; } + + /// Visit an element. + virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ ) { return true; } + /// Visit an element. + virtual bool VisitExit( const TiXmlElement& /*element*/ ) { return true; } + + /// Visit a declaration + virtual bool Visit( const TiXmlDeclaration& /*declaration*/ ) { return true; } + /// Visit a text node + virtual bool Visit( const TiXmlText& /*text*/ ) { return true; } + /// Visit a comment node + virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; } + /// Visit an unknown node + virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; } +}; + +// Only used by Attribute::Query functions +enum +{ + TIXML_SUCCESS, + TIXML_NO_ATTRIBUTE, + TIXML_WRONG_TYPE +}; + + +// Used by the parsing routines. +enum TiXmlEncoding +{ + TIXML_ENCODING_UNKNOWN, + TIXML_ENCODING_UTF8, + TIXML_ENCODING_LEGACY +}; + +const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; + +/** TiXmlBase is a base class for every class in TinyXml. + It does little except to establish that TinyXml classes + can be printed and provide some utility functions. + + In XML, the document and elements can contain + other elements and other types of nodes. + + @verbatim + A Document can contain: Element (container or leaf) + Comment (leaf) + Unknown (leaf) + Declaration( leaf ) + + An Element can contain: Element (container or leaf) + Text (leaf) + Attributes (not on tree) + Comment (leaf) + Unknown (leaf) + + A Decleration contains: Attributes (not on tree) + @endverbatim +*/ +class TiXmlBase +{ + friend class TiXmlNode; + friend class TiXmlElement; + friend class TiXmlDocument; + +public: + TiXmlBase() : userData(0) {} + virtual ~TiXmlBase() {} + + /** All TinyXml classes can print themselves to a filestream + or the string class (TiXmlString in non-STL mode, std::string + in STL mode.) Either or both cfile and str can be null. + + This is a formatted print, and will insert + tabs and newlines. + + (For an unformatted stream, use the << operator.) + */ + virtual void Print( FILE* cfile, int depth ) const = 0; + + /** The world does not agree on whether white space should be kept or + not. In order to make everyone happy, these global, static functions + are provided to set whether or not TinyXml will condense all white space + into a single space or not. The default is to condense. Note changing this + value is not thread safe. + */ + static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } + + /// Return the current white space setting. + static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } + + /** Return the position, in the original source file, of this node or attribute. + The row and column are 1-based. (That is the first row and first column is + 1,1). If the returns values are 0 or less, then the parser does not have + a row and column value. + + Generally, the row and column value will be set when the TiXmlDocument::Load(), + TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set + when the DOM was created from operator>>. + + The values reflect the initial load. Once the DOM is modified programmatically + (by adding or changing nodes and attributes) the new values will NOT update to + reflect changes in the document. + + There is a minor performance cost to computing the row and column. Computation + can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value. + + @sa TiXmlDocument::SetTabSize() + */ + int Row() const { return location.row + 1; } + int Column() const { return location.col + 1; } ///< See Row() + + void SetUserData( void* user ) { userData = user; } ///< Set a pointer to arbitrary user data. + void* GetUserData() { return userData; } ///< Get a pointer to arbitrary user data. + const void* GetUserData() const { return userData; } ///< Get a pointer to arbitrary user data. + + // Table that returs, for a given lead byte, the total number of bytes + // in the UTF-8 sequence. + static const int utf8ByteTable[256]; + + virtual const char* Parse( const char* p, + TiXmlParsingData* data, + TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; + + /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc, + or they will be transformed into entities! + */ + static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out ); + + enum + { + TIXML_NO_ERROR = 0, + TIXML_ERROR, + TIXML_ERROR_OPENING_FILE, + TIXML_ERROR_PARSING_ELEMENT, + TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, + TIXML_ERROR_READING_ELEMENT_VALUE, + TIXML_ERROR_READING_ATTRIBUTES, + TIXML_ERROR_PARSING_EMPTY, + TIXML_ERROR_READING_END_TAG, + TIXML_ERROR_PARSING_UNKNOWN, + TIXML_ERROR_PARSING_COMMENT, + TIXML_ERROR_PARSING_DECLARATION, + TIXML_ERROR_DOCUMENT_EMPTY, + TIXML_ERROR_EMBEDDED_NULL, + TIXML_ERROR_PARSING_CDATA, + TIXML_ERROR_DOCUMENT_TOP_ONLY, + + TIXML_ERROR_STRING_COUNT + }; + +protected: + + static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); + + inline static bool IsWhiteSpace( char c ) + { + return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); + } + inline static bool IsWhiteSpace( int c ) + { + if ( c < 256 ) + return IsWhiteSpace( (char) c ); + return false; // Again, only truly correct for English/Latin...but usually works. + } + + #ifdef TIXML_USE_STL + static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ); + static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag ); + #endif + + /* Reads an XML name into the string provided. Returns + a pointer just past the last character of the name, + or 0 if the function has an error. + */ + static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding ); + + /* Reads text. Returns a pointer past the given end tag. + Wickedly complex options, but it keeps the (sensitive) code in one place. + */ + static const char* ReadText( const char* in, // where to start + TIXML_STRING* text, // the string read + bool ignoreWhiteSpace, // whether to keep the white space + const char* endTag, // what ends this text + bool ignoreCase, // whether to ignore case in the end tag + TiXmlEncoding encoding ); // the current encoding + + // If an entity has been found, transform it into a character. + static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding ); + + // Get a character, while interpreting entities. + // The length can be from 0 to 4 bytes. + inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding ) + { + assert( p ); + if ( encoding == TIXML_ENCODING_UTF8 ) + { + *length = utf8ByteTable[ *((const unsigned char*)p) ]; + assert( *length >= 0 && *length < 5 ); + } + else + { + *length = 1; + } + + if ( *length == 1 ) + { + if ( *p == '&' ) + return GetEntity( p, _value, length, encoding ); + *_value = *p; + return p+1; + } + else if ( *length ) + { + //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), + // and the null terminator isn't needed + for( int i=0; p[i] && i<*length; ++i ) { + _value[i] = p[i]; + } + return p + (*length); + } + else + { + // Not valid text. + return 0; + } + } + + // Return true if the next characters in the stream are any of the endTag sequences. + // Ignore case only works for english, and should only be relied on when comparing + // to English words: StringEqual( p, "version", true ) is fine. + static bool StringEqual( const char* p, + const char* endTag, + bool ignoreCase, + TiXmlEncoding encoding ); + + static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; + + TiXmlCursor location; + + /// Field containing a generic user pointer + void* userData; + + // None of these methods are reliable for any language except English. + // Good for approximation, not great for accuracy. + static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding ); + static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding ); + inline static int ToLower( int v, TiXmlEncoding encoding ) + { + if ( encoding == TIXML_ENCODING_UTF8 ) + { + if ( v < 128 ) return tolower( v ); + return v; + } + else + { + return tolower( v ); + } + } + static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); + +private: + TiXmlBase( const TiXmlBase& ); // not implemented. + void operator=( const TiXmlBase& base ); // not allowed. + + struct Entity + { + const char* str; + unsigned int strLength; + char chr; + }; + enum + { + NUM_ENTITY = 5, + MAX_ENTITY_LENGTH = 6 + + }; + static Entity entity[ NUM_ENTITY ]; + static bool condenseWhiteSpace; +}; + + +/** The parent class for everything in the Document Object Model. + (Except for attributes). + Nodes have siblings, a parent, and children. A node can be + in a document, or stand on its own. The type of a TiXmlNode + can be queried, and it can be cast to its more defined type. +*/ +class TiXmlNode : public TiXmlBase +{ + friend class TiXmlDocument; + friend class TiXmlElement; + +public: + #ifdef TIXML_USE_STL + + /** An input stream operator, for every class. Tolerant of newlines and + formatting, but doesn't expect them. + */ + friend std::istream& operator >> (std::istream& in, TiXmlNode& base); + + /** An output stream operator, for every class. Note that this outputs + without any newlines or formatting, as opposed to Print(), which + includes tabs and new lines. + + The operator<< and operator>> are not completely symmetric. Writing + a node to a stream is very well defined. You'll get a nice stream + of output, without any extra whitespace or newlines. + + But reading is not as well defined. (As it always is.) If you create + a TiXmlElement (for example) and read that from an input stream, + the text needs to define an element or junk will result. This is + true of all input streams, but it's worth keeping in mind. + + A TiXmlDocument will read nodes until it reads a root element, and + all the children of that root element. + */ + friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); + + /// Appends the XML node or attribute to a std::string. + friend std::string& operator<< (std::string& out, const TiXmlNode& base ); + + #endif + + /** The types of XML nodes supported by TinyXml. (All the + unsupported types are picked up by UNKNOWN.) + */ + enum NodeType + { + TINYXML_DOCUMENT, + TINYXML_ELEMENT, + TINYXML_COMMENT, + TINYXML_UNKNOWN, + TINYXML_TEXT, + TINYXML_DECLARATION, + TINYXML_TYPECOUNT + }; + + virtual ~TiXmlNode(); + + /** The meaning of 'value' changes for the specific type of + TiXmlNode. + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + + The subclasses will wrap this function. + */ + const char *Value() const { return value.c_str (); } + + #ifdef TIXML_USE_STL + /** Return Value() as a std::string. If you only use STL, + this is more efficient than calling Value(). + Only available in STL mode. + */ + const std::string& ValueStr() const { return value; } + #endif + + const TIXML_STRING& ValueTStr() const { return value; } + + /** Changes the value of the node. Defined as: + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + */ + void SetValue(const char * _value) { value = _value;} + + #ifdef TIXML_USE_STL + /// STL std::string form. + void SetValue( const std::string& _value ) { value = _value; } + #endif + + /// Delete all the children of this node. Does not affect 'this'. + void Clear(); + + /// One step up the DOM. + TiXmlNode* Parent() { return parent; } + const TiXmlNode* Parent() const { return parent; } + + const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. + TiXmlNode* FirstChild() { return firstChild; } + const TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. + /// The first child of this node with the matching 'value'. Will be null if none found. + TiXmlNode* FirstChild( const char * _value ) { + // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe) + // call the method, cast the return back to non-const. + return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value )); + } + const TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. + TiXmlNode* LastChild() { return lastChild; } + + const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. + TiXmlNode* LastChild( const char * _value ) { + return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value )); + } + + #ifdef TIXML_USE_STL + const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); } ///< STL std::string form. + const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); } ///< STL std::string form. + #endif + + /** An alternate way to walk the children of a node. + One way to iterate over nodes is: + @verbatim + for( child = parent->FirstChild(); child; child = child->NextSibling() ) + @endverbatim + + IterateChildren does the same thing with the syntax: + @verbatim + child = 0; + while( child = parent->IterateChildren( child ) ) + @endverbatim + + IterateChildren takes the previous child as input and finds + the next one. If the previous child is null, it returns the + first. IterateChildren will return null when done. + */ + const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const; + TiXmlNode* IterateChildren( const TiXmlNode* previous ) { + return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) ); + } + + /// This flavor of IterateChildren searches for children with a particular 'value' + const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const; + TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) { + return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) ); + } + + #ifdef TIXML_USE_STL + const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. + TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. + #endif + + /** Add a new node related to this. Adds a child past the LastChild. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); + + + /** Add a new node related to this. Adds a child past the LastChild. + + NOTE: the node to be added is passed by pointer, and will be + henceforth owned (and deleted) by tinyXml. This method is efficient + and avoids an extra copy, but should be used with care as it + uses a different memory model than the other insert functions. + + @sa InsertEndChild + */ + TiXmlNode* LinkEndChild( TiXmlNode* addThis ); + + /** Add a new node related to this. Adds a child before the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ); + + /** Add a new node related to this. Adds a child after the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ); + + /** Replace a child of this node. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ); + + /// Delete a child of this node. + bool RemoveChild( TiXmlNode* removeThis ); + + /// Navigate to a sibling node. + const TiXmlNode* PreviousSibling() const { return prev; } + TiXmlNode* PreviousSibling() { return prev; } + + /// Navigate to a sibling node. + const TiXmlNode* PreviousSibling( const char * ) const; + TiXmlNode* PreviousSibling( const char *_prev ) { + return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) ); + } + + #ifdef TIXML_USE_STL + const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. + const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Navigate to a sibling node. + const TiXmlNode* NextSibling() const { return next; } + TiXmlNode* NextSibling() { return next; } + + /// Navigate to a sibling node with the given 'value'. + const TiXmlNode* NextSibling( const char * ) const; + TiXmlNode* NextSibling( const char* _next ) { + return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) ); + } + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + const TiXmlElement* NextSiblingElement() const; + TiXmlElement* NextSiblingElement() { + return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() ); + } + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + const TiXmlElement* NextSiblingElement( const char * ) const; + TiXmlElement* NextSiblingElement( const char *_next ) { + return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) ); + } + + #ifdef TIXML_USE_STL + const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. + TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Convenience function to get through elements. + const TiXmlElement* FirstChildElement() const; + TiXmlElement* FirstChildElement() { + return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() ); + } + + /// Convenience function to get through elements. + const TiXmlElement* FirstChildElement( const char * _value ) const; + TiXmlElement* FirstChildElement( const char * _value ) { + return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) ); + } + + #ifdef TIXML_USE_STL + const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. + TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /** Query the type (as an enumerated value, above) of this node. + The possible types are: TINYXML_DOCUMENT, TINYXML_ELEMENT, TINYXML_COMMENT, + TINYXML_UNKNOWN, TINYXML_TEXT, and TINYXML_DECLARATION. + */ + int Type() const { return type; } + + /** Return a pointer to the Document this node lives in. + Returns null if not in a document. + */ + const TiXmlDocument* GetDocument() const; + TiXmlDocument* GetDocument() { + return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() ); + } + + /// Returns true if this node has no children. + bool NoChildren() const { return !firstChild; } + + virtual const TiXmlDocument* ToDocument() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlElement* ToElement() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlComment* ToComment() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlUnknown* ToUnknown() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlText* ToText() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + + virtual TiXmlDocument* ToDocument() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlElement* ToElement() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlComment* ToComment() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlUnknown* ToUnknown() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlText* ToText() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + virtual TiXmlDeclaration* ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. + + /** Create an exact duplicate of this node and return it. The memory must be deleted + by the caller. + */ + virtual TiXmlNode* Clone() const = 0; + + /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the + XML tree will be conditionally visited and the host will be called back + via the TiXmlVisitor interface. + + This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse + the XML for the callbacks, so the performance of TinyXML is unchanged by using this + interface versus any other.) + + The interface has been based on ideas from: + + - http://www.saxproject.org/ + - http://c2.com/cgi/wiki?HierarchicalVisitorPattern + + Which are both good references for "visiting". + + An example of using Accept(): + @verbatim + TiXmlPrinter printer; + tinyxmlDoc.Accept( &printer ); + const char* xmlcstr = printer.CStr(); + @endverbatim + */ + virtual bool Accept( TiXmlVisitor* visitor ) const = 0; + +protected: + TiXmlNode( NodeType _type ); + + // Copy to the allocated object. Shared functionality between Clone, Copy constructor, + // and the assignment operator. + void CopyTo( TiXmlNode* target ) const; + + #ifdef TIXML_USE_STL + // The real work of the input operator. + virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0; + #endif + + // Figure out what is at *p, and parse it. Returns null if it is not an xml node. + TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); + + TiXmlNode* parent; + NodeType type; + + TiXmlNode* firstChild; + TiXmlNode* lastChild; + + TIXML_STRING value; + + TiXmlNode* prev; + TiXmlNode* next; + +private: + TiXmlNode( const TiXmlNode& ); // not implemented. + void operator=( const TiXmlNode& base ); // not allowed. +}; + + +/** An attribute is a name-value pair. Elements have an arbitrary + number of attributes, each with a unique name. + + @note The attributes are not TiXmlNodes, since they are not + part of the tinyXML document object model. There are other + suggested ways to look at this problem. +*/ +class TiXmlAttribute : public TiXmlBase +{ + friend class TiXmlAttributeSet; + +public: + /// Construct an empty attribute. + TiXmlAttribute() : TiXmlBase() + { + document = 0; + prev = next = 0; + } + + #ifdef TIXML_USE_STL + /// std::string constructor. + TiXmlAttribute( const std::string& _name, const std::string& _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + #endif + + /// Construct an attribute with a name and value. + TiXmlAttribute( const char * _name, const char * _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + + const char* Name() const { return name.c_str(); } ///< Return the name of this attribute. + const char* Value() const { return value.c_str(); } ///< Return the value of this attribute. + #ifdef TIXML_USE_STL + const std::string& ValueStr() const { return value; } ///< Return the value of this attribute. + #endif + int IntValue() const; ///< Return the value of this attribute, converted to an integer. + double DoubleValue() const; ///< Return the value of this attribute, converted to a double. + + // Get the tinyxml string representation + const TIXML_STRING& NameTStr() const { return name; } + + /** QueryIntValue examines the value string. It is an alternative to the + IntValue() method with richer error checking. + If the value is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. + + A specialized but useful call. Note that for success it returns 0, + which is the opposite of almost all other TinyXml calls. + */ + int QueryIntValue( int* _value ) const; + /// QueryDoubleValue examines the value string. See QueryIntValue(). + int QueryDoubleValue( double* _value ) const; + + void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. + void SetValue( const char* _value ) { value = _value; } ///< Set the value. + + void SetIntValue( int _value ); ///< Set the value from an integer. + void SetDoubleValue( double _value ); ///< Set the value from a double. + + #ifdef TIXML_USE_STL + /// STL std::string form. + void SetName( const std::string& _name ) { name = _name; } + /// STL std::string form. + void SetValue( const std::string& _value ) { value = _value; } + #endif + + /// Get the next sibling attribute in the DOM. Returns null at end. + const TiXmlAttribute* Next() const; + TiXmlAttribute* Next() { + return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); + } + + /// Get the previous sibling attribute in the DOM. Returns null at beginning. + const TiXmlAttribute* Previous() const; + TiXmlAttribute* Previous() { + return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); + } + + bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } + bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } + bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; } + + /* Attribute parsing starts: first letter of the name + returns: the next char after the value end quote + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + // Prints this Attribute to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const { + Print( cfile, depth, 0 ); + } + void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; + + // [internal use] + // Set the document pointer so the attribute can report errors. + void SetDocument( TiXmlDocument* doc ) { document = doc; } + +private: + TiXmlAttribute( const TiXmlAttribute& ); // not implemented. + void operator=( const TiXmlAttribute& base ); // not allowed. + + TiXmlDocument* document; // A pointer back to a document, for error reporting. + TIXML_STRING name; + TIXML_STRING value; + TiXmlAttribute* prev; + TiXmlAttribute* next; +}; + + +/* A class used to manage a group of attributes. + It is only used internally, both by the ELEMENT and the DECLARATION. + + The set can be changed transparent to the Element and Declaration + classes that use it, but NOT transparent to the Attribute + which has to implement a next() and previous() method. Which makes + it a bit problematic and prevents the use of STL. + + This version is implemented with circular lists because: + - I like circular lists + - it demonstrates some independence from the (typical) doubly linked list. +*/ +class TiXmlAttributeSet +{ +public: + TiXmlAttributeSet(); + ~TiXmlAttributeSet(); + + void Add( TiXmlAttribute* attribute ); + void Remove( TiXmlAttribute* attribute ); + + const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + + TiXmlAttribute* Find( const char* _name ) const; + TiXmlAttribute* FindOrCreate( const char* _name ); + +# ifdef TIXML_USE_STL + TiXmlAttribute* Find( const std::string& _name ) const; + TiXmlAttribute* FindOrCreate( const std::string& _name ); +# endif + + +private: + //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element), + //*ME: this class must be also use a hidden/disabled copy-constructor !!! + TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed + void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute) + + TiXmlAttribute sentinel; +}; + + +/** The element is a container class. It has a value, the element name, + and can contain other elements, text, comments, and unknowns. + Elements also contain an arbitrary number of attributes. +*/ +class TiXmlElement : public TiXmlNode +{ +public: + /// Construct an element. + TiXmlElement (const char * in_value); + + #ifdef TIXML_USE_STL + /// std::string constructor. + TiXmlElement( const std::string& _value ); + #endif + + TiXmlElement( const TiXmlElement& ); + + TiXmlElement& operator=( const TiXmlElement& base ); + + virtual ~TiXmlElement(); + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + */ + const char* Attribute( const char* name ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an integer, + the integer value will be put in the return 'i', if 'i' + is non-null. + */ + const char* Attribute( const char* name, int* i ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an double, + the double value will be put in the return 'd', if 'd' + is non-null. + */ + const char* Attribute( const char* name, double* d ) const; + + /** QueryIntAttribute examines the attribute - it is an alternative to the + Attribute() method with richer error checking. + If the attribute is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. If the attribute + does not exist, then TIXML_NO_ATTRIBUTE is returned. + */ + int QueryIntAttribute( const char* name, int* _value ) const; + /// QueryUnsignedAttribute examines the attribute - see QueryIntAttribute(). + int QueryUnsignedAttribute( const char* name, unsigned* _value ) const; + /** QueryBoolAttribute examines the attribute - see QueryIntAttribute(). + Note that '1', 'true', or 'yes' are considered true, while '0', 'false' + and 'no' are considered false. + */ + int QueryBoolAttribute( const char* name, bool* _value ) const; + /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). + int QueryDoubleAttribute( const char* name, double* _value ) const; + /// QueryFloatAttribute examines the attribute - see QueryIntAttribute(). + int QueryFloatAttribute( const char* name, float* _value ) const { + double d; + int result = QueryDoubleAttribute( name, &d ); + if ( result == TIXML_SUCCESS ) { + *_value = (float)d; + } + return result; + } + + #ifdef TIXML_USE_STL + /// QueryStringAttribute examines the attribute - see QueryIntAttribute(). + int QueryStringAttribute( const char* name, std::string* _value ) const { + const char* cstr = Attribute( name ); + if ( cstr ) { + *_value = std::string( cstr ); + return TIXML_SUCCESS; + } + return TIXML_NO_ATTRIBUTE; + } + + /** Template form of the attribute query which will try to read the + attribute into the specified type. Very easy, very powerful, but + be careful to make sure to call this with the correct type. + + NOTE: This method doesn't work correctly for 'string' types that contain spaces. + + @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE + */ + template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const + { + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + std::stringstream sstream( node->ValueStr() ); + sstream >> *outValue; + if ( !sstream.fail() ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; + } + + int QueryValueAttribute( const std::string& name, std::string* outValue ) const + { + const TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + *outValue = node->ValueStr(); + return TIXML_SUCCESS; + } + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char* name, const char * _value ); + + #ifdef TIXML_USE_STL + const std::string* Attribute( const std::string& name ) const; + const std::string* Attribute( const std::string& name, int* i ) const; + const std::string* Attribute( const std::string& name, double* d ) const; + int QueryIntAttribute( const std::string& name, int* _value ) const; + int QueryDoubleAttribute( const std::string& name, double* _value ) const; + + /// STL std::string form. + void SetAttribute( const std::string& name, const std::string& _value ); + ///< STL std::string form. + void SetAttribute( const std::string& name, int _value ); + ///< STL std::string form. + void SetDoubleAttribute( const std::string& name, double value ); + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char * name, int value ); + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetDoubleAttribute( const char * name, double value ); + + /** Deletes an attribute with the given name. + */ + void RemoveAttribute( const char * name ); + #ifdef TIXML_USE_STL + void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. + #endif + + const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. + TiXmlAttribute* FirstAttribute() { return attributeSet.First(); } + const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. + TiXmlAttribute* LastAttribute() { return attributeSet.Last(); } + + /** Convenience function for easy access to the text inside an element. Although easy + and concise, GetText() is limited compared to getting the TiXmlText child + and accessing it directly. + + If the first child of 'this' is a TiXmlText, the GetText() + returns the character string of the Text node, else null is returned. + + This is a convenient method for getting the text of simple contained text: + @verbatim + This is text + const char* str = fooElement->GetText(); + @endverbatim + + 'str' will be a pointer to "This is text". + + Note that this function can be misleading. If the element foo was created from + this XML: + @verbatim + This is text + @endverbatim + + then the value of str would be null. The first child node isn't a text node, it is + another element. From this XML: + @verbatim + This is text + @endverbatim + GetText() will return "This is ". + + WARNING: GetText() accesses a child node - don't become confused with the + similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are + safe type casts on the referenced node. + */ + const char* GetText() const; + + /// Creates a new Element and returns it - the returned element is a copy. + virtual TiXmlNode* Clone() const; + // Print the Element to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /* Attribtue parsing starts: next char past '<' + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlElement* ToElement() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* visitor ) const; + +protected: + + void CopyTo( TiXmlElement* target ) const; + void ClearThis(); // like clear, but initializes 'this' object as well + + // Used to be public [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + /* [internal use] + Reads the "value" of the element -- another element, or text. + This should terminate with the current end tag. + */ + const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding ); + +private: + TiXmlAttributeSet attributeSet; +}; + + +/** An XML comment. +*/ +class TiXmlComment : public TiXmlNode +{ +public: + /// Constructs an empty comment. + TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {} + /// Construct a comment from text. + TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) { + SetValue( _value ); + } + TiXmlComment( const TiXmlComment& ); + TiXmlComment& operator=( const TiXmlComment& base ); + + virtual ~TiXmlComment() {} + + /// Returns a copy of this Comment. + virtual TiXmlNode* Clone() const; + // Write this Comment to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /* Attribtue parsing starts: at the ! of the !-- + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* visitor ) const; + +protected: + void CopyTo( TiXmlComment* target ) const; + + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif +// virtual void StreamOut( TIXML_OSTREAM * out ) const; + +private: + +}; + + +/** XML text. A text node can have 2 ways to output the next. "normal" output + and CDATA. It will default to the mode it was parsed from the XML file and + you generally want to leave it alone, but you can change the output mode with + SetCDATA() and query it with CDATA(). +*/ +class TiXmlText : public TiXmlNode +{ + friend class TiXmlElement; +public: + /** Constructor for text element. By default, it is treated as + normal, encoded text. If you want it be output as a CDATA text + element, set the parameter _cdata to 'true' + */ + TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT) + { + SetValue( initValue ); + cdata = false; + } + virtual ~TiXmlText() {} + + #ifdef TIXML_USE_STL + /// Constructor. + TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT) + { + SetValue( initValue ); + cdata = false; + } + #endif + + TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT ) { copy.CopyTo( this ); } + TiXmlText& operator=( const TiXmlText& base ) { base.CopyTo( this ); return *this; } + + // Write this text object to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /// Queries whether this represents text using a CDATA section. + bool CDATA() const { return cdata; } + /// Turns on or off a CDATA representation of text. + void SetCDATA( bool _cdata ) { cdata = _cdata; } + + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlText* ToText() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* content ) const; + +protected : + /// [internal use] Creates a new Element and returns it. + virtual TiXmlNode* Clone() const; + void CopyTo( TiXmlText* target ) const; + + bool Blank() const; // returns true if all white space and new lines + // [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + bool cdata; // true if this should be input and output as a CDATA style text element +}; + + +/** In correct XML the declaration is the first entry in the file. + @verbatim + + @endverbatim + + TinyXml will happily read or write files without a declaration, + however. There are 3 possible attributes to the declaration: + version, encoding, and standalone. + + Note: In this version of the code, the attributes are + handled as special cases, not generic attributes, simply + because there can only be at most 3 and they are always the same. +*/ +class TiXmlDeclaration : public TiXmlNode +{ +public: + /// Construct an empty declaration. + TiXmlDeclaration() : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) {} + +#ifdef TIXML_USE_STL + /// Constructor. + TiXmlDeclaration( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ); +#endif + + /// Construct. + TiXmlDeclaration( const char* _version, + const char* _encoding, + const char* _standalone ); + + TiXmlDeclaration( const TiXmlDeclaration& copy ); + TiXmlDeclaration& operator=( const TiXmlDeclaration& copy ); + + virtual ~TiXmlDeclaration() {} + + /// Version. Will return an empty string if none was found. + const char *Version() const { return version.c_str (); } + /// Encoding. Will return an empty string if none was found. + const char *Encoding() const { return encoding.c_str (); } + /// Is this a standalone document? + const char *Standalone() const { return standalone.c_str (); } + + /// Creates a copy of this Declaration and returns it. + virtual TiXmlNode* Clone() const; + // Print this declaration to a FILE stream. + virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; + virtual void Print( FILE* cfile, int depth ) const { + Print( cfile, depth, 0 ); + } + + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* visitor ) const; + +protected: + void CopyTo( TiXmlDeclaration* target ) const; + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + + TIXML_STRING version; + TIXML_STRING encoding; + TIXML_STRING standalone; +}; + + +/** Any tag that tinyXml doesn't recognize is saved as an + unknown. It is a tag of text, but should not be modified. + It will be written back to the XML, unchanged, when the file + is saved. + + DTD tags get thrown into TiXmlUnknowns. +*/ +class TiXmlUnknown : public TiXmlNode +{ +public: + TiXmlUnknown() : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) {} + virtual ~TiXmlUnknown() {} + + TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN ) { copy.CopyTo( this ); } + TiXmlUnknown& operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); return *this; } + + /// Creates a copy of this Unknown and returns it. + virtual TiXmlNode* Clone() const; + // Print this Unknown to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* content ) const; + +protected: + void CopyTo( TiXmlUnknown* target ) const; + + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + +}; + + +/** Always the top level node. A document binds together all the + XML pieces. It can be saved, loaded, and printed to the screen. + The 'value' of a document node is the xml file name. +*/ +class TiXmlDocument : public TiXmlNode +{ +public: + /// Create an empty document, that has no name. + TiXmlDocument(); + /// Create a document with a name. The name of the document is also the filename of the xml. + TiXmlDocument( const char * documentName ); + + #ifdef TIXML_USE_STL + /// Constructor. + TiXmlDocument( const std::string& documentName ); + #endif + + TiXmlDocument( const TiXmlDocument& copy ); + TiXmlDocument& operator=( const TiXmlDocument& copy ); + + virtual ~TiXmlDocument() {} + + /** Load a file using the current document value. + Returns true if successful. Will delete any existing + document data before loading. + */ + bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the current document value. Returns true if successful. + bool SaveFile() const; + /// Load a file using the given filename. Returns true if successful. + bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the given filename. Returns true if successful. + bool SaveFile( const char * filename ) const; + /** Load a file using the given FILE*. Returns true if successful. Note that this method + doesn't stream - the entire object pointed at by the FILE* + will be interpreted as an XML file. TinyXML doesn't stream in XML from the current + file location. Streaming may be added in the future. + */ + bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the given FILE*. Returns true if successful. + bool SaveFile( FILE* ) const; + + #ifdef TIXML_USE_STL + bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. + { + return LoadFile( filename.c_str(), encoding ); + } + bool SaveFile( const std::string& filename ) const ///< STL std::string version. + { + return SaveFile( filename.c_str() ); + } + #endif + + /** Parse the given null terminated block of xml data. Passing in an encoding to this + method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml + to use that encoding, regardless of what TinyXml might otherwise try to detect. + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + + /** Get the root element -- the only top level element -- of the document. + In well formed XML, there should only be one. TinyXml is tolerant of + multiple elements at the document level. + */ + const TiXmlElement* RootElement() const { return FirstChildElement(); } + TiXmlElement* RootElement() { return FirstChildElement(); } + + /** If an error occurs, Error will be set to true. Also, + - The ErrorId() will contain the integer identifier of the error (not generally useful) + - The ErrorDesc() method will return the name of the error. (very useful) + - The ErrorRow() and ErrorCol() will return the location of the error (if known) + */ + bool Error() const { return error; } + + /// Contains a textual (english) description of the error if one occurs. + const char * ErrorDesc() const { return errorDesc.c_str (); } + + /** Generally, you probably want the error string ( ErrorDesc() ). But if you + prefer the ErrorId, this function will fetch it. + */ + int ErrorId() const { return errorId; } + + /** Returns the location (if known) of the error. The first column is column 1, + and the first row is row 1. A value of 0 means the row and column wasn't applicable + (memory errors, for example, have no row/column) or the parser lost the error. (An + error in the error reporting, in that case.) + + @sa SetTabSize, Row, Column + */ + int ErrorRow() const { return errorLocation.row+1; } + int ErrorCol() const { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() + + /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) + to report the correct values for row and column. It does not change the output + or input in any way. + + By calling this method, with a tab size + greater than 0, the row and column of each node and attribute is stored + when the file is loaded. Very useful for tracking the DOM back in to + the source file. + + The tab size is required for calculating the location of nodes. If not + set, the default of 4 is used. The tabsize is set per document. Setting + the tabsize to 0 disables row/column tracking. + + Note that row and column tracking is not supported when using operator>>. + + The tab size needs to be enabled before the parse or load. Correct usage: + @verbatim + TiXmlDocument doc; + doc.SetTabSize( 8 ); + doc.Load( "myfile.xml" ); + @endverbatim + + @sa Row, Column + */ + void SetTabSize( int _tabsize ) { tabsize = _tabsize; } + + int TabSize() const { return tabsize; } + + /** If you have handled the error, it can be reset with this call. The error + state is automatically cleared if you Parse a new XML block. + */ + void ClearError() { error = false; + errorId = 0; + errorDesc = ""; + errorLocation.row = errorLocation.col = 0; + //errorLocation.last = 0; + } + + /** Write the document to standard out using formatted printing ("pretty print"). */ + void Print() const { Print( stdout, 0 ); } + + /* Write the document to a string using formatted printing ("pretty print"). This + will allocate a character array (new char[]) and return it as a pointer. The + calling code pust call delete[] on the return char* to avoid a memory leak. + */ + //char* PrintToMemory() const; + + /// Print this Document to a FILE stream. + virtual void Print( FILE* cfile, int depth = 0 ) const; + // [internal use] + void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding ); + + virtual const TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + virtual TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Walk the XML tree visiting this node and all of its children. + */ + virtual bool Accept( TiXmlVisitor* content ) const; + +protected : + // [internal use] + virtual TiXmlNode* Clone() const; + #ifdef TIXML_USE_STL + virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); + #endif + +private: + void CopyTo( TiXmlDocument* target ) const; + + bool error; + int errorId; + TIXML_STRING errorDesc; + int tabsize; + TiXmlCursor errorLocation; + bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write. +}; + + +/** + A TiXmlHandle is a class that wraps a node pointer with null checks; this is + an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml + DOM structure. It is a separate utility class. + + Take an example: + @verbatim + + + + + + + @endverbatim + + Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very + easy to write a *lot* of code that looks like: + + @verbatim + TiXmlElement* root = document.FirstChildElement( "Document" ); + if ( root ) + { + TiXmlElement* element = root->FirstChildElement( "Element" ); + if ( element ) + { + TiXmlElement* child = element->FirstChildElement( "Child" ); + if ( child ) + { + TiXmlElement* child2 = child->NextSiblingElement( "Child" ); + if ( child2 ) + { + // Finally do something useful. + @endverbatim + + And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity + of such code. A TiXmlHandle checks for null pointers so it is perfectly safe + and correct to use: + + @verbatim + TiXmlHandle docHandle( &document ); + TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement(); + if ( child2 ) + { + // do something useful + @endverbatim + + Which is MUCH more concise and useful. + + It is also safe to copy handles - internally they are nothing more than node pointers. + @verbatim + TiXmlHandle handleCopy = handle; + @endverbatim + + What they should not be used for is iteration: + + @verbatim + int i=0; + while ( true ) + { + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement(); + if ( !child ) + break; + // do something + ++i; + } + @endverbatim + + It seems reasonable, but it is in fact two embedded while loops. The Child method is + a linear walk to find the element, so this code would iterate much more than it needs + to. Instead, prefer: + + @verbatim + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement(); + + for( child; child; child=child->NextSiblingElement() ) + { + // do something + } + @endverbatim +*/ +class TiXmlHandle +{ +public: + /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. + TiXmlHandle( TiXmlNode* _node ) { this->node = _node; } + /// Copy constructor + TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } + TiXmlHandle operator=( const TiXmlHandle& ref ) { if ( &ref != this ) this->node = ref.node; return *this; } + + /// Return a handle to the first child node. + TiXmlHandle FirstChild() const; + /// Return a handle to the first child node with the given name. + TiXmlHandle FirstChild( const char * value ) const; + /// Return a handle to the first child element. + TiXmlHandle FirstChildElement() const; + /// Return a handle to the first child element with the given name. + TiXmlHandle FirstChildElement( const char * value ) const; + + /** Return a handle to the "index" child with the given name. + The first child is 0, the second 1, etc. + */ + TiXmlHandle Child( const char* value, int index ) const; + /** Return a handle to the "index" child. + The first child is 0, the second 1, etc. + */ + TiXmlHandle Child( int index ) const; + /** Return a handle to the "index" child element with the given name. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandle ChildElement( const char* value, int index ) const; + /** Return a handle to the "index" child element. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandle ChildElement( int index ) const; + + #ifdef TIXML_USE_STL + TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } + TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } + + TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } + TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } + #endif + + /** Return the handle as a TiXmlNode. This may return null. + */ + TiXmlNode* ToNode() const { return node; } + /** Return the handle as a TiXmlElement. This may return null. + */ + TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } + /** Return the handle as a TiXmlText. This may return null. + */ + TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } + /** Return the handle as a TiXmlUnknown. This may return null. + */ + TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } + + /** @deprecated use ToNode. + Return the handle as a TiXmlNode. This may return null. + */ + TiXmlNode* Node() const { return ToNode(); } + /** @deprecated use ToElement. + Return the handle as a TiXmlElement. This may return null. + */ + TiXmlElement* Element() const { return ToElement(); } + /** @deprecated use ToText() + Return the handle as a TiXmlText. This may return null. + */ + TiXmlText* Text() const { return ToText(); } + /** @deprecated use ToUnknown() + Return the handle as a TiXmlUnknown. This may return null. + */ + TiXmlUnknown* Unknown() const { return ToUnknown(); } + +private: + TiXmlNode* node; +}; + + +/** Print to memory functionality. The TiXmlPrinter is useful when you need to: + + -# Print to memory (especially in non-STL mode) + -# Control formatting (line endings, etc.) + + When constructed, the TiXmlPrinter is in its default "pretty printing" mode. + Before calling Accept() you can call methods to control the printing + of the XML document. After TiXmlNode::Accept() is called, the printed document can + be accessed via the CStr(), Str(), and Size() methods. + + TiXmlPrinter uses the Visitor API. + @verbatim + TiXmlPrinter printer; + printer.SetIndent( "\t" ); + + doc.Accept( &printer ); + fprintf( stdout, "%s", printer.CStr() ); + @endverbatim +*/ +class TiXmlPrinter : public TiXmlVisitor +{ +public: + TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ), + buffer(), indent( " " ), lineBreak( "\n" ) {} + + virtual bool VisitEnter( const TiXmlDocument& doc ); + virtual bool VisitExit( const TiXmlDocument& doc ); + + virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ); + virtual bool VisitExit( const TiXmlElement& element ); + + virtual bool Visit( const TiXmlDeclaration& declaration ); + virtual bool Visit( const TiXmlText& text ); + virtual bool Visit( const TiXmlComment& comment ); + virtual bool Visit( const TiXmlUnknown& unknown ); + + /** Set the indent characters for printing. By default 4 spaces + but tab (\t) is also useful, or null/empty string for no indentation. + */ + void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; } + /// Query the indention string. + const char* Indent() { return indent.c_str(); } + /** Set the line breaking string. By default set to newline (\n). + Some operating systems prefer other characters, or can be + set to the null/empty string for no indenation. + */ + void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; } + /// Query the current line breaking string. + const char* LineBreak() { return lineBreak.c_str(); } + + /** Switch over to "stream printing" which is the most dense formatting without + linebreaks. Common when the XML is needed for network transmission. + */ + void SetStreamPrinting() { indent = ""; + lineBreak = ""; + } + /// Return the result. + const char* CStr() { return buffer.c_str(); } + /// Return the length of the result string. + size_t Size() { return buffer.size(); } + + #ifdef TIXML_USE_STL + /// Return the result. + const std::string& Str() { return buffer; } + #endif + +private: + void DoIndent() { + for( int i=0; i +#include + +#include "tinyxml.h" + +//#define DEBUG_PARSER +#if defined( DEBUG_PARSER ) +# if defined( DEBUG ) && defined( _MSC_VER ) +# include +# define TIXML_LOG OutputDebugString +# else +# define TIXML_LOG printf +# endif +#endif + +// Note tha "PutString" hardcodes the same list. This +// is less flexible than it appears. Changing the entries +// or order will break putstring. +TiXmlBase::Entity TiXmlBase::entity[ TiXmlBase::NUM_ENTITY ] = +{ + { "&", 5, '&' }, + { "<", 4, '<' }, + { ">", 4, '>' }, + { """, 6, '\"' }, + { "'", 6, '\'' } +}; + +// Bunch of unicode info at: +// http://www.unicode.org/faq/utf_bom.html +// Including the basic of this table, which determines the #bytes in the +// sequence from the lead byte. 1 placed for invalid sequences -- +// although the result will be junk, pass it through as much as possible. +// Beware of the non-characters in UTF-8: +// ef bb bf (Microsoft "lead bytes") +// ef bf be +// ef bf bf + +const unsigned char TIXML_UTF_LEAD_0 = 0xefU; +const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; +const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; + +const int TiXmlBase::utf8ByteTable[256] = +{ + // 0 1 2 3 4 5 6 7 8 9 a b c d e f + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 + 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte + 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid +}; + + +void TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) +{ + const unsigned long BYTE_MASK = 0xBF; + const unsigned long BYTE_MARK = 0x80; + const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; + + if (input < 0x80) + *length = 1; + else if ( input < 0x800 ) + *length = 2; + else if ( input < 0x10000 ) + *length = 3; + else if ( input < 0x200000 ) + *length = 4; + else + { *length = 0; return; } // This code won't covert this correctly anyway. + + output += *length; + + // Scary scary fall throughs. + switch (*length) + { + case 4: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 3: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 2: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 1: + --output; + *output = (char)(input | FIRST_BYTE_MARK[*length]); + } +} + + +/*static*/ int TiXmlBase::IsAlpha( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) +{ + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky trying + // to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + +// if ( encoding == TIXML_ENCODING_UTF8 ) +// { + if ( anyByte < 127 ) + return isalpha( anyByte ); + else + return 1; // What else to do? The unicode set is huge...get the english ones right. +// } +// else +// { +// return isalpha( anyByte ); +// } +} + + +/*static*/ int TiXmlBase::IsAlphaNum( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) +{ + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky trying + // to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + +// if ( encoding == TIXML_ENCODING_UTF8 ) +// { + if ( anyByte < 127 ) + return isalnum( anyByte ); + else + return 1; // What else to do? The unicode set is huge...get the english ones right. +// } +// else +// { +// return isalnum( anyByte ); +// } +} + + +class TiXmlParsingData +{ + friend class TiXmlDocument; + public: + void Stamp( const char* now, TiXmlEncoding encoding ); + + const TiXmlCursor& Cursor() const { return cursor; } + + private: + // Only used by the document! + TiXmlParsingData( const char* start, int _tabsize, int row, int col ) + { + assert( start ); + stamp = start; + tabsize = _tabsize; + cursor.row = row; + cursor.col = col; + } + + TiXmlCursor cursor; + const char* stamp; + int tabsize; +}; + + +void TiXmlParsingData::Stamp( const char* now, TiXmlEncoding encoding ) +{ + assert( now ); + + // Do nothing if the tabsize is 0. + if ( tabsize < 1 ) + { + return; + } + + // Get the current row, column. + int row = cursor.row; + int col = cursor.col; + const char* p = stamp; + assert( p ); + + while ( p < now ) + { + // Treat p as unsigned, so we have a happy compiler. + const unsigned char* pU = (const unsigned char*)p; + + // Code contributed by Fletcher Dunn: (modified by lee) + switch (*pU) { + case 0: + // We *should* never get here, but in case we do, don't + // advance past the terminating null character, ever + return; + + case '\r': + // bump down to the next line + ++row; + col = 0; + // Eat the character + ++p; + + // Check for \r\n sequence, and treat this as a single character + if (*p == '\n') { + ++p; + } + break; + + case '\n': + // bump down to the next line + ++row; + col = 0; + + // Eat the character + ++p; + + // Check for \n\r sequence, and treat this as a single + // character. (Yes, this bizarre thing does occur still + // on some arcane platforms...) + if (*p == '\r') { + ++p; + } + break; + + case '\t': + // Eat the character + ++p; + + // Skip to next tab stop + col = (col / tabsize + 1) * tabsize; + break; + + case TIXML_UTF_LEAD_0: + if ( encoding == TIXML_ENCODING_UTF8 ) + { + if ( *(p+1) && *(p+2) ) + { + // In these cases, don't advance the column. These are + // 0-width spaces. + if ( *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) + p += 3; + else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU ) + p += 3; + else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU ) + p += 3; + else + { p +=3; ++col; } // A normal character. + } + } + else + { + ++p; + ++col; + } + break; + + default: + if ( encoding == TIXML_ENCODING_UTF8 ) + { + // Eat the 1 to 4 byte utf8 character. + int step = TiXmlBase::utf8ByteTable[*((const unsigned char*)p)]; + if ( step == 0 ) + step = 1; // Error case from bad encoding, but handle gracefully. + p += step; + + // Just advance one column, of course. + ++col; + } + else + { + ++p; + ++col; + } + break; + } + } + cursor.row = row; + cursor.col = col; + assert( cursor.row >= -1 ); + assert( cursor.col >= -1 ); + stamp = p; + assert( stamp ); +} + + +const char* TiXmlBase::SkipWhiteSpace( const char* p, TiXmlEncoding encoding ) +{ + if ( !p || !*p ) + { + return 0; + } + if ( encoding == TIXML_ENCODING_UTF8 ) + { + while ( *p ) + { + const unsigned char* pU = (const unsigned char*)p; + + // Skip the stupid Microsoft UTF-8 Byte order marks + if ( *(pU+0)==TIXML_UTF_LEAD_0 + && *(pU+1)==TIXML_UTF_LEAD_1 + && *(pU+2)==TIXML_UTF_LEAD_2 ) + { + p += 3; + continue; + } + else if(*(pU+0)==TIXML_UTF_LEAD_0 + && *(pU+1)==0xbfU + && *(pU+2)==0xbeU ) + { + p += 3; + continue; + } + else if(*(pU+0)==TIXML_UTF_LEAD_0 + && *(pU+1)==0xbfU + && *(pU+2)==0xbfU ) + { + p += 3; + continue; + } + + if ( IsWhiteSpace( *p ) ) // Still using old rules for white space. + ++p; + else + break; + } + } + else + { + while ( *p && IsWhiteSpace( *p ) ) + ++p; + } + + return p; +} + +#ifdef TIXML_USE_STL +/*static*/ bool TiXmlBase::StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ) +{ + for( ;; ) + { + if ( !in->good() ) return false; + + int c = in->peek(); + // At this scope, we can't get to a document. So fail silently. + if ( !IsWhiteSpace( c ) || c <= 0 ) + return true; + + *tag += (char) in->get(); + } +} + +/*static*/ bool TiXmlBase::StreamTo( std::istream * in, int character, TIXML_STRING * tag ) +{ + //assert( character > 0 && character < 128 ); // else it won't work in utf-8 + while ( in->good() ) + { + int c = in->peek(); + if ( c == character ) + return true; + if ( c <= 0 ) // Silent failure: can't get document at this scope + return false; + + in->get(); + *tag += (char) c; + } + return false; +} +#endif + +// One of TinyXML's more performance demanding functions. Try to keep the memory overhead down. The +// "assign" optimization removes over 10% of the execution time. +// +const char* TiXmlBase::ReadName( const char* p, TIXML_STRING * name, TiXmlEncoding encoding ) +{ + // Oddly, not supported on some comilers, + //name->clear(); + // So use this: + *name = ""; + assert( p ); + + // Names start with letters or underscores. + // Of course, in unicode, tinyxml has no idea what a letter *is*. The + // algorithm is generous. + // + // After that, they can be letters, underscores, numbers, + // hyphens, or colons. (Colons are valid ony for namespaces, + // but tinyxml can't tell namespaces from names.) + if ( p && *p + && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) + { + const char* start = p; + while( p && *p + && ( IsAlphaNum( (unsigned char ) *p, encoding ) + || *p == '_' + || *p == '-' + || *p == '.' + || *p == ':' ) ) + { + //(*name) += *p; // expensive + ++p; + } + if ( p-start > 0 ) { + name->assign( start, p-start ); + } + return p; + } + return 0; +} + +const char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding ) +{ + // Presume an entity, and pull it out. + TIXML_STRING ent; + int i; + *length = 0; + + if ( *(p+1) && *(p+1) == '#' && *(p+2) ) + { + unsigned long ucs = 0; + ptrdiff_t delta = 0; + unsigned mult = 1; + + if ( *(p+2) == 'x' ) + { + // Hexadecimal. + if ( !*(p+3) ) return 0; + + const char* q = p+3; + q = strchr( q, ';' ); + + if ( !q || !*q ) return 0; + + delta = q-p; + --q; + + while ( *q != 'x' ) + { + if ( *q >= '0' && *q <= '9' ) + ucs += mult * (*q - '0'); + else if ( *q >= 'a' && *q <= 'f' ) + ucs += mult * (*q - 'a' + 10); + else if ( *q >= 'A' && *q <= 'F' ) + ucs += mult * (*q - 'A' + 10 ); + else + return 0; + mult *= 16; + --q; + } + } + else + { + // Decimal. + if ( !*(p+2) ) return 0; + + const char* q = p+2; + q = strchr( q, ';' ); + + if ( !q || !*q ) return 0; + + delta = q-p; + --q; + + while ( *q != '#' ) + { + if ( *q >= '0' && *q <= '9' ) + ucs += mult * (*q - '0'); + else + return 0; + mult *= 10; + --q; + } + } + if ( encoding == TIXML_ENCODING_UTF8 ) + { + // convert the UCS to UTF-8 + ConvertUTF32ToUTF8( ucs, value, length ); + } + else + { + *value = (char)ucs; + *length = 1; + } + return p + delta + 1; + } + + // Now try to match it. + for( i=0; iappend( cArr, len ); + } + } + else + { + bool whitespace = false; + + // Remove leading white space: + p = SkipWhiteSpace( p, encoding ); + while ( p && *p + && !StringEqual( p, endTag, caseInsensitive, encoding ) ) + { + if ( *p == '\r' || *p == '\n' ) + { + whitespace = true; + ++p; + } + else if ( IsWhiteSpace( *p ) ) + { + whitespace = true; + ++p; + } + else + { + // If we've found whitespace, add it before the + // new character. Any whitespace just becomes a space. + if ( whitespace ) + { + (*text) += ' '; + whitespace = false; + } + int len; + char cArr[4] = { 0, 0, 0, 0 }; + p = GetChar( p, cArr, &len, encoding ); + if ( len == 1 ) + (*text) += cArr[0]; // more efficient + else + text->append( cArr, len ); + } + } + } + if ( p && *p ) + p += strlen( endTag ); + return ( p && *p ) ? p : 0; +} + +#ifdef TIXML_USE_STL + +void TiXmlDocument::StreamIn( std::istream * in, TIXML_STRING * tag ) +{ + // The basic issue with a document is that we don't know what we're + // streaming. Read something presumed to be a tag (and hope), then + // identify it, and call the appropriate stream method on the tag. + // + // This "pre-streaming" will never read the closing ">" so the + // sub-tag can orient itself. + + if ( !StreamTo( in, '<', tag ) ) + { + SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + + while ( in->good() ) + { + int tagIndex = (int) tag->length(); + while ( in->good() && in->peek() != '>' ) + { + int c = in->get(); + if ( c <= 0 ) + { + SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + break; + } + (*tag) += (char) c; + } + + if ( in->good() ) + { + // We now have something we presume to be a node of + // some sort. Identify it, and call the node to + // continue streaming. + TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); + + if ( node ) + { + node->StreamIn( in, tag ); + bool isElement = node->ToElement() != 0; + delete node; + node = 0; + + // If this is the root element, we're done. Parsing will be + // done by the >> operator. + if ( isElement ) + { + return; + } + } + else + { + SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + } + } + // We should have returned sooner. + SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); +} + +#endif + +const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) +{ + ClearError(); + + // Parse away, at the document level. Since a document + // contains nothing but other tags, most of what happens + // here is skipping white space. + if ( !p || !*p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + // Note that, for a document, this needs to come + // before the while space skip, so that parsing + // starts from the pointer we are given. + location.Clear(); + if ( prevData ) + { + location.row = prevData->cursor.row; + location.col = prevData->cursor.col; + } + else + { + location.row = 0; + location.col = 0; + } + TiXmlParsingData data( p, TabSize(), location.row, location.col ); + location = data.Cursor(); + + if ( encoding == TIXML_ENCODING_UNKNOWN ) + { + // Check for the Microsoft UTF-8 lead bytes. + const unsigned char* pU = (const unsigned char*)p; + if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 + && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 + && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) + { + encoding = TIXML_ENCODING_UTF8; + useMicrosoftBOM = true; + } + } + + p = SkipWhiteSpace( p, encoding ); + if ( !p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + while ( p && *p ) + { + TiXmlNode* node = Identify( p, encoding ); + if ( node ) + { + p = node->Parse( p, &data, encoding ); + LinkEndChild( node ); + } + else + { + break; + } + + // Did we get encoding info? + if ( encoding == TIXML_ENCODING_UNKNOWN + && node->ToDeclaration() ) + { + TiXmlDeclaration* dec = node->ToDeclaration(); + const char* enc = dec->Encoding(); + assert( enc ); + + if ( *enc == 0 ) + encoding = TIXML_ENCODING_UTF8; + else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) + encoding = TIXML_ENCODING_UTF8; + else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) + encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice + else + encoding = TIXML_ENCODING_LEGACY; + } + + p = SkipWhiteSpace( p, encoding ); + } + + // Was this empty? + if ( !firstChild ) { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); + return 0; + } + + // All is well. + return p; +} + +void TiXmlDocument::SetError( int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding ) +{ + // The first error in a chain is more accurate - don't set again! + if ( error ) + return; + + assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); + error = true; + errorId = err; + errorDesc = errorString[ errorId ]; + + errorLocation.Clear(); + if ( pError && data ) + { + data->Stamp( pError, encoding ); + errorLocation = data->Cursor(); + } +} + + +TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) +{ + TiXmlNode* returnNode = 0; + + p = SkipWhiteSpace( p, encoding ); + if( !p || !*p || *p != '<' ) + { + return 0; + } + + p = SkipWhiteSpace( p, encoding ); + + if ( !p || !*p ) + { + return 0; + } + + // What is this thing? + // - Elements start with a letter or underscore, but xml is reserved. + // - Comments: "; + + if ( !StringEqual( p, startTag, false, encoding ) ) + { + if ( document ) + document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding ); + return 0; + } + p += strlen( startTag ); + + // [ 1475201 ] TinyXML parses entities in comments + // Oops - ReadText doesn't work, because we don't want to parse the entities. + // p = ReadText( p, &value, false, endTag, false, encoding ); + // + // from the XML spec: + /* + [Definition: Comments may appear anywhere in a document outside other markup; in addition, + they may appear within the document type declaration at places allowed by the grammar. + They are not part of the document's character data; an XML processor MAY, but need not, + make it possible for an application to retrieve the text of comments. For compatibility, + the string "--" (double-hyphen) MUST NOT occur within comments.] Parameter entity + references MUST NOT be recognized within comments. + + An example of a comment: + + + */ + + value = ""; + // Keep all the white space. + while ( p && *p && !StringEqual( p, endTag, false, encoding ) ) + { + value.append( p, 1 ); + ++p; + } + if ( p && *p ) + p += strlen( endTag ); + + return p; +} + + +const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) +{ + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p ) return 0; + + if ( data ) + { + data->Stamp( p, encoding ); + location = data->Cursor(); + } + // Read the name, the '=' and the value. + const char* pErr = p; + p = ReadName( p, &name, encoding ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding ); + return 0; + } + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p || *p != '=' ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + + ++p; // skip '=' + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + + const char* end; + const char SINGLE_QUOTE = '\''; + const char DOUBLE_QUOTE = '\"'; + + if ( *p == SINGLE_QUOTE ) + { + ++p; + end = "\'"; // single quote in string + p = ReadText( p, &value, false, end, false, encoding ); + } + else if ( *p == DOUBLE_QUOTE ) + { + ++p; + end = "\""; // double quote in string + p = ReadText( p, &value, false, end, false, encoding ); + } + else + { + // All attribute values should be in single or double quotes. + // But this is such a common error that the parser will try + // its best, even without them. + value = ""; + while ( p && *p // existence + && !IsWhiteSpace( *p ) // whitespace + && *p != '/' && *p != '>' ) // tag end + { + if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) { + // [ 1451649 ] Attribute values with trailing quotes not handled correctly + // We did not have an opening quote but seem to have a + // closing one. Give up and throw an error. + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + value += *p; + ++p; + } + } + return p; +} + +#ifdef TIXML_USE_STL +void TiXmlText::StreamIn( std::istream * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( !cdata && (c == '<' ) ) + { + return; + } + if ( c <= 0 ) + { + TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + + (*tag) += (char) c; + in->get(); // "commits" the peek made above + + if ( cdata && c == '>' && tag->size() >= 3 ) { + size_t len = tag->size(); + if ( (*tag)[len-2] == ']' && (*tag)[len-3] == ']' ) { + // terminator of cdata. + return; + } + } + } +} +#endif + +const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) +{ + value = ""; + TiXmlDocument* document = GetDocument(); + + if ( data ) + { + data->Stamp( p, encoding ); + location = data->Cursor(); + } + + const char* const startTag = ""; + + if ( cdata || StringEqual( p, startTag, false, encoding ) ) + { + cdata = true; + + if ( !StringEqual( p, startTag, false, encoding ) ) + { + if ( document ) + document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding ); + return 0; + } + p += strlen( startTag ); + + // Keep all the white space, ignore the encoding, etc. + while ( p && *p + && !StringEqual( p, endTag, false, encoding ) + ) + { + value += *p; + ++p; + } + + TIXML_STRING dummy; + p = ReadText( p, &dummy, false, endTag, false, encoding ); + return p; + } + else + { + bool ignoreWhite = true; + + const char* end = "<"; + p = ReadText( p, &value, ignoreWhite, end, false, encoding ); + if ( p && *p ) + return p-1; // don't truncate the '<' + return 0; + } +} + +#ifdef TIXML_USE_STL +void TiXmlDeclaration::StreamIn( std::istream * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->get(); + if ( c <= 0 ) + { + TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + (*tag) += (char) c; + + if ( c == '>' ) + { + // All is well. + return; + } + } +} +#endif + +const char* TiXmlDeclaration::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding ) +{ + p = SkipWhiteSpace( p, _encoding ); + // Find the beginning, find the end, and look for + // the stuff in-between. + TiXmlDocument* document = GetDocument(); + if ( !p || !*p || !StringEqual( p, "SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding ); + return 0; + } + if ( data ) + { + data->Stamp( p, _encoding ); + location = data->Cursor(); + } + p += 5; + + version = ""; + encoding = ""; + standalone = ""; + + while ( p && *p ) + { + if ( *p == '>' ) + { + ++p; + return p; + } + + p = SkipWhiteSpace( p, _encoding ); + if ( StringEqual( p, "version", true, _encoding ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + version = attrib.Value(); + } + else if ( StringEqual( p, "encoding", true, _encoding ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + encoding = attrib.Value(); + } + else if ( StringEqual( p, "standalone", true, _encoding ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + standalone = attrib.Value(); + } + else + { + // Read over whatever it is. + while( p && *p && *p != '>' && !IsWhiteSpace( *p ) ) + ++p; + } + } + return 0; +} + +bool TiXmlText::Blank() const +{ + for ( unsigned i=0; i +#include "bDNA.h" +#include "bBlenderFile.h" +#include "btBulletFile.h" +#include "bCommon.h" +#include +#include +#include + +bool isBulletFile = false; + +using namespace bParse; +typedef std::string bString; + +/////////////////////////////////////////////////////////////////////////////// +typedef std::map bStringMap; +typedef std::vector bVariableList; +typedef std::vector bStringList; + + +/////////////////////////////////////////////////////////////////////////////// +static FILE *dump = 0; +static bDNA *mDNA =0; +static bStringMap mStructs; + + +/////////////////////////////////////////////////////////////////////////////// +class bVariable +{ +public: + bVariable(); + ~bVariable(); + + + bString dataType; + bString variableName; + + + bString functionName; + bString classCtor; + + bString memberVariable; + bString memberDataType; + bString functionArgs; + + + void initialize(bString dataType, bString variable, bStringMap refDataTable); + + bool isPtr; + bool isFunctionPtr; + bool isPtrToPtr; + bool isArray; + bool isCharArray; + bool isListBase; + bool isPadding; + bool isCommentedOut; + bool isGeneratedType; + bool isbString; +}; + +/////////////////////////////////////////////////////////////////////////////// +bool dataTypeStandard(bString dataType) +{ + if (dataType == "char") + return true; + if (dataType == "short") + return true; + if (dataType == "int") + return true; + if (dataType == "long") + return true; + if (dataType == "float") + return true; + if (dataType == "double") + return true; + if (dataType == "void") + return true; + if (dataType == "btScalar") + return true; + return false; +} + +/////////////////////////////////////////////////////////////////////////////// +void writeTemplate(short *structData) +{ + bString type = mDNA->getType(structData[0]); + bString className=type; + bString prefix = isBulletFile? "bullet_" : "blender_"; + + int thisLen = structData[1]; + structData+=2; + + bString fileName = prefix+type; + + bVariableList dataTypes; + bStringMap includeFiles; + + + for (int dataVal =0; dataValgetType(structData[0]); + bString dataName = mDNA->getName(structData[1]); + { + bString newDataType = ""; + bString newDataName = ""; + + bStringMap::iterator addB = mStructs.find(dataType); + if (addB != mStructs.end()) + { + newDataType = addB->second; + newDataName = dataName; + } + + else + { + if (dataTypeStandard(dataType)) + { + newDataType = dataType; + newDataName = dataName; + } + else + { + // Unresolved + // set it to an empty struct + // if it's not a ptr generate an error + newDataType = "bInvalidHandle"; + newDataName = dataName; + + if (dataName[0] != '*') + { + } + + } + } + + if (!newDataType.empty() && !newDataName.empty()) + { + bVariable var = bVariable(); + var.initialize(newDataType, newDataName, mStructs); + dataTypes.push_back(var); + } + } + + + bStringMap::iterator include = mStructs.find(dataType); + if (include != mStructs.end()) + { + if (dataName[0] != '*') + { + if (includeFiles.find(dataType)== includeFiles.end()) + { + includeFiles[dataType]=prefix+dataType; + } + } + } + } + + + fprintf(dump, "###############################################################\n"); + fprintf(dump, "%s = bStructClass()\n", fileName.c_str()); + fprintf(dump, "%s.name = '%s'\n", fileName.c_str(), className.c_str()); + fprintf(dump, "%s.filename = '%s'\n", fileName.c_str(), fileName.c_str()); + + bVariableList::iterator vars = dataTypes.begin(); + while (vars!= dataTypes.end()) + { + fprintf(dump, "%s.dataTypes.append('%s %s')\n", fileName.c_str(), vars->dataType.c_str(), vars->variableName.c_str()); + vars++; + } + + bStringMap::iterator inc = includeFiles.begin(); + while (inc != includeFiles.end()) + { + fprintf(dump, "%s.includes.append('%s.h')\n", fileName.c_str(), inc->second.c_str()); + inc++; + } + fprintf(dump, "DataTypeList.append(%s)\n", fileName.c_str()); +} + + +/////////////////////////////////////////////////////////////////////////////// +char data[]={ +"\n" +"class bStructClass:\n" +" def __init__(self):\n" +" self.name = \"\";\n" +" self.filename = \"\";\n" +" self.includes = []\n" +" self.dataTypes = []\n" +"\n\n" +"DataTypeList = []\n" +}; + + +/////////////////////////////////////////////////////////////////////////////// +int main(int argc,char** argv) +{ + using namespace bParse; + dump = fopen("dump.py", "w"); + + if (!dump) return 0; + fprintf(dump, "%s\n", data); + + + char* filename = "../../../Demos/SerializeDemo/testFile.bullet"; + + if (argc==2) + filename = argv[1]; + + bString fileStr(filename); + bString extension(".bullet"); + + int index2 = fileStr.find(extension); + if (index2>=0) + isBulletFile=true; + + + FILE* fp = fopen (filename,"rb"); + + if (!fp) + { + printf("error: file not found %s\n",filename); + exit(0); + } + + char* memBuf = 0; + int len = 0; + + long currentpos = ftell(fp); /* save current cursor position */ + long newpos; + int bytesRead; + + fseek(fp, 0, SEEK_END); /* seek to end */ + newpos = ftell(fp); /* find position of end -- this is the length */ + fseek(fp, currentpos, SEEK_SET); /* restore previous cursor position */ + + len = newpos; + + memBuf = (char*)malloc(len); + bytesRead = fread(memBuf,len,1,fp); + + bool swap = false; + + + if (isBulletFile) + { + btBulletFile f(memBuf,len); + swap = (f.getFlags() & FD_ENDIAN_SWAP)!=0; + } else + { + bBlenderFile f(memBuf,len); + swap = (f.getFlags() & FD_ENDIAN_SWAP)!=0; + } + + + + + + char *blenderData = memBuf; + int sdnaPos=0; + int mDataStart = 12; + + char *tempBuffer = blenderData; + for (int i=0; iinitMemory(); + + mDNA->init(memBuf+sdnaPos, len-sdnaPos, swap); + + + for (int i=0; igetNumStructs(); i++) + { + short *structData = mDNA->getStruct(i); + bString type = mDNA->getType(structData[0]); + + bString className = type; + mStructs[type]=className; + } + + + for (int i=0; igetNumStructs(); i++) + { + short *structData = mDNA->getStruct(i); + writeTemplate(structData); + } + + delete mDNA; + fclose(dump); + return 0; +} +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +int _getArraySize(char* str) +{ + int a, mul=1; + char stri[100], *cp=0; + int len = (int)strlen(str); + + memcpy(stri, str, len+1); + for (a=0; a + +///work-in-progress +///This ReadBulletSample is kept as simple as possible without dependencies to the Bullet SDK. +///It can be used to load .bullet data for other physics SDKs +///For a more complete example how to load and convert Bullet data using the Bullet SDK check out +///the Bullet/Demos/SerializeDemo and Bullet/Serialize/BulletWorldImporter + +using namespace Bullet; + +enum LocalBroadphaseNativeTypes +{ + // polyhedral convex shapes + BOX_SHAPE_PROXYTYPE, + TRIANGLE_SHAPE_PROXYTYPE, + TETRAHEDRAL_SHAPE_PROXYTYPE, + CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE, + CONVEX_HULL_SHAPE_PROXYTYPE, + CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE, + CUSTOM_POLYHEDRAL_SHAPE_TYPE, +//implicit convex shapes +IMPLICIT_CONVEX_SHAPES_START_HERE, + SPHERE_SHAPE_PROXYTYPE, + MULTI_SPHERE_SHAPE_PROXYTYPE, + CAPSULE_SHAPE_PROXYTYPE, + CONE_SHAPE_PROXYTYPE, + CONVEX_SHAPE_PROXYTYPE, + CYLINDER_SHAPE_PROXYTYPE, + UNIFORM_SCALING_SHAPE_PROXYTYPE, + MINKOWSKI_SUM_SHAPE_PROXYTYPE, + MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE, + BOX_2D_SHAPE_PROXYTYPE, + CONVEX_2D_SHAPE_PROXYTYPE, + CUSTOM_CONVEX_SHAPE_TYPE, +//concave shapes +CONCAVE_SHAPES_START_HERE, + //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy! + TRIANGLE_MESH_SHAPE_PROXYTYPE, + SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE, + ///used for demo integration FAST/Swift collision library and Bullet + FAST_CONCAVE_MESH_PROXYTYPE, + //terrain + TERRAIN_SHAPE_PROXYTYPE, +///Used for GIMPACT Trimesh integration + GIMPACT_SHAPE_PROXYTYPE, +///Multimaterial mesh + MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE, + + EMPTY_SHAPE_PROXYTYPE, + STATIC_PLANE_PROXYTYPE, + CUSTOM_CONCAVE_SHAPE_TYPE, +CONCAVE_SHAPES_END_HERE, + + COMPOUND_SHAPE_PROXYTYPE, + + SOFTBODY_SHAPE_PROXYTYPE, + HFFLUID_SHAPE_PROXYTYPE, + HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE, + INVALID_SHAPE_PROXYTYPE, + + MAX_BROADPHASE_COLLISION_TYPES + +}; + +btBulletDataExtractor::btBulletDataExtractor() +{ +} + +btBulletDataExtractor::~btBulletDataExtractor() +{ +} + +void btBulletDataExtractor::convertAllObjects(bParse::btBulletFile* bulletFile2) +{ + int i; + + for (i=0;im_collisionShapes.size();i++) + { + btCollisionShapeData* shapeData = (btCollisionShapeData*)bulletFile2->m_collisionShapes[i]; + if (shapeData->m_name) + printf("converting shape %s\n", shapeData->m_name); + void* shape = convertCollisionShape(shapeData); + } + +} + + + +void* btBulletDataExtractor::convertCollisionShape( btCollisionShapeData* shapeData ) +{ + void* shape = 0; + + switch (shapeData->m_shapeType) + { + case STATIC_PLANE_PROXYTYPE: + { + btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*)shapeData; + void* shape = createPlaneShape(planeData->m_planeNormal,planeData->m_planeConstant, planeData->m_localScaling); + break; + } + + case CYLINDER_SHAPE_PROXYTYPE: + case CAPSULE_SHAPE_PROXYTYPE: + case BOX_SHAPE_PROXYTYPE: + case SPHERE_SHAPE_PROXYTYPE: + case MULTI_SPHERE_SHAPE_PROXYTYPE: + case CONVEX_HULL_SHAPE_PROXYTYPE: + { + btConvexInternalShapeData* bsd = (btConvexInternalShapeData*)shapeData; + + switch (shapeData->m_shapeType) + { + case BOX_SHAPE_PROXYTYPE: + { + shape = createBoxShape(bsd->m_implicitShapeDimensions, bsd->m_localScaling,bsd->m_collisionMargin); + break; + } + case SPHERE_SHAPE_PROXYTYPE: + { + shape = createSphereShape(bsd->m_implicitShapeDimensions.m_floats[0],bsd->m_localScaling, bsd->m_collisionMargin); + break; + } +#if 0 + case CAPSULE_SHAPE_PROXYTYPE: + { + btCapsuleShapeData* capData = (btCapsuleShapeData*)shapeData; + switch (capData->m_upAxis) + { + case 0: + { + shape = createCapsuleShapeX(implicitShapeDimensions.getY(),2*implicitShapeDimensions.getX()); + break; + } + case 1: + { + shape = createCapsuleShapeY(implicitShapeDimensions.getX(),2*implicitShapeDimensions.getY()); + break; + } + case 2: + { + shape = createCapsuleShapeZ(implicitShapeDimensions.getX(),2*implicitShapeDimensions.getZ()); + break; + } + default: + { + printf("error: wrong up axis for btCapsuleShape\n"); + } + + }; + + break; + } + case CYLINDER_SHAPE_PROXYTYPE: + { + btCylinderShapeData* cylData = (btCylinderShapeData*) shapeData; + btVector3 halfExtents = implicitShapeDimensions+margin; + switch (cylData->m_upAxis) + { + case 0: + { + shape = createCylinderShapeX(halfExtents.getY(),halfExtents.getX()); + break; + } + case 1: + { + shape = createCylinderShapeY(halfExtents.getX(),halfExtents.getY()); + break; + } + case 2: + { + shape = createCylinderShapeZ(halfExtents.getX(),halfExtents.getZ()); + break; + } + default: + { + printf("unknown Cylinder up axis\n"); + } + + }; + + + + break; + } + case MULTI_SPHERE_SHAPE_PROXYTYPE: + { + btMultiSphereShapeData* mss = (btMultiSphereShapeData*)bsd; + int numSpheres = mss->m_localPositionArraySize; + int i; + for ( i=0;im_localPositionArrayPtr[i].m_pos); + radii[i] = mss->m_localPositionArrayPtr[i].m_radius; + } + shape = new btMultiSphereShape(&tmpPos[0],&radii[0],numSpheres); + break; + } + case CONVEX_HULL_SHAPE_PROXYTYPE: + { + btConvexHullShapeData* convexData = (btConvexHullShapeData*)bsd; + int numPoints = convexData->m_numUnscaledPoints; + + btAlignedObjectArray tmpPoints; + tmpPoints.resize(numPoints); + int i; + for ( i=0;im_unscaledPointsFloatPtr) + tmpPoints[i].deSerialize(convexData->m_unscaledPointsFloatPtr[i]); + if (convexData->m_unscaledPointsDoublePtr) + tmpPoints[i].deSerializeDouble(convexData->m_unscaledPointsDoublePtr[i]); + } + shape = createConvexHullShape(); + + return shape; + break; + } +#endif + + default: + { + printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType); + } + } + + break; + } +#if 0 + case TRIANGLE_MESH_SHAPE_PROXYTYPE: + { + btTriangleMeshShapeData* trimesh = (btTriangleMeshShapeData*)shapeData; + btTriangleIndexVertexArray* meshInterface = createMeshInterface(trimesh->m_meshInterface); + if (!meshInterface->getNumSubParts()) + { + return 0; + } + + btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling); + meshInterface->setScaling(scaling); + + + btOptimizedBvh* bvh = 0; + + btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface,bvh); + trimeshShape->setMargin(trimesh->m_collisionMargin); + shape = trimeshShape; + + if (trimesh->m_triangleInfoMap) + { + btTriangleInfoMap* map = createTriangleInfoMap(); + map->deSerialize(*trimesh->m_triangleInfoMap); + trimeshShape->setTriangleInfoMap(map); + +#ifdef USE_INTERNAL_EDGE_UTILITY + gContactAddedCallback = btAdjustInternalEdgeContactsCallback; +#endif //USE_INTERNAL_EDGE_UTILITY + + } + + //printf("trimesh->m_collisionMargin=%f\n",trimesh->m_collisionMargin); + break; + } + case COMPOUND_SHAPE_PROXYTYPE: + { + btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData; + btCompoundShape* compoundShape = createCompoundShape(); + + + btAlignedObjectArray childShapes; + for (int i=0;im_numChildShapes;i++) + { + btCollisionShape* childShape = convertCollisionShape(compoundData->m_childShapePtr[i].m_childShape); + if (childShape) + { + btTransform localTransform; + localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform); + compoundShape->addChildShape(localTransform,childShape); + } else + { + printf("error: couldn't create childShape for compoundShape\n"); + } + + } + shape = compoundShape; + + break; + } + + case GIMPACT_SHAPE_PROXYTYPE: + { + btGImpactMeshShapeData* gimpactData = (btGImpactMeshShapeData*) shapeData; + if (gimpactData->m_gimpactSubType == CONST_GIMPACT_TRIMESH_SHAPE) + { + btTriangleIndexVertexArray* meshInterface = createMeshInterface(gimpactData->m_meshInterface); + btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface); + btVector3 localScaling; + localScaling.deSerializeFloat(gimpactData->m_localScaling); + gimpactShape->setLocalScaling(localScaling); + gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin)); + gimpactShape->updateBound(); + shape = gimpactShape; + } else + { + printf("unsupported gimpact sub type\n"); + } + break; + } + case SOFTBODY_SHAPE_PROXYTYPE: + { + return 0; + } +#endif + default: + { + printf("unsupported shape type (%d)\n",shapeData->m_shapeType); + } + } + + return shape; + +} + +void* btBulletDataExtractor::createBoxShape( const Bullet::btVector3FloatData& halfDimensions, const Bullet::btVector3FloatData& localScaling, float collisionMargin) +{ + printf("createBoxShape with halfDimensions %f,%f,%f\n",halfDimensions.m_floats[0], halfDimensions.m_floats[1],halfDimensions.m_floats[2]); + return 0; +} + +void* btBulletDataExtractor::createSphereShape( float radius, const Bullet::btVector3FloatData& localScaling, float collisionMargin) +{ + printf("createSphereShape with radius %f\n",radius); + return 0; +} + + +void* btBulletDataExtractor::createPlaneShape( const btVector3FloatData& planeNormal, float planeConstant, const Bullet::btVector3FloatData& localScaling) +{ + printf("createPlaneShape with normal %f,%f,%f and planeConstant\n",planeNormal.m_floats[0], planeNormal.m_floats[1],planeNormal.m_floats[2],planeConstant); + return 0; +} + diff --git a/Extras/Serialize/ReadBulletSample/BulletDataExtractor.h b/Extras/Serialize/ReadBulletSample/BulletDataExtractor.h new file mode 100644 index 0000000000..8524716ba7 --- /dev/null +++ b/Extras/Serialize/ReadBulletSample/BulletDataExtractor.h @@ -0,0 +1,32 @@ +#ifndef BULLET_DATA_EXTRACTOR_H +#define BULLET_DATA_EXTRACTOR_H + + +#include "../BulletFileLoader/autogenerated/bullet.h" + +namespace bParse +{ + class btBulletFile; +}; + +class btBulletDataExtractor +{ + public: + + btBulletDataExtractor(); + + virtual ~btBulletDataExtractor(); + + virtual void convertAllObjects(bParse::btBulletFile* bulletFile); + + virtual void* convertCollisionShape( Bullet::btCollisionShapeData* shapeData ); + + virtual void* createPlaneShape( const Bullet::btVector3FloatData& planeNormal, float planeConstant, const Bullet::btVector3FloatData& localScaling); + + virtual void* createBoxShape( const Bullet::btVector3FloatData& halfDimensions, const Bullet::btVector3FloatData& localScaling, float collisionMargin); + + virtual void* createSphereShape( float radius, const Bullet::btVector3FloatData& localScaling, float collisionMargin); + +}; + +#endif //BULLET_DATA_EXTRACTOR_H \ No newline at end of file diff --git a/Extras/Serialize/ReadBulletSample/CMakeLists.txt b/Extras/Serialize/ReadBulletSample/CMakeLists.txt new file mode 100644 index 0000000000..e819b9e5ec --- /dev/null +++ b/Extras/Serialize/ReadBulletSample/CMakeLists.txt @@ -0,0 +1,33 @@ + +INCLUDE_DIRECTORIES( +${BULLET_PHYSICS_SOURCE_DIR}/src +) + +LINK_LIBRARIES( + BulletFileLoader +) +IF (WIN32) + SET(ADDITIONAL_SRC + ${BULLET_PHYSICS_SOURCE_DIR}/build/bullet.rc + ) +ENDIF() + +SET(READBULLET_SRC + main.cpp + BulletDataExtractor.cpp + BulletDataExtractor.h + ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btSerializer.cpp + ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btAlignedAllocator.cpp +) + +ADD_EXECUTABLE(AppReadBulletSample + ${READBULLET_SRC} + ${ADDITIONAL_SRC} +) + + +IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) + SET_TARGET_PROPERTIES(AppReadBulletSample PROPERTIES DEBUG_POSTFIX "_Debug") + SET_TARGET_PROPERTIES(AppReadBulletSample PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel") + SET_TARGET_PROPERTIES(AppReadBulletSample PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo") +ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) \ No newline at end of file diff --git a/Extras/Serialize/ReadBulletSample/main.cpp b/Extras/Serialize/ReadBulletSample/main.cpp new file mode 100644 index 0000000000..e9420c7d24 --- /dev/null +++ b/Extras/Serialize/ReadBulletSample/main.cpp @@ -0,0 +1,63 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2011 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#include +#include "../BulletFileLoader/btBulletFile.h" +#include "BulletDataExtractor.h" + +///This ReadBulletSample is kept as simple as possible without dependencies to the Bullet SDK. +///It can be used to load .bullet data for other physics SDKs +///For a more complete example how to load and convert Bullet data using the Bullet SDK check out +///the Bullet/Demos/SerializeDemo and Bullet/Serialize/BulletWorldImporter + +int main(int argc, char** argv) +{ + const char* fileName="testFile.bullet"; + bool verboseDumpAllTypes = false; + + bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(fileName); + + bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0; + + if (ok) + bulletFile2->parse(verboseDumpAllTypes); + else + { + printf("Error loading file %s.\n",fileName); + exit(0); + } + ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0; + if (!ok) + { + printf("Error parsing file %s.\n",fileName); + exit(0); + } + + if (verboseDumpAllTypes) + { + bulletFile2->dumpChunks(bulletFile2->getFileDNA()); + } + + + btBulletDataExtractor extractor; + + extractor.convertAllObjects(bulletFile2); + + delete bulletFile2; + + return 0; +} + diff --git a/Extras/Serialize/makesdna/CMakeLists.txt b/Extras/Serialize/makesdna/CMakeLists.txt new file mode 100644 index 0000000000..9f5d5c6837 --- /dev/null +++ b/Extras/Serialize/makesdna/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 2.4) + +IF(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +ENDIF(COMMAND cmake_policy) + +INCLUDE_DIRECTORIES(${BULLET_PHYSICS_SOURCE_DIR}/src ) + +#FILE(GLOB INC_FILES ../*.h) + +SET (INC_FILES + DNA_rigidbody.h + + ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btVector3.h + ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btMatrix3x3.h + ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btTransform.h + ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletCollision/CollisionShapes/btCollisionShape.h + ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletCollision/CollisionShapes/btConvexInternalShape.h + ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletCollision/CollisionDispatch/btCollisionObject.h +) + +# Build makesdna executable +SET(SRC makesdna.cpp) +ADD_EXECUTABLE(makesdna ${SRC} ${INC_FILES}) + +# Output BulletDNA.c +ADD_CUSTOM_COMMAND( + OUTPUT ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btSerializer.cpp + COMMAND ${CMAKE_CFG_INTDIR}/makesdna ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btSerializer.cpp ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/CommonSerialize/ + DEPENDS makesdna +) + +# Build bf_dna library +SET(SRC ${BULLET_PHYSICS_SOURCE_DIR}/src/LinearMath/btSerializer.cpp) +ADD_LIBRARY(BulletDNA ${SRC} ${INC_FILES}) + +MESSAGE(STATUS "Configuring makesdna") diff --git a/Extras/Serialize/makesdna/DNA_rigidbody.h b/Extras/Serialize/makesdna/DNA_rigidbody.h new file mode 100644 index 0000000000..010ed1bbfa --- /dev/null +++ b/Extras/Serialize/makesdna/DNA_rigidbody.h @@ -0,0 +1,29 @@ + +#ifndef DNA_RIGIDBODY_H +#define DNA_RIGIDBODY_H + + +struct PointerArray +{ + int m_size; + int m_capacity; + void *m_data; +}; + + +struct btPhysicsSystem +{ + PointerArray m_collisionShapes; + PointerArray m_collisionObjects; + PointerArray m_constraints; +}; + +///we need this to compute the pointer sizes +struct ListBase +{ + void *first; + void *last; +}; + + +#endif diff --git a/Extras/Serialize/makesdna/makesdna.cpp b/Extras/Serialize/makesdna/makesdna.cpp new file mode 100644 index 0000000000..25f994cbff --- /dev/null +++ b/Extras/Serialize/makesdna/makesdna.cpp @@ -0,0 +1,1255 @@ +/// Current makesdna.cpp is a from Blender, but we will completely rewrite it in C++ under a ZLib license +/// The Original version is at https://svn.blender.org/svnroot/bf-blender/trunk/blender/source/blender/makesdna/intern/makesdna.c + +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + * + * Struct muncher for making SDNA + * + * Originally by Ton, some mods by Frank, and some cleaning and + * extension by Nzc. + * + * Makesdna creates a .c file with a long string of numbers that + * encode the Blender file format. It is fast, because it is basically + * a binary dump. There are some details to mind when reconstructing + * the file (endianness and byte-alignment). + * + * This little program scans all structs that need to be serialized, + * and determined the names and types of all members. It calculates + * how much memory (on disk or in ram) is needed to store that struct, + * and the offsets for reaching a particular one. + * + * There is a facility to get verbose output from sdna. Search for + * debugSDNA. This int can be set to 0 (no output) to some int. Higher + * numbers give more output. + * */ + + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) && !defined(FREE_WINDOWS) + +/* The __intXX are built-in types of the visual complier! So we don't + * need to include anything else here. */ + +typedef signed __int8 int8_t; +typedef signed __int16 int16_t; +typedef signed __int32 int32_t; +typedef signed __int64 int64_t; + +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; + +#ifndef _INTPTR_T_DEFINED +#ifdef _WIN64 +typedef __int64 intptr_t; +#else +typedef long intptr_t; +#endif +#define _INTPTR_T_DEFINED +#endif + +#ifndef _UINTPTR_T_DEFINED +#ifdef _WIN64 +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned long uintptr_t; +#endif +#define _UINTPTR_T_DEFINED +#endif + +#elif defined(__linux__) || defined(__NetBSD__) + + /* Linux-i386, Linux-Alpha, Linux-ppc */ +#include + +#elif defined (__APPLE__) + +#include + +#elif defined(FREE_WINDOWS) + +#include + +#else + + /* FreeBSD, Irix, Solaris */ +#include + +#endif /* ifdef platform for types */ + +#ifdef __cplusplus +} +#endif + + +#include +#include +#include + +//#include "DNA_sdna_types.h" +// include files for automatic dependancies +#include "DNA_rigidbody.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btMatrix3x3.h" +#include "LinearMath/btTransform.h" +#include "BulletCollision/BroadphaseCollision/btQuantizedBvh.h" +#include "BulletCollision/CollisionShapes/btCollisionShape.h" +#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" +#include "BulletCollision/CollisionShapes/btConvexInternalShape.h" +#include "BulletCollision/CollisionShapes/btMultiSphereShape.h" +#include "BulletCollision/CollisionShapes/btConvexHullShape.h" +#include "BulletCollision/CollisionShapes/btStridingMeshInterface.h" +#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" +#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h" +#include "BulletCollision/CollisionShapes/btCompoundShape.h" +#include "BulletCollision/CollisionShapes/btCylinderShape.h" +#include "BulletCollision/CollisionShapes/btConeShape.h" +#include "BulletCollision/CollisionShapes/btCapsuleShape.h" +#include "BulletCollision/CollisionShapes/btTriangleInfoMap.h" +#include "BulletCollision/Gimpact/btGImpactShape.h" +#include "BulletCollision/CollisionDispatch/btCollisionObject.h" +#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h" +#include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h" +#include "BulletDynamics/ConstraintSolver/btHingeConstraint.h" +#include "BulletDynamics/ConstraintSolver/btConeTwistConstraint.h" +#include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h" +#include "BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h" +#include "BulletDynamics/ConstraintSolver/btSliderConstraint.h" +#include "BulletDynamics/ConstraintSolver/btGearConstraint.h" +#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h" +#include "BulletDynamics/Dynamics/btDynamicsWorld.h" + +#include "BulletDynamics/Dynamics/btRigidBody.h" +#include "BulletSoftBody/btSoftBodyData.h" + +#ifdef HAVE_CONFIG_H +#include +#endif + +#define SDNA_MAX_FILENAME_LENGTH 255 + +/* Included the path relative from /source/blender/ here, so we can move */ +/* headers around with more freedom. */ +char *includefiles[] = { + + // if you add files here, please add them at the end + // of makesdna.c (this file) as well + "../makesdna/DNA_rigidbody.h", + "../../../src/LinearMath/btVector3.h", + "../../../src/LinearMath/btMatrix3x3.h", + "../../../src/LinearMath/btTransform.h", + "../../../src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h", + "../../../src/BulletCollision/CollisionShapes/btCollisionShape.h", + "../../../src/BulletCollision/CollisionShapes/btStaticPlaneShape.h", + "../../../src/BulletCollision/CollisionShapes/btConvexInternalShape.h", + "../../../src/BulletCollision/CollisionShapes/btMultiSphereShape.h", + "../../../src/BulletCollision/CollisionShapes/btStridingMeshInterface.h", + "../../../src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h", + "../../../src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h", + "../../../src/BulletCollision/CollisionShapes/btCompoundShape.h", + "../../../src/BulletCollision/CollisionShapes/btCylinderShape.h", + "../../../src/BulletCollision/CollisionShapes/btConeShape.h", + "../../../src/BulletCollision/CollisionShapes/btCapsuleShape.h", + "../../../src/BulletCollision/CollisionShapes/btTriangleInfoMap.h", + "../../../src/BulletCollision/Gimpact/btGImpactShape.h", + "../../../src/BulletCollision/CollisionShapes/btConvexHullShape.h", + "../../../src/BulletCollision/CollisionDispatch/btCollisionObject.h", + "../../../src/BulletDynamics/Dynamics/btDynamicsWorld.h", + "../../../src/BulletDynamics/Dynamics/btRigidBody.h", + "../../../src/BulletDynamics/ConstraintSolver/btTypedConstraint.h", + "../../../src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h", + "../../../src/BulletDynamics/ConstraintSolver/btHingeConstraint.h", + "../../../src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h", + "../../../src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h", + "../../../src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h", + "../../../src/BulletDynamics/ConstraintSolver/btSliderConstraint.h", + "../../../src/BulletDynamics/ConstraintSolver/btGearConstraint.h", + "../../../src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h", + "../../../src/BulletSoftBody/btSoftBodyData.h", + // empty string to indicate end of includefiles + "" +}; + +void* malloc_and_setzero(int numbytes) +{ + char* buf = (char*)malloc(numbytes); + memset(buf,0,numbytes); + return buf; +} + +int maxdata= 500000, maxnr= 50000; +int nr_names=0; +int nr_types=0; +int nr_structs=0; +char **names, *namedata; /* at adress names[a] is string a */ +char **types, *typedata; /* at adress types[a] is string a */ +short *typelens; /* at typelens[a] is de length of type a */ +short *alphalens; /* contains sizes as they are calculated on the DEC Alpha (64 bits) */ +short **structs, *structdata; /* at sp= structs[a] is the first adress of a struct definition + sp[0] is type number + sp[1] is amount of elements + sp[2] sp[3] is typenr, namenr (etc) */ +/* + * debugSDNA: + * - 0 = no output, except errors + * - 1 = detail actions + * - 2 = full trace, tell which names and types were found + * - 4 = full trace, plus all gritty details + */ +int debugSDNA = 0; +int additional_slen_offset; + +/* ************************************************************************** */ +/* Functions */ +/* ************************************************************************** */ + +/** + * Add type to struct indexed by , if it was not yet found. + */ +int add_type(char *str, int len); + +/** + * Add variable to + */ +int add_name(char *str); + +/** + * Search whether this structure type was already found, and if not, + * add it. + */ +short *add_struct(int namecode); + +/** + * Remove comments from this buffer. Assumes that the buffer refers to + * ascii-code text. + */ +int preprocess_include(char *maindata, int len); + +/** + * Scan this file for serializable types. + */ +int convert_include(char *filename); + +/** + * Determine how many bytes are needed for an array. + */ +int arraysize(char *astr, int len); + +/** + * Determine how many bytes are needed for each struct. + */ +static int calculate_structlens(int); + +/** + * Construct the DNA.c file + */ +void dna_write(FILE *file, void *pntr, int size); + +/** + * Report all structures found so far, and print their lenghts. + */ +void printStructLenghts(void); + + + +/* ************************************************************************** */ +/* Implementation */ +/* ************************************************************************** */ + +/* ************************* MAKEN DNA ********************** */ + +int add_type(char *str, int len) +{ + int nr; + char *cp; + + if(str[0]==0) return -1; + + /* search through type array */ + for(nr=0; nr=maxnr) { + printf("too many types\n"); + return nr_types-1;; + } + nr_types++; + + return nr_types-1; +} + +/** + * + * Because of the weird way of tokenizing, we have to 'cast' function + * pointers to ... (*f)(), whatever the original signature. In fact, + * we add name and type at the same time... There are two special + * cases, unfortunately. These are explicitly checked. + * + * */ +int add_name(char *str) +{ + int nr, i, j, k; + char *cp; + char buf[255]; /* stupid limit, change it :) */ + char *name; + + additional_slen_offset = 0; + + if((str[0]==0) /* || (str[1]==0) */) return -1; + + if (str[0] == '(' && str[1] == '*') { + if (debugSDNA > 3) printf("\t\t\t\t*** Function pointer found\n"); + /* functionpointer: transform the type (sometimes) */ + i = 0; + j = 0; + + while (str[i] != ')') { + buf[i] = str[i]; + i++; + } + + /* Another number we need is the extra slen offset. This extra + * offset is the overshoot after a space. If there is no + * space, no overshoot should be calculated. */ + j = i; /* j at first closing brace */ + + if (debugSDNA > 3) printf("first brace after offset %d\n", i); + + j++; /* j beyond closing brace ? */ + while ((str[j] != 0) && (str[j] != ')' )) { + if (debugSDNA > 3) printf("seen %c ( %d) \n", str[j], str[j]); + j++; + } + if (debugSDNA > 3) printf("seen %c ( %d) \n", str[j], str[j]); + if (debugSDNA > 3) printf("special after offset %d\n", j); + + if (str[j] == 0 ) { + if (debugSDNA > 3) printf("offsetting for space\n"); + /* get additional offset */ + k = 0; + while (str[j] != ')') { + j++; + k++; + } + if (debugSDNA > 3) printf("extra offset %d\n", k); + additional_slen_offset = k; + } else if (str[j] == ')' ) { + if (debugSDNA > 3) printf("offsetting for brace\n"); + ; /* don't get extra offset */ + } else { + printf("Error during tokening function pointer argument list\n"); + } + + /* + * Put )(void) at the end? Maybe )(). Should check this with + * old sdna. Actually, sometimes )(), sometimes )(void...) + * Alas.. such is the nature of braindamage :( + * + * Sorted it out: always do )(), except for headdraw and + * windraw, part of ScrArea. This is important, because some + * linkers will treat different fp's differently when called + * !!! This has to do with interference in byte-alignment and + * the way args are pushed on the stack. + * + * */ + buf[i] = 0; + if (debugSDNA > 3) printf("Name before chomping: %s\n", buf); + if ( (strncmp(buf,"(*headdraw", 10) == 0) + || (strncmp(buf,"(*windraw", 9) == 0) ) { + buf[i] = ')'; + buf[i+1] = '('; + buf[i+2] = 'v'; + buf[i+3] = 'o'; + buf[i+4] = 'i'; + buf[i+5] = 'd'; + buf[i+6] = ')'; + buf[i+7] = 0; + } else { + buf[i] = ')'; + buf[i+1] = '('; + buf[i+2] = ')'; + buf[i+3] = 0; + } + /* now precede with buf*/ + if (debugSDNA > 3) printf("\t\t\t\t\tProposing fp name %s\n", buf); + name = buf; + } else { + /* normal field: old code */ + name = str; + } + + /* search name array */ + for(nr=0; nr=maxnr) { + printf("too many names\n"); + return nr_names-1; + } + nr_names++; + + return nr_names-1; +} + +short *add_struct(int namecode) +{ + int len; + short *sp; + + if(nr_structs==0) { + structs[0]= structdata; + } + else { + sp= structs[nr_structs-1]; + len= sp[1]; + structs[nr_structs]= sp+ 2*len+2; + } + + sp= structs[nr_structs]; + sp[0]= namecode; + + if(nr_structs>=maxnr) { + printf("too many structs\n"); + return sp; + } + nr_structs++; + + return sp; +} + +int preprocess_include(char *maindata, int len) +{ + int a, newlen, comment = 0; + char *cp, *temp, *md; + + temp= (char*) malloc_and_setzero(len); + memcpy(temp, maindata, len); + + // remove all c++ comments + /* replace all enters/tabs/etc with spaces */ + cp= temp; + a= len; + comment = 0; + while(a--) { + if(cp[0]=='/' && cp[1]=='/') { + comment = 1; + } else if (*cp<32) { + comment = 0; + } + if (comment || *cp<32 || *cp>128 ) *cp= 32; + cp++; + } + + + /* data from temp copy to maindata, remove comments and double spaces */ + cp= temp; + md= maindata; + newlen= 0; + comment= 0; + a= len; + while(a--) { + + if(cp[0]=='/' && cp[1]=='*') { + comment= 1; + cp[0]=cp[1]= 32; + } + if(cp[0]=='*' && cp[1]=='/') { + comment= 0; + cp[0]=cp[1]= 32; + } + + /* do not copy when: */ + if(comment); + else if( cp[0]==' ' && cp[1]==' ' ); + else if( cp[-1]=='*' && cp[0]==' ' ); /* pointers with a space */ + else { + md[0]= cp[0]; + md++; + newlen++; + } + cp++; + } + + free(temp); + return newlen; +} + +static void *read_file_data(char *filename, int *len_r) +{ +#ifdef WIN32 + FILE *fp= fopen(filename, "rb"); +#else + FILE *fp= fopen(filename, "r"); +#endif + void *data; + + if (!fp) { + *len_r= -1; + return NULL; + } + + fseek(fp, 0L, SEEK_END); + *len_r= ftell(fp); + fseek(fp, 0L, SEEK_SET); + + data= malloc_and_setzero(*len_r); + if (!data) { + *len_r= -1; + fclose(fp); + return NULL; + } + + if (fread(data, *len_r, 1, fp)!=1) { + *len_r= -1; + free(data); + fclose(fp); + return NULL; + } + + fclose(fp); + return data; +} + + +const char* skipStructTypes[]= +{ + "btContactSolverInfoData", + "btRigidBodyConstructionInfo", + "Euler", + "btConstraintInfo2", + "btConstraintSetting", + "btTriangleInfo", + "" +}; + +int skipStruct(const char* structType) +{ + int i=0; + while (strlen(skipStructTypes[i])) + { + if (strcmp(structType,skipStructTypes[i])==0) + { + return 1; + } + i++; + } + return 0; +} + +int convert_include(char *filename) +{ + /* read include file, skip structs with a '#' before it. + store all data in temporal arrays. + */ + int filelen, count, overslaan, slen, type, name, strct; + short *structpoin, *sp; + char *maindata, *mainend, *md, *md1; + + md= maindata= (char*)read_file_data(filename, &filelen); + if (filelen==-1) { + printf("Can't read file %s\n", filename); + return 1; + } + + filelen= preprocess_include(maindata, filelen); + mainend= maindata+filelen-1; + + /* we look for '{' and then back to 'struct' */ + count= 0; + overslaan= 0; + while(count 1) printf("\t|\t|-- detected struct %s\n", types[strct]); + + /* first lets make it all nice strings */ + md1= md+1; + while(*md1 != '}') { + if(md1>mainend) break; + + if(*md1==',' || *md1==' ') *md1= 0; + md1++; + } + + /* read types and names until first character that is not '}' */ + md1= md+1; + while( *md1 != '}' ) { + if(md1>mainend) break; + + /* skip when it says 'struct' or 'unsigned' or 'const' */ + if(*md1) { + if( strncmp(md1, "struct", 6)==0 ) md1+= 7; + if( strncmp(md1, "unsigned", 8)==0 ) md1+= 9; + if( strncmp(md1, "const", 5)==0 ) md1+= 6; + + /* we've got a type! */ + type= add_type(md1, 0); + + if (debugSDNA > 1) printf("\t|\t|\tfound type %s (", md1); + + md1+= strlen(md1); + + + /* read until ';' */ + while( *md1 != ';' ) { + if(md1>mainend) break; + + if(*md1) { + /* We've got a name. slen needs + * correction for function + * pointers! */ + slen= (int) strlen(md1); + if( md1[slen-1]==';' ) { + md1[slen-1]= 0; + + + name= add_name(md1); + slen += additional_slen_offset; + sp[0]= type; + sp[1]= name; + + if ((debugSDNA>1) && (names[name] != 0 )) printf("%s |", names[name]); + + structpoin[1]++; + sp+= 2; + + md1+= slen; + break; + } + + + name= add_name(md1); + slen += additional_slen_offset; + + sp[0]= type; + sp[1]= name; + if ((debugSDNA > 1) && (names[name] != 0 )) printf("%s ||", names[name]); + + structpoin[1]++; + sp+= 2; + + md1+= slen; + } + md1++; + } + + if (debugSDNA > 1) printf(")\n"); + + } + md1++; + } + } + } + } + } + count++; + md++; + } + + free(maindata); + + return 0; +} + +int arraysize(char *astr, int len) +{ + int a, mul=1; + char str[100], *cp=0; + + memcpy(str, astr, len+1); + + for(a=0; a= firststruct) { + if(sizeof(void *)==8 && (len % 8) ) { + printf("Align struct error: %s %s\n", types[structtype],cp); + dna_error = 1; + } + } + + /* 2-4 aligned/ */ + if(typelens[type]>3 && (len % 4) ) { + printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len%4); + dna_error = 1; + } + else if(typelens[type]==2 && (len % 2) ) { + printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len%2); + dna_error = 1; + } + + len += mul*typelens[type]; + alphalen += mul * alphalens[type]; + + } else { + len= 0; + alphalen = 0; + break; + } + } + + if (len==0) { + unknown++; + } else { + typelens[structtype]= len; + alphalens[structtype]= alphalen; + // two ways to detect if a struct contains a pointer: + // has_pointer is set or alphalen != len + if (has_pointer || alphalen != len) { + if (alphalen % 8) { + printf("alphalen = %d len = %d\n",alphalen,len); + printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], alphalen%8); + dna_error = 1; + } + } + + if(len % 4) { + printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len%4); + dna_error = 1; + } + + } + } + } + + if(unknown==lastunknown) break; + } + + if(unknown) { + printf("ERROR: still %d structs unknown\n", unknown); + + if (debugSDNA) { + printf("*** Known structs : \n"); + + for(a=0; a= MAX_DNA_LINE_LENGTH) { + fprintf(file, "\n"); + linelength = 0; + } + } +} + +void printStructLenghts(void) +{ + int a, unknown= nr_structs, lastunknown, structtype; + short *structpoin; + printf("\n\n*** All detected structs:\n"); + + while(unknown) { + lastunknown= unknown; + unknown= 0; + + /* check all structs... */ + for(a=0; a -1) { + fflush(stdout); + printf("Running makesdna at debug level %d\n", debugSDNA); + + } + + /* the longest known struct is 50k, so we assume 100k is sufficent! */ + namedata= (char*)malloc_and_setzero(maxdata); + typedata= (char*)malloc_and_setzero(maxdata); + structdata= (short*)malloc_and_setzero(maxdata); + + /* a maximum of 5000 variables, must be sufficient? */ + names= (char**)malloc_and_setzero(sizeof(char *)*maxnr); + types= (char**)malloc_and_setzero(sizeof(char *)*maxnr); + typelens= (short*) malloc_and_setzero(sizeof(short)*maxnr); + alphalens= (short*)malloc_and_setzero(sizeof(short)*maxnr); + structs= (short**)malloc_and_setzero(sizeof(short)*maxnr); + + /* insertion of all known types */ + /* watch it: uint is not allowed! use in structs an unsigned int */ + add_type("char", 1); /* 0 */ + add_type("uchar", 1); /* 1 */ + add_type("short", 2); /* 2 */ + add_type("ushort", 2); /* 3 */ + add_type("int", 4); /* 4 */ + add_type("long", 4); /* 5 */ /* should it be 8 on 64 bits? */ + add_type("ulong", 4); /* 6 */ + add_type("float", 4); /* 7 */ + add_type("double", 8); /* 8 */ + add_type("void", 0); /* 9 */ + + // the defines above shouldn't be output in the padding file... + firststruct = nr_types; + + /* add all include files defined in the global array */ + /* Since the internal file+path name buffer has limited length, I do a */ + /* little test first... */ + /* Mind the breaking condition here! */ + if (debugSDNA) printf("\tStart of header scan:\n"); + for (i = 0; strlen(includefiles[i]); i++) { + sprintf(str, "%s%s", baseDirectory, includefiles[i]); + if (debugSDNA) printf("\t|-- Converting %s\n", str); + if (convert_include(str)) { + return (1); + } + } + if (debugSDNA) printf("\tFinished scanning %d headers.\n", i); + + if (calculate_structlens(firststruct)) { + // error + return(1); + } + + + /* FOR DEBUG */ + if (debugSDNA > 1) + { + int a,b; +/* short *elem; */ + short num_types; + + printf("nr_names %d nr_types %d nr_structs %d\n", nr_names, nr_types, nr_structs); + for(a=0; a -1) printf("Writing file ... "); + + if(nr_names==0 || nr_structs==0); + else { + strcpy(str, "SDNA"); + dna_write(file, str, 4); + + /* write names */ + strcpy(str, "NAME"); + dna_write(file, str, 4); + len= nr_names; + dna_write(file, &len, 4); + + /* calculate size of datablock with strings */ + cp= names[nr_names-1]; + cp+= strlen(names[nr_names-1]) + 1; /* +1: null-terminator */ + len= (intptr_t) (cp - (char*) names[0]); + len= (len+3) & ~3; + dna_write(file, names[0], len); + + /* write TYPES */ + strcpy(str, "TYPE"); + dna_write(file, str, 4); + len= nr_types; + dna_write(file, &len, 4); + + /* calculate datablock size */ + cp= types[nr_types-1]; + cp+= strlen(types[nr_types-1]) + 1; /* +1: null-terminator */ + len= (intptr_t) (cp - (char*) types[0]); + len= (len+3) & ~3; + + dna_write(file, types[0], len); + + /* WRITE TYPELENGTHS */ + strcpy(str, "TLEN"); + dna_write(file, str, 4); + + len= 2*nr_types; + if(nr_types & 1) len+= 2; + dna_write(file, typelens, len); + + /* WRITE STRUCTS */ + strcpy(str, "STRC"); + dna_write(file, str, 4); + len= nr_structs; + dna_write(file, &len, 4); + + /* calc datablock size */ + sp= structs[nr_structs-1]; + sp+= 2+ 2*( sp[1] ); + len= (intptr_t) ((char*) sp - (char*) structs[0]); + len= (len+3) & ~3; + + dna_write(file, structs[0], len); + + /* a simple dna padding test */ + if (0) { + FILE *fp; + int a; + + fp= fopen("padding.c", "w"); + if(fp==NULL); + else { + + // add all include files defined in the global array + for (i = 0; strlen(includefiles[i]); i++) { + fprintf(fp, "#include \"%s%s\"\n", baseDirectory, includefiles[i]); + } + + fprintf(fp, "main(){\n"); + sp = typelens; + sp += firststruct; + for(a=firststruct; a -1) printf("done.\n"); + + return(0); +} + +/* ************************* END MAKE DNA ********************** */ + +static void make_bad_file(char *file) +{ + FILE *fp= fopen(file, "w"); + fprintf(fp, "ERROR! Cannot make correct DNA.c file, STUPID!\n"); + fclose(fp); +} + +#ifndef BASE_HEADER +#define BASE_HEADER "../" +#endif + +int main(int argc, char ** argv) +{ +// printf("btCollisionObject=%d\n",sizeof(btCollisionObject)); +// printf("btCollisionObjectData=%d\n",sizeof(btCollisionObjectData)); +// printf("btTransform=%d\n",sizeof(btTransform)); +// printf("btTransformData=%d\n",sizeof(btTransformData)); +// +// btCollisionObject* bla = new btCollisionObject(); +// btCollisionObjectData* bla2 = new btCollisionObjectData(); + + //int offsetof(bla,m_hasAnisotropicFriction); +/* + btTransformData m_worldTransform; + btTransform m_interpolationWorldTransform; + btVector3 m_interpolationLinearVelocity; + btVector3 m_interpolationAngularVelocity; + btVector3 m_anisotropicFriction; + bool m_hasAnisotropicFriction; + btScalar m_contactProcessingThreshold; + btBroadphaseProxy *m_broadphaseHandle; + btCollisionShape *m_collisionShape; + btCollisionShape *m_rootCollisionShape; + int m_collisionFlags; + int m_islandTag1; + int m_companionId; + int m_activationState1; + btScalar m_deactivationTime; + btScalar m_friction; + btScalar m_restitution; + void* m_userObjectPointer; + int m_internalType; + btScalar m_hitFraction; + btScalar m_ccdSweptSphereRadius; + btScalar m_ccdMotionThreshold; + bool m_checkCollideWith; + char m_pad[7]; +*/ + + FILE *file; + int return_status = 0; + + if (argc!=2 && argc!=3) { + printf("Usage: %s outfile.c [base directory]\n", argv[0]); + return_status = 1; + } else { + file = fopen(argv[1], "w"); + if (!file) { + printf ("Unable to open file: %s\n", argv[1]); + return_status = 1; + } else { + char baseDirectory[256]; + + if (argc==3) { + strcpy(baseDirectory, argv[2]); + } else { + strcpy(baseDirectory, BASE_HEADER); + } + + if (sizeof(void*)==8) + { + fprintf (file, "char sBulletDNAstr64[]= {\n"); + } else + { + fprintf (file, "char sBulletDNAstr[]= {\n"); + } + + if (make_structDNA(baseDirectory, file)) { + // error + fclose(file); + make_bad_file(argv[1]); + return_status = 1; + } else { + fprintf(file, "};\n"); + if (sizeof(void*)==8) + { + fprintf(file, "int sBulletDNAlen64= sizeof(sBulletDNAstr64);\n"); + } else + { + fprintf(file, "int sBulletDNAlen= sizeof(sBulletDNAstr);\n"); + } + + fclose(file); + } + } + } + + + return(return_status); +} + + +/* end of list */ diff --git a/Extras/premake4.lua b/Extras/premake4.lua new file mode 100644 index 0000000000..a044468dad --- /dev/null +++ b/Extras/premake4.lua @@ -0,0 +1,8 @@ + +include "HACD" +include "ConvexDecomposition" + +include "Serialize/BulletFileLoader" +include "Serialize/BulletWorldImporter" +include "Serialize/BulletXmlWorldImporter" + diff --git a/test/Bullet2/Info.plist b/test/Bullet2/Info.plist new file mode 100644 index 0000000000..4785b60c5f --- /dev/null +++ b/test/Bullet2/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFiles + + CFBundleIdentifier + Apple.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/test/Bullet2/README.txt b/test/Bullet2/README.txt new file mode 100644 index 0000000000..c231a54911 --- /dev/null +++ b/test/Bullet2/README.txt @@ -0,0 +1,28 @@ +1) Add a .cpp and .h file for your test function. The function should conform to: + + #ifdef __cplusplus + extern "C" { + #endif + + #include "Utils.h" + #include "main.h" + #include "vector.h" + + // Your test function + int MyTestFunc(void); + + #ifdef __cplusplus + } + #endif + + The rest of the program doesn't care or know what you do in MyTestFunc, except that MyTestFunc should return non-zero in case of failure in MyTestFunc. There are some handy functions in Utils.h that you might want to use. Please use vlog instead of printf to print stuff, and random_number32/64() in place of rand(), so I can multithread later if it comes to that. There are some read-only globals that you may wish to respond to, declared in Utils.h: + + gReportAverageTimes if you do timing, report times as averages instead of best times if non-zero + gExitOnError if non-zero, return non-zero immediately if you encounter an error + gAppName (const char*) the name of the application + + As a convenience, vector.h has some cross platform vector types declared and will correctly include various vector headers according to compiler flag. + + +2) Add an entry to gTestList in TestList.cpp for your test function, so the rest of the app knows to call it + diff --git a/test/Bullet2/Source/TestList.cpp b/test/Bullet2/Source/TestList.cpp new file mode 100644 index 0000000000..7e342b1bf5 --- /dev/null +++ b/test/Bullet2/Source/TestList.cpp @@ -0,0 +1,97 @@ +// +// TestList.c +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#include +#include "TestList.h" + +#include "Test_qtmul.h" +#include "Test_qtmulQV3.h" +#include "Test_qtmulV3Q.h" +#include "Test_qtdot.h" +#include "Test_qtnorm.h" + +#include "Test_v3dot.h" +#include "Test_v3sdiv.h" +#include "Test_v3norm.h" +#include "Test_v3cross.h" +#include "Test_v3triple.h" +#include "Test_v3interp.h" +#include "Test_v3lerp.h" +#include "Test_v3skew.h" +#include "Test_v3div.h" +#include "Test_v3rotate.h" + +#include "Test_maxdot.h" +#include "Test_mindot.h" +#include "Test_dot3.h" +#include "Test_3x3transpose.h" +#include "Test_3x3transposeTimes.h" +#include "Test_3x3timesTranspose.h" +#include "Test_3x3mulM.h" +#include "Test_3x3mulM1M2.h" +#include "Test_3x3mulMV.h" +#include "Test_3x3mulVM.h" +#include "Test_3x3setRot.h" +#include "Test_3x3getRot.h" + +#include "Test_btDbvt.h" +#include "Test_quat_aos_neon.h" + +#include "LinearMath/btScalar.h" +#define ENTRY( _name, _func ) { _name, _func } + +// +// Test functions have the form int (*TestFunc)( void ) +// They return a non-zero result in case of failure. +// +// Please see handy stuff in Utils.h, vector.h when writing your test code. +// +#if defined (BT_USE_NEON) || defined (BT_USE_SSE_IN_API) + +TestDesc gTestList[] = +{ + ENTRY( "maxdot", Test_maxdot ), + ENTRY( "mindot", Test_mindot ), + + ENTRY( "qtmul", Test_qtmul ), + ENTRY( "qtmulQV3", Test_qtmulQV3 ), + ENTRY( "qtmulV3Q", Test_qtmulV3Q ), + ENTRY( "qtdot", Test_qtdot ), + ENTRY( "qtnorm", Test_qtnorm ), + + ENTRY( "v3dot", Test_v3dot ), + ENTRY( "v3sdiv", Test_v3sdiv ), + ENTRY( "v3norm", Test_v3norm ), + ENTRY( "v3cross", Test_v3cross ), + ENTRY( "v3triple", Test_v3triple ), + ENTRY( "v3interp", Test_v3interp ), + ENTRY( "v3lerp", Test_v3lerp ), + ENTRY( "v3skew", Test_v3skew ), + ENTRY( "v3div", Test_v3div ), + ENTRY( "v3rotate", Test_v3rotate ), + + ENTRY( "dot3", Test_dot3 ), + ENTRY( "3x3transpose", Test_3x3transpose ), + ENTRY( "3x3transposeTimes", Test_3x3transposeTimes ), + ENTRY( "3x3timesTranspose", Test_3x3timesTranspose ), + ENTRY( "3x3mulM", Test_3x3mulM ), + ENTRY( "3x3mulM1M2", Test_3x3mulM1M2 ), + ENTRY( "3x3mulMV", Test_3x3mulMV ), + ENTRY( "3x3mulVM", Test_3x3mulMV ), + ENTRY( "3x3setRot", Test_3x3setRot ), + ENTRY( "3x3getRot", Test_3x3getRot ), + + ENTRY( "btDbvt", Test_btDbvt ), + ENTRY("quat_aos_neon", Test_quat_aos_neon), + + { NULL, NULL } +}; +#else +TestDesc gTestList[]={{NULL,NULL}}; + +#endif + diff --git a/test/Bullet2/Source/TestList.h b/test/Bullet2/Source/TestList.h new file mode 100644 index 0000000000..f66d4c67c4 --- /dev/null +++ b/test/Bullet2/Source/TestList.h @@ -0,0 +1,28 @@ +// +// TestList.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_TestList_h +#define BulletTest_TestList_h + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct TestDesc +{ + const char *name; + int (*test_func)(void); // return 0 for success, non-zero for failure +}TestDesc; + +extern TestDesc gTestList[]; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/Bullet2/Source/Tests/Test_3x3getRot.cpp b/test/Bullet2/Source/Tests/Test_3x3getRot.cpp new file mode 100644 index 0000000000..dbf2241e73 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3getRot.cpp @@ -0,0 +1,158 @@ +// +// Test_3x3getRot.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_3x3getRot.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define LOOPCOUNT 1000 +#define ARRAY_SIZE 128 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF_m1p1, RANDF_m1p1, RANDF_m1p1, BT_NAN ); // w channel NaN +} + +static inline btSimdFloat4 qtNAN_f4(void) +{ + return btAssign128( BT_NAN, BT_NAN, BT_NAN, BT_NAN ); +} + +static void M3x3getRot_ref( const btMatrix3x3 &m, btQuaternion &q ) +{ + btVector3 m_el[3] = { m[0], m[1], m[2] }; + + btScalar trace = m_el[0].x() + m_el[1].y() + m_el[2].z(); + + btScalar temp[4]; + + if (trace > btScalar(0.0)) + { + btScalar s = btSqrt(trace + btScalar(1.0)); + temp[3]=(s * btScalar(0.5)); + s = btScalar(0.5) / s; + + temp[0]=((m_el[2].y() - m_el[1].z()) * s); + temp[1]=((m_el[0].z() - m_el[2].x()) * s); + temp[2]=((m_el[1].x() - m_el[0].y()) * s); + } + else + { + int i = m_el[0].x() < m_el[1].y() ? + (m_el[1].y() < m_el[2].z() ? 2 : 1) : + (m_el[0].x() < m_el[2].z() ? 2 : 0); + int j = (i + 1) % 3; + int k = (i + 2) % 3; + + btScalar s = btSqrt(m_el[i][i] - m_el[j][j] - m_el[k][k] + btScalar(1.0)); + temp[i] = s * btScalar(0.5); + s = btScalar(0.5) / s; + + temp[3] = (m_el[k][j] - m_el[j][k]) * s; + temp[j] = (m_el[j][i] + m_el[i][j]) * s; + temp[k] = (m_el[k][i] + m_el[i][k]) * s; + } + q.setValue(temp[0],temp[1],temp[2],temp[3]); +} + +static int operator!= ( const btQuaternion &a, const btQuaternion &b ) +{ + if( fabs(a.x() - b.x()) + + fabs(a.y() - b.y()) + + fabs(a.z() - b.z()) + + fabs(a.w() - b.w()) > FLT_EPSILON * 4) + return 1; + + return 0; +} + +int Test_3x3getRot(void) +{ + // Init an array flanked by guard pages + btMatrix3x3 in1[ARRAY_SIZE]; + btQuaternion out[ARRAY_SIZE]; + btQuaternion out2[ARRAY_SIZE]; + + // Init the data + size_t i, j; + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + out[i] = btQuaternion(qtNAN_f4()); + out2[i] = btQuaternion(qtNAN_f4()); + + M3x3getRot_ref(in1[i], out[i]); + in1[i].getRotation(out2[i]); + + if( out[i] != out2[i] ) + { + vlog( "Error - M3x3getRot result error! "); + vlog( "failure @ %ld\n", i); + vlog( "\ncorrect = (%10.7f, %10.7f, %10.7f, %10.7f) " + "\ntested = (%10.7f, %10.7f, %10.7f, %10.7f) \n", + out[i].x(), out[i].y(), out[i].z(), out[i].w(), + out2[i].x(), out2[i].y(), out2[i].z(), out2[i].w()); + + return -1; + } + } + + uint64_t scalarTime, vectorTime; + uint64_t startTime, bestTime, currentTime; + bestTime = ~(bestTime&0);//-1ULL; + scalarTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + M3x3getRot_ref(in1[i], out[i]); + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= LOOPCOUNT; + + bestTime = ~(bestTime&0);//-1ULL; + vectorTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in1[i].getRotation(out2[i]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= LOOPCOUNT; + + vlog( "Timing:\n" ); + vlog( "\t scalar\t vector\n" ); + vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE ); + + return 0; +} + +#endif//BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_3x3getRot.h b/test/Bullet2/Source/Tests/Test_3x3getRot.h new file mode 100644 index 0000000000..1998763bb1 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3getRot.h @@ -0,0 +1,22 @@ +// +// Test_3x3getRot.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_3x3getRot_h +#define BulletTest_Test_3x3getRot_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_3x3getRot(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_3x3mulM.cpp b/test/Bullet2/Source/Tests/Test_3x3mulM.cpp new file mode 100644 index 0000000000..51a013e1f8 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3mulM.cpp @@ -0,0 +1,169 @@ +// +// Test_3x3mulM.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_3x3mulM.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define LOOPCOUNT 1000 +#define ARRAY_SIZE 128 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF_01, RANDF_01, RANDF_01, BT_NAN ); // w channel NaN +} + +static btMatrix3x3 M3x3mulM_ref( btMatrix3x3 &in, const btMatrix3x3 &m ) +{ + btVector3 m_el[3] = { in[0], in[1], in[2] }; + + in.setValue( + m.tdotx(m_el[0]), m.tdoty(m_el[0]), m.tdotz(m_el[0]), + m.tdotx(m_el[1]), m.tdoty(m_el[1]), m.tdotz(m_el[1]), + m.tdotx(m_el[2]), m.tdoty(m_el[2]), m.tdotz(m_el[2])); + + return in; +} + +static SIMD_FORCE_INLINE bool fuzzyEqualSlow(const btVector3& ref, const btVector3& other) +{ + const btScalar epsilon = SIMD_EPSILON; + return ((btFabs(ref.m_floats[3]-other.m_floats[3])<=epsilon) && + (btFabs(ref.m_floats[2]-other.m_floats[2])<=epsilon) && + (btFabs(ref.m_floats[1]-other.m_floats[1])<=epsilon) && + (btFabs(ref.m_floats[0]-other.m_floats[0])<=epsilon)); +} + + +static int operator!= ( const btMatrix3x3 &a, const btMatrix3x3 &b ) +{ + if( a.getRow(0) != b.getRow(0) ) + { + if (!fuzzyEqualSlow(a.getRow(0),b.getRow(0))) + { + return 1; + } + } + if( a.getRow(1) != b.getRow(1) ) + { + if( !fuzzyEqualSlow(a.getRow(1),b.getRow(1)) ) + return 1; + } + if( a.getRow(2) != b.getRow(2) ) + { + if( !fuzzyEqualSlow(a.getRow(2),b.getRow(2)) ) + { + return 1; + } + } + return 0; +} + +int Test_3x3mulM(void) +{ + // Init an array flanked by guard pages + btMatrix3x3 in1[ARRAY_SIZE]; + btMatrix3x3 in2[ARRAY_SIZE]; + btMatrix3x3 in3[ARRAY_SIZE]; + btMatrix3x3 out[ARRAY_SIZE]; + btMatrix3x3 out2[ARRAY_SIZE]; + + // Init the data + size_t i, j; + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + in2[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + in3[i] = in1[i]; + + out[i] = M3x3mulM_ref(in1[i], in2[i]); + out2[i] = (in3[i] *= in2[i]); + + if( out[i] != out2[i] ) + { + vlog( "Error - M3x3mulM result error! "); + vlog( "failure @ %ld\n", i); + btVector3 m0, m1, m2; + m0 = out[i].getRow(0); + m1 = out[i].getRow(1); + m2 = out[i].getRow(2); + + vlog( "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) \n", + m0.m_floats[0], m0.m_floats[1], m0.m_floats[2], m0.m_floats[3], + m1.m_floats[0], m1.m_floats[1], m1.m_floats[2], m1.m_floats[3], + m2.m_floats[0], m2.m_floats[1], m2.m_floats[2], m2.m_floats[3]); + + m0 = out2[i].getRow(0); + m1 = out2[i].getRow(1); + m2 = out2[i].getRow(2); + + vlog( "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) \n", + m0.m_floats[0], m0.m_floats[1], m0.m_floats[2], m0.m_floats[3], + m1.m_floats[0], m1.m_floats[1], m1.m_floats[2], m1.m_floats[3], + m2.m_floats[0], m2.m_floats[1], m2.m_floats[2], m2.m_floats[3]); + + return -1; + } + } + + uint64_t scalarTime, vectorTime; + uint64_t startTime, bestTime, currentTime; + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = M3x3mulM_ref(in1[i], in2[i]); + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= LOOPCOUNT; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out2[i] = (in3[i] *= in2[i]); + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= LOOPCOUNT; + + vlog( "Timing:\n" ); + vlog( "\t scalar\t vector\n" ); + vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE ); + + return 0; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_3x3mulM.h b/test/Bullet2/Source/Tests/Test_3x3mulM.h new file mode 100644 index 0000000000..fb5128e660 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3mulM.h @@ -0,0 +1,22 @@ +// +// Test_3x3mulM.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_3x3mulM_h +#define BulletTest_Test_3x3mulM_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_3x3mulM(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_3x3mulM1M2.cpp b/test/Bullet2/Source/Tests/Test_3x3mulM1M2.cpp new file mode 100644 index 0000000000..c435c546ce --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3mulM1M2.cpp @@ -0,0 +1,164 @@ +// +// Test_3x3mulM1M2.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_3x3mulM1M2.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define LOOPCOUNT 1000 +#define ARRAY_SIZE 128 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF_01, RANDF_01, RANDF_01, BT_NAN ); // w channel NaN +} + +static btMatrix3x3 M3x3mulM1M2_ref( const btMatrix3x3 &m1, const btMatrix3x3 &m2 ) +{ + return btMatrix3x3( + m2.tdotx(m1[0]), m2.tdoty(m1[0]), m2.tdotz(m1[0]), + m2.tdotx(m1[1]), m2.tdoty(m1[1]), m2.tdotz(m1[1]), + m2.tdotx(m1[2]), m2.tdoty(m1[2]), m2.tdotz(m1[2])); +} + +static bool fuzzyEqualSlow(const btVector3& ref, const btVector3& other) +{ + const btScalar epsilon = SIMD_EPSILON; + return ((btFabs(ref.m_floats[3]-other.m_floats[3])<=epsilon) && + (btFabs(ref.m_floats[2]-other.m_floats[2])<=epsilon) && + (btFabs(ref.m_floats[1]-other.m_floats[1])<=epsilon) && + (btFabs(ref.m_floats[0]-other.m_floats[0])<=epsilon)); +} + + +static int operator!= ( const btMatrix3x3 &a, const btMatrix3x3 &b ) +{ + if( a.getRow(0) != b.getRow(0) ) + { + if (!fuzzyEqualSlow(a.getRow(0),b.getRow(0))) + { + return 1; + } + } + if( a.getRow(1) != b.getRow(1) ) + { + if( !fuzzyEqualSlow(a.getRow(1),b.getRow(1)) ) + return 1; + } + if( a.getRow(2) != b.getRow(2) ) + { + if( !fuzzyEqualSlow(a.getRow(2),b.getRow(2)) ) + { + return 1; + } + } + return 0; +} + +int Test_3x3mulM1M2(void) +{ + // Init an array flanked by guard pages + btMatrix3x3 in1[ARRAY_SIZE]; + btMatrix3x3 in2[ARRAY_SIZE]; + btMatrix3x3 out[ARRAY_SIZE]; + btMatrix3x3 out2[ARRAY_SIZE]; + + // Init the data + size_t i, j; + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + in2[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + + out[i] = M3x3mulM1M2_ref(in1[i], in2[i]); + out2[i] = (in1[i] * in2[i]); + + if( out[i] != out2[i] ) + { + vlog( "Error - M3x3mulM1M2 result error! "); + vlog( "failure @ %ld\n", i); + btVector3 m0, m1, m2; + m0 = out[i].getRow(0); + m1 = out[i].getRow(1); + m2 = out[i].getRow(2); + + vlog( "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) \n", + m0.m_floats[0], m0.m_floats[1], m0.m_floats[2], m0.m_floats[3], + m1.m_floats[0], m1.m_floats[1], m1.m_floats[2], m1.m_floats[3], + m2.m_floats[0], m2.m_floats[1], m2.m_floats[2], m2.m_floats[3]); + + m0 = out2[i].getRow(0); + m1 = out2[i].getRow(1); + m2 = out2[i].getRow(2); + + vlog( "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) \n", + m0.m_floats[0], m0.m_floats[1], m0.m_floats[2], m0.m_floats[3], + m1.m_floats[0], m1.m_floats[1], m1.m_floats[2], m1.m_floats[3], + m2.m_floats[0], m2.m_floats[1], m2.m_floats[2], m2.m_floats[3]); + + return -1; + } + } + + uint64_t scalarTime, vectorTime; + uint64_t startTime, bestTime, currentTime; + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = M3x3mulM1M2_ref(in1[i], in2[i]); + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= LOOPCOUNT; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out2[i] = (in1[i] * in2[i]); + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= LOOPCOUNT; + + vlog( "Timing:\n" ); + vlog( "\t scalar\t vector\n" ); + vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE ); + + return 0; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_3x3mulM1M2.h b/test/Bullet2/Source/Tests/Test_3x3mulM1M2.h new file mode 100644 index 0000000000..a3075bd86c --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3mulM1M2.h @@ -0,0 +1,22 @@ +// +// Test_3x3mulM1M2.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_3x3mulM1M2_h +#define BulletTest_Test_3x3mulM1M2_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_3x3mulM1M2(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_3x3mulMV.cpp b/test/Bullet2/Source/Tests/Test_3x3mulMV.cpp new file mode 100644 index 0000000000..ba07831e3d --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3mulMV.cpp @@ -0,0 +1,112 @@ +// +// Test_3x3mulMV.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_3x3mulMV.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define LOOPCOUNT 1000 +#define ARRAY_SIZE 128 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128(RANDF_01, RANDF_01, RANDF_01, BT_NAN ); // w channel NaN +} + +static btVector3 M3x3mulMV_ref( const btMatrix3x3 &m, const btVector3 &v ) +{ + return btVector3(m[0].dot(v), m[1].dot(v), m[2].dot(v)); +} + +int Test_3x3mulMV(void) +{ + // Init an array flanked by guard pages + btMatrix3x3 in1[ARRAY_SIZE]; + btVector3 in2[ARRAY_SIZE]; + btVector3 out[ARRAY_SIZE]; + btVector3 out2[ARRAY_SIZE]; + + // Init the data + size_t i, j; + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + in2[i] = btVector3(rand_f4()); + + out[i] = M3x3mulMV_ref(in1[i], in2[i]); + out2[i] = (in1[i] * in2[i]); + + if( fabsf(out[i].m_floats[0] - out2[i].m_floats[0]) + + fabsf(out[i].m_floats[1] - out2[i].m_floats[1]) + + fabsf(out[i].m_floats[2] - out2[i].m_floats[2]) + + fabsf(out[i].m_floats[3] - out2[i].m_floats[3]) > FLT_EPSILON*4 ) + { + vlog( "Error - M3x3mulMV result error! "); + vlog( "failure @ %ld\n", i); + vlog( "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) \n", + out[i].m_floats[0], out[i].m_floats[1], out[i].m_floats[2], out[i].m_floats[3], + out2[i].m_floats[0], out2[i].m_floats[1], out2[i].m_floats[2], out2[i].m_floats[3]); + + return 1; + } + } + + uint64_t scalarTime, vectorTime; + uint64_t startTime, bestTime, currentTime; + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = M3x3mulMV_ref(in1[i], in2[i]); + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= LOOPCOUNT; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out2[i] = (in1[i] * in2[i]); + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= LOOPCOUNT; + + vlog( "Timing:\n" ); + vlog( "\t scalar\t vector\n" ); + vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE ); + + return 0; +} +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_3x3mulMV.h b/test/Bullet2/Source/Tests/Test_3x3mulMV.h new file mode 100644 index 0000000000..877380d3d9 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3mulMV.h @@ -0,0 +1,23 @@ +// +// Test_3x3mulMV.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_3x3mulMV_h +#define BulletTest_Test_3x3mulMV_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_3x3mulMV(void); + +#ifdef __cplusplus +} +#endif + + +#endif + diff --git a/test/Bullet2/Source/Tests/Test_3x3mulVM.cpp b/test/Bullet2/Source/Tests/Test_3x3mulVM.cpp new file mode 100644 index 0000000000..86db895cae --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3mulVM.cpp @@ -0,0 +1,112 @@ +// +// Test_3x3mulVM.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_3x3mulVM.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define LOOPCOUNT 1000 +#define ARRAY_SIZE 128 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF_01, RANDF_01, RANDF_01, BT_NAN ); // w channel NaN +} + +static btVector3 M3x3mulVM_ref( const btVector3 &v, const btMatrix3x3 &m) +{ + return btVector3(m.tdotx(v), m.tdoty(v), m.tdotz(v)); +} + +int Test_3x3mulVM(void) +{ + // Init an array flanked by guard pages + btVector3 in1[ARRAY_SIZE]; + btMatrix3x3 in2[ARRAY_SIZE]; + btVector3 out[ARRAY_SIZE]; + btVector3 out2[ARRAY_SIZE]; + + // Init the data + size_t i, j; + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in1[i] = btVector3(rand_f4()); + in2[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + + out[i] = M3x3mulVM_ref(in1[i], in2[i]); + out2[i] = (in1[i] * in2[i]); + + if( fabsf(out[i].m_floats[0] - out2[i].m_floats[0]) + + fabsf(out[i].m_floats[1] - out2[i].m_floats[1]) + + fabsf(out[i].m_floats[2] - out2[i].m_floats[2]) + + fabsf(out[i].m_floats[3] - out2[i].m_floats[3]) > FLT_EPSILON*4 ) + { + vlog( "Error - M3x3mulVM result error! "); + vlog( "failure @ %ld\n", i); + vlog( "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) \n", + out[i].m_floats[0], out[i].m_floats[1], out[i].m_floats[2], out[i].m_floats[3], + out2[i].m_floats[0], out2[i].m_floats[1], out2[i].m_floats[2], out2[i].m_floats[3]); + + return 1; + } + } + + uint64_t scalarTime, vectorTime; + uint64_t startTime, bestTime, currentTime; + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = M3x3mulVM_ref(in1[i], in2[i]); + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= LOOPCOUNT; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out2[i] = (in1[i] * in2[i]); + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= LOOPCOUNT; + + vlog( "Timing:\n" ); + vlog( "\t scalar\t vector\n" ); + vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE ); + + return 0; +} +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_3x3mulVM.h b/test/Bullet2/Source/Tests/Test_3x3mulVM.h new file mode 100644 index 0000000000..81c34df897 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3mulVM.h @@ -0,0 +1,22 @@ +// +// Test_3x3mulVM.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_3x3mulVM_h +#define BulletTest_Test_3x3mulVM_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_3x3mulVM(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_3x3setRot.cpp b/test/Bullet2/Source/Tests/Test_3x3setRot.cpp new file mode 100644 index 0000000000..49f177521a --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3setRot.cpp @@ -0,0 +1,171 @@ +// +// Test_3x3setRot.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_3x3setRot.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define LOOPCOUNT 1000 +#define ARRAY_SIZE 128 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF_01, RANDF_01, RANDF_01, BT_NAN ); // w channel NaN +} + +static inline btSimdFloat4 qtrand_f4(void) +{ + return btAssign128( RANDF_01, RANDF_01, RANDF_01, RANDF_01 ); +} + +static btMatrix3x3 M3x3setRot_ref( btMatrix3x3 &m, const btQuaternion &q ) +{ + btScalar d = q.length2(); + btScalar s = btScalar(2.0) / d; + + btScalar xs = q.x() * s, ys = q.y() * s, zs = q.z() * s; + + btScalar wx = q.w() * xs, wy = q.w() * ys, wz = q.w() * zs; + btScalar xx = q.x() * xs, xy = q.x() * ys, xz = q.x() * zs; + btScalar yy = q.y() * ys, yz = q.y() * zs, zz = q.z() * zs; + m.setValue( + btScalar(1.0) - (yy + zz), xy - wz, xz + wy, + xy + wz, btScalar(1.0) - (xx + zz), yz - wx, + xz - wy, yz + wx, btScalar(1.0) - (xx + yy)); + + return m; +} + + +static int operator!= ( const btMatrix3x3 &a, const btMatrix3x3 &b ) +{ + int i; + btVector3 av3, bv3; + + for(i=0; i<3; i++) + { + av3 = a.getRow(i); + bv3 = b.getRow(i); + + if( fabs(av3.m_floats[0] - bv3.m_floats[0]) + + fabs(av3.m_floats[1] - bv3.m_floats[1]) + + fabs(av3.m_floats[2] - bv3.m_floats[2]) > FLT_EPSILON * 4) + return 1; + } + + return 0; +} + +int Test_3x3setRot(void) +{ + // Init an array flanked by guard pages + btMatrix3x3 in1[ARRAY_SIZE]; + btQuaternion in2[ARRAY_SIZE]; + btMatrix3x3 in3[ARRAY_SIZE]; + btMatrix3x3 out[ARRAY_SIZE]; + btMatrix3x3 out2[ARRAY_SIZE]; + + // Init the data + size_t i, j; + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + in2[i] = btQuaternion(qtrand_f4()); + in3[i] = in1[i]; + + out[i] = M3x3setRot_ref(in1[i], in2[i]); + in3[i].setRotation(in2[i]); + out2[i] = in3[i]; + + if( out[i] != out2[i] ) + { + vlog( "Error - M3x3setRot result error! "); + vlog( "failure @ %ld\n", i); + btVector3 m0, m1, m2; + m0 = out[i].getRow(0); + m1 = out[i].getRow(1); + m2 = out[i].getRow(2); + + vlog( "\ncorrect = (%10.7f, %10.7f, %10.7f, %10.7f) " + "\n (%10.7f, %10.7f, %10.7f, %10.7f) " + "\n (%10.7f, %10.7f, %10.7f, %10.7f) \n", + m0.m_floats[0], m0.m_floats[1], m0.m_floats[2], m0.m_floats[3], + m1.m_floats[0], m1.m_floats[1], m1.m_floats[2], m1.m_floats[3], + m2.m_floats[0], m2.m_floats[1], m2.m_floats[2], m2.m_floats[3]); + + m0 = out2[i].getRow(0); + m1 = out2[i].getRow(1); + m2 = out2[i].getRow(2); + + vlog( "\ntested = (%10.7f, %10.7f, %10.7f, %10.7f) " + "\n (%10.7f, %10.7f, %10.7f, %10.7f) " + "\n (%10.7f, %10.7f, %10.7f, %10.7f) \n", + m0.m_floats[0], m0.m_floats[1], m0.m_floats[2], m0.m_floats[3], + m1.m_floats[0], m1.m_floats[1], m1.m_floats[2], m1.m_floats[3], + m2.m_floats[0], m2.m_floats[1], m2.m_floats[2], m2.m_floats[3]); + + return -1; + } + } + + uint64_t scalarTime, vectorTime; + uint64_t startTime, bestTime, currentTime; + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = M3x3setRot_ref(in1[i], in2[i]); + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= LOOPCOUNT; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < LOOPCOUNT; j++) + { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in3[i].setRotation(in2[i]); + out2[i] = in3[i]; + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= LOOPCOUNT; + + vlog( "Timing:\n" ); + vlog( "\t scalar\t vector\n" ); + vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE ); + + return 0; +} +#endif //BT_USE_SSE + diff --git a/test/Bullet2/Source/Tests/Test_3x3setRot.h b/test/Bullet2/Source/Tests/Test_3x3setRot.h new file mode 100644 index 0000000000..aac0ebf9a2 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3setRot.h @@ -0,0 +1,22 @@ +// +// Test_3x3setRot.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_3x3setRot_h +#define BulletTest_Test_3x3setRot_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_3x3setRot(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_3x3timesTranspose.cpp b/test/Bullet2/Source/Tests/Test_3x3timesTranspose.cpp new file mode 100644 index 0000000000..70e12e4ad5 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3timesTranspose.cpp @@ -0,0 +1,117 @@ +// +// Test_3x3timesTranspose.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_3x3timesTranspose.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define LOOPCOUNT 1000 +#define ARRAY_SIZE 128 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF, RANDF, RANDF, BT_NAN ); // w channel NaN +} + +static btMatrix3x3 timesTranspose( const btMatrix3x3 &in, const btMatrix3x3 &m ) +{ + btVector3 m_el[3] = { in[0], in[1], in[2] }; + return btMatrix3x3( + m_el[0].dot(m[0]), m_el[0].dot(m[1]), m_el[0].dot(m[2]), + m_el[1].dot(m[0]), m_el[1].dot(m[1]), m_el[1].dot(m[2]), + m_el[2].dot(m[0]), m_el[2].dot(m[1]), m_el[2].dot(m[2])); +} + +static int operator!= ( const btMatrix3x3 &a, const btMatrix3x3 &b ) +{ + if( a.getRow(0) != b.getRow(0) ) + return 1; + if( a.getRow(1) != b.getRow(1) ) + return 1; + if( a.getRow(2) != b.getRow(2) ) + return 1; + return 0; +} + +int Test_3x3timesTranspose(void) +{ + // Init an array flanked by guard pages + btMatrix3x3 in1[ARRAY_SIZE]; + btMatrix3x3 in2[ARRAY_SIZE]; + btMatrix3x3 out[ARRAY_SIZE]; + btMatrix3x3 out2[ARRAY_SIZE]; + + // Init the data + size_t i, j; + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + in2[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + + out[i] = timesTranspose(in1[i], in2[i]); + out2[i] = in1[i].timesTranspose(in2[i]); + + if( out[i] != out2[i] ) + { + printf( "failure @ %ld\n", i); + return -1; + } + } + + uint64_t scalarTime, vectorTime; + uint64_t startTime, bestTime, currentTime; + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < LOOPCOUNT; j++) { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = timesTranspose(in1[i], in2[i]); + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= LOOPCOUNT; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < LOOPCOUNT; j++) { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = in1[i].timesTranspose(in2[i]); + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= LOOPCOUNT; + + vlog( "Timing:\n" ); + vlog( "\t scalar\t vector\n" ); + vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE ); + + return 0; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_3x3timesTranspose.h b/test/Bullet2/Source/Tests/Test_3x3timesTranspose.h new file mode 100644 index 0000000000..a1c396bd2c --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3timesTranspose.h @@ -0,0 +1,22 @@ +// +// Test_3x3timesTranspose.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_3x3timesTranspose_h +#define BulletTest_Test_3x3timesTranspose_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_3x3timesTranspose(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_3x3transpose.cpp b/test/Bullet2/Source/Tests/Test_3x3transpose.cpp new file mode 100644 index 0000000000..c85333ff24 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3transpose.cpp @@ -0,0 +1,116 @@ +// +// Test_3x3transpose.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_3x3transpose.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define LOOPCOUNT 1000 +#define ARRAY_SIZE 1024 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF, RANDF, RANDF, BT_NAN ); // w channel NaN +} + +static btMatrix3x3 Transpose( btMatrix3x3 &in ) +{ + btVector3 row0 = in.getRow(0); + btVector3 row1 = in.getRow(1); + btVector3 row2 = in.getRow(2); + btVector3 col0 = btAssign128(row0.x(), row1.x(), row2.x(), 0 ); + btVector3 col1 = btAssign128(row0.y(), row1.y(), row2.y(), 0 ); + btVector3 col2 = btAssign128(row0.z(), row1.z(), row2.z(), 0); + return btMatrix3x3( col0, col1, col2); +} + +static int operator!= ( const btMatrix3x3 &a, const btMatrix3x3 &b ) +{ + if( a.getRow(0) != b.getRow(0) ) + return 1; + if( a.getRow(1) != b.getRow(1) ) + return 1; + if( a.getRow(2) != b.getRow(2) ) + return 1; + return 0; +} + +int Test_3x3transpose(void) +{ + // Init an array flanked by guard pages + btMatrix3x3 in[ARRAY_SIZE]; + btMatrix3x3 out[ARRAY_SIZE]; + btMatrix3x3 out2[ARRAY_SIZE]; + + // Init the data + size_t i, j; + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + + out[i] = Transpose(in[i]); + out2[i] = in[i].transpose(); + + if( out[i] != out2[i] ) + { + printf( "failure @ %ld\n", i); + return -1; + } + } + + uint64_t scalarTime, vectorTime; + uint64_t startTime, bestTime, currentTime; + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < LOOPCOUNT; j++) { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = Transpose(in[i]); + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= LOOPCOUNT; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < LOOPCOUNT; j++) { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = in[i].transpose(); + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= LOOPCOUNT; + + vlog( "Timing:\n" ); + vlog( "\t scalar\t vector\n" ); + vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE ); + + return 0; +} +#endif //BT_USE_SSE + diff --git a/test/Bullet2/Source/Tests/Test_3x3transpose.h b/test/Bullet2/Source/Tests/Test_3x3transpose.h new file mode 100644 index 0000000000..3c4b834c2a --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3transpose.h @@ -0,0 +1,22 @@ +// +// Test_3x3transpose.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_3x3transpose_h +#define BulletTest_Test_3x3transpose_h + +#ifdef __cplusplus +extern "C" { +#endif + + int Test_3x3transpose(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_3x3transposeTimes.cpp b/test/Bullet2/Source/Tests/Test_3x3transposeTimes.cpp new file mode 100644 index 0000000000..5f14caf769 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3transposeTimes.cpp @@ -0,0 +1,168 @@ +// +// Test_3x3transposeTimes.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_3x3transposeTimes.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define LOOPCOUNT 1000 +#define ARRAY_SIZE 128 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF_01, RANDF_01, RANDF_01, BT_NAN ); // w channel NaN +} + +static btMatrix3x3 TransposeTimesReference( const btMatrix3x3 &in, const btMatrix3x3 &m ) +{ + btVector3 m_el[3] = { in[0], in[1], in[2] }; + btSimdFloat4 r0 = btAssign128(m_el[0].x() * m[0].x() + m_el[1].x() * m[1].x() + m_el[2].x() * m[2].x(), + m_el[0].x() * m[0].y() + m_el[1].x() * m[1].y() + m_el[2].x() * m[2].y(), + m_el[0].x() * m[0].z() + m_el[1].x() * m[1].z() + m_el[2].x() * m[2].z(), + 0.0f ); + btSimdFloat4 r1 = btAssign128( m_el[0].y() * m[0].x() + m_el[1].y() * m[1].x() + m_el[2].y() * m[2].x(), + m_el[0].y() * m[0].y() + m_el[1].y() * m[1].y() + m_el[2].y() * m[2].y(), + m_el[0].y() * m[0].z() + m_el[1].y() * m[1].z() + m_el[2].y() * m[2].z(), + 0.0f ); + btSimdFloat4 r2 = btAssign128( m_el[0].z() * m[0].x() + m_el[1].z() * m[1].x() + m_el[2].z() * m[2].x(), + m_el[0].z() * m[0].y() + m_el[1].z() * m[1].y() + m_el[2].z() * m[2].y(), + m_el[0].z() * m[0].z() + m_el[1].z() * m[1].z() + m_el[2].z() * m[2].z(), + 0.0f ); + return btMatrix3x3( r0, r1, r2 ); +} + +static int operator!= ( const btMatrix3x3 &a, const btMatrix3x3 &b ) +{ + if( a.getRow(0) != b.getRow(0) ) + return 1; + if( a.getRow(1) != b.getRow(1) ) + return 1; + if( a.getRow(2) != b.getRow(2) ) + return 1; + return 0; +} + +int Test_3x3transposeTimes(void) +{ + // Init an array flanked by guard pages + btMatrix3x3 in1[ARRAY_SIZE]; + btMatrix3x3 in2[ARRAY_SIZE]; + btMatrix3x3 out[ARRAY_SIZE]; + btMatrix3x3 out2[ARRAY_SIZE]; + + float maxRelativeError = 0.f; + // Init the data + size_t i, j; + for( i = 0; i < ARRAY_SIZE; i++ ) + { + in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + in2[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() ); + + out[i] = TransposeTimesReference(in1[i], in2[i]); + out2[i] = in1[i].transposeTimes(in2[i]); + + if( out[i] != out2[i] ) + { + + float relativeError = 0.f; + + for (int column=0;column<3;column++) + for (int row=0;row<3;row++) + relativeError = btMax(relativeError,btFabs(out2[i][row][column] - out[i][row][column]) / out[i][row][column]); + + if (relativeError>1e-6) + { + vlog( "failure @ %ld\n", i); + btVector3 m0, m1, m2; + m0 = out[i].getRow(0); + m1 = out[i].getRow(1); + m2 = out[i].getRow(2); + + vlog( "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) \n", + m0.m_floats[0], m0.m_floats[1], m0.m_floats[2], m0.m_floats[3], + m1.m_floats[0], m1.m_floats[1], m1.m_floats[2], m1.m_floats[3], + m2.m_floats[0], m2.m_floats[1], m2.m_floats[2], m2.m_floats[3]); + + m0 = out2[i].getRow(0); + m1 = out2[i].getRow(1); + m2 = out2[i].getRow(2); + + vlog( "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) " + "\n (%10.4f, %10.4f, %10.4f, %10.4f) \n", + m0.m_floats[0], m0.m_floats[1], m0.m_floats[2], m0.m_floats[3], + m1.m_floats[0], m1.m_floats[1], m1.m_floats[2], m1.m_floats[3], + m2.m_floats[0], m2.m_floats[1], m2.m_floats[2], m2.m_floats[3]); + + return -1; + } else + { + if (relativeError>maxRelativeError) + maxRelativeError = relativeError; + } + } + } + + if (maxRelativeError) + { + printf("Warning: maxRelativeError = %e\n",maxRelativeError); + } + uint64_t scalarTime, vectorTime; + uint64_t startTime, bestTime, currentTime; + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < LOOPCOUNT; j++) { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = TransposeTimesReference(in1[i], in2[i]); + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= LOOPCOUNT; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < LOOPCOUNT; j++) { + startTime = ReadTicks(); + for( i = 0; i < ARRAY_SIZE; i++ ) + out[i] = in1[i].transposeTimes(in2[i]); + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= LOOPCOUNT; + + vlog( "Timing:\n" ); + vlog( "\t scalar\t vector\n" ); + vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE ); + + return 0; +} + +#endif //BT_USE_SSE + diff --git a/test/Bullet2/Source/Tests/Test_3x3transposeTimes.h b/test/Bullet2/Source/Tests/Test_3x3transposeTimes.h new file mode 100644 index 0000000000..08af2e1e00 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_3x3transposeTimes.h @@ -0,0 +1,22 @@ +// +// Test_3x3transposeTimes.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_3x3transposeTimes_h +#define BulletTest_Test_3x3transposeTimes_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_3x3transposeTimes(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_btDbvt.cpp b/test/Bullet2/Source/Tests/Test_btDbvt.cpp new file mode 100644 index 0000000000..96ce525083 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_btDbvt.cpp @@ -0,0 +1,495 @@ +// +// Test_btDbvt.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc., Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_btDbvt.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +SIMD_FORCE_INLINE bool Intersect_ref( btDbvtAabbMm& a, btDbvtAabbMm& b) +{ + return( (a.tMins().x()<=b.tMaxs().x())&& + (a.tMaxs().x()>=b.tMins().x())&& + (a.tMins().y()<=b.tMaxs().y())&& + (a.tMaxs().y()>=b.tMins().y())&& + (a.tMins().z()<=b.tMaxs().z())&& + (a.tMaxs().z()>=b.tMins().z())); + + } + + +SIMD_FORCE_INLINE btScalar Proximity_ref( btDbvtAabbMm& a, + btDbvtAabbMm& b) +{ + const btVector3 d=(a.tMins()+a.tMaxs())-(b.tMins()+b.tMaxs()); + return(btFabs(d.x())+btFabs(d.y())+btFabs(d.z())); +} + + + +SIMD_FORCE_INLINE int Select_ref( btDbvtAabbMm& o, + btDbvtAabbMm& a, + btDbvtAabbMm& b) +{ + return(Proximity_ref(o,a)b.tMaxs().m_floats[i]) + r.tMaxs().m_floats[i]=a.tMaxs().m_floats[i]; + else + r.tMaxs().m_floats[i]=b.tMaxs().m_floats[i]; + } +} +/* +[0] float32_t 0.0318338 +[1] float32_t 0.0309355 +[2] float32_t 0.93264 +[3] float32_t 0.88788 + +[0] float32_t 0.59133 +[1] float32_t 0.478779 +[2] float32_t 0.833354 +[3] float32_t 0.186335 + +[0] float32_t 0.242578 +[1] float32_t 0.0134696 +[2] float32_t 0.383139 +[3] float32_t 0.414653 + +[0] float32_t 0.067769 +[1] float32_t 0.993127 +[2] float32_t 0.484308 +[3] float32_t 0.765338 +*/ + +#define LOOPCOUNT 1000 +#define NUM_CYCLES 10000 +#define DATA_SIZE 1024 + +int Test_btDbvt(void) +{ + btDbvtAabbMm a[DATA_SIZE], b[DATA_SIZE], c[DATA_SIZE]; + btDbvtAabbMm a_ref[DATA_SIZE], b_ref[DATA_SIZE], c_ref[DATA_SIZE]; + + int i; + + bool Intersect_Test_Res[DATA_SIZE], Intersect_Ref_Res[DATA_SIZE]; + int Select_Test_Res[DATA_SIZE], Select_Ref_Res[DATA_SIZE]; + + + for (i = 0; i < DATA_SIZE; i++) + { + a[i].tMins().m_floats[0] = (float)rand() / (float)RAND_MAX; + a[i].tMins().m_floats[1] = (float)rand() / (float)RAND_MAX; + a[i].tMins().m_floats[2] = (float)rand() / (float)RAND_MAX; + a[i].tMins().m_floats[3] = (float)rand() / (float)RAND_MAX; + + a[i].tMaxs().m_floats[0] = (float)rand() / (float)RAND_MAX; + a[i].tMaxs().m_floats[1] = (float)rand() / (float)RAND_MAX; + a[i].tMaxs().m_floats[2] = (float)rand() / (float)RAND_MAX; + a[i].tMaxs().m_floats[3] = (float)rand() / (float)RAND_MAX; + + b[i].tMins().m_floats[0] = (float)rand() / (float)RAND_MAX; + b[i].tMins().m_floats[1] = (float)rand() / (float)RAND_MAX; + b[i].tMins().m_floats[2] = (float)rand() / (float)RAND_MAX; + b[i].tMins().m_floats[3] = (float)rand() / (float)RAND_MAX; + + b[i].tMaxs().m_floats[0] = (float)rand() / (float)RAND_MAX; + b[i].tMaxs().m_floats[1] = (float)rand() / (float)RAND_MAX; + b[i].tMaxs().m_floats[2] = (float)rand() / (float)RAND_MAX; + b[i].tMaxs().m_floats[3] = (float)rand() / (float)RAND_MAX; + + c[i].tMins().m_floats[0] = (float)rand() / (float)RAND_MAX; + c[i].tMins().m_floats[1] = (float)rand() / (float)RAND_MAX; + c[i].tMins().m_floats[2] = (float)rand() / (float)RAND_MAX; + c[i].tMins().m_floats[3] = (float)rand() / (float)RAND_MAX; + + c[i].tMaxs().m_floats[0] = (float)rand() / (float)RAND_MAX; + c[i].tMaxs().m_floats[1] = (float)rand() / (float)RAND_MAX; + c[i].tMaxs().m_floats[2] = (float)rand() / (float)RAND_MAX; + c[i].tMaxs().m_floats[3] = (float)rand() / (float)RAND_MAX; + + + a_ref[i].tMins().m_floats[0] = a[i].tMins().m_floats[0]; + a_ref[i].tMins().m_floats[1] = a[i].tMins().m_floats[1]; + a_ref[i].tMins().m_floats[2] = a[i].tMins().m_floats[2]; + a_ref[i].tMins().m_floats[3] = a[i].tMins().m_floats[3]; + + a_ref[i].tMaxs().m_floats[0] = a[i].tMaxs().m_floats[0]; + a_ref[i].tMaxs().m_floats[1] = a[i].tMaxs().m_floats[1]; + a_ref[i].tMaxs().m_floats[2] = a[i].tMaxs().m_floats[2]; + a_ref[i].tMaxs().m_floats[3] = a[i].tMaxs().m_floats[3]; + + b_ref[i].tMins().m_floats[0] = b[i].tMins().m_floats[0]; + b_ref[i].tMins().m_floats[1] = b[i].tMins().m_floats[1]; + b_ref[i].tMins().m_floats[2] = b[i].tMins().m_floats[2]; + b_ref[i].tMins().m_floats[3] = b[i].tMins().m_floats[3]; + + b_ref[i].tMaxs().m_floats[0] = b[i].tMaxs().m_floats[0]; + b_ref[i].tMaxs().m_floats[1] = b[i].tMaxs().m_floats[1]; + b_ref[i].tMaxs().m_floats[2] = b[i].tMaxs().m_floats[2]; + b_ref[i].tMaxs().m_floats[3] = b[i].tMaxs().m_floats[3]; + + c_ref[i].tMins().m_floats[0] = c[i].tMins().m_floats[0]; + c_ref[i].tMins().m_floats[1] = c[i].tMins().m_floats[1]; + c_ref[i].tMins().m_floats[2] = c[i].tMins().m_floats[2]; + c_ref[i].tMins().m_floats[3] = c[i].tMins().m_floats[3]; + + c_ref[i].tMaxs().m_floats[0] = c[i].tMaxs().m_floats[0]; + c_ref[i].tMaxs().m_floats[1] = c[i].tMaxs().m_floats[1]; + c_ref[i].tMaxs().m_floats[2] = c[i].tMaxs().m_floats[2]; + c_ref[i].tMaxs().m_floats[3] = c[i].tMaxs().m_floats[3]; + + } + + +#if 1 + for (i = 0; i < DATA_SIZE; i++) + { + + Intersect_Test_Res[i] = Intersect(a[i], b[i]); + Intersect_Ref_Res[i] = Intersect_ref(a_ref[i], b_ref[i]); + + if(Intersect_Test_Res[i] != Intersect_Ref_Res[i]) + { + printf("Diff on %d\n", i); + + printf("a_mx_f[0] = %.3f, a_mx_f[1] = %.3f, a_mx_f[2] = %.3f, a_mx_f[3] = %.3f\n", a[i].tMaxs().m_floats[0], a[i].tMaxs().m_floats[1], a[i].tMaxs().m_floats[2], a[i].tMaxs().m_floats[3]); + printf("a_mi_f[0] = %.3f, a_mi_f[1] = %.3f, a_mi_f[2] = %.3f, a_mi_f[3] = %.3f\n", a[i].tMins().m_floats[0], a[i].tMins().m_floats[1], a[i].tMins().m_floats[2], a[i].tMins().m_floats[3]); + printf("b_mx_f[0] = %.3f, b_mx_f[1] = %.3f, b_mx_f[2] = %.3f, b_mx_f[3] = %.3f\n", b[i].tMaxs().m_floats[0], b[i].tMaxs().m_floats[1], b[i].tMaxs().m_floats[2], b[i].tMaxs().m_floats[3]); + printf("b_mi_f[0] = %.3f, b_mi_f[1] = %.3f, b_mi_f[2] = %.3f, b_mi_f[3] = %.3f\n", b[i].tMins().m_floats[0], b[i].tMins().m_floats[1], b[i].tMins().m_floats[2], b[i].tMins().m_floats[3]); + + printf("a_mx_f_ref[0] = %.3f, a_mx_f_ref[1] = %.3f, a_mx_f_ref[2] = %.3f, a_mx_f_ref[3] = %.3f\n", a_ref[i].tMaxs().m_floats[0], a_ref[i].tMaxs().m_floats[1], a_ref[i].tMaxs().m_floats[2], a_ref[i].tMaxs().m_floats[3]); + printf("a_mi_f_ref[0] = %.3f, a_mi_f_ref[1] = %.3f, a_mi_f_ref[2] = %.3f, a_mi_f_ref[3] = %.3f\n", a_ref[i].tMins().m_floats[0], a_ref[i].tMins().m_floats[1], a_ref[i].tMins().m_floats[2], a_ref[i].tMins().m_floats[3]); + printf("b_mx_f_ref[0] = %.3f, b_mx_f_ref[1] = %.3f, b_mx_f_ref[2] = %.3f, b_mx_f_ref[3] = %.3f\n", b_ref[i].tMaxs().m_floats[0], b_ref[i].tMaxs().m_floats[1], b_ref[i].tMaxs().m_floats[2], b_ref[i].tMaxs().m_floats[3]); + printf("b_mi_f_ref[0] = %.3f, b_mi_f_ref[1] = %.3f, b_mi_f_ref[2] = %.3f, b_mi_f_ref[3] = %.3f\n", b_ref[i].tMins().m_floats[0], b_ref[i].tMins().m_floats[1], b_ref[i].tMins().m_floats[2], b_ref[i].tMins().m_floats[3]); + } + } +#endif + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j; + + + //////////////////////////////////// + // + // Time and Test Intersect + // + //////////////////////////////////// + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + + + for (i = 0; i < DATA_SIZE; i++) + { + Intersect_Ref_Res[i] = Intersect_ref(a_ref[i], b_ref[i]); + } + + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + + for (i = 0; i < DATA_SIZE; i++) + { + Intersect_Test_Res[i] = Intersect(a[i], b[i]); + } + + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Intersect Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, TicksToCycles( vectorTime ) / LOOPCOUNT ); + + //printf("scalar = %llu, vector = %llu\n", scalarTime, vectorTime); + + for (i = 0; i < DATA_SIZE; i++) + { + if(Intersect_Test_Res[i] != Intersect_Ref_Res[i]) + { + printf("Intersect fail at %d\n", i); + return 1; + } + } + + //////////////////////////////////// + // + // Time and Test Merge + // + //////////////////////////////////// + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + + + for (i = 0; i < DATA_SIZE; i++) + { + Merge_ref(a_ref[i], b_ref[i], c_ref[i]); + } + + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + + for (i = 0; i < DATA_SIZE; i++) + { + Merge(a[i], b[i], c[i]); + } + + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Merge Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, TicksToCycles( vectorTime ) / LOOPCOUNT ); + + //printf("scalar = %llu, vector = %llu\n", scalarTime, vectorTime); + /* + c [0] float32_t 0.00455523 + [1] float32_t 0.559712 + [2] float32_t 0.0795838 + [3] float32_t 0.10182 + +c_ref + [0] float32_t 0.00455523 + [1] float32_t 0.559712 + [2] float32_t 0.0795838 + [3] float32_t 0.552081 + + +c [0] float32_t 0.829904 + [1] float32_t 0.692891 + [2] float32_t 0.961654 + [3] float32_t 0.666956 + + c_ref + [0] float32_t 0.829904 + [1] float32_t 0.692891 + [2] float32_t 0.961654 + [3] float32_t 0.522878 + */ + for (i = 0; i < DATA_SIZE; i++) + { + //ignore 4th component because it is not computed in all code-paths + if( (fabs(c[i].tMaxs().m_floats[0] - c_ref[i].tMaxs().m_floats[0]) > 0.001) || + (fabs(c[i].tMaxs().m_floats[1] - c_ref[i].tMaxs().m_floats[1]) > 0.001) || + (fabs(c[i].tMaxs().m_floats[2] - c_ref[i].tMaxs().m_floats[2]) > 0.001) || + // (fabs(c[i].tMaxs().m_floats[3] - c_ref[i].tMaxs().m_floats[3]) > 0.001) || + (fabs(c[i].tMins().m_floats[0] - c_ref[i].tMins().m_floats[0]) > 0.001) || + (fabs(c[i].tMins().m_floats[1] - c_ref[i].tMins().m_floats[1]) > 0.001) || + (fabs(c[i].tMins().m_floats[2] - c_ref[i].tMins().m_floats[2]) > 0.001) + //|| (fabs(c[i].tMins().m_floats[3] - c_ref[i].tMins().m_floats[3]) > 0.001) + ) + + + //if((c[i].tMaxs().m_floats[0] != c_ref[i].tMaxs().m_floats[0]) || (c[i].tMaxs().m_floats[1] != c_ref[i].tMaxs().m_floats[1]) || (c[i].tMaxs().m_floats[2] != c_ref[i].tMaxs().m_floats[2]) || (c[i].tMaxs().m_floats[3] != c_ref[i].tMaxs().m_floats[3]) || (c[i].tMins().m_floats[0] != c_ref[i].tMins().m_floats[0]) || (c[i].tMins().m_floats[1] != c_ref[i].tMins().m_floats[1]) || (c[i].tMins().m_floats[2] != c_ref[i].tMins().m_floats[2]) || (c[i].tMins().m_floats[3] != c_ref[i].tMins().m_floats[3])) + { + printf("Merge fail at %d with test = %d, ref = %d\n", i, Select_Test_Res[i], Select_Ref_Res[i]); + + printf("a_mx_f[0] = %.3f, a_mx_f[1] = %.3f, a_mx_f[2] = %.3f, a_mx_f[3] = %.3f\n", a[i].tMaxs().m_floats[0], a[i].tMaxs().m_floats[1], a[i].tMaxs().m_floats[2], a[i].tMaxs().m_floats[3]); + printf("a_mi_f[0] = %.3f, a_mi_f[1] = %.3f, a_mi_f[2] = %.3f, a_mi_f[3] = %.3f\n", a[i].tMins().m_floats[0], a[i].tMins().m_floats[1], a[i].tMins().m_floats[2], a[i].tMins().m_floats[3]); + printf("b_mx_f[0] = %.3f, b_mx_f[1] = %.3f, b_mx_f[2] = %.3f, b_mx_f[3] = %.3f\n", b[i].tMaxs().m_floats[0], b[i].tMaxs().m_floats[1], b[i].tMaxs().m_floats[2], b[i].tMaxs().m_floats[3]); + printf("b_mi_f[0] = %.3f, b_mi_f[1] = %.3f, b_mi_f[2] = %.3f, b_mi_f[3] = %.3f\n", b[i].tMins().m_floats[0], b[i].tMins().m_floats[1], b[i].tMins().m_floats[2], b[i].tMins().m_floats[3]); + printf("c_mx_f[0] = %.3f, c_mx_f[1] = %.3f, c_mx_f[2] = %.3f, c_mx_f[3] = %.3f\n", c[i].tMaxs().m_floats[0], c[i].tMaxs().m_floats[1], c[i].tMaxs().m_floats[2], c[i].tMaxs().m_floats[3]); + printf("c_mi_f[0] = %.3f, c_mi_f[1] = %.3f, c_mi_f[2] = %.3f, c_mi_f[3] = %.3f\n", c[i].tMins().m_floats[0], c[i].tMins().m_floats[1], c[i].tMins().m_floats[2], c[i].tMins().m_floats[3]); + + printf("a_mx_f_ref[0] = %.3f, a_mx_f_ref[1] = %.3f, a_mx_f_ref[2] = %.3f, a_mx_f_ref[3] = %.3f\n", a_ref[i].tMaxs().m_floats[0], a_ref[i].tMaxs().m_floats[1], a_ref[i].tMaxs().m_floats[2], a_ref[i].tMaxs().m_floats[3]); + printf("a_mi_f_ref[0] = %.3f, a_mi_f_ref[1] = %.3f, a_mi_f_ref[2] = %.3f, a_mi_f_ref[3] = %.3f\n", a_ref[i].tMins().m_floats[0], a_ref[i].tMins().m_floats[1], a_ref[i].tMins().m_floats[2], a_ref[i].tMins().m_floats[3]); + printf("b_mx_f_ref[0] = %.3f, b_mx_f_ref[1] = %.3f, b_mx_f_ref[2] = %.3f, b_mx_f_ref[3] = %.3f\n", b_ref[i].tMaxs().m_floats[0], b_ref[i].tMaxs().m_floats[1], b_ref[i].tMaxs().m_floats[2], b_ref[i].tMaxs().m_floats[3]); + printf("b_mi_f_ref[0] = %.3f, b_mi_f_ref[1] = %.3f, b_mi_f_ref[2] = %.3f, b_mi_f_ref[3] = %.3f\n", b_ref[i].tMins().m_floats[0], b_ref[i].tMins().m_floats[1], b_ref[i].tMins().m_floats[2], b_ref[i].tMins().m_floats[3]); + printf("c_mx_f_ref[0] = %.3f, c_mx_f_ref[1] = %.3f, c_mx_f_ref[2] = %.3f, c_mx_f_ref[3] = %.3f\n", c_ref[i].tMaxs().m_floats[0], c_ref[i].tMaxs().m_floats[1], c_ref[i].tMaxs().m_floats[2], c_ref[i].tMaxs().m_floats[3]); + printf("c_mi_f_ref[0] = %.3f, c_mi_f_ref[1] = %.3f, c_mi_f_ref[2] = %.3f, c_mi_f_ref[3] = %.3f\n", c_ref[i].tMins().m_floats[0], c_ref[i].tMins().m_floats[1], c_ref[i].tMins().m_floats[2], c_ref[i].tMins().m_floats[3]); + return 1; + + } + + } + + //////////////////////////////////// + // + // Time and Test Select + // + //////////////////////////////////// + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + + + for (i = 0; i < DATA_SIZE; i++) + { + Select_Ref_Res[i] = Select_ref(a_ref[i], b_ref[i], c_ref[i]); + } + + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + + for (i = 0; i < DATA_SIZE; i++) + { + Select_Test_Res[i] = Select(a[i], b[i], c[i]); + } + + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Select Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, TicksToCycles( vectorTime ) / LOOPCOUNT ); + + //printf("scalar = %llu, vector = %llu\n", scalarTime, vectorTime); + + for (i = 0; i < DATA_SIZE; i++) + { + Select_Ref_Res[i] = Select_ref(a_ref[i], b_ref[i], c_ref[i]); + Select_Test_Res[i] = Select(a[i], b[i], c[i]); + + if(Select_Test_Res[i] != Select_Ref_Res[i]) + { + printf("Select fail at %d with test = %d, ref = %d\n", i, Select_Test_Res[i], Select_Ref_Res[i]); + + printf("a_mx_f[0] = %.3f, a_mx_f[1] = %.3f, a_mx_f[2] = %.3f, a_mx_f[3] = %.3f\n", a[i].tMaxs().m_floats[0], a[i].tMaxs().m_floats[1], a[i].tMaxs().m_floats[2], a[i].tMaxs().m_floats[3]); + printf("a_mi_f[0] = %.3f, a_mi_f[1] = %.3f, a_mi_f[2] = %.3f, a_mi_f[3] = %.3f\n", a[i].tMins().m_floats[0], a[i].tMins().m_floats[1], a[i].tMins().m_floats[2], a[i].tMins().m_floats[3]); + printf("b_mx_f[0] = %.3f, b_mx_f[1] = %.3f, b_mx_f[2] = %.3f, b_mx_f[3] = %.3f\n", b[i].tMaxs().m_floats[0], b[i].tMaxs().m_floats[1], b[i].tMaxs().m_floats[2], b[i].tMaxs().m_floats[3]); + printf("b_mi_f[0] = %.3f, b_mi_f[1] = %.3f, b_mi_f[2] = %.3f, b_mi_f[3] = %.3f\n", b[i].tMins().m_floats[0], b[i].tMins().m_floats[1], b[i].tMins().m_floats[2], b[i].tMins().m_floats[3]); + printf("c_mx_f[0] = %.3f, c_mx_f[1] = %.3f, c_mx_f[2] = %.3f, c_mx_f[3] = %.3f\n", c[i].tMaxs().m_floats[0], c[i].tMaxs().m_floats[1], c[i].tMaxs().m_floats[2], c[i].tMaxs().m_floats[3]); + printf("c_mi_f[0] = %.3f, c_mi_f[1] = %.3f, c_mi_f[2] = %.3f, c_mi_f[3] = %.3f\n", c[i].tMins().m_floats[0], c[i].tMins().m_floats[1], c[i].tMins().m_floats[2], c[i].tMins().m_floats[3]); + + printf("a_mx_f_ref[0] = %.3f, a_mx_f_ref[1] = %.3f, a_mx_f_ref[2] = %.3f, a_mx_f_ref[3] = %.3f\n", a_ref[i].tMaxs().m_floats[0], a_ref[i].tMaxs().m_floats[1], a_ref[i].tMaxs().m_floats[2], a_ref[i].tMaxs().m_floats[3]); + printf("a_mi_f_ref[0] = %.3f, a_mi_f_ref[1] = %.3f, a_mi_f_ref[2] = %.3f, a_mi_f_ref[3] = %.3f\n", a_ref[i].tMins().m_floats[0], a_ref[i].tMins().m_floats[1], a_ref[i].tMins().m_floats[2], a_ref[i].tMins().m_floats[3]); + printf("b_mx_f_ref[0] = %.3f, b_mx_f_ref[1] = %.3f, b_mx_f_ref[2] = %.3f, b_mx_f_ref[3] = %.3f\n", b_ref[i].tMaxs().m_floats[0], b_ref[i].tMaxs().m_floats[1], b_ref[i].tMaxs().m_floats[2], b_ref[i].tMaxs().m_floats[3]); + printf("b_mi_f_ref[0] = %.3f, b_mi_f_ref[1] = %.3f, b_mi_f_ref[2] = %.3f, b_mi_f_ref[3] = %.3f\n", b_ref[i].tMins().m_floats[0], b_ref[i].tMins().m_floats[1], b_ref[i].tMins().m_floats[2], b_ref[i].tMins().m_floats[3]); + printf("c_mx_f_ref[0] = %.3f, c_mx_f_ref[1] = %.3f, c_mx_f_ref[2] = %.3f, c_mx_f_ref[3] = %.3f\n", c_ref[i].tMaxs().m_floats[0], c_ref[i].tMaxs().m_floats[1], c_ref[i].tMaxs().m_floats[2], c_ref[i].tMaxs().m_floats[3]); + printf("c_mi_f_ref[0] = %.3f, c_mi_f_ref[1] = %.3f, c_mi_f_ref[2] = %.3f, c_mi_f_ref[3] = %.3f\n", c_ref[i].tMins().m_floats[0], c_ref[i].tMins().m_floats[1], c_ref[i].tMins().m_floats[2], c_ref[i].tMins().m_floats[3]); + return 1; + } + + } + + return 0; +} +#endif + + + + diff --git a/test/Bullet2/Source/Tests/Test_btDbvt.h b/test/Bullet2/Source/Tests/Test_btDbvt.h new file mode 100644 index 0000000000..92e309a110 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_btDbvt.h @@ -0,0 +1,21 @@ +// +// Test_btDbvt.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc., Inc. +// + +#ifndef BulletTest_Test_btDbvt_h +#define BulletTest_Test_btDbvt_h + +#ifdef __cplusplus +extern "C" { +#endif + + int Test_btDbvt(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/Bullet2/Source/Tests/Test_dot3.cpp b/test/Bullet2/Source/Tests/Test_dot3.cpp new file mode 100644 index 0000000000..ef3ff4a552 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_dot3.cpp @@ -0,0 +1,153 @@ +// +// Test_v3dot.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_dot3.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static btVector3 dot3_ref( const btVector3 &, const btVector3 &, const btVector3 &, const btVector3 &); +static btVector3 dot3_ref( const btVector3 &v, const btVector3 &v1, const btVector3 &v2, const btVector3 &v3) +{ + return btVector3( v.dot(v1), v.dot(v2), v.dot(v3)); +} + +/* +SIMD_FORCE_INLINE int operator!=(const btVector3 &s, const btVector3 &v) +{ +#ifdef __SSE__ + __m128 test = _mm_cmpneq_ps( s.mVec128, v.mVec128 ); + return (_mm_movemask_ps( test ) & 7) != 0; +#elif defined __ARM_NEON_H + uint32x4_t test = vandq_u32( vceqq_f32( s.mVec128, v.mVec128 ), (uint32x4_t){-1,-1,-1,0}); + uint32x2_t t = vpadd_u32( vget_low_u32(test), vget_high_u32(test)); + t = vpadd_u32(t, t); + return -3 != (int32_t) vget_lane_u32(t, 0); +#else + return s.m_floats[0] != v.m_floats[0] || + s.m_floats[1] != v.m_floats[1] || + s.m_floats[2] != v.m_floats[2]; +#endif +} +*/ + + + +#define LOOPCOUNT 1000 +#define NUM_CYCLES 10000 + +int Test_dot3(void) +{ + btVector3 v, v1, v2, v3; + +#define DATA_SIZE 1024 + + btVector3 vec3_arr[DATA_SIZE]; + btVector3 vec3_arr1[DATA_SIZE]; + btVector3 vec3_arr2[DATA_SIZE]; + btVector3 vec3_arr3[DATA_SIZE]; + btVector3 res_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + btVector3 correct, test; + + for( k = 0; k < DATA_SIZE; k++ ) + { + + vec3_arr[k] = btVector3( btAssign128( RANDF, RANDF, RANDF, BT_NAN)); + vec3_arr1[k] = btVector3( btAssign128( RANDF, RANDF, RANDF, BT_NAN)); + vec3_arr2[k] = btVector3( btAssign128( RANDF, RANDF, RANDF, BT_NAN )); + vec3_arr3[k] = btVector3( btAssign128( RANDF, RANDF, RANDF, BT_NAN)); + + correct = dot3_ref(vec3_arr[k], vec3_arr1[k], vec3_arr2[k], vec3_arr3[k]); + test = vec3_arr[k].dot3( vec3_arr1[k], vec3_arr2[k], vec3_arr3[k]); + + if( correct != test ) + { + vlog( "Error (%ld) - dot3 result error! *{%a, %a, %a, %a} != {%a, %a, %a, %a} \n", k, + correct.x(), correct.y(), correct.z(), correct.w(), + test.x(), test.y(), test.z(), test.w() ); + + return 1; + } + } + + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t k32 = (k & (DATA_SIZE-1)); + res_arr[k32] = dot3_ref( vec3_arr[k32], vec3_arr1[k32], vec3_arr2[k32], vec3_arr3[k32]); k32++; + res_arr[k32] = dot3_ref( vec3_arr[k32], vec3_arr1[k32], vec3_arr2[k32], vec3_arr3[k32]); k32++; + res_arr[k32] = dot3_ref( vec3_arr[k32], vec3_arr1[k32], vec3_arr2[k32], vec3_arr3[k32]); k32++; + res_arr[k32] = dot3_ref( vec3_arr[k32], vec3_arr1[k32], vec3_arr2[k32], vec3_arr3[k32]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t k32 = (k & (DATA_SIZE-1)); + res_arr[k32] = vec3_arr[k32].dot3( vec3_arr1[k32], vec3_arr2[k32], vec3_arr3[k32]); k32++; + res_arr[k32] = vec3_arr[k32].dot3( vec3_arr1[k32], vec3_arr2[k32], vec3_arr3[k32]); k32++; + res_arr[k32] = vec3_arr[k32].dot3( vec3_arr1[k32], vec3_arr2[k32], vec3_arr3[k32]); k32++; + res_arr[k32] = vec3_arr[k32].dot3( vec3_arr1[k32], vec3_arr2[k32], vec3_arr3[k32]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_dot3.h b/test/Bullet2/Source/Tests/Test_dot3.h new file mode 100644 index 0000000000..cb525f88ad --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_dot3.h @@ -0,0 +1,22 @@ +// +// Test_mindot.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_dot3_h +#define BulletTest_Test_dot3_h + +#ifdef __cplusplus +extern "C" { +#endif + + int Test_dot3(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_maxdot.cpp b/test/Bullet2/Source/Tests/Test_maxdot.cpp new file mode 100644 index 0000000000..acc0caeb42 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_maxdot.cpp @@ -0,0 +1,281 @@ +// +// Test_maxdot.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_maxdot.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + + +// reference code for testing purposes +static long maxdot_ref( const btSimdFloat4 *vertices, + float *vec, + size_t count, + float *dotResult ); + + + + + +#ifdef __arm__ + #define MAX_LOG2_SIZE 9 +#else + #define MAX_LOG2_SIZE 10 +#endif +#define MAX_SIZE (1U << MAX_LOG2_SIZE) +#define LOOPCOUNT 10 + +int Test_maxdot(void) +{ + // Init an array flanked by guard pages + btSimdFloat4 *data = (btSimdFloat4*) GuardCalloc( 1, MAX_SIZE * sizeof(btSimdFloat4), NULL ); + float *fp = (float*) data; + long correct, test; + btVector3 localScaling( 0.1f, 0.2f, 0.3f); + size_t size; + + // Init the data + size_t i; + for( i = 0; i < MAX_SIZE; i++ ) + { + fp[4*i] = (int32_t) RANDF_16; + fp[4*i+1] = (int32_t) RANDF_16; + fp[4*i+2] = (int32_t) RANDF_16; + fp[4*i+3] = BT_NAN; // w channel NaN + } + + float correctDot, testDot; + fp = (float*) localScaling; + float maxRelativeError = 0.f; + + for( size = 1; size <= MAX_SIZE; size++ ) + { + float *in = (float*)(data + MAX_SIZE - size); + size_t position; + + for( position = 0; position < size; position++ ) + { + float *biggest = in + position * 4; + float old[4] = { biggest[0], biggest[1], biggest[2], biggest[3] }; + biggest[0] += LARGE_FLOAT17; + biggest[1] += LARGE_FLOAT17; + biggest[2] += LARGE_FLOAT17; + biggest[3] += LARGE_FLOAT17; + + correctDot = BT_NAN; + testDot = BT_NAN; + correct = maxdot_ref( (btSimdFloat4*) in, (float*) &localScaling, size, &correctDot); + test = localScaling.maxDot( (btVector3*) in, size, testDot); + if( test < 0 || test >= size ) + { + vlog( "Error @ %ld: index out of bounds! *%ld vs %ld \n", size, correct, test); + continue; + } + if( correct != test ) + { + vlog( "Error @ %ld: index misreported! *%ld vs %ld (*%f, %f)\n", size, correct, test, + fp[0] * in[4*correct] + fp[1] * in[4*correct+1] + fp[2] * in[4*correct+2], + fp[0] * in[4*test] + fp[1] * in[4*test+1] + fp[2] * in[4*test+2] ); + return 1; + } + if( test != position ) + { + vlog( "Biggest not found where it is supposed to be: *%ld vs %ld (*%f, %f)\n", position, test, + fp[0] * in[4*test] + fp[1] * in[4*test+1] + fp[2] * in[4*test+2], + fp[0] * in[4*position] + fp[1] * in[4*position+1] + fp[2] * in[4*position+2] ); + return 1; + } + + if( correctDot != testDot ) + { + float relativeError = btFabs((testDot - correctDot) / correctDot); + if (relativeError>1e-6) + { + vlog( "Error @ %ld: dotpr misreported! *%f vs %f (*%f, %f)\n", size, correctDot, testDot, + fp[0] * in[4*correct] + fp[1] * in[4*correct+1] + fp[2] * in[4*correct+2], + fp[0] * in[4*test] + fp[1] * in[4*test+1] + fp[2] * in[4*test+2] ); + return 1; + } else + { + if (maxRelativeError < relativeError) + { + maxRelativeError = relativeError; +#ifdef VERBOSE_WARNING + sprintf(errStr,"Warning @ %ld: dotpr misreported! *%f vs %f (*%f, %f)\n", size, correctDot, testDot, + fp[0] * in[4*correct] + fp[1] * in[4*correct+1] + fp[2] * in[4*correct+2], + fp[0] * in[4*test] + fp[1] * in[4*test+1] + fp[2] * in[4*test+2]); +#endif //VERBOSE_WARNING + } + } + } + + memcpy( biggest, old, 16 ); + } + } + + + if (maxRelativeError) + { + printf("Warning: relative error = %e\n", maxRelativeError); +#ifdef VERBOSE_WARNING + vlog(errStr); +#endif + } + + uint64_t scalarTimes[33 + (MAX_LOG2_SIZE-5)]; + uint64_t vectorTimes[33 + (MAX_LOG2_SIZE-5)]; + size_t j, k; + float *in = (float*) data; + for( size = 1; size <= 32; size++ ) + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTimes[size] = 0; + for (j = 0; j < 100; j++) { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + correct += maxdot_ref( (btSimdFloat4*) in, (float*) &localScaling, size, &correctDot); + currentTime = ReadTicks() - startTime; + scalarTimes[size] += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTimes[size] = bestTime; + else + scalarTimes[size] /= 100; + } + + uint64_t *timep = &scalarTimes[33]; + for( size = 64; size <= MAX_SIZE; size *= 2 ) + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + timep[0] =0; + for (j = 0; j < 100; j++) { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + correct += maxdot_ref( (btSimdFloat4*) in, (float*) &localScaling, size, &correctDot); + currentTime = ReadTicks() - startTime; + timep[0] += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + timep[0] = bestTime; + else + timep[0] /= 100; + + timep++; + } + + for( size = 1; size <= 32; size++ ) + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTimes[size] = 0; + for (j = 0; j < 100; j++) { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + test += localScaling.maxDot( (btVector3*) in, size, testDot); + currentTime = ReadTicks() - startTime; + vectorTimes[size] += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTimes[size] = bestTime; + else + vectorTimes[size] /= 100; + } + + timep = &vectorTimes[33]; + for( size = 64; size <= MAX_SIZE; size *= 2 ) + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + timep[0] =0; + for (j = 0; j < 100; j++) { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + test += localScaling.maxDot( (btVector3*) in, size, testDot); + currentTime = ReadTicks() - startTime; + timep[0] += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + timep[0] = bestTime; + else + timep[0] /= 100; + + timep++; + } + + vlog( "Timing:\n" ); + vlog( " size\t scalar\t vector\n" ); + for( size = 1; size <= 32; size++ ) + vlog( "%5lu\t%10.2f\t%10.2f\n", size, TicksToCycles( scalarTimes[size] ) / LOOPCOUNT, TicksToCycles( vectorTimes[size] ) / LOOPCOUNT ); + size_t index = 33; + for( size = 64; size <= MAX_SIZE; size *= 2 ) + { + vlog( "%5lu\t%10.2f\t%10.2f\n", size, TicksToCycles( scalarTimes[index] ) / LOOPCOUNT, TicksToCycles( vectorTimes[index] ) / LOOPCOUNT ); + index++; + } + + // Useless check to make sure that the timing loops are not optimized away + if( test != correct ) + vlog( "Error: Test != correct: *%ld vs. %ld\n", correct, test); + + GuardFree(data); + + return 0; +} + + +static long maxdot_ref( const btSimdFloat4 *vertices, + float *vec, + size_t count, + float *dotResult ) +{ + + const float *dp = (const float*) vertices; + float maxDot = -BT_INFINITY; + long i = 0; + long ptIndex = -1; + + for( i = 0; i < count; i++ ) + { + float dot = vec[0] * dp[0] + vec[1] * dp[1] + vec[2] * dp[2]; dp += 4; + + if( dot > maxDot ) + { + maxDot = dot; + ptIndex = i; + } + } + + *dotResult = maxDot; + + return ptIndex; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_maxdot.h b/test/Bullet2/Source/Tests/Test_maxdot.h new file mode 100644 index 0000000000..2e6c517f2f --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_maxdot.h @@ -0,0 +1,22 @@ +// +// Test_maxdot.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_maxdot_h +#define BulletTest_Test_maxdot_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_maxdot(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_mindot.cpp b/test/Bullet2/Source/Tests/Test_mindot.cpp new file mode 100644 index 0000000000..2f44256219 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_mindot.cpp @@ -0,0 +1,269 @@ +// +// Test_mindot.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_mindot.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + + +// reference code for testing purposes +static long mindot_ref( const btSimdFloat4 *vertices, + float *vec, + size_t count, + float *dotResult ); + +#ifdef __arm__ + #define MAX_LOG2_SIZE 9 +#else + #define MAX_LOG2_SIZE 9 +#endif +#define MAX_SIZE (1U << MAX_LOG2_SIZE) +#define LOOPCOUNT 100 + +int Test_mindot(void) +{ + // Init an array flanked by guard pages + btSimdFloat4 *data = (btSimdFloat4*) GuardCalloc( 1, MAX_SIZE * sizeof(btSimdFloat4), NULL ); + float *fp = (float*) data; + long correct, test; + btVector3 localScaling( 0.1f, 0.2f, 0.3f); + size_t size; + + // Init the data + size_t i; + for( i = 0; i < MAX_SIZE; i++ ) + { + fp[4*i] = (int32_t) RANDF_16; + fp[4*i+1] = (int32_t) RANDF_16; + fp[4*i+2] = (int32_t) RANDF_16; + fp[4*i+3] = BT_NAN; // w channel NaN + } + + float correctDot, testDot; + fp = (float*) localScaling; + float maxRelativeError = 0.f; + + for( size = 1; size <= MAX_SIZE; size++ ) + { + float *in = (float*)(data + MAX_SIZE - size); + size_t position; + + for( position = 0; position < size; position++ ) + { + float *biggest = in + position * 4; + float old[4] = { biggest[0], biggest[1], biggest[2], biggest[3] }; + biggest[0] -= LARGE_FLOAT17; + biggest[1] -= LARGE_FLOAT17; + biggest[2] -= LARGE_FLOAT17; + biggest[3] -= LARGE_FLOAT17; + + correctDot = BT_NAN; + testDot = BT_NAN; + correct = mindot_ref( (btSimdFloat4*) in, (float*) &localScaling, size, &correctDot); + test = localScaling.minDot( (btVector3*) in, size, testDot); + if( test < 0 || test >= size ) + { + vlog( "Error @ %ld: index out of bounds! *%ld vs %ld \n", size, correct, test); + continue; + } + if( correct != test ) + { + vlog( "Error @ %ld: index misreported! *%ld vs %ld (*%f, %f)\n", size, correct, test, + fp[0] * in[4*correct] + fp[1] * in[4*correct+1] + fp[2] * in[4*correct+2], + fp[0] * in[4*test] + fp[1] * in[4*test+1] + fp[2] * in[4*test+2] ); + return 1; + } + if( test != position ) + { + vlog( "Biggest not found where it is supposed to be: *%ld vs %ld (*%f, %f)\n", position, test, + fp[0] * in[4*test] + fp[1] * in[4*test+1] + fp[2] * in[4*test+2], + fp[0] * in[4*position] + fp[1] * in[4*position+1] + fp[2] * in[4*position+2] ); + return 1; + } + + if( correctDot != testDot ) + { + float relativeError = btFabs((testDot - correctDot) / correctDot); + if (relativeError>1e6) + { + vlog( "Error @ %ld: dotpr misreported! *%f vs %f (*%f, %f)\n", size, correctDot, testDot, + fp[0] * in[4*correct] + fp[1] * in[4*correct+1] + fp[2] * in[4*correct+2], + fp[0] * in[4*test] + fp[1] * in[4*test+1] + fp[2] * in[4*test+2] ); + return 1; + } else + { + if (maxRelativeError < relativeError) + { + maxRelativeError = relativeError; + } + } + } + + + memcpy( biggest, old, 16 ); + } + } + + if (maxRelativeError) + { + printf("Warning: relative error = %e\n", maxRelativeError); + } + uint64_t scalarTimes[33 + (MAX_LOG2_SIZE-5)]; + uint64_t vectorTimes[33 + (MAX_LOG2_SIZE-5)]; + size_t j, k; + float *in = (float*) data; + for( size = 1; size <= 32; size++ ) + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTimes[size] = 0; + for (j = 0; j < 100; j++) { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + correct += mindot_ref( (btSimdFloat4*) in, (float*) &localScaling, size, &correctDot); + currentTime = ReadTicks() - startTime; + scalarTimes[size] += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTimes[size] = bestTime; + else + scalarTimes[size] /= 100; + } + + uint64_t *timep = &scalarTimes[33]; + for( size = 64; size <= MAX_SIZE; size *= 2 ) + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + timep[0] =0; + for (j = 0; j < 100; j++) { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + correct += mindot_ref( (btSimdFloat4*) in, (float*) &localScaling, size, &correctDot); + currentTime = ReadTicks() - startTime; + timep[0] += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + timep[0] = bestTime; + else + timep[0] /= 100; + + timep++; + } + + for( size = 1; size <= 32; size++ ) + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTimes[size] = 0; + for (j = 0; j < 100; j++) { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + test += localScaling.minDot( (btVector3*) in, size, testDot); + currentTime = ReadTicks() - startTime; + vectorTimes[size] += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTimes[size] = bestTime; + else + vectorTimes[size] /= 100; + } + + timep = &vectorTimes[33]; + for( size = 64; size <= MAX_SIZE; size *= 2 ) + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + timep[0] =0; + for (j = 0; j < 100; j++) { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + test += localScaling.minDot( (btVector3*) in, size, testDot); + currentTime = ReadTicks() - startTime; + timep[0] += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + timep[0] = bestTime; + else + timep[0] /= 100; + + timep++; + } + + vlog( "Timing:\n" ); + vlog( " size\t scalar\t vector\n" ); + for( size = 1; size <= 32; size++ ) + vlog( "%5lu\t%10.2f\t%10.2f\n", size, TicksToCycles( scalarTimes[size] ) / LOOPCOUNT, TicksToCycles( vectorTimes[size] ) / LOOPCOUNT ); + size_t index = 33; + for( size = 64; size <= MAX_SIZE; size *= 2 ) + { + vlog( "%5lu\t%10.2f\t%10.2f\n", size, TicksToCycles( scalarTimes[index] ) / LOOPCOUNT, TicksToCycles( vectorTimes[index] ) / LOOPCOUNT ); + index++; + } + + // Useless check to make sure that the timing loops are not optimized away + if( test != correct ) + vlog( "Error: Test != correct: *%ld vs. %ld\n", correct, test); + + GuardFree(data); + + return 0; +} + + + +static long mindot_ref( const btSimdFloat4 *vertices, + float *vec, + size_t count, + float *dotResult ) +{ + + const float *dp = (const float*) vertices; + float minDot = BT_INFINITY; + long i = 0; + long ptIndex = -1; + + for( i = 0; i < count; i++ ) + { + float dot = vec[0] * dp[0] + vec[1] * dp[1] + vec[2] * dp[2]; dp += 4; + + if( dot < minDot ) + { + minDot = dot; + ptIndex = i; + } + } + + *dotResult = minDot; + + return ptIndex; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_mindot.h b/test/Bullet2/Source/Tests/Test_mindot.h new file mode 100644 index 0000000000..4810dcd8df --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_mindot.h @@ -0,0 +1,22 @@ +// +// Test_mindot.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_mindot_h +#define BulletTest_Test_mindot_h + +#ifdef __cplusplus +extern "C" { +#endif + + int Test_mindot(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_qtdot.cpp b/test/Bullet2/Source/Tests/Test_qtdot.cpp new file mode 100644 index 0000000000..3fad74d377 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtdot.cpp @@ -0,0 +1,162 @@ +// +// Test_qtdot.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_qtdot.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define BT_OP(a, b) (a.dot(b)) +// reference code for testing purposes +static inline btScalar qtdot_ref(btQuaternion& q1, btQuaternion& q2); + +static inline btScalar qtdot_ref(btQuaternion& q1, btQuaternion& q2) +{ + return + q1.x() * q2.x() + + q1.y() * q2.y() + + q1.z() * q2.z() + + q1.w() * q2.w(); +} + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +int Test_qtdot(void) +{ + btQuaternion q1, q2; + float x, y, z, w, vNaN; + vNaN = BT_NAN; // w channel NaN + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + q1.setValue(x,y,z,w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + q2.setValue(x,y,z,w); + + btScalar correct_res, test_res; + + { + correct_res = vNaN; + test_res = vNaN; + correct_res = qtdot_ref(q1, q2); + test_res = BT_OP(q1,q2); + + if( fabsf(correct_res - test_res) > FLT_EPSILON*4 ) + { + vlog( "Error - qtdot result error! " + "\ncorrect = %10.4f " + "\ntested = %10.4f \n", + correct_res, test_res); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btQuaternion qt_arr1[DATA_SIZE]; + btQuaternion qt_arr2[DATA_SIZE]; + btScalar res_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + qt_arr1[k].setValue(x,y,z,w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + qt_arr2[k].setValue(x,y,z,w); + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t km = (k & (DATA_SIZE-1)); + res_arr[km] = qtdot_ref(qt_arr1[km], qt_arr2[km]);km++; + res_arr[km] = qtdot_ref(qt_arr1[km], qt_arr2[km]);km++; + res_arr[km] = qtdot_ref(qt_arr1[km], qt_arr2[km]);km++; + res_arr[km] = qtdot_ref(qt_arr1[km], qt_arr2[km]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t km = (k & (DATA_SIZE-1)); + res_arr[km] = BT_OP(qt_arr1[km], qt_arr2[km]);km++; + res_arr[km] = BT_OP(qt_arr1[km], qt_arr2[km]);km++; + res_arr[km] = BT_OP(qt_arr1[km], qt_arr2[km]);km++; + res_arr[km] = BT_OP(qt_arr1[km], qt_arr2[km]);km++; + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_qtdot.h b/test/Bullet2/Source/Tests/Test_qtdot.h new file mode 100644 index 0000000000..4917780c90 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtdot.h @@ -0,0 +1,22 @@ +// +// Test_qtdot.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_qtdot_h +#define BulletTest_Test_qtdot_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_qtdot(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_qtmul.cpp b/test/Bullet2/Source/Tests/Test_qtmul.cpp new file mode 100644 index 0000000000..7b83a7bb47 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtmul.cpp @@ -0,0 +1,183 @@ +// +// Test_qtmul.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_qtmul.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define BT_OP(a, b) ((a) *= (b)) +// reference code for testing purposes +static inline btQuaternion& qtmul_ref(btQuaternion& q1, btQuaternion& q2); + +static inline btQuaternion& qtmul_ref(btQuaternion& q1, btQuaternion& q2) +{ + float x,y,z,w; + x = q1.w() * q2.x() + q1.x() * q2.w() + q1.y() * q2.z() - q1.z() * q2.y(), + y = q1.w() * q2.y() + q1.y() * q2.w() + q1.z() * q2.x() - q1.x() * q2.z(), + z = q1.w() * q2.z() + q1.z() * q2.w() + q1.x() * q2.y() - q1.y() * q2.x(), + w = q1.w() * q2.w() - q1.x() * q2.x() - q1.y() * q2.y() - q1.z() * q2.z(); + + q1.setValue(x, y, z, w); + return q1; +} + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +int Test_qtmul(void) +{ + btQuaternion q1, q2, q3; + + float x, y, z, w, vNaN; + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + vNaN = BT_NAN; // w channel NaN + q1.setValue(x,y,z,w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + q2.setValue(x,y,z,w); + + q3 = q1; + + btQuaternion correct_res, test_res; + + { + float vNaN = BT_NAN; + correct_res.setValue(vNaN, vNaN, vNaN, vNaN); + test_res.setValue(vNaN, vNaN, vNaN, vNaN); + correct_res = qtmul_ref(q1, q2); + test_res = BT_OP(q3,q2); + + if( fabsf(correct_res.x() - test_res.x()) + + fabsf(correct_res.y() - test_res.y()) + + fabsf(correct_res.z() - test_res.z()) + + fabsf(correct_res.w() - test_res.w()) > FLT_EPSILON*10 ) + { + vlog( "Error - qtmul result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) \n", + correct_res.x(), correct_res.y(), + correct_res.z(), correct_res.w(), + test_res.x(), test_res.y(), + test_res.z(), test_res.w()); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btQuaternion qt_arr1[DATA_SIZE]; + btQuaternion qt_arr2[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + qt_arr1[k].setValue(x,y,z,w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + qt_arr2[k].setValue(x,y,z,w); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + qt_arr1[k] = qtmul_ref(qt_arr1[k], qt_arr2[k]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + qt_arr1[k].setValue(x,y,z,w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + qt_arr2[k].setValue(x,y,z,w); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + qt_arr1[k] = BT_OP(qt_arr1[k], qt_arr2[k]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_qtmul.h b/test/Bullet2/Source/Tests/Test_qtmul.h new file mode 100644 index 0000000000..9109199b6f --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtmul.h @@ -0,0 +1,22 @@ +// +// Test_qtmul.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_qtmul_h +#define BulletTest_Test_qtmul_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_qtmul(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_qtmulQV3.cpp b/test/Bullet2/Source/Tests/Test_qtmulQV3.cpp new file mode 100644 index 0000000000..0a26b50d96 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtmulQV3.cpp @@ -0,0 +1,162 @@ +// +// Test_qtmulQV3.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_qtmulQV3.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define BT_OP(a, b) ((a) * (b)) +// reference code for testing purposes +static inline btQuaternion qtmulQV3_ref(const btQuaternion& q, const btVector3& w); + +static inline btQuaternion qtmulQV3_ref(const btQuaternion& q, const btVector3& w) +{ + return btQuaternion( + q.w() * w.x() + q.y() * w.z() - q.z() * w.y(), + q.w() * w.y() + q.z() * w.x() - q.x() * w.z(), + q.w() * w.z() + q.x() * w.y() - q.y() * w.x(), + -q.x() * w.x() - q.y() * w.y() - q.z() * w.z()); +} + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF_m1p1, RANDF_m1p1, RANDF_m1p1, BT_NAN ); // w channel NaN +} + +static inline btSimdFloat4 qtrand_f4(void) +{ + return btAssign128( RANDF_m1p1, RANDF_m1p1, RANDF_m1p1, RANDF_m1p1 ); +} + +static inline btSimdFloat4 qtNAN_f4(void) +{ + return btAssign128( BT_NAN, BT_NAN, BT_NAN, BT_NAN ); +} + +int Test_qtmulQV3(void) +{ + btQuaternion q; + btVector3 v3; + + // Init the data + q = btQuaternion(qtrand_f4()); + v3 = btVector3(rand_f4()); + + btQuaternion correct_res, test_res; + correct_res = btQuaternion(qtNAN_f4()); + test_res = btQuaternion(qtNAN_f4()); + + { + correct_res = qtmulQV3_ref(q, v3); + test_res = BT_OP(q, v3); + + if( fabsf(correct_res.x() - test_res.x()) + + fabsf(correct_res.y() - test_res.y()) + + fabsf(correct_res.z() - test_res.z()) + + fabsf(correct_res.w() - test_res.w()) > FLT_EPSILON*8 ) + { + vlog( "Error - qtmulQV3 result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) \n", + correct_res.x(), correct_res.y(), + correct_res.z(), correct_res.w(), + test_res.x(), test_res.y(), + test_res.z(), test_res.w()); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btQuaternion qt_arrR[DATA_SIZE]; + btQuaternion qt_arr[DATA_SIZE]; + btVector3 v3_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + qt_arr[k] = btQuaternion(qtrand_f4()); + v3_arr[k] = btVector3(rand_f4()); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + qt_arrR[k] = qtmulQV3_ref(qt_arr[k], v3_arr[k]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + qt_arr[k] = btQuaternion(qtrand_f4()); + v3_arr[k] = btVector3(rand_f4()); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + qt_arrR[k] = BT_OP(qt_arr[k], v3_arr[k]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_qtmulQV3.h b/test/Bullet2/Source/Tests/Test_qtmulQV3.h new file mode 100644 index 0000000000..f7bffce0b8 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtmulQV3.h @@ -0,0 +1,22 @@ +// +// Test_qtmulQV3.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_qtmulQV3_h +#define BulletTest_Test_qtmulQV3_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_qtmulQV3(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_qtmulV3Q.cpp b/test/Bullet2/Source/Tests/Test_qtmulV3Q.cpp new file mode 100644 index 0000000000..48f51245cb --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtmulV3Q.cpp @@ -0,0 +1,161 @@ +// +// Test_qtmulV3Q.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_qtmulV3Q.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define BT_OP(a, b) ((a) * (b)) +// reference code for testing purposes +static inline btQuaternion qtmulV3Q_ref(const btVector3& w, const btQuaternion& q); + +static inline btQuaternion qtmulV3Q_ref(const btVector3& w, const btQuaternion& q) +{ + return btQuaternion( + +w.x() * q.w() + w.y() * q.z() - w.z() * q.y(), + +w.y() * q.w() + w.z() * q.x() - w.x() * q.z(), + +w.z() * q.w() + w.x() * q.y() - w.y() * q.x(), + -w.x() * q.x() - w.y() * q.y() - w.z() * q.z()); +} + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +static inline btSimdFloat4 rand_f4(void) +{ + return btAssign128( RANDF_m1p1, RANDF_m1p1, RANDF_m1p1, BT_NAN ); // w channel NaN +} + +static inline btSimdFloat4 qtrand_f4(void) +{ + return btAssign128( RANDF_m1p1, RANDF_m1p1, RANDF_m1p1, RANDF_m1p1 ); +} + +static inline btSimdFloat4 qtNAN_f4(void) +{ + return btAssign128( BT_NAN, BT_NAN, BT_NAN, BT_NAN ); +} + +int Test_qtmulV3Q(void) +{ + btQuaternion q; + btVector3 v3; + + // Init the data + q = btQuaternion(qtrand_f4()); + v3 = btVector3(rand_f4()); + + btQuaternion correct_res, test_res; + correct_res = btQuaternion(qtNAN_f4()); + test_res = btQuaternion(qtNAN_f4()); + + { + correct_res = qtmulV3Q_ref(v3, q); + test_res = BT_OP(v3, q); + + if( fabsf(correct_res.x() - test_res.x()) + + fabsf(correct_res.y() - test_res.y()) + + fabsf(correct_res.z() - test_res.z()) + + fabsf(correct_res.w() - test_res.w()) > FLT_EPSILON*8 ) + { + vlog( "Error - qtmulV3Q result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) \n", + correct_res.x(), correct_res.y(), + correct_res.z(), correct_res.w(), + test_res.x(), test_res.y(), + test_res.z(), test_res.w()); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btQuaternion qt_arrR[DATA_SIZE]; + btQuaternion qt_arr[DATA_SIZE]; + btVector3 v3_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + qt_arr[k] = btQuaternion(qtrand_f4()); + v3_arr[k] = btVector3(rand_f4()); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + qt_arrR[k] = qtmulV3Q_ref(v3_arr[k], qt_arr[k]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + qt_arr[k] = btQuaternion(qtrand_f4()); + v3_arr[k] = btVector3(rand_f4()); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + qt_arrR[k] = BT_OP(v3_arr[k], qt_arr[k]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} +#endif//#ifdef BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_qtmulV3Q.h b/test/Bullet2/Source/Tests/Test_qtmulV3Q.h new file mode 100644 index 0000000000..f9714c9b66 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtmulV3Q.h @@ -0,0 +1,22 @@ +// +// Test_qtmulV3Q.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_qtmulV3Q_h +#define BulletTest_Test_qtmulV3Q_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_qtmulV3Q(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_qtnorm.cpp b/test/Bullet2/Source/Tests/Test_qtnorm.cpp new file mode 100644 index 0000000000..3d008bffd3 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtnorm.cpp @@ -0,0 +1,176 @@ +// +// Test_qtnorm.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_qtnorm.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define BT_OP(a) (a.normalize()) +// reference code for testing purposes +static inline btQuaternion& qtnorm_ref(btQuaternion& q1); + +static inline btQuaternion& qtnorm_ref(btQuaternion& q1) +{ + float dot = + q1.x() * q1.x() + + q1.y() * q1.y() + + q1.z() * q1.z() + + q1.w() * q1.w(); + + dot = 1.0f / sqrtf(dot); + + q1.setValue(q1.x()*dot, q1.y()*dot, q1.z()*dot, q1.w()*dot); + + return q1; +} + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +int Test_qtnorm(void) +{ + int i; + btQuaternion q1, q2; + float x, y, z, w, vNaN; + vNaN = BT_NAN; // w channel NaN + + btQuaternion correct_res, test_res; + + for (i=0; i FLT_EPSILON*10 ) + { + vlog( "Error - qtnorm result error! " + "\ncorrect = (%10.7f, %10.7f, %10.7f, %10.7f) " + "\ntested = (%10.7f, %10.7f, %10.7f, %10.7f) \n", + correct_res.x(), correct_res.y(), + correct_res.z(), correct_res.w(), + test_res.x(), test_res.y(), + test_res.z(), test_res.w()); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btQuaternion qt_arr0[DATA_SIZE]; + btQuaternion qt_arr1[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + qt_arr1[k].setValue(x,y,z,w); + } + + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t km = (k & (DATA_SIZE-1)); + qt_arr0[km] = qtnorm_ref(qt_arr1[km]);km++; + qt_arr0[km] = qtnorm_ref(qt_arr1[km]);km++; + qt_arr0[km] = qtnorm_ref(qt_arr1[km]);km++; + qt_arr0[km] = qtnorm_ref(qt_arr1[km]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = RANDF_01; + qt_arr1[k].setValue(x,y,z,w); + } + + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t km = (k & (DATA_SIZE-1)); + qt_arr0[km] = BT_OP(qt_arr1[km]);km++; + qt_arr0[km] = BT_OP(qt_arr1[km]);km++; + qt_arr0[km] = BT_OP(qt_arr1[km]);km++; + qt_arr0[km] = BT_OP(qt_arr1[km]);km++; + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_qtnorm.h b/test/Bullet2/Source/Tests/Test_qtnorm.h new file mode 100644 index 0000000000..5b0021709e --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_qtnorm.h @@ -0,0 +1,22 @@ +// +// Test_qtnorm.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_qtnorm_h +#define BulletTest_Test_qtnorm_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_qtnorm(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_quat_aos_neon.cpp b/test/Bullet2/Source/Tests/Test_quat_aos_neon.cpp new file mode 100644 index 0000000000..c13e41aebf --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_quat_aos_neon.cpp @@ -0,0 +1,599 @@ +// +// Test_quat_aos_neon.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc., Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_quat_aos_neon.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" + +#include + + +//typedef Vectormath::Aos::Vector3 vmVector3; +//typedef Vectormath::Aos::Quat vmQuat; +//typedef Vectormath::Aos::Matrix3 vmMatrix3; +//typedef Vectormath::Aos::Transform3 vmTransform3; +//typedef Vectormath::Aos::Point3 vmPoint3; + + +typedef Vectormath::Aos::Vector4 vmVector4; + +// reference code for testing purposes +ATTRIBUTE_ALIGNED16(class) Quat_ref +{ + float mX; + float mY; + float mZ; + float mW; + +public: + // Default constructor; does no initialization + // + inline Quat_ref( ) { }; + + // Copy a quaternion + // + inline Quat_ref( const Quat_ref & quat ); + + // Construct a quaternion from x, y, z, and w elements + // + inline Quat_ref( float x, float y, float z, float w ); + + // Construct a quaternion from a 3-D vector and a scalar + // + inline Quat_ref( const vmVector3 & xyz, float w ); + + // Copy elements from a 4-D vector into a quaternion + // + explicit inline Quat_ref( const vmVector4 & vec ); + + // Convert a rotation matrix to a unit-length quaternion + // + explicit inline Quat_ref( const vmMatrix3 & rotMat ); + + // Set all elements of a quaternion to the same scalar value + // + explicit inline Quat_ref( float scalar ); + + // Assign one quaternion to another + // + inline Quat_ref & operator =( const Quat_ref & quat ); + + // Set the x, y, and z elements of a quaternion + // NOTE: + // This function does not change the w element. + // + inline Quat_ref & setXYZ( const vmVector3 & vec ); + + // Get the x, y, and z elements of a quaternion + // + inline const vmVector3 getXYZ( ) const; + + // Set the x element of a quaternion + // + inline Quat_ref & setX( float x ); + + // Set the y element of a quaternion + // + inline Quat_ref & setY( float y ); + + // Set the z element of a quaternion + // + inline Quat_ref & setZ( float z ); + + // Set the w element of a quaternion + // + inline Quat_ref & setW( float w ); + + // Get the x element of a quaternion + // + inline float getX( ) const; + + // Get the y element of a quaternion + // + inline float getY( ) const; + + // Get the z element of a quaternion + // + inline float getZ( ) const; + + // Get the w element of a quaternion + // + inline float getW( ) const; + + // Set an x, y, z, or w element of a quaternion by index + // + inline Quat_ref & setElem( int idx, float value ); + + // Get an x, y, z, or w element of a quaternion by index + // + inline float getElem( int idx ) const; + + // Subscripting operator to set or get an element + // + inline float & operator []( int idx ); + + // Subscripting operator to get an element + // + inline float operator []( int idx ) const; + + // Add two quaternions + // + inline const Quat_ref operator +( const Quat_ref & quat ) const; + + // Subtract a quaternion from another quaternion + // + inline const Quat_ref operator -( const Quat_ref & quat ) const; + + // Multiply two quaternions + // + inline const Quat_ref operator *( const Quat_ref & quat ) const; + + // Multiply a quaternion by a scalar + // + inline const Quat_ref operator *( float scalar ) const; + + // Divide a quaternion by a scalar + // + inline const Quat_ref operator /( float scalar ) const; + + // Perform compound assignment and addition with a quaternion + // + inline Quat_ref & operator +=( const Quat_ref & quat ); + + // Perform compound assignment and subtraction by a quaternion + // + inline Quat_ref & operator -=( const Quat_ref & quat ); + + // Perform compound assignment and multiplication by a quaternion + // + inline Quat_ref & operator *=( const Quat_ref & quat ); + + // Perform compound assignment and multiplication by a scalar + // + inline Quat_ref & operator *=( float scalar ); + + // Perform compound assignment and division by a scalar + // + inline Quat_ref & operator /=( float scalar ); + + // Negate all elements of a quaternion + // + inline const Quat_ref operator -( ) const; + + // Construct an identity quaternion + // + static inline const Quat_ref identity( ); + + // Construct a quaternion to rotate between two unit-length 3-D vectors + // NOTE: + // The result is unpredictable if unitVec0 and unitVec1 point in opposite directions. + // + static inline const Quat_ref rotation( const vmVector3 & unitVec0, const vmVector3 & unitVec1 ); + + // Construct a quaternion to rotate around a unit-length 3-D vector + // + static inline const Quat_ref rotation( float radians, const vmVector3 & unitVec ); + + // Construct a quaternion to rotate around the x axis + // + static inline const Quat_ref rotationX( float radians ); + + // Construct a quaternion to rotate around the y axis + // + static inline const Quat_ref rotationY( float radians ); + + // Construct a quaternion to rotate around the z axis + // + static inline const Quat_ref rotationZ( float radians ); + +}; + +inline Quat_ref::Quat_ref( const Quat_ref & quat ) +{ + mX = quat.mX; + mY = quat.mY; + mZ = quat.mZ; + mW = quat.mW; +} + +inline Quat_ref::Quat_ref( float _x, float _y, float _z, float _w ) +{ + mX = _x; + mY = _y; + mZ = _z; + mW = _w; +} + +inline Quat_ref::Quat_ref( const vmVector3 & xyz, float _w ) +{ + this->setXYZ( xyz ); + this->setW( _w ); +} + +inline Quat_ref::Quat_ref( const vmVector4 & vec ) +{ + mX = vec.getX(); + mY = vec.getY(); + mZ = vec.getZ(); + mW = vec.getW(); +} + +inline Quat_ref::Quat_ref( float scalar ) +{ + mX = scalar; + mY = scalar; + mZ = scalar; + mW = scalar; +} + +inline const Quat_ref Quat_ref::identity( ) +{ + return Quat_ref( 0.0f, 0.0f, 0.0f, 1.0f ); +} + + +inline void loadXYZW_ref( Quat_ref & quat, const float * fptr ) +{ + quat = Quat_ref( fptr[0], fptr[1], fptr[2], fptr[3] ); +} + +inline void storeXYZW_ref( const Quat_ref & quat, float * fptr ) +{ + fptr[0] = quat.getX(); + fptr[1] = quat.getY(); + fptr[2] = quat.getZ(); + fptr[3] = quat.getW(); +} + +inline Quat_ref & Quat_ref::operator =( const Quat_ref & quat ) +{ + mX = quat.mX; + mY = quat.mY; + mZ = quat.mZ; + mW = quat.mW; + return *this; +} + +inline Quat_ref & Quat_ref::setXYZ( const vmVector3 & vec ) +{ + mX = vec.getX(); + mY = vec.getY(); + mZ = vec.getZ(); + return *this; +} + +inline const vmVector3 Quat_ref::getXYZ( ) const +{ + return vmVector3( mX, mY, mZ ); +} + +inline Quat_ref & Quat_ref::setX( float _x ) +{ + mX = _x; + return *this; +} + +inline float Quat_ref::getX( ) const +{ + return mX; +} + +inline Quat_ref & Quat_ref::setY( float _y ) +{ + mY = _y; + return *this; +} + +inline float Quat_ref::getY( ) const +{ + return mY; +} + +inline Quat_ref & Quat_ref::setZ( float _z ) +{ + mZ = _z; + return *this; +} + +inline float Quat_ref::getZ( ) const +{ + return mZ; +} + +inline Quat_ref & Quat_ref::setW( float _w ) +{ + mW = _w; + return *this; +} + +inline float Quat_ref::getW( ) const +{ + return mW; +} + +inline Quat_ref & Quat_ref::setElem( int idx, float value ) +{ + *(&mX + idx) = value; + return *this; +} + +inline float Quat_ref::getElem( int idx ) const +{ + return *(&mX + idx); +} + +inline float & Quat_ref::operator []( int idx ) +{ + return *(&mX + idx); +} + +inline float Quat_ref::operator []( int idx ) const +{ + return *(&mX + idx); +} + +inline const Quat_ref Quat_ref::operator +( const Quat_ref & quat ) const +{ + return Quat_ref( + ( mX + quat.mX ), + ( mY + quat.mY ), + ( mZ + quat.mZ ), + ( mW + quat.mW ) + ); +} + +inline const Quat_ref Quat_ref::operator -( const Quat_ref & quat ) const +{ + return Quat_ref( + ( mX - quat.mX ), + ( mY - quat.mY ), + ( mZ - quat.mZ ), + ( mW - quat.mW ) + ); +} + +inline const Quat_ref Quat_ref::operator *( float scalar ) const +{ + return Quat_ref( + ( mX * scalar ), + ( mY * scalar ), + ( mZ * scalar ), + ( mW * scalar ) + ); +} + +inline Quat_ref & Quat_ref::operator +=( const Quat_ref & quat ) +{ + *this = *this + quat; + return *this; +} + +inline Quat_ref & Quat_ref::operator -=( const Quat_ref & quat ) +{ + *this = *this - quat; + return *this; +} + +inline Quat_ref & Quat_ref::operator *=( float scalar ) +{ + *this = *this * scalar; + return *this; +} + +inline const Quat_ref Quat_ref::operator /( float scalar ) const +{ + return Quat_ref( + ( mX / scalar ), + ( mY / scalar ), + ( mZ / scalar ), + ( mW / scalar ) + ); +} + +inline Quat_ref & Quat_ref::operator /=( float scalar ) +{ + *this = *this / scalar; + return *this; +} + +inline const Quat_ref Quat_ref::operator -( ) const +{ + return Quat_ref( + -mX, + -mY, + -mZ, + -mW + ); +} + +inline const Quat_ref operator *( float scalar, const Quat_ref & quat ) +{ + return quat * scalar; +} + +inline float dot( const Quat_ref & quat0, const Quat_ref & quat1 ) +{ + float result; + result = ( quat0.getX() * quat1.getX() ); + result = ( result + ( quat0.getY() * quat1.getY() ) ); + result = ( result + ( quat0.getZ() * quat1.getZ() ) ); + result = ( result + ( quat0.getW() * quat1.getW() ) ); + return result; +} + +inline const Quat_ref lerp( float t, const Quat_ref & quat0, const Quat_ref & quat1 ) +{ + return ( quat0 + ( ( quat1 - quat0 ) * t ) ); +} + +inline const Quat_ref slerp( float t, const Quat_ref & unitQuat0, const Quat_ref & unitQuat1 ) +{ + Quat_ref start; + float recipSinAngle, scale0, scale1, cosAngle, angle; + cosAngle = dot( unitQuat0, unitQuat1 ); + if ( cosAngle < 0.0f ) { + cosAngle = -cosAngle; + start = ( -unitQuat0 ); + } else { + start = unitQuat0; + } + if ( cosAngle < _VECTORMATH_SLERP_TOL ) { + angle = acosf( cosAngle ); + recipSinAngle = ( 1.0f / sinf( angle ) ); + scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle ); + scale1 = ( sinf( ( t * angle ) ) * recipSinAngle ); + } else { + scale0 = ( 1.0f - t ); + scale1 = t; + } + return ( ( start * scale0 ) + ( unitQuat1 * scale1 ) ); +} + +inline const Quat_ref squad( float t, const Quat_ref & unitQuat0, const Quat_ref & unitQuat1, const Quat_ref & unitQuat2, const Quat_ref & unitQuat3 ) +{ + Quat_ref tmp0, tmp1; + tmp0 = slerp( t, unitQuat0, unitQuat3 ); + tmp1 = slerp( t, unitQuat1, unitQuat2 ); + return slerp( ( ( 2.0f * t ) * ( 1.0f - t ) ), tmp0, tmp1 ); +} + +inline float norm( const Quat_ref & quat ) +{ + float result; + result = ( quat.getX() * quat.getX() ); + result = ( result + ( quat.getY() * quat.getY() ) ); + result = ( result + ( quat.getZ() * quat.getZ() ) ); + result = ( result + ( quat.getW() * quat.getW() ) ); + return result; +} + +inline float length( const Quat_ref & quat ) +{ + return ::sqrtf( norm( quat ) ); +} + +inline const Quat_ref normalize( const Quat_ref & quat ) +{ + float lenSqr, lenInv; + lenSqr = norm( quat ); + lenInv = ( 1.0f / sqrtf( lenSqr ) ); + return Quat_ref( + ( quat.getX() * lenInv ), + ( quat.getY() * lenInv ), + ( quat.getZ() * lenInv ), + ( quat.getW() * lenInv ) + ); +} + +inline const Quat_ref Quat_ref::rotation( const vmVector3 & unitVec0, const vmVector3 & unitVec1 ) +{ + float cosHalfAngleX2, recipCosHalfAngleX2; + cosHalfAngleX2 = sqrtf( ( 2.0f * ( 1.0f + dot( unitVec0, unitVec1 ) ) ) ); + recipCosHalfAngleX2 = ( 1.0f / cosHalfAngleX2 ); + return Quat_ref( ( cross( unitVec0, unitVec1 ) * recipCosHalfAngleX2 ), ( cosHalfAngleX2 * 0.5f ) ); +} + +inline const Quat_ref Quat_ref::rotation( float radians, const vmVector3 & unitVec ) +{ + float s, c, angle; + angle = ( radians * 0.5f ); + s = sinf( angle ); + c = cosf( angle ); + return Quat_ref( ( unitVec * s ), c ); +} + +inline const Quat_ref Quat_ref::rotationX( float radians ) +{ + float s, c, angle; + angle = ( radians * 0.5f ); + s = sinf( angle ); + c = cosf( angle ); + return Quat_ref( s, 0.0f, 0.0f, c ); +} + +inline const Quat_ref Quat_ref::rotationY( float radians ) +{ + float s, c, angle; + angle = ( radians * 0.5f ); + s = sinf( angle ); + c = cosf( angle ); + return Quat_ref( 0.0f, s, 0.0f, c ); +} + +inline const Quat_ref Quat_ref::rotationZ( float radians ) +{ + float s, c, angle; + angle = ( radians * 0.5f ); + s = sinf( angle ); + c = cosf( angle ); + return Quat_ref( 0.0f, 0.0f, s, c ); +} + +inline const Quat_ref Quat_ref::operator *( const Quat_ref & quat ) const +{ + return Quat_ref( + ( ( ( ( mW * quat.mX ) + ( mX * quat.mW ) ) + ( mY * quat.mZ ) ) - ( mZ * quat.mY ) ), + ( ( ( ( mW * quat.mY ) + ( mY * quat.mW ) ) + ( mZ * quat.mX ) ) - ( mX * quat.mZ ) ), + ( ( ( ( mW * quat.mZ ) + ( mZ * quat.mW ) ) + ( mX * quat.mY ) ) - ( mY * quat.mX ) ), + ( ( ( ( mW * quat.mW ) - ( mX * quat.mX ) ) - ( mY * quat.mY ) ) - ( mZ * quat.mZ ) ) + ); +} + +inline Quat_ref & Quat_ref::operator *=( const Quat_ref & quat ) +{ + *this = *this * quat; + return *this; +} + +inline const vmVector3 rotate( const Quat_ref & quat, const vmVector3 & vec ) +{ + float tmpX, tmpY, tmpZ, tmpW; + tmpX = ( ( ( quat.getW() * vec.getX() ) + ( quat.getY() * vec.getZ() ) ) - ( quat.getZ() * vec.getY() ) ); + tmpY = ( ( ( quat.getW() * vec.getY() ) + ( quat.getZ() * vec.getX() ) ) - ( quat.getX() * vec.getZ() ) ); + tmpZ = ( ( ( quat.getW() * vec.getZ() ) + ( quat.getX() * vec.getY() ) ) - ( quat.getY() * vec.getX() ) ); + tmpW = ( ( ( quat.getX() * vec.getX() ) + ( quat.getY() * vec.getY() ) ) + ( quat.getZ() * vec.getZ() ) ); + return vmVector3( + ( ( ( ( tmpW * quat.getX() ) + ( tmpX * quat.getW() ) ) - ( tmpY * quat.getZ() ) ) + ( tmpZ * quat.getY() ) ), + ( ( ( ( tmpW * quat.getY() ) + ( tmpY * quat.getW() ) ) - ( tmpZ * quat.getX() ) ) + ( tmpX * quat.getZ() ) ), + ( ( ( ( tmpW * quat.getZ() ) + ( tmpZ * quat.getW() ) ) - ( tmpX * quat.getY() ) ) + ( tmpY * quat.getX() ) ) + ); +} + +inline const Quat_ref conj( const Quat_ref & quat ) +{ + return Quat_ref( -quat.getX(), -quat.getY(), -quat.getZ(), quat.getW() ); +} + +inline const Quat_ref select( const Quat_ref & quat0, const Quat_ref & quat1, bool select1 ) +{ + return Quat_ref( + ( select1 )? quat1.getX() : quat0.getX(), + ( select1 )? quat1.getY() : quat0.getY(), + ( select1 )? quat1.getZ() : quat0.getZ(), + ( select1 )? quat1.getW() : quat0.getW() + ); +} + + + +#define LOOPCOUNT 1000 +#define NUM_CYCLES 10000 +#define DATA_SIZE 1024 + +int Test_quat_aos_neon(void) +{ + + return 0; +} + +#endif + diff --git a/test/Bullet2/Source/Tests/Test_quat_aos_neon.h b/test/Bullet2/Source/Tests/Test_quat_aos_neon.h new file mode 100644 index 0000000000..e751a41be4 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_quat_aos_neon.h @@ -0,0 +1,21 @@ +// +// Test_quat_aos_neon.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc., Inc. +// + +#ifndef BulletTest_Test_quat_aos_neon_h +#define BulletTest_Test_quat_aos_neon_h + +#ifdef __cplusplus +extern "C" { +#endif + + int Test_quat_aos_neon(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3cross.cpp b/test/Bullet2/Source/Tests/Test_v3cross.cpp new file mode 100644 index 0000000000..00ff4e4212 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3cross.cpp @@ -0,0 +1,181 @@ +// +// Test_v3cross.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_v3cross.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static btVector3& v3cross_ref(btVector3& v1, btVector3& v2); + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +int Test_v3cross(void) +{ + btVector3 v1, v2, v3; + + float x,y,z,w; + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = BT_NAN; // w channel NaN + v1.setValue(x,y,z); + v1.setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v2.setValue(x,y,z); + v2.setW(w); + + v3 = v1; + + btVector3 correct_res, test_res; + + { + float vNaN = BT_NAN; + correct_res.setValue(vNaN, vNaN, vNaN); + test_res.setValue(vNaN, vNaN, vNaN); + correct_res = v3cross_ref(v1, v2); + test_res = v3.cross(v2); + + if( fabs(correct_res.m_floats[0] - test_res.m_floats[0]) + + fabs(correct_res.m_floats[1] - test_res.m_floats[1]) + + fabs(correct_res.m_floats[2] - test_res.m_floats[2]) > FLT_EPSILON * 4) + { + vlog( "Error - v3cross result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f) \n", + correct_res.m_floats[0], correct_res.m_floats[1], correct_res.m_floats[2], + test_res.m_floats[0], test_res.m_floats[1], test_res.m_floats[2]); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btVector3 vec3_arr1[DATA_SIZE]; + btVector3 vec3_arr2[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr2[k].setValue(x,y,z); + vec3_arr2[k].setW(w); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + vec3_arr1[k] = v3cross_ref(vec3_arr1[k], vec3_arr2[k]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr2[k].setValue(x,y,z); + vec3_arr2[k].setW(w); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + vec3_arr1[k] = vec3_arr1[k].cross(vec3_arr2[k]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + +static btVector3& v3cross_ref(btVector3& v1, btVector3& v2) +{ + btScalar x,y,z; + x = v1.m_floats[1] * v2.m_floats[2] - v1.m_floats[2] * v2.m_floats[1]; + y = v1.m_floats[2] * v2.m_floats[0] - v1.m_floats[0] * v2.m_floats[2]; + z = v1.m_floats[0] * v2.m_floats[1] - v1.m_floats[1] * v2.m_floats[0]; + + v1.m_floats[0] = x; + v1.m_floats[1] = y; + v1.m_floats[2] = z; + + return v1; +} + + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_v3cross.h b/test/Bullet2/Source/Tests/Test_v3cross.h new file mode 100644 index 0000000000..79854fe917 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3cross.h @@ -0,0 +1,22 @@ +// +// Test_v3cross.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3cross_h +#define BulletTest_Test_v3cross_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3cross(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3div.cpp b/test/Bullet2/Source/Tests/Test_v3div.cpp new file mode 100644 index 0000000000..bd58002898 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3div.cpp @@ -0,0 +1,178 @@ +// +// Test_v3div.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_v3div.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +#define BT_OP(a, b) ((a) / (b)) +// reference code for testing purposes +static inline btVector3& v3div_ref(btVector3& v1, btVector3& v2); + +static btVector3& v3div_ref(btVector3& v0, btVector3& v1, btVector3& v2) +{ + v0.m_floats[0] = BT_OP(v1.m_floats[0] , v2.m_floats[0]), + v0.m_floats[1] = BT_OP(v1.m_floats[1] , v2.m_floats[1]), + v0.m_floats[2] = BT_OP(v1.m_floats[2] , v2.m_floats[2]); + + return v0; +} + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +int Test_v3div(void) +{ + btVector3 v1, v2, v3; + + float x,y,z,w; + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = BT_NAN; // w channel NaN + v1.setValue(x,y,z); + v1.setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v2.setValue(x,y,z); + v2.setW(w); + + v3 = v1; + + btVector3 correct_res, test_res; + + { + float vNaN = BT_NAN; + correct_res.setValue(vNaN, vNaN, vNaN); + test_res.setValue(vNaN, vNaN, vNaN); + correct_res = v3div_ref(correct_res, v1, v2); + test_res = BT_OP(v3,v2); + + if( fabsf(correct_res.m_floats[0] - test_res.m_floats[0]) + + fabsf(correct_res.m_floats[1] - test_res.m_floats[1]) + + fabsf(correct_res.m_floats[2] - test_res.m_floats[2]) > FLT_EPSILON*10 ) + { + vlog( "Error - v3div result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f) \n", + correct_res.m_floats[0], correct_res.m_floats[1], correct_res.m_floats[2], + test_res.m_floats[0], test_res.m_floats[1], test_res.m_floats[2]); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btVector3 vec3_arr0[DATA_SIZE]; + btVector3 vec3_arr1[DATA_SIZE]; + btVector3 vec3_arr2[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + w = BT_NAN; // w channel NaN + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr2[k].setValue(x,y,z); + vec3_arr2[k].setW(w); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + vec3_arr0[k] = v3div_ref(vec3_arr0[k], vec3_arr1[k], vec3_arr2[k]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr2[k].setValue(x,y,z); + vec3_arr2[k].setW(w); + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + vec3_arr0[k] = BT_OP(vec3_arr1[k] , vec3_arr2[k]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_v3div.h b/test/Bullet2/Source/Tests/Test_v3div.h new file mode 100644 index 0000000000..21bfb6131a --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3div.h @@ -0,0 +1,22 @@ +// +// Test_v3div.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3div_h +#define BulletTest_Test_v3div_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3div(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3dot.cpp b/test/Bullet2/Source/Tests/Test_v3dot.cpp new file mode 100644 index 0000000000..caa2967d2c --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3dot.cpp @@ -0,0 +1,164 @@ +// +// Test_v3dot.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_v3dot.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static inline +btScalar v3dot_ref( + const btVector3& v1, + const btVector3& v2); + +#define LOOPCOUNT 1000 +#define NUM_CYCLES 10000 + +int Test_v3dot(void) +{ + btVector3 v1, v2; + + float x,y,z,w; + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = BT_NAN; // w channel NaN + v1.setValue(x,y,z); + v1.setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v2.setValue(x,y,z); + v2.setW(w); + + float correctDot0, testDot0; + + { + correctDot0 = w; + testDot0 = w; ; + correctDot0 = v3dot_ref(v1, v2); + testDot0 = v1.dot(v2); + + if( fabsf(correctDot0 - testDot0) > FLT_EPSILON * 4 ) + { + vlog( "Error - v3dot result error! %f != %f \n", correctDot0, testDot0); + + return 1; + } + } + +#define DATA_SIZE 1024 + + btVector3 vec3_arr1[DATA_SIZE]; + btVector3 vec3_arr2[DATA_SIZE]; + btScalar res_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr2[k].setValue(x,y,z); + vec3_arr2[k].setW(w); + + res_arr[k] = w; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t k32 = (k & (DATA_SIZE-1)); + res_arr[k32] = v3dot_ref( vec3_arr1[k32], vec3_arr2[k32]); k32++; + res_arr[k32] = v3dot_ref( vec3_arr1[k32], vec3_arr2[k32]); k32++; + res_arr[k32] = v3dot_ref( vec3_arr1[k32], vec3_arr2[k32]); k32++; + res_arr[k32] = v3dot_ref( vec3_arr1[k32], vec3_arr2[k32]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t k32 = k & (DATA_SIZE -1); + res_arr[k32] = vec3_arr1[k32].dot(vec3_arr2[k32]); k32++; + res_arr[k32] = vec3_arr1[k32].dot(vec3_arr2[k32]); k32++; + res_arr[k32] = vec3_arr1[k32].dot(vec3_arr2[k32]); k32++; + res_arr[k32] = vec3_arr1[k32].dot(vec3_arr2[k32]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + + +static btScalar v3dot_ref(const btVector3& v1, + const btVector3& v2) +{ + return (v1.m_floats[0] * v2.m_floats[0] + + v1.m_floats[1] * v2.m_floats[1] + + v1.m_floats[2] * v2.m_floats[2]); +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_v3dot.h b/test/Bullet2/Source/Tests/Test_v3dot.h new file mode 100644 index 0000000000..b80a3af64c --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3dot.h @@ -0,0 +1,22 @@ +// +// Test_v3dot.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3dot_h +#define BulletTest_Test_v3dot_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3dot(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3interp.cpp b/test/Bullet2/Source/Tests/Test_v3interp.cpp new file mode 100644 index 0000000000..b03377597d --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3interp.cpp @@ -0,0 +1,195 @@ +// +// Test_v3interp.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_v3interp.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static inline +btVector3& v3interp_ref( + btVector3& vr, + btVector3& v0, + btVector3& v1, + btScalar& rt); + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +int Test_v3interp(void) +{ + btVector3 v1, v2; + btScalar rt; + + float x,y,z,w; + + float vNaN = BT_NAN; + w = BT_NAN; // w channel NaN + + btVector3 correct_res, test_res; + + for (rt = 0.0f; rt <= 1.0f; rt += 0.1f) + { + correct_res.setValue(vNaN, vNaN, vNaN); + test_res.setValue(vNaN, vNaN, vNaN); + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v1.setValue(x,y,z); + v1.setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v2.setValue(x,y,z); + v2.setW(w); + + correct_res = v3interp_ref(correct_res, v1, v2, rt); + test_res.setInterpolate3(v1, v2, rt); + + if( fabs(correct_res.m_floats[0] - test_res.m_floats[0]) + + fabs(correct_res.m_floats[1] - test_res.m_floats[1]) + + fabs(correct_res.m_floats[2] - test_res.m_floats[2]) > FLT_EPSILON * 4) + { + vlog( "Error - v3interp result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f) \n" + "\n rt=%10.4f", + correct_res.m_floats[0], correct_res.m_floats[1], correct_res.m_floats[2], + test_res.m_floats[0], test_res.m_floats[1], test_res.m_floats[2], rt); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btVector3 vec3_arr1[DATA_SIZE]; + btVector3 vec3_arr2[DATA_SIZE]; + btScalar rt_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr2[k].setValue(x,y,z); + vec3_arr2[k].setW(w); + + rt_arr[k] = RANDF_01; + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + v3interp_ref(vec3_arr1[k], vec3_arr1[k], vec3_arr2[k], rt_arr[k]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr2[k].setValue(x,y,z); + vec3_arr2[k].setW(w); + + rt_arr[k] = RANDF_01; + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + vec3_arr1[k].setInterpolate3(vec3_arr1[k], vec3_arr2[k], rt_arr[k]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + +static btVector3& +v3interp_ref( + btVector3& vr, + btVector3& v0, + btVector3& v1, + btScalar& rt) +{ + btScalar s = btScalar(1.0) - rt; + vr.m_floats[0] = s * v0.m_floats[0] + rt * v1.m_floats[0]; + vr.m_floats[1] = s * v0.m_floats[1] + rt * v1.m_floats[1]; + vr.m_floats[2] = s * v0.m_floats[2] + rt * v1.m_floats[2]; + + return vr; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_v3interp.h b/test/Bullet2/Source/Tests/Test_v3interp.h new file mode 100644 index 0000000000..502b1ad739 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3interp.h @@ -0,0 +1,22 @@ +// +// Test_v3interp.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3interp_h +#define BulletTest_Test_v3interp_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3interp(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3lerp.cpp b/test/Bullet2/Source/Tests/Test_v3lerp.cpp new file mode 100644 index 0000000000..311d0bd4e6 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3lerp.cpp @@ -0,0 +1,198 @@ +// +// Test_v3lerp.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_v3lerp.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static inline +btVector3& +v3lerp_ref( + btVector3& vr, + btVector3& v0, + btVector3& v1, + btScalar& rt); + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +int Test_v3lerp(void) +{ + btVector3 v1, v2; + btScalar rt; + + float x,y,z,w; + + float vNaN =BT_NAN; + w =BT_NAN; // w channel NaN + + btVector3 correct_res, test_res; + + for (rt = 0.0f; rt <= 1.0f; rt += 0.1f) + { + correct_res.setValue(vNaN, vNaN, vNaN); + test_res.setValue(vNaN, vNaN, vNaN); + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v1.setValue(x,y,z); + v1.setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v2.setValue(x,y,z); + v2.setW(w); + + correct_res = v3lerp_ref(correct_res, v1, v2, rt); + test_res = v1.lerp(v2, rt); + + if( fabs(correct_res.m_floats[0] - test_res.m_floats[0]) + + fabs(correct_res.m_floats[1] - test_res.m_floats[1]) + + fabs(correct_res.m_floats[2] - test_res.m_floats[2]) > FLT_EPSILON * 4) + { + vlog( "Error - v3lerp result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f) \n" + "\n rt=%10.4f", + correct_res.m_floats[0], correct_res.m_floats[1], correct_res.m_floats[2], + test_res.m_floats[0], test_res.m_floats[1], test_res.m_floats[2], rt); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btVector3 vec3_arr1[DATA_SIZE]; + btVector3 vec3_arr2[DATA_SIZE]; + btScalar rt_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + w =BT_NAN; // w channel NaN + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr2[k].setValue(x,y,z); + vec3_arr2[k].setW(w); + + rt_arr[k] = RANDF_01; + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + v3lerp_ref(vec3_arr1[k], vec3_arr1[k], vec3_arr2[k], rt_arr[k]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr2[k].setValue(x,y,z); + vec3_arr2[k].setW(w); + + rt_arr[k] = RANDF_01; + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + vec3_arr1[k] = vec3_arr1[k].lerp(vec3_arr2[k], rt_arr[k]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + +static +btVector3& +v3lerp_ref( + btVector3& vr, + btVector3& v0, + btVector3& v1, + btScalar& rt) +{ + vr.m_floats[0] = v0.m_floats[0] + rt * (v1.m_floats[0] - v0.m_floats[0]); + vr.m_floats[1] = v0.m_floats[1] + rt * (v1.m_floats[1] - v0.m_floats[1]); + vr.m_floats[2] = v0.m_floats[2] + rt * (v1.m_floats[2] - v0.m_floats[2]); + + return vr; +} + +#endif //BT_USE_SSE + diff --git a/test/Bullet2/Source/Tests/Test_v3lerp.h b/test/Bullet2/Source/Tests/Test_v3lerp.h new file mode 100644 index 0000000000..a38a12c197 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3lerp.h @@ -0,0 +1,22 @@ +// +// Test_v3lerp.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3lerp_h +#define BulletTest_Test_v3lerp_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3lerp(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3norm.cpp b/test/Bullet2/Source/Tests/Test_v3norm.cpp new file mode 100644 index 0000000000..51e0dd35c5 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3norm.cpp @@ -0,0 +1,170 @@ +// +// Test_v3norm.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_v3norm.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static inline btVector3& v3norm_ref(btVector3& v); + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 1000 + +int Test_v3norm(void) +{ + btVector3 v1, v2; + + float x,y,z,w; + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = BT_NAN; // w channel NaN + v1.setValue(x,y,z); + v1.setW(w); + + v2 = v1; + + btVector3 correct_res, test_res; + + { + float vNaN = BT_NAN; + correct_res.setValue(vNaN, vNaN, vNaN); + test_res.setValue(vNaN, vNaN, vNaN); + correct_res = v3norm_ref(v1); + test_res = v2.normalize(); + + if( fabs(correct_res.m_floats[0] - test_res.m_floats[0]) + + fabs(correct_res.m_floats[1] - test_res.m_floats[1]) + + fabs(correct_res.m_floats[2] - test_res.m_floats[2]) > FLT_EPSILON * 4) + { + vlog( "Error - v3norm result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f) \n", + correct_res.m_floats[0], correct_res.m_floats[1], correct_res.m_floats[2], + test_res.m_floats[0], test_res.m_floats[1], test_res.m_floats[2]); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btVector3 vec3_arr0[DATA_SIZE]; + btVector3 vec3_arr1[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + } + + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + vec3_arr0[k] = v3norm_ref(vec3_arr1[k]); + vec3_arr0[k+1] = v3norm_ref(vec3_arr1[k+1]); + vec3_arr0[k+2] = v3norm_ref(vec3_arr1[k+2]); + vec3_arr0[k+3] = v3norm_ref(vec3_arr1[k+3]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + } + + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + vec3_arr0[k] = vec3_arr1[k].normalize(); + vec3_arr0[k+1] = vec3_arr1[k+1].normalize(); + vec3_arr0[k+2] = vec3_arr1[k+2].normalize(); + vec3_arr0[k+3] = vec3_arr1[k+3].normalize(); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + +static btVector3& v3norm_ref(btVector3& v) +{ + float dot = v.m_floats[0] * v.m_floats[0] + + v.m_floats[1] * v.m_floats[1] + + v.m_floats[2] * v.m_floats[2]; + + dot = 1.0f / sqrtf(dot); + v.m_floats[0] *= dot; + v.m_floats[1] *= dot; + v.m_floats[2] *= dot; + + return v; +} + +#endif //BT_USE_SSE + diff --git a/test/Bullet2/Source/Tests/Test_v3norm.h b/test/Bullet2/Source/Tests/Test_v3norm.h new file mode 100644 index 0000000000..5b86b4acd6 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3norm.h @@ -0,0 +1,22 @@ +// +// Test_v3norm.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3norm_h +#define BulletTest_Test_v3norm_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3norm(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3rotate.cpp b/test/Bullet2/Source/Tests/Test_v3rotate.cpp new file mode 100644 index 0000000000..8c3aea99bd --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3rotate.cpp @@ -0,0 +1,194 @@ +// +// Test_v3rotate.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_v3rotate.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static inline +btVector3& v3rotate_ref( + btVector3& v0, + btVector3& v1, + const btScalar& s); + +#define LOOPCOUNT 2048 +#define NUM_CYCLES 1000 + +int Test_v3rotate(void) +{ + btVector3 v1, v2; + float s; + + float x,y,z,w; + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = BT_NAN; // w channel NaN + v1.setValue(x,y,z); + v1.setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v2.setValue(x,y,z); + v2.setW(w); + + s = RANDF_01 * (float) SIMD_PI; + + btVector3 correct_res, test_res; + + { + float vNaN = BT_NAN; + correct_res.setValue(vNaN, vNaN, vNaN); + test_res.setValue(vNaN, vNaN, vNaN); + test_res = v1.rotate(v2, s); + correct_res = v3rotate_ref(v1, v2, s); + + if( fabs(correct_res.m_floats[0] - test_res.m_floats[0]) + + fabs(correct_res.m_floats[1] - test_res.m_floats[1]) + + fabs(correct_res.m_floats[2] - test_res.m_floats[2]) > FLT_EPSILON * 4) + { + vlog( "Error - v3rotate result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f) \n", + correct_res.m_floats[0], correct_res.m_floats[1], correct_res.m_floats[2], + test_res.m_floats[0], test_res.m_floats[1], test_res.m_floats[2]); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btVector3 vec3_arr0[DATA_SIZE]; + btVector3 vec3_arr1[DATA_SIZE]; + btScalar s_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr0[k].setValue(x,y,z); + vec3_arr0[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + s_arr[k] = RANDF_01 * (float)SIMD_PI; + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + vec3_arr0[k] = v3rotate_ref(vec3_arr0[k], vec3_arr1[k], s_arr[k]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr0[k].setValue(x,y,z); + vec3_arr0[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr1[k].setValue(x,y,z); + vec3_arr1[k].setW(w); + + s_arr[k] = RANDF_01 * (float)SIMD_PI; + } + + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + vec3_arr0[k ] = vec3_arr0[k ].rotate(vec3_arr1[k ], s_arr[k]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + +static inline +btVector3& +v3rotate_ref( + btVector3& v0, + btVector3& wAxis, + const btScalar& _angle) +{ + btVector3 o = wAxis * wAxis.dot( v0 ); + btVector3 _x = v0 - o; + btVector3 _y; + + _y = wAxis.cross( v0 ); + + v0 = o + _x * cosf( _angle ) + _y * sinf( _angle ); + + return v0; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_v3rotate.h b/test/Bullet2/Source/Tests/Test_v3rotate.h new file mode 100644 index 0000000000..0c40fc4a49 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3rotate.h @@ -0,0 +1,22 @@ +// +// Test_v3rotate.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3rotate_h +#define BulletTest_Test_v3rotate_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3rotate(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3sdiv.cpp b/test/Bullet2/Source/Tests/Test_v3sdiv.cpp new file mode 100644 index 0000000000..43d5735ad1 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3sdiv.cpp @@ -0,0 +1,181 @@ +// +// Test_v3sdiv.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + + +#include "Test_v3sdiv.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static inline +btVector3& v3sdiv_ref( + btVector3& v, + const btScalar& s); + +#define LOOPCOUNT 2048 +#define NUM_CYCLES 1000 + +int Test_v3sdiv(void) +{ + btVector3 v1, v2; + btScalar s; + + float x,y,z,w; + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = BT_NAN; // w channel NaN + v1.setValue(x,y,z); + v1.setW(w); + + v2.setValue(x,y,z); + v2.setW(w); + + s = (float) RANDF_16; + + btVector3 correct_res, test_res; + + { + float vNaN = BT_NAN; + correct_res.setValue(vNaN, vNaN, vNaN); + test_res.setValue(vNaN, vNaN, vNaN); + correct_res = v3sdiv_ref(v1, s); + test_res = (v2 /= s); + + if( fabs(correct_res.m_floats[0] - test_res.m_floats[0]) + + fabs(correct_res.m_floats[1] - test_res.m_floats[1]) + + fabs(correct_res.m_floats[2] - test_res.m_floats[2]) > FLT_EPSILON * 4) + { + vlog( "Error - v3sdiv result error! " + "\ncorrect = (%10.4f, %10.4f, %10.4f) " + "\ntested = (%10.4f, %10.4f, %10.4f) \n", + correct_res.m_floats[0], correct_res.m_floats[1], correct_res.m_floats[2], + test_res.m_floats[0], test_res.m_floats[1], test_res.m_floats[2]); + + return 1; + } + } + +#define DATA_SIZE LOOPCOUNT + + btVector3 vec3_arr[DATA_SIZE]; + btScalar s_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = uint64_t(-1LL); + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr[k].setValue(x,y,z); + vec3_arr[k].setW(w); + + s_arr[k] = RANDF_01; + } + + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + v3sdiv_ref( vec3_arr[k], s_arr[k]); + v3sdiv_ref( vec3_arr[k+1], s_arr[k+1]); + v3sdiv_ref( vec3_arr[k+2], s_arr[k+2]); + v3sdiv_ref( vec3_arr[k+3], s_arr[k+3]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + vec3_arr[k].setValue(x,y,z); + vec3_arr[k].setW(w); + + s_arr[k] = RANDF_01; + } + + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + vec3_arr[k] /= s_arr[k]; + vec3_arr[k+1] /= s_arr[k+1]; + vec3_arr[k+2] /= s_arr[k+2]; + vec3_arr[k+3] /= s_arr[k+3]; + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, + TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + +static inline +btVector3& +v3sdiv_ref( + btVector3& v, + const btScalar& s) +{ + btScalar recip = btScalar(1.0) / s; + + v.m_floats[0] *= recip; + v.m_floats[1] *= recip; + v.m_floats[2] *= recip; + + return v; +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_v3sdiv.h b/test/Bullet2/Source/Tests/Test_v3sdiv.h new file mode 100644 index 0000000000..648715e09a --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3sdiv.h @@ -0,0 +1,22 @@ +// +// Test_v3sdiv.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3sdiv_h +#define BulletTest_Test_v3sdiv_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3sdiv(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3skew.cpp b/test/Bullet2/Source/Tests/Test_v3skew.cpp new file mode 100644 index 0000000000..a9c90fb25f --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3skew.cpp @@ -0,0 +1,197 @@ +// +// Test_v3skew.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_v3skew.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static void +v3skew_ref( + const btVector3* v, + btVector3* v1, + btVector3* v2, + btVector3* v3); + +#define LOOPCOUNT 2048 +#define NUM_CYCLES 10000 + +int Test_v3skew(void) +{ + btVector3 v, v1, v2, v3, vt1, vt2, vt3; + + float x,y,z,w; + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = BT_NAN; // w channel NaN + v.setValue(x,y,z); + v.setW(w); + + v1.setValue(w,w,w); + v1.setW(w); + + vt3 = vt2 = vt1 = v3 = v2 = v1; + + { + v3skew_ref(&v, &v1, &v2, &v3); + v.getSkewSymmetricMatrix(&vt1, &vt2, &vt3); + /* + if( v1.m_floats[0] != vt1.m_floats[0] || + v1.m_floats[1] != vt1.m_floats[1] || + v1.m_floats[2] != vt1.m_floats[2] ) + */ + if(!(v1 == vt1)) + { + vlog( "Error - v3skew result error! " + "\ncorrect v1 = (%10.4f, %10.4f, %10.4f) " + "\ntested v1 = (%10.4f, %10.4f, %10.4f) \n", + v1.m_floats[0], v1.m_floats[1], v1.m_floats[2], + vt1.m_floats[0], vt1.m_floats[1], vt1.m_floats[2]); + + return 1; + } + + /* + if( v2.m_floats[0] != vt2.m_floats[0] || + v2.m_floats[1] != vt2.m_floats[1] || + v2.m_floats[2] != vt2.m_floats[2] ) + */ + if(!(v2 == vt2)) + { + vlog( "Error - v3skew result error! " + "\ncorrect v2 = (%10.4f, %10.4f, %10.4f) " + "\ntested v2 = (%10.4f, %10.4f, %10.4f) \n", + v2.m_floats[0], v2.m_floats[1], v2.m_floats[2], + vt2.m_floats[0], vt2.m_floats[1], vt2.m_floats[2]); + + return 1; + } + + /* + if( v3.m_floats[0] != vt3.m_floats[0] || + v3.m_floats[1] != vt3.m_floats[1] || + v3.m_floats[2] != vt3.m_floats[2] ) + */ + if(!(v3 == vt3)) + { + vlog( "Error - v3skew result error! " + "\ncorrect v3 = (%10.4f, %10.4f, %10.4f) " + "\ntested v3 = (%10.4f, %10.4f, %10.4f) \n", + v3.m_floats[0], v3.m_floats[1], v3.m_floats[2], + vt3.m_floats[0], vt3.m_floats[1], vt3.m_floats[2]); + + return 1; + } + } + +#define DATA_SIZE 256 + + btVector3 v3_arr0[DATA_SIZE]; + btVector3 v3_arr1[DATA_SIZE]; + btVector3 v3_arr2[DATA_SIZE]; + btVector3 v3_arr3[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v3_arr0[k].setValue(x,y,z); + v3_arr0[k].setW(w); + + v3_arr1[k].setValue(w,w,w); + v3_arr1[k].setW(w); + + v3_arr3[k] = v3_arr2[k] = v3_arr1[k]; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + size_t k32 = (k & (DATA_SIZE-1)); + v3skew_ref( &v3_arr0[k32], &v3_arr1[k32], &v3_arr2[k32], &v3_arr3[k32]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = -1LL; + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k < LOOPCOUNT; k++ ) + { + size_t k32 = (k & (DATA_SIZE -1)); + v3_arr0[k32].getSkewSymmetricMatrix(&v3_arr1[k32], &v3_arr2[k32], &v3_arr3[k32]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + + +static void +v3skew_ref( + const btVector3* v, + btVector3* v1, + btVector3* v2, + btVector3* v3) +{ + v1->setValue(0. ,-v->z(),v->y()); + v2->setValue(v->z() ,0. ,-v->x()); + v3->setValue(-v->y(),v->x() ,0.); +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_v3skew.h b/test/Bullet2/Source/Tests/Test_v3skew.h new file mode 100644 index 0000000000..255f4a2256 --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3skew.h @@ -0,0 +1,22 @@ +// +// Test_v3skew.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3skew_h +#define BulletTest_Test_v3skew_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3skew(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Tests/Test_v3triple.cpp b/test/Bullet2/Source/Tests/Test_v3triple.cpp new file mode 100644 index 0000000000..f0ecbd48ed --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3triple.cpp @@ -0,0 +1,180 @@ +// +// Test_v3triple.cpp +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + + + +#include "LinearMath/btScalar.h" +#if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON) + +#include "Test_v3triple.h" +#include "vector.h" +#include "Utils.h" +#include "main.h" +#include +#include + +#include + +// reference code for testing purposes +static btScalar +v3triple_ref( + const btVector3& v, + const btVector3& v1, + const btVector3& v2); + +#define LOOPCOUNT 1024 +#define NUM_CYCLES 10000 + +int Test_v3triple(void) +{ + btVector3 v1, v2, v3; + + float x,y,z,w; + + // Init the data + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + w = BT_NAN; // w channel NaN + v1.setValue(x,y,z); + v1.setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v2.setValue(x,y,z); + v2.setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v3.setValue(x,y,z); + v3.setW(w); + + float correctTriple0, testTriple0; + + { + correctTriple0 = w; + testTriple0 = w; + testTriple0 = v3triple_ref(v1,v2,v3); + correctTriple0 = v1.triple(v2, v3); + + if( fabsf(correctTriple0 - testTriple0) > FLT_EPSILON * 4 ) + { + vlog( "Error - v3triple result error! %f != %f \n", correctTriple0, testTriple0); + + return 1; + } + } + +#define DATA_SIZE 1024 + + btVector3 v3_arr1[DATA_SIZE]; + btVector3 v3_arr2[DATA_SIZE]; + btVector3 v3_arr3[DATA_SIZE]; + btScalar res_arr[DATA_SIZE]; + + uint64_t scalarTime; + uint64_t vectorTime; + size_t j, k; + + for( k = 0; k < DATA_SIZE; k++ ) + { + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v3_arr1[k].setValue(x,y,z); + v3_arr1[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v3_arr2[k].setValue(x,y,z); + v3_arr2[k].setW(w); + + x = RANDF_01; + y = RANDF_01; + z = RANDF_01; + v3_arr3[k].setValue(x,y,z); + v3_arr3[k].setW(w); + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = uint64_t(-1LL); + scalarTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t k32 = (k & (DATA_SIZE-1)); + res_arr[k32] = v3triple_ref( v3_arr1[k32], v3_arr2[k32], v3_arr3[k32]); k32++; + res_arr[k32] = v3triple_ref( v3_arr1[k32], v3_arr2[k32], v3_arr3[k32]); k32++; + res_arr[k32] = v3triple_ref( v3_arr1[k32], v3_arr2[k32], v3_arr3[k32]); k32++; + res_arr[k32] = v3triple_ref( v3_arr1[k32], v3_arr2[k32], v3_arr3[k32]); + } + currentTime = ReadTicks() - startTime; + scalarTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + scalarTime = bestTime; + else + scalarTime /= NUM_CYCLES; + } + + { + uint64_t startTime, bestTime, currentTime; + + bestTime = uint64_t(-1LL); + vectorTime = 0; + for (j = 0; j < NUM_CYCLES; j++) + { + startTime = ReadTicks(); + for( k = 0; k+4 <= LOOPCOUNT; k+=4 ) + { + size_t k32 = k & (DATA_SIZE -1); + res_arr[k32] = v3_arr1[k32].triple(v3_arr2[k32], v3_arr3[k32]); k32++; + res_arr[k32] = v3_arr1[k32].triple(v3_arr2[k32], v3_arr3[k32]); k32++; + res_arr[k32] = v3_arr1[k32].triple(v3_arr2[k32], v3_arr3[k32]); k32++; + res_arr[k32] = v3_arr1[k32].triple(v3_arr2[k32], v3_arr3[k32]); + } + currentTime = ReadTicks() - startTime; + vectorTime += currentTime; + if( currentTime < bestTime ) + bestTime = currentTime; + } + if( 0 == gReportAverageTimes ) + vectorTime = bestTime; + else + vectorTime /= NUM_CYCLES; + } + + vlog( "Timing:\n" ); + vlog( " \t scalar\t vector\n" ); + vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT, TicksToCycles( vectorTime ) / LOOPCOUNT ); + + return 0; +} + + +static btScalar +v3triple_ref( + const btVector3& v, + const btVector3& v1, + const btVector3& v2) +{ + return + v.m_floats[0] * (v1.m_floats[1] * v2.m_floats[2] - v1.m_floats[2] * v2.m_floats[1]) + + v.m_floats[1] * (v1.m_floats[2] * v2.m_floats[0] - v1.m_floats[0] * v2.m_floats[2]) + + v.m_floats[2] * (v1.m_floats[0] * v2.m_floats[1] - v1.m_floats[1] * v2.m_floats[0]); +} + +#endif //BT_USE_SSE diff --git a/test/Bullet2/Source/Tests/Test_v3triple.h b/test/Bullet2/Source/Tests/Test_v3triple.h new file mode 100644 index 0000000000..16fcf2b74b --- /dev/null +++ b/test/Bullet2/Source/Tests/Test_v3triple.h @@ -0,0 +1,22 @@ +// +// Test_v3triple.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Test_v3triple_h +#define BulletTest_Test_v3triple_h + +#ifdef __cplusplus +extern "C" { +#endif + +int Test_v3triple(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/test/Bullet2/Source/Utils.cpp b/test/Bullet2/Source/Utils.cpp new file mode 100644 index 0000000000..830f53a843 --- /dev/null +++ b/test/Bullet2/Source/Utils.cpp @@ -0,0 +1,272 @@ +// +// File.c +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#include +#ifdef __APPLE__ +#include +#include +#include +#include +#else +#include "LinearMath/btAlignedAllocator.h" + +#endif //__APPLE__ + +#include + +#include "Utils.h" + +#pragma mark Timing + +int gReportNanoseconds = 0; + +#ifdef _WIN32 +#include +uint64_t ReadTicks( void ) +{ + return __rdtsc(); +} +double TicksToCycles( uint64_t delta ) +{ + return double(delta); +} + +double TicksToSeconds( uint64_t delta ) +{ + return double(delta); +} + +void *GuardCalloc( size_t count, size_t size, size_t *objectStride ) +{ + if (objectStride) + *objectStride = size; + return (void*) btAlignedAlloc(count * size,16); +} +void GuardFree( void *buf ) +{ + btAlignedFree(buf); +} + +#endif + + +#ifdef __APPLE__ + +uint64_t ReadTicks( void ) +{ + return mach_absolute_time(); +} + +double TicksToCycles( uint64_t delta ) +{ + static long double conversion = 0.0L; + if( 0.0L == conversion ) + { + // attempt to get conversion to nanoseconds + mach_timebase_info_data_t info; + int err = mach_timebase_info( &info ); + if( err ) + return __builtin_nanf(""); + conversion = (long double) info.numer / info.denom; + + // attempt to get conversion to cycles + if( 0 == gReportNanoseconds ) + { + uint64_t frequency = 0; + size_t freq_size = sizeof( frequency ); + err = sysctlbyname( "hw.cpufrequency_max", &frequency, &freq_size, NULL, 0 ); + if( err || 0 == frequency ) + vlog( "Failed to get max cpu frequency. Reporting times as nanoseconds.\n" ); + else + { + conversion *= 1e-9L /* sec / ns */ * frequency /* cycles / sec */; + vlog( "Reporting times as cycles. (%2.2f MHz)\n", 1e-6 * frequency ); + } + } + else + vlog( "Reporting times as nanoseconds.\n" ); + } + + return (double) (delta * conversion); +} + +double TicksToSeconds( uint64_t delta ) +{ + static long double conversion = 0.0L; + if( 0.0L == conversion ) + { + // attempt to get conversion to nanoseconds + mach_timebase_info_data_t info; + int err = mach_timebase_info( &info ); + if( err ) + return __builtin_nanf(""); + conversion = info.numer / (1e9L * info.denom); + } + + return (double) (delta * conversion); +} + + + +#pragma mark - +#pragma mark GuardCalloc + +#define kPageSize 4096 + + +typedef struct BufInfo +{ + void *head; + size_t count; + size_t stride; + size_t totalSize; +}BufInfo; + +static int GuardMarkBuffer( void *buffer, int flag ); + +void *GuardCalloc( size_t count, size_t size, size_t *objectStride ) +{ + if( objectStride ) + *objectStride = 0; + + // Round size up to a multiple of a page size + size_t stride = (size + kPageSize - 1) & -kPageSize; + + //Calculate total size of the allocation + size_t totalSize = count * (stride + kPageSize) + kPageSize; + + // Allocate + char *buf = (char*)mmap( NULL, + totalSize, + PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, + 0, 0 ); + if( MAP_FAILED == buf ) + { + vlog( "mmap failed: %d\n", errno ); + return NULL; + } + + // Find the first byte of user data + char *result = buf + kPageSize; + + // Record what we did for posterity + BufInfo *bptr = (BufInfo*) result - 1; + bptr->head = buf; + bptr->count = count; + bptr->stride = stride; + bptr->totalSize = totalSize; + + // Place the first guard page. Masks our record above. + if( mprotect(buf, kPageSize, PROT_NONE) ) + { + munmap( buf, totalSize); + vlog( "mprotect -1 failed: %d\n", errno ); + return NULL; + } + + // Place the rest of the guard pages + size_t i; + char *p = result; + for( i = 0; i < count; i++ ) + { + p += stride; + if( mprotect(p, kPageSize, PROT_NONE) ) + { + munmap( buf, totalSize); + vlog( "mprotect %lu failed: %d\n", i, errno ); + return NULL; + } + p += kPageSize; + } + + // record the stride from object to object + if( objectStride ) + *objectStride = stride + kPageSize; + + // return pointer to first object + return result; +} + + +void GuardFree( void *buf ) +{ + if( mprotect((char*)buf - kPageSize, kPageSize, PROT_READ) ) + { + vlog( "Unable to read buf info. GuardFree failed! %p (%d)\n", buf, errno ); + return; + } + + BufInfo *bptr = (BufInfo*) buf - 1; + + if( munmap( bptr->head, bptr->totalSize ) ) + vlog( "Unable to unmap data. GuardFree failed! %p (%d)\n", buf, errno ); +} + +int GuardMarkReadOnly( void *buf ) +{ + return GuardMarkBuffer(buf, PROT_READ); +} + +int GuardMarkReadWrite( void *buf) +{ + return GuardMarkBuffer(buf, PROT_READ | PROT_WRITE); +} + +int GuardMarkWriteOnly( void *buf) +{ + return GuardMarkBuffer(buf, PROT_WRITE); +} + +static int GuardMarkBuffer( void *buf, int flag ) +{ + if( mprotect((char*)buf - kPageSize, kPageSize, PROT_READ) ) + { + vlog( "Unable to read buf info. GuardMarkBuffer %d failed! %p (%d)\n", flag, buf, errno ); + return errno; + } + + BufInfo *bptr = (BufInfo*) buf - 1; + + size_t count = bptr->count; + size_t stride = bptr->stride; + + size_t i; + for( i = 0; i < count; i++ ) + { + if( mprotect(buf, stride, flag) ) + { + vlog( "Unable to protect segment %ld. GuardMarkBuffer %d failed! %p (%d)\n", i, flag, buf, errno ); + return errno; + } + bptr += stride + kPageSize; + } + + if( mprotect((char*)buf - kPageSize, kPageSize, PROT_NONE) ) + { + vlog( "Unable to protect leading guard page. GuardMarkBuffer %d failed! %p (%d)\n", flag, buf, errno ); + return errno; + } + + return 0; +} +#endif + +uint32_t random_number32(void) +{ + return ((uint32_t) rand() << 16) ^ rand(); +} + + +uint64_t random_number64(void) +{ + return ((uint64_t) rand() << 48) ^ + ((uint64_t) rand() << 32) ^ + ((uint64_t) rand() << 16) ^ + rand(); +} + diff --git a/test/Bullet2/Source/Utils.h b/test/Bullet2/Source/Utils.h new file mode 100644 index 0000000000..9d30cd450e --- /dev/null +++ b/test/Bullet2/Source/Utils.h @@ -0,0 +1,72 @@ +// +// Utils.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_Utils_h +#define BulletTest_Utils_h + +#include "btIntDefines.h" + + + +#include +#include + +#ifdef _WIN32 +#define LARGE_FLOAT17 (1.f * powf(2,17)) +#define RANDF_16 (random_number32() * powf(2,-16)) +#define RANDF_01 ( random_number32() * powf(2,-32) ) +#define RANDF ( random_number32() * powf(2,-8) ) +#define RANDF_m1p1 (2.0f*( random_number32() * powf(2,-32)-1.0f)) +#else +#define LARGE_FLOAT17 (0x1.0p17f) +#define RANDF_16 (random_number32() * 0x1.0p-16f) +#define RANDF_01 ( random_number32() * 0x1.0p-32f ) +#define RANDF ( random_number32() * 0x1.0p-8f ) +#define RANDF_m1p1 (2.0f*( random_number32() * 0x1.0p-32f )-1.0f) +#endif//_WIN32 + + +#ifdef __cplusplus +extern "C" { +#endif + + /********************* + * Timing * + *********************/ + extern int gReportNanoseconds; + + uint64_t ReadTicks( void ); + double TicksToCycles( uint64_t delta ); // Performance data should be reported in cycles most of the time. + double TicksToSeconds( uint64_t delta ); + + + /********************* + * Guard Heap * + *********************/ + // return buffer containing count objects of size size, with guard pages in betweeen. + // The stride between one object and the next is given by objectStride. + // objectStride may be NULL. Objects so created are freed with GuardFree + void *GuardCalloc( size_t count, size_t size, size_t *objectStride ); + void GuardFree( void * ); + // mark the contents of a guard buffer read-only or write-only. Return 0 on success. + int GuardMarkReadOnly( void *); + int GuardMarkWriteOnly( void *); + int GuardMarkReadWrite( void *); + + /********************* + * Printing * + *********************/ + #define vlog( ... ) printf( __VA_ARGS__ ) + uint32_t random_number32(void); + uint64_t random_number64(void); + +#ifdef __cplusplus + } +#endif + + +#endif diff --git a/test/Bullet2/Source/btIntDefines.h b/test/Bullet2/Source/btIntDefines.h new file mode 100644 index 0000000000..c5dfd5fcc2 --- /dev/null +++ b/test/Bullet2/Source/btIntDefines.h @@ -0,0 +1,19 @@ + +#ifndef BT_INT_DEFINES_H +#define BT_INT_DEFINES_H + +#ifdef __GNUC__ + #include +#elif defined(_MSC_VER) + typedef __int32 int32_t; + typedef __int64 int64_t; + typedef unsigned __int32 uint32_t; + typedef unsigned __int64 uint64_t; +#else + typedef int int32_t; + typedef long long int int64_t; + typedef unsigned int uint32_t; + typedef unsigned long long int uint64_t; +#endif + +#endif //BT_INT_DEFINES_H diff --git a/test/Bullet2/Source/main.cpp b/test/Bullet2/Source/main.cpp new file mode 100644 index 0000000000..55f3f84898 --- /dev/null +++ b/test/Bullet2/Source/main.cpp @@ -0,0 +1,326 @@ +// +// main.c +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// +#include +#ifdef __APPLE__ +#include +#endif //__APPLE__ + +#include +#include +#include +#include "main.h" +#include "Utils.h" +#include "TestList.h" +#include "LinearMath/btScalar.h" + +#if defined (BT_USE_NEON) || defined (BT_USE_SSE_IN_API) + +#ifdef _WIN32 +#define strcasecmp _stricmp +#define basename(A) A +#endif + +#define EXIT_NO_ERROR INT_MIN + +//int gReportNanoseconds = 0; // in Utils.c + +int gReportAverageTimes = 0; +int gExitOnError = 0; +char *gFullPath = NULL; +const char *gAppName = NULL; +int gArgc; +const char **gArgv; + +typedef struct TestNode +{ + struct TestNode *next; + const char *name; +}TestNode; + +TestNode *gNodeList = NULL; + +static int ParseArgs( int argc, const char *argv[] ); +static void PrintUsage( void ); +static int Init( void ); +static void ListTests(void ); + +const char *gArch = +#ifdef __i386__ + "i386"; +#elif defined __x86_64__ + "x86_64"; +#elif defined __arm__ + "arm"; +#elif defined _WIN64 + "win64"; +#elif defined _WIN32 + "win32"; +#else + #error unknown arch +#endif + + + + + +#include + +int main (int argc, const char * argv[]) +{ + + // Enable just one test programatically (instead of command-line param) + // TestNode *node = (TestNode*) malloc( sizeof( TestNode ) ); + // node->name = "btDbvt"; + // node->next = 0; + // gNodeList = node; + + srand(0.f); + + int numPassedTests=0; + int numFailedTests= 0; + + int err; + + // Parse arguments. Build gNodeList. + if( (err = ParseArgs( argc, argv ) ) ) + { + if( EXIT_NO_ERROR == err ) + return 0; + + PrintUsage(); + return err; + } + + printf("Arch: %s\n", gArch ); + + if( gReportAverageTimes ) + printf( "Reporting average times.\n" ); + else + printf( "Reporting best times.\n" ); + + // Set a few things up + if( (err = Init() )) + { + printf( "Init failed.\n" ); + return err; + } + + if( NULL == gNodeList ) + { // test everything + printf( "No function list found. Testing everything...\n" ); + size_t i; + for( i = 0; NULL != gTestList[i].test_func; i++ ) + { + printf( "\n----------------------------------------------\n" ); + printf( "Testing %s:\n", gTestList[i].name ); + printf( "----------------------------------------------\n" ); + uint64_t startTime = ReadTicks(); + int local_error = gTestList[i].test_func(); + uint64_t currentTime = ReadTicks() - startTime; + if( local_error ) + { + numFailedTests++; + printf( "*** %s test failed with error: %d\n", gTestList[i].name, local_error ); + if( gExitOnError ) + return local_error; + if( 0 == err ) + err = local_error; + } + else + { + numPassedTests++; + printf("%s Passed.\t\t\t(%2.2gs)\n", gTestList[i].name, TicksToSeconds(currentTime)); + } + } + } + else + { // test just the list + while( NULL != gNodeList ) + { + TestNode *currentNode = gNodeList; + gNodeList = gNodeList->next; + + // Find the test with that name + size_t i; + for( i = 0; NULL != gTestList[i].test_func; i++ ) + if( 0 == strcasecmp( currentNode->name, gTestList[i].name ) ) + break; + + if( NULL != gTestList[i].test_func ) + { + printf( "\n----------------------------------------------\n" ); + printf( "Testing %s:\n", gTestList[i].name ); + printf( "----------------------------------------------\n" ); + uint64_t startTime = ReadTicks(); + int local_error = gTestList[i].test_func(); + uint64_t currentTime = ReadTicks() - startTime; + if( local_error ) + { + numFailedTests++; + printf( "*** %s test failed with error: %d\n", gTestList[i].name, local_error ); + if( gExitOnError ) + return local_error; + if( 0 == err ) + err = local_error; + } + else + { + numPassedTests++; + printf("%s Passed.\t\t\t(%2.2gs)\n", gTestList[i].name, TicksToSeconds(currentTime)); + } + } + else + { + printf( "\n***Error: Test name \"%s\" not found! Skipping.\n", currentNode->name ); + err = -1; + if( gExitOnError ) + return -1; + } + + free( currentNode ); + } + } + printf( "\n----------------------------------------------\n" ); + printf("numPassedTests = %d, numFailedTests = %d\n",numPassedTests,numFailedTests); + + free(gFullPath); + return err; +} + +static int Init( void ) +{ + // init the timer + TicksToCycles(0); + + return 0; +} + +static int ParseArgs( int argc, const char *argv[] ) +{ + int listTests = 0; + TestNode *list = NULL; + + gArgc = argc; + gArgv = argv; + gFullPath = (char*)malloc( strlen(argv[0]) + 1); + strcpy(gFullPath, argv[0]); + gAppName = basename( gFullPath ); + if( NULL == gAppName ) + gAppName = ""; + + printf( "%s ", gAppName ); + int skipremaining=0; + + size_t i; + for( i = 1; i < argc; i++ ) + { + const char *arg = argv[i]; + printf( "\t%s", arg ); + if( arg[0] == '-' ) + { + arg++; + while( arg[0] != '\0' ) + { + int stop = 0; + switch( arg[0] ) + { + case 'a': + gReportAverageTimes ^= 1; + break; + case 'e': + gExitOnError ^= 1; + break; + case 'h': + PrintUsage(); + return EXIT_NO_ERROR; + case 'l': + listTests ^= 1; + return EXIT_NO_ERROR; + case 's': + gReportNanoseconds ^= 1; + break; + case ' ': + stop = 1; + break; + case 'N'://ignore the -NSDocumentRevisionsDebugMode argument from XCode 4.3.2 + skipremaining = 1; + stop = 1; + break; + default: + printf( "\nError: Unknown flag \'%c\'\n", arg[0] ); + return -1; + } + if( stop ) + break; + arg++; + } + } + else + { // add function name to the list + TestNode *node = (TestNode*) malloc( sizeof( TestNode ) ); + node->name = arg; + node->next = list; + list = node; + } + if (skipremaining) + break; + } + + // reverse the list of test names, and stick on gNodeList + while( list ) + { + TestNode *node = list; + TestNode *next = node->next; + node->next = gNodeList; + gNodeList = node; + list = next; + } + + printf( "\n" ); + if( listTests ) + ListTests(); + + return 0; +} + + +static void PrintUsage( void ) +{ + printf("\nUsage:\n" ); + printf("%s: <-aehls> ", gAppName); + printf("Options:\n"); + printf("\t-a\tToggle report average times vs. best times. (Default: best times)\n"); + printf("\t-e\tToggle exit immediately on error behavior. (Default: off)\n"); + printf("\t-h\tPrint this message.\n"); + printf("\t-l\tToggle list available test names. (Default: off)\n"); + printf("\t-s\tToggle report times in cycles or nanoseconds. (Default: cycles)\n\n"); + printf("\tOptions may be followed by one or more test names. If no test names \n" ); + printf("\tare provided, then all tests are run.\n\n"); +} + +static void ListTests(void ) +{ + size_t i; + + printf("\nTests:\n"); + for( i = 0; NULL != gTestList[i].test_func; i++ ) + { + printf( "%19s", gTestList[i].name ); + if( NULL != gTestList[i].test_func ) + printf( "," ); + if( 3 == (i&3) ) + printf( "\n" ); + } +} +#else +#include +int main(int argc, char* argv[]) +{ + printf("error: no SIMD enabled through BT_USE_NEON or BT_USE_SSE_IN_API \n(enable in LinearMath/btScalar.h or through build system)\n"); + return 0; +} +#endif diff --git a/test/Bullet2/Source/main.h b/test/Bullet2/Source/main.h new file mode 100644 index 0000000000..e8e5dd2847 --- /dev/null +++ b/test/Bullet2/Source/main.h @@ -0,0 +1,25 @@ +// +// main.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_main_h +#define BulletTest_main_h + +#ifdef __cplusplus +extern "C" { +#endif + + extern int gReportAverageTimes; // if 0, report best times + extern int gExitOnError; // if non-zero, exit as soon an an error is encountered + extern const char *gAppName; // the name of this application + +#ifdef __cplusplus +} +#endif + + + +#endif diff --git a/test/Bullet2/Source/vector.h b/test/Bullet2/Source/vector.h new file mode 100644 index 0000000000..c476a9e162 --- /dev/null +++ b/test/Bullet2/Source/vector.h @@ -0,0 +1,70 @@ +// +// vector.h +// BulletTest +// +// Copyright (c) 2011 Apple Inc. +// + +#ifndef BulletTest_vector_h +#define BulletTest_vector_h + +#ifdef __SSE__ + typedef float float4 __attribute__ ((__vector_size__(16))); + #include +#endif + +#ifdef __SSE2__ + typedef double double2 __attribute__ ((__vector_size__(16))); + typedef char char16 __attribute__ ((__vector_size__(16))); + typedef unsigned char uchar16 __attribute__ ((__vector_size__(16))); + typedef short short8 __attribute__ ((__vector_size__(16))); + typedef unsigned short ushort8 __attribute__ ((__vector_size__(16))); + typedef int int4 __attribute__ ((__vector_size__(16))); + // typedef unsigned int uint4 __attribute__ ((__vector_size__(16))); + #ifdef __LP64__ + typedef long long2 __attribute__ ((__vector_size__(16))); + typedef unsigned long ulong2 __attribute__ ((__vector_size__(16))); + #else + typedef long long long2 __attribute__ ((__vector_size__(16))); + typedef unsigned long long ulong2 __attribute__ ((__vector_size__(16))); + #endif + #include +#endif + +#ifdef __SSE3__ + #include +#endif + +#ifdef __SSSE3__ + #include +#endif + +#ifdef __SSE4_1__ + #include +#endif + +#ifdef __arm__ + #include + #ifdef _ARM_ARCH_7 + #define ARM_NEON_GCC_COMPATIBILITY 1 + #include + typedef float float4 __attribute__ ((__vector_size__(16))); + typedef double double2 __attribute__ ((__vector_size__(16))); + typedef char char16 __attribute__ ((__vector_size__(16))); + typedef unsigned char uchar16 __attribute__ ((__vector_size__(16))); + typedef short short8 __attribute__ ((__vector_size__(16))); + typedef unsigned short ushort8 __attribute__ ((__vector_size__(16))); + typedef int int4 __attribute__ ((__vector_size__(16))); + typedef unsigned int uint4 __attribute__ ((__vector_size__(16))); + #ifdef __LP64__ + typedef long long2 __attribute__ ((__vector_size__(16))); + typedef unsigned long ulong2 __attribute__ ((__vector_size__(16))); + #else + typedef long long long2 __attribute__ ((__vector_size__(16))); + typedef unsigned long long ulong2 __attribute__ ((__vector_size__(16))); + #endif + #endif +#endif + + +#endif diff --git a/test/Bullet2/premake4.lua b/test/Bullet2/premake4.lua new file mode 100644 index 0000000000..bca0cb5dcb --- /dev/null +++ b/test/Bullet2/premake4.lua @@ -0,0 +1,23 @@ + +project "AppUnitTest" + +if _OPTIONS["ios"] then + kind "WindowedApp" +else + kind "ConsoleApp" +end +targetdir "bin" + +includedirs {"../src","Source", "Source/Tests"} + +links { + "BulletDynamics","BulletCollision", "LinearMath" +} + +language "C++" + +files { + "Source/**.cpp", + "Source/**.h", +} +