Polyline creation #235
-
Add polyline creation? Currently MeshLab and PyMeshLab can internally generate polylines from edges or selection perimeters. These are very useful. Could PyMeshLab include the ability for the user to create polylines? (given edge_matrix and vertex_matrix arrays). |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You can create edge meshes as in the next example: import pymeshlab
import numpy
# create a numpy 8x3 array of vertices
verts = numpy.array([
[-0.5, -0.5, -0.5],
[0.5, -0.5, -0.5],
[-0.5, 0.5, -0.5],
[0.5, 0.5, -0.5],
[-0.5, -0.5, 0.5],
[0.5, -0.5, 0.5],
[-0.5, 0.5, 0.5],
[0.5, 0.5, 0.5]])
# create a numpy 7x2 array of edges
edges = numpy.array([
[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]])
# create a new Mesh with the two arrays
m = pymeshlab.Mesh(vertex_matrix=verts, edge_matrix=edges) But it is true that you can only apply a small set of filters to that mesh. Mainly, compute geometric statistics. ms = pymeshlab.MeshSet()
ms.add_mesh(m, "edge_mesh")
ms.save_current_mesh("my_edgeMesh.ply", binary=False) will produce this file ply
format ascii 1.0
comment VCGLIB generated
element vertex 8
property double x
property double y
property double z
property uchar red
property uchar green
property uchar blue
property uchar alpha
property double quality
element face 0
property list uchar int vertex_indices
end_header
-0.5 -0.5 -0.5 255 255 255 255 0
0.5 -0.5 -0.5 255 255 255 255 0
-0.5 0.5 -0.5 255 255 255 255 0
0.5 0.5 -0.5 255 255 255 255 0
-0.5 -0.5 0.5 255 255 255 255 0
0.5 -0.5 0.5 255 255 255 255 0
-0.5 0.5 0.5 255 255 255 255 0
0.5 0.5 0.5 255 255 255 255 0 |
Beta Was this translation helpful? Give feedback.
-
Thank you for the edge example. I was not clear enough in the question. Most of the time I am interested in extracting polylines resulting from borders or sections (rather than edges). For example starting with a mesh with a border:
The (unordered) vertices are returned above. The issue is preserving vertex order. The order of the array is not the sequential order of the vertices in the polyline. I am currently reassembling the polyline from the unsorted vertices. Is there a way to recover the vertex order of the polyline vertices? In my application I am starting with a watertight mesh representing an
In each case I need the vertices in polyline order. How do I accomplish this? Thanks Dan Bean |
Beta Was this translation helpful? Give feedback.
-
Creating a boundary polyline and using a chained list of its edge_matrix to reassemble the boundary vertices in the proper order works. Note that small loops may occur in the polyline and must be handled. Returning a polyline as a 1-D array of ordered vertex indices would be much simpler for the user. |
Beta Was this translation helpful? Give feedback.
I see... m.edge_matrix() return a list of (unsorted) edges that sometimes are in reverse order.
I would file a bug for this behaviour, but in the meanwhile you can sort the edges manually