Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenMesh
openmesh-python
Commits
3bbc2e3c
Commit
3bbc2e3c
authored
Feb 23, 2018
by
Alexander Dielen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated tests to use the new read/write functions
parent
89f4ed30
Pipeline
#6300
passed with stages
in 5 minutes and 18 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
123 additions
and
400 deletions
+123
-400
tests/test_indices.py
tests/test_indices.py
+1
-2
tests/test_property_array.py
tests/test_property_array.py
+1
-2
tests/test_property_list.py
tests/test_property_list.py
+1
-2
tests/test_read_write_obj.py
tests/test_read_write_obj.py
+8
-96
tests/test_read_write_off.py
tests/test_read_write_off.py
+28
-58
tests/test_read_write_om.py
tests/test_read_write_om.py
+23
-64
tests/test_read_write_ply.py
tests/test_read_write_ply.py
+55
-145
tests/test_read_write_stl.py
tests/test_read_write_stl.py
+6
-31
No files found.
tests/test_indices.py
View file @
3bbc2e3c
...
@@ -96,8 +96,7 @@ class Python(unittest.TestCase):
...
@@ -96,8 +96,7 @@ class Python(unittest.TestCase):
self
.
assertEqual
(
indices2
.
shape
,
(
self
.
mesh
.
n_vertices
(),
3
))
self
.
assertEqual
(
indices2
.
shape
,
(
self
.
mesh
.
n_vertices
(),
3
))
def
test_face_vertex_indices_trimesh
(
self
):
def
test_face_vertex_indices_trimesh
(
self
):
self
.
mesh
=
openmesh
.
TriMesh
()
self
.
mesh
=
openmesh
.
read_trimesh
(
'TestFiles/cube-minimal.obj'
)
openmesh
.
read_mesh
(
self
.
mesh
,
'TestFiles/cube-minimal.obj'
)
indices1
=
self
.
mesh
.
face_vertex_indices
()
indices1
=
self
.
mesh
.
face_vertex_indices
()
indices2
=
self
.
mesh
.
fv_indices
()
indices2
=
self
.
mesh
.
fv_indices
()
...
...
tests/test_property_array.py
View file @
3bbc2e3c
...
@@ -6,8 +6,7 @@ import numpy as np
...
@@ -6,8 +6,7 @@ import numpy as np
class
Python
(
unittest
.
TestCase
):
class
Python
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
mesh
=
openmesh
.
TriMesh
()
self
.
mesh
=
openmesh
.
read_trimesh
(
'TestFiles/cube-minimal.obj'
)
openmesh
.
read_mesh
(
self
.
mesh
,
'TestFiles/cube-minimal.obj'
)
def
test_vertex_property_array
(
self
):
def
test_vertex_property_array
(
self
):
self
.
assertFalse
(
self
.
mesh
.
has_vertex_property
(
'random'
))
self
.
assertFalse
(
self
.
mesh
.
has_vertex_property
(
'random'
))
...
...
tests/test_property_list.py
View file @
3bbc2e3c
...
@@ -6,8 +6,7 @@ import numpy as np
...
@@ -6,8 +6,7 @@ import numpy as np
class
Python
(
unittest
.
TestCase
):
class
Python
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
mesh
=
openmesh
.
TriMesh
()
self
.
mesh
=
openmesh
.
read_trimesh
(
'TestFiles/cube-minimal.obj'
)
openmesh
.
read_mesh
(
self
.
mesh
,
'TestFiles/cube-minimal.obj'
)
def
test_vertex_property_list
(
self
):
def
test_vertex_property_list
(
self
):
self
.
assertFalse
(
self
.
mesh
.
has_vertex_property
(
'random'
))
self
.
assertFalse
(
self
.
mesh
.
has_vertex_property
(
'random'
))
...
...
tests/test_read_write_obj.py
View file @
3bbc2e3c
...
@@ -3,30 +3,15 @@ import openmesh
...
@@ -3,30 +3,15 @@ import openmesh
class
ReadWriteOBJ
(
unittest
.
TestCase
):
class
ReadWriteOBJ
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
mesh
=
openmesh
.
TriMesh
()
def
test_load_simple_obj
(
self
):
def
test_load_simple_obj
(
self
):
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
"TestFiles/cube-minimal.obj"
)
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/cube-minimal.obj"
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_faces
(),
12
)
self
.
assertEqual
(
self
.
mesh
.
n_faces
(),
12
)
def
test_load_simple_obj_check_halfedge_and_vertex_normals
(
self
):
def
test_load_simple_obj_check_halfedge_and_vertex_normals
(
self
):
self
.
mesh
.
request_halfedge_normals
()
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/cube-minimal.obj"
,
vertex_normal
=
True
)
self
.
mesh
.
request_vertex_normals
()
self
.
mesh
.
update_halfedge_normals
()
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
VertexNormal
file_name
=
"TestFiles/cube-minimal.obj"
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
file_name
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
...
@@ -85,66 +70,11 @@ class ReadWriteOBJ(unittest.TestCase):
...
@@ -85,66 +70,11 @@ class ReadWriteOBJ(unittest.TestCase):
self
.
mesh
.
release_halfedge_normals
()
self
.
mesh
.
release_halfedge_normals
()
def
test_load_simple_obj_force_vertex_colors_although_not_available
(
self
):
def
test_load_simple_obj_force_vertex_colors_although_not_available
(
self
):
self
.
mesh
.
request_vertex_colors
()
with
self
.
assertRaises
(
RuntimeError
):
openmesh
.
read_trimesh
(
"TestFiles/cube-minimal.obj"
,
vertex_color
=
True
)
file_name
=
"TestFiles/cube-minimal.obj"
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
VertexColor
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
file_name
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_faces
(),
12
)
self
.
assertEqual
(
self
.
mesh
.
n_halfedges
(),
36
)
def
test_load_simple_obj_check_texcoords
(
self
):
self
.
mesh
.
request_halfedge_texcoords2D
()
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
FaceTexCoord
file_name
=
"TestFiles/cube-minimal-texCoords.obj"
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
file_name
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
0
))[
0
],
1.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
0
))[
1
],
1.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
10
))[
0
],
3.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
10
))[
1
],
3.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
19
))[
0
],
6.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
19
))[
1
],
6.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
24
))[
0
],
7.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
24
))[
1
],
7.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
30
))[
0
],
9.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
30
))[
1
],
9.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
35
))[
0
],
12.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
halfedge_handle
(
35
))[
1
],
12.0
)
self
.
mesh
.
release_halfedge_texcoords2D
()
def
test_load_obj_with_material
(
self
):
def
test_load_obj_with_material
(
self
):
self
.
mesh
.
request_face_colors
()
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/square_material.obj"
,
face_color
=
True
)
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
FaceColor
file_name
=
"TestFiles/square_material.obj"
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
file_name
,
options
)
self
.
assertTrue
(
ok
)
fh
=
self
.
mesh
.
face_handle
(
self
.
mesh
.
halfedge_handle
(
0
))
fh
=
self
.
mesh
.
face_handle
(
self
.
mesh
.
halfedge_handle
(
0
))
self
.
assertTrue
(
fh
.
is_valid
())
self
.
assertTrue
(
fh
.
is_valid
())
...
@@ -156,16 +86,7 @@ class ReadWriteOBJ(unittest.TestCase):
...
@@ -156,16 +86,7 @@ class ReadWriteOBJ(unittest.TestCase):
self
.
mesh
.
release_face_colors
()
self
.
mesh
.
release_face_colors
()
def
test_load_simple_obj_with_vertex_colors_after_vertices
(
self
):
def
test_load_simple_obj_with_vertex_colors_after_vertices
(
self
):
self
.
mesh
.
request_vertex_colors
()
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/cube-minimal-vertex-colors-after-vertex-definition.obj"
,
vertex_color
=
True
)
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
VertexColor
file_name
=
"TestFiles/cube-minimal-vertex-colors-after-vertex-definition.obj"
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
file_name
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
...
@@ -190,16 +111,7 @@ class ReadWriteOBJ(unittest.TestCase):
...
@@ -190,16 +111,7 @@ class ReadWriteOBJ(unittest.TestCase):
self
.
mesh
.
release_vertex_colors
()
self
.
mesh
.
release_vertex_colors
()
def
test_load_simple_obj_with_vertex_colors_as_vc_lines
(
self
):
def
test_load_simple_obj_with_vertex_colors_as_vc_lines
(
self
):
self
.
mesh
.
request_vertex_colors
()
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/cube-minimal-vertex-colors-as-vc-lines.obj"
,
vertex_color
=
True
)
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
VertexColor
file_name
=
"TestFiles/cube-minimal-vertex-colors-as-vc-lines.obj"
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
file_name
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
...
...
tests/test_read_write_off.py
View file @
3bbc2e3c
...
@@ -8,20 +8,17 @@ import numpy as np
...
@@ -8,20 +8,17 @@ import numpy as np
class
ReadWriteOFF
(
unittest
.
TestCase
):
class
ReadWriteOFF
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
mesh
=
openmesh
.
TriMesh
()
if
not
os
.
path
.
exists
(
'OutFiles'
):
if
not
os
.
path
.
exists
(
'OutFiles'
):
os
.
makedirs
(
'OutFiles'
)
os
.
makedirs
(
'OutFiles'
)
def
test_load_simple_off_file
(
self
):
def
test_load_simple_off_file
(
self
):
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
"TestFiles/cube1.off"
)
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/cube1.off"
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
7526
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
7526
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
22572
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
22572
)
self
.
assertEqual
(
self
.
mesh
.
n_faces
(),
15048
)
self
.
assertEqual
(
self
.
mesh
.
n_faces
(),
15048
)
def
test_write_and_read_vertex_colors_to_and_from_off_file
(
self
):
def
test_write_and_read_vertex_colors_to_and_from_off_file
(
self
):
self
.
mesh
=
openmesh
.
TriMesh
()
self
.
mesh
.
request_vertex_colors
()
self
.
mesh
.
request_vertex_colors
()
self
.
mesh
.
add_vertex
(
np
.
array
([
0
,
0
,
1
]))
self
.
mesh
.
add_vertex
(
np
.
array
([
0
,
0
,
1
]))
...
@@ -45,12 +42,8 @@ class ReadWriteOFF(unittest.TestCase):
...
@@ -45,12 +42,8 @@ class ReadWriteOFF(unittest.TestCase):
self
.
assertEqual
(
count
,
0
)
self
.
assertEqual
(
count
,
0
)
options
=
openmesh
.
Options
()
openmesh
.
write_mesh
(
"OutFiles/temp.off"
,
self
.
mesh
,
vertex_color
=
True
,
color_float
=
True
)
options
+=
openmesh
.
Options
.
VertexColor
self
.
mesh
=
openmesh
.
read_trimesh
(
"OutFiles/temp.off"
,
vertex_color
=
True
,
color_float
=
True
)
options
+=
openmesh
.
Options
.
ColorFloat
openmesh
.
write_mesh
(
self
.
mesh
,
"OutFiles/temp.off"
,
options
)
openmesh
.
read_mesh
(
self
.
mesh
,
"OutFiles/temp.off"
,
options
)
# Check if vertices still have the same color
# Check if vertices still have the same color
count
=
0
count
=
0
...
@@ -64,23 +57,14 @@ class ReadWriteOFF(unittest.TestCase):
...
@@ -64,23 +57,14 @@ class ReadWriteOFF(unittest.TestCase):
self
.
mesh
.
release_vertex_colors
()
self
.
mesh
.
release_vertex_colors
()
def
test_write_and_read_float_vertex_colors_to_and_from_off_file
(
self
):
def
test_write_and_read_float_vertex_colors_to_and_from_off_file
(
self
):
self
.
mesh
.
request_vertex_colors
()
# Read the mesh
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/meshlab.ply"
,
vertex_color
=
True
)
options
=
openmesh
.
Options
(
openmesh
.
Options
.
VertexColor
)
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
"TestFiles/meshlab.ply"
,
options
)
self
.
assertTrue
(
ok
)
options
.
clear
()
options
+=
openmesh
.
Options
.
VertexColor
options
+=
openmesh
.
Options
.
ColorFloat
# Write the mesh
# Write the mesh
ok
=
openmesh
.
write_mesh
(
self
.
mesh
,
"OutFiles/cube_floating.off"
,
options
)
openmesh
.
write_mesh
(
"OutFiles/cube_floating.off"
,
self
.
mesh
,
vertex_color
=
True
,
color_float
=
True
)
self
.
assertTrue
(
ok
)
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
"OutFiles/cube_floating.off"
,
options
)
# Read the mesh again
self
.
assertTrue
(
ok
)
self
.
mesh
=
openmesh
.
read_trimesh
(
"OutFiles/cube_floating.off"
,
vertex_color
=
True
,
color_float
=
True
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
...
@@ -102,37 +86,23 @@ class ReadWriteOFF(unittest.TestCase):
...
@@ -102,37 +86,23 @@ class ReadWriteOFF(unittest.TestCase):
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
1
],
0.0
)
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
1
],
0.0
)
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
2
],
1.0
)
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
2
],
1.0
)
self
.
assertFalse
(
options
.
vertex_has_normal
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_normals
())
self
.
assertFalse
(
options
.
vertex_has_texcoord
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_texcoords1D
())
self
.
assertTrue
(
options
.
vertex_has_color
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_texcoords2D
())
self
.
assertTrue
(
options
.
color_is_float
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_texcoords3D
())
self
.
assertTrue
(
self
.
mesh
.
has_vertex_colors
())
self
.
mesh
.
release_vertex_colors
()
self
.
mesh
.
release_vertex_colors
()
def
test_write_and_read_binary_float_vertex_colors_to_and_from_off_file
(
self
):
def
test_write_and_read_binary_float_vertex_colors_to_and_from_off_file
(
self
):
self
.
mesh
.
request_vertex_colors
()
# Read the mesh
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/meshlab.ply"
,
vertex_color
=
True
)
options
=
openmesh
.
Options
(
openmesh
.
Options
.
VertexColor
)
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
"TestFiles/meshlab.ply"
,
options
)
self
.
assertTrue
(
ok
)
options
.
clear
()
options
+=
openmesh
.
Options
.
VertexColor
options
+=
openmesh
.
Options
.
Binary
options
+=
openmesh
.
Options
.
ColorFloat
# Write the mesh
# Write the mesh
ok
=
openmesh
.
write_mesh
(
self
.
mesh
,
"OutFiles/cube_floating_binary.off"
,
options
)
openmesh
.
write_mesh
(
"OutFiles/cube_floating_binary.off"
,
self
.
mesh
,
vertex_color
=
True
,
binary
=
True
,
color_float
=
True
)
self
.
assertTrue
(
ok
)
self
.
mesh
.
clear
()
# Read the mesh again
options
.
clear
()
self
.
mesh
=
openmesh
.
read_trimesh
(
"OutFiles/cube_floating_binary.off"
,
vertex_color
=
True
,
binary
=
True
,
color_float
=
True
)
options
+=
openmesh
.
Options
.
VertexColor
options
+=
openmesh
.
Options
.
Binary
options
+=
openmesh
.
Options
.
ColorFloat
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
"OutFiles/cube_floating_binary.off"
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
...
@@ -154,12 +124,12 @@ class ReadWriteOFF(unittest.TestCase):
...
@@ -154,12 +124,12 @@ class ReadWriteOFF(unittest.TestCase):
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
1
],
0.0
)
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
1
],
0.0
)
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
2
],
1.0
)
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
2
],
1.0
)
self
.
assertFalse
(
options
.
vertex_
has_
normal
())
self
.
assertFalse
(
self
.
mesh
.
has_
vertex_normal
s
())
self
.
assertFalse
(
options
.
vertex_
has_
texcoord
())
self
.
assertFalse
(
self
.
mesh
.
has_
vertex_texcoord
s1D
())
self
.
assertFalse
(
options
.
face_has_
co
l
or
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_tex
coor
ds2D
())
self
.
assert
True
(
options
.
vertex_
has_
co
l
or
())
self
.
assert
False
(
self
.
mesh
.
has_
vertex_
tex
coor
ds3D
())
self
.
assert
True
(
options
.
color_is_float
())
self
.
assert
False
(
self
.
mesh
.
has_face_colors
())
self
.
assertTrue
(
options
.
is_binary
())
self
.
assertTrue
(
self
.
mesh
.
has_vertex_colors
())
self
.
mesh
.
release_vertex_colors
()
self
.
mesh
.
release_vertex_colors
()
...
...
tests/test_read_write_om.py
View file @
3bbc2e3c
...
@@ -7,40 +7,15 @@ import numpy as np
...
@@ -7,40 +7,15 @@ import numpy as np
class
ReadWriteOM
(
unittest
.
TestCase
):
class
ReadWriteOM
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
mesh
=
openmesh
.
TriMesh
()
if
not
os
.
path
.
exists
(
'OutFiles'
):
if
not
os
.
path
.
exists
(
'OutFiles'
):
os
.
makedirs
(
'OutFiles'
)
os
.
makedirs
(
'OutFiles'
)
def
test_load_simple_om_force_vertex_colors_although_not_available
(
self
):
def
test_load_simple_om_force_vertex_colors_although_not_available
(
self
):
self
.
mesh
.
request_vertex_colors
()
with
self
.
assertRaises
(
RuntimeError
):
openmesh
.
read_trimesh
(
"TestFiles/cube-minimal.om"
,
vertex_color
=
True
)
file_name
=
"TestFiles/cube-minimal.om"
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
VertexColor
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
file_name
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_faces
(),
12
)
self
.
assertEqual
(
self
.
mesh
.
n_halfedges
(),
36
)
self
.
assertFalse
(
options
.
vertex_has_normal
())
self
.
assertFalse
(
options
.
vertex_has_texcoord
())
self
.
assertFalse
(
options
.
vertex_has_color
())
def
test_load_simple_om_with_texcoords
(
self
):
def
test_load_simple_om_with_texcoords
(
self
):
self
.
mesh
.
request_vertex_texcoords2D
()
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/cube-minimal-texCoords.om"
,
vertex_tex_coord
=
True
)
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
VertexTexCoord
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
"TestFiles/cube-minimal-texCoords.om"
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
...
@@ -58,21 +33,16 @@ class ReadWriteOM(unittest.TestCase):
...
@@ -58,21 +33,16 @@ class ReadWriteOM(unittest.TestCase):
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
vertex_handle
(
7
))[
0
],
12.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
vertex_handle
(
7
))[
0
],
12.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
vertex_handle
(
7
))[
1
],
12.0
)
self
.
assertEqual
(
self
.
mesh
.
texcoord2D
(
self
.
mesh
.
vertex_handle
(
7
))[
1
],
12.0
)
self
.
assertFalse
(
options
.
vertex_has_normal
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_normals
())
self
.
assertTrue
(
options
.
vertex_has_texcoord
())
self
.
assertTrue
(
self
.
mesh
.
has_vertex_texcoords1D
())
self
.
assertFalse
(
options
.
vertex_has_color
())
self
.
assertTrue
(
self
.
mesh
.
has_vertex_texcoords2D
())
self
.
assertTrue
(
self
.
mesh
.
has_vertex_texcoords3D
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_colors
())
self
.
mesh
.
release_vertex_texcoords2D
()
self
.
mesh
.
release_vertex_texcoords2D
()
def
test_load_simple_om_with_vertex_colors
(
self
):
def
test_load_simple_om_with_vertex_colors
(
self
):
self
.
mesh
.
request_vertex_colors
()
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/cube-minimal-vertexColors.om"
,
vertex_color
=
True
)
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
VertexColor
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
"TestFiles/cube-minimal-vertexColors.om"
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
8
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
self
.
assertEqual
(
self
.
mesh
.
n_edges
(),
18
)
...
@@ -94,14 +64,16 @@ class ReadWriteOM(unittest.TestCase):
...
@@ -94,14 +64,16 @@ class ReadWriteOM(unittest.TestCase):
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
1
],
0.0
)
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
1
],
0.0
)
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
2
],
1.0
)
self
.
assertEqual
(
self
.
mesh
.
color
(
self
.
mesh
.
vertex_handle
(
7
))[
2
],
1.0
)
self
.
assertFalse
(
options
.
vertex_has_normal
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_normals
())
self
.
assertFalse
(
options
.
vertex_has_texcoord
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_texcoords1D
())
self
.
assertTrue
(
options
.
vertex_has_color
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_texcoords2D
())
self
.
assertFalse
(
self
.
mesh
.
has_vertex_texcoords3D
())
self
.
assertTrue
(
self
.
mesh
.
has_vertex_colors
())
self
.
mesh
.
release_vertex_colors
()
self
.
mesh
.
release_vertex_colors
()
def
test_write_triangle
(
self
):
def
test_write_triangle
(
self
):
filename
=
"OutFiles/triangle-minimal.om"
;
self
.
mesh
=
openmesh
.
TriMesh
()
# Generate data
# Generate data
v1
=
self
.
mesh
.
add_vertex
(
np
.
array
([
1.0
,
0.0
,
0.0
]))
v1
=
self
.
mesh
.
add_vertex
(
np
.
array
([
1.0
,
0.0
,
0.0
]))
...
@@ -110,15 +82,11 @@ class ReadWriteOM(unittest.TestCase):
...
@@ -110,15 +82,11 @@ class ReadWriteOM(unittest.TestCase):
self
.
mesh
.
add_face
(
v1
,
v2
,
v3
)
self
.
mesh
.
add_face
(
v1
,
v2
,
v3
)
# Save
# Save
ok
=
openmesh
.
write_mesh
(
self
.
mesh
,
filename
)
filename
=
"OutFiles/triangle-minimal.om"
self
.
assertTrue
(
ok
)
openmesh
.
write_mesh
(
filename
,
self
.
mesh
)
# Reset
self
.
mesh
.
clear
()
# Load
# Load
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
filename
)
self
.
mesh
=
openmesh
.
read_trimesh
(
filename
)
self
.
assertTrue
(
ok
)
# Compare
# Compare
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
3
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
3
)
...
@@ -133,14 +101,8 @@ class ReadWriteOM(unittest.TestCase):
...
@@ -133,14 +101,8 @@ class ReadWriteOM(unittest.TestCase):
os
.
remove
(
filename
)
os
.
remove
(
filename
)
def
test_write_triangle_vertex_integer_color
(
self
):
def
test_write_triangle_vertex_integer_color
(
self
):
self
.
mesh
.
request_vertex_colors
()
self
.
mesh
=
openmesh
.
TriMesh
()
options
=
openmesh
.
Options
()
options
+=
openmesh
.
Options
.
VertexColor
options
+=
openmesh
.
Options
.
ColorFloat
filename
=
"OutFiles/triangle-minimal-ColorsPerVertex.om"
# Generate data
# Generate data
v1
=
self
.
mesh
.
add_vertex
(
np
.
array
([
1.0
,
0.0
,
0.0
]))
v1
=
self
.
mesh
.
add_vertex
(
np
.
array
([
1.0
,
0.0
,
0.0
]))
v2
=
self
.
mesh
.
add_vertex
(
np
.
array
([
0.0
,
1.0
,
0.0
]))
v2
=
self
.
mesh
.
add_vertex
(
np
.
array
([
0.0
,
1.0
,
0.0
]))
...
@@ -156,16 +118,13 @@ class ReadWriteOM(unittest.TestCase):
...
@@ -156,16 +118,13 @@ class ReadWriteOM(unittest.TestCase):
self
.
mesh
.
set_color
(
v3
,
c3
)
self
.
mesh
.
set_color
(
v3
,
c3
)
# Save
# Save
ok
=
op
enme
sh
.
write_mesh
(
self
.
mesh
,
filename
,
options
)
fil
en
a
me
=
"OutFiles/triangle-minimal-ColorsPerVertex.om"
self
.
assertTrue
(
ok
)
openmesh
.
write_mesh
(
filename
,
self
.
mesh
,
vertex_color
=
True
,
color_float
=
True
)
self
.
mesh
.
release_vertex_colors
()
self
.
mesh
.
release_vertex_colors
()
# Load
# Load
cmpMesh
=
openmesh
.
TriMesh
()
cmpMesh
=
openmesh
.
read_trimesh
(
filename
,
vertex_color
=
True
,
color_float
=
True
)
cmpMesh
.
request_vertex_colors
()
ok
=
openmesh
.
read_mesh
(
cmpMesh
,
filename
,
options
)
self
.
assertTrue
(
ok
)
self
.
assertTrue
(
cmpMesh
.
has_vertex_colors
())
self
.
assertTrue
(
cmpMesh
.
has_vertex_colors
())
...
...
tests/test_read_write_ply.py
View file @
3bbc2e3c
...
@@ -5,69 +5,33 @@ import os
...
@@ -5,69 +5,33 @@ import os
class
ReadWritePLY
(
unittest
.
TestCase
):
class
ReadWritePLY
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
mesh
=
openmesh
.
TriMesh
()
if
not
os
.
path
.
exists
(
'OutFiles'
):
if
not
os
.
path
.
exists
(
'OutFiles'
):
os
.
makedirs
(
'OutFiles'
)
os
.
makedirs
(
'OutFiles'
)
def
test_load_simple_point_ply_file_with_bad_encoding
(
self
):
def
test_load_simple_point_ply_file_with_bad_encoding
(
self
):
ok
=
openmesh
.
read_mesh
(
self
.
mesh
,
"TestFiles/pointCloudBadEncoding.ply"
)
self
.
mesh
=
openmesh
.
read_trimesh
(
"TestFiles/pointCloudBadEncoding.ply"
)
self
.
assertTrue
(
ok
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
10
)
self
.
assertEqual
(
self
.
mesh
.
n_vertices
(),
10
)