def load_textures():
    global texture
    texture = GL.glGenTextures(2)

    png_img = Reader(
        filename=
        'D:\\0\\GitHub\\CEFET-Computacao_Grafica_2020-2\\Trab_08-Esfera_Texturizada\\mapa.png'
    )

    w, h, pixels, metadata = png_img.read_flat()

    if (metadata['alpha']):
        modo = GL.GL_RGBA
    else:
        modo = GL.GL_RGB

    GL.glBindTexture(GL.GL_TEXTURE_2D, texture[0])
    GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, modo, w, h, 0, modo,
                    GL.GL_UNSIGNED_BYTE, pixels.tolist())
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
                       GL.GL_NEAREST)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
                       GL.GL_NEAREST)
    GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL)
Ejemplo n.º 2
0
def load():
    global textura
    textura = GL.glGenTextures(2)
    imagem = Reader(filename='C:\\Users\\Pedro\\Desktop\\computacao grafica\\trabalhos cg 2021.1\\7 - globo textura\\globomodelo.png')
    w, h, pixels, metadata = imagem.read_flat()
    if(metadata['alpha']):
        mod = GL.GL_RGBA
    else:
        mod = GL.GL_RGB
    GL.glBindTexture(GL.GL_TEXTURE_2D, textura[0])
    GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, mod, w, h, 0, mod, GL.GL_UNSIGNED_BYTE, pixels.tolist())
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST)
    GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL)
Ejemplo n.º 3
0
def LoadTextures():
    global texture
    texture = GL.glGenTextures(2)

    ###############################################################################################
    reader = Reader(filename='C:\\Users\\user\\Desktop\\computação grafica\\mapa.png')
    w, h, pixels, metadata = reader.read_flat()

    if(metadata['alpha']):
        modo = GL.GL_RGBA
    else:
        modo = GL.GL_RGB

    GL.glBindTexture(GL.GL_TEXTURE_2D, texture[0])
    GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)
    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, modo, w, h, 0, modo, GL.GL_UNSIGNED_BYTE, pixels.tolist())
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST)
    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST)
    GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL)
Ejemplo n.º 4
0
def load_textures():
    global texture
    texture = glGenTextures(2)

    mapa = Reader(filename='./mapa.png')

    w, h, pixels, metadata = mapa.read_flat()

    if (metadata['alpha']):
        modo = GL_RGBA
    else:
        modo = GL_RGB

    glBindTexture(GL_TEXTURE_2D, texture[0])
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
    glTexImage2D(GL_TEXTURE_2D, 0, modo, w, h, 0, modo, GL_UNSIGNED_BYTE,
                 pixels.tolist())
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
def to_liq(image: png.Reader, attr: liq.Attr) -> liq.Image:
    """
    Convert png.Reader to liq.Image.
    """
    width, height, data, info = image.read_flat()
    return attr.create_rgba(data, width, height, info.get('gamma', 0))
Ejemplo n.º 6
0
def main():

    comm = MPI.COMM_WORLD
    id= comm.Get_rank()
    wsize= comm.Get_size()    
    tstart = MPI.Wtime()
    fsky = open("skymap.png","r")
    reader = Reader(fsky)
    skypixelwidth, skypixelheight, skypixels, metadata=reader.read_flat()
    pixelwidth = int(argv[1])
    pixelheight = int(argv[2])
    tskymapstart = MPI.Wtime()
    telepixels = np.zeros((pixelwidth*pixelheight*3),dtype=np.uint8)
    colorpixels = np.zeros((pixelwidth*pixelheight),dtype=np.uint8)
    skystartall = np.zeros((pixelwidth*pixelheight),dtype=np.uint32)
    telestartall = np.zeros((pixelwidth*pixelheight),dtype=np.uint32)
    colorall = np.zeros((pixelwidth*pixelheight),dtype=np.uint8)
    totnstepsall=np.zeros((wsize),dtype=np.uint32)
    tskymapend = MPI.Wtime()
    tskymap = tskymapend-tskymapstart

    tmin = 1.e6
    tpercparmin=1.e6
    hinit=1.e-1
    #h=1.e-4
    Router = 1000.
    Rplane = 700.
    Rs = 2.
    every = 1
    deltalamb = 1.e-1
    imagewidth = 50;
    imageheight = 50;
    tiny = 1.e-30
    epsilon=1.e-8
    eccentricity = 0.2
    Rfac = 1.+1.e-10
    heps = 1.e-14
    semilatusr = 10.0  

    
    tstartpp=MPI.Wtime() #percent parallelized
    numperprocess = pixelheight*pixelwidth/wsize
    skystart=np.zeros((numperprocess),dtype=np.int32)
    telestart=np.zeros((numperprocess),dtype=np.int32)
    color = np.zeros((numperprocess),dtype=np.int8)
    totnsteps=np.zeros((numperprocess),dtype=np.int32)
    trk4all=np.zeros((numperprocess),dtype=np.float)
    ttelestop = MPI.Wtime()
    ttele = ttelestop-tstartpp
    trk4=float("inf")
    for index in range(numperprocess):
        ypix = int((id*numperprocess+index)/pixelwidth)
        xpix = (id*numperprocess+index)%pixelwidth
        tstartrk4=MPI.Wtime()
        totnsteps[index],skystart[index],telestart[index],color[index]=integrateNullGeodesic(xpix, ypix, pixelheight,pixelwidth, skypixelheight,skypixelwidth,imagewidth,imageheight,Rs,Router,Rplane,eccentricity, semilatusr, epsilon, tiny, hinit,Rfac,heps)
        tendrk4=MPI.Wtime()
        trk4=min(trk4,(tendrk4-tstartrk4)/float(totnsteps[index]))
    totnstepsmax=max(totnsteps)
    tstoppp = MPI.Wtime()
    tpercpar=tstoppp-tstartpp

    comm.Barrier()
    if id==0:
        totnstepsmaxall=0
    else:
        totnstepsmaxall=None
    comm.Barrier()

    totnstepsmaxall=comm.reduce(totnstepsmax,op=MPI.MAX,root=0)
    tskymapall = comm.reduce(tskymap, op=MPI.MAX, root=0)
    tteleall = comm.reduce(ttele,op=MPI.MAX,root=0)
    comm.Gatherv(skystart,skystartall,root=0)
    comm.Gatherv(telestart, telestartall, root=0)
    comm.Gatherv(color,colorall, root=0)
    trk4min=comm.reduce(trk4,op=MPI.MIN,root=0)
    comm.Barrier()
    tend = MPI.Wtime()
    tall = tend-tstart
    if id==0:
        tindexstart = MPI.Wtime()
        for index in range(pixelheight*pixelwidth):

            if(colorall[index]==1):
                telepixels[telestartall[index]:telestartall[index]+3]=skypixels[skystartall[index]:skystartall[index]+3]
            else:
                telepixels[telestartall[index]]=255 #leave other two indices zero,red
        tindexend = MPI.Wtime()
        tindex = tindexend-tindexstart
    if id==0:
        twritestart = MPI.Wtime()
        ftele = open('teleview_{pw}_{ph}_{ws}.png'.format(pw=pixelwidth,ph=pixelheight,ws=wsize), "w")
        telewrite=Writer(width=pixelwidth,height=pixelheight,greyscale=False,alpha=False)
        telewrite.write_array(ftele,telepixels)
        ftele.close()
        twriteend=MPI.Wtime()
        twrite = twriteend-twritestart
    fsky.close()
    comm.Barrier()
    tmax = comm.reduce(tall,MPI.MAX,root=0)
    tpercparmin = comm.reduce(tpercpar/tall,op=MPI.MIN,root=0)
    comm.Barrier()
    if (id==0):
#        print("Telescope dimensions in M", 2.*imagewidth, 2.*imageheight)
#        print("Telescope resolution", pixelwidth, pixelheight)
#        print("Skymap resolution", skypixelwidth, skypixelheight)
#        print("Schwarzschild radius in M", 2.*Rs)
#        print("Outer radius in M", 2.*Router)
#        print("Telescope radius in M", 2.*Rplane)
#        print("Number of processes = ",wsize)
#        print("Maximum number of integration steps taken is",totnstepsmaxall)
#        print("The time for a single step of the RK4 is",trk4min)
#        print("Total runtime = ",tmax)
#        print("Fraction parallel = ", tpercparmin)
        print pixelwidth,pixelheight,wsize,totnstepsmaxall,trk4min,tmax,tpercparmin, tindex, twrite, tskymapall, tteleall

    MPI.Finalize()