Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure only images written with mapproject -t rpc are used in stereo …

…with dg session
  • Loading branch information...
commit 84c1ab7720ded4d0f18b6d0585cc9a84338dccc5 1 parent 837f0e5
@oleg-alexandrov oleg-alexandrov authored
View
16 docs/book/tutorial.tex
@@ -929,15 +929,15 @@ \section{Processing Map-Projected Imagery}
\subsubsection*{Commands}
\begin{verbatim}
- > mapproject -t rpc --t_srs "+proj=eqc +units=m +datum=WGS84" \
- --tr 0.5 srtm_53_07.tif \
- 12FEB12053305-P1BS_R2C1-052783824050_01_P001.TIF \
- 12FEB12053305-P1BS_R2C1-052783824050_01_P001.XML \
+ > mapproject --t_srs "+proj=eqc +units=m +datum=WGS84" \
+ --tr 0.5 srtm_53_07.tif \
+ 12FEB12053305-P1BS_R2C1-052783824050_01_P001.TIF \
+ 12FEB12053305-P1BS_R2C1-052783824050_01_P001.XML \
left_mapped.tif
- > mapproject -t rpc --t_srs "+proj=eqc +units=m +datum=WGS84" \
- --tr 0.5 srtm_53_07.tif \
- 12FEB12053341-P1BS_R2C1-052783824050_01_P001.TIF \
- 12FEB12053341-P1BS_R2C1-052783824050_01_P001.XML \
+ > mapproject --t_srs "+proj=eqc +units=m +datum=WGS84" \
+ --tr 0.5 srtm_53_07.tif \
+ 12FEB12053341-P1BS_R2C1-052783824050_01_P001.TIF \
+ 12FEB12053341-P1BS_R2C1-052783824050_01_P001.XML \
right_mapped.tif
> stereo -t dg left_mapped.tif right_mapped.tif \
12FEB12053305-P1BS_R2C1-052783824050_01_P001.XML \
View
46 src/asp/Core/Common.h
@@ -31,6 +31,8 @@
#include <vw/Math/Vector.h>
#include <vw/Image/ImageViewRef.h>
#include <vw/Cartography/GeoReference.h>
+#include <map>
+#include <string>
namespace asp {
@@ -133,14 +135,21 @@ namespace asp {
vw::block_write_image( *rsrc, image.impl(), progress_callback );
}
- // Block write image with georef.
+ // Block write image with georef and keywords to geoheader.
template <class ImageT>
void block_write_gdal_image( const std::string &filename,
vw::ImageViewBase<ImageT> const& image,
vw::cartography::GeoReference const& georef,
BaseOptions const& opt,
- vw::ProgressCallback const& progress_callback = vw::ProgressCallback::dummy_instance() ) {
+ vw::ProgressCallback const& progress_callback = vw::ProgressCallback::dummy_instance(),
+ std::map<std::string, std::string> keywords =
+ std::map<std::string, std::string>()
+ ) {
boost::scoped_ptr<vw::DiskImageResourceGDAL> rsrc( build_gdal_rsrc( filename, image, opt ) );
+ for (std::map<std::string, std::string>::iterator i = keywords.begin();
+ i != keywords.end(); i++){
+ vw::cartography::write_header_string(*rsrc, i->first, i->second);
+ }
vw::cartography::write_georeference(*rsrc, georef);
vw::block_write_image( *rsrc, image.impl(), progress_callback );
}
@@ -157,43 +166,66 @@ namespace asp {
vw::block_write_image( *rsrc, image.impl(), progress_callback );
}
- // Block write image with nodata and georef.
+ // Block write image with nodata, georef, and keywords to geoheader.
template <class ImageT, class NoDataT>
void block_write_gdal_image( const std::string &filename,
vw::ImageViewBase<ImageT> const& image,
vw::cartography::GeoReference const& georef,
NoDataT nodata,
BaseOptions const& opt,
- vw::ProgressCallback const& progress_callback = vw::ProgressCallback::dummy_instance() ) {
+ vw::ProgressCallback const& progress_callback =
+ vw::ProgressCallback::dummy_instance(),
+ std::map<std::string, std::string> keywords =
+ std::map<std::string, std::string>()
+ ) {
boost::scoped_ptr<vw::DiskImageResourceGDAL> rsrc( build_gdal_rsrc( filename, image, opt ) );
rsrc->set_nodata_write(nodata);
+
+ for (std::map<std::string, std::string>::iterator i = keywords.begin();
+ i != keywords.end(); i++){
+ vw::cartography::write_header_string(*rsrc, i->first, i->second);
+ }
+
vw::cartography::write_georeference(*rsrc, georef);
vw::block_write_image( *rsrc, image.impl(), progress_callback );
}
// Single-threaded write functions.
+ // Write image with georef and keywords to geoheader.
template <class ImageT>
void write_gdal_georeferenced_image( const std::string &filename,
vw::ImageViewBase<ImageT> const& image,
vw::cartography::GeoReference const& georef,
BaseOptions const& opt,
- vw::ProgressCallback const& progress_callback = vw::ProgressCallback::dummy_instance() ) {
+ vw::ProgressCallback const& progress_callback = vw::ProgressCallback::dummy_instance(),
+ std::map<std::string, std::string> keywords = std::map<std::string, std::string>()
+ ) {
boost::scoped_ptr<vw::DiskImageResourceGDAL> rsrc( build_gdal_rsrc( filename, image, opt ) );
+ for (std::map<std::string, std::string>::iterator i = keywords.begin();
+ i != keywords.end(); i++){
+ vw::cartography::write_header_string(*rsrc, i->first, i->second);
+ }
vw::cartography::write_georeference(*rsrc, georef);
vw::write_image( *rsrc, image.impl(), progress_callback );
}
- // Write image with nodata and georef.
+ // Write image with georef, nodata, and keywords to geoheader.
template <class ImageT, class NoDataT>
void write_gdal_georeferenced_image( const std::string &filename,
vw::ImageViewBase<ImageT> const& image,
vw::cartography::GeoReference const& georef,
NoDataT nodata,
BaseOptions const& opt,
- vw::ProgressCallback const& progress_callback = vw::ProgressCallback::dummy_instance() ) {
+ vw::ProgressCallback const& progress_callback = vw::ProgressCallback::dummy_instance(),
+ std::map<std::string, std::string> keywords = std::map<std::string, std::string>()
+ ) {
boost::scoped_ptr<vw::DiskImageResourceGDAL> rsrc( build_gdal_rsrc( filename, image, opt ) );
rsrc->set_nodata_write(nodata);
+ for (std::map<std::string, std::string>::iterator i = keywords.begin();
+ i != keywords.end(); i++){
+ vw::cartography::write_header_string(*rsrc, i->first, i->second);
+ }
vw::cartography::write_georeference(*rsrc, georef);
vw::write_image( *rsrc, image.impl(), progress_callback );
}
View
28 src/asp/Tools/mapproject.cc
@@ -93,17 +93,14 @@ void handle_arguments( int argc, char *argv[], Options& opt ) {
<< "input in order to proceed.\n\n"
<< usage << general_options );
- // When doing stereo, we usually guess the session type to be dg if
- // the camera model is an xml file, yet this tool will most likely
- // be used with rpc sessions, hence the user must be explicit about
- // which session is desired.
+ // If the camera file is in xml format, most likely the user would like
+ // to use the rpc session for map-projection, as that's what is needed
+ // later to use the map-projected images to perform stereo with -t dg.
if ( boost::iends_with(boost::to_lower_copy(opt.camera_model_file), ".xml") &&
opt.stereo_session == "" ){
- vw_throw( ArgumentErr() << "Unable to guess session type. Please specify "
- << "whether it is dg or rpc via the -t option.\n\n"
- << usage << general_options );
+ opt.stereo_session = "rpc";
}
-
+
}
template <class ImageT>
@@ -113,24 +110,31 @@ void write_parallel_cond( std::string const& filename,
bool has_nodata, double nodata_val,
Options const& opt,
TerminalProgressCallback const& tpc ) {
+
+ // Save the session type. Later in stereo we will check that we use
+ // only images written by mapproject with the -t rpc session.
+ std::map<std::string, std::string> keywords;
+ keywords["CAMERA_MODEL_TYPE" ] = opt.stereo_session;
+
// ISIS is not thread safe so we must switch out base on what the
// session is.
+
vw_out() << "Writing: " << filename << "\n";
if (has_nodata){
if ( opt.stereo_session == "isis" ) {
asp::write_gdal_georeferenced_image(filename, image.impl(), georef,
- nodata_val, opt, tpc);
+ nodata_val, opt, tpc, keywords);
} else {
asp::block_write_gdal_image(filename, image.impl(), georef,
- nodata_val, opt, tpc);
+ nodata_val, opt, tpc, keywords);
}
}else{
if ( opt.stereo_session == "isis" ) {
asp::write_gdal_georeferenced_image(filename, image.impl(), georef,
- opt, tpc);
+ opt, tpc, keywords);
} else {
asp::block_write_gdal_image(filename, image.impl(), georef,
- opt, tpc);
+ opt, tpc, keywords);
}
}
View
31 src/asp/Tools/stereo.cc
@@ -301,10 +301,12 @@ namespace asp {
<< "provided for stereo to give correct results.\n";
}
- // We did not implement using map-projected images with the RPC session
- if ( opt.session->name() == "rpc" && !opt.input_dem.empty() ) {
+ // We did not implement stereo using map-projected images with dem
+ // on anything except "dg" and "dgmaprpc" sessions.
+ if ( !opt.input_dem.empty() && opt.session->name() != "dg"
+ && opt.session->name() != "dgmaprpc" ) {
vw_throw( ArgumentErr() << "Cannot use map-projected images with "
- << "an RPC session.\n");
+ << "a session of type: " << opt.session->name() << ".\n");
}
// No alignment must be set for map-projected images.
@@ -314,6 +316,29 @@ namespace asp {
<< "needs to be 'none'.\n");
}
+ // Ensure that we are not accidentally doing stereo with
+ // images map-projected with other camera model than 'rpc'.
+ if (!opt.input_dem.empty()){
+
+ std::string cam_tag = "CAMERA_MODEL_TYPE";
+ std::string l_cam_type, r_cam_type;
+ boost::shared_ptr<vw::DiskImageResource> l_rsrc
+ ( new vw::DiskImageResourceGDAL(opt.in_file1) );
+ vw::cartography::read_header_string(*l_rsrc.get(), cam_tag, l_cam_type);
+ boost::shared_ptr<vw::DiskImageResource> r_rsrc
+ ( new vw::DiskImageResourceGDAL(opt.in_file2) );
+ vw::cartography::read_header_string(*r_rsrc.get(), cam_tag, r_cam_type);
+
+ if ( (l_cam_type != "" && l_cam_type != "rpc")
+ ||
+ (r_cam_type != "" && r_cam_type != "rpc")
+ ){
+ vw_throw( ArgumentErr()
+ << "The images were map-projected with another option "
+ << "than -t rpc.\n");
+ }
+
+ }
// Camera checks
try {
Please sign in to comment.
Something went wrong with that request. Please try again.