Permalink
Browse files

image2qtree: Factor out georeference loading in image2qtree

Every little bit out of the header helps compile times.
  • Loading branch information...
Zack Moratto
Zack Moratto committed Jun 1, 2012
1 parent 9c09b3b commit e25c74479a8aba069fff503244de01f05d3959ec
Showing with 52 additions and 39 deletions.
  1. +47 −0 src/vw/tools/image2qtree.cc
  2. +5 −39 src/vw/tools/image2qtree.h
@@ -82,6 +82,52 @@ void get_normalize_vals(boost::shared_ptr<DiskImageResource> file,
cout << "Pixel range for \"" << file->filename() << ": [" << new_lo << " " << new_hi << "] Output dynamic range: [" << lo_value << " " << hi_value << "]" << endl;
}
+std::vector<GeoReference>
+load_image_georeferences( const Options& opt, int& total_resolution ) {
+ std::vector<GeoReference> georeferences;
+ georeferences.reserve( opt.input_files.size() );
+
+ BOOST_FOREACH(const std::string filename, opt.input_files) {
+ boost::shared_ptr<DiskImageResource> file( DiskImageResource::open(filename) );
+ vw_out() << "Adding file " << file->filename() << std::endl;
+
+ if( opt.normalize ) get_normalize_vals(file, opt);
+
+ GeoReference input_georef = make_input_georef(file, opt);
+ georeferences.push_back( input_georef );
+
+ GeoReference output_georef(input_georef.datum());
+
+ // Right now, we only need a WGS84 output geoereference to compute
+ // the resolution. The rest of the output info will get set later.
+ GeoTransform geotx( input_georef, output_georef );
+
+ // Calculate the best resolution at 5 different points in the image,
+ // as occasionally there's a singularity at the center pixel that
+ // makes it extremely tiny (such as in pole-centered images).
+ const int cols = file->cols();
+ const int rows = file->rows();
+ Vector2 res_pixel[5];
+ res_pixel[0] = Vector2( cols/2, rows/2 );
+ res_pixel[1] = Vector2( cols/2 + cols/4, rows/2 );
+ res_pixel[2] = Vector2( cols/2 - cols/4, rows/2 );
+ res_pixel[3] = Vector2( cols/2, rows/2 + rows/4 );
+ res_pixel[4] = Vector2 (cols/2, rows/2 - rows/4 );
+ int resolution;
+ for(int i=0; i < 5; i++) {
+ resolution = compute_resolution(opt.mode, geotx, res_pixel[i]);
+ if( resolution > total_resolution ) total_resolution = resolution;
+ }
+ }
+
+ if(opt.global_resolution.set()) {
+ vw_out(VerboseDebugMessage) << "Overriding calculated resolution " << total_resolution << " with " << opt.global_resolution.value() << std::endl;
+ total_resolution = opt.global_resolution;
+ }
+
+ return georeferences;
+}
+
GeoReference make_input_georef(boost::shared_ptr<DiskImageResource> file,
const Options& opt) {
GeoReference input_georef;
@@ -129,6 +175,7 @@ GeoReference make_input_georef(boost::shared_ptr<DiskImageResource> file,
case Projection::STEREOGRAPHIC: input_georef.set_stereographic(opt.proj.lat,opt.proj.lon,opt.proj.scale); break;
case Projection::TRANSVERSE_MERCATOR: input_georef.set_transverse_mercator(opt.proj.lat,opt.proj.lon,opt.proj.scale); break;
case Projection::UTM: input_georef.set_UTM( abs(opt.proj.utm_zone), opt.proj.utm_zone > 0 ); break;
+ case Projection::DEFAULT:
case Projection::NONE: break;
}
View
@@ -212,6 +212,9 @@ vw::cartography::GeoReference
make_input_georef(boost::shared_ptr<vw::DiskImageResource> file,
const Options& opt);
+std::vector<vw::cartography::GeoReference>
+load_image_georeferences( const Options& opt, int& total_resolution );
+
template <class PixelT>
void do_mosaic(const Options& opt, const vw::ProgressCallback *progress) {
using namespace vw;
@@ -229,45 +232,8 @@ void do_mosaic(const Options& opt, const vw::ProgressCallback *progress) {
// Read in georeference info and compute total resolution.
int total_resolution = 1024;
- std::vector<GeoReference> georeferences;
-
- BOOST_FOREACH(const std::string filename, opt.input_files) {
- boost::shared_ptr<DiskImageResource> file( DiskImageResource::open(filename) );
- std::cout << "Adding file " << file->filename() << std::endl;
-
- if( opt.normalize ) get_normalize_vals(file, opt);
-
- GeoReference input_georef = make_input_georef(file, opt);
- georeferences.push_back( input_georef );
-
- GeoReference output_georef(input_georef.datum());
-
- // Right now, we only need a WGS84 output geoereference to compute
- // the resolution. The rest of the output info will get set later.
- GeoTransform geotx( input_georef, output_georef );
-
- // Calculate the best resolution at 5 different points in the image,
- // as occasionally there's a singularity at the center pixel that
- // makes it extremely tiny (such as in pole-centered images).
- const int cols = file->cols();
- const int rows = file->rows();
- Vector2 res_pixel[5];
- res_pixel[0] = Vector2( cols/2, rows/2 );
- res_pixel[1] = Vector2( cols/2 + cols/4, rows/2 );
- res_pixel[2] = Vector2( cols/2 - cols/4, rows/2 );
- res_pixel[3] = Vector2( cols/2, rows/2 + rows/4 );
- res_pixel[4] = Vector2 (cols/2, rows/2 - rows/4 );
- int resolution;
- for(int i=0; i < 5; i++) {
- resolution = compute_resolution(opt.mode, geotx, res_pixel[i]);
- if( resolution > total_resolution ) total_resolution = resolution;
- }
- }
-
- if(opt.global_resolution.set()) {
- vw_out(VerboseDebugMessage) << "Overriding calculated resolution " << total_resolution << " with " << opt.global_resolution.value() << std::endl;
- total_resolution = opt.global_resolution;
- }
+ std::vector<GeoReference> georeferences =
+ load_image_georeferences( opt, total_resolution );
boost::shared_ptr<mosaic::QuadTreeConfig> config =
mosaic::QuadTreeConfig::make(opt.mode.string());

0 comments on commit e25c744

Please sign in to comment.