contrib/gel/mrc/vpgl/algo/vpgl_nitf_camera_coverage.cxx
Go to the documentation of this file.
00001 #include "vpgl_nitf_camera_coverage.h"
00002 
00003 #include <vpgl/file_formats/vpgl_nitf_rational_camera.h>
00004 
00005 #include <vcl_iostream.h>
00006 #include <vcl_fstream.h>
00007 
00008 #include <vul/vul_awk.h>
00009 
00010 #include <vgl/vgl_polygon.h>
00011 
00012 bool vpgl_nitf_camera_coverage::coverage_list(vcl_vector<vgl_point_2d<double> > geo_pts,
00013                                               vcl_string img_list,
00014                                               vcl_string img_coverage_list)
00015 {
00016   vcl_ifstream ifs( img_list.c_str() );
00017   vcl_ofstream ofs( img_coverage_list.c_str() );
00018 
00019   if (!ifs)
00020   {
00021     vcl_cerr << "Error in vpgl_nitf_camera_coverage::coverage_list: Failed to open image list file\n";
00022     return false;
00023   }
00024 
00025   if (!ofs)
00026   {
00027     vcl_cerr << "Error in vpgl_nitf_camera_coverage::coverage_list: Failed to create output file\n";
00028     return false;
00029   }
00030 
00031   vul_awk awk(ifs);
00032   for (; awk; ++awk)
00033   {
00034     vcl_string img_file = awk.line();
00035 
00036     //load rational camera from image file
00037     vpgl_nitf_rational_camera *nitf_cam = new vpgl_nitf_rational_camera(img_file);
00038 
00039     if (!nitf_cam)
00040     {
00041       vcl_cerr << "Error in vpgl_nitf_camera_coverage::coverage_list: Failed to load NITF camera\n";
00042       return false;
00043     }
00044 
00045     //create a the coverage polygon-only one sheet.
00046     vgl_polygon<double> poly_region(1);
00047     poly_region.push_back(nitf_cam->upper_right()[0],nitf_cam->upper_right()[1]);
00048     poly_region.push_back(nitf_cam->upper_left()[0],nitf_cam->upper_left()[1]);
00049     poly_region.push_back(nitf_cam->lower_left()[0],nitf_cam->lower_left()[1]);
00050     poly_region.push_back(nitf_cam->lower_right()[0],nitf_cam->lower_right()[1]);
00051 
00052     bool contain = true;
00053 
00054     for ( unsigned i = 0; i<geo_pts.size(); i++)
00055     {
00056       contain = contain && poly_region.contains( vgl_point_2d<double>(
00057         geo_pts[i].x(), geo_pts[i].y() ) );
00058     }
00059 
00060     //If all the points aren't contained within the image region, continue to next image
00061     //otherwise add th image to the list file
00062     if (!contain) continue;
00063 
00064     ofs << img_file << '\n';
00065   }
00066 
00067   return true;
00068 }
00069 
00070 //Not implemented yet
00071 bool vpgl_nitf_camera_coverage::compute_coverage_region(vcl_string /*camera_list*/, vcl_string /*out_imfile*/)
00072 {
00073   return true;
00074 }