summaryrefslogtreecommitdiff
path: root/matching/src/bifiltration.cpp
diff options
context:
space:
mode:
authorArnur Nigmetov <nigmetov@tugraz.at>2020-02-19 17:42:41 +0100
committerArnur Nigmetov <nigmetov@tugraz.at>2020-02-19 17:42:41 +0100
commitf62d98e76b9dff173f9144caddff1217d0bb81a9 (patch)
tree4ea6a6d894114c0d98c91079edfcc59d0611eb14 /matching/src/bifiltration.cpp
parentbe93a006a3f2c630abf9d0169a70e6292ac7504f (diff)
Require first file line specify the format.
1. Input format must be in the first line of input file, as in RIVET. 2. Disable more unnecessary output. 3. Get rid of some warnings.
Diffstat (limited to 'matching/src/bifiltration.cpp')
-rw-r--r--matching/src/bifiltration.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/matching/src/bifiltration.cpp b/matching/src/bifiltration.cpp
index 676b0cc..4131e6b 100644
--- a/matching/src/bifiltration.cpp
+++ b/matching/src/bifiltration.cpp
@@ -29,7 +29,7 @@ namespace md {
bounding_box_ = Box(lower_left, upper_right);
}
- Bifiltration::Bifiltration(const std::string& fname, BifiltrationFormat input_format)
+ Bifiltration::Bifiltration(const std::string& fname )
{
std::ifstream ifstr {fname.c_str()};
if (!ifstr.good()) {
@@ -38,6 +38,23 @@ namespace md {
throw std::runtime_error(error_message);
}
+ BifiltrationFormat input_format;
+
+ std::string s;
+
+ while(ignore_line(s)) {
+ std::getline(ifstr, s);
+ }
+
+ if (s == "bifiltration") {
+ input_format = BifiltrationFormat::rivet;
+ } else if (s == "bifiltration_phat_like") {
+ input_format = BifiltrationFormat::phat_like;
+ } else {
+ std::cerr << "Unknown format: '" << s << "' in file " << fname << std::endl;
+ throw std::runtime_error("unknown bifiltration format");
+ }
+
switch(input_format) {
case BifiltrationFormat::rivet :
rivet_format_reader(ifstr);
@@ -46,22 +63,27 @@ namespace md {
phat_like_format_reader(ifstr);
break;
}
+
+ ifstr.close();
+
init();
}
void Bifiltration::rivet_format_reader(std::ifstream& ifstr)
{
std::string s;
- std::getline(ifstr, s);
- assert(s == std::string("bifiltration"));
+ // read axes names
std::getline(ifstr, parameter_1_name_);
std::getline(ifstr, parameter_2_name_);
Index index = 0;
while(std::getline(ifstr, s)) {
- if (not ignore_line(s))
+ if (!ignore_line(s)) {
simplices_.emplace_back(index++, s, BifiltrationFormat::rivet);
+ }
}
+
+
}
void Bifiltration::phat_like_format_reader(std::ifstream& ifstr)
@@ -70,11 +92,17 @@ namespace md {
// read stream line by line; do not use >> operator
std::string s;
std::getline(ifstr, s);
+
+ // first line contains number of simplices
long n_simplices = std::stol(s);
- for(Index index = 0; index < n_simplices; index++) {
+ // all other lines represent a simplex
+ Index index = 0;
+ while(index < n_simplices) {
std::getline(ifstr, s);
- simplices_.emplace_back(index, s, BifiltrationFormat::phat_like);
+ if (!ignore_line(s)) {
+ simplices_.emplace_back(index++, s, BifiltrationFormat::phat_like);
+ }
}
spd::debug("Read {} simplices from file", n_simplices);
}