summaryrefslogtreecommitdiff
path: root/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-09-10 07:37:33 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-09-10 07:37:33 +0000
commit9bcfe7ed9dabd7ac4688bd4e5ee6f60bf83635b4 (patch)
tree316baf5f6377d11c8db1075e34b4fddfaff3db65 /src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp
parente361de9c520eb3e5d789099f4cdaf4fb0efdba63 (diff)
Code review : Fix alpha_complex_3d_persistence utility with new alpha_complex_3d design
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_complex_3d_module_vincent@3877 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 59c028ed6d5a3c85efeb99398a6d2e34c3af096a
Diffstat (limited to 'src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp')
-rw-r--r--src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp142
1 files changed, 73 insertions, 69 deletions
diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp
index 1a152541..fb1418bb 100644
--- a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp
+++ b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp
@@ -38,29 +38,10 @@ using Filtration_value = Simplex_tree::Filtration_value;
using Persistent_cohomology =
Gudhi::persistent_cohomology::Persistent_cohomology<Simplex_tree, Gudhi::persistent_cohomology::Field_Zp>;
-using Fast_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::fast, false, false>;
-using Safe_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::safe, false, false>;
-using Exact_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact, false, false>;
-using Fast_weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::fast, true, false>;
-using Safe_weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::safe, true, false>;
-using Exact_weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact, true, false>;
-using Fast_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::fast, false, true>;
-using Safe_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::safe, false, true>;
-using Exact_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact, false, true>;
-using Fast_weighted_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::fast, true, true>;
-using Safe_weighted_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::safe, true, true>;
-using Exact_weighted_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact, true, true>;
-
void program_options(int argc, char *argv[], std::string &off_file_points, bool& exact, std::string &weight_file,
std::string &cuboid_file, std::string &output_file_diag, Filtration_value &alpha_square_max_value,
int &coeff_field_characteristic, Filtration_value &min_persistence);
-template<typename AlphaComplex3d>
-bool create_complex(AlphaComplex3d& alpha_complex, Simplex_tree& simplex_tree,
- Filtration_value alpha_square_max_value) {
- return alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
-}
-
bool read_weight_file(const std::string& weight_file, std::vector<double>& weights) {
// Read weights information from file
std::ifstream weights_ifstr(weight_file);
@@ -90,6 +71,18 @@ bool read_cuboid_file(const std::string& cuboid_file, double& x_min, double& y_m
return true;
}
+template<typename AlphaComplex3d>
+std::vector<typename AlphaComplex3d::Point_3> read_off(const std::string& off_file_points) {
+ // Read the OFF file (input file name given as parameter) and triangulate points
+ Gudhi::Points_3D_off_reader<typename AlphaComplex3d::Point_3> off_reader(off_file_points);
+ // Check the read operation was correct
+ if (!off_reader.is_valid()) {
+ std::cerr << "Unable to read OFF file " << off_file_points << std::endl;
+ exit(-1);
+ }
+ return off_reader.get_point_cloud();
+}
+
int main(int argc, char **argv) {
std::string off_file_points;
std::string weight_file;
@@ -105,28 +98,61 @@ int main(int argc, char **argv) {
program_options(argc, argv, off_file_points, exact_version, weight_file, cuboid_file, output_file_diag,
alpha_square_max_value, coeff_field_characteristic, min_persistence);
+ std::vector<double> weights;
+ if (weight_file != std::string()) {
+ if (!read_weight_file(weight_file, weights)) {
+ std::cerr << "Unable to read weights file " << weight_file << std::endl;
+ exit(-1);
+ }
+ weighted_version = true;
+ }
+
+ double x_min=0., y_min=0., z_min=0., x_max=0., y_max=0., z_max=0.;
+ std::ifstream iso_cuboid_str(argv[3]);
+ if (cuboid_file != std::string()) {
+ if (!read_cuboid_file(cuboid_file, x_min, y_min, z_min, x_max, y_max, z_max)) {
+ std::cerr << "Unable to read cuboid file " << cuboid_file << std::endl;
+ exit(-1);
+ }
+ periodic_version = true;
+ }
+
Gudhi::alpha_complex::complexity complexity = Gudhi::alpha_complex::complexity::fast;
if (exact_version) {
complexity = Gudhi::alpha_complex::complexity::exact;
}
+ Simplex_tree simplex_tree;
+
switch(complexity) {
case Gudhi::alpha_complex::complexity::fast:
if (weighted_version) {
if (periodic_version) {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::fast,
true, true>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points, weights, x_min, y_min, z_min, x_max, y_max, z_max);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
} else {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::fast,
true, false>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points, weights);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
}
} else {
if (periodic_version) {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::fast,
false, true>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points, x_min, y_min, z_min, x_max, y_max, z_max);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
} else {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::fast,
false, false>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
}
}
break;
@@ -135,17 +161,29 @@ int main(int argc, char **argv) {
if (periodic_version) {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact,
true, true>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points, weights, x_min, y_min, z_min, x_max, y_max, z_max);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
} else {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact,
true, false>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points, weights);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
}
} else {
if (periodic_version) {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact,
false, true>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points, x_min, y_min, z_min, x_max, y_max, z_max);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
} else {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact,
false, false>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
}
}
break;
@@ -154,72 +192,38 @@ int main(int argc, char **argv) {
if (periodic_version) {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::safe,
true, true>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points, weights, x_min, y_min, z_min, x_max, y_max, z_max);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
} else {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::safe,
true, false>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points, weights);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
}
} else {
if (periodic_version) {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::safe,
false, true>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points, x_min, y_min, z_min, x_max, y_max, z_max);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
} else {
using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::safe,
false, false>;
+ auto points = read_off<Alpha_complex_3d>(off_file_points);
+ Alpha_complex_3d alpha_complex(points);
+ alpha_complex.create_complex(simplex_tree, alpha_square_max_value);
}
}
break;
- }
-
- /*const Gudhi::alpha_complex::complexity complexity_(complexity);
- // Read the OFF file (input file name given as parameter) and triangulate points
- Gudhi::Points_3D_off_reader<Alpha_complex_3d::Point_3> off_reader(off_file_points);
- // Check the read operation was correct
- if (!off_reader.is_valid()) {
- std::cerr << "Unable to read OFF file " << off_file_points << std::endl;
- exit(-1);
- }
-
- std::vector<double> weights;
- if (weight_file != std::string()) {
- if (!read_weight_file(weight_file, weights)) {
- std::cerr << "Unable to read weights file " << weight_file << std::endl;
- exit(-1);
- }
- weighted_version = true;
- }
-
- double x_min=0., y_min=0., z_min=0., x_max=0., y_max=0., z_max=0.;
- std::ifstream iso_cuboid_str(argv[3]);
- if (cuboid_file != std::string()) {
- if (!read_cuboid_file(cuboid_file, x_min, y_min, z_min, x_max, y_max, z_max)) {
- std::cerr << "Unable to read cuboid file " << cuboid_file << std::endl;
+ default:
+ std::cerr << "Unknown complexity value " << std::endl;
exit(-1);
- }
- periodic_version = true;
- }
-
- Simplex_tree simplex_tree;
-
- if (weighted_version) {
- if (periodic_version) {
- Alpha_complex_3d alpha_complex(off_reader.get_point_cloud(), weights,
- x_min, y_min, z_min, x_max, y_max, z_max);
- create_complex(alpha_complex, simplex_tree, alpha_square_max_value);
- } else {
- Alpha_complex_3d alpha_complex(off_reader.get_point_cloud(), weights);
- create_complex(alpha_complex, simplex_tree, alpha_square_max_value);
- }
- } else {
- if (periodic_version) {
- Alpha_complex_3d alpha_complex(off_reader.get_point_cloud(), x_min, y_min, z_min, x_max, y_max, z_max);
- create_complex(alpha_complex, simplex_tree, alpha_square_max_value);
- } else {
- Alpha_complex_3d alpha_complex(off_reader.get_point_cloud());
- create_complex(alpha_complex, simplex_tree, alpha_square_max_value);
- }
+ break;
}
-
// Sort the simplices in the order of the filtration
simplex_tree.initialize_filtration();
@@ -239,7 +243,7 @@ int main(int argc, char **argv) {
std::ofstream out(output_file_diag);
pcoh.output_diagram(out);
out.close();
- }*/
+ }
return 0;
}