PCL
Crop.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/Crop.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_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 ), m_mode( CropMode::RelativeMargins )
117  {
118  }
119 
124  template <typename T>
125  Crop( const GenericRectangle<T>& r ) :
126  m_margins( r ), m_mode( CropMode::RelativeMargins )
127  {
128  }
129 
133  Crop( const Crop& ) = default;
134 
138  Crop& operator =( const Crop& ) = default;
139 
144  DRect Margins() const
145  {
146  return m_margins;
147  }
148 
153  template <typename T>
155  {
156  m_margins = r;
157  }
158 
163  void SetMargins( int left, int top, int right, int bottom )
164  {
165  m_margins = Rect( left, top, right, bottom );
166  }
167 
171  crop_mode Mode() const
172  {
173  return m_mode;
174  }
175 
181  bool IsRelative() const
182  {
183  return m_mode == CropMode::RelativeMargins;
184  }
185 
191  bool IsAbsolute() const
192  {
193  return !IsRelative();
194  }
195 
199  void SetMode( crop_mode mode )
200  {
201  m_mode = mode;
202  }
203 
210  const DVector& FillValues() const
211  {
212  return m_fillValues;
213  }
214 
227  void SetFillValues( const DVector& fillValues )
228  {
229  m_fillValues = fillValues;
230  }
231 
234  void GetNewSizes( int& width, int& height ) const override;
235 
236 protected:
237 
238  DRect m_margins;
239  crop_mode m_mode;
240  DVector m_fillValues;
241 
242  // Inherited from ImageTransformation.
243  void Apply( pcl::Image& ) const override;
244  void Apply( pcl::DImage& ) const override;
245  void Apply( pcl::ComplexImage& ) const override;
246  void Apply( pcl::DComplexImage& ) const override;
247  void Apply( pcl::UInt8Image& ) const override;
248  void Apply( pcl::UInt16Image& ) const override;
249  void Apply( pcl::UInt32Image& ) const override;
250 };
251 
252 // ----------------------------------------------------------------------------
253 
254 } // pcl
255 
256 #endif // __PCL_Crop_h
257 
258 // ----------------------------------------------------------------------------
259 // EOF pcl/Crop.h - Released 2019-11-07T10:59:34Z
Image cropping/expansion algorithm
Definition: Crop.h:101
void SetMargins(const GenericRectangle< T > &r)
Definition: Crop.h:154
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:163
crop_mode Mode() const
Definition: Crop.h:171
CropMode::value_type crop_mode
Definition: Crop.h:109
void SetMode(crop_mode mode)
Definition: Crop.h:199
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:125
64-bit floating-point rectangle in the R^2 space.
Image resolution data
32-bit floating point complex image.
void Apply(FI i, FI j, F f)
Definition: Utility.h:249
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:181
void SetFillValues(const DVector &fillValues)
Definition: Crop.h:227
64-bit floating point real image.
32-bit unsigned integer image.
bool IsAbsolute() const
Definition: Crop.h:191
8-bit unsigned integer image.
const DVector & FillValues() const
Definition: Crop.h:210
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:144