Skip to content

Commit

Permalink
probepoints
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Apr 9, 2019
1 parent 62307fc commit 1fa08f9
Show file tree
Hide file tree
Showing 76 changed files with 1,019 additions and 1,109 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
[![gdocs](https://img.shields.io/badge/docs%20by-gendocs-blue.svg)](https://gendocs.readthedocs.io/en/latest)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2561402.svg)](https://doi.org/10.5281/zenodo.2561402)

A python module for scientific visualization, analysis and animation of 3D objects
and *point clouds* based on [VTK](https://www.vtk.org/)
and [numpy](http://www.numpy.org/).<br>
A pure python module for scientific visualization, analysis and animation of 3D objects
and *point clouds* based on [VTK](https://www.vtk.org/) and [numpy](http://www.numpy.org/).<br>

## Download and Install:
Use [pip](https://projects.raspberrypi.org/en/projects/using-pip-on-windows) to install:
Expand Down Expand Up @@ -62,24 +61,25 @@ for the all following functionalities:
- Generate volumetric signed-distance data from an input surface mesh
- Probe a volume with lines and planes.
- Add sliders and buttons to interact with the scene and the individual objects.
- Draw `latex`-formatted formulas on the rending window.
- Examples using [SHTools](https://shtools.oca.eu/shtools) package for *spherical harmonics* expansion of a mesh shape.
- Integration with the *Qt5* framework.
- Support for [FEniCS/dolfin](https://fenicsproject.org/) package.
- Support for [FEniCS/Dolfin](https://fenicsproject.org/) package.



## Command-line usage
```bash
vtkplotter mesh.obj
# valid formats: [vtk,vtu,vts,vtp,vtm,ply,obj,stl,3ds,xml,neutral,
# gmsh,pcd,xyz,txt,byu,tif,off,slc,vti,mhd,png,jpg]
# gmsh,pcd,xyz,txt,byu,tif,off,slc,vti,mhd,dcm,png,jpg]
```
to visualize multiple files or files time-sequences try `-n` or `-s` options. Use `-h` for help.<br>
Voxel-data (_vti, slc, tiff_) files can also be visualized with options `-g` and `--slicer`,
e.g.:
```bash
vtkplotter -g -c blue examples/data/embryo.slc # (3D scan of a mouse embryo)
vtkplotter --slicer examples/data/embryo.slc # can read a DICOM directory
vtkplotter --slicer examples/data/embryo.slc # can be used to read DICOM datasets
```
![e2](https://user-images.githubusercontent.com/32848391/50738810-58af4380-11d8-11e9-8fc7-6c6959207224.jpg)

Expand Down
6 changes: 4 additions & 2 deletions bin/vtkplotter
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def _showVoxelImage():
reader.SetFileName(filename)
reader.Update()
img = reader.GetOutput()

if not args.quiet:
vc.printHistogram(img, bins=15, minbin=1, logscale=0, height=8, bold=0, c='b')

if args.z_spacing:
ispa = img.GetSpacing()
Expand All @@ -119,13 +122,12 @@ def _showVoxelImage():
volumeMapper.SetBlendModeToMaximumIntensity()
volumeMapper.UseJitteringOn()
volumeMapper.SetInputConnection(reader.GetOutputPort())
printc("scalar range is ", img.GetScalarRange(), c="b", bold=0)
smin, smax = img.GetScalarRange()
if smax > 1e10:
print("Warning, high scalar range detected:", smax)
smax = abs(10 * smin) + 0.1
print(" reset to:", smax)
printc("voxel spacing is", img.GetSpacing(), c="b", bold=0)
printc("voxel spacing:", img.GetSpacing(), c="b", bold=0)

# Create transfer mapping scalar value to color
if args.color is None:
Expand Down
6 changes: 4 additions & 2 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ for the all following functionalities:
- Add sliders and buttons to interact with the scene and the individual objects.
- Examples with `SHTools <https://shtools.oca.eu/shtools>`_ package for *spherical harmonics* expansion of a mesh shape.
- Integration with the *Qt5* framework.
- Draw `latex`-formatted formulas on the rending window.
- Support for `FEniCS/dolfin <https://fenicsproject.org/>`_ package


Hello World example
Expand All @@ -113,7 +115,7 @@ Allowed input objects to the ``show()`` command are: \ :raw-html-m2r:`<br>`

Supported ``filename`` extensions are: \ :raw-html-m2r:`<br>`
`vtk, vtu, vts, vtp, ply, obj, stl, 3ds, xml, neutral, gmsh, pcd, xyz, txt, byu,
tif, slc, vti, mhd, png, jpg`.
tif, slc, vti, mhd, dcm, png, jpg`.



Expand Down Expand Up @@ -141,7 +143,7 @@ with options ``-g`` or ``--slicer``, e.g.:
vtkplotter examples/data/embryo.tif # shows a 3D scan of a mouse embryo
vtkplotter -g -c blue examples/data/embryo.slc # with sliders to control isosurfacing
vtkplotter --slicer examples/data/embryo.slc
vtkplotter --slicer examples/data/embryo.slc # can be used to show DICOM files
.. image:: https://user-images.githubusercontent.com/32848391/50738810-58af4380-11d8-11e9-8fc7-6c6959207224.jpg
:target: https://user-images.githubusercontent.com/32848391/50738810-58af4380-11d8-11e9-8fc7-6c6959207224.jpg
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
author = 'Marco Musy'

# The short X.Y version
version = '2019.1.3'
version = '2019.1.4'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ vp.show(Cylinder(), at=8, legend='cylinder', interactive=1)
vp = Plotter(shape=(3,3), title='mesh formats') # split window in 3 rows and 3 columns
vp.sharecam = False # each object can be moved independently
vp.show('data/beethoven.ply', at=0, c=0, axes=0) # dont show axes
vp.show('data/cow.g', at=1, c=1, zoom=1.15) # make it 15% bigger
vp.show('data/cow.byu', at=1, c=1, zoom=1.15) # make it 15% bigger
vp.show('data/limb.pcd', at=2, c=2)
vp.show('data/ring.gmsh', at=3, c=3, wire=1) # show mesh as wireframe
vp.show('data/images/dog.jpg',at=4) # 2d images can be loaded the same way
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/convexHull.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

ch = convexHull(spid.coordinates()).alpha(0.2)

show([spid, ch, Text(__doc__)], axes=1)
show(spid, ch, Text(__doc__), axes=1)
4 changes: 2 additions & 2 deletions examples/advanced/cutAndCap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

cutmesh = Hyperboloid().scale(0.4).wire(True).alpha(0.1)

show([p1, cutmesh], at=0, N=2, axes=1, viewup="z")
show(p1, cutmesh, at=0, N=2, axes=1, viewup="z")

p2 = p1.clone().cutWithMesh(cutmesh)

redcap = p2.cap(returnCap=True).color("r") # dark red cap only

show([redcap, p2, Text(__doc__)], at=1, interactive=1)
show(redcap, p2, Text(__doc__), at=1, interactive=1)
2 changes: 1 addition & 1 deletion examples/advanced/cutWithMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# make a working copy and cut it with the ellipsoid
cutembryo = embryo.clone().cutWithMesh(msh).backColor("t").phong()

show([embryo, msh, Text(__doc__)], at=0, N=2, axes=1, viewup="z")
show(embryo, msh, Text(__doc__), at=0, N=2, axes=1, viewup="z")
show(cutembryo, at=1, interactive=1)
2 changes: 1 addition & 1 deletion examples/advanced/geodesic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

doc = Text(__doc__, c="w")

show([s, Earth(lw=1), doc] + paths, viewup="z", verbose=0)
show(s, Earth(lw=1), doc, paths, viewup="z", verbose=0)
2 changes: 1 addition & 1 deletion examples/advanced/interpolateField.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@

vp2 = Plotter(N=2, pos=(200, 300), verbose=0)
vp2.camera = vp.camera # share the same camera with previous Plotter
vp2.show([apos, warped_rbf, src, trs, arr, Text("Radial Basis Function")], at=0)
vp2.show(apos, warped_rbf, src, trs, arr, Text("Radial Basis Function"), at=0)
vp2.show(allarr_rbf, at=1, interactive=1)
6 changes: 4 additions & 2 deletions examples/advanced/meshquality.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

a1 = meshQuality(Sphere())
a2 = meshQuality(load(datadir+"shapes/bunny.obj").normalize())
a3 = meshQuality(load(datadir+"shapes/motor.g").normalize())
a3 = meshQuality(load(datadir+"shapes/motor.byu").normalize())

show([a1, a2, a3], N=3)
printHistogram(a2, title='bunny quality', c='g') # histo active scalars

show(a1, a2, a3, N=3)
4 changes: 2 additions & 2 deletions examples/advanced/moving_least_squares2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
a0 = Spheres(s1.coordinates(), c=vcols, r=0.03).legend("variance")
a1 = Spheres(s1.coordinates(), c="red", r=variances).legend("variance")

vp2.show([a0, Text(__doc__, c="k")], at=0)
vp2.show([a1, act], at=1, zoom=1.3, interactive=1)
vp2.show(a0, Text(__doc__, c="k"), at=0)
vp2.show(a1, act, at=1, zoom=1.3, interactive=1)
2 changes: 1 addition & 1 deletion examples/advanced/projectsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

ef = projectSphereFilter(e).normalize().wire(True)

show([e, ef, Text(__doc__)])
show(e, ef, Text(__doc__))
6 changes: 3 additions & 3 deletions examples/advanced/quadratic_morphing.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def draw_shapes(self):
text2 = Text("morphed vs target", tpos, s=sz / 10, c="dg")
text3 = Text("deformation", tpos, s=sz / 10, c="dr")

vp.show([sphere0, sphere1, zero, text3] + hairsacts, at=2)
vp.show([self.msource, self.target, text2], at=1)
vp.show([self.source, self.target, text1], at=0, zoom=1.2, interactive=1)
vp.show(sphere0, sphere1, zero, text3, hairsacts, at=2)
vp.show(self.msource, self.target, text2, at=1)
vp.show(self.source, self.target, text1, at=0, zoom=1.2, interactive=1)


#################################
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/thinplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@

apts = Points(ptsource, r=15, c="r")

vp.show([act, warped, apts, Text(__doc__)], viewup="z")
vp.show(act, warped, apts, Text(__doc__), viewup="z")
2 changes: 1 addition & 1 deletion examples/advanced/thinplate_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
apts = Points(ptsource, r=5, c="r")
arrs = Arrows(ptsource, pttarget)

show([warped, apts, arrs, Text(__doc__)], axes=9, viewup="z", verbose=0, bg="w")
show(warped, apts, arrs, Text(__doc__), axes=9, viewup="z", verbose=0, bg="w")
2 changes: 1 addition & 1 deletion examples/advanced/thinplate_morphing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@

arro = Arrow(sources[0], targets[0])

show([mesh, arro, warp, apts, Text(__doc__)], viewup="z", axes=1)
show(mesh, arro, warp, apts, Text(__doc__), viewup="z", axes=1)
2 changes: 2 additions & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ python example.py
| | |
| [![largestregion](https://user-images.githubusercontent.com/32848391/50738859-bfccf800-11d8-11e9-8c59-17c0ca4d8e06.jpg)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/largestregion.py)<br/> `largestregion.py` | Extract the mesh region that has the largest connected surface with method `analysis.extractLargestRegion()`. |
| | |
| [![latex](https://user-images.githubusercontent.com/32848391/55568648-6190b200-5700-11e9-9547-0798c588a7a5.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/latex.py)<br/> `latex.py` | Draw latex formatted text on the rendering window. |
| | |
| [![manyspheres](https://user-images.githubusercontent.com/32848391/50738858-bfccf800-11d8-11e9-9daf-3b11eedf72ac.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/manyspheres.py)<br/> `manyspheres.py` | Draw a very large number of spheres (200.000) with different colors or different radii (for vtk versions before 8.0 this might be slow). |
| | |
| [![mesh_alphas](https://user-images.githubusercontent.com/32848391/50738857-bf346180-11d8-11e9-80a1-d283aed0b305.jpg)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/mesh_alphas.py)<br/> `mesh_alphas.py` | Create a set of transparencies which can be passed to method `pointColors()`.|
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/a_first_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
c.show() # draw the cube only
(c+s).show() # Actor+Actor = Assembly, then show it.
show([c,s]) # can show list of [Actor, Volume, filename ...]
show(c,s) # can show list of [Actor, Volume, filename ...]
vp = Plotter() # Make a new Plotter() instance and pop up a new window
vp.add(Torus()) # generate another mesh and add it to the Plotter list
Expand All @@ -29,8 +29,8 @@
print("-> (c+s).show() # Actor+Actor = Assembly, then show it.")
(c + s).show()

print("-> show([c,s]) # can show list of [Actor, Volume, filename ...]")
show([c, s])
print("-> show(c,s) # can show list of [Actor, Volume, filename ...]")
show(c, s)

print("\n-> # Make a new Plotter() instance and pop up a new window\n-> vp = Plotter()")
vp = Plotter(verbose=0)
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/align2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
act1 = Points(pts1, r=8, c="b").legend("source")
act2 = Points(pts2, r=8, c="r").legend("target")

vp.show([act1, act2], at=0)
vp.show(act1, act2, at=0)

# find best alignment between the 2 sets of Points, e.i. find
# how to move act1 to best match act2
Expand Down
10 changes: 5 additions & 5 deletions examples/basic/align3.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Example usage of align() method:
Example usage of alignProcrustes() method:
generate 3 random sets of points
and align them using vtkProcrustesAlignmentFilter.
"""
from __future__ import division, print_function
from random import uniform as u

from vtkplotter import Plotter, procrustes, Text, Points
from vtkplotter import Plotter, alignProcrustes, Text, Points

vp = Plotter(shape=[1, 2], verbose=0, axes=2, sharecam=0, bg="w")

Expand All @@ -21,12 +21,12 @@
act2 = Points(pts2, c="g").legend("set2")
act3 = Points(pts3, c="b").legend("set3")

vp.show([act1, act2, act3], at=0)
vp.show(act1, act2, act3, at=0)

# find best alignment among the n sets of Points,
# return an Assembly formed by the aligned sets
aligned = procrustes([act1, act2, act3])
aligned = alignProcrustes([act1, act2, act3])

# print(aligned.info['transform'])

vp.show([aligned, Text(__doc__)], at=1, interactive=1)
vp.show(aligned, Text(__doc__), at=1, interactive=1)
2 changes: 1 addition & 1 deletion examples/basic/bgImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
a1 = load(datadir+"shapes/flamingo.3ds").rotateX(-90)
a2 = Polygon()

vp.show([a1, doc], at=0)
vp.show(a1, doc, at=0)

vp.backgroundRenderer.GetActiveCamera().Zoom(2.5)

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
b3 = booleanOperation(s1, "minus", s2, c=None).legend("minus")

# show the result in 4 different subwindows 0->3
vp.show([s1, s2], at=0)
vp.show(s1, s2, at=0)
vp.show(b1, at=1)
vp.show(b2, at=2)
vp.show(b3, at=3)
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
# find back their identity through clustering
cl = cluster(pts, radius=0.1) # returns a vtkAssembly

show([cl, Text(__doc__)], axes=1, verbose=0)
show(cl, Text(__doc__), axes=1, verbose=0)
2 changes: 1 addition & 1 deletion examples/basic/connVtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
apt = Point(s.getPoint(index), c="r", r=15)
cpts = Points(vtxs, c="blue", r=15)

show([s, apt, cpts, Text(__doc__)], verbose=False)
show(s, apt, cpts, Text(__doc__), verbose=False)
4 changes: 2 additions & 2 deletions examples/basic/delaunay2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
cents = d1.cellCenters()
ap = Points(cents).legend("cell centers")

vp.show([d0, d1], at=0) # NB: d0 and d1 are slightly different
vp.show([d1, ap], at=1, interactive=1)
vp.show(d0, d1, at=0) # NB: d0 and d1 are slightly different
vp.show(d1, ap, at=1, interactive=1)
2 changes: 1 addition & 1 deletion examples/basic/fillholes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

doc = Text(__doc__)

show([a, b, doc], elevation=-70)
show(a, b, doc, elevation=-70)
4 changes: 2 additions & 2 deletions examples/basic/glyphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
scaleByVectorSize=True,
)

show([s, gsphere1, t], at=0, N=2, verbose=0)
show(s, gsphere1, t, at=0, N=2, verbose=0)


#######################################
gly2 = load(datadir+"shuttle.obj").rotateY(180).scale(0.02)

gsphere2 = Glyph(s, gly2, orientationArray="normals")

show([s, gsphere2], at=1, interactive=1)
show(s, gsphere2, at=1, interactive=1)
12 changes: 8 additions & 4 deletions examples/basic/histo2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
2D histogram with hexagonal binning.
"""
print(__doc__)
from vtkplotter import Plotter, histogram2D, Points
from vtkplotter import Plotter, histogram2D, Points, Latex
import numpy as np

vp = Plotter(axes=1, verbose=0, bg="w")
Expand All @@ -14,8 +14,12 @@
x = np.random.randn(N) * 1.0
y = np.random.randn(N) * 1.5

vp.add(histogram2D(x, y, c="dr", bins=15, fill=False))
histo = histogram2D(x, y, c="dr", bins=15, fill=False)

vp.add(Points([x, y, np.zeros(N)], c="black", alpha=0.1))
pts = Points([x, y, np.zeros(N)], c="black", alpha=0.1)

vp.show(viewup="z")
f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}{2 \sigma_{y}^{2}}\right)\right)'

formula = Latex(f, c='k', s=2).rotateZ(90).pos(5,-2,1)

vp.show(histo, pts, formula, viewup="z")
2 changes: 1 addition & 1 deletion examples/basic/largestregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
act2 = extractLargestRegion(act1).color("b")
printc("area2 =", act2.area(), c="b")

show([act1, Text(__doc__)], at=0, shape=(2, 1))
show(act1, Text(__doc__), at=0, shape=(2, 1))
show(act2, at=1, zoom=1.2, interactive=1)
18 changes: 18 additions & 0 deletions examples/basic/latex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from vtkplotter import Latex, Cube, Point, show

# https://matplotlib.org/tutorials/text/mathtext.html

latex1 = r'x= \frac{ - b \pm \sqrt {b^2 - 4ac} }{2a}'
latex2 = r'$\mathcal{A}\mathrm{sin}(2 \omega t)$'
latex3 = r'I(Y | X)=\sum_{x \in \mathcal{X}, y \in \mathcal{Y}} p(x, y) \log \left(\frac{p(x)}{p(x, y)}\right)'
latex4 = r'\Gamma_{\epsilon}(x)=\left[1-e^{-2 \pi \epsilon}\right]^{1-x} \prod_{n=0}^{\infty} \frac{1-\exp (-2 \pi \epsilon(n+1))}{1-\exp (-2 \pi \epsilon(x+n))}'
latex5 = r'\left( \begin{array}{l}{c t^{\prime}} \\ {x^{\prime}} \\ {y^{\prime}} \\ {z^{\prime}}\end{array}\right)=\left( \begin{array}{cccc}{\gamma} & {-\gamma \beta} & {0} & {0} \\ {-\gamma \beta} & {\gamma} & {0} & {0} \\ {0} & {0} & {1} & {0} \\ {0} & {0} & {0} & {1}\end{array}\right) \left( \begin{array}{l}{c t} \\ {x} \\ {y} \\ {z}\end{array}\right)'
latex6 = r'\mathrm{CO}_{2}+6 \mathrm{H}_{2} \mathrm{O} \rightarrow \mathrm{C}_{6} \mathrm{H}_{12} \mathrm{O}_{6}+6 \mathrm{O}_{2}'
latex7 = r'x~\mathrm{(arb. units)}'

p = Point()
c = Cube().wire()

l = Latex(latex5, s=1, c='white', bg='', alpha=0.9, fromweb=False).addPos(4,0,-1)

show(p, c, l, axes=8)
2 changes: 1 addition & 1 deletion examples/basic/lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

vp = Plotter()

cow = vp.load(datadir+"cow.g", c="grey", alpha=0.7)
cow = vp.load(datadir+"cow.byu", c="grey", alpha=0.7)

vp.add(Plane(pos=[0, -3.6, 0], normal=[0, 1, 0], sx=20, texture="grass"))

Expand Down
Loading

0 comments on commit 1fa08f9

Please sign in to comment.