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
Analyze
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
arbor-sim
arbor
Commits
9713ea1a
Commit
9713ea1a
authored
9 years ago
by
Vasileios Karakasis
Browse files
Options
Downloads
Patches
Plain Diff
Renamed cell_record to swc_record.
Fixes issue #8.
parent
223078a3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/swcio.cpp
+37
-37
37 additions, 37 deletions
src/swcio.cpp
src/swcio.hpp
+64
-64
64 additions, 64 deletions
src/swcio.hpp
tests/test_swcio.cpp
+81
-81
81 additions, 81 deletions
tests/test_swcio.cpp
with
182 additions
and
182 deletions
src/swcio.cpp
+
37
−
37
View file @
9713ea1a
...
...
@@ -12,9 +12,9 @@ namespace io
{
//
//
cell
_record implementation
//
swc
_record implementation
//
void
cell
_record
::
renumber
(
id_type
new_id
,
std
::
map
<
id_type
,
id_type
>
&
idmap
)
void
swc
_record
::
renumber
(
id_type
new_id
,
std
::
map
<
id_type
,
id_type
>
&
idmap
)
{
auto
old_id
=
id_
;
id_
=
new_id
;
...
...
@@ -29,12 +29,12 @@ void cell_record::renumber(id_type new_id, std::map<id_type, id_type> &idmap)
idmap
.
insert
(
std
::
make_pair
(
old_id
,
new_id
));
}
void
cell
_record
::
check_consistency
()
const
void
swc
_record
::
check_consistency
()
const
{
// Check
cell
type as well; enum's do not offer complete type safety,
// Check
record
type as well; enum's do not offer complete type safety,
// since you can cast anything that fits to its underlying type
if
(
type_
<
0
||
type_
>
custom
)
{
throw
std
::
invalid_argument
(
"unknown
cell
type"
);
throw
std
::
invalid_argument
(
"unknown
record
type"
);
}
if
(
id_
<
0
)
{
...
...
@@ -54,24 +54,24 @@ void cell_record::check_consistency() const
}
}
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
cell
_record
&
cell
)
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
swc
_record
&
record
)
{
swc_parser
parser
;
parser
.
parse_record
(
is
,
cell
);
parser
.
parse_record
(
is
,
record
);
return
is
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
cell
_record
&
cell
)
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
swc
_record
&
record
)
{
// output in one-based indexing
os
<<
cell
.
id_
+
1
<<
" "
<<
cell
.
type_
<<
" "
<<
std
::
setprecision
(
7
)
<<
cell
.
x_
<<
" "
<<
std
::
setprecision
(
7
)
<<
cell
.
y_
<<
" "
<<
std
::
setprecision
(
7
)
<<
cell
.
z_
<<
" "
<<
std
::
setprecision
(
7
)
<<
cell
.
r_
<<
" "
<<
((
cell
.
parent_id_
==
-
1
)
?
cell
.
parent_id_
:
cell
.
parent_id_
+
1
);
os
<<
record
.
id_
+
1
<<
" "
<<
record
.
type_
<<
" "
<<
std
::
setprecision
(
7
)
<<
record
.
x_
<<
" "
<<
std
::
setprecision
(
7
)
<<
record
.
y_
<<
" "
<<
std
::
setprecision
(
7
)
<<
record
.
z_
<<
" "
<<
std
::
setprecision
(
7
)
<<
record
.
r_
<<
" "
<<
((
record
.
parent_id_
==
-
1
)
?
record
.
parent_id_
:
record
.
parent_id_
+
1
);
return
os
;
}
...
...
@@ -104,22 +104,22 @@ T parse_value_strict(std::istream &is, const swc_parser &parser)
return
val
;
}
// specialize parsing for
cell
types
// specialize parsing for
record
types
template
<
>
cell
_record
::
kind
parse_value_strict
(
std
::
istream
&
is
,
const
swc_parser
&
parser
)
swc
_record
::
kind
parse_value_strict
(
std
::
istream
&
is
,
const
swc_parser
&
parser
)
{
cell
_record
::
id_type
val
;
swc
_record
::
id_type
val
;
check_parse_status
(
is
>>
val
,
parser
);
// Let
cell
_record's constructor check for the type validity
return
static_cast
<
cell
_record
::
kind
>
(
val
);
// Let
swc
_record's constructor check for the type validity
return
static_cast
<
swc
_record
::
kind
>
(
val
);
}
//
// swc_parser implementation
//
std
::
istream
&
swc_parser
::
parse_record
(
std
::
istream
&
is
,
cell
_record
&
cell
)
std
::
istream
&
swc_parser
::
parse_record
(
std
::
istream
&
is
,
swc
_record
&
record
)
{
while
(
!
is
.
eof
()
&&
!
is
.
bad
())
{
// consume empty and comment lines first
...
...
@@ -146,7 +146,7 @@ std::istream &swc_parser::parse_record(std::istream &is, cell_record &cell)
std
::
istringstream
line
(
linebuff_
);
try
{
cell
=
parse_record
(
line
);
record
=
parse_record
(
line
);
}
catch
(
std
::
invalid_argument
&
e
)
{
// Rethrow as a parse error
throw
swc_parse_error
(
e
.
what
(),
lineno_
);
...
...
@@ -155,34 +155,34 @@ std::istream &swc_parser::parse_record(std::istream &is, cell_record &cell)
return
is
;
}
cell
_record
swc_parser
::
parse_record
(
std
::
istringstream
&
is
)
swc
_record
swc_parser
::
parse_record
(
std
::
istringstream
&
is
)
{
auto
id
=
parse_value_strict
<
int
>
(
is
,
*
this
);
auto
type
=
parse_value_strict
<
cell
_record
::
kind
>
(
is
,
*
this
);
auto
type
=
parse_value_strict
<
swc
_record
::
kind
>
(
is
,
*
this
);
auto
x
=
parse_value_strict
<
float
>
(
is
,
*
this
);
auto
y
=
parse_value_strict
<
float
>
(
is
,
*
this
);
auto
z
=
parse_value_strict
<
float
>
(
is
,
*
this
);
auto
r
=
parse_value_strict
<
float
>
(
is
,
*
this
);
auto
parent_id
=
parse_value_strict
<
cell
_record
::
id_type
>
(
is
,
*
this
);
auto
parent_id
=
parse_value_strict
<
swc
_record
::
id_type
>
(
is
,
*
this
);
// Convert to zero-based, leaving parent_id as-is if -1
if
(
parent_id
!=
-
1
)
{
parent_id
--
;
}
return
cell
_record
(
type
,
id
-
1
,
x
,
y
,
z
,
r
,
parent_id
);
return
swc
_record
(
type
,
id
-
1
,
x
,
y
,
z
,
r
,
parent_id
);
}
cell
_record_range_clean
::
cell
_record_range_clean
(
std
::
istream
&
is
)
swc
_record_range_clean
::
swc
_record_range_clean
(
std
::
istream
&
is
)
{
std
::
unordered_set
<
cell
_record
::
id_type
>
ids
;
std
::
unordered_set
<
swc
_record
::
id_type
>
ids
;
std
::
size_t
num_trees
=
0
;
cell
_record
::
id_type
last_id
=
-
1
;
swc
_record
::
id_type
last_id
=
-
1
;
bool
needsort
=
false
;
cell
_record
curr_
cell
;
swc
_record
curr_
record
;
for
(
auto
c
:
swc_get_records
<
swc_io_raw
>
(
is
))
{
if
(
c
.
parent
()
==
-
1
&&
++
num_trees
>
1
)
{
// only a single tree is allowed
...
...
@@ -191,8 +191,8 @@ cell_record_range_clean::cell_record_range_clean(std::istream &is)
auto
inserted
=
ids
.
insert
(
c
.
id
());
if
(
inserted
.
second
)
{
// not a duplicate; insert
cell
cell
s_
.
push_back
(
c
);
// not a duplicate; insert
record
record
s_
.
push_back
(
c
);
if
(
!
needsort
&&
c
.
id
()
<
last_id
)
{
needsort
=
true
;
}
...
...
@@ -202,13 +202,13 @@ cell_record_range_clean::cell_record_range_clean(std::istream &is)
}
if
(
needsort
)
{
std
::
sort
(
cell
s_
.
begin
(),
cell
s_
.
end
());
std
::
sort
(
record
s_
.
begin
(),
record
s_
.
end
());
}
// Renumber
cell
s if necessary
std
::
map
<
cell
_record
::
id_type
,
cell
_record
::
id_type
>
idmap
;
cell
_record
::
id_type
next_id
=
0
;
for
(
auto
&
c
:
cell
s_
)
{
// Renumber
record
s if necessary
std
::
map
<
swc
_record
::
id_type
,
swc
_record
::
id_type
>
idmap
;
swc
_record
::
id_type
next_id
=
0
;
for
(
auto
&
c
:
record
s_
)
{
if
(
c
.
id
()
!=
next_id
)
{
c
.
renumber
(
next_id
,
idmap
);
}
...
...
This diff is collapsed.
Click to expand it.
src/swcio.hpp
+
64
−
64
View file @
9713ea1a
...
...
@@ -13,7 +13,7 @@ namespace io
{
class
cell
_record
class
swc
_record
{
public:
using
id_type
=
int
;
...
...
@@ -33,8 +33,8 @@ public:
custom
};
//
cell
records assume zero-based indexing; root's parent remains -1
cell
_record
(
kind
type
,
int
id
,
//
swc
records assume zero-based indexing; root's parent remains -1
swc
_record
(
kind
type
,
int
id
,
float
x
,
float
y
,
float
z
,
float
r
,
int
parent_id
)
:
type_
(
type
)
...
...
@@ -48,8 +48,8 @@ public:
check_consistency
();
}
cell
_record
()
:
type_
(
cell
_record
::
undefined
)
swc
_record
()
:
type_
(
swc
_record
::
undefined
)
,
id_
(
0
)
,
x_
(
0
)
,
y_
(
0
)
...
...
@@ -58,10 +58,10 @@ public:
,
parent_id_
(
-
1
)
{
}
cell
_record
(
const
cell
_record
&
other
)
=
default
;
cell
_record
&
operator
=
(
const
cell
_record
&
other
)
=
default
;
swc
_record
(
const
swc
_record
&
other
)
=
default
;
swc
_record
&
operator
=
(
const
swc
_record
&
other
)
=
default
;
bool
strict_equals
(
const
cell
_record
&
other
)
const
bool
strict_equals
(
const
swc
_record
&
other
)
const
{
return
id_
==
other
.
id_
&&
x_
==
other
.
x_
&&
...
...
@@ -72,43 +72,43 @@ public:
}
// Equality and comparison operators
friend
bool
operator
==
(
const
cell
_record
&
lhs
,
const
cell
_record
&
rhs
)
friend
bool
operator
==
(
const
swc
_record
&
lhs
,
const
swc
_record
&
rhs
)
{
return
lhs
.
id_
==
rhs
.
id_
;
}
friend
bool
operator
<
(
const
cell
_record
&
lhs
,
const
cell
_record
&
rhs
)
friend
bool
operator
<
(
const
swc
_record
&
lhs
,
const
swc
_record
&
rhs
)
{
return
lhs
.
id_
<
rhs
.
id_
;
}
friend
bool
operator
<=
(
const
cell
_record
&
lhs
,
const
cell
_record
&
rhs
)
friend
bool
operator
<=
(
const
swc
_record
&
lhs
,
const
swc
_record
&
rhs
)
{
return
(
lhs
<
rhs
)
||
(
lhs
==
rhs
);
}
friend
bool
operator
!=
(
const
cell
_record
&
lhs
,
const
cell
_record
&
rhs
)
friend
bool
operator
!=
(
const
swc
_record
&
lhs
,
const
swc
_record
&
rhs
)
{
return
!
(
lhs
==
rhs
);
}
friend
bool
operator
>
(
const
cell
_record
&
lhs
,
const
cell
_record
&
rhs
)
friend
bool
operator
>
(
const
swc
_record
&
lhs
,
const
swc
_record
&
rhs
)
{
return
!
(
lhs
<
rhs
)
&&
(
lhs
!=
rhs
);
}
friend
bool
operator
>=
(
const
cell
_record
&
lhs
,
const
cell
_record
&
rhs
)
friend
bool
operator
>=
(
const
swc
_record
&
lhs
,
const
swc
_record
&
rhs
)
{
return
!
(
lhs
<
rhs
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
cell
_record
&
cell
);
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
swc
_record
&
record
);
kind
type
()
const
{
...
...
@@ -155,11 +155,11 @@ public:
private
:
void
check_consistency
()
const
;
kind
type_
;
//
cell
type
id_type
id_
;
//
cell
id
float
x_
,
y_
,
z_
;
//
cell
coordinates
float
r_
;
//
cell
radius
id_type
parent_id_
;
//
cell
parent's id
kind
type_
;
//
record
type
id_type
id_
;
//
record
id
float
x_
,
y_
,
z_
;
//
record
coordinates
float
r_
;
//
record
radius
id_type
parent_id_
;
//
record
parent's id
};
...
...
@@ -206,11 +206,11 @@ public:
return
lineno_
;
}
std
::
istream
&
parse_record
(
std
::
istream
&
is
,
cell
_record
&
cell
);
std
::
istream
&
parse_record
(
std
::
istream
&
is
,
swc
_record
&
record
);
private
:
// Read the record from a string stream; will be treated like a single line
cell
_record
parse_record
(
std
::
istringstream
&
is
);
swc
_record
parse_record
(
std
::
istringstream
&
is
);
std
::
string
delim_
;
std
::
string
comment_prefix_
;
...
...
@@ -219,15 +219,15 @@ private:
};
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
cell
_record
&
cell
);
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
swc
_record
&
record
);
class
cell
_record_stream_iterator
:
public
std
::
iterator
<
std
::
forward_iterator_tag
,
cell
_record
>
class
swc
_record_stream_iterator
:
public
std
::
iterator
<
std
::
forward_iterator_tag
,
swc
_record
>
{
public:
struct
eof_tag
{
};
cell
_record_stream_iterator
(
std
::
istream
&
is
)
swc
_record_stream_iterator
(
std
::
istream
&
is
)
:
is_
(
is
)
,
eof_
(
false
)
{
...
...
@@ -236,19 +236,19 @@ public:
read_next_record
();
}
cell
_record_stream_iterator
(
std
::
istream
&
is
,
eof_tag
)
swc
_record_stream_iterator
(
std
::
istream
&
is
,
eof_tag
)
:
is_
(
is
)
,
eof_
(
true
)
{
}
cell
_record_stream_iterator
(
const
cell
_record_stream_iterator
&
other
)
swc
_record_stream_iterator
(
const
swc
_record_stream_iterator
&
other
)
:
is_
(
other
.
is_
)
,
parser_
(
other
.
parser_
)
,
curr_record_
(
other
.
curr_record_
)
,
eof_
(
other
.
eof_
)
{
}
cell
_record_stream_iterator
&
operator
++
()
swc
_record_stream_iterator
&
operator
++
()
{
if
(
eof_
)
{
throw
std
::
out_of_range
(
"attempt to read past eof"
);
...
...
@@ -258,9 +258,9 @@ public:
return
*
this
;
}
cell
_record_stream_iterator
operator
++
(
int
)
swc
_record_stream_iterator
operator
++
(
int
)
{
cell
_record_stream_iterator
ret
(
*
this
);
swc
_record_stream_iterator
ret
(
*
this
);
operator
++
();
return
ret
;
}
...
...
@@ -274,7 +274,7 @@ public:
return
curr_record_
;
}
bool
operator
==
(
const
cell
_record_stream_iterator
&
other
)
const
bool
operator
==
(
const
swc
_record_stream_iterator
&
other
)
const
{
if
(
eof_
&&
other
.
eof_
)
{
return
true
;
...
...
@@ -283,13 +283,13 @@ public:
}
}
bool
operator
!=
(
const
cell
_record_stream_iterator
&
other
)
const
bool
operator
!=
(
const
swc
_record_stream_iterator
&
other
)
const
{
return
!
(
*
this
==
other
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
cell
_record_stream_iterator
&
iter
)
const
swc
_record_stream_iterator
&
iter
)
{
os
<<
"{ is_.tellg(): "
<<
iter
.
is_
.
tellg
()
<<
", "
<<
"curr_record_: "
<<
iter
.
curr_record_
<<
", "
...
...
@@ -309,7 +309,7 @@ private:
std
::
istream
&
is_
;
swc_parser
parser_
;
cell
_record
curr_record_
;
swc
_record
curr_record_
;
// indicator of eof; we need a way to define an end() iterator without
// seeking to the end of file
...
...
@@ -317,28 +317,28 @@ private:
};
class
cell
_record_range_raw
class
swc
_record_range_raw
{
public:
using
value_type
=
cell
_record
;
using
value_type
=
swc
_record
;
using
reference
=
value_type
&
;
using
const_reference
=
const
value_type
&
;
using
iterator
=
cell
_record_stream_iterator
;
using
const_iterator
=
const
cell
_record_stream_iterator
;
using
iterator
=
swc
_record_stream_iterator
;
using
const_iterator
=
const
swc
_record_stream_iterator
;
cell
_record_range_raw
(
std
::
istream
&
is
)
swc
_record_range_raw
(
std
::
istream
&
is
)
:
is_
(
is
)
{
}
iterator
begin
()
const
{
return
cell
_record_stream_iterator
(
is_
);
return
swc
_record_stream_iterator
(
is_
);
}
iterator
end
()
const
{
iterator
::
eof_tag
eof
;
return
cell
_record_stream_iterator
(
is_
,
eof
);
return
swc
_record_stream_iterator
(
is_
,
eof
);
}
bool
empty
()
const
...
...
@@ -351,62 +351,62 @@ private:
};
//
// Reads
cell
s from an input stream until an eof is encountered and returns a
// cleaned sequence of
cell
records.
// Reads
record
s from an input stream until an eof is encountered and returns a
// cleaned sequence of
swc
records.
//
// For more information check here:
// https://github.com/eth-cscs/cell_algorithms/wiki/SWC-file-parsing
//
class
cell
_record_range_clean
class
swc
_record_range_clean
{
public:
using
value_type
=
cell
_record
;
using
value_type
=
swc
_record
;
using
reference
=
value_type
&
;
using
const_referene
=
const
value_type
&
;
using
iterator
=
std
::
vector
<
cell
_record
>::
iterator
;
using
const_iterator
=
std
::
vector
<
cell
_record
>::
const_iterator
;
using
iterator
=
std
::
vector
<
swc
_record
>::
iterator
;
using
const_iterator
=
std
::
vector
<
swc
_record
>::
const_iterator
;
cell
_record_range_clean
(
std
::
istream
&
is
);
swc
_record_range_clean
(
std
::
istream
&
is
);
iterator
begin
()
{
return
cell
s_
.
begin
();
return
record
s_
.
begin
();
}
iterator
end
()
{
return
cell
s_
.
end
();
return
record
s_
.
end
();
}
std
::
size_t
size
()
{
return
cell
s_
.
size
();
return
record
s_
.
size
();
}
bool
empty
()
const
{
return
cell
s_
.
empty
();
return
record
s_
.
empty
();
}
private
:
std
::
vector
<
cell
_record
>
cell
s_
;
std
::
vector
<
swc
_record
>
record
s_
;
};
struct
swc_io_raw
{
using
cell
_range_type
=
cell
_record_range_raw
;
using
record
_range_type
=
swc
_record_range_raw
;
};
struct
swc_io_clean
{
using
cell
_range_type
=
cell
_record_range_clean
;
using
record
_range_type
=
swc
_record_range_clean
;
};
template
<
typename
T
=
swc_io_clean
>
typename
T
::
cell
_range_type
swc_get_records
(
std
::
istream
&
is
)
typename
T
::
record
_range_type
swc_get_records
(
std
::
istream
&
is
)
{
return
typename
T
::
cell
_range_type
(
is
);
return
typename
T
::
record
_range_type
(
is
);
}
}
// end of nestmc::io
...
...
This diff is collapsed.
Click to expand it.
tests/test_swcio.cpp
+
81
−
81
View file @
9713ea1a
...
...
@@ -10,8 +10,8 @@
#include
<swcio.hpp>
// SWC tests
void
expect_
cell
_equals
(
const
nestmc
::
io
::
cell
_record
&
expected
,
const
nestmc
::
io
::
cell
_record
&
actual
)
void
expect_
record
_equals
(
const
nestmc
::
io
::
swc
_record
&
expected
,
const
nestmc
::
io
::
swc
_record
&
actual
)
{
EXPECT_EQ
(
expected
.
id
(),
actual
.
id
());
EXPECT_EQ
(
expected
.
type
(),
actual
.
type
());
...
...
@@ -22,85 +22,85 @@ void expect_cell_equals(const nestmc::io::cell_record &expected,
EXPECT_EQ
(
expected
.
parent
(),
actual
.
parent
());
}
TEST
(
cell
_record
,
construction
)
TEST
(
swc
_record
,
construction
)
{
using
namespace
nestmc
::
io
;
{
// force an invalid type
cell
_record
::
kind
invalid_type
=
static_cast
<
cell
_record
::
kind
>
(
100
);
EXPECT_THROW
(
cell
_record
cell
(
invalid_type
,
7
,
1.
,
1.
,
1.
,
1.
,
5
),
swc
_record
::
kind
invalid_type
=
static_cast
<
swc
_record
::
kind
>
(
100
);
EXPECT_THROW
(
swc
_record
record
(
invalid_type
,
7
,
1.
,
1.
,
1.
,
1.
,
5
),
std
::
invalid_argument
);
}
{
// invalid id
EXPECT_THROW
(
cell
_record
cell
(
cell
_record
::
custom
,
-
3
,
1.
,
1.
,
1.
,
1.
,
5
),
EXPECT_THROW
(
swc
_record
record
(
swc
_record
::
custom
,
-
3
,
1.
,
1.
,
1.
,
1.
,
5
),
std
::
invalid_argument
);
}
{
// invalid parent id
EXPECT_THROW
(
cell
_record
cell
(
cell
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
-
5
),
EXPECT_THROW
(
swc
_record
record
(
swc
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
-
5
),
std
::
invalid_argument
);
}
{
// invalid radius
EXPECT_THROW
(
cell
_record
cell
(
cell
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
-
1.
,
-
1
),
EXPECT_THROW
(
swc
_record
record
(
swc
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
-
1.
,
-
1
),
std
::
invalid_argument
);
}
{
// parent_id > id
EXPECT_THROW
(
cell
_record
cell
(
cell
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
2
),
EXPECT_THROW
(
swc
_record
record
(
swc
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
2
),
std
::
invalid_argument
);
}
{
// parent_id == id
EXPECT_THROW
(
cell
_record
cell
(
cell
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
0
),
EXPECT_THROW
(
swc
_record
record
(
swc
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
0
),
std
::
invalid_argument
);
}
{
// check standard construction by value
cell
_record
cell
(
cell
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
-
1
);
EXPECT_EQ
(
cell
.
id
(),
0
);
EXPECT_EQ
(
cell
.
type
(),
cell
_record
::
custom
);
EXPECT_EQ
(
cell
.
x
(),
1.
);
EXPECT_EQ
(
cell
.
y
(),
1.
);
EXPECT_EQ
(
cell
.
z
(),
1.
);
EXPECT_EQ
(
cell
.
radius
(),
1.
);
EXPECT_EQ
(
cell
.
diameter
(),
2
*
1.
);
EXPECT_EQ
(
cell
.
parent
(),
-
1
);
swc
_record
record
(
swc
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
-
1
);
EXPECT_EQ
(
record
.
id
(),
0
);
EXPECT_EQ
(
record
.
type
(),
swc
_record
::
custom
);
EXPECT_EQ
(
record
.
x
(),
1.
);
EXPECT_EQ
(
record
.
y
(),
1.
);
EXPECT_EQ
(
record
.
z
(),
1.
);
EXPECT_EQ
(
record
.
radius
(),
1.
);
EXPECT_EQ
(
record
.
diameter
(),
2
*
1.
);
EXPECT_EQ
(
record
.
parent
(),
-
1
);
}
{
// check copy constructor
cell
_record
cell
_orig
(
cell
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
-
1
);
cell
_record
cell
(
cell
_orig
);
expect_
cell
_equals
(
cell
_orig
,
cell
);
swc
_record
record
_orig
(
swc
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
-
1
);
swc
_record
record
(
record
_orig
);
expect_
record
_equals
(
record
_orig
,
record
);
}
}
TEST
(
cell
_record
,
comparison
)
TEST
(
swc
_record
,
comparison
)
{
using
namespace
nestmc
::
io
;
{
// check comparison operators
cell
_record
cell0
(
cell
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
-
1
);
cell
_record
cell1
(
cell
_record
::
custom
,
0
,
2.
,
3.
,
4.
,
5.
,
-
1
);
cell
_record
cell2
(
cell
_record
::
custom
,
1
,
2.
,
3.
,
4.
,
5.
,
-
1
);
EXPECT_EQ
(
cell0
,
cell
1
);
EXPECT_LT
(
cell0
,
cell
2
);
EXPECT_GT
(
cell2
,
cell
1
);
swc
_record
record0
(
swc
_record
::
custom
,
0
,
1.
,
1.
,
1.
,
1.
,
-
1
);
swc
_record
record1
(
swc
_record
::
custom
,
0
,
2.
,
3.
,
4.
,
5.
,
-
1
);
swc
_record
record2
(
swc
_record
::
custom
,
1
,
2.
,
3.
,
4.
,
5.
,
-
1
);
EXPECT_EQ
(
record0
,
record
1
);
EXPECT_LT
(
record0
,
record
2
);
EXPECT_GT
(
record2
,
record
1
);
}
}
...
...
@@ -112,24 +112,24 @@ TEST(swc_parser, invalid_input)
{
// check incomplete lines; missing parent
std
::
istringstream
is
(
"1 1 14.566132 34.873772 7.857000 0.717830
\n
"
);
cell
_record
cell
;
EXPECT_THROW
(
is
>>
cell
,
swc_parse_error
);
swc
_record
record
;
EXPECT_THROW
(
is
>>
record
,
swc_parse_error
);
}
{
// Check non-parsable values
std
::
istringstream
is
(
"1a 1 14.566132 34.873772 7.857000 0.717830 -1
\n
"
);
cell
_record
cell
;
EXPECT_THROW
(
is
>>
cell
,
swc_parse_error
);
swc
_record
record
;
EXPECT_THROW
(
is
>>
record
,
swc_parse_error
);
}
{
// Check invalid
cell
type
// Check invalid
record
type
std
::
istringstream
is
(
"1 10 14.566132 34.873772 7.857000 0.717830 -1
\n
"
);
cell
_record
cell
;
EXPECT_THROW
(
is
>>
cell
,
swc_parse_error
);
swc
_record
record
;
EXPECT_THROW
(
is
>>
record
,
swc_parse_error
);
}
}
...
...
@@ -139,58 +139,58 @@ TEST(swc_parser, valid_input)
using
namespace
nestmc
::
io
;
{
// check empty file; no
cell
may be parsed
cell
_record
cell
,
cell
_orig
;
// check empty file; no
record
may be parsed
swc
_record
record
,
record
_orig
;
std
::
istringstream
is
(
""
);
EXPECT_NO_THROW
(
is
>>
cell
);
expect_
cell
_equals
(
cell
_orig
,
cell
);
EXPECT_NO_THROW
(
is
>>
record
);
expect_
record
_equals
(
record
_orig
,
record
);
}
{
// check comment-only file not ending with a newline;
// no
cell
may be parsed
cell
_record
cell
,
cell
_orig
;
// no
record
may be parsed
swc
_record
record
,
record
_orig
;
std
::
istringstream
is
(
"#comment
\n
#comment"
);
EXPECT_NO_THROW
(
is
>>
cell
);
expect_
cell
_equals
(
cell
_orig
,
cell
);
EXPECT_NO_THROW
(
is
>>
record
);
expect_
record
_equals
(
record
_orig
,
record
);
}
{
// check last line case (no newline at the end)
std
::
istringstream
is
(
"1 1 14.566132 34.873772 7.857000 0.717830 -1"
);
cell
_record
cell
;
EXPECT_NO_THROW
(
is
>>
cell
);
EXPECT_EQ
(
0
,
cell
.
id
());
// zero-based indexing
EXPECT_EQ
(
cell
_record
::
soma
,
cell
.
type
());
EXPECT_FLOAT_EQ
(
14.566132
,
cell
.
x
());
EXPECT_FLOAT_EQ
(
34.873772
,
cell
.
y
());
EXPECT_FLOAT_EQ
(
7.857000
,
cell
.
z
());
EXPECT_FLOAT_EQ
(
0.717830
,
cell
.
radius
());
EXPECT_FLOAT_EQ
(
-
1
,
cell
.
parent
());
swc
_record
record
;
EXPECT_NO_THROW
(
is
>>
record
);
EXPECT_EQ
(
0
,
record
.
id
());
// zero-based indexing
EXPECT_EQ
(
swc
_record
::
soma
,
record
.
type
());
EXPECT_FLOAT_EQ
(
14.566132
,
record
.
x
());
EXPECT_FLOAT_EQ
(
34.873772
,
record
.
y
());
EXPECT_FLOAT_EQ
(
7.857000
,
record
.
z
());
EXPECT_FLOAT_EQ
(
0.717830
,
record
.
radius
());
EXPECT_FLOAT_EQ
(
-
1
,
record
.
parent
());
}
{
// check valid input with a series of records
std
::
vector
<
cell
_record
>
cell
s_orig
=
{
cell
_record
(
cell
_record
::
soma
,
0
,
std
::
vector
<
swc
_record
>
record
s_orig
=
{
swc
_record
(
swc
_record
::
soma
,
0
,
14.566132
,
34.873772
,
7.857000
,
0.717830
,
-
1
),
cell
_record
(
cell
_record
::
dendrite
,
1
,
swc
_record
(
swc
_record
::
dendrite
,
1
,
14.566132
+
1
,
34.873772
+
1
,
7.857000
+
1
,
0.717830
+
1
,
-
1
)
};
std
::
stringstream
swc_input
;
swc_input
<<
"# this is a comment
\n
"
;
swc_input
<<
"# this is a comment
\n
"
;
for
(
auto
c
:
cell
s_orig
)
for
(
auto
c
:
record
s_orig
)
swc_input
<<
c
<<
"
\n
"
;
swc_input
<<
"# this is a final comment
\n
"
;
std
::
size_t
nr_records
=
0
;
for
(
auto
cell
:
swc_get_records
<
swc_io_raw
>
(
swc_input
))
{
ASSERT_LT
(
nr_records
,
cell
s_orig
.
size
());
expect_
cell
_equals
(
cell
s_orig
[
nr_records
],
cell
);
for
(
auto
record
:
swc_get_records
<
swc_io_raw
>
(
swc_input
))
{
ASSERT_LT
(
nr_records
,
record
s_orig
.
size
());
expect_
record
_equals
(
record
s_orig
[
nr_records
],
record
);
++
nr_records
;
}
}
...
...
@@ -207,8 +207,8 @@ TEST(swc_parser, from_allen_db)
return
;
}
// load the
cell
records into a std::vector
std
::
vector
<
io
::
cell
_record
>
nodes
;
// load the
record
records into a std::vector
std
::
vector
<
io
::
swc
_record
>
nodes
;
for
(
auto
node
:
io
::
swc_get_records
<
io
::
swc_io_raw
>
(
fid
))
{
nodes
.
push_back
(
std
::
move
(
node
));
}
...
...
@@ -240,8 +240,8 @@ TEST(swc_parser, input_cleaning)
is
<<
"3 1 14.566132 34.873772 7.857000 0.717830 -1
\n
"
;
is
<<
"4 1 14.566132 34.873772 7.857000 0.717830 1
\n
"
;
auto
cell
s
=
swc_get_records
(
is
);
EXPECT_EQ
(
2u
,
cell
s
.
size
());
auto
record
s
=
swc_get_records
(
is
);
EXPECT_EQ
(
2u
,
record
s
.
size
());
}
{
...
...
@@ -252,7 +252,7 @@ TEST(swc_parser, input_cleaning)
is
<<
"4 1 14.566132 34.873772 7.857000 0.717830 1
\n
"
;
is
<<
"1 1 14.566132 34.873772 7.857000 0.717830 -1
\n
"
;
std
::
array
<
cell
_record
::
id_type
,
4
>
expected_id_list
=
{{
0
,
1
,
2
,
3
}};
std
::
array
<
swc
_record
::
id_type
,
4
>
expected_id_list
=
{{
0
,
1
,
2
,
3
}};
auto
expected_id
=
expected_id_list
.
cbegin
();
for
(
auto
c
:
swc_get_records
(
is
))
{
...
...
@@ -274,9 +274,9 @@ TEST(swc_parser, input_cleaning)
is
<<
"51 1 14.566132 34.873772 7.857000 0.717830 1
\n
"
;
is
<<
"61 1 14.566132 34.873772 7.857000 0.717830 51
\n
"
;
std
::
array
<
cell
_record
::
id_type
,
6
>
expected_id_list
=
std
::
array
<
swc
_record
::
id_type
,
6
>
expected_id_list
=
{{
0
,
1
,
2
,
3
,
4
,
5
}};
std
::
array
<
cell
_record
::
id_type
,
6
>
expected_parent_list
=
std
::
array
<
swc
_record
::
id_type
,
6
>
expected_parent_list
=
{{
-
1
,
0
,
1
,
1
,
0
,
4
}};
auto
expected_id
=
expected_id_list
.
cbegin
();
...
...
@@ -294,7 +294,7 @@ TEST(swc_parser, input_cleaning)
}
}
TEST
(
cell
_record_ranges
,
raw
)
TEST
(
swc
_record_ranges
,
raw
)
{
using
namespace
nestmc
::
io
;
...
...
@@ -306,17 +306,17 @@ TEST(cell_record_ranges, raw)
is
<<
"3 1 14.566132 34.873772 7.857000 0.717830 1
\n
"
;
is
<<
"4 1 14.566132 34.873772 7.857000 0.717830 1
\n
"
;
std
::
vector
<
cell
_record
>
cell
s
;
std
::
vector
<
swc
_record
>
record
s
;
for
(
auto
c
:
swc_get_records
<
swc_io_raw
>
(
is
))
{
cell
s
.
push_back
(
c
);
record
s
.
push_back
(
c
);
}
EXPECT_EQ
(
4u
,
cell
s
.
size
());
EXPECT_EQ
(
4u
,
record
s
.
size
());
bool
entered
=
false
;
auto
citer
=
cell
s
.
begin
();
auto
citer
=
record
s
.
begin
();
for
(
auto
c
:
swc_get_records
<
swc_io_raw
>
(
is
))
{
expect_
cell
_equals
(
c
,
*
citer
++
);
expect_
record
_equals
(
c
,
*
citer
++
);
entered
=
true
;
}
...
...
@@ -343,7 +343,7 @@ TEST(cell_record_ranges, raw)
auto
iter
=
swc_get_records
<
swc_io_raw
>
(
is
).
begin
();
auto
iend
=
swc_get_records
<
swc_io_raw
>
(
is
).
end
();
cell
_record
c
;
swc
_record
c
;
EXPECT_NO_THROW
(
c
=
*
iter
++
);
EXPECT_EQ
(
-
1
,
c
.
parent
());
EXPECT_EQ
(
iend
,
iter
);
...
...
@@ -360,10 +360,10 @@ TEST(cell_record_ranges, raw)
is
<<
"3 10 14.566132 34.873772 7.857000 0.717830 1
\n
"
;
is
<<
"4 1 14.566132 34.873772 7.857000 0.717830 1
\n
"
;
std
::
vector
<
cell
_record
>
cell
s
;
std
::
vector
<
swc
_record
>
record
s
;
try
{
for
(
auto
c
:
swc_get_records
<
swc_io_raw
>
(
is
))
{
cell
s
.
push_back
(
c
);
record
s
.
push_back
(
c
);
}
ADD_FAILURE
()
<<
"expected an exception
\n
"
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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
register
or
sign in
to comment