Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arbor
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
arbor-sim
arbor
Commits
41972a06
Commit
41972a06
authored
Apr 18, 2016
by
Vasileios Karakasis
Browse files
Options
Downloads
Patches
Plain Diff
Reject SWC input if branches are not contiguously numbered.
parent
d04de96a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/algorithms.hpp
+1
-0
1 addition, 0 deletions
src/algorithms.hpp
src/swcio.cpp
+20
-9
20 additions, 9 deletions
src/swcio.cpp
with
21 additions
and
9 deletions
src/algorithms.hpp
+
1
−
0
View file @
41972a06
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/swcio.cpp
+
20
−
9
View file @
41972a06
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment