├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── bin ├── vtkconvert └── vtkplotter ├── docs ├── Makefile ├── README.rst ├── fenics_logo3d.py ├── fenics_mesh.py ├── fenics_poster.pdf ├── requirements.txt ├── sharpelab.py ├── source │ ├── _templates │ │ ├── breadcrumbs.html │ │ └── footer.html │ └── conf.py ├── vlogo.odp ├── vlogo.pdf ├── vlogo.png ├── vlogo_m.ico ├── vlogo_maketube.py └── vlogo_s.ico ├── examples ├── README.md ├── advanced │ ├── README.md │ ├── convexHull.ipynb │ ├── convexHull.py │ ├── cutAndCap.py │ ├── cutWithMesh.py │ ├── densifycloud.py │ ├── fatlimb.py │ ├── fitplanes.py │ ├── fitspheres1.py │ ├── fitspheres2.py │ ├── geodesic.py │ ├── interpolateField.py │ ├── interpolateScalar.py │ ├── mesh_smoothers.py │ ├── meshquality.py │ ├── moving_least_squares1D.py │ ├── moving_least_squares2D.py │ ├── moving_least_squares3D.py │ ├── projectsphere.py │ ├── quadratic_morphing.py │ ├── recosurface.py │ ├── skeletonize.py │ ├── splitmesh.py │ ├── thinplate.py │ ├── thinplate_grid.ipynb │ ├── thinplate_grid.py │ ├── thinplate_morphing.py │ └── thinplate_morphing_2d.py ├── basic │ ├── README.md │ ├── a_first_example.py │ ├── acollection.ipynb │ ├── acollection.py │ ├── align1.ipynb │ ├── align1.py │ ├── align2.ipynb │ ├── align2.py │ ├── align3.py │ ├── annotations.py │ ├── bgImage.py │ ├── boolean.py │ ├── buildmesh.ipynb │ ├── buildmesh.py │ ├── buttons.py │ ├── carcrash.py │ ├── closewindow.py │ ├── clustering.ipynb │ ├── clustering.py │ ├── colorMeshCells.py │ ├── colorcubes.py │ ├── colormaps.py │ ├── connCells.py │ ├── connVtx.ipynb │ ├── connVtx.py │ ├── customAxes.py │ ├── cutter.py │ ├── delaunay2d.py │ ├── deleteMeshPoints.py │ ├── distance2mesh.ipynb │ ├── distance2mesh.py │ ├── fillholes.py │ ├── fitline.ipynb │ ├── fitline.py │ ├── flatarrow.py │ ├── fonts.py │ ├── fxy.ipynb │ ├── fxy.py │ ├── glyphs.py │ ├── glyphs_arrows.py │ ├── histo2D.py │ ├── ids.py │ ├── interactionstyle.py │ ├── isolines.py │ ├── keypress.py │ ├── largestregion.py │ ├── latex.py │ ├── lightings.py │ ├── lights.py │ ├── lorenz.py │ ├── manypoints.py │ ├── manyspheres.py │ ├── markpoint.py │ ├── mesh_alphas.py │ ├── mesh_bands.py │ ├── mesh_coloring.py │ ├── mesh_custom.py │ ├── mesh_map2cell.py │ ├── mesh_modify.py │ ├── mesh_sharemap.py │ ├── mesh_threshold.py │ ├── mirror.ipynb │ ├── mirror.py │ ├── mouseclick.py │ ├── multiblocks.py │ ├── multiwindows.py │ ├── pca.ipynb │ ├── pca.py │ ├── ribbon.py │ ├── rotateImage.py │ ├── shadow.ipynb │ ├── shadow.py │ ├── shrink.ipynb │ ├── shrink.py │ ├── silhouette.py │ ├── sliders.py │ ├── sliders3d.py │ ├── specular.py │ ├── surfIntersect.py │ ├── text_just.py │ ├── texturecubes.py │ ├── trail.py │ └── tube.py ├── data ├── notebooks │ ├── README.md │ ├── draw_points.ipynb │ ├── embryo.ipynb │ └── sphere.ipynb ├── other │ ├── README.md │ ├── colorpalette.py │ ├── create_logo.py │ ├── dolfin │ │ ├── README.md │ │ ├── ascalarbar.py │ │ ├── awefem.py │ │ ├── calc_surface_area.py │ │ ├── collisions.py │ │ ├── curl2d.py │ │ ├── demo_cahn-hilliard.ipynb │ │ ├── demo_cahn-hilliard.py │ │ ├── demo_submesh.ipynb │ │ ├── demo_submesh.py │ │ ├── elasticbeam.ipynb │ │ ├── elasticbeam.py │ │ ├── elastodynamics.py │ │ ├── ex01_show-mesh.py │ │ ├── ex02_tetralize-mesh.py │ │ ├── ex03_poisson.ipynb │ │ ├── ex03_poisson.py │ │ ├── ex04_mixed-poisson.ipynb │ │ ├── ex04_mixed-poisson.py │ │ ├── ex05_non-matching-meshes.py │ │ ├── ex06_elasticity1.py │ │ ├── ex06_elasticity2.ipynb │ │ ├── ex06_elasticity2.py │ │ ├── ex07_stokes-iterative.ipynb │ │ ├── ex07_stokes-iterative.py │ │ ├── ft02_poisson_membrane.ipynb │ │ ├── ft02_poisson_membrane.py │ │ ├── ft04_heat_gaussian.py │ │ ├── ft07_navier_stokes_channel.py │ │ ├── ft08_navier_stokes_cylinder.py │ │ ├── ft09_reaction_system.py │ │ ├── heatconv.py │ │ ├── magnetostatics.ipynb │ │ ├── magnetostatics.py │ │ ├── markmesh.ipynb │ │ ├── markmesh.py │ │ ├── navier-stokes_lshape.py │ │ ├── noplot │ │ │ ├── README.md │ │ │ ├── ex01_show-mesh.py │ │ │ ├── ex02_tetralize-mesh.py │ │ │ ├── ex03_poisson.py │ │ │ ├── ex04_mixed-poisson.py │ │ │ ├── ex05_non-matching-meshes.py │ │ │ ├── ex06_elasticity1.py │ │ │ ├── ex06_elasticity2.py │ │ │ └── ex07_stokes-iterative.py │ │ ├── pi_estimate.py │ │ ├── run_all.sh │ │ ├── scalemesh.py │ │ ├── stokes.ipynb │ │ ├── stokes.py │ │ ├── stokes2.py │ │ ├── submesh_boundary.ipynb │ │ ├── submesh_boundary.py │ │ ├── turing_pattern.py │ │ └── wavy_1d.py │ ├── downloading.py │ ├── export_numpy.py │ ├── export_x3d.py │ ├── icon.py │ ├── inset.py │ ├── makeVideo.py │ ├── menger_fractal.ipynb │ ├── menger_fractal.py │ ├── printc.ipynb │ ├── printc.py │ ├── qt_window.py │ ├── qt_window_split.py │ ├── remesh_ACVD.py │ ├── remesh_meshfix.py │ ├── save_as_numpy.py │ ├── self_org_maps2d.py │ ├── self_org_maps3d.py │ ├── sierpinski.ipynb │ ├── sierpinski.py │ ├── spherical_harmonics1.py │ ├── spherical_harmonics2.py │ ├── tf_learn_embryo.py │ ├── tf_learn_volume.py │ ├── trimesh │ │ ├── README.md │ │ ├── first_example.ipynb │ │ ├── first_example.py │ │ ├── nearest.py │ │ ├── ray.ipynb │ │ ├── ray.py │ │ ├── run_all.sh │ │ ├── section.ipynb │ │ ├── section.py │ │ ├── shortest.ipynb │ │ └── shortest.py │ ├── value-iteration.ipynb │ ├── value-iteration.py │ └── voronoi3d.py ├── run_all.sh ├── simulations │ ├── README.md │ ├── airplanes.py │ ├── aspring.py │ ├── brownian2D.py │ ├── cell.py │ ├── cell_main.py │ ├── doubleslit.py │ ├── gas.py │ ├── gray_scott.ipynb │ ├── gyroscope1.py │ ├── gyroscope2.py │ ├── hanoi3d.py │ ├── multiple_pendulum.py │ ├── particle_simulator.py │ ├── pendulum.py │ ├── run_all.sh │ ├── tunnelling1.py │ ├── tunnelling2.py │ ├── turing.py │ ├── volterra.ipynb │ ├── volterra.py │ └── wave_equation.py ├── tutorial.ipynb ├── tutorial.py └── volumetric │ ├── README.md │ ├── create_imagedata.ipynb │ ├── erode_dilate.py │ ├── euclDist.py │ ├── interpolateVolume.ipynb │ ├── interpolateVolume.py │ ├── isosurfaces1.py │ ├── isosurfaces2.ipynb │ ├── isosurfaces2.py │ ├── legosurface.ipynb │ ├── legosurface.py │ ├── lowpassfilter.py │ ├── mesh2volume.py │ ├── numpy2volume.ipynb │ ├── numpy2volume.py │ ├── office.ipynb │ ├── office.py │ ├── office_furniture.py │ ├── pointDensity.py │ ├── probeLine.ipynb │ ├── probeLine.py │ ├── probePlane.py │ ├── probePoints.py │ ├── readVolume.py │ ├── readVolumeAsIsoSurface.py │ ├── read_vti.py │ ├── streamlines1.py │ ├── streamlines2.ipynb │ ├── streamlines2.py │ ├── streamribbons.ipynb │ ├── streamribbons.py │ ├── tensors.ipynb │ ├── tensors.py │ ├── tet_mesh_ugrid.py │ ├── vol2points.py │ ├── volumeFromMesh.py │ └── volumeOperations.py ├── requirements.txt ├── setup.py ├── vtkplotter.desktop └── vtkplotter ├── __init__.py ├── actors.py ├── addons.py ├── analysis.py ├── colors.py ├── data ├── 250.vtk ├── 270.vtk ├── 270_flank.vtk ├── 270_rim.vtk ├── 290.neutral ├── 290.vtk ├── 290.xml.gz ├── SainteHelens.dem ├── SuperQuadric.vtp ├── airboat.vtk ├── atc.ply ├── beethoven.ply ├── bunny.obj ├── cessna.vtk ├── circle.xml.gz ├── clown.facet ├── combq.bin ├── combxyz.bin ├── cow.byu ├── cow.vtk ├── cube.off ├── dodecahedron.vtk ├── dolfin_cube.h5 ├── dolfin_cube.xdmf ├── dolfin_fine.xml ├── dolfin_fine_subdomains.xml.gz ├── embryo.slc ├── embryo.tif ├── fenics.xml.gz ├── flamingo.3ds ├── foolf.nrrd ├── grasshop.wrl ├── head.vti ├── icosahedron.vtk ├── images │ ├── airplanes_frames │ │ ├── frame_00_delay-0.08s.jpg │ │ ├── frame_01_delay-0.08s.jpg │ │ ├── frame_02_delay-0.08s.jpg │ │ ├── frame_03_delay-0.08s.jpg │ │ ├── frame_04_delay-0.08s.jpg │ │ ├── frame_05_delay-0.08s.jpg │ │ ├── frame_06_delay-0.08s.jpg │ │ ├── frame_07_delay-0.08s.jpg │ │ ├── frame_08_delay-0.08s.jpg │ │ ├── frame_09_delay-0.08s.jpg │ │ ├── frame_10_delay-0.12s.jpg │ │ ├── frame_11_delay-0.08s.jpg │ │ ├── frame_12_delay-0.08s.jpg │ │ ├── frame_13_delay-0.08s.jpg │ │ ├── frame_14_delay-0.08s.jpg │ │ ├── frame_15_delay-0.08s.jpg │ │ ├── frame_16_delay-0.08s.jpg │ │ ├── frame_17_delay-0.08s.jpg │ │ ├── frame_18_delay-0.08s.jpg │ │ ├── frame_19_delay-0.08s.jpg │ │ ├── frame_20_delay-0.08s.jpg │ │ ├── frame_21_delay-0.08s.jpg │ │ ├── frame_22_delay-0.12s.jpg │ │ ├── frame_23_delay-0.08s.jpg │ │ ├── frame_24_delay-0.08s.jpg │ │ ├── frame_25_delay-0.08s.jpg │ │ ├── frame_26_delay-0.08s.jpg │ │ ├── frame_27_delay-0.08s.jpg │ │ ├── frame_28_delay-0.08s.jpg │ │ ├── frame_29_delay-0.08s.jpg │ │ ├── frame_30_delay-0.08s.jpg │ │ ├── frame_31_delay-0.08s.jpg │ │ ├── frame_32_delay-0.08s.jpg │ │ ├── frame_33_delay-0.08s.jpg │ │ ├── frame_34_delay-0.12s.jpg │ │ ├── frame_35_delay-0.08s.jpg │ │ ├── frame_36_delay-0.08s.jpg │ │ ├── frame_37_delay-0.08s.jpg │ │ ├── frame_38_delay-0.08s.jpg │ │ ├── frame_39_delay-0.08s.jpg │ │ ├── frame_40_delay-0.08s.jpg │ │ ├── frame_41_delay-0.08s.jpg │ │ ├── frame_42_delay-0.08s.jpg │ │ ├── frame_43_delay-0.08s.jpg │ │ ├── frame_44_delay-0.08s.jpg │ │ └── frame_45_delay-0.08s.jpg │ ├── dog.jpg │ ├── embl_logo.jpg │ ├── fenics_logo.png │ ├── gyro_formulas.png │ ├── schrod.png │ ├── tropical.jpg │ ├── vlogo_large.png │ ├── vlogo_medium.png │ ├── vlogo_small.png │ ├── vlogo_small_dark.png │ ├── vlogo_tube.png │ ├── vlogo_tube_dark.png │ ├── vtk_logo.png │ └── wave_wiki.png ├── lamp.vtk ├── lego_beam.xml.gz ├── limb.pcd ├── limb_ugrid.vtk ├── lshape.xml.gz ├── magnolia.vtk ├── man.vtk ├── motor.byu ├── mug.ply ├── octahedron.vtk ├── office.binary.vtk ├── origami_train.stl ├── political.vtp ├── porsche.ply ├── pulley.vtu ├── pulley.xdmf ├── pumpkin.vtk ├── ring.gmsh ├── sextant.wrl ├── shark.ply ├── shuttle.obj ├── shuttle.stl ├── skyscraper.obj ├── spider.ply ├── structgrid.vts ├── teapot.vtk ├── teapot.xyz ├── teddy.vtk ├── timecourse1d.npy ├── timecourse1d │ ├── reference_249.vtk │ ├── reference_250.vtk │ ├── reference_251.vtk │ ├── reference_252.vtk │ ├── reference_253.vtk │ ├── reference_254.vtk │ ├── reference_255.vtk │ ├── reference_256.vtk │ ├── reference_257.vtk │ ├── reference_258.vtk │ ├── reference_259.vtk │ ├── reference_260.vtk │ ├── reference_261.vtk │ ├── reference_262.vtk │ ├── reference_263.vtk │ ├── reference_264.vtk │ ├── reference_265.vtk │ ├── reference_266.vtk │ ├── reference_267.vtk │ ├── reference_268.vtk │ ├── reference_269.vtk │ ├── reference_270.vtk │ ├── reference_271.vtk │ ├── reference_272.vtk │ ├── reference_273.vtk │ ├── reference_274.vtk │ ├── reference_275.vtk │ ├── reference_276.vtk │ ├── reference_277.vtk │ ├── reference_278.vtk │ ├── reference_279.vtk │ ├── reference_280.vtk │ ├── reference_281.vtk │ ├── reference_282.vtk │ ├── reference_283.vtk │ ├── reference_284.vtk │ ├── reference_285.vtk │ ├── reference_286.vtk │ ├── reference_287.vtk │ ├── reference_288.vtk │ ├── reference_289.vtk │ ├── reference_290.vtk │ ├── reference_291.vtk │ ├── reference_292.vtk │ ├── reference_293.vtk │ ├── reference_294.vtk │ ├── reference_295.vtk │ ├── reference_296.vtk │ ├── reference_297.vtk │ ├── reference_298.vtk │ ├── reference_299.vtk │ ├── reference_300.vtk │ ├── reference_301.vtk │ ├── reference_302.vtk │ ├── reference_303.vtk │ ├── reference_304.vtk │ ├── reference_305.vtk │ ├── reference_306.vtk │ ├── reference_307.vtk │ ├── reference_308.vtk │ ├── reference_309.vtk │ ├── reference_310.vtk │ ├── reference_311.vtk │ ├── reference_312.vtk │ ├── reference_313.vtk │ ├── reference_314.vtk │ ├── reference_315.vtk │ ├── reference_316.vtk │ ├── reference_317.vtk │ ├── reference_318.vtk │ ├── reference_319.vtk │ ├── reference_320.vtk │ ├── reference_321.vtk │ ├── reference_322.vtk │ ├── reference_323.vtk │ ├── reference_324.vtk │ ├── reference_325.vtk │ ├── reference_326.vtk │ ├── reference_327.vtk │ ├── reference_328.vtk │ ├── reference_329.vtk │ ├── reference_330.vtk │ ├── reference_331.vtk │ ├── reference_332.vtk │ ├── reference_333.vtk │ ├── reference_334.vtk │ ├── reference_335.vtk │ ├── reference_336.vtk │ ├── reference_337.vtk │ ├── reference_338.vtk │ ├── reference_339.vtk │ ├── reference_340.vtk │ ├── reference_341.vtk │ ├── reference_342.vtk │ ├── reference_343.vtk │ ├── reference_344.vtk │ ├── reference_345.vtk │ ├── reference_346.vtk │ ├── reference_347.vtk │ ├── reference_348.vtk │ ├── reference_349.vtk │ ├── reference_350.vtk │ ├── reference_351.vtk │ ├── reference_352.vtk │ ├── reference_353.vtk │ ├── reference_354.vtk │ ├── reference_355.vtk │ ├── reference_356.vtk │ ├── reference_357.vtk │ ├── reference_358.vtk │ ├── reference_359.vtk │ ├── reference_360.vtk │ ├── reference_361.vtk │ ├── reference_362.vtk │ ├── reference_363.vtk │ ├── reference_364.vtk │ ├── reference_365.vtk │ ├── reference_366.vtk │ ├── reference_367.vtk │ ├── reference_368.vtk │ ├── reference_369.vtk │ ├── reference_370.vtk │ ├── reference_371.vtk │ ├── reference_372.vtk │ ├── reference_373.vtk │ ├── reference_374.vtk │ ├── reference_375.vtk │ ├── reference_376.vtk │ ├── reference_377.vtk │ ├── reference_378.vtk │ ├── reference_379.vtk │ ├── reference_380.vtk │ └── reference_381.vtk ├── turing_data.npy ├── ugrid.vtk └── vase.vti ├── docs.py ├── dolfin.py ├── fonts ├── ALDORA.ttf ├── Ageo.ttf ├── CallingCode.ttf ├── Godsway.ttf ├── Gula.ttf ├── ImpactLabel.ttf ├── Komiko.ttf ├── MidnightDrive.ttf ├── Militech.ttf ├── MonaShark.ttf ├── Montserrat.ttf ├── MyDisplaySt.ttf ├── PointedLaidSt.ttf ├── SchoolTeacher.ttf ├── SpecialElite.ttf ├── lamborgini.ttf └── licenses │ ├── ALDORA - License.txt │ ├── Ageo - License.txt │ ├── CallingCode License.txt │ ├── Gula - License.txt │ ├── Impact Label License.txt │ ├── Midnight_Drive License.txt │ ├── Militech - licence.txt │ ├── Mona Shark - License.txt │ ├── Montserrat - License.txt │ ├── My Display St - License.txt │ ├── Pointed Laid St - License.txt │ └── SpecialElite - LICENSE.txt ├── plotter.py ├── settings.py ├── shapes.py ├── textures ├── aqua.jpg ├── blue.jpg ├── bricks.jpg ├── earth.ppm ├── fibers.jpg ├── gold1.jpg ├── gold2.jpg ├── grass.jpg ├── greenfloor.jpg ├── greentiles.jpg ├── grid.jpg ├── grunge1.jpg ├── grunge2.jpg ├── indented.jpg ├── ivy.jpg ├── leather1.jpg ├── leather2.jpg ├── marble.jpg ├── marble2.jpg ├── marble3.jpg ├── marble4.jpg ├── masonry.jpg ├── metal1.jpg ├── metal2.jpg ├── metalfloor1.jpg ├── metalfloor2.jpg ├── paper.jpg ├── tissue1.jpg ├── tissue2.jpg ├── water.jpg ├── white1.jpg ├── white2.jpg ├── white3.jpg ├── white4.jpg ├── wood1.jpg ├── wood2.jpg ├── wood3.jpg ├── wood4.jpg ├── wood5.jpg ├── wood6.jpg ├── wood7.jpg ├── wood8.jpg └── wood9.jpg ├── utils.py ├── version.py └── vtkio.py /.gitignore: -------------------------------------------------------------------------------- 1 | *pyc 2 | .DS_Store 3 | 4 | .ipynb 5 | examples/.ipynb 6 | examples/notebooks/.ipynb 7 | examples/basic/.ipynb 8 | examples/volumetric/.ipynb 9 | examples/advanced/.ipynb 10 | examples/other/.ipynb 11 | examples/other/dolfin/.ipynb 12 | 13 | docs/build/ 14 | docs/source/content 15 | docs/source/index.rst 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Marco Musy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include vtkplotter/* 2 | include vtkplotter/textures/* 3 | include vtkplotter/fonts/* 4 | include vtkplotter/fonts/licenses/* 5 | include vtkplotter/data/* 6 | include vtkplotter/data/images/* 7 | include vtkplotter/data/timecourse1d/* 8 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = omfvtk 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/fenics_mesh.py: -------------------------------------------------------------------------------- 1 | from vtkplotter import * 2 | 3 | mytext='FEniCS' 4 | 5 | tf = Text(mytext, pos=[0,0,0], depth=0.5).triangle().subdivide(3).clean(0.0025) 6 | 7 | bx = Box([1.35, 0.27, -0.0], 5.8, 1.5, .2).triangle().subdivide(4, method=1).clean(0.0025) 8 | 9 | show(tf, bx) 10 | 11 | printc('implicitModeller', mytext, "this takes time") 12 | imp = implicitModeller(mergeActors(tf, bx), 13 | distance=0.04, 14 | outer=True, 15 | # res=[50,20,10], 16 | res=[110,40,20], 17 | bounds=[-1.0, 10.0, -1.0, 2.0, -.5, .5], 18 | maxdist=0.25, 19 | ) 20 | 21 | imp.write(mytext+'.stl', binary=False) 22 | show(imp) 23 | 24 | #### tetralize 25 | import mshr 26 | import dolfin 27 | 28 | surface = mshr.Surface3D(mytext+'.stl') 29 | polyhedral_domain = mshr.CSGCGALDomain3D(surface) 30 | dolfin.info(polyhedral_domain, True) 31 | 32 | generator = mshr.CSGCGALMeshGenerator3D() 33 | generator.parameters["mesh_resolution"] = 40.0 34 | mesh = generator.generate(polyhedral_domain) 35 | 36 | dolfin.File(mytext + ".xml") << mesh 37 | printc('saved', mytext + ".xml") 38 | 39 | #from vtkplotter.dolfin import plot 40 | #plot(mesh) 41 | -------------------------------------------------------------------------------- /docs/fenics_poster.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/docs/fenics_poster.pdf -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | Sphinx>=1.7.5 2 | sphinx-autobuild>=0.7.1 3 | sphinx-rtd-theme>=0.4.0 4 | sphinxcontrib-napoleon>=0.6.1 5 | sphinxcontrib-websupport>=1.1.0 6 | gendocs>=0.3.1 7 | numpy 8 | vtk 9 | -------------------------------------------------------------------------------- /docs/sharpelab.py: -------------------------------------------------------------------------------- 1 | """ 2 | Create an animated logo. 3 | """ 4 | from vtkplotter import * 5 | 6 | exa = Polygon().scale(4.1).pos(5.25, 4.8, 0).off() 7 | box = Box([10, 5, 0], 20, 20, 15).alpha(0) 8 | his = histogram2D([-1, 1], [-1, 1]).getActors() 9 | 10 | exah, cmh = [], [] 11 | for h in his: 12 | cm = h.centerOfMass() 13 | if exa.isInside(cm): 14 | h.shrink(0.94)#.addShadow(z=-1) 15 | exah.append(h) 16 | cmh.append(cm) 17 | exah[13].c('red') 18 | 19 | v1 = vector(9.1, 5.0, -0.1) 20 | v2 = vector(9.2, 3.4, -0.1) 21 | t1 = Text("Sharpe Lab", v1, c="k").scale([.999,1,1]) 22 | t2 = Text("EMBL Barcelona", v2, c="dg") 23 | 24 | Plotter(bg="w", axes=0, interactive=0) 25 | def run(rng): 26 | for ti in rng: 27 | t = ti / 100. 28 | for j, h in enumerate(exah): 29 | cx, cy, _ = cmh[j] - [4,5,0] 30 | h.pos(cos(cy*t) *t*2, sin(cx*t)*t*2, t*cx/2).alpha((1-t)**3) 31 | #h.shadow.alpha(t**4) 32 | t1.alpha((1-t)**4) 33 | t2.scale([(1-t)*0.67, (1-t)*0.75, (1-t)*0.75]).alpha((1-t)**2) 34 | show(box, exa, exah, t1, t2, resetcam=0, elevation=0) 35 | import time 36 | run(reversed(range(100))) 37 | time.sleep(2) 38 | run(range(100)) 39 | time.sleep(.2) 40 | run(reversed(range(100))) 41 | interactive() 42 | -------------------------------------------------------------------------------- /docs/source/_templates/breadcrumbs.html: -------------------------------------------------------------------------------- 1 | {%- extends "sphinx_rtd_theme/breadcrumbs.html" %} 2 | 3 | {% block breadcrumbs_aside %} 4 | {% endblock %} 5 | -------------------------------------------------------------------------------- /docs/source/_templates/footer.html: -------------------------------------------------------------------------------- 1 | {% extends "!footer.html" %} 2 | 3 | {% block extrafooter %} 4 | 5 | {{ super() }} 6 | 7 |
12 | 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /docs/vlogo.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/docs/vlogo.odp -------------------------------------------------------------------------------- /docs/vlogo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/docs/vlogo.pdf -------------------------------------------------------------------------------- /docs/vlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/docs/vlogo.png -------------------------------------------------------------------------------- /docs/vlogo_m.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/docs/vlogo_m.ico -------------------------------------------------------------------------------- /docs/vlogo_maketube.py: -------------------------------------------------------------------------------- 1 | ''' 2 | logo 3 | ''' 4 | from vtkplotter import * 5 | 6 | ln = [ [sin(x), cos(x), x/2] for x in arange(0,9, 0.1)] 7 | N = len(ln) 8 | 9 | vp = Plotter(verbose=0, axes=0) 10 | vp.camera.SetPosition( [-0.088, 6.198, 12.757] ) 11 | vp.camera.SetFocalPoint( [-0.105, 0.105, 2.209] ) 12 | vp.camera.SetViewUp( [-0.294, -0.827, 0.478] ) 13 | vp.camera.SetDistance( 12.181 ) 14 | vp.camera.SetClippingRange( [6.344, 19.557] ) 15 | 16 | rads = [ 0.3*(cos(6.*ir/N))**2+0.1 for ir in range(N) ] 17 | cols = [ -i for i in range(N)] 18 | cols = makeBands(cols, 5) # make 5 color bins 19 | t = Tube(ln, r=rads, c=cols, res=24) 20 | vp.show(t) 21 | -------------------------------------------------------------------------------- /docs/vlogo_s.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/docs/vlogo_s.ico -------------------------------------------------------------------------------- /examples/advanced/convexHull.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "application/vnd.jupyter.widget-view+json": { 11 | "model_id": "5285de33fccc4d3aaae6e58bc6073e63", 12 | "version_major": 2, 13 | "version_minor": 0 14 | }, 15 | "text/plain": [ 16 | "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, …" 17 | ] 18 | }, 19 | "metadata": {}, 20 | "output_type": "display_data" 21 | } 22 | ], 23 | "source": [ 24 | "from vtkplotter import *\n", 25 | "\n", 26 | "spid = load(datadir+\"spider.ply\")\n", 27 | "\n", 28 | "scalars = spid.coordinates()[:,2] # take the z coordinates of vertices as scalars\n", 29 | "\n", 30 | "spid.pointColors(scalars, cmap='afmhot_r') # use those scalar to color the mesh\n", 31 | "\n", 32 | "chull = convexHull(spid).c(\"black\").alpha(0.2).wireframe()\n", 33 | "\n", 34 | "show(spid, chull)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [] 43 | } 44 | ], 45 | "metadata": { 46 | "kernelspec": { 47 | "display_name": "Python 3", 48 | "language": "python", 49 | "name": "python3" 50 | }, 51 | "language_info": { 52 | "codemirror_mode": { 53 | "name": "ipython", 54 | "version": 3 55 | }, 56 | "file_extension": ".py", 57 | "mimetype": "text/x-python", 58 | "name": "python", 59 | "nbconvert_exporter": "python", 60 | "pygments_lexer": "ipython3", 61 | "version": "3.6.7" 62 | } 63 | }, 64 | "nbformat": 4, 65 | "nbformat_minor": 2 66 | } 67 | -------------------------------------------------------------------------------- /examples/advanced/convexHull.py: -------------------------------------------------------------------------------- 1 | """ 2 | Create a 3D Delaunay triangulation of input points. 3 | """ 4 | from vtkplotter import * 5 | 6 | spid = load(datadir+"spider.ply", c="brown") 7 | 8 | ch = convexHull(spid.coordinates()).alpha(0.2) 9 | 10 | show(spid, ch, Text(__doc__), axes=1) 11 | -------------------------------------------------------------------------------- /examples/advanced/cutAndCap.py: -------------------------------------------------------------------------------- 1 | """ 2 | Cut a paraboloid with a mesh and cap the holes. 3 | """ 4 | from vtkplotter import * 5 | 6 | p1 = Paraboloid().rotateX(90) 7 | 8 | cutmesh = Hyperboloid().scale(0.4).wireframe(True).alpha(0.1) 9 | 10 | show(p1, cutmesh, at=0, N=2, axes=1, viewup="z") 11 | 12 | p2 = p1.clone().cutWithMesh(cutmesh) 13 | 14 | redcap = p2.cap(returnCap=True).color("r") # dark red cap only 15 | 16 | show(redcap, p2, Text(__doc__), at=1, interactive=1) 17 | -------------------------------------------------------------------------------- /examples/advanced/cutWithMesh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Cut a mesh with another mesh 3 | """ 4 | from vtkplotter import * 5 | 6 | embryo = load(datadir+"embryo.tif", threshold=30).normalize() 7 | txt = Text(__doc__, c='w', bg='lb') 8 | 9 | # mesh used to cut: 10 | msh = Ellipsoid().pos(0.8, 0.1, -0.3).scale(0.5).wireframe() 11 | 12 | # make a working copy and cut it with the ellipsoid 13 | cutembryo = embryo.clone().cutWithMesh(msh).backColor("t") 14 | 15 | show(embryo, msh, at=0, N=2, axes=1, viewup="z") 16 | show(cutembryo, txt, at=1, interactive=1) 17 | -------------------------------------------------------------------------------- /examples/advanced/densifycloud.py: -------------------------------------------------------------------------------- 1 | """Adds new points to an input point cloud. 2 | The new points are created in such a way that 3 | all points in any local neighborhood are 4 | within a target distance of one another. 5 | """ 6 | from vtkplotter import * 7 | import numpy as np 8 | np.random.seed(3) 9 | 10 | npts = 200 # nr. of points 11 | coords = np.random.rand(npts, 3) # range is [0, 1] 12 | scals = np.abs(coords[:, 2]) # let the scalar be the z of point itself 13 | 14 | apts = Points(coords, r=9).addPointScalars(scals, name='scals') 15 | 16 | densecloud = densifyCloud(apts, .05, closestN=10, maxIter=1) 17 | print(apts.N(), '->', densecloud.N()) 18 | 19 | ppp = Points(densecloud.coordinates()) 20 | show(apts, densecloud, Text(__doc__), axes=8) 21 | -------------------------------------------------------------------------------- /examples/advanced/fatlimb.py: -------------------------------------------------------------------------------- 1 | """ 2 | In this example we modify the mesh of a shape 3 | by moving the points along the normals to the surface 4 | and along the radius of a sphere centered at the center of mass. 5 | At each step we redefine the actor so that the normals are 6 | recalculated for the underlying polydata. 7 | """ 8 | from __future__ import division, print_function 9 | from vtkplotter import * 10 | 11 | settings.computeNormals = True # on object creation by default 12 | 13 | vp = Plotter(axes=0, verbose=0, bg="w") 14 | 15 | s = vp.load(datadir+"290.vtk", c="red") 16 | c = s.centerOfMass() 17 | vp += [Point(c), Text(__doc__, c="k")] 18 | 19 | Niter = 4 20 | for t in range(Niter): 21 | print("iteration", t) 22 | coords = s.coordinates() 23 | normals = s.normals() 24 | aves = s.averageSize() * 1.5 25 | 26 | for i in range(s.N()): 27 | n = normals[i] 28 | p = coords[i] 29 | q = versor(p - c) * aves + c # versor = unit vector 30 | dp = mag(q - p) 31 | alongn = n * dp 32 | alongr = q - p # bias normal 33 | newp = p + (alongn + alongr) / 2 / Niter 34 | s.setPoint(i, newp) 35 | 36 | # refresh actor, so polydata normals are recalculated 37 | s = s.clone() 38 | vp += s.alpha(0.1).color("gold").wireframe(True) #add into Plotter 39 | 40 | vp.show() 41 | -------------------------------------------------------------------------------- /examples/advanced/fitplanes.py: -------------------------------------------------------------------------------- 1 | """ 2 | In this example we fit a plane to regions of a surface defined by 3 | N points that are closest to a given point of the surface. 4 | For some of these point we show the fitting plane. 5 | Black points are the N points used for fitting. 6 | Green histogram is the distribution of residuals from the fitting. 7 | Both plane center and normal can be accessed from the 8 | attribute plane.info['center'] and plane.info['normal']. 9 | """ 10 | from vtkplotter import * 11 | 12 | vp = Plotter(verbose=0, axes=0, bg='w') 13 | 14 | s = vp.load(datadir+"cow.vtk").alpha(0.3).subdivide() # remesh 15 | 16 | variances = [] 17 | for i, p in enumerate(s.coordinates()): 18 | if i % 100: 19 | continue # skip most points 20 | pts = s.closestPoint(p, N=12) # find the N closest points to p 21 | plane = fitPlane(pts) # find the fitting plane 22 | vp += plane 23 | vp += Points(pts) # blue points 24 | vp += Point(p, r=5, c="red") # mark in red the current point 25 | cn, v = plane.info["center"], plane.info["normal"] 26 | vp += Arrow(cn, cn + v / 15.0, c="g") 27 | variances.append(plane.info["variance"]) 28 | 29 | vp += histogram(variances, title="variance", c="g") 30 | 31 | vp += Text(__doc__, pos=1) 32 | vp.show(viewup="z") 33 | -------------------------------------------------------------------------------- /examples/advanced/fitspheres1.py: -------------------------------------------------------------------------------- 1 | """ 2 | In this example we fit spheres to a region of a surface defined by 3 | N points that are closest to a given point of the surface. 4 | For some of these point we show the fitting sphere. 5 | Red lines join the center of the sphere to the surface point. 6 | Blue points are the N points used for fitting. 7 | Green histogram is the distribution of residuals from the fitting. 8 | Red histogram is the distribution of the curvatures (1/r**2). 9 | Fitted radius can be accessed from actor.info['radius']. 10 | """ 11 | from __future__ import division, print_function 12 | from vtkplotter import * 13 | 14 | vp = Plotter(verbose=0, axes=0, bg='white') 15 | 16 | # load mesh and increase by a lot (N=2) the nr of surface vertices 17 | s = vp.load(datadir+"cow.vtk").alpha(0.3).subdivide(N=2) 18 | 19 | reds, invr = [], [] 20 | for i, p in enumerate(s.coordinates()): 21 | if i % 1000: 22 | continue # skip most points 23 | pts = s.closestPoint(p, N=16) # find the N closest points to p 24 | sph = fitSphere(pts).alpha(0.05) # find the fitting sphere 25 | if sph is None: 26 | continue # may fail if all points sit on a plane 27 | vp += sph 28 | vp += Points(pts) 29 | vp += Line(sph.info["center"], p, lw=2) 30 | reds.append(sph.info["residue"]) 31 | invr.append(1 / sph.info["radius"] ** 2) 32 | 33 | vp += histogram(reds, title="residue", bins=12, c="g", pos=3) 34 | vp += histogram(invr, title="1/r**2", bins=12, c="r", pos=4) 35 | 36 | vp += Text(__doc__) 37 | vp.show(viewup="z") 38 | -------------------------------------------------------------------------------- /examples/advanced/fitspheres2.py: -------------------------------------------------------------------------------- 1 | """ 2 | For each point finds the 9 closest ones and fit a sphere 3 | color points based on the size of the sphere radius 4 | """ 5 | from __future__ import division, print_function 6 | from vtkplotter import * 7 | 8 | vp = Plotter(verbose=0, axes=0, bg="w") 9 | 10 | s = vp.load(datadir+"cow.vtk", alpha=0.3) # .subdivide() 11 | 12 | pts1, pts2, vals, cols = [], [], [], [] 13 | 14 | for i, p in enumerate(s.coordinates()): 15 | pts = s.closestPoint(p, N=12) # find the N closest points to p 16 | sph = fitSphere(pts) # find the fitting sphere 17 | if sph is None: 18 | continue 19 | 20 | value = sph.info["radius"] * 10 21 | color = colorMap(value, "jet", 0, 1) # map value to a RGB color 22 | n = versor(p - sph.info["center"]) # unit vector from sphere center to p 23 | vals.append(value) 24 | cols.append(color) 25 | pts1.append(p) 26 | pts2.append(p + n / 8) 27 | if not i % 500: 28 | print(i, "/", s.N()) 29 | 30 | vp += Points(pts1, c=cols) 31 | vp += Lines(pts1, pts2, c="black 0.2") 32 | vp += histogram(vals, title="values", bins=20, vrange=[0, 1]) 33 | vp += Text(__doc__, pos=1) 34 | 35 | vp.show() 36 | -------------------------------------------------------------------------------- /examples/advanced/geodesic.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dijkstra algorithm to compute the graph geodesic. 3 | 4 | Takes as input a polygonal mesh and performs 5 | a shortest path calculation 20 times. 6 | """ 7 | from vtkplotter import * 8 | 9 | s = Sphere(r=1.05, res=200).clean(0.005).wireframe().alpha(0.05) 10 | 11 | paths = [] 12 | for i in range(20): 13 | paths.append(geodesic(s, 500, i * 700)) 14 | # print(paths[-1].info['CumulativeWeights']) 15 | 16 | doc = Text(__doc__, c="w") 17 | 18 | show(s, Earth(lw=1), doc, paths, viewup="z") 19 | -------------------------------------------------------------------------------- /examples/advanced/interpolateScalar.py: -------------------------------------------------------------------------------- 1 | """ 2 | Use scipy to interpolate the value of a scalar known on a set of points 3 | on a new set of points where the scalar is not defined. 4 | Two interpolation methods are possible: Radial Basis Function, Nearest Point. 5 | """ 6 | from scipy.interpolate import Rbf, NearestNDInterpolator as Near 7 | import numpy as np 8 | 9 | # np.random.seed(0) 10 | 11 | 12 | # a small set of points for which the scalar is given 13 | x, y, z = np.random.rand(3, 20) 14 | 15 | scals = z # scalar value is just z component 16 | 17 | # build the interpolator 18 | itr = Rbf(x, y, z, scals) # Radial Basis Function interpolator 19 | # itr = Near(list(zip(x,y,z)), scals) # Nearest-neighbour interpolator 20 | 21 | # generate a new set of points 22 | t = np.linspace(0, 7, 100) 23 | xi, yi, zi = [np.sin(t) / 10 + 0.5, np.cos(t) / 5 + 0.5, (t - 1) / 5] # an helix 24 | 25 | # interpolate scalar values on the new set 26 | scalsi = itr(xi, yi, zi) 27 | 28 | 29 | from vtkplotter import Plotter, Points, Text 30 | 31 | vp = Plotter(axes=1, bg="w") 32 | vp += Points([x, y, z], r=10, alpha=0.5).pointColors(scals) 33 | vp += Points([xi, yi, zi]).pointColors(scalsi) 34 | vp += Text(__doc__, pos=1, c="dr") 35 | 36 | vp.show(viewup="z") 37 | -------------------------------------------------------------------------------- /examples/advanced/mesh_smoothers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Mesh smoothing with two different VTK methods. 3 | 4 | See also analogous Plotter method smoothMLS2D() 5 | in exammples/advanced/moving_least_squares2D.py 6 | """ 7 | print(__doc__) 8 | from vtkplotter import Plotter, datadir 9 | 10 | vp = Plotter(shape=(1, 3), axes=4) 11 | 12 | # Load a mesh and show it 13 | a0 = vp.load(datadir+"embryo.tif", threshold=True, c="v") 14 | vp.show(a0, at=0) 15 | 16 | # Adjust mesh using Laplacian smoothing 17 | a1 = a0.clone().smoothLaplacian().color("crimson").alpha(1).legend("laplacian") 18 | vp.show(a1, at=1) 19 | 20 | # Adjust mesh using a windowed sinc function interpolation kernel 21 | a2 = a0.clone().smoothWSinc().color("seagreen").alpha(1).legend("window sinc") 22 | vp.show(a2, at=2) 23 | 24 | vp.renderers[0].SetBackground(0.8, 1, 1) # set first renderer color 25 | vp.show(zoom=1.4, interactive=True) 26 | -------------------------------------------------------------------------------- /examples/advanced/meshquality.py: -------------------------------------------------------------------------------- 1 | """ 2 | Calculate functions of quality of the elements of a triangular mesh. 3 | """ 4 | print(__doc__) 5 | 6 | from vtkplotter import * 7 | 8 | a1 = meshQuality(Sphere()) 9 | a2 = meshQuality(load(datadir+"bunny.obj").normalize()) 10 | a3 = meshQuality(load(datadir+"motor.byu").normalize()) 11 | 12 | printHistogram(a2, title='bunny quality', c='g') # histo active scalars 13 | 14 | show(a1, a2, a3, N=3) 15 | -------------------------------------------------------------------------------- /examples/advanced/moving_least_squares1D.py: -------------------------------------------------------------------------------- 1 | """ 2 | This example shows how to use a variant of a 1 dimensional 3 | Moving Least Squares (MLS) algorithm to project a cloud 4 | of unordered points to become a smooth line. 5 | The parameter f controls the size of the local regression. 6 | If showNLines>0 an actor is built demonstrating the 7 | details of the regression for some random points 8 | """ 9 | from __future__ import division, print_function 10 | 11 | print(__doc__) 12 | from vtkplotter import * 13 | import numpy as np 14 | 15 | N = 6 # nr. of iterations 16 | 17 | # build some initial cloud of noisy points along a line 18 | pts = [ (sin(6*x), sin(2*x)/(x+1), cos(9*x)) for x in arange(0,1, .001)] 19 | #pts = [ (0, sin(x), cos(x)) for x in arange(0,6, .002) ] 20 | #pts = [(sqrt(x), sin(x), x/10) for x in arange(0, 16, 0.01)] 21 | 22 | pts += np.random.randn(len(pts), 3) /20 # add noise 23 | np.random.shuffle(pts) # make sure points are not ordered 24 | 25 | a = Points(pts).legend("cloud") 26 | 27 | show(a, at=0, N=N, axes=5) 28 | 29 | for i in range(1, N): 30 | a = smoothMLS1D(a.clone(), f=0.2).color(i).legend("iter #" + str(i)) 31 | 32 | # at last iteration make sure points are separated by tol (in % of bbox) 33 | if i == N-1: 34 | a.clean(tol=0.01) 35 | 36 | print("iteration", i, "#points:", len(a.coordinates())) 37 | show(a, at=i) 38 | 39 | interactive() -------------------------------------------------------------------------------- /examples/advanced/moving_least_squares3D.py: -------------------------------------------------------------------------------- 1 | """Generate a time sequence of 3D shapes 2 | (from a sphere to a tetrahedron) as noisy cloud Points, 3 | and smooth it with Moving Least Squares (smoothMLS3D). 4 | This make a simultaneus fit in 4D (space+time). 5 | smoothMLS3D method returns a vtkActor where points 6 | are color coded in bins of fitted time. 7 | Data itself can suggest a meaningful time separation 8 | based on the spatial distribution of points. 9 | The nr neighbours in the local 4D fitting must be specified. 10 | """ 11 | from vtkplotter import * 12 | 13 | # generate uniform points on sphere (tol separates points by 2% of actor size) 14 | cc = Sphere(res=200).clean(tol=0.02).coordinates() 15 | txt = Text(__doc__, c="k") 16 | 17 | a, b, noise = 0.2, 0.4, 0.1 # some random warping paramenters, and noise factor 18 | sets = [] 19 | for i in range(5): # generate a time sequence of 5 shapes 20 | cs = cc + a * i * cc ** 2 + b * i * cc ** 3 # warp sphere in weird ways 21 | # set absolute time of points actor, and add 1% noise on positions 22 | ap = Points(cs, c=i, alpha=0.5).addGaussNoise(1.0).time(0.2 * i) 23 | sets.append(ap) 24 | 25 | show(sets, txt, at=0, N=2, bg="w", zoom=1.4) 26 | 27 | sm3d = smoothMLS3D(sets, neighbours=10) 28 | 29 | #sm3d.addScalarBar3D(pos=(-2, 0, -1)) # color indicates fitted time 30 | 31 | show(sm3d, at=1, zoom=1.4, axes=4, interactive=1) 32 | -------------------------------------------------------------------------------- /examples/advanced/projectsphere.py: -------------------------------------------------------------------------------- 1 | """ 2 | Project a spherical-like object onto a plane. 3 | """ 4 | from vtkplotter import * 5 | 6 | e = Ellipsoid() 7 | 8 | ef = projectSphereFilter(e).normalize().wireframe(True) 9 | 10 | show(e, ef, Text(__doc__)) 11 | -------------------------------------------------------------------------------- /examples/advanced/recosurface.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example to show how to use recoSurface() 3 | to reconstruct a surface from points. 4 | 5 | 1. An object is loaded and 6 | noise is added to its vertices. 7 | 2. the point cloud is smoothened with MLS 8 | (see moving_least_squares.py) 9 | 3. clean(actor) imposes a minimum distance 10 | among mesh points where 'tol' is the 11 | fraction of the actor size. 12 | 4. a triangular mesh is extracted from 13 | this set of sparse Points, 'bins' is the 14 | number of voxels of the subdivision 15 | """ 16 | print(__doc__) 17 | from vtkplotter import * 18 | import numpy as np 19 | 20 | 21 | vp = Plotter(N=4, axes=0, bg='w') 22 | 23 | act = vp.load(datadir+"pumpkin.vtk") 24 | vp.show(act, at=0) 25 | 26 | noise = np.random.randn(act.N(), 3) * 0.04 27 | 28 | pts0 = Points(act.coordinates() + noise, r=3).legend("noisy cloud") 29 | vp.show(pts0, at=1) 30 | 31 | pts1 = smoothMLS2D(pts0, f=0.4) # smooth cloud, input actor is modified 32 | 33 | print("Nr of points before cleaning polydata:", pts1.N()) 34 | 35 | # impose a min distance among mesh points 36 | pts1.clean(tol=0.01).legend("smooth cloud") 37 | print(" after cleaning polydata:", pts1.N()) 38 | 39 | vp.show(pts1, at=2) 40 | 41 | # reconstructed surface from point cloud 42 | reco = recoSurface(pts1, bins=128).legend("surf reco") 43 | vp.show(reco, at=3, axes=7, zoom=1.2, interactive=1) 44 | -------------------------------------------------------------------------------- /examples/advanced/skeletonize.py: -------------------------------------------------------------------------------- 1 | """ 2 | Using 1D Moving Least Squares to skeletonize a surface. 3 | """ 4 | print(__doc__) 5 | 6 | from vtkplotter import * 7 | 8 | N = 9 # nr of iterations 9 | f = 0.1 # fraction of neighbours 10 | 11 | pts = load(datadir+"man.vtk").decimate(0.1).coordinates() 12 | # pts = load(datadir+'spider.ply').coordinates() 13 | # pts = load(datadir+'magnolia.vtk').subdivide().coordinates() 14 | # pts = load(datadir+'pumpkin.vtk').coordinates() 15 | # pts = load(datadir+'teapot.vtk').coordinates() 16 | 17 | a = Points(pts) 18 | 19 | for i in range(N): 20 | show(a, at=i, N=N, elevation=-5) 21 | a = smoothMLS1D(a.clone(), f).color(i) 22 | 23 | interactive() 24 | -------------------------------------------------------------------------------- /examples/advanced/splitmesh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Split a mesh by connectivity and order the pieces 3 | by increasing area. 4 | """ 5 | print(__doc__) 6 | from vtkplotter import splitByConnectivity, load, show, datadir 7 | 8 | em = load(datadir+"embryo.tif", threshold=80) 9 | 10 | # return the list of the largest 10 connected meshes: 11 | splitem = splitByConnectivity(em, maxdepth=40)[0:9] 12 | 13 | show([em, splitem], N=2, axes=1) 14 | -------------------------------------------------------------------------------- /examples/advanced/thinplate.py: -------------------------------------------------------------------------------- 1 | """ 2 | Thin Plate Spline transformations describe a nonlinear warp 3 | transform defined by a set of source and target landmarks. 4 | Any point on the mesh close to a source landmark will 5 | be moved to a place close to the corresponding target landmark. 6 | The points in between are interpolated using Bookstein's algorithm. 7 | """ 8 | from vtkplotter import * 9 | import numpy as np 10 | 11 | np.random.seed(1) 12 | 13 | vp = Plotter(axes=1) 14 | 15 | act = vp.load(datadir+"shuttle.obj", c='silver') 16 | 17 | # pick 4 random points 18 | indxs = np.random.randint(0, act.N(), 4) 19 | 20 | # and move them randomly by a little 21 | ptsource, pttarget = [], [] 22 | for i in indxs: 23 | ptold = act.getPoint(i) 24 | ptnew = ptold + np.random.rand(3) * 0.2 25 | act.setPoint(i, ptnew) 26 | ptsource.append(ptold) 27 | pttarget.append(ptnew) 28 | # print(ptold,'->',ptnew) 29 | 30 | warped = thinPlateSpline(act, ptsource, pttarget) 31 | warped.alpha(0.4).color("b") 32 | # print(warped.info['transform']) # saved here. 33 | 34 | apts = Points(ptsource, r=15, c="r") 35 | 36 | vp.show(act, warped, apts, Text(__doc__), viewup="z") 37 | -------------------------------------------------------------------------------- /examples/advanced/thinplate_grid.py: -------------------------------------------------------------------------------- 1 | """ 2 | Thin Plate Spline transformations describe a nonlinear warp 3 | transform defined by a set of source and target landmarks. 4 | Any point on the mesh close to a source landmark will 5 | be moved to a place close to the corresponding target landmark. 6 | The points in between are interpolated using Bookstein's algorithm. 7 | """ 8 | 9 | from vtkplotter import * 10 | import numpy as np 11 | 12 | np.random.seed(2) 13 | 14 | grids = [] 15 | for i in range(10): 16 | grids.append(Grid([0, 0, i / 10.0], resx=100, resy=100)) 17 | act = mergeActors(grids) # merge grids into a single object 18 | 19 | idxs = np.random.randint(0, act.N(), 10) # pick 10 indexes 20 | 21 | ptsource, pttarget = [], [] 22 | for i in idxs: 23 | ptold = act.getPoint(i) + np.random.randn(3) * 0.02 24 | ptsource.append(ptold) 25 | ptnew = ptold + [0, 0, np.random.randn(1) * 0.10] # move in z 26 | pttarget.append(ptnew) 27 | 28 | warped = thinPlateSpline(act, ptsource, pttarget) 29 | warped.alpha(0.2).color("b") 30 | # print(warped.getTransform()) 31 | 32 | apts = Points(ptsource, r=5, c="r") 33 | arrs = Arrows(ptsource, pttarget) 34 | 35 | show(warped, apts, arrs, Text(__doc__), axes=9, viewup="z", bg="w") 36 | -------------------------------------------------------------------------------- /examples/advanced/thinplate_morphing.py: -------------------------------------------------------------------------------- 1 | """ 2 | Warp the tip of a mesh using Thin Plate Splines. 3 | Red points stay fixed while a single point in space 4 | moves as the arrow shows. 5 | """ 6 | from vtkplotter import * 7 | 8 | 9 | mesh = load(datadir+"man.vtk").normalize() 10 | 11 | meshd = mesh.clone().decimate(N=100) # a heavily decimated copy 12 | 13 | sources = [[0.0, 1.0, 0.2]] # this point moves 14 | targets = [[0.3, 1.3, 0.4]] # to this. 15 | for pt in meshd.coordinates(): 16 | if pt[1] < 0.3: # these pts don't move 17 | sources.append(pt) # source = target 18 | targets.append(pt) 19 | 20 | # calculate the warping T on the reduced mesh 21 | T = thinPlateSpline(meshd, sources, targets).getTransform() 22 | 23 | warp = mesh.clone().transformMesh(T).c("blue").alpha(0.4) 24 | 25 | apts = Points(sources).c("red") 26 | 27 | arro = Arrow(sources[0], targets[0]) 28 | 29 | show(mesh, arro, warp, apts, Text(__doc__), viewup="z", axes=1) 30 | -------------------------------------------------------------------------------- /examples/basic/a_first_example.py: -------------------------------------------------------------------------------- 1 | """ 2 | ----------------------------------------------------------------------- 3 | A first example: how to draw any mesh. 4 | 5 | from vtkplotter import * 6 | 7 | c = Cube(side=1.5, alpha=0.5) 8 | s = Sphere() 9 | 10 | c.show() # draw the cube only 11 | (c+s).show() # Actor+Actor = Assembly, then show it. 12 | show(c,s) # can show list of [Actor, Volume, filename ...] 13 | 14 | vp = Plotter() # Make a new Plotter() instance and pop up a new window 15 | vp += Torus() # generate another mesh and add it to the Plotter list 16 | vp.show() # no argument needed 17 | ----------------------------------------------------------------------- 18 | """ 19 | print(__doc__) 20 | 21 | from vtkplotter import * 22 | 23 | c = Cube(side=1.5, alpha=0.5) 24 | s = Sphere() 25 | 26 | print("-> c.show() # press q to continue") 27 | c.show(verbose=0) # draw the cube only 28 | 29 | print("-> (c+s).show() # Actor+Actor = Assembly, then show it.") 30 | (c + s).show() 31 | 32 | print("-> show(c,s) # can show list of [Actor, Volume, filename ...]") 33 | show(c, s) 34 | 35 | print("\n-> # Make a new Plotter() instance and pop up a new window\n-> vp = Plotter()") 36 | vp = Plotter(verbose=0) 37 | 38 | print("-> vp += Torus() # generate another mesh and add to the Plotter list") 39 | vp += Torus() # generate another mesh and add to Plotter 40 | 41 | print("-> vp.show() # no argument needed") 42 | vp.show() 43 | -------------------------------------------------------------------------------- /examples/basic/acollection.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "application/vnd.jupyter.widget-view+json": { 11 | "model_id": "2f6ae0f7e52e4127b293aabac95456b9", 12 | "version_major": 2, 13 | "version_minor": 0 14 | }, 15 | "text/plain": [ 16 | "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, …" 17 | ] 18 | }, 19 | "metadata": {}, 20 | "output_type": "display_data" 21 | } 22 | ], 23 | "source": [ 24 | "from vtkplotter import *\n", 25 | "\n", 26 | "for i in range(10):\n", 27 | " Cone(pos=[3*i, 0, 0], axis=[i, i-5, 0]) # no variable needs to be assigned\n", 28 | "\n", 29 | "# collection() retrieves the list of all sofar created actors\n", 30 | "show(collection())" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [] 39 | } 40 | ], 41 | "metadata": { 42 | "kernelspec": { 43 | "display_name": "Python 3", 44 | "language": "python", 45 | "name": "python3" 46 | }, 47 | "language_info": { 48 | "codemirror_mode": { 49 | "name": "ipython", 50 | "version": 3 51 | }, 52 | "file_extension": ".py", 53 | "mimetype": "text/x-python", 54 | "name": "python", 55 | "nbconvert_exporter": "python", 56 | "pygments_lexer": "ipython3", 57 | "version": "3.6.7" 58 | } 59 | }, 60 | "nbformat": 4, 61 | "nbformat_minor": 2 62 | } 63 | -------------------------------------------------------------------------------- /examples/basic/acollection.py: -------------------------------------------------------------------------------- 1 | ''' 2 | for i in range(10): 3 | Cone(...) # no variable assigned! 4 | show(collection()) 5 | ''' 6 | from vtkplotter import Cone, collection, Text, show 7 | 8 | for i in range(10): 9 | Cone(pos=[3*i, 0, 0], axis=[i, i-5, 0]) # no variable assigned 10 | 11 | Text(__doc__, font='courier') 12 | 13 | # collection() retrieves the list of all created actors 14 | show(collection()) 15 | -------------------------------------------------------------------------------- /examples/basic/align1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Align 2 shapes and for each vertex of the first draw 3 | and arrow to the closest point of the second. 4 | The source transformation is accessible with getTransform() 5 | rigid=True doesn't allow scaling 6 | """ 7 | from vtkplotter import * 8 | 9 | vp = Plotter() 10 | 11 | limb = vp.load(datadir + "270.vtk") 12 | rim = vp.load(datadir + "270_rim.vtk").c("r").lw(4) 13 | 14 | arim = alignICP(rim, limb, rigid=True).c("g").lw(5) 15 | vp += [arim, Text(__doc__)] 16 | 17 | d = 0 18 | for p in arim.coordinates(): 19 | cpt = limb.closestPoint(p) 20 | vp += Arrow(p, cpt, c="g") 21 | d += mag2(p - cpt) # square of residual distance 22 | 23 | printc("ave. squared distance =", d / arim.N(), c="g") 24 | printc("vtkTransform is available with getTransform():") 25 | printc([arim.getTransform()]) 26 | vp.show() 27 | -------------------------------------------------------------------------------- /examples/basic/align2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example usage of align() method: 3 | generate two random sets of points as 2 actors 4 | and align them using the Iterative Closest Point algorithm. 5 | """ 6 | from __future__ import division 7 | from random import uniform as u 8 | from vtkplotter import * 9 | 10 | vp = Plotter(shape=[1, 2], verbose=0, axes=2, bg="w") 11 | 12 | N1 = 15 # number of points of first set 13 | N2 = 15 # number of points of second set 14 | x = 1.0 # add some randomness 15 | 16 | pts1 = [(u(0, x), u(0, x), u(0, x) + i) for i in range(N1)] 17 | pts2 = [(u(0, x) + 3, u(0, x) + i / 2 + 2, u(0, x) + i + 1) for i in range(N2)] 18 | 19 | act1 = Points(pts1, r=8, c="b").legend("source") 20 | act2 = Points(pts2, r=8, c="r").legend("target") 21 | 22 | vp.show(act1, act2, at=0) 23 | 24 | # find best alignment between the 2 sets of Points, e.i. find 25 | # how to move act1 to best match act2 26 | alpts1 = alignICP(act1, act2).coordinates() 27 | vp += [Points(alpts1, r=8, c="b"), Text(__doc__, c="k")] 28 | 29 | for i in range(N1): # draw arrows to see where points end up 30 | vp += Arrow(pts1[i], alpts1[i], c="k", s=0.007, alpha=0.1) 31 | 32 | vp.show(at=1, interactive=1) 33 | -------------------------------------------------------------------------------- /examples/basic/align3.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example usage of alignProcrustes() method: 3 | generate 3 random sets of points 4 | and align them using vtkProcrustesAlignmentFilter. 5 | """ 6 | from __future__ import division, print_function 7 | from random import uniform as u 8 | 9 | from vtkplotter import Plotter, alignProcrustes, Text, Points 10 | 11 | vp = Plotter(shape=[1, 2], verbose=0, axes=2, sharecam=0, bg="w") 12 | 13 | N = 15 # number of points 14 | x = 1.0 # add some randomness 15 | 16 | pts1 = [(u(0, x), u(0, x), u(0, x) + i) for i in range(N)] 17 | pts2 = [(u(0, x) + 3, u(0, x) + i / 2 + 2, u(0, x) + i + 1) for i in range(N)] 18 | pts3 = [(u(0, x) + 4, u(0, x) + i / 4 - 3, u(0, x) + i - 2) for i in range(N)] 19 | 20 | act1 = Points(pts1, c="r").legend("set1") 21 | act2 = Points(pts2, c="g").legend("set2") 22 | act3 = Points(pts3, c="b").legend("set3") 23 | 24 | vp.show(act1, act2, act3, at=0) 25 | 26 | # find best alignment among the n sets of Points, 27 | # return an Assembly formed by the aligned sets 28 | aligned = alignProcrustes([act1, act2, act3]) 29 | 30 | # print(aligned.info['transform']) 31 | 32 | vp.show(aligned, Text(__doc__), at=1, interactive=1) 33 | -------------------------------------------------------------------------------- /examples/basic/annotations.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show some text as a corner annotation. 3 | Fonts: arial, courier, times. 4 | """ 5 | from vtkplotter import show, Text 6 | 7 | with open("basic/align1.py") as fname: 8 | t = fname.read() 9 | 10 | actor2d = Text(t, pos=3, s=1.2, c='k', bg="lb", font="courier") 11 | 12 | show(actor2d, verbose=0, axes=0) 13 | -------------------------------------------------------------------------------- /examples/basic/bgImage.py: -------------------------------------------------------------------------------- 1 | """Set a jpeg background image on a 2 | vtkRenderingWindow layer, after 3 | the first rendering it can be 4 | zoomed to fill the window.""" 5 | from vtkplotter import Plotter, load, Polygon, Text, datadir 6 | 7 | doc = Text(__doc__, c="k", bg="w") 8 | 9 | vp = Plotter(N=2, size=(400, 800), axes=4, sharecam=0, 10 | bg=datadir+"images/tropical.jpg") 11 | 12 | a1 = load(datadir+"flamingo.3ds").rotateX(-90) 13 | a2 = Polygon() 14 | 15 | vp.show(a1, doc, at=0) 16 | 17 | vp.backgroundRenderer.GetActiveCamera().Zoom(2.5) 18 | 19 | vp.show(a2, at=1, interactive=1) 20 | -------------------------------------------------------------------------------- /examples/basic/boolean.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example of boolean operations with actors or polydata 3 | """ 4 | print(__doc__) 5 | 6 | from vtkplotter import Plotter, booleanOperation, Sphere 7 | 8 | 9 | # declare the instance of the class 10 | vp = Plotter(shape=(2, 2), interactive=0, axes=3) 11 | 12 | # build to sphere actors 13 | s1 = Sphere(pos=[-0.7, 0, 0], c="r", alpha=0.5) 14 | s2 = Sphere(pos=[0.7, 0, 0], c="g", alpha=0.5) 15 | 16 | # make 3 different possible operations: 17 | b1 = booleanOperation(s1, "intersect", s2).c('m').legend("intersect") 18 | b2 = booleanOperation(s1, "plus", s2).c("b").wireframe(True).legend("plus") 19 | b3 = booleanOperation(s1, "minus", s2).legend("minus") 20 | 21 | # show the result in 4 different subwindows 0->3 22 | vp.show(s1, s2, at=0) 23 | vp.show(b1, at=1) 24 | vp.show(b2, at=2) 25 | vp.show(b3, at=3) 26 | vp.addScalarBar() # adds a scalarbar to the last actor 27 | vp.show(interactive=1) 28 | -------------------------------------------------------------------------------- /examples/basic/buildmesh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Manually build a mesh. 3 | """ 4 | from vtkplotter import * 5 | 6 | verts = [(50,50,50), (70,40,50), (50,40,80), (80,70,50)] 7 | faces = [(0,1,2), (2,1,3), (1,0,3)] 8 | # (the first triangle face is formed by vertex 0, 1 and 2) 9 | 10 | a = Actor([verts, faces]) 11 | a.backColor('violet').lineColor('black').lineWidth(1) 12 | 13 | # the way vertices are assembled into polygons can be retrieved 14 | # in two different formats: 15 | printc('getPolygons() format is :', a.getPolygons(), c=3) 16 | printc('getConnectivity() format is:', a.getConnectivity(), c=3) 17 | 18 | show(a, Text(__doc__), viewup='z', axes=8) 19 | -------------------------------------------------------------------------------- /examples/basic/buttons.py: -------------------------------------------------------------------------------- 1 | """ 2 | Add a square button with N possible internal states 3 | to a rendering window that calls an external function. 4 | Available fonts: arial, courier, times 5 | """ 6 | print(__doc__) 7 | 8 | from vtkplotter import Plotter, printc, datadir 9 | 10 | 11 | vp = Plotter(shape=(2, 1), axes=4) 12 | 13 | act = vp.load(datadir+"magnolia.vtk", c="v") 14 | 15 | vp.show(act, at=0) 16 | vp.show(act, at=1) 17 | 18 | # add a button to the current renderer (e.i. nr1) 19 | def buttonfunc(): 20 | act.alpha(1 - act.alpha()) # toggle mesh transparency 21 | bu.switch() # change to next status 22 | printc(bu.status(), box="_", dim=True) 23 | 24 | 25 | bu = vp.addButton( 26 | buttonfunc, 27 | pos=(0.7, 0.05), # x,y fraction from bottom left corner 28 | states=["press to hide", "press to show"], 29 | c=["w", "w"], 30 | bc=["dg", "dv"], # colors of states 31 | font="courier", 32 | size=18, 33 | bold=True, 34 | italic=False, 35 | ) 36 | 37 | vp.show(interactive=1) 38 | -------------------------------------------------------------------------------- /examples/basic/carcrash.py: -------------------------------------------------------------------------------- 1 | """ 2 | Make a textured floor, a lamp post, and load a mesh of a car 3 | make copies of the car, rotate and move them in a loop. 4 | """ 5 | from __future__ import division, print_function 6 | from vtkplotter import Plotter, Plane, Text, datadir 7 | 8 | vp = Plotter(interactive=0, axes=0) 9 | 10 | vp += Plane(pos=(4, 0, -0.45), sx=12).texture("metalfloor1") 11 | 12 | # load and set its position (methods can be concatenated) 13 | vp.load(datadir+"lamp.vtk").pos([1.7, -0.4, 2]) 14 | vp += Text(__doc__) 15 | 16 | a = vp.load(datadir+"porsche.ply", c="r").rotateX(90) 17 | a.normalize() # set actor at origin and scale size to 1 18 | 19 | for i in range(1, 10): 20 | b = a.clone().color("aqua").alpha(0.04 * i) 21 | b.rotateX(-20 * i).rotateY(-10 * i).pos([i, i / 2, i / 2]) 22 | vp += b # add actor b to Plotter 23 | vp.show(rate=10) # maximum frame rate in hertz 24 | print(i, "time:", vp.clock, "s") 25 | 26 | vp.show(interactive=1) 27 | -------------------------------------------------------------------------------- /examples/basic/closewindow.py: -------------------------------------------------------------------------------- 1 | """Closing the Rendering Window 2 | 3 | Press q: 4 | Control returns to terminal, 5 | window will not close but become unresponsive""" 6 | from vtkplotter import Text, Paraboloid, Hyperboloid, Plotter, show 7 | 8 | mesh = Paraboloid() 9 | 10 | vp1 = show(mesh, Text(__doc__), title='First Plotter instance') 11 | 12 | # Now press 'q' to exit the window interaction, 13 | # windows stays open but not reactive anymore. 14 | 15 | # You can go back to interavtion mode by simply calling: 16 | #show() 17 | 18 | input('\nControl returned to terminal shell:\nwindow is now unresponsive (press Enter)') 19 | 20 | vp1.closeWindow() 21 | 22 | # window should now close, the Plotter instance becomes unusable 23 | # but mesh objects still exist in it: 24 | 25 | print("First Plotter actors:", vp1.actors) 26 | vp1.show() # THIS HAS NO EFFECT: window does not exist anymore. Cannot reopen. 27 | 28 | ################################################################## 29 | # Can now create a brand new Plotter and show the old object in it 30 | vp2 = Plotter(title='Second Plotter instance', pos=(500,0)) 31 | vp2.show(vp1.actors[0].color('red')) 32 | 33 | ################################################################## 34 | # Create a third new Plotter and then close the second 35 | vp3 = Plotter(title='Third Plotter instance') 36 | 37 | vp2.closeWindow() 38 | print('vp2.closeWindow() called') 39 | 40 | vp3.show(Hyperboloid()) 41 | 42 | from vtkplotter import closeWindow 43 | closeWindow() # automatically find and close the current window 44 | 45 | print('done.') 46 | -------------------------------------------------------------------------------- /examples/basic/clustering.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example usage of removeOutliers() 3 | and cluster() methods. 4 | """ 5 | from vtkplotter import show, cluster, removeOutliers, Text 6 | import numpy as np 7 | 8 | 9 | # generate 4 random sets of N points in space 10 | N = 2000 11 | f = 0.6 12 | noise1 = np.random.rand(N, 3) * f + np.array([1, 1, 0]) 13 | noise2 = np.random.rand(N, 3) * f + np.array([1, 0, 1.2]) 14 | noise3 = np.random.rand(N, 3) * f + np.array([0, 1, 1]) 15 | noise4 = np.random.randn(N, 3) * f / 8 + np.array([1, 1, 1]) 16 | 17 | noise4 = removeOutliers(noise4, 0.05) 18 | 19 | # merge points to lose their identity 20 | pts = noise1.tolist() + noise2.tolist() + noise3.tolist() + noise4.tolist() 21 | 22 | # find back their identity through clustering 23 | cl = cluster(pts, radius=0.1) # returns a vtkAssembly 24 | 25 | show(cl, Text(__doc__), axes=1, viewup='z') 26 | -------------------------------------------------------------------------------- /examples/basic/colorMeshCells.py: -------------------------------------------------------------------------------- 1 | """colorCellsByArray() 2 | Colorize faces of a mesh one by one, 3 | passing a 1-to-1 list of colors and 4 | optionally a list of transparencies. 5 | """ 6 | from vtkplotter import * 7 | 8 | ################ 9 | sc = Torus(res=9).lw(0.1) 10 | 11 | cols, alphas = [], [] 12 | for i in range(sc.NCells()): 13 | cols.append(i) # i-th color 14 | alphas.append(i/sc.NCells()) 15 | 16 | sc.colorCellsByArray(cols, alphas) 17 | print('all scalars:', sc.scalars()) 18 | 19 | tc = Text(__doc__, c='k') 20 | 21 | show(sc, tc, at=0, N=2, bg='w') 22 | 23 | ################ 24 | sv = Torus(res=5).lw(0.1) 25 | 26 | cols = [i for i in range(sv.NPoints())] 27 | 28 | sv.colorVerticesByArray(cols) 29 | print('all scalars:', sv.scalars()) 30 | 31 | tv = Text('''colorVerticesByArray() 32 | tries to interpolate inbetween vertices''', c='k') 33 | 34 | show(sv, tv, at=1, interactive=True) 35 | -------------------------------------------------------------------------------- /examples/basic/colorcubes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show a cube for each available color name 3 | """ 4 | print(__doc__) 5 | from vtkplotter import Plotter, Cube, Text 6 | from vtkplotter.colors import colors, getColor 7 | from operator import itemgetter 8 | 9 | # sorting by hex color code: 10 | sorted_colors = sorted(colors.items(), key=itemgetter(1)) 11 | # or by name: 12 | # sorted_colors = sorted(colors.items(), key=itemgetter(0)) 13 | 14 | 15 | vp = Plotter(N=len(sorted_colors), axes=0, size="fullscreen") 16 | 17 | for i, sc in enumerate(sorted_colors): 18 | cname = sc[0] 19 | rgb = getColor(cname) 20 | cb = Cube(c=rgb) 21 | tname = Text(cname, pos=3) 22 | vp.show(cb, tname, at=i) 23 | 24 | print("click on any cube and press i") 25 | vp.show(interactive=1) 26 | -------------------------------------------------------------------------------- /examples/basic/colormaps.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example usage of pointColors to assign a color to each mesh vertex 3 | by looking it up in matplotlib database of colormaps 4 | """ 5 | print(__doc__) 6 | from vtkplotter import Plotter, datadir 7 | 8 | # these are the available color maps 9 | mapkeys = [ 10 | "afmhot", 11 | "binary", 12 | "bone", 13 | "cool", 14 | "coolwarm", 15 | "copper", 16 | "gist_earth", 17 | "gray", 18 | "hot", 19 | "jet", 20 | "rainbow", 21 | "winter", 22 | ] 23 | 24 | vp = Plotter(N=len(mapkeys), axes=4) 25 | vp.legendSize = 0.4 26 | 27 | mug = vp.load(datadir+"mug.ply") 28 | scalars = mug.coordinates()[:, 1] # let y-coord be the scalar 29 | 30 | for i, key in enumerate(mapkeys): # for each available color map name 31 | imug = mug.clone().legend(key) 32 | imug.pointColors(scalars, cmap=key) 33 | vp.show(imug, at=i) 34 | 35 | vp.show(interactive=1) 36 | -------------------------------------------------------------------------------- /examples/basic/connCells.py: -------------------------------------------------------------------------------- 1 | """ 2 | Parse mesh with connectedCells() 3 | """ 4 | from vtkplotter import * 5 | 6 | N = 12 7 | sub = 0 8 | tol = 0.02 9 | 10 | actor = load(datadir+'250.vtk') 11 | show( 12 | actor.wireframe().c('blue'), 13 | actor.boundaries(), 14 | Point(actor.getPoint(30)), 15 | actor.connectedCells(30), # cells polygons at vertex nr.30 16 | ) 17 | 18 | s = actor.subdivide(sub).clean(tol) 19 | 20 | coords = s.coordinates() 21 | pactor = Points(coords) 22 | 23 | tomerge = [] 24 | for p in coords: 25 | ipts = s.closestPoint(p, N=N, returnIds=True) 26 | pts = coords[ipts] 27 | 28 | d = delaunay2D(pts, mode='fit').c('blue').wireframe() 29 | 30 | piece = d.connectedCells(0, returnIds=False) 31 | 32 | show(pactor, d, piece, Point(p, c='r'), interactive=0) 33 | 34 | tomerge.append(piece) 35 | 36 | show(mergeActors(tomerge).clean(), interactive=1) 37 | 38 | -------------------------------------------------------------------------------- /examples/basic/connVtx.py: -------------------------------------------------------------------------------- 1 | """ 2 | Find the vertices that are connected 3 | to a specific vertex in a mesh. 4 | """ 5 | from vtkplotter import * 6 | 7 | s = Sphere(c="y", res=12).wireframe() 8 | 9 | index = 12 10 | 11 | vtxs = s.connectedVertices(index, returnIds=False) 12 | 13 | apt = Point(s.getPoint(index), c="r", r=15) 14 | cpts = Points(vtxs, c="blue", r=15) 15 | 16 | show(s, apt, cpts, Text(__doc__), verbose=False) 17 | -------------------------------------------------------------------------------- /examples/basic/cutter.py: -------------------------------------------------------------------------------- 1 | """ 2 | Load a Volume (atif stack). 3 | Invoke a tool to cut off parts of it. 4 | """ 5 | print(__doc__) 6 | 7 | from vtkplotter import Plotter, datadir 8 | 9 | 10 | vp = Plotter(axes=4) 11 | 12 | act = vp.load(datadir+"embryo.tif") 13 | 14 | vp.addCutterTool(act) 15 | vp.show() 16 | -------------------------------------------------------------------------------- /examples/basic/delaunay2d.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example for delaunay2D() and cellCenters() functions. 3 | """ 4 | print(__doc__) 5 | 6 | from vtkplotter import Plotter, delaunay2D, Points, datadir 7 | 8 | vp = Plotter(shape=(1, 2), interactive=0) 9 | 10 | d0 = vp.load(datadir+"250.vtk").rotateY(-90).legend("original mesh") 11 | 12 | coords = d0.coordinates() # get the coordinates of the mesh vertices 13 | # Build a mesh starting from points in space 14 | # (points must be projectable on the XY plane) 15 | d1 = delaunay2D(coords, mode='fit') 16 | d1.color("r").wireframe(True).legend("delaunay mesh") 17 | 18 | cents = d1.cellCenters() 19 | ap = Points(cents).legend("cell centers") 20 | 21 | vp.show(d0, d1, at=0) # NB: d0 and d1 are slightly different 22 | vp.show(d1, ap, at=1, interactive=1) 23 | -------------------------------------------------------------------------------- /examples/basic/deleteMeshPoints.py: -------------------------------------------------------------------------------- 1 | """ 2 | Remove the 200 points (and cells) from a mesh 3 | which are closest to a specified point. 4 | """ 5 | from vtkplotter import * 6 | 7 | pu = load(datadir+'pumpkin.vtk') 8 | pu.c('lightgreen').bc('tomato').lw(.1).lc('gray') 9 | 10 | pt = [1, 0.5, 1] 11 | ids = pu.closestPoint(pt, N=200, returnIds=True) 12 | 13 | pu.deletePoints(ids) 14 | 15 | show(Point(pt), pu, Text(__doc__), bg='white') 16 | -------------------------------------------------------------------------------- /examples/basic/distance2mesh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Computes the (signed) distance 3 | from one mesh to another. 4 | """ 5 | from vtkplotter import Sphere, Cube, show, Text 6 | 7 | s1 = Sphere() 8 | s2 = Cube(pos=[1,0,0], c='white', alpha=0.4) 9 | 10 | s1.distanceToMesh(s2, signed=True, negate=False) 11 | 12 | s1.addScalarBar(title='Signed\nDistance') 13 | 14 | #print(s1.scalars("Distance")) 15 | 16 | show(s1, s2, Text(__doc__)) 17 | -------------------------------------------------------------------------------- /examples/basic/fillholes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Identifies and fills holes in input mesh. 3 | Holes are identified by locating boundary edges, linking them 4 | together into loops, and then triangulating the resulting loops. 5 | size: approximate limit to the size of the hole that can be filled. 6 | """ 7 | from vtkplotter import load, show, Text, datadir 8 | 9 | a = load(datadir+"bunny.obj") 10 | 11 | b = a.clone().fillHoles(size=0.1) 12 | b.color("b").wireframe(True).legend("filled mesh") 13 | 14 | doc = Text(__doc__) 15 | 16 | show(a, b, doc, elevation=-70) 17 | -------------------------------------------------------------------------------- /examples/basic/fitline.py: -------------------------------------------------------------------------------- 1 | """ 2 | Usage example of fitLine() and fitPlane() 3 | 4 | Draw a line in 3D that fits a cloud of 20 Points, 5 | Show the first set of 20 points and fit a plane to them. 6 | """ 7 | from __future__ import division, print_function 8 | import numpy as np 9 | from vtkplotter import Plotter, fitLine, fitPlane, Points, Text 10 | 11 | # declare the class instance 12 | vp = Plotter(verbose=0, title="linear fitting") 13 | 14 | # draw 500 fit lines superimposed and very transparent 15 | for i in range(500): 16 | 17 | x = np.linspace(-2, 5, 20) # generate each time 20 points 18 | y = np.linspace(1, 9, 20) 19 | z = np.linspace(-5, 3, 20) 20 | data = np.array(list(zip(x, y, z))) 21 | data += np.random.normal(size=data.shape) * 0.8 # add gauss noise 22 | 23 | vp += fitLine(data).lw(4).alpha(0.03) # fit a line 24 | 25 | # 'data' still contains the last iteration points 26 | vp += Points(data, r=10, c="yellow") 27 | 28 | # the first fitted slope direction is stored 29 | # in actor.info['slope] and actor.info['normal] 30 | print("Line Fit slope = ", vp.actors[0].info["slope"]) 31 | 32 | plane = fitPlane(data) # fit a plane 33 | print("Plan Fit normal=", plane.info["normal"]) 34 | 35 | vp += [plane, Text(__doc__)] 36 | 37 | vp.show(axes=1) 38 | -------------------------------------------------------------------------------- /examples/basic/flatarrow.py: -------------------------------------------------------------------------------- 1 | """ 2 | FlatArrow example 3 | """ 4 | from vtkplotter import * 5 | 6 | for i in range(10): 7 | s, c = sin(i), cos(i) 8 | l1 = [[sin(x)+c, -cos(x)+s, x] for x in arange(0,3, 0.1)] 9 | l2 = [[sin(x)+c+0.1, -cos(x)+s + x/15, x] for x in arange(0,3, 0.1)] 10 | 11 | FlatArrow(l1, l2, c=i, tipSize=1, tipWidth=1) 12 | 13 | show(collection(), viewup="z", axes=1, bg="w") 14 | -------------------------------------------------------------------------------- /examples/basic/fonts.py: -------------------------------------------------------------------------------- 1 | from vtkplotter import Cube, Text, show, collection 2 | from vtkplotter.settings import fonts 3 | 4 | Text("List of available fonts:") 5 | 6 | Cube().c('white').rotateX(20).rotateZ(20) 7 | 8 | for i, f in enumerate(fonts): 9 | Text(f+': The quick fox jumps over the lazy dog.', 10 | pos=(5,i*40+20), font=f, c=i%3) 11 | 12 | show(collection(), axes=False) 13 | -------------------------------------------------------------------------------- /examples/basic/fxy.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example for function() method. 3 | Draw a surface representing the 3D function specified as a string 4 | or as a reference to an external already existing function. 5 | Red points indicate where the function does not exist. 6 | """ 7 | print(__doc__) 8 | from vtkplotter import Plotter, fxy, sin, cos, show 9 | 10 | 11 | def my_z(x, y): 12 | return sin(2 * x * y) * cos(3 * y) / 2 13 | 14 | 15 | # draw at renderer nr.0 the first actor, show it with a texture 16 | # an existing function z(x,y) can be passed: 17 | f1 = fxy(my_z) 18 | 19 | # red dots are shown where the function does not exist (y>x): 20 | # if vp is set to verbose, sympy calculates derivatives and prints them: 21 | f2 = fxy("sin(3*x)*log(x-y)/3") 22 | 23 | # specify x and y ranges and z vertical limits: 24 | f3 = fxy("log(x**2+y**2 - 1)", x=[-2, 2], y=[-2, 2], zlimits=[-1, 1.5]) 25 | 26 | show(f1, f2, f3, N=3, axes=1, sharecam=False, bg="w") 27 | -------------------------------------------------------------------------------- /examples/basic/glyphs.py: -------------------------------------------------------------------------------- 1 | """Glyphs. 2 | At each vertex of a mesh, another mesh is shown with 3 | various orientation options and coloring. 4 | """ 5 | from vtkplotter import * 6 | from numpy.random import rand 7 | 8 | t = Text(__doc__) 9 | 10 | s = Sphere(res=12).wireframe(True).alpha(0.2) 11 | 12 | randvs = rand(s.N(), 3) # random orientation vectors for each vertex 13 | 14 | ####################################### 15 | gly1 = Cylinder().rotateY(90).scale(0.05) 16 | 17 | gsphere1 = Glyph(s, gly1, orientationArray=randvs, scaleByVectorSize=True) 18 | 19 | show(s, gsphere1, t, at=0, N=2) 20 | 21 | 22 | ####################################### 23 | gly2 = load(datadir+"shuttle.obj").rotateY(180).scale(0.02) 24 | 25 | gsphere2 = Glyph(s, gly2, 26 | c='gold', 27 | orientationArray="normals", 28 | tol=0.1, # impose a minimum seaparation of 10% 29 | ) 30 | 31 | show(s, gsphere2, at=1, zoom=1.4, interactive=1) 32 | -------------------------------------------------------------------------------- /examples/basic/glyphs_arrows.py: -------------------------------------------------------------------------------- 1 | """ 2 | Draw color arrow glyphs. 3 | """ 4 | from vtkplotter import * 5 | import numpy as np 6 | 7 | s1 = Sphere(r=10, res=8).c('white').wireframe() 8 | s2 = Sphere(r=20, res=8).c('white').wireframe().alpha(0.1).pos(0,4,0) 9 | 10 | coords1 = s1.coordinates() # get the vertices coords 11 | coords2 = s2.coordinates() 12 | 13 | # color can be a colormap which maps arrrow sizes 14 | a1 = Arrows(coords1, coords2, c='coolwarm', alpha=0.4).addScalarBar() 15 | 16 | 17 | # get a list of random rgb colors 18 | nrs = np.random.randint(0, 10, len(coords1)) 19 | cols = getColor(nrs) 20 | 21 | a2 = Arrows(coords1, coords2, c=cols, scale=0.5) 22 | 23 | t1 = Text('Color arrows by size\nusing a color map') 24 | t2 = Text('Color arrows by an array\nand scale them') 25 | 26 | # draw 2 groups of actors on two renderers 27 | show([[s1, s2, a1, t1], [s1, s2, a2, t2]], N=2) 28 | 29 | -------------------------------------------------------------------------------- /examples/basic/histo2D.py: -------------------------------------------------------------------------------- 1 | """ 2 | 2D histogram with hexagonal binning. 3 | """ 4 | from vtkplotter import * 5 | import numpy as np 6 | 7 | vp = Plotter(axes=1, verbose=0, bg="w") 8 | vp.xtitle = "x gaussian, s=1.0" 9 | vp.ytitle = "y gaussian, s=1.5" 10 | vp.ztitle = "dN/dx/dy" 11 | 12 | N = 20000 13 | x = np.random.randn(N) * 1.0 14 | y = np.random.randn(N) * 1.5 15 | 16 | histo = histogram2D(x, y, bins=10, fill=True) 17 | 18 | pts = Points([x, y, np.zeros(N)+6], c="black", alpha=0.01) 19 | 20 | f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}' 21 | f+= r'{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}' 22 | f+= r'{2 \sigma_{y}^{2}}\right)\right)' 23 | 24 | formula = Latex(f, c='k', s=1.5).rotateZ(90).rotateX(90).pos(1,-1,1) 25 | 26 | vp.show(histo, pts, formula, Text(__doc__), viewup="z") 27 | -------------------------------------------------------------------------------- /examples/basic/ids.py: -------------------------------------------------------------------------------- 1 | """ 2 | Add an array of cell and point IDs. 3 | """ 4 | print(__doc__) 5 | 6 | from vtkplotter import * 7 | 8 | act = Spring().addIDs() 9 | 10 | print(act.scalars(), "press k to apply point scalars.") 11 | 12 | show(act, viewup="z", verbose=0) 13 | -------------------------------------------------------------------------------- /examples/basic/interactionstyle.py: -------------------------------------------------------------------------------- 1 | """ 2 | Scene interaction styles. Available styles are: 3 | - 0, TrackballCamera 4 | - 1, TrackballActor 5 | - 2, JoystickCamera 6 | - 3, Unicam 7 | - 4, Flight 8 | - 5, RubberBand3D 9 | - 6, RubberBandZoom 10 | """ 11 | print(__doc__) 12 | from vtkplotter import * 13 | 14 | show(Spring(), Cube(), at=[0, 1], shape=(3, 1), bg="blackboard") 15 | 16 | t = Text( 17 | """TrackballCamera is the default 18 | ...lets change it to JoystickCamera:""", 19 | c="k", bg="w" ) 20 | 21 | print("..change it to JoystickCamera") 22 | show(Paraboloid(), t, at=2, interactorStyle=2, interactive=True) 23 | -------------------------------------------------------------------------------- /examples/basic/isolines.py: -------------------------------------------------------------------------------- 1 | """ 2 | Draw the isolines of the 3 | active scalars on a surface 4 | """ 5 | from vtkplotter import * 6 | 7 | mesh = Hyperboloid().rotateX(20) # a whatever mesh 8 | 9 | scals = mesh.coordinates()[:,1] # pick x coords of vertices 10 | mesh.pointColors(scals).addScalarBar() 11 | 12 | isols = mesh.isolines(n=12, vmin=0).color('w') 13 | 14 | show(mesh, isols, Text(__doc__), axes=1) 15 | 16 | -------------------------------------------------------------------------------- /examples/basic/keypress.py: -------------------------------------------------------------------------------- 1 | """ 2 | This example shows how to implement a custom function that is triggered by 3 | pressing a keyboard button when the rendering window is in interactive mode. 4 | Every time a key is pressed the picked point of the mesh is used 5 | to add a sphere and some info is printed. 6 | """ 7 | from vtkplotter import Plotter, printc, Sphere, Text, datadir 8 | 9 | ############################################################################## 10 | def myfnc(key): 11 | if not vp.clickedActor or key != "c": 12 | printc("click an actor and press c.", c="r") 13 | return 14 | printc("clicked actor :", vp.clickedActor.legend(), c=4) 15 | printc("clicked 3D point:", vp.picked3d, c=4) 16 | printc("clicked renderer:", [vp.renderer], c=2) 17 | 18 | vp.add(Sphere(pos=vp.picked3d, r=0.005, c="v")) 19 | vp.show() 20 | 21 | 22 | ############################################################################## 23 | 24 | vp = Plotter(verbose=0) 25 | 26 | vp.keyPressFunction = myfnc # make it known to Plotter class 27 | 28 | vp.load(datadir+"bunny.obj") 29 | 30 | vp += Text(__doc__) 31 | 32 | printc("\nPress c to execute myfnc()", c=1) 33 | vp.show() 34 | -------------------------------------------------------------------------------- /examples/basic/largestregion.py: -------------------------------------------------------------------------------- 1 | """ 2 | Extract the mesh region that 3 | has the largest connected surface 4 | """ 5 | from vtkplotter import * 6 | 7 | 8 | act1 = load(datadir+"embryo.slc", threshold=True, c="y") 9 | printc("area1 =", act1.area(), c="y") 10 | 11 | act2 = extractLargestRegion(act1).color("b") 12 | printc("area2 =", act2.area(), c="b") 13 | 14 | show(act1, Text(__doc__), at=0, shape=(2, 1)) 15 | show(act2, at=1, zoom=1.2, interactive=1) 16 | -------------------------------------------------------------------------------- /examples/basic/latex.py: -------------------------------------------------------------------------------- 1 | from vtkplotter import Latex, Point, show 2 | 3 | # https://matplotlib.org/tutorials/text/mathtext.html 4 | 5 | latex1 = r'x= \frac{ - b \pm \sqrt {b^2 - 4ac} }{2a}' 6 | latex2 = r'\mathcal{A}\mathrm{sin}(2 \omega t)' 7 | 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)' 8 | 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))}' 9 | 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)' 10 | 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}' 11 | latex7 = r'x \mathrm{(arb. units)}' 12 | 13 | l = Latex(latex4, s=1, c='white', bg='', alpha=0.9, usetex=False, fromweb=False) 14 | l.crop(0.3, 0.3) # crop top and bottom 30% 15 | l.pos(2,0,0) 16 | 17 | p = Point() 18 | box = l.box() # return the bounding box of an actor 19 | 20 | show(p, l, box, axes=8) 21 | -------------------------------------------------------------------------------- /examples/basic/lightings.py: -------------------------------------------------------------------------------- 1 | from vtkplotter import * 2 | 3 | styles = ['default', 'metallic', 'plastic', 'shiny', 'reflective'] 4 | 5 | a = load(datadir+"beethoven.ply").subdivide() 6 | 7 | for i,s in enumerate(styles): 8 | show(a.clone().lighting(s), Text(s), at=i, N=len(styles)) 9 | 10 | interactive() 11 | -------------------------------------------------------------------------------- /examples/basic/lights.py: -------------------------------------------------------------------------------- 1 | from vtkplotter import Plotter, load, Plane, datadir 2 | 3 | vp = Plotter() 4 | 5 | cow = vp.load(datadir+"cow.byu", c="grey", alpha=0.7) 6 | vp += Plane(pos=[0, -3.6, 0], normal=[0, 1, 0], sx=20, texture="grass") 7 | vp.show(viewup='y') 8 | 9 | # vp.light() returns a vtkLight object with focal Point, fp, to actor cow 10 | # fp can also be explicitly set as fp=[x,y,z] 11 | l = vp.addLight(pos=[-6, 6, 6], focalPoint=cow, deg=12, showsource=1) 12 | 13 | # can be switched on/off this way 14 | #l.SwitchOff() 15 | 16 | vp.show() 17 | -------------------------------------------------------------------------------- /examples/basic/lorenz.py: -------------------------------------------------------------------------------- 1 | from vtkplotter import Plotter, mag, Points, Point 2 | import numpy as np 3 | 4 | 5 | dt = 0.002 6 | y = [25.0, -10.0, -7.0] # Starting point (initial condition) 7 | pts, cols = [], [] 8 | 9 | 10 | for t in np.linspace(0, 20, int(20 / dt)): 11 | # Integrate a funny differential equation 12 | dydt = np.array( 13 | [-8 / 3.0 * y[0] + y[1] * y[2], -10.0 * (y[1] - y[2]), -y[1] * y[0] + 28.0 * y[1] - y[2]] 14 | ) 15 | y = y + dydt * dt 16 | 17 | c = np.clip([mag(dydt) * 0.005], 0, 1)[0] # color by speed 18 | pts.append(y) 19 | cols.append([c, 0, 1 - c]) 20 | 21 | scene = Plotter(title="Lorenz attractor", axes=2, verbose=0, bg="w") 22 | scene += Point(y, r=20, c="g") 23 | scene += Points(pts, r=5, c=cols) 24 | scene.show() 25 | -------------------------------------------------------------------------------- /examples/basic/manypoints.py: -------------------------------------------------------------------------------- 1 | """ 2 | Colorize a large cloud of points by passing 3 | colors and transparencies in the format (R,G,B,A) 4 | """ 5 | print(__doc__) 6 | from vtkplotter import Points 7 | import numpy as np 8 | import time 9 | 10 | N = 1000000 11 | 12 | pts = np.random.rand(N, 3) 13 | RGB = pts * 255 14 | Alpha = pts[:, 2] * 255 15 | RGBA = np.c_[RGB, Alpha] # concatenate 16 | 17 | print("clock starts") 18 | t0 = time.clock() 19 | 20 | # passing c in format (R,G,B,A) is ~50x faster 21 | pts = Points(pts, r=2, c=RGBA) #fast 22 | #pts = Points(pts, r=2, c=pts, alpha=pts[:, 2]) #slow 23 | 24 | t1 = time.clock() 25 | print("----> elapsed time:", t1-t0, "seconds for N:", N) 26 | 27 | pts.show(bg="white", axes=True) 28 | -------------------------------------------------------------------------------- /examples/basic/manyspheres.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example that shows how to draw very large number of 3 | spheres (same for Points, lines) with different colors 4 | or different radius. Resolution (res) can be specified. 5 | """ 6 | # (vtk versions<8.0 might be slow) 7 | from vtkplotter import show, Spheres, Text 8 | from random import gauss 9 | 10 | N = 40000 11 | 12 | cols = range(N) # color numbers 13 | pts = [(gauss(0, 1), gauss(0, 2), gauss(0, 1)) for i in cols] 14 | rads = [abs(pts[i][1]) / 10 for i in cols] # radius=0 for y=0 15 | 16 | # all have same radius but different colors: 17 | s0 = Spheres(pts, c=cols, r=0.1, res=3) # res= theta-phi resolution 18 | 19 | # all have same color but different radius along y: 20 | s1 = Spheres(pts, r=rads, c="lb", res=8) 21 | 22 | print("..rendering spheres:", N * 2) 23 | show(s0, at=0, N=2, axes=2, viewup=(-0.7, 0.7, 0)) 24 | show(s1, Text(__doc__), at=1, zoom=1.5, interactive=1) 25 | -------------------------------------------------------------------------------- /examples/basic/markpoint.py: -------------------------------------------------------------------------------- 1 | """ 2 | Mark a specific point 3 | on a mesh with some text. 4 | """ 5 | from vtkplotter import Sphere, Point, show, Text 6 | 7 | sp = Sphere().wireframe(True) 8 | 9 | pcoords = sp.getPoint(144) 10 | 11 | pt = Point(pcoords, r=12, c="white") 12 | 13 | tx = Text("my fave\npoint", pcoords, s=0.1, c="lightblue", bc="green", followcam=False) 14 | 15 | show(sp, pt, tx, Text(__doc__), axes=1) 16 | -------------------------------------------------------------------------------- /examples/basic/mesh_alphas.py: -------------------------------------------------------------------------------- 1 | """ 2 | Create a set of transparencies which can be passed to method pointColors() 3 | """ 4 | from vtkplotter import load, show, Text, datadir 5 | 6 | mesh = load(datadir+"beethoven.ply") 7 | 8 | # pick y coordinates of vertices and use them as scalars 9 | scals = mesh.coordinates()[:, 1] 10 | 11 | # define opacities in the range of the scalar, 12 | # at min(scals) alpha is 0.1, 13 | # at max(scals) alpha is 0.9: 14 | alphas = [0.1, 0.1, 0.3, 0.4, 0.9] 15 | 16 | mesh.pointColors(scals, alpha=alphas, cmap="copper") 17 | # print(mesh.scalars('pointColors_copper')) # retrieve scalars 18 | 19 | show(mesh, Text(__doc__), axes=9) 20 | -------------------------------------------------------------------------------- /examples/basic/mesh_bands.py: -------------------------------------------------------------------------------- 1 | """ 2 | Use a scalar to paint colored bands on a mesh, 3 | this can be combined with opacities values for each vertex of the mesh. 4 | Keyword depthpeeling improves the rendering of translucent objects. 5 | """ 6 | from vtkplotter import show, Hyperboloid, Torus, Text 7 | from numpy import linspace 8 | 9 | doc = Text(__doc__, c="k", bg="lg") 10 | 11 | 12 | hyp = Hyperboloid() 13 | scalars = hyp.coordinates()[:, 2] # let z-coord be the scalar 14 | hyp.pointColors(scalars, bands=5, cmap="rainbow") # make color bands 15 | 16 | tor = Torus(thickness=0.3) 17 | scalars = tor.coordinates()[:, 2] # let z-coord be the scalar 18 | transp = linspace(1, 0.5, len(scalars)) # set transparencies from 1 -> .5 19 | tor.pointColors(scalars, alpha=transp, bands=3, cmap="winter") 20 | 21 | show(hyp, tor, doc, viewup="z", depthpeeling=1, axes=2) 22 | -------------------------------------------------------------------------------- /examples/basic/mesh_custom.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example on how to specify a color for each 3 | individual cell or point of an actor's mesh. 4 | Keyword depthpeeling may improve the rendering of transparent objects. 5 | """ 6 | from vtkplotter import * 7 | 8 | doc = Text(__doc__, pos=1, c="w") 9 | 10 | 11 | man = load(datadir+"man.vtk") 12 | 13 | # let the scalar be the z coordinate of the mesh vertices 14 | scals = man.coordinates()[:, 2] 15 | 16 | # custom color map with specified opacities 17 | #mymap = ["darkblue", "cyan", (1, 0, 0)] 18 | #alphas = [0.8, 0.4, 0.2] 19 | 20 | # - OR by predefined color numbers: 21 | mymap = [i for i in range(10)] 22 | alphas = [i/10. for i in range(10)] 23 | 24 | # - OR by generating a palette betwwen 2 colors: 25 | # from vtkplotter.colors import makePalette 26 | #mymap = makePalette('pink', 'green', N=500, hsv=True) 27 | #alphas = 1 28 | 29 | man.pointColors(scals, cmap=mymap, alpha=alphas).addScalarBar() 30 | 31 | show(man, doc, viewup="z", axes=1, depthpeeling=1) 32 | -------------------------------------------------------------------------------- /examples/basic/mesh_map2cell.py: -------------------------------------------------------------------------------- 1 | """How to transform/map an array 2 | which is defined on the vertices of a mesh 3 | to its cells with mapPointsToCells() 4 | """ 5 | from vtkplotter import * 6 | 7 | mesh1 = load(datadir+'icosahedron.vtk') 8 | 9 | # let the scalar be the z coordinate of the mesh vertices 10 | scals = mesh1.coordinates()[:, 2] 11 | 12 | mesh1.lineWidth(0.1).addPointScalars(scals, name='scals') 13 | mesh2 = mesh1.clone().addScalarBar().mapPointsToCells() 14 | 15 | doc = Text(__doc__, pos=8, c="w") 16 | msg1 = Text("Scalar originally defined on points..", pos=5, c="w") 17 | msg2 = Text("..is interpolated to cells.", pos=5, c="w") 18 | 19 | printInfo(mesh1) 20 | printInfo(mesh2) 21 | 22 | show(mesh1, msg1, doc, at=0, N=2, axes=1, viewup="z") 23 | show(mesh2, msg2, at=1, interactive=True) 24 | 25 | -------------------------------------------------------------------------------- /examples/basic/mesh_modify.py: -------------------------------------------------------------------------------- 1 | """ 2 | Modify mesh vertex positions. 3 | """ 4 | from vtkplotter import * 5 | 6 | dsc = Disc().lineWidth(0.1) 7 | coords = dsc.coordinates() 8 | t = Text(__doc__) 9 | 10 | for i in range(50): 11 | coords[:,2] = sin(i/10.*coords[:,0])/5 # move vertices in z 12 | dsc.setPoints(coords) # modify mesh 13 | show(dsc, t, axes=8, resetcam=0, interactive=0) 14 | 15 | interactive() 16 | -------------------------------------------------------------------------------- /examples/basic/mesh_sharemap.py: -------------------------------------------------------------------------------- 1 | """ 2 | How to share the same color map 3 | across different meshes. 4 | """ 5 | from vtkplotter import load, Text, show, datadir 6 | 7 | 8 | ##################################### 9 | man1 = load(datadir+"man.vtk") 10 | scals = man1.coordinates()[:, 2] * 5 + 27 # pick z coordinates [18->34] 11 | 12 | man1.pointColors(scals, cmap="jet", vmin=18, vmax=44) 13 | 14 | ##################################### 15 | man2 = load(datadir+"man.vtk") 16 | scals = man2.coordinates()[:, 2] * 5 + 37 # pick z coordinates [28->44] 17 | 18 | man2.pointColors(scals, cmap="jet", vmin=18, vmax=44) 19 | 20 | show([[man1, Text(__doc__)], man2], N=2, elevation=-40) 21 | -------------------------------------------------------------------------------- /examples/basic/mesh_threshold.py: -------------------------------------------------------------------------------- 1 | """ 2 | Extracts the cells where scalar value 3 | satisfies a threshold criterion. 4 | """ 5 | from vtkplotter import * 6 | 7 | doc = Text(__doc__) 8 | 9 | man = load(datadir+"man.vtk") 10 | 11 | scals = man.coordinates()[:, 1] + 37 # pick y coords of vertices 12 | 13 | man.pointColors(scals, cmap="cool") 14 | man.addScalarBar(title="threshold", horizontal=True) 15 | 16 | # make a copy and threshold the mesh 17 | cutman = man.clone().threshold(scals, vmin=36.9, vmax=37.5) 18 | 19 | printInfo(cutman) 20 | 21 | # distribute the actors on 2 renderers 22 | show([[man, doc], cutman], N=2, elevation=-30, axes=0) 23 | -------------------------------------------------------------------------------- /examples/basic/mirror.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "application/vnd.jupyter.widget-view+json": { 11 | "model_id": "6641ad0338cc4bdbba28d11714154945", 12 | "version_major": 2, 13 | "version_minor": 0 14 | }, 15 | "text/plain": [ 16 | "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, …" 17 | ] 18 | }, 19 | "metadata": {}, 20 | "output_type": "display_data" 21 | } 22 | ], 23 | "source": [ 24 | "\"\"\"Mirror a mesh along one of the Cartesian axes.\"\"\"\n", 25 | "\n", 26 | "from vtkplotter import *\n", 27 | "\n", 28 | "myted1 = load(datadir+\"teddy.vtk\")\n", 29 | "\n", 30 | "myted2 = myted1.clone().mirror(\"y\").pos(0,3,0).color(\"green\")\n", 31 | "\n", 32 | "show(myted1, myted2)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [] 41 | } 42 | ], 43 | "metadata": { 44 | "kernelspec": { 45 | "display_name": "Python 3", 46 | "language": "python", 47 | "name": "python3" 48 | }, 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 3 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython3", 59 | "version": "3.6.8" 60 | } 61 | }, 62 | "nbformat": 4, 63 | "nbformat_minor": 2 64 | } 65 | -------------------------------------------------------------------------------- /examples/basic/mirror.py: -------------------------------------------------------------------------------- 1 | """ 2 | Mirror a mesh along one of the Cartesian axes. 3 | """ 4 | from vtkplotter import Plotter, Text, datadir 5 | 6 | vp = Plotter(axes=2) 7 | 8 | myted1 = vp.load(datadir+"teddy.vtk") 9 | 10 | myted2 = myted1.clone().mirror("y").pos([0, 3, 0]).color("green") 11 | 12 | vp.show(myted1, myted2, Text(__doc__), viewup="z") 13 | -------------------------------------------------------------------------------- /examples/basic/mouseclick.py: -------------------------------------------------------------------------------- 1 | """ 2 | Mouse click event example 3 | click of the mouse causes a call to a custom function. 4 | """ 5 | from vtkplotter import Plotter, printc, Text, datadir 6 | 7 | 8 | def onLeftClick(actor): 9 | printc("Left button pressed on", [actor], c="g") 10 | 11 | 12 | def onMiddleClick(actor): 13 | printc("Middle button pressed on", [actor], c="y") 14 | 15 | 16 | def onRightClick(actor): 17 | printc("Right button pressed on", [actor], c="r") 18 | 19 | 20 | vp = Plotter(verbose=0) 21 | 22 | vp.load(datadir+"skyscraper.obj", c='gold') 23 | 24 | vp.mouseLeftClickFunction = onLeftClick 25 | vp.mouseMiddleClickFunction = onMiddleClick 26 | vp.mouseRightClickFunction = onRightClick 27 | 28 | printc("Click object to trigger function call", invert=1, box="-") 29 | 30 | vp += Text(__doc__) 31 | vp.show() 32 | -------------------------------------------------------------------------------- /examples/basic/multiblocks.py: -------------------------------------------------------------------------------- 1 | # Files can be grouped into a single data entity 2 | # which can be loaded as a single object and unpacked. 3 | # 4 | from vtkplotter import * 5 | 6 | cube = Cube(side=30) 7 | scals = cube.coordinates()[:,1] 8 | poly = cube.addPointScalars(scals, 'scalsname').polydata() 9 | 10 | img = load(datadir+'vase.vti').imagedata() 11 | 12 | filename = "multiblock.vtm" 13 | 14 | mblock = write([poly, img], filename) #returns a vtkMultiBlockData 15 | printc("~save wrote file", filename, 16 | "and corresponding directory", c='g') 17 | 18 | # load back from file into a list of actors/volumes 19 | mbacts = load(filename) # loads and unpacks a MultiBlockData obj 20 | 21 | show(mbacts, Text('load("file.vtm") #MultiBlockData', c='k'), bg='w') 22 | 23 | show(mblock, Text('show(multiblock)', c='w'), newPlotter=True, pos=(800,0)) 24 | -------------------------------------------------------------------------------- /examples/basic/multiwindows.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example of drawing objects on different windows 3 | and/or subwindows within the same window. 4 | We split the main window in a 25 subwindows and draw something 5 | in specific windows numbers. 6 | Then open an independent window and draw a shape on it. 7 | """ 8 | print(__doc__) 9 | 10 | from vtkplotter import Plotter, Text, datadir 11 | 12 | 13 | # this is one instance of the class Plotter with 5 raws and 5 columns 14 | vp1 = Plotter(shape=(5, 5), axes=0, bg="white") 15 | # having set shape=(n,m), script execution after the show() is not held 16 | 17 | # set a different background color for a specific subwindow (the last one) 18 | vp1.renderers[24].SetBackground(0.8, 0.9, 0.9) # use vtk method SetBackground() 19 | 20 | # load the actors and give them a name 21 | a = vp1.load(datadir+"airboat.vtk").legend("some legend") 22 | b = vp1.load(datadir+"cessna.vtk", c="red") 23 | c = vp1.load(datadir+"atc.ply") 24 | 25 | # show a text in each renderer 26 | for i in range(25): 27 | txt = Text("renderer\nnr."+str(i), c='k', s=0.5, font='arial') 28 | vp1.show(txt, at=i, interactive=0) 29 | 30 | vp1.show(a, at=22) 31 | vp1.show(b, at=23) 32 | vp1.show(c, at=24, interactive=0) 33 | 34 | 35 | ############################################################ 36 | # declare a second independent instance of the class Plotter 37 | vp2 = Plotter(pos=(500, 250), bg=(0.9, 0.9, 1)) # blue-ish background 38 | 39 | vp2.load(datadir+"porsche.ply").legend("an other window") 40 | 41 | vp2.show() # show and interact with mouse and keyboard 42 | -------------------------------------------------------------------------------- /examples/basic/pca.py: -------------------------------------------------------------------------------- 1 | """ 2 | Draw the PCA (Principal Component Analysis) ellipsoid that contains 3 | 50% of a cloud of Points, then check if points are inside the surface. 4 | Extra info is stored in actor.info['sphericity'], 'va', 'vb', 'vc'. 5 | """ 6 | from vtkplotter import Plotter, pcaEllipsoid, Points, Text 7 | import numpy as np 8 | 9 | 10 | vp = Plotter() 11 | 12 | pts = np.random.randn(500, 3) # random gaussian point cloud 13 | 14 | act = pcaEllipsoid(pts, pvalue=0.5, pcaAxes=1) 15 | 16 | ipts = act.getActor(0).insidePoints(pts) # act is a vtkAssembly 17 | opts = act.getActor(0).insidePoints(pts, invert=True) 18 | vp += Points(ipts, c="g") 19 | vp += Points(opts, c="r") 20 | vp += [act, Text(__doc__)] 21 | 22 | print("inside points #", len(ipts)) 23 | print("outside points #", len(opts)) 24 | print("sphericity :", act.info["sphericity"]) 25 | vp.show() 26 | -------------------------------------------------------------------------------- /examples/basic/ribbon.py: -------------------------------------------------------------------------------- 1 | """ 2 | Form a surface by joining two close lines. 3 | """ 4 | from vtkplotter import * 5 | 6 | 7 | l1 = [[sin(x), cos(x), x / 2] for x in arange(0, 9, 0.1)] 8 | l2 = [[sin(x) + 0.2, cos(x) + x / 15, x / 2] for x in arange(0, 9, 0.1)] 9 | 10 | t1 = Tube(l1, c="g", r=0.02) 11 | t2 = Tube(l2, c="b", r=0.02) 12 | 13 | r = Ribbon(l1, l2, alpha=0.2, res=(200, 5)) 14 | r.wireframe(True).legend("ruled surf") 15 | 16 | doc = Text(__doc__) 17 | show(r, t1, t2, doc, viewup="z", axes=1, bg="w") 18 | -------------------------------------------------------------------------------- /examples/basic/rotateImage.py: -------------------------------------------------------------------------------- 1 | """ 2 | Normal jpg/png images can be loaded, 3 | cropped and rendered as any vtkImageActor 4 | """ 5 | from vtkplotter import Plotter, Text, datadir 6 | 7 | vp = Plotter(axes=3, verbose=0) 8 | 9 | for i in range(5): 10 | a = vp.load(datadir+"images/dog.jpg").crop(bottom=0.2) # crop 20% 11 | a.scale(1-i/10.0).alpha(0.8) # image can be scaled in size 12 | a.rotateX(20*i).pos(0,0,30*i) # (can concatenate methods) 13 | 14 | vp += Text(__doc__) 15 | 16 | vp.show() 17 | -------------------------------------------------------------------------------- /examples/basic/shadow.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "application/vnd.jupyter.widget-view+json": { 11 | "model_id": "29c92382f9f74b84b7cdef29f3916659", 12 | "version_major": 2, 13 | "version_minor": 0 14 | }, 15 | "text/plain": [ 16 | "Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, fps_meter=False, grid=[-1, -1, -1, 1, 1, 1]…" 17 | ] 18 | }, 19 | "metadata": {}, 20 | "output_type": "display_data" 21 | } 22 | ], 23 | "source": [ 24 | "\"\"\"Make a shadow of 2 meshes on the wall.\"\"\"\n", 25 | "from vtkplotter import *\n", 26 | "\n", 27 | "a = load(datadir + \"spider.ply\").normalize().rotateZ(-90).addShadow(x=-4)\n", 28 | "\n", 29 | "s = Sphere(pos=[-0.4, 1.4, 0.3], r=0.3).addShadow(x=-4)\n", 30 | "\n", 31 | "show(a, s)" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [] 40 | } 41 | ], 42 | "metadata": { 43 | "kernelspec": { 44 | "display_name": "Python 3", 45 | "language": "python", 46 | "name": "python3" 47 | }, 48 | "language_info": { 49 | "codemirror_mode": { 50 | "name": "ipython", 51 | "version": 3 52 | }, 53 | "file_extension": ".py", 54 | "mimetype": "text/x-python", 55 | "name": "python", 56 | "nbconvert_exporter": "python", 57 | "pygments_lexer": "ipython3", 58 | "version": "3.6.8" 59 | } 60 | }, 61 | "nbformat": 4, 62 | "nbformat_minor": 2 63 | } 64 | -------------------------------------------------------------------------------- /examples/basic/shadow.py: -------------------------------------------------------------------------------- 1 | """Make a shadow of 2 meshes on the wall.""" 2 | from vtkplotter import * 3 | 4 | a = load(datadir + "spider.ply") 5 | a.normalize().rotateZ(-90).addShadow(x=-4, alpha=0.5) 6 | 7 | s = Sphere(pos=[-0.4, 1.4, 0.3], r=0.3).addShadow(x=-4) 8 | 9 | show(a, s, Text(__doc__), axes=1, viewup="z", bg="w") 10 | -------------------------------------------------------------------------------- /examples/basic/shrink.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "application/vnd.jupyter.widget-view+json": { 11 | "model_id": "8059a1bb4d1a405694ef645a54f58939", 12 | "version_major": 2, 13 | "version_minor": 0 14 | }, 15 | "text/plain": [ 16 | "Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, fps_meter=False, grid=[-1.505191683769226, …" 17 | ] 18 | }, 19 | "metadata": {}, 20 | "output_type": "display_data" 21 | } 22 | ], 23 | "source": [ 24 | "\"\"\"Shrink the triangulation of a mesh to make the inside visible.\"\"\"\n", 25 | "\n", 26 | "from vtkplotter import *\n", 27 | "\n", 28 | "pot = load(datadir+\"teapot.vtk\").shrink(0.75)\n", 29 | "\n", 30 | "s = Sphere(r=0.2).pos(0, 0, -0.5)\n", 31 | "\n", 32 | "show(pot, s)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [] 41 | } 42 | ], 43 | "metadata": { 44 | "kernelspec": { 45 | "display_name": "Python 3", 46 | "language": "python", 47 | "name": "python3" 48 | }, 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 3 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython3", 59 | "version": "3.7.1" 60 | } 61 | }, 62 | "nbformat": 4, 63 | "nbformat_minor": 2 64 | } 65 | -------------------------------------------------------------------------------- /examples/basic/shrink.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shrink the triangulation of a mesh 3 | to make the inside visible. 4 | """ 5 | from vtkplotter import load, Sphere, show, Text, datadir 6 | 7 | pot = load(datadir+"teapot.vtk").shrink(0.75) 8 | 9 | s = Sphere(r=0.2).pos(0, 0, -0.5) 10 | 11 | show(pot, s, Text(__doc__), viewup="z") 12 | -------------------------------------------------------------------------------- /examples/basic/silhouette.py: -------------------------------------------------------------------------------- 1 | """Show the silhouette of a mesh 2 | as seen along a specified direction. 3 | """ 4 | from vtkplotter import * 5 | 6 | s = Hyperboloid().rotateX(20) 7 | 8 | sx = s.clone().projectOnPlane('x').c('r').x(-3) 9 | sy = s.clone().projectOnPlane('y').c('g').y(-3) 10 | sz = s.clone().projectOnPlane('z').c('b').z(-3) 11 | 12 | show(s, sx, sy, sz, 13 | sx.silhouette(), 14 | sy.silhouette(), 15 | sz.silhouette(), 16 | Text(__doc__), 17 | axes={'zxGrid':True}, 18 | viewup='z', 19 | bg='w') 20 | -------------------------------------------------------------------------------- /examples/basic/sliders.py: -------------------------------------------------------------------------------- 1 | """Use two sliders to change color and transparency of a mesh. 2 | pos = position corner number: horizontal [1-4] or vertical [11-14] 3 | """ 4 | print(__doc__) 5 | from vtkplotter import Plotter, datadir 6 | 7 | vp = Plotter(axes=0, bg="w") 8 | 9 | mesh = vp.load(datadir+"magnolia.vtk").flat().lw(0.1) 10 | 11 | 12 | def slider1(widget, event): 13 | value = widget.GetRepresentation().GetValue() 14 | mesh.color(value) 15 | 16 | 17 | def slider2(widget, event): 18 | value = widget.GetRepresentation().GetValue() 19 | mesh.alpha(value) 20 | 21 | 22 | vp.addSlider2D(slider1, -9, 9, value=0, pos=4, title="color number") 23 | 24 | vp.addSlider2D( 25 | slider2, xmin=0.01, xmax=0.99, value=0.5, 26 | pos=14, c="blue", title="alpha value (opacity)" 27 | ) 28 | vp.show() 29 | -------------------------------------------------------------------------------- /examples/basic/sliders3d.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3D sliders. 3 | Can be combined with 2D sliders. 4 | """ 5 | from vtkplotter import Plotter, datadir 6 | 7 | vp = Plotter() 8 | 9 | mesh = vp.load(datadir+"spider.ply") 10 | mesh.normalize().rotateZ(190).scale(0.8) 11 | 12 | 13 | def slider_y(widget, event): 14 | value = widget.GetRepresentation().GetValue() 15 | mesh.y(value) # set y coordinate position 16 | 17 | 18 | vp.addSlider3D( 19 | slider_y, 20 | pos1=[2, -1, -1], 21 | pos2=[2, 1, -1], 22 | xmin=-1, 23 | xmax=1, 24 | value=0, 25 | s=0.04, 26 | c="r", 27 | rotation=45, 28 | title="y position", 29 | ) 30 | 31 | vp.show(viewup="z", axes=1) 32 | -------------------------------------------------------------------------------- /examples/basic/specular.py: -------------------------------------------------------------------------------- 1 | """ 2 | Setting illumination properties: 3 | ambient, diffuse 4 | specular, specularPower, specularColor. 5 | """ 6 | #https://lorensen.github.io/VTKExamples/site/Python/Rendering/SpecularSpheres 7 | from vtkplotter import Plotter, Text, Arrow, datadir 8 | 9 | 10 | vp = Plotter(axes=1, bg="w") 11 | 12 | ambient, diffuse, specular = 0.1, 0., 0. 13 | specularPower, specularColor= 20, 'white' 14 | 15 | for i in range(8): 16 | s = vp.load(datadir+'pumpkin.vtk')#.color(i) 17 | s.normalize().pos((i%4)*2.2, int(i<4)*3, 0) 18 | 19 | #s.phong() 20 | #s.gouraud() 21 | s.flat() 22 | 23 | # modify the default with specific values 24 | s.lighting('default', ambient, diffuse, specular, specularPower, specularColor) 25 | #ambient += 0.125 26 | diffuse += 0.125 27 | specular += 0.125 28 | 29 | vp += Text(__doc__) 30 | vp.show() 31 | 32 | print('Adding a light source..') 33 | p = (3, 1.5, 3) 34 | f = (3, 1.5, 0) 35 | vp.addLight(pos=p, focalPoint=f) 36 | vp += Arrow(p,f, s=0.01, c='gray', alpha=0.2) 37 | vp.show() 38 | -------------------------------------------------------------------------------- /examples/basic/surfIntersect.py: -------------------------------------------------------------------------------- 1 | """ 2 | 1D intersection of two polygonal meshes 3 | """ 4 | from vtkplotter import * 5 | 6 | car = load(datadir+"porsche.ply").alpha(0.2) 7 | 8 | s = Tube([(-9.,0.,0.), (0.,1.,0.), (9.,0.,0.)]) 9 | s.triangle().clean().color("violet").alpha(0.2) 10 | 11 | contour = surfaceIntersection(car, s) 12 | contour.lw(4).printInfo() 13 | 14 | show(s, car, contour, Text(__doc__), bg='w') 15 | -------------------------------------------------------------------------------- /examples/basic/text_just.py: -------------------------------------------------------------------------------- 1 | """ 2 | Text jutification and positioning: 3 | top-left, top-right, bottom-left, bottom-right, 4 | center-left, center-right, center-left, center-right 5 | """ 6 | print(__doc__) 7 | from vtkplotter import show, Text, Point 8 | 9 | txt = "Text\njustification\n& position" 10 | 11 | pos = [1, 2, 0] 12 | 13 | tx = Text(txt, pos, s=1, depth=0.1, justify="bottom-left") 14 | 15 | t0 = Point(pos, c="r") # mark text position 16 | ax = Point(c="blue") # mark axes origin 17 | 18 | show(tx, 19 | tx.box().c("y"), 20 | t0, 21 | ax, 22 | axes=8, bg="lb", size=(500,500) 23 | ) 24 | -------------------------------------------------------------------------------- /examples/basic/texturecubes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show a cube for each available texture name 3 | any jpg file can be used as texture. 4 | """ 5 | from vtkplotter import Plotter, Cube, Text 6 | from vtkplotter.settings import textures, textures_path 7 | 8 | print(__doc__) 9 | print(textures_path) 10 | print(textures) 11 | 12 | vp = Plotter(N=len(textures), axes=0) 13 | 14 | for i, txt in enumerate(textures): 15 | cb = Cube().texture(txt) 16 | tname = Text(txt, pos=3) 17 | vp.show(cb, tname, at=i) 18 | 19 | vp.show(interactive=1) 20 | -------------------------------------------------------------------------------- /examples/basic/trail.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example usage of addTrail(). 3 | Add a trailing line to a moving object. 4 | """ 5 | print(__doc__) 6 | from vtkplotter import Plotter, sin, Sphere, Point 7 | 8 | 9 | vp = Plotter(axes=6, bg='white', interactive=0) 10 | 11 | s = Sphere().c("green").bc("tomato") 12 | s.cutWithPlane([-0.9, 0, 0], showcut=True) # cut left part of sphere 13 | 14 | p = Point([1, 1, 1], r=12, c="k") 15 | 16 | # add a trail to point p with maximum length 0.5 and 50 segments 17 | p.addTrail(c="k", lw=3, maxlength=0.5, n=50) 18 | vp += [s, p] 19 | 20 | for i in range(200): 21 | p.pos([-2 + i / 100.0, sin(i / 5.0) / 15, 0]) 22 | vp.show() 23 | vp.camera.Azimuth(-0.2) 24 | 25 | vp.show(interactive=1) 26 | -------------------------------------------------------------------------------- /examples/basic/tube.py: -------------------------------------------------------------------------------- 1 | """ 2 | A scalar array can be specified to vary 3 | radius and color of a line represented as a tube. 4 | """ 5 | print(__doc__) 6 | 7 | from vtkplotter import * 8 | 9 | doc = Text(__doc__) 10 | 11 | 12 | ln = [[sin(x), cos(x), x / 2] for x in arange(0, 9, 0.1)] 13 | N = len(ln) 14 | 15 | ############################### a simple tube( along ln 16 | t1 = Tube(ln, c="blue", r=0.08) 17 | show(t1, doc, at=0, N=3, axes=1, viewup="z") 18 | 19 | ############################### vary radius 20 | rads = [0.3 * (cos(6.0 * ir / N)) ** 2 + 0.1 for ir in range(N)] 21 | 22 | t2 = Tube(ln, r=rads, c="tomato", res=24) 23 | show(t2, at=1) 24 | 25 | ############################### vary color 26 | cols = [i for i in range(N)] 27 | cols = makeBands(cols, 5) # make color bins 28 | 29 | t3 = Tube(ln, r=rads, c=cols, res=24) 30 | show(t3, at=2, interactive=1) 31 | -------------------------------------------------------------------------------- /examples/data: -------------------------------------------------------------------------------- 1 | ../vtkplotter/data -------------------------------------------------------------------------------- /examples/notebooks/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Jupyter Notebooks 3 | 4 | Here you will find a set of basic notebooks. 5 | It allows to embed a redering window into a jupyter notebook via 6 | [K3D](https://github.com/K3D-tools/K3D-jupyter) 7 | (or optionally with [panel](https://github.com/pyviz/panel)). 8 | 9 | More notebooks are available in each example directory. 10 | 11 | On top of this `K3D` allows to export an interactive 12 | [snapshot](https://vtkplotter.embl.es/examples/K3D_snapshot.html) 13 | of the rendered scene. 14 | 15 | `jupyter notebook examples/notebooks/embryo.ipynb` 16 | 17 |  18 | -------------------------------------------------------------------------------- /examples/notebooks/embryo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "application/vnd.jupyter.widget-view+json": { 11 | "model_id": "f8cb4b66b66a471a814f9590d5692cb4", 12 | "version_major": 2, 13 | "version_minor": 0 14 | }, 15 | "text/plain": [ 16 | "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, …" 17 | ] 18 | }, 19 | "metadata": {}, 20 | "output_type": "display_data" 21 | } 22 | ], 23 | "source": [ 24 | "from vtkplotter import *\n", 25 | "\n", 26 | "#embedWindow(False)\n", 27 | "\n", 28 | "em = load(datadir+'embryo.tif', threshold=40)\n", 29 | "em.color('green')\n", 30 | "\n", 31 | "s = Sphere(r=2000, res=10).color('tomato').pos(8000,0,0).wireframe()\n", 32 | "\n", 33 | "show(em, s)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [] 42 | } 43 | ], 44 | "metadata": { 45 | "kernelspec": { 46 | "display_name": "Python 3", 47 | "language": "python", 48 | "name": "python3" 49 | }, 50 | "language_info": { 51 | "codemirror_mode": { 52 | "name": "ipython", 53 | "version": 3 54 | }, 55 | "file_extension": ".py", 56 | "mimetype": "text/x-python", 57 | "name": "python", 58 | "nbconvert_exporter": "python", 59 | "pygments_lexer": "ipython3", 60 | "version": "3.6.8" 61 | } 62 | }, 63 | "nbformat": 4, 64 | "nbformat_minor": 2 65 | } 66 | -------------------------------------------------------------------------------- /examples/other/colorpalette.py: -------------------------------------------------------------------------------- 1 | """ 2 | Generate a list of N colors starting from color1 to color2 in RGB or HSV space 3 | """ 4 | from __future__ import print_function 5 | 6 | print(__doc__) 7 | 8 | from vtkplotter.colors import makePalette, getColorName 9 | 10 | cols = makePalette("red", "blue", 10, hsv=True) 11 | 12 | for c in cols: 13 | print("rgb =", c, " closest color is:", getColorName(c)) 14 | -------------------------------------------------------------------------------- /examples/other/create_logo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Create an animated logo. 3 | """ 4 | from vtkplotter import * 5 | 6 | exa = Polygon().scale(4.1).pos(5.25, 4.8, 0).off() 7 | his = histogram2D([-1, 1], [-1, 1]).getActors() 8 | 9 | exah, cmh = [], [] 10 | for h in his: 11 | cm = h.centerOfMass() 12 | if exa.isInside(cm): 13 | h.c('green').shrink(0.9).addShadow(z=-.4) 14 | exah.append(h) 15 | cmh.append(cm) 16 | 17 | v1 = vector(9.4, 5.2, 0) 18 | v2 = vector(9.4, 2.7, 0) 19 | t1 = Text("EMBL", v1, c="k", s=1.5, depth=0) 20 | t2 = Text("European Molecular\nBiology Laboratory", v2, c="dg", s=0.6, depth=0) 21 | 22 | show(exa, exah, t1, t2, bg="w", axes=0, interactive=0, elevation=-50) 23 | for ti in reversed(range(100)): 24 | t = ti / 100. 25 | for j, h in enumerate(exah): 26 | cx, cy, _ = cmh[j] - [4,5,0] 27 | x = t*-4+(1-t)*6 28 | g = exp(-(cx-x)**2/.5)*2 29 | h.z(g) 30 | t1.pos([sin(t)*-10, 0, -0.41] + v1).alpha((1-t)**2) 31 | t2.pos([sin(t)*-15, 0, -0.41] + v2).alpha((1-t)**4) 32 | exah[13].c('red') 33 | show(exa, exah, t1, t2, resetcam=0, elevation=t, azimuth=-0.02) 34 | 35 | interactive() 36 | -------------------------------------------------------------------------------- /examples/other/dolfin/ascalarbar.py: -------------------------------------------------------------------------------- 1 | """#Control scalar bar range. 2 | > plot(u, mode='color', vmin=-3, vmax=3, style=1) 3 | 4 | Avaliable styles: 5 | 0. vtk 6 | 1. matplotlib 7 | 2. meshlab 8 | 3. paraview 9 | 4. bw 10 | """ 11 | from dolfin import * 12 | 13 | mesh = UnitSquareMesh(16, 16) 14 | V = FunctionSpace(mesh, 'Lagrange', 1) 15 | f = Expression('10*(x[0]+x[1]-1)', degree=1) 16 | u = interpolate(f, V) 17 | 18 | 19 | ################################## vtkplotter 20 | from vtkplotter.dolfin import plot 21 | 22 | plot(u, mode='color', vmin=-3, vmax=3, style=1, text=__doc__) 23 | 24 | -------------------------------------------------------------------------------- /examples/other/dolfin/calc_surface_area.py: -------------------------------------------------------------------------------- 1 | from dolfin import * 2 | import sympy as sp 3 | # Credits: 4 | # https://github.com/pf4d/fenics_scripts/calc_surface_area.py 5 | 6 | x, y = sp.symbols('x, y') 7 | 8 | # surface : 9 | def s(x,y): return sp.exp(x) 10 | 11 | # x-derivative of surface 12 | def dsdx(x,y): return s(x,y).diff(x, 1) 13 | 14 | # y-derivative of surface 15 | def dsdy(x,y): return s(x,y).diff(y, 1) 16 | 17 | # outward-pointing-normal-vector magnitude at surface : 18 | def n_mag_s(x,y): return sp.sqrt(1 + dsdx(x,y)**2 + dsdy(x,y)**2) 19 | 20 | # surface area of surface : 21 | def area(x,y): return sp.integrate(n_mag_s(x,y), (x,0,1), (y,0,1)) 22 | 23 | A_exact = area(x,y) 24 | 25 | for n in [5,10,100,500]: 26 | mesh = UnitSquareMesh(n,n) 27 | Q = FunctionSpace(mesh, "CG", 1) 28 | e = Expression('exp(x[0])', degree=2) 29 | f = interpolate(e, Q) 30 | A_num = assemble( sqrt(f.dx(0)**2 + f.dx(1)**2 + 1) * dx) 31 | print('for n = %i -- error = %.2e' % (n, abs(A_exact.evalf()-A_num))) 32 | 33 | n = 10 34 | mesh = UnitSquareMesh(n,n) 35 | Q = FunctionSpace(mesh, "CG", 1) 36 | e = Expression('exp(x[0])', degree=2) 37 | f = interpolate(e, Q) 38 | A_vector = project( sqrt(f.dx(0)**2 + f.dx(1)**2 + 1), Q) 39 | 40 | 41 | from vtkplotter.dolfin import plot 42 | plot(A_vector) 43 | 44 | -------------------------------------------------------------------------------- /examples/other/dolfin/collisions.py: -------------------------------------------------------------------------------- 1 | ''' 2 | compute_collision() will compute the collision of all the entities with 3 | a Point while compute_first_collision() will always return its first entry. 4 | Especially if a point is on an element edge this can be tricky. 5 | You may also want to compare with the Cell.contains(Point) tool. 6 | ''' 7 | # Script by Rudy at https://fenicsproject.discourse.group/t/ 8 | # any-function-to-determine-if-the-point-is-in-the-mesh/275/3 9 | import dolfin 10 | from vtkplotter.dolfin import shapes, plot, printc 11 | 12 | n = 4 13 | Px = 0.5 14 | Py = 0.5 15 | mesh = dolfin.UnitSquareMesh(n, n) 16 | bbt = mesh.bounding_box_tree() 17 | collisions = bbt.compute_collisions(dolfin.Point(Px, Py)) 18 | collisions1st = bbt.compute_first_entity_collision(dolfin.Point(Px, Py)) 19 | printc("collisions : ", collisions) 20 | printc("collisions 1st: ", collisions1st) 21 | 22 | for cell in dolfin.cells(mesh): 23 | contains = cell.contains(dolfin.Point(Px, Py)) 24 | printc("Cell", cell.index(), "contains P:", contains, c=contains) 25 | 26 | ########################################### 27 | pt = shapes.Point([Px, Py], c='blue') 28 | 29 | plot(mesh, pt, text=__doc__) 30 | -------------------------------------------------------------------------------- /examples/other/dolfin/demo_submesh.py: -------------------------------------------------------------------------------- 1 | """ 2 | how to extract matching 3 | sub meshes from a common mesh. 4 | """ 5 | from dolfin import * 6 | 7 | class Structure(SubDomain): 8 | def inside(self, x, on_boundary): 9 | return x[0] > 1.4 - DOLFIN_EPS and x[0] < 1.6 \ 10 | + DOLFIN_EPS and x[1] < 0.6 + DOLFIN_EPS 11 | 12 | mesh = RectangleMesh(Point(0.0, 0.0), Point(3.0, 1.0), 60, 20) 13 | 14 | # Create sub domain markers and mark everaything as 0 15 | sub_domains = MeshFunction("size_t", mesh, mesh.topology().dim()) 16 | sub_domains.set_all(0) 17 | 18 | # Mark structure domain as 1 19 | structure = Structure() 20 | structure.mark(sub_domains, 1) 21 | 22 | # Extract sub meshes 23 | fluid_mesh = SubMesh(mesh, sub_domains, 0) 24 | structure_mesh = SubMesh(mesh, sub_domains, 1) 25 | 26 | # Move structure mesh 27 | for x in structure_mesh.coordinates(): 28 | x[0] += 0.1*x[0]*x[1] 29 | 30 | # Move fluid mesh according to structure mesh 31 | ALE.move(fluid_mesh, structure_mesh) 32 | fluid_mesh.smooth() 33 | 34 | ############################################# 35 | from vtkplotter.dolfin import plot 36 | 37 | plot(fluid_mesh, text=__doc__, interactive=False) 38 | plot(structure_mesh, c='tomato', add=True) 39 | plot() 40 | 41 | -------------------------------------------------------------------------------- /examples/other/dolfin/ex01_show-mesh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Visualize a Fenics/dolfin mesh. 3 | Select mesh and press X to slice it. 4 | """ 5 | import dolfin 6 | from vtkplotter.dolfin import plot, datadir 7 | 8 | mesh1 = dolfin.Mesh(datadir + "dolfin_fine.xml") 9 | 10 | plot(mesh1) 11 | 12 | # show another light-green mesh in a new plotter window, 13 | # show file header too as an additional text comment 14 | mesh2 = dolfin.UnitCubeMesh(8,8,8) 15 | 16 | plot(mesh2, text=__doc__, color='lg', newPlotter=True) 17 | -------------------------------------------------------------------------------- /examples/other/dolfin/ex02_tetralize-mesh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tetrahedral meshes generation with 3 | package mshr and dolfin. 4 | 5 | You can then visualize the file with: 6 | > vtkplotter shuttle.xml 7 | """ 8 | import mshr 9 | import dolfin 10 | from vtkplotter.dolfin import datadir, plot 11 | 12 | fname = "shuttle.stl" 13 | 14 | surface = mshr.Surface3D(datadir + fname) 15 | 16 | # add a cylinder 17 | cyl = mshr.Cylinder(dolfin.Point(-1.4, 0, 0), 18 | dolfin.Point(-1.0, 0, 0), 0.5, 0.7) 19 | totdomain = surface + cyl 20 | 21 | polyhedral_domain = mshr.CSGCGALDomain3D(totdomain) 22 | dolfin.info(polyhedral_domain, True) 23 | 24 | generator = mshr.CSGCGALMeshGenerator3D() 25 | 26 | #### Try automatic 27 | generator.parameters["mesh_resolution"] = 35.0 28 | mesh = generator.generate(polyhedral_domain) 29 | 30 | xmlname = fname.split(".")[0] + ".xml" 31 | dolfin.File(xmlname) << mesh 32 | print(mesh, "saved to " + xmlname) 33 | 34 | 35 | ################################## 36 | plot(mesh, text=__doc__) 37 | ################################## 38 | 39 | -------------------------------------------------------------------------------- /examples/other/dolfin/ex03_poisson.py: -------------------------------------------------------------------------------- 1 | """ 2 | Poisson equation with Dirichlet conditions. 3 | 4 | -Laplace(u) = f in the unit square 5 | u = uD on the boundary 6 | 7 | uD = 1 + x^2 + 2*y^2 8 | (f = -6) 9 | """ 10 | ########################################################### fenics 11 | from fenics import * 12 | 13 | # Create mesh and define function space 14 | mesh = UnitSquareMesh(8, 8) 15 | V = FunctionSpace(mesh, "P", 1) 16 | 17 | # Define boundary condition 18 | uD = Expression("1 + x[0]*x[0] + 2*x[1]*x[1]", degree=2) 19 | bc = DirichletBC(V, uD, "on_boundary") 20 | 21 | # Define variational problem 22 | w = TrialFunction(V) 23 | v = TestFunction(V) 24 | u = Function(V) 25 | f = Constant(-6.0) 26 | 27 | # Compute solution 28 | solve( dot(grad(w), grad(v))*dx == f*v*dx, u, bc) 29 | 30 | f = r'-\nabla^{2} u=f' 31 | 32 | ########################################################### vtkplotter 33 | from vtkplotter.dolfin import plot, Latex, clear 34 | 35 | l = Latex(f, s=0.2, c='w').addPos(.6,.6,.1) 36 | 37 | plot(u, l, cmap='jet', scalarbar='h', text=__doc__) 38 | 39 | # Now show uD values on the boundary of a much finer mesh 40 | clear() 41 | bmesh = BoundaryMesh(UnitSquareMesh(80, 80), "exterior") 42 | plot(uD, bmesh, cmap='cool', ps=5, legend='boundary') # ps = point size 43 | -------------------------------------------------------------------------------- /examples/other/dolfin/ex05_non-matching-meshes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Interpolate functions between 3 | finite element spaces on non-matching meshes. 4 | """ 5 | # https://fenicsproject.org/docs/dolfin/2018.1.0/python/demos 6 | # /nonmatching-interpolation/demo_nonmatching-interpolation.py.html 7 | from dolfin import * 8 | 9 | mesh1 = UnitSquareMesh(16, 16) 10 | mesh3 = UnitSquareMesh(64, 64) 11 | 12 | P1 = FunctionSpace(mesh1, "Lagrange", 1) 13 | P3 = FunctionSpace(mesh3, "Lagrange", 3) 14 | 15 | v = Expression("sin(10*x[0])*sin(10*x[1])", degree=5) 16 | 17 | # Create function on P3 and interpolate v 18 | v3 = Function(P3) 19 | v3.interpolate(v) 20 | 21 | # Create function on P1 and interpolate v3 22 | v1 = Function(P1) 23 | v1.interpolate(v3) 24 | 25 | 26 | ######################################### vtkplotter 27 | from vtkplotter.dolfin import plot 28 | 29 | # Plot v1 and v3 on 2 synced renderers 30 | plot(v1, at=0, N=2, text='coarse mesh') 31 | plot(v3, at=1, N=2, text='finer mesh', interactive=True) 32 | -------------------------------------------------------------------------------- /examples/other/dolfin/ex06_elasticity1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show mesh and displacement solution with arrows. 3 | 4 | Refer to original script for the detailed description: 5 | https://fenicsproject.org/docs/dolfin/2018.1.0/python/ 6 | demos/hyperelasticity/demo_hyperelasticity.py.html 7 | """ 8 | print(__doc__) 9 | ########################################################### dolfin 10 | from dolfin import * 11 | 12 | # Create mesh and define function space 13 | mesh = UnitCubeMesh(10, 10, 10) 14 | V = VectorFunctionSpace(mesh, "Lagrange", 1) 15 | 16 | # Mark boundary subdomains 17 | left = CompiledSubDomain("near(x[0], side) && on_boundary", side=0.0) 18 | right = CompiledSubDomain("near(x[0], side) && on_boundary", side=1.0) 19 | 20 | # Define Dirichlet boundary (x = 0 or x = 1) 21 | c = Constant((0.0, 0.0, 0.0)) 22 | r = Expression(( 23 | "scale*0.0", 24 | "scale*(y0 + (x[1]-y0)*cos(theta) - (x[2]-z0)*sin(theta) - x[1])", 25 | "scale*(z0 + (x[1]-y0)*sin(theta) + (x[2]-z0)*cos(theta) - x[2])", 26 | ), 27 | scale=0.5, y0=0.5, z0=0.5, theta=pi/3, degree=2 ) 28 | 29 | bcl = DirichletBC(V, c, left) 30 | bcr = DirichletBC(V, r, right) 31 | 32 | w = TrialFunction(V) # Incremental displacement 33 | v = TestFunction(V) # Test function 34 | u = Function(V) # solution 35 | 36 | solve(inner(grad(w), grad(v)) * dx == inner(c, v) * dx, u, [bcl, bcr]) 37 | 38 | bmesh = BoundaryMesh(mesh, "exterior") 39 | 40 | ########################################################### vtkplotter 41 | from vtkplotter.dolfin import * 42 | 43 | # ps = point size, only mesh vertices are shown 44 | plot(u, mode='mesh', ps=10) 45 | 46 | # plot displacements as white arrows, lw controls the mesh visibility 47 | plot(u, mode='arrows', add=True, 48 | color='w', alpha=0.5, cmap='gist_earth', lw=1) 49 | -------------------------------------------------------------------------------- /examples/other/dolfin/markmesh.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Mark mesh with boundary function 3 | ''' 4 | from dolfin import * 5 | 6 | mesh = UnitCubeMesh(5,5,5) 7 | V = FunctionSpace(mesh, "Lagrange", 1) 8 | 9 | class left(SubDomain): 10 | def inside(self, x, on_boundary): 11 | return on_boundary and abs(x[0]) < DOLFIN_EPS 12 | left = left() 13 | 14 | tcond = MeshFunction("size_t", mesh, 0) 15 | tcond.set_all(0) 16 | left.mark(tcond, 1) 17 | 18 | ################################## 19 | from vtkplotter.dolfin import plot 20 | plot(tcond, cmap='cool', elevation=20, text=__doc__) 21 | -------------------------------------------------------------------------------- /examples/other/dolfin/noplot/README.md: -------------------------------------------------------------------------------- 1 | # _FEniCS/dolfin_ examples without the plot() command 2 | In this directory you will find very similar examples as in the parent directory 3 | without using the shortcut ``plot()`` command. 4 | 5 | This implies that a better knowledge of the `vtkplotter` is needed, but at the same time 6 | you will be able to produce more flexible and customized visualizations. 7 | ```bash 8 | git clone https://github.com/marcomusy/vtkplotter.git 9 | cd vtkplotter/examples/other/dolfin/noplot 10 | python example.py # on mac OSX try 'pythonw' instead 11 | ``` 12 | -------------------------------------------------------------------------------- /examples/other/dolfin/noplot/ex01_show-mesh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Fenics/dolfin mesh interoperability. 3 | Select mesh and press X to slice it. 4 | """ 5 | import dolfin 6 | from vtkplotter.dolfin import MeshActor, Text, show, datadir 7 | 8 | mesh1 = dolfin.Mesh(datadir + "dolfin_fine.xml") 9 | 10 | show(Text("a dolfin 2d mesh", pos=2), interactive=False) 11 | 12 | show(mesh1, interactive=True) # show mesh and hold on 13 | 14 | ## show another dolfin mesh 15 | mesh2 = dolfin.UnitCubeMesh(8,8,8) 16 | 17 | actor = MeshActor(mesh2) # build a vtkActor from Mesh 18 | 19 | # show Actor and the header comment of this file 20 | show(actor, Text(__doc__), interactive=True) 21 | -------------------------------------------------------------------------------- /examples/other/dolfin/noplot/ex03_poisson.py: -------------------------------------------------------------------------------- 1 | """ 2 | Poisson equation with Dirichlet conditions. 3 | 4 | -Laplace(u) = f in the unit square 5 | u = u_D on the boundary 6 | 7 | u_D = 1 + x^2 + 2y^2 8 | (f = -6) 9 | """ 10 | ########################################################### fenics 11 | from fenics import * 12 | 13 | # Create mesh and define function space 14 | mesh = UnitSquareMesh(8, 8) 15 | V = FunctionSpace(mesh, "P", 1) 16 | 17 | # Define boundary condition 18 | u_D = Expression("1 + x[0]*x[0] + 2*x[1]*x[1]", degree=2) 19 | bc = DirichletBC(V, u_D, "on_boundary") 20 | 21 | # Define variational problem 22 | u = TrialFunction(V) 23 | v = TestFunction(V) 24 | f = Constant(-6.0) 25 | a = dot(grad(u), grad(v)) * dx 26 | L = f * v * dx 27 | 28 | # Compute solution 29 | u = Function(V) 30 | solve(a == L, u, bc) 31 | 32 | 33 | ########################################################### vtkplotter 34 | from vtkplotter.dolfin import * 35 | 36 | msg = Text(__doc__, c="white") 37 | 38 | # u=u triggers coloring with default color map 39 | pts = MeshActor(u, wire=False) 40 | pts.lineWidth(1).addScalarBar() 41 | show(pts, msg) 42 | 43 | ##### Now show u_D values on the boundary of a much finer mesh 44 | bmesh = BoundaryMesh(UnitSquareMesh(80, 80), "exterior") 45 | 46 | bpts = MeshPoints(u_D, bmesh) 47 | show(bpts) 48 | -------------------------------------------------------------------------------- /examples/other/dolfin/noplot/ex05_non-matching-meshes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Interpolate functions between 3 | finite element spaces on non-matching meshes. 4 | """ 5 | # https://fenicsproject.org/docs/dolfin/2018.1.0/python/demos 6 | # /nonmatching-interpolation/demo_nonmatching-interpolation.py.html 7 | from dolfin import * 8 | 9 | mesh1 = UnitSquareMesh(16, 16) 10 | mesh3 = UnitSquareMesh(64, 64) 11 | 12 | P1 = FunctionSpace(mesh1, "Lagrange", 1) 13 | P3 = FunctionSpace(mesh3, "Lagrange", 3) 14 | 15 | v = Expression("sin(10*x[0])*sin(10*x[1])", degree=5) 16 | 17 | # Create function on P3 and interpolate v 18 | v3 = Function(P3) 19 | v3.interpolate(v) 20 | 21 | # Create function on P1 and interpolate v3 22 | v1 = Function(P1) 23 | v1.interpolate(v3) 24 | 25 | 26 | ######################################### vtkplotter 27 | from vtkplotter.dolfin import * 28 | 29 | s1 = MeshActor(v1).lineWidth(0.5).wire(False) 30 | s3 = MeshActor(v3).lineWidth(0.5).wire(False) 31 | 32 | show(s1, s3, N=2) # distribute s1 and s3 on 2 synced renderers 33 | -------------------------------------------------------------------------------- /examples/other/dolfin/noplot/ex06_elasticity1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show fenics mesh and displacement solution with arrows. 3 | """ 4 | # Refer to original script for the detailed description: 5 | # https://fenicsproject.org/docs/dolfin/2018.1.0/python/ 6 | # demos/hyperelasticity/demo_hyperelasticity.py.html 7 | # 8 | print(__doc__) 9 | ########################################################### dolfin 10 | from dolfin import * 11 | 12 | # Create mesh and define function space 13 | mesh = UnitCubeMesh(10, 10, 10) 14 | V = VectorFunctionSpace(mesh, "Lagrange", 1) 15 | 16 | # Mark boundary subdomains 17 | left = CompiledSubDomain("near(x[0], side) && on_boundary", side=0.0) 18 | right = CompiledSubDomain("near(x[0], side) && on_boundary", side=1.0) 19 | 20 | # Define Dirichlet boundary (x = 0 or x = 1) 21 | c = Constant((0.0, 0.0, 0.0)) 22 | r = Expression(( 23 | "scale*0.0", 24 | "scale*(y0 + (x[1] - y0)*cos(theta) - (x[2] - z0)*sin(theta) - x[1])", 25 | "scale*(z0 + (x[1] - y0)*sin(theta) + (x[2] - z0)*cos(theta) - x[2])", 26 | ), 27 | scale=0.5, y0=0.5, z0=0.5, theta=pi/3, degree=2 ) 28 | 29 | bcl = DirichletBC(V, c, left) 30 | bcr = DirichletBC(V, r, right) 31 | 32 | w = TrialFunction(V) # Incremental displacement 33 | v = TestFunction(V) # Test function 34 | u = Function(V) # solution 35 | 36 | solve(inner(grad(w), grad(v)) * dx == inner(c, v) * dx, u, [bcl, bcr]) 37 | 38 | bmesh = BoundaryMesh(mesh, "exterior") 39 | 40 | ########################################################### vtkplotter 41 | from vtkplotter.dolfin import * 42 | 43 | mpts = MeshPoints(u, bmesh).pointSize(10) 44 | 45 | arrs = MeshArrows(u, bmesh) # try also MeshLines(mesh, u) 46 | arrs.color("white").opacity(0.2) 47 | 48 | show(mpts, arrs, azimuth=60) 49 | -------------------------------------------------------------------------------- /examples/other/dolfin/pi_estimate.py: -------------------------------------------------------------------------------- 1 | from dolfin import * 2 | from mshr import Circle, generate_mesh 3 | from vtkplotter.dolfin import plot, printc, Latex 4 | # Credits: 5 | # https://github.com/pf4d/fenics_scripts/blob/master/pi_estimate.py 6 | 7 | domain = Circle(Point(0.0,0.0), 1.0) 8 | 9 | 10 | for res in [2**k for k in range(7)]: 11 | mesh = generate_mesh(domain, res) 12 | A = assemble(Constant(1) * dx(domain=mesh)) 13 | printc("resolution = %i, \t A-pi = %.5e" % (res, A-pi)) 14 | 15 | printc('~pi is about', A, c='yellow') 16 | 17 | l = Latex(r'\mathrm{Area}(r)=\pi=\int\int_D 1 \cdot d(x,y)', s=0.3) 18 | l.crop(0.3,0.3).z(0.1) # crop invisible top and bottom and set at z=0.1 19 | 20 | plot(mesh, l, alpha=0.4, ztitle='', style=1, axes=3) 21 | -------------------------------------------------------------------------------- /examples/other/dolfin/scalemesh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Scale a mesh asymmetrically in one coordinate 3 | """ 4 | from dolfin import * 5 | from mshr import * 6 | 7 | domain = Rectangle(Point(0.0, 0.0), Point(5.0, 0.01)) 8 | mesh = generate_mesh(domain, 20) 9 | V = FunctionSpace(mesh, "CG", 2) 10 | 11 | e = Expression("sin(2*pi*(x[0]*x[0]+x[1]*x[1]))", degree=2) 12 | f = interpolate(e, V) 13 | 14 | #################################################### 15 | from vtkplotter.dolfin import plot 16 | 17 | plt = plot(f, 18 | scaleMeshFactors=(0.01, 1, 1), 19 | warpZfactor = 0.05, 20 | style=1, 21 | lw=0, 22 | scalarbar='horizontal', 23 | xtitle = 'y-coord is scaled by factor 100', 24 | text=__doc__, 25 | ) 26 | -------------------------------------------------------------------------------- /examples/other/dolfin/stokes2.py: -------------------------------------------------------------------------------- 1 | from dolfin import * 2 | from mshr import * 3 | 4 | b = 0.7 5 | embryo = Ellipse(Point(0.0, 0.0), 1, b) 6 | mesh = generate_mesh(embryo, 32) 7 | 8 | # Define function spaces 9 | P2 = VectorElement("CG", triangle, 2) 10 | P1 = FiniteElement("CG", triangle, 1) 11 | TH = MixedElement([P2, P1]) 12 | W = FunctionSpace(mesh, TH) 13 | g = Constant(0.0) 14 | mu = Constant(1.0) 15 | force = Constant((0.0, 0.0)) 16 | 17 | # Specify Boundary Conditions 18 | flow_profile = ("-sin(atan2(x[1]/b, x[0]))*sin(nharmonic*atan2(x[1]/b, x[0]))", 19 | "+cos(atan2(x[1]/b, x[0]))*sin(nharmonic*atan2(x[1]/b, x[0]))") 20 | bc = DirichletBC(W.sub(0), 21 | Expression(flow_profile, degree=2, b=b, nharmonic=2), 22 | "on_boundary") 23 | 24 | # Define trial and test functions 25 | (u, p) = TrialFunctions(W) 26 | (v, q) = TestFunctions(W) 27 | 28 | def epsilon(u): 29 | return grad(u) + nabla_grad(u) 30 | a = inner(mu*epsilon(u) + p*Identity(2), epsilon(v))*dx -div(u)*q*dx -1e-10*p*q*dx 31 | L = dot(force, v)*dx + g*q*dx 32 | 33 | # Solve system 34 | U = Function(W) 35 | solve(a == L, U, bc) 36 | 37 | # Get sub-functions 38 | u, p = U.split() 39 | 40 | from vtkplotter.dolfin import plot 41 | plot(u, 42 | mode='mesh and arrows', 43 | scale=0.1, 44 | warpZfactor=-0.1, 45 | lw=0, 46 | scalarbar='horizontal', 47 | axes={'xLabelSize':0.01,'yLabelSize':0.01, 'ztitle':''}, 48 | title="Velocity") 49 | -------------------------------------------------------------------------------- /examples/other/dolfin/submesh_boundary.py: -------------------------------------------------------------------------------- 1 | """ 2 | Extract submesh boundaries. 3 | """ 4 | # https://fenicsproject.discourse.group/t/output-parts-of-boundary/537 5 | from fenics import * 6 | from mshr import * 7 | from numpy import array 8 | from numpy.linalg import norm 9 | 10 | domain = Box(Point(0,0,0), Point(10,10,10)) - Sphere(Point(5,5,5), 3) 11 | mesh = generate_mesh(domain, 32) 12 | exterior = BoundaryMesh(mesh, "exterior") 13 | 14 | 15 | def inSphere(x): 16 | v = x - array([5, 5, 5]) 17 | return norm(v) < 3 + 1e2 * DOLFIN_EPS 18 | 19 | class SphereDomain(SubDomain): 20 | def inside(self, x, on_boundary): 21 | return inSphere(x) 22 | 23 | class BoxDomain(SubDomain): 24 | def inside(self, x, on_boundary): 25 | return not inSphere(x) 26 | 27 | sph = SubMesh(exterior, SphereDomain()) 28 | box = SubMesh(exterior, BoxDomain()) 29 | 30 | 31 | from vtkplotter.dolfin import plot 32 | 33 | plot(sph, at=0, N=2, c='red', text=__doc__) 34 | plot(box, at=1, wireframe=True) 35 | -------------------------------------------------------------------------------- /examples/other/downloading.py: -------------------------------------------------------------------------------- 1 | # Download a large file from a URL link and unzip it 2 | # 3 | from vtkplotter import download, gunzip, show 4 | 5 | fgz = download('https://vtkplotter.embl.es/examples/truck.vtk.gz') # 200MB 6 | 7 | filename = gunzip(fgz) 8 | print('gunzip-ped to temporary file:', filename) 9 | 10 | show(filename) 11 | -------------------------------------------------------------------------------- /examples/other/export_numpy.py: -------------------------------------------------------------------------------- 1 | from vtkplotter import * 2 | 3 | m1 = load(datadir+'bunny.obj').c('g').normalize().rotateX(+90) 4 | m2 = load(datadir+'teddy.vtk').c('v').normalize().rotateZ(-90).pos(3,0,0) 5 | 6 | show(m1, m2, axes=1) 7 | 8 | exportWindow('scene.npy') 9 | printc("Window exported to numpy file: scene.npy", c='g') 10 | 11 | 12 | ################################################ 13 | vp = importWindow('scene.npy') 14 | 15 | vp += Text("Imported scene", c='w', bg='lb') 16 | 17 | vp.show() 18 | 19 | printc("\nTry also:\n> vtkplotter scene.npy", c='g') -------------------------------------------------------------------------------- /examples/other/export_x3d.py: -------------------------------------------------------------------------------- 1 | """Embed a 3D scene 2 | in a webpage with 3 | x3dom and vtkplotter""" 4 | from vtkplotter import * 5 | 6 | e = load(datadir+'embryo.tif', threshold=True).decimate(0.5) 7 | ec = e.coordinates() 8 | e.pointColors(ec[:,1]) # add dummy colors along y 9 | 10 | t = Text(__doc__, pos=[3000., 2000., 4723], s=150, c='w', depth=0.1) 11 | show(t, e) 12 | 13 | # This exports the scene and generates 2 files: 14 | # embryo.x3d and an example embryo.html to inspect in the browser 15 | exportWindow('embryo.x3d') 16 | 17 | -------------------------------------------------------------------------------- /examples/other/icon.py: -------------------------------------------------------------------------------- 1 | """ 2 | Make a icon actor to indicate orientation 3 | and place it in one of the 4 corners 4 | within the same renderer. 5 | """ 6 | from vtkplotter import * 7 | 8 | 9 | vp = Plotter(axes=5, bg="white") 10 | # axes type 5 builds an annotated orientation cube 11 | 12 | vp.load(datadir+'porsche.ply').lighting('metallic') 13 | 14 | vp.show(interactive=0) 15 | 16 | vlg = load(datadir+"images/vtk_logo.png", alpha=0.5) 17 | vp.addIcon(vlg, pos=1) 18 | 19 | elg = load(datadir+"images/embl_logo.jpg") 20 | vp.addIcon(elg, pos=2, size=0.06) 21 | 22 | plg = load(datadir+"images/vlogo_small.png") 23 | vp.addIcon(plg, pos=4, size=0.1) # 4=bottom-right 24 | 25 | vp += Text(__doc__, pos=8) 26 | 27 | vp.show(interactive=1) 28 | -------------------------------------------------------------------------------- /examples/other/inset.py: -------------------------------------------------------------------------------- 1 | """ 2 | Renderer meshes into insets. 3 | (can be dragged) 4 | """ 5 | from vtkplotter import * 6 | 7 | vp = Plotter(axes=1, bg="white") 8 | 9 | e = load(datadir+"embryo.tif", threshold=True) # automatic isosurfacing 10 | e.normalize().c("gold") 11 | msg = Text(__doc__) 12 | 13 | vp.show(e, msg, viewup='z', interactive=0) 14 | 15 | e1 = e.clone().cutWithPlane(normal=[1,0,0]).c("red") 16 | e2 = e.clone().cutWithPlane(normal=[0,1,0]).c("pink") 17 | e3 = e.clone().cutWithPlane(normal=[0,0,1]).c("blue") 18 | 19 | vp.showInset(e1, pos=(0.9,0.2)) 20 | vp.showInset(e2, pos=(0.9,0.5)) 21 | vp.showInset(e2, e3, pos=(0.9,0.8)) 22 | 23 | vp.show(interactive=1) 24 | -------------------------------------------------------------------------------- /examples/other/makeVideo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Make a video (needs ffmpeg) 3 | Set offscreen=True to only produce the video 4 | without any graphical window showing 5 | """ 6 | print(__doc__) 7 | from vtkplotter import * 8 | 9 | # declare the class instance 10 | vp = Plotter(bg='beige', axes=10, interactive=0, offscreen=True) 11 | 12 | vp.load(datadir+"spider.ply").texture("leather2").rotateX(-90) 13 | 14 | # open a video file and force it to last 3 seconds in total 15 | video = Video(name="spider.mp4", duration=3) 16 | 17 | for i in range(80): 18 | vp.show() # render the scene first 19 | vp.camera.Elevation(1) 20 | vp.camera.Azimuth(2) # rotate by 5 deg at each iteration 21 | video.addFrame() 22 | 23 | video.close() # merge all the recorded frames 24 | 25 | vp.show(interactive=1) 26 | -------------------------------------------------------------------------------- /examples/other/menger_fractal.py: -------------------------------------------------------------------------------- 1 | """ 2 | Menger fractal sponge 3 | """ 4 | # Credits: K3D authors at 5 | # https://github.com/K3D-tools/K3D-jupyter/tree/master/examples 6 | #https://en.wikipedia.org/wiki/Menger_sponge 7 | import numpy as np 8 | from vtkplotter import Volume, legosurface, show 9 | 10 | iteration = 4 11 | size = 3**iteration 12 | 13 | voxels = np.ones((size, size, size)); 14 | 15 | def iterate(length, x, y, z): 16 | 17 | nl = length // 3 18 | if nl < 1: return 19 | 20 | margin = (nl-1) // 2 21 | voxels[z-margin:z+margin+1, y-margin:y+margin+1, :] = 0 22 | voxels[z-margin:z+margin+1, :, x-margin:x+margin+1] = 0 23 | voxels[:, y-margin:y+margin+1, x-margin:x+margin+1] = 0 24 | 25 | for ix,iy,iz in np.ndindex((3,3,3)): 26 | if (1 if ix !=1 else 0) + (1 if iy != 1 else 0) + (1 if iz != 1 else 0) !=2: 27 | iterate(nl, x + (ix-1) * nl, y + (iy-1) * nl , z + (iz-1) * nl) 28 | 29 | iterate(size, size//2, size//2, size//2) 30 | print('voxels min, max =', np.min(voxels), np.max(voxels)) 31 | 32 | vol = Volume(voxels) 33 | lego = legosurface(vol, -0.1, 1.1, cmap='afmhot_r') 34 | 35 | show(vol, lego, N=2, bg='w') 36 | -------------------------------------------------------------------------------- /examples/other/qt_window.py: -------------------------------------------------------------------------------- 1 | """ 2 | A sort of minimal example of how to embed a rendering window 3 | into a qt application. 4 | """ 5 | print(__doc__) 6 | import sys 7 | from PyQt5 import Qt 8 | from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor 9 | 10 | from vtkplotter import Plotter, Cone 11 | 12 | class MainWindow(Qt.QMainWindow): 13 | def __init__(self, parent=None): 14 | 15 | Qt.QMainWindow.__init__(self, parent) 16 | self.frame = Qt.QFrame() 17 | self.vl = Qt.QVBoxLayout() 18 | self.vtkWidget = QVTKRenderWindowInteractor(self.frame) 19 | self.vl.addWidget(self.vtkWidget) 20 | 21 | vp = Plotter(qtWidget=self.vtkWidget, axes=4, bg='white') 22 | 23 | vp += Cone() 24 | vp.show() # create renderer and add the actors 25 | 26 | # set-up the rest of the Qt window 27 | self.frame.setLayout(self.vl) 28 | self.setCentralWidget(self.frame) 29 | 30 | self.show() # <--- show the Qt Window 31 | 32 | 33 | if __name__ == "__main__": 34 | app = Qt.QApplication(sys.argv) 35 | window = MainWindow() 36 | app.exec_() 37 | -------------------------------------------------------------------------------- /examples/other/remesh_ACVD.py: -------------------------------------------------------------------------------- 1 | # Credits: 2 | # https://github.com/akaszynski/pyacvd 3 | # Needs PyACVD: 4 | # pip install pyacvd 5 | # 6 | from vtkplotter import * 7 | from pyvista import wrap 8 | from pyacvd import Clustering 9 | 10 | mesh = Sphere(res=50).subdivide().lw(0.2).normalize().cutWithPlane() 11 | 12 | clus = Clustering(wrap(mesh.polydata())) 13 | clus.cluster(1000, maxiter=100, iso_try=10, debug=False) 14 | 15 | pvremesh = clus.create_mesh() 16 | 17 | remesh = Actor(pvremesh).computeNormals() 18 | remesh.color('o').backColor('v').lw(0.2) 19 | 20 | show(mesh, remesh, N=2) 21 | 22 | #remesh.write('sphere.vtk') 23 | -------------------------------------------------------------------------------- /examples/other/remesh_meshfix.py: -------------------------------------------------------------------------------- 1 | #Credits: 2 | #M. Attene. A lightweight approach to repairing digitized polygon meshes. 3 | #The Visual Computer, 2010. (c) Springer. DOI: 10.1007/s00371-010-0416-3 4 | #http://pymeshfix.pyvista.org 5 | # 6 | # pip install pymeshfix 7 | # 8 | from pyvista import wrap 9 | from pymeshfix import MeshFix 10 | from vtkplotter import * 11 | 12 | amesh = load(datadir+'270.vtk').flat() 13 | 14 | meshfix = MeshFix(wrap(amesh.polydata())) 15 | meshfix.repair() 16 | repaired = meshfix.mesh 17 | 18 | #write(repaired, 'repaired.vtk') 19 | show(amesh, repaired, axes=1, N=2) -------------------------------------------------------------------------------- /examples/other/save_as_numpy.py: -------------------------------------------------------------------------------- 1 | """ 2 | Write one or more vtk objects to a numpy file 3 | and read them back. Properties are also saved. 4 | """ 5 | from vtkplotter import * 6 | 7 | ######################################## load some vtk objects 8 | tcs = load(datadir+'timecourse1d/reference_*.vtk') 9 | n = len(tcs) 10 | printc('loaded list of actor of length =', n, c='yellow') 11 | 12 | show(tcs, Text(__doc__)) 13 | 14 | 15 | ######################################## write them to 1 numpy file 16 | # let's change mesh colors (lines in this case) 17 | # all properties (position, color, opacity etc) are saved too. 18 | for i in range(n): 19 | tcs[i].color(i) 20 | 21 | write(tcs, 'timecourse1d.npy') 22 | 23 | 24 | ######################################## read them back 25 | tcs2 = load('timecourse1d.npy') # will return a list 26 | show(tcs2, newPlotter=True, pos=(1100,0), verbose=0) 27 | 28 | 29 | ######################################## inspect numpy file 30 | import numpy as np 31 | 32 | fdict = np.load('timecourse1d.npy', allow_pickle=True)[0] 33 | 34 | printc('type is: ', type(fdict), c='y', italic=1) 35 | printc('keys are:', fdict.keys(), c='g', italic=1) 36 | 37 | -------------------------------------------------------------------------------- /examples/other/tf_learn_volume.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from keras.models import Sequential 3 | from keras.layers import Dense 4 | from vtkplotter import Volume, show, arange 5 | 6 | n = 10 7 | neurons = 60 8 | 9 | visdata = np.zeros([n, n, n]) 10 | datalist, scalars = [], [] 11 | ls = np.linspace(0, 1, n, endpoint=False) 12 | for i, x in enumerate(ls): 13 | for j, y in enumerate(ls): 14 | for k, z in enumerate(ls): 15 | s = (np.sin(x * 4) ** 2 + np.cos(y * 3) ** 2 + np.sqrt(z)) / 3 16 | visdata[i, j, k] = s 17 | datalist.append([x, y, z]) 18 | scalars.append(s) 19 | datalist = np.array(datalist) 20 | scalars = np.array(scalars) 21 | 22 | model = Sequential() 23 | model.add(Dense(neurons, activation="relu", input_dim=3)) 24 | model.add(Dense(neurons, activation="relu")) 25 | model.add(Dense(neurons, activation="relu")) 26 | model.add(Dense(1, activation="sigmoid")) 27 | 28 | model.compile(optimizer="rmsprop", loss="mse", metrics=["mae"]) 29 | 30 | model.fit(datalist, scalars, epochs=50, batch_size=64) 31 | 32 | predicted_scalars = model.predict(datalist) 33 | 34 | model.summary() 35 | 36 | idx = 0 37 | vispred = np.zeros([n, n, n]) 38 | for i, x in enumerate(ls): 39 | for j, y in enumerate(ls): 40 | for k, z in enumerate(ls): 41 | vispred[i, j, k] = predicted_scalars[idx] 42 | idx += 1 43 | 44 | v1 = Volume(visdata) 45 | v2 = Volume(vispred) 46 | 47 | s1 = v1.isosurface(threshold=[t for t in arange(0, 1, 0.1)]) 48 | s1.alpha(0.5) 49 | 50 | s2 = v2.isosurface(threshold=[t for t in arange(0, 1, 0.1)]) 51 | s2.alpha(0.5) 52 | 53 | show([[v1, s1], s2], N=2, axes=8, bg="w", depthpeeling=1) 54 | -------------------------------------------------------------------------------- /examples/other/trimesh/first_example.py: -------------------------------------------------------------------------------- 1 | """ 2 | trimesh to vtkplotter interoperability 3 | """ 4 | 5 | # Install trimesh with: 6 | # sudo apt install python3-rtree 7 | # pip install rtree shapely 8 | # conda install trimesh 9 | 10 | import trimesh 11 | from vtkplotter import download, trimesh2vtk, show 12 | 13 | url = 'https://raw.githubusercontent.com/mikedh/trimesh/master/models/' 14 | filename = download(url + 'machinist.XAML') 15 | mesh = trimesh.load(filename) 16 | 17 | actor = trimesh2vtk(mesh) # returns a Actor(vtkActor) object from Trimesh 18 | 19 | # Any of these will work: 20 | show(mesh) # conversion is on the fly (don't need 'actor') 21 | 22 | # or 23 | #actor.show() 24 | 25 | # or 26 | #show(actor) 27 | 28 | # or 29 | mesh.show() # this is the trimesh built-in visualizer 30 | -------------------------------------------------------------------------------- /examples/other/trimesh/nearest.py: -------------------------------------------------------------------------------- 1 | """ 2 | Find the closest point 3 | on the mesh to each random point 4 | """ 5 | import trimesh 6 | import numpy as np 7 | from vtkplotter import Text, show 8 | 9 | mesh = trimesh.load_remote('https://github.com/mikedh/trimesh/raw/master/models/cycloidal.ply') 10 | points = mesh.bounding_box_oriented.sample_volume(count=30) 11 | 12 | # find the closest point on the mesh to each random point 13 | closest_points, distances, triangle_id = mesh.nearest.on_surface(points) 14 | #print('Distance from point to surface of mesh:\n{}'.format(distances)) 15 | 16 | # create a PointCloud object out of each (n,3) list of points 17 | cloud_original = trimesh.points.PointCloud(points) 18 | cloud_close = trimesh.points.PointCloud(closest_points) 19 | 20 | # create a unique color for each point 21 | cloud_colors = np.array([trimesh.visual.random_color() for i in points]) 22 | 23 | # set the colors on the random point and its nearest point to be the same 24 | cloud_original.vertices_color = cloud_colors 25 | cloud_close.vertices_color = cloud_colors 26 | 27 | ## create a scene containing the mesh and two sets of points 28 | show(mesh, cloud_original, cloud_close, Text(__doc__), bg='w') -------------------------------------------------------------------------------- /examples/other/trimesh/ray.py: -------------------------------------------------------------------------------- 1 | import trimesh 2 | import numpy as np 3 | from vtkplotter import show 4 | 5 | # test on a sphere mesh 6 | mesh = trimesh.creation.icosphere() 7 | 8 | # create some rays 9 | ray_origins = np.array([[0, 0, -3], [1, 2, -3]]) 10 | ray_directions = np.array([[0, 0, 1], [0, -1, 1]]) 11 | 12 | # run the mesh-ray query 13 | locations, index_ray, index_tri = mesh.ray.intersects_location( 14 | ray_origins=ray_origins, ray_directions=ray_directions 15 | ) 16 | locs = trimesh.points.PointCloud(locations) 17 | 18 | # stack rays into line segments for visualization as Path3D 19 | ray_visualize = trimesh.load_path( 20 | np.hstack((ray_origins, ray_origins + ray_directions)).reshape(-1, 2, 3) 21 | ) 22 | 23 | print("The rays hit the mesh at coordinates:\n", locations) 24 | print("The rays with index: {} hit triangles stored at mesh.faces[{}]".format(index_ray, index_tri)) 25 | 26 | # stack rays into line segments for visualization as Path3D 27 | ray_visualize = trimesh.load_path( 28 | np.hstack((ray_origins, ray_origins + ray_directions * 5.0)).reshape(-1, 2, 3) 29 | ) 30 | 31 | # make mesh white-ish 32 | mesh.visual.face_colors = [200, 200, 250, 100] 33 | mesh.visual.face_colors[index_tri] = [255, 0, 0, 255] 34 | 35 | show(mesh, ray_visualize, locs, bg="w") 36 | -------------------------------------------------------------------------------- /examples/other/trimesh/run_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # source run_all.sh 3 | # 4 | printf "\033c" 5 | echo Running examples in directory other/trimesh/ 6 | 7 | ########################## 8 | echo Running first_example.py 9 | python first_example.py 10 | 11 | echo Running nearest.py 12 | python nearest.py 13 | 14 | echo Running ray.py 15 | python ray.py 16 | 17 | echo Running section.py 18 | python section.py 19 | 20 | 21 | echo Running shortest.py 22 | python shortest.py 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/other/trimesh/shortest.py: -------------------------------------------------------------------------------- 1 | import trimesh 2 | import networkx as nx 3 | from vtkplotter import Text, show 4 | 5 | # test on a sphere mesh 6 | mesh = trimesh.primitives.Sphere() 7 | 8 | # edges without duplication 9 | edges = mesh.edges_unique 10 | 11 | # the actual length of each unique edge 12 | length = mesh.edges_unique_length 13 | 14 | # create the graph with edge attributes for length 15 | g = nx.Graph() 16 | for edge, L in zip(edges, length): 17 | g.add_edge(*edge, length=L) 18 | 19 | # alternative method for weighted graph creation 20 | # you can also create the graph with from_edgelist and 21 | # a list comprehension, which is like 1.5x faster 22 | ga = nx.from_edgelist([(e[0], e[1], {"length": L}) for e, L in zip(edges, length)]) 23 | 24 | # arbitrary indices of mesh.vertices to test with 25 | start = 0 26 | end = int(len(mesh.vertices) / 2.0) 27 | 28 | # run the shortest path query using length for edge weight 29 | path = nx.shortest_path(g, source=start, target=end, weight="length") 30 | 31 | # VISUALIZE RESULT 32 | # make the sphere transparent-ish 33 | mesh.visual.face_colors = [100, 100, 100, 100] 34 | 35 | # Path3D with the path between the points 36 | path_visual = trimesh.load_path(mesh.vertices[path]) 37 | 38 | # visualizable two points 39 | points_visual = trimesh.points.PointCloud(mesh.vertices[[start, end]]) 40 | 41 | txt = Text('Shortest path query\nusing length for edge weight', c='blue') 42 | 43 | show(mesh, points_visual, path_visual, txt, bg="w", axes=6) 44 | -------------------------------------------------------------------------------- /examples/other/voronoi3d.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Voronoi in 3D with Voro++ library. 3 | ''' 4 | from vtkplotter import voronoi3D, Points, show, settings 5 | import numpy as np 6 | 7 | #settings.voro_path = '/g/sharpeba/software/bin' 8 | 9 | N = 2000 10 | nuclei = np.random.rand(N, 3) - (0.5,0.5,0.5) 11 | ncl = Points(nuclei).clean(0.1) # clean makes points evenly spaced 12 | nuclei = ncl.coordinates() 13 | 14 | actor = voronoi3D(nuclei, tol=.001) 15 | #print(len(actor.info['cells']), actor.info['volumes']) 16 | 17 | pts_inside = actor.insidePoints(nuclei) 18 | inpts = Points(pts_inside, r=50, c='r', alpha=0.2) 19 | 20 | show(actor, inpts) 21 | 22 | -------------------------------------------------------------------------------- /examples/simulations/airplanes.py: -------------------------------------------------------------------------------- 1 | # Draw the shadow and trailing lines of 2 planes. This is not really 2 | # a simulation.. just a way to illustrate how to move objects around! 3 | from vtkplotter import * 4 | 5 | world = Box([0,0,0], 30, 15, 8).wireframe() 6 | 7 | plane1 = load(datadir+"cessna.vtk").c("green").addTrail().addShadow(z=-4) 8 | plane2 = plane1.clone().c("tomato") # make a clone copy of the first plane 9 | 10 | # Setup the scene 11 | show(world, plane1, plane2, axes=1, bg="white", viewup="z", interactive=0) 12 | 13 | for t in arange(0, 3.2, 0.01): 14 | plane1.pos(9*t-15, 2-t, sin(3-t)).rotateX(0+t) # make up some movement 15 | plane2.pos(8*t-15, t-2, sin(t-3)).rotateX(2-t) # for the 2 planes 16 | show(world, plane1, plane2) 17 | 18 | interactive() 19 | -------------------------------------------------------------------------------- /examples/simulations/aspring.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simulation of a block connected 3 | to a spring in a vicous medium. 4 | """ 5 | from __future__ import division, print_function 6 | from vtkplotter import * 7 | 8 | vp = Plotter(interactive=0, axes=0) 9 | 10 | L = 0.1 # spring x position at rest 11 | x0 = 0.85 # initial x-coordinate of the block 12 | k = 25 # spring constant 13 | m = 20 # block mass 14 | b = 0.5 # viscosity friction (proportional to velocity) 15 | dt = 0.15 # time step 16 | 17 | # initial conditions 18 | v = vector(0, 0, 0.2) 19 | x = vector(x0, 0, 0) 20 | xr = vector(L, 0, 0) 21 | sx0 = vector(-0.8, 0, 0) 22 | offx = vector(0, 0.3, 0) 23 | 24 | vp += Box(pos=(0, -0.1, 0), length=2.0, width=0.02, height=0.5) # surface 25 | vp += Box(pos=(-0.82, 0.15, 0), length=0.04, width=0.50, height=0.3) # wall 26 | 27 | block = Cube(pos=x, side=0.2, c="tomato") 28 | block.addTrail(offset=[0, 0.2, 0], alpha=0.6, lw=2, n=500) 29 | spring = Spring(sx0, x, r=0.06, thickness=0.01) 30 | vp += [block, spring, Text(__doc__)] 31 | 32 | pb = ProgressBar(0, 300, c="r") 33 | for i in pb.range(): 34 | F = -k * (x - xr) - b * v # Force and friction 35 | a = F / m # acceleration 36 | v = v + a * dt # velocity 37 | x = x + v * dt + 1 / 2 * a * dt ** 2 # position 38 | 39 | block.pos(x) # update block position and trail 40 | spring.stretch(sx0, x) # stretch helix accordingly 41 | 42 | vp.show(elevation=0.1, azimuth=0.1) 43 | pb.print() 44 | 45 | vp.show(interactive=1) 46 | -------------------------------------------------------------------------------- /examples/simulations/pendulum.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Visualize the phase space of a simple pendulum. 3 | x = starting angle theta 4 | y = starting angular velocity 5 | ''' 6 | # From https://www.youtube.com/watch?v=p_di4Zn4wz4 7 | # Overview of differential equations | Chapter 1 8 | # (by 3Blue1Brown) 9 | 10 | #Install with: 11 | # pip install vtkplotter 12 | 13 | from vtkplotter import * 14 | 15 | # Physical constants 16 | g = 9.81 # m/s^2 17 | L = 2 # m 18 | mu = 0.1 # friction 1/s 19 | delta_t = 0.01 # Some time step 20 | t_tot = 50 # seconds total time 21 | 22 | # Definition of ODE 23 | def get_theta_dot_dot(theta, theta_dot): 24 | return -mu * theta_dot - (g/L) * sin(theta) 25 | 26 | lines = [] 27 | for THETA_0 in arange(0, 3.1415, 0.2): 28 | for THETA_DOT_0 in arange(4, 9, 1): 29 | 30 | # Solution to the differential equation 31 | theta = THETA_0 32 | theta_dot = THETA_DOT_0 33 | pts = [] 34 | for time in arange(0, t_tot, delta_t): 35 | theta_dot_dot = get_theta_dot_dot(theta, theta_dot) 36 | theta += theta_dot * delta_t 37 | theta_dot += theta_dot_dot * delta_t 38 | pts.append([theta, theta_dot]) 39 | 40 | l = Line(pts).color(int(THETA_DOT_0)) 41 | lines.append(l) 42 | 43 | show(lines, Text(__doc__), axes=2, bg='white') 44 | -------------------------------------------------------------------------------- /examples/simulations/run_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # source run_all.sh 3 | # 4 | printf "\033c" 5 | 6 | echo ############################################# 7 | echo Press F1 at anytime to skip example 8 | echo ############################################# 9 | echo 10 | echo 11 | echo 12 | 13 | 14 | ################################### simulations 15 | echo Running aspring.py 16 | python aspring.py 17 | 18 | echo Running cell_main.py 19 | python cell_main.py 20 | 21 | echo Running brownian2D.py 22 | python brownian2D.py 23 | 24 | echo Running gas.py 25 | python gas.py 26 | 27 | echo Running gyroscope1.py 28 | python gyroscope1.py 29 | 30 | echo Running gyroscope2.py 31 | python gyroscope2.py 32 | 33 | echo Running multiple_pendulum.py 34 | python multiple_pendulum.py 35 | 36 | echo Running hanoi3d.py 37 | python hanoi3d.py 38 | 39 | echo Running airplanes.py 40 | python airplanes.py 41 | 42 | echo Running pendulum.py 43 | python pendulum.py 44 | 45 | echo Running wave_equation.py 46 | python wave_equation.py 47 | 48 | echo Running turing.py 49 | python turing.py 50 | 51 | echo Running particle_simulator.py 52 | python particle_simulator.py 53 | 54 | echo Running doubleslit.py 55 | python doubleslit.py 56 | 57 | echo Running tunnelling2.py 58 | python tunnelling2.py 59 | 60 | echo Running volterra.py 61 | python volterra.py 62 | 63 | echo '-----------------------------' 64 | echo '-----------------------------' 65 | echo 'cd ../other/dolfin; ./run_all.sh' 66 | echo '-----------------------------' 67 | echo '-----------------------------' 68 | -------------------------------------------------------------------------------- /examples/volumetric/erode_dilate.py: -------------------------------------------------------------------------------- 1 | """Erode or dilate a Volume 2 | by replacing a voxel with the max/min 3 | over an ellipsoidal neighborhood. 4 | """ 5 | from vtkplotter import * 6 | 7 | t = Text(__doc__, c='white') 8 | e = load(datadir+'embryo.slc').printHistogram(logscale=1) 9 | 10 | eroded = erodeVolume( e, neighbours=(5,5,5)).printHistogram(logscale=1) 11 | dilatd = dilateVolume(e, neighbours=(5,5,5)).printHistogram(logscale=1) 12 | 13 | show([(e, t), eroded, dilatd], N=3, viewup='z', zoom=2) 14 | 15 | -------------------------------------------------------------------------------- /examples/volumetric/euclDist.py: -------------------------------------------------------------------------------- 1 | """Euclidean Distance Transform using Saito algorithm. 2 | The distance map produced contains the square 3 | of the Euclidean distance values. 4 | """ 5 | from vtkplotter import * 6 | 7 | t = Text(__doc__, c='white') 8 | e = load(datadir+'embryo.tif') # Volume 9 | 10 | edt = euclideanDistanceVolume(e) 11 | 12 | show([(e,t), edt], N=2, viewup='z', zoom=1.5) 13 | 14 | -------------------------------------------------------------------------------- /examples/volumetric/interpolateVolume.py: -------------------------------------------------------------------------------- 1 | """ 2 | Generate a voxel dataset (vtkImageData) by interpolating a scalar 3 | which is only known on a scattered set of points or mesh. 4 | Available interpolation kernels are: shepard, gaussian, voronoi, linear. 5 | The blue layer is the result of thresholding the volume 6 | between 0.3 and 0.4 and assigning it the new value 0.9 7 | """ 8 | # Author: Giovanni Dalmasso 9 | from vtkplotter import * 10 | import numpy as np 11 | 12 | npts = 500 # nr. of points of known scalar value 13 | coords = np.random.rand(npts, 3) # range is [0, 1] 14 | scals = np.abs(coords[:, 2]) # let the scalar be the z of point itself 15 | 16 | apts = Points(coords).addPointScalars(scals, name='scals') 17 | 18 | vol = interpolateToVolume(apts, kernel='shepard', radius=0.2, dims=(90,90,90)) 19 | vol.c(["tomato", "g", "b"]).alpha([0.4, 0.8]) # set color/opacity transfer functions 20 | 21 | vol.threshold(vmin=0.3, vmax=0.4, replaceWith=0.9) # replace voxel value in [vmin,vmax] 22 | 23 | printHistogram(vol, bins=25, c='b') 24 | 25 | #write(vol, 'cube.vti') 26 | 27 | show(apts, vol, Text(__doc__), bg="white", axes=1, viewup='z') 28 | -------------------------------------------------------------------------------- /examples/volumetric/isosurfaces1.py: -------------------------------------------------------------------------------- 1 | from vtkplotter import * 2 | import numpy as np 3 | 4 | data_matrix = np.zeros([75, 75, 75]) 5 | # data_matrix[0:35, 0:35, 0:35] = 50 6 | # data_matrix[25:55, 25:55, 25:55] = 100 7 | # data_matrix[45:74, 45:74, 45:74] = 150 8 | # or 9 | for ix in range(75): 10 | for iy in range(75): 11 | for iz in range(75): 12 | data_matrix[ix, iy, iz] = ix + iy + iz 13 | 14 | v = Volume(data_matrix) 15 | 16 | s = v.isosurface(threshold=[t for t in arange(0, 200, 10)]) 17 | s.alpha(0.5).lw(0.1) 18 | 19 | show(v, s, N=2, axes=8, bg="w", depthpeeling=1) 20 | -------------------------------------------------------------------------------- /examples/volumetric/isosurfaces2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Generate the isosurfaces corresponding to a set of thresholds. 3 | (These surfaces are not separate meshes). 4 | """ 5 | from vtk import vtkQuadric, vtkSampleFunction 6 | 7 | # Quadric definition. This is a type of implicit function. 8 | quadric = vtkQuadric() 9 | quadric.SetCoefficients(0.5, 1, 0.2, 0, 0.1, 0, 0, 0.2, 0, 0) 10 | 11 | # the vtkSampleFunction evaluates quadric over a volume 12 | sample = vtkSampleFunction() 13 | sample.SetSampleDimensions(40, 40, 40) 14 | sample.SetImplicitFunction(quadric) 15 | sample.Update() 16 | 17 | img = sample.GetOutput() # vtkImageData 18 | print("Scalar Range", img.GetScalarRange(), "\ntry press shift-x.") 19 | 20 | ######################## 21 | from vtkplotter import show, Text, Volume 22 | 23 | # generate an isosurface the volume for each thresholds 24 | ts = [0.1, 0.25, 0.4, 0.6, 0.75, 0.9] 25 | 26 | # Use c=None to use the default vtk color map. isos is of type Actor 27 | isos = Volume(img).isosurface(threshold=ts) 28 | 29 | show(isos, Text(__doc__)) 30 | -------------------------------------------------------------------------------- /examples/volumetric/legosurface.py: -------------------------------------------------------------------------------- 1 | """Represent a volume as lego blocks (voxels). 2 | Colors correspond to the volume's scalar. 3 | Try also: 4 | > vtkplotter --lego data/embryo.tif""" 5 | # https://matplotlib.org/users/colormaps.html 6 | from vtkplotter import * 7 | 8 | vol = load(datadir+'embryo.tif') # load Volume 9 | printHistogram(vol, logscale=True) 10 | 11 | vol.crop(back=0.5) # crop 50% from neg. y 12 | 13 | # show lego blocks whose value is between vmin and vmax 14 | lego = vol.legosurface(vmin=60, cmap='seismic') 15 | 16 | lego.addScalarBar(vmin=40, horizontal=1) # make colormap start at 40 17 | 18 | comment = Text(__doc__, c='k') 19 | 20 | show(lego, comment, bg='w', axes=1, viewup='z') 21 | -------------------------------------------------------------------------------- /examples/volumetric/lowpassfilter.py: -------------------------------------------------------------------------------- 1 | from vtkplotter import * 2 | 3 | # mode = 1 is maximum projection (default is 0=composite) 4 | v1 = load(datadir+'embryo.tif').mode(1) 5 | t1 = Text('Original volume', c='lg') 6 | 7 | # cutoff range is roughly in the range of 1 / size of object 8 | v2 = frequencyPassFilter(v1, highcutoff=.001, order=1).mode(1) 9 | t2 = Text('High freqs in the FFT\nare cut off:', c='lb') 10 | 11 | printHistogram(v1, logscale=1, horizontal=1, c='g') 12 | printHistogram(v2, logscale=1, horizontal=1, c='b') 13 | 14 | show([(v1,t1), (v2,t2)], N=2, zoom=1.5) 15 | #write(v2, 'embryo_filtered.vti') 16 | -------------------------------------------------------------------------------- /examples/volumetric/mesh2volume.py: -------------------------------------------------------------------------------- 1 | """Convert a mesh it into volume (left in grey) where the 2 | foreground voxels are 1 and the background voxels are 0. 3 | 4 | Right: the Volume is isosurfaced. 5 | """ 6 | from vtkplotter import * 7 | 8 | doc = Text(__doc__, c="k") 9 | 10 | s = load(datadir+"bunny.obj").normalize().wireframe() 11 | 12 | v = actor2Volume(s, spacing=(0.02, 0.02, 0.02)).alpha([0,0.5]).c('blue') 13 | 14 | iso = v.isosurface().color("b") 15 | 16 | show(v, s.scale(1.05), doc, at=0, N=2, bg="w") 17 | 18 | show(iso, at=1, interactive=1) 19 | -------------------------------------------------------------------------------- /examples/volumetric/numpy2volume.py: -------------------------------------------------------------------------------- 1 | # Make a Volume from a numpy object 2 | # 3 | import numpy as np 4 | from vtkplotter import * 5 | 6 | X, Y, Z = np.mgrid[:30, :30, :30] 7 | # scaled distance from the center at (15, 15, 15) 8 | scalar_field = ((X-15)**2 + (Y-15)**2 + (Z-15)**2)/225 9 | print('scalar min, max =', np.min(scalar_field), np.max(scalar_field)) 10 | 11 | vol = Volume(scalar_field) 12 | lego = vol.legosurface(vmin=1, vmax=2) 13 | text1 = Text('Make a Volume from a numpy object', c='blue') 14 | text2 = Text('legosurface representation', c='darkred') 15 | 16 | print('numpy array from Volume:', vol.getPointArray().shape) 17 | 18 | show([(vol,text1), (lego,text2)], N=2, bg='white') 19 | -------------------------------------------------------------------------------- /examples/volumetric/office.py: -------------------------------------------------------------------------------- 1 | """ 2 | Stream tubes originating from a probing grid of points. 3 | Data is from CFD analysis of airflow in an office with 4 | ventilation and a burning cigarette. 5 | """ 6 | # see original script at: 7 | # https://github.com/Kitware/VTK/blob/master/Examples/ 8 | # VisualizationAlgorithms/Python/officeTube.py 9 | from vtkplotter import * 10 | from office_furniture import furniture 11 | 12 | 13 | # We read a data file the is a CFD analysis of airflow in an office 14 | # (with ventilation and a burning cigarette). 15 | sgrid = loadStructuredGrid(datadir + "office.binary.vtk") 16 | 17 | 18 | # Now we will generate multiple streamlines in the data. We create a 19 | # grid of points of points and then use those as integration seeds. 20 | seeds = Grid(pos=[2,2,1], normal=[1,0,0], resx=2, resy=3, c="gray") 21 | 22 | # We select the integration order to use (RungeKutta order 4) and 23 | # associate it with the streamer. We integrate in the forward direction. 24 | slines = streamLines( 25 | sgrid, seeds, 26 | integrator="rk4", 27 | direction="forward", 28 | initialStepSize=0.01, 29 | maxPropagation=15, 30 | tubes={"radius":0.004, "varyRadius":2, "ratio":1}, 31 | ) 32 | 33 | comment = Text(__doc__, c="w") 34 | show(slines, seeds, furniture(), comment, axes=0) 35 | -------------------------------------------------------------------------------- /examples/volumetric/pointDensity.py: -------------------------------------------------------------------------------- 1 | """Density field as a Volume from a point cloud""" 2 | 3 | from vtkplotter import * 4 | 5 | t1 = Text("Original mesh") 6 | s = load(datadir+'spider.ply') 7 | 8 | t2 = Text("Density field as a Volume from point cloud") 9 | v = pointDensity(s).mode(1).printInfo() 10 | 11 | show([ [s, t1], 12 | [v, t2] ], 13 | N=2, 14 | ) 15 | -------------------------------------------------------------------------------- /examples/volumetric/probeLine.py: -------------------------------------------------------------------------------- 1 | """ 2 | Intersect a Volume (voxel dataset) with planes. 3 | """ 4 | from vtkplotter import show, load, probeLine, vector, Text, datadir 5 | 6 | vol = load(datadir+"embryo.slc") 7 | 8 | pos = vol.imagedata().GetCenter() 9 | 10 | lines = [] 11 | for i in range(60): # probe scalars on 60 parallel lines 12 | step = (i - 30) * 2 13 | p1, p2 = pos + vector(-100, step, step), pos + vector(100, step, step) 14 | a = probeLine(vol, p1, p2, res=200) 15 | a.alpha(0.5).lineWidth(6) 16 | lines.append(a) 17 | # print(a.scalars(0)) # numpy scalars can be access here 18 | # print(a.scalars('vtkValidPointMask')) # the mask of valid points 19 | 20 | show(lines, Text(__doc__), axes=4, bg="w") 21 | -------------------------------------------------------------------------------- /examples/volumetric/probePlane.py: -------------------------------------------------------------------------------- 1 | """ 2 | Intersect a Volume (voxel dataset) with planes 3 | """ 4 | from vtkplotter import show, load, probePlane, vector, Text, datadir 5 | 6 | vol = load(datadir+"embryo.slc") 7 | 8 | planes = [] 9 | for i in range(6): 10 | print("probing slice plane #", i) 11 | pos = vol.imagedata().GetCenter() + vector(0, 0, (i - 3) * 25.0) 12 | a = probePlane(vol, origin=pos, normal=(0, 0, 1)).alpha(0.2) 13 | planes.append(a) 14 | # print(max(a.scalars(0))) # access scalars this way, 0 means first 15 | 16 | show(planes, Text(__doc__), axes=4, bg="w") 17 | -------------------------------------------------------------------------------- /examples/volumetric/probePoints.py: -------------------------------------------------------------------------------- 1 | """ 2 | Probe a voxel dataset at specified points 3 | """ 4 | from vtkplotter import * 5 | import numpy as np 6 | 7 | vol = load(datadir+"embryo.slc") 8 | 9 | pts = np.random.rand(1000, 3)*256 10 | 11 | apts = probePoints(vol, pts).pointSize(3) 12 | 13 | #print(apts.scalars()) # check the list of point/cell scalars 14 | scals = apts.scalars(0) 15 | 16 | printHistogram(scals, minbin=1, horizontal=1, c='g') 17 | 18 | show(vol, apts, Text(__doc__), bg='w', axes=8) 19 | -------------------------------------------------------------------------------- /examples/volumetric/readVolume.py: -------------------------------------------------------------------------------- 1 | """ 2 | Work with vtkVolume objects and surface meshes 3 | in the same rendering window. 4 | """ 5 | from vtkplotter import * 6 | 7 | # Build a vtkVolume object. 8 | # A set of transparency values - of any length - can be passed 9 | # to define the opacity transfer function in the range of the scalar. 10 | # E.g.: setting alpha=[0, 0, 0, 1, 0, 0, 0] would make visible 11 | # only voxels with value close to center of the range (see printed histogram). 12 | vol = load(datadir+"embryo.slc", spacing=[1, 1, 1]) # vtkVolume 13 | vol.c("green").alpha([0, 0, 0.4, 0.9, 0.9]) 14 | 15 | printHistogram(vol, logscale=True) 16 | 17 | # can relocate volume in space: 18 | # vol.scale(0.3).pos([-1,1,0]).rotate(90, axis=[0,1,1]) 19 | 20 | sph = Sphere(pos=(100, 100, 100), r=20) # add a dummy surface 21 | 22 | doc = Text(__doc__, c="k") 23 | 24 | # show both vtkVolume and vtkActor 25 | show(vol, sph, doc, axes=8, verbose=0, bg="w", zoom=1.4) 26 | -------------------------------------------------------------------------------- /examples/volumetric/readVolumeAsIsoSurface.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example to read volumetric data in the form of a tiff stack 3 | or SLC (StereoLithography Contour) from files 4 | with or without automatic isosurfacing: 5 | 6 | A tiff stack is a set of image slices in z. The scalar value 7 | (intensity of white) is used to create an isosurface by fixing a threshold. 8 | If threshold=None this is set to 1/3 of the scalar range. 9 | 10 | - If the spacing of the tiff stack is uneven in xyz, this can be 11 | fixed by setting scaling factors with scaling=[xfac,yfac,zfac] 12 | """ 13 | print(__doc__) 14 | from vtkplotter import show, load, datadir 15 | 16 | # Read volume data from a tif file: 17 | f = datadir+"embryo.tif" 18 | 19 | v = load(f) # Volume 20 | a = load(f, threshold=80) # isosurfacing on the fly 21 | vp1 = show(v, a, shape=(1, 2), axes=8, viewup='z') 22 | 23 | # Can also read SLC files 24 | vol = load(datadir+"embryo.slc") # Volume 25 | vol.color(['lb','db','dg','dr']) # color transfer values along range 26 | vol.alpha([0.0, 0.0, 0.2, 0.6, 0.8, 1]) # opacity values along range 27 | 28 | # newPlotter triggers the instantiation of a new Plotter object 29 | vp2 = show(vol, pos=(300, 300), bg='white', 30 | viewup='z', zoom=1.5, 31 | newPlotter=True) 32 | -------------------------------------------------------------------------------- /examples/volumetric/read_vti.py: -------------------------------------------------------------------------------- 1 | """Using normal vtk commands to load a vtkImageData 2 | then use vtkplotter to show the resulting 3d images. 3 | 4 | mode=0, composite rendering 5 | mode=1, maximum-projection rendering 6 | """ 7 | import vtk 8 | from vtkplotter import datadir, load 9 | 10 | # Create the reader for the data. 11 | reader = vtk.vtkXMLImageDataReader() 12 | reader.SetFileName(datadir+"vase.vti") 13 | reader.Update() 14 | img = reader.GetOutput() # vtkImageData object 15 | 16 | # NB: the above lines could be reduced to: 17 | #img = load(datadir+"vase.vti").imagedata() 18 | 19 | ################################# 20 | from vtkplotter import Volume, show, Text 21 | 22 | # can set colors and transparencies along the scalar range 23 | # from minimum to maximum value. In this example voxels with 24 | # the smallest value will be completely transparent (and white) 25 | # while voxels with highest value of the scalar will get alpha=0.8 26 | # and color will be=(0,0,1) 27 | vol1 = Volume(img, mode=0) # composite rendering 28 | vol1.color(["white", "fuchsia", "dg", (0,0,1)]) 29 | #vol1.color('jet') # a matplotlib colormap name is also accepted 30 | vol1.alpha([0.0, 0.2, 0.3, 0.8]) 31 | 32 | # a transparency for the GRADIENT of the scalar can also be set: 33 | # in this case when the scalar is ~constant the gradient is ~zero 34 | # and the voxel are made transparent: 35 | vol1.alphaGradient([0.0, 0.5, 0.9]) 36 | 37 | # mode = 1 is maximum-projection volume rendering 38 | vol2 = load(datadir+"vase.vti").mode(1).addPos(60,0,0) 39 | 40 | # show command creates and returns an instance of class Plotter 41 | show(vol1, vol2, Text(__doc__), bg="w", axes=1) 42 | -------------------------------------------------------------------------------- /examples/volumetric/streamlines1.py: -------------------------------------------------------------------------------- 1 | """Streamlines originating from a probing sphere 2 | in a volume domain defined by the pink hyperboloid. 3 | The vector field is given by the coords of the hyperboloid, 4 | this field is interpolated to the whole bounding box. 5 | """ 6 | from vtkplotter import * 7 | 8 | 9 | mesh = Hyperboloid(pos=(0,0,0)).alpha(0.2) 10 | 11 | vects = mesh.clone().coordinates() # let's assume this 12 | mesh.addPointVectors(vects, 'hyp_coords') 13 | 14 | probe = Sphere(pos=[0,0.6,0.3], r=0.3, res=8).clean() 15 | probe.wireframe().alpha(0.2).color('g') 16 | 17 | stream = streamLines(mesh, probe, 18 | maxPropagation=0.3, 19 | extrapolateToBoundingBox={'dims':(10,10,10)}) 20 | 21 | msg = Text(__doc__, c='k') 22 | 23 | show(stream, probe, mesh, mesh.box(), msg, 24 | bg='w', axes=3, viewup='z') 25 | -------------------------------------------------------------------------------- /examples/volumetric/streamlines2.py: -------------------------------------------------------------------------------- 1 | """Load an existing vtkStructuredGrid and draw 2 | the streamlines of the velocity field 3 | """ 4 | import vtk 5 | from vtkplotter import * 6 | 7 | ######################## vtk 8 | # Read the data and specify which scalars and vectors to read. 9 | pl3d = vtk.vtkMultiBlockPLOT3DReader() 10 | pl3d.SetXYZFileName(datadir+"combxyz.bin") 11 | pl3d.SetQFileName(datadir+"combq.bin") 12 | pl3d.SetScalarFunctionNumber(100) 13 | pl3d.SetVectorFunctionNumber(202) 14 | pl3d.Update() 15 | # this vtkStructuredData already has a vector field: 16 | domain = pl3d.GetOutput().GetBlock(0) 17 | 18 | ######################## vtkplotter 19 | comment = Text(__doc__, c='w') 20 | box = Actor(domain, c=None, alpha=0.1) 21 | 22 | probe= Grid(pos=[9,0,30], normal=[1,0,0], sx=5, sy=5, resx=6, resy=6) 23 | probe.color('k') 24 | 25 | stream = streamLines(domain, probe, direction='backwards') 26 | 27 | show(stream, probe, box, comment, axes=8) 28 | -------------------------------------------------------------------------------- /examples/volumetric/streamribbons.py: -------------------------------------------------------------------------------- 1 | """Load an existing vtkStructuredGrid and draw the 2 | lines of the velocity field joining them in ribbons 3 | """ 4 | import vtk 5 | from vtkplotter import * 6 | 7 | ######################## vtk 8 | # Read the data and specify which scalars and vectors to read. 9 | pl3d = vtk.vtkMultiBlockPLOT3DReader() 10 | pl3d.SetXYZFileName(datadir+"combxyz.bin") 11 | pl3d.SetQFileName(datadir+"combq.bin") 12 | pl3d.SetScalarFunctionNumber(100) 13 | pl3d.SetVectorFunctionNumber(202) 14 | pl3d.Update() 15 | # this vtkStructuredData already contains a vector field: 16 | domain = pl3d.GetOutput().GetBlock(0) 17 | 18 | ######################## vtkplotter 19 | msg = Text(__doc__, c='w') 20 | box = Actor(domain, c=None, alpha=0.1) 21 | 22 | probe = Line([9,0,28], [11,0,33], res=11).color('k') 23 | 24 | stream = streamLines(domain, probe, direction='backwards', ribbons=2) 25 | 26 | show(box, probe, stream, msg, axes=8) 27 | -------------------------------------------------------------------------------- /examples/volumetric/tensors.py: -------------------------------------------------------------------------------- 1 | """Visualize stress tensors as ellipsoids.""" 2 | import vtk 3 | from vtkplotter import * 4 | 5 | # Create a volume with tensors 6 | pl = vtk.vtkPointLoad() 7 | pl.SetLoadValue(50) 8 | pl.SetSampleDimensions(6,6,6) 9 | pl.ComputeEffectiveStressOn() 10 | pl.SetPoissonsRatio(0.2) 11 | pl.SetModelBounds(-10,10,-10,10,-10,10) 12 | pl.Update() 13 | vol = Volume(pl.GetOutput(), mode=1) 14 | 15 | # Extract a slice of the volume data at index 3 16 | zsl = vol.zSlice(3) 17 | 18 | # Generate tensor ellipsoids 19 | tens1 = Tensors(vol, source='ellipse', scale=10) 20 | tens2 = Tensors(zsl, source='ellipse', scale=20) 21 | t = Text(__doc__, c='k') 22 | 23 | show([[vol, t], tens1], N=2, axes=9, bg='w', viewup='z') 24 | show(vol, tens2, zsl, axes=9, bg='w', viewup='z', newPlotter=True) 25 | -------------------------------------------------------------------------------- /examples/volumetric/tet_mesh_ugrid.py: -------------------------------------------------------------------------------- 1 | """Read a tetrahedral mesh from a 2 | vtkUnstructuredGrid object and visualize 3 | it as either a Volume or a mesh Actor 4 | """ 5 | from vtkplotter import * 6 | 7 | ug = loadUnStructuredGrid(datadir+'limb_ugrid.vtk') 8 | 9 | cmap = 'nipy_spectral' 10 | 11 | vol = Volume(ug).color(cmap) 12 | 13 | ################################ 14 | # if False will only show the outer surface: 15 | settings.visibleGridEdges = True 16 | 17 | mesh = Actor(ug).color(cmap).alpha(0.2).addScalarBar() 18 | 19 | txt = Text(__doc__, c='w') 20 | 21 | show([(txt,vol), mesh], N=2) 22 | -------------------------------------------------------------------------------- /examples/volumetric/vol2points.py: -------------------------------------------------------------------------------- 1 | """Extract all image voxels as points""" 2 | from vtkplotter import * 3 | 4 | t = Text(__doc__, c='white') 5 | v = load(datadir+'vase.vti') # Volume 6 | 7 | pts = volumeToPoints(v).printInfo() # returns an Actor 8 | 9 | scalars = pts.scalars(0) 10 | pts.pointColors(scalars, cmap='jet') 11 | 12 | show([(v,t), pts], N=2, viewup='z', zoom=1.5) 13 | 14 | -------------------------------------------------------------------------------- /examples/volumetric/volumeFromMesh.py: -------------------------------------------------------------------------------- 1 | """Generate a scalar field by the signed distance from a mesh, 2 | optionally save it to a vti file, 3 | then extract an isosurface from the 3d image. 4 | """ 5 | from vtkplotter import * 6 | 7 | mesh = load(datadir+"pumpkin.vtk") 8 | 9 | # Generate signed distance volume 10 | vol = volumeFromMesh(mesh, 11 | dims=(40,40,40), 12 | bounds=(-1.1, 1.1, -1.1, 1.1, -1.1, 1.1), 13 | signed=True, 14 | negate=True, # invert sign 15 | ) 16 | #write(vol, 'stack.vti') 17 | 18 | iso = vol.isosurface(threshold=-0.01) 19 | 20 | pts = Points(mesh.coordinates()) 21 | 22 | show(iso, pts, Text(__doc__), axes=1) 23 | -------------------------------------------------------------------------------- /examples/volumetric/volumeOperations.py: -------------------------------------------------------------------------------- 1 | """ 2 | Perform other simple mathematical operation between 3d Volumes. 3 | Possible operations are: +, -, /, 1/x, sin, cos, exp, log, abs, **2, sqrt, 4 | min, max, atan, atan2, median, mag, dot, gradient, divergence, laplacian. 5 | Alphas defines the opacity transfer function in the scalar range. 6 | """ 7 | print(__doc__) 8 | 9 | from vtkplotter import Plotter, load, volumeOperation, datadir 10 | 11 | vp = Plotter(N=8, axes=0, bg="w") 12 | 13 | v0 = load(datadir+"embryo.slc").c(0) # vtkVolume 14 | vp.show(v0, at=0) 15 | 16 | v1 = volumeOperation(v0, "gradient") 17 | v1 = volumeOperation(v1, "+", 92.0).c(1).alpha([0, 1, 0, 0, 0]) 18 | vp.show(v1, at=1) 19 | 20 | v2 = volumeOperation(v0, "divergence").c(2) 21 | vp.show(v2, at=2) 22 | 23 | v3 = volumeOperation(v0, "laplacian").c(3).alpha([0, 1, 0, 0, 1]) 24 | vp.show(v3, at=3) 25 | 26 | v4 = volumeOperation(v0, "median").c(4) 27 | vp.show(v4, at=4) 28 | 29 | v5 = volumeOperation(v0, "sqrt").c(5) 30 | vp.show(v5, at=5) 31 | 32 | v6 = volumeOperation(v0, "log").c(6) 33 | vp.show(v6, at=6) 34 | 35 | v7 = volumeOperation(v0, "dot", v0).c(7) 36 | vp.show(v7, at=7, zoom=1.3, interactive=1) 37 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | vtk 2 | k3d 3 | -------------------------------------------------------------------------------- /vtkplotter.desktop: -------------------------------------------------------------------------------- 1 | 2 | #To be placed in /usr/share/applications/ 3 | #then right-click a file 4 | #choose Properties 5 | #choose Open With ... vtkplotter 6 | 7 | [Desktop Entry] 8 | Type=Application 9 | Name=vtkplotter 10 | GenericName=vtkplotter 11 | Comment=Scientific 3D Viewer 12 | Comment[it]=Visualizzatore di modelli 3D in vari formati 13 | Exec=vtkplotter %F 14 | Categories=Science;Graphics;3DGraphics; 15 | Icon=python 16 | Terminal=true 17 | StartupNotify=false 18 | MimeType=text/x-python;application/x-wavefront-obj;application/x-collada; 19 | X-AppStream-Ignore=True 20 | Keywords=browser;vtk;collada; 21 | 22 | -------------------------------------------------------------------------------- /vtkplotter/data/270_flank.vtk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/vtkplotter/data/270_flank.vtk -------------------------------------------------------------------------------- /vtkplotter/data/290.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/vtkplotter/data/290.xml.gz -------------------------------------------------------------------------------- /vtkplotter/data/SuperQuadric.vtp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/vtkplotter/data/SuperQuadric.vtp -------------------------------------------------------------------------------- /vtkplotter/data/circle.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/vtkplotter/data/circle.xml.gz -------------------------------------------------------------------------------- /vtkplotter/data/combq.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/vtkplotter/data/combq.bin -------------------------------------------------------------------------------- /vtkplotter/data/combxyz.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/vtkplotter/data/combxyz.bin -------------------------------------------------------------------------------- /vtkplotter/data/cube.off: -------------------------------------------------------------------------------- 1 | OFF 2 | 8 6 0 3 | -0.500000 -0.500000 0.500000 4 | 0.500000 -0.500000 0.500000 5 | -0.500000 0.500000 0.500000 6 | 0.500000 0.500000 0.500000 7 | -0.500000 0.500000 -0.500000 8 | 0.500000 0.500000 -0.500000 9 | -0.500000 -0.500000 -0.500000 10 | 0.500000 -0.500000 -0.500000 11 | 4 0 1 3 2 12 | 4 2 3 5 4 13 | 4 4 5 7 6 14 | 4 6 7 1 0 15 | 4 1 7 5 3 16 | 4 6 0 2 4 17 | -------------------------------------------------------------------------------- /vtkplotter/data/dolfin_cube.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NNU-GISA/vtkplotter/fbed73d6ed3f049dca3421c64e2e82ac1eef69a8/vtkplotter/data/dolfin_cube.h5 -------------------------------------------------------------------------------- /vtkplotter/data/dolfin_cube.xdmf: -------------------------------------------------------------------------------- 1 | 2 |