Added multiplier to filenames + spheres filename recognition
authorDmitriy Morozov <dmitriy@mrzv.org>
Tue, 26 Jul 2011 13:57:48 -0700
changeset 19 c1c2dda0c427
parent 18 7d5e8fdf69f2
child 20 0b7b52941b22
Added multiplier to filenames + spheres filename recognition
PyVEFViewer.py
VEFViewer.py
edges.py
points.py
spheres.py
triangles.py
--- a/PyVEFViewer.py	Tue Jun 21 16:48:36 2011 -0700
+++ b/PyVEFViewer.py	Tue Jul 26 13:57:48 2011 -0700
@@ -119,13 +119,14 @@
             self.model_list.addItem(Spheres(sph, self.model_list))
 
     def read_from_extension(self, fn):
-        if   ext(fn) == '.vrt' or ext(fn) == '.pts':
+        fn0 = fn.split(':')[0]
+        if   ext(fn0) == '.vrt' or ext(fn0) == '.pts':
             self.read_points([fn])
-        elif ext(fn) == '.edg':
+        elif ext(fn0) == '.edg':
             self.read_edges([fn])
-        elif ext(fn) == '.stl':
+        elif ext(fn0) == '.stl':
             self.read_triangles([fn])
-        elif ext(fn) == '.sph':
+        elif ext(fn0) == '.sph':
             self.read_spheres([fn])
         else:
             return False
--- a/VEFViewer.py	Tue Jun 21 16:48:36 2011 -0700
+++ b/VEFViewer.py	Tue Jul 26 13:57:48 2011 -0700
@@ -11,14 +11,18 @@
         self.ui = ui.Ui_MainWindow()
         self.ui.setupUi(self)
 
+# TODO: add completer for filenames
 @command(usage = '%name [options]',
-         options = [('p', 'points',    [], 'files with points'),       # TODO: add completer for filenames
-                    ('e', 'edges',     [], 'files with edges'),
-                    ('t', 'triangles', [], 'files with triangles')])
+         options = [('p', 'points',    [], 'files with points (vrt or pts)'),
+                    ('e', 'edges',     [], 'files with edges (edg)'),
+                    ('t', 'triangles', [], 'files with triangles (stl)'),
+                    ('s', 'spheres',   [], 'files with spheres (sph)')])
 def main(*args, **opts):
+    """Visualize points, edges, or triangles in the given files. Appending :MULT to the filename multiplies the positions in that file by MULT."""
     points    = opts['points']
     edges     = opts['edges']
     triangles = opts['triangles']
+    spheres   = opts['spheres']
 
     qapp = ui.QtGui.QApplication([])
     win  = VEFViewerWindow()
@@ -28,6 +32,7 @@
     win.ui.viewer.read_points(points)
     win.ui.viewer.read_edges(edges)
     win.ui.viewer.read_triangles(triangles)
+    win.ui.viewer.read_spheres(spheres)
     # Guess types from extensions
     for fn in args:
         if not win.ui.viewer.read_from_extension(fn):
--- a/edges.py	Tue Jun 21 16:48:36 2011 -0700
+++ b/edges.py	Tue Jul 26 13:57:48 2011 -0700
@@ -13,6 +13,9 @@
 
 class Edges(ViewerItem):
     def __init__(self, filename, parent = None):
+        filename = filename.split(':')
+        self.mult = float(filename[1]) if len(filename) > 1 else 1.
+        filename = filename[0]
         super(Edges, self).__init__(basename(filename), parent, color = (0,0,255))
 
         self.read_edges(filename)
@@ -90,7 +93,7 @@
     def read_edges(self, filename):
         self.edges = []
         for block in line_blocks(filename, 2):
-            u = Point(map(float, block[0].split()))
-            v = Point(map(float, block[1].split()))
+            u = Point(map(float, block[0].split()))*self.mult
+            v = Point(map(float, block[1].split()))*self.mult
             self.edges.append((u,v))
 
--- a/points.py	Tue Jun 21 16:48:36 2011 -0700
+++ b/points.py	Tue Jul 26 13:57:48 2011 -0700
@@ -20,6 +20,17 @@
         self.z += p.z
         return self
 
+    def __imul__(self, s):
+        self.x *= s
+        self.y *= s
+        self.z *= s
+        return self
+
+    def __mul__(self, s):
+        p = Point([self.x, self.y, self.z])
+        p *= s
+        return p
+
     def __idiv__(self, s):
         self.x /= s
         self.y /= s
@@ -38,11 +49,14 @@
 
 class Points(ViewerItem):
     def __init__(self, filename, parent = None):
+        filename = filename.split(':')
+        self.mult = float(filename[1]) if len(filename) > 1 else 1.
+        filename = filename[0]
         super(Points, self).__init__(basename(filename), parent, (255,0,255))
 
         self.points = []
         for block in line_blocks(filename):
-            self.points.append(Point(map(float, block[0].split())))
+            self.points.append(Point(map(float, block[0].split()))*self.mult)
         self.create_display_list()
         self.center, self.min, self.max = centerMinMax(self.points)
 
--- a/spheres.py	Tue Jun 21 16:48:36 2011 -0700
+++ b/spheres.py	Tue Jul 26 13:57:48 2011 -0700
@@ -12,6 +12,9 @@
 
 class Spheres(ViewerItem):
     def __init__(self, filename, parent = None):
+        filename = filename.split(':')
+        self.mult = float(filename[1]) if len(filename) > 1 else 1.
+        filename = filename[0]
         super(Spheres, self).__init__(basename(filename), parent, color = (0,0,255))
 
         self.read_spheres(filename)
@@ -78,6 +81,6 @@
         self.spheres = []
         for block in line_blocks(filename, 1):
             block = block[0].split()
-            c = Point(map(float, block[:3]))
-            r = float(block[3])
+            c = Point(map(float, block[:3]))*self.mult
+            r = float(block[3])*self.mult
             self.spheres.append((c,r))
--- a/triangles.py	Tue Jun 21 16:48:36 2011 -0700
+++ b/triangles.py	Tue Jul 26 13:57:48 2011 -0700
@@ -10,6 +10,9 @@
 
 class Triangles(ViewerItem):
     def __init__(self, filename, parent = None):
+        filename = filename.split(':')
+        self.mult = float(filename[1]) if len(filename) > 1 else 1.
+        filename = filename[0]
         super(Triangles, self).__init__(basename(filename), parent, color = (200,200,200))
 
         self.read_triangles(filename)
@@ -85,7 +88,7 @@
     def read_triangles(self, filename):
         self.triangles = []
         for block in line_blocks(filename, 7):
-            u = Point(map(float, block[2].split()[1:4]))
-            v = Point(map(float, block[3].split()[1:4]))
-            w = Point(map(float, block[4].split()[1:4]))
+            u = Point(map(float, block[2].split()[1:4]))*self.mult
+            v = Point(map(float, block[3].split()[1:4]))*self.mult
+            w = Point(map(float, block[4].split()[1:4]))*self.mult
             self.triangles.append((u,v,w))