Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
openmesh-python
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenMesh
openmesh-python
Commits
1722d006
Commit
1722d006
authored
Mar 16, 2018
by
Alexander Dielen
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added mesh constructor that takes arrays
parent
77871b94
Pipeline
#6523
passed with stages
in 5 minutes and 23 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
src/Mesh.hh
src/Mesh.hh
+44
-0
tests/test_indices.py
tests/test_indices.py
+40
-0
No files found.
src/Mesh.hh
View file @
1722d006
...
...
@@ -596,6 +596,50 @@ void expose_mesh(py::module& m, const char *_name) {
class_mesh
.
def
(
py
::
init
<>
())
.
def
(
py
::
init
([](
py
::
array_t
<
typename
Point
::
value_type
>
_points
,
py
::
array_t
<
int
>
_faces
)
{
Mesh
mesh
;
// return if _points is empty
if
(
_points
.
size
()
==
0
)
{
return
mesh
;
}
// _points is not empty, throw if _points has wrong shape
if
(
_points
.
ndim
()
!=
2
||
_points
.
shape
(
1
)
!=
3
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"Array 'points' must have shape (n, 3)"
);
throw
py
::
error_already_set
();
}
for
(
ssize_t
i
=
0
;
i
<
_points
.
shape
(
0
);
++
i
)
{
mesh
.
add_vertex
(
Point
(
_points
.
at
(
i
,
0
),
_points
.
at
(
i
,
1
),
_points
.
at
(
i
,
2
)));
}
// return if _faces is empty
if
(
_faces
.
size
()
==
0
)
{
return
mesh
;
}
// _faces is not empty, throw if _faces has wrong shape
if
(
_faces
.
ndim
()
!=
2
||
_faces
.
shape
(
1
)
<
3
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"Array 'face_vertex_indices' must have shape (n, m) with m > 2"
);
throw
py
::
error_already_set
();
}
for
(
ssize_t
i
=
0
;
i
<
_faces
.
shape
(
0
);
++
i
)
{
std
::
vector
<
OM
::
VertexHandle
>
vhandles
;
for
(
ssize_t
j
=
0
;
j
<
_faces
.
shape
(
1
);
++
j
)
{
if
(
_faces
.
at
(
i
,
j
)
>=
0
&&
_faces
.
at
(
i
,
j
)
<
_points
.
shape
(
0
))
{
vhandles
.
push_back
(
OM
::
VertexHandle
(
_faces
.
at
(
i
,
j
)));
}
}
if
(
vhandles
.
size
()
>=
3
)
{
mesh
.
add_face
(
vhandles
);
}
}
return
mesh
;
}),
py
::
arg
(
"points"
),
py
::
arg
(
"face_vertex_indices"
)
=
py
::
array_t
<
int
>
())
//======================================================================
// KernelT
//======================================================================
...
...
tests/test_indices.py
View file @
1722d006
...
...
@@ -354,6 +354,46 @@ class Python(unittest.TestCase):
self
.
delete_vertices
()
self
.
assertRaises
(
RuntimeError
,
self
.
mesh
.
halfedge_edge_indices
)
self
.
assertRaises
(
RuntimeError
,
self
.
mesh
.
he_indices
)
def
test_init_with_arrays
(
self
):
points
=
self
.
mesh
.
points
()
face_vertex_indices
=
self
.
mesh
.
face_vertex_indices
()
# init polymesh
polymesh
=
openmesh
.
PolyMesh
(
points
,
face_vertex_indices
)
self
.
assertEqual
(
polymesh
.
n_vertices
(),
self
.
mesh
.
n_vertices
())
self
.
assertEqual
(
polymesh
.
n_faces
(),
self
.
mesh
.
n_faces
())
# init trimesh (one face will be triangulated)
trimesh
=
openmesh
.
TriMesh
(
points
,
face_vertex_indices
)
self
.
assertEqual
(
trimesh
.
n_vertices
(),
self
.
mesh
.
n_vertices
())
self
.
assertEqual
(
trimesh
.
n_faces
(),
self
.
mesh
.
n_faces
()
+
1
)
# init with empty points and faces
trimesh
=
openmesh
.
TriMesh
(
np
.
empty
((
0
,
3
)),
np
.
empty
((
0
,
4
)))
self
.
assertEqual
(
trimesh
.
n_vertices
(),
0
)
self
.
assertEqual
(
trimesh
.
n_faces
(),
0
)
# init with empty points
trimesh
=
openmesh
.
TriMesh
(
np
.
empty
((
0
,
3
)),
face_vertex_indices
)
self
.
assertEqual
(
trimesh
.
n_vertices
(),
0
)
self
.
assertEqual
(
trimesh
.
n_faces
(),
0
)
# init with empty faces
trimesh
=
openmesh
.
TriMesh
(
points
,
np
.
empty
((
0
,
4
)))
self
.
assertEqual
(
trimesh
.
n_vertices
(),
self
.
mesh
.
n_vertices
())
self
.
assertEqual
(
trimesh
.
n_faces
(),
0
)
# init with points only
trimesh
=
openmesh
.
TriMesh
(
points
)
self
.
assertEqual
(
trimesh
.
n_vertices
(),
self
.
mesh
.
n_vertices
())
self
.
assertEqual
(
trimesh
.
n_faces
(),
0
)
# init with wrong points shape
with
self
.
assertRaises
(
RuntimeError
):
openmesh
.
TriMesh
(
points
[:,
:
2
])
# init with wrong faces shape
with
self
.
assertRaises
(
RuntimeError
):
openmesh
.
TriMesh
(
points
,
face_vertex_indices
[:,
:
2
])
# init with points and invalid faces
face_vertex_indices
[
1
]
=
[
-
1
,
-
1
,
-
1
,
-
1
]
face_vertex_indices
[
3
]
=
[
-
1
,
-
1
,
-
1
,
-
1
]
polymesh
=
openmesh
.
PolyMesh
(
points
,
face_vertex_indices
)
self
.
assertEqual
(
polymesh
.
n_vertices
(),
self
.
mesh
.
n_vertices
())
self
.
assertEqual
(
polymesh
.
n_faces
(),
self
.
mesh
.
n_faces
()
-
2
)
if
__name__
==
'__main__'
:
...
...
Alexander Dielen
@adielen
mentioned in issue
#12 (closed)
·
Mar 16, 2018
mentioned in issue
#12 (closed)
mentioned in issue #12
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment