Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
openmesh-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
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
OpenMesh
openmesh-python
Commits
1722d006
There was a problem fetching the pipeline summary.
Commit
1722d006
authored
7 years ago
by
Alexander Dielen
Browse files
Options
Downloads
Patches
Plain Diff
added mesh constructor that takes arrays
parent
77871b94
No related branches found
No related tags found
No related merge requests found
Pipeline
#
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Mesh.hh
+44
-0
44 additions, 0 deletions
src/Mesh.hh
tests/test_indices.py
+40
-0
40 additions, 0 deletions
tests/test_indices.py
with
84 additions
and
0 deletions
src/Mesh.hh
+
44
−
0
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
//======================================================================
...
...
This diff is collapsed.
Click to expand it.
tests/test_indices.py
+
40
−
0
View file @
1722d006
...
...
@@ -355,6 +355,46 @@ class Python(unittest.TestCase):
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__
'
:
suite
=
unittest
.
TestLoader
().
loadTestsFromTestCase
(
Python
)
...
...
This diff is collapsed.
Click to expand it.
Alexander Dielen
@adielen
mentioned in issue
#12 (closed)
·
7 years ago
mentioned in issue
#12 (closed)
mentioned in issue #12
Toggle commit list
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