Browse Source

装系统前赶紧提交

master
lab pc 4 years ago
parent
commit
352b44c32d
  1. 2
      CMakeLists.txt
  2. 1
      tests/aabb_tree_test/.gitignore
  3. 9
      tests/aabb_tree_test/CMakeLists.txt
  4. 3
      tests/aabb_tree_test/data/.gitignore
  5. 201
      tests/aabb_tree_test/data/quarter_sphere.obj
  6. 30
      tests/aabb_tree_test/main.cpp
  7. 18
      tests/aabb_tree_test/test-path.h.in
  8. 19
      tests/search_assign_test/main.cpp
  9. 72
      tests/search_assign_test/search_assign.cpp

2
CMakeLists.txt

@ -38,6 +38,7 @@ if(Octree_BUILD_TEST)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/sdf_test) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/sdf_test)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/udf_test) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/udf_test)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/search_assign_test) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/search_assign_test)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/aabb_tree_test)
endif() endif()
enable_testing() enable_testing()
@ -46,4 +47,5 @@ if(Octree_BUILD_TEST)
add_test(NAME sdf_test COMMAND $<TARGET_FILE:sdf_test>) add_test(NAME sdf_test COMMAND $<TARGET_FILE:sdf_test>)
add_test(NAME udf_test COMMAND $<TARGET_FILE:udf_test>) add_test(NAME udf_test COMMAND $<TARGET_FILE:udf_test>)
add_test(NAME search_assign_test COMMAND $<TARGET_FILE:search_assign_test>) add_test(NAME search_assign_test COMMAND $<TARGET_FILE:search_assign_test>)
add_test(NAME aabb_tree_test COMMAND $<TARGET_FILE:aabb_tree_test>)
endif() endif()

1
tests/aabb_tree_test/.gitignore

@ -0,0 +1 @@
test-path.h

9
tests/aabb_tree_test/CMakeLists.txt

@ -0,0 +1,9 @@
set(LOCAL_TEST_DATA_BASE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/data)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/test-path.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/test-path.h"
)
add_executable(aabb_tree_test main.cpp)
target_link_libraries(aabb_tree_test Octree pMesh)

3
tests/aabb_tree_test/data/.gitignore

@ -0,0 +1,3 @@
*
!quarter_sphere.obj

201
tests/aabb_tree_test/data/quarter_sphere.obj

@ -0,0 +1,201 @@
# Created by meshio v4.4.6, 2021-12-07T16:21:22.906848
v 1.138410449 0.5 -2.2768445015
v 1.7076212168 0.91354751587 -1.8420119286
v 1.7076212168 0.086452484131 -1.8420119286
v 0.35179293156 1.5826867819 -2.2768466473
v 0.13438233733 2.2518339157 -1.8420149088
v 0.92100143433 1.9962415695 -1.8420145512
v 2.4112110138 0.91354966164 -0.70358890295
v 2.5455842018 0.5 0.0
v 2.4112110138 0.086450368166 -0.70358890295
v -0.36570191383 2.9486951828 -0.59173762798
v 0.351796031 2.9209909439 -0.703592062
v -0.017884045839 2.6959853172 -1.2873725891
v 1.3052562475 2.2660632133 -1.2873718739
v 1.1384255886 2.6653971672 -0.70359134674
v 1.7351754904 2.2660727501 -0.5917378068
v 2.215842247 1.6044858694 -0.59173750877
v 2.4112110138 0.91354966164 -0.70358890295
v 2.0829803944 1.1956111193 -1.287368536
v 0.56276673079 0.9088691473 -2.448697567
v -0.21495345235 1.1615698338 -2.448697567
v 0.35179293156 1.5826867819 -2.2768466473
v 1.3052562475 2.2660632133 -1.2873718739
v 1.5202087164 1.604483366 -1.7172887325
v 0.92100143433 1.9962415695 -1.8420145512
v -0.58065658808 2.2871074677 -1.7172898054
v -0.017884045839 2.6959853172 -1.2873725891
v 0.13438233733 2.2518339157 -1.8420149088
v -0.21495345235 1.1615698338 -2.448697567
v -0.69562107325 0.5 -2.4486958981
v -0.92099320889 1.1691398621 -2.2768449783
v 0.56276673079 0.9088691473 -2.448697567
v 1.138410449 0.5 -2.2768445015
v 0.56276673079 0.091130852699 -2.448697567
v 2.0829803944 1.1956111193 -1.287368536
v 1.7076212168 0.91354751587 -1.8420119286
v 1.5202087164 1.604483366 -1.7172887325
v 0.0 0.5 -2.5455842018
v 0.56276673079 0.091130852699 -2.448697567
v -0.21495345235 -0.16156989336 -2.448697567
v 2.1653957367 0.5 -1.3383048773
v 2.0829803944 -0.19561111927 -1.287368536
v 1.7076212168 0.086452484131 -1.8420119286
v 2.1653957367 0.5 -1.3383048773
v 1.7076212168 0.91354751587 -1.8420119286
v 2.0829803944 1.1956111193 -1.287368536
v 1.0826948881 1.2866146564 -2.1654121876
v 1.5202087164 1.604483366 -1.7172887325
v 1.7076212168 0.91354751587 -1.8420119286
v 1.841984868 1.8382645845 -1.1384234428
v 2.0829803944 1.1956111193 -1.287368536
v 1.5202087164 1.604483366 -1.7172887325
v 1.0826948881 1.2866146564 -2.1654121876
v 1.138410449 0.5 -2.2768445015
v 0.56276673079 0.9088691473 -2.448697567
v 1.0826948881 -0.28661459684 -2.1654121876
v 0.56276673079 0.091130852699 -2.448697567
v 1.138410449 0.5 -2.2768445015
v 0.0 0.5 -2.5455842018
v 0.56276673079 0.9088691473 -2.448697567
v 0.56276673079 0.091130852699 -2.448697567
v 0.0 0.5 -2.5455842018
v -0.21495345235 -0.16156989336 -2.448697567
v -0.69562107325 0.5 -2.4486958981
v -0.41354432702 1.77278018 -2.1654121876
v -0.21495345235 1.1615698338 -2.448697567
v -0.92099320889 1.1691398621 -2.2768449783
v 0.0 0.5 -2.5455842018
v -0.69562107325 0.5 -2.4486958981
v -0.21495345235 1.1615698338 -2.448697567
v -0.41354432702 1.77278018 -2.1654121876
v -0.58065658808 2.2871074677 -1.7172898054
v 0.13438233733 2.2518339157 -1.8420149088
v 0.66915482283 2.5594072342 -1.3383095264
v 0.13438233733 2.2518339157 -1.8420149088
v -0.017884045839 2.6959853172 -1.2873725891
v -0.703561306 2.6653757095 -1.1384234428
v -0.017884045839 2.6959853172 -1.2873725891
v -0.58065658808 2.2871074677 -1.7172898054
v 0.66915482283 2.5594072342 -1.3383095264
v 1.3052562475 2.2660632133 -1.2873718739
v 0.92100143433 1.9962415695 -1.8420145512
v 1.0826948881 1.2866146564 -2.1654121876
v 0.92100143433 1.9962415695 -1.8420145512
v 1.5202087164 1.604483366 -1.7172887325
v 1.841984868 1.8382645845 -1.1384234428
v 1.5202087164 1.604483366 -1.7172887325
v 1.3052562475 2.2660632133 -1.2873718739
v 1.0826948881 1.2866146564 -2.1654121876
v 0.56276673079 0.9088691473 -2.448697567
v 0.35179293156 1.5826867819 -2.2768466473
v -0.41354432702 1.77278018 -2.1654121876
v 0.35179293156 1.5826867819 -2.2768466473
v -0.21495345235 1.1615698338 -2.448697567
v 0.0 0.5 -2.5455842018
v -0.21495345235 1.1615698338 -2.448697567
v 0.56276673079 0.9088691473 -2.448697567
v 2.1653957367 0.5 -1.3383048773
v 2.4112110138 0.086450368166 -0.70358890295
v 2.0829803944 -0.19561111927 -1.287368536
v 2.4209980965 1.2866177559 0.0
v 2.4112110138 0.91354966164 -0.70358890295
v 2.215842247 1.6044858694 -0.59173750877
v 2.1653957367 0.5 -1.3383048773
v 2.0829803944 1.1956111193 -1.287368536
v 2.4112110138 0.91354966164 -0.70358890295
v 1.841984868 1.8382645845 -1.1384234428
v 2.215842247 1.6044858694 -0.59173750877
v 2.0829803944 1.1956111193 -1.287368536
v 0.66915482283 2.5594072342 -1.3383095264
v 1.1384255886 2.6653971672 -0.70359134674
v 1.3052562475 2.2660632133 -1.2873718739
v 1.841984868 1.8382645845 -1.1384234428
v 1.3052562475 2.2660632133 -1.2873718739
v 1.7351754904 2.2660727501 -0.5917378068
v 0.66915482283 2.5594072342 -1.3383095264
v -0.017884045839 2.6959853172 -1.2873725891
v 0.351796031 2.9209909439 -0.703592062
v -0.703561306 2.6653757095 -1.1384234428
v -0.36570191383 2.9486951828 -0.59173762798
v -0.017884045839 2.6959853172 -1.2873725891
v 1.841984868 1.8382645845 -1.1384234428
v 1.7351754904 2.2660727501 -0.5917378068
v 2.215842247 1.6044858694 -0.59173750877
v 0.66915482283 2.5594072342 -1.3383095264
v 0.351796031 2.9209909439 -0.703592062
v 1.1384255886 2.6653971672 -0.70359134674
v 2.4209980965 1.2866177559 0.0
v 2.5455842018 0.5 0.0
v 2.4112110138 0.91354966164 -0.70358890295
v 2.1653957367 0.5 -1.3383048773
v 2.4112110138 0.91354966164 -0.70358890295
v 2.4112110138 0.086450368166 -0.70358890295
v 1.0826948881 1.2866146564 -2.1654121876
v 0.35179293156 1.5826867819 -2.2768466473
v 0.92100143433 1.9962415695 -1.8420145512
v 0.66915482283 2.5594072342 -1.3383095264
v 0.92100143433 1.9962415695 -1.8420145512
v 0.13438233733 2.2518339157 -1.8420149088
v -0.41354432702 1.77278018 -2.1654121876
v 0.13438233733 2.2518339157 -1.8420149088
v 0.35179293156 1.5826867819 -2.2768466473
v 1.0826948881 1.2866146564 -2.1654121876
v 1.7076212168 0.91354751587 -1.8420119286
v 1.138410449 0.5 -2.2768445015
v 2.1653957367 0.5 -1.3383048773
v 1.7076212168 0.086452484131 -1.8420119286
v 1.7076212168 0.91354751587 -1.8420119286
v 1.0826948881 -0.28661459684 -2.1654121876
v 1.138410449 0.5 -2.2768445015
v 1.7076212168 0.086452484131 -1.8420119286
f 1 2 3
f 4 5 6
f 7 8 9
f 10 11 12
f 13 14 15
f 16 17 18
f 19 20 21
f 22 23 24
f 25 26 27
f 28 29 30
f 31 32 33
f 34 35 36
f 37 38 39
f 40 41 42
f 43 44 45
f 46 47 48
f 49 50 51
f 52 53 54
f 55 56 57
f 58 59 60
f 61 62 63
f 64 65 66
f 67 68 69
f 70 71 72
f 73 74 75
f 76 77 78
f 79 80 81
f 82 83 84
f 85 86 87
f 88 89 90
f 91 92 93
f 94 95 96
f 97 98 99
f 100 101 102
f 103 104 105
f 106 107 108
f 109 110 111
f 112 113 114
f 115 116 117
f 118 119 120
f 121 122 123
f 124 125 126
f 127 128 129
f 130 131 132
f 133 134 135
f 136 137 138
f 139 140 141
f 142 143 144
f 145 146 147
f 148 149 150

30
tests/aabb_tree_test/main.cpp

@ -0,0 +1,30 @@
/**
* ------------------------------------
* @author: Weipeng Kong
* @date: 2021/11/17
* @email: yjxkwp@foxmail.com
* @site: https://donot.fit
* @description:
* ------------------------------------
**/
#include <iostream>
#include <igl/marching_cubes.h>
#include <igl/voxel_grid.h>
#include <igl/writeOBJ.h>
#include <igl/readOBJ.h>
#include <igl/read_triangle_mesh.h>
#include <igl/in_element.h>
#include <boost/log/trivial.hpp>
#include <boost/filesystem.hpp>
#include <Eigen/Core>
#include "test-path.h"
int main() {
auto mesh_path = boost::filesystem::path(LOCAL_TEST_DATA_BASE_PATH) / "quarter_sphere.obj";
Eigen::MatrixXd V;
Eigen::MatrixXi F;
igl::read_triangle_mesh(mesh_path.string(), V, F);
return 0;
}

18
tests/aabb_tree_test/test-path.h.in

@ -0,0 +1,18 @@
/**
* ------------------------------------
* @author: Weipeng Kong
* @date: 2021/12/1
* @email: yjxkwp@foxmail.com
* @site: https://donot.fit
* @description:
* ------------------------------------
**/
#ifndef OCTREE_SDF_TEST_PATH_H
#define OCTREE_SDF_TEST_PATH_H
#define TEST_DATA_BASE_PATH "@TEST_DATA_BASE_PATH@"
#define LOCAL_TEST_DATA_BASE_PATH "@LOCAL_TEST_DATA_BASE_PATH@"
#endif //OCTREE_SDF_TEST_PATH_H

19
tests/search_assign_test/main.cpp

@ -39,9 +39,9 @@ int main() {
Eigen::AlignedBox<double, 3> aabb(Eigen::Vector3d(0,0,0), Eigen::Vector3d(1, 1, 1)); Eigen::AlignedBox<double, 3> aabb(Eigen::Vector3d(0,0,0), Eigen::Vector3d(1, 1, 1));
int aabb_res_x = 20; int aabb_res_x = 400;
int aabb_res_y = 20; int aabb_res_y = 400;
int aabb_res_z = 20; int aabb_res_z = 400;
int aabb_len = aabb_res_x * aabb_res_y * aabb_res_z; int aabb_len = aabb_res_x * aabb_res_y * aabb_res_z;
double x0 = 0; double x0 = 0;
@ -77,16 +77,23 @@ int main() {
if(use_udf) { if(use_udf) {
int start[3] = {aabb_res_x/2, aabb_res_y/2, aabb_res_z/2}; int start[3] = {aabb_res_x/2, aabb_res_y/2, aabb_res_z/2};
double block_size[3]; double block_size[3] = {
aabb.sizes().x() / (aabb_res_x - 1),
aabb.sizes().y() / (aabb_res_y - 1),
aabb.sizes().z() / (aabb_res_z - 1)
};
// TODO: // TODO:
double threshold = 0; double threshold = std::max({block_size[0], block_size[1], block_size[2]});
boost::timer t;
search_assign(udf_data, start, threshold); search_assign(udf_data, start, threshold);
BOOST_LOG_TRIVIAL(debug) << "[search_assign]: " << t.elapsed();
} }
if (1) { if (1) {
Eigen::MatrixXd GV; Eigen::MatrixXd GV;
Eigen::RowVector3i res; Eigen::RowVector3i res;
const int s = 200; const int s = 10;
igl::voxel_grid(aabb, s, 1, GV, res); igl::voxel_grid(aabb, s, 1, GV, res);
// compute values // compute values

72
tests/search_assign_test/search_assign.cpp

@ -22,8 +22,6 @@ dfs_for_assigning(Octree::UDFData &udf, int current_x, int current_y, int curren
if (abs(udf.value[ind]) < threshold) { if (abs(udf.value[ind]) < threshold) {
return; return;
// double pos[] = {current_x * 1.0, current_y * 1.0, current_z * 1.0, udf.value[ind]};
// recorder(pos);
} }
udf.value[ind] = -abs(udf.value[ind]); udf.value[ind] = -abs(udf.value[ind]);
@ -46,20 +44,66 @@ dfs_for_assigning(Octree::UDFData &udf, int current_x, int current_y, int curren
} }
} }
} }
}
#include <queue>
#include <boost/tuple/tuple.hpp>
struct BFSParam{
int x;
int y;
int z;
int id;
};
void
bfs_for_assigning(Octree::UDFData &udf, int start_x, int start_y, int start_z, const double threshold,
std::function<void(const double *)> recorder) {
int start_id = udf.get_array_index(start_x, start_y, start_z);
std::queue<BFSParam> Q;
Q.push({.x=start_x, .y=start_y, .z=start_z, .id=start_id});
while(not Q.empty()){
auto [current_x, current_y, current_z, ind] = Q.front();
Q.pop();
if(visited[ind]) continue;
visited[ind] = true;
if (abs(udf.value[ind]) < threshold) {
continue;
}
udf.value[ind] = -abs(udf.value[ind]);
// sub routine // sub routine
// for (auto nb: neighbors) { for (int i = -1; i <= 1; ++i) {
// if (nb[0] < 0 || nb[0] >= udf._x || int x = current_x + i;
// nb[1] < 0 || nb[1] >= udf._y || if (x < 0 || x >= udf._x) continue;
// nb[2] < 0 || nb[2] >= udf._z) {
// continue; for (int j = -1; j <= 1; ++j) {
// } else { int y = current_y + j;
// int next_ind = udf.get_array_index(nb[0], nb[1], nb[2]); if (y < 0 || y >= udf._y) continue;
// dfs_for_assigning(udf, nb[0], nb[1], nb[2], next_ind, threshold, recorder);
// } for (int k = -1; k <= 1; ++k) {
// } int z = current_z + k;
if (z < 0 || z >= udf._z) continue;
int next_ind = udf.get_array_index(x, y, z);
Q.push({.x=x, .y=y, .z=z, .id=next_ind});
}
}
}
}
} }
#include <igl/point_mesh_squared_distance.h>
#include <igl/signed_distance.h>
#include <igl/AABB.h>
#include <igl/in_element.h>
void search_assign(Octree::UDFData &udf, int *start, double threshold) { void search_assign(Octree::UDFData &udf, int *start, double threshold) {
visited = new bool[udf._x * udf._y * udf._z]; visited = new bool[udf._x * udf._y * udf._z];
@ -70,9 +114,7 @@ void search_assign(Octree::UDFData &udf, int *start, double threshold) {
}; };
// TODO: 选取开始点 // TODO: 选取开始点
int next_ind = udf.get_array_index(start[0], start[1], start[2]); bfs_for_assigning(udf, start[0], start[1], start[2], threshold, recoder);
dfs_for_assigning(udf, start[0], start[1], start[2], next_ind, threshold, recoder);
// TODO: 爆栈问题
delete visited; delete visited;
visited = nullptr; visited = nullptr;

Loading…
Cancel
Save