summaryrefslogtreecommitdiff
path: root/geometry.py
diff options
context:
space:
mode:
Diffstat (limited to 'geometry.py')
-rw-r--r--geometry.py53
1 files changed, 28 insertions, 25 deletions
diff --git a/geometry.py b/geometry.py
index 8dee8c9..5cd1bf2 100644
--- a/geometry.py
+++ b/geometry.py
@@ -3,7 +3,7 @@ import numpy.ma as ma
import pycuda.driver as cuda
from pycuda import gpuarray
from mesh import Mesh
-from materials import wavelengths
+from materials import standard_wavelengths
def interleave(arr, bits):
"""
@@ -51,8 +51,11 @@ def morton_order(mesh, bits):
return interleave(mean_positions, bits)
class Geometry(object):
- def __init__(self, solids=[]):
- self.solids = solids
+ def __init__(self, solids=None):
+ if solids is not None:
+ self.solids = list(solids)
+ else:
+ self.solids = []
def add_solid(self, solid):
self.solids.append(solid)
@@ -73,8 +76,8 @@ class Geometry(object):
np.inner(solid.mesh.vertices, solid.rotation) + solid.displacement
self.mesh = Mesh(vertices, triangles)
- del vertices
- del triangles
+ #del vertices
+ #del triangles
zvalues_mesh = morton_order(self.mesh[:], bits)
reorder = np.argsort(zvalues_mesh)
@@ -118,7 +121,7 @@ class Geometry(object):
else:
self.surface_index[i] = -1
- self.colors = np.concatenate([solid.color for solid in self.solids])
+ self.colors = np.concatenate([solid.color for solid in self.solids])[reorder]
self.solid_id = np.concatenate([np.tile(solid.id, len(solid.mesh)) \
for solid in self.solids])[reorder]
@@ -204,16 +207,16 @@ class Geometry(object):
set_wavelength_range = module.get_function('set_wavelength_range')
- set_wavelength_range(wavelengths[0], wavelengths[-1], wavelengths[1]-wavelengths[0], block=(1,1,1), grid=(1,1))
+ set_wavelength_range(np.float32(standard_wavelengths[0]), np.float32(standard_wavelengths[-1]), np.float32(standard_wavelengths[1]-standard_wavelengths[0]), np.uint32(standard_wavelengths.size), block=(1,1,1), grid=(1,1))
set_material = module.get_function('set_material')
for i, material in enumerate(self.materials):
if material is None:
continue
- refractive_index = np.interp(wavelengths, material.refractive_index[:,0], material.refractive_index[:,1]).astype(np.float32)
- absorption_length = np.interp(wavelengths, material.absorption_length[:,0], material.absorption_length[:,1]).astype(np.float32)
- scattering_length = np.interp(wavelengths, material.scattering_length[:,0], material.scattering_length[:,1]).astype(np.float32)
+ refractive_index = np.interp(standard_wavelengths, material.refractive_index[:,0], material.refractive_index[:,1]).astype(np.float32)
+ absorption_length = np.interp(standard_wavelengths, material.absorption_length[:,0], material.absorption_length[:,1]).astype(np.float32)
+ scattering_length = np.interp(standard_wavelengths, material.scattering_length[:,0], material.scattering_length[:,1]).astype(np.float32)
material.refractive_index_gpu = cuda.to_device(refractive_index)
material.absorption_length_gpu = cuda.to_device(absorption_length)
@@ -226,9 +229,9 @@ class Geometry(object):
if surface is None:
continue
- absorption = np.interp(wavelengths, surface.absorption[:,0], surface.absorption[:,1]).astype(np.float32)
- reflection_diffuse = np.interp(wavelengths, surface.reflection_diffuse[:,0], surface.reflection_diffuse[:,1]).astype(np.float32)
- reflection_specular = np.interp(wavelengths, surface.reflection_specular[:,0], surface.reflection_specular[:,1]).astype(np.float32)
+ absorption = np.interp(standard_wavelengths, surface.absorption[:,0], surface.absorption[:,1]).astype(np.float32)
+ reflection_diffuse = np.interp(standard_wavelengths, surface.reflection_diffuse[:,0], surface.reflection_diffuse[:,1]).astype(np.float32)
+ reflection_specular = np.interp(standard_wavelengths, surface.reflection_specular[:,0], surface.reflection_specular[:,1]).astype(np.float32)
surface.absorption_gpu = cuda.to_device(absorption)
surface.reflection_diffuse_gpu = cuda.to_device(reflection_diffuse)
@@ -236,21 +239,21 @@ class Geometry(object):
set_surface(np.int32(i), surface.absorption_gpu, surface.reflection_diffuse_gpu, surface.reflection_specular_gpu, block=(1,1,1), grid=(1,1))
- material1_index_tex = module.get_texref('material1_lookup')
- material2_index_tex = module.get_texref('material2_lookup')
- surface_index_tex = module.get_texref('surface_lookup')
+ self.material1_index_tex = module.get_texref('material1_lookup')
+ self.material2_index_tex = module.get_texref('material2_lookup')
+ self.surface_index_tex = module.get_texref('surface_lookup')
- material1_index_gpu = cuda.to_device(self.material1_index)
- material2_index_gpu = cuda.to_device(self.material2_index)
- surface_index_gpu = cuda.to_device(self.surface_index)
+ self.material1_index_gpu = cuda.to_device(self.material1_index)
+ self.material2_index_gpu = cuda.to_device(self.material2_index)
+ self.surface_index_gpu = cuda.to_device(self.surface_index)
- material1_index_tex.set_address(material1_index_gpu, self.material1_index.nbytes)
- material2_index_tex.set_address(material2_index_gpu, self.material2_index.nbytes)
- surface_index_tex.set_address(surface_index_gpu, self.surface_index.nbytes)
+ self.material1_index_tex.set_address(self.material1_index_gpu, self.material1_index.nbytes)
+ self.material2_index_tex.set_address(self.material2_index_gpu, self.material2_index.nbytes)
+ self.surface_index_tex.set_address(self.surface_index_gpu, self.surface_index.nbytes)
- material1_index_tex.set_format(cuda.array_format.SIGNED_INT32, 1)
- material2_index_tex.set_format(cuda.array_format.SIGNED_INT32, 1)
- surface_index_tex.set_format(cuda.array_format.SIGNED_INT32, 1)
+ self.material1_index_tex.set_format(cuda.array_format.SIGNED_INT32, 1)
+ self.material2_index_tex.set_format(cuda.array_format.SIGNED_INT32, 1)
+ self.surface_index_tex.set_format(cuda.array_format.SIGNED_INT32, 1)
vertices = np.empty(len(self.mesh.vertices), dtype=gpuarray.vec.float4)
vertices['x'] = self.mesh.vertices[:,0]