K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
921 stars 123 forks source link

Adding multiple lines to the plot #345

Closed niosus closed 2 years ago

niosus commented 2 years ago

Before speaking of any issues, I just wanted to say thanks for the amazing library! It is really helpful to have a tool like this :+1:

I'm using the library to work with LiDAR point clouds and to match these point clouds. Whenever point clouds are matched I would like to be able to show lines, each of which connects 2 3D points. For now, the only way I see for this is to create a Line, subsequently adding it to the Plot object.

Ideally, I would love to be able to create a "lines" drawable that would generate a set of lines from an array of points. I believe that for now, if I provide an array of points to the k3d.line it will draw a single line through all the points.

Alternatively, what would help me is to be able to stop the rendeing of the plot while adding objects to it. For now whever I do plot += line the scene is redrawn. I'd like to be able to batch-add multiple lines with a single redraw afterwards.

Am I just missing some already existing functionality?

tgandor commented 2 years ago

Here's an issue mentioning a workaround: https://github.com/K3D-tools/K3D-jupyter/issues/173 Splitting the points with NaN-s allows to draw multiple disconnected https://en.wikipedia.org/wiki/Polygonal_chain (which k3d.line normally is).

This way, the chains can be of different length (not, e.g. all 2-point segments).

niosus commented 2 years ago

Thanks! That is very helpful and I can use it as is. I will keep this open in case there is a push to make this an explicit interface and now a workaround though.

artur-trzesiok commented 2 years ago

@niosus Thanks for kind words.

In next release we will introduce k3d.lines: https://github.com/K3D-tools/K3D-jupyter/blob/devel/examples/lines.ipynb

So this is object where you can pass list of vertices + list of indices that will contain pair of index in vertices array that should be connected (or triple to draw triangle outline). Probably that will meet with your expectations better than workaround that @tgandor mentioned.

artur-trzesiok commented 2 years ago

Please download new version of k3d@2.13.0:

It should be there :)