Exemplo n.º 1
0
QcTileSpecSet
QcMapViewLayer::intersec_polygon_with_grid(const QcPolygon & polygon, double tile_length_m, int zoom_level)
{
  QcTileSpecSet visible_tiles;
  QcTiledPolygon tiled_polygon = transform_polygon(polygon).intersec_with_grid(tile_length_m);
  int number_of_tiles = 1 << zoom_level; // Fixme: cf. tile_matrix_set
  QcIntervalInt valid_interval(0, number_of_tiles -1);
  for (const QcTiledPolygonRun & run: tiled_polygon.runs()) {
    QcIntervalInt run_interval = run.interval(); // const &
    int y = run.y();
    // qInfo() << "Run " << run.y() << " [" << run_interval.inf() << ", " << run_interval.sup() << "]";
    if (!valid_interval.contains(y)) {
      // It arises at large zoom, when the item eight is larger than the map.
      // qWarning() << "Tile columns is out of range" << y;
      y = qMax(qMin(y, number_of_tiles -1), 0); // Fixme: to func
    }
    // It arises when the polygon vertexes are at the border
    if (run_interval.sup() >= number_of_tiles)
      run_interval.set_sup(valid_interval.sup());
    // if (!run_interval.is_included_in(valid_interval)) {
    //   // qWarning() << "Tile row is out of range" << run_interval;
    //   run_interval &= valid_interval;
    // }
    for (int x = run_interval.inf(); x <= run_interval.sup(); x++)
      visible_tiles.insert(m_plugin_layer->create_tile_spec(zoom_level, x, y));
  }
  return visible_tiles;
}
Exemplo n.º 2
0
static void render(struct widget *w)
{
    struct home_data *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[50];
    float d, a;
    struct point arrow_points[7] = { {-3, 0}, {-3, -6}, {3, -6}, {3, 0},
                                     {6, 0}, {0, 6}, {-6, 0} };
    struct polygon arrow = {
        .len = 7,
        .points = arrow_points,
    };

    if (priv->lock != HOME_LOCKED) {
        sprintf(buf, "No Home");
        draw_str(buf, 0, 0, ca, 2);
    } else {
        switch (get_units(w->cfg)) {
            case UNITS_METRIC:
            default:
                sprintf(buf, "Alt %dm\nDis %dm\n%d",
                        priv->altitude,
                        (unsigned int) priv->distance,
                        priv->direction);
                break;
            case UNITS_IMPERIAL:
                a = (float) priv->altitude * M2FEET;
                d = (float) priv->distance * M2FEET;
                sprintf(buf, "Alt %df\nDis %df\n%d",
                        (unsigned int) a,
                        (unsigned int) d,
                        priv->direction);
                break;
        }

        draw_str(buf, 0, 0, ca, 1);

        transform_polygon(&arrow, 50, 34, priv->direction + 180);
        draw_polygon(&arrow, 3, ca);
        move_polygon(&arrow, -1, -1);
        draw_polygon(&arrow, 1, ca);
    }
}


const struct widget_ops home_info_widget_ops = {
    .name = "Home info",
    .mavname = "HOMEINF",
    .id = WIDGET_HOME_INFO_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Exemplo n.º 3
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[10];
    unsigned long d = (unsigned long) priv->home->distance;
    unsigned int r = (w->ca.width/2)-2;
    int x, y;
    int min_increment;
    long i, scale;
    struct point ils_points[5] = { {-4, -6}, {-4, 6}, {0, 10}, {4, 6}, {4, -6} };
    struct polygon ils = {
        .len = 5,
        .points = ils_points,
    };
    struct point uav_points[4] = { {0, 0}, {6, 8}, {0, -8}, {-6, 8} };
    struct polygon uav = {
        .len = 4,
        .points = uav_points,
    };

    struct polygon *p;

    x = (w->ca.width/2)-1;
    y = (w->ca.height/2)-1;


    draw_vline(x, 0, r*2, 2, ca);
    draw_hline(0, r*2, y, 2, ca);

    //draw_circle(x, y, r+1, 3, ca);
    draw_circle(x, y, r  , 2, ca);


    /* auto scale */
    switch (get_units(w->cfg)) {
    default:
    case UNITS_METRIC:
        min_increment = 500;
        scale = ((d / min_increment) + 1) * min_increment;
        sprintf(buf, "%um", (unsigned int) scale);
        break;
    case UNITS_IMPERIAL:
        d *= M2FEET;
        min_increment = 1000;
        scale = ((d / min_increment) + 1) * min_increment;
        if (d > 5000) {
            d = (d * 1000) / MILE2FEET;
            scale /= 1000;
            sprintf(buf, "%umi", (unsigned int) scale);
        } else {
            sprintf(buf, "%uf", (unsigned int) scale);
        }
        break;
    }

    draw_str(buf, 0, 0, ca, 0);

    i = (long) d * r;
    i /= scale;

    switch (w->cfg->props.mode >> 1) {
    case 0:
    default:
        /* radar fixed at uav heading, home moves */
        x += sin(DEG2RAD(priv->home->direction)) * i;
        y -= cos(DEG2RAD(priv->home->direction)) * i;
        transform_polygon(&ils, x, y, priv->stats->launch_heading - priv->heading - 180);
        p = &ils;
        break;
    case 1:
        /* radar always facing north, uav moves */
        x += sin(DEG2RAD(priv->home->uav_bearing)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing)) * i;
        transform_polygon(&uav, x, y, priv->heading);
        p = &uav;
        break;
    case 2:
        /* radar always facing launch direction, uav moves */
        x += sin(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i;
        transform_polygon(&uav, x, y, priv->heading - priv->stats->launch_heading);
        p = &uav;
        break;
    case 3:
        /* testing waypoints */
        /* radar always facing north, uav moves with waypoints */
        if (priv->wp_seq > 0) {
            long i_wp = (long) priv->wp_distance * r;
            i_wp /= scale;
            int x_wp = x, y_wp = y;
            x_wp += sin(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp;
            y_wp -= cos(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp;
            sprintf(buf, "%d", priv->wp_seq);
            draw_str(buf, x_wp, y_wp, ca, 0);
        }
        x += sin(DEG2RAD(priv->home->uav_bearing)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing)) * i;
        transform_polygon(&uav, x, y, priv->heading);
        p = &uav;
        break;
    }

    draw_polygon(p, 3, ca);
    move_polygon(p, -1, -1);
    draw_polygon(p, 1, ca);
}


const struct widget_ops radar_widget_ops = {
    .name = "Radar",
    .mavname = "RADAR",
    .id = WIDGET_RADAR_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Exemplo n.º 4
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    struct home_data *home = get_home_data();
    struct flight_stats *fstats = get_flight_stats();

    mavlink_attitude_t *att = mavdata_get(MAVLINK_MSG_ID_ATTITUDE);
    mavlink_vfr_hud_t *hud = mavdata_get(MAVLINK_MSG_ID_VFR_HUD);
    unsigned long d = (unsigned long) home->distance;
    unsigned int r = (w->ca.width/2)-2;
    u8 i;
    
    struct point ils_screen[5];
    struct point ils_points[5] = { {-35, -100}, {-35, 100}, {0, 130}, {35, 100}, {35, -100} };
    struct polygon ils = {
        .len = 5,
        .points = ils_points,
    };

    
    
    float x,y,z;
    
    eye.x = 0; //X_SIZE/2;
    eye.y = 0; //Y_SIZE/2;
    eye.z = 10;

    x = sin(DEG2RAD(home->direction)) * d;
    z = cos(DEG2RAD(home->direction)) * d;
    y = home->altitude;
    
    ls.x = (s32) x;
    ls.y = (s32) y;
    ls.z = (s32) z;
    
    if (ls.z <= 0)
        return;
    
    //ls.x = XX;
    //ls.y = YY;
    //ls.z = ZZ;
    
    eye.z = ZZ;
    
    p.x = (eye.z * (ls.x-eye.x)) / (eye.z + ls.z) + eye.x;
    p.y = (eye.z * (ls.y-eye.y)) / (eye.z + ls.z) + eye.y;
    
    draw_circle(X_SIZE/2 + p.x, Y_SIZE/2 + p.y, 5, 1, ca);

    
    transform_polygon(&ils, x, z,  - (fstats->launch_heading - hud->heading));
    for (i = 0; i < 5; i++) {
        ils_screen[i].x = (eye.z * (ils_points[i].x-eye.x)) / (eye.z + ils_points[i].y) + eye.x;
        ils_screen[i].y = (eye.z * (ls.y-eye.y)) / (eye.z + ils_points[i].y) + eye.y;
    }
    ils.points = ils_screen;
    transform_polygon(&ils, X_SIZE/2, Y_SIZE/2, 0);
    draw_polygon(&ils, 1, ca);

    
}

const struct widget_ops ils_widget_ops = {
    .name = "Imaginary LS",
    .mavname = "ILS",
    .id = WIDGET_ILS_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};