Navigation Menu

Skip to content

Commit

Permalink
3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Jul 3, 2019
1 parent 3a9f2ca commit 0596ec4
Show file tree
Hide file tree
Showing 64 changed files with 56,643 additions and 1,428 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -69,7 +69,7 @@ for all the following functionalities:
- Visualization of tensors.
- Export a 3D scene and embed it into a [web page](https://vtkplotter.embl.es/examples/fenics_elasticity.html).
- Embed the 3D rendering in a *jupyter* notebook with [K3D](https://github.com/K3D-tools/K3D-jupyter) (can export an interactive 3D-snapshot page [here](https://vtkplotter.embl.es/examples/K3D_snapshot.html)).

- Interoperability with the [trimesh](https://trimsh.org/) library.


## Command-line interface
Expand Down Expand Up @@ -100,13 +100,14 @@ git clone https://github.com/marcomusy/vtkplotter.git
cd vtkplotter/examples
python tutorial.py
```
**More than 250 working examples can be found in directories** _(scroll down to see the screenshots):_ <br>
**More than 260 working examples can be found in directories** _(scroll down to see the screenshots):_ <br>
[**examples/basic**](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic)<br>
[**examples/advanced**](https://github.com/marcomusy/vtkplotter/blob/master/examples/advanced)<br>
[**examples/volumetric**](https://github.com/marcomusy/vtkplotter/blob/master/examples/volumetric)<br>
[**examples/simulations**](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations)<br>
[**examples/other**](https://github.com/marcomusy/vtkplotter/blob/master/examples/other)<br>
[**examples/other/dolfin**](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin)<br>
[**examples/other/trimesh**](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/trimesh)<br>
[**examples/notebooks**](https://github.com/marcomusy/vtkplotter/blob/master/examples/notebooks).<br>

| | |
Expand Down
100 changes: 39 additions & 61 deletions bin/vtkplotter
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#
from __future__ import division, print_function
from vtkplotter import Plotter, ProgressBar, printc, humansort, __version__
from vtkplotter import Actor, Plotter, ProgressBar, printc, humansort, __version__
from vtkplotter import vtkio
import vtk
import sys, argparse, os
Expand All @@ -10,7 +10,7 @@ pr = argparse.ArgumentParser(description="version "+str(__version__)+""" -
check out home page https://github.com/marcomusy/vtkplotter""")
pr.add_argument('files', nargs='*', help="Input filename(s)")
pr.add_argument("-c", "--color", type=str, help="mesh color [integer or color name]", default=None, metavar='')
pr.add_argument("-a", "--alpha", type=float, help="alpha value [0-1]", default=-1, metavar='')
pr.add_argument("-a", "--alpha", type=float, help="alpha value [0-1]", default=1, metavar='')
pr.add_argument("-w", "--wireframe", help="use wireframe representation", action="store_true")
pr.add_argument("-p", "--point-size", type=float, help="specify point size", default=-1, metavar='')
pr.add_argument("-x", "--axes-type", type=int, help="specify axes type [0-5]", default=4, metavar='')
Expand Down Expand Up @@ -71,15 +71,12 @@ else:
vp.verbose = not args.quiet
vp.sharecam = not args.no_camera_share

alpha = 1
leg = True
wire = False
if args.legend_off or nfiles == 1:
leg = False
if args.wireframe:
wire = True
if args.scrolling_mode and args.multirenderer_mode:
args.scrolling_mode = False

_alphaslider0, _alphaslider1, _alphaslider2 = 0.33, 0.66, 1 # defaults

Expand Down Expand Up @@ -115,9 +112,9 @@ def _showVoxelImage():
smax = abs(10 * smin) + 0.1
print(" reset to:", smax)

x0alpha = smin + (smax - smin) * 0.33
x1alpha = smin + (smax - smin) * 0.66
x2alpha = smin + (smax - smin) * 1.00
x0alpha = smin + (smax - smin) * 0.25
x1alpha = smin + (smax - smin) * 0.5
x2alpha = smin + (smax - smin) * 1.0

############################## color map slider
# Create transfer mapping scalar value to color
Expand Down Expand Up @@ -175,15 +172,15 @@ def _showVoxelImage():
_alphaslider0 = widget.GetRepresentation().GetValue()
setOTF()
w0 = vp.addSlider2D(
sliderA0, 0, 1, value=_alphaslider0, pos=[(0.855, 0.1), (0.855, 0.26)], c=csl, showValue=0
sliderA0, 0, 1, value=_alphaslider0, pos=[(0.84, 0.1), (0.84, 0.26)], c=csl, showValue=0
)

def sliderA1(widget, event):
global _alphaslider1
_alphaslider1 = widget.GetRepresentation().GetValue()
setOTF()
w1 = vp.addSlider2D(
sliderA1, 0, 1, value=_alphaslider1, pos=[(0.9075, 0.1), (0.9075, 0.26)], c=csl, showValue=0
sliderA1, 0, 1, value=_alphaslider1, pos=[(0.89, 0.1), (0.89, 0.26)], c=csl, showValue=0
)

def sliderA2(widget, event):
Expand Down Expand Up @@ -258,6 +255,7 @@ def _showVoxelImage():
##########################################################
# special case of SLC/TIFF volumes with -g option
if args.ray_cast_mode or args.z_spacing or args.y_spacing:
#print('DEBUG special case of SLC/TIFF volumes with -g option')
if args.axes_type in [1, 2, 3]:
vp.axes = 4
wsize = "auto"
Expand All @@ -269,6 +267,7 @@ if args.ray_cast_mode or args.z_spacing or args.y_spacing:
##########################################################
# special case of SLC/TIFF/DICOM volumes with --slicer option
elif args.slicer:
#print('DEBUG special case of SLC/TIFF/DICOM volumes with --slicer option')

filename = args.files[0]
img = vtkio.load(filename).imagedata()
Expand Down Expand Up @@ -336,7 +335,8 @@ elif nfiles == 1 and (
or ".nrrd" in args.files[0]
or ".dem" in args.files[0]
):
from vtkplotter import Actor, legosurface
#print('DEBUG normal mode for single VOXEL file with Isosurface Slider or LEGO mode')
from vtkplotter import legosurface

image = vtkio.loadImageData(args.files[0])
scrange = image.GetScalarRange()
Expand Down Expand Up @@ -368,7 +368,7 @@ elif nfiles == 1 and (

cf.SetValue(0, threshold)
cf.Update()
act = Actor(cf.GetOutput(), c=ic, alpha=abs(args.alpha)).wire(args.wireframe)
act = Actor(cf.GetOutput(), c=ic, alpha=args.alpha).wire(args.wireframe)
act.phong()

############################## threshold slider
Expand Down Expand Up @@ -409,61 +409,41 @@ elif nfiles == 1 and (

########################################################################
# NORMAL mode for single or multiple files, or multiren mode
elif (not args.scrolling_mode) or nfiles == 1:
elif nfiles == 1 or (not args.scrolling_mode):
#print('DEBUG NORMAL mode for single or multiple files, or multiren mode')

actors = []
for i in range(N):
f = args.files[i]

if ".neutral" in f.lower() or ".xml" in f.lower() or ".gmsh" in f.lower():
alpha = 0.05
wire = True
else:
wire = False

if 0 < args.alpha <= 1:
alpha = args.alpha

if args.wireframe:
wire = True

ic = i # default here
if args.color is not None:
if args.color.isdigit():
ic = int(args.color)
else:
ic = args.color
colb = args.color
if args.color is None and N > 1:
colb = i

actor = vp.load(f, c=ic, alpha=alpha)
poly = actor.polydata(False)
ptdata = poly.GetPointData()
actor = vp.load(f, c=colb, alpha=args.alpha)

if args.color is None and ptdata.GetNumberOfArrays() > 0:
arrname = ptdata.GetArrayName(0)
if "Normals" not in arrname:
ptdata.SetActiveScalars(arrname)
actor.GetMapper().ScalarVisibilityOn()
if isinstance(actor, vtk.vtkActor):

if hasattr(actor, "wire"):
actor.wire(wire)
if isinstance(actor, Actor):
actor.wireframe(wire)

if leg:
actor.legend(os.path.basename(f))
if leg:
actor.legend(os.path.basename(f))

actors.append(actor)
actors.append(actor)

if args.point_size > 0:
try:
ps = actor.GetProperty().GetPointSize()
actor.GetProperty().SetPointSize(args.point_size)
actor.GetProperty().SetRepresentationToPoints()
except AttributeError:
print("cannot set point size for", f)
if args.point_size > 0:
try:
ps = actor.GetProperty().GetPointSize()
actor.GetProperty().SetPointSize(args.point_size)
actor.GetProperty().SetRepresentationToPoints()
except AttributeError:
pass

if args.multirenderer_mode:
actor._legend = None
vp.show(actor, at=i, interactive=False, zoom=args.zoom)
vp.actors = actors
if args.multirenderer_mode:
actor._legend = None
vp.show(actor, at=i, interactive=False, zoom=args.zoom)
vp.actors = actors

if args.multirenderer_mode:
vp.interactor.Start()
Expand All @@ -473,11 +453,9 @@ elif (not args.scrolling_mode) or nfiles == 1:
########################################################################
# scrolling mode -s
else:
#print('DEBUG scrolling mode -s')
import numpy

if 0 < args.alpha <= 1:
alpha = args.alpha

n = len(args.files)
pb = ProgressBar(0, n)

Expand All @@ -491,8 +469,8 @@ else:
else:
ic = args.color

actor = vp.load(f, c=ic, alpha=alpha)
if hasattr(actor, "wire"):
actor = vp.load(f, c=ic, alpha=args.alpha) # can be Image
if hasattr(actor, 'wireframe'):
actor.wire(wire)
actor.legend(leg)
actors.append(actor)
Expand All @@ -502,7 +480,7 @@ else:
actor.GetProperty().SetPointSize(args.point_size)
actor.GetProperty().SetRepresentationToPoints()
except AttributeError:
print("cannot set point size for", f)
pass

# calculate max actors bounds
bns = []
Expand Down
6 changes: 4 additions & 2 deletions docs/README.rst
Expand Up @@ -95,6 +95,8 @@ for the all following functionalities:
- Draw `latex`-formatted formulas on the rending window.
- Export a 3D scene and embed it into a html page.
- Support for `FEniCS/dolfin <https://fenicsproject.org/>`_ package.
- Visualization of tensors.
- Embed the 3D rendering in a jupyter notebook with K3D.


Hello World example
Expand All @@ -106,7 +108,7 @@ In your python script, load a simple ``3DS`` file and display it:
from vtkplotter import show
show('data/shapes/flamingo.3ds')
show('data/flamingo.3ds')
.. image:: https://user-images.githubusercontent.com/32848391/50738813-58af4380-11d8-11e9-84ce-53579c1dba65.png
:alt: flam
Expand Down Expand Up @@ -225,7 +227,7 @@ Support for the `FEniCS/dolfin <https://fenicsproject.org/>`_ platform for visua
finite element solutions
(`see here <https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin>`_.

.. image:: https://user-images.githubusercontent.com/32848391/54932788-bd4a8680-4f1b-11e9-9326-33645171a45e.gif
.. image:: https://user-images.githubusercontent.com/32848391/58368591-8b3fab80-7eef-11e9-882f-8b8eaef43567.gif



Expand Down
4 changes: 2 additions & 2 deletions examples/advanced/moving_least_squares2D.py
Expand Up @@ -49,8 +49,8 @@
print("min and max of variances:", vmin, vmax)
vcols = [colorMap(v, "jet", vmin, vmax) for v in variances] # scalars->colors

a0 = Spheres(s1.coordinates(), c=vcols, r=0.03).legend("variance")
a1 = Spheres(s1.coordinates(), c="red", r=variances).legend("variance")
a0 = Spheres(s1.coordinates(), c=vcols, r=0.03)
a1 = Spheres(s1.coordinates(), c="red", r=variances)

vp2.show(a0, Text(__doc__, c="k"), at=0)
vp2.show(a1, act, at=1, zoom=1.3, interactive=1)
2 changes: 0 additions & 2 deletions examples/advanced/splitmesh.py
Expand Up @@ -10,6 +10,4 @@
# return the list of the largest 10 connected meshes:
splitem = splitByConnectivity(em, maxdepth=40)[0:9]

splitem[0].alpha(0.5).phong() # make the largest part transparent

show([em, splitem], N=2, axes=1)
2 changes: 1 addition & 1 deletion examples/advanced/thinplate.py
Expand Up @@ -12,7 +12,7 @@

vp = Plotter(axes=1)

act = vp.load(datadir+"shuttle.obj")
act = vp.load(datadir+"shuttle.obj", c='silver')

# pick 4 random points
indxs = np.random.randint(0, act.N(), 4)
Expand Down
84 changes: 84 additions & 0 deletions examples/advanced/thinplate_grid.ipynb
@@ -0,0 +1,84 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ca2f57fd0f324b09ae2b0a4eccf31ad6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[4.5, 4.5, 4.5, 0.0, 0.0, 0.0, 1.0, …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\"\"\"Thin Plate Spline transformations describe a nonlinear warp\n",
"transform defined by a set of source and target landmarks.\n",
"Any point on the mesh close to a source landmark will\n",
"be moved to a place close to the corresponding target landmark.\n",
"The points in between are interpolated using Bookstein's algorithm. \"\"\"\n",
"from vtkplotter import *\n",
"import numpy as np\n",
"np.random.seed(2)\n",
"\n",
"grids = []\n",
"for i in range(10):\n",
" grids.append(Grid([0, 0, i / 10.0], resx=100, resy=100))\n",
"act = mergeActors(grids) # merge grids into a single object\n",
"\n",
"idxs = np.random.randint(0, act.N(), 10) # pick 10 indexes\n",
"\n",
"ptsource, pttarget = [], []\n",
"for i in idxs:\n",
" ptold = act.getPoint(i) + np.random.randn(3) * 0.02\n",
" ptsource.append(ptold)\n",
" ptnew = ptold + [0, 0, np.random.randn(1) * 0.10] # move in z\n",
" pttarget.append(ptnew)\n",
"\n",
"warped = thinPlateSpline(act, ptsource, pttarget)\n",
"warped.alpha(0.2).color(\"b\")\n",
"\n",
"arrs = Arrows(ptsource, pttarget)\n",
"\n",
"show(warped, arrs)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 0596ec4

Please sign in to comment.