Added pan + zoom to diagram viewer; show_diagram() didn't return; added PyQt, PyOpenGL, NumPy as dependencies in the docs
--- a/bindings/python/dionysus/viewer/__init__.py Thu Jun 07 10:52:15 2012 -0700
+++ b/bindings/python/dionysus/viewer/__init__.py Thu Jun 07 11:57:33 2012 -0700
@@ -11,7 +11,6 @@
show_complex_2D(points, complex, values, app = _app)
if len(points[0]) == 3:
show_complex_3D(points, complex, values, app = _app)
- #_app.exec_()
def show_diagram(dgm):
- _show_diagram(dgm, _app)
+ return _show_diagram(dgm, _app)
--- a/bindings/python/dionysus/viewer/diagram.py Thu Jun 07 10:52:15 2012 -0700
+++ b/bindings/python/dionysus/viewer/diagram.py Thu Jun 07 11:57:33 2012 -0700
@@ -16,6 +16,7 @@
super(QtGui.QGraphicsView, self).__init__()
self.selection = None
+ self._pan = False
self.setRenderHint(QtGui.QPainter.Antialiasing)
self.scene = QtGui.QGraphicsScene(self)
@@ -27,7 +28,7 @@
maxx = max(p[0] for p in dgm if p[0] != inf)
maxy = max(p[1] for p in dgm if p[1] != inf)
- radius = max(.005, min(maxx - minx, maxy - miny)/200)
+ radius = max(.005, min(maxx - minx, maxy - miny)/500)
border = 25
self.scene.setSceneRect(minx - border*radius, miny - border*radius, (maxx - minx) + 2*border*radius, (maxy - miny) + 2*border*radius)
@@ -40,19 +41,48 @@
self.scene.addItem(item)
# Flip y-axis
- self.scale(1,-1)
+ self.scale(1, -1)
# Set the correct view
rect = self.scene.itemsBoundingRect()
self.fitInView(rect, QtCore.Qt.KeepAspectRatio)
def mousePressEvent(self, event):
- p = self.mapToScene(event.pos())
- item = self.scene.itemAt(p)
- if isinstance(item, DiagramPoint):
- #item.color()
- self.selection = item.p
- self.close()
+ if event.button() == QtCore.Qt.RightButton:
+ self._pan = True
+ self._panStartX = event.x()
+ self._panStartY = event.y()
+ self.setCursor(QtCore.Qt.ClosedHandCursor)
+ event.accept()
+ else:
+ p = self.mapToScene(event.pos())
+ item = self.scene.itemAt(p)
+ if isinstance(item, DiagramPoint):
+ item.color()
+ self.selection = item.p
+ self.close()
+
+ def mouseReleaseEvent(self, event):
+ if event.button() == QtCore.Qt.RightButton:
+ self._pan = False
+ self.setCursor(QtCore.Qt.ArrowCursor)
+ event.accept()
+ return
+ event.ignore()
+
+ def mouseMoveEvent(self, event):
+ if self._pan:
+ self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - (event.x() - self._panStartX))
+ self.verticalScrollBar().setValue(self.verticalScrollBar().value() - (event.y() - self._panStartY))
+ self._panStartX = event.x()
+ self._panStartY = event.y()
+ event.accept()
+ return
+ event.ignore()
+
+ def wheelEvent(self, event):
+ delta = 1 + float(event.delta())/100
+ self.scale(delta, delta)
def draw_axes(self, minx, miny, maxx, maxy):
# Draw axes and diagonal
@@ -70,11 +100,11 @@
# Dashed, gray integer lattice
pen = QtGui.QPen(QtCore.Qt.DashLine)
pen.setColor(QtCore.Qt.gray)
- for i in xrange(int(minx) + 1, int(maxx) + 1):
+ for i in xrange(min(0, int(minx)) + 1, max(0,int(maxx)) + 1):
line = QtGui.QGraphicsLineItem(i,0, i, maxy)
line.setPen(pen)
self.scene.addItem(line)
- for i in xrange(int(miny) + 1, int(maxy) + 1):
+ for i in xrange(min(0, int(miny)) + 1, max(0, int(maxy)) + 1):
line = QtGui.QGraphicsLineItem(0,i, maxx, i)
line.setPen(pen)
self.scene.addItem(line)
--- a/doc/get-build-install.rst Thu Jun 07 10:52:15 2012 -0700
+++ b/doc/get-build-install.rst Thu Jun 07 11:57:33 2012 -0700
@@ -3,8 +3,8 @@
Get, Build, Install
===================
-The most up to date code is available from
-`my Mercurial repository`_.
+The most up to date code is available from
+`my Mercurial repository`_.
If you have Mercurial_, the easiest way to obtain the code is by cloning it:
.. parsed-literal::
@@ -41,6 +41,8 @@
:CGAL_: for alpha shapes (version :math:`\geq` 3.4)
:CVXOPT_: for :ref:`circle-valued parametrization <cohomology-parametrization>` using LSQR
+ :PyQt4_: for :mod:`viewer` module
+ :PyOpenGL_, NumPy_: for 3D visualization in :mod:`viewer` module
:PyX_: :sfile:`tools/draw-diagram/draw.py` uses `PyX`_ to
produce a PDF of the diagram
:rlog_: used for logging only (not needed by default)
@@ -52,8 +54,11 @@
.. _CMake: http://www.cmake.org
.. _Boost: http://www.boost.org
.. _CGAL: http://www.cgal.org
-.. _CVXOPT: http://abel.ee.ucla.edu/cvxopt/
-.. _PyX: http://pyx.sourceforge.net/
+.. _CVXOPT: http://abel.ee.ucla.edu/cvxopt/
+.. _PyQt4: http://www.riverbankcomputing.co.uk/software/pyqt/intro
+.. _PyOpenGL: http://pyopengl.sourceforge.net/
+.. _NumPy: http://numpy.scipy.org/
+.. _PyX: http://pyx.sourceforge.net/
.. _rlog: http://www.arg0.net/rlog
.. _dsrpdb: http://www.salilab.org/~drussel/pdb/
.. _SYNAPS: http://www-sop.inria.fr/galaad/synaps/