Ejemplo n.º 1
0
    def __init__(self, rend, event):
        self.rend = rend
        self.event = event

        self.rend.ortho()
        self.rend.origin()

        self.updates = []

        yellow = material.mat().color(vector3(1, 1, 0))
        orange = material.mat().color(vector3(1, 0.6, 0))

        verts = [vector2(100, 320), vector2(90, 310), vector2(100, 300), vector2(110, 310)]

        o = obj.base(verts)
        o.set_velocity(vector2(4.0, 0, 0))
        o.create_draw(False)
        o.draw.state.material = yellow

        self.updates.append(o)
        self.rend.add_draw(o.draw)

        verts = [v + vector2(30, 5) for v in verts]
        o = obj.base(verts)
        o.set_velocity(vector2(0.0, 0, 0))
        o.create_draw(False)
        o.draw.state.material = orange

        self.updates.append(o)
        self.rend.add_draw(o.draw)
Ejemplo n.º 2
0
 def __init__(self, center, radius, material=None):
     """initializes a Sphere
         @center is the center of the sphere as point
         @radius is the radius of the sphere
     """
     self.center = center
     self.radius = radius
     self.material = material if material else mat()
Ejemplo n.º 3
0
    def __init__(self, a, b, c, material=None):
        #Points
        self.a = a
        self.b = b
        self.c = c
        #Vectors
        self.u = np.subtract(self.b, self.a)
        self.v = np.subtract(self.c, self.a)

        self.material = material if material else mat()
Ejemplo n.º 4
0
def mater2voxel(mat_list, cell_map, volumes):
    """ Generate a material distribution in a mesh, given a material list mat_list and a cell map
    cell_map and a volumes matrix."""
    import material as mat
    cell_total = cell_map.sum(axis=3).todense()
    iints, jints, kints = cell_map.shape[0:3]
    lvoxel = np.dtype([('voxel_ID',int), ('i',int), ('j',int), ('k',int), ('Material',object),
                       ('RoA',float), ('RoG',float), ('volume',float)])
    voxel_comp_index = np.zeros((iints*jints*kints),dtype=lvoxel)
    voxel_ID = 0
    mat_list_sorted = {}  # Dictionary for cells.
    print ("Creating cell material dictionary")
    for m in mat_list:
        i = m['C']
        mat_list_sorted[i] = m
    print ("Created cell material dictionary")
    for i, j, k in np.ndindex(iints, jints, kints):
        if voxel_ID %1e4 == 0:
            print(voxel_ID)
        volume = volumes[i, j, k]
        sint_RoA = 0
        sint_RoG = 0
        sint_mat = mat.mat(voxel_ID)
        if cell_total[i][j][k] == 0:
            print("WARNING: Voxel {0} {1} {2} has no data!!".format(i, j, k))
            sint_mat.N = []
            sint_mat.M = []
        else:
            cells_ijk = cell_map[i, j, k].coords[0]
            data_ijk = cell_map[i, j, k].data
            lista_isotopes_comp=[]
            for cel, data in zip(cells_ijk, data_ijk):
                addedmat = mat_list_sorted[cel]['Material']
                for index, isotope in enumerate(addedmat.N):
                    if isotope not in lista_isotopes_comp:
                        lista_isotopes_comp.append((isotope, addedmat.M[index]*data))
                    else:
                        isoindex = lista_isotopes_comp[0].index(isotope) # Find the first (and should be only) isotope that matches
                        lista_isotopes_comp[isoindex][1] = lista_isotopes_comp[isoindex]+addedmat.M[index]*data

                sint_RoA = sint_RoA + data*mat_list_sorted[cel]['RoA']/cell_total[i, j, k]
                sint_RoG = sint_RoG + data*mat_list_sorted[cel]['RoG']/cell_total[i, j, k]
                sint_mat.N = [int(iso[0]) for iso in lista_isotopes_comp]
                sint_mat.M = [float(iso[1]) for iso in lista_isotopes_comp]
#            linea=np.array((voxel_ID,i,j,k,sint_mat,sint_RoA,sint_RoG,volume),dtype=lvoxel)
#            print(linea)
        sint_mat.normalize()
        voxel_comp_index[voxel_ID]=(voxel_ID, i, j, k, sint_mat, sint_RoA, sint_RoG, volume)
        voxel_ID += 1
    return voxel_comp_index  #We are done
Ejemplo n.º 5
0
s = hf.normalize(np.cross(f, up))  #x coordiante
u = np.cross(s, f)  #y coordinate

#intern camera parameters
alpha = np.deg2rad(FOV) / 2.0
viewheight = 2 * np.tan(alpha)  #heigth of viewport
viewWidth = ASPRATIO * viewheight  #width of viewport

pixelWidth = viewWidth / WIDTH  #width of a pixel
pixelHeigth = viewheight / HEIGHT  #height of a pixel
"""init scene"""
objectList = []
if MODE == 6:
    objectList.append(
        Sphere(hf.cVector(0, 5, 20), 2,
               mat(hf.cVector(0, 0, 255), 32, 1, 0.7, 0.1)))
    objectList.append(
        Sphere(hf.cVector(-1, 1, 5), 0.2,
               mat(hf.cVector(255, 100, 0), 1, 0.2, 0.3, 0.4)))
    objectList.append(
        Sphere(hf.cVector(-1, -4, 3), 1,
               mat(hf.cVector(255, 70, 30), 1, 0.2, 0.3, 0.4)))
    objectList.append(
        Sphere(hf.cVector(-1, 1, 2), 0.2,
               mat(hf.cVector(30, 240, 24), 1, 0.2, 0.3, 0.4)))
    objectList.append(
        Sphere(hf.cVector(4, 2, 10), 3,
               mat(hf.cVector(100, 0, 255), 20, 0.6, 0.9, 0.1)))
    objectList.append(
        Triangle(hf.cVector(1, 4, 20), hf.cVector(3, -6, 20),
                 hf.cVector(-2.5, -2, 20),