PCL
LinearTransformation.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/LinearTransformation.h - Released 2024-06-18T15:48:54Z
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-2024 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 (https://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_LinearTransformation_h
53 #define __PCL_LinearTransformation_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/Matrix.h>
60 #include <pcl/Point.h>
61 #include <pcl/String.h>
62 #include <pcl/Vector.h>
63 
64 /*
65  * Based on original work contributed by AndrĂ©s del Pozo.
66  */
67 
68 namespace pcl
69 {
70 
71 // ----------------------------------------------------------------------------
72 
88 {
89 public:
90 
94  LinearTransformation() = default;
95 
100 
105 
109  LinearTransformation( double a00, double a01, double a02, double a10, double a11, double a12 )
110  : m_a00( a00 ), m_a01( a01 ), m_a02( a02 )
111  , m_a10( a10 ), m_a11( a11 ), m_a12( a12 )
112  , m_det( a00*a11 - a01*a10 )
113  {
114  }
115 
119  double Determinant() const
120  {
121  return m_det;
122  }
123 
129  bool IsSingularMatrix() const
130  {
131  return 1 + m_det == 1;
132  }
133 
137  DPoint Transform( const DPoint& p ) const
138  {
139  return DPoint( m_a00*p.x + m_a01*p.y + m_a02,
140  m_a10*p.x + m_a11*p.y + m_a12 );
141  }
142 
147  DPoint operator ()( const DPoint& p ) const
148  {
149  return Transform( p );
150  }
151 
158  DPoint TransformInverse( const DPoint& p ) const
159  {
160  if ( IsSingularMatrix() )
161  throw Error( "Invalid call to LinearTransformation::TransformInverse(): Singular matrix" );
162  return DPoint( ( m_a11*p.x - m_a01*p.y + m_a01*m_a12 - m_a02*m_a11)/m_det,
163  (-m_a10*p.x + m_a00*p.y + m_a02*m_a10 - m_a00*m_a12)/m_det );
164  }
165 
170  {
171  return LinearTransformation( m_a00*T.m_a00 + m_a01*T.m_a10,
172  m_a00*T.m_a01 + m_a01*T.m_a11,
173  m_a00*T.m_a02 + m_a01*T.m_a12 + m_a02,
174  m_a10*T.m_a00 + m_a11*T.m_a10,
175  m_a10*T.m_a01 + m_a11*T.m_a11,
176  m_a10*T.m_a02 + m_a11*T.m_a12 + m_a12 );
177  }
178 
186  {
187  if ( IsSingularMatrix() )
188  throw Error( "Invalid call to LinearTransformation::Inverse(): Singular matrix" );
189  return LinearTransformation( m_a11/m_det,
190  -m_a01/m_det,
191  (m_a01*m_a12 - m_a02*m_a11)/m_det,
192  -m_a10/m_det,
193  m_a00/m_det,
194  (m_a02*m_a10 - m_a00*m_a12)/m_det );
195  }
196 
200  double A00() const
201  {
202  return m_a00;
203  }
204 
208  double A01() const
209  {
210  return m_a01;
211  }
212 
216  double A02() const
217  {
218  return m_a02;
219  }
220 
224  double A10() const
225  {
226  return m_a10;
227  }
228 
232  double A11() const
233  {
234  return m_a11;
235  }
236 
240  double A12() const
241  {
242  return m_a12;
243  }
244 
249  Matrix ToMatrix() const
250  {
251  return Matrix( m_a00, m_a01, m_a02,
252  m_a10, m_a11, m_a12,
253  0.0, 0.0, 1.0 );
254  }
255 
261  {
262  Matrix H( 2, 3 );
263  H[0][0] = m_a00;
264  H[0][1] = m_a01;
265  H[0][2] = m_a02;
266  H[1][0] = m_a10;
267  H[1][1] = m_a11;
268  H[1][2] = m_a12;
269  return H;
270  }
271 
276  Vector ToVector() const
277  {
278  return Vector( { m_a00, m_a01, m_a02, m_a10, m_a11, m_a12 } );
279  }
280 
286  String ToString( int indent = 0 ) const
287  {
288  String text;
289  if ( indent > 0 )
290  text << String( ' ', indent );
291  text.AppendFormat( "%+16.8e %+16.8e %+16.8e\n", m_a00, m_a01, m_a02 );
292  if ( indent > 0 )
293  text << String( ' ', indent );
294  text.AppendFormat( "%+16.8e %+16.8e %+16.8e", m_a10, m_a11, m_a12 );
295  return text;
296  }
297 
303  {
304  return LinearTransformation( 0, 0, 0, 0, 0, 0 );
305  }
306 
307 private:
308 
309  double m_a00 = 1, m_a01 = 0, m_a02 = 0,
310  m_a10 = 0, m_a11 = 1, m_a12 = 0;
311  double m_det = 1;
312 };
313 
314 // ----------------------------------------------------------------------------
315 
316 } // pcl
317 
318 #endif // __PCL_LinearTransformation_h
319 
320 // ----------------------------------------------------------------------------
321 // EOF pcl/LinearTransformation.h - Released 2024-06-18T15:48:54Z
A simple exception with an associated error message.
Definition: Exception.h:239
Generic dynamic matrix of arbitrary dimensions.
Definition: Matrix.h:123
A generic point in the two-dimensional space.
Definition: Point.h:100
component x
Abscissa (horizontal, or X-axis coordinate).
Definition: Point.h:111
component y
Ordinate (vertical, or Y-axis coordinate).
Definition: Point.h:112
Generic vector of arbitrary length.
Definition: Vector.h:107
A linear geometric transformation on the plane defined as a 2x3 matrix of 64-bit floating point scala...
static LinearTransformation Null()
DPoint TransformInverse(const DPoint &p) const
DPoint Transform(const DPoint &p) const
LinearTransformation & operator=(const LinearTransformation &)=default
DPoint operator()(const DPoint &p) const
String ToString(int indent=0) const
LinearTransformation Multiply(const LinearTransformation &T) const
LinearTransformation(double a00, double a01, double a02, double a10, double a11, double a12)
LinearTransformation(const LinearTransformation &)=default
LinearTransformation Inverse() const
Unicode (UTF-16) string.
Definition: String.h:8113
String & AppendFormat(const_c_string8 fmt,...)
Definition: String.h:11103
PCL root namespace.
Definition: AbstractImage.h:77