Shortest path 代码

发布于:2025-05-30 ⋅ 阅读:(16) ⋅ 点赞:(0)

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/ShortestPathTest.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)
在这里插入图片描述