~chaffra/fenics-viper/main

« back to all changes in this revision

Viewing changes to src/viper/viper.py

  • Committer: Chaffra Affouda
  • Date: 2012-02-13 21:11:42 UTC
  • mfrom: (192.2.10 fenics-viper)
  • Revision ID: chaffra@gmail.com-20120213211142-vv05ch2t5tqza2ff
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
 
3
 
__copyright__ = "(C) 2006-2009 Ola Skavhaug and Simula Research Laboratory"
4
 
__license__   = "GNU LGPL Version 2.1."
 
3
# Copyright (C) 2006-2011 Ola Skavhaug and Simula Research Laboratory
 
4
#
 
5
# This file is part of Viper.
 
6
#
 
7
# Viper is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU Lesser General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# Viper is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
# GNU Lesser General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU Lesser General Public License
 
18
# along with Viper. If not, see <http://www.gnu.org/licenses/>.
 
19
 
5
20
__cite__      = """Ola Skavhaug, Viper Visualization Software,
6
21
http://www.fenics.org/wiki/viper/"""
7
 
__version__ = "0.4.7"
 
22
__version__ = "1.0.0"
8
23
 
9
24
r"""
10
25
Viper
703
718
                    self.vtkgrid.GetCellData().SetScalars(self.darr)
704
719
 
705
720
        if self.rescale and not self.mode == "scalar_xy":
706
 
            self.show_scalarbar()
707
 
            self.rescaleColors(self.x.min(), self.x.max())
 
721
            if self.mode == "vector":
 
722
                norms = [numpy.linalg.norm(v) for v in self.x]
 
723
                vmin, vmax = min(norms), max(norms)
 
724
            else:
 
725
                vmin, vmax = self.x.min(), self.x.max()
 
726
            self.rescaleColors(vmin, vmax)
708
727
        self.renWin.Render()
709
728
 
710
729
        # Set the window title after the window is actually created to
736
755
        mapper = self.vector_actors[idx].GetMapper()
737
756
        if mapper is not None:
738
757
            _update_range(dmin, dmax, mapper)
 
758
        self.show_scalarbar()
739
759
 
740
760
    def _add_arrow(self, vectors):
741
761
        tipradius = self.args.get("arrow_tip_radius", 0.15)
833
853
            renWin.SetSize(*self.window_size)
834
854
        return ren, renWin
835
855
 
836
 
    def compute_vector_scale(self, x, scale=2.0):
 
856
    def compute_vector_scale(self, x, scale=2.0, vmax=None):
837
857
        n,d = x.shape
838
 
        norms = [numpy.linalg.norm(v) for v in x]
839
 
        vmin, vmax = min(norms), max(norms)
840
 
        if abs(vmax) < 1e-16:
841
 
            vmax = 1.0
 
858
        if vmax is None:
 
859
            norms = [numpy.linalg.norm(v) for v in x]
 
860
            vmin, vmax = min(norms), max(norms)
 
861
            if abs(vmax) < 1e-16:
 
862
                vmax = 1.0
842
863
        return scale/vmax*self.__D/(n**(1.0/d))
843
864
 
844
865
 
853
874
        self.__D = math.sqrt(reduce(operator.add,[(a[i]-a[i-1])**2 for i in xrange(1,6,2)]))
854
875
 
855
876
        # Resolve scale factor:
856
 
        vectors.SetScaleFactor(self.compute_vector_scale(x, scale=sf))
 
877
        if self.rescale:
 
878
            vectors.SetScaleFactor(self.compute_vector_scale(x, scale=sf))
 
879
        else:
 
880
            vectors.SetScaleFactor(self.compute_vector_scale(x, scale=sf, vmax=vmax))
857
881
        self.vectors = vectors
858
882
 
859
883
        if self.ren is None:
1330
1354
            
1331
1355
        return xyplot
1332
1356
 
 
1357
#        # set up the renderer
 
1358
#        ren = vtk.vtkRenderer()
 
1359
#        ren.SetBackground(1,1,1)
 
1360
#        ren.AddActor(xyplot)
 
1361
#
 
1362
#        renWin = vtk.vtkRenderWindow()
 
1363
#        renWin.AddRenderer(ren)
 
1364
#        renWin.SetSize(*self.window_size)
 
1365
#
 
1366
#        # interaction
 
1367
#        iren = vtk.vtkRenderWindowInteractor()
 
1368
#        iren.SetRenderWindow(renWin)
 
1369
#
 
1370
#        return iren, renWin, ren
 
1371
 
1333
1372
    def add_sphere(self, pt, rad, thera_res=8, phi_res=6, color=(0,0,0)):
1334
1373
        """Add a sphere at point pt, with radius rad."""
1335
1374
        sphere = vtk.vtkSphereSource()