PCL
LocalNormalizationData.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.4.0
6 // ----------------------------------------------------------------------------
7 // pcl/LocalNormalizationData.h - Released 2020-07-31T19:33:04Z
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 (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_LocalNormalizationData_h
53 #define __PCL_LocalNormalizationData_h
54 
56 
57 #include <pcl/Defs.h>
58 
60 #include <pcl/File.h>
61 #include <pcl/Image.h>
62 #include <pcl/TimePoint.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
69 class PCL_CLASS XMLDocument;
70 class PCL_CLASS XMLElement;
71 
109 class PCL_CLASS LocalNormalizationData
110 {
111 public:
112 
117 
121  typedef normalization_matrices::sample normalization_coefficient;
122 
129 
134 
138  LocalNormalizationData() = default;
139 
144 
149 
169  LocalNormalizationData( const String& filePath, bool ignoreNormalizationData = false )
170  {
171  Parse( filePath, ignoreNormalizationData );
172  }
173 
193  LocalNormalizationData( const XMLDocument& xml, bool ignoreNormalizationData = false )
194  {
195  Parse( xml, ignoreNormalizationData );
196  }
197 
217  LocalNormalizationData( const XMLElement& element, bool ignoreNormalizationData = false )
218  {
219  Parse( element, ignoreNormalizationData );
220  }
221 
226  {
227  }
228 
236  const String& ReferenceFilePath() const
237  {
238  return m_referenceFilePath;
239  }
240 
247  void SetReferenceFilePath( const String& filePath )
248  {
249  m_referenceFilePath = File::FullPath( filePath );
250  }
251 
266  const String& TargetFilePath() const
267  {
268  return m_targetFilePath;
269  }
270 
277  void SetTargetFilePath( const String& filePath )
278  {
279  m_targetFilePath = File::FullPath( filePath );
280  }
281 
290  int NormalizationScale() const
291  {
292  return m_scale;
293  }
294 
301  void SetNormalizationScale( int scale )
302  {
303  m_scale = scale;
304  }
305 
312  int ReferenceWidth() const
313  {
314  return m_referenceWidth;
315  }
316 
323  int ReferenceHeight() const
324  {
325  return m_referenceHeight;
326  }
327 
334  void SetReferenceDimensions( int width, int height )
335  {
336  m_referenceWidth = width;
337  m_referenceHeight = height;
338  }
339 
345  int NumberOfChannels() const
346  {
347  return m_A.NumberOfChannels();
348  }
349 
359  const normalization_matrices& ZeroOffset() const
360  {
361  return m_B;
362  }
363 
373  const normalization_matrices& Scale() const
374  {
375  return m_A;
376  }
377 
392  void SetNormalizationMatrices( const normalization_matrices& A, const normalization_matrices& B )
393  {
394  if ( A.Bounds() != B.Bounds() || A.NumberOfChannels() != B.NumberOfChannels() )
395  throw Error( "LocalNormalizationData::SetNormalizationMatrices(): Incompatible matrix dimensions." );
396  m_A = A;
397  m_B = B;
398  }
399 
418  void InitInterpolations();
419 
424  bool HasInterpolations() const
425  {
426  return !m_UA.IsEmpty() && !m_UB.IsEmpty();
427  }
428 
451  double operator()( double z, int x, int y, int c = 0 ) const
452  {
453  double sx = m_sx*x;
454  double sy = m_sy*y;
455  return m_UA[c]( sx, sy )*z + m_UB[c]( sx, sy );
456  }
457 
463  {
464  return m_creationTime;
465  }
466 
471  void Clear();
472 
493  void Parse( const String& filePath, bool ignoreNormalizationData = false );
494 
516  void Parse( const XMLDocument& xml, bool ignoreNormalizationData = false );
517 
539  void Parse( const XMLElement& element, bool ignoreNormalizationData = false );
540 
551  bool IsCompressionEnabled() const
552  {
553  return m_compressionEnabled;
554  }
555 
561  void EnableCompression( bool enable = true )
562  {
563  m_compressionEnabled = enable;
564  }
565 
571  void DisableCompression( bool disable = true )
572  {
573  EnableCompression( !disable );
574  }
575 
583  XMLDocument* Serialize() const;
584 
593  void SerializeToFile( const String& path ) const;
594 
595 private:
596 
597  String m_referenceFilePath; // path to the normalization reference image
598  String m_targetFilePath; // path to the normalization target image
599  int m_scale = -1; // normalization scale in px
600  int m_referenceWidth = -1; // reference image width in px
601  int m_referenceHeight = -1; // reference image height in px
602  normalization_matrices m_A; // scaling coefficients
603  normalization_matrices m_B; // zero offset coefficients
604  matrix_interpolations m_UA; // interpolators for m_A
605  matrix_interpolations m_UB; // interpolators for m_B
606  double m_sx; // coordinate scaling factor, X axis
607  double m_sy; // coordinate scaling factor, Y axis
608  TimePoint m_creationTime;
609  bool m_compressionEnabled = true;
610 
611  void ParseNormalizationMatrices( normalization_matrices&, const XMLElement& ) const;
612  void SerializeNormalizationMatrices( XMLElement*, const normalization_matrices& ) const;
613 };
614 
615 // ----------------------------------------------------------------------------
616 
617 } // pcl
618 
619 #endif // __PCL_LocalNormalizationData_h
620 
621 // ----------------------------------------------------------------------------
622 // EOF pcl/LocalNormalizationData.h - Released 2020-07-31T19:33:04Z
const normalization_matrices & Scale() const
LocalNormalizationData(const XMLElement &element, bool ignoreNormalizationData=false)
An instant in any timescale.
Definition: TimePoint.h:102
double operator()(double z, int x, int y, int c=0) const
LocalNormalizationData(const XMLDocument &xml, bool ignoreNormalizationData=false)
Array< matrix_interpolation > matrix_interpolations
PCL root namespace.
Definition: AbstractImage.h:76
XML document parsing and generation
Definition: XML.h:2560
void SetReferenceDimensions(int width, int height)
Bicubic B-Spline Interpolation Algorithm.
Unicode (UTF-16) string.
Definition: String.h:7916
const normalization_matrices & ZeroOffset() const
const String & ReferenceFilePath() const
64-bit floating point real image.
LocalNormalizationData(const String &filePath, bool ignoreNormalizationData=false)
BicubicBSplineInterpolation< normalization_coefficient > matrix_interpolation
void SetReferenceFilePath(const String &filePath)
void SetTargetFilePath(const String &filePath)
A simple exception with an associated error message.
Definition: Exception.h:238
void EnableCompression(bool enable=true)
XML element
Definition: XML.h:1137
Normalization data parser and generator.
normalization_matrices::sample normalization_coefficient
static String FullPath(const String &path)
void DisableCompression(bool disable=true)
const String & TargetFilePath() const
void SetNormalizationMatrices(const normalization_matrices &A, const normalization_matrices &B)