Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
82285e88
Commit
82285e88
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Updated mesh tests.
parent
075910d3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_gifti.py
+28
-9
28 additions, 9 deletions
tests/test_gifti.py
tests/test_mesh.py
+49
-12
49 additions, 12 deletions
tests/test_mesh.py
with
77 additions
and
21 deletions
tests/test_gifti.py
+
28
−
9
View file @
82285e88
...
...
@@ -28,7 +28,7 @@ def test_GiftiMesh_create():
minbounds
=
np
.
array
([
59.50759888
,
88.43039703
,
72.10890198
])
maxbounds
=
np
.
array
([
77.72619629
,
128.40600586
,
94.82050323
])
minb
,
maxb
=
surf
.
getB
ounds
()
minb
,
maxb
=
surf
.
b
ounds
assert
surf
.
name
==
'
example
'
assert
surf
.
dataSource
==
testfile
...
...
@@ -47,9 +47,9 @@ def test_GiftiMesh_create_loadAll():
with
tempdir
()
as
td
:
vertSets
=
[
op
.
join
(
td
,
'
prefix.1.surf.gii
'
),
op
.
join
(
td
,
'
prefix.2.surf.gii
'
),
op
.
join
(
td
,
'
prefix.3.surf.gii
'
)]
vertSets
=
[
op
.
join
(
td
,
'
prefix.
L.
1.surf.gii
'
),
op
.
join
(
td
,
'
prefix.
L.
2.surf.gii
'
),
op
.
join
(
td
,
'
prefix.
L.
3.surf.gii
'
)]
for
vs
in
vertSets
:
shutil
.
copy
(
testfile
,
vs
)
...
...
@@ -83,6 +83,27 @@ def test_loadGiftiMesh():
gifti
.
loadGiftiSurface
(
bf
)
def
test_loadVertices
():
testdir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
)
testfile
=
op
.
join
(
testdir
,
'
example.surf.gii
'
)
with
tempdir
():
mesh
=
gifti
.
GiftiMesh
(
testfile
)
shutil
.
copy
(
testfile
,
'
example2.surf.gii
'
)
verts
=
mesh
.
vertices
verts2
=
verts
*
2
np
.
savetxt
(
'
verts.txt
'
,
verts2
)
assert
np
.
all
(
np
.
isclose
(
mesh
.
loadVertices
(
'
example2.surf.gii
'
),
verts
))
assert
np
.
all
(
np
.
isclose
(
mesh
.
loadVertices
(
'
verts.txt
'
)
,
verts2
))
def
test_GiftiMesh_loadVertexData
():
testdir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
)
...
...
@@ -100,7 +121,7 @@ def test_GiftiMesh_loadVertexData():
assert
surf
.
loadVertexData
(
txtfile
).
shape
==
(
642
,
1
)
# add from memory
surf
.
addVertexData
(
'
inmemdata
'
,
memdata
)
assert
np
.
all
(
np
.
isclose
(
surf
.
addVertexData
(
'
inmemdata
'
,
memdata
)
,
memdata
.
reshape
(
-
1
,
1
)))
# check cached
assert
surf
.
getVertexData
(
shapefile
)
.
shape
==
(
642
,
1
)
...
...
@@ -197,12 +218,10 @@ def test_relatedFiles():
with
open
(
op
.
join
(
td
,
l
),
'
wt
'
)
as
f
:
f
.
write
(
l
)
with
pytest
.
raises
(
Exception
):
gifti
.
relatedFiles
(
'
nonexistent
'
)
badname
=
op
.
join
(
op
.
join
(
td
,
'
badly-formed-filename
'
))
assert
len
(
gifti
.
relatedFiles
(
badname
))
==
0
assert
len
(
gifti
.
relatedFiles
(
badname
))
==
0
assert
len
(
gifti
.
relatedFiles
(
'
nonexistent
'
))
==
0
lsurfaces
=
[
op
.
join
(
td
,
f
)
for
f
in
lsurfaces
]
rsurfaces
=
[
op
.
join
(
td
,
f
)
for
f
in
rsurfaces
]
...
...
This diff is collapsed.
Click to expand it.
tests/test_mesh.py
+
49
−
12
View file @
82285e88
...
...
@@ -68,8 +68,11 @@ def test_mesh_create():
mesh
=
fslmesh
.
Mesh
(
tris
,
vertices
=
verts
)
print
(
str
(
mesh
))
assert
mesh
.
name
==
'
mesh
'
assert
mesh
.
dataSource
is
None
assert
mesh
.
nvertices
==
8
assert
np
.
all
(
np
.
isclose
(
mesh
.
vertices
,
verts
))
assert
np
.
all
(
np
.
isclose
(
mesh
.
indices
,
tris
))
...
...
@@ -92,13 +95,13 @@ def test_mesh_addVertices():
assert
mesh
.
vertexSets
()
==
[
'
default
'
]
assert
np
.
all
(
np
.
isclose
(
mesh
.
vertices
,
verts
))
mesh
.
addVertices
(
verts2
,
'
twotimes
'
)
assert
np
.
all
(
np
.
isclose
(
mesh
.
addVertices
(
verts2
,
'
twotimes
'
)
,
verts2
))
assert
mesh
.
selectedVertices
()
==
'
twotimes
'
assert
mesh
.
vertexSets
()
==
[
'
default
'
,
'
twotimes
'
]
assert
np
.
all
(
np
.
isclose
(
mesh
.
vertices
,
verts2
))
mesh
.
addVertices
(
verts3
,
'
threetimes
'
,
select
=
False
)
assert
np
.
all
(
np
.
isclose
(
mesh
.
addVertices
(
verts3
,
'
threetimes
'
,
select
=
False
)
,
verts3
))
assert
mesh
.
selectedVertices
()
==
'
twotimes
'
assert
mesh
.
vertexSets
()
==
[
'
default
'
,
'
twotimes
'
,
'
threetimes
'
]
...
...
@@ -109,6 +112,32 @@ def test_mesh_addVertices():
assert
mesh
.
selectedVertices
()
==
'
threetimes
'
assert
np
.
all
(
np
.
isclose
(
mesh
.
vertices
,
verts3
))
with
pytest
.
raises
(
ValueError
):
mesh
.
addVertices
(
verts
[:
-
1
,
:],
'
badverts
'
)
def
test_loadVertices
():
tris
=
np
.
array
(
CUBE_TRIANGLES_CCW
)
verts
=
np
.
array
(
CUBE_VERTICES
)
mesh
=
fslmesh
.
Mesh
(
tris
,
vertices
=
verts
)
with
tempdir
():
verts2
=
verts
*
2
np
.
savetxt
(
'
verts2.txt
'
,
verts2
)
assert
np
.
all
(
np
.
isclose
(
mesh
.
loadVertices
(
'
verts2.txt
'
),
verts2
))
assert
mesh
.
selectedVertices
()
==
op
.
abspath
(
'
verts2.txt
'
)
np
.
savetxt
(
'
badverts.txt
'
,
verts2
[:
-
1
,
:])
with
pytest
.
raises
(
ValueError
):
mesh
.
loadVertices
(
'
badverts.txt
'
)
def
test_mesh_addVertexData
():
...
...
@@ -122,9 +151,14 @@ def test_mesh_addVertexData():
data4D
=
np
.
random
.
randint
(
1
,
100
,
(
nverts
,
20
))
dataBad
=
np
.
random
.
randint
(
1
,
100
,
(
nverts
-
1
,
20
))
mesh
.
addVertexData
(
'
3d
'
,
data3D
)
mesh
.
addVertexData
(
'
3_1d
'
,
data3_1D
)
mesh
.
addVertexData
(
'
4d
'
,
data4D
)
assert
np
.
all
(
np
.
isclose
(
mesh
.
addVertexData
(
'
3d
'
,
data3D
),
data3D
.
reshape
(
-
1
,
1
)))
assert
list
(
mesh
.
vertexDataSets
())
==
[
'
3d
'
]
assert
np
.
all
(
np
.
isclose
(
mesh
.
addVertexData
(
'
3_1d
'
,
data3_1D
),
data3_1D
))
assert
list
(
mesh
.
vertexDataSets
())
==
[
'
3d
'
,
'
3_1d
'
]
assert
np
.
all
(
np
.
isclose
(
mesh
.
addVertexData
(
'
4d
'
,
data4D
),
data4D
))
assert
list
(
mesh
.
vertexDataSets
())
==
[
'
3d
'
,
'
3_1d
'
,
'
4d
'
]
assert
mesh
.
getVertexData
(
'
3d
'
)
.
shape
==
(
nverts
,
1
)
assert
mesh
.
getVertexData
(
'
3_1d
'
).
shape
==
(
nverts
,
1
)
...
...
@@ -150,7 +184,8 @@ def test_loadVertexData():
mesh
=
fslmesh
.
Mesh
(
tris
,
vertices
=
verts
)
with
tempdir
():
np
.
savetxt
(
'
vdata.txt
'
,
vdata
)
np
.
savetxt
(
'
vdata.txt
'
,
vdata
)
np
.
savetxt
(
'
badvdata.txt
'
,
vdata
[:
-
1
])
key
=
op
.
abspath
(
'
vdata.txt
'
)
...
...
@@ -159,6 +194,9 @@ def test_loadVertexData():
assert
np
.
all
(
np
.
isclose
(
mesh
.
loadVertexData
(
key
,
'
vdkey
'
),
vdata
))
assert
np
.
all
(
np
.
isclose
(
mesh
.
getVertexData
(
'
vdkey
'
),
vdata
))
with
pytest
.
raises
(
ValueError
):
mesh
.
loadVertexData
(
'
badvdata.txt
'
)
def
test_normals
():
...
...
@@ -217,17 +255,16 @@ def test_needsFixing():
def
test_trimesh_no_trimesh
():
verts
=
np
.
array
(
CUBE_VERTICES
)
tris
=
np
.
array
(
CUBE_TRIANGLES_CCW
)
mods
=
[
'
trimesh
'
,
'
rtree
'
]
for
mod
in
mods
:
with
mock
.
patch
.
dict
(
'
sys.modules
'
,
**
{
mod
:
None
}):
mesh
=
fslmesh
.
Mesh
(
tris
,
vertices
=
verts
)
verts
=
np
.
array
(
CUBE_VERTICES
)
tris
=
np
.
array
(
CUBE_TRIANGLES_CCW
)
mesh
=
fslmesh
.
Mesh
(
tris
,
vertices
=
verts
)
assert
mesh
.
trimesh
()
is
None
assert
mesh
.
trimesh
is
None
locs
,
tris
=
mesh
.
rayIntersection
([[
0
,
0
,
0
]],
[[
0
,
0
,
1
]])
assert
locs
.
size
==
0
assert
tris
.
size
==
0
...
...
@@ -250,7 +287,7 @@ def test_trimesh():
tris
=
np
.
array
(
CUBE_TRIANGLES_CCW
)
mesh
=
fslmesh
.
Mesh
(
tris
,
vertices
=
verts
)
assert
isinstance
(
mesh
.
trimesh
()
,
trimesh
.
Trimesh
)
assert
isinstance
(
mesh
.
trimesh
,
trimesh
.
Trimesh
)
def
test_rayIntersection
():
...
...
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
register
or
sign in
to comment