def __init__(self, filename, blend=False, screenGeomRect=None, dstRectScale=None): self.texture = Texture(filename) if blend: self.blendFunc = (GL_SRC_ALPHA, GL_ONE) else: self.blendFunc = (None, None) #(GL_SRC_ALPHA, GL_ONE); #(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) self.txtrMode = M_REPLACE # self.txtrTarget = GL_TEXTURE_2D # self.alphaTest = False # assume this for now self.nativeWidth, self.nativeHeight = self.texture.getWidth( ), self.texture.getHeight() self.width, self.height = self.texture.getWidth( ), self.texture.getHeight() if screenGeomRect == None: self.screenGeomRect = Rect(0, 0, self.width, self.height) else: self.screenGeomRect = screenGeomRect self.texXMinMax = Vec2(0, 1) self.texYMinMax = Vec2(0, 1) self.color = None if dstRectScale == None: self.setDstRectScale((1.0, 1.0)) else: self.setDstRectScale(dstRectScale)
def CreateMultiNetGroupTileDisplayStreamObject(addresses, objDesc, screenRect, pos, absRect, fullRect, gridColsRows, netGridColsRows, blend=True, scale=None, doCenter=True, plant=False): #from streamView import StreamView objectsToGroup = [] if len(addresses) != netGridColsRows[0] * netGridColsRows[1]: raise Exception("Number of addresses should match number of net grid tiles (e.g. use: --streamGroupsColsRows=3x2). currently: %d, %s" % (len(addresses), netGridColsRows) ) #for address in addresses: gridCols = gridColsRows[0] gridRows = gridColsRows[1] bigTileWidth = gridCols * objDesc.streamWidth # 352 bigTileHeight = gridRows * objDesc.streamHeight # 288 if scale != None: bigTileWidth *= scale[0] bigTileHeight *= scale[1] netGridCols = netGridColsRows[0] netGridRows = netGridColsRows[1] print "BIGTILESIZE:", bigTileWidth, bigTileHeight basePos = pos if doCenter: centeredPos = Vec2(pos[0], pos[1]) - Vec2(netGridCols * bigTileWidth/2, netGridRows * bigTileHeight/2) basePos = centeredPos # for xcol in range(1,2): print "grid within network stream:", gridCols, gridRows print "bigTile width,height:", bigTileWidth, bigTileHeight for xcol in range(netGridCols): for yrow in range(netGridRows): streamAddressIndex = netGridCols * yrow + xcol # btm left to right, to top address = addresses[streamAddressIndex] yOffset = yrow * bigTileHeight xOffset = xcol * bigTileWidth singlePos = Vec2(xOffset+basePos[0],yOffset+basePos[1]) loadTile = True if plant: # only load if it's on this machine streamTileRenderRect = Rect(singlePos[0], singlePos[1], bigTileWidth, bigTileHeight) # print "Checking colliderects to see if stream tile is on this display tile:", movieRenderRect.colliderect(absRect), movieRenderRect, absRect, movieRenderRect.colliderect(absRect), "indexes:", xIndex, yIndex, "flipped indexes:", xIndex,yIndexBZ if streamTileRenderRect.colliderect(absRect): loadTile = True # Debug import mpi print mpi.rank, " Loading stream with rect: ", streamTileRenderRect, "me:", (absRect.x,absRect.y,absRect.width,absRect.height), address else: import mpi print mpi.rank, " Not loading stream with rect: ", streamTileRenderRect, "me:", (absRect.x,absRect.y,absRect.width,absRect.height), address loadTile = False if loadTile: groupStreamObj = GroupTiledStreamObject(address, objDesc, screenRect=screenRect, pos=singlePos, absRect= absRect, fullRect=fullRect, blend=blend, scale=scale, gridColsRows=gridColsRows, doCenter=False) objectsToGroup.append(groupStreamObj) else: groupStreamObj = NullTileDisplayObject(pos=singlePos,size=(bigTileWidth,bigTileHeight) ) # Empty object to represent objects on other nodes and help describe large object on this node . objectsToGroup.append(groupStreamObj) shortName = "_".join(addresses) largeGroupObject = GroupObject(shortName, objectsToGroup, doChildUpdates=True) return largeGroupObject
def getMainDisplayRect(self): tileRects = [] rects = [] for machineDesc in self.machines: for tile in machineDesc.tiles: rects.append(self.getAbsoluteFullDisplayRect(tile.uid)) rect = Rect(0, 0, 0, 0) for r in rects: rect = rect.union(r) return rect
def getRect(self): if self.pos and self.getSize(): # avoid None return Rect(self.pos.x, self.pos.y, self.getSize()[0], self.getSize()[1]) else: return None
def __init__(self, filename, blend=False, screenGeomRect=None, dstRectScale=None): self.texture = Texture(filename) if blend: self.blendFunc = (GL_SRC_ALPHA, GL_ONE) else: self.blendFunc = (None, None) #(GL_SRC_ALPHA, GL_ONE); #(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) self.txtrMode = M_REPLACE # self.txtrTarget = GL_TEXTURE_2D # self.alphaTest = False # assume this for now self.nativeWidth, self.nativeHeight = self.texture.getWidth(), self.texture.getHeight() self.width, self.height = self.texture.getWidth(), self.texture.getHeight() if screenGeomRect == None: self.screenGeomRect = Rect(0,0,self.width,self.height) else: self.screenGeomRect = screenGeomRect self.texXMinMax = Vec2(0, 1) self.texYMinMax = Vec2(0, 1) self.color = None if dstRectScale == None: self.setDstRectScale( (1.0, 1.0) ) else: self.setDstRectScale(dstRectScale)
def CreateCursor(x=500, y=500, xvel=100, yvel=100): tmpCursors = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] cursor = glTxtrBox("../../../../data/fl-logo-color-small.gif", screenRect=Rect(0, 0, locRect.width, locRect.height), imagePos=(x, y), absRect=absRect, fullRect=fullRect) app.addDynamicObject(cursor, addToRenderer=False) renderers[i].addDynamicObject(cursor) tmpCursors.append(cursor) # change this to only happen on master and sync if mpi.rank == 0: app.addDynamicObject(CursorAutoMover(cursor, xrange=(0, fullRect.width), yrange=(0, fullRect.height), xvel=xvel, yvel=yvel), addToRenderer=False) return tmpCursors
def CreateTiledMovieObjectFromLayout(layoutFile, screenRect, pos, absRect, fullRect, loadAllMovieTiles=False, scale=None, allowFrameSkip=None): print "CreateTiledMovieObjectFromLayout" objectsToGroup = [] if None == pos: pos = (0, 0) layoutEntries = ReadLayout(layoutFile) for entry in layoutEntries: moviePos = Vec2(pos[0] + entry.pos[0], pos[1] + entry.pos[1]) movieRenderRect = Rect(moviePos[0], moviePos[1], entry.getWidth(), entry.getHeight()) tileObject = None # same code as below func if loadAllMovieTiles or movieRenderRect.colliderect(absRect): movieTileFilename = entry.path fullMovieTilePath = movieTileFilename # for now has absolute paths # same code as below function print "movieTileFilename:", movieTileFilename, len(movieTileFilename) if len(movieTileFilename.strip()) > 0: print "movieTileFilename:", movieTileFilename, len(movieTileFilename) print "TiledMovie: loading tile: ", fullMovieTilePath # obj.pos and obj.size will be used to group movie tiles. fps = fps=entry.getProperty("fps") tileObject = CreateMovieObject(fullMovieTilePath, screenRect, moviePos, absRect, fullRect, fps=fps, scale=scale, allowFrameSkip=allowFrameSkip) else: print "Warning movieTile not found for:", xIndex, yIndex if not tileObject: tileObject = NullTileDisplayObject(pos=moviePos,size=(movieRenderRect.width,movieRenderRect.height) ) # Empty object to represent # objects on other nodes # and keep object list synced. objectsToGroup.append(tileObject) shortName = os.path.basename(layoutFile.strip(os.path.sep)) duration = layoutEntries[0].getProperty("duration") fps = fps=layoutEntries[0].getProperty("fps") groupObject = TiledMovieGroupObject(shortName, objectsToGroup, duration=duration, fps=fps) groupObject.doChildUpdates=True returnObj = groupObject return returnObj
def getLocalDrawRect(self, tileId): tileDict = self._getTileDict() machine = self._getMachineForTile(tileId) # print "WARNING: getLocalDrawRect not accounting for borders and mullions yet" for i in range(len(machine.tiles)): tile = machine.tiles[i] if tile.uid == tileId: return Rect(tile.localOffset[0], tile.localOffset[1], tile.pixelSize[0], tile.pixelSize[1]) return None
def isPixelTransparent(self, imagecoords): for child,offset in self.childrenAndOffsets.items(): # need to adjust image coords to match individual image instead of group rect #print "orig imagecoords:", imagecoords #print "child coords:", child.getPos(), "group coords:", self.getPos() offset = child.getPos() - self.getPos() tileImagecoords = Vec2(imagecoords[0] - offset.x, imagecoords[1] - offset.y) #print "modified imagecoords:", tileImagecoords if ( Rect(0,0,child.getWidth(), child.getHeight()).containsPoint(*tileImagecoords) and not child.isPixelTransparent(tileImagecoords) ): return False return True
def getLocalRectTxtrRectBL(self): # convert to local coords, BL means 0,0 is in the Bottom Left localBtmLeft = Vec2(self.pos.x - self.absRect.x, self.pos.y - self.absRect.y) # print "CALC LOCAL TR1:", localBtmLeft.x, self.getSize()[0], localBtmLeft.y, self.getSize()[1] localTopRight = Vec2(localBtmLeft.x + self.getSize()[0], localBtmLeft.y + self.getSize()[1]) # clip to max/min of local display localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0)) #if mpi.rank == 3: # print "clip top right y:", localTopRight.y, self.screenRect.height # print "CALC LOCAL TR:", localTopRight.x, self.screenRect.width, localTopRight.y, self.screenRect.height localTopRight = Vec2(min(localTopRight.x, self.screenRect.width), min(localTopRight.y, self.screenRect.height)) #if mpi.rank == 3: # print "clip top right y:", localTopRight.y blitSize = Vec2(localTopRight.x - localBtmLeft.x, localTopRight.y - localBtmLeft.y) # convert clipped local coords back to global coords find the source rect globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x, localBtmLeft.y + self.absRect.y) globalTopRight = Vec2(localTopRight.x + self.absRect.x, localTopRight.y + self.absRect.y) # convert global coords to txtr coords offset = Vec2(globalBtmLeft.x - self.pos.x, globalBtmLeft.y - self.pos.y) #size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y + 80) size = (globalTopRight.x - globalBtmLeft.x, localTopRight.y - localBtmLeft.y) # print "CALC LOCALRECTSIZE:", localTopRight, localBtmLeft localRectSize = localTopRight - localBtmLeft return Rect(localBtmLeft.x, localBtmLeft.y, localRectSize[0], localRectSize[1]), Rect(offset.x, offset.y, size[0], size[1])
def getChildrenRect(self): if len(self.childrenAndOffsets) == 0: return Rect(0,0, 0, 0) # union all child rects and report size children = self.childrenAndOffsets.keys() rect = copy.copy(children[0].getRect()) for child in children[1:]: # print " child rect:", child.getRect() if child.getRect(): # avoid None if rect: #avoid None rect = rect.union(child.getRect()) else: rect = copy.copy(child.getRect()) print "GET CHILDREN RECT:", rect return rect
def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) # convert to local coords localBtmLeft = Vec2(self.imagePos.x - self.absRect.x, self.imagePos.y - self.absRect.y) localTopRight = Vec2(localBtmLeft.x + self.imageSize[0], localBtmLeft.y + self.imageSize[1]) # clip to max/min of local display localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0)) #if mpi.rank == 3: # print "clip top right y:", localTopRight.y, self.screenRect.height localTopRight = Vec2(min(localTopRight.x, self.screenRect.width), min(localTopRight.y, self.screenRect.height)) #if mpi.rank == 3: # print "clip top right y:", localTopRight.y blitSize = Vec2(localTopRight.x - localBtmLeft.x, localTopRight.y - localBtmLeft.y) # convert clipped local coords back to global coords find the source rect globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x, localBtmLeft.y + self.absRect.y) globalTopRight = Vec2(localTopRight.x + self.absRect.x, localTopRight.y + self.absRect.y) # convert global coords to txtr coords offset = Vec2(globalBtmLeft.x - self.imagePos.x, globalBtmLeft.y - self.imagePos.y) #size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y + 80) size = (globalTopRight.x - globalBtmLeft.x, localTopRight.y - localBtmLeft.y) if size[0] > 0 and size[1] > 0: #if mpi.rank == 3: # print "renderer height:", renderer.height self.texture.blit(localBtmLeft, Rect(offset.x, offset.y, size[0], size[1]), (renderer.width, renderer.height))
def __init__(self, rect=None, displayStr=":0"): if not rect: self.rect = Rect(0, 0, 0, 0) else: self.rect = rect self.displayStr = displayStr
def CreateTiledMovieObjectFromLayout(layoutFile, screenRect, pos, absRect, fullRect, loadAllMovieTiles=False, scale=None, allowFrameSkip=None): print "CreateTiledMovieObjectFromLayout" objectsToGroup = [] if None == pos: pos = (0, 0) layoutEntries = ReadLayout(layoutFile) for entry in layoutEntries: moviePos = Vec2(pos[0] + entry.pos[0], pos[1] + entry.pos[1]) movieRenderRect = Rect(moviePos[0], moviePos[1], entry.getWidth(), entry.getHeight()) tileObject = None # same code as below func if loadAllMovieTiles or movieRenderRect.colliderect(absRect): movieTileFilename = entry.path fullMovieTilePath = movieTileFilename # for now has absolute paths # same code as below function print "movieTileFilename:", movieTileFilename, len( movieTileFilename) if len(movieTileFilename.strip()) > 0: print "movieTileFilename:", movieTileFilename, len( movieTileFilename) print "TiledMovie: loading tile: ", fullMovieTilePath # obj.pos and obj.size will be used to group movie tiles. fps = fps = entry.getProperty("fps") tileObject = CreateMovieObject(fullMovieTilePath, screenRect, moviePos, absRect, fullRect, fps=fps, scale=scale, allowFrameSkip=allowFrameSkip) else: print "Warning movieTile not found for:", xIndex, yIndex if not tileObject: tileObject = NullTileDisplayObject( pos=moviePos, size=(movieRenderRect.width, movieRenderRect.height)) # Empty object to represent # objects on other nodes # and keep object list synced. objectsToGroup.append(tileObject) shortName = os.path.basename(layoutFile.strip(os.path.sep)) duration = layoutEntries[0].getProperty("duration") fps = fps = layoutEntries[0].getProperty("fps") groupObject = TiledMovieGroupObject(shortName, objectsToGroup, duration=duration, fps=fps) groupObject.doChildUpdates = True returnObj = groupObject return returnObj
def run(): tileConfig = CreateAMConfig() # fqdn = getfqdn() hostname = gethostname() machineDesc = tileConfig.getMachineDescByHostname(hostname) localRects = [] absoluteRects = [] for tile in machineDesc.tiles: localRects.append(tileConfig.getLocalDrawRect(tile.uid)) absoluteRects.append(tileConfig.getAbsoluteFullDisplayRect(tile.uid)) print hostname, machineDesc.hostname, localRects, absoluteRects # return fullRect = tileConfig.getMainDisplayRect() if mpi.rank == 0: print "FULL DISPLAY:", fullRect.width, fullRect.height #rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] #rects = [Rect(0,0,1280,1024)] os.environ["DISPLAY"] = ":0.0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" imageFilename = sys.argv[1] #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(localRects)): displayRect = localRects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj( ScreenClearer(color=(.0, .0, .0), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj( ScreenClearer(color=(.0, .0, .0), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) # app.initialize(windowBorder=False) app.initialize(windowBorder=True) for i in range(len(localRects)): print "SETTING RECT:", localRects[i] renderers[i].init(app.width, app.height, viewportRect=localRects[i]) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename, screenRect, fullRect, absRect, initialOffset=(0, 0), zoom=(4, 4), imagePos=(0, 0), imageSize=None): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True self.texture = Texture(imageFilename) #self.easyTexture = EasyTexture(imageFilename, screenGeomRect=screenRect, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 #self.easyTexture.width = renderer.width #self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.zoom = zoom #self.easyTexture.zoom(zoom[0], zoom[1]) #self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) self.autoPan = True self.imagePos = Vec2(imagePos[0], imagePos[1]) if imageSize == None: self.imageSize = self.texture.getWidth( ), self.texture.getHeight() else: self.imageSize = imageSize self.fullRect = fullRect self.absRect = absRect self.screenRect = screenRect def getPos(self): return (self.imagePos.x, self.imagePos.y) def setPos(self, x, y): self.imagePos = Vec2(x, y) def update(self, secs, app): pass #if self.autoPan: # self.easyTexture.pan(self.xvel * secs, self.yvel* secs) def pan(self, xchange, ychange): if mpi.rank == 1: print "Panning:", xchange, ychange #self.easyTexture.pan(xchange * 300, ychange * 300) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) # convert to local coords localBtmLeft = Vec2(self.imagePos.x - self.absRect.x, self.imagePos.y - self.absRect.y) localTopRight = Vec2(localBtmLeft.x + self.imageSize[0], localBtmLeft.y + self.imageSize[1]) localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0)) localTopRight = Vec2(min(localTopRight.x, self.screenRect.width), min(localTopRight.y, self.screenRect.height)) blitSize = Vec2(localTopRight.x - localBtmLeft.x, localTopRight.y - localBtmLeft.y) # convert clipped local coords back to global coords find the source rect globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x, localBtmLeft.y + self.absRect.y) globalTopRight = Vec2(localTopRight.x + self.absRect.x, localTopRight.y + self.absRect.y) # convert global coords to txtr coords offset = Vec2(globalBtmLeft.x - self.imagePos.x, globalBtmLeft.y - self.imagePos.y) size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y) if size[0] > 0 and size[1] > 0: self.texture.blit(localBtmLeft, Rect(offset.x, offset.y, size[0], size[1]), (renderer.width, renderer.height)) #self.easyTexture.draw() #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) boxes = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] box = glTxtrBox(imageFilename, screenRect=Rect(0, 0, locRect.width, locRect.height), imagePos=(2000, 500), absRect=absRect, fullRect=fullRect) # 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) app.drawBounds = 0 # setup control def setupMoteControl(panningObjects, app, displayWidth, displayHeight): tileMote = TileMote(panningObjects, displayWidth, displayHeight) if mpi.rank == 0: mote = connectToMote() moteMouse = MoteMouse(mote, tileMote) else: moteMouse = None mote = None class MouseUpdater: def __init__(self, moteMouse, tileMote): self.moteMouse = moteMouse self.tileMote = tileMote def update(self, app, secs): # process data from device if mpi.rank == 0: self.moteMouse.processAndUpdateMouse() # send data to all nodes and apply self.tileMote.syncAndApply() app.addDynamicObject(MouseUpdater(moteMouse, tileMote), addToRenderer=False) return mote, moteMouse, tileMote mote = None for arg in sys.argv: if "wii" in arg.lower(): mote, moteMouse, tileMote = setupMoteControl( boxes, app, fullRect.width, fullRect.height) for box in boxes: box.autoPan = False break # break out of this loop class Syncer: def __init__(self, cursorObjectsListList=None): # list of lists: [ [a1,a2,a3], [b1,b2] ] # access: cursor[i][localcopies] # only the first object for each cursors is read, all are written if cursorObjectsListList == None: self.cursorObjects = [] else: self.cursorObjects = cursorObjectsListList self.cursors = [] for obj in self.cursorObjects: self.cursors.append((0, 0)) self.resultCursors = [] if mpi.rank == 0: self.dataLock = Lock() def update(self, app, secs): self.syncAndApply() def syncAndApply(self): if mpi.rank == 0: self.dataLock.acquire( ) # this lock probably isn't necessary yet try: for i in range(len(self.cursorObjects)): self.cursors[i] = self.cursorObjects[i][0].getPos() except: traceback.print_exc() finally: self.dataLock.release() if mpi.rank == 0: resultCursors = mpi.bcast(self.cursors) else: self.resultCursors = mpi.bcast() if mpi.rank != 0: for i in range(len(self.cursorObjects)): if len(self.resultCursors) > i: # access: cursorObjects[i][localcopies] for j in range(len(self.cursorObjects[i]) ): # set for each local copy self.cursorObjects[i][j].setPos( self.resultCursors[i][0], self.resultCursors[i][1]) #if len(resultQueue) > 0: # print "Bcasting recv:", resultQueue, mpi.rank class CursorAutoMover: def __init__(self, target, xrange=(0, 5000), yrange=(0, 3000), xvel=100, yvel=100): self.target = target self.xvel = xvel self.yvel = yvel self.xrange = xrange self.yrange = yrange self.visible = False def draw(self): pass def update(self, secs, app): posTuple = self.target.getPos() pos = Vec2(posTuple[0], posTuple[1]) pos.x = pos.x + self.xvel * secs pos.y = pos.y + self.yvel * secs if pos.x > self.xrange[1]: self.xvel = -abs(self.xvel) if pos.y > self.yrange[1]: self.yvel = -abs(self.yvel) if pos.x < self.xrange[0]: self.xvel = abs(self.xvel) if pos.y < self.xrange[0]: self.yvel = abs(self.yvel) self.target.setPos(pos.x, pos.y) # print "pos:", pos.x, pos.y #class Cursor: def CreateCursor(x=500, y=500, xvel=100, yvel=100): tmpCursors = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] cursor = glTxtrBox("../../../../data/fl-logo-color-small.gif", screenRect=Rect(0, 0, locRect.width, locRect.height), imagePos=(x, y), absRect=absRect, fullRect=fullRect) app.addDynamicObject(cursor, addToRenderer=False) renderers[i].addDynamicObject(cursor) tmpCursors.append(cursor) # change this to only happen on master and sync if mpi.rank == 0: app.addDynamicObject(CursorAutoMover(cursor, xrange=(0, fullRect.width), yrange=(0, fullRect.height), xvel=xvel, yvel=yvel), addToRenderer=False) return tmpCursors numCursors = 3 cursorListList = [] for i in range(numCursors): nodeCursors = CreateCursor(x=randrange(0, fullRect.width), y=randrange(0, fullRect.height), xvel=randrange(200, 400), yvel=randrange(200, 400)) cursorListList.append(nodeCursors) # print mpi.rank, " cursor list:", cursorListList syncer = Syncer(cursorListList) app.addDynamicObject(syncer, addToRenderer=False) print "Running app" try: app.run() except: traceback.print_exc() finally: if mpi.rank == 0: if mote != None: mote.disconnect() if mote.readThread != None: print "Exiting, joining thread" mote.readThread.join()
def getRect(self): return Rect(self.pos.x, self.pos.y, self.imageSize[0], self.imageSize[1])
def getRect(self): return Rect(0, 0, self.width, self.height)
def run(): print "starting:", mpi.rank os.environ['SDL_VIDEO_WINDOW_POS'] = "400,300" print "Just after run SDL_VIDEO_WIDOW_POS:", mpi.rank, os.environ[ 'SDL_VIDEO_WINDOW_POS'] rects = [Rect(0, 0, 1280, 1024), Rect(1280, 0, 1280, 1024)] os.environ["DISPLAY"] = ":0.0" #os.environ['SDL_VIDEO_WINDOW_POS']="0,0" import pygame windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(rects)): displayRect = rects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj( ScreenClearer(color=(.9, .4, .4), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj( ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) print "app.initialize", mpi.rank app.initialize(windowBorder=False) for i in range(len(rects)): print "SETTING RECT:", rects[i] renderers[i].init(app.width, app.height, viewportRect=rects[i]) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename="../data/test1.png", initialOffset=(0, 0)): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture(imageFilename, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 self.easyTexture.width = renderer.width self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.easyTexture.zoom(2, 2) self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) def update(self, secs, app): self.easyTexture.pan(self.xvel * secs, self.yvel * secs) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() imageFilename = "/home/eolson/am-macs/data/JC4-Sol1355A_1358A_DeckPan_L456atc_br2.jpg" glEnable(GL_TEXTURE_2D) for i in range(len(renderers)): rect = rects[i] box = glTxtrBox(imageFilename, initialOffset=(rect.x, rect.y)) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) print "Running app" try: app.run() except: traceback.print_exc() #import time #time.sleep(3) print "exiting: ", mpi.rank
class EasyTexture: # Advanced texture functions def __init__(self, filename, blend=False, screenGeomRect=None, dstRectScale=None): self.texture = Texture(filename) if blend: self.blendFunc = (GL_SRC_ALPHA, GL_ONE) else: self.blendFunc = (None, None) #(GL_SRC_ALPHA, GL_ONE); #(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) self.txtrMode = M_REPLACE # self.txtrTarget = GL_TEXTURE_2D # self.alphaTest = False # assume this for now self.nativeWidth, self.nativeHeight = self.texture.getWidth( ), self.texture.getHeight() self.width, self.height = self.texture.getWidth( ), self.texture.getHeight() if screenGeomRect == None: self.screenGeomRect = Rect(0, 0, self.width, self.height) else: self.screenGeomRect = screenGeomRect self.texXMinMax = Vec2(0, 1) self.texYMinMax = Vec2(0, 1) self.color = None if dstRectScale == None: self.setDstRectScale((1.0, 1.0)) else: self.setDstRectScale(dstRectScale) def reloadGLTextureFromData(self): self.texture.reloadGLTextureFromData() self.nativeWidth, self.nativeHeight = self.texture.getWidth( ), self.texture.getHeight() if self.dstRectScale == None: self.setWidth(self.texture.getWidth()) self.setHeight(self.texture.getHeight()) else: self.setDstRectScale( self.dstRectScale) # apply scale based on new resolution def bind(self): self.texture.bind() def setTexXMinMax(self, xmin, xmax): self.texXMinMax.x = xmin self.texXMinMax.y = xmax def setTexYMinMax(self, ymin, ymax): self.texYMinMax.x = ymin self.texYMinMax.y = ymax def unbind(self): self.texture.unbind() def release(self): self.texture.release() def draw(self, vflipTexture=False): glPushAttrib(GL_ENABLE_BIT) glDepthMask(GL_FALSE) # avoids annoying boxes visible around see through particles glEnable(GL_CULL_FACE) #if self.alphaTest != None: # #glEnable(GL_ALPHA_TEST); # #glAlphaFunc(GL_GREATER, .5); if self.blendFunc == (None, None): glDisable(GL_BLEND) else: glEnable(GL_BLEND) #glBlendFunc(GL_SRC_ALPHA, GL_ONE); #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBlendFunc(self.blendFunc[0], self.blendFunc[1]) if self.texture != None: # don't have gl textures glEnable(GL_TEXTURE_2D) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GLTextureModes[self.txtrMode]) # glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, self.txtrMode ); # was GL_DECAL, or GL_MODULATE self.texture.bind() if (self.color != None): glColor4f(self.color[0], self.color[1], self.color[2], self.color[3]) unit_up_vec = Vec2(0.0, 1.0) edge_vec = Vec2(1.0, 0.0) if self.texture != None: # have gl textures # print "easy texture draw:", self.screenGeomRect.x, self.screenGeomRect.y , self.screenGeomRect.width,self.screenGeomRect.height, self.texXMinMax, self.texYMinMax DrawTxtrd2dSquareIn2DFromCorner(Vec2(self.screenGeomRect.x, self.screenGeomRect.y), self.screenGeomRect.width, self.screenGeomRect.height, self.texXMinMax, self.texYMinMax, vflipTexture=vflipTexture) else: Draw2dSquareIn2D(Vec2(0, 0), self.width, self.height) """ glBegin(GL_TRIANGLE_STRIP) glTexCoord2d(0.0, 1.0); glVertex2f(200, 400) glTexCoord2d(0.0, 0.0); glVertex2f(200, 200) glTexCoord2d(1.0, 1.0); glVertex2f(400, 400) glTexCoord2d(1.0, 0.0); glVertex2f(400, 200) glEnd() """ self.texture.unbind() glPopAttrib() def setOffsetX(self, x): self.screenGeomRect.setX(x) def setOffsetY(self, y): self.screenGeomRect.setY(y) def setPos(self, x, y): self.screenGeomRect.setOffset(x, y) def getPos(self): return self.screenGeomRect.x, self.screenGeomRect.y def setDstRectScale(self, dstRectScale): self.dstRectScale = dstRectScale if self.dstRectScale == None: self.setWidth(self.getNativeWidth()) self.setHeight(self.getNativeHeight()) else: self.setWidth(self.getNativeWidth() * dstRectScale[0]) self.setHeight(self.getNativeHeight() * dstRectScale[1]) def setWidth(self, w): self.width = w self.screenGeomRect.setWidth(w) def setHeight(self, h): self.height = h self.screenGeomRect.setHeight(h) def getWidth(self): return self.width get_width = getWidth def getNativeWidth(self): return self.nativeWidth def getHeight(self): return self.height get_height = getHeight def getNativeHeight(self): return self.nativeHeight def getRect(self): return Rect(0, 0, self.width, self.height) def zoom(self, factorx, factory): # just change max of x and y width = self.texXMinMax[1] - self.texXMinMax[0] height = self.texYMinMax[1] - self.texYMinMax[0] # slightly confusing, the first .y, means "max" # max = min + width / factor self.texXMinMax.y = self.texXMinMax[0] + width / factorx self.texYMinMax.y = self.texYMinMax[0] + height / factory def setZoom(self, factorx, factory): # just change max of x and y # slightly confusing, the first .y, means "max" # max = min + width / factor self.texXMinMax.y = self.texXMinMax[0] + self.nativeWidth / factorx self.texYMinMax.y = self.texYMinMax[0] + self.nativeHeight / factory def setOffset(self, x, y): self.texXMinMax.x = x self.texYMinMax.x = y setPan = setOffset def pan(self, amountx, amounty): #self.texXMinMax.x = (self.texXMinMax.x + amountx + 1) % 1.0 #self.texYMinMax.x = (self.texXMinMax.x + amounty + 1) % 1.0 #self.texXMinMax.y = (self.texXMinMax.y + amountx + 1) % 1.0 #self.texYMinMax.y = (self.texXMinMax.y + amounty + 1) % 1.0 self.texXMinMax.x += amountx self.texYMinMax.x += amounty self.texXMinMax.y += amountx self.texYMinMax.y += amounty
def run(): mpi.barrier() print "run", mpi.rank mpi.barrier() os.environ['SDL_VIDEO_WINDOW_POS'] = "400,300" print "Just after run SDL_VIDEO_WIDOW_POS:", mpi.rank, os.environ[ 'SDL_VIDEO_WINDOW_POS'] print "run", mpi.rank """ tileConfig = CreateAMConfig() # fqdn = getfqdn() hostname = gethostname() machineDesc = tileConfig.getMachineDescByHostname(hostname) tileRects = [] rects = [] for tile in machineDesc.tiles: # tileConfig.getLocalDrawRect() rects.append(tileConfig.getAbsoluteFullDisplayRect(tile.uid)) print hostname, machineDesc.hostname, rects # return """ rects = [Rect(0, 0, 1280, 1024), Rect(1280, 0, 1280, 1024)] #rects = [Rect(0,0,1280,1024)] os.environ["DISPLAY"] = ":0.0" #os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" import pygame os.system("export SDL_VIDEO_WINDOW_POS=0,0") imageFilename = sys.argv[1] #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) renderers = [] for i in range(len(rects)): displayRect = rects[i] if i == 0: renderer = glRenderer2D(multipleRenderers=True, firstRenderer=True) renderer.addFrameSetupObj( ScreenClearer(color=(.9, .4, .4), clearDepth=False)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj( ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) print "app.initialize" app.initialize(windowBorder=False) #app.initialize(windowBorder=True) for i in range(len(rects)): print "SETTING RECT:", rects[i] renderers[i].init(app.width, app.height, viewportRect=rects[i]) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename="../data/test1.png", initialOffset=(0, 0)): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True #self.texture = Texture( "../data/test1.png") self.easyTexture = EasyTexture(imageFilename, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 self.easyTexture.width = renderer.width self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.easyTexture.zoom(2, 2) self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) def update(self, secs, app): self.easyTexture.pan(self.xvel * secs, self.yvel * secs) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) self.easyTexture.draw() #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) for i in range(len(renderers)): rect = rects[i] box = glTxtrBox(imageFilename, initialOffset=(rect.x, rect.y)) app.addDynamicObject(box, addToRenderer=False) renderers[i].addDynamicObject(box) app.drawBounds = 0 print "Running app" try: app.run() except: traceback.print_exc()
class EasyTexture: # Advanced texture functions def __init__(self, filename, blend=False, screenGeomRect=None, dstRectScale=None): self.texture = Texture(filename) if blend: self.blendFunc = (GL_SRC_ALPHA, GL_ONE) else: self.blendFunc = (None, None) #(GL_SRC_ALPHA, GL_ONE); #(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) self.txtrMode = M_REPLACE # self.txtrTarget = GL_TEXTURE_2D # self.alphaTest = False # assume this for now self.nativeWidth, self.nativeHeight = self.texture.getWidth(), self.texture.getHeight() self.width, self.height = self.texture.getWidth(), self.texture.getHeight() if screenGeomRect == None: self.screenGeomRect = Rect(0,0,self.width,self.height) else: self.screenGeomRect = screenGeomRect self.texXMinMax = Vec2(0, 1) self.texYMinMax = Vec2(0, 1) self.color = None if dstRectScale == None: self.setDstRectScale( (1.0, 1.0) ) else: self.setDstRectScale(dstRectScale) def reloadGLTextureFromData(self): self.texture.reloadGLTextureFromData() self.nativeWidth, self.nativeHeight = self.texture.getWidth(), self.texture.getHeight() if self.dstRectScale == None: self.setWidth(self.texture.getWidth()) self.setHeight(self.texture.getHeight()) else: self.setDstRectScale(self.dstRectScale) # apply scale based on new resolution def bind(self): self.texture.bind() def setTexXMinMax(self, xmin, xmax): self.texXMinMax.x = xmin self.texXMinMax.y = xmax def setTexYMinMax(self, ymin, ymax): self.texYMinMax.x = ymin self.texYMinMax.y = ymax def unbind(self): self.texture.unbind() def release(self): self.texture.release() def draw(self, vflipTexture=False): glPushAttrib(GL_ENABLE_BIT) glDepthMask(GL_FALSE); # avoids annoying boxes visible around see through particles glEnable(GL_CULL_FACE); #if self.alphaTest != None: # #glEnable(GL_ALPHA_TEST); # #glAlphaFunc(GL_GREATER, .5); if self.blendFunc == (None,None) : glDisable(GL_BLEND) else: glEnable(GL_BLEND); #glBlendFunc(GL_SRC_ALPHA, GL_ONE); #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBlendFunc(self.blendFunc[0], self.blendFunc[1]) if self.texture != None: # don't have gl textures glEnable(GL_TEXTURE_2D) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GLTextureModes[self.txtrMode]); # glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, self.txtrMode ); # was GL_DECAL, or GL_MODULATE self.texture.bind() if (self.color != None): glColor4f(self.color[0], self.color[1], self.color[2], self.color[3]); unit_up_vec = Vec2(0.0, 1.0) edge_vec = Vec2(1.0, 0.0) if self.texture != None: # have gl textures # print "easy texture draw:", self.screenGeomRect.x, self.screenGeomRect.y , self.screenGeomRect.width,self.screenGeomRect.height, self.texXMinMax, self.texYMinMax DrawTxtrd2dSquareIn2DFromCorner(Vec2(self.screenGeomRect.x, self.screenGeomRect.y), self.screenGeomRect.width,self.screenGeomRect.height, self.texXMinMax, self.texYMinMax, vflipTexture=vflipTexture) else: Draw2dSquareIn2D(Vec2(0,0), self.width, self.height) """ glBegin(GL_TRIANGLE_STRIP) glTexCoord2d(0.0, 1.0); glVertex2f(200, 400) glTexCoord2d(0.0, 0.0); glVertex2f(200, 200) glTexCoord2d(1.0, 1.0); glVertex2f(400, 400) glTexCoord2d(1.0, 0.0); glVertex2f(400, 200) glEnd() """ self.texture.unbind() glPopAttrib() def setOffsetX(self, x): self.screenGeomRect.setX(x) def setOffsetY(self, y): self.screenGeomRect.setY(y) def setPos(self, x, y): self.screenGeomRect.setOffset(x,y) def getPos(self): return self.screenGeomRect.x, self.screenGeomRect.y def setDstRectScale(self, dstRectScale): self.dstRectScale = dstRectScale if self.dstRectScale == None: self.setWidth(self.getNativeWidth()) self.setHeight(self.getNativeHeight()) else: self.setWidth(self.getNativeWidth() * dstRectScale[0]) self.setHeight(self.getNativeHeight() * dstRectScale[1]) def setWidth(self, w): self.width = w self.screenGeomRect.setWidth(w) def setHeight(self, h): self.height = h self.screenGeomRect.setHeight(h) def getWidth(self): return self.width get_width = getWidth def getNativeWidth(self): return self.nativeWidth def getHeight(self): return self.height get_height = getHeight def getNativeHeight(self): return self.nativeHeight def getRect(self): return Rect(0,0,self.width, self.height) def zoom(self, factorx, factory): # just change max of x and y width = self.texXMinMax[1] - self.texXMinMax[0] height = self.texYMinMax[1] - self.texYMinMax[0] # slightly confusing, the first .y, means "max" # max = min + width / factor self.texXMinMax.y = self.texXMinMax[0] + width / factorx self.texYMinMax.y = self.texYMinMax[0] + height / factory def setZoom(self, factorx, factory): # just change max of x and y # slightly confusing, the first .y, means "max" # max = min + width / factor self.texXMinMax.y = self.texXMinMax[0] + self.nativeWidth / factorx self.texYMinMax.y = self.texYMinMax[0] + self.nativeHeight / factory def setOffset(self, x, y): self.texXMinMax.x = x self.texYMinMax.x = y setPan = setOffset def pan(self, amountx, amounty): #self.texXMinMax.x = (self.texXMinMax.x + amountx + 1) % 1.0 #self.texYMinMax.x = (self.texXMinMax.x + amounty + 1) % 1.0 #self.texXMinMax.y = (self.texXMinMax.y + amountx + 1) % 1.0 #self.texYMinMax.y = (self.texXMinMax.y + amounty + 1) % 1.0 self.texXMinMax.x += amountx self.texYMinMax.x += amounty self.texXMinMax.y += amountx self.texYMinMax.y += amounty
def CreateTiledMovieObject(filename, screenRect, pos, absRect, fullRect, loadAllMovieTiles=False, scale=None, allowFrameSkip=None): # A tiled movie object has a mostly frozen position on the display (for now) # Each tile only loads the movie tiles that it will display at the # movie's current position. # Find the tiles that are located on the current display, load them, and # position them. print "CreateTiledMovieObject" objectsToGroup = [] # Load info from description des = ReadTiledMovieDescription(filename) tileFilenames = os.listdir(filename) print "tileFilenames:", tileFilenames # calculate adjustment in case full movie width and height are not # evenly divisible by tile width and height. adjustment = (des["tileColsRows"][0] * des["tileRes"][0] - des["fullRes"][0], des["tileColsRows"][1] * des["tileRes"][1] - des["fullRes"][1]) imageBased = False if IsTiledMovieChunkImageBased(os.path.join(filename, tileFilenames[0])): imageBased = True for xIndex in range(des["tileColsRows"][0]): for yIndex in range(des["tileColsRows"][1]): # TZ==TopZero yIndexBZ = des["tileColsRows"][1] - 1 - yIndex # BZ==BottomZero movieTileFilename = "" for f in tileFilenames: tileYIndex = yIndexBZ if imageBased: # The 0th row for our movie and image loaders is different. tileYIndex = yIndex if f.startswith("%s_%s." % (xIndex, tileYIndex) ) or f == "%s_%s" % (xIndex, tileYIndex): movieTileFilename = f fullMovieTilePath = os.path.join(filename, movieTileFilename) tileObject = None # full movie width and height are not evenly divisible by # tile width and tile height, so adjust offset xSrcOffset = xIndex * des["tileRes"][0] - adjustment[0] ySrcOffset = yIndex * des["tileRes"][1] - adjustment[1] srcWidth, srcHeight = (des["tileRes"][0], des["tileRes"][1]) # adjust a possibly small row or column's offset and size # might only be necessary for y, since y is flipped (x untested). #if xIndex == 0: # xOffset -= adjustment[0] # width -= adjustment[0] if scale != None: xRenderOffset = xIndex * des["tileRes"][0] * scale[ 0] - adjustment[0] yRenderOffset = yIndex * des["tileRes"][1] * scale[ 1] - adjustment[1] * scale[1] # remove the adjustment when yIndex == 0 if yIndex == 0: yRenderOffset = yIndex * des["tileRes"][1] * scale[1] srcHeight -= adjustment[1] renderWidth, renderHeight = srcWidth * scale[ 0], srcHeight * scale[1] else: # remove the adjustment when yIndex == 0 if yIndex == 0: # FIXME, if we ever use imagebased (slow, movies # from image files, this may have to be adjusted # to use tileYIndex and maybe flip signs below. ySrcOffset += adjustment[1] srcHeight -= adjustment[1] xRenderOffset, yRenderOffset = xSrcOffset, ySrcOffset renderWidth, renderHeight = srcWidth, srcHeight #xSrcOffset = xIndex * des["tileRes"][0] #ySrcOffset = yIndex * des["tileRes"][1] #moviePos = Vec2(pos[0] + xSrcOffset, pos[1] + ySrcOffset) moviePos = Vec2(pos[0] + xRenderOffset, pos[1] + yRenderOffset) #movieRect = Rect(pos[0] + xSrcOffset, pos[1] + ySrcOffset, srcWidth, srcHeight) movieRenderRect = Rect(pos[0] + xRenderOffset, pos[1] + yRenderOffset, renderWidth, renderHeight) # print "Checking colliderects to see if movie tile is on this display tile:", movieRenderRect.colliderect(absRect), movieRenderRect, absRect, movieRenderRect.colliderect(absRect), "indexes:", xIndex, yIndex, "flipped indexes:", xIndex,yIndexBZ if loadAllMovieTiles or movieRenderRect.colliderect(absRect): movieTileFilename = "" for f in tileFilenames: if f.startswith("%s_%s." % (xIndex, yIndexBZ) ) or f == "%s_%s" % (xIndex, yIndexBZ): movieTileFilename = f print "movieTileFilename:", movieTileFilename, len( movieTileFilename) if len(movieTileFilename.strip()) > 0: print "movieTileFilename:", movieTileFilename, len( movieTileFilename) print "TiledMovie: loading tile: ", fullMovieTilePath # obj.pos and obj.size will be used to group movie tiles. tileObject = CreateMovieObject( fullMovieTilePath, screenRect, moviePos, absRect, fullRect, fps=des["FPS"], scale=scale, allowFrameSkip=allowFrameSkip) else: print "Warning movieTile not found for:", xIndex, yIndex if not tileObject: tileObject = NullTileDisplayObject( pos=moviePos, size=(movieRenderRect.width, movieRenderRect.height)) # Empty object to represent # objects on other nodes # and keep object list synced. objectsToGroup.append(tileObject) shortName = os.path.basename(filename.strip(os.path.sep)) groupObject = TiledMovieGroupObject(shortName, objectsToGroup, duration=des["duration"], fps=des["FPS"]) groupObject.doChildUpdates = True returnObj = groupObject return returnObj
def CreateTiledMovieObject(filename, screenRect, pos, absRect, fullRect, loadAllMovieTiles=False, scale=None, allowFrameSkip=None): # A tiled movie object has a mostly frozen position on the display (for now) # Each tile only loads the movie tiles that it will display at the # movie's current position. # Find the tiles that are located on the current display, load them, and # position them. print "CreateTiledMovieObject" objectsToGroup = [] # Load info from description des = ReadTiledMovieDescription(filename) tileFilenames = os.listdir(filename) print "tileFilenames:", tileFilenames # calculate adjustment in case full movie width and height are not # evenly divisible by tile width and height. adjustment = (des["tileColsRows"][0] * des["tileRes"][0]-des["fullRes"][0], des["tileColsRows"][1] * des["tileRes"][1]-des["fullRes"][1]) imageBased = False if IsTiledMovieChunkImageBased(os.path.join(filename, tileFilenames[0])): imageBased = True for xIndex in range(des["tileColsRows"][0]): for yIndex in range(des["tileColsRows"][1]): # TZ==TopZero yIndexBZ = des["tileColsRows"][1] - 1 - yIndex # BZ==BottomZero movieTileFilename = "" for f in tileFilenames: tileYIndex = yIndexBZ if imageBased: # The 0th row for our movie and image loaders is different. tileYIndex = yIndex if f.startswith("%s_%s." % (xIndex,tileYIndex)) or f == "%s_%s" % (xIndex,tileYIndex): movieTileFilename = f fullMovieTilePath = os.path.join(filename, movieTileFilename) tileObject = None # full movie width and height are not evenly divisible by # tile width and tile height, so adjust offset xSrcOffset = xIndex * des["tileRes"][0] - adjustment[0] ySrcOffset = yIndex * des["tileRes"][1] - adjustment[1] srcWidth,srcHeight = (des["tileRes"][0], des["tileRes"][1]) # adjust a possibly small row or column's offset and size # might only be necessary for y, since y is flipped (x untested). #if xIndex == 0: # xOffset -= adjustment[0] # width -= adjustment[0] if scale != None: xRenderOffset = xIndex * des["tileRes"][0] * scale[0] - adjustment[0] yRenderOffset = yIndex * des["tileRes"][1] * scale[1] - adjustment[1] * scale[1] # remove the adjustment when yIndex == 0 if yIndex == 0: yRenderOffset = yIndex * des["tileRes"][1] * scale[1] srcHeight -= adjustment[1] renderWidth, renderHeight = srcWidth * scale[0], srcHeight * scale[1] else: # remove the adjustment when yIndex == 0 if yIndex == 0: # FIXME, if we ever use imagebased (slow, movies # from image files, this may have to be adjusted # to use tileYIndex and maybe flip signs below. ySrcOffset += adjustment[1] srcHeight -= adjustment[1] xRenderOffset, yRenderOffset = xSrcOffset, ySrcOffset renderWidth, renderHeight = srcWidth, srcHeight #xSrcOffset = xIndex * des["tileRes"][0] #ySrcOffset = yIndex * des["tileRes"][1] #moviePos = Vec2(pos[0] + xSrcOffset, pos[1] + ySrcOffset) moviePos = Vec2(pos[0] + xRenderOffset, pos[1] + yRenderOffset) #movieRect = Rect(pos[0] + xSrcOffset, pos[1] + ySrcOffset, srcWidth, srcHeight) movieRenderRect = Rect(pos[0] + xRenderOffset, pos[1] + yRenderOffset, renderWidth, renderHeight) # print "Checking colliderects to see if movie tile is on this display tile:", movieRenderRect.colliderect(absRect), movieRenderRect, absRect, movieRenderRect.colliderect(absRect), "indexes:", xIndex, yIndex, "flipped indexes:", xIndex,yIndexBZ if loadAllMovieTiles or movieRenderRect.colliderect(absRect): movieTileFilename = "" for f in tileFilenames: if f.startswith("%s_%s." % (xIndex,yIndexBZ)) or f == "%s_%s" % (xIndex,yIndexBZ): movieTileFilename = f print "movieTileFilename:", movieTileFilename, len(movieTileFilename) if len(movieTileFilename.strip()) > 0: print "movieTileFilename:", movieTileFilename, len(movieTileFilename) print "TiledMovie: loading tile: ", fullMovieTilePath # obj.pos and obj.size will be used to group movie tiles. tileObject = CreateMovieObject(fullMovieTilePath, screenRect, moviePos, absRect, fullRect, fps=des["FPS"], scale=scale, allowFrameSkip=allowFrameSkip) else: print "Warning movieTile not found for:", xIndex, yIndex if not tileObject: tileObject = NullTileDisplayObject(pos=moviePos,size=(movieRenderRect.width,movieRenderRect.height) ) # Empty object to represent # objects on other nodes # and keep object list synced. objectsToGroup.append(tileObject) shortName = os.path.basename(filename.strip(os.path.sep)) groupObject = TiledMovieGroupObject(shortName, objectsToGroup, duration=des["duration"], fps=des["FPS"]) groupObject.doChildUpdates=True returnObj = groupObject return returnObj
def CreateTileImageObject(imageFilename, screenRect, pos, absRect, fullRect, blend=True, scale=None): print "CreateTileImageObject", imageFilename, "at", pos imageSize = Image.open(imageFilename).size maxTextureSize = GetMaxTextureSize() numTiles = (int(math.ceil(float(imageSize[0]) / maxTextureSize)), int(math.ceil(float(imageSize[1]) / maxTextureSize))) print "NUMTILES:", numTiles if numTiles[0] == 1 and numTiles[1] == 1: returnObj = glTxtrBox(imageFilename, screenRect=screenRect, imagePos=pos, absRect=absRect, fullRect=fullRect, blend=blend, scale=scale) else: objectsToGroup = [] # Create a group object xSrcOffset = 0 xRenderOffset = 0 subImageWidth = imageSize[0] / numTiles[0] subImageHeight = imageSize[1] / numTiles[1] for xIndex in range(numTiles[0]): ySrcOffset = 0 yRenderOffset = 0 if xIndex == numTiles[0] - 1: # make sure we don't cut off any # pixels if it's not evenly divisible. width = imageSize[0] - xSrcOffset else: width = subImageWidth for yIndex in range(numTiles[1]): if yIndex == numTiles[1] - 1: # make sure we don't cut off any # pixels if it's not evenly divisible. height = imageSize[1] - ySrcOffset else: height = subImageHeight pos = Vec2(xRenderOffset, -yRenderOffset) # flip y coord # cropRect is for cropping a subsection out of the source image cropRect = Rect(xSrcOffset, ySrcOffset, width, height) print "Loading with crop rect:", cropRect obj = glTxtrBox(imageFilename, screenRect=screenRect, imagePos=pos, absRect=absRect, fullRect=fullRect, blend=blend, cropRect=cropRect, scale=scale) objectsToGroup.append(obj) ySrcOffset += obj.getSrcSize()[1] yRenderOffset += obj.getRenderSize()[1] xSrcOffset += obj.getSrcSize()[0] xRenderOffset += obj.getRenderSize()[0] shortName = os.path.basename(imageFilename.strip(os.path.sep)) groupObject = GroupObject(shortName, objectsToGroup) returnObj = groupObject print "************* CreateTileDisplayObject finished", returnObj return returnObj
def CreateMultiNetGroupTileDisplayStreamObject(addresses, objDesc, screenRect, pos, absRect, fullRect, gridColsRows, netGridColsRows, blend=True, scale=None, doCenter=True, plant=False): #from streamView import StreamView objectsToGroup = [] if len(addresses) != netGridColsRows[0] * netGridColsRows[1]: raise Exception( "Number of addresses should match number of net grid tiles (e.g. use: --streamGroupsColsRows=3x2). currently: %d, %s" % (len(addresses), netGridColsRows)) #for address in addresses: gridCols = gridColsRows[0] gridRows = gridColsRows[1] bigTileWidth = gridCols * objDesc.streamWidth # 352 bigTileHeight = gridRows * objDesc.streamHeight # 288 if scale != None: bigTileWidth *= scale[0] bigTileHeight *= scale[1] netGridCols = netGridColsRows[0] netGridRows = netGridColsRows[1] print "BIGTILESIZE:", bigTileWidth, bigTileHeight basePos = pos if doCenter: centeredPos = Vec2(pos[0], pos[1]) - Vec2( netGridCols * bigTileWidth / 2, netGridRows * bigTileHeight / 2) basePos = centeredPos # for xcol in range(1,2): print "grid within network stream:", gridCols, gridRows print "bigTile width,height:", bigTileWidth, bigTileHeight for xcol in range(netGridCols): for yrow in range(netGridRows): streamAddressIndex = netGridCols * yrow + xcol # btm left to right, to top address = addresses[streamAddressIndex] yOffset = yrow * bigTileHeight xOffset = xcol * bigTileWidth singlePos = Vec2(xOffset + basePos[0], yOffset + basePos[1]) loadTile = True if plant: # only load if it's on this machine streamTileRenderRect = Rect(singlePos[0], singlePos[1], bigTileWidth, bigTileHeight) # print "Checking colliderects to see if stream tile is on this display tile:", movieRenderRect.colliderect(absRect), movieRenderRect, absRect, movieRenderRect.colliderect(absRect), "indexes:", xIndex, yIndex, "flipped indexes:", xIndex,yIndexBZ if streamTileRenderRect.colliderect(absRect): loadTile = True # Debug import mpi print mpi.rank, " Loading stream with rect: ", streamTileRenderRect, "me:", ( absRect.x, absRect.y, absRect.width, absRect.height), address else: import mpi print mpi.rank, " Not loading stream with rect: ", streamTileRenderRect, "me:", ( absRect.x, absRect.y, absRect.width, absRect.height), address loadTile = False if loadTile: groupStreamObj = GroupTiledStreamObject( address, objDesc, screenRect=screenRect, pos=singlePos, absRect=absRect, fullRect=fullRect, blend=blend, scale=scale, gridColsRows=gridColsRows, doCenter=False) objectsToGroup.append(groupStreamObj) else: groupStreamObj = NullTileDisplayObject( pos=singlePos, size=(bigTileWidth, bigTileHeight) ) # Empty object to represent objects on other nodes and help describe large object on this node . objectsToGroup.append(groupStreamObj) shortName = "_".join(addresses) largeGroupObject = GroupObject(shortName, objectsToGroup, doChildUpdates=True) return largeGroupObject
def getAbsoluteFullDisplayRect(self, tileDict): offset = self.location.getAbsoluteLocation(tileDict, [self.uid]) return Rect(offset[0], offset[1], self.pixelSize[0], self.pixelSize[1])
def run(): tileConfig = CreateAMConfig() # fqdn = getfqdn() hostname = gethostname() machineDesc = tileConfig.getMachineDescByHostname(hostname) localRects = [] absoluteRects = [] for tile in machineDesc.tiles: localRects.append(tileConfig.getLocalDrawRect(tile.uid)) absoluteRects.append(tileConfig.getAbsoluteFullDisplayRect(tile.uid)) print hostname, machineDesc.hostname, localRects, absoluteRects # return fullRect = tileConfig.getMainDisplayRect() if mpi.rank == 0: print "FULL DISPLAY:", fullRect.width, fullRect.height #rects = [Rect(0,0,1280,1024), Rect(1280,0, 1280,1024)] #rects = [Rect(0,0,1280,1024)] os.environ["DISPLAY"] = ":0.0" os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" imageFilename = sys.argv[1] #windowWidth = 2560 # 1280# 320 #windowWidth = 3840 # 1280# 320 windowWidth = 2560 # 1280# 320 windowHeight = 1024 # 1024 # 280 #windowWidth = 1280 # 1280# 320 #windowHeight = 1024 # 1024 # 280 app = App(windowWidth, windowHeight) 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)) else: renderer = glRenderer2D(multipleRenderers=True) renderer.addFrameSetupObj( ScreenClearer(color=(.4, .9, .4), clearDepth=False)) renderers.append(renderer) app.addRenderer(renderer) # app.initialize(windowBorder=False) app.initialize(windowBorder=True) for i in range(len(localRects)): print "SETTING RECT:", localRects[i] renderers[i].init(app.width, app.height, viewportRect=localRects[i]) class glBox: def __init__(self): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True def update(self, app, secs): pass def draw(self, renderer): #glClearColor(.4, .4, .4, 1.0) #glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_TRIANGLE_STRIP) glVertex2f(100, 200) glVertex2f(100, 100) glVertex2f(200, 200) glVertex2f(200, 100) glEnd() class glTxtrBox: def __init__(self, imageFilename, screenRect, fullRect, absRect, initialOffset=(0, 0), zoom=(4, 4), imagePos=(0, 0), imageSize=None): self.hasDrawFunc = True self.hasEraseDrawFunc = True self.visible = True self.texture = Texture(imageFilename) #self.easyTexture = EasyTexture(imageFilename, screenGeomRect=screenRect, blend=False) #self.easyTexture.width = renderer.width * 0.8 #self.easyTexture.height = renderer.height * 0.8 #self.easyTexture.width = renderer.width #self.easyTexture.height = renderer.height self.useDrawPixel = False # For comparison debugging self.xvel = 0.1 self.yvel = 0.1 self.zoom = zoom #self.easyTexture.zoom(zoom[0], zoom[1]) #self.easyTexture.setOffset(initialOffset[0], initialOffset[1]) self.autoPan = True self.imagePos = imagePos if imageSize == None: self.imageSize = self.texture.getWidth( ), self.texture.getHeight() else: self.imageSize = imageSize self.fullRect = fullRect self.absRect = absRect self.screenRect = screenRect def update(self, secs, app): pass #if self.autoPan: # self.easyTexture.pan(self.xvel * secs, self.yvel* secs) def pan(self, xchange, ychange): if mpi.rank == 1: print "Panning:", xchange, ychange #self.easyTexture.pan(xchange * 300, ychange * 300) def draw(self, renderer): #glClearColor(.8, .8, .8, 1.0) #glClear(GL_COLOR_BUFFER_BIT) # glPixelStoref(GL_UNPACK_ALIGNMENT, 1) # self.texture.blit( Vec2(10,10), Rect(10,10, 30,30), (app.width, app.height) ) # self.texture.blit( Vec2(50,50), Rect(0,0, 64,64), (app.width, app.height) ) # self.texture.blit( Vec2(150,50), Rect(40,40, 64,64), (app.width, app.height) , blend=True) #self.texture.blit( Vec2(0.1 * renderer.width,0.1 * renderer.height), Rect(0,0, 30,30), (app.width, app.height) ) # convert to local coords localBtmLeft = Vec2(self.imagePos[0] - self.absRect.x, self.imagePos[1] - self.absRect.y) localTopRight = Vec2(localBtmLeft.x + self.imageSize[0], localBtmLeft.y + self.imageSize[1]) localBtmLeft = Vec2(max(localBtmLeft.x, 0), max(localBtmLeft.y, 0)) localTopRight = Vec2(min(localTopRight.x, self.screenRect.width), min(localTopRight.y, self.screenRect.height)) blitSize = Vec2(localTopRight.x - localBtmLeft.x, localTopRight.y - localBtmLeft.y) # convert clipped local coords back to global coords find the source rect globalBtmLeft = Vec2(localBtmLeft.x + self.absRect.x, localBtmLeft.y + self.absRect.y) globalTopRight = Vec2(localTopRight.x + self.absRect.x, localTopRight.y + self.absRect.y) # convert global coords to txtr coords offset = Vec2(globalBtmLeft.x - self.imagePos[0], globalBtmLeft.y - self.imagePos[1]) size = (globalTopRight.x - globalBtmLeft.x, globalTopRight.y - globalBtmLeft.y) if size[0] > 0 and size[1] > 0: self.texture.blit(localBtmLeft, Rect(offset.x, offset.y, size[0], size[1]), (renderer.width, renderer.height)) #self.easyTexture.draw() #box = glBox() #app.addDynamicObject(box) glEnable(GL_TEXTURE_2D) boxes = [] for i in range(len(renderers)): absRect = absoluteRects[i] locRect = localRects[i] renderer = renderers[i] box = glTxtrBox(imageFilename, screenRect=Rect(0, 0, locRect.width, locRect.height), imagePos=(2000, 500), absRect=absRect, fullRect=fullRect) # 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) app.drawBounds = 0 # setup control def setupMoteControl(panningObjects, app, displayWidth, displayHeight): tileMote = TileMote(panningObjects, displayWidth, displayHeight) if mpi.rank == 0: mote = connectToMote() moteMouse = MoteMouse(mote, tileMote) else: moteMouse = None mote = None class MouseUpdater: def __init__(self, moteMouse, tileMote): self.moteMouse = moteMouse self.tileMote = tileMote def update(self, app, secs): # process data from device if mpi.rank == 0: self.moteMouse.processAndUpdateMouse() # send data to all nodes and apply self.tileMote.syncAndApply() app.addDynamicObject(MouseUpdater(moteMouse, tileMote), addToRenderer=False) return mote, moteMouse, tileMote mote = None for arg in sys.argv: if "wii" in arg.lower(): mote, moteMouse, tileMote = setupMoteControl( boxes, app, fullRect.width, fullRect.height) for box in boxes: box.autoPan = False break # break out of this loop print "Running app" try: app.run() except: traceback.print_exc() finally: if mpi.rank == 0: if mote != None: mote.disconnect() if mote.readThread != None: print "Exiting, joining thread" mote.readThread.join()