Ejemplo n.º 1
0
 def __init__(self, scene=None, source=None, throws=1, steps=50, seed=None, use_visualiser=True, show_log=True, background=(0.957, 0.957, 1), ambient=0.5):
     super(Tracer, self).__init__()
     self.scene = scene
     from LightSources import SimpleSource, PlanarSource, CylindricalSource, PointSource, RadialSource
     self.source = source
     self.throws = throws
     self.steps = steps
     self.totalsteps = 0
     self.seed = seed
     self.killed = 0
     self.database = PhotonDatabase.PhotonDatabase()
     self.stats = dict()
     self.show_log = show_log
     np.random.seed(self.seed)
     if not use_visualiser:
         Visualiser.VISUALISER_ON = False
     else:
         Visualiser.VISUALISER_ON = True
     self.visualiser = Visualiser(background=background, ambient=ambient)
     
     for obj in scene.objects:
         if obj != scene.bounds:
             if not isinstance(obj.shape, CSGadd) and not isinstance(obj.shape, CSGint) and not isinstance(obj.shape, CSGsub):
             
                 if isinstance(obj.material, SimpleMaterial):
                     wavelength = obj.material.bandgap
                 else:
                     
                     if not hasattr(obj.material, 'all_absorption_coefficients'):
                         maxindex = obj.material.emission_data.y.argmax()
                         wavelength = obj.material.emission_data.x[maxindex]
                         colour = wav2RGB(wavelength)
                     else:
                         # It is possible to processes the most likley colour of a spectrum in a better way than this!
                         colour = [0.1,0.1,0.1]
                     
                     if colour[0] == np.nan or colour[1] == np.nan or colour[2] == np.nan:
                         colour = [0.1,0.1,0.1]
                     
                     self.visualiser.addObject(obj.shape, colour=colour)
                     
     self.show_lines = True#False
     self.show_exit = True
     self.show_path = True#False
     self.show_start = True
Ejemplo n.º 2
0
    def __init__(self,
                 scene=None,
                 source=None,
                 throws=1,
                 steps=50,
                 seed=None,
                 use_visualiser=True,
                 show_log=False,
                 background=(0.957, 0.957, 1),
                 ambient=0.5,
                 database_file="pvtracedb.sql"):
        super(Tracer, self).__init__()
        self.scene = scene
        from LightSources import SimpleSource, PlanarSource, CylindricalSource, PointSource, RadialSource
        self.source = source
        self.throws = throws
        self.steps = steps
        self.totalsteps = 0
        self.seed = seed
        self.killed = 0
        self.database = PhotonDatabase.PhotonDatabase(database_file)
        self.stats = dict()
        self.show_log = show_log
        np.random.seed(self.seed)
        if not use_visualiser:
            Visualiser.VISUALISER_ON = False
        else:
            Visualiser.VISUALISER_ON = True

        self.visualiser = Visualiser(background=background, ambient=ambient)

        # This should not happen here in the tracer... refactor this non-sense
        if VISUAL_INSTALLED:
            for obj in scene.objects:
                if obj != scene.bounds:
                    if not isinstance(obj.shape, CSGadd) and not isinstance(
                            obj.shape, CSGint) and not isinstance(
                                obj.shape, CSGsub):

                        #import pdb; pdb.set_trace()
                        if isinstance(obj, RayBin):
                            #checkerboard = ( (0,0.01,0,0.01), (0.01,0,0.01,0), (0,0.01,0,1), (0.01,0,0.01,0) )
                            #checkerboard = ( (0,1,0,1), (1,0,1,0), (0,1,0,1), (1,0,1,0) )
                            #material = visual.materials.texture(data=checkerboard, mapping="rectangular", interpolate=False)
                            material = visual.materials.wood
                            colour = visual.color.blue
                            opacity = 1.

                        elif isinstance(obj, Coating):

                            colour = visual.color.white
                            opacity = 0.5
                            material = visual.materials.plastic

                            if hasattr(obj.reflectivity, 'lambertian'):
                                if obj.reflectivity.lambertian is True:
                                    # The material is a diffuse reflector
                                    colour = visual.color.white
                                    opacity = 1.
                                    material = visual.materials.plastic

                        elif isinstance(obj.material, SimpleMaterial):
                            #import pdb; pdb.set_trace()
                            wavelength = obj.material.bandgap
                            colour = norm(wav2RGB(wavelength))
                            opacity = 0.5
                            material = visual.materials.plastic
                        else:

                            if not hasattr(obj.material,
                                           'all_absorption_coefficients'):
                                try:
                                    maxindex = obj.material.emission_data.y.argmax(
                                    )
                                    wavelength = obj.material.emission_data.x[
                                        maxindex]
                                    colour = norm(wav2RGB(wavelength))
                                except:
                                    colour = (0.2, 0.2, 0.2)

                                opacity = 0.5
                                material = visual.materials.plastic
                            else:
                                # It is possible to processes the most likley colour of a spectrum in a better way than this!
                                colour = (0.2, 0.2, 0.2)
                                opacity = 0.5
                                material = visual.materials.plastic

                            if colour[0] == np.nan or colour[
                                    1] == np.nan or colour[2] == np.nan:
                                colour = (0.2, 0.2, 0.2)

                        self.visualiser.addObject(obj.shape,
                                                  colour=colour,
                                                  opacity=opacity,
                                                  material=material)

        self.show_lines = True  #False
        self.show_exit = True
        self.show_path = True  #False
        self.show_start = True
        self.show_normals = False