def draw_example():
     Draw.draw_intersection_calculation(
         42.495994, 3.442279,
         Triangulation.distance_between_coordinates_in_m(
             42.495994, 3.442279, 43.10572, 3.949412), 43.181071, 5.21284,
         Triangulation.distance_between_coordinates_in_m(
             43.181071, 5.21284, 43.10572, 3.949412), 43.355465, 3.828563,
         Triangulation.distance_between_coordinates_in_m(
             43.355465, 3.828563, 43.10572, 3.949412), 43.10572, 3.949412)
Ejemplo n.º 2
0
def main_lib(faces,
             vertices,
             output_fname,
             x_expand=1,
             y_expand=1,
             z_expand=1):
    """ Call the CSV to OBJ converter from a different functions,
    usually the batch converter """
    tr = Triangulation(faces, vertices)
    creator = tr.get_obj_creator()
    creator.create_obj_file(output_fname, x_expand, y_expand, z_expand)
Ejemplo n.º 3
0
def main_commandline():
    parser = create_parser()
    args = parser.parse_args()
    x_expand, y_expand, z_expand = 1, 1, 1
    if args.expand is not None:
        x_expand, y_expand, z_expand = [
            float(x) for x in args.expand.split(",")
        ]

    output_fname = args.output

    tr = Triangulation(args.faces, args.vertices)
    # tr.print_stats()

    creator = tr.get_obj_creator()
    creator.create_obj_file(output_fname, x_expand, y_expand, z_expand)
    print("\tDone!")
Ejemplo n.º 4
0
 def __init__(self, point):
     
     self._point = Point(point.id, point.x, point.y)
     self._points = [point]
     self._polygon = [(point.x, point.y)]
     self._triangulation = Triangulation(self._points)
     self._color = Coloring(self._points, self._triangulation)
     self.lock = threading.RLock()
     self.version = 0
def pretraitement(document):
    """
    pretraitement necessaire avant le tatouage ou la detection
    document = Doc ( carte )
    """
    global gms
    w = document
    tri = Triangulation(w)  # crée une triangulation du Doc
    get_sites(w, tri)  # crée les sites du Doc
    return (w, tri)
Ejemplo n.º 6
0
#!/usr/bin/env python
from forms import *

import json
from flask import render_template, request
from app import app
from triangulation import Triangulation
measure = Triangulation('./app/coordination')

@app.route('/')
@app.route('/index')
def index():
    return render_template('index.html')



@app.route('/getloc/', methods=['POST', 'GET'])
def getloc(jsonstring=None):
    data = json.loads(request.get_data())	
    print("receive data: ", data)
    response = measure.getCoord(data, need_meta=True)
    print("response:", response)
    #rep = json.loads(response)
    #measure.mycnt += 1
    #rep["cnt"] = measure.mycnt
    #response = json.dumps(rep)
    return response
Ejemplo n.º 7
0
class ArtGallery(object):
    """ This class resolves The art gallery problem. 
    It is a visibility problem in computational geometry.
    Guarding an art gallery with the minimum number of guards who together
    can observe the whole gallery
    """

    def __init__(self, point):
        
        self._point = Point(point.id, point.x, point.y)
        self._points = [point]
        self._polygon = [(point.x, point.y)]
        self._triangulation = Triangulation(self._points)
        self._color = Coloring(self._points, self._triangulation)
        self.lock = threading.RLock()
        self.version = 0
        
    @staticmethod
    def load(file_name):
        points = []
        with open(file_name, "r") as hfile:
            hfile.readline()
            i = 0
            for line in hfile:
                x, y = line.split()
                point = Point(i, Decimal(x), Decimal(y))
                i += 1
                points.append(point)
        return points

    def _update(self):
        self._points.sort()
        self._polygon = []
        for p in self._points:
            self._polygon.append((p.x, p.y))

    def get_polygon(self):
        with self.lock:
            return self._polygon

    def get_process_point(self):
        with self.lock:
            return self._point

    def get_points(self):
        with self.lock:
            return self._points

    def get_diagonals(self):
        with self.lock:
            return self._triangulation.get_diagonals()

    def get_min_color(self):
        with self.lock:
            return self._color.get_min_color()

    def is_guard(self, point):
        with self.lock:
            return point.color == self._color.get_min_color()

    def include(self, point):
        """ Add a new point to the art gallery """
        with self.lock:
            self._points.append(Point(point.id, point.x, point.y))
            self._update()
            triangulated = self._triangulation.process()
            if (triangulated):
                self._color.process()
            self.version += 1
    def aggregate(b1_path, b2_path, b3_path, p_path):
        """
        Parses CSV files and combines them into a tab with all relevant data
        :param b1_path: Beacon 1 file
        :param b2_path: Beacon 2 file
        :param b3_path: Beacon 3 file
        :param p_path: Diver file
        :return: Tab with format - timestamp - T° - Pression - coordonnee plongeur - profondeur (liee a la pression)
        """
        b1_timestamps = []
        b1_lats = []
        b1_longs = []
        b2_timestamps = []
        b2_lats = []
        b2_longs = []
        b3_timestamps = []
        b3_lats = []
        b3_longs = []
        p_timestamps = []
        p_temperatures = []
        p_pressures = []
        p_dists_with_b1 = []
        p_dists_with_b2 = []
        p_dists_with_b3 = []

        # Parse b1.csv
        with open(b1_path, 'r') as b1_data:
            row_reader = csv.reader(b1_data, delimiter=',', quotechar='|')
            for row in row_reader:
                line = []
                for data in row:
                    line.append(data)
                b1_timestamps.append(int(line[0]))
                b1_lats.append(float(line[1]))
                b1_longs.append(float(line[2]))

        # Parse b2.csv
        with open(b2_path, 'r') as b2_data:
            row_reader = csv.reader(b2_data, delimiter=',', quotechar='|')
            for row in row_reader:
                line = []
                for data in row:
                    line.append(data)
                b2_timestamps.append(int(line[0]))
                b2_lats.append(float(line[1]))
                b2_longs.append(float(line[2]))

        # Parse b3.csv
        with open(b3_path, 'r') as b3_data:
            row_reader = csv.reader(b3_data, delimiter=',', quotechar='|')
            for row in row_reader:
                line = []
                for data in row:
                    line.append(data)
                b3_timestamps.append(int(line[0]))
                b3_lats.append(float(line[1]))
                b3_longs.append(float(line[2]))

        # Parse p.csv
        with open(p_path, 'r') as p_data:
            row_reader = csv.reader(p_data, delimiter=',', quotechar='|')
            for row in row_reader:
                line = []
                for data in row:
                    line.append(data)
                p_timestamps.append(int(line[0]))
                p_temperatures.append(float(line[1]))
                p_pressures.append(float(line[2]))
                p_dists_with_b1.append(float(line[3]))
                p_dists_with_b2.append(float(line[4]))
                p_dists_with_b3.append(float(line[5]))

        # Build final tab
        # | timestamp | T° | Pression | coordonnée plongeur | profondeur (liée à la pression) |
        rich_tab = []
        for i in range(len(p_timestamps)):
            b1_index = Aggregator.find_minimum_gap_index(
                p_timestamps[i], b1_timestamps)
            b2_index = Aggregator.find_minimum_gap_index(
                p_timestamps[i], b2_timestamps)
            b3_index = Aggregator.find_minimum_gap_index(
                p_timestamps[i], b3_timestamps)
            point_depth = Triangulation.get_depth_from_pressure(
                pressure=p_pressures[i])
            diver_gps = Triangulation.triangulate(
                b1_lat=b1_lats[b1_index],
                b1_long=b1_longs[b1_index],
                b2_lat=b2_lats[b2_index],
                b2_long=b2_longs[b2_index],
                b3_lat=b3_lats[b3_index],
                b3_long=b3_longs[b3_index],
                horizontal_dist1=Triangulation.
                get_horizontal_dist_from_diag_and_depth(
                    diagonal_dist=p_dists_with_b1[i], depth=point_depth),
                horizontal_dist2=Triangulation.
                get_horizontal_dist_from_diag_and_depth(
                    diagonal_dist=p_dists_with_b2[i], depth=point_depth),
                horizontal_dist3=Triangulation.
                get_horizontal_dist_from_diag_and_depth(
                    diagonal_dist=p_dists_with_b3[i], depth=point_depth))
            rich_tab.append([
                p_timestamps[i], p_temperatures[i], p_pressures[i],
                diver_gps[0], diver_gps[1], point_depth
            ])

        print('Final tab :')
        for row in rich_tab:
            print(row)

        return rich_tab
Ejemplo n.º 9
0
from triangulation import Camera, Triangulation, InsufficientDataException
import numpy as np

if __name__ == "__main__":
    # Initialise cameras and enter normalized directional vector
    camera1 = Camera(np.array([250, -275, 84]))
    camera1.normalize_direction(np.array([-211.9, 225, 77, -84]))
    camera2 = Camera(np.array([250, 275, 84]))
    camera2.normalize_direction(np.array([-221.41, -223.62, -84]))
    camera3 = Camera(np.array([-250, 275, 84]))
    camera3.normalize_direction(np.array([203.077, -208.711, -84]))
    camera4 = Camera(np.array([-250, -275, 84]))
    camera4.normalize_direction(np.array([205.669, 216.506, -84]))

    triang = Triangulation([camera1, camera2, camera3, camera4])

    camera1.ball_pos = np.array([20, 60])
    camera2.ball_pos = np.array([-75, 50])
    camera3.ball_pos = np.array([48, 95])
    camera4.ball_pos = np.array([-47, 82])
    try:
        position = triang.calculate_position()
        print(position)
    except InsufficientDataException:
        print(
            "Position could not be found because of insufficient picture data")
    wait = input("Press enter to close")
Ejemplo n.º 10
0
        back_sub = data['Back_Sub']
        factor = data['Factor']
        res_x = data['Res_X']
        res_y = data['Res_Y']
        fps = data['FPS']
    except yaml.YAMLError as e:
        print(e)
        exit()

    # List of video sources
    source_list = []
    # List will contain points of the flying curve
    ball_curve = []
    position_list: List[List[int]] = []
    tracking = Tracking()
    triangulation = Triangulation()
    triangulation.FACTOR_X = 1 / factor
    triangulation.FACTOR_Y = 1 / factor

    # filename = "Battledork_180s_tonic-tradition__2021-05-30+18 40 33__{}.h264"
    print("Please enter the name of your files (replace number with '{}')")
    filename = input("File :")
    #filename = "Battledork_180s_tonic-tradition__2021-05-30+18:40:33__{}.mp4"

    frame_counter = 0

    print("Preparing cameras...")

    for i in range(NUM_CAMS):
        src = cv2.VideoCapture("videos/" + filename.format(i))
        source_list.append(src)
    def measure_new_vertices(self,
                             host,
                             port,
                             recover=False,
                             recover_i=0,
                             recover_j=0):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect((host, port))

        #TMC_DoMeasure(sock, 3, 2) # STOP
        #BAP_SetMeasPrg(sock, 5) # set continious
        #TMC_SetEdmMode(sock, 8) # CONT_REFLESS
        #TMC_DoMeasure(sock, 1, 2)

        COM_NullProc(sock)
        BAP_SetMeasPrg(sock, BAP_USER_MEASPRG.BAP_CONT_REF_STANDARD)
        BAP_SetTargetType(sock, 1)

        v_per_edge = 45
        max_distance = 20  # 1000
        yaws = (-np.pi * 0.6, 0.3)
        pitchs = (np.pi * 0.05, np.pi * 0.85)
        triangulation = Triangulation(v_per_edge, yaws[0], yaws[1], pitchs[0],
                                      pitchs[1])
        if recover:
            self._load_last_vertices()
        else:
            self.vertices = np.zeros((v_per_edge, v_per_edge, 3))
        for (i, j, yaw, pitch) in triangulation:
            if recover and (i != recover_i or j != recover_j):
                continue
            recover = False

            if i == 0 or i == v_per_edge - 1 or j == 0 or j == v_per_edge - 1:
                # edges
                self.vertices[i][j] = utils.sph_to_dec(yaw, pitch,
                                                       max_distance)
                continue

            retries = 2
            while retries > 0:
                AUT_MakePositioning(sock, yaw + random.uniform(-0.003, 0.003),
                                    pitch + random.uniform(-0.003, 0.003))
                point = BAP_MeasDistanceAngle(sock)
                if point['RC'] == 0:
                    point = point['P']
                    self.vertices[i][j] = utils.sph_to_dec(
                        point['dHz'], point['dV'], point['dDist'])
                    break
                elif retries > 1:
                    retries -= 1
                    print('bad response ' + str(point) + ', ' + str(retries) +
                          ' retries left')
                else:
                    retries -= 1
                    print('zero retries left, replacing the point')
                    self.vertices[i][j] = utils.sph_to_dec(
                        yaw, pitch, max_distance)
            print(i, j)
            np.save('vertices', self.vertices)

        self.vertices[0][0] = utils.sph_to_dec((yaws[0] + yaws[1]) * 0.5,
                                               (pitchs[0] + pitchs[1]) * 0.5,
                                               max_distance * 2)
        np.save('vertices', self.vertices)
        sock.close()
    def compute_fake_distances():
        """
        Computes the distances for fake coordinates
        :return: List of distances for each beacon
        """
        lats_b1 = [
            42.475537, 42.462165, 42.459861, 42.487563, 42.468548, 42.445896,
            42.495632, 42.458961, 42.464587, 42.431256, 42.459864, 42.485214,
            42.484562
        ]
        longs_b1 = [
            3.476611, 3.497214, 3.486521, 3.465423, 3.498541, 3.475632,
            3.475698, 3.482541, 3.476589, 3.463251, 3.463254, 3.485201,
            3.458900
        ]

        lats_b2 = [
            42.459861, 42.495632, 42.445896, 42.462165, 42.468548, 42.475537,
            42.487563, 42.485214, 42.464587, 42.484562, 42.431256, 42.459864,
            42.458961
        ]
        longs_b2 = [
            3.576611, 3.575632, 3.582541, 3.565423, 3.585201, 3.597214,
            3.575698, 3.586521, 3.576589, 3.598541, 3.563254, 3.563251,
            3.558900
        ]

        lats_b3 = [
            42.587563, 42.568548, 42.559861, 42.559864, 42.584562, 42.545896,
            42.595632, 42.562165, 42.564587, 42.531256, 42.525537, 42.585214,
            42.558961
        ]
        longs_b3 = [
            3.576611, 3.558900, 3.586521, 3.575632, 3.598541, 3.565423,
            3.575698, 3.585201, 3.576589, 3.563251, 3.563254, 3.597214,
            3.575406
        ]

        lats_p = [
            42.588544, 42.565214, 42.558523, 42.557459, 42.588456, 42.544587,
            42.591265, 42.563269, 42.561204, 42.530021, 42.523698, 42.581254,
            42.550789
        ]
        longs_p = [
            3.574569, 3.555524, 3.587894, 3.576532, 3.597854, 3.561022,
            3.572266, 3.589884, 3.577845, 3.562653, 3.567854, 3.596694,
            3.572235
        ]

        horizontal_distances_with_b1 = []
        horizontal_distances_with_b2 = []
        horizontal_distances_with_b3 = []
        for i in range(len(lats_b1)):
            horizontal_distances_with_b1.append(
                Triangulation.distance_between_coordinates_in_m(
                    lats_b1[i], longs_b1[i], lats_p[i], longs_p[i]))
            horizontal_distances_with_b2.append(
                Triangulation.distance_between_coordinates_in_m(
                    lats_b2[i], longs_b2[i], lats_p[i], longs_p[i]))
            horizontal_distances_with_b3.append(
                Triangulation.distance_between_coordinates_in_m(
                    lats_b3[i], longs_b3[i], lats_p[i], longs_p[i]))

        pressures = [
            1.2, 1.9, 2.6, 3.8, 4.7, 5.2, 5.6, 5.3, 4.9, 3.8, 2.5, 1.9, 1.1
        ]
        depths = []
        for i in pressures:
            depths.append(10 * (i - 1))

        diagonal_distances_with_b1 = []
        diagonal_distances_with_b2 = []
        diagonal_distances_with_b3 = []
        for i in range(len(depths)):
            diagonal_distances_with_b1.append(
                sqrt((depths[i] * depths[i]) +
                     (horizontal_distances_with_b1[i] *
                      horizontal_distances_with_b1[i])))
            diagonal_distances_with_b2.append(
                sqrt((depths[i] * depths[i]) +
                     (horizontal_distances_with_b2[i] *
                      horizontal_distances_with_b2[i])))
            diagonal_distances_with_b3.append(
                sqrt((depths[i] * depths[i]) +
                     (horizontal_distances_with_b3[i] *
                      horizontal_distances_with_b3[i])))

        print('Diagonal distances : ')
        for i in range(len(horizontal_distances_with_b1)):
            print('Diagonal : ' + str(diagonal_distances_with_b1[i]) +
                  ', horizontal : ' + str(horizontal_distances_with_b1[i]) +
                  ', vertical : ' + str(depths[i]))
        print('---')
        for i in range(len(horizontal_distances_with_b2)):
            print('Diagonal : ' + str(diagonal_distances_with_b2[i]) +
                  ', horizontal : ' + str(horizontal_distances_with_b2[i]) +
                  ', vertical : ' + str(depths[i]))
        print('---')
        for i in range(len(horizontal_distances_with_b3)):
            print('Diagonal : ' + str(diagonal_distances_with_b3[i]) +
                  ', horizontal : ' + str(horizontal_distances_with_b3[i]) +
                  ', vertical : ' + str(depths[i]))

        return [
            diagonal_distances_with_b1, diagonal_distances_with_b2,
            diagonal_distances_with_b3
        ]
                sqrt((depths[i] * depths[i]) +
                     (horizontal_distances_with_b3[i] *
                      horizontal_distances_with_b3[i])))

        print('Diagonal distances : ')
        for i in range(len(horizontal_distances_with_b1)):
            print('Diagonal : ' + str(diagonal_distances_with_b1[i]) +
                  ', horizontal : ' + str(horizontal_distances_with_b1[i]) +
                  ', vertical : ' + str(depths[i]))
        print('---')
        for i in range(len(horizontal_distances_with_b2)):
            print('Diagonal : ' + str(diagonal_distances_with_b2[i]) +
                  ', horizontal : ' + str(horizontal_distances_with_b2[i]) +
                  ', vertical : ' + str(depths[i]))
        print('---')
        for i in range(len(horizontal_distances_with_b3)):
            print('Diagonal : ' + str(diagonal_distances_with_b3[i]) +
                  ', horizontal : ' + str(horizontal_distances_with_b3[i]) +
                  ', vertical : ' + str(depths[i]))

        return [
            diagonal_distances_with_b1, diagonal_distances_with_b2,
            diagonal_distances_with_b3
        ]


if __name__ == '__main__':
    d = Triangulation().distance_between_coordinates_in_m(12, 3, 15, 9)
    print('Result : ' + str(d) + ' km.')
    diagonal_d = Coordinates().compute_fake_distances()