1 //*****************************************************************************
2 // FILE: ossimEcefPoint.h
3 //
4 // License:  See top level LICENSE.txt file.
5 //
6 // DESCRIPTION:
7 //   Contains declaration of a 3D point object in the Earth-centered, earth
8 //   fixed (ECEF) coordinate system.
9 //
10 // SOFTWARE HISTORY:
11 //>
12 //   08Aug2001  Oscar Kramer (http://www.oscarkramer.com)
13 //              Initial coding.
14 //<
15 //*****************************************************************************
16 //  $Id: ossimEcefPoint.h 20043 2011-09-06 15:00:55Z oscarkramer $
17 
18 #ifndef ossimEcefPoint_HEADER
19 #define ossimEcefPoint_HEADER
20 #include <iosfwd>
21 #include <ossim/base/ossimCommon.h>
22 #include <ossim/base/ossimColumnVector3d.h>
23 #include <ossim/base/ossimNotify.h>
24 #include <ossim/base/ossimString.h>
25 #include <ossim/matrix/newmat.h>
26 
27 class ossimGpt;
28 class ossimEcefVector;
29 class ossimDpt3d;
30 
31 //*****************************************************************************
32 //  CLASS: ossimEcefPoint
33 //
34 //*****************************************************************************
35 class OSSIMDLLEXPORT ossimEcefPoint
36 {
37 public:
38    /*!
39     * CONSTRUCTORS:
40     */
41    ossimEcefPoint()
42       : theData(0,0,0) {}
43 
44    // Default definition is perfect
45    // ossimEcefPoint(const ossimEcefPoint& copy_this) = default;
46 
47    ossimEcefPoint(const ossimGpt& convert_this);
48 
49    ossimEcefPoint(const double& x,
50                   const double& y,
51                   const double& z)
52       : theData(x, y, z) {}
53 
54    ossimEcefPoint(const ossimColumnVector3d& assign_this)
55       : theData(assign_this) {}
56 
57    ossimEcefPoint(const NEWMAT::ColumnVector& assign_this)
58       : theData(assign_this) {}
59 
60    ossimEcefPoint(const ossimDpt3d& pt);
61 
62    void makeNan()
63       {
64          theData[0] = ossim::nan();
65          theData[1] = ossim::nan();
66          theData[2] = ossim::nan();
67       }
68 
69    bool hasNans()const
70       {
71          return ( ossim::isnan(theData[0]) ||
72                   ossim::isnan(theData[1]) ||
73                   ossim::isnan(theData[2]) );
74 
75       }
76 
77    bool isNan()const
78       {
79          return ( ossim::isnan(theData[0]) &&
80                   ossim::isnan(theData[1]) &&
81                   ossim::isnan(theData[2]) );
82 
83       }
84    /*!
85     * OPERATORS:
86     */
87    ossimEcefVector       operator- (const ossimEcefPoint&)  const;
88    ossimEcefPoint        operator+ (const ossimEcefVector&) const;
89    ossimEcefPoint        operator- (const ossimEcefVector&) const;
90    // ossimEcefPoint&       operator= (const ossimEcefPoint&) = default;
91    bool                  operator==(const ossimEcefPoint&)  const; // inline
92    bool                  operator!=(const ossimEcefPoint&)  const; // inline
93 
94    /*!
95     * COMPONENT ACCESS METHODS:
96     */
97    double    x() const { return theData[0]; }
98    double&   x()       { return theData[0]; }
99    double    y() const { return theData[1]; }
100    double&   y()       { return theData[1]; }
101    double    z() const { return theData[2]; }
102    double&   z()       { return theData[2]; }
103    double&   operator[](int idx){return theData[idx];}
104    const double&   operator[](int idx)const{return theData[idx];}
105    const ossimColumnVector3d& data() const { return theData; }
106    ossimColumnVector3d&       data()       { return theData; }
107 
108    double getMagnitude() const
109       {
110          return theData.magnitude();
111       }
112    double magnitude()const
113    {
114       return theData.magnitude();
115    }
116    double length()const
117    {
118       return theData.magnitude();
119    }
120    double normalize()
121    {
122       double result = magnitude();
123 
124       if(result > 1e-15)
125       {
126          theData[0]/=result;
127          theData[1]/=result;
128          theData[2]/=result;
129       }
130 
131       return result;
132    }
133 
134    /**
135     * @brief To string method.
136     *
137     * @param precision Output floating point precision.
138     *
139     * @return ossimString representing point.
140     *
141     * Output format:
142     * ( 0.0000000,  0.0000000,  0.00000000 )
143     *   -----x----  -----y----  ------z----
144     */
145    ossimString toString(ossim_uint32 precision=15) const;
146 
147    /**
148     * @brief Initializes this point from string.
149     *
150     * Expected format:
151     *
152     * ( 0.0000000,  0.0000000,  0.00000000 )
153     *   -----x----  -----y----  ------z----
154     *
155     * @param s String to initialize from.
156     */
157    void toPoint(const std::string& s);
158 
159    //! Converts this point to a 3D column vector.
160    NEWMAT::ColumnVector toVector() const
161    {
162       NEWMAT::ColumnVector v (3);
163       v(0) = theData[0];
164       v(1) = theData[1];
165       v(2) = theData[2];
166       return v;
167    }
168 
169    //! Converts 3D column vector to this point.
170    void toPoint(const NEWMAT::ColumnVector& v)
171    {
172       if (v.Nrows() == 3)
173       {
174          theData[0] = v[0];
175          theData[1] = v[1];
176          theData[2] = v[2];
177       }
178    }
179 
180    /*!
181     * Debug Dump:
182     */
183    void print(std::ostream& os = ossimNotify(ossimNotifyLevel_INFO)) const;
184 
185    friend OSSIM_DLL std::ostream& operator<<(std::ostream& os ,
186                                              const ossimEcefPoint& instance);
187 
188 protected:
189    ossimColumnVector3d theData;
190 };
191 
192 //================== BEGIN DEFINITIONS FOR INLINE METHODS =====================
193 
194 //*****************************************************************************
195 //  INLINE METHOD: ossimEcefPoint::operator==(ossimEcefPoint)
196 //*****************************************************************************
197 inline bool ossimEcefPoint::operator==(const ossimEcefPoint& p) const
198 {
199    return (theData == p.theData);
200 }
201 
202 //*****************************************************************************
203 //  INLINE METHOD: ossimEcefPoint::operator!=(ossimEcefPoint)
204 //*****************************************************************************
205 inline bool ossimEcefPoint::operator!=(const ossimEcefPoint& p) const
206 {
207    return (theData != p.theData);
208 }
209 
210 #endif
211