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.
 
 
 

83 lines
2.6 KiB

#include "DGG_precompute/dgg_precompute.h"
#include "ICH/RichModel.h"
#include "Renderer/Renderer.h"
#include "dgg_dijkstra.h"
#include "src/ICH/Point3D.h"
#include <filesystem>
using namespace std;
namespace fs = std::filesystem;
string getDGGFileName(const string &input_obj_name,
double accuracy_control_parameter,
double const_for_theta) {
char buf[1024];
sprintf(buf, "%s_FD%.10lf_c%.0lf.binary",
input_obj_name.substr(0, input_obj_name.length() - 4).c_str(),
accuracy_control_parameter, const_for_theta);
return string(buf);
}
int main(int argc, char **argv) {
string input_file_name = "E:\\CProj\\DGG_and_SVG\\bunny.obj";
double accuracy_control_parameter = 0.01;
double const_for_theta = 5;
int thread_num = 12;
string dgg_file_name = getDGGFileName(
input_file_name, accuracy_control_parameter, const_for_theta);
std::cout << "Output DGG file: " << dgg_file_name << std::endl;
// * step 1: pre-compute the DGG
if (!fs::exists(dgg_file_name)) {
DGG_ICH_Precompute_Multithread(input_file_name, accuracy_control_parameter,
const_for_theta, thread_num);
} else {
std::cout << "DGG file exists, skip pre-computation." << std::endl;
}
// * step 2: load mesh (for rendering)
// * It is better to reused the model loaded in step 1
CRichModel model("E:\\CProj\\DGG_and_SVG\\bunny.obj");
model.Preprocess();
// * step 3: load the pre-computed DGG and do single-source shortest path
// query
SparseGraph<float> *s_graph = nullptr;
int from = 0, to = 6666;
s_graph = new Dijkstra<float>();
s_graph->readDGGFile(dgg_file_name);
s_graph->findShortestDistance(from); // find the geodesic distance from a
// single source to all vertex of a mesh
// * step 4: get the shortest path from source to destination
std::vector<int> path_nodes;
s_graph->getPath(to, path_nodes); // get the shortest path from source
for (auto n : path_nodes) {
std::cout << n << " ";
}
vector<CPoint3D> path;
path.reserve(path_nodes.size());
for (auto n : path_nodes) {
path.emplace_back(model.Vert(n));
}
// * step 5: render the mesh and the path
Renderer &renderer = Renderer::getInstance();
renderer.addMesh({.model = &model, .color = GREEN, .opacity = 0.8f});
renderer.addPolyline(
{.points = path, .color = RED, .width = 8.0f, .closed = false});
renderer.addPointCloud(
{.points = {model.Vert(from), model.Vert(to)},
.color = BLUE,
.pointSize = 10.0f});
renderer.render();
return 0;
}