Skip to content

Commit ddc1fc1

Browse files
committed
also reconstruct the save the leaves model
1 parent 128ed75 commit ddc1fc1

File tree

1 file changed

+58
-26
lines changed

1 file changed

+58
-26
lines changed

AdTree/main.cpp

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,41 +133,70 @@ int batch_reconstruct(std::vector<std::string>& point_cloud_files, const std::st
133133
continue;
134134
}
135135

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

141138
Skeleton *skeleton = new Skeleton();
142-
bool status = skeleton->reconstruct_branches(cloud, mesh);
143-
if (!status) {
144-
std::cerr << "failed in reconstructing branches" << std::endl;
145-
delete cloud;
146-
delete mesh;
147-
delete skeleton;
148-
continue;
149-
}
150139

151-
// copy translation property from point_cloud to surface_mesh
152-
SurfaceMesh::ModelProperty<dvec3> prop = mesh->add_model_property<dvec3>("translation");
153-
prop[0] = cloud->get_model_property<dvec3>("translation")[0];
140+
// reconstruct branches
141+
{
142+
SurfaceMesh *mesh_branches = new SurfaceMesh;
143+
const std::string &branch_filename = file_system::base_name(cloud->name()) + "_branches.obj";
144+
mesh_branches->set_name(branch_filename);
145+
bool status = skeleton->reconstruct_branches(cloud, mesh_branches);
146+
if (!status) {
147+
std::cerr << "failed in reconstructing branches" << std::endl;
148+
delete cloud;
149+
delete mesh_branches;
150+
delete skeleton;
151+
continue;
152+
}
153+
// copy translation property from point_cloud to the branches model
154+
SurfaceMesh::ModelProperty<dvec3> prop = mesh_branches->add_model_property<dvec3>("translation");
155+
prop[0] = cloud->get_model_property<dvec3>("translation")[0];
156+
// save branches model
157+
const std::string branch_file = output_folder + "/" + branch_filename;
158+
if (SurfaceMeshIO::save(branch_file, mesh_branches)) {
159+
std::cout << "model of branches saved to: " << branch_file << std::endl;
160+
++count;
161+
} else
162+
std::cerr << "failed to save the model of branches" << std::endl;
163+
delete mesh_branches;
164+
}
154165

155-
// save branches model
156-
const std::string branch_file = output_folder + "/" + branch_filename;
157-
if (SurfaceMeshIO::save(branch_file, mesh)) {
158-
std::cout << "model of branches saved to: " << branch_file << std::endl;
159-
++count;
166+
// reconstruct leaves
167+
{
168+
SurfaceMesh *mesh_leaves = new SurfaceMesh;
169+
const std::string &leaves_filename = file_system::base_name(cloud->name()) + "_leaves.obj";
170+
mesh_leaves->set_name(leaves_filename);
171+
bool status = skeleton->reconstruct_leaves(mesh_leaves);
172+
if (!status) {
173+
std::cerr << "failed in reconstructing leaves" << std::endl;
174+
delete cloud;
175+
delete mesh_leaves;
176+
delete skeleton;
177+
continue;
178+
}
179+
// copy translation property from point_cloud to the leaves model
180+
SurfaceMesh::ModelProperty<dvec3> prop = mesh_leaves->add_model_property<dvec3>("translation");
181+
prop[0] = cloud->get_model_property<dvec3>("translation")[0];
182+
// save leaves model
183+
const std::string leaves_file = output_folder + "/" + leaves_filename;
184+
if (SurfaceMeshIO::save(leaves_file, mesh_leaves)) {
185+
std::cout << "model of leaves saved to: " << leaves_file << std::endl;
186+
++count;
187+
} else
188+
std::cerr << "failed to save the model of leaves" << std::endl;
189+
delete mesh_leaves;
160190
}
161-
else
162-
std::cerr << "failed to save the model of branches" << std::endl;
191+
192+
// --------------------------------------------------------------------------------------------
163193

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

169199
delete cloud;
170-
delete mesh;
171200
delete skeleton;
172201
}
173202

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

177206

178207
int main(int argc, char *argv[]) {
179-
// argc = 2;
180-
// argv[1] = "/Users/lnan/Projects/adtree/data";
181-
// argv[2] = "/Users/lnan/Projects/adtree/data-results";
208+
#if 0
209+
argc = 4;
210+
argv[1] = "/Users/lnan/Documents/Projects/AdTree/data";
211+
argv[2] = "/Users/lnan/Documents/Projects/AdTree/data-results";
212+
argv[3] = "-s";
213+
#endif
182214

183215
if (argc == 1) {
184216
TreeViewer viewer;

0 commit comments

Comments
 (0)