├── .gitignore ├── CMakeLists.txt ├── EG18_FinalPresentation.pptx ├── LICENSE.md ├── README.md ├── Source ├── Bin │ └── CudaProject │ │ └── vs2015x64Release │ │ ├── CudaProjectx64Release.iobj │ │ ├── CudaProjectx64Release.ipdb │ │ ├── assimp-vc140-mt.dll │ │ └── cudart64_80.dll ├── Build │ └── vs2015 │ │ └── Mine │ │ ├── CudaProject │ │ ├── CudaProject.vcxproj │ │ └── CudaProject.vcxproj.filters │ │ └── Mine.sln ├── Externals │ ├── inc │ │ ├── assimp │ │ │ ├── .editorconfig │ │ │ ├── Compiler │ │ │ │ ├── poppack1.h │ │ │ │ ├── pstdint.h │ │ │ │ └── pushpack1.h │ │ │ ├── DefaultLogger.hpp │ │ │ ├── Exporter.hpp │ │ │ ├── IOStream.hpp │ │ │ ├── IOSystem.hpp │ │ │ ├── Importer.hpp │ │ │ ├── LogStream.hpp │ │ │ ├── Logger.hpp │ │ │ ├── NullLogger.hpp │ │ │ ├── ProgressHandler.hpp │ │ │ ├── README.txt │ │ │ ├── ai_assert.h │ │ │ ├── anim.h │ │ │ ├── camera.h │ │ │ ├── cexport.h │ │ │ ├── cfileio.h │ │ │ ├── cimport.h │ │ │ ├── color4.h │ │ │ ├── color4.inl │ │ │ ├── config.h │ │ │ ├── defs.h │ │ │ ├── importerdesc.h │ │ │ ├── light.h │ │ │ ├── material.h │ │ │ ├── material.inl │ │ │ ├── matrix3x3.h │ │ │ ├── matrix3x3.inl │ │ │ ├── matrix4x4.h │ │ │ ├── matrix4x4.inl │ │ │ ├── mesh.h │ │ │ ├── metadata.h │ │ │ ├── port │ │ │ │ └── AndroidJNI │ │ │ │ │ └── AndroidJNIIOSystem.h │ │ │ ├── postprocess.h │ │ │ ├── quaternion.h │ │ │ ├── quaternion.inl │ │ │ ├── scene.h │ │ │ ├── texture.h │ │ │ ├── types.h │ │ │ ├── vector2.h │ │ │ ├── vector2.inl │ │ │ ├── vector3.h │ │ │ ├── vector3.inl │ │ │ └── version.h │ │ ├── cuda │ │ │ ├── GL │ │ │ │ ├── freeglut.h │ │ │ │ ├── freeglut_ext.h │ │ │ │ ├── freeglut_std.h │ │ │ │ ├── glew.h │ │ │ │ ├── glext.h │ │ │ │ ├── glut.h │ │ │ │ ├── glxew.h │ │ │ │ ├── glxext.h │ │ │ │ ├── wglew.h │ │ │ │ └── wglext.h │ │ │ ├── cuda_drvapi_dynlink.c │ │ │ ├── drvapi_error_string.h │ │ │ ├── dynlink │ │ │ │ ├── cuda_drvapi_dynlink.h │ │ │ │ ├── cuda_drvapi_dynlink_cuda.h │ │ │ │ ├── cuda_drvapi_dynlink_d3d.h │ │ │ │ └── cuda_drvapi_dynlink_gl.h │ │ │ ├── dynlink_d3d10.h │ │ │ ├── dynlink_d3d11.h │ │ │ ├── exception.h │ │ │ ├── helper_cuda.h │ │ │ ├── helper_cuda_drvapi.h │ │ │ ├── helper_cuda_gl.h │ │ │ ├── helper_cusolver.h │ │ │ ├── helper_functions.h │ │ │ ├── helper_gl.h │ │ │ ├── helper_image.h │ │ │ ├── helper_math.h │ │ │ ├── helper_string.h │ │ │ ├── helper_timer.h │ │ │ ├── multithreading.h │ │ │ ├── nvMath.h │ │ │ ├── nvMatrix.h │ │ │ ├── nvQuaternion.h │ │ │ ├── nvShaderUtils.h │ │ │ ├── nvVector.h │ │ │ ├── nvrtc_helper.h │ │ │ ├── param.h │ │ │ ├── paramgl.h │ │ │ ├── rendercheck_d3d10.h │ │ │ ├── rendercheck_d3d11.h │ │ │ ├── rendercheck_d3d9.h │ │ │ ├── rendercheck_gl.h │ │ │ ├── rendercheck_gles.h │ │ │ └── timer.h │ │ └── gProximity │ │ │ ├── README.txt │ │ │ ├── cuda_intersect_tritri.h │ │ │ └── cuda_vectors.h │ └── lib │ │ ├── vs2013x64 │ │ ├── assimp-vc120-mt.dll │ │ └── assimp-vc120-mt.lib │ │ ├── vs2015x64 │ │ ├── assimp-vc140-mt.dll │ │ ├── assimp-vc140-mt.lib │ │ ├── assimp-vc140-mtd.dll │ │ └── assimp-vc140-mtd.lib │ │ └── vs2015x86 │ │ ├── assimp-vc140-mt.dll │ │ ├── assimp-vc140-mt.lib │ │ ├── assimp-vc140-mtd.dll │ │ └── assimp-vc140-mtd.lib └── Project │ ├── Mine │ ├── Frameworks │ │ ├── AppBase │ │ │ ├── AppBase.cpp │ │ │ ├── AppBase.h │ │ │ ├── Main.cpp │ │ │ └── Main.h │ │ └── CudaProject │ │ │ ├── CudaProjectApp.cpp │ │ │ ├── CudaProjectApp.h │ │ │ ├── CudaProjectModuleRegister.cpp │ │ │ └── CudaProjectModuleRegister.h │ ├── README.txt │ ├── base │ │ ├── AggregatedAttribs.h │ │ ├── Bv.h │ │ ├── MultiArray.h │ │ ├── MultiObject.h │ │ └── Singleton.h │ ├── collision │ │ ├── auxiliary │ │ │ ├── BvhRestrLog.cpp │ │ │ ├── BvhRestrLog.cu │ │ │ ├── BvhRestrLog.h │ │ │ ├── FlOrderLog.cpp │ │ │ ├── FlOrderLog.cu │ │ │ ├── FlOrderLog.h │ │ │ └── OrderLog.h │ │ ├── bvtt_front │ │ │ ├── BVTTFront.h │ │ │ ├── BvhCDKernels.cu │ │ │ ├── BvttFrontGenerateKernels.cu │ │ │ ├── BvttFrontKeepKernels.cu │ │ │ ├── BvttFrontLooseInter.cu │ │ │ ├── BvttFrontLooseInter.h │ │ │ ├── BvttFrontLooseIntra.cu │ │ │ ├── BvttFrontLooseIntra.h │ │ │ ├── BvttFrontLooseKernels.cuh │ │ │ ├── BvttFrontPruneSproutKernels.cu │ │ │ ├── BvttFrontReorderKernels.cu │ │ │ └── BvttFrontRestructureKernels.cu │ │ ├── lbvh │ │ │ ├── BvhBV.cu │ │ │ ├── BvhBV.h │ │ │ ├── BvhExtNode.cu │ │ │ ├── BvhExtNode.h │ │ │ ├── BvhIntNode.cu │ │ │ ├── BvhIntNode.h │ │ │ ├── BvhPrimitiveNode.cu │ │ │ ├── BvhPrimitiveNode.h │ │ │ ├── LBvh.h │ │ │ ├── LBvhBuildKernels.cu │ │ │ ├── LBvhFixedDeformable.cu │ │ │ ├── LBvhFixedDeformable.h │ │ │ ├── LBvhKernels.cuh │ │ │ ├── LBvhRestructureKernels.cu │ │ │ ├── LBvhRigid.cu │ │ │ ├── LBvhRigid.h │ │ │ └── LBvhUpdateKernels.cu │ │ └── narrow_phase │ │ │ ├── narrow_phase.cu │ │ │ └── narrow_phase.cuh │ ├── entry_cudaproject.cpp │ ├── setting │ │ ├── BvhSettings.h │ │ ├── BvttFrontSettings.h │ │ ├── CDBenchmarkConfiguration.hpp │ │ ├── CDBenchmarkSettings.cpp │ │ └── CDBenchmarkSettings.h │ ├── system │ │ ├── CudaDevice │ │ │ ├── CudaDevice.cu │ │ │ ├── CudaDevice.h │ │ │ └── CudaKernelLauncher.cu │ │ ├── Log │ │ │ └── Logger.hpp │ │ └── Logic │ │ │ └── BenchmarkLogic.hpp │ ├── utility │ │ ├── CudaDeviceUtils.cu │ │ ├── CudaDeviceUtils.h │ │ ├── CudaExecutionPolicy.h │ │ ├── CudaHostUtils.h │ │ ├── CudaKernelUtils.cu │ │ ├── CudaKernelUtils.cuh │ │ ├── CudaThrustUtils.hpp │ │ ├── CudaTimer.hpp │ │ ├── Meta.h │ │ ├── ModelReader.hpp │ │ ├── Timer.hpp │ │ └── Utils.h │ └── world │ │ ├── Scene.cpp │ │ └── Scene.h │ └── README.txt └── Tools └── FrontAnalyser ├── .vs └── DataExtractor │ └── v15 │ ├── .suo │ ├── Browse.VC.db │ └── ipch │ └── AutoPCH │ ├── b360d4677b155e31 │ └── SOURCE.ipch │ └── de20fc9f94596831 │ └── SOURCE.ipch ├── DataExtractor.sdf ├── DataExtractor.sln └── DataExtractor ├── DataExtractor.vcxproj ├── DataExtractor.vcxproj.filters ├── DataExtractor.vcxproj.user └── Source.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.i 2 | *.ii 3 | *.gpu 4 | *.ptx 5 | *.cubin 6 | *.fatbin 7 | .vs 8 | out 9 | build 10 | Source/Temp 11 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.19) 2 | 3 | project(efficient_bvhcd CXX CUDA) 4 | find_package(assimp CONFIG REQUIRED) 5 | find_package(CUDAToolkit REQUIRED) 6 | 7 | add_executable(bvhcd) 8 | target_link_libraries(bvhcd PRIVATE assimp::assimp) 9 | target_link_libraries(bvhcd PRIVATE CUDA::cuda_driver CUDA::cudart) 10 | 11 | target_compile_features(bvhcd PRIVATE cuda_std_17 cxx_std_17) 12 | set_target_properties(bvhcd 13 | PROPERTIES POSITION_INDEPENDENT_CODE ON 14 | ) 15 | 16 | target_include_directories(bvhcd PRIVATE Source/Externals/inc) 17 | target_include_directories(bvhcd PRIVATE Source/Externals/inc/gProximity) 18 | target_include_directories(bvhcd PRIVATE Source/Externals/inc/cuda) 19 | target_include_directories(bvhcd PRIVATE Source/Project/Mine) 20 | 21 | target_compile_options(bvhcd 22 | PRIVATE $<$:${CMAKE_CUDA_FLAGS} -lineinfo --ptxas-options=-allow-expensive-optimizations=true> 23 | 24 | PUBLIC $<$:--extended-lambda --expt-relaxed-constexpr --default-stream=per-thread -Xcudafe "--display_error_number --diag_suppress=implicit_return_from_non_void_function --diag_suppress=loop_not_reachable --diag_suppress=2642"> 25 | ) 26 | set_target_properties(bvhcd 27 | PROPERTIES # LINKER_LANGUAGE CUDA 28 | CUDA_SEPARABLE_COMPILATION ON 29 | CUDA_RESOLVE_DEVICE_SYMBOLS ON 30 | ) 31 | target_compile_definitions(bvhcd INTERFACE CMAKE_GENERATOR_PLATFORM=x64) 32 | target_link_options(bvhcd 33 | PRIVATE $ 34 | ) 35 | 36 | # 37 | target_sources(bvhcd PRIVATE 38 | Source/Project/Mine/entry_cudaproject.cpp 39 | Source/Project/Mine/world/Scene.cpp 40 | Source/Project/Mine/utility/CudaDeviceUtils.cu 41 | Source/Project/Mine/utility/CudaKernelUtils.cu 42 | Source/Project/Mine/system/CudaDevice/CudaDevice.cu 43 | Source/Project/Mine/system/CudaDevice/CudaKernelLauncher.cu 44 | Source/Project/Mine/setting/CDBenchmarkSettings.cpp 45 | Source/Project/Mine/Frameworks/AppBase/AppBase.cpp 46 | Source/Project/Mine/Frameworks/AppBase/Main.cpp 47 | Source/Project/Mine/Frameworks/CudaProject/CudaProjectApp.cpp 48 | Source/Project/Mine/Frameworks/CudaProject/CudaProjectModuleRegister.cpp 49 | 50 | Source/Project/Mine/collision/auxiliary/BvhRestrLog.cpp 51 | Source/Project/Mine/collision/auxiliary/BvhRestrLog.cu 52 | Source/Project/Mine/collision/auxiliary/FlOrderLog.cpp 53 | Source/Project/Mine/collision/auxiliary/FlOrderLog.cu 54 | 55 | Source/Project/Mine/collision/bvtt_front/BvhCDKernels.cu 56 | Source/Project/Mine/collision/bvtt_front/BvttFrontGenerateKernels.cu 57 | Source/Project/Mine/collision/bvtt_front/BvttFrontKeepKernels.cu 58 | Source/Project/Mine/collision/bvtt_front/BvttFrontLooseInter.cu 59 | Source/Project/Mine/collision/bvtt_front/BvttFrontLooseIntra.cu 60 | Source/Project/Mine/collision/bvtt_front/BvttFrontPruneSproutKernels.cu 61 | Source/Project/Mine/collision/bvtt_front/BvttFrontReorderKernels.cu 62 | Source/Project/Mine/collision/bvtt_front/BvttFrontRestructureKernels.cu 63 | 64 | Source/Project/Mine/collision/lbvh/BvhBV.cu 65 | Source/Project/Mine/collision/lbvh/BvhExtNode.cu 66 | Source/Project/Mine/collision/lbvh/BvhIntNode.cu 67 | Source/Project/Mine/collision/lbvh/BvhPrimitiveNode.cu 68 | Source/Project/Mine/collision/lbvh/LBvhBuildKernels.cu 69 | Source/Project/Mine/collision/lbvh/LBvhFixedDeformable.cu 70 | Source/Project/Mine/collision/lbvh/LBvhRestructureKernels.cu 71 | Source/Project/Mine/collision/lbvh/LBvhRigid.cu 72 | Source/Project/Mine/collision/lbvh/LBvhUpdateKernels.cu 73 | 74 | Source/Project/Mine/collision/narrow_phase/narrow_phase.cu 75 | ) 76 | -------------------------------------------------------------------------------- /EG18_FinalPresentation.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/EG18_FinalPresentation.pptx -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2018 Zhejiang University. 2 | All rights reserved. 3 | 4 | Permission to use, copy, modify, and distribute this software and its 5 | documentation for educational, research, and non-profit purposes, without 6 | fee, and without a written agreement is hereby granted, provided that the 7 | above copyright notice, this paragraph, and the following four paragraphs 8 | appear in all copies. 9 | 10 | Permission to incorporate this software into commercial products may be 11 | obtained by contacting Zhejiang University. 12 | 13 | This software program and documentation are copyrighted by Zhejiang University. 14 | The software program and documentation are supplied "as is", without any 15 | accompanying services from Zhejiang University or the authors. Zhejiang 16 | University and the authors do not warrant that the operation of the program 17 | will be uninterrupted or error-free. The end-user understands that the program 18 | was developed for research purposes and is advised not to rely exclusively on 19 | the program for any reason. 20 | 21 | IN NO EVENT SHALL ZHEJIANG UNIVERSITY OR ITS EMPLOYEES OR THE AUTHORS BE 22 | LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL 23 | DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND 24 | ITS DOCUMENTATION, EVEN IF ZHEJIANG UNIVERSITY OR THE AUTHORS HAVE BEEN ADVISED 25 | OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ZHEJIANG UNIVERSITY AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, 28 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 29 | FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY OF NON-INFRINGEMENT. 30 | THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND ZHEJIANG UNIVERSITY 31 | AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 32 | ENHANCEMENTS, OR MODIFICATIONS. 33 | 34 | Please send all BUG REPORTS to: 35 | 36 | wxlwxl1993@zju.edu.cn / 37 | tang_m@zju.edu.cn 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is the collision detection package by littlemine (Xinlei Wang). 2 | 3 | ------------------------------------------------------------------------------ 4 | 1. Configuration Instructions 5 | ------------------------------------------------------------------------------ 6 | 7 | This project is developed using Visual Studio 2015 and CUDA 9 (>= 8) on Windows platform. It is the source code of the article [Efficient BVH-based Collision Detection Scheme with Ordering and Restructuring](https://onlinelibrary.wiley.com/doi/abs/10.1111/cgf.13356). 8 | 9 | All configurations are set in directory "Source\Project\Mine\setting\". 10 | All the standalone benchmarks can be downloaded at [UNC Dynamic Scene Benchmarks](http://gamma.cs.unc.edu/DYNAMICB/). 11 | 12 | Open "Source\Build\vs2015\Mine\Mine.sln", then build and run it. If the project loading fails, please modify the CUDA version number matching the installed one, and reload the project. 13 | 14 | If you plan to use Visual Studio 2017, please make sure build and link the corresponding *assimp* libraries. 15 | 16 | ------------------------------------------------------------------------------ 17 | 2. Credits 18 | ------------------------------------------------------------------------------ 19 | 20 | [I-Cloth](http://gamma.cs.unc.edu/CAMA/) 21 | 22 | [gProximity](http://gamma.cs.unc.edu/GPUCOL/) 23 | 24 | [Assimp](http://www.assimp.org/) 25 | 26 | [UNC Dynamic Scene Collection](http://gamma.cs.unc.edu/DYNAMICB/) 27 | 28 | ------------------------------------------------------------------------------ 29 | 3. Bug report 30 | ------------------------------------------------------------------------------ 31 | 32 | We would be interested in knowing more about your application as well as any 33 | bugs you may encounter in the collision detection library. You can 34 | report them by sending e-mail to wxlwxl1993@zju.edu.cn or tang_m@zju.edu.cn 35 | 36 | ------------------------------------------------------------------------------ 37 | 4. Release date 38 | ------------------------------------------------------------------------------ 39 | 40 | 2018/02/10 41 | -------------------------------------------------------------------------------- /Source/Bin/CudaProject/vs2015x64Release/CudaProjectx64Release.iobj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Bin/CudaProject/vs2015x64Release/CudaProjectx64Release.iobj -------------------------------------------------------------------------------- /Source/Bin/CudaProject/vs2015x64Release/CudaProjectx64Release.ipdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Bin/CudaProject/vs2015x64Release/CudaProjectx64Release.ipdb -------------------------------------------------------------------------------- /Source/Bin/CudaProject/vs2015x64Release/assimp-vc140-mt.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Bin/CudaProject/vs2015x64Release/assimp-vc140-mt.dll -------------------------------------------------------------------------------- /Source/Bin/CudaProject/vs2015x64Release/cudart64_80.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Bin/CudaProject/vs2015x64Release/cudart64_80.dll -------------------------------------------------------------------------------- /Source/Build/vs2015/Mine/Mine.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CudaProject", "CudaProject\CudaProject.vcxproj", "{FEA41310-7EF2-4B24-B5AA-4C07A84ED1E4}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {FEA41310-7EF2-4B24-B5AA-4C07A84ED1E4}.Debug|x64.ActiveCfg = Debug|x64 17 | {FEA41310-7EF2-4B24-B5AA-4C07A84ED1E4}.Debug|x64.Build.0 = Debug|x64 18 | {FEA41310-7EF2-4B24-B5AA-4C07A84ED1E4}.Debug|x86.ActiveCfg = Debug|Win32 19 | {FEA41310-7EF2-4B24-B5AA-4C07A84ED1E4}.Debug|x86.Build.0 = Debug|Win32 20 | {FEA41310-7EF2-4B24-B5AA-4C07A84ED1E4}.Release|x64.ActiveCfg = Release|x64 21 | {FEA41310-7EF2-4B24-B5AA-4C07A84ED1E4}.Release|x64.Build.0 = Release|x64 22 | {FEA41310-7EF2-4B24-B5AA-4C07A84ED1E4}.Release|x86.ActiveCfg = Release|Win32 23 | {FEA41310-7EF2-4B24-B5AA-4C07A84ED1E4}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/.editorconfig: -------------------------------------------------------------------------------- 1 | # See for details 2 | 3 | [*.{h,hpp,inl}] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | indent_size = 4 8 | indent_style = space 9 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/Compiler/poppack1.h: -------------------------------------------------------------------------------- 1 | 2 | // =============================================================================== 3 | // May be included multiple times - resets structure packing to the defaults 4 | // for all supported compilers. Reverts the changes made by #include 5 | // 6 | // Currently this works on the following compilers: 7 | // MSVC 7,8,9 8 | // GCC 9 | // BORLAND (complains about 'pack state changed but not reverted', but works) 10 | // =============================================================================== 11 | 12 | #ifndef AI_PUSHPACK_IS_DEFINED 13 | # error pushpack1.h must be included after poppack1.h 14 | #endif 15 | 16 | // reset packing to the original value 17 | #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) 18 | # pragma pack( pop ) 19 | #endif 20 | #undef PACK_STRUCT 21 | 22 | #undef AI_PUSHPACK_IS_DEFINED 23 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/Compiler/pushpack1.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | // =============================================================================== 4 | // May be included multiple times - sets structure packing to 1 5 | // for all supported compilers. #include reverts the changes. 6 | // 7 | // Currently this works on the following compilers: 8 | // MSVC 7,8,9 9 | // GCC 10 | // BORLAND (complains about 'pack state changed but not reverted', but works) 11 | // Clang 12 | // 13 | // 14 | // USAGE: 15 | // 16 | // struct StructToBePacked { 17 | // } PACK_STRUCT; 18 | // 19 | // =============================================================================== 20 | 21 | #ifdef AI_PUSHPACK_IS_DEFINED 22 | # error poppack1.h must be included after pushpack1.h 23 | #endif 24 | 25 | #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) 26 | # pragma pack(push,1) 27 | # define PACK_STRUCT 28 | #elif defined( __GNUC__ ) 29 | # if !defined(HOST_MINGW) 30 | # define PACK_STRUCT __attribute__((__packed__)) 31 | # else 32 | # define PACK_STRUCT __attribute__((gcc_struct, __packed__)) 33 | # endif 34 | #else 35 | # error Compiler not supported 36 | #endif 37 | 38 | #if defined(_MSC_VER) 39 | 40 | // C4103: Packing was changed after the inclusion of the header, probably missing #pragma pop 41 | # pragma warning (disable : 4103) 42 | #endif 43 | 44 | #define AI_PUSHPACK_IS_DEFINED 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/LogStream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2016, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | 41 | /** @file LogStream.hpp 42 | * @brief Abstract base class 'LogStream', representing an output log stream. 43 | */ 44 | #ifndef INCLUDED_AI_LOGSTREAM_H 45 | #define INCLUDED_AI_LOGSTREAM_H 46 | #include "types.h" 47 | namespace Assimp { 48 | class IOSystem; 49 | 50 | // ------------------------------------------------------------------------------------ 51 | /** @brief CPP-API: Abstract interface for log stream implementations. 52 | * 53 | * Several default implementations are provided, see #aiDefaultLogStream for more 54 | * details. Writing your own implementation of LogStream is just necessary if these 55 | * are not enough for your purpose. */ 56 | class ASSIMP_API LogStream 57 | #ifndef SWIG 58 | : public Intern::AllocateFromAssimpHeap 59 | #endif 60 | { 61 | protected: 62 | /** @brief Default constructor */ 63 | LogStream() { 64 | } 65 | public: 66 | /** @brief Virtual destructor */ 67 | virtual ~LogStream() { 68 | } 69 | 70 | // ------------------------------------------------------------------- 71 | /** @brief Overwrite this for your own output methods 72 | * 73 | * Log messages *may* consist of multiple lines and you shouldn't 74 | * expect a consistent formatting. If you want custom formatting 75 | * (e.g. generate HTML), supply a custom instance of Logger to 76 | * #DefaultLogger:set(). Usually you can *expect* that a log message 77 | * is exactly one line and terminated with a single \n character. 78 | * @param message Message to be written */ 79 | virtual void write(const char* message) = 0; 80 | 81 | // ------------------------------------------------------------------- 82 | /** @brief Creates a default log stream 83 | * @param streams Type of the default stream 84 | * @param name For aiDefaultLogStream_FILE: name of the output file 85 | * @param io For aiDefaultLogStream_FILE: IOSystem to be used to open the output 86 | * file. Pass NULL for the default implementation. 87 | * @return New LogStream instance. */ 88 | static LogStream* createDefaultStream(aiDefaultLogStream stream, 89 | const char* name = "AssimpLog.txt", 90 | IOSystem* io = NULL); 91 | 92 | }; // !class LogStream 93 | // ------------------------------------------------------------------------------------ 94 | } // Namespace Assimp 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/NullLogger.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2016, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | 41 | /** @file NullLogger.hpp 42 | * @brief Dummy logger 43 | */ 44 | 45 | #ifndef INCLUDED_AI_NULLLOGGER_H 46 | #define INCLUDED_AI_NULLLOGGER_H 47 | 48 | #include "Logger.hpp" 49 | namespace Assimp { 50 | // --------------------------------------------------------------------------- 51 | /** @brief CPP-API: Empty logging implementation. 52 | * 53 | * Does nothing! Used by default if the application hasn't requested a 54 | * custom logger via #DefaultLogger::set() or #DefaultLogger::create(); */ 55 | class ASSIMP_API NullLogger 56 | : public Logger { 57 | 58 | public: 59 | 60 | /** @brief Logs a debug message */ 61 | void OnDebug(const char* message) { 62 | (void)message; //this avoids compiler warnings 63 | } 64 | 65 | /** @brief Logs an info message */ 66 | void OnInfo(const char* message) { 67 | (void)message; //this avoids compiler warnings 68 | } 69 | 70 | /** @brief Logs a warning message */ 71 | void OnWarn(const char* message) { 72 | (void)message; //this avoids compiler warnings 73 | } 74 | 75 | /** @brief Logs an error message */ 76 | void OnError(const char* message) { 77 | (void)message; //this avoids compiler warnings 78 | } 79 | 80 | /** @brief Detach a still attached stream from logger */ 81 | bool attachStream(LogStream *pStream, unsigned int severity) { 82 | (void)pStream; (void)severity; //this avoids compiler warnings 83 | return false; 84 | } 85 | 86 | /** @brief Detach a still attached stream from logger */ 87 | bool detatchStream(LogStream *pStream, unsigned int severity) { 88 | (void)pStream; (void)severity; //this avoids compiler warnings 89 | return false; 90 | } 91 | 92 | private: 93 | }; 94 | } 95 | #endif // !! AI_NULLLOGGER_H_INCLUDED 96 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/README.txt: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------- 2 | Open Asset Import Library (assimp) 3 | --------------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2016, assimp team 6 | 7 | All rights reserved. 8 | 9 | Redistribution and use of this software in source and binary forms, 10 | with or without modification, are permitted provided that the following 11 | conditions are met: 12 | 13 | * Redistributions of source code must retain the above 14 | copyright notice, this list of conditions and the 15 | following disclaimer. 16 | 17 | * Redistributions in binary form must reproduce the above 18 | copyright notice, this list of conditions and the 19 | following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | * Neither the name of the assimp team, nor the names of its 23 | contributors may be used to endorse or promote products 24 | derived from this software without specific prior 25 | written permission of the assimp team. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | --------------------------------------------------------------------------- 39 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/ai_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2016, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | #ifndef AI_DEBUG_H_INC 42 | #define AI_DEBUG_H_INC 43 | 44 | #ifdef ASSIMP_BUILD_DEBUG 45 | # include 46 | # define ai_assert(expression) assert(expression) 47 | #else 48 | # define ai_assert(expression) 49 | #endif 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/color4.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2016, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | /** @file color4.h 42 | * @brief RGBA color structure, including operators when compiling in C++ 43 | */ 44 | #ifndef AI_COLOR4D_H_INC 45 | #define AI_COLOR4D_H_INC 46 | 47 | #include "./Compiler/pushpack1.h" 48 | 49 | #ifdef __cplusplus 50 | 51 | // ---------------------------------------------------------------------------------- 52 | /** Represents a color in Red-Green-Blue space including an 53 | * alpha component. Color values range from 0 to 1. */ 54 | // ---------------------------------------------------------------------------------- 55 | template 56 | class aiColor4t 57 | { 58 | public: 59 | aiColor4t () : r(), g(), b(), a() {} 60 | aiColor4t (TReal _r, TReal _g, TReal _b, TReal _a) 61 | : r(_r), g(_g), b(_b), a(_a) {} 62 | explicit aiColor4t (TReal _r) : r(_r), g(_r), b(_r), a(_r) {} 63 | aiColor4t (const aiColor4t& o) 64 | : r(o.r), g(o.g), b(o.b), a(o.a) {} 65 | 66 | public: 67 | // combined operators 68 | const aiColor4t& operator += (const aiColor4t& o); 69 | const aiColor4t& operator -= (const aiColor4t& o); 70 | const aiColor4t& operator *= (TReal f); 71 | const aiColor4t& operator /= (TReal f); 72 | 73 | public: 74 | // comparison 75 | bool operator == (const aiColor4t& other) const; 76 | bool operator != (const aiColor4t& other) const; 77 | bool operator < (const aiColor4t& other) const; 78 | 79 | // color tuple access, rgba order 80 | inline TReal operator[](unsigned int i) const; 81 | inline TReal& operator[](unsigned int i); 82 | 83 | /** check whether a color is (close to) black */ 84 | inline bool IsBlack() const; 85 | 86 | public: 87 | 88 | // Red, green, blue and alpha color values 89 | TReal r, g, b, a; 90 | } PACK_STRUCT; // !struct aiColor4D 91 | 92 | typedef aiColor4t aiColor4D; 93 | 94 | #else 95 | 96 | struct aiColor4D { 97 | float r, g, b, a; 98 | } PACK_STRUCT; 99 | 100 | #endif // __cplusplus 101 | 102 | #include "./Compiler/poppack1.h" 103 | 104 | #endif // AI_COLOR4D_H_INC 105 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/port/AndroidJNI/AndroidJNIIOSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2016, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | 41 | /** @file Android implementation of IOSystem using the standard C file functions. 42 | * Aimed to ease the access to android assets */ 43 | 44 | #if __ANDROID__ and __ANDROID_API__ > 9 and defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT) 45 | #ifndef AI_ANDROIDJNIIOSYSTEM_H_INC 46 | #define AI_ANDROIDJNIIOSYSTEM_H_INC 47 | 48 | #include "../code/DefaultIOSystem.h" 49 | #include 50 | #include 51 | #include 52 | 53 | namespace Assimp { 54 | 55 | // --------------------------------------------------------------------------- 56 | /** Android extension to DefaultIOSystem using the standard C file functions */ 57 | class ASSIMP_API AndroidJNIIOSystem : public DefaultIOSystem 58 | { 59 | public: 60 | 61 | /** Initialize android activity data */ 62 | std::string mApkWorkspacePath; 63 | AAssetManager* mApkAssetManager; 64 | 65 | /** Constructor. */ 66 | AndroidJNIIOSystem(ANativeActivity* activity); 67 | 68 | /** Destructor. */ 69 | ~AndroidJNIIOSystem(); 70 | 71 | // ------------------------------------------------------------------- 72 | /** Tests for the existence of a file at the given path. */ 73 | bool Exists( const char* pFile) const; 74 | 75 | // ------------------------------------------------------------------- 76 | /** Opens a file at the given path, with given mode */ 77 | IOStream* Open( const char* strFile, const char* strMode); 78 | 79 | // ------------------------------------------------------------------------------------------------ 80 | // Inits Android extractor 81 | void AndroidActivityInit(ANativeActivity* activity); 82 | 83 | // ------------------------------------------------------------------------------------------------ 84 | // Extracts android asset 85 | bool AndroidExtractAsset(std::string name); 86 | 87 | }; 88 | 89 | } //!ns Assimp 90 | 91 | #endif //AI_ANDROIDJNIIOSYSTEM_H_INC 92 | #endif //__ANDROID__ and __ANDROID_API__ > 9 and defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT) 93 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/quaternion.h: -------------------------------------------------------------------------------- 1 | /* 2 | Open Asset Import Library (assimp) 3 | ---------------------------------------------------------------------- 4 | 5 | Copyright (c) 2006-2016, assimp team 6 | All rights reserved. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of the assimp team, nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of the assimp team. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | ---------------------------------------------------------------------- 39 | */ 40 | 41 | /** @file quaternion.h 42 | * @brief Quaternion structure, including operators when compiling in C++ 43 | */ 44 | #ifndef AI_QUATERNION_H_INC 45 | #define AI_QUATERNION_H_INC 46 | 47 | #ifdef __cplusplus 48 | 49 | template class aiVector3t; 50 | template class aiMatrix3x3t; 51 | 52 | // --------------------------------------------------------------------------- 53 | /** Represents a quaternion in a 4D vector. */ 54 | template 55 | class aiQuaterniont 56 | { 57 | public: 58 | aiQuaterniont() : w(1.0), x(), y(), z() {} 59 | aiQuaterniont(TReal pw, TReal px, TReal py, TReal pz) 60 | : w(pw), x(px), y(py), z(pz) {} 61 | 62 | /** Construct from rotation matrix. Result is undefined if the matrix is not orthonormal. */ 63 | explicit aiQuaterniont( const aiMatrix3x3t& pRotMatrix); 64 | 65 | /** Construct from euler angles */ 66 | aiQuaterniont( TReal rotx, TReal roty, TReal rotz); 67 | 68 | /** Construct from an axis-angle pair */ 69 | aiQuaterniont( aiVector3t axis, TReal angle); 70 | 71 | /** Construct from a normalized quaternion stored in a vec3 */ 72 | explicit aiQuaterniont( aiVector3t normalized); 73 | 74 | /** Returns a matrix representation of the quaternion */ 75 | aiMatrix3x3t GetMatrix() const; 76 | 77 | public: 78 | 79 | bool operator== (const aiQuaterniont& o) const; 80 | bool operator!= (const aiQuaterniont& o) const; 81 | 82 | bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const; 83 | 84 | public: 85 | 86 | /** Normalize the quaternion */ 87 | aiQuaterniont& Normalize(); 88 | 89 | /** Compute quaternion conjugate */ 90 | aiQuaterniont& Conjugate (); 91 | 92 | /** Rotate a point by this quaternion */ 93 | aiVector3t Rotate (const aiVector3t& in); 94 | 95 | /** Multiply two quaternions */ 96 | aiQuaterniont operator* (const aiQuaterniont& two) const; 97 | 98 | public: 99 | 100 | /** Performs a spherical interpolation between two quaternions and writes the result into the third. 101 | * @param pOut Target object to received the interpolated rotation. 102 | * @param pStart Start rotation of the interpolation at factor == 0. 103 | * @param pEnd End rotation, factor == 1. 104 | * @param pFactor Interpolation factor between 0 and 1. Values outside of this range yield undefined results. 105 | */ 106 | static void Interpolate( aiQuaterniont& pOut, const aiQuaterniont& pStart, 107 | const aiQuaterniont& pEnd, TReal pFactor); 108 | 109 | public: 110 | 111 | //! w,x,y,z components of the quaternion 112 | TReal w, x, y, z; 113 | } ; 114 | 115 | typedef aiQuaterniont aiQuaternion; 116 | 117 | #else 118 | 119 | struct aiQuaternion { 120 | float w, x, y, z; 121 | }; 122 | 123 | #endif 124 | 125 | 126 | #endif // AI_QUATERNION_H_INC 127 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/vector2.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2016, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | /** @file vector2.h 42 | * @brief 2D vector structure, including operators when compiling in C++ 43 | */ 44 | #ifndef AI_VECTOR2D_H_INC 45 | #define AI_VECTOR2D_H_INC 46 | 47 | #ifdef __cplusplus 48 | # include 49 | #else 50 | # include 51 | #endif 52 | 53 | #include "./Compiler/pushpack1.h" 54 | 55 | // ---------------------------------------------------------------------------------- 56 | /** Represents a two-dimensional vector. 57 | */ 58 | 59 | #ifdef __cplusplus 60 | template 61 | class aiVector2t 62 | { 63 | public: 64 | 65 | aiVector2t () : x(), y() {} 66 | aiVector2t (TReal _x, TReal _y) : x(_x), y(_y) {} 67 | explicit aiVector2t (TReal _xyz) : x(_xyz), y(_xyz) {} 68 | aiVector2t (const aiVector2t& o) : x(o.x), y(o.y) {} 69 | 70 | public: 71 | 72 | void Set( TReal pX, TReal pY); 73 | TReal SquareLength() const ; 74 | TReal Length() const ; 75 | aiVector2t& Normalize(); 76 | 77 | public: 78 | 79 | const aiVector2t& operator += (const aiVector2t& o); 80 | const aiVector2t& operator -= (const aiVector2t& o); 81 | const aiVector2t& operator *= (TReal f); 82 | const aiVector2t& operator /= (TReal f); 83 | 84 | TReal operator[](unsigned int i) const; 85 | TReal& operator[](unsigned int i); 86 | 87 | bool operator== (const aiVector2t& other) const; 88 | bool operator!= (const aiVector2t& other) const; 89 | 90 | bool Equal(const aiVector2t& other, TReal epsilon = 1e-6) const; 91 | 92 | aiVector2t& operator= (TReal f); 93 | const aiVector2t SymMul(const aiVector2t& o); 94 | 95 | template 96 | operator aiVector2t () const; 97 | 98 | TReal x, y; 99 | } PACK_STRUCT; 100 | 101 | typedef aiVector2t aiVector2D; 102 | 103 | #else 104 | 105 | struct aiVector2D { 106 | float x, y; 107 | }; 108 | 109 | #endif // __cplusplus 110 | 111 | #include "./Compiler/poppack1.h" 112 | 113 | #endif // AI_VECTOR2D_H_INC 114 | -------------------------------------------------------------------------------- /Source/Externals/inc/assimp/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Open Asset Import Library (assimp) 4 | --------------------------------------------------------------------------- 5 | 6 | Copyright (c) 2006-2016, assimp team 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use of this software in source and binary forms, 11 | with or without modification, are permitted provided that the following 12 | conditions are met: 13 | 14 | * Redistributions of source code must retain the above 15 | copyright notice, this list of conditions and the 16 | following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above 19 | copyright notice, this list of conditions and the 20 | following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | * Neither the name of the assimp team, nor the names of its 24 | contributors may be used to endorse or promote products 25 | derived from this software without specific prior 26 | written permission of the assimp team. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | --------------------------------------------------------------------------- 40 | */ 41 | 42 | /** @file version.h 43 | * @brief Functions to query the version of the Assimp runtime, check 44 | * compile flags, ... 45 | */ 46 | #ifndef INCLUDED_AI_VERSION_H 47 | #define INCLUDED_AI_VERSION_H 48 | 49 | #include "defs.h" 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | // --------------------------------------------------------------------------- 56 | /** @brief Returns a string with legal copyright and licensing information 57 | * about Assimp. The string may include multiple lines. 58 | * @return Pointer to static string. 59 | */ 60 | ASSIMP_API const char* aiGetLegalString (void); 61 | 62 | // --------------------------------------------------------------------------- 63 | /** @brief Returns the current minor version number of Assimp. 64 | * @return Minor version of the Assimp runtime the application was 65 | * linked/built against 66 | */ 67 | ASSIMP_API unsigned int aiGetVersionMinor (void); 68 | 69 | // --------------------------------------------------------------------------- 70 | /** @brief Returns the current major version number of Assimp. 71 | * @return Major version of the Assimp runtime the application was 72 | * linked/built against 73 | */ 74 | ASSIMP_API unsigned int aiGetVersionMajor (void); 75 | 76 | // --------------------------------------------------------------------------- 77 | /** @brief Returns the repository revision of the Assimp runtime. 78 | * @return SVN Repository revision number of the Assimp runtime the 79 | * application was linked/built against. 80 | */ 81 | ASSIMP_API unsigned int aiGetVersionRevision (void); 82 | 83 | //! Assimp was compiled as a shared object (Windows: DLL) 84 | #define ASSIMP_CFLAGS_SHARED 0x1 85 | //! Assimp was compiled against STLport 86 | #define ASSIMP_CFLAGS_STLPORT 0x2 87 | //! Assimp was compiled as a debug build 88 | #define ASSIMP_CFLAGS_DEBUG 0x4 89 | 90 | //! Assimp was compiled with ASSIMP_BUILD_BOOST_WORKAROUND defined 91 | #define ASSIMP_CFLAGS_NOBOOST 0x8 92 | //! Assimp was compiled with ASSIMP_BUILD_SINGLETHREADED defined 93 | #define ASSIMP_CFLAGS_SINGLETHREADED 0x10 94 | 95 | // --------------------------------------------------------------------------- 96 | /** @brief Returns assimp's compile flags 97 | * @return Any bitwise combination of the ASSIMP_CFLAGS_xxx constants. 98 | */ 99 | ASSIMP_API unsigned int aiGetCompileFlags (void); 100 | 101 | #ifdef __cplusplus 102 | } // end extern "C" 103 | #endif 104 | 105 | #endif // !! #ifndef INCLUDED_AI_VERSION_H 106 | -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/GL/freeglut.h: -------------------------------------------------------------------------------- 1 | #ifndef __FREEGLUT_H__ 2 | #define __FREEGLUT_H__ 3 | 4 | /* 5 | * freeglut.h 6 | * 7 | * The freeglut library include file 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 10 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 12 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | */ 16 | 17 | #include "freeglut_std.h" 18 | #include "freeglut_ext.h" 19 | 20 | /*** END OF FILE ***/ 21 | 22 | #endif /* __FREEGLUT_H__ */ 23 | -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/GL/freeglut_ext.h: -------------------------------------------------------------------------------- 1 | #ifndef __FREEGLUT_EXT_H__ 2 | #define __FREEGLUT_EXT_H__ 3 | 4 | /* 5 | * freeglut_ext.h 6 | * 7 | * The non-GLUT-compatible extensions to the freeglut library include file 8 | * 9 | * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved. 10 | * Written by Pawel W. Olszta, 11 | * Creation date: Thu Dec 2 1999 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a 14 | * copy of this software and associated documentation files (the "Software"), 15 | * to deal in the Software without restriction, including without limitation 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | * and/or sell copies of the Software, and to permit persons to whom the 18 | * Software is furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included 21 | * in all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 27 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 28 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* 36 | * GLUT API Extension macro definitions -- behaviour when the user clicks on an "x" to close a window 37 | */ 38 | #define GLUT_ACTION_EXIT 0 39 | #define GLUT_ACTION_GLUTMAINLOOP_RETURNS 1 40 | #define GLUT_ACTION_CONTINUE_EXECUTION 2 41 | 42 | /* 43 | * Create a new rendering context when the user opens a new window? 44 | */ 45 | #define GLUT_CREATE_NEW_CONTEXT 0 46 | #define GLUT_USE_CURRENT_CONTEXT 1 47 | 48 | /* 49 | * GLUT API Extension macro definitions -- the glutGet parameters 50 | */ 51 | #define GLUT_ACTION_ON_WINDOW_CLOSE 0x01F9 52 | 53 | #define GLUT_WINDOW_BORDER_WIDTH 0x01FA 54 | #define GLUT_WINDOW_HEADER_HEIGHT 0x01FB 55 | 56 | #define GLUT_VERSION 0x01FC 57 | 58 | #define GLUT_RENDERING_CONTEXT 0x01FD 59 | 60 | /* 61 | * Process loop function, see freeglut_main.c 62 | */ 63 | FGAPI void FGAPIENTRY glutMainLoopEvent(void); 64 | FGAPI void FGAPIENTRY glutLeaveMainLoop(void); 65 | 66 | /* 67 | * Window-specific callback functions, see freeglut_callbacks.c 68 | */ 69 | FGAPI void FGAPIENTRY glutMouseWheelFunc(void (* callback)(int, int, int, int)); 70 | FGAPI void FGAPIENTRY glutCloseFunc(void (* callback)(void)); 71 | FGAPI void FGAPIENTRY glutWMCloseFunc(void (* callback)(void)); 72 | /* A. Donev: Also a destruction callback for menus */ 73 | FGAPI void FGAPIENTRY glutMenuDestroyFunc(void (* callback)(void)); 74 | 75 | /* 76 | * State setting and retrieval functions, see freeglut_state.c 77 | */ 78 | FGAPI void FGAPIENTRY glutSetOption(GLenum option_flag, int value) ; 79 | /* A.Donev: User-data manipulation */ 80 | FGAPI void *FGAPIENTRY glutGetWindowData(void); 81 | FGAPI void FGAPIENTRY glutSetWindowData(void *data); 82 | FGAPI void *FGAPIENTRY glutGetMenuData(void); 83 | FGAPI void FGAPIENTRY glutSetMenuData(void *data); 84 | 85 | /* 86 | * Font stuff, see freeglut_font.c 87 | */ 88 | FGAPI int FGAPIENTRY glutBitmapHeight(void *font); 89 | FGAPI GLfloat FGAPIENTRY glutStrokeHeight(void *font); 90 | FGAPI void FGAPIENTRY glutBitmapString(void *font, const unsigned char *string); 91 | FGAPI void FGAPIENTRY glutStrokeString(void *font, const unsigned char *string); 92 | 93 | /* 94 | * Geometry functions, see freeglut_geometry.c 95 | */ 96 | FGAPI void FGAPIENTRY glutWireRhombicDodecahedron(void); 97 | FGAPI void FGAPIENTRY glutSolidRhombicDodecahedron(void); 98 | FGAPI void FGAPIENTRY glutWireSierpinskiSponge(int num_levels, GLdouble offset[3], GLdouble scale) ; 99 | FGAPI void FGAPIENTRY glutSolidSierpinskiSponge(int num_levels, GLdouble offset[3], GLdouble scale) ; 100 | FGAPI void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks); 101 | FGAPI void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks); 102 | 103 | /* 104 | * Extension functions, see freeglut_ext.c 105 | */ 106 | FGAPI void *FGAPIENTRY glutGetProcAddress(const char *procName); 107 | 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | /*** END OF FILE ***/ 114 | 115 | #endif /* __FREEGLUT_EXT_H__ */ 116 | -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/dynlink/cuda_drvapi_dynlink.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | #ifndef __cuda_drvapi_dynlink_h__ 13 | #define __cuda_drvapi_dynlink_h__ 14 | 15 | #include "cuda_drvapi_dynlink_cuda.h" 16 | 17 | #if defined(CUDA_INIT_D3D9)||defined(CUDA_INIT_D3D10)||defined(CUDA_INIT_D3D11) 18 | #include "cuda_drvapi_dynlink_d3d.h" 19 | #endif 20 | 21 | #ifdef CUDA_INIT_OPENGL 22 | #include "cuda_drvapi_dynlink_gl.h" 23 | #endif 24 | 25 | #endif //__cuda_drvapi_dynlink_h__ 26 | -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/dynlink/cuda_drvapi_dynlink_gl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | #ifndef __cuda_drvapi_dynlink_cuda_gl_h__ 13 | #define __cuda_drvapi_dynlink_cuda_gl_h__ 14 | 15 | #ifdef CUDA_INIT_OPENGL 16 | 17 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 18 | # define WINDOWS_LEAN_AND_MEAN 19 | # define NOMINMAX 20 | # include 21 | #endif 22 | 23 | // includes, system 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | // includes, GL 30 | #include 31 | 32 | #if defined (__APPLE__) || defined(MACOSX) 33 | #include 34 | #else 35 | #include 36 | #endif 37 | 38 | /************************************ 39 | ** 40 | ** OpenGL Graphics/Interop 41 | ** 42 | ***********************************/ 43 | 44 | // OpenGL/CUDA interop (CUDA 2.0+) 45 | typedef CUresult CUDAAPI tcuGLCtxCreate(CUcontext *pCtx, unsigned int Flags, CUdevice device); 46 | typedef CUresult CUDAAPI tcuGraphicsGLRegisterBuffer(CUgraphicsResource *pCudaResource, GLuint buffer, unsigned int Flags); 47 | typedef CUresult CUDAAPI tcuGraphicsGLRegisterImage(CUgraphicsResource *pCudaResource, GLuint image, GLenum target, unsigned int Flags); 48 | 49 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 50 | #include 51 | // WIN32 52 | typedef CUresult CUDAAPI tcuWGLGetDevice(CUdevice *pDevice, HGPUNV hGpu); 53 | #endif 54 | 55 | #endif // CUDA_INIT_OPENGL 56 | 57 | #endif // __cuda_drvapi_dynlink_cuda_gl_h__ 58 | 59 | -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/helper_functions.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | // These are helper functions for the SDK samples (string parsing, timers, image helpers, etc) 13 | #ifndef HELPER_FUNCTIONS_H 14 | #define HELPER_FUNCTIONS_H 15 | 16 | #ifdef WIN32 17 | #pragma warning(disable:4996) 18 | #endif 19 | 20 | // includes, project 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | // includes, timer, string parsing, image helpers 34 | #include // helper functions for timers 35 | #include // helper functions for string parsing 36 | #include // helper functions for image compare, dump, data comparisons 37 | 38 | #ifndef EXIT_WAIVED 39 | #define EXIT_WAIVED 2 40 | #endif 41 | 42 | #endif // HELPER_FUNCTIONS_H 43 | -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/multithreading.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | #ifndef MULTITHREADING_H 13 | #define MULTITHREADING_H 14 | 15 | 16 | //Simple portable thread library. 17 | 18 | //Windows threads. 19 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 20 | #include 21 | 22 | typedef HANDLE CUTThread; 23 | typedef unsigned(WINAPI *CUT_THREADROUTINE)(void *); 24 | 25 | #define CUT_THREADPROC unsigned WINAPI 26 | #define CUT_THREADEND return 0 27 | 28 | #else 29 | //POSIX threads. 30 | #include 31 | 32 | typedef pthread_t CUTThread; 33 | typedef void *(*CUT_THREADROUTINE)(void *); 34 | 35 | #define CUT_THREADPROC void 36 | #define CUT_THREADEND 37 | #endif 38 | 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | //Create thread. 45 | CUTThread cutStartThread(CUT_THREADROUTINE, void *data); 46 | 47 | //Wait for thread to finish. 48 | void cutEndThread(CUTThread thread); 49 | 50 | //Destroy thread. 51 | void cutDestroyThread(CUTThread thread); 52 | 53 | //Wait for multiple threads. 54 | void cutWaitForThreads(const CUTThread *threads, int num); 55 | 56 | #ifdef __cplusplus 57 | } //extern "C" 58 | #endif 59 | 60 | #endif //MULTITHREADING_H 61 | -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/nvMath.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | // 13 | // Template math library for common 3D functionality 14 | // 15 | // This code is in part deriver from glh, a cross platform glut helper library. 16 | // The copyright for glh follows this notice. 17 | // 18 | // Copyright (c) NVIDIA Corporation. All rights reserved. 19 | //////////////////////////////////////////////////////////////////////////////// 20 | 21 | /* 22 | Copyright (c) 2000 Cass Everitt 23 | Copyright (c) 2000 NVIDIA Corporation 24 | All rights reserved. 25 | 26 | Redistribution and use in source and binary forms, with or 27 | without modification, are permitted provided that the following 28 | conditions are met: 29 | 30 | * Redistributions of source code must retain the above 31 | copyright notice, this list of conditions and the following 32 | disclaimer. 33 | 34 | * Redistributions in binary form must reproduce the above 35 | copyright notice, this list of conditions and the following 36 | disclaimer in the documentation and/or other materials 37 | provided with the distribution. 38 | 39 | * The names of contributors to this software may not be used 40 | to endorse or promote products derived from this software 41 | without specific prior written permission. 42 | 43 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 44 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 45 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 46 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 47 | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 48 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 50 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 51 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 52 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 53 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 54 | POSSIBILITY OF SUCH DAMAGE. 55 | 56 | 57 | Cass Everitt - cass@r3.nu 58 | */ 59 | 60 | #ifndef NV_MATH_H 61 | #define NV_MATH_H 62 | 63 | #include 64 | 65 | #include 66 | #include 67 | #include 68 | 69 | #define NV_PI float(3.1415926535897932384626433832795) 70 | 71 | namespace nv 72 | { 73 | 74 | typedef vec2 vec2f; 75 | typedef vec3 vec3f; 76 | typedef vec3 vec3i; 77 | typedef vec3 vec3ui; 78 | typedef vec4 vec4f; 79 | typedef matrix4 matrix4f; 80 | typedef quaternion quaternionf; 81 | 82 | 83 | inline void applyRotation(const quaternionf &r) 84 | { 85 | float angle; 86 | vec3f axis; 87 | r.get_value(axis, angle); 88 | glRotatef(angle/3.1415926f * 180.0f, axis[0], axis[1], axis[2]); 89 | } 90 | 91 | 92 | 93 | }; 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/nvrtc_helper.h: -------------------------------------------------------------------------------- 1 | #if !defined(__NVRTC_HELPER__) 2 | 3 | #define __NVRTC_HELPER__ 1 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define NVRTC_SAFE_CALL(Name, x) \ 13 | do { \ 14 | nvrtcResult result = x; \ 15 | if (result != NVRTC_SUCCESS) { \ 16 | std::cerr << "\nerror: " << Name << " failed with error " << \ 17 | nvrtcGetErrorString(result); \ 18 | exit(1); \ 19 | } \ 20 | } while(0) 21 | 22 | void compileFileToPTX(char *filename, int argc, const char **argv, 23 | char **ptxResult, size_t *ptxResultSize) 24 | { 25 | std::ifstream inputFile(filename, std::ios::in | std::ios::binary | 26 | std::ios::ate); 27 | 28 | if (!inputFile.is_open()) 29 | { 30 | std::cerr << "\nerror: unable to open " << filename << " for reading!\n"; 31 | exit(1); 32 | } 33 | 34 | std::streampos pos = inputFile.tellg(); 35 | size_t inputSize = (size_t)pos; 36 | char * memBlock = new char [inputSize + 1]; 37 | 38 | inputFile.seekg (0, std::ios::beg); 39 | inputFile.read (memBlock, inputSize); 40 | inputFile.close(); 41 | memBlock[inputSize] = '\x0'; 42 | 43 | // compile 44 | nvrtcProgram prog; 45 | NVRTC_SAFE_CALL("nvrtcCreateProgram", nvrtcCreateProgram(&prog, memBlock, 46 | filename, 0, NULL, NULL)); 47 | nvrtcResult res = nvrtcCompileProgram(prog, argc, argv); 48 | 49 | // dump log 50 | size_t logSize; 51 | NVRTC_SAFE_CALL("nvrtcGetProgramLogSize", nvrtcGetProgramLogSize(prog, &logSize)); 52 | char *log = (char *) malloc(sizeof(char) * logSize + 1); 53 | NVRTC_SAFE_CALL("nvrtcGetProgramLog", nvrtcGetProgramLog(prog, log)); 54 | log[logSize] = '\x0'; 55 | 56 | /* 57 | std::cerr << "\n compilation log ---\n"; 58 | std::cerr << log; 59 | std::cerr << "\n end log ---\n"; 60 | */ 61 | free(log); 62 | 63 | NVRTC_SAFE_CALL("nvrtcCompileProgram", res); 64 | // fetch PTX 65 | size_t ptxSize; 66 | NVRTC_SAFE_CALL("nvrtcGetPTXSize", nvrtcGetPTXSize(prog, &ptxSize)); 67 | char *ptx = (char *) malloc(sizeof(char) * ptxSize); 68 | NVRTC_SAFE_CALL("nvrtcGetPTX", nvrtcGetPTX(prog, ptx)); 69 | NVRTC_SAFE_CALL("nvrtcDestroyProgram", nvrtcDestroyProgram(&prog)); 70 | *ptxResult = ptx; 71 | *ptxResultSize = ptxSize; 72 | } 73 | 74 | CUmodule loadPTX(char *ptx, int argc, char **argv) 75 | { 76 | CUmodule module; 77 | CUcontext context; 78 | int major = 0, minor = 0; 79 | char deviceName[256]; 80 | 81 | // Picks the best CUDA device available 82 | CUdevice cuDevice = findCudaDeviceDRV(argc, (const char **)argv); 83 | 84 | // get compute capabilities and the devicename 85 | checkCudaErrors(cuDeviceComputeCapability(&major, &minor, cuDevice)); 86 | checkCudaErrors(cuDeviceGetName(deviceName, 256, cuDevice)); 87 | printf("> GPU Device has SM %d.%d compute capability\n", major, minor); 88 | 89 | checkCudaErrors(cuInit(0)); 90 | checkCudaErrors(cuDeviceGet(&cuDevice, 0)); 91 | checkCudaErrors(cuCtxCreate(&context, 0, cuDevice)); 92 | 93 | checkCudaErrors(cuModuleLoadDataEx(&module, ptx, 0, 0, 0)); 94 | 95 | return module; 96 | } 97 | 98 | #endif 99 | 100 | -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/rendercheck_d3d10.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | #pragma once 13 | 14 | #ifndef _RENDERCHECK_D3D10_H_ 15 | #define _RENDERCHECK_D3D10_H_ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | class CheckRenderD3D10 25 | { 26 | public: 27 | 28 | CheckRenderD3D10() {} 29 | 30 | static HRESULT ActiveRenderTargetToPPM(ID3D10Device *pDevice, const char *zFileName); 31 | static HRESULT ResourceToPPM(ID3D10Device *pDevice, ID3D10Resource *pResource, const char *zFileName); 32 | 33 | static bool PPMvsPPM(const char *src_file, const char *ref_file, const char *exec_path, 34 | const float epsilon, const float threshold = 0.0f); 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/rendercheck_d3d11.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | #pragma once 13 | 14 | #ifndef _RENDERCHECK_D3D11_H_ 15 | #define _RENDERCHECK_D3D11_H_ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | class CheckRenderD3D11 25 | { 26 | public: 27 | 28 | CheckRenderD3D11() {} 29 | 30 | static HRESULT ActiveRenderTargetToPPM(ID3D11Device *pDevice, const char *zFileName); 31 | static HRESULT ResourceToPPM(ID3D11Device *pDevice, ID3D11Resource *pResource, const char *zFileName); 32 | 33 | static bool PPMvsPPM(const char *src_file, const char *ref_file, const char *exec_path, 34 | const float epsilon, const float threshold = 0.0f); 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/rendercheck_d3d9.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | #pragma once 13 | 14 | #ifndef _RENDERCHECK_D3D9_H_ 15 | #define _RENDERCHECK_D3D9_H_ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | class CheckRenderD3D9 24 | { 25 | public: 26 | 27 | CheckRenderD3D9() {} 28 | 29 | static HRESULT BackbufferToPPM(IDirect3DDevice9 *pDevice, const char *zFileName); 30 | static HRESULT SurfaceToPPM(IDirect3DDevice9 *pDevice, IDirect3DSurface9 *pSurface, const char *zFileName); 31 | 32 | static bool PPMvsPPM(const char *src_file, const char *ref_file, const char *exec_path, 33 | const float epsilon, const float threshold = 0.0f); 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /Source/Externals/inc/cuda/timer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | #ifndef TIMER_H 13 | #define TIMER_H 14 | 15 | #include 16 | 17 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 18 | #define WIN32_LEAN_AND_MEAN 19 | #include 20 | #else 21 | #include 22 | #endif 23 | 24 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 25 | double PCFreq = 0.0; 26 | __int64 timerStart = 0; 27 | #else 28 | struct timeval timerStart; 29 | #endif 30 | 31 | void StartTimer() 32 | { 33 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 34 | LARGE_INTEGER li; 35 | 36 | if (!QueryPerformanceFrequency(&li)) 37 | { 38 | printf("QueryPerformanceFrequency failed!\n"); 39 | } 40 | 41 | PCFreq = (double)li.QuadPart/1000.0; 42 | QueryPerformanceCounter(&li); 43 | timerStart = li.QuadPart; 44 | #else 45 | gettimeofday(&timerStart, NULL); 46 | #endif 47 | } 48 | 49 | // time elapsed in ms 50 | double GetTimer() 51 | { 52 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 53 | LARGE_INTEGER li; 54 | QueryPerformanceCounter(&li); 55 | return (double)(li.QuadPart-timerStart)/PCFreq; 56 | #else 57 | struct timeval timerStop, timerElapsed; 58 | gettimeofday(&timerStop, NULL); 59 | timersub(&timerStop, &timerStart, &timerElapsed); 60 | return timerElapsed.tv_sec*1000.0+timerElapsed.tv_usec/1000.0; 61 | #endif 62 | } 63 | #endif // TIMER_H 64 | 65 | -------------------------------------------------------------------------------- /Source/Externals/inc/gProximity/README.txt: -------------------------------------------------------------------------------- 1 | * gProximity Library. 2 | * 3 | * 4 | * Copyright (C) 2010 University of North Carolina at Chapel Hill. 5 | * All rights reserved. 6 | * 7 | * Permission to use, copy, modify, and distribute this software and its 8 | * documentation for educational, research, and non-profit purposes, without 9 | * fee, and without a written agreement is hereby granted, provided that the 10 | * above copyright notice, this paragraph, and the following four paragraphs 11 | * appear in all copies. 12 | * 13 | * Permission to incorporate this software into commercial products may be 14 | * obtained by contacting the University of North Carolina at Chapel Hill. 15 | * 16 | * This software program and documentation are copyrighted by the University of 17 | * North Carolina at Chapel Hill. The software program and documentation are 18 | * supplied "as is", without any accompanying services from the University of 19 | * North Carolina at Chapel Hill or the authors. The University of North 20 | * Carolina at Chapel Hill and the authors do not warrant that the operation of 21 | * the program will be uninterrupted or error-free. The end-user understands 22 | * that the program was developed for research purposes and is advised not to 23 | * rely exclusively on the program for any reason. 24 | * 25 | * IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR ITS 26 | * EMPLOYEES OR THE AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, 27 | * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, 28 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE 29 | * UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED 30 | * OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY 33 | * DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 34 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY 35 | * STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS 36 | * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND 37 | * THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 38 | * ENHANCEMENTS, OR MODIFICATIONS. 39 | * 40 | * Please send all BUG REPORTS to: 41 | * 42 | * geom@cs.unc.edu 43 | * 44 | * The authors may be contacted via: 45 | * 46 | * Christian Lauterbach, Qi Mo, Jia Pan and Dinesh Manocha 47 | * Dept. of Computer Science 48 | * Frederick P. Brooks Jr. Computer Science Bldg. 49 | * 3175 University of N.C. 50 | * Chapel Hill, N.C. 27599-3175 51 | * United States of America 52 | * 53 | * http://gamma.cs.unc.edu/GPUCOL/ 54 | -------------------------------------------------------------------------------- /Source/Externals/lib/vs2013x64/assimp-vc120-mt.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2013x64/assimp-vc120-mt.dll -------------------------------------------------------------------------------- /Source/Externals/lib/vs2013x64/assimp-vc120-mt.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2013x64/assimp-vc120-mt.lib -------------------------------------------------------------------------------- /Source/Externals/lib/vs2015x64/assimp-vc140-mt.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2015x64/assimp-vc140-mt.dll -------------------------------------------------------------------------------- /Source/Externals/lib/vs2015x64/assimp-vc140-mt.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2015x64/assimp-vc140-mt.lib -------------------------------------------------------------------------------- /Source/Externals/lib/vs2015x64/assimp-vc140-mtd.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2015x64/assimp-vc140-mtd.dll -------------------------------------------------------------------------------- /Source/Externals/lib/vs2015x64/assimp-vc140-mtd.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2015x64/assimp-vc140-mtd.lib -------------------------------------------------------------------------------- /Source/Externals/lib/vs2015x86/assimp-vc140-mt.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2015x86/assimp-vc140-mt.dll -------------------------------------------------------------------------------- /Source/Externals/lib/vs2015x86/assimp-vc140-mt.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2015x86/assimp-vc140-mt.lib -------------------------------------------------------------------------------- /Source/Externals/lib/vs2015x86/assimp-vc140-mtd.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2015x86/assimp-vc140-mtd.dll -------------------------------------------------------------------------------- /Source/Externals/lib/vs2015x86/assimp-vc140-mtd.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Source/Externals/lib/vs2015x86/assimp-vc140-mtd.lib -------------------------------------------------------------------------------- /Source/Project/Mine/Frameworks/AppBase/AppBase.cpp: -------------------------------------------------------------------------------- 1 | #include "AppBase.h" 2 | 3 | namespace mn { 4 | 5 | AppBase* AppBase::TheApplication = nullptr; 6 | AppBase::EntryPoint AppBase::Run = nullptr; 7 | 8 | AppBase::AppBase() {} 9 | AppBase::~AppBase() {} 10 | 11 | } -------------------------------------------------------------------------------- /Source/Project/Mine/Frameworks/AppBase/AppBase.h: -------------------------------------------------------------------------------- 1 | #ifndef __APP_BASE_H_ 2 | #define __APP_BASE_H_ 3 | 4 | 5 | namespace mn { 6 | 7 | class AppBase { 8 | public: 9 | virtual ~AppBase(); 10 | 11 | static AppBase* TheApplication; 12 | 13 | typedef int(*EntryPoint)(int, char**); 14 | static EntryPoint Run; 15 | 16 | protected: 17 | AppBase(); 18 | 19 | }; 20 | 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/Frameworks/AppBase/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | namespace mn { 4 | 5 | Main::InitializerArray* Main::s_pkInitializers = nullptr; 6 | Main::TerminatorArray* Main::s_pkTerminators = nullptr; 7 | int Main::s_iStartObjects = 0; 8 | int Main::s_iFinalObjects = 0; 9 | 10 | void Main::AddInitializer(Initializer oInitialize) { 11 | if (!s_pkInitializers) 12 | s_pkInitializers = new InitializerArray; 13 | s_pkInitializers->push_back(oInitialize); 14 | } 15 | 16 | void Main::Initialize() { 17 | if (s_pkInitializers) 18 | for (int i = 0; i < s_pkInitializers->size(); i++) 19 | (*s_pkInitializers)[i](); 20 | delete s_pkInitializers; 21 | s_pkInitializers = nullptr; 22 | } 23 | 24 | void Main::AddTerminator(Terminator oTerminate) { 25 | if (!s_pkTerminators) 26 | s_pkTerminators = new TerminatorArray; 27 | s_pkTerminators->push_back(oTerminate); 28 | } 29 | 30 | void Main::Terminate() { 31 | if (s_pkTerminators) 32 | for (int i = 0; i < s_pkTerminators->size(); i++) 33 | (*s_pkTerminators)[i](); 34 | delete s_pkTerminators; 35 | s_pkTerminators = nullptr; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Source/Project/Mine/Frameworks/AppBase/Main.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIN_H_ 2 | #define __MAIN_H_ 3 | 4 | #include 5 | 6 | namespace mn { 7 | 8 | class Main { 9 | public: 10 | typedef void(*Initializer)(void); 11 | typedef std::vector InitializerArray; 12 | 13 | static void AddInitializer(Initializer oInitialize); ///< sub-system registration 14 | static void Initialize(); 15 | 16 | typedef void(*Terminator)(void); 17 | typedef std::vector TerminatorArray; 18 | 19 | static void AddTerminator(Terminator oTerminate); 20 | static void Terminate(); 21 | 22 | private: 23 | static InitializerArray* s_pkInitializers; 24 | static TerminatorArray* s_pkTerminators; 25 | static int s_iStartObjects; 26 | static int s_iFinalObjects; 27 | }; 28 | 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/Frameworks/CudaProject/CudaProjectApp.cpp: -------------------------------------------------------------------------------- 1 | #include "CudaProjectApp.h" 2 | #include 3 | 4 | // systems 5 | #include "system/Log/Logger.hpp" 6 | #include "system/CudaDevice/CudaDevice.h" 7 | #include "system/Logic/BenchmarkLogic.hpp" 8 | 9 | namespace mn { 10 | 11 | void SimpleApp::Initialize() { 12 | SimpleApp* app; 13 | AppBase::Run = &SimpleApp::Run; 14 | AppBase::TheApplication = app = new SimpleApp; 15 | app->TheCudaDevice = CudaDevice::getInstance(); 16 | app->TheLogic = BenchmarkLogic::getInstance(); 17 | printf("* Finishing App initialization!\n"); 18 | } 19 | 20 | int SimpleApp::Run(int iQuantity, char** apcArguments) { 21 | auto pkTheApp = dynamic_cast(TheApplication); 22 | return pkTheApp->Main(iQuantity, apcArguments); 23 | } 24 | 25 | int SimpleApp::Main(int iQuantity, char** apcArguments) { 26 | reportMemory(); 27 | printf("Begin allocating memory for BVH\n"); 28 | _bvh = std::make_unique>(LBvhBuildConfig{}); 29 | printf("Begin allocating memory for BVTT fronts\n"); 30 | _fl = std::make_unique>(mn::BvttFrontIntraBuildConfig>( 31 | _bvh.get(), BvttFrontType::LooseIntraType, 32 | BvttFrontSettings::ext_front_size(), BvttFrontSettings::int_front_size(), 33 | BvhSettings::ext_node_size(), BvhSettings::int_node_size() 34 | )); 35 | printf("End GPU memory allocations\n"); 36 | 37 | // Main loop 38 | while (true) { 39 | if (!TheLogic->next()) { 40 | if (TheLogic->isBenchmarkFinished()) 41 | Logger::record(TheLogic->previousOutputFile()); 42 | if (getchar() == 'q') break; 43 | continue; 44 | } 45 | if (!_scene.update()) continue; 46 | if (TheLogic->isBenchmarkFinished()) 47 | Logger::record(TheLogic->previousOutputFile()); 48 | 49 | auto maintainOpts = TheLogic->maintainScheme(); 50 | 51 | _bvh->maintain(maintainOpts.first, _scene.getFormatedData()); 52 | _fl->maintain(maintainOpts.second); 53 | 54 | Logger::blankLine(); 55 | } 56 | _fl.reset(); 57 | _bvh.reset(); 58 | return 0; 59 | } 60 | 61 | void SimpleApp::Terminate() { 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /Source/Project/Mine/Frameworks/CudaProject/CudaProjectApp.h: -------------------------------------------------------------------------------- 1 | #ifndef __CUDA_PROJECT_APP_H_ 2 | #define __CUDA_PROJECT_APP_H_ 3 | 4 | #include 5 | #include "base/Singleton.h" 6 | #include "Frameworks/AppBase/AppBase.h" 7 | 8 | // framework modules 9 | #include "world/Scene.h" 10 | #include "collision/lbvh/LBvh.h" 11 | #include "collision/bvtt_front/BVTTFront.h" 12 | 13 | class GLFWwindow; 14 | 15 | namespace mn { 16 | 17 | class BenchmarkLogic; ///< or should be context? 18 | class CudaDevice; 19 | /* 20 | * @note Engine Framework, manages loop/ resources 21 | */ 22 | class SimpleApp : public AppBase { 23 | public: 24 | static void Initialize(); 25 | static int Run(int iQuantity, char** apcArguments); 26 | static void Terminate(); 27 | 28 | virtual int Main(int iQuantity, char** apcArguments); 29 | 30 | protected: 31 | SimpleApp() {} 32 | virtual ~SimpleApp() {} 33 | 34 | private: 35 | /// systems (initialized) 36 | CudaDevice* TheCudaDevice; 37 | BenchmarkLogic* TheLogic; 38 | 39 | // for CD benchmark testing 40 | Scene _scene; 41 | LBvhKernelRegister _kLBvhKernelRegister; 42 | BvttFrontKernelRegister _kFrontKernelRegister; 43 | std::unique_ptr> 44 | _bvh; 45 | std::unique_ptr> 46 | _fl; 47 | }; 48 | 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/Frameworks/CudaProject/CudaProjectModuleRegister.cpp: -------------------------------------------------------------------------------- 1 | #include "CudaProjectModuleRegister.h" 2 | #include "Frameworks/AppBase/Main.h" 3 | 4 | #include "system/Logic/BenchmarkLogic.hpp" 5 | #include "system/CudaDevice/CudaDevice.h" 6 | #include "system/Log/Logger.hpp" 7 | 8 | #include "CudaProjectApp.h" 9 | 10 | namespace mn { 11 | 12 | bool ModuleRegister::RegisterInitialize() { 13 | Main::AddInitializer(CudaDevice::startup); 14 | Main::AddInitializer(Logger::startup); 15 | Main::AddInitializer(BenchmarkLogic::startup); 16 | Main::AddInitializer(SimpleApp::Initialize); 17 | return true; 18 | } 19 | 20 | bool ModuleRegister::RegisterTerminate() { 21 | Main::AddTerminator(SimpleApp::Terminate); 22 | Main::AddTerminator(BenchmarkLogic::shutdown); 23 | Main::AddTerminator(Logger::shutdown); 24 | Main::AddTerminator(CudaDevice::shutdown); 25 | return false; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Source/Project/Mine/Frameworks/CudaProject/CudaProjectModuleRegister.h: -------------------------------------------------------------------------------- 1 | #ifndef __MODULE_REGISTER_H_ 2 | #define __MODULE_REGISTER_H_ 3 | 4 | namespace mn { 5 | 6 | class ModuleRegister { 7 | public: 8 | static bool RegisterInitialize(); 9 | static bool RegisterTerminate(); 10 | 11 | private: 12 | static bool s_bInitializeRegistered; 13 | static bool s_bTerminateRegistered; 14 | }; 15 | 16 | } 17 | 18 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/README.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2018 Zhejiang University. 2 | All rights reserved. 3 | 4 | Permission to use, copy, modify, and distribute this software and its 5 | documentation for educational, research, and non-profit purposes, without 6 | fee, and without a written agreement is hereby granted, provided that the 7 | above copyright notice, this paragraph, and the following four paragraphs 8 | appear in all copies. 9 | 10 | Permission to incorporate this software into commercial products may be 11 | obtained by contacting Zhejiang University. 12 | 13 | This software program and documentation are copyrighted by Zhejiang University. 14 | The software program and documentation are supplied "as is", without any 15 | accompanying services from Zhejiang University or the authors. Zhejiang 16 | University and the authors do not warrant that the operation of the program 17 | will be uninterrupted or error-free. The end-user understands that the program 18 | was developed for research purposes and is advised not to rely exclusively on 19 | the program for any reason. 20 | 21 | IN NO EVENT SHALL ZHEJIANG UNIVERSITY OR ITS EMPLOYEES OR THE AUTHORS BE 22 | LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL 23 | DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND 24 | ITS DOCUMENTATION, EVEN IF ZHEJIANG UNIVERSITY OR THE AUTHORS HAVE BEEN ADVISED 25 | OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ZHEJIANG UNIVERSITY AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, 28 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 29 | FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY OF NON-INFRINGEMENT. 30 | THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND ZHEJIANG UNIVERSITY 31 | AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 32 | ENHANCEMENTS, OR MODIFICATIONS. 33 | 34 | Please send all BUG REPORTS to: 35 | 36 | wxlwxl1993@zju.edu.cn / 37 | tang_m@zju.edu.cn -------------------------------------------------------------------------------- /Source/Project/Mine/base/AggregatedAttribs.h: -------------------------------------------------------------------------------- 1 | /** \file AggregatedAttribs.h 2 | * \brief Base structure for handling CUDA allocated resources in SoA layout 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __AGGREGATED_ATTRIBS_H_ 8 | #define __AGGREGATED_ATTRIBS_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace mn { 14 | 15 | /** 16 | * \brief Constructed on host, copied to device, used in cuda kernels 17 | */ 18 | template 19 | class AttribPort { ///< indices to certain attributes 20 | public: 21 | __host__ __device__ AttribPort() {} 22 | __host__ __device__ ~AttribPort() {} 23 | // selective link copy 24 | __inline__ __host__ void link(void **_hdAttrs, int *stencil) { 25 | for (int i = 0; i < numAttribs; i++) 26 | checkCudaErrors(cudaMemcpy(_ddAttrs + i, _hdAttrs + stencil[i], sizeof(void*), cudaMemcpyHostToHost)); 27 | } 28 | // continuous link copy 29 | __inline__ __host__ void link(void **_hdAttrs, int stpos) { 30 | checkCudaErrors(cudaMemcpy(_ddAttrs, _hdAttrs + stpos, sizeof(void*)*numAttribs, cudaMemcpyHostToHost)); 31 | } 32 | protected: 33 | void* _ddAttrs[numAttribs]; 34 | }; 35 | 36 | /** 37 | * \brief Distributer of ports, managed on host 38 | * \tparam numAttribs 39 | * \tparam numPorts 40 | */ 41 | template 42 | class AttribConnector { 43 | public: 44 | AttribConnector() {} 45 | ~AttribConnector() {} 46 | 47 | protected: 48 | /// manage data 49 | void* _attribs[numAttribs]; ///< cuda allocated arrays 50 | /// distribute ports 51 | void* _ports[numPorts]; 52 | }; 53 | 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/base/Bv.h: -------------------------------------------------------------------------------- 1 | #ifndef __BV_H_ 2 | #define __BV_H_ 3 | 4 | #include "utility/Meta.h" 5 | #include 6 | #include 7 | 8 | namespace mn { 9 | 10 | class AABB { 11 | public: 12 | PointType _min, _max; 13 | 14 | inline __host__ __device__ AABB(); 15 | __host__ __device__ AABB(const AABB& b) { _min = b._min; _max = b._max; } 16 | __host__ __device__ AABB(AABB&& b) { _min = b._min; _max = b._max; } 17 | __host__ __device__ AABB(const ExtentType &minx, const ExtentType &miny, const ExtentType &minz, 18 | const ExtentType &maxx, const ExtentType &maxy, const ExtentType &maxz) { 19 | _min = MakePoint::p(minx, miny, minz); 20 | _max = MakePoint::p(maxx, maxy, maxz); 21 | } 22 | __host__ __device__ AABB(const PointType &v) { _min = _max = v; } 23 | __host__ __device__ AABB(const PointType &v1, const PointType &v2) { 24 | _min = MakePoint::p(::fmin(v1.x, v2.x), ::fmin(v1.y, v2.y), ::fmin(v1.z, v2.z)); 25 | _max = MakePoint::p(::fmax(v1.x, v2.x), ::fmax(v1.y, v2.y), ::fmax(v1.z, v2.z)); 26 | } 27 | __host__ __device__ void combines(const PointType &b) { 28 | _min = MakePoint::p(::fmin(_min.x, b.x), ::fmin(_min.y, b.y), ::fmin(_min.z, b.z)); 29 | _max = MakePoint::p(::fmax(_max.x, b.x), ::fmax(_max.y, b.y), ::fmax(_max.z, b.z)); 30 | } 31 | __host__ __device__ void combines(const ExtentType x, const ExtentType y, const ExtentType z) { 32 | _min = MakePoint::p(::fmin(_min.x, x), ::fmin(_min.y, y), ::fmin(_min.z, z)); 33 | _max = MakePoint::p(::fmax(_max.x, x), ::fmax(_max.y, y), ::fmax(_max.z, z)); 34 | } 35 | __host__ __device__ void combines(const AABB &b) { 36 | _min = MakePoint::p(::fmin(_min.x, b._min.x), ::fmin(_min.y, b._min.y), ::fmin(_min.z, b._min.z)); 37 | _max = MakePoint::p(::fmax(_max.x, b._max.x), ::fmax(_max.y, b._max.y), ::fmax(_max.z, b._max.z)); 38 | } 39 | 40 | __host__ __device__ bool overlaps(const AABB &b) const { 41 | if (b._min.x > _max.x || b._max.x < _min.x) return false; 42 | if (b._min.y > _max.y || b._max.y < _min.y) return false; 43 | if (b._min.z > _max.z || b._max.z < _min.z) return false; 44 | return true; 45 | } 46 | __host__ __device__ bool contains(const PointType &v) const { 47 | return v.x <= _max.x && v.x >= _min.x && 48 | v.y <= _max.y && v.y >= _min.y && 49 | v.z <= _max.z && v.z >= _min.z; 50 | } 51 | __host__ __device__ ExtentType merges(const AABB &a, const AABB &b, ExtentType *qualityMetric) { 52 | _min = MakePoint::p(::fmin(a._min.x, b._min.x), ::fmin(a._min.y, b._min.y), ::fmin(a._min.z, b._min.z)); 53 | _max = MakePoint::p(::fmax(a._max.x, b._max.x), ::fmax(a._max.y, b._max.y), ::fmax(a._max.z, b._max.z)); 54 | *qualityMetric = (a.volume() + b.volume()) / volume(); 55 | return *qualityMetric; 56 | } 57 | __host__ __device__ void merges(const AABB &a, const AABB &b) { 58 | _min = MakePoint::p(::fmin(a._min.x, b._min.x), ::fmin(a._min.y, b._min.y), ::fmin(a._min.z, b._min.z)); 59 | _max = MakePoint::p(::fmax(a._max.x, b._max.x), ::fmax(a._max.y, b._max.y), ::fmax(a._max.z, b._max.z)); 60 | } 61 | 62 | __host__ __device__ ExtentType width() const { return _max.x - _min.x; } 63 | __host__ __device__ ExtentType height() const { return _max.y - _min.y; } 64 | __host__ __device__ ExtentType depth() const { return _max.z - _min.z; } 65 | __host__ __device__ auto center() const -> decltype(MakePoint::p(0, 0, 0)){ 66 | return MakePoint::p((_min.x + _max.x)*0.5, (_min.y + _max.y) *0.5, (_min.z + _max.z)*0.5); 67 | } 68 | __host__ __device__ ExtentType volume() const { return width()*height()*depth(); } 69 | 70 | template 71 | inline __host__ __device__ void empty(); 72 | 73 | //template<> 74 | //__host__ __device__ void empty() { 75 | // _max = MakePoint(-DBL_MAX, -DBL_MAX, -DBL_MAX); 76 | // _min = MakePoint(DBL_MAX, DBL_MAX, DBL_MAX); 77 | //} 78 | }; 79 | 80 | template<> 81 | inline __host__ __device__ void AABB::empty() { 82 | _max = MakePoint::p(-FLT_MAX, -FLT_MAX, -FLT_MAX); 83 | _min = MakePoint::p(FLT_MAX, FLT_MAX, FLT_MAX); 84 | } 85 | 86 | inline __host__ __device__ AABB::AABB() { empty(); } 87 | 88 | using BOX = AABB; 89 | } 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /Source/Project/Mine/base/MultiObject.h: -------------------------------------------------------------------------------- 1 | /** \file MultiObject.h 2 | * \brief Base structure 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __MULTI_OBJECT_H_ 8 | #define __MULTI_OBJECT_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace mn { 16 | 17 | typedef unsigned char uchar; 18 | 19 | template 20 | class MultiObjectH { 21 | public: 22 | MultiObjectH() : _offset(0), _span(1) { 23 | assert(_total % _span == 0); 24 | } 25 | virtual ~MultiObjectH() {} 26 | 27 | /// host access 28 | T& hobj(uchar absID) { 29 | assert(absID < _total); 30 | return h_objs[absID]; 31 | } 32 | T& cho(uchar relID = 0) { ///< current host object 33 | assert(relID < _span); 34 | return h_objs[_offset + relID]; 35 | } 36 | T& nho(uchar relID = 0) { ///< next host object 37 | assert(relID < _span); 38 | return h_objs[(_offset + _span) % _total + relID]; 39 | } 40 | /// 41 | void init(uchar span = 1) { _span = span; } 42 | void slide() { _offset = (_offset + _span) % _total; } 43 | 44 | protected: 45 | /// scroll 46 | uchar _offset, _span; 47 | 48 | private: 49 | /// objects 50 | std::array h_objs; 51 | }; 52 | 53 | template 54 | class MultiObjectD { 55 | public: 56 | MultiObjectD() : _offset(0), _span(1) { 57 | assert(_total % _span == 0); 58 | checkCudaErrors(cudaMalloc((void**)&d_objs, sizeof(T) * _total)); 59 | } 60 | virtual ~MultiObjectD() { 61 | checkCudaErrors(cudaFree(d_objs)); 62 | } 63 | 64 | /// host access 65 | T* dptr(uchar absID) { 66 | assert(absID < _total); 67 | return d_objs + absID; 68 | } 69 | T* cdp(uchar relID) { ///< current host object 70 | assert(relID < _span); 71 | return d_objs + _offset + relID; 72 | } 73 | T* ndp(uchar relID) { ///< next host object 74 | assert(relID < _span); 75 | return d_objs + ((_offset + _span) % _total + relID); 76 | } 77 | /// 78 | void init(uchar span = 1) { _span = span; } 79 | void slide() { _offset = (_offset + _span) % _total; } 80 | 81 | protected: 82 | /// scroll 83 | uchar _offset, _span; 84 | /// objects 85 | T* d_objs; 86 | 87 | }; 88 | 89 | } 90 | 91 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/base/Singleton.h: -------------------------------------------------------------------------------- 1 | #ifndef __SINGLETON_H_ 2 | #define __SINGLETON_H_ 3 | 4 | #include 5 | // http ://www.boost.org/doc/libs/1_39_0/boost/pool/detail/singleton.hpp 6 | 7 | namespace mn { 8 | 9 | /* 10 | * @note Singleton 11 | */ 12 | // T must be: no-throw default constructible and no-throw destructible 13 | template 14 | struct Singleton { 15 | private: 16 | struct SingletonCreator { 17 | // This constructor does nothing more than ensure that instance() 18 | // is called before main() begins, thus creating the static 19 | // T object before multithreading race issues can come up. 20 | SingletonCreator() { Singleton::instance(); } 21 | inline void doNothing() const {} 22 | }; 23 | static SingletonCreator g_Creator; 24 | 25 | // private on purpose 26 | Singleton(); 27 | 28 | public: 29 | // If, at any point (in user code), singleton_default::instance() 30 | // is called, then the following function is instantiated. 31 | static T & instance() { 32 | // This is the object that we return a reference to. 33 | // It is guaranteed to be created before main() begins because of 34 | // the next line. 35 | static T _instance; 36 | 37 | // The following line does nothing else than force the instantiation 38 | // of singleton_default::create_object, whose constructor is 39 | // called before main() begins. 40 | g_Creator.do_nothing(); 41 | 42 | return _instance; 43 | } 44 | }; 45 | template 46 | typename Singleton::SingletonCreator 47 | Singleton::g_Creator; 48 | 49 | /* 50 | * \class ManagedSingleton 51 | * \note Used in global systems 52 | */ 53 | template 54 | struct ManagedSingleton { 55 | 56 | static void startup() { 57 | assert(_pInstance == nullptr); 58 | _pInstance = new T(); 59 | } 60 | static void shutdown() { 61 | assert(_pInstance != nullptr); 62 | delete _pInstance; 63 | } 64 | 65 | protected: 66 | static T* _pInstance; 67 | 68 | public: 69 | /// 70 | T* operator ->() { return _pInstance; } 71 | 72 | static T* getInstance() { 73 | assert(_pInstance != nullptr); 74 | return _pInstance; 75 | } 76 | }; 77 | template 78 | T* ManagedSingleton::_pInstance = nullptr; 79 | } 80 | 81 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/auxiliary/BvhRestrLog.cpp: -------------------------------------------------------------------------------- 1 | #include "BvhRestrLog.h" 2 | #include 3 | #include 4 | #include 5 | 6 | namespace mn { 7 | 8 | BvhRestrLog::BvhRestrLog() {} 9 | BvhRestrLog::~BvhRestrLog() {} 10 | void BvhRestrLog::setup(uint extSize, uint primSize) { 11 | _extSize = extSize; 12 | _primSize = primSize; 13 | /// build attribs 14 | checkCudaErrors(cudaMalloc((void**)&_attribs[EXT_RANGE], sizeof(int)*extSize)); 15 | checkCudaErrors(cudaMalloc((void**)&_attribs[INT_RANGE], sizeof(int)*(extSize - 1))); 16 | checkCudaErrors(cudaMalloc((void**)&_attribs[EXT_RESTR], sizeof(int)*extSize)); 17 | checkCudaErrors(cudaMalloc((void**)&_attribs[INT_RESTR], sizeof(int)*(extSize - 1))); 18 | checkCudaErrors(cudaMalloc((void**)&_attribs[PRIM_RESTR], sizeof(int)*primSize)); 19 | checkCudaErrors(cudaMalloc((void**)&_attribs[SUBBVH_ROOT_IDS], sizeof(int)*extSize)); 20 | checkCudaErrors(cudaMalloc((void**)&_attribs[SUBBVH_OVERSIZE], sizeof(int)*(extSize - 1))); 21 | /// build ports 22 | portptr(COMPLETE) = new BvhRestrCompletePort; 23 | /// link ports 24 | port()->link(_attribs, EXT_RANGE); 25 | } 26 | void BvhRestrLog::cleanup() { 27 | /// clean attribs 28 | for (int i = 0; i < NUM_ATTRIBS; i++) 29 | checkCudaErrors(cudaFree(_attribs[i])); 30 | /// clean ports 31 | delete port(); 32 | } 33 | 34 | void*& BvhRestrLog::portptr(EnumBvhRestrPorts no) { 35 | assert(no >= COMPLETE && no < NUM_PORTS); 36 | return _ports[no]; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Source/Project/Mine/collision/auxiliary/BvhRestrLog.cu: -------------------------------------------------------------------------------- 1 | #include "BvhRestrLog.h" 2 | #include 3 | #include "utility/CudaThrustUtils.hpp" 4 | #include "system/CudaDevice/CudaKernelLauncher.cu" 5 | 6 | namespace mn { 7 | 8 | void BvhRestrLog::clear(int extSize) { 9 | checkThrustErrors(thrust::fill(getDevicePtr(getRestrBvhRoot()), getDevicePtr(getRestrBvhRoot()) + extSize, INT_MAX)); 10 | checkThrustErrors(thrust::fill(getDevicePtr(getIntRange()), getDevicePtr(getIntRange()) + extSize - 1, 0)); 11 | //checkThrustErrors(thrust::fill(getDevicePtr(getExtRange()), getDevicePtr(getExtRange()) + extSize, 0)); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Source/Project/Mine/collision/auxiliary/BvhRestrLog.h: -------------------------------------------------------------------------------- 1 | /** \file BvhRestrLog.h 2 | * \brief Base structure 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __BVH_RESTR_LOG_H_ 8 | #define __BVH_RESTR_LOG_H_ 9 | 10 | #include "base/AggregatedAttribs.h" 11 | 12 | namespace mn { 13 | 14 | typedef unsigned int uint; 15 | 16 | /** 17 | * \brief Port 18 | */ 19 | class BvhRestrCompletePort : public AttribPort<7> { 20 | public: 21 | __host__ __device__ BvhRestrCompletePort() {} 22 | __host__ __device__ ~BvhRestrCompletePort() {} 23 | 24 | __device__ int& extrange(int i) { return ((int*)_ddAttrs[EXT_RANGE])[i]; } 25 | __device__ int& intrange(int i) { return ((int*)_ddAttrs[INT_RANGE])[i]; } 26 | __device__ int& extrt(int i) { return ((int*)_ddAttrs[EXT_RESTR])[i]; } 27 | __device__ int& intrt(int i) { return ((int*)_ddAttrs[INT_RESTR])[i]; } 28 | __device__ int& primrt(int i) { return ((int*)_ddAttrs[PRIM_RESTR])[i]; } 29 | __device__ int& rtroot(int i) { return ((int*)_ddAttrs[SUBBVH_ROOT_IDS])[i]; } 30 | __device__ int& islarge(int i) { return ((int*)_ddAttrs[SUBBVH_OVERSIZE])[i]; } 31 | private: 32 | enum { EXT_RANGE, INT_RANGE, EXT_RESTR, INT_RESTR, PRIM_RESTR, SUBBVH_ROOT_IDS, SUBBVH_OVERSIZE } ; 33 | }; 34 | 35 | template 36 | struct BvhRestrPortType; 37 | template<> 38 | struct BvhRestrPortType<0> { typedef BvhRestrCompletePort PortType; }; 39 | /** 40 | * \brief Connector, two-phase constructor 41 | */ 42 | class BvhRestrLog : public AttribConnector<7, 1> { 43 | public: 44 | /** 45 | * \note SUBBVH_ROOT_IDS: take ext-index as input 46 | * \note SUBBVH_OVERSIZE: take int-index (restr-subbvh's root) as input 47 | */ 48 | typedef enum { EXT_RANGE, INT_RANGE, EXT_RESTR, INT_RESTR, PRIM_RESTR, SUBBVH_ROOT_IDS, SUBBVH_OVERSIZE, NUM_ATTRIBS } EnumBvhRestrAttribs; 49 | typedef enum { COMPLETE, NUM_PORTS } EnumBvhRestrPorts; 50 | BvhRestrLog(); 51 | ~BvhRestrLog(); 52 | void setup(uint extSize, uint primSize); 53 | void cleanup(); 54 | 55 | void clear(int extSize); 56 | 57 | void setUpdateTag(bool tag = true) { _updated = tag; } 58 | bool getUpdateTag() const { return _updated; } 59 | void setBvhOptTag(int tag = 0) { _bvhopt = tag; } ///< 0: refit 1: restr 2: build 60 | int getBvhOptTag() const { return _bvhopt; } 61 | 62 | int* getExtRange() { return (int*)_attribs[EXT_RANGE]; } 63 | int* getExtMark() { return (int*)_attribs[EXT_RESTR]; } 64 | int* getIntRange() { return (int*)_attribs[INT_RANGE]; } 65 | int* getIntMark() { return (int*)_attribs[INT_RESTR]; } 66 | int* getPrimMark() { return (int*)_attribs[PRIM_RESTR]; } 67 | int* getRestrBvhRoot() { return (int*)_attribs[SUBBVH_ROOT_IDS]; } 68 | 69 | template 70 | typename BvhRestrPortType::PortType portobj() { return *port(); } 71 | 72 | private: 73 | void* &portptr(EnumBvhRestrPorts no); 74 | template 75 | typename BvhRestrPortType::PortType* port() { return static_cast::PortType*>(_ports[N]); } 76 | 77 | uint _extSize, _primSize; 78 | bool _updated{ false }; // 79 | int _bvhopt{ 0 }; // 80 | }; 81 | 82 | 83 | } 84 | 85 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/auxiliary/FlOrderLog.cpp: -------------------------------------------------------------------------------- 1 | #include "FlOrderLog.h" 2 | #include 3 | #include 4 | #include 5 | 6 | namespace mn { 7 | 8 | FlOrderLog::FlOrderLog() {} 9 | FlOrderLog::~FlOrderLog() {} 10 | void FlOrderLog::setup(uint intSize, uint extSize, uint intFtSize, uint extFtSize) { 11 | _intSize = intSize, _extSize = extSize; 12 | _intFtSize = intFtSize, _extFtSize = extFtSize; 13 | /// build attribs 14 | checkCudaErrors(cudaMalloc((void**)&_attribs[INT_FL_NODE_NUM], sizeof(uint)*intSize*2 + 1)); 15 | checkCudaErrors(cudaMalloc((void**)&_attribs[EXT_FL_NODE_NUM], sizeof(uint)*extSize*2 + 1)); 16 | checkCudaErrors(cudaMalloc((void**)&_attribs[INT_FL_BEG], sizeof(uint)*intSize*2 + 1)); 17 | checkCudaErrors(cudaMalloc((void**)&_attribs[EXT_FL_BEG], sizeof(uint)*extSize*2 + 1)); 18 | checkCudaErrors(cudaMalloc((void**)&_attribs[INT_FL_BACK_NUM], sizeof(uint)*intSize + 1)); 19 | checkCudaErrors(cudaMalloc((void**)&_attribs[EXT_FL_BACK_NUM], sizeof(uint)*extSize + 1)); 20 | checkCudaErrors(cudaMalloc((void**)&_attribs[INT_FL_BEG_BAK], sizeof(uint) * intSize + 1)); 21 | checkCudaErrors(cudaMalloc((void**)&_attribs[EXT_FL_BEG_BAK], sizeof(uint) * extSize + 1)); 22 | //checkCudaErrors(cudaMalloc((void**)&_attribs[INT_OPT_MARK], sizeof(char) * intFtSize)); 23 | //checkCudaErrors(cudaMalloc((void**)&_attribs[EXT_OPT_MARK], sizeof(char) * extFtSize)); 24 | checkCudaErrors(cudaMalloc((void**)&_attribs[PRIM_CP_NUM], sizeof(uint) * extFtSize)); ///< should be primsize 25 | checkCudaErrors(cudaMalloc((void**)&_attribs[PRIM_CP_OFFSET], sizeof(uint) * extFtSize)); ///< should be primsize 26 | /// build ports 27 | portptr(COMPLETE) = new FlOrderCompletePort; 28 | /// link ports 29 | port()->link(_attribs, INT_FL_NODE_NUM); 30 | } 31 | void FlOrderLog::cleanup() { 32 | /// clean attribs 33 | for (int i = 0; i < NUM_ATTRIBS; i++) 34 | checkCudaErrors(cudaFree(_attribs[i])); 35 | /// clean ports 36 | delete port(); 37 | } 38 | 39 | void FlOrderLog::clear(int size) { 40 | //checkCudaErrors(cudaMemset(_attribs[INT_FL_NODE_NUM], 0, sizeof(uint)*(size - 1))); 41 | //checkCudaErrors(cudaMemset(_attribs[EXT_FL_NODE_NUM], 0, sizeof(uint)*size)); 42 | checkCudaErrors(cudaMemset(_attribs[INT_FL_NODE_NUM], 0, sizeof(uint)*size)); 43 | checkCudaErrors(cudaMemset(_attribs[EXT_FL_NODE_NUM], 0, sizeof(uint)*(size + 1))); 44 | checkCudaErrors(cudaMemset(_attribs[INT_FL_BACK_NUM], 0, sizeof(uint)*size)); 45 | checkCudaErrors(cudaMemset(_attribs[EXT_FL_BACK_NUM], 0, sizeof(uint)*(size + 1))); 46 | } 47 | 48 | void FlOrderLog::clearCpCnts(int size) { 49 | checkCudaErrors(cudaMemset(_attribs[PRIM_CP_NUM], 0, sizeof(uint)*size)); 50 | } 51 | 52 | void*& FlOrderLog::portptr(EnumFlOrderPorts no) { 53 | assert(no >= COMPLETE && no < NUM_PORTS); 54 | return _ports[no]; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Source/Project/Mine/collision/auxiliary/FlOrderLog.cu: -------------------------------------------------------------------------------- 1 | #include "FlOrderLog.h" 2 | #include "thrust/scan.h" 3 | #include "utility/CudaThrustUtils.hpp" 4 | 5 | namespace mn { 6 | 7 | void FlOrderLog::prepare(int size) { 8 | checkThrustErrors(thrust::exclusive_scan(getDevicePtr((uint*)_attribs[INT_FL_NODE_NUM]), 9 | getDevicePtr((uint*)_attribs[INT_FL_NODE_NUM]) + size, getDevicePtr((uint*)_attribs[INT_FL_BEG]))); 10 | checkThrustErrors(thrust::exclusive_scan(getDevicePtr((uint*)_attribs[EXT_FL_NODE_NUM]), 11 | getDevicePtr((uint*)_attribs[EXT_FL_NODE_NUM]) + size + 1, getDevicePtr((uint*)_attribs[EXT_FL_BEG]))); 12 | } 13 | 14 | void FlOrderLog::prepareBak(int size) { 15 | checkThrustErrors(thrust::exclusive_scan(getDevicePtr((uint*)_attribs[INT_FL_BACK_NUM]), 16 | getDevicePtr((uint*)_attribs[INT_FL_BACK_NUM]) + size, getDevicePtr((uint*)_attribs[INT_FL_BEG_BAK]))); 17 | checkThrustErrors(thrust::exclusive_scan(getDevicePtr((uint*)_attribs[EXT_FL_BACK_NUM]), 18 | getDevicePtr((uint*)_attribs[EXT_FL_BACK_NUM]) + size + 1, getDevicePtr((uint*)_attribs[EXT_FL_BEG_BAK]))); 19 | } 20 | 21 | void FlOrderLog::preserveCnts(int size) { 22 | checkThrustErrors(thrust::copy(getDevicePtr((uint*)_attribs[INT_FL_NODE_NUM]), 23 | getDevicePtr((uint*)_attribs[INT_FL_NODE_NUM]) + size, getDevicePtr((uint*)_attribs[INT_FL_BACK_NUM]))); 24 | checkThrustErrors(thrust::copy(getDevicePtr((uint*)_attribs[EXT_FL_NODE_NUM]), 25 | getDevicePtr((uint*)_attribs[EXT_FL_NODE_NUM]) + size + 1, getDevicePtr((uint*)_attribs[EXT_FL_BACK_NUM]))); 26 | } 27 | 28 | /// used to preserve back cnts (restr part) 29 | __global__ void filterCnts(uint size, int *_masks, uint *_validCnts, uint *_invalidCnts) { 30 | int idx = blockIdx.x * blockDim.x + threadIdx.x; 31 | if (idx >= size) return; 32 | if (_masks[idx]) _validCnts[idx] = 0; 33 | else _invalidCnts[idx] = 0; 34 | } 35 | 36 | __global__ void filterIntFrontCnts(uint size, int *_masks, const int* _prevLbds, const int* _leafRestrRoots, 37 | uint *_validIntCnts, uint *_invalidIntCnts) { 38 | int idx = blockIdx.x * blockDim.x + threadIdx.x; 39 | if (idx >= size) return; 40 | bool tag = _masks[idx]; 41 | int lbd = _prevLbds[idx]; 42 | int rt = _leafRestrRoots[lbd]; 43 | if (tag) { 44 | _validIntCnts[idx] = 0; 45 | if (lbd != _prevLbds[rt]) { 46 | _invalidIntCnts[idx] = 0; 47 | return; 48 | } 49 | if (idx != rt) { 50 | atomicAdd(_invalidIntCnts + rt, _invalidIntCnts[idx]); 51 | _invalidIntCnts[idx] = 0; 52 | } 53 | _masks[idx] = -1; ///< -1 marked restructured index preserved 54 | } else 55 | _invalidIntCnts[idx] = 0; 56 | } 57 | 58 | __global__ void filterExtFrontCnts(uint size, int *_masks, const int* _prevLbds, const int* _leafRestrRoots, 59 | uint *_validExtCnts, uint *_invalidExtCnts, uint *_invalidIntCnts) { 60 | int idx = blockIdx.x * blockDim.x + threadIdx.x; 61 | if (idx >= size) return; 62 | int rt = _leafRestrRoots[idx]; 63 | if (_masks[idx]) { 64 | _validExtCnts[idx] = 0; 65 | if (idx != _prevLbds[rt]) { 66 | _invalidExtCnts[idx] = 0; 67 | return; 68 | } 69 | atomicAdd(_invalidIntCnts + rt, _invalidExtCnts[idx]); 70 | _masks[idx] = -1; 71 | } 72 | _invalidExtCnts[idx] = 0; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Source/Project/Mine/collision/auxiliary/FlOrderLog.h: -------------------------------------------------------------------------------- 1 | /** \file FlOrderLog.h 2 | * \brief Base structure 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __FL_ORDER_LOG_H_ 8 | #define __FL_ORDER_LOG_H_ 9 | 10 | #include 11 | 12 | namespace mn { 13 | 14 | typedef unsigned int uint; 15 | 16 | /** 17 | * \brief Port 18 | */ 19 | class FlOrderCompletePort : public AttribPort<10> { 20 | public: 21 | __host__ __device__ FlOrderCompletePort() {} 22 | __host__ __device__ ~FlOrderCompletePort() {} 23 | 24 | __device__ uint& intcnt(int i) { return ((uint*)_ddAttrs[INT_FL_NODE_NUM])[i]; } 25 | __device__ uint* pintcnt(int i) const { return ((uint*)_ddAttrs[INT_FL_NODE_NUM]) + i; } 26 | __device__ uint& extcnt(int i) { return ((uint*)_ddAttrs[EXT_FL_NODE_NUM])[i]; } 27 | __device__ uint* pextcnt(int i) const { return ((uint*)_ddAttrs[EXT_FL_NODE_NUM]) + i; } 28 | __device__ uint& intbeg(int i) { return ((uint*)_ddAttrs[INT_FL_BEG])[i]; } 29 | __device__ uint& extbeg(int i) { return ((uint*)_ddAttrs[EXT_FL_BEG])[i]; } 30 | 31 | __device__ uint& intbackcnt(int i) { return ((uint*)_ddAttrs[INT_FL_BACK_NUM])[i]; } 32 | __device__ uint& extbackcnt(int i) { return ((uint*)_ddAttrs[EXT_FL_BACK_NUM])[i]; } 33 | __device__ uint& intbegbak(int i) { return ((uint*)_ddAttrs[INT_FL_BEG_BAK])[i]; } 34 | __device__ uint& extbegbak(int i) { return ((uint*)_ddAttrs[EXT_FL_BEG_BAK])[i]; } 35 | 36 | __device__ uint& primCpCnt(int i) { return ((uint*)_ddAttrs[PRIM_CP_NUM])[i]; } 37 | __device__ uint& primCpOffset(int i) { return ((uint*)_ddAttrs[PRIM_CP_OFFSET])[i]; } 38 | private: 39 | enum { 40 | INT_FL_NODE_NUM, EXT_FL_NODE_NUM, INT_FL_BEG, EXT_FL_BEG, 41 | INT_FL_BACK_NUM, EXT_FL_BACK_NUM, INT_FL_BEG_BAK, EXT_FL_BEG_BAK, 42 | PRIM_CP_NUM, PRIM_CP_OFFSET 43 | }; 44 | }; 45 | 46 | template 47 | struct FlOrderLogPortType; 48 | template<> 49 | struct FlOrderLogPortType<0> { typedef FlOrderCompletePort PortType; }; 50 | /** 51 | * \brief Connector, two-phase constructor 52 | * \note Not CRTP here! 53 | */ 54 | class FlOrderLog : public AttribConnector<10, 1> { 55 | public: 56 | FlOrderLog(); 57 | ~FlOrderLog(); 58 | void setup(uint intSize, uint extSize, uint intFtSize, uint extFtSize); 59 | void cleanup(); 60 | 61 | void clear(int size); 62 | void clearCpCnts(int size); 63 | void prepare(int size); 64 | void prepareBak(int size); 65 | void preserveCnts(int size); 66 | 67 | uint* intNodeCnts() { return static_cast(_attribs[INT_FL_NODE_NUM]); } 68 | uint* extNodeCnts() { return static_cast(_attribs[EXT_FL_NODE_NUM]); } 69 | uint* intBegPos() { return static_cast(_attribs[INT_FL_BEG]); } 70 | uint* extBegPos() { return static_cast(_attribs[EXT_FL_BEG]); } 71 | uint* intNodeBackCnts() { return static_cast(_attribs[INT_FL_BACK_NUM]); } 72 | uint* extNodeBackCnts() { return static_cast(_attribs[EXT_FL_BACK_NUM]); } 73 | uint* intBegPosBak() { return static_cast(_attribs[INT_FL_BEG_BAK]); } 74 | uint* extBegPosBak() { return static_cast(_attribs[EXT_FL_BEG_BAK]); } 75 | uint* primCpNum() { return static_cast(_attribs[PRIM_CP_NUM]); } 76 | uint* primCpOffset() { return static_cast(_attribs[PRIM_CP_OFFSET]); } 77 | 78 | template 79 | typename FlOrderLogPortType::PortType portobj() { return *port(); } 80 | private: 81 | typedef enum { INT_FL_NODE_NUM, EXT_FL_NODE_NUM, INT_FL_BEG, EXT_FL_BEG, 82 | INT_FL_BACK_NUM, EXT_FL_BACK_NUM, INT_FL_BEG_BAK, EXT_FL_BEG_BAK, PRIM_CP_NUM, PRIM_CP_OFFSET, NUM_ATTRIBS } EnumFlOrderAttribs; 83 | typedef enum { COMPLETE, NUM_PORTS } EnumFlOrderPorts; 84 | 85 | void* &portptr(EnumFlOrderPorts no); 86 | template 87 | typename FlOrderLogPortType::PortType* port() { return static_cast::PortType*>(_ports[N]); } 88 | 89 | uint _intSize, _extSize, _intFtSize, _extFtSize; 90 | }; 91 | 92 | __global__ void filterCnts(uint size, int *_masks, uint *_validCnts, uint *_invalidCnts); 93 | __global__ void filterIntFrontCnts(uint size, int *_masks, const int* _prevLbds, const int* _leafRestrRoots, 94 | uint *_validIntCnts, uint *_invalidIntCnts); 95 | __global__ void filterExtFrontCnts(uint size, int *_masks, const int* _prevLbds, const int* _leafRestrRoots, 96 | uint *_validExtCnts, uint *_invalidExtCnts, uint *_invalidIntCnts); 97 | } 98 | 99 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/auxiliary/OrderLog.h: -------------------------------------------------------------------------------- 1 | /** \file OrderLog.h 2 | * \brief Base structure 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __ORDER_LOG_H_ 8 | #define __ORDER_LOG_H_ 9 | 10 | #include "base/AggregatedAttribs.h" 11 | 12 | namespace mn { 13 | 14 | typedef unsigned int uint; 15 | 16 | /** 17 | * \brief Port 18 | */ 19 | class OrderCompletePort : public AttribPort<2> { 20 | public: 21 | __host__ __device__ OrderCompletePort() {} 22 | __host__ __device__ ~OrderCompletePort() {} 23 | 24 | __device__ uint& cnt(int i) { return ((uint*)_ddAttrs[RECORD_NUM])[i]; } 25 | __device__ uint* pcnt(int i) const { return ((uint*)_ddAttrs[RECORD_NUM]) + i; } 26 | __device__ uint& segbeg(int i) { return ((uint*)_ddAttrs[SEGMENT_POS])[i]; } 27 | private: 28 | enum { RECORD_NUM, SEGMENT_POS }; 29 | }; 30 | 31 | template 32 | struct OrderLogPortType; 33 | template<> 34 | struct OrderLogPortType<0> { typedef OrderCompletePort PortType; }; 35 | 36 | /** 37 | * \brief Connector, two-phase constructor 38 | * \note Not CRTP here! 39 | */ 40 | class OrderLog : public AttribConnector<2, 1> { 41 | public: 42 | OrderLog(); 43 | ~OrderLog(); 44 | void setup(uint size); 45 | void cleanup(); 46 | 47 | void clear(int size); 48 | void prepare(int size); 49 | uint* recordCnts() { return static_cast(_attribs[RECORD_NUM]); } 50 | uint* segmentPos() { return static_cast(_attribs[SEGMENT_POS]); }; 51 | 52 | template 53 | typename OrderLogPortType::PortType portobj() { return *port(); } 54 | private: 55 | typedef enum { RECORD_NUM, SEGMENT_POS, NUM_ATTRIBS } EnumOrderAttribs; 56 | typedef enum { COMPLETE, NUM_PORTS } EnumOrderPorts; 57 | 58 | void* &portptr(EnumOrderPorts no); 59 | template 60 | typename OrderLogPortType::PortType* port() { return static_cast::PortType*>(_ports[N]); } 61 | 62 | uint _size; 63 | }; 64 | 65 | } 66 | 67 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/bvtt_front/BvhCDKernels.cu: -------------------------------------------------------------------------------- 1 | #include "BvttFrontLooseKernels.cuh" 2 | #include 3 | #include "utility/CudaDeviceUtils.h" 4 | #include "setting/CDBenchmarkSettings.h" 5 | #include "collision/lbvh/BvhExtNode.h" 6 | #include "collision/lbvh/BvhIntNode.h" 7 | 8 | namespace mn { 9 | 10 | __global__ void reorderCdPairs(uint cnt, uint* _segpos, uint* _cnt, int2* _pairs, int2* _orderedPairs) { 11 | int idx = blockIdx.x * blockDim.x + threadIdx.x; 12 | if (idx >= cnt) return; 13 | int2 cp = _pairs[idx]; 14 | _orderedPairs[_segpos[cp.y] + atomicAdd(_cnt + cp.y, 1)] = cp; 15 | } 16 | 17 | __global__ void pureBvhSelfCD(uint primsize, const BvhExtNodeCompletePort _lvs, const BvhIntNodeCompletePort _tks, int* _cpNum, int2* _cpRes) { 18 | int idx = blockIdx.x * blockDim.x + threadIdx.x; 19 | if (idx >= primsize - 1) return; 20 | const auto& prims = _lvs.primPort(); 21 | //int idx = primsize - 1 - (blockIdx.x * blockDim.x + threadIdx.x); 22 | //for (; idx >= 0; idx -= gridDim.x * blockDim.x) { ///< size of primitives 23 | int lbd; 24 | int st = _lvs.getlca(idx + 1); ///< prims.getextno(idx) 25 | const BOX bv{ prims.getBV(idx) }; 26 | #if MACRO_VERSION 27 | const int3 ids = prims.getVids(idx); 28 | #endif 29 | do { 30 | int t = st & 1; 31 | st >>= 1; 32 | 33 | if (!t) for (t = _lvs.getpar(lbd = _tks.getrangex(st));st <= t && _tks.overlaps(st, bv); st++); 34 | else t = st - 1, lbd = st; 35 | if (st > t) { 36 | if ( 37 | #if MACRO_VERSION 38 | !covertex(ids, prims.getVids(lbd)) && 39 | #endif 40 | _lvs.overlaps(lbd, bv)) { 41 | _cpRes[atomicAdd(_cpNum, 1)] = make_int2(prims.getidx(idx), prims.getidx(lbd)); 42 | } 43 | st = _lvs.getlca(lbd + 1); 44 | } 45 | else 46 | st = _lvs.getlca(_tks.getrangey(st) + 1); 47 | } while (st != -1); 48 | //} 49 | } 50 | 51 | __global__ void pureBvhInterCD(uint travPrimSize, const BvhPrimitiveCompletePort _travPrims, const BvhExtNodeCompletePort _lvs, const BvhIntNodeCompletePort _tks, int* _cpNum, int2* _cpRes) { 52 | int idx = blockIdx.x * blockDim.x + threadIdx.x; 53 | if (idx >= travPrimSize - 1) return; 54 | const auto& prims = _lvs.primPort(); 55 | //int idx = primsize - 1 - (blockIdx.x * blockDim.x + threadIdx.x); 56 | //for (; idx >= 0; idx -= gridDim.x * blockDim.x) { ///< size of primitives 57 | int lbd; 58 | int st = 0; 59 | const BOX bv{ _travPrims.getBV(idx) }; 60 | do { 61 | int t = st & 1; 62 | st >>= 1; 63 | 64 | if (!t) for (t = _lvs.getpar(lbd = _tks.getrangex(st)); st <= t && _tks.overlaps(st, bv); st++); 65 | else t = st - 1, lbd = st; 66 | if (st > t) { 67 | if (_lvs.overlaps(lbd, bv)) 68 | _cpRes[atomicAdd(_cpNum, 1)] = make_int2(prims.getidx(lbd), _travPrims.getidx(idx)); 69 | st = _lvs.getlca(lbd + 1); 70 | } 71 | else { 72 | st = _lvs.getlca(_tks.getrangey(st) + 1); 73 | } 74 | } while (st != -1); 75 | //} 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /Source/Project/Mine/collision/bvtt_front/BvttFrontKeepKernels.cu: -------------------------------------------------------------------------------- 1 | #include "BvttFrontLooseKernels.cuh" 2 | #include 3 | #include "utility/CudaDeviceUtils.h" 4 | #include "setting/CDBenchmarkSettings.h" 5 | #include "collision/lbvh/BvhIntNode.h" 6 | #include "collision/lbvh/BvhExtNode.h" 7 | #include "collision/auxiliary/FlOrderLog.h" 8 | 9 | namespace mn { 10 | 11 | __global__ void keepIntLooseIntraFronts(const BvhExtNodeCompletePort _lvs, const BvhIntNodeCompletePort _tks, 12 | uint ftSize, const int2 *_ftList, int *_cpNum, int2 *_cpRes) { 13 | uint idx = blockIdx.x * blockDim.x + threadIdx.x; 14 | const auto &_prims = _lvs.primPort(); 15 | if (idx >= ftSize) return; 16 | int2 cp = _ftList[idx]; 17 | const BOX bv{ _prims.getBV(cp.x) }; 18 | if (!_tks.overlaps(cp.y, bv)) 19 | return; 20 | 21 | int st = (_tks.getlc(cp.y) << 1) | (_tks.getmark(cp.y) & 1); 22 | cp.y = _lvs.getlca(_tks.getrangey(cp.y) + 1); 23 | #if MACRO_VERSION 24 | const int3 ids = _prims.getVids(cp.x); 25 | #endif 26 | while (st != cp.y) { 27 | int t = st & 1; 28 | st >>= 1; 29 | if (!t) for (t = _lvs.getpar(idx = _tks.getrangex(st)); st <= t && _tks.overlaps(st, bv); st++); 30 | else t = st - 1, idx = st; 31 | if (st == t + 1) { 32 | if ( 33 | #if MACRO_VERSION 34 | !covertex(ids, _prims.getVids(idx)) && 35 | #endif 36 | _lvs.overlaps(idx, bv)) 37 | _cpRes[atomicAdd(_cpNum, 1)] = make_int2(_prims.getidx(cp.x), _prims.getidx(idx)); 38 | st = _lvs.getlca(idx + 1); 39 | } 40 | else 41 | st = _lvs.getlca(_tks.getrangey(st) + 1); 42 | } 43 | } 44 | 45 | __global__ void keepExtLooseIntraFronts(const BvhExtNodeCompletePort _lvs, uint ftSize, const int2 *_ftList, int *_cpNum, int2 *_cpRes) { 46 | uint idx = blockIdx.x * blockDim.x + threadIdx.x; 47 | if (idx >= ftSize) return; 48 | const auto &_prims = _lvs.primPort(); 49 | int2 cp = _ftList[idx]; 50 | 51 | if ( 52 | #if MACRO_VERSION 53 | !covertex(_prims.getVids(cp.x), _prims.getVids(cp.y)) && 54 | #endif 55 | _lvs.overlaps(cp.x, cp.y)) { 56 | _cpRes[atomicAggInc(_cpNum)] = make_int2(_prims.getidx(cp.x), _prims.getidx(cp.y)); 57 | } 58 | } 59 | 60 | __global__ void keepIntLooseInterFronts(const BvhPrimitiveCompletePort _travPrims, const BvhExtNodeCompletePort _lvs, const BvhIntNodeCompletePort _tks, 61 | uint ftSize, const int2 *_ftList, int *_cpNum, int2 *_cpRes) { 62 | uint idx = blockIdx.x * blockDim.x + threadIdx.x; 63 | const auto &_prims = _lvs.primPort(); 64 | if (idx >= ftSize) return; 65 | int2 cp = _ftList[idx]; 66 | const BOX bv{ _travPrims.getBV(cp.x) }; 67 | if (!_tks.overlaps(cp.y, bv)) 68 | return; 69 | 70 | int st = (_tks.getlc(cp.y) << 1) | (_tks.getmark(cp.y) & 1); 71 | cp.y = _lvs.getlca(_tks.getrangey(cp.y) + 1); 72 | while (st != cp.y) { 73 | int t = st & 1; 74 | st >>= 1; 75 | if (!t) for (t = _lvs.getpar(idx = _tks.getrangex(st)); st <= t && _tks.overlaps(st, bv); st++); 76 | else t = st - 1, idx = st; 77 | if (st == t + 1) { 78 | if (_lvs.overlaps(idx, bv)) 79 | _cpRes[atomicAdd(_cpNum, 1)] = make_int2(_prims.getidx(idx), _travPrims.getidx(cp.x)); 80 | st = _lvs.getlca(idx + 1); 81 | } 82 | else 83 | st = _lvs.getlca(_tks.getrangey(st) + 1); 84 | } 85 | } 86 | 87 | __global__ void keepExtLooseInterFronts(const BvhPrimitiveCompletePort _travPrims, const BvhExtNodeCompletePort _lvs, uint ftSize, const int2 *_ftList, int *_cpNum, int2 *_cpRes) { 88 | uint idx = blockIdx.x * blockDim.x + threadIdx.x; 89 | if (idx >= ftSize) return; 90 | const auto &_prims = _lvs.primPort(); 91 | int2 cp = _ftList[idx]; 92 | 93 | if (_lvs.overlaps(cp.y, _travPrims.getBV(cp.x))) { 94 | _cpRes[atomicAggInc(_cpNum)] = make_int2(_prims.getidx(cp.y), _travPrims.getidx(cp.x)); 95 | } 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /Source/Project/Mine/collision/bvtt_front/BvttFrontLooseInter.h: -------------------------------------------------------------------------------- 1 | /** \file BvttFrontLooseInter.h 2 | * \brief Bvtt-Inter-Front 3 | */ 4 | 5 | #ifndef __BVTT_FRONT_LOOSE_INTER_H_ 6 | #define __BVTT_FRONT_LOOSE_INTER_H_ 7 | 8 | #include 9 | 10 | #include "setting/BvttFrontSettings.h" 11 | #include "base/MultiArray.h" 12 | #include "collision/auxiliary/FlOrderLog.h" 13 | #include "collision/lbvh/LBvh.h" 14 | 15 | namespace mn { 16 | 17 | class CudaDevice; 18 | 19 | /// for now, maintenance work is specified by this input alone 20 | enum class BvttFrontLooseInterMaintenance { 21 | PURE_BVH_CD, GENERATE, UPDATE, REORDER, KEEP, RESTRUCTURE 22 | }; 23 | 24 | /* 25 | * \brief BvttFrontLooseInter 26 | * \note RAII 27 | */ 28 | class BvttFrontLooseInter { 29 | public: 30 | BvttFrontLooseInter() = delete; 31 | BvttFrontLooseInter(BvttFrontInterBuildConfig, LBvh> config); 32 | ~BvttFrontLooseInter(); 33 | void maintain(BvttFrontLooseInterMaintenance scheme); 34 | 35 | void inspectResults(); 36 | void applyCpResults(uint* _idx, uint2* _front); 37 | private: 38 | void reorderFronts(); ///< ordering 39 | void separateFronts(); ///< prepare for restructure 40 | /// front-based CD pipeline 41 | void generate(); 42 | void pruneSprout(); 43 | void balance(); 44 | void keep(); 45 | void restructure(); 46 | /// BVH-based CD 47 | void pureBvhCd(); 48 | 49 | CudaDevice* TheCudaDevice; 50 | LBvh* _pFixedDeformableBvh; 51 | LBvh* _pRigidBvh; 52 | 53 | MultiArray _fronts; 54 | FlOrderLog _log; 55 | 56 | bool _restructured{ false }; 57 | 58 | int _numValidFrontNodes[2]; // 0: intfront 1: extfront 59 | int _numInvalidFrontNodes[2]; // 0: intrestrfront 1: extrestrfront 60 | 61 | /// coherent bvh-based cd 62 | thrust::device_vector d_cpCntLog; 63 | thrust::device_vector d_cpPosLog; 64 | thrust::device_vector d_cdpairOffsets; 65 | /// broad-phase results 66 | thrust::device_vector d_ExtFtIndices; 67 | thrust::device_vector d_IntFtIndices; 68 | 69 | int *d_cpNum, _cpNum, *d_actualCpNum, _actualCpNum; 70 | thrust::device_vector d_cpRes; 71 | thrust::device_vector d_orderedCdpairs; 72 | }; 73 | 74 | } 75 | 76 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/bvtt_front/BvttFrontLooseIntra.h: -------------------------------------------------------------------------------- 1 | /** \file BvttFrontLooseIntra.h 2 | * \brief Bvtt-Intra-Front 3 | */ 4 | 5 | #ifndef __BVTT_FRONT_LOOSE_INTRA_H_ 6 | #define __BVTT_FRONT_LOOSE_INTRA_H_ 7 | 8 | #include 9 | 10 | #include "setting/BvttFrontSettings.h" 11 | #include "base/MultiArray.h" 12 | #include "collision/auxiliary/FlOrderLog.h" 13 | #include "collision/lbvh/LBvh.h" 14 | 15 | namespace mn { 16 | 17 | class CudaDevice; 18 | 19 | /// for now, maintenance work is specified by this input alone 20 | enum class BvttFrontLooseIntraMaintenance { 21 | PURE_BVH_CD, GENERATE, UPDATE, REORDER, KEEP, RESTRUCTURE 22 | }; 23 | 24 | /* 25 | * \brief BvttFrontLooseIntra 26 | * \note RAII 27 | */ 28 | class BvttFrontLooseIntra { 29 | public: 30 | BvttFrontLooseIntra() = delete; 31 | BvttFrontLooseIntra(BvttFrontIntraBuildConfig> config); 32 | ~BvttFrontLooseIntra(); 33 | void maintain(BvttFrontLooseIntraMaintenance scheme); 34 | 35 | void inspectResults(); 36 | void applyCpResults(uint* _idx, uint2* _front); 37 | private: 38 | void proximityQuery(); ///< narrow phase CD 39 | void reorderFronts(); ///< ordering 40 | void separateFronts(); ///< prepare for restructure 41 | /// quality inspection 42 | void calcSnapshot(); // used for BVH quality evaluation 43 | void checkQuality(); // used for BVH quality evaluation 44 | /// front-based CD pipeline 45 | void generate(); 46 | void pruneSprout(); 47 | void balance(); 48 | void keep(); 49 | void restructure(); 50 | /// BVH-based CD 51 | void pureBvhCd(); 52 | 53 | CudaDevice* TheCudaDevice; 54 | LBvh* _pBvh; 55 | 56 | MultiArray _fronts; 57 | FlOrderLog _log; 58 | 59 | bool _restructured{ false }; 60 | 61 | int _numValidFrontNodes[2]; // 0: intfront 1: extfront 62 | int _numInvalidFrontNodes[2]; // 0: intrestrfront 1: extrestrfront 63 | 64 | thrust::device_vector d_snapshot; /// quality inspection 65 | 66 | /// coherent bvh-based cd 67 | thrust::device_vector d_cpCntLog; 68 | thrust::device_vector d_cpPosLog; 69 | thrust::device_vector d_cdpairOffsets; 70 | /// broad-phase results 71 | thrust::device_vector d_ExtFtIndices; 72 | thrust::device_vector d_IntFtIndices; 73 | 74 | int *d_cpNum, _cpNum, *d_actualCpNum, _actualCpNum; 75 | uint *d_extFtNodeCnt, _extFtNodeCnt, *d_intFtNodeCnt, _intFtNodeCnt; 76 | thrust::device_vector d_cpRes; 77 | thrust::device_vector d_orderedCdpairs; 78 | }; 79 | 80 | } 81 | 82 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/lbvh/BvhBV.cu: -------------------------------------------------------------------------------- 1 | #include "BvhBV.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "utility/CudaThrustUtils.hpp" 8 | 9 | namespace mn { 10 | 11 | BvhBvArray::BvhBvArray() {} 12 | BvhBvArray::~BvhBvArray() {} 13 | 14 | void BvhBvArray::setup(uint count) { 15 | _count = count; 16 | /// build attribs 17 | checkCudaErrors(cudaMalloc((void**)&_attribs[MINX], sizeof(ExtentType)*count)); 18 | checkCudaErrors(cudaMalloc((void**)&_attribs[MINY], sizeof(ExtentType)*count)); 19 | checkCudaErrors(cudaMalloc((void**)&_attribs[MINZ], sizeof(ExtentType)*count)); 20 | checkCudaErrors(cudaMalloc((void**)&_attribs[MAXX], sizeof(ExtentType)*count)); 21 | checkCudaErrors(cudaMalloc((void**)&_attribs[MAXY], sizeof(ExtentType)*count)); 22 | checkCudaErrors(cudaMalloc((void**)&_attribs[MAXZ], sizeof(ExtentType)*count)); 23 | /// build ports 24 | portptr(COMPLETE) = new BvhBvCompletePort; 25 | /// link ports 26 | port()->link(_attribs, MINX); 27 | } 28 | void BvhBvArray::cleanup() { 29 | /// clean attribs 30 | for (int i = 0; i < NUM_ATTRIBS; i++) 31 | checkCudaErrors(cudaFree(_attribs[i])); 32 | /// clean ports 33 | delete port(); 34 | } 35 | 36 | void BvhBvArray::gather(int size, const int* gatherPos, BvhBvArray& to) { 37 | //recordLaunch("GatherBVs", (size + 255) / 256, 256, 0, gatherBVs, 38 | configuredLaunch( {"GatherBVs", size }, gatherBVs, 39 | size, gatherPos, portobj<0>(), to.portobj<0>()); 40 | } 41 | void BvhBvArray::scatter(int size, const int* scatterPos, BvhBvArray& to) { 42 | //recordLaunch("ScatterBVs", (size + 255) / 256, 256, 0, scatterBVs, 43 | configuredLaunch( {"ScatterBVs", size }, scatterBVs, 44 | size, scatterPos, portobj<0>(), to.portobj<0>()); 45 | } 46 | 47 | void BvhBvArray::clear(int size) { 48 | uchar i; 49 | for (i = MINX; i <= MINZ; i++) 50 | checkThrustErrors(thrust::fill(thrust::device_ptr((ExtentType*)_attribs[i]), thrust::device_ptr((ExtentType*)_attribs[i]) + size, DBL_MAX)); 51 | for (; i <= MAXZ; i++) 52 | checkThrustErrors(thrust::fill(thrust::device_ptr((ExtentType*)_attribs[i]), thrust::device_ptr((ExtentType*)_attribs[i]) + size, -DBL_MAX)); 53 | } 54 | 55 | void*& BvhBvArray::portptr(EnumBvhBvPorts no) { 56 | assert(no >= COMPLETE && no < NUM_PORTS); 57 | return _ports[no]; 58 | } 59 | 60 | __global__ void gatherBVs(int size, const int* gatherPos, BvhBvCompletePort from, BvhBvCompletePort to) { 61 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 62 | if (idx >= size) return; 63 | int ori = gatherPos[idx]; 64 | to.minx(idx) = from.minx(ori); 65 | to.miny(idx) = from.miny(ori); 66 | to.minz(idx) = from.minz(ori); 67 | to.maxx(idx) = from.maxx(ori); 68 | to.maxy(idx) = from.maxy(ori); 69 | to.maxz(idx) = from.maxz(ori); 70 | } 71 | __global__ void scatterBVs(int size, const int* scatterPos, BvhBvCompletePort from, BvhBvCompletePort to) { 72 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 73 | if (idx >= size) return; 74 | int tar = scatterPos[idx]; 75 | to.minx(tar) = from.minx(idx); 76 | to.miny(tar) = from.miny(idx); 77 | to.minz(tar) = from.minz(idx); 78 | to.maxx(tar) = from.maxx(idx); 79 | to.maxy(tar) = from.maxy(idx); 80 | to.maxz(tar) = from.maxz(idx); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Source/Project/Mine/collision/lbvh/BvhBV.h: -------------------------------------------------------------------------------- 1 | /** \file BvhBv.h 2 | * \brief Bounding box (SoA) class 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __BVH_BV_H_ 8 | #define __BVH_BV_H_ 9 | 10 | #include "base/Bv.h" 11 | #include "base/AggregatedAttribs.h" 12 | #include "utility/Utils.h" 13 | 14 | namespace mn { 15 | 16 | /** 17 | * \brief Port 18 | */ 19 | class BvhBvCompletePort : public AttribPort<6> { 20 | public: 21 | __host__ __device__ BvhBvCompletePort() {} 22 | __host__ __device__ ~BvhBvCompletePort() {} 23 | 24 | __device__ ExtentType& minx(int i) { return ((ExtentType*)_ddAttrs[MINX])[i]; } 25 | __device__ ExtentType& miny(int i) { return ((ExtentType*)_ddAttrs[MINY])[i]; } 26 | __device__ ExtentType& minz(int i) { return ((ExtentType*)_ddAttrs[MINZ])[i]; } 27 | __device__ ExtentType& maxx(int i) { return ((ExtentType*)_ddAttrs[MAXX])[i]; } 28 | __device__ ExtentType& maxy(int i) { return ((ExtentType*)_ddAttrs[MAXY])[i]; } 29 | __device__ ExtentType& maxz(int i) { return ((ExtentType*)_ddAttrs[MAXZ])[i]; } 30 | 31 | __device__ ExtentType getminx(int i) const { return ((ExtentType*)_ddAttrs[MINX])[i]; } 32 | __device__ ExtentType getminy(int i) const { return ((ExtentType*)_ddAttrs[MINY])[i]; } 33 | __device__ ExtentType getminz(int i) const { return ((ExtentType*)_ddAttrs[MINZ])[i]; } 34 | __device__ ExtentType getmaxx(int i) const { return ((ExtentType*)_ddAttrs[MAXX])[i]; } 35 | __device__ ExtentType getmaxy(int i) const { return ((ExtentType*)_ddAttrs[MAXY])[i]; } 36 | __device__ ExtentType getmaxz(int i) const { return ((ExtentType*)_ddAttrs[MAXZ])[i]; } 37 | 38 | __device__ ExtentType volume(int i) const { 39 | return (getmaxx(i) - getminx(i)) * (getmaxy(i) - getminy(i)) * (getmaxz(i) - getminz(i)); 40 | } 41 | 42 | __device__ void setBV(int i, const BvhBvCompletePort& bvs, int j) { 43 | minx(i) = bvs.getminx(j), miny(i) = bvs.getminy(j), minz(i) = bvs.getminz(j); 44 | maxx(i) = bvs.getmaxx(j), maxy(i) = bvs.getmaxy(j), maxz(i) = bvs.getmaxz(j); 45 | } 46 | 47 | __device__ void setBV(int i, const BOX& bv) { 48 | minx(i) = bv._min.x, miny(i) = bv._min.y, minz(i) = bv._min.z; 49 | maxx(i) = bv._max.x, maxy(i) = bv._max.y, maxz(i) = bv._max.z; 50 | } 51 | __device__ BOX getBV(int i) const { 52 | return BOX{ getminx(i), getminy(i), getminz(i), getmaxx(i), getmaxy(i), getmaxz(i) }; 53 | } 54 | __device__ bool overlaps(int i, const BOX&b) const { 55 | if (b._min.x >getmaxx(i) || b._max.x < getminx(i)) return false; 56 | if (b._min.y >getmaxy(i) || b._max.y < getminy(i)) return false; 57 | if (b._min.z >getmaxz(i) || b._max.z < getminz(i)) return false; 58 | return true; 59 | } 60 | __device__ bool overlaps(int i, int j) const { 61 | if (getminx(j) >getmaxx(i) || getmaxx(j) < getminx(i)) return false; 62 | if (getminy(j) >getmaxy(i) || getmaxy(j) < getminy(i)) return false; 63 | if (getminz(j) >getmaxz(i) || getmaxz(j) < getminz(i)) return false; 64 | return true; 65 | } 66 | __device__ bool contains(int i, const PointType &v) const { 67 | return v.x <= getmaxx(i) && v.x >= getminx(i) && 68 | v.y <= getmaxy(i) && v.y >= getminy(i) && 69 | v.z <= getmaxz(i) && v.z >= getminz(i); 70 | } 71 | /// examine the max corner cover situation 72 | __device__ unsigned int examine_overlap(int i, const BOX &b) const { 73 | unsigned int mark = getmaxx(i) > b._max.x | ((getmaxy(i) > b._max.y) << 1) | ((getmaxz(i) > b._max.z) << 2); 74 | return mark; 75 | } 76 | private: 77 | enum { MINX, MINY, MINZ, MAXX, MAXY, MAXZ }; 78 | }; 79 | 80 | template 81 | struct BvhBvPortType; 82 | template<> 83 | struct BvhBvPortType<0> { typedef BvhBvCompletePort PortType; }; 84 | /** 85 | * \brief Connector, two-phase constructor 86 | * \note Not CRTP here! 87 | */ 88 | class BvhBvArray : public AttribConnector<6, 1> { 89 | public: 90 | BvhBvArray(); 91 | ~BvhBvArray(); 92 | void setup(uint count); 93 | void cleanup(); 94 | 95 | template 96 | typename BvhBvPortType::PortType portobj() { return *port(); } 97 | void gather(int size, const int* gatherPos, BvhBvArray& to); 98 | void scatter(int size, const int* scatterPos, BvhBvArray& to); 99 | 100 | void clear(int size); 101 | private: 102 | typedef enum { MINX, MINY, MINZ, MAXX, MAXY, MAXZ, NUM_ATTRIBS } EnumBvhBvAttribs; 103 | typedef enum { COMPLETE, NUM_PORTS } EnumBvhBvPorts; 104 | 105 | void* &portptr(EnumBvhBvPorts no); 106 | template 107 | typename BvhBvPortType::PortType* port() { return static_cast::PortType*>(_ports[N]); } 108 | 109 | uint _count; 110 | }; 111 | 112 | __global__ void gatherBVs(int size, const int* gatherPos, BvhBvCompletePort from, BvhBvCompletePort to); 113 | __global__ void scatterBVs(int size, const int* scatterPos, BvhBvCompletePort from, BvhBvCompletePort to); 114 | 115 | } 116 | 117 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/lbvh/BvhIntNode.cu: -------------------------------------------------------------------------------- 1 | #include "BvhIntNode.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "system/CudaDevice/CudaKernelLauncher.cu" 7 | #include "utility/CudaThrustUtils.hpp" 8 | 9 | namespace mn { 10 | 11 | BvhIntNodeArray::BvhIntNodeArray() {} 12 | BvhIntNodeArray::~BvhIntNodeArray() {} 13 | 14 | void BvhIntNodeArray::setup(uint intSize) { 15 | _bvArray.setup(intSize); 16 | _intSize = intSize; 17 | /// build attribs 18 | checkCudaErrors(cudaMalloc((void**)&_attribs[LC], sizeof(int)*intSize)); 19 | checkCudaErrors(cudaMalloc((void**)&_attribs[RC], sizeof(int)*intSize)); 20 | checkCudaErrors(cudaMalloc((void**)&_attribs[PAR], sizeof(int)*intSize)); 21 | checkCudaErrors(cudaMalloc((void**)&_attribs[RCD], sizeof(int)*intSize)); 22 | checkCudaErrors(cudaMalloc((void**)&_attribs[MARK], sizeof(uint)*intSize)); 23 | checkCudaErrors(cudaMalloc((void**)&_attribs[RANGEX], sizeof(int)*intSize)); 24 | checkCudaErrors(cudaMalloc((void**)&_attribs[RANGEY], sizeof(int)*intSize)); 25 | checkCudaErrors(cudaMalloc((void**)&_attribs[FLAG], sizeof(uint)*intSize)); 26 | checkCudaErrors(cudaMalloc((void**)&_attribs[QUALITY_METRIC], sizeof(ExtentType)*intSize)); 27 | /// build ports 28 | portptr(COMPLETE) = new BvhIntNodeCompletePort(_bvArray.portobj<0>()); 29 | /// link ports 30 | port()->link(_attribs, LC); 31 | } 32 | void BvhIntNodeArray::cleanup() { 33 | /// clean attribs 34 | for (int i = 0; i < NUM_ATTRIBS; i++) 35 | checkCudaErrors(cudaFree(_attribs[i])); 36 | /// clean ports 37 | delete port(); 38 | _bvArray.cleanup(); 39 | } 40 | 41 | void BvhIntNodeArray::scatter(int size, const int* scatterPos, BvhIntNodeArray& to) { 42 | _bvArray.scatter(size, scatterPos, to._bvArray); 43 | //recordLaunch("ScatterIntNodes", (size + 255) / 256, 256, 0, scatterIntNodes, 44 | configuredLaunch( {"ScatterIntNodes", size }, scatterIntNodes, 45 | size, scatterPos, portobj<0>(), to.portobj<0>()); 46 | } 47 | 48 | void BvhIntNodeArray::clear(int size) { 49 | for (int i = LC; i <= PAR; i++) 50 | checkCudaErrors(cudaMemset(_attribs[i], 0xff, sizeof(int)*size)); 51 | checkCudaErrors(cudaMemset(_attribs[RCD], 0, sizeof(int)*size)); 52 | checkThrustErrors(thrust::fill(thrust::device_ptr((uint*)_attribs[MARK]), thrust::device_ptr((uint*)_attribs[MARK]) + size, 7)); 53 | for (int i = RANGEX; i <= RANGEY; i++) 54 | checkCudaErrors(cudaMemset(_attribs[i], 0xff, sizeof(int)*size)); 55 | checkCudaErrors(cudaMemset(_attribs[FLAG], 0, sizeof(uint)*size)); 56 | _bvArray.clear(size); 57 | } 58 | 59 | void BvhIntNodeArray::clearIntNodes(int size) { 60 | checkCudaErrors(cudaMemset(_attribs[FLAG], 0, sizeof(uint)*size)); 61 | _bvArray.clear(size); 62 | } 63 | 64 | void BvhIntNodeArray::clearFlags(int size) { 65 | checkCudaErrors(cudaMemset(_attribs[FLAG], 0, sizeof(uint)*size)); 66 | } 67 | 68 | void*& BvhIntNodeArray::portptr(EnumBvhIntNodePorts no) { 69 | assert(no >= COMPLETE && no < NUM_PORTS); 70 | return _ports[no]; 71 | } 72 | 73 | __global__ void scatterIntNodes(int size, const int* scatterPos, BvhIntNodeCompletePort from, BvhIntNodeCompletePort to) { 74 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 75 | if (idx >= size) return; 76 | int tar = scatterPos[idx]; 77 | //LC, RC, PAR, MARK, RANGEX, RANGEY, FLAG, QUALITY_METRIC, 78 | to.lc(tar) = from.getlc(idx); 79 | to.rc(tar) = from.getrc(idx); 80 | to.par(tar) = from.getpar(idx); 81 | to.rcd(tar) = from.getrcd(idx); 82 | to.mark(tar) = from.getmark(idx); 83 | to.rangex(tar) = from.getrangex(idx); 84 | to.rangey(tar) = from.getrangey(idx); 85 | to.metric(tar) = from.getmetric(idx); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /Source/Project/Mine/collision/lbvh/BvhPrimitiveNode.cu: -------------------------------------------------------------------------------- 1 | #include "BvhPrimitiveNode.h" 2 | #include 3 | #include 4 | #include 5 | #include "system/CudaDevice/CudaKernelLauncher.cu" 6 | 7 | namespace mn { 8 | 9 | BvhPrimitiveArray::BvhPrimitiveArray() {} 10 | BvhPrimitiveArray::~BvhPrimitiveArray() {} 11 | 12 | void BvhPrimitiveArray::setup(uint primSize) { 13 | _bvArray.setup(primSize); 14 | _primSize = primSize; 15 | /// build attribs 16 | checkCudaErrors(cudaMalloc((void**)&_attribs[MTCODE], sizeof(MCSize)*primSize)); 17 | checkCudaErrors(cudaMalloc((void**)&_attribs[IDX], sizeof(int)*primSize)); 18 | checkCudaErrors(cudaMalloc((void**)&_attribs[VIDA], sizeof(int)*primSize)); 19 | checkCudaErrors(cudaMalloc((void**)&_attribs[VIDB], sizeof(int)*primSize)); 20 | checkCudaErrors(cudaMalloc((void**)&_attribs[VIDC], sizeof(int)*primSize)); 21 | checkCudaErrors(cudaMalloc((void**)&_attribs[TYPE], sizeof(uint)*primSize)); 22 | checkCudaErrors(cudaMalloc((void**)&_attribs[EXT_MARK], sizeof(uint)*primSize)); 23 | checkCudaErrors(cudaMalloc((void**)&_attribs[EXT_NO], sizeof(int)*primSize)); 24 | /// build ports 25 | portptr(COMPLETE) = new BvhPrimitiveCompletePort(_bvArray.portobj<0>()); 26 | /// link ports 27 | port()->link(_attribs, MTCODE); 28 | } 29 | void BvhPrimitiveArray::cleanup() { 30 | /// clean attribs 31 | for (int i = 0; i < NUM_ATTRIBS; i++) 32 | checkCudaErrors(cudaFree(_attribs[i])); 33 | /// clean ports 34 | delete port(); 35 | /// 36 | _bvArray.cleanup(); 37 | } 38 | 39 | void BvhPrimitiveArray::gather(int size, const int* gatherPos, BvhPrimitiveArray& to) { 40 | _bvArray.gather(size, gatherPos, to._bvArray); 41 | recordLaunch("GatherPrims", (size + 255) / 256, 256, 0, gatherPrims, 42 | size, gatherPos, portobj<0>(), to.portobj<0>()); 43 | } 44 | void BvhPrimitiveArray::scatter(int size, const int* scatterPos, BvhPrimitiveArray& to) { 45 | _bvArray.scatter(size, scatterPos, to._bvArray); 46 | recordLaunch("ScatterPrims", (size + 255) / 256, 256, 0, scatterPrims, 47 | size, scatterPos, portobj<0>(), to.portobj<0>()); 48 | } 49 | 50 | void*& BvhPrimitiveArray::portptr(EnumBvhPrimPorts no) { 51 | assert(no >= COMPLETE && no < NUM_PORTS); 52 | return _ports[no]; 53 | } 54 | 55 | __global__ void gatherPrims(int size, const int* gatherPos, BvhPrimitiveCompletePort from, BvhPrimitiveCompletePort to) { 56 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 57 | if (idx >= size) return; 58 | int ori = gatherPos[idx]; 59 | to.mtcode(idx) = from.mtcode(ori); 60 | to.idx(idx) = from.idx(ori); 61 | to.vida(idx) = from.vida(ori); 62 | to.vidb(idx) = from.vidb(ori); 63 | to.vidc(idx) = from.vidc(ori); 64 | to.type(idx) = from.type(ori); 65 | } 66 | __global__ void scatterPrims(int size, const int* scatterPos, BvhPrimitiveCompletePort from, BvhPrimitiveCompletePort to) { 67 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 68 | if (idx >= size) return; 69 | int tar = scatterPos[idx]; 70 | to.mtcode(tar) = from.mtcode(idx); 71 | to.idx(tar) = from.idx(idx); 72 | to.vida(tar) = from.vida(idx); 73 | to.vidb(tar) = from.vidb(idx); 74 | to.vidc(tar) = from.vidc(idx); 75 | to.type(tar) = from.type(idx); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /Source/Project/Mine/collision/lbvh/BvhPrimitiveNode.h: -------------------------------------------------------------------------------- 1 | /** \file BvhPrimitiveNode.h 2 | * \brief Bridge layer between leaf layer and scene(model) data 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __BVH_PRIMITIVE_NODE_H_ 8 | #define __BVH_PRIMITIVE_NODE_H_ 9 | 10 | #include "base/AggregatedAttribs.h" 11 | #include "BvhBV.h" 12 | 13 | namespace mn { 14 | 15 | /** 16 | * \brief Port 17 | */ 18 | class BvhPrimitiveCompletePort : public AttribPort<8> { 19 | public: 20 | __host__ __device__ BvhPrimitiveCompletePort() {} 21 | __host__ BvhPrimitiveCompletePort(BvhBvCompletePort bvPort) { _bvPort = bvPort; } 22 | __host__ __device__ ~BvhPrimitiveCompletePort() {} 23 | 24 | __device__ MCSize& mtcode(int i) { return ((MCSize*)_ddAttrs[MTCODE])[i]; } 25 | __device__ int& idx(int i) { return ((int*)_ddAttrs[IDX])[i]; } 26 | __device__ int& vid(int i, int j) { return ((int*)_ddAttrs[VIDA + j])[i]; } 27 | __device__ int& vida(int i) { return ((int*)_ddAttrs[VIDA])[i]; } 28 | __device__ int& vidb(int i) { return ((int*)_ddAttrs[VIDB])[i]; } 29 | __device__ int& vidc(int i) { return ((int*)_ddAttrs[VIDC])[i]; } 30 | __device__ uint& type(int i) { return ((uint*)_ddAttrs[TYPE])[i]; } 31 | __device__ uint& extmark(int i) { return ((uint*)_ddAttrs[EXT_MARK])[i]; } 32 | __device__ int& extno(int i) { return ((int*)_ddAttrs[EXT_NO])[i]; } 33 | 34 | __device__ MCSize getmtcode(int i) const { return ((MCSize*)_ddAttrs[MTCODE])[i]; } 35 | __device__ int getidx(int i) const { return ((int*)_ddAttrs[IDX])[i]; } 36 | __device__ int getvida(int i) const { return ((int*)_ddAttrs[VIDA])[i]; } 37 | __device__ int getvidb(int i) const { return ((int*)_ddAttrs[VIDB])[i]; } 38 | __device__ int getvidc(int i) const { return ((int*)_ddAttrs[VIDC])[i]; } 39 | __device__ int getextno(int i) const { return ((int*)_ddAttrs[EXT_NO])[i]; } 40 | 41 | __device__ void setBV(int i, const BOX& bv) { _bvPort.setBV(i, bv); } 42 | __device__ BOX getBV(int i) const { return _bvPort.getBV(i); } 43 | __device__ BvhBvCompletePort getPrimBvs() const { return _bvPort; } 44 | __device__ BvhBvCompletePort &refPrimBvs() { return _bvPort; } 45 | __device__ const BvhBvCompletePort &primBvs() const { return _bvPort; } 46 | __device__ int3 getVids(int i) const { return make_int3(getvida(i), getvidb(i), getvidc(i)); } 47 | private: 48 | enum { MTCODE, IDX, VIDA, VIDB, VIDC, TYPE, EXT_MARK, EXT_NO }; 49 | 50 | BvhBvCompletePort _bvPort; 51 | }; 52 | 53 | template 54 | struct BvhPrimitivePortType; 55 | template<> 56 | struct BvhPrimitivePortType<0> { typedef BvhPrimitiveCompletePort PortType; }; 57 | /** 58 | * \brief Connector, two-phase constructor 59 | * \note Not CRTP here! 60 | */ 61 | class BvhPrimitiveArray : public AttribConnector<8, 1> { 62 | public: 63 | BvhPrimitiveArray(); 64 | ~BvhPrimitiveArray(); 65 | void setup(uint primSize); 66 | void cleanup(); 67 | 68 | template 69 | typename BvhPrimitivePortType::PortType portobj() { return *port(); } 70 | 71 | void gather(int size, const int* gatherPos, BvhPrimitiveArray& to); 72 | void scatter(int size, const int* scatterPos, BvhPrimitiveArray& to); 73 | 74 | MCSize* getMtCodes() { return static_cast(_attribs[MTCODE]); } 75 | uint* getMarks() { return static_cast(_attribs[EXT_MARK]); } 76 | int* getExtIds() { return static_cast(_attribs[EXT_NO]); } 77 | int* getIdx() { return static_cast(_attribs[IDX]); } 78 | BvhBvArray& getBvArray() { return _bvArray; } 79 | private: 80 | typedef enum { MTCODE, IDX, VIDA, VIDB, VIDC, TYPE, EXT_MARK, EXT_NO, NUM_ATTRIBS } EnumBvhPrimAttribs; 81 | typedef enum { COMPLETE, NUM_PORTS } EnumBvhPrimPorts; 82 | 83 | void* &portptr(EnumBvhPrimPorts no); 84 | template 85 | typename BvhPrimitivePortType::PortType* port() { return static_cast::PortType*>(_ports[N]); } 86 | 87 | BvhBvArray _bvArray; 88 | uint _primSize; 89 | }; 90 | 91 | __global__ void gatherPrims(int size, const int* gatherPos, BvhPrimitiveCompletePort from, BvhPrimitiveCompletePort to); 92 | __global__ void scatterPrims(int size, const int* scatterPos, BvhPrimitiveCompletePort from, BvhPrimitiveCompletePort to); 93 | } 94 | 95 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/lbvh/LBvh.h: -------------------------------------------------------------------------------- 1 | /** \file LBvh.h 2 | * \brief LBvh selector & bvh kernel register 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __LBVH_H_ 8 | #define __LBVH_H_ 9 | 10 | #include "setting/BvhSettings.h" 11 | #include "LBvhRigid.h" 12 | #include "LBvhFixedDeformable.h" 13 | #include "system/CudaDevice/CudaDevice.h" 14 | #include "utility/CudaKernelUtils.cuh" 15 | 16 | namespace mn { 17 | 18 | template 19 | struct LBvhSelector; 20 | 21 | template<> 22 | struct LBvhSelector { 23 | using type = LBvhFixedDeformable; 24 | }; 25 | template<> 26 | struct LBvhSelector { 27 | using type = LBvhRigid; 28 | }; 29 | 30 | template 31 | using LBvh = typename LBvhSelector::type; 32 | 33 | class LBvhKernelRegister { 34 | public: 35 | LBvhKernelRegister() { 36 | CudaDevice* device = CudaDevice::getInstance(); 37 | /// components 38 | device->registerKernel("GatherBVs", (void *)gatherBVs, cudaFuncCachePreferL1, false); 39 | device->registerKernel("ScatterBVs", (void *)scatterBVs, cudaFuncCachePreferL1, false); 40 | device->registerKernel("GatherPrims", (void *)gatherPrims, cudaFuncCachePreferL1, false); 41 | device->registerKernel("ScatterPrims", (void *)scatterPrims, cudaFuncCachePreferL1, false); 42 | device->registerKernel("MarkPrimSplitPos", (void *)markPrimSplitPos, cudaFuncCachePreferL1, false); 43 | device->registerKernel("CollapsePrimitives", (void *)collapsePrimitives, cudaFuncCachePreferL1, false); 44 | device->registerKernel("CalcExtNodeSplitMetrics", (void *)calcExtNodeSplitMetrics, cudaFuncCachePreferL1, false); 45 | device->registerKernel("CalcExtNodeRestrSplitMetrics", (void *)calcExtNodeRestrSplitMetrics, cudaFuncCachePreferL1, false); 46 | device->registerKernel("ScatterIntNodes", (void *)scatterIntNodes, cudaFuncCachePreferL1, false); 47 | 48 | #if MACRO_VERSION 49 | device->registerKernel("CalcBVARCSim", (void *)calcMaxBVARCSim, cudaFuncCachePreferL1, false); 50 | device->registerKernel("CalcMCsARCSim", (void *)calcMCsARCSim, cudaFuncCachePreferL1, false); 51 | device->registerKernel("BuildPrimsARCSim", (void *)buildPrimitivesARCSim, cudaFuncCachePreferL1, false); 52 | device->registerKernel("RefitExtNodeARCSim", (void *)refitExtNodeARCSim, cudaFuncCachePreferL1, false); 53 | #endif 54 | /// morton codes 55 | device->registerKernel("CalcBV", (void *)calcMaxBV, cudaFuncCachePreferL1, false); 56 | device->registerKernel("CalcMCs", (void *)calcMCs, cudaFuncCachePreferL1, false); 57 | device->registerKernel("CalcMC64s", (void *)calcMC64s, cudaFuncCachePreferL1, false); 58 | /// build 59 | device->registerKernel("CalcPrimMap", (void *)calcInverseMapping, cudaFuncCachePreferL1, false); 60 | device->registerKernel("BuildPrims", (void *)buildPrimitives, cudaFuncCachePreferL1, false); 61 | device->registerKernel("BuildIntNodes", (void *)buildIntNodes, cudaFuncCachePreferL1, false); 62 | device->registerKernel("CalcIntNodeOrders", (void *)calcIntNodeOrders, cudaFuncCachePreferL1, false); 63 | device->registerKernel("UpdateBvhExtNodeLinks", (void *)updateBvhExtNodeLinks, cudaFuncCachePreferL1, false); 64 | device->registerKernel("ReorderIntNode", (void *)reorderIntNode, cudaFuncCachePreferL1, false); 65 | /// refit 66 | device->registerKernel("RefitExtNode", (void *)refitExtNode, cudaFuncCachePreferL1, false); 67 | device->registerKernel("RefitIntNode", (void *)refitIntNode, cudaFuncCachePreferL1, false); 68 | device->registerKernel("UpdateIntNode", (void *)updateIntNode, cudaFuncCachePreferL1, true); 69 | /// restructure 70 | device->registerKernel("CalibrateLeafRangeMarks", (void *)calibrateLeafRangeMarks, cudaFuncCachePreferL1, false); 71 | device->registerKernel("CalibrateRestrRoots", (void *)calibrateRestrRoots, cudaFuncCachePreferL1, false); 72 | device->registerKernel("CalcRestrMCs", (void *)calcRestrMCs, cudaFuncCachePreferL1, false); 73 | device->registerKernel("SelectPrimitives", (void *)selectPrimitives, cudaFuncCachePreferL1, false); 74 | device->registerKernel("UpdatePrimMap", (void *)updatePrimMap, cudaFuncCachePreferL1, false); 75 | device->registerKernel("UpdatePrimAndExtNode", (void *)updatePrimAndExtNode, cudaFuncCachePreferL1, false); 76 | device->registerKernel("RestrIntNodes", (void *)restrIntNodes, cudaFuncCachePreferL1, false); 77 | device->registerKernel("CalcRestrIntNodeOrders", (void *)calcRestrIntNodeOrders, cudaFuncCachePreferL1, false); 78 | device->registerKernel("ReorderRestrIntNodes", (void *)reorderRestrIntNodes, cudaFuncCachePreferL1, false); 79 | } 80 | ~LBvhKernelRegister() {} 81 | }; 82 | } 83 | 84 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/lbvh/LBvhFixedDeformable.h: -------------------------------------------------------------------------------- 1 | #ifndef __LBVH_FIXEDDEFORMABLE_H_ 2 | #define __LBVH_FIXEDDEFORMABLE_H_ 3 | 4 | #include 5 | 6 | #include "setting/BvhSettings.h" 7 | #include "world/Scene.h" 8 | #include "BvhExtNode.h" 9 | #include "BvhIntNode.h" 10 | #include "LBvhKernels.cuh" 11 | #include "collision/auxiliary/BvhRestrLog.h" 12 | #include "utility/CudaThrustUtils.hpp" 13 | 14 | namespace mn { 15 | class FlOrderCompletePort; 16 | 17 | class CudaDevice; 18 | 19 | /// for now, maintenance work is configured by this input alone, regardless of Bvh state 20 | enum class LBvhFixedDeformableMaintenance 21 | { BUILD, REFIT, UPDATE }; 22 | 23 | /* 24 | * \brief LBvhFixedDeformable 25 | * \note RAII 26 | */ 27 | class LBvhFixedDeformable { 28 | public: 29 | LBvhFixedDeformable() = delete; 30 | LBvhFixedDeformable(LBvhBuildConfig&& config); 31 | ~LBvhFixedDeformable(); 32 | void maintain(LBvhFixedDeformableMaintenance scheme, const SceneData& pdata); 33 | #if MACRO_VERSION 34 | void maintain(LBvhFixedDeformableMaintenance scheme, const ARCSimSceneData& pdata); 35 | #endif 36 | 37 | BvhPrimitiveArray& cprim() { return cbvh().lvs().getPrimitiveArray(); } 38 | BvhExtNodeArray& clvs() { return cbvh().lvs(); } 39 | BvhIntNodeArray& ctks() { return cbvh().tks(); } 40 | int* getPrevLbds() { return getRawPtr(d_prevLbds); } 41 | int* getPrevRbds() { return getRawPtr(d_prevRbds); } 42 | BvhRestrLog& restrLog() { return _restrLog; } 43 | bool logUpdated() const { return _restrLog.getUpdateTag(); } 44 | int bvhOptTag() const { return _restrLog.getBvhOptTag(); } 45 | uint getExtNodeSize() { return cbvh().extSize(); } 46 | uint getIntNodeSize() { return cbvh().intSize(); } 47 | uint getPrimNodeSize() { return cbvh().primSize(); } 48 | int* getPrimMap() { return getRawPtr(d_primMap); } 49 | const int3* getFaces() const { return d_faces; } 50 | const PointType* getVertices() const { return d_vertices; } 51 | 52 | private: 53 | class Bvh { 54 | public: 55 | Bvh() {} 56 | ~Bvh() {} 57 | void setup(LBvhBuildConfig config) { 58 | _lvs.setup(config.primSize, config.extSize); 59 | _tks.setup(config.intSize); 60 | checkCudaErrors(cudaMalloc((void**)&_bv, sizeof(BOX))); 61 | } 62 | void cleanup() { 63 | _lvs.cleanup(); 64 | _tks.cleanup(); 65 | checkCudaErrors(cudaFree(_bv)); 66 | } 67 | int &primSize() { return _primSize; } 68 | int &extSize() { return _extSize; } 69 | int &intSize() { return _intSize; } 70 | BOX* &bv() { return _bv; } 71 | BvhExtNodeArray &lvs() { return _lvs; } 72 | BvhIntNodeArray &tks() { return _tks; } 73 | private: 74 | int _primSize, _extSize, _intSize; 75 | BvhExtNodeArray _lvs; 76 | BvhIntNodeArray _tks; 77 | BOX* _bv; 78 | }; 79 | 80 | CudaDevice* TheCudaDevice; 81 | //Bvh& cbvh() { return _bvhs.cho(); } 82 | Bvh& cbvh() { return _bvh; } 83 | 84 | /// main maintenance methods 85 | void build(); 86 | void refit(); 87 | void update(); ///< gather degradation infos 88 | /// 89 | bool restructure(); 90 | void updatePrimData(const SceneData& pdata); 91 | void reorderPrims(); 92 | void reorderIntNodes(); 93 | /// 94 | void checkPrimitiveMap(); 95 | void checkBvhValidity(); 96 | 97 | /// pre-formated input data 98 | int3* d_faces; 99 | PointType* d_vertices; 100 | #if MACRO_VERSION 101 | uint3* d_facesARCSim; 102 | g_box* d_bxsARCSim; 103 | #endif 104 | /// bvh 105 | Bvh _bvh; 106 | /// auxiliary structures during maintenance procedure 107 | BvhPrimitiveArray _unsortedPrims; 108 | BvhIntNodeArray _unsortedTks; 109 | thrust::device_vector d_primMap; ///< map from primitives to leaves 110 | thrust::device_vector d_tkMap; 111 | thrust::device_vector d_offsetTable; 112 | // sort 113 | thrust::device_vector d_count; 114 | thrust::device_vector d_keys32; 115 | thrust::device_vector d_keys64; 116 | thrust::device_vector d_vals; 117 | /// single values 118 | int _numTaskedPrims, _numRtSubtree, _numRtIntNode, _numRtPrim, _numRtExtNode; 119 | int *d_numRtSubtree, *d_numRtIntNode; 120 | // restructure 121 | BvhRestrLog _restrLog; 122 | thrust::device_vector d_prevLbds, d_prevRbds; 123 | thrust::device_vector d_gatherMap; 124 | thrust::device_vector d_taskSequence; 125 | thrust::device_vector d_sequence; 126 | thrust::device_vector d_rtSubtrees; ///< stores root nodes of subtrees 127 | 128 | thrust::device_vector d_sizePerSubtree; 129 | thrust::device_vector d_begPerSubtree; 130 | 131 | }; 132 | 133 | } 134 | 135 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/lbvh/LBvhKernels.cuh: -------------------------------------------------------------------------------- 1 | #ifndef __LBVH_KERNELS_H_ 2 | #define __LBVH_KERNELS_H_ 3 | 4 | #include 5 | #include "utility/Meta.h" 6 | #include "collision/lbvh/BvhIntNode.h" 7 | #include "collision/lbvh/BvhExtNode.h" 8 | #include "collision/auxiliary/BvhRestrLog.h" 9 | 10 | namespace mn { 11 | 12 | /// Building Kernels 13 | #if MACRO_VERSION 14 | __global__ void calcMaxBVARCSim(int size, g_box *_bxs, BOX* _bv); 15 | __global__ void calcMCsARCSim(int size, g_box *_bxs, BOX scene, uint* codes); 16 | __global__ void buildPrimitivesARCSim(int size, BvhPrimitiveCompletePort _prims, int *_primMap, uint3 *_faces, g_box *_bxs); 17 | __global__ void refitExtNodeARCSim(int primsize, BvhExtNodeCompletePort _lvs, int* _primMap, uint3* _faces, g_box* _bxs); 18 | #endif 19 | 20 | __global__ void calcMaxBV(int size, const int3 *_faces, const PointType *_vertices, BOX* _bv); 21 | __global__ void calcMCs(int size, int3 *_faces, PointType *_vertices, BOX scene, uint* codes); 22 | __global__ void calcMC64s(int size, int3* _faces, PointType* _vertices, BOX* scene, uint64* codes); 23 | __global__ void copyBackCodes(int size, uint64* _primcodes, uint* _codes); ///< deprecated 24 | __global__ void buildPrimitives(int size, BvhPrimitiveCompletePort _prims, int *_primMap, int3 *_faces, PointType *_vertices); 25 | __global__ void buildIntNodes(int size, uint *_depths, BvhExtNodeCompletePort _lvs, BvhIntNodeCompletePort _tks); 26 | __global__ void calcIntNodeOrders(int size, BvhIntNodeCompletePort _tks, int *_lcas, uint *_depths, uint *_offsets, int *_tkMap); 27 | __global__ void updateBvhExtNodeLinks(int size, const int *_mapTable, int* _lcas, int* _pars); 28 | __global__ void reorderIntNode(int intSize, const int *_tkMap, BvhIntNodeCompletePort _unorderedTks, BvhIntNodeCompletePort _tks); 29 | 30 | /// Updating Kernels 31 | __global__ void refitExtNode(int primsize, BvhExtNodeCompletePort _lvs, int* _primMap, int3* _faces, PointType* _vertices); 32 | __global__ void refitIntNode(int size, BvhExtNodeCompletePort _lvs, BvhIntNodeCompletePort _tks); 33 | __global__ void updateIntNode(int size, BvhExtNodeCompletePort _lvs, BvhIntNodeCompletePort _tks, //FlOrderCompletePort _log, 34 | int* _lvMarks, int* _tkMarks, int* _restrLcas); 35 | 36 | /// Restructure Kernels 37 | __global__ void calibrateLeafRangeMarks(int size, BvhIntNodeCompletePort _tks, const int* _leafRestrRoots, const int* _intRestrMarks, int* _leafRangeMarks); // mark relative leaves according to restr roots 38 | __global__ void calibrateRestrRoots(int size, BvhIntNodeCompletePort _tks, const int* _leafRestrRoots, 39 | const int* _intRestrMarks, int* _leafRestrRootMarks, int* _numSubtree, uint* _subtreeSizes, int* _subtrees, int* _numRtIntNode); // uniform inclusive_scanned restr marks 40 | __global__ void calcRestrMCs(int size, const int3* _faces, const PointType* _vertices, BOX scene, 41 | const int* _primRestrMarks, const int* _primmap, uint* codes); 42 | __global__ void selectPrimitives(int primsize, const int* _leafRestrRoots, const int* _gatherMap, const MCSize* _mtcodes, 43 | uint64* _finalKeys, int* _scatterMap); 44 | __global__ void updatePrimMap(int restrPrimNum, int* _indices, int* _values, int* _primToIdx, int* _primmap); 45 | __global__ void updatePrimAndExtNode(int primsize, const int *_primRestrMarks, const int* _primMap, const int3* _faces, const PointType * _vertices, const BOX* scene, BvhExtNodeCompletePort _lvs); 46 | __global__ void restrIntNodes(int extSize, int numRtExtNode, const int *_restrExtNodes, const uint *_prevTkMarks, 47 | const int *_leafRestrRoots, uint *_depths, int *_localLcas, BvhExtNodeCompletePort _lvs, BvhIntNodeCompletePort _tks); 48 | __global__ void calcRestrIntNodeOrders(int numRtExtNode, const int *_restrExtNodes, const uint *_depths, const uint *_offsets, const int *_subtreeRoots, 49 | const int* _prevLbds, const uint *_prevTkMarks, const int* _localLcas, int *_lcas, int *_pars, BvhIntNodeCompletePort _unorderedTks, int *_tkMap, int *_sequence); 50 | __global__ void reorderRestrIntNodes(int numRtIntNode, const int *_restrIntNodes, const int *_tkMap, 51 | BvhIntNodeCompletePort _unorderedTks, BvhIntNodeCompletePort _tks); 52 | 53 | /// Debug 54 | __global__ void checkRestrTrunkMap(int numRtIntNode, const int* _restrQueue, const int* _tkMap, const int * _restrIntMark, int *_rtIntCount); 55 | __global__ void checkPrimmap(int size, int* _primmap, int* _cnt); 56 | __global__ void checkBVHIntegrity(int size, BvhExtNodeCompletePort _leaves, BvhIntNodeCompletePort _trunks, int *tag); 57 | 58 | } 59 | 60 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/lbvh/LBvhRigid.h: -------------------------------------------------------------------------------- 1 | #ifndef __LBVH_RIGID_H_ 2 | #define __LBVH_RIGID_H_ 3 | 4 | #include 5 | #include "setting/BvhSettings.h" 6 | #include "world/Scene.h" 7 | #include "BvhExtNode.h" 8 | #include "BvhIntNode.h" 9 | #include "LBvhKernels.cuh" 10 | #include "utility/CudaThrustUtils.hpp" 11 | 12 | namespace mn { 13 | 14 | /// for now, maintenance work is configured by this input alone, regardless of Bvh state 15 | enum class LBvhRigidMaintenance { BUILD, REFIT }; 16 | 17 | /* 18 | * \brief LBvhRigid 19 | * \note RAII 20 | */ 21 | class LBvhRigid { 22 | public: 23 | LBvhRigid() = delete; 24 | LBvhRigid(LBvhBuildConfig&& config); 25 | ~LBvhRigid(); 26 | void maintain(LBvhRigidMaintenance scheme, const SceneData& pdata); 27 | #if MACRO_VERSION 28 | void maintain(LBvhRigidMaintenance scheme, const ARCSimSceneData& pdata); 29 | #endif 30 | 31 | uint getPrimNodeSize() { return _primSize; } 32 | uint getExtNodeSize() { return _extSize; } 33 | uint getIntNodeSize() { return _intSize; } 34 | BvhPrimitiveArray cprim() { return _lvs.getPrimitiveArray(); } 35 | BvhExtNodeArray clvs() { return _lvs; } 36 | BvhIntNodeArray ctks() { return _tks; } 37 | private: 38 | 39 | void build(); 40 | void refit(); 41 | 42 | void updatePrimData(const SceneData& pdata); 43 | void reorderPrims(); 44 | void reorderIntNodes(); 45 | 46 | /// pre-formated input data 47 | int3* d_faces; 48 | PointType* d_vertices; 49 | #if MACRO_VERSION 50 | uint3* d_facesARCSim; 51 | g_box* d_bxsARCSim; 52 | #endif 53 | /// bvh 54 | int _primSize, _extSize, _intSize; 55 | BOX* d_bv; 56 | BvhExtNodeArray _lvs; 57 | BvhIntNodeArray _tks; 58 | /// auxiliary structures during maintenance procedure 59 | BvhPrimitiveArray _unsortedPrims; 60 | BvhIntNodeArray _unsortedTks; 61 | thrust::device_vector d_primMap; ///< map from primitives to leaves 62 | thrust::device_vector d_tkMap; 63 | thrust::device_vector d_offsetTable; 64 | // sort 65 | thrust::device_vector d_count; 66 | thrust::device_vector d_keys32; 67 | thrust::device_vector d_vals; 68 | }; 69 | 70 | } 71 | 72 | 73 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/collision/narrow_phase/narrow_phase.cu: -------------------------------------------------------------------------------- 1 | #include "narrow_phase.cuh" 2 | #include "collision/lbvh/BvhBV.h" 3 | #include "utility/CudaDeviceUtils.h" 4 | #include 5 | 6 | namespace mn { 7 | 8 | __global__ void simpleNarrowPhase(uint numpair, int2* _cps, const int3* _indices, const PointType* _vertices, int* _actualCpNum) { 9 | int idx = blockIdx.x * blockDim.x + threadIdx.x; 10 | if (idx >= numpair) return; 11 | const int2 cp = _cps[idx]; 12 | const PointType P0 = _vertices[_indices[cp.x].x]; 13 | const PointType P1 = _vertices[_indices[cp.x].y]; 14 | const PointType P2 = _vertices[_indices[cp.x].z]; 15 | const PointType Q0 = _vertices[_indices[cp.y].x]; 16 | const PointType Q1 = _vertices[_indices[cp.y].y]; 17 | const PointType Q2 = _vertices[_indices[cp.y].z]; 18 | if (!triangleIntersection2(make_float3(P0.x, P0.y, P0.z), make_float3(P1.x, P1.y, P1.z), make_float3(P2.x, P2.y, P2.z), 19 | make_float3(Q0.x, Q0.y, Q0.z), make_float3(Q1.x, Q1.y, Q1.z), make_float3(Q2.x, Q2.y, Q2.z))) { 20 | _cps[idx] = { -1, -1 }; 21 | } 22 | else 23 | atomicAggInc(_actualCpNum); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Project/Mine/collision/narrow_phase/narrow_phase.cuh: -------------------------------------------------------------------------------- 1 | #ifndef __NARROW_PHASE_CUH_ 2 | #define __NARROW_PHASE_CUH_ 3 | 4 | #include "collision/lbvh/BvhPrimitiveNode.h" 5 | 6 | namespace mn { 7 | 8 | using uint = unsigned int; 9 | 10 | __global__ void simpleNarrowPhase(uint numpair, int2* _cps, const int3* _indices, const PointType* _vertices, int* _actualCpNum); 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/entry_cudaproject.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Frameworks/AppBase/Main.h" 3 | 4 | #include "Frameworks/CudaProject/CudaProjectModuleRegister.h" ///< pick one application 5 | #include "Frameworks/AppBase/AppBase.h" 6 | 7 | bool mn::ModuleRegister::s_bInitializeRegistered = mn::ModuleRegister::RegisterInitialize(); 8 | bool mn::ModuleRegister::s_bTerminateRegistered = mn::ModuleRegister::RegisterTerminate(); 9 | 10 | int main(int argc, char** argv) { 11 | mn::Main::Initialize(); 12 | 13 | int iExitCode = mn::AppBase::Run(argc, argv); ///< class type derived from AppBase 14 | 15 | mn::Main::Terminate(); 16 | 17 | printf("Press any key to exit system."); 18 | getchar(); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Source/Project/Mine/setting/BvhSettings.h: -------------------------------------------------------------------------------- 1 | /** \file BvhSettings.h 2 | * \brief BVH configuration 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __BVH_SETTINGS_H_ 8 | #define __BVH_SETTINGS_H_ 9 | 10 | namespace mn { 11 | 12 | using uint = unsigned int; 13 | using uchar = unsigned char; 14 | 15 | enum struct ModelType { FixedDeformableType, AdaptiveDeformableType, RigidType, ParticleType, ModelTypeNum }; 16 | 17 | #define SINGLE_SUBTREE_RESTR_SIZE_UPPER_THRESHOLD 100 18 | #define SINGLE_SUBTREE_RESTR_SIZE_LOWER_THRESHOLD 4 19 | #define RESTR_BASE_QUALITY_METRIC 1.111 20 | #define RESTR_WARNING_QUALITY_METRIC 1.25 21 | 22 | class BvhSettings { ///< static (pre-defined) setting 23 | public: 24 | static int prim_size() { return _maxPrimitiveSize; } 25 | static int ext_node_size() { return _maxExtNodeSize; } 26 | static int int_node_size() { return _maxIntNodeSize; } 27 | 28 | static int mandatoryRebuildCycle() { return _mandatoryRebuildCycle; } 29 | static uchar& maintainScheme() { return _maintainScheme; } 30 | private: 31 | /// only allow access to static methods 32 | BvhSettings() = delete; 33 | ~BvhSettings() = delete; 34 | 35 | static const int _maxPrimitiveSize = 150000; ///< (1 << 19); 36 | static const int _maxExtNodeSize = 150000; ///< (1 << 19); 37 | //static const int _maxPrimitiveSize = 524288; ///< (1 << 19); 38 | //static const int _maxExtNodeSize = 524288; ///< (1 << 19); 39 | //static const int _maxPrimitiveSize = 4194304; ///< (1 << 22); 40 | //static const int _maxExtNodeSize = 4194304; ///< (1 << 22); 41 | //static const int _maxPrimitiveSize = 2097152; ///< (1 << 21); 42 | //static const int _maxExtNodeSize = 2097152; ///< (1 << 21); 43 | static const int _maxIntNodeSize = _maxExtNodeSize - 1; ///< (1 << 19); 44 | 45 | static const int _mandatoryRebuildCycle = 12; 46 | static uchar _maintainScheme; 47 | }; 48 | 49 | struct LBvhBuildConfig { 50 | int primSize{ BvhSettings::prim_size() }; 51 | int extSize{ BvhSettings::ext_node_size() }; 52 | int intSize{ BvhSettings::int_node_size() }; 53 | ModelType type{ ModelType::FixedDeformableType }; 54 | }; 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/setting/BvttFrontSettings.h: -------------------------------------------------------------------------------- 1 | /** \file BvttFrontSettings.h 2 | * \brief BVTT front configuration 3 | * \author littlemine 4 | * \ref article - Efficient BVH-based collision detection scheme for deformable models with ordering and restructuring 5 | */ 6 | 7 | #ifndef __BVTT_FRONT_SETTINGS_H_ 8 | #define __BVTT_FRONT_SETTINGS_H_ 9 | 10 | #include "BvhSettings.h" 11 | #include 12 | 13 | namespace mn { 14 | 15 | using uint = unsigned int; 16 | using uchar = unsigned char; 17 | 18 | enum struct BvttFrontType { LooseInterType, LooseIntraType, BvttFrontTypeNum }; 19 | 20 | class BvttFrontSettings { ///< static (pre-defined) setting 21 | public: 22 | static int ext_front_size() { return _maxExtFrontSize; } 23 | static int int_front_size() { return _maxIntFrontSize; } 24 | static int collision_pair_num() { return _maxCollisionPairNum; } 25 | static int mandatoryRebuildCycle() { return _mandatoryRebuildCycle; } 26 | 27 | private: 28 | /// only allow access to static methods 29 | BvttFrontSettings() = delete; 30 | ~BvttFrontSettings() = delete; 31 | 32 | //static const int _maxExtFrontSize = 33554432; //(1 << 25) 33 | //static const int _maxExtFrontSize = 16777216; //(1 << 24) 34 | static const int _maxExtFrontSize = 2300000; 35 | //static const int _maxExtFrontSize = 50000000; 36 | 37 | //static const int _maxIntFrontSize = 16777216; //(1 << 24) 38 | static const int _maxIntFrontSize = 2300000; 39 | //static const int _maxIntFrontSize = 33554432; 40 | //static const int _maxIntFrontSize = 50000000; 41 | 42 | //static const int _maxCollisionPairNum = 8388608; //(1 << 23) 43 | static const int _maxCollisionPairNum = 1600000; 44 | //static const int _maxCollisionPairNum = 4194304; //(1 << 22) 45 | //static const int _maxCollisionPairNum = 2000000; 46 | //static const int _maxCollisionPairNum = 35000000; 47 | //static const int _maxCollisionPairNum = 25000000; 48 | 49 | static const int _mandatoryRebuildCycle = 6; 50 | }; 51 | 52 | template 53 | struct BvttFrontIntraBuildConfig { 54 | Bvh* pbvh{ nullptr }; 55 | BvttFrontType type{ BvttFrontType::LooseIntraType }; 56 | int extFrontSize{ BvttFrontSettings::ext_front_size() }; 57 | int intFrontSize{ BvttFrontSettings::int_front_size() }; 58 | int cpNum{ BvttFrontSettings::collision_pair_num() }; 59 | int extNodeSize{ BvhSettings::ext_node_size() }; 60 | int intNodeSize{ BvhSettings::int_node_size() }; 61 | BvttFrontIntraBuildConfig(Bvh* bvh, BvttFrontType type, int extSize, int intSize, int enNum, int inNum) : 62 | pbvh(bvh), type(type), extFrontSize(extSize), intFrontSize(intSize), extNodeSize(enNum), intNodeSize(inNum) {} 63 | }; 64 | 65 | template 66 | struct BvttFrontInterBuildConfig { 67 | BvhA* pbvha{ nullptr }; ///< should directly be primitive 68 | BvhB* pbvhb{ nullptr }; 69 | BvttFrontType type{ BvttFrontType::LooseInterType }; 70 | int extFrontSize{ BvttFrontSettings::ext_front_size() }; 71 | int intFrontSize{ BvttFrontSettings::int_front_size() }; 72 | int cpNum{ BvttFrontSettings::collision_pair_num() }; 73 | int extNodeSize{ BvhSettings::ext_node_size() }; 74 | int intNodeSize{ BvhSettings::int_node_size() }; 75 | BvttFrontInterBuildConfig(BvhA* a, BvhB* b, BvttFrontType type, int extSize, int intSize, int enNum, int inNum) : 76 | pbvha(a), pbvhb(b), type(type), extFrontSize(extSize), intFrontSize(intSize), extNodeSize(enNum), intNodeSize(inNum) {} 77 | }; 78 | } 79 | 80 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/setting/CDBenchmarkConfiguration.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __CD_BENCHMARK_CONFIGURATION_H_ 2 | #define __CD_BENCHMARK_CONFIGURATION_H_ 3 | 4 | #include "CDBenchmarkSettings.h" 5 | #include 6 | #include 7 | 8 | namespace mn { 9 | 10 | class CDBenchmarkConfiguration { 11 | public: 12 | CDBenchmarkConfiguration(std::string iptAddr, std::string optAddr) : 13 | _inputBaseAddr(std::move(iptAddr)), _outputBaseAddr(std::move(optAddr)) {} 14 | 15 | 16 | private: 17 | std::string _inputBaseAddr; 18 | std::string _outputBaseAddr; 19 | bool _bSchemeOverride {false}; 20 | }; 21 | 22 | } 23 | 24 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/setting/CDBenchmarkSettings.h: -------------------------------------------------------------------------------- 1 | #ifndef __CD_BENCHMARK_SETTINGS_H_ 2 | #define __CD_BENCHMARK_SETTINGS_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace mn { 8 | 9 | enum class CDSchemeType { STATIC_MANDATORY, REFIT_ONLY_FRONT, GENERATE, FRONT_GENERATE }; 10 | 11 | #define MACRO_VERSION 0 12 | 13 | struct Scheme { 14 | CDSchemeType type; 15 | std::string tag; 16 | Scheme() {} 17 | Scheme(CDSchemeType type, std::string tag) : type(type), tag(std::move(tag)) {} 18 | }; 19 | 20 | struct Benchmark { 21 | int stIdx, len; 22 | std::string inputFileFormat; 23 | std::string expName; 24 | std::string outputFileFormat; 25 | Scheme schemeOpt; 26 | }; 27 | 28 | class CDBenchmarkSettings { 29 | public: 30 | static bool enableRestr() { return _enableRestr; } 31 | static bool enableDivergentMark() { return _enableDivergentMark; } 32 | static bool includeNarrowPhase() { return _includeNarrowPhase; } 33 | static int version() { return _version; } 34 | static int benchmarkNum() { return _benchmarks.size(); } 35 | static Benchmark benchmark(int i) { return _benchmarks[i]; } 36 | static std::pair file_name(int expNo, int frameNo) { 37 | char tmp[500]; 38 | std::pair pair; 39 | sprintf(tmp, benchmark(expNo).inputFileFormat.c_str(), frameNo); 40 | pair.first = _inputBaseAddr + std::string(tmp); 41 | sprintf(tmp, benchmark(expNo).outputFileFormat.c_str(), benchmark(expNo).schemeOpt.tag.c_str(), benchmark(expNo).expName.c_str()); 42 | pair.second = _outputBaseAddr + std::string(tmp); 43 | return pair; 44 | } 45 | 46 | private: 47 | /// only allow access to static methods 48 | CDBenchmarkSettings() = delete; 49 | ~CDBenchmarkSettings() = delete; 50 | 51 | static std::string _inputBaseAddr; 52 | static std::string _outputBaseAddr; 53 | static std::vector _benchmarks; 54 | static const bool _enableRestr{ true }; 55 | static const bool _enableDivergentMark{ true }; 56 | static const bool _includeNarrowPhase{ true }; 57 | 58 | static const int _version{ MACRO_VERSION }; ///< 0: standalone 1: arcsim 59 | }; 60 | 61 | } 62 | 63 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/system/CudaDevice/CudaDevice.cu: -------------------------------------------------------------------------------- 1 | #include "CudaDevice.h" 2 | #include 3 | 4 | #include 5 | #include ///< for optimal kernel launching 6 | #include ///< for evaluating kernel performance 7 | #include 8 | 9 | namespace mn { 10 | 11 | cudaDeviceProp* CudaDevice::_akDeviceProps; 12 | int CudaDevice::_iDevID; 13 | std::unordered_map 14 | CudaDevice::_kFuncTable; 15 | 16 | CudaDevice::KernelConfig::KernelConfig(KernelFunc f, cudaFuncCache cacheConfig, bool isWave) : 17 | func(f), cachePreference(cacheConfig), waveFashion(isWave) { 18 | cudaFuncGetAttributes(&attribs, f); 19 | maxOccBlockSize = evalOptimalBlockSize(attribs, cachePreference); 20 | if (cacheConfig != cudaFuncCachePreferNone) ///< should be different from device cache preference 21 | checkCudaErrors(cudaFuncSetCacheConfig(f, cacheConfig)); 22 | } 23 | 24 | CudaDevice::CudaDevice() { 25 | // acquire devices 26 | int deviceCount = 0; 27 | cudaError_t error_id = cudaGetDeviceCount(&deviceCount); 28 | if (error_id != cudaSuccess) { 29 | printf("cudaGetDeviceCount returned %d\n-> %s\n", (int)error_id, cudaGetErrorString(error_id)); 30 | printf("Result = FAIL\n"); 31 | exit(EXIT_FAILURE); 32 | } 33 | if (deviceCount == 0) printf("There are no available device(s) that support cuda/n"); 34 | else printf("Detected %d CUDA Capable device(s)\n", deviceCount); 35 | _akDeviceProps = new cudaDeviceProp[deviceCount]; 36 | for (int i = 0; i < deviceCount; i++) { 37 | cudaSetDevice(i); 38 | cudaGetDeviceProperties(&_akDeviceProps[i], i); 39 | } 40 | _iDevID = findCudaDevice(0, nullptr); 41 | printf("> GPU device has %d Multi-Processors, SM %d.%d compute capabilities\n", 42 | _akDeviceProps[_iDevID].multiProcessorCount, _akDeviceProps[_iDevID].major, 43 | _akDeviceProps[_iDevID].minor); 44 | 45 | printf("# Finished \'CudaDevice/' initialization\n"); 46 | } 47 | 48 | CudaDevice::~CudaDevice() { 49 | delete[] _akDeviceProps; 50 | printf("# Finished \'CudaDevice/' termination\n"); 51 | } 52 | 53 | int CudaDevice::generalGridSize(int& threadNum, int& blockSize) const { return (threadNum + blockSize - 1) / blockSize; } 54 | int CudaDevice::waveGridSize(int& threadNum, int& blockSize) const { 55 | return ((threadNum / blockSize / _akDeviceProps[_iDevID].multiProcessorCount) * _akDeviceProps[_iDevID].multiProcessorCount ? 56 | (threadNum / blockSize / _akDeviceProps[_iDevID].multiProcessorCount) * _akDeviceProps[_iDevID].multiProcessorCount : 1); 57 | } 58 | 59 | /// static methods 60 | int CudaDevice::evalOptimalBlockSize(cudaFuncAttributes attribs, cudaFuncCache cachePreference, size_t smemBytes) { 61 | cudaOccDeviceProp prop = _akDeviceProps[_iDevID]; ///< cache preference 62 | cudaOccFuncAttributes occAttribs = attribs; 63 | cudaOccDeviceState occCache; 64 | switch(cachePreference) { 65 | case cudaFuncCachePreferNone: 66 | occCache.cacheConfig = CACHE_PREFER_NONE; 67 | break; 68 | case cudaFuncCachePreferShared: 69 | occCache.cacheConfig = CACHE_PREFER_SHARED; 70 | break; 71 | case cudaFuncCachePreferL1: 72 | occCache.cacheConfig = CACHE_PREFER_L1; 73 | break; 74 | case cudaFuncCachePreferEqual: 75 | occCache.cacheConfig = CACHE_PREFER_EQUAL; 76 | break; 77 | default: 78 | ; ///< should throw error 79 | } 80 | int minGridSize, blockSize; 81 | cudaOccMaxPotentialOccupancyBlockSize(&minGridSize, &blockSize, &prop, &occAttribs, &occCache, nullptr, smemBytes); 82 | return blockSize; 83 | } 84 | 85 | ExecutionPolicy CudaDevice::launchConfig(const std::string& kernelName, int threadNum, bool sync, size_t smemSize, cudaStream_t sid) const { 86 | auto& config = _kFuncTable[kernelName]; 87 | int bs = config.maxOccBlockSize; 88 | if (smemSize > 0) 89 | bs = evalOptimalBlockSize(config.attribs, config.cachePreference, smemSize); 90 | //printf("configurating for kernel[%s] blocksize: %d\n", kernelName.c_str(), bs); 91 | if (config.waveFashion) 92 | return{ waveGridSize(threadNum, bs), bs, smemSize, sync }; 93 | return{ generalGridSize(threadNum, bs), bs, smemSize, sync }; 94 | } 95 | 96 | void CudaDevice::registerKernel(const std::string& tag, KernelFunc f, cudaFuncCache cacheConfig, bool waveFashion) { 97 | _kFuncTable.emplace(tag, KernelConfig(f, cacheConfig, waveFashion)); 98 | printf("Kernel[%s](%s) block size configuration: %d\n", tag.c_str(), waveFashion?"wave":"general", _kFuncTable[tag].maxOccBlockSize); 99 | } 100 | const CudaDevice::KernelConfig& CudaDevice::findKernel(const std::string& tag) { 101 | return _kFuncTable[tag]; 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /Source/Project/Mine/system/CudaDevice/CudaDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSTEM_CUDA_DEVICE_H_ 2 | #define __SYSTEM_CUDA_DEVICE_H_ 3 | 4 | #include "base/Singleton.h" 5 | #include "utility/CudaExecutionPolicy.h" 6 | #include 7 | #include 8 | #include 9 | 10 | namespace mn { 11 | 12 | class CudaDevice : public ManagedSingleton { 13 | public: 14 | CudaDevice(); 15 | ~CudaDevice(); 16 | 17 | using KernelFunc = void*; 18 | 19 | struct KernelConfig { ///< static kernel attrib, could contain run-time debugger setting(error checking/ time recording etc...) 20 | KernelFunc func; 21 | cudaFuncAttributes attribs; 22 | cudaFuncCache cachePreference; 23 | bool waveFashion; ///< general fashion or loop fashion 24 | int maxOccBlockSize; ///< condition: use no shared memory 25 | KernelConfig(KernelFunc f = nullptr, cudaFuncCache cacheConfig = cudaFuncCachePreferNone, bool isWave = false); 26 | }; 27 | 28 | static void registerKernel(const std::string& tag, KernelFunc f, cudaFuncCache cacheConfig = cudaFuncCachePreferL1, bool waveFashion = true); 29 | static const KernelConfig& findKernel(const std::string& name); 30 | 31 | int generalGridSize(int& threadNum, int& blockSize) const; 32 | int waveGridSize(int& threadNum, int& blockSize) const; 33 | static int evalOptimalBlockSize(cudaFuncAttributes attribs, cudaFuncCache cachePreference, size_t smemBytes = 0); 34 | ExecutionPolicy launchConfig(const std::string& kernelName, int threadNum, bool sync = false, size_t smemSize = 0, cudaStream_t sid = nullptr) const; 35 | 36 | /// Launching Kernels 37 | private: 38 | static cudaDeviceProp* _akDeviceProps; 39 | static int _iDevID; ///< selected cuda device 40 | static std::unordered_map 41 | _kFuncTable; 42 | }; 43 | 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/system/CudaDevice/CudaKernelLauncher.cu: -------------------------------------------------------------------------------- 1 | #ifndef __CUDA_LAUNCHER_H_ 2 | #define __CUDA_LAUNCHER_H_ 3 | 4 | #include "utility/CudaExecutionPolicy.h" 5 | #include "CudaDevice.h" 6 | #include "system/Log/Logger.hpp" 7 | 8 | namespace mn { 9 | 10 | template 11 | void debugLaunch(int gs, int bs, void(*f)(Arguments...), Arguments... args) { 12 | cudaError_t error; 13 | f << > >(args...); 14 | cudaDeviceSynchronize(); 15 | error = cudaGetLastError(); 16 | if (error != cudaSuccess) printf("Kernel launch failure %s\n", cudaGetErrorString(error)); 17 | } 18 | 19 | template 20 | void recordLaunch(std::string tag, int gs, int bs, size_t mem, void(*f)(Arguments...), Arguments... args) { 21 | if (!mem) { 22 | Logger::tick(); 23 | f << > > (args...); 24 | Logger::tock(tag); 25 | } else { 26 | Logger::tick(); 27 | f << > > (args...); 28 | Logger::tock(tag); 29 | } 30 | cudaError_t error = cudaGetLastError(); 31 | if (error != cudaSuccess) printf("Kernel launch failure %s\n", cudaGetErrorString(error)); 32 | } 33 | 34 | template 35 | void recordLaunch(const char* tag, int gs, int bs, size_t mem, void(*f)(Arguments...), Arguments... args) { 36 | if (!mem) { 37 | Logger::tick(); 38 | f << > > (args...); 39 | Logger::tock(tag); 40 | } else { 41 | Logger::tick(); 42 | f << > > (args...); 43 | Logger::tock(tag); 44 | } 45 | cudaError_t error = cudaGetLastError(); 46 | if (error != cudaSuccess) printf("Kernel launch failure %s\n", cudaGetErrorString(error)); 47 | } 48 | 49 | template 50 | void cleanLaunch(int gs, int bs, void(*f)(Arguments...), Arguments... args) { 51 | f << > >(args...); 52 | } 53 | 54 | template 55 | void configuredLaunch(LaunchInput instr, void(*f)(Arguments...), Arguments... args) { 56 | ExecutionPolicy p = CudaDevice::getInstance()->launchConfig(instr.name(), instr.threads()); 57 | if (p.getSharedMemBytes() == 0) { 58 | Logger::tick(); 59 | f << > >(args...); 60 | Logger::tock(instr.name()); 61 | } 62 | else { 63 | Logger::tick(); 64 | f << > >(args...); 65 | Logger::tock(instr.name()); 66 | } 67 | cudaError_t error = cudaGetLastError(); 68 | if (error != cudaSuccess) printf("Kernel launch failure %s\n", cudaGetErrorString(error)); 69 | } 70 | 71 | /* 72 | template 73 | void debugLaunch(int gs, int bs, void(*f)(Arguments...), Arguments&&... args) { 74 | cudaError_t error; 75 | f << > >(std::forward(args)...); 76 | cudaDeviceSynchronize(); 77 | error = cudaGetLastError(); 78 | if (error != cudaSuccess) printf("Kernel launch failure %s\n", cudaGetErrorString(error)); 79 | } 80 | 81 | template 82 | void recordLaunch(std::string&& tag, int gs, int bs, size_t mem, void(*f)(Arguments...), Arguments&&... args) { 83 | if (!mem) { 84 | Logger::tick(); 85 | f << > > (std::forward(args)...); 86 | Logger::tock(tag); 87 | } 88 | else { 89 | Logger::tick(); 90 | f << > > (std::forward(args)...); 91 | Logger::tock(tag); 92 | } 93 | cudaError_t error = cudaGetLastError(); 94 | if (error != cudaSuccess) printf("Kernel launch failure %s\n", cudaGetErrorString(error)); 95 | } 96 | 97 | template 98 | void cleanLaunch(int gs, int bs, void(*f)(Arguments...), Arguments&&... args) { 99 | f << > >(std::forward(std::forward(args)...)); 100 | } 101 | 102 | template 103 | void configuredLaunch(LaunchInput&& instr, void(*f)(Arguments...), Arguments&&... args) { 104 | ExecutionPolicy p = CudaDevice::getInstance()->launchConfig(instr.name(), instr.threads()); 105 | if (p.getSharedMemBytes() == 0) { 106 | Logger::tick(); 107 | f << > >(std::forward(args)...); 108 | Logger::tock(instr.name()); 109 | } 110 | else { 111 | Logger::tick(); 112 | f << > >(std::forward(args)...); 113 | Logger::tock(instr.name()); 114 | } 115 | cudaError_t error = cudaGetLastError(); 116 | if (error != cudaSuccess) printf("Kernel launch failure %s\n", cudaGetErrorString(error)); 117 | } 118 | */ 119 | } 120 | 121 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/system/Log/Logger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __LOGGER_HPP_ 2 | #define __LOGGER_HPP_ 3 | 4 | #include "base/Singleton.h" 5 | #include "utility/CudaTimer.hpp" 6 | #include "utility/Timer.hpp" 7 | #include 8 | #include 9 | 10 | namespace fs = std::filesystem; 11 | 12 | namespace mn { 13 | using path = fs::path; 14 | 15 | enum class TimerType { CPU, GPU }; 16 | 17 | class Logger : public ManagedSingleton { 18 | public: 19 | Logger() {} 20 | ~Logger() {} 21 | 22 | template 23 | static void tick(); 24 | template 25 | static void tock(); 26 | template 27 | static void tock(std::string message); 28 | template 29 | static void blankLine(); 30 | template 31 | static void recordSection(std::string msg); 32 | 33 | static void message(const std::string& filename); 34 | 35 | static void record(const std::string& filename); 36 | static void insertRecord(const std::string& filename); 37 | 38 | private: 39 | CudaTimer _kGPUTimer; 40 | Timer _kCPUTimer; 41 | std::vector _kInfos; 42 | }; 43 | 44 | template <> 45 | inline void Logger::tick() { getInstance()->_kGPUTimer.tick(); } 46 | template <> 47 | inline void Logger::tick() { getInstance()->_kCPUTimer.tick(); } 48 | 49 | template <> 50 | inline void Logger::tock(std::string message) { 51 | //getInstance()->_kGPUTimer.tock(); 52 | getInstance()->_kGPUTimer.record(message); 53 | //std::cout << message.c_str() << ": " << getInstance()->_kGPUTimer.elapsed() << std::endl; 54 | std::cout << message.c_str() << ": " << getInstance()->_kGPUTimer << std::endl; 55 | } 56 | template <> 57 | inline void Logger::tock(std::string message) { 58 | getInstance()->_kCPUTimer.record(message); 59 | std::cout << message.c_str() << ": " << getInstance()->_kCPUTimer << std::endl; 60 | } 61 | template<> 62 | inline void Logger::recordSection(std::string msg) { getInstance()->_kGPUTimer.recordSection(msg); } 63 | template<> 64 | inline void Logger::blankLine() { getInstance()->_kGPUTimer.blankLine(); } 65 | template<> 66 | inline void Logger::blankLine() { getInstance()->_kCPUTimer.blankLine(); } 67 | 68 | inline void Logger::record(const std::string& filename) { 69 | using namespace fs; 70 | path outputTarget(filename); 71 | if (outputTarget.empty()) return; 72 | if (!exists(outputTarget.parent_path())) 73 | create_directory(outputTarget.parent_path()); 74 | 75 | std::ofstream ofs; 76 | while (exists(outputTarget)) { 77 | outputTarget = outputTarget.parent_path().string() + "\\" + outputTarget.stem().string() + "_" + outputTarget.extension().string(); 78 | } 79 | ofs.open(outputTarget.string()); 80 | if (ofs.is_open()) { 81 | getInstance()->_kCPUTimer.log(ofs, true); 82 | ofs << '\n'; 83 | 84 | for (auto& str : getInstance()->_kInfos) 85 | ofs << str << '\n'; 86 | ofs << '\n'; 87 | getInstance()->_kInfos.clear(); 88 | 89 | getInstance()->_kGPUTimer.log(ofs, true); 90 | ofs << '\n'; 91 | 92 | ofs.close(); 93 | } 94 | } 95 | 96 | inline void Logger::insertRecord(const std::string& filename) { 97 | std::ofstream ofs; 98 | ofs.open(filename, std::ios_base::app); 99 | printf("writing to %s\n", filename.c_str()); 100 | if (ofs.is_open()) { 101 | getInstance()->_kCPUTimer.log(ofs, true); 102 | ofs << '\n'; 103 | 104 | for (auto& str : getInstance()->_kInfos) 105 | ofs << str << '\n'; 106 | ofs << '\n'; 107 | getInstance()->_kInfos.clear(); 108 | 109 | getInstance()->_kGPUTimer.log(ofs, true); 110 | ofs << '\n'; 111 | 112 | ofs.close(); 113 | } 114 | } 115 | 116 | inline void Logger::message(const std::string& filename) { 117 | getInstance()->_kInfos.emplace_back(filename); 118 | } 119 | } 120 | 121 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/utility/CudaDeviceUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef __CUDA_DEVICE_UTILS_H_ 2 | #define __CUDA_DEVICE_UTILS_H_ 3 | 4 | #include "Meta.h" 5 | #include 6 | #include "base/Bv.h" 7 | #include "CudaHostUtils.h" 8 | 9 | namespace mn { 10 | 11 | using uint = unsigned int; 12 | using uint64 = unsigned long long int; 13 | 14 | #define PRINT_BOX_INFO(idx, box) printf("%d: %.3f, %.3f, %.3f ~ %.3f, %.3f, %.3f\n", idx, (box)._min.x, (box)._min.y, (box)._min.z, (box)._max.x, (box)._max.y, (box)._max.z); 15 | #define WARP_SIZE 32 16 | 17 | inline __device__ double dabs(double a) { return a < 0 ? -a : a; } 18 | inline __device__ double dmin(double a, double b) { return a < b ? a : b; } 19 | inline __device__ double dmax(double a, double b) { return a > b ? a : b; } 20 | /// CUDA atomic operations customized 21 | __device__ bool atomicMinf(float* address, float val); 22 | __device__ bool atomicMaxf(float* address, float val); 23 | __device__ bool atomicMinD(double* address, double val); 24 | __device__ bool atomicMaxD(double* address, double val); 25 | 26 | template 27 | inline __device__ bool atomicMinCustom(T* addr, T val); 28 | template<> 29 | inline __device__ bool atomicMinCustom(float* addr, float val) { return atomicMinf(addr, val); } 30 | template<> 31 | inline __device__ bool atomicMinCustom(double* addr, double val) { return atomicMinD(addr, val); } 32 | template 33 | inline __device__ bool atomicMaxCustom(T* addr, T val); 34 | template<> 35 | inline __device__ bool atomicMaxCustom(float* addr, float val) { return atomicMaxf(addr, val); } 36 | template<> 37 | inline __device__ bool atomicMaxCustom(double* addr, double val) { return atomicMaxD(addr, val); } 38 | 39 | __device__ uint atomicAggInc(uint *ctr); 40 | __device__ int atomicAggInc(int *ctr); 41 | 42 | __device__ uint expandBits(uint v); 43 | __device__ uint64 expandBits64(uint v); 44 | __device__ uint compactBits(uint v); 45 | __device__ uint compactBits64(uint64 v); 46 | 47 | __device__ uint morton3D(float x, float y, float z); 48 | __device__ uint morton3Dbounds(float x, float y, float z, 49 | int dx, int dy, int dz); 50 | __device__ uint64 morton3D64(double x, double y, double z); 51 | __device__ uint3 morton3D64_d(uint64 c); 52 | 53 | __device__ bool covertex(int3 a, int3 b); 54 | 55 | // compute geometry 56 | inline __device__ char sgn(double a) { 57 | //return a < -DBL_EPSILON ? -1 : a > DBL_EPSILON; 58 | return a < -FLT_EPSILON ? -1 : a > FLT_EPSILON; 59 | } 60 | inline __device__ ExtentType dot(const PointType &a, const PointType &b) { 61 | return a.x * b.x + a.y * b.y + a.z * b.z; 62 | } 63 | inline __device__ PointType cross(const PointType& a, const PointType& b) { 64 | return MakePoint::p(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x); 65 | } 66 | inline __device__ ExtentType proj(const PointType &v, const PointType &p0, const PointType &p1) { 67 | return dot(v, cross(p0, p1)); 68 | } 69 | inline __device__ bool diff(const PointType &v0, const PointType &v1) { 70 | // what if both 0? 71 | return sgn(v0.x) != sgn(v1.x) && sgn(v0.y) != sgn(v1.y) && sgn(v0.z) != sgn(v1.z); 72 | } 73 | inline __device__ bool edgeBvOverlap(const PointType a0, const PointType a1, 74 | const PointType b0, const PointType b1) { 75 | return diff(a0 - b0, a0 - b1) || 76 | diff(a1 - b0, a1 - b1); 77 | } 78 | __device__ PointType normalize(const PointType v); 79 | __device__ ExtentType signed_vf_distance(const PointType &x, const PointType &y0, 80 | const PointType &y1, const PointType &y2, PointType& n, ExtentType* const &w); 81 | __device__ ExtentType signed_ee_distance(const PointType& x0, const PointType& x1, 82 | const PointType& y0, const PointType& y1, PointType& n, ExtentType* const &w); 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /Source/Project/Mine/utility/CudaExecutionPolicy.h: -------------------------------------------------------------------------------- 1 | #ifndef __CUDA_EXECUTION_POLICY_H_ 2 | #define __CUDA_EXECUTION_POLICY_H_ 3 | #include 4 | 5 | namespace mn { 6 | 7 | struct LaunchInput { ///< could contain more information on operation (error checking/ time recording/ etc...) 8 | LaunchInput() = delete; 9 | LaunchInput(std::string kernel, int taskNum, size_t sharedMemBytes = 0) : 10 | kernelName(kernel), numThreads(taskNum), sharedMemBytes(sharedMemBytes) {} 11 | const std::string& name() { return kernelName; } 12 | const int& threads() { return numThreads; } 13 | const size_t& memBytes() { return sharedMemBytes; } 14 | private: 15 | const std::string kernelName; 16 | const int numThreads; 17 | const size_t sharedMemBytes; 18 | }; 19 | 20 | /// kernel launching configuration 21 | struct ExecutionPolicy { 22 | ExecutionPolicy() {} 23 | ExecutionPolicy(int gs, int bs, size_t memsize, bool s) : 24 | gridSize(gs), blockSize(bs), sharedMemBytes(memsize), sync(s) {} 25 | int getGridSize() const { return gridSize; } 26 | int getBlockSize() const { return blockSize; } 27 | size_t getSharedMemBytes() const { return sharedMemBytes; } 28 | bool needSync() const { return sync; } 29 | private: 30 | int gridSize{ 0 }; 31 | int blockSize{ 0 }; 32 | size_t sharedMemBytes{ 0 }; 33 | bool sync{ false }; 34 | }; 35 | 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/utility/CudaHostUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef __CUDA_HOST_UTILS_H_ 2 | #define __CUDA_HOST_UTILS_H_ 3 | 4 | #include "Meta.h" 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mn { 10 | 11 | inline void reportMemory() { 12 | size_t free_byte; 13 | size_t total_byte; 14 | cudaError_t cuda_status = cudaMemGetInfo(&free_byte, &total_byte); 15 | if (cudaSuccess != cuda_status) { 16 | printf("Error: cudaMemGetInfo fails, %s \n", cudaGetErrorString(cuda_status)); 17 | exit(1); 18 | } 19 | double free_db = (double)free_byte; 20 | double total_db = (double)total_byte; 21 | double used_db = total_db - free_db; 22 | printf("GPU memory usage: used = %f, free = %f MB, total = %f MB\n", 23 | used_db / 1024.0 / 1024.0, free_db / 1024.0 / 1024.0, total_db / 1024.0 / 1024.0); 24 | } 25 | 26 | inline __host__ __device__ float diagonalLength(float3 ext) { 27 | return sqrt(ext.x * ext.x + ext.y * ext.y + ext.z * ext.z); 28 | } 29 | inline __host__ __device__ double diagonalLength(double3 ext) { 30 | return sqrt(ext.x * ext.x + ext.y * ext.y + ext.z * ext.z); 31 | } 32 | 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Source/Project/Mine/utility/CudaKernelUtils.cu: -------------------------------------------------------------------------------- 1 | #include "CudaKernelUtils.cuh" 2 | #include 3 | #include 4 | 5 | namespace mn { 6 | 7 | __global__ void checkArray(int size, uint* arr) { 8 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 9 | if (idx >= size) return; 10 | printf("%d: %x\n", idx, arr[idx]); 11 | } 12 | 13 | __global__ void checkSame(int size, int* A, int* B) { 14 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 15 | if (idx >= size) return; 16 | if (A[idx] != B[idx]) 17 | printf("A[%d](%d) - B[%d](%d) not same!\n", idx, A[idx], idx, B[idx]); 18 | } 19 | 20 | __global__ void checkLink(int size, int* A, int* B) { 21 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 22 | if (idx >= size) return; 23 | if (B[A[idx]] != idx) 24 | printf("%d-th A-B link failed!\n", idx); 25 | } 26 | 27 | /// incoherent access, thus poor performance 28 | __global__ void calcInverseMapping(int size, int* map, int* invMap) { 29 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 30 | if (idx >= size) return; 31 | invMap[map[idx]] = idx; 32 | } 33 | 34 | __global__ void calcFurtherMap(int size, int* A, int* B, int* map) { 35 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 36 | if (idx >= size) return; 37 | map[A[idx]] = B[idx]; 38 | } 39 | 40 | __global__ void updateMapping(int size, int* map, int* scatterMap) { 41 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 42 | if (idx >= size || scatterMap[map[idx]] == -1) return; 43 | map[idx] = scatterMap[map[idx]]; 44 | } 45 | 46 | __global__ void extractFrontKeys(int size, int2* _front, int* _frontKeys) { 47 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 48 | if (idx >= size) return; 49 | _frontKeys[idx] = _front[idx].y; 50 | } 51 | /* 52 | /// DEBUG! 53 | __global__ void checkPrims(int size, BvhPrimitiveCompletePort prims) { 54 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 55 | if (idx >= size) return; 56 | if (idx < 10) 57 | printf("%d-th prim: code(%x) tri-id(%d: %d, %d, %d) \n", idx, prims.mtcode(idx), 58 | prims.idx(idx), prims.vida(idx), prims.vidb(idx), prims.vidc(idx)); 59 | } 60 | __global__ void checkBV(BOX* bv) { 61 | PRINT_BOX_INFO(0, *bv); 62 | } 63 | __global__ void checkRawInput(int size, glm::ivec3* d_faces, glm::vec3* d_vertices) { 64 | int idx = blockDim.x * blockIdx.x + threadIdx.x; 65 | if (idx >= size) return; 66 | if (idx < 10) 67 | printf("%d-th input: tri (%d: %.3f, %.3f, %.3f) (%d: %.3f, %.3f, %.3f) (%d: %.3f, %.3f, %.3f)\n", idx, 68 | d_faces[idx].x, d_vertices[d_faces[idx].x].x, d_vertices[d_faces[idx].x].y, d_vertices[d_faces[idx].x].z, 69 | d_faces[idx].y, d_vertices[d_faces[idx].y].x, d_vertices[d_faces[idx].y].y, d_vertices[d_faces[idx].y].z, 70 | d_faces[idx].z, d_vertices[d_faces[idx].z].x, d_vertices[d_faces[idx].z].y, d_vertices[d_faces[idx].z].z); 71 | } 72 | */ 73 | 74 | } -------------------------------------------------------------------------------- /Source/Project/Mine/utility/CudaKernelUtils.cuh: -------------------------------------------------------------------------------- 1 | #ifndef __CUDA_KERNEL_UTILS_CUH_ 2 | #define __CUDA_KERNEL_UTILS_CUH_ 3 | 4 | #include 5 | 6 | namespace mn { 7 | 8 | using uint = unsigned int; 9 | 10 | __host__ __device__ struct NotZero { 11 | __host__ __device__ 12 | bool operator()(const int &x) { 13 | return (x != 0 ? 1 : 0); 14 | } 15 | }; 16 | __host__ __device__ struct NotOne { 17 | __host__ __device__ 18 | bool operator()(const int &x) { 19 | return (x != 1 ? 1 : 0); 20 | } 21 | }; 22 | __host__ __device__ struct GreaterOne { 23 | __host__ __device__ 24 | bool operator()(const int &x) { 25 | return (x > 1 ? 1 : 0); 26 | } 27 | }; 28 | __global__ void checkArray(int size, uint* arr); 29 | __global__ void checkSame(int size, int* A, int* B); 30 | __global__ void checkLink(int size, int* A, int* B); 31 | 32 | __global__ void calcInverseMapping(int size, int* map, int* invMap); 33 | __global__ void calcFurtherMap(int size, int* A, int* B, int* map); 34 | __global__ void updateMapping(int size, int* map, int* scatterMap); 35 | __global__ void extractFrontKeys(int size, int2* _front, int* _frontKeys); 36 | 37 | } 38 | 39 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/utility/CudaThrustUtils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __CUDA_THRUST_UTILS_HPP_ 2 | #define __CUDA_THRUST_UTILS_HPP_ 3 | 4 | #include 5 | #include 6 | 7 | namespace mn { 8 | 9 | #define checkThrustErrors(func) \ 10 | try {func;} \ 11 | catch (thrust::system_error &e) { std::cout << std::string(__FILE__) << ":" << __LINE__ << " " << e.what() << std::endl; } 12 | 13 | template 14 | __inline__ __host__ T* getRawPtr(thrust::device_vector &V) { 15 | return thrust::raw_pointer_cast(V.data()); 16 | } 17 | template 18 | __inline__ __host__ thrust::device_ptr getDevicePtr(thrust::device_vector &V) { 19 | return thrust::device_ptr(thrust::raw_pointer_cast(V.data())); 20 | } 21 | template 22 | __inline__ __host__ thrust::device_ptr getDevicePtr(T* V) { 23 | return thrust::device_ptr(V); 24 | } 25 | 26 | } 27 | 28 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/utility/CudaTimer.hpp: -------------------------------------------------------------------------------- 1 | /** \file CudaTimer.hpp 2 | * \brief CUDA GPU timer based on cudaEvent 3 | */ 4 | 5 | #ifndef __CUDA_TIMER_HPP_ 6 | #define __CUDA_TIMER_HPP_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace mn { 15 | 16 | class CudaTimer { 17 | cudaEvent_t _start, _end; 18 | std::vector> _records; 19 | int lastSectionLen{ 0 }; 20 | public: 21 | CudaTimer() { 22 | cudaEventCreate(&_start); 23 | cudaEventCreate(&_end); 24 | } 25 | ~CudaTimer() { 26 | cudaEventDestroy(_start); 27 | cudaEventDestroy(_end); 28 | } 29 | 30 | void tick(cudaStream_t streamid = 0) { cudaEventRecord(_start, streamid); } 31 | void tock(cudaStream_t streamid = 0) { cudaEventRecord(_end, streamid); } 32 | float elapsed() const { 33 | float ms; 34 | cudaEventSynchronize(_end); 35 | cudaEventElapsedTime(&ms, _start, _end); 36 | return ms; 37 | } 38 | void clear() { _records.clear(); } 39 | void record(std::string tag) { 40 | tock(); 41 | _records.push_back(make_pair(tag, elapsed())); 42 | } 43 | void recordSection(std::string msg) { 44 | float sec = 0; 45 | auto it = _records.end(); 46 | for (--it; it != _records.begin() && !it->first.empty(); --it) 47 | if (it->first[0] != '@' && it->first[0] != '#') 48 | sec += it->second; 49 | if (it == _records.begin()) 50 | sec += it->second; 51 | _records.emplace_back("@"+msg, sec); 52 | _records.emplace_back("", 0); 53 | } 54 | void blankLine() { 55 | float sum = 0; 56 | auto it = _records.end(); 57 | for (--it; it != _records.begin() && it->first != "###"; --it) 58 | if (it->first[0] != '@' && it->first[0] != '#') 59 | sum += it->second; 60 | if (it == _records.begin()) 61 | sum += it->second; 62 | _records.emplace_back("#cd_total_time", sum); 63 | _records.emplace_back("###", 0); 64 | } 65 | void log(std::ofstream& fs, bool bclear = true) { 66 | for (auto& pair : _records) 67 | if (!pair.first.empty()) 68 | fs << pair.first.c_str() << ": " << pair.second << '\n'; 69 | else 70 | fs << '\n'; 71 | if (bclear) 72 | clear(); 73 | } 74 | 75 | template 76 | friend std::basic_ostream& operator<<(std::basic_ostream& out, const CudaTimer& timer) { 77 | return out << timer.elapsed(); 78 | }; 79 | }; 80 | 81 | } 82 | 83 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/utility/Meta.h: -------------------------------------------------------------------------------- 1 | #ifndef __META_H_ 2 | #define __META_H_ 3 | 4 | #include 5 | 6 | namespace mn { 7 | using uint = unsigned int; 8 | using uint64 = unsigned long long int; 9 | using ExtentType = float; 10 | 11 | template 12 | struct CorrespondingPoint; 13 | template<> 14 | struct CorrespondingPoint { 15 | using Type = float3; 16 | }; 17 | template<> 18 | struct CorrespondingPoint { 19 | using Type = double3; 20 | }; 21 | template 22 | using PointTypeSelector = typename CorrespondingPoint::Type; 23 | 24 | using PointType = PointTypeSelector; 25 | 26 | template struct MakePoint; 27 | 28 | template<> 29 | struct MakePoint { 30 | MakePoint() = delete; 31 | static __host__ __device__ float3 p(float&& x, float&& y, float&& z) { 32 | return make_float3(x, y, z); 33 | } 34 | static __host__ __device__ float3 p(const float& x, const float& y, const float& z) { 35 | return make_float3(x, y, z); 36 | } 37 | }; 38 | template<> 39 | struct MakePoint { 40 | MakePoint() = delete; 41 | static __host__ __device__ double3 p(double&& x, double&& y, double&& z) { 42 | return make_double3(x, y, z); 43 | } 44 | static __host__ __device__ double3 p(const double& x, const double& y, const double& z) { 45 | return make_double3(x, y, z); 46 | } 47 | }; 48 | 49 | inline __host__ __device__ PointType operator - (PointType a, PointType b) { 50 | return MakePoint::p(a.x - b.x, a.y - b.y, a.z - b.z); 51 | } 52 | inline __host__ __device__ PointType operator + (PointType a, PointType b) { 53 | return MakePoint::p(a.x + b.x, a.y + b.y, a.z + b.z); 54 | } 55 | inline __host__ __device__ PointType operator * (PointType a, ExtentType k) { 56 | return MakePoint::p(a.x * k, a.y * k, a.z * k); 57 | } 58 | 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Source/Project/Mine/utility/ModelReader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __MODEL_READER_HPP_ 2 | #define __MODEL_READER_HPP_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace mn { 11 | 12 | class ModelReader { 13 | public: 14 | ModelReader() { _scenes.clear(); } 15 | ~ModelReader() { release(); } 16 | 17 | const aiScene* getMesh(int no = -1) { 18 | if (no == -1) return _scenes.back(); 19 | else { 20 | assert(no < _scenes.size()); 21 | return _scenes[no]; 22 | } 23 | } 24 | void loadMesh(const char* str) { 25 | release(); 26 | const aiScene* scene = aiImportFile(str, aiProcess_Triangulate | aiProcess_GenSmoothNormals); 27 | _scenes.push_back(scene); 28 | 29 | } 30 | void release() { 31 | if (!_scenes.empty()) { 32 | for (auto scene : _scenes) 33 | aiReleaseImport(scene); 34 | _scenes.clear(); 35 | } 36 | } 37 | 38 | private: 39 | std::vector _scenes; 40 | 41 | }; 42 | 43 | } 44 | 45 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/utility/Timer.hpp: -------------------------------------------------------------------------------- 1 | /** \file Timer.hpp 2 | * \brief CPU timer based on std::chrono and std::basic_ostream 3 | * \ref https://www.daniweb.com/programming/software-development/code/445750/simple-timer-using-c-11-s-chrono-library 4 | */ 5 | 6 | #ifndef __TIMER_HPP_ 7 | #define __TIMER_HPP_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace mn { 15 | 16 | class Timer { 17 | typedef std::chrono::high_resolution_clock HRC; 18 | typedef std::chrono::milliseconds MS; ///< default timer unit 19 | typedef std::chrono::microseconds US; ///< default timer unit 20 | 21 | HRC::time_point _start, _end; 22 | //std::vector> _records; 23 | std::vector> _records; 24 | 25 | //MS elapsed() const { return std::chrono::duration_cast(_end - _start); } 26 | US elapsed() const { return std::chrono::duration_cast(_end - _start); } 27 | public: 28 | Timer() {} 29 | ~Timer() {} 30 | 31 | void tick() { _start = HRC::now(); } 32 | void tock() { _end = HRC::now(); } 33 | void clear() { _records.clear(); } 34 | void record(std::string tag) { 35 | tock(); 36 | _records.push_back(make_pair(tag, elapsed())); 37 | } 38 | void blankLine() { _records.emplace_back("", US()); } 39 | void log(std::ofstream& fs, bool bclear = true) { 40 | for (auto& pair : _records) 41 | if (!pair.first.empty()) 42 | //fs << pair.first.c_str() << ": " << pair.second.count() << std::endl; 43 | fs << pair.first.c_str() << ": " << pair.second.count() / 1000.f << std::endl; 44 | else 45 | fs << '\n'; 46 | if (bclear) 47 | clear(); 48 | } 49 | 50 | template 51 | friend std::basic_ostream& operator<<(std::basic_ostream& out, const Timer& timer) { 52 | //return out << timer.elapsed().count(); 53 | return out << timer.elapsed().count() / 1000.f; 54 | } 55 | }; 56 | 57 | } 58 | 59 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/utility/Utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTILS_H_ 2 | #define __UTILS_H_ 3 | 4 | #include 5 | 6 | namespace mn { 7 | 8 | using uint = unsigned int; 9 | using uchar = unsigned char; 10 | using uint64 = unsigned long long int; 11 | using MCSize = uint; 12 | 13 | template 14 | T min(T a, T b) { return a <= b ? a : b; } 15 | template 16 | T max(T a, T b) { return a > b ? a : b; } 17 | 18 | template 19 | std::string string_format(const char* format, Args ... args) { 20 | size_t size = snprintf(nullptr, 0, format, args ...) + 1; // Extra space for '\0' 21 | std::unique_ptr buf(new char[size]); 22 | snprintf(buf.get(), size, format, args ...); 23 | return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside 24 | } 25 | 26 | template 27 | std::string string_format(const std::string&& format, Args ... args) { 28 | size_t size = snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0' 29 | std::unique_ptr buf(new char[size]); 30 | snprintf(buf.get(), size, format.c_str(), args ...); 31 | return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside 32 | } 33 | 34 | /* 35 | template 36 | auto make_vector(Args&&... args) { 37 | using Item = std::common_type_t; 38 | std::vector result(sizeof...(Args)); 39 | // works as a building block 40 | forArgs( 41 | [&result](auto&& x) {result.emplace_back(std::forward(x)); }, 42 | std::forward(args)... 43 | ); 44 | return result; 45 | } 46 | */ 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /Source/Project/Mine/world/Scene.cpp: -------------------------------------------------------------------------------- 1 | #include "Scene.h" 2 | #include 3 | #include "system/Logic/BenchmarkLogic.hpp" 4 | 5 | namespace fs = std::filesystem; 6 | 7 | namespace mn { 8 | using path = fs::path; 9 | 10 | Scene::Scene() { clearMeshes(); } 11 | Scene::Scene(ModelReader loader) : _kModelLoader(loader) { clearMeshes(); } 12 | Scene::~Scene() {} 13 | 14 | bool Scene::update() { 15 | using namespace fs; 16 | clearMeshes(); 17 | const std::string &inputFile = BenchmarkLogic::getInstance()->currentInputFile(); 18 | path inputTarget(inputFile); 19 | if (!exists(inputTarget)) { 20 | printf("\nFail loading frame %d [%s]\n", BenchmarkLogic::getInstance()->currentFrameId(), inputFile.c_str()); 21 | return false; 22 | } 23 | printf("\nLoaded frame %d [%s]\n", BenchmarkLogic::getInstance()->currentFrameId(), inputFile.c_str()); 24 | addMesh(inputFile); 25 | return true; 26 | } 27 | 28 | void Scene::addMesh(const std::string& fn) { 29 | _kModelLoader.loadMesh(fn.c_str()); 30 | const aiScene* scene = _kModelLoader.getMesh(); 31 | for (int i = 0; i < scene->mNumMeshes; i++) { 32 | for (int j = 0; j < scene->mMeshes[i]->mNumVertices; j++) { 33 | _kFormatedData.pos.emplace_back(MakePoint::p(scene->mMeshes[i]->mVertices[j].x, scene->mMeshes[i]->mVertices[j].y, scene->mMeshes[i]->mVertices[j].z)); 34 | } 35 | for (int j = 0; j < scene->mMeshes[i]->mNumFaces; j++) { 36 | _kFormatedData.fids.emplace_back(make_int3(_kFormatedData.offset + scene->mMeshes[i]->mFaces[j].mIndices[0], 37 | _kFormatedData.offset + scene->mMeshes[i]->mFaces[j].mIndices[1], _kFormatedData.offset + scene->mMeshes[i]->mFaces[j].mIndices[2])); 38 | } 39 | _kFormatedData.offset += scene->mMeshes[i]->mNumVertices; 40 | } 41 | printf("Loaded %d meshes\n", scene->mNumMeshes); 42 | } 43 | 44 | void Scene::clearMeshes() { 45 | _kFormatedData.offset = 0; 46 | _kFormatedData.fids.clear(); 47 | _kFormatedData.pos.clear(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Source/Project/Mine/world/Scene.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCENE_H_ 2 | #define __SCENE_H_ 3 | 4 | #include 5 | #include "setting/CDBenchmarkSettings.h" 6 | 7 | #if MACRO_VERSION 8 | #include "cuda/box.cuh" 9 | #else 10 | #include "utility/Meta.h" 11 | #include "utility/ModelReader.hpp" 12 | #endif 13 | 14 | namespace mn { 15 | 16 | struct SceneData { 17 | int offset = 0; 18 | std::vector pos; 19 | std::vector fids; 20 | }; 21 | 22 | class Scene { 23 | public: 24 | Scene(); 25 | Scene(ModelReader loader); 26 | ~Scene(); 27 | 28 | const SceneData& getFormatedData() const { return _kFormatedData; } 29 | 30 | bool update(); 31 | void addMesh(const std::string& fn); 32 | void clearMeshes(); 33 | 34 | private: 35 | ModelReader _kModelLoader; 36 | SceneData _kFormatedData; 37 | }; 38 | 39 | #if MACRO_VERSION 40 | struct ARCSimSceneData { 41 | int fsize, psize; 42 | uint3 *faces; 43 | //double3 *points; 44 | g_box *boxes; ///< 2*n boxes, bounding boxes(min + max) 45 | }; 46 | #endif 47 | 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /Source/Project/README.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2018 Zhejiang University. 2 | All rights reserved. 3 | 4 | Permission to use, copy, modify, and distribute this software and its 5 | documentation for educational, research, and non-profit purposes, without 6 | fee, and without a written agreement is hereby granted, provided that the 7 | above copyright notice, this paragraph, and the following four paragraphs 8 | appear in all copies. 9 | 10 | Permission to incorporate this software into commercial products may be 11 | obtained by contacting Zhejiang University. 12 | 13 | This software program and documentation are copyrighted by Zhejiang University. 14 | The software program and documentation are supplied "as is", without any 15 | accompanying services from Zhejiang University or the authors. Zhejiang 16 | University and the authors do not warrant that the operation of the program 17 | will be uninterrupted or error-free. The end-user understands that the program 18 | was developed for research purposes and is advised not to rely exclusively on 19 | the program for any reason. 20 | 21 | IN NO EVENT SHALL ZHEJIANG UNIVERSITY OR ITS EMPLOYEES OR THE AUTHORS BE 22 | LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL 23 | DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND 24 | ITS DOCUMENTATION, EVEN IF ZHEJIANG UNIVERSITY OR THE AUTHORS HAVE BEEN ADVISED 25 | OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ZHEJIANG UNIVERSITY AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, 28 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 29 | FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY OF NON-INFRINGEMENT. 30 | THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND ZHEJIANG UNIVERSITY 31 | AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 32 | ENHANCEMENTS, OR MODIFICATIONS. 33 | 34 | Please send all BUG REPORTS to: 35 | 36 | wxlwxl1993@zju.edu.cn / 37 | tang_m@zju.edu.cn -------------------------------------------------------------------------------- /Tools/FrontAnalyser/.vs/DataExtractor/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Tools/FrontAnalyser/.vs/DataExtractor/v15/.suo -------------------------------------------------------------------------------- /Tools/FrontAnalyser/.vs/DataExtractor/v15/Browse.VC.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Tools/FrontAnalyser/.vs/DataExtractor/v15/Browse.VC.db -------------------------------------------------------------------------------- /Tools/FrontAnalyser/.vs/DataExtractor/v15/ipch/AutoPCH/b360d4677b155e31/SOURCE.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Tools/FrontAnalyser/.vs/DataExtractor/v15/ipch/AutoPCH/b360d4677b155e31/SOURCE.ipch -------------------------------------------------------------------------------- /Tools/FrontAnalyser/.vs/DataExtractor/v15/ipch/AutoPCH/de20fc9f94596831/SOURCE.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Tools/FrontAnalyser/.vs/DataExtractor/v15/ipch/AutoPCH/de20fc9f94596831/SOURCE.ipch -------------------------------------------------------------------------------- /Tools/FrontAnalyser/DataExtractor.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/littlemine/BVH-based-Collision-Detection-Scheme/14a517563a81228f884fb077a9d2929e2e6b9faf/Tools/FrontAnalyser/DataExtractor.sdf -------------------------------------------------------------------------------- /Tools/FrontAnalyser/DataExtractor.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DataExtractor", "DataExtractor\DataExtractor.vcxproj", "{5516B480-3C40-4168-A219-14196F76D9EB}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {5516B480-3C40-4168-A219-14196F76D9EB}.Debug|x64.ActiveCfg = Debug|x64 17 | {5516B480-3C40-4168-A219-14196F76D9EB}.Debug|x64.Build.0 = Debug|x64 18 | {5516B480-3C40-4168-A219-14196F76D9EB}.Debug|x86.ActiveCfg = Debug|Win32 19 | {5516B480-3C40-4168-A219-14196F76D9EB}.Debug|x86.Build.0 = Debug|Win32 20 | {5516B480-3C40-4168-A219-14196F76D9EB}.Release|x64.ActiveCfg = Release|x64 21 | {5516B480-3C40-4168-A219-14196F76D9EB}.Release|x64.Build.0 = Release|x64 22 | {5516B480-3C40-4168-A219-14196F76D9EB}.Release|x86.ActiveCfg = Release|Win32 23 | {5516B480-3C40-4168-A219-14196F76D9EB}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Tools/FrontAnalyser/DataExtractor/DataExtractor.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /Tools/FrontAnalyser/DataExtractor/DataExtractor.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Tools/FrontAnalyser/DataExtractor/Source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace fs; 6 | 7 | std::string g_keyword = "front"; 8 | 9 | void record(const std::string input, const std::string output) { 10 | std::cout << "reading " << input << "\n\tto " << output << '\n'; 11 | path outputTarget(output); 12 | if (output.empty()) return; 13 | if (!exists(outputTarget.parent_path())) 14 | create_directory(outputTarget.parent_path()); 15 | 16 | std::ifstream ifs; 17 | std::ofstream ofs; 18 | ifs.open(input); 19 | ofs.open(output); 20 | if (ofs.is_open() && ifs.is_open()) { 21 | int n1, n2, n3, n4, n; 22 | std::string key, key1, key2; 23 | char c; 24 | while (ifs >> key) { 25 | if (key == g_keyword) { 26 | ifs >> c >> n1 >> c >> n2 >> c >> key >> n3 >> /*key2 >> n >> key2 >> n >>*/ key2 >> n4; 27 | ofs << n1 << '\t' << n2 << '\t' << n3 << '\t' << n4 << '\n'; 28 | //ofs << (n1 + n2) * 1. / n3 << '\n'; 29 | } 30 | } 31 | ifs.close(); 32 | ofs.close(); 33 | } 34 | } 35 | 36 | void scan(const std::string dir) { 37 | path cates(dir); 38 | const directory_iterator end{}; 39 | for (directory_iterator it{ cates }; it != end; ++it) { 40 | if (is_directory(*it)) { 41 | const auto cateName = it->path().stem().string(); 42 | //std::cout << it->path().string() << ' ' << cateName << '\n'; 43 | 44 | for (directory_iterator itr{ it->path() }; itr != end; ++itr) { 45 | //std::cout << itr->path().string() << '\n'; 46 | if (!is_directory(*itr)) { 47 | record(itr->path().string(), it->path().parent_path().parent_path().string() + "\\frontstatus\\" + cateName + '\\' + itr->path().stem().string() + ".txt"); 48 | } 49 | } 50 | 51 | } 52 | } 53 | } 54 | 55 | int main(int argc, char** argv) { 56 | if (argc == 1) 57 | scan("C:\\Mine\\ExpResults\\standaloneCD\\"); 58 | else { 59 | g_keyword = argv[1]; 60 | scan(argv[2]); 61 | } 62 | 63 | getchar(); 64 | return 0; 65 | } --------------------------------------------------------------------------------