Add function for solid angle

This commit is contained in:
Vincent Lejeune 2014-10-21 23:28:01 +02:00
parent 690ad4ce95
commit d9ea756b15

View File

@ -2,7 +2,7 @@ import Image as img
import numpy as np
import pylab as pl
n = 4
n = 3
# constant factor of Ylm
c00 = 0.282095
@ -30,22 +30,40 @@ def computeYmlOnGrid(Xgrid, Ygrid, Zgrid):
return (Y00, Y1minus1, Y10, Y11, Y2minus2, Y2minus1, Y20, Y21, Y22)
Grid0, Grid1 = np.meshgrid(np.linspace(-1, 1, n), np.linspace(-1, 1, n))
GridI, GridJ = np.meshgrid(np.linspace(-1, 1, n), np.linspace(-1, 1, n))
FaceGrid = [(np.ones((n,n)), Grid0, Grid1), #GL_TEXTURE_CUBE_MAP_POSITIVE_X
(-1 * np.ones((n,n)), Grid0, Grid1), #GL_TEXTURE_CUBE_MAP_NEGATIVE_X
(Grid0, np.ones((n,n)), Grid1), #GL_TEXTURE_CUBE_MAP_POSITIVE_Y
(Grid0, -1 * np.ones((n,n)), Grid1), #GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
(Grid0, Grid1, np.ones((n,n))), #GL_TEXTURE_CUBE_MAP_POSITIVE_Z
(Grid0, Grid1, -1 * np.ones((n,n)))] #GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
FaceGrid = [(np.ones((n,n)), -GridI, -GridJ), #GL_TEXTURE_CUBE_MAP_POSITIVE_X
(-1 * np.ones((n,n)), -GridI, GridJ), #GL_TEXTURE_CUBE_MAP_NEGATIVE_X
(GridJ, np.ones((n,n)), GridI), #GL_TEXTURE_CUBE_MAP_POSITIVE_Y
(GridJ, -1 * np.ones((n,n)), -GridI), #GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
(GridJ, GridI, np.ones((n,n))), #GL_TEXTURE_CUBE_MAP_POSITIVE_Z
(GridJ, -GridI, -1 * np.ones((n,n)))] #GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
res = []
for (Xd, Yd, Zd) in FaceGrid:
res.append(computeYmlOnGrid(Xd, Yd, Zd))
print(res)
# From http://www.rorydriscoll.com/2012/01/15/cubemap-texel-solid-angle/
def areaToPoint(x, y):
return np.arctan2(x * y, np.sqrt(x * x + y * y + 1))
def getSolidAngleGrid(Xgrid, Ygrid):
"Compute solid angles using Xgrid/Ygrid/Zgrid texel position"
result = np.zeros((n,n))
for i in range(n):
for j in range(n):
x = Xgrid[i,j]
y = Ygrid[i,j]
x0 = x - (1. / n)
x1 = x + (1. / n)
y0 = y - (1. / n)
y1 = y + (1. / n)
result[i,j] = areaToPoint(x0,y0) - areaToPoint(x1, y0) - areaToPoint(x0, y1) + areaToPoint(x1, y1)
return result
print(getSolidAngleGrid(GridI, GridJ))
I = img.open("C:/Users/vljn_000/Documents/GitHub/stk-assets/textures/ants.png")
m = np.array(I)
print(type(m))
pl.imshow(m)
#I = img.open("C:/Users/vljn_000/Documents/GitHub/stk-assets/textures/ants.png")
#m = np.array(I)
#print(type(m))
#pl.imshow(m)