PCL
Crop.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.4.7
6 // ----------------------------------------------------------------------------
7 // pcl/Crop.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_Crop_h
53 #define __PCL_Crop_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
61 #include <pcl/ImageResolution.h>
62 
63 namespace pcl
64 {
65 
66 // ----------------------------------------------------------------------------
67 
79 namespace CropMode
80 {
81  enum value_type
82  {
83  RelativeMargins, // Cropping margins are relative to current image dimensions
84  AbsolutePixels, // Absolute cropping margins in pixels
85  AbsoluteCentimeters, // Absolute cropping margins in centimeters
86  AbsoluteInches // Absolute cropping margins in inches
87  };
88 }
89 
90 // ----------------------------------------------------------------------------
91 
101 class PCL_CLASS Crop : public GeometricTransformation,
102  public ImageResolution
103 {
104 public:
105 
109  typedef CropMode::value_type crop_mode;
110 
115  Crop( double left = 0, double top = 0, double right = 0, double bottom = 0 )
116  : m_margins( left, top, right, bottom )
117  , m_mode( CropMode::RelativeMargins )
118  {
119  }
120 
125  template <typename T>
127  : m_margins( r )
128  , m_mode( CropMode::RelativeMargins )
129  {
130  }
131 
135  Crop( const Crop& ) = default;
136 
140  Crop& operator =( const Crop& ) = default;
141 
146  DRect Margins() const
147  {
148  return m_margins;
149  }
150 
155  template <typename T>
157  {
158  m_margins = r;
159  }
160 
165  void SetMargins( int left, int top, int right, int bottom )
166  {
167  m_margins = Rect( left, top, right, bottom );
168  }
169 
173  crop_mode Mode() const
174  {
175  return m_mode;
176  }
177 
183  bool IsRelative() const
184  {
185  return m_mode == CropMode::RelativeMargins;
186  }
187 
193  bool IsAbsolute() const
194  {
195  return !IsRelative();
196  }
197 
201  void SetMode( crop_mode mode )
202  {
203  m_mode = mode;
204  }
205 
212  const DVector& FillValues() const
213  {
214  return m_fillValues;
215  }
216 
229  void SetFillValues( const DVector& fillValues )
230  {
231  m_fillValues = fillValues;
232  }
233 
236  void GetNewSizes( int& width, int& height ) const override;
237 
238 protected:
239 
240  DRect m_margins;
241  crop_mode m_mode;
242  DVector m_fillValues;
243 
244  // Inherited from ImageTransformation.
245  void Apply( pcl::Image& ) const override;
246  void Apply( pcl::DImage& ) const override;
247  void Apply( pcl::ComplexImage& ) const override;
248  void Apply( pcl::DComplexImage& ) const override;
249  void Apply( pcl::UInt8Image& ) const override;
250  void Apply( pcl::UInt16Image& ) const override;
251  void Apply( pcl::UInt32Image& ) const override;
252 };
253 
254 // ----------------------------------------------------------------------------
255 
256 } // pcl
257 
258 #endif // __PCL_Crop_h
259 
260 // ----------------------------------------------------------------------------
261 // EOF pcl/Crop.h - Released 2020-12-17T15:46:29Z
Image cropping/expansion algorithm
Definition: Crop.h:101
void SetMargins(const GenericRectangle< T > &r)
Definition: Crop.h:156
Abstract base class of all PCL geometric image transformations.
PCL root namespace.
Definition: AbstractImage.h:76
void SetMargins(int left, int top, int right, int bottom)
Definition: Crop.h:165
crop_mode Mode() const
Definition: Crop.h:173
CropMode::value_type crop_mode
Definition: Crop.h:109
void SetMode(crop_mode mode)
Definition: Crop.h:201
16-bit unsigned integer image.
A generic rectangle in the two-dimensional space.
Definition: Rectangle.h:313
Crop(const GenericRectangle< T > &r)
Definition: Crop.h:126
64-bit floating-point rectangle in the R^2 space.
Image resolution data
32-bit floating point complex image.
Crop(double left=0, double top=0, double right=0, double bottom=0)
Definition: Crop.h:115
64-bit floating point real vector.
bool IsRelative() const
Definition: Crop.h:183
void Apply(FI i, FI j, F f) noexcept(noexcept(f))
Definition: Utility.h:249
void SetFillValues(const DVector &fillValues)
Definition: Crop.h:229
64-bit floating point real image.
32-bit unsigned integer image.
bool IsAbsolute() const
Definition: Crop.h:193
8-bit unsigned integer image.
const DVector & FillValues() const
Definition: Crop.h:212
64-bit floating point complex image.
32-bit integer rectangle on the plane.
32-bit floating point real image.
DRect Margins() const
Definition: Crop.h:146