#!/usr/bin/python
"""Generate an empty geometry, with a single infinite medium"""
import sys
import array
import struct
import math
import Numeric
from tables import *

from local_modules import hdf5

Inf = 1e3000
Epsilon = 1e-3

triangles = []
norms = []
vertices = {}
bounds=[[-Inf,-Inf,-Inf],[Inf,Inf,Inf]]

levels = 5;
breaking_levels = 3;
N = Numeric.array([2,2,2]);
N3 = Numeric.array([2,2,2]*3)
result={"empty":0, "weird":0}

h5file = None



def dot(v, w):
    return v[0]*w[0] + v[1]*w[1] + v[2]*w[2]

# v and w are tuples representing 3d vectors
def cross(v, w):
    x = v[1]*w[2] - v[2]*w[1]
    y = v[2]*w[0] - v[0]*w[2]
    z = v[0]*w[1] - v[1]*w[0]
    return (x, y, z)



def idx_3d(n,level):
    return int( (n[2]*(N[1]^level)+n[1])*(N[0]^level)+n[0])


def add_triangle( tree, t):
    if "T" in tree:
        tree["T"].append(t)
    else:
        tree["T"]=[t]

# Generate a list with materials according to the definitions in
# localmodules.hdf5

def make_materials():
    m1 = hdf5.Material()
    m1.name     = "TestMat"
    m1.idnumber = 1
    m1.n        = 1.4
    m1.mu_s     = 7.95e3
    m1.mu_a     = 90
    m1.g        = 0.9
    
    return [m1]

def make_config():
    cfgs = []

    c1 = hdf5.Configuration()
    c1.idnumber  = 1
    c1.num_phots = 1e1
    c1.descr     = "Default"
    c1.bin_size  = 2e-4
    c1.f 	 = 16e-3
    c1.w0  	 = 1e-3
    c1.out_file  = "test/outtest.h5"
    c1.src_type  = "gaussian"
    c1.sim_type  = hdf5.sim_types["EXTRA"]    
    c1.src_dir   = (0, 0, 1)
    c1.src_pos   = (0, 0, -0.00399)
    c1.lambd  	 = 1310e-9
    c1.extra_params= 0
    c1.f         = 1e-1
    c1.w0        = 0.5e-3
    c1.first_mat = 0
    
    cfgs.append(c1)
    
    return cfgs



    

def main():
    if len(sys.argv) <> 2:
        print( "Usage: " + sys.argv[0] + " Testfile.h5")
        sys.exit(1)


    materials = make_materials()
    config = make_config();
    trs = hdf5.TriangleList2Numeric(triangles,bounds)
    trs.tree = hdf5.make_tree(trs.vertices,bounds);

    hdf5.write_file(sys.argv[1], materials, trs, config )    

if __name__ == "__main__":
    import profile
    profile.run('main()', 'fooprof')
