/[escript]/trunk/modellib/py_src/tsunami.py
ViewVC logotype

Diff of /trunk/modellib/py_src/tsunami.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 276 by cochrane, Wed Nov 30 04:31:40 2005 UTC revision 280 by cochrane, Wed Nov 30 06:23:59 2005 UTC
# Line 881  class SurfMovie(Model): Line 881  class SurfMovie(Model):
881                                   north=5.,                                   north=5.,
882                                   east=3.,                                   east=3.,
883                                   west=15.,                                   west=15.,
884                                     max_height=1.0,
885                                   filename="movie.mpg")                                   filename="movie.mpg")
886    
887             self.paramsFileString = "REFERENCE_FRAME DECODED\n"             self.paramsFileString = "REFERENCE_FRAME DECODED\n"
# Line 903  class SurfMovie(Model): Line 904  class SurfMovie(Model):
904    
905             self.firstFrame = True             self.firstFrame = True
906    
907         self.imageFiles = []             self.imageFiles = []
908    
909         def doInitialization(self):         def doInitialization(self):
910            """            """
# Line 917  class SurfMovie(Model): Line 918  class SurfMovie(Model):
918            # wndow(south,west,north,east)            # wndow(south,west,north,east)
919    
920            # the bathymmetry colourmap            # the bathymmetry colourmap
921        data = []            data = []
922        data.append([-8000, 0,   0,   0])            data.append([-8000, 0,   0,   0])
923        data.append([-7000, 0,   5,   25])            data.append([-7000, 0,   5,   25])
924        data.append([-6000, 0,   10,  50])            data.append([-6000, 0,   10,  50])
925        data.append([-5000, 0,   80,  125])            data.append([-5000, 0,   80,  125])
926        data.append([-4000, 0,   150, 200])            data.append([-4000, 0,   150, 200])
927        data.append([-3000, 86,  197, 184])            data.append([-3000, 86,  197, 184])
928        data.append([-2000, 172, 245, 168])            data.append([-2000, 172, 245, 168])
929        data.append([-1000, 211, 250, 211])            data.append([-1000, 211, 250, 211])
930        data.append([0,     16,  48,  16])            data.append([0,     16,  48,  16])
931        data.append([300,   70,  150, 50])            data.append([300,   70,  150, 50])
932        data.append([500,   146, 126, 60])            data.append([500,   146, 126, 60])
933        data.append([1000,  198, 178, 80])            data.append([1000,  198, 178, 80])
934        data.append([1250,  250, 230, 100])            data.append([1250,  250, 230, 100])
935        data.append([1500,  250, 234, 126])            data.append([1500,  250, 234, 126])
936        data.append([1750,  252, 238, 152])            data.append([1750,  252, 238, 152])
937        data.append([2000,  252, 243, 177])            data.append([2000,  252, 243, 177])
938        data.append([2250,  253, 249, 216])            data.append([2250,  253, 249, 216])
939        data.append([2500,  255, 255, 255])            data.append([2500,  255, 255, 255])
940    
941        # the amount to scale the data by            # the amount to scale the data by
942            scale = 255.0            scale = 255.0
943            numColours = len(data)            numColours = len(data)
944    
945        # convert the colourmap into something vtk is more happy with            # convert the colourmap into something vtk is more happy with
946            height = numarray.zeros(numColours, numarray.Float)            height = numarray.zeros(numColours, numarray.Float)
947            red = numarray.zeros(numColours, numarray.Float)            red = numarray.zeros(numColours, numarray.Float)
948            green = numarray.zeros(numColours, numarray.Float)            green = numarray.zeros(numColours, numarray.Float)
# Line 1002  class SurfMovie(Model): Line 1003  class SurfMovie(Model):
1003                  h += 1                  h += 1
1004                  transFunc.AddRGBPoint(h, red[i], green[i], blue[i])                  transFunc.AddRGBPoint(h, red[i], green[i], blue[i])
1005    
1006        # set up the lookup table for the wave data            # set up the lookup table for the wave data
1007        refLut = vtk.vtkLookupTable()            refLut = vtk.vtkLookupTable()
1008        self.lutTrans = vtk.vtkLookupTable()            self.lutTrans = vtk.vtkLookupTable()
1009        refLut.Build()            refLut.Build()
1010        alpha = 0.4   # alpha channel value            alpha = 0.7   # alpha channel value
1011        for i in range(256):            for i in range(256):
1012            (r,g,b,a) = refLut.GetTableValue(255-i)                (r,g,b,a) = refLut.GetTableValue(255-i)
1013            if g == 1.0 and b < 0.5 and r < 0.5:                if g == 1.0 and b < 0.5 and r < 0.5:
1014            self.lutTrans.SetTableValue(i, r, g, b, 0.0)                    self.lutTrans.SetTableValue(i, r, g, b, 0.0)
1015            else:                else:
1016            self.lutTrans.SetTableValue(i, r, g-0.2, b, alpha)                    self.lutTrans.SetTableValue(i, r, g-0.2, b, alpha)
1017    
1018            print "Generating the bathymmetry vtk object..."            print "Generating the bathymmetry vtk object..."
1019    
# Line 1064  class SurfMovie(Model): Line 1065  class SurfMovie(Model):
1065    
1066            self.ren.AddActor(bathActor)            self.ren.AddActor(bathActor)
1067    
1068        ### now add the coastline            ### now add the coastline
1069            print "Loading the coastline data..."            print "Loading the coastline data..."
1070    
1071        # make the coastline points            # make the coastline points
1072        coastPoints = vtk.vtkPoints()            coastPoints = vtk.vtkPoints()
1073    
1074        # make the coastline grid            # make the coastline grid
1075        coastGrid = vtk.vtkUnstructuredGrid()            coastGrid = vtk.vtkUnstructuredGrid()
1076    
1077        # now point the points and lines into the grid            # now point the points and lines into the grid
1078        totalCoastPoints = 0            totalCoastPoints = 0
1079        for polyline in self.coastline.polylines:            for polyline in self.coastline.polylines:
1080            numPoints = len(polyline)                numPoints = len(polyline)
1081            coastLine = vtk.vtkPolyLine()                coastLine = vtk.vtkPolyLine()
1082            coastLine.GetPointIds().SetNumberOfIds(numPoints)                coastLine.GetPointIds().SetNumberOfIds(numPoints)
1083            j = 0                j = 0
1084            for point in polyline:                for point in polyline:
1085            coastLine.GetPointIds().SetId(j, j+totalCoastPoints)                    coastLine.GetPointIds().SetId(j, j+totalCoastPoints)
1086            coastPoints.InsertNextPoint(point.long, point.lat, 0.0)                    coastPoints.InsertNextPoint(point.long, point.lat, 0.0)
1087            j += 1                    j += 1
1088            coastGrid.InsertNextCell(coastLine.GetCellType(),                coastGrid.InsertNextCell(coastLine.GetCellType(),
1089                coastLine.GetPointIds())                        coastLine.GetPointIds())
1090            totalCoastPoints += numPoints                totalCoastPoints += numPoints
1091    
1092        coastGrid.SetPoints(coastPoints)            coastGrid.SetPoints(coastPoints)
1093    
1094        # make the coast's mapper            # make the coast's mapper
1095        coastMapper = vtk.vtkDataSetMapper()            coastMapper = vtk.vtkDataSetMapper()
1096        coastMapper.SetInput(coastGrid)            coastMapper.SetInput(coastGrid)
1097    
1098        # make its actor            # make its actor
1099        coastActor = vtk.vtkActor()            coastActor = vtk.vtkActor()
1100        coastActor.SetMapper(coastMapper)            coastActor.SetMapper(coastMapper)
1101        coastActor.GetProperty().SetColor(0,0,0)            coastActor.GetProperty().SetColor(0,0,0)
1102    
1103        # add the actor to the renderer            # add the actor to the renderer
1104        self.ren.AddActor(coastActor)            self.ren.AddActor(coastActor)
1105    
1106            # set up the actor for the wave            # set up the actor for the wave
1107            self.waveActor = vtk.vtkActor()            self.waveActor = vtk.vtkActor()
# Line 1122  class SurfMovie(Model): Line 1123  class SurfMovie(Model):
1123               # vtkobj=...               # vtkobj=...
1124               # save(self.__frame_name)               # save(self.__frame_name)
1125    
1126           # make a reader for the data               # make a reader for the data
1127           waveReader = vtk.vtkXMLUnstructuredGridReader()               waveReader = vtk.vtkXMLUnstructuredGridReader()
1128           waveReader.SetFileName(self.__fn)               waveReader.SetFileName(self.__fn)
1129           waveReader.Update()               waveReader.Update()
1130    
1131               # make the grid               # make the grid
1132               waveGrid = waveReader.GetOutput()               waveGrid = waveReader.GetOutput()
1133           waveGrid.Update()               waveGrid.Update()
1134    
1135               (zMin, zMax) = waveGrid.GetPointData().GetScalars().GetRange()               (zMin, zMax) = waveGrid.GetPointData().GetScalars().GetRange()
1136               print "Wave height range %f - %f" % (zMin, zMax)               print "Wave height range %f - %f" % (zMin, zMax)
# Line 1137  class SurfMovie(Model): Line 1138  class SurfMovie(Model):
1138               # make a mapper for the grid               # make a mapper for the grid
1139               waveMapper = vtk.vtkDataSetMapper()               waveMapper = vtk.vtkDataSetMapper()
1140               waveMapper.SetInput(waveGrid)               waveMapper.SetInput(waveGrid)
1141           waveMapper.SetLookupTable(self.lutTrans)               waveMapper.SetLookupTable(self.lutTrans)
1142               waveMapper.SetScalarRange(zMin, zMax)               waveMapper.SetScalarRange(-self.max_height, self.max_height)
1143    
1144               self.waveActor.SetMapper(waveMapper)               self.waveActor.SetMapper(waveMapper)
1145    
# Line 1165  class SurfMovie(Model): Line 1166  class SurfMovie(Model):
1166               outWriter.Write()               outWriter.Write()
1167               print "Wrote %s" % imgFname               print "Wrote %s" % imgFname
1168    
1169           # helpful for debugging:               # helpful for debugging:
1170           #os.system("display %s" % imgFname)               #os.system("display %s" % imgFname)
1171    
1172               self.paramsFileString += "%s\n" % imgFname               self.paramsFileString += "%s\n" % imgFname
1173           self.imageFiles.append(imgFname)               self.imageFiles.append(imgFname)
1174    
1175               self.__next_t+=self.dt               self.__next_t+=self.dt
1176    
# Line 1205  class SurfMovie(Model): Line 1206  class SurfMovie(Model):
1206            if result != 0:            if result != 0:
1207                print "An error occurred in mpeg conversion"                print "An error occurred in mpeg conversion"
1208    
1209        # now clean up the image files            # now clean up the image files
1210        print "Removing temporary image files"            print "Removing temporary image files"
1211        os.unlink("%s.params" % self.filename)            os.unlink("%s.params" % self.filename)
1212        for fname in self.imageFiles:            for fname in self.imageFiles:
1213            os.unlink(fname)                os.unlink(fname)
1214    
1215  if __name__=="__main__":  if __name__=="__main__":
1216     from esys.escript.modelframe import Link,Simulation     from esys.escript.modelframe import Link,Simulation
# Line 1262  if __name__=="__main__": Line 1263  if __name__=="__main__":
1263     sm.t=Link(sq,"t")     sm.t=Link(sq,"t")
1264     sm.dt=5000.     sm.dt=5000.
1265     sm.filename="movie.mpg"     sm.filename="movie.mpg"
1266       sm.max_height=Link(src,"amplitude")
1267        
1268     s=Simulation([sq,oc,b,oreg,src,ts,sm])     s=Simulation([sq,oc,b,oreg,src,ts,sm])
1269     # s.writeXML()     # s.writeXML()

Legend:
Removed from v.276  
changed lines
  Added in v.280

  ViewVC Help
Powered by ViewVC 1.1.26