PCL
Resample.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/Resample.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_Resample_h
53 #define __PCL_Resample_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
61 #include <pcl/ImageResolution.h>
62 #include <pcl/ParallelProcess.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
82 namespace ResizeMode
83 {
84  enum value_type
85  {
86  RelativeDimensions, // Resize relative to current image dimensions
87  AbsolutePixels, // ... to absolute dimensions in pixels
88  AbsoluteCentimeters, // ... to absolute dimensions in centimeters
89  AbsoluteInches, // ... to absolute dimensions in inches
90  ForceArea, // Force number of pixels, keep aspect ratio
91  NumberOfResizeModes,
92  Default = RelativeDimensions
93  };
94 }
95 
96 // ----------------------------------------------------------------------------
97 
113 namespace AbsoluteResizeMode
114 {
115  enum value_type
116  {
117  ForceWidthAndHeight, // Force both dimensions
118  ForceWidth, // Force width, preserve aspect ratio
119  ForceHeight, // Force height, preserve aspect ratio
120  NumberOfAbsoluteResizeModes,
121  Default = ForceWidthAndHeight
122  };
123 }
124 
125 // ----------------------------------------------------------------------------
126 
134  public ImageResolution,
135  public ParallelProcess
136 {
137 public:
138 
142  typedef ResizeMode::value_type resize_mode;
143 
147  typedef AbsoluteResizeMode::value_type abs_resize_mode;
148 
158  Resample( PixelInterpolation& p, double scale = 1.0 ) :
160  m_xSize( scale ), m_ySize( scale )
161  {
162  }
163 
174  Resample( PixelInterpolation& p, double scaleX, double scaleY ) :
176  m_xSize( scaleX ), m_ySize( scaleY )
177  {
178  }
179 
183  Resample( const Resample& ) = default;
184 
191  void GetSizes( double& width, double& height ) const
192  {
193  width = m_xSize; height = m_ySize;
194  }
195 
202  double XSize() const
203  {
204  return m_xSize;
205  }
206 
213  double YSize() const
214  {
215  return m_ySize;
216  }
217 
224  void SetSizes( double width, double height )
225  {
226  m_xSize = width; m_ySize = height;
227  }
228 
235  void SetXSize( double width )
236  {
237  m_xSize = width;
238  }
239 
246  void SetYSize( double height )
247  {
248  m_ySize = height;
249  }
250 
259  void GetScalingFactors( double& sx, double& sy ) const
260  {
261  GetSizes( sx, sy );
262  }
263 
271  double XScale() const
272  {
273  return XSize();
274  }
275 
283  double YScale() const
284  {
285  return YSize();
286  }
287 
296  void SetScalingFactors( double sx, double sy )
297  {
298  SetSizes( sx, sy );
299  }
300 
308  void SetXScale( double sx )
309  {
310  SetXSize( sx );
311  }
312 
320  void SetYScale( double sy )
321  {
322  SetYSize( sy );
323  }
324 
328  resize_mode Mode() const
329  {
330  return m_mode;
331  }
332 
338  bool IsRelative() const
339  {
340  return m_mode == ResizeMode::RelativeDimensions;
341  }
342 
347  bool IsAbsolute() const
348  {
349  return !IsRelative();
350  }
351 
355  void SetMode( resize_mode mode )
356  {
357  m_mode = mode;
358  }
359 
364  abs_resize_mode AbsMode() const
365  {
366  return m_absMode;
367  }
368 
373  void SetAbsMode( abs_resize_mode absMode )
374  {
375  m_absMode = absMode;
376  }
377 
380  void GetNewSizes( int& width, int& height ) const override;
381 
382 protected:
383 
384  double m_xSize = 1.0;
385  double m_ySize = 1.0;
386  resize_mode m_mode = ResizeMode::Default;
387  abs_resize_mode m_absMode = AbsoluteResizeMode::Default;
388 
389  // Inherited from ImageTransformation.
390  void Apply( pcl::Image& ) const override;
391  void Apply( pcl::DImage& ) const override;
392  void Apply( pcl::UInt8Image& ) const override;
393  void Apply( pcl::UInt16Image& ) const override;
394  void Apply( pcl::UInt32Image& ) const override;
395 };
396 
397 // ----------------------------------------------------------------------------
398 
399 } // pcl
400 
401 #endif // __PCL_Resample_h
402 
403 // ----------------------------------------------------------------------------
404 // EOF pcl/Resample.h - Released 2019-11-07T10:59:34Z
void SetYSize(double height)
Definition: Resample.h:246
void GetScalingFactors(double &sx, double &sy) const
Definition: Resample.h:259
Image resampling algorithm.
Definition: Resample.h:133
PCL root namespace.
Definition: AbstractImage.h:76
void SetYScale(double sy)
Definition: Resample.h:320
void SetMode(resize_mode mode)
Definition: Resample.h:355
resize_mode Mode() const
Definition: Resample.h:328
abs_resize_mode AbsMode() const
Definition: Resample.h:364
16-bit unsigned integer image.
Resample(PixelInterpolation &p, double scaleX, double scaleY)
Definition: Resample.h:174
void SetScalingFactors(double sx, double sy)
Definition: Resample.h:296
ResizeMode::value_type resize_mode
Definition: Resample.h:142
Image resolution data
void Apply(FI i, FI j, F f)
Definition: Utility.h:249
AbsoluteResizeMode::value_type abs_resize_mode
Definition: Resample.h:147
double YScale() const
Definition: Resample.h:283
bool IsRelative() const
Definition: Resample.h:338
64-bit floating point real image.
double YSize() const
Definition: Resample.h:213
32-bit unsigned integer image.
void GetSizes(double &width, double &height) const
Definition: Resample.h:191
8-bit unsigned integer image.
Abstract base class of all PCL interpolating geometric image transformations.
bool IsAbsolute() const
Definition: Resample.h:347
void SetXScale(double sx)
Definition: Resample.h:308
double XScale() const
Definition: Resample.h:271
void SetSizes(double width, double height)
Definition: Resample.h:224
void SetXSize(double width)
Definition: Resample.h:235
void SetAbsMode(abs_resize_mode absMode)
Definition: Resample.h:373
double XSize() const
Definition: Resample.h:202
Abstract root base class for all pixel interpolation algorithms.
32-bit floating point real image.
A process using multiple concurrent execution threads.
Resample(PixelInterpolation &p, double scale=1.0)
Definition: Resample.h:158