Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store Polyline in one cell #48

Closed
laserman781 opened this issue Aug 12, 2019 · 4 comments
Closed

Store Polyline in one cell #48

laserman781 opened this issue Aug 12, 2019 · 4 comments
Labels
mesh-creation Topics around creating a PyVista mesh

Comments

@laserman781
Copy link

laserman781 commented Aug 12, 2019

Using pyvista.lines_from_points I create polylines, although each cell contains lines for each connection to point. Is there a way to make it so that it recognizes the entire polyline as a cell?

How can I solve this? Thanks!

def create_line(lines):
    lines_frame = {}
    poly_array =lines[['Name','x', 'y', 'z']]
    n_dh = poly_array['lines'].nunique()
    n_rows = len(poly_array)
    for i in range (0,n_dh):
        lines_frame['poly_array{}'.format(i)] = poly_array[poly_array['Name'] == i]
    for i in range (0,n_dh):
      lines_frame['coords{}'.format(i)] = (lines_frame['poly_array{}'.format(i)])[['x', 'y', 'z']].values
    for i in range (0,n_dh):
        for j in range (0,n_rows):
            if (poly_array['Name'] == i) is True:
                lines_frame['coords{}'.format(i)] = np.append(lines_frame['coords{}'.format(i)],poly_array[poly_array['Name'] == i])
            else:
                continue
    return drillhole_frame

def poly_line(lines):
    lines_frame= create_line(lines)
    poly_array = lines[['Name','x', 'y', 'z']]
    n_dh = poly_array['Name'].nunique()
    for i in range (0,n_dh):
        lines_frame['poly_segments{}'.format(i)] = lines_from_points(lines_frame['coords{}'.format(i)])
    return line_frame
@banesullivan banesullivan added the mesh-creation Topics around creating a PyVista mesh label Aug 12, 2019
@banesullivan
Copy link
Member

Have you experimented with the different types of lines in this example?: https://docs.pyvista.org/examples/00-load/create-spline.html

If you sort the points in order, then you can create a poly line cell for all of them using the function:

def polyline_from_points(points):
    poly = pv.PolyData()
    poly.points = points
    the_cell = np.arange(0, len(points), dtype=np.int)
    the_cell = np.insert(the_cell, 0, len(points))
    poly.lines = the_cell
    return poly

@laserman781
Copy link
Author

laserman781 commented Aug 14, 2019

Upon trying the code above I receive this error:

~\Desktop\Jupyter Notebook\Plotter_R4.py in lines_from_points(points)
     64     the_cell = np.arange(0, len(points), dtype=np.int)
     65     the_cell = np.insert(the_cell, 0, len(points))
---> 66     poly.lines = the_cell
     67     return poly
     68 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pyvista\core\pointset.py in lines(self, lines)
    205         if lines.ndim == 1:
    206             div = lines.size / 3.0
--> 207             assert not div % 1, 'Invalid lines array'
    208             nlines = int(div)
    209         else:

AssertionError: Invalid lines array

My points are in order before I apply this function.

@banesullivan
Copy link
Member

This was fixed on the last release of PyVista. Would you please make sure you are using the latest version of PyVista:

pip install -U pyvista

@laserman781
Copy link
Author

Worked perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mesh-creation Topics around creating a PyVista mesh
Projects
None yet
Development

No branches or pull requests

2 participants