Skip to content
Snippets Groups Projects
Commit 41972a06 authored by Vasileios Karakasis's avatar Vasileios Karakasis
Browse files

Reject SWC input if branches are not contiguously numbered.

parent d04de96a
Branches
Tags
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
#include <type_traits> #include <type_traits>
#include <vector>
/* /*
* Some simple wrappers around stl algorithms to improve readability of code * Some simple wrappers around stl algorithms to improve readability of code
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <sstream> #include <sstream>
#include <unordered_set> #include <unordered_set>
#include <algorithms.hpp>
#include <swcio.hpp> #include <swcio.hpp>
namespace nest { namespace nest {
...@@ -183,21 +184,21 @@ swc_record_range_clean::swc_record_range_clean(std::istream &is) ...@@ -183,21 +184,21 @@ swc_record_range_clean::swc_record_range_clean(std::istream &is)
bool needsort = false; bool needsort = false;
swc_record curr_record; swc_record curr_record;
for (auto c : swc_get_records<swc_io_raw>(is)) { for (auto r : swc_get_records<swc_io_raw>(is)) {
if (c.parent() == -1 && ++num_trees > 1) { if (r.parent() == -1 && ++num_trees > 1) {
// only a single tree is allowed // only a single tree is allowed
break; break;
} }
auto inserted = ids.insert(c.id()); auto inserted = ids.insert(r.id());
if (inserted.second) { if (inserted.second) {
// not a duplicate; insert record // not a duplicate; insert record
records_.push_back(c); records_.push_back(r);
if (!needsort && c.id() < last_id) { if (!needsort && r.id() < last_id) {
needsort = true; needsort = true;
} }
last_id = c.id(); last_id = r.id();
} }
} }
...@@ -208,13 +209,23 @@ swc_record_range_clean::swc_record_range_clean(std::istream &is) ...@@ -208,13 +209,23 @@ swc_record_range_clean::swc_record_range_clean(std::istream &is)
// Renumber records if necessary // Renumber records if necessary
std::map<swc_record::id_type, swc_record::id_type> idmap; std::map<swc_record::id_type, swc_record::id_type> idmap;
swc_record::id_type next_id = 0; swc_record::id_type next_id = 0;
for (auto &c : records_) { for (auto &r : records_) {
if (c.id() != next_id) { if (r.id() != next_id) {
c.renumber(next_id, idmap); r.renumber(next_id, idmap);
} }
++next_id; ++next_id;
} }
// Reject if branches are not contiguously numbered
std::vector<swc_record::id_type> parent_list = { 0 };
for (std::size_t i = 1; i < records_.size(); ++i) {
parent_list.push_back(records_[i].parent());
}
if (!nest::mc::algorithms::is_contiguously_numbered(parent_list)) {
throw swc_parse_error("branches are not contiguously numbered", 0);
}
} }
} // namespace io } // namespace io
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment