author Dmitriy Morozov Fri, 08 Jun 2012 15:40:09 -0700 branch dev changeset 266 38cf887cb139 parent 265 66a311c0d597 child 267 2f02384a4d9b
Display lists in ComplexViewer3D + circular.smooth() raises exceptions
```--- a/bindings/python/dionysus/circular/__init__.py	Thu Jun 07 21:36:53 2012 -0700
+++ b/bindings/python/dionysus/circular/__init__.py	Fri Jun 08 15:40:09 2012 -0700
@@ -26,8 +26,10 @@
[0     for zz in cocycle], (dimension, 1))

v1 = D * z
-    # print "D^2 is zero:", not bool(D*D)
-    # print "D*z is zero:", not bool(v1)
+    if bool(D*D):
+        raise Exception('D^2 is not 0')
+    if bool(v1):
+        raise Exception('Expect a cocycle as input')
z = matrix(z)

def Dfun(x,y,trans = 'N'):
@@ -48,7 +50,7 @@
# print sum(z_smooth**2)
# assert sum((D*z_smooth)**2) < tol and sum((D.T*z_smooth)**2) < tol, "Expected a harmonic cocycle"
if not (sum((D*z_smooth)**2) < tol and sum((D.T*z_smooth)**2) < tol):
-        print "Expected a harmonic cocycle:", sum((D*z_smooth)**2), sum((D.T*z_smooth)**2)
+        raise Exception("Expected a harmonic cocycle: %f %f" % (sum((D*z_smooth)**2), sum((D.T*z_smooth)**2)))

values = []
vertices = ((i,s) for (i,s) in enumerate(filtration) if s.dimension() == 0)```
```--- a/bindings/python/dionysus/viewer/__init__.py	Thu Jun 07 21:36:53 2012 -0700
+++ b/bindings/python/dionysus/viewer/__init__.py	Fri Jun 08 15:40:09 2012 -0700
@@ -1,16 +1,16 @@
from    diagram     import show_diagram as _show_diagram
-from    complex2d   import show_complex_2D
-from    complex3d   import show_complex_3D
+from    complex2d   import show_complex_2D as _show_complex_2D
+from    complex3d   import show_complex_3D as _show_complex_3D

from    PyQt4       import QtGui

_app = QtGui.QApplication([])

-def show_complex(points, complex = None, values = None):
+def show_complex(points, complex = None, values = None, **kwargs):
if len(points[0]) == 2:
-        show_complex_2D(points, complex, values, app = _app)
+        _show_complex_2D(points, complex, values, app = _app, **kwargs)
if len(points[0]) == 3:
-        show_complex_3D(points, complex, values, app = _app)
+        _show_complex_3D(points, complex, values, app = _app, **kwargs)

def show_diagram(dgm, noise = 0):
return _show_diagram(dgm, noise, _app)```
```--- a/bindings/python/dionysus/viewer/complex3d.py	Thu Jun 07 21:36:53 2012 -0700
+++ b/bindings/python/dionysus/viewer/complex3d.py	Fri Jun 08 15:40:09 2012 -0700
@@ -5,8 +5,9 @@
from    math        import sqrt

class ComplexViewer3D(PyGLWidget):
-    def __init__(self, points, complex = None, values = None):
+    def __init__(self, points, complex = None, values = None, point_size = 3.):
PyGLWidget.__init__(self)
+        self.point_size = point_size

self.points = points
if complex:
@@ -24,6 +25,8 @@
self.set_center(center)

+        self.make_display_list()
+
c = [0,0,0]
for p in self.points:
@@ -38,6 +41,12 @@

def paintGL(self):
PyGLWidget.paintGL(self)
+        glCallList(self.display_list)
+
+    def make_display_list(self):
+        self.display_list = glGenLists(1)
+        glNewList(self.display_list, GL_COMPILE)
+
self.complex.sort(lambda s1, s2: -cmp(s1.dimension(), s2.dimension()))
for s in self.complex:
vertices = [v for v in s.vertices]
@@ -45,7 +54,7 @@
p = self.points[vertices[0]]
v = self.values[vertices[0]]

-                glPointSize(3.0)
+                glPointSize(self.point_size)
c = self.colormap(v)
cr = float(c.red())/255
cg = float(c.green())/255
@@ -75,6 +84,7 @@
glVertex3f(p2[0],p2[1],p2[2])
glEnd()

+        glEndList()

def colormap(self, v):
if self.maxval <= self.minval:
@@ -86,9 +96,10 @@
return c

# TODO: cycle
-def show_complex_3D(points, complex = None, values = None, app = None):
+def show_complex_3D(points, complex = None, values = None, app = None, point_size = 3.):
+    print "Point size:", point_size
#app = QtGui.QApplication([])
-    view = ComplexViewer3D(points, complex, values)
+    view = ComplexViewer3D(points, complex, values, point_size)
view.show()
view.raise_()
app.exec_()```