pyvista / pyvista

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)
https://docs.pyvista.org
MIT License
2.73k stars 501 forks source link

compute_arc_length: does not behave as expected #1948

Open pvanhauw opened 2 years ago

pvanhauw commented 2 years ago

compute_arc_length when applied to a slice does not provide a continuous output. It seems like the algorithm does not account for the fact that the line are not ordered.


To Reproduce


#!/bin/python
import pyvista as pv

mesh = pv.Sphere()

mesh_sliced = mesh.slice(normal=[0, 1, 0])
print(mesh_sliced.n_lines)

# checking that no merging of point is required since each point is used twice per line segment
pointIndex = mesh_sliced.lines.reshape(0 + mesh_sliced.n_lines, -1)
print(pointIndex)

# compute_arc_length is computed but it sounds like the order of the lines is not re-arange to obtain an arc_length that continuously increase
arc = mesh_sliced.compute_arc_length()

p = pv.Plotter()
p.add_mesh(mesh, opacity=0.1)
p.add_mesh(arc, scalars="arc_length")
p.show()
58
[[ 2  0  1]

 [ 2  1  2]
 [ 2  3  4]
 [ 2  5  3]
 [ 2  6  0]
 [ 2  7  6]
 [ 2  8  7]
 [ 2  9  8]
 [ 2 10  9]
 [ 2 11 10]
 [ 2 12 11]
 [ 2 13 12]
 [ 2 14 13]
 [ 2 15 14]
 [ 2 16 15]
 [ 2 17 16]
 [ 2 18 17]
 [ 2 19 18]
 [ 2 20 19]
 [ 2 21 20]
 [ 2 22 21]
 [ 2 23 22]
 [ 2 24 23]
 [ 2 25 24]
 [ 2 26 25]
 [ 2 27 26]
 [ 2 28 27]
 [ 2 29 28]
 [ 2 30 29]
 [ 2 31 30]
 [ 2  4 31]
 [ 2  2 32]
 [ 2 32 33]
 [ 2 33 34]
 [ 2 34 35]
 [ 2 35 36]
 [ 2 36 37]
 [ 2 37 38]
 [ 2 38 39]
 [ 2 39 40]
 [ 2 40 41]
 [ 2 41 42]
 [ 2 42 43]
 [ 2 43 44]
 [ 2 44 45]
 [ 2 45 46]
 [ 2 46 47]
 [ 2 47 48]
 [ 2 48 49]
 [ 2 49 50]
 [ 2 50 51]
 [ 2 51 52]
 [ 2 52 53]
 [ 2 53 54]
 [ 2 54 55]
 [ 2 55 56]
 [ 2 56 57]
 [ 2 57  5]]

Screenshots arc


import pyvista as pv
print(pv.Report())
--------------------------------------------------------------------------------
  Date: Thu Dec 16 09:55:30 2021 CET

                OS : Linux
            CPU(s) : 16
           Machine : x86_64
      Architecture : 64bit
               RAM : 62.8 GiB
       Environment : Python
        GPU Vendor : NVIDIA Corporation
      GPU Renderer : NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2
       GPU Version : 4.5.0 NVIDIA 470.82.00

  Python 3.8.10 (default, Jun  4 2021, 15:09:15)  [GCC 7.5.0]

           pyvista : 0.32.1
               vtk : 9.0.3
             numpy : 1.20.2
           imageio : 2.9.0
           appdirs : 1.4.4
            scooby : 0.5.7
            meshio : 4.4.3
        matplotlib : 3.3.4
         pyvistaqt : 0.5.0
             PyQt5 : 5.9.2
           IPython : 7.22.0
          colorcet : 1.0.0
             scipy : 1.7.1
              tqdm : 4.60.0

  Intel(R) oneAPI Math Kernel Library Version 2021.2-Product Build 20210312
  for Intel(R) 64 architecture applications
github-actions[bot] commented 2 years ago

Hi and welcome! Thanks for posting your first issue in the PyVista project! Someone from @pyvista/developers will chime in before too long. If your question is support related, it may be automatically transferred to Discussions.

pvanhauw commented 2 years ago

changing

mesh_sliced = mesh.slice(normal=[0, 1, 0]) into : mesh_sliced = mesh.slice(normal=[0, 1, 0]).strip() did the job.

It sounds like a good idea to document that in compute_arc_length Anyway, that issue can be solved with some pre-processing

pvanhauw commented 2 years ago

reopening because cell data cannot be recovered correctly.

For exemple the cell_data below is of dimension 1 ( and contained as "field data" instead of "cell_data"), whatever "join" is set to True of False.


#!/bin/python
import pyvista as pv

mesh = pv.Sphere()
mesh = mesh.compute_cell_sizes()
print(mesh.field_data)
print(mesh.cell_data)

mesh_sliced = mesh.slice(normal=[0, 1, 0]).strip(join=True, pass_cell_data=True)
print(mesh_sliced.field_data)
print(mesh_sliced.cell_data)

mesh_sliced = mesh.slice(normal=[0, 1, 0]).strip(join=False, pass_cell_data=True)
print(mesh_sliced.field_data)
print(mesh_sliced.cell_data)
pyvista DataSetAttributes
Association     : NONE
Contains arrays : None
pyvista DataSetAttributes
Association     : CELL
Active Scalars  : None
Active Vectors  : None
Active Texture  : None
Active Normals  : None
Contains arrays :
    Length                  float64  (1680,)
    Area                    float64  (1680,)
    Volume                  float64  (1680,)
pyvista DataSetAttributes
Association     : NONE
Contains arrays :
    Length                  float64  (1,)
    Area                    float64  (1,)
    Volume                  float64  (1,)
pyvista DataSetAttributes
Association     : CELL
Active Scalars  : None
Active Vectors  : None
Active Texture  : None
Active Normals  : None
Contains arrays : None
pyvista DataSetAttributes
Association     : NONE
Contains arrays :
    Length                  float64  (1,)
    Area                    float64  (1,)
    Volume                  float64  (1,)
pyvista DataSetAttributes
Association     : CELL
Active Scalars  : None
Active Vectors  : None
Active Texture  : None
Active Normals  : None
Contains arrays : None
[[59  0  1  2 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  52 53 54 55 56 57  5  3  4 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17
  16 15 14 13 12 11 10  9  8  7  6  0]]