You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.4 KiB

4 years ago
/**
* ------------------------------------
* @author: Weipeng Kong
* @date: 2021/12/6
* @email: yjxkwp@foxmail.com
* @site: https://donot.fit
* @description:
* ------------------------------------
**/
#include "search_assign.h"
#include <pMesh/mesh/TriangleMesh.h>
#include <iostream>
bool *visited;
void
dfs_for_assigning(Octree::UDFData &udf, int current_x, int current_y, int current_z, int ind, const double threshold,
std::function<void(const double *)> recorder) {
if (visited[ind] || ind == -1) return;
visited[ind] = true;
if (abs(udf.value[ind]) < threshold) {
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]);
// sub routine
for (int i = -1; i <= 1; ++i) {
int x = current_x + i;
if (x < 0 || x >= udf._x) continue;
for (int j = -1; j <= 1; ++j) {
int y = current_y + j;
if (y < 0 || y >= udf._y) continue;
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);
dfs_for_assigning(udf, x, y, z, next_ind, threshold, recorder);
}
}
}
// sub routine
// for (auto nb: neighbors) {
// if (nb[0] < 0 || nb[0] >= udf._x ||
// nb[1] < 0 || nb[1] >= udf._y ||
// nb[2] < 0 || nb[2] >= udf._z) {
// continue;
// } else {
// int next_ind = udf.get_array_index(nb[0], nb[1], nb[2]);
// dfs_for_assigning(udf, nb[0], nb[1], nb[2], next_ind, threshold, recorder);
// }
// }
}
void search_assign(Octree::UDFData &udf, int *start, double threshold) {
visited = new bool[udf._x * udf._y * udf._z];
pMesh::Triangle3dMesh point_cloud;
auto recoder = [&](const double *pos) {
// point_cloud.vertices.emplace_back(pMesh::Triangle3dMesh::VertexField())
// std::cout << pos[0] << " " << pos[1] << " " << pos[2] << std::endl;
};
// TODO: 选取开始点
int next_ind = udf.get_array_index(start[0], start[1], start[2]);
dfs_for_assigning(udf, start[0], start[1], start[2], next_ind, threshold, recoder);
// TODO: 爆栈问题
delete visited;
visited = nullptr;
};