Permalink
Browse files

RPC: Fix RPCModel so that it compiles

There are too many mistakes to list
  • Loading branch information...
1 parent 51d2623 commit a52a692920bdf869c9198b28c40889479d6116a1 Zack Moratto committed Mar 22, 2012
Showing with 27 additions and 46 deletions.
  1. +13 −29 src/asp/Sessions/RPC/RPCModel.cc
  2. +11 −16 src/asp/Sessions/RPC/RPCModel.h
  3. +3 −1 src/asp/Sessions/RPC/StereoSessionRPC.h
@@ -6,6 +6,7 @@
#include <asp/Sessions/RPC/RPCModel.h>
+#include <vw/Math/Vector.h>
#include <vw/FileIO/GdalIO.h>
#include <vw/FileIO/DiskImageResourceGDAL.h>
#include <vw/Cartography.h>
@@ -15,19 +16,19 @@ using namespace vw;
void asp::RPCModel::initialize( DiskImageResourceGDAL* resource ) {
// Extract Datum (by means of GeoReference)
- GeoReference georef;
- read_georeference( georef, *resource );
+ cartography::GeoReference georef;
+ cartography::read_georeference( georef, *resource );
m_datum = georef.datum();
// Extract RPC Info
boost::shared_ptr<GDALDataset> dataset = resource->get_dataset_ptr();
if ( !dataset )
- vw_throw( LogicErr() << "RPCModel: Could not read data. No file has been opened." );
+ vw_throw( NotFoundErr() << "RPCModel: Could not read data. No file has been opened." );
GDALRPCInfo gdal_rpc;
if ( !GDALExtractRPCInfo( dataset->GetMetadata("RPC"),
&gdal_rpc) )
- vw_throw( LogicErr() << "RPCModel: GDAL resource appears not to have RPC metadata." );
+ vw_throw( NotFoundErr() << "RPCModel: GDAL resource appears not to have RPC metadata." );
// Copy information over to our data structures.
m_lonlatheight_offset = Vector3(gdal_rpc.dfLONG_OFF,
@@ -62,33 +63,16 @@ asp::RPCModel::RPCModel( DiskImageResourceGDAL* resource ) {
// safe reinterpretation that is safe to distribute.
Vector2 asp::RPCModel::point_to_pixel( Vector3 const& point ) const {
- Vector3 lonlatrad = cartography::xyz_to_lon_lat_radius( point );
+ Vector3 geodetic = m_datum.cartesian_to_geodetic( point );
CoeffVec term =
- calculate_terms( elem_quot(lonlatrad - lonlatheight_offset,
- lonlatheight_scale) );
+ calculate_terms( elem_quot(geodetic - m_lonlatheight_offset,
+ m_lonlatheight_scale) );
- return Vector2( dot_prod(term,m_sample_num_coeff) /
- dot_prod(term,m_sample_den_coeff) * sample_os[1] + sample_os[0],
- dot_prod(term,m_line_num_coeff) /
- dot_prod(term,m_line_den_coeff) * sample_os[1] + sample_os[0] );
-}
-
-Vector3 asp::RPCModel::pixel_to_vector( Vector2 const& pix ) const {
- Vector3 point, direction;
- inverse_transform( pix, point, direction );
- return direction;
-}
-
-Vector3 asp::RPCModel::camera_center( Vector2 const& pix ) const {
- Vector3 point, direction;
- inverse_transform( pix, point, direction );
- return point;
-}
-
-void asp::RPCModel::inverse_transform( Vector2 const& pix, Vector3& point, Vector3& direction ) const {
- // Step 1: Calculate an approximate starting point and assume the
- // direction vector is point towards the center of the earth.
+ Vector2 normalized_proj( dot_prod(term,m_sample_num_coeff) /
+ dot_prod(term,m_sample_den_coeff),
+ dot_prod(term,m_line_num_coeff) /
+ dot_prod(term,m_line_den_coeff) );
- // Step 2: Reduce the reprojection error
+ return elem_prod( normalized_proj, m_xy_scale ) + m_xy_offset;
}
@@ -9,21 +9,14 @@
#include <vw/FileIO/DiskImageResourceGDAL.h>
#include <vw/Camera/CameraModel.h>
-
-namespace vw {
- namespace cartography {
- class Datum;
- }
-}
+#include <vw/Cartography/Datum.h>
namespace asp {
// TODO: Need to work out a different way to triangulate. Our
// standard midpoint method doesn't seem to work.
- // * Pull Datum from file. LLH measurement are geodetic.
-
class RPCModel : public vw::camera::CameraModel {
- Datum m_datum;
+ vw::cartography::Datum m_datum;
// Scaling parameters
vw::Vector<double,20> m_line_num_coeff, m_line_den_coeff,
@@ -45,16 +38,18 @@ namespace asp {
// Standard Access Methods (Most of these will fail because they
// don't apply well to RPC.)
virtual vw::Vector2 point_to_pixel( vw::Vector3 const& point ) const;
- virtual vw::Vector3 pixel_to_vector( vw::Vector2 const& pix ) const;
- virtual vw::Vector3 camera_center( vw::Vector2 const& pix ) const;
-
- // Non standard access, but more efficient
- void inverse_transform( vw::Vector2 const& pix, vw::Vector3& point,
- vw::Vector3& direction ) const;
+ virtual vw::Vector3 pixel_to_vector( vw::Vector2 const& pix ) const {
+ vw::vw_throw( vw::NoImplErr() << "RPCModel: Pixel to Vector not implemented" );
+ return vw::Vector3();
+ }
+ virtual vw::Vector3 camera_center( vw::Vector2 const& pix ) const {
+ vw::vw_throw( vw::NoImplErr() << "RPCModel: Camera center not implemented" );
+ return vw::Vector3();
+ }
// Access to constants
typedef vw::Vector<double,20> CoeffVec;
- Datum const& datum() const { return m_datum; }
+ vw::cartography::Datum const& datum() const { return m_datum; }
CoeffVec const& line_num_coeff() const { return m_line_num_coeff; }
CoeffVec const& line_den_coeff() const { return m_line_den_coeff; }
CoeffVec const& sample_num_coeff() const { return m_sample_num_coeff; }
@@ -22,7 +22,9 @@ namespace asp {
// Produces a camera model from the images
virtual boost::shared_ptr<vw::camera::CameraModel>
camera_model( std::string const& image_file,
- std::string const& camera_file = "" );
+ std::string const& camera_file = "" ) {
+ vw::vw_throw( vw::NoImplErr() << "StereoSessionRPC: Not implemented" );
+ }
static StereoSession* construct() { return new StereoSessionRPC; }
};

0 comments on commit a52a692

Please sign in to comment.