PCL
ProjectionBase.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/ProjectionBase.h - Released 2019-11-07T10:59:34Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2019 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_ProjectionBase_h
53 #define __PCL_ProjectionBase_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/Optional.h>
60 #include <pcl/Point.h>
61 #include <pcl/SphericalRotation.h>
62 #include <pcl/WCSKeywords.h>
63 
64 /*
65  * Based on original work contributed by Andrés del Pozo.
66  */
67 
68 namespace pcl
69 {
70 
71 // ----------------------------------------------------------------------------
72 
79 class PCL_CLASS ProjectionBase
80 {
81 public:
82 
86  virtual ~ProjectionBase()
87  {
88  }
89 
93  virtual ProjectionBase* Clone() const = 0;
94 
98  virtual IsoString ProjCode() const = 0;
99 
103  virtual IsoString Name() const = 0;
104 
109  virtual void GetWCS( WCSKeywords& wcs ) const;
110 
114  void InitFromRefPoint( double lng0, double lat0, const Optional<double>& phip = Optional<double>() );
115 
119  virtual bool Direct( DPoint& pW, const DPoint& pRD ) const noexcept
120  {
121  DPoint pN = m_sph.CelestialToNative( pRD );
122  return IsFinite( pN.x ) && IsFinite( pN.y ) && Project( pW, pN );
123  }
124 
128  virtual bool Inverse( DPoint& pRD, const DPoint& pW ) const noexcept
129  {
130  DPoint pN;
131  if ( Unproject( pN, pW ) )
132  if ( IsFinite( pN.x ) )
133  if ( IsFinite( pN.y ) )
134  {
135  pRD = m_sph.NativeToCelestial( pN );
136  return true;
137  }
138  return false;
139  }
140 
144  virtual bool CheckBrokenLine( const DPoint& cp1, const DPoint& cp2 ) const noexcept
145  {
146  return DistanceFast( m_sph.CelestialToNative( cp1 ), m_sph.CelestialToNative( cp2 ) ) < 150;
147  }
148 
152  virtual DPoint ProjectionOrigin() const
153  {
154  return DPoint( Deg( m_ra0 ), Deg( m_dec0 ) );
155  }
156 
161  static double Distance( const DPoint& p1, const DPoint& p2 )
162  {
163  double sinX, cosX;
164  SinCos( Rad( Abs( p1.x - p2.x ) ), sinX, cosX );
165  double sinY1, cosY1;
166  SinCos( Rad( p1.y ), sinY1, cosY1 );
167  double sinY2, cosY2;
168  SinCos( Rad( p2.y ), sinY2, cosY2 );
169  double K = cosY1*sinY2 - sinY1*cosY2*cosX;
170  return Deg( ArcTan( Sqrt( cosY2*sinX*cosY2*sinX + K*K ), sinY1*sinY2 + cosY1*cosY2*cosX ) );
171  };
172 
177  static double DistanceFast( const DPoint& p1, const DPoint& p2 )
178  {
179  double sinY1, cosY1;
180  SinCos( Rad( p1.y ), sinY1, cosY1 );
181  double sinY2, cosY2;
182  SinCos( Rad( p2.y ), sinY2, cosY2 );
183  return Deg( ArcCos( sinY1*sinY2 + cosY1*cosY2*Cos( Rad( p1.x - p2.x ) ) ) );
184  }
185 
186 protected:
187 
188  double m_ra0 = 0; // radians
189  double m_dec0 = 0; // radians
190  double m_theta0 = 0; // degrees
191  double m_phi0 = 0; // degrees
192  Optional<double> m_lonpole; // degrees
193  Optional<double> m_latpole; // degrees
194  SphericalRotation m_sph;
195 
199  ProjectionBase() = default;
200 
204  ProjectionBase( const ProjectionBase& ) = default;
205 
209  void InitFromWCS( const WCSKeywords& );
210 
214  virtual bool Project( DPoint& pW, const DPoint& pN ) const noexcept = 0;
215 
219  virtual bool Unproject( DPoint& pN, const DPoint& pW ) const noexcept = 0;
220 
221  friend class ProjectionFactory;
222 };
223 
224 // ----------------------------------------------------------------------------
225 
226 } // pcl
227 
228 #endif // __PCL_ProjectionBase_h
229 
230 // ----------------------------------------------------------------------------
231 // EOF pcl/ProjectionBase.h - Released 2019-11-07T10:59:34Z
constexpr T ArcTan(T x)
Definition: Math.h:487
PCL root namespace.
Definition: AbstractImage.h:76
Rotation in spherical coordinates.
virtual bool Direct(DPoint &pW, const DPoint &pRD) const noexcept
Complex< T > Sqrt(const Complex< T > &c)
Definition: Complex.h:665
bool IsFinite(float x)
Definition: Math.h:170
constexpr T Rad(T x)
Definition: Math.h:1728
A structure for management of WCS FITS header keywords and associated image properties.
Definition: WCSKeywords.h:88
T Abs(const Complex< T > &c)
Definition: Complex.h:420
virtual DPoint ProjectionOrigin() const
constexpr T ArcCos(T x)
Definition: Math.h:463
virtual ~ProjectionBase()
Selectable projection system.
constexpr T Deg(T x)
Definition: Math.h:567
String Name(int colorSpace)
Base class of all projection systems.
static double DistanceFast(const DPoint &p1, const DPoint &p2)
64-bit floating-point point in the R^2 space.
void SinCos(T x, T &sx, T &cx)
Definition: Math.h:938
static double Distance(const DPoint &p1, const DPoint &p2)
Complex< T > Cos(const Complex< T > &c)
Definition: Complex.h:797
virtual bool Inverse(DPoint &pRD, const DPoint &pW) const noexcept
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5387