Commit 2092c3c6 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Include interactive visualization demo

parent c9fca17b
...@@ -155,7 +155,7 @@ format <http://www.webmproject.org>`_: ...@@ -155,7 +155,7 @@ format <http://www.webmproject.org>`_:
.. code-block:: bash .. code-block:: bash
$ mencoder mf://frames/dancing*.png -mf w=500:h=400:type=png -ovc raw -of rawvideo -vf format=i420 -nosound -o dancing.yuy $ mencoder mf://frames/dancing*.png -mf w=500:h=400:type=png -ovc raw -of rawvideo -vf format=i420 -nosound -o dancing.yuy
$ vpxenc sirs.yuy -o dancing.webm -w 500 -h 400 --fps=100/1 --target-bitrate=5000 --good --threads=4 $ vpxenc dancing.yuy -o dancing.webm -w 500 -h 400 --fps=100/1 --target-bitrate=5000 --good --threads=4
.. doctest:: .. doctest::
...@@ -175,4 +175,58 @@ The resulting animation can be downloaded :download:`here ...@@ -175,4 +175,58 @@ The resulting animation can be downloaded :download:`here
<div style="text-align:center"> <div style="text-align:center">
<video id="sirs" src="../_downloads/dancing.webm" controls></video> <video id="sirs" src="../_downloads/dancing.webm" controls></video>
</div> </div>
\ No newline at end of file
Interactive visualizations
--------------------------
Here we show an example of interactive visualization where the BFS tree
of the currently selected vertex is highlighted with a different color.
The script which performs the visualization is called
:download:`interactive_bst.py <interactive_bst.py>` and is shown
below. When called, it will open an interactive window.
.. literalinclude:: interactive_bst.py
:linenos:
.. code-block:: bash
$ ./interactive_bst.py offscreen
.. doctest::
:hide:
>>> import subprocess
>>> subprocess.call(["demos/interactive_bst.py", "offscreen"])
0
The above script is interactive, i.e. it expects a reaction from the
user. But for the purpose of this demo, it also saves the frames to a
file, so we can encode the animation with the `WebM format
<http://www.webmproject.org>`_:
.. code-block:: bash
$ mencoder mf://frames/bfs*.png -mf w=500:h=400:type=png -ovc raw -of rawvideo -vf format=i420 -nosound -o bfs.yuy
$ vpxenc bfs.yuy -o bfs.webm -w 500 -h 400 --fps=5/1 --target-bitrate=5000 --good --threads=4
.. doctest::
:hide:
>>> import subprocess
>>> subprocess.call("mencoder mf://frames/bfs*.png -mf w=500:h=400:type=png -ovc raw -of rawvideo -vf format=i420 -nosound -o demos/bfs.yuy".split())
0
>>> subprocess.call("vpxenc demos/bfs.yuy -o demos/bfs.webm -w 500 -h 400 --fps=5/1 --target-bitrate=2000 --good --threads=4".split())
0
The resulting animation can be downloaded :download:`here
<bfs.webm>`, or played below if your browser supports WebM.
.. raw:: html
<div style="text-align:center">
<video id="sirs" src="../_downloads/bfs.webm" controls></video>
</div>
...@@ -656,14 +656,10 @@ class GraphWidget(Gtk.DrawingArea): ...@@ -656,14 +656,10 @@ class GraphWidget(Gtk.DrawingArea):
self.queue_draw() self.queue_draw()
if self.drag_begin is None: if self.drag_begin is None:
self.drag_begin = [x, y] self.drag_begin = [x, y]
return True elif (event.button == 2 or
if (event.button == 2 or
(event.button == 1 and state & Gdk.ModifierType.CONTROL_MASK)): (event.button == 1 and state & Gdk.ModifierType.CONTROL_MASK)):
self.panning = (event.x, event.y) self.panning = (event.x, event.y)
return True elif event.button == 3:
if event.button == 3:
if isinstance(self.picked, PropertyMap): if isinstance(self.picked, PropertyMap):
self.picked = None self.picked = None
self.selected.fa = False self.selected.fa = False
...@@ -672,7 +668,6 @@ class GraphWidget(Gtk.DrawingArea): ...@@ -672,7 +668,6 @@ class GraphWidget(Gtk.DrawingArea):
self.picked = False self.picked = False
self.selected.fa = False self.selected.fa = False
self.queue_draw() self.queue_draw()
return True
def button_release_event(self, widget, event): def button_release_event(self, widget, event):
r"""Handle button release.""" r"""Handle button release."""
...@@ -710,13 +705,9 @@ class GraphWidget(Gtk.DrawingArea): ...@@ -710,13 +705,9 @@ class GraphWidget(Gtk.DrawingArea):
self.moved_picked = False self.moved_picked = False
self.regenerate_surface(timeout=100) self.regenerate_surface(timeout=100)
self.queue_draw() self.queue_draw()
elif event.button == 2:
return True
if event.button == 2:
self.panning = None self.panning = None
self.queue_draw() self.queue_draw()
return True
def motion_notify_event(self, widget, event): def motion_notify_event(self, widget, event):
r"""Handle pointer motion.""" r"""Handle pointer motion."""
...@@ -775,7 +766,6 @@ class GraphWidget(Gtk.DrawingArea): ...@@ -775,7 +766,6 @@ class GraphWidget(Gtk.DrawingArea):
self.queue_draw() self.queue_draw()
self.picked = v self.picked = v
self.selected[v] = True self.selected[v] = True
return True
def scroll_event(self, widget, event): def scroll_event(self, widget, event):
r"""Handle scrolling.""" r"""Handle scrolling."""
...@@ -845,21 +835,20 @@ class GraphWidget(Gtk.DrawingArea): ...@@ -845,21 +835,20 @@ class GraphWidget(Gtk.DrawingArea):
self.moved_picked = True self.moved_picked = True
self.queue_draw() self.queue_draw()
return True
def key_press_event(self, widget, event): def key_press_event(self, widget, event):
r"""Handle key press.""" r"""Handle key press."""
#print event.keyval #print event.keyval
if event.keyval == 114: if event.keyval == ord('r'):
self.fit_to_window() self.fit_to_window()
self.regenerate_surface(timeout=50) self.regenerate_surface(timeout=50)
self.queue_draw() self.queue_draw()
elif event.keyval == 115: elif event.keyval == ord('s'):
self.reset_layout() self.reset_layout()
elif event.keyval == 97: elif event.keyval == ord('a'):
self.apply_transform() self.apply_transform()
elif event.keyval == 112: elif event.keyval == ord('p'):
if self.picked == False: if self.picked == False:
self.init_picked() self.init_picked()
else: else:
...@@ -867,13 +856,12 @@ class GraphWidget(Gtk.DrawingArea): ...@@ -867,13 +856,12 @@ class GraphWidget(Gtk.DrawingArea):
self.selected.fa = False self.selected.fa = False
self.vertex_matrix = None self.vertex_matrix = None
self.queue_draw() self.queue_draw()
elif event.keyval == 0x7a: elif event.keyval == ord('z'):
if isinstance(self.picked, PropertyMap): if isinstance(self.picked, PropertyMap):
u = GraphView(self.g, vfilt=self.picked) u = GraphView(self.g, vfilt=self.picked)
self.fit_to_window(g=u) self.fit_to_window(g=u)
self.regenerate_surface(timeout=50) self.regenerate_surface(timeout=50)
self.queue_draw() self.queue_draw()
return True
def key_release_event(self, widget, event): def key_release_event(self, widget, event):
r"""Handle release event.""" r"""Handle release event."""
...@@ -883,12 +871,11 @@ class GraphWidget(Gtk.DrawingArea): ...@@ -883,12 +871,11 @@ class GraphWidget(Gtk.DrawingArea):
self.key_press_user_callback(self.g, event.keyval, self.picked, self.key_press_user_callback(self.g, event.keyval, self.picked,
self.pos, self.vprops, self.eprops) self.pos, self.vprops, self.eprops)
if event.keyval == 65507: if event.keyval == 65507: # Control_L
if self.moved_picked: if self.moved_picked:
self.moved_picked = False self.moved_picked = False
self.regenerate_surface(timeout=100) self.regenerate_surface(timeout=100)
self.queue_draw() self.queue_draw()
return True
class GraphWindow(Gtk.Window): class GraphWindow(Gtk.Window):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment