Ejemplo n.º 1
0
void read_dem_header ( image<short> & dem )
{
    char file[1000];
    GDALDataset  *df;
    GDALRasterBand *bd;
    double        trans[6];
    int rows, cols;

    strcpy ( file, p.value("dem_file").c_str());
    if ( strlen(file) == 0 ) {
        fprintf(stderr,"Need to specify a dem file\n");
        exit(1);
    }

    df = (GDALDataset *) GDALOpen( file, GA_ReadOnly );
    if( df == NULL ) {
        fprintf(stderr,"Could not open dem file: %s\n", file );
        exit(1);
    }
    rows = df->GetRasterYSize();
    cols = df->GetRasterXSize();
    dem.create(rows,cols);

    if( df->GetGeoTransform( trans ) == CE_None ) {
        dem_east = trans[0];
        dem_north = trans[3];
        dem_wid = trans[1];
    } else {
        fprintf(stderr,"Dem file: %s has no geographic metadata\n", file );
        exit(1);
    }

    delete df;
}
Ejemplo n.º 2
0
void output_dist_geotiff ( image<float> & dist, image<unsigned char> & v )
{
    int r, c;
    int val;
    OGRSpatialReference ref;
    GDALDataset  *df;
    char *wkt = NULL;
    GDALRasterBand *bd;
    double        trans[6];
    GDALDriver   *gt;
    char         **options = NULL;
    int          ov[] = { 2, 4, 8, 16, 32 };
    int          nov;
    int          n;
    char         file[1000];

    options = CSLSetNameValue ( options, "TILED", "NO" );
    options = CSLSetNameValue ( options, "COMPRESS", "LZW" );

    gt = GetGDALDriverManager()->GetDriverByName("GTiff");
    if ( !gt ) {
        fprintf(stderr,"Could not get GTiff driver\n");
        exit(1);
    }

    strcpy ( file, p.value("dist_file").c_str() );
    df = gt->Create( file, dist.cols, dist.rows, 1, GDT_Byte, options );
    if( df == NULL ) {
        fprintf(stderr,"Could not create %s\n", file );
        exit(1);
    }

    trans[0] = p.dvalue("easting_left");
    trans[1] = p.dvalue("output_cell_size");
    trans[2] = 0.0;
    trans[3] = p.dvalue("northing_top");
    trans[4] = 0.0;
    trans[5] = -p.dvalue("output_cell_size");
    df->SetGeoTransform ( trans );
    ref.SetUTM ( p.ivalue("utm_zone") );
    ref.SetWellKnownGeogCS ( "NAD27" );
    ref.exportToWkt ( &wkt );
    df->SetProjection(wkt);
    CPLFree ( wkt );

    for ( r=0; r < dist.rows; r++ ) {
        for ( c=0; c < dist.cols; c++ ) {
            val = int(sqrt(dist[r][c])+0.5);
            if ( val > 255 ) val = 255;
            v[r][c] = val;
        }
    }

    bd = df->GetRasterBand(1);
    bd->RasterIO( GF_Write, 0, 0, v.cols, v.rows, v.data,
                  v.cols, v.rows, GDT_Byte, 0, 0 );

    delete df;

    df = (GDALDataset *)GDALOpen ( file, GA_Update );
    if( df == NULL ) {
        fprintf(stderr,"Could not open for update %s\n", file );
        exit(1);
    }
    nov = p.ivalue("overviews");
    if ( nov > 5 ) nov = 5;
    if ( nov > 0 ) {
        n = 1;
        df->BuildOverviews("NEAREST", nov, ov, 1, &n, NULL, NULL );
    }

}
Ejemplo n.º 3
0
void output_geotiff ( rgb_image & out )
{
    int i, r, c;
    int val;
    char s[2];
    OGRSpatialReference ref;
    GDALDataset  *df;
    char *wkt = NULL;
    GDALRasterBand *bd;
    double        trans[6];
    GDALDriver   *gt;
    char         **options = NULL;
    int          ov[] = { 2, 4, 8, 16, 32 };
    int          nov;
    int          n;
    int          bands[] = { 1, 2, 3 };
    char         file[1000];
    int          block, ir, rows;

    options = CSLSetNameValue ( options, "TILED", "NO" );
    options = CSLSetNameValue ( options, "BLOCKXSIZE", "256" );
    options = CSLSetNameValue ( options, "BLOCKYSIZE", "256" );
    options = CSLSetNameValue ( options, "COMPRESS", "LZW" );

    gt = GetGDALDriverManager()->GetDriverByName("GTiff");
    if ( !gt ) {
        fprintf(stderr,"Could not get GTiff driver\n");
        exit(1);
    }

    strcpy ( file, p.value("output_file").c_str() );
    df = gt->Create( file, out.cols, out.rows, 3, GDT_Byte, options );
    if( df == NULL ) {
        fprintf(stderr,"Could not create %s\n", file );
        exit(1);
    }

    trans[0] = p.dvalue("easting_left");
    trans[1] = p.dvalue("output_cell_size");
    trans[2] = 0.0;
    trans[3] = p.dvalue("northing_top");
    trans[4] = 0.0;
    trans[5] = -p.dvalue("output_cell_size");
    df->SetGeoTransform ( trans );
    ref.SetUTM ( p.ivalue("utm_zone") );
    ref.SetWellKnownGeogCS ( "NAD27" );
    ref.exportToWkt ( &wkt );
    df->SetProjection(wkt);
    CPLFree ( wkt );

    for ( ir = 0; ir < out.rows; ir += bs ) {
        rows = out.rows - ir;
        if ( rows > bs ) rows = bs;
        //printf("Writer waiting for %d\n",ir );
        pe.wait_for("data",ir);
        for ( i = 0; i < 3; i++ ) {
            bd = df->GetRasterBand(i+1);
            bd->RasterIO( GF_Write, 0, ir, out.cols, rows,
                          out.img[i].data+ir*out.cols,
                          out.cols, rows, GDT_Byte, 0, 0 );
        }
    }

    delete df;

    df = (GDALDataset *)GDALOpen ( file, GA_Update );
    if( df == NULL ) {
        fprintf(stderr,"Could not open for update %s\n", file );
        exit(1);
    }
    nov = p.ivalue("overviews");
    if ( nov > 5 ) nov = 5;
    if ( nov > 0 ) {
        df->BuildOverviews("NEAREST", nov, ov, 3, bands, NULL, NULL );
    }

}
Ejemplo n.º 4
0
void read_image_file(image<short> & img)
{
    double camera_roll, camera_pitch, camera_yaw;
    FILE *fp;
    rgb_image rgb, *q;
    double east, north, alt;
    img_map::iterator i;
    vec3 utm(0,0,0), x(1,0,0), y(0,1,0), z(0,0,1);
    mat4 trans, roll, pitch, yaw;

    camera_roll = p.dvalue("camera_roll");
    camera_pitch = p.dvalue("camera_pitch");
    camera_yaw = p.dvalue("camera_yaw");
    fp = fopen ( p.value("images_file").c_str(), "r" );

    if ( !fp ) {
        fprintf(stderr,"Could not open images file: %s\n",
                p.value("images_file").c_str() );
        exit(1);
    }

    xy[0][0] = -2*img.rows;
    xy[0][1] = -2*img.cols;

    while ( rgb.read_params(fp) ) {
        if ( rgb.id > max_img_id ) max_img_id = rgb.id;
        imgs[rgb.id] = rgb;
    }
    fclose(fp);

    img_indices = new int[max_img_id+1];

    sea_level = p.dvalue("sea_level");
    i = imgs.begin();
    while ( i != imgs.end() ) {
        q = &i->second;
        q->create_image(input_rows,input_cols);
        //printf("%s\n", q->pathname.c_str());
        //printf("%d %10.2f %10.2f %7.2f %7.2f %7.2f %7.2f\n",p->id,
                //p->east, p->north, p->alt,
                //p->omega, p->phi, p->kappa );
        img_indices[img_ct] = q->id;
        img_ct++;
        utm[0]=q->east;
        utm[1]=q->north;
        trans = translation3D(utm);
        pitch = rotation3D ( x, q->omega);
        roll = rotation3D ( y, q->phi);
        yaw = rotation3D ( z, q->kappa);
        q->M = pitch;
        q->M = q->M * roll;
        q->M = q->M * yaw;
        q->zrot = -1.0 * z;
        q->zrot = q->M * q->zrot;
        q->M = trans;
        q->M = q->M * pitch;
        q->M = q->M * roll;
        q->M = q->M * yaw;
        q->MI = q->M.inverse();
        q->unit_depth = p.dvalue("focal_length")*1000.0/p.dvalue("pixel_size");
        q->cam = utm;
        q->cam[2] = 0;
        i++;
    }
}