1 // This is core/vpgl/vpgl_local_rational_camera.h
2 #ifndef vpgl_local_rational_camera_h_
3 #define vpgl_local_rational_camera_h_
4 //:
5 // \file
6 // \brief A local rational camera model
7 // \author Joseph Mundy
8 // \date February 16, 2008
9 //
10 // Rational camera models are defined with respect to global geographic
11 // coordinates. In many applications it is necessary to project points with
12 // local 3-d Cartesian coordinates. This camera class incorporates a
13 // Local Vertical Coordinate System (LVCS) to convert local coordinates
14 // to geographic coordinates to input to the native geographic RPC model.
15 
16 #include <iostream>
17 #include <string>
18 #include <vgl/vgl_fwd.h>
19 #ifdef _MSC_VER
20 #  include <vcl_msvc_warnings.h>
21 #endif
22 #include "vpgl_rational_camera.h"
23 #include "vpgl_lvcs.h"
24 //
25 //--------------------=== composite rational camera ===---------------------------
26 //
27 template <class T>
28 class vpgl_local_rational_camera : public vpgl_rational_camera<T>
29 {
30  public:
31   //: default constructor
32   vpgl_local_rational_camera();
33 
34   //: Constructor from a rational camera and a lvcs
35   vpgl_local_rational_camera(vpgl_lvcs const& lvcs,
36                              vpgl_rational_camera<T> const& rcam);
37 
38   //: Constructor from a rational camera and a geographic origin
39   vpgl_local_rational_camera(T longitude, T latitude, T elevation,
40                              vpgl_rational_camera<T> const& rcam);
41 
42   ~vpgl_local_rational_camera() override = default;
43 
type_name()44   std::string type_name() const override { return "vpgl_local_rational_camera"; }
45 
46   //: Clone `this': creation of a new object and initialization
47   // legal C++ because the return type is covariant with vpgl_camera<T>*
48   vpgl_local_rational_camera<T> *clone() const override;
49 
50   //: Equality test
51   inline bool operator==(vpgl_local_rational_camera<T> const &that) const
52   { return this == &that ||
53            ( static_cast<vpgl_rational_camera<T> const&>(*this) ==
54              static_cast<vpgl_rational_camera<T> const&>(that)      &&
55              this->lvcs() == that.lvcs() );
56   }
57 
58   //: set the local vertical coordinate system
set_lvcs(vpgl_lvcs const & lvcs)59   void set_lvcs(vpgl_lvcs const& lvcs) {lvcs_ = lvcs;}
60   void set_lvcs(double const& lon, double const& lat, double const& elev);
61 
62   //: get the local vertical coordinate system
lvcs()63   vpgl_lvcs lvcs() const {return lvcs_;}
64 
65   //: project 3D->2D, x,y,z are relative to the lvcs
66   using vpgl_rational_camera<T>::project; // "project" overload from base class
67   void project(const T x, const T y, const T z, T& u, T& v) const override;
68 
69   // write PVL (paramter value language) to output stream
70   void write_pvl(std::ostream& s, vpgl_rational_order output_order) const override;
71 
72   //: read from PVL (parameter value language) file/stream
73   using vpgl_rational_camera<T>::read_pvl; // "read_pvl" overload from base class
74   bool read_pvl(std::istream& istr) override;
75 
76   //: read from TXT file/stream
77   using vpgl_rational_camera<T>::read_txt; // "read_txt" overload from base class
78   bool read_txt(std::istream& istr) override;
79 
80  protected:
81   // members
82   vpgl_lvcs lvcs_;
83 };
84 
85 //: Write to stream
86 // \relatesalso vpgl_local_rational_camera
87 template <class T>
88 std::ostream& operator<<(std::ostream& s, const vpgl_local_rational_camera<T>& p);
89 
90 //: Read from stream
91 // \relatesalso vpgl_local_rational_camera
92 template <class T>
93 std::istream& operator>>(std::istream& is, vpgl_local_rational_camera<T>& p);
94 
95 //: Creates a local rational camera from a PVL file
96 // \relatesalso vpgl_local_rational_camera
97 template <class T>
98 vpgl_local_rational_camera<T>* read_local_rational_camera(std::string cam_path);
99 
100 //: Creates a local rational camera from a PVL input stream
101 // \relatesalso vpgl_local_rational_camera
102 template <class T>
103 vpgl_local_rational_camera<T>* read_local_rational_camera(std::istream& istr);
104 
105 //: Creates a local rational camera from a TXT file
106 // \relatesalso vpgl_local_rational_camera
107 template <class T>
108 vpgl_local_rational_camera<T>* read_local_rational_camera_from_txt(std::string cam_path);
109 
110 //: Creates a local rational camera from a TXT input stream
111 // \relatesalso vpgl_local_rational_camera
112 template <class T>
113 vpgl_local_rational_camera<T>* read_local_rational_camera_from_txt(std::istream& istr);
114 
115 
116 #define VPGL_LOCAL_RATIONAL_CAMERA_INSTANTIATE(T) extern "please include vgl/vpgl_local_rational_camera.hxx first"
117 
118 
119 #endif // vpgl_local_rational_camera_h_
120