Project
https://graphics.cs.utah.edu/research/projects/shortest-path-to-boundary/
Build and Debug
Fork:(在Win10上)
https://github.com/chunleili/Shortest-Path-to-Boundary-for-Self-Intersecting-Meshes
commit hash
d3160168d2b6a58188d12e6cd959da0ac9b56e95
./vscode/launch.json
{
“version”: “0.2.0”,
“configurations”: [
{
“name”: “(msvc) Launch”,
“type”: “cppvsdbg”,
“request”: “launch”,
// Resolved by CMake Tools:
“program”: “ w o r k s p a c e F o l d e r / b u i l d / D e b u g / S h o r t e s t ? P a t h ? T e s t . e x e " , " a r g s " : [ " T e s t D a t a / P a r a m e t e r s . j s o n " , " T e s t D a t a / I n t e r s e c t i n g S h a p e . t " ] , " s t o p A t E n t r y " : t r u e , " c w d " : " {workspaceFolder}/build/Debug/Shortest-Path-Test.exe", "args": ["TestData/Parameters.json", "TestData/IntersectingShape.t"], "stopAtEntry": true, "cwd": " workspaceFolder/build/Debug/Shortest?Path?Test.exe","args":["TestData/Parameters.json","TestData/IntersectingShape.t"],"stopAtEntry":true,"cwd":"{workspaceFolder}”,
“environment”: [
{
// add the directory where our target was built to the PATHs
// it gets resolved by CMake Tools:
“name”: “PATH”,
“value”: “ e n v : P A T H : {env:PATH}: env:PATH:{command:cmake.getLaunchTargetDirectory}”
},
],
“console”: “internalConsole”,
}
]
}
Code Explain
Test.cpp中是入口main函數
40行之前是初始化(mesh和param)
在這個for loop當中查找每個Vert的最近點。
關鍵的函數
dcd.vertexCollisionDetection(iV, meshId, &colDecResult);
用BVH做碰撞檢測。(Broad Phase)
dcd.closestPointQuery(&colDecResult, &queryResult);
用碰撞檢測后的結果查找最近點。(Narrow Phase)
Broad Phase:vertexCollisionDetection
核心就rtcPointQuery,調用的是intel embree的API
D:\Dev\Shortest-Path-to-Boundary-for-Self-Intersecting-Meshes\ShortestPath\CollisionDetector\DiscreteCollisionDetector.cpp
L598
https://github.com/chunleili/Shortest-Path-to-Boundary-for-Self-Intersecting-Meshes/blob/5be890b7775dc92cde410895d124c81162bee978/ShortestPath/CollisionDetector/DiscreteCollisionDetector.cpp#L598
Narrow Phase: closestPointQuery
https://github.com/chunleili/Shortest-Path-to-Boundary-for-Self-Intersecting-Meshes/blob/5be890b7775dc92cde410895d124c81162bee978/ShortestPath/CollisionDetector/DiscreteCollisionDetector.cpp#L621
其中較為關鍵的是idTetIntersected,表示相交的四面體的id。intersectedTets則是所有相交四面的的array。
執行查詢最近點:
rtcPointQuery(surfaceMeshScenes[idTMIntersected], &query, &context, nullptr, (void*)pClosestPtResult); 仍然是用API來查詢點。目的是針對某個表面網格(surfaceMeshScenes[idTMIntersected]),找到距離查詢點最近的表面點,并把結果存儲在 pClosestPtResult 中。
接下來是存儲找到的最近點的信息:其face id, 坐標, barycentric coord.
另外,rtc是根據注冊機制自動調用一些hook函數的例如比較關鍵的是
其中checkTetTraverse這個flag表示檢查四面體的遍歷,正是文中提到的連接性檢測(valid path)