-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
614 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,32 @@ | ||
""" | ||
Create an animated logo. | ||
Sharpe lab animated logo. | ||
""" | ||
from vtkplotter import * | ||
|
||
exa = Polygon().scale(4.1).pos(5.25, 4.8, 0).off() | ||
box = Box([10, 5, 0], 20, 20, 15).alpha(0) | ||
his = histogram2D([-1, 1], [-1, 1]).getActors() | ||
his = hexHistogram([-1, 1], [-1, 1]).getActors() | ||
|
||
exah, cmh = [], [] | ||
for h in his: | ||
cm = h.centerOfMass() | ||
if exa.isInside(cm): | ||
h.shrink(0.94)#.addShadow(z=-1) | ||
h.c('green').shrink(0.94) | ||
exah.append(h) | ||
cmh.append(cm) | ||
exah[13].c('red') | ||
|
||
v1 = vector(9.1, 5.0, -0.1) | ||
v2 = vector(9.2, 3.4, -0.1) | ||
t1 = Text("Sharpe Lab", v1, c="k").scale([.999,1,1]) | ||
t2 = Text("EMBL Barcelona", v2, c="dg") | ||
t1 = Text("Sharpe Lab", (9.1, 5.0, -0.1), c="k") | ||
t2 = Text("EMBL Barcelona", (9.2, 3.4, -0.1), c="dg") | ||
|
||
for ti in reversed(range(100)): | ||
t = ti / 100. | ||
for j, h in enumerate(exah): | ||
cx, cy, _ = cmh[j] - [4,5,0] | ||
h.pos(cos(cy*t) *t*2, sin(cx*t)*t*2, t*cx/2).alpha((1-t)**3) | ||
t1.alpha((1-t)**4) | ||
t2.scale([(1-t)*0.67, (1-t)*0.75, (1-t)*0.75]).alpha((1-t)**2) | ||
show(box, exa, exah, t1, t2, | ||
resetcam=0, elevation=0, bg="w", axes=0, interactive=0) | ||
|
||
Plotter(bg="w", axes=0, interactive=0) | ||
def run(rng): | ||
for ti in rng: | ||
t = ti / 100. | ||
for j, h in enumerate(exah): | ||
cx, cy, _ = cmh[j] - [4,5,0] | ||
h.pos(cos(cy*t) *t*2, sin(cx*t)*t*2, t*cx/2).alpha((1-t)**3) | ||
#h.shadow.alpha(t**4) | ||
t1.alpha((1-t)**4) | ||
t2.scale([(1-t)*0.67, (1-t)*0.75, (1-t)*0.75]).alpha((1-t)**2) | ||
show(box, exa, exah, t1, t2, resetcam=0, elevation=0) | ||
import time | ||
run(reversed(range(100))) | ||
time.sleep(2) | ||
run(range(100)) | ||
time.sleep(.2) | ||
run(reversed(range(100))) | ||
interactive() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
''' | ||
logo | ||
vtkplotter logo | ||
''' | ||
from vtkplotter import * | ||
|
||
ln = [ [sin(x), cos(x), x/2] for x in arange(0,9, 0.1)] | ||
N = len(ln) | ||
|
||
vp = Plotter(verbose=0, axes=0) | ||
vp.camera.SetPosition( [-0.088, 6.198, 12.757] ) | ||
vp.camera.SetFocalPoint( [-0.105, 0.105, 2.209] ) | ||
vp.camera.SetViewUp( [-0.294, -0.827, 0.478] ) | ||
vp.camera.SetDistance( 12.181 ) | ||
vp.camera.SetClippingRange( [6.344, 19.557] ) | ||
vp = Plotter(verbose=0, axes=0, bg='bb') | ||
|
||
rads = [ 0.3*(cos(6.*ir/N))**2+0.1 for ir in range(N) ] | ||
cols = [ -i for i in range(N)] | ||
cols = makeBands(cols, 5) # make 5 color bins | ||
t = Tube(ln, r=rads, c=cols, res=24) | ||
vp.show(t) | ||
|
||
vp.show(t, interactive=0) | ||
vp.camera.SetPosition( [-0.088, 6.198, 12.757] ) | ||
vp.camera.SetFocalPoint( [-0.105, 0.105, 2.209] ) | ||
vp.camera.SetViewUp( [-0.294, -0.827, 0.478] ) | ||
vp.camera.SetDistance( 12.181 ) | ||
vp.camera.SetClippingRange( [6.344, 19.557] ) | ||
vp.show(t, interactive=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
''' | ||
for i in range(10): | ||
Cone(...) # no variable assigned! | ||
show(collection()) | ||
Cone().x(i) # no variable assigned! | ||
show(...) # show all sofar created objs | ||
''' | ||
from vtkplotter import Cone, collection, Text, show | ||
|
||
for i in range(10): | ||
Cone(pos=[3*i, 0, 0], axis=[i, i-5, 0]) # no variable assigned | ||
Cone(pos=[2*i, 0, 0]).color(i) # no variable assigned | ||
|
||
Text(__doc__, font='courier') | ||
Text(__doc__) | ||
|
||
# collection() retrieves the list of all created actors | ||
show(collection()) | ||
# three points, aka ellipsis, retrieves the list of all created objects | ||
# in python 2 use collection() instead | ||
show(..., axes=1, viewup='z') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Find cells within specified bounds in x, y and z. | ||
""" | ||
from vtkplotter import * | ||
|
||
mesh = load(datadir+'shark.ply').normalize() | ||
mesh.color('aqua').lineWidth(0.1) | ||
|
||
x1, x2 = -0.1,0.3 | ||
|
||
ids = mesh.findCellsWithin(xbounds=(x1,x2), c='tomato') | ||
|
||
printc('IDs of cells within bounds:', ids, c='r') | ||
|
||
p1 = Plane(normal=(1,0,0), sx=2, sy=2).x(x1).c('gray').alpha(0.5) | ||
p2 = Plane(normal=(1,0,0), sx=2, sy=2).x(x2).c('gray').alpha(0.5) | ||
|
||
show(mesh, p1, p2, Text(__doc__), axes=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Extruding a polygon | ||
along the z-axis | ||
""" | ||
from vtkplotter import * | ||
|
||
pol = Star().pos(0,0,0).rotateX(10) | ||
|
||
epol = extrude(pol, zshift=1, rotation=10, dR=-0.2, cap=False, res=1) | ||
epol.bc('violet') | ||
|
||
show(epol, Text(__doc__), axes=1, bg='white', viewup='z') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Kochanek–Bartels spline | ||
""" | ||
from vtkplotter import Text, Points, KSpline, show | ||
from random import uniform as u | ||
|
||
pts = [(u(0, 2), u(0, 2), u(0, 2) + i) for i in range(8)] | ||
|
||
Points(pts, r=10) | ||
Text(__doc__) | ||
|
||
for i in range(10): | ||
g = (i/10-0.5)*2 # from -1 to 1 | ||
KSpline(pts, continuity=g, tension=0, bias=0, closed=False).color(i) | ||
|
||
# plot all object sofar created: | ||
show(..., viewup="z", axes=1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from dolfin import * | ||
|
||
mesh = Mesh() | ||
editor = MeshEditor() | ||
editor.open(mesh, "triangle", 2, 2) | ||
editor.init_vertices(3) | ||
editor.add_vertex(0, [-1, 0]) | ||
editor.add_vertex(1, [ 1, 0]) | ||
editor.add_vertex(2, [ 0, 1]) | ||
editor.init_cells(1) | ||
editor.add_cell(0, [0, 1, 2]) | ||
editor.close() | ||
mesh.init() | ||
|
||
W = FunctionSpace(mesh, "BDM", 1) | ||
|
||
v = Expression(("0", "x[0]*x[0]"), degree=2) | ||
|
||
vi = interpolate(v, W) | ||
|
||
from vtkplotter.dolfin import plot | ||
plot(vi, scalarbar="horizontal", style="meshlab") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from PyQt5 import QtWidgets | ||
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor | ||
from vtkplotter import load, datadir, Plotter | ||
|
||
from qt_tabs_ui import Ui_MainWindow | ||
|
||
|
||
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): | ||
def __init__(self, parent=None): | ||
QtWidgets.QMainWindow.__init__(self, parent) | ||
self.setupUi(self) | ||
|
||
self.vtkWidget = QVTKRenderWindowInteractor(self) | ||
self.vtkLayout.addWidget(self.vtkWidget) | ||
|
||
self.plt = Plotter(qtWidget=self.vtkWidget, axes=1, bg='white') | ||
|
||
self.plt += load(datadir+'shark.ply').c('cyan') | ||
|
||
self.plt.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
|
||
app = QtWidgets.QApplication(sys.argv) | ||
|
||
window = MainWindow() | ||
window.show() | ||
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# https://stackoverflow.com/questions/58039617/problem-loading-vtk-window-into-pyqt-window | ||
from PyQt5 import QtCore, QtWidgets | ||
|
||
try: | ||
_fromUtf8 = QtCore.QString.fromUtf8 | ||
except AttributeError: | ||
def _fromUtf8(s): return s | ||
|
||
try: | ||
_encoding = QtWidgets.QApplication.UnicodeUTF8 | ||
def _translate(context, text, disambig): | ||
return QtWidgets.QApplication.translate(context, text, disambig, _encoding) | ||
except AttributeError: | ||
def _translate(context, text, disambig): | ||
return QtWidgets.QApplication.translate(context, text, disambig) | ||
|
||
|
||
class Ui_MainWindow(object): | ||
def setupUi(self, MainWindow): | ||
MainWindow.setObjectName(_fromUtf8("MainWindow")) | ||
MainWindow.resize(800, 600) | ||
self.centralwidget = QtWidgets.QWidget(MainWindow) | ||
self.centralwidget.setObjectName(_fromUtf8("centralwidget")) | ||
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) | ||
self.gridLayout.setObjectName(_fromUtf8("gridLayout")) | ||
self.verticalLayout = QtWidgets.QVBoxLayout() | ||
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) | ||
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget) | ||
self.tabWidget.setObjectName(_fromUtf8("tabWidget")) | ||
self.tab = QtWidgets.QWidget() | ||
self.tab.setObjectName(_fromUtf8("tab")) | ||
self.gridLayout_2 = QtWidgets.QGridLayout(self.tab) | ||
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) | ||
self.vtkLayout = QtWidgets.QVBoxLayout() | ||
self.vtkLayout.setObjectName(_fromUtf8("vtkLayout")) | ||
self.gridLayout_2.addLayout(self.vtkLayout, 0, 0, 1, 1) | ||
self.tabWidget.addTab(self.tab, _fromUtf8("")) | ||
self.tab_2 = QtWidgets.QWidget() | ||
self.tab_2.setObjectName(_fromUtf8("tab_2")) | ||
self.tabWidget.addTab(self.tab_2, _fromUtf8("")) | ||
self.verticalLayout.addWidget(self.tabWidget) | ||
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1) | ||
MainWindow.setCentralWidget(self.centralwidget) | ||
self.menubar = QtWidgets.QMenuBar(MainWindow) | ||
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 31)) | ||
self.menubar.setObjectName(_fromUtf8("menubar")) | ||
MainWindow.setMenuBar(self.menubar) | ||
self.statusbar = QtWidgets.QStatusBar(MainWindow) | ||
self.statusbar.setObjectName(_fromUtf8("statusbar")) | ||
MainWindow.setStatusBar(self.statusbar) | ||
|
||
self.retranslateUi(MainWindow) | ||
self.tabWidget.setCurrentIndex(0) | ||
QtCore.QMetaObject.connectSlotsByName(MainWindow) | ||
|
||
def retranslateUi(self, MainWindow): | ||
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None)) | ||
self.tabWidget.setTabText( | ||
self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Tab 1", None) | ||
) | ||
self.tabWidget.setTabText( | ||
self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Tab 2", None) | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
|
||
app = QtWidgets.QApplication(sys.argv) | ||
MainWindow = QtWidgets.QMainWindow() | ||
ui = Ui_MainWindow() | ||
ui.setupUi(MainWindow) | ||
MainWindow.show() | ||
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.