Changeset 3958


Ignore:
Timestamp:
Nov 9, 2006, 1:07:13 PM (18 years ago)
Author:
jack
Message:

Updated the visualisers to work with the new general_mesh structure.

Location:
anuga_core/source
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/examples/sww_file_visualiser_example.py

    r3873 r3958  
    1111
    1212# The argument to OfflineVisualiser is the path to a sww file
    13 o = OfflineVisualiser("../../swollen_viewer/tests/cylinders.sww")
     13o = OfflineVisualiser("../../anuga_viewer/tests/cylinders.sww")
    1414#o = OfflineVisualiser("../../../../anuga_validation/analytical solutions/circular_second_order.sww")
    1515
  • anuga_core/source/anuga/examples/visualise_rectangle.py

    r3918 r3958  
    3333        return self.h0 + self.h*((x>self.x0)&(x<self.x1)&(y>self.y0)&(y<self.y1))
    3434
    35 M = 10
     35M = 20
    3636points, vertices, boundary = rectangular(M, M, len1 = 1.0, len2 = 1.0)
    3737
     
    7979R = Reflective_boundary(domain)
    8080domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R} )
    81 domain.set_quantity('stage', Set_Stage(0.2, 0.4, 0.25, 0.75, 1.0, 0.00))
     81domain.set_quantity('stage', Set_Stage(0.2, 0.4, 0.25, 0.75, 2.0, 0.00))
    8282
    8383#-----------------------------------------------------------------
  • anuga_core/source/anuga/visualiser/realtime.py

    r3918 r3958  
    4545    def setup_grid(self):
    4646        self.vtk_cells = vtkCellArray()
     47        triangles = self.source.triangles
     48        N_tri = self.source.number_of_triangles
     49        verticies = self.source.get_vertex_coordinates()
     50        N_vert = len(verticies)
    4751        # Also build vert_index - a list of the x & y values of each vertex
    48         N_vert = len(self.source.vertex_coordinates)
    4952        self.vert_index = zeros((N_vert,2), Float)
    50         for n in range(N_vert):
     53        for n in range(N_tri):
    5154            self.vtk_cells.InsertNextCell(3)
    5255            for v in range(3):
    53                 self.vert_index[self.source.triangles[n][v]] = self.source.vertex_coordinates[n][v*2:v*2+2]
    54                 self.vtk_cells.InsertCellPoint(self.source.triangles[n][v])
     56                self.vert_index[triangles[n][v]] = verticies[n * 3 + v]
     57                self.vtk_cells.InsertCellPoint(triangles[n][v])
    5558
    5659    def update_height_quantity(self, quantityName, dynamic=True):
     
    118121
    119122    def redraw(self):
    120         print "Calling redraw"
    121123        if self.running and self.sync_unpaused.isSet():
    122124            self.sync_redrawReady.wait()
  • anuga_core/source/anuga/visualiser/visualiser-tvtk.py

    r3906 r3958  
    3030        self.vtk_polyData = {}
    3131
    32         # A function queue to ensure all the visualiser configuration is done in the visualiser thread.
    33         # The queue will contain zero or more functions, with the arguments to that function immediately following
    34         # as a tuple.
    35         self.sync_configFuncs = Queue(-1)
     32        # A list of operations to be performed on the cube axes. Type: [(func, (args))]
     33        self.conf_axesAlterations = []
     34        # A list of all polygons to overlay. Type: [([coords], height, (colour)]
     35        self.conf_overlaidPolygons = []
     36        # A list of alterations to be performed on the Tk root. Type: [(func, (args))]
     37        self.conf_tkAlterations = []
    3638
    3739    def run(self):
     
    4042        self.setup_grid()
    4143
    42         # Normally, empty() is not reliable, however all configuration is done
    43         # before the visualiser is started and nothing is added to the queue after that.
    44         while not self.sync_configFuncs.empty():
    45             func = self.sync_configFuncs.get(True)
    46             args = self.sync_configFuncs.get(True)
    47             func(*args)
     44        # Handle any deferred configuration
     45        # Overlaid polygons
     46        for args in self.conf_overlaidPolygons:
     47            self.overlay_polygon_internal(*args)
     48        # Draw (and maybe alter) the axes
     49        if self.vtk_drawAxes:
     50            self.vtk_axes = vtkCubeAxesActor2D()
     51            # Perform all of the alterations required, by applying func to the vtk_axes instance (with the given args).
     52            for func, args in self.conf_axesAlterations:
     53                func(*((self.vtk_axes,) + args))
     54        # Alter the Tk root as necessary.
     55        for func, args in self.conf_tkAlterations:
     56            func(*((self.tk_root,) + args))
     57        # Finished with deferred configuration.
    4858
    4959        # Draw Height Quantities
     
    5161            self.update_height_quantity(q, self.height_dynamic[q])
    5262            self.draw_height_quantity(q)
    53 
    54         if self.vtk_drawAxes is True:
    55             self.tk_root.after(1, self.draw_axes)
    5663           
    5764        self.tk_root.mainloop()
    5865
    59     def redraw_quantities(self, dynamic_only=False):
     66    def redraw_quantities(self):
    6067        """Redraw all dynamic quantities.
    6168        """
     
    7380        """Intstruct the visualiser to render cube axes around the render.
    7481        """
    75         self.sync_configFuncs.put(self._render_axes, True)
    76         self.sync_configFuncs.put(())
    77 
    78     def _render_axes(self):
    79         """Add the axes to the visualiser.
    80         """
    8182        self.vtk_drawAxes = True
    82         self.vtk_axes = vtkCubeAxesActor2D()
    8383
    8484    def draw_axes(self):
     
    9090            self.vtk_axes.SetCamera(self.vtk_renderer.GetActiveCamera())
    9191            self.vtk_renderer.AddActor(self.vtk_axes)
     92            self.vtk_renderer.ResetCamera(self.get_3d_bounds())
    9293       
    9394    def alter_axes(self, func, args):
     
    100101        alter_axes(vtkCubeAxesActor2D.SetNumberOfPoints, (5,))
    101102        """
    102         self.sync_configFuncs.put(self._alter_axes, True)
    103         self.sync_configFuncs.put((func,)+args, True)
    104 
    105     def _alter_axes(self, func, *args):
    106         """Apply func, with args *args to the axes actor. This function should be called from
    107         within the visualiser thread after the axes have been initialised.
    108         """
    109         func(*((self.vtk_axes,) + args))
     103        self.conf_axesAlterations.append((func, args))
    110104           
    111105    # --- Height Based Rendering --- #
     
    218212        colour is the colour of the polygon, as a 3-tuple representing
    219213        r, g, b values between 0 and 1."""
    220         self.sync_configFuncs.put(self._overlay_polygon, True)
    221         self.sync_configFuncs.put((coords, height, colour), True)
    222 
    223     def _overlay_polygon(self, coords, height, colour):
     214        self.conf_overlaidPolygons.append((coords, height, colour))
     215
     216    def overlay_polygon_internal(self, coords, height, colour):
    224217        """Add a polygon to the output of the visualiser.
    225218
     
    276269        """Apply func, with arguments tuple args to the root tk window for this visualiser.
    277270        """
    278         self.sync_configFuncs.put(self._alter_tkroot, True)
    279         self.sync_configFuncs.put((func,)+args, True)
    280 
    281     def _alter_tkroot(self, func, *args):
    282         """Apply func, with arguments tuple args to the root tk window for this visualiser.
    283         This function should only be called from within the visualiser after the tk root window
    284         has been created.
    285         """
    286         func(*((self.tk_root,) + args))
     271        self.conf_tkAlterations.append((func, args))
    287272
    288273    # --- GUI Events --- #
  • anuga_core/source/anuga/visualiser/visualiser.py

    r3873 r3958  
    3030        self.vtk_polyData = {}
    3131
    32         # A function queue to ensure all the visualiser configuration is done in the visualiser thread.
    33         # The queue will contain zero or more functions, with the arguments to that function immediately following
    34         # as a tuple.
    35         self.sync_configFuncs = Queue(-1)
     32        # A list of operations to be performed on the cube axes. Type: [(func, (args))]
     33        self.conf_axesAlterations = []
     34        # A list of all polygons to overlay. Type: [([coords], height, (colour)]
     35        self.conf_overlaidPolygons = []
     36        # A list of alterations to be performed on the Tk root. Type: [(func, (args))]
     37        self.conf_tkAlterations = []
    3638
    3739    def run(self):
     
    4042        self.setup_grid()
    4143
    42         # Normally, empty() is not reliable, however all configuration is done
    43         # before the visualiser is started and nothing is added to the queue after that.
    44         while not self.sync_configFuncs.empty():
    45             func = self.sync_configFuncs.get(True)
    46             args = self.sync_configFuncs.get(True)
    47             func(*args)
     44        # Handle any deferred configuration
     45        # Overlaid polygons
     46        for args in self.conf_overlaidPolygons:
     47            self.overlay_polygon_internal(*args)
     48        # Draw (and maybe alter) the axes
     49        if self.vtk_drawAxes:
     50            self.vtk_axes = vtkCubeAxesActor2D()
     51            # Perform all of the alterations required, by applying func to the vtk_axes instance (with the given args).
     52            for func, args in self.conf_axesAlterations:
     53                func(*((self.vtk_axes,) + args))
     54        # Alter the Tk root as necessary.
     55        for func, args in self.conf_tkAlterations:
     56            func(*((self.tk_root,) + args))
     57        # Finished with deferred configuration.
    4858
    4959        # Draw Height Quantities
     
    5161            self.update_height_quantity(q, self.height_dynamic[q])
    5262            self.draw_height_quantity(q)
    53 
    54         if self.vtk_drawAxes is True:
    55             self.tk_root.after(1, self.draw_axes)
    5663           
    5764        self.tk_root.mainloop()
    5865
    59     def redraw_quantities(self, dynamic_only=False):
     66    def redraw_quantities(self):
    6067        """Redraw all dynamic quantities.
    6168        """
     
    7380        """Intstruct the visualiser to render cube axes around the render.
    7481        """
    75         self.sync_configFuncs.put(self._render_axes, True)
    76         self.sync_configFuncs.put(())
    77 
    78     def _render_axes(self):
    79         """Add the axes to the visualiser.
    80         """
    8182        self.vtk_drawAxes = True
    82         self.vtk_axes = vtkCubeAxesActor2D()
    8383
    8484    def draw_axes(self):
     
    9090            self.vtk_axes.SetCamera(self.vtk_renderer.GetActiveCamera())
    9191            self.vtk_renderer.AddActor(self.vtk_axes)
     92            self.vtk_renderer.ResetCamera(self.get_3d_bounds())
    9293       
    9394    def alter_axes(self, func, args):
     
    100101        alter_axes(vtkCubeAxesActor2D.SetNumberOfPoints, (5,))
    101102        """
    102         self.sync_configFuncs.put(self._alter_axes, True)
    103         self.sync_configFuncs.put((func,)+args, True)
    104 
    105     def _alter_axes(self, func, *args):
    106         """Apply func, with args *args to the axes actor. This function should be called from
    107         within the visualiser thread after the axes have been initialised.
    108         """
    109         func(*((self.vtk_axes,) + args))
     103        self.conf_axesAlterations.append((func, args))
    110104           
    111105    # --- Height Based Rendering --- #
     
    218212        colour is the colour of the polygon, as a 3-tuple representing
    219213        r, g, b values between 0 and 1."""
    220         self.sync_configFuncs.put(self._overlay_polygon, True)
    221         self.sync_configFuncs.put((coords, height, colour), True)
    222 
    223     def _overlay_polygon(self, coords, height, colour):
     214        self.conf_overlaidPolygons.append((coords, height, colour))
     215
     216    def overlay_polygon_internal(self, coords, height, colour):
    224217        """Add a polygon to the output of the visualiser.
    225218
     
    276269        """Apply func, with arguments tuple args to the root tk window for this visualiser.
    277270        """
    278         self.sync_configFuncs.put(self._alter_tkroot, True)
    279         self.sync_configFuncs.put((func,)+args, True)
    280 
    281     def _alter_tkroot(self, func, *args):
    282         """Apply func, with arguments tuple args to the root tk window for this visualiser.
    283         This function should only be called from within the visualiser after the tk root window
    284         has been created.
    285         """
    286         func(*((self.tk_root,) + args))
     271        self.conf_tkAlterations.append((func, args))
    287272
    288273    # --- GUI Events --- #
Note: See TracChangeset for help on using the changeset viewer.