Skip to content

Commit

Permalink
docs updated
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Aug 29, 2021
1 parent 4273f08 commit 51298fb
Show file tree
Hide file tree
Showing 18 changed files with 1,511 additions and 1,534 deletions.
1 change: 1 addition & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
---
### `plotter.py`

- removed global functions `closeWindow()` `ion()` `ioff()`, `plotter.load()`
- added `record()` and `play()` to store and playback camera and all other events
- keyword `interactorStyle` becomes now `mode`

Expand Down
31 changes: 15 additions & 16 deletions examples/basic/mousehover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@
Press c to clear the path"""
from vedo import *

def func(evt): ### called every time the mouse moves!
if not evt.actor: return # no hits, return. (NB: evt is a dictionary)
pt = evt.picked3d # 3d coords of picked point under mouse
def func(evt): ### called every time mouse moves!
msh = evt.actor
if not msh: return # no mouse hits, return.
pt = evt.picked3d # 3d coords of point under mouse

pid = evt.actor.closestPoint(pt, returnPointId=True)
pid = msh.closestPoint(pt, returnPointId=True)
txt = f"Point: {precision(pt[:2] ,2)}\n" \
f"Height: {precision(arr[pid],3)}\n" \
f"Ground speed: {precision(evt.speed3d*100,2)}"
arw = Arrow(pt - evt.delta3d, pt, s=0.001, c='orange5')
vig = evt.actor.vignette(txt, point=pt, offset=(0.4,0.6),
s=0.04, c='k', font="VictorMono").followCamera()
msg.text(txt) # update text message
if len(plt.actors)>3:
plt.pop() # remove the old vignette
plt.add([arw, vig]) # add Arrow and the new vig
vig = msh.vignette(txt, point=pt, offset=(0.4,0.6),
s=0.04, c='k', font="VictorMono").followCamera()
msg.text(txt) # update text message
if len(plt.actors)>3: plt.pop() # remove the old vignette
plt.add([arw, vig]) # add Arrow and the new vignette

msg = Text2D(pos='bottom-left', font="VictorMono") # an empty text
hil = ParametricShape('RandomHills').cmap('terrain').addScalarBar()
arr = hil.getPointArray("Scalars")
arr = hil.getPointArray("Scalars") # numpy array with heights

plt = Plotter(axes=1, bg2='lightblue')
plt.addCallback('mouse moving', func) # the callback function
plt.addCallback('keyboard', lambda e: plt.remove(plt.actors[3:], render=True))

msg = Text2D("", pos='bottom-left', font="VictorMono")

plt.addCallback('mouse move', func) # add the callback function
plt.addCallback('keyboard', lambda e: plt.remove(plt.actors[3:]).render())
plt.show(hil, msg, __doc__, viewup='z')

45 changes: 45 additions & 0 deletions examples/other/wx_window2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import wx
import vedo
from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor

##################################################### wx app
app = wx.App(False)
frame = wx.Frame(None, -1, "vedo with wxpython", size=(800,800))
widget = wxVTKRenderWindowInteractor(frame, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(widget, 1, wx.EXPAND)
frame.SetSizer(sizer)
frame.Layout()
widget.Enable(1)
widget.AddObserver("ExitEvent", lambda o,e,f=frame: f.Close())

##################################################### vedo
def funcMove(event):
mesh = event.actor
if not mesh: return

ptid = mesh.closestPoint(event.picked3d, returnPointId=True)
txt = f"Probed point:\n{vedo.utils.precision(event.picked3d, 3)}\n" \
f"value = {vedo.utils.precision(arr[ptid], 2)}"

vpt = vedo.shapes.Sphere(mesh.points(ptid), r=0.01, c='orange2').pickable(False)
vig = vpt.vignette(txt, s=.05, offset=(0.5,0.5), font="VictorMono").followCamera()

msg.text(txt) # update the 2d text message
plt.remove(plt.actors[-2:]).add([vpt, vig]) # remove last 2 objects, add the new ones
widget.Render() # need to manually call Render

msg = vedo.Text2D(pos='bottom-left', font="VictorMono")
msh = vedo.shapes.ParametricShape("RandomHills").cmap('terrain')
axs = vedo.Axes(msh)
arr = msh.getPointArray("Scalars")

plt = vedo.Plotter(bg='moccasin', bg2='blue9', wxWidget=widget)
plt.add([msh, axs, msg]).resetCamera()
plt.actors += [None,None,None] # place holder for sphere, vignette, text2d
plt.addCallback('MouseMove', funcMove)

#####################################################
# Show everything
frame.Show()
app.MainLoop()
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
vtk==8.1.2,>=7
vtk
Deprecated

4 changes: 0 additions & 4 deletions vedo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,3 @@
settings._init()
###########################################################################


def CubicGrid(*args, **kwargs):
print("*** CubicGrid is obsolete: use TessellatedBox. ***")
return TessellatedBox(*args, **kwargs)
55 changes: 2 additions & 53 deletions vedo/addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"addSlider3D",
"addButton",
"addCutterTool",
"addSplineTool",
"addIcon",
"LegendBox",
"Light",
Expand Down Expand Up @@ -248,7 +247,6 @@ def __init__(self, points, pc='k', ps=8, lc='r4', ac='g5', lw=2, closed=False, o
ontop : bool, optional
show it always on top of other objects. The default is True.
"""

vtk.vtkContourWidget.__init__(self)

self.representation = vtk.vtkOrientedGlyphContourRepresentation()
Expand Down Expand Up @@ -470,55 +468,6 @@ def Light(


#####################################################################
def addSplineTool(plotter, points, pc='k', ps=8, lc='r4', ac='g5',
lw=2, closed=False, interactive=True):
"""
Add a spline tool to the current plotter. Nodes of the spline can be dragged in space
with the mouse.
Clicking on the line itself adds an extra point.
Selecting a point and pressing ``del`` removes it.
Parameters
----------
points : Mesh, Points, array
the set of vertices forming the spline nodes.
pc : str, optional
point color. The default is 'k'.
ps : str, optional
point size. The default is 8.
lc : str, optional
line color. The default is 'r4'.
ac : str, optional
active point marker color. The default is 'g5'.
lw : int, optional
line width. The default is 2.
closed : bool, optional
spline is meant to be closed. The default is False.
Returns
-------
SplineTool object.
"""
sw = SplineTool(points, pc, ps, lc, ac, lw, closed)
if plotter.interactor:
sw.SetInteractor(plotter.interactor)
else:
printc("Error in addSplineTool: no interactor found.", c='r')
raise RuntimeError
sw.On()
sw.Initialize(sw.points.polydata())
if sw.closed:
sw.representation.ClosedLoopOn()
sw.representation.SetRenderer(plotter.renderer)
sw.representation.BuildRepresentation()
sw.Render()
if interactive:
plotter.interactor.Start()
else:
plotter.interactor.Render()
return sw


def addScalarBar(obj,
title="",
pos=(0.8,0.05),
Expand Down Expand Up @@ -1580,8 +1529,8 @@ def Ruler(
|goniometer| |goniometer.py|_
"""
if unitScale != 1.0 and units == "":
raise ValueError(f"When setting 'unitScale' to a value other than 1, "
f"a 'units' arguments must be specified.")
raise ValueError("When setting 'unitScale' to a value other than 1, " +
"a 'units' arguments must be specified.")

if isinstance(p1, Points): p1 = p1.GetPosition()
if isinstance(p2, Points): p2 = p2.GetPosition()
Expand Down
27 changes: 14 additions & 13 deletions vedo/applications.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vedo
from vedo.addons import addScalarBar, addGlobalAxes
from vedo.addons import addScalarBar
from vedo.plotter import Plotter
from vedo.pyplot import cornerHistogram
from vedo.utils import mag, precision, linInterpolate, isSequence
Expand Down Expand Up @@ -532,20 +532,21 @@ def sliderfunc(widget, event=None):
class FreeHandCutPlotter(Plotter):
"""
A Plotter derived class which edits polygonal meshes interactively.
Can also be invoked from command line. E.g. with:
Can also be invoked from command line. E.g. with
``vedo --edit https://vedo.embl.es/examples/data/porsche.ply``
Usage
-----
- Left-click and hold to rotate
- Right-click and move to draw line
- Second right-click to stop drawing
- Press c to clear points
- z/Z to cut mesh (Z inverts inside-out the selection area)
- L to keep only the largest connected surface
- s to save mesh to file (tag _edited is appended to filename)
- u to undo last action
- h for help, i for info
Usage:
- Left-click and hold to rotate
- Right-click and move to draw line
- Second right-click to stop drawing
- Press c to clear points
- z/Z to cut mesh (Z inverts inside-out the selection area)
- L to keep only the largest connected surface
- s to save mesh to file (tag _edited is appended to filename)
- u to undo last action
- h for help, i for info
Parameters
----------
Expand Down
8 changes: 7 additions & 1 deletion vedo/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
# see below, this is dealt with in colorMap()


red = '\x1b[1m\x1b[31;1m'
green = '\x1b[1m\x1b[32;1m'
blue = '\x1b[1m\x1b[34;1m'
yellow= '\x1b[1m\x1b[33;1m'
reset = "\x1b[0m"


#########################################################
# basic color schemes
#########################################################
Expand Down Expand Up @@ -445,7 +452,6 @@
"viridis", "viridis_r", "winter", "winter_r"
)


def _isSequence(arg):
# Check if input is iterable.
if hasattr(arg, "strip"):
Expand Down
Loading

0 comments on commit 51298fb

Please sign in to comment.