7 changed files with 114 additions and 59 deletions
@ -1,3 +1,59 @@ |
|||||
# SingularityJudger |
# SingularityJudger |
||||
|
|
||||
Integration of gauss map, osculating toroidal patches, loop detection and C2 judgement to figure out the singular or loop intersection. |
Integration of gauss map, osculating toroidal patches, loop detection and C2 judgement to figure out the singular or loop intersection. |
||||
|
|
||||
|
## Usage |
||||
|
CmakeLists.txt中将以下两行改为自己tinynurbs和glm的依赖路径 |
||||
|
```cmake |
||||
|
include_directories(E:/CLib/tinynurbs/include E:/CLib/glm) |
||||
|
``` |
||||
|
### 直接运行 |
||||
|
直接cmake构建,make编译链接,运行可执行文件即可 |
||||
|
### 生成依赖库 |
||||
|
1. CMakeLists.txt中注释以下代码 |
||||
|
```cmake |
||||
|
add_executable(SingularityJudger main.cpp ${DIR_SRCS} ${DIR_INCLUDE}) |
||||
|
|
||||
|
# 下面两个仅仅是main文件的依赖,用于对读取的曲面文本文件做字符串处理 |
||||
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) |
||||
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) |
||||
|
``` |
||||
|
2. CMakeLists.txt中取消注释以下代码 |
||||
|
```cmake |
||||
|
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
||||
|
#add_library(SingularityJudger ${DIR_SRCS}) |
||||
|
``` |
||||
|
3. CMake构建,make生成 |
||||
|
### 具体使用 |
||||
|
```c++ |
||||
|
#include "bvh.h" |
||||
|
#include "singularityJudger.h" |
||||
|
// 创建两个曲面 |
||||
|
tinynursb::RationalSurface<float> s; |
||||
|
tinynursb::RationalSurface<float> f; |
||||
|
// 曲面初始化 |
||||
|
... |
||||
|
|
||||
|
// 采样层数 |
||||
|
int level = 6; |
||||
|
// 得到两个曲面level层的采样信息 |
||||
|
// 如果已经采样过,这里用SrfMesh的无参构造,然后把采样的网格数据传入,避免重复采样 |
||||
|
auto mesh1 = SrfMesh(s, level); |
||||
|
auto mesh2 = SrfMesh(f, level); |
||||
|
|
||||
|
// 构建BVH |
||||
|
BVH bvh1(mesh1.evaluation); |
||||
|
BVH bvh2(mesh2.evaluation); |
||||
|
bvh1.build(); |
||||
|
bvh2.build(); |
||||
|
// bvh判交,获得重叠盒子对 |
||||
|
auto intersectBoxPairs = getOverlapLeafNodes(bvh1, bvh2); // return [{{u1, v1}, {u2, v2}}] |
||||
|
|
||||
|
// 创建SingularityJudger对象 |
||||
|
SingularityJudger singularityJudger(s, f, mesh1, mesh2); |
||||
|
|
||||
|
// 对于两个曲面各自的参数下标范围所确定的两个子面片,判断哪些小格子内存在critical point |
||||
|
// 一般就用完整的参数下标范围,即{0, pow(2, level - 1) - 1} |
||||
|
pair<int, int> cellIdxFullRange = {0, pow(2, level - 1) - 1}; |
||||
|
auto cellsWithCriticalPts = singularityJudger.judge(intersectBoxPairs, cellIdxFullRange, cellIdxFullRange, cellIdxFullRange, cellIdxFullRange); |
||||
|
``` |
@ -1 +1,40 @@ |
|||||
#include "srf_mesh.h" |
#include "srf_mesh.h" |
||||
|
|
||||
|
SrfMesh::SrfMesh(const tinynurbs::RationalSurface<float> &s, int sampleLevel_): sampleLevel(sampleLevel_) { |
||||
|
auto sampleCnt = sampleCntOnSingleDir = int(pow(2, sampleLevel - 1) + 1); |
||||
|
evaluation = vector<vector<glm::vec3>>(sampleCntOnSingleDir, vector<glm::vec3>(sampleCntOnSingleDir)); |
||||
|
tangent_u = vector<vector<glm::vec3>>(sampleCntOnSingleDir, vector<glm::vec3>(sampleCntOnSingleDir)); |
||||
|
tangent_v = vector<vector<glm::vec3>>(sampleCntOnSingleDir, vector<glm::vec3>(sampleCntOnSingleDir)); |
||||
|
normal = vector<vector<glm::vec3>>(sampleCntOnSingleDir, vector<glm::vec3>(sampleCntOnSingleDir)); |
||||
|
|
||||
|
auto s_first_u = *(s.knots_u.begin()); |
||||
|
auto s_first_v = *(s.knots_v.begin()); |
||||
|
auto s_step_u = (*(s.knots_u.end() - 1) - s_first_u) / float(sampleCntOnSingleDir - 1); |
||||
|
auto s_step_v = (*(s.knots_v.end() - 1) - s_first_v) / float(sampleCntOnSingleDir - 1); |
||||
|
|
||||
|
// evaluation correction test
|
||||
|
auto u = 0.35f; |
||||
|
auto v = 0.35f; |
||||
|
auto pt = tinynurbs::surfacePoint(s, u, v); |
||||
|
printf("pt on u = %g, v = %g is (%f, %f, %f)\n", u, v, pt.x, pt.y, pt.z); |
||||
|
auto der = tinynurbs::surfaceDerivatives(s, 1, u, v); |
||||
|
auto du = der(1, 0); |
||||
|
auto dv = der(0, 1); |
||||
|
printf("derivatives of u when u = %g, v = %g is (%f, %f, %f)\n", u, v, du.x, du.y, du.z); |
||||
|
printf("derivatives of v when u = %g, v = %g is (%f, %f, %f)\n", u, v, dv.x, dv.y, dv.z); |
||||
|
// end of correction test
|
||||
|
|
||||
|
for (int i = 0; i < sampleCnt; i++) { |
||||
|
auto u = s_first_u + s_step_u * float(i); |
||||
|
for (int j = 0; j < sampleCnt; j++) { |
||||
|
auto v = s_first_v + s_step_v * float(j); |
||||
|
evaluation[i][j] = tinynurbs::surfacePoint(s, u, v); |
||||
|
auto der = tinynurbs::surfaceDerivatives(s, 1, u, v); |
||||
|
// if(der(0, 0) == evaluation[i][j]) cout<<"amazing"<<endl;
|
||||
|
// else cout<<"what??? ("<<evaluation[i][j].x<<" "<<evaluation[i][j].y<<" "<<evaluation[i][j].z<<") | ("<<der(0, 0).x<<" "<<der(0, 0).y<<" "<<der(0, 0).z<<")"<<endl;
|
||||
|
tangent_u[i][j] = der(1, 0); |
||||
|
tangent_v[i][j] = der(0, 1); |
||||
|
normal[i][j] = glm::normalize(glm::cross(tangent_u[i][j], tangent_v[i][j])); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
Loading…
Reference in new issue