コード例 #1
0
ファイル: app.py プロジェクト: KotsMikhail/OpticalSystem
    def run(self):
        self.up_plane_process.start()
        self.down_plane_process.start()
        self.plane_3_process.start()
        self.plane_4_process.start()
        tee = self.periscope.target

        exit_app = False
        iteration = 0
        while not exit_app:
            p1_intersect = self.periscope.laser.intersect_plane(self.periscope.mirror_down.triangle)
            p2_intersect = self.periscope.laser.reflect_plane(self.periscope.mirror_down.triangle). \
                intersect_plane(self.periscope.mirror_up.triangle)
            p3_intersect = self.periscope.laser.reflect_plane(self.periscope.mirror_down.triangle). \
                reflect_plane(self.periscope.mirror_up.triangle).intersect_plane(self.periscope.mirror_3.triangle)
            p4_intersect = self.periscope.laser.reflect_plane(self.periscope.mirror_down.triangle). \
                reflect_plane(self.periscope.mirror_up.triangle).reflect_plane(self.periscope.mirror_3.triangle). \
                intersect_plane(self.periscope.mirror_4.triangle)
            p_aim = self.periscope.ray_to_aim().intersect_plane(
                Triangle(Point3d(tee.location.x, 0.5, 0.2),
                         Point3d(tee.location.x, 0.4, 0.1),
                         Point3d(tee.location.x, 0.3, 0.5)
                         ))
            p_aim_2 = self.periscope.ray_to_aim().intersect_plane(
                Triangle(Point3d(self.periscope.target_2.location.x, 0.5, 0.2),
                         Point3d(self.periscope.target_2.location.x, 0.4, 0.1),
                         Point3d(self.periscope.target_2.location.x, 0.3, 0.5)
                         ))
            self.renderer.render(p1_intersect, p2_intersect, p3_intersect, p4_intersect, tee, self.periscope.target_2,
                                 p_aim, p_aim_2)

            exit_app, need_rebuild = self.__move_target()

            if need_rebuild:
                self.down_plane_queue.put(self.periscope.target)
                self.up_plane_queue.put(self.periscope.target)
                self.plane_3_queue.put(self.periscope.target)
                self.plane_4_queue.put(self.periscope.target)

                self.update_log(iteration, p_aim)
                iteration += 1

            self.apply_changes(self.periscope.mirror_down.triangle, self.down_plane_points)
            self.apply_changes(self.periscope.mirror_up.triangle, self.up_plane_points)
            self.apply_changes(self.periscope.mirror_3.triangle, self.plane_3_points)
            self.apply_changes(self.periscope.mirror_4.triangle, self.plane_4_points)
            # update log

        self.up_plane_process.terminate()
        self.down_plane_process.terminate()
        self.plane_3_process.terminate()
        self.plane_4_process.terminate()
        self.write_log()
        exit()
コード例 #2
0
ファイル: app.py プロジェクト: DuhastMish/Computer_Network
    def __init__(self, input_model: str = '2d'):
        self.log_list = []
        pygame.init()
        self.input_model = input_model
        config = parse(input_model)

        self.periscope: Periscope = Periscope(config)
        p_target = self.periscope.ray_to_aim().intersect_plane(
            Triangle(Point3d(0.2, 0.5, 0.2),
                     Point3d(0.2, 0.4, 0.1),
                     Point3d(0.2, 0.3, 0.5)
                     ))
        tee = Target(p_target, config["target_radius"])
        self.periscope.set_target(tee)

        self.renderer = Renderer(self.periscope)

        # Shared memory
        self.down_plane_points = mp.Array('d', 6)
        self.up_plane_points = mp.Array('d', 6)
        self.__init_share_memory()

        self.up_plane_queue = mp.Queue()
        self.down_plane_queue = mp.Queue()

        self.up_plane_process: mp.Process = mp.Process(
            target=DirectAlgorithm.plane_direct_process,
            args=(self.up_plane_queue, self.up_plane_points, self.periscope, MirrorLocation.UP))
        self.down_plane_process: mp.Process = mp.Process(
            target=DirectAlgorithm.plane_direct_process,
            args=(self.down_plane_queue, self.down_plane_points, self.periscope, MirrorLocation.DOWN))
コード例 #3
0
ファイル: app.py プロジェクト: KoDim97/Computer_Network
 def apply_changes(plane: Triangle, arr: mp.Array):
     plane.point_b = Point3d(arr[0], arr[1], arr[2])
     plane.point_c = Point3d(arr[3], arr[4], arr[5])
コード例 #4
0
ファイル: app.py プロジェクト: KoDim97/Computer_Network
    def __init__(
        self,
        input_model: str = '2d',
        algorithm: SolveAlgorithm = SolveAlgorithm.DIRECT,
        mode: str = '',
    ):
        self.log_list = []
        pygame.init()
        self.input_model = input_model
        self.mode = mode
        config = parse(input_model)

        self.periscope: Periscope = Periscope(config)
        p_target = self.periscope.ray_to_aim().intersect_plane(
            Triangle(Point3d(0.4, 0.7, 0.2), Point3d(0.5, 0.4, 0.1),
                     Point3d(0.2, 0.6, 0.5)))
        p_target = Point3d(0.62, 0.66, 0)
        tee = Target(p_target, config["target_radius"])
        self.periscope.set_target(tee)

        self.renderer = Renderer(self.periscope)

        # Shared memory
        self.down_plane_points = mp.Array('d', 6)
        self.up_plane_points = mp.Array('d', 6)
        self.plane_3_points = mp.Array('d', 6)
        self.__init_share_memory()

        self.up_plane_queue = mp.Queue()
        self.down_plane_queue = mp.Queue()
        self.plane_3_queue = mp.Queue()

        if algorithm == SolveAlgorithm.DIRECT:
            self.up_plane_process: mp.Process = mp.Process(
                target=DirectAlgorithm.plane_direct_process,
                args=(self.up_plane_queue, self.up_plane_points,
                      self.periscope, MirrorLocation.UP))
            self.down_plane_process: mp.Process = mp.Process(
                target=DirectAlgorithm.plane_direct_process,
                args=(self.down_plane_queue, self.down_plane_points,
                      self.periscope, MirrorLocation.DOWN))
            self.plane_3_process: mp.Process = mp.Process(
                target=DirectAlgorithm.plane_direct_process,
                args=(self.plane_3_queue, self.plane_3_points, self.periscope,
                      MirrorLocation.THIRD))
        else:  # algorithm == SolveAlgorithm.NEURAL_NET:
            from keras.models import load_model
            from src.algorithms.net import NeuralNetAlgorithm
            model = load_model(
                str(get_project_root()) + '\\src\\neuralnet\\' +
                self.input_model + '_model.h5')
            self.up_plane_process: mp.Process = mp.Process(
                target=NeuralNetAlgorithm.run,
                args=(self.up_plane_queue, self.up_plane_points,
                      self.periscope, MirrorLocation.UP, model))
            self.down_plane_process: mp.Process = mp.Process(
                target=NeuralNetAlgorithm.run,
                args=(self.down_plane_queue, self.down_plane_points,
                      self.periscope, MirrorLocation.DOWN, model))
            self.plane_3_process: mp.Process = mp.Process(
                target=NeuralNetAlgorithm.run,
                args=(self.plane_3_queue, self.plane_3_points, self.periscope,
                      MirrorLocation.THIRD, model))
コード例 #5
0
    def run(self):
        self.up_plane_process.start()
        self.down_plane_process.start()
        tee = self.periscope.target
        prev_tee = self.periscope.prev_target

        str_down = f'sending 1st target coord: {self.periscope.target.get_description()} to down plane process by ' + mp.process.current_process(
        ).name + '\n'
        print(str_down)
        with open('первый_опыт.txt', 'a') as f:
            f.write(str_down)
        self.down_plane_queue.put(self.periscope.target)  # send

        str_up = f'sending 1st target coord: {self.periscope.target.get_description()} to up plane process by ' + mp.process.current_process(
        ).name + '\n'
        print(str_up)
        with open('первый_опыт.txt', 'a') as f:
            f.write(str_up)
        self.up_plane_queue.put(self.periscope.target)  # send

        exit_app = False
        iteration = 0
        max_iteration = 4
        sleep_time = 2
        while not exit_app and iteration <= max_iteration:

            p1_intersect = self.periscope.laser.intersect_plane(
                self.periscope.mirror_down.triangle)
            p2_intersect = self.periscope.laser.reflect_plane(self.periscope.mirror_down.triangle). \
                intersect_plane(self.periscope.mirror_up.triangle)
            p_aim = self.periscope.ray_to_aim().intersect_plane(
                Triangle(Point3d(tee.location.x, 0.5, 0.2),
                         Point3d(tee.location.x, 0.4, 0.1),
                         Point3d(tee.location.x, 0.3, 0.5)))
            self.renderer.render(p1_intersect, p2_intersect, tee, prev_tee,
                                 p_aim)

            if iteration == max_iteration:
                sleep(sleep_time)
                break

            self.update_log(iteration, p_aim, 'before move')
            exit_app, need_rebuild = self.__move_target(iteration)

            str_down = f'sending target coord: {self.periscope.target.get_description()} to down plane process by ' + mp.process.current_process(
            ).name + '\n'
            print(str_down)
            with open('первый_опыт.txt', 'a') as f:
                f.write(str_down)
            self.down_plane_queue.put(self.periscope.target)  # send

            str_up = f'sending target coord: {self.periscope.target.get_description()} to up plane process by ' + mp.process.current_process(
            ).name + '\n'
            print(str_up)
            with open('первый_опыт.txt', 'a') as f:
                f.write(str_up)
            self.up_plane_queue.put(self.periscope.target)  # send

            self.update_log(iteration, p_aim, 'after move')
            iteration += 1

            self.apply_changes(self.periscope.mirror_down.triangle,
                               self.down_plane_points)
            self.apply_changes(self.periscope.mirror_up.triangle,
                               self.up_plane_points)
            # update log
            sleep(sleep_time)

        self.up_plane_process.terminate()
        self.down_plane_process.terminate()
        self.write_log()
        exit()