PCL
Resample.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.4.7
6 // ----------------------------------------------------------------------------
7 // pcl/Resample.h - Released 2020-12-17T15:46:29Z
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-2020 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_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 )
161  , m_ySize( scale )
162  {
163  }
164 
175  Resample( PixelInterpolation& p, double scaleX, double scaleY )
177  , m_xSize( scaleX )
178  , m_ySize( scaleY )
179  {
180  }
181 
185  Resample( const Resample& ) = default;
186 
193  void GetSizes( double& width, double& height ) const
194  {
195  width = m_xSize; height = m_ySize;
196  }
197 
204  double XSize() const
205  {
206  return m_xSize;
207  }
208 
215  double YSize() const
216  {
217  return m_ySize;
218  }
219 
226  void SetSizes( double width, double height )
227  {
228  m_xSize = width; m_ySize = height;
229  }
230 
237  void SetXSize( double width )
238  {
239  m_xSize = width;
240  }
241 
248  void SetYSize( double height )
249  {
250  m_ySize = height;
251  }
252 
261  void GetScalingFactors( double& sx, double& sy ) const
262  {
263  GetSizes( sx, sy );
264  }
265 
273  double XScale() const
274  {
275  return XSize();
276  }
277 
285  double YScale() const
286  {
287  return YSize();
288  }
289 
298  void SetScalingFactors( double sx, double sy )
299  {
300  SetSizes( sx, sy );
301  }
302 
310  void SetXScale( double sx )
311  {
312  SetXSize( sx );
313  }
314 
322  void SetYScale( double sy )
323  {
324  SetYSize( sy );
325  }
326 
330  resize_mode Mode() const
331  {
332  return m_mode;
333  }
334 
340  bool IsRelative() const
341  {
342  return m_mode == ResizeMode::RelativeDimensions;
343  }
344 
349  bool IsAbsolute() const
350  {
351  return !IsRelative();
352  }
353 
357  void SetMode( resize_mode mode )
358  {
359  m_mode = mode;
360  }
361 
366  abs_resize_mode AbsMode() const
367  {
368  return m_absMode;
369  }
370 
375  void SetAbsMode( abs_resize_mode absMode )
376  {
377  m_absMode = absMode;
378  }
379 
382  void GetNewSizes( int& width, int& height ) const override;
383 
384 protected:
385 
386  double m_xSize = 1.0;
387  double m_ySize = 1.0;
388  resize_mode m_mode = ResizeMode::Default;
389  abs_resize_mode m_absMode = AbsoluteResizeMode::Default;
390 
391  // Inherited from ImageTransformation.
392  void Apply( pcl::Image& ) const override;
393  void Apply( pcl::DImage& ) const override;
394  void Apply( pcl::UInt8Image& ) const override;
395  void Apply( pcl::UInt16Image& ) const override;
396  void Apply( pcl::UInt32Image& ) const override;
397 };
398 
399 // ----------------------------------------------------------------------------
400 
401 } // pcl
402 
403 #endif // __PCL_Resample_h
404 
405 // ----------------------------------------------------------------------------
406 // EOF pcl/Resample.h - Released 2020-12-17T15:46:29Z
void SetYSize(double height)
Definition: Resample.h:248
void GetScalingFactors(double &sx, double &sy) const
Definition: Resample.h:261
Image resampling algorithm.
Definition: Resample.h:133
PCL root namespace.
Definition: AbstractImage.h:76
void SetYScale(double sy)
Definition: Resample.h:322
void SetMode(resize_mode mode)
Definition: Resample.h:357
resize_mode Mode() const
Definition: Resample.h:330
abs_resize_mode AbsMode() const
Definition: Resample.h:366
16-bit unsigned integer image.
Resample(PixelInterpolation &p, double scaleX, double scaleY)
Definition: Resample.h:175
void SetScalingFactors(double sx, double sy)
Definition: Resample.h:298
ResizeMode::value_type resize_mode
Definition: Resample.h:142
Image resolution data
AbsoluteResizeMode::value_type abs_resize_mode
Definition: Resample.h:147
double YScale() const
Definition: Resample.h:285
void Apply(FI i, FI j, F f) noexcept(noexcept(f))
Definition: Utility.h:249
bool IsRelative() const
Definition: Resample.h:340
64-bit floating point real image.
double YSize() const
Definition: Resample.h:215
32-bit unsigned integer image.
void GetSizes(double &width, double &height) const
Definition: Resample.h:193
8-bit unsigned integer image.
Abstract base class of all PCL interpolating geometric image transformations.
bool IsAbsolute() const
Definition: Resample.h:349
void SetXScale(double sx)
Definition: Resample.h:310
double XScale() const
Definition: Resample.h:273
void SetSizes(double width, double height)
Definition: Resample.h:226
void SetXSize(double width)
Definition: Resample.h:237
void SetAbsMode(abs_resize_mode absMode)
Definition: Resample.h:375
double XSize() const
Definition: Resample.h:204
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