Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
camilovergara committed Jun 24, 2010
1 parent 46c5b4d commit 003873d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 62 deletions.
2 changes: 2 additions & 0 deletions cuerpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def patchesCubo(origin,lengthx,lengthy,lengthz,lum,color):
z0 += step
y0 = origin.y

for patch in patchesCubo:
patch.oclussion = True
return patchesCubo

def uvsphere(tx,ty,tz,w,lum, color):
Expand Down
91 changes: 50 additions & 41 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def sistema(a,b):
return x

def visibility(i,j) :
if(i==j):
return 1
p_i = patchesList[i]
p_j = patchesList[j]

Expand All @@ -71,6 +73,8 @@ def visibility(i,j) :
for x, p in enumerate(patchesList):
if(x == i or x == j):
continue
if(not p.oclussion):
continue
cp = p.center

l = cp.x
Expand All @@ -85,7 +89,7 @@ def visibility(i,j) :
det = b**2 - 4*a*c
if(det <= 0):
return 1.0
return 0.0
return 0.0

def visibility2(i,j) :
p_i = patchesList[i]
Expand Down Expand Up @@ -166,43 +170,48 @@ def visibility2(i,j) :
return 1.0

# recibe dos parches, y determina el factor de visibilidad entre los centros de ambos (valor 0 o 1)
# def visibility(i,j):
# if(i==j):
# return 1

# p_i = patchesList[i]
# p_j = patchesList[j]
# rvalue = 1
# ci = p_i.center
# cj = p_j.center

# # PARA CADA PARCHE P EN LA ESCENA
# for p in patchesList:
# cp = p.center
# # CALCULAR ANGULO THETA ENTRE VECTORES PI,PJ Y PI,CP
# v = cp.resta(ci,1)
# w = cj.resta(ci,1)
# if( v.modulo() == 0 or w.modulo() == 0):
# return 1
# theta = v.anguloEntre(w)
# # CALCULAR DISTANCIA COMO (CP-PI)SEN THETA
# d = math.sin(theta) * v.modulo()
# # CALCULAR MAYOR DISTANCIA ENTRE UN VERTICE DE P Y EL CENTRO DE P (DIS_MAX = DM)
# dm = p.pradio
# dmm = p.pmradio
# # CALCULAR ANGULO ENTRE NORMAL DE P Y R, ANGULO = TH
# alpha = p.normal.anguloEntre(w)
# # CALCULAR DD = DM*COS(TH) -> 'CUANTO SE ACERCA P A R'
# dd = dm*math.cos(alpha)
# ddm = dmm*math.cos(alpha)
# # SI D < DD => RECTA ATRAVIESA PARCHE
# # RETURN 0
# if( d < ddm ):
# return 0
# # elif(d < dd):
# # rvalue = 0.5
# # FIN DEL LOOP

# # RETURN 1
# return rvalue

def visibility3(i,j):
if(i==j):
return 1

p_i = patchesList[i]
p_j = patchesList[j]
rvalue = 1
ci = p_i.center
cj = p_j.center

# PARA CADA PARCHE P EN LA ESCENA
for x,p in enumerate(patchesList):
if(x == i or x == j):
continue
if(not p.oclussion):
continue
cp = p.center
# CALCULAR ANGULO THETA ENTRE VECTORES PI,PJ Y PI,CP
v = cp.resta(ci,1)
w = cj.resta(ci,1)
if( v.modulo() == 0 or w.modulo() == 0):
return 1
theta = v.anguloEntre(w)
# CALCULAR DISTANCIA COMO (CP-PI)SEN THETA
d = math.sin(theta) * v.modulo()
# CALCULAR MAYOR DISTANCIA ENTRE UN VERTICE DE P Y EL CENTRO DE P (DIS_MAX = DM)
dm = p.pradio
dmm = p.pmradio
# CALCULAR ANGULO ENTRE NORMAL DE P Y R, ANGULO = TH
alpha = p.normal.anguloEntre(w)
# CALCULAR DD = DM*COS(TH) -> 'CUANTO SE ACERCA P A R'
dd = dm*math.cos(alpha)
# ddm = dmm*math.cos(alpha)
# SI D < DD => RECTA ATRAVIESA PARCHE
# RETURN 0
# if( d < ddm ):
# return 0.1
# elif(d < dd):
# rvalue = 0.7
if( d < dd):
return 0.1
# FIN DEL LOOP

# RETURN 1
return rvalue
15 changes: 9 additions & 6 deletions patch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from OpenGL.GL import glVertex3f
import math
from variables import *

#implementado como triangulo
class Patch:
Expand Down Expand Up @@ -32,6 +33,7 @@ def __init__(self,p1,p2,p3,p4):
self.area = self._area()
self.pradio = self._pradio()
self.pmradio = self._pmradio()
self.oclussion = False

#retorna el baricentro del parche
def _center(self):
Expand Down Expand Up @@ -77,18 +79,19 @@ def draw(self):

# retorna el radio de la circunferencia circunscrita
def _pradio(self):
d1 = self.center.resta(self.p1,1).modulo()
d2 = self.center.resta(self.p2,1).modulo()
d3 = self.center.resta(self.p3,1).modulo()
d4 = self.center.resta(self.p4,1).modulo()
return max(d1,d2,d3,d4)
# d1 = self.center.resta(self.p1,1).modulo()
# d2 = self.center.resta(self.p2,1).modulo()
# d3 = self.center.resta(self.p3,1).modulo()
# d4 = self.center.resta(self.p4,1).modulo()
# return max(d1,d2,d3,d4)
return (1/SECTIONS)*0.5*(2**0.5)

# retorna el radio de la circunferencia inscrita
def _pmradio(self):
d1 = self.center.resta(self.p1,1).modulo()
d2 = self.center.resta(self.p2,1).modulo()
d3 = self.center.resta(self.p3,1).modulo()
d4 = self.center.resta(self.p4,1).modulo()
return min(d1,d2,d3,d4)
return max(d1,d2,d3,d4)*0.5*(2**0.5)


18 changes: 9 additions & 9 deletions radiosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import math
import time

from time import gmtime, strftime

from patch import *
from punto import *
from functions import *
Expand Down Expand Up @@ -38,12 +40,8 @@ def init(width, height):
# FormFactors = [[-1]*len(patchesList)]*len(patchesList)
# Visibilidad = [[-1]*len(patchesList)]*len(patchesList)

# 0 = cargar
# 1 = calcular
VSB = 1
FFT = 0
shoots = 30


print strftime("%a, %d %b %Y %H:%M:%S ", gmtime(time.time()-3600*4))
if( VSB == 1):
print "Computar Visibilidades"
computeVisibilidad()
Expand All @@ -61,6 +59,8 @@ def init(width, height):
print "Ejecutar ",shoots," iteraciones"
RadiosityIteration(shoots)
print "segundos= ",time.time()-ITIME
print strftime("%a, %d %b %Y %H:%M:%S", gmtime(time.time()-3600*4))


glClearColor(0.0, 0.0, 0.0, 0.0) # Color negro, sin transparencia

Expand Down Expand Up @@ -200,8 +200,8 @@ def generarPlanos():
# funcion que llama a los metodos de cuerpos.py
def generarCuerpos():
global patchesList
patchesList.extend( patchesCubo( Punto(4,1,4) , 2.0 , 2.0 , 1.0 , 0.0 , [0.2,0.1,0.1]) )
patchesList.extend( patchesCubo( Punto(1,0,1) , 1.0 , 1.0 , 1.0 , 0.0 , [0.15,0.15,0.1]) )
patchesList.extend( patchesCubo( Punto(4,1,4) , 2.0 , 2.0 , 1.0 , 0.0 , [0.7,0.1,0.1]) )
patchesList.extend( patchesCubo( Punto(1,0,1) , 1.0 , 1.0 , 1.0 , 0.0 , [0.7,0.7,0.1]) )
# patchesList.extend( patchesCubo( Punto(4,1,4),2,2,1,0,[0.8,0.2,0.2]) )
# patchesList.extend( uvsphere(2 , 3 , 1.5 , 0.4, 0, [0.9,0.5,0.5]) )
# patchesList.extend( uvsphere(4 , 2 , 1.5 , 0.5, 0, [0.9,0.5,0.5]) )
Expand Down Expand Up @@ -250,7 +250,7 @@ def computeVisibilidad():
Visibilidad[x][y] = 1.0
else:
# Visibilidad[x][y] = visibility(x,y)
Visibilidad[x][y] = visibility(x,y)
Visibilidad[x][y] = visibility3(x,y)
cPickle.dump(Visibilidad, open('visibilidad.dat', 'wb'))

def getVisibilidad(i,j):
Expand Down
17 changes: 11 additions & 6 deletions variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
HEIGHT = 600

#variables de los planos
SECTIONS = 3.0 #numero de triangulos por unidad de espacio
SECTIONS = 2.0 #numero de parches por unidad de espacio
# 0 = cargar
# 1 = calcular
VSB = 0
FFT = 0
shoots = 1

# intensidad de fuentes luminosas
INITINTEN = 500.0
Expand All @@ -41,17 +46,17 @@
size = 9.0
step = 1.0 / SECTIONS

XY_reflectance_red = 0.15
XY_reflectance_green = 0.15
XY_reflectance_blue = 0.1
XY_reflectance_red = 0.5
XY_reflectance_green = 0.5
XY_reflectance_blue = 0.5

XZ_reflectance_red = 0.1
XZ_reflectance_green = 0.2
XZ_reflectance_green = 0.8
XZ_reflectance_blue = 0.1

YZ_reflectance_red = 0.1
YZ_reflectance_green = 0.1
YZ_reflectance_blue = 0.2
YZ_reflectance_blue = 0.8

FormFactors = None
Visibilidad = None
Expand Down

0 comments on commit 003873d

Please sign in to comment.