def run(): # not really working #sys.stdout = open( "output/%s.stdout" % mpi.rank, "w" ) #sys.stderr = open( "output/%s.stderr" % mpi.rank, "w" ) #debugFile.openfile("output/%s" % mpi.rank, "w") # of = open( "output/%s" % mpi.rank, "w" ) #debugFile.write("begin\n") #debugFile.flush() #debugFile.write("%s\n"% sys.argv ) #debugFile.flush() global tileConfig print "args:", sys.argv #streamProtocol = StreamProtocols.FLX_H261 streamProtocol = StreamProtocols.CELERITAS_TCP_RAW # Parse options: parser = OptionParser() parser.add_option("-c", "--config", dest="config", default=None, help="Specify a tiled display config file.") parser.add_option("", "--loadAllMovieTiles", action="store_true", dest="loadAllMovieTiles", default=False, help="Have all tiles load all movie tiles so movie can be dragged around.") parser.add_option("", "--allowFrameSkip", action="store_false", dest="allowFrameSkip", default=True, help="Allow movies to skip frames (automatic with --loadAllTiles).") parser.add_option("--stream", action="append", dest="stream", default=None, help="Specify a stream to receive.") parser.add_option("--groupedStream", action="append", dest="groupedStream", default=None, help="Specify a stream to receive.") parser.add_option("--hostnames", dest="hostnames", default=None, help="Force list of hostnames/confignames. mpi id used to index the list.") parser.add_option("--streamColsRows", dest="streamColsRows", default=None, help="Specify columns and rows for streams (in one/each network location).") parser.add_option("--streamGroupsColsRows", dest="streamGroupsColsRows", default=None, help="Specify columns and rows for network locations.") parser.add_option("--scale", dest="movieScale", default=None, help="Specify scale for movie playback.") parser.add_option("--sequence", action="append", dest="sequences", default=None, help="Specify sequence of movies. (comma separated)") parser.add_option("--plant", dest="plant", action="store_true", default=False, help="Plant a stream so it can't move (allows streaming optimizations).") parser.add_option("--streamSize", action="append", dest="streamSize", default=None, help="Specify a stream size.") parser.add_option("--pos", action="append", dest="positions", default=None, help="Specify an object position.") parser.add_option("--layout", action="append", dest="layouts", default=None, help="Specify layout of objects.") parser.add_option("--movieLayout", action="append", dest="movieLayouts", default=None, help="Specify layout of tiles in a movie.") parser.add_option("--inputhost", dest="inputHost", default="localhost", help="Airstream server hostname.") parser.add_option("--inputport", dest="inputPort", default=11000, help="Airstream server port.") #parser.add_option("--streamRects", action="append", dest="streamRects", # default=None, # help="Specify streamRects.") options, sysArgs = parser.parse_args() allowFrameSkip=False if options.allowFrameSkip or options.loadAllMovieTiles: allowFrameSkip = True movieScale = None if options.movieScale != None: movieScale = options.movieScale.split("x")[:2] if len(movieScale) < 2: raise Exception("--scale option should be in this format: --scale=2.0x2.0") movieScale = float(movieScale[0]), float(movieScale[1]) movieSequences = [] if options.sequences != None: for sequence in options.sequences: paths = sequence.split(",") movieSequences.append(paths) if options.streamColsRows != None: options.streamColsRows = options.streamColsRows.split("x") options.streamColsRows = [ int(i) for i in options.streamColsRows ] if len(options.streamColsRows) < 2: raise Exception("--streamColsRows needs to be in the format \"3x2\"") #print "COLS ROWS:", options.streamColsRows, type(options.streamColsRows[0]) #raise if options.streamGroupsColsRows != None: options.streamGroupsColsRows = options.streamGroupsColsRows.split("x") options.streamGroupsColsRows = [ int(i) for i in options.streamGroupsColsRows ] if len(options.streamGroupsColsRows) < 2: raise Exception("--streamGroupsColsRows needs to be in the format \"3x2\"") if options.streamSize != None: tmp = [] for pair in options.streamSize: if len(pair.split("x")) != 2: raise Exception("--streamSize needs to be in the format \"600x400\" or \"600x400\",\"500x300\"") x,y = pair.split("x") tmp.append( (int(x),int(y)) ) options.streamSize = tmp if options.positions != None: tmp = [] for p in options.positions: if len(p.split("x")) != 2: raise Exception("--pos needs to be in the format \"100x200\" or \"200x300\",\"100x300\"") x,y = p.split("x") tmp.append( (int(x),int(y)) ) options.positions = tmp global gPositionsIndex gPositionsIndex = 0 if (gFlxStreamingSupported and not gCeleritasStreamingSupported): options.streamSizes = [(352,288)] # H.261 for now. print dir(options), type(options), options.__class__ if hasattr(options, "config") and getattr(options, "config"): from configLoader import LoadConfigPy tileConfig = LoadConfigPy(getattr(options,"config")) else: raise Exception("Please specify the config file on the cmd-line with -c") # Older method: #if mpi.procs == 2: # tileConfig = CreateLocal2TestConfig() #else: # tileConfig = CreateLocalTestConfig() # SaveConfig(tileConfig, "amConfigTmp.txt") # tileConfig = LoadConfig("amConfigTmp.txt") # important to load from file so all nodes have the same tileIds. setupLocalConfig(tileConfig, options) print gethostname(), machineDesc.hostname, localRects, absoluteRects #rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] #rects = [Rect(0,0,1280,1024)] if len(localWindows) == 0: os.environ["DISPLAY"] = ":0.0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 print "POSA:", os.environ['SDL_VIDEO_WINDOW_POS'] else: # There is currently only one "localWindow" per process. # All tiles are within the same localWindow. We can get get # this window simply from any tile's config for a machine. os.environ["DISPLAY"] = localWindows[0].getDisplayStr() print "Local windows offset:", localWindows[0].getOffset() os.environ['SDL_VIDEO_WINDOW_POS'] = "%s,%s" % (localWindows[0].getOffset()) print "POS:", os.environ['SDL_VIDEO_WINDOW_POS'] windowWidth = localWindows[0].rect.width windowHeight = localWindows[0].rect.height # print gethostname(), mpi.rank, "DISPLAY SIZE:", windowWidth, windowHeight fullRightBoundary = fullRect.width #imageFilename = sys.argv[1] app = App(windowWidth, windowHeight) # app state contains a few things such as the exitFlag that # will be synced from the master state. app.state=AppState() app.state.exitNextFrame = False visualsManager = VisualsManager() ### Setup Renderers renderers = [] for i in range(len(localRects)): displayRect = localRects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) #renderer.addFrameSetupObj(ScreenClearer(color=(.9, .4, .4), clearDepth=False)) renderer.addFrameSetupObj(ScreenClearer(color=(.0, .0, .0), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) #renderer.addFrameSetupObj(ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderer.addFrameSetupObj(ScreenClearer(color=(.0, .0, .0), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) app.initialize(windowBorder=False) #app.initialize(windowBorder=True) pygame.mouse.set_visible(False) for i in range(len(localRects)): print "SETTING RECT:", localRects[i] renderers[i].init(app.width, app.height, viewportRect=localRects[i]) visualsManager.setRenderers(renderers) #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) masterObjects = [] objectsListList = [] # first object in each tuple on master node is source for all others #for i in range(len(renderers)): def CreateObj(imageFilename, imagePos=(2000,500), obj=None, scale=None, objDesc=None, gridColsRows=None, netGridColsRows=None, plant=False): if None == objDesc: objDesc = ObjDesc(ObjType.UNSPECIFIED) boxes = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] if obj == None: if objDesc.type == ObjType.STREAM: #box = CreateTileDisplayStreamObject(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, blend=True, scale=scale) box = CreateGroupTileDisplayStreamObject(imageFilename, objDesc, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, blend=True, scale=scale, gridColsRows=gridColsRows) elif objDesc.type == ObjType.GROUPED_STREAM: try: box = CreateMultiNetGroupTileDisplayStreamObject(imageFilename, objDesc, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, blend=True, scale=scale, gridColsRows=gridColsRows, netGridColsRows=netGridColsRows, plant=plant ) except: traceback.print_exc() sys.exit() elif objDesc.type == ObjType.TILED_MOVIE_WITH_LAYOUT: try: box = CreateTiledMovieObjectFromLayout(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, loadAllMovieTiles=options.loadAllMovieTiles, scale=scale, allowFrameSkip=allowFrameSkip) except: import traceback traceback.print_exc() sys.exit() else: # objDesc.type.UNSPECIFIED #box = glTxtrBox(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), imagePos=imagePos, absRect= absRect, fullRect=fullRect, blend=True) box = CreateTileDisplayObject(imageFilename, screenRect=Rect(0,0,locRect.width, locRect.height), pos=imagePos, absRect= absRect, fullRect=fullRect, blend=True, loadAllMovieTiles=options.loadAllMovieTiles, scale=scale, allowFrameSkip=allowFrameSkip) else: box = obj # to scale, change the geometry and the txtr coords: imageSize and #box.imageSize = (box.imageSize[0]*2, box.imageSize[1]*2) #box.easyTexture.zoom(5,1) #box.easyTexture.setOffset( (absRect.x % float(box.easyTexture.getWidth())) / box.easyTexture.getWidth(), # (absRect.y % float(box.easyTexture.getHeight())) / box.easyTexture.getHeight() ) # box.easyTexture.setWidth( float(locRect.width) / float(box.easyTexture.getHeight()) ) #zoom = (0.5,1) #box.easyTexture.setZoom(zoom[0], zoom[1]) #box.easyTexture.setOffset(absRect.x * zoom[0] ,absRect.y * zoom[1]) #box.easyTexture.setZoom(float(box.easyTexture.getWidth()) / localRect.width, # float(box.easyTexture.getHeight()) / localRect.height ) # scale offset back by zoom (offset is between 0 and 1) #box.easyTexture.setOffset( float(rect.x) / fullRect.width * box.easyTexture.getWidth(), # float(rect.y) / fullRect.height * box.easyTexture.getHeight()) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) boxes.append(box) if i == 0 and mpi.rank == 0: masterObjects.append(box) if objDesc.type==ObjType.STREAM: # setup network reception for one machine if StreamProtocols.FLX_H261 == streamProtocol: from streamView import StreamView, StartStreamViewLoop, StreamState elif StreamProtocols.CELERITAS_TCP_RAW == streamProtocol: from streamViewCeleritas import StreamView, StartStreamViewLoop, StreamState else: raise Exception("Unhandled stream format: %s" % streamProtocol) numStreamStates = boxes[0].getNumStreams() streamStateList = [] for i in range(numStreamStates): streamState = StreamState() streamState.printInterval = 0 # disable extra prints for now streamStateList.append(streamState) def nop(nameList): pass #streamStateList = [streamState] address = imageFilename if StreamProtocols.FLX_H261 == streamProtocol: StartStreamViewLoop(address, streamStateList, [ x.reorder for x in boxes ]) #call reorder on each group stream obj else: # CELERITAS_RAW_TCP for now address, streamPort = address.split("/") streamPort = int(streamPort) StartStreamViewLoop(address, streamPort, objDesc.streamWidth, objDesc.streamHeight, streamStateList, [ x.reorder for x in boxes ]) #call reorder on each group stream obj for box in boxes: # add the gui objects for each display on the machine. box.setStreamState(streamStateList) elif objDesc.type==ObjType.GROUPED_STREAM: # setup network reception for one machine if StreamProtocols.FLX_H261 == streamProtocol: from streamView import StreamView, StartStreamViewLoop, StreamState elif StreamProtocols.CELERITAS_TCP_RAW == streamProtocol: from streamViewCeleritas import StreamView, StartStreamViewLoop, StreamState else: raise Exception("Unhandled stream format: %s" % streamProtocol) # Want to avoid creating duplicate streamStates for the same address # keep a dict of address -> streamState print "ADDRESS:", imageFilename addressStateDict = {} # address: streamStateList addressReorderCallbacks = {} # address: [callbacks] for box in boxes: # add the gui objects for each display on the machine. for child in box.getChildren(): #box is a GroupObject holding GroupTiledStreamObject # creating stream states for children if isinstance(child, GroupTiledStreamObject): numStreamStatesForChild = child.getNumStreams() # num streams per net conn. if child.address not in addressStateDict: streamStateList = [] for i in range(numStreamStatesForChild): streamState = StreamState() streamState.printInterval = 0 # disable extra prints for now streamStateList.append(streamState) def nop(nameList): pass # store streamStateList for network address addressStateDict[child.address] = streamStateList if child.address not in addressReorderCallbacks: addressReorderCallbacks[child.address] = [] else: streamStateList = addressStateDict[child.address] # store reorder callback for this object addressReorderCallbacks[child.address].append(child.reorder) #else: # pass # Null placeholder object, don't setup a stream #for address,streamStateList in addressStateDict.items(): for address in imageFilename: # import to iterate through addresses in this order if address in addressStateDict: streamStateList = addressStateDict[address] reorderCallbacks = addressReorderCallbacks[address] print "***** STARTING:|%s|"% address, type(address) #time.sleep(0.1) # FIXME, intead, need add a "ready" callback from # pyRTP once thread is setup. #time.sleep(0.1) address, streamPort = address.split("/") streamPort = int(streamPort) StartStreamViewLoop(address, streamPort, objDesc.streamWidth, objDesc.streamHeight, streamStateList, reorderCallbacks) #call reorder on each group stream obj for box in boxes: for child in box.getChildren(): if isinstance(child, GroupTiledStreamObject): streamStateList = addressStateDict[child.address] child.setStreamState(streamStateList) print "CREATED OBJS:", len(boxes), boxes return boxes """ obj = CreateObj(imageFilename, (0,0)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20071116/B/Screenshot-VL3 Application-B0250.png", imagePos=(3200,400)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20071116/A/Screenshot-VL3 Application-600.png", imagePos=(800,1700)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20070123/vl3_20070123_142002.png", imagePos=(100,800)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20061109/vl3_20061109_161226.png", imagePos=(4500,2000)) objectsListList.append(obj) obj = CreateObj("/home/eolson/public_html/vl3/20080402paper/vl3_nodes.png", imagePos=(0,0)) objectsListList.append(obj) obj = CreateObj("/home/eolson/am-macs/data/pic8.png", imagePos=(4200,0)) #obj = CreateObj("/home/eolson/am-macs/data/trim.png", imagePos=(4200,0)) objectsListList.append(obj) """ #imageDir = '/homes/turam/tiledDisplayImages' #imageDir = '/homes/eolson/am-macs/data/images' #defaultImageDir = '/homes/eolson/am-macs/data/largeImages' defaultImageDir = '/homes/eolson/data/largeImages' #imageDir = '/home/eolson/am-macs/data/kuhlmann' imageDir=None # let command line arg override the image path. #if len(sys.argv) > 1 and os.path.exists(sys.argv[1]): # and os.path.isdir(sys.argv[1]): # imageDir = sys.argv[1] if len(sysArgs) > 0 and os.path.exists(sysArgs[0]): # and os.path.isdir(sys.argv[1]): imageDir = sysArgs[0] if options.stream == None and options.groupedStream == None and imageDir == None: imageDir = defaultImageDir # make sure we try to show something on the screen. print "image path to load:", imageDir def IsValidDataType(path): recognizedExtensions = ["png", "jpg", "jpeg", "tif", "tiff", "tga", "gif", "rgb", "rgba", "sgi", "mpg", "mp4", "mov", "vob", "ogv", "avi", "tdmovie"] extension = (path.split(".")[-1]).lower() if extension in recognizedExtensions and not path.startswith("._"): return True else: return False def loadImageOrMovie(objPath, pos=None): if None == objPath: return None thisObjScale = movieScale if "NOAA_TEST.tdmovie" in objPath: # FIXME, add per object scale options thisObjScale = [2.0, 2.0] elif "HeadHeartLiver2.tdmovie" in objPath: thisObjScale = [1.2, 1.2] elif "jai-head2.mp4" in objPath: thisObjScale = [3.0, 3.0] elif "FOAM.tdmovie" in objPath: thisObjScale = [1.8, 1.8] #elif "NEW_DWARF.tdmovie" in objPath: # thisObjScale = [2.0, 2.0] #elif "VORTICITY.tdmovie" in objPath: # thisObjScale = [2.0, 2.0] elif "FUZZY.tdmovie" in objPath: thisObjScale = [2.0, 2.0] #elif "FISCHER.tdmovie" in objPath: # thisObjScale = [2.0, 2.0] #elif "DWARF.tdmovie" in objPath: # thisObjScale = [2.0, 2.0] elif "BGL.tdmovie" in objPath: thisObjScale = [2.0, 2.0] elif "enzo-b4096_2.tdmovie" in objPath: thisObjScale = [1.4, 1.4] elif "Enzo-4096-Evo-res4096x2304.tdmovie" in objPath: thisObjScale = [1.4, 1.4] elif "Enzo-4096-SC09-res4096x2304.tdmovie" in objPath: thisObjScale = [1.3, 1.3] elif "fischer_movie01.tdmovie" in objPath: thisObjScale = [1.0, 1.0] #if None == options.positions: # options.positions = [ (0, -1000) ] elif "FISCHER_MOVIE01" in objPath: if None == options.positions: options.positions = [ (0, -100) ] #elif "enzo-b4096" in objPath: # thisObjScale = [2.0, 2.0] if objPath != None and os.path.exists(objPath): if IsValidDataType(objPath): # some data types are directories print "Creating Obj:", objPath #if None == pos: # pos = (0,30) if IsTiledMoviePath(objPath): movieDims = GetTiledMoviePathDims(objPath) # center obj since there's only one if thisObjScale != None: #pos = [2500 + fullRect.width / 2 - movieDims[0] / 2 * movieScale[0], fullRect.height / 2 - movieDims[1] / 2 * movieScale[1]] if None == pos: pos = [fullRect.width / 2. - movieDims[0] / 2. * thisObjScale[0], fullRect.height / 2. - movieDims[1] / 2. * thisObjScale[1]] else: print "Pos is not None, not recentering movie" else: if None == pos: pos = [fullRect.width / 2. - movieDims[0] / 2., fullRect.height / 2. - movieDims[1] / 2.] print "Recentered Movie position is:", pos, "movieDims:", movieDims, "full display rect:", fullRect elif IsImagePath(objPath): f = Image.open(objPath) imageDims = f.size if None == pos: pos = [fullRect.width / 2 - imageDims[0] / 2, fullRect.height / 2 - imageDims[1] / 2] print "SCALE !!!", thisObjScale obj = CreateObj(objPath, imagePos=pos, scale=thisObjScale) if obj != None: objectsListList.append(obj) else: print "Path is not to a single data file/data item" if os.path.isdir(objPath): imageList = os.listdir(objPath) else: # just one image imageList = [objPath] objPath = "" print "File List:", imageList j = 0 imageList.sort() for i in imageList: extension = i.split(".")[-1] # just guesses so far #if extension.lower() in ["png", "jpg", "jpeg", "tif", "tiff", "tga", "gif", "rgb", "rgba", "sgi", "mpg", "mp4", "mov", "vob", "ogv"] and not i.startswith("._"): if IsValidDataType(i): #obj = CreateObj(os.path.join(objPath,i), imagePos=(3000-j*300,2000-j*200)) pos = (100+j*220,30+j*0) fullPath = os.path.join(objPath, i) if IsTiledMoviePath(fullPath): movieDims = GetTiledMoviePathDims(fullPath) # center tiled movies for now pos = [fullRect.width / 2 - movieDims[0] / 2, fullRect.height / 2 - movieDims[1] / 2] print "Creating Obj:", fullPath obj = CreateObj(fullPath, imagePos=pos, scale=thisObjScale) #obj = CreateObj(os.path.join(objPath,i), imagePos=(0+j*220,0+j*0)) if obj != None: objectsListList.append(obj) j += 1 else: print "skipping file (unhandled extension):", i return obj def loadMovieSequence(moviePaths): if len(movieSequence) > 1: sequenceObj = MovieSequence() else: sequenceObj = None for moviePath in movieSequence: obj = loadImageOrMovie(moviePath) if None != sequenceObj: numLoops = 1 if "NOAA_TEST.tdmovie" in moviePath: numLoops = 5 sequenceObj.append(obj, numLoops) if None != sequenceObj: sequenceObj.initializeObjects() return sequenceObj def loadLayout(layoutPath): layoutEntries = ReadLayout(layoutPath) for entry in layoutEntries: loadImageOrMovie(entry.path, pos=entry.pos) def getNextPosition(): global gPositionsIndex if None != options.positions and gPositionsIndex < len(options.positions): tmpPos = options.positions[gPositionsIndex] gPositionsIndex+=1 return tmpPos return None # load movie layout if specified if options.movieLayouts != None: thisObjScale = movieScale for movieLayout in options.movieLayouts: pos = getNextPosition() obj = CreateObj(movieLayout, imagePos=pos, scale=thisObjScale, objDesc=ObjectDescription(ObjType.TILED_MOVIE_WITH_LAYOUT)) if obj != None: objectsListList.append(obj) # load layout if specified if options.layouts != None: for layout in options.layouts: loadLayout(layout) # load image path if specified (different from default) if imageDir != defaultImageDir: loadImageOrMovie(imageDir, getNextPosition()) elif 0 == len(movieSequences) and None == options.layouts and None == options.movieLayouts: # or load default if no extra options # were specified. loadImageOrMovie(imageDir, getNextPosition()) # default if len(movieSequences) > 0: # load sequences from --sequence for movieSequence in movieSequences: sequenceObj = loadMovieSequence(movieSequence) app.addDynamicObject(sequenceObj, addToRenderer=False) #print "******************", options.stream if options.stream != None: if not gStreamingSupported: raise Exception("Error using --stream. Streaming not supported. Make sure StreamView could be imported.") try: address = options.stream[0] if len(options.stream) > 1: print "WARNING: So far we only handle one stream address. (multiple stream address handling coming soon)" #from streamView import StreamView, StartStreamViewLoop #streamView = StreamView() #obj = CreateObj(None, imagePos=(0, 0), obj=streamView) #objectsListList.append(obj) #StartStreamViewLoop(address) pos = [fullRect.width / 2, fullRect.height / 2 ] print "*********POS:", pos, "from:", fullRect streamWidth = options.streamSize[0][0] streamHeight = options.streamSize[0][1] vflip=False # works for RAW if StreamProtocols.FLX_H261 == streamProtocol: vflip=True streamDesc = objDesc=StreamObjDescription(streamProtocol, (streamWidth,streamHeight), vflip=vflip ) obj = CreateObj(address, imagePos=pos, objDesc=streamDesc, scale=movieScale, gridColsRows=options.streamColsRows) if obj != None: objectsListList.append(obj) except Exception, e: traceback.print_exc()