Skip to content

Commit

Permalink
also reconstruct the save the leaves model
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Jan 13, 2025
1 parent 128ed75 commit ddc1fc1
Showing 1 changed file with 58 additions and 26 deletions.
84 changes: 58 additions & 26 deletions AdTree/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,41 +133,70 @@ int batch_reconstruct(std::vector<std::string>& point_cloud_files, const std::st
continue;
}

// reconstruct branches
SurfaceMesh *mesh = new SurfaceMesh;
const std::string &branch_filename = file_system::base_name(cloud->name()) + "_branches.obj";
mesh->set_name(branch_filename);
// --------------------------------------------------------------------------------------------

Skeleton *skeleton = new Skeleton();
bool status = skeleton->reconstruct_branches(cloud, mesh);
if (!status) {
std::cerr << "failed in reconstructing branches" << std::endl;
delete cloud;
delete mesh;
delete skeleton;
continue;
}

// copy translation property from point_cloud to surface_mesh
SurfaceMesh::ModelProperty<dvec3> prop = mesh->add_model_property<dvec3>("translation");
prop[0] = cloud->get_model_property<dvec3>("translation")[0];
// reconstruct branches
{
SurfaceMesh *mesh_branches = new SurfaceMesh;
const std::string &branch_filename = file_system::base_name(cloud->name()) + "_branches.obj";
mesh_branches->set_name(branch_filename);
bool status = skeleton->reconstruct_branches(cloud, mesh_branches);
if (!status) {
std::cerr << "failed in reconstructing branches" << std::endl;
delete cloud;
delete mesh_branches;
delete skeleton;
continue;
}
// copy translation property from point_cloud to the branches model
SurfaceMesh::ModelProperty<dvec3> prop = mesh_branches->add_model_property<dvec3>("translation");
prop[0] = cloud->get_model_property<dvec3>("translation")[0];
// save branches model
const std::string branch_file = output_folder + "/" + branch_filename;
if (SurfaceMeshIO::save(branch_file, mesh_branches)) {
std::cout << "model of branches saved to: " << branch_file << std::endl;
++count;
} else
std::cerr << "failed to save the model of branches" << std::endl;
delete mesh_branches;
}

// save branches model
const std::string branch_file = output_folder + "/" + branch_filename;
if (SurfaceMeshIO::save(branch_file, mesh)) {
std::cout << "model of branches saved to: " << branch_file << std::endl;
++count;
// reconstruct leaves
{
SurfaceMesh *mesh_leaves = new SurfaceMesh;
const std::string &leaves_filename = file_system::base_name(cloud->name()) + "_leaves.obj";
mesh_leaves->set_name(leaves_filename);
bool status = skeleton->reconstruct_leaves(mesh_leaves);
if (!status) {
std::cerr << "failed in reconstructing leaves" << std::endl;
delete cloud;
delete mesh_leaves;
delete skeleton;
continue;
}
// copy translation property from point_cloud to the leaves model
SurfaceMesh::ModelProperty<dvec3> prop = mesh_leaves->add_model_property<dvec3>("translation");
prop[0] = cloud->get_model_property<dvec3>("translation")[0];
// save leaves model
const std::string leaves_file = output_folder + "/" + leaves_filename;
if (SurfaceMeshIO::save(leaves_file, mesh_leaves)) {
std::cout << "model of leaves saved to: " << leaves_file << std::endl;
++count;
} else
std::cerr << "failed to save the model of leaves" << std::endl;
delete mesh_leaves;
}
else
std::cerr << "failed to save the model of branches" << std::endl;

// --------------------------------------------------------------------------------------------

if (export_skeleton) {
const std::string& skeleton_file = output_folder + "/" + file_system::base_name(cloud->name()) + "_skeleton.ply";
save_skeleton(skeleton, cloud, skeleton_file);
}

delete cloud;
delete mesh;
delete skeleton;
}

Expand All @@ -176,9 +205,12 @@ int batch_reconstruct(std::vector<std::string>& point_cloud_files, const std::st


int main(int argc, char *argv[]) {
// argc = 2;
// argv[1] = "/Users/lnan/Projects/adtree/data";
// argv[2] = "/Users/lnan/Projects/adtree/data-results";
#if 0
argc = 4;
argv[1] = "/Users/lnan/Documents/Projects/AdTree/data";
argv[2] = "/Users/lnan/Documents/Projects/AdTree/data-results";
argv[3] = "-s";
#endif

if (argc == 1) {
TreeViewer viewer;
Expand Down

0 comments on commit ddc1fc1

Please sign in to comment.