PCL
ZenithalProjections.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/ZenithalProjections.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_ZenithalProjections_h
53 #define __PCL_ZenithalProjections_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/ProjectionBase.h>
60 
61 /*
62  * Based on original work contributed by AndrĂ©s del Pozo.
63  */
64 
65 namespace pcl
66 {
67 
68 // ----------------------------------------------------------------------------
69 
76 class PCL_CLASS ZenithalProjectionBase : public ProjectionBase
77 {
78 protected:
79 
84  {
85  m_theta0 = 90;
86  }
87 
92 
96  virtual ProjectionBase* Clone() const override = 0;
97 
101  virtual IsoString ProjCode() const override = 0;
102 
106  virtual IsoString Name() const override = 0;
107 
108 protected:
109 
113  bool Project( DPoint& pW, const DPoint& pN ) const noexcept override
114  {
115  double rTheta = GetRTheta( pN );
116  double sinTheta, cosTheta;
117  SinCos( Rad( pN.x ), sinTheta, cosTheta );
118  pW.x = rTheta * sinTheta;
119  pW.y = -rTheta * cosTheta;
120  return true;
121  }
122 
126  bool Unproject( DPoint& pN, const DPoint& pW ) const noexcept override
127  {
128  pN.x = Deg( ArcTan( pW.x, -pW.y ) );
129  pN.y = GetTheta( Sqrt( pW.x*pW.x + pW.y*pW.y ) );
130  return true;
131  }
132 
133  virtual double GetRTheta( const DPoint& np ) const = 0;
134  virtual double GetTheta( double rTheta ) const = 0;
135 };
136 
137 // ----------------------------------------------------------------------------
138 
146 {
147 public:
148 
152  ZenithalEqualAreaProjection() = default;
153 
158 
162  ProjectionBase* Clone() const override
163  {
164  return new ZenithalEqualAreaProjection( *this );
165  }
166 
170  IsoString ProjCode() const override
171  {
172  return "ZEA";
173  }
174 
178  IsoString Name() const override
179  {
180  return "Zenithal Equal Area";
181  }
182 
186  bool CheckBrokenLine( const DPoint& cp1, const DPoint& cp2 ) const noexcept override
187  {
188  DPoint np1 = m_sph.CelestialToNative( cp1 );
189  DPoint np2 = m_sph.CelestialToNative( cp2 );
190  return Min( Mod( Abs( np1.x - np2.x - 360 ), 360.0 ),
191  Mod( Abs( np1.x - np2.x + 360 ), 360.0 ) ) < 180*Sin( Rad( 45 + (np1.y + np2.y)/2/2 ) );
192  }
193 
194 private:
195 
196  double GetRTheta( const DPoint& np ) const override
197  {
198  return 2 * Deg( Sin( Rad( (90 - np.y)/2 ) ) );
199  }
200 
201  double GetTheta( double rTheta ) const override
202  {
203  return 90 - 2*Deg( ArcSin( Rad( rTheta )/2 ) );
204  }
205 };
206 
207 // ----------------------------------------------------------------------------
208 
216 {
217 public:
218 
222  StereographicProjection() = default;
223 
228 
232  ProjectionBase* Clone() const override
233  {
234  return new StereographicProjection( *this );
235  }
236 
240  IsoString ProjCode() const override
241  {
242  return "STG";
243  }
244 
248  IsoString Name() const override
249  {
250  return "Stereographic";
251  }
252 
256  bool CheckBrokenLine(const DPoint& cp1, const DPoint& cp2) const noexcept override
257  {
258  return true;
259  }
260 
261 private:
262 
263  double GetRTheta( const DPoint& np ) const override
264  {
265  return 2 * Deg( Tan( Rad( (90 - np.y)/2 ) ) );
266  }
267 
268  double GetTheta( double rTheta ) const override
269  {
270  return 90 - 2*Deg( ArcTan( Rad( rTheta )/2 ) );
271  }
272 };
273 
274 // ----------------------------------------------------------------------------
275 
276 } // pcl
277 
278 #endif // __PCL_ZenithalProjections_h
279 
280 // ----------------------------------------------------------------------------
281 // EOF pcl/ZenithalProjections.h - Released 2019-11-07T10:59:34Z
constexpr T ArcTan(T x)
Definition: Math.h:487
bool Project(DPoint &pW, const DPoint &pN) const noexcept override
IsoString ProjCode() const override
PCL root namespace.
Definition: AbstractImage.h:76
constexpr T ArcSin(T x)
Definition: Math.h:475
Complex< T > Sqrt(const Complex< T > &c)
Definition: Complex.h:665
constexpr T Rad(T x)
Definition: Math.h:1728
ProjectionBase * Clone() const override
T Abs(const Complex< T > &c)
Definition: Complex.h:420
IsoString Name() const override
constexpr const T & Min(const T &a, const T &b)
Definition: Utility.h:90
constexpr T Mod(T x, T y)
Definition: Math.h:803
IsoString ProjCode() const override
bool Unproject(DPoint &pN, const DPoint &pW) const noexcept override
ProjectionBase * Clone() const override
constexpr T Deg(T x)
Definition: Math.h:567
String Name(int colorSpace)
Base class of all projection systems.
Base class of zenithal projection systems.
IsoString Name() const override
64-bit floating-point point in the R^2 space.
void SinCos(T x, T &sx, T &cx)
Definition: Math.h:938
Complex< T > Sin(const Complex< T > &c)
Definition: Complex.h:786
Complex< T > Tan(const Complex< T > &c)
Definition: Complex.h:808
Zenithal equal-area projection system.
Stereographic projection system.
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5387