Beispiel #1
0
osg::ref_ptr<osg::Group> BuildGeoBoundsNode(std::string const &name,
                                            GeoBounds const &b,
                                            osg::Vec4 const &color,
                                            double min_angle,
                                            int level_offset)
{
    static const double k_eps = 1E-8;

    double const lon_delta = b.maxLon-b.minLon;
    double const lat_delta = b.maxLat-b.minLat;
    if((lon_delta < k_eps) ||
       (lat_delta < k_eps)) {
        osg::ref_ptr<osg::Group> gp = new osg::Group;
        gp->setName(name);
        return gp;
    }

    double const lon_div = (b.maxLon - b.minLon)/min_angle;
    double const lat_div = (b.maxLat - b.minLat)/min_angle;

    std::vector<osg::Vec3d> list_ecef;

    // left edge
    for(double lat=b.maxLat; lat >= b.minLat; lat-=lat_div) {
        LLA lla; lla.lon = b.minLon; lla.lat = lat; lla.alt = 0;
        list_ecef.push_back(ConvLLAToECEF(lla));
    }

    // bottom edge
    for(double lon=b.minLon; lon <= b.maxLon; lon+=lon_div) {
        LLA lla; lla.lon = lon; lla.lat = b.minLat; lla.alt = 0;
        list_ecef.push_back(ConvLLAToECEF(lla));
    }

    // right edge
    for(double lat=b.minLat; lat <= b.maxLat; lat+=lat_div) {
        LLA lla; lla.lon = b.maxLon; lla.lat = lat; lla.alt = 0;
        list_ecef.push_back(ConvLLAToECEF(lla));
    }

    // top edge
    for(double lon=b.maxLon; lon >= b.minLon; lon-=lon_div) {
        LLA lla; lla.lon = lon; lla.lat = b.maxLat; lla.alt = 0;
        list_ecef.push_back(ConvLLAToECEF(lla));
    }

    osg::ref_ptr<osg::Group> gp = BuildSurfacePolyNode(name,list_ecef,color,0.0,level_offset);

    return gp;
}
TileSetLLByPixelArea::Eval::Eval(GeoBounds const &bounds,
                                 osg::Matrixd const &mvp,
                                 double min_angle_degs)
{
    uint32_t lon_segments = std::max((bounds.maxLon-bounds.minLon)/min_angle_degs,1.0);
    uint32_t lat_segments = std::max((bounds.maxLat-bounds.minLat)/min_angle_degs,1.0);

    BuildEarthSurface(bounds.minLon,
                      bounds.maxLon,
                      bounds.minLat,
                      bounds.maxLat,
                      lon_segments,
                      lat_segments,
                      list_lla,
                      list_vx,
                      list_ix);

    // get the ndc for each vertex
    bool ok;
    list_ndc.reserve(list_vx.size());
    for(auto const &vx : list_vx) {
        list_ndc.push_back(ConvWorldToNDC(mvp,vx,ok));
    }

    // calculate the normals for each quad
    list_quad_nx.clear();
    list_quad_nx.reserve(list_ix.size()/6);
    for(size_t i=0; i < list_ix.size(); i+=6) {
        // 6 vx per quad (2 tris)
        // the normal of any tri == the quad normal
        // since this is a 'flat' quad
        osg::Vec3d const &v0 = list_vx[list_ix[i+0]];
        osg::Vec3d const &v1 = list_vx[list_ix[i+1]];
        osg::Vec3d const &v2 = list_vx[list_ix[i+2]];
        list_quad_nx.push_back((v1-v0)^(v2-v0));
        list_quad_nx.back().normalize();
    }

    // lon and lat planes
    plane_min_lon = CalcLonPlane(bounds.minLon,true,true);
    plane_max_lon = CalcLonPlane(bounds.maxLon,false,true);
    plane_min_lat = CalcLatPlane(bounds.minLat,false);
    plane_max_lat = CalcLatPlane(bounds.maxLat,true);

    // (mid lon,mid lat) ecef
    LLA lla_mid;
    lla_mid.lon = (bounds.minLon+bounds.maxLon)*0.5;
    lla_mid.lat = (bounds.minLat+bounds.maxLat)*0.5;
    lla_mid.alt = 0.0;
    ecef_mid = ConvLLAToECEF(lla_mid);
}
Beispiel #3
0
VxTile * BuildRootTile(uint8_t const level,
                       double const minLon,
                       double const minLat,
                       double const maxLon,
                       double const maxLat)
{
    VxTile * t = new VxTile;
    t->level = level;
    t->minLon = minLon;
    t->minLat = minLat;
    t->maxLon = maxLon;
    t->maxLat = maxLat;

    t->midLon = (minLon+maxLon)*0.5;
    t->midLat = (minLat+maxLat)*0.5;

    t->p_ecef_LT = new osg::Vec3d;
    *(t->p_ecef_LT) = ConvLLAToECEF(PointLLA(minLon,maxLat));

    t->p_ecef_LB = new osg::Vec3d;
    *(t->p_ecef_LB) = ConvLLAToECEF(PointLLA(minLon,minLat));

    t->p_ecef_RB = new osg::Vec3d;
    *(t->p_ecef_RB) = ConvLLAToECEF(PointLLA(maxLon,minLat));

    t->p_ecef_RT = new osg::Vec3d;
    *(t->p_ecef_RT) = ConvLLAToECEF(PointLLA(maxLon,maxLat));

    t->ecef_LM = ConvLLAToECEF(PointLLA(minLon,t->midLat));
    t->ecef_MB = ConvLLAToECEF(PointLLA(t->midLon,minLat));
    t->ecef_RM = ConvLLAToECEF(PointLLA(maxLon,t->midLat));
    t->ecef_MT = ConvLLAToECEF(PointLLA(t->midLon,maxLat));
    t->ecef_MM = ConvLLAToECEF(PointLLA(t->midLon,t->midLat));

    CalcTileOBB(t);

    return t;
}
Beispiel #4
0
std::unique_ptr<VxTile> BuildChildTile(VxTile * parent,
                                       uint8_t const quadrant)
{
    std::unique_ptr<VxTile> t(new VxTile);

    if(quadrant == 0) {
        // LT
        t->minLon = parent->minLon;
        t->maxLon = parent->midLon;
        t->minLat = parent->midLat;
        t->maxLat = parent->maxLat;

        t->p_ecef_LT = parent->p_ecef_LT;
        t->p_ecef_LB = &(parent->ecef_LM);
        t->p_ecef_RB = &(parent->ecef_MM);
        t->p_ecef_RT = &(parent->ecef_MT);
    }
    else if(quadrant == 1) {
        // LB
        t->minLon = parent->minLon;
        t->maxLon = parent->midLon;
        t->minLat = parent->minLat;
        t->maxLat = parent->midLat;

        t->p_ecef_LT = &(parent->ecef_LM);
        t->p_ecef_LB = parent->p_ecef_LB;
        t->p_ecef_RB = &(parent->ecef_MB);
        t->p_ecef_RT = &(parent->ecef_MM);
    }
    else if(quadrant == 2) {
        // RB
        t->minLon = parent->midLon;
        t->maxLon = parent->maxLon;
        t->minLat = parent->minLat;
        t->maxLat = parent->midLat;

        t->p_ecef_LT = &(parent->ecef_MM);
        t->p_ecef_LB = &(parent->ecef_MB);
        t->p_ecef_RB = parent->p_ecef_RB;
        t->p_ecef_RT = &(parent->ecef_RM);
    }
    else {
        // RT
        t->minLon = parent->midLon;
        t->maxLon = parent->maxLon;
        t->minLat = parent->midLat;
        t->maxLat = parent->maxLat;

        t->p_ecef_LT = &(parent->ecef_MT);
        t->p_ecef_LB = &(parent->ecef_MM);
        t->p_ecef_RB = &(parent->ecef_RM);
        t->p_ecef_RT = parent->p_ecef_RT;
    }

    t->level = parent->level + 1;
    t->midLon = (t->minLon+t->maxLon)*0.5;
    t->midLat = (t->minLat+t->maxLat)*0.5;

    t->ecef_LM = ConvLLAToECEF(PointLLA(t->minLon,t->midLat));
    t->ecef_MB = ConvLLAToECEF(PointLLA(t->midLon,t->minLat));
    t->ecef_RM = ConvLLAToECEF(PointLLA(t->maxLon,t->midLat));
    t->ecef_MT = ConvLLAToECEF(PointLLA(t->midLon,t->maxLat));
    t->ecef_MM = ConvLLAToECEF(PointLLA(t->midLon,t->midLat));

    CalcTileOBB(t.get());

    return t;
}