PCL
ImageTransformation.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.11
6 // ----------------------------------------------------------------------------
7 // pcl/ImageTransformation.h - Released 2024-05-07T15:27:32Z
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_ImageTransformation_h
53 #define __PCL_ImageTransformation_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
60 #include <pcl/Exception.h>
61 #include <pcl/ImageVariant.h>
62 
63 namespace pcl
64 {
65 
66 // ----------------------------------------------------------------------------
67 
90 class PCL_CLASS ImageTransformation
91 {
92 public:
93 
97  ImageTransformation() = default;
98 
103 
108  {
109  }
110 
119  template <class P>
121  {
122  Apply( image );
123  return image;
124  }
125 
138  {
139  if ( image )
140  if ( image.IsFloatSample() )
141  switch ( image.BitsPerSample() )
142  {
143  case 32: Apply( static_cast<pcl::Image&>( *image ) ); break;
144  case 64: Apply( static_cast<pcl::DImage&>( *image ) ); break;
145  }
146  else if ( image.IsComplexSample() )
147  switch ( image.BitsPerSample() )
148  {
149  case 32: Apply( static_cast<pcl::ComplexImage&>( *image ) ); break;
150  case 64: Apply( static_cast<pcl::DComplexImage&>( *image ) ); break;
151  }
152  else
153  switch ( image.BitsPerSample() )
154  {
155  case 8: Apply( static_cast<pcl::UInt8Image&>( *image ) ); break;
156  case 16: Apply( static_cast<pcl::UInt16Image&>( *image ) ); break;
157  case 32: Apply( static_cast<pcl::UInt32Image&>( *image ) ); break;
158  }
159  return image;
160  }
161 
162 protected:
163 
167  virtual void Apply( pcl::Image& image ) const
168  {
169  throw NotImplemented( *this, "Apply to 32-bit floating-point images" );
170  }
171 
175  virtual void Apply( pcl::DImage& image ) const
176  {
177  throw NotImplemented( *this, "Apply to 64-bit floating-point images" );
178  }
179 
183  virtual void Apply( pcl::ComplexImage& image ) const
184  {
185  throw NotImplemented( *this, "Apply to 32-bit complex images" );
186  }
187 
191  virtual void Apply( pcl::DComplexImage& image ) const
192  {
193  throw NotImplemented( *this, "Apply to 64-bit complex images" );
194  }
195 
199  virtual void Apply( pcl::UInt8Image& image ) const
200  {
201  throw NotImplemented( *this, "Apply to 8-bit integer images" );
202  }
203 
207  virtual void Apply( pcl::UInt16Image& image ) const
208  {
209  throw NotImplemented( *this, "Apply to 16-bit integer images" );
210  }
211 
215  virtual void Apply( pcl::UInt32Image& image ) const
216  {
217  throw NotImplemented( *this, "Apply to 32-bit integer images" );
218  }
219 };
220 
221 // ----------------------------------------------------------------------------
222 
237 {
238 public:
239 
244 
249 
254  {
255  }
256 
266  template <class P>
268  {
269  Transform( image );
270  return image;
271  }
272 
283  const ImageVariant& operator <<( const ImageVariant& image )
284  {
285  if ( image )
286  if ( image.IsFloatSample() )
287  switch ( image.BitsPerSample() )
288  {
289  case 32: Transform( static_cast<const pcl::Image&>( *image ) ); break;
290  case 64: Transform( static_cast<const pcl::DImage&>( *image ) ); break;
291  }
292  else if ( image.IsComplexSample() )
293  switch ( image.BitsPerSample() )
294  {
295  case 32: Transform( static_cast<const pcl::ComplexImage&>( *image ) ); break;
296  case 64: Transform( static_cast<const pcl::DComplexImage&>( *image ) ); break;
297  }
298  else
299  switch ( image.BitsPerSample() )
300  {
301  case 8: Transform( static_cast<const pcl::UInt8Image&>( *image ) ); break;
302  case 16: Transform( static_cast<const pcl::UInt16Image&>( *image ) ); break;
303  case 32: Transform( static_cast<const pcl::UInt32Image&>( *image ) ); break;
304  }
305  return image;
306  }
307 
308 protected:
309 
313  virtual void Transform( const pcl::Image& image )
314  {
315  throw NotImplemented( *this, "Transformation of 32-bit floating-point images" );
316  }
317 
321  virtual void Transform( const pcl::DImage& image )
322  {
323  throw NotImplemented( *this, "Transformation of 64-bit floating-point images" );
324  }
325 
329  virtual void Transform( const pcl::ComplexImage& image )
330  {
331  throw NotImplemented( *this, "Transformation of 32-bit complex images" );
332  }
333 
337  virtual void Transform( const pcl::DComplexImage& image )
338  {
339  throw NotImplemented( *this, "Transformation of 64-bit complex images" );
340  }
341 
345  virtual void Transform( const pcl::UInt8Image& image )
346  {
347  throw NotImplemented( *this, "Transformation of 8-bit integer images" );
348  }
349 
353  virtual void Transform( const pcl::UInt16Image& image )
354  {
355  throw NotImplemented( *this, "Transformation of 16-bit integer images" );
356  }
357 
361  virtual void Transform( const pcl::UInt32Image& image )
362  {
363  throw NotImplemented( *this, "Transformation of 32-bit integer images" );
364  }
365 };
366 
367 // ----------------------------------------------------------------------------
368 // ----------------------------------------------------------------------------
369 
370 /*
371  * Implementation of members of GenericImage<> requiring a complete declaration
372  * of ImageTransformation.
373  */
374 
375 // ----------------------------------------------------------------------------
376 
377 template <class P> inline
379  const Rect& rect, int firstChannel, int lastChannel )
380 {
381  Rect r = rect;
382  if ( !ParseSelection( r, firstChannel, lastChannel ) )
383  return *this;
384 
385  PushSelections();
386  SelectRectangle( r );
387  SelectChannelRange( firstChannel, lastChannel );
388 
389  try
390  {
391  transformation >> *this;
392  PopSelections();
393  }
394  catch ( ... )
395  {
396  PopSelections();
397  throw;
398  }
399 
400  return *this;
401 }
402 
403 // ----------------------------------------------------------------------------
404 
405 template <class P> inline
407  const Rect& rect, int firstChannel, int lastChannel ) const
408 {
409  Rect r = rect;
410  if ( !ParseSelection( r, firstChannel, lastChannel ) )
411  return;
412 
413  PushSelections();
414  SelectRectangle( r );
415  SelectChannelRange( firstChannel, lastChannel );
416 
417  try
418  {
419  transform << *this;
420  PopSelections();
421  }
422  catch ( ... )
423  {
424  PopSelections();
425  throw;
426  }
427 }
428 
429 // ----------------------------------------------------------------------------
430 
431 } // pcl
432 
433 #endif // __PCL_ImageTransformation_h
434 
435 // ----------------------------------------------------------------------------
436 // EOF pcl/ImageTransformation.h - Released 2024-05-07T15:27:32Z
Root base class for bidirectional PCL image transformations.
virtual void Transform(const pcl::Image &image)
virtual void Transform(const pcl::DComplexImage &image)
virtual void Transform(const pcl::ComplexImage &image)
virtual void Transform(const pcl::DImage &image)
virtual void Transform(const pcl::UInt16Image &image)
virtual void Transform(const pcl::UInt8Image &image)
virtual void Transform(const pcl::UInt32Image &image)
BidirectionalImageTransformation(const BidirectionalImageTransformation &)=default
Implements a generic, two-dimensional, shared or local image.
Definition: Image.h:278
void Transform(BidirectionalImageTransformation &transform, const Rect &rect=Rect(0), int firstChannel=-1, int lastChannel=-1) const
GenericImage & Apply(T scalar, image_op op=ImageOp::Mov, const Rect &rect=Rect(0), int firstChannel=-1, int lastChannel=-1)
Definition: Image.h:9119
A generic rectangle in the two-dimensional space.
Definition: Rectangle.h:314
Root base class of all PCL image transformations.
virtual void Apply(pcl::ComplexImage &image) const
ImageTransformation(const ImageTransformation &)=default
virtual void Apply(pcl::UInt32Image &image) const
virtual void Apply(pcl::DImage &image) const
virtual void Apply(pcl::Image &image) const
virtual void Apply(pcl::UInt8Image &image) const
virtual void Apply(pcl::UInt16Image &image) const
virtual void Apply(pcl::DComplexImage &image) const
Acts like a union for all types of images in PCL, with optional class-wide ownership of transported i...
Definition: ImageVariant.h:322
bool IsFloatSample() const noexcept
Definition: ImageVariant.h:441
bool IsComplexSample() const noexcept
Definition: ImageVariant.h:449
int BitsPerSample() const noexcept
Definition: ImageVariant.h:458
An exception that indicates an unsupported feature.
Definition: Exception.h:344
Array< T, A > & operator<<(Array< T, A > &x, const V &v)
Definition: Array.h:2118
Console & operator>>(Console &o, char &c)
Definition: Console.h:803
void Apply(FI i, FI j, F f) noexcept(noexcept(f))
Definition: Utility.h:249
PCL root namespace.
Definition: AbstractImage.h:77