PCL
DrizzleData.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.11
6 // ----------------------------------------------------------------------------
7 // pcl/DrizzleData.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_DrizzleData_h
53 #define __PCL_DrizzleData_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/File.h>
60 #include <pcl/GridInterpolation.h>
61 #include <pcl/MultiVector.h>
62 #include <pcl/SurfaceSpline.h>
63 #include <pcl/TimePoint.h>
64 
65 namespace pcl
66 {
67 
68 // ----------------------------------------------------------------------------
69 
83 namespace DrizzleParserOption
84 {
85  enum mask_type
86  {
87  IgnoreIntegrationData = 0x00000001,
88  RequireIntegrationData = 0x00000002,
89  };
90 }
91 
96 using DrizzleParserOptions = Flags<DrizzleParserOption::mask_type>;
97 
98 // ----------------------------------------------------------------------------
99 
100 class PCL_CLASS XMLDocument;
101 class PCL_CLASS XMLElement;
102 
142 class PCL_CLASS DrizzleData
143 {
144 public:
145 
152 
158 
165 
171 
177 
182 
186  DrizzleData() = default;
187 
191  DrizzleData( const DrizzleData& ) = default;
192 
196  DrizzleData( DrizzleData&& ) = default;
197 
218  {
219  Parse( filePath, options );
220  }
221 
239  {
240  Parse( xml, options );
241  }
242 
258  {
259  Parse( element, options );
260  }
261 
265  virtual ~DrizzleData()
266  {
267  }
268 
272  DrizzleData& operator =( const DrizzleData& ) = default;
273 
277  DrizzleData& operator =( DrizzleData&& ) = default;
278 
289  const String& SourceFilePath() const
290  {
291  return m_sourceFilePath;
292  }
293 
300  void SetSourceFilePath( const String& filePath )
301  {
302  m_sourceFilePath = File::FullPath( filePath );
303  }
304 
315  const String& CFASourceFilePath() const
316  {
317  return m_cfaSourceFilePath;
318  }
319 
326  void SetCFASourceFilePath( const String& filePath )
327  {
328  m_cfaSourceFilePath = File::FullPath( filePath );
329  }
330 
342  const String& CFASourcePattern() const
343  {
344  return m_cfaSourcePattern;
345  }
346 
356  void SetCFASourcePattern( const String& cfaPattern )
357  {
358  m_cfaSourcePattern = cfaPattern;
359  }
360 
382  int CFASourceChannel() const
383  {
384  return m_cfaSourceChannel;
385  }
386 
398  void SetCFASourceChannel( int channel )
399  {
400  m_cfaSourceChannel = Range( channel, -1, int( int32_max ) );
401  }
402 
420  {
421  return m_alignTargetFilePath;
422  }
423 
430  void SetAlignmentTargetFilePath( const String& filePath )
431  {
432  m_alignTargetFilePath = File::FullPath( filePath );
433  }
434 
440  int ReferenceWidth() const
441  {
442  return m_referenceWidth;
443  }
444 
450  int ReferenceHeight() const
451  {
452  return m_referenceHeight;
453  }
454 
461  void SetReferenceDimensions( int width, int height )
462  {
463  m_referenceWidth = width;
464  m_referenceHeight = height;
465  }
466 
471  int NumberOfChannels() const
472  {
473  return m_location.Length();
474  }
475 
483  const DPoint& AlignmentOrigin() const
484  {
485  return m_alignmentOrigin;
486  }
487 
499  void SetAlignmentOrigin( const DPoint& p0 )
500  {
501  m_alignmentOrigin = p0;
502  }
503 
511  const Matrix& AlignmentMatrix() const
512  {
513  return m_H;
514  }
515 
522  void SetAlignmentMatrix( const Matrix& H )
523  {
524  m_H = H;
525  }
526 
533  bool HasAlignmentMatrix() const
534  {
535  return !m_H.IsEmpty();
536  }
537 
547  {
548  return m_S;
549  }
550 
559  {
560  m_S = S;
561  }
562 
570  bool HasAlignmentSplines() const
571  {
572  return m_S.IsValid();
573  }
574 
584  {
585  return m_Sinv;
586  }
587 
596  {
597  m_Sinv = Sinv;
598  }
599 
608  {
609  return m_Sinv.IsValid();
610  }
611 
665  point_list& P2, point_list& D1,
666  weight_vector& W,
667  int& order, float& regularization, bool& extrapolate )
668  {
669  P1 = m_LP1;
670  D2 = m_LD2;
671  P2 = m_LP2;
672  D1 = m_LD1;
673  W = m_LW;
674  order = m_localDistortionOrder;
675  regularization = m_localDistortionRegularization;
676  extrapolate = m_localDistortionExtrapolation;
677  }
678 
690  {
691  return !m_LP1.IsEmpty();
692  }
693 
701  const String& Metadata() const
702  {
703  return m_metadata;
704  }
705 
712  void SetMetadata( const String& metadata )
713  {
714  m_metadata = metadata.Trimmed();
715  }
716 
730  const DVector& Location() const
731  {
732  return m_location;
733  }
734 
743  void SetLocation( const DVector& v )
744  {
745  m_location = v;
746  }
747 
762  const DVector& ReferenceLocation() const
763  {
764  return m_referenceLocation;
765  }
766 
775  void SetReferenceLocation( const DVector& v )
776  {
777  m_referenceLocation = v;
778  }
779 
804  const DVector& Scale() const
805  {
806  if ( !m_scale.IsEmpty() )
807  return m_scale;
808  if ( m_unitScale.IsEmpty() )
809  m_unitScale = DVector( 1.0, NumberOfChannels() );
810  return m_unitScale;
811  }
812 
820  void SetScale( const DVector& v )
821  {
822  m_scale = v;
823  }
824 
837  {
838  return m_adaptiveCoordinates;
839  }
840 
849  {
850  m_adaptiveCoordinates = points;
851  }
852 
869  {
870  return m_adaptiveLocation;
871  }
872 
882  {
883  m_adaptiveLocation = m;
884  }
885 
934  {
935  sLow = m_adaptiveScaleLow;
936  sHigh = m_adaptiveScaleHigh;
937  }
938 
947  {
948  m_adaptiveScaleLow = sLow;
949  m_adaptiveScaleHigh = sHigh;
950  }
951 
970  {
971  mLow = m_adaptiveZeroOffsetLow;
972  mHigh = m_adaptiveZeroOffsetHigh;
973  }
974 
983  {
984  m_adaptiveZeroOffsetLow = mLow;
985  m_adaptiveZeroOffsetHigh = mHigh;
986  }
987 
995  {
996  return !m_adaptiveCoordinates.IsEmpty() &&
997  !m_adaptiveLocation.IsEmpty() &&
998  !m_adaptiveScaleLow.IsEmpty() &&
999  !m_adaptiveScaleHigh.IsEmpty() &&
1000  !m_adaptiveZeroOffsetLow.IsEmpty() &&
1001  !m_adaptiveZeroOffsetHigh.IsEmpty();
1002  }
1003 
1008  double Pedestal() const
1009  {
1010  return m_pedestal;
1011  }
1012 
1018  void SetPedestal( double p )
1019  {
1020  m_pedestal = Range( p, 0.0, 1.0 );
1021  }
1022 
1034  const DVector& Weight() const
1035  {
1036  if ( !m_weight.IsEmpty() )
1037  return m_weight;
1038  if ( m_unitWeight.IsEmpty() )
1039  m_unitWeight = DVector( 1.0, NumberOfChannels() );
1040  return m_unitWeight;
1041  }
1042 
1050  void SetWeight( const DVector& v )
1051  {
1052  m_weight = v;
1053  }
1054 
1061  bool HasIntegrationData() const
1062  {
1063  return !m_location.IsEmpty();
1064  }
1065 
1072  bool HasImageWeightsData() const
1073  {
1074  return !m_weight.IsEmpty();
1075  }
1076 
1089  {
1090  return m_rejectionLowCount;
1091  }
1092 
1105  {
1106  return m_rejectionHighCount;
1107  }
1108 
1156  const UInt8Image& RejectionMap() const
1157  {
1158  return m_rejectionMap;
1159  }
1160 
1167  bool IsRejected( const Point& position, int channel = 0 ) const
1168  {
1169  return m_rejectionMap.Includes( position )
1170  && m_rejectionMap.IsValidChannelIndex( channel )
1171  && (m_rejectionMap( position, channel ) & 0x3F) != 0;
1172  }
1173 
1181  void SetRejectionMap( const UInt8Image& map )
1182  {
1183  m_rejectionMap = map;
1184  }
1185 
1190  bool HasRejectionData() const
1191  {
1192  return !m_rejectionMap.IsEmpty();
1193  }
1194 
1200  {
1201  return m_creationTime;
1202  }
1203 
1208  void Clear();
1209 
1217 
1238  void Parse( const String& filePath, DrizzleParserOptions options = DrizzleParserOptions() );
1239 
1259 
1277  void Parse( const XMLElement& element, DrizzleParserOptions options = DrizzleParserOptions() );
1278 
1290  {
1291  return m_compressionEnabled;
1292  }
1293 
1299  void EnableCompression( bool enable = true )
1300  {
1301  m_compressionEnabled = enable;
1302  }
1303 
1309  void DisableCompression( bool disable = true )
1310  {
1311  EnableCompression( !disable );
1312  }
1313 
1322 
1331  void SerializeToFile( const String& path ) const;
1332 
1333 private:
1334 
1335  String m_sourceFilePath;
1336  String m_cfaSourceFilePath;
1337  String m_cfaSourcePattern;
1338  int m_cfaSourceChannel = -1;
1339  String m_alignTargetFilePath;
1340  int m_referenceWidth = -1;
1341  int m_referenceHeight = -1;
1342  DPoint m_alignmentOrigin = 0.5;
1343  Matrix m_H;
1344  vector_spline m_S;
1345  vector_spline m_Sinv;
1346  point_list m_LP1; // D* = deprecated
1347  point_list m_LD2; // D*
1348  point_list m_LP2; // D*
1349  point_list m_LD1; // D*
1350  weight_vector m_LW; // D*
1351  int m_localDistortionOrder = 2; // D*
1352  float m_localDistortionRegularization = 0.01F; // D*
1353  bool m_localDistortionExtrapolation = true; // D*
1354  String m_metadata;
1355  double m_pedestal = 0.0;
1356  Vector m_location;
1357  Vector m_referenceLocation;
1358  Vector m_scale;
1359  mutable Vector m_unitScale;
1360  Vector m_weight;
1361  mutable Vector m_unitWeight;
1362  point_list m_adaptiveCoordinates;
1363  MultiVector m_adaptiveLocation;
1364  MultiVector m_adaptiveScaleLow;
1365  MultiVector m_adaptiveScaleHigh;
1366  MultiVector m_adaptiveZeroOffsetLow;
1367  MultiVector m_adaptiveZeroOffsetHigh;
1368  UI64Vector m_rejectionLowCount;
1369  UI64Vector m_rejectionHighCount;
1370  UInt8Image m_rejectionMap;
1371  TimePoint m_creationTime;
1372  bool m_compressionEnabled = true;
1373 
1374  // Working data for spline deserialization.
1375  spline m_Sx;
1376  spline m_Sy;
1377  Matrix m_SH;
1378  spline m_Sxinv;
1379  spline m_Syinv;
1380  Matrix m_SinvH;
1381 
1382  // Working data for old text format compatibility.
1383  rejection_data m_rejectLowData;
1384  rejection_data m_rejectHighData;
1385 
1386  void ParseRejectionMap( const XMLElement& );
1387  void SerializeRejectionMap( XMLElement* ) const;
1388 
1389  static void ParseSpline( spline&, const XMLElement& );
1390  static void SerializeSpline( XMLElement*, const spline& );
1391 
1392  static point_list ParsePoints( const XMLElement& );
1393  void SerializePoints( XMLElement*, const point_list& ) const;
1394 
1395  static weight_vector ParseDistortionWeights( const XMLElement& );
1396  void SerializeDistortionWeights( XMLElement*, const weight_vector& ) const;
1397 
1398  static ByteArray ParseMaybeCompressedData( const XMLElement& );
1399  void SerializeMaybeCompressedData( XMLElement* root,
1400  const void* data, size_type size, size_type itemSize = 1 ) const;
1401 
1407  class PlainTextDecoder
1408  {
1409  public:
1410 
1411  PlainTextDecoder( DrizzleData* data, bool ignoreIntegrationData )
1412  : m_data( data )
1413  , m_ignoreIntegrationData( ignoreIntegrationData )
1414  {
1415  }
1416 
1417  virtual ~PlainTextDecoder()
1418  {
1419  }
1420 
1421  void Decode( IsoString&, size_type start = 0, size_type end = 0 );
1422 
1423  protected:
1424 
1425  PlainTextDecoder() = default;
1426 
1427  private:
1428 
1429  DrizzleData* m_data = nullptr;
1430  bool m_ignoreIntegrationData = false;
1431 
1432  virtual void ProcessBlock( IsoString&, const IsoString&, size_type, size_type );
1433 
1434  static rejection_coordinates ParseRejectionCoordinates( IsoString&, size_type, size_type );
1435  static rejection_data ParseRejectionData( IsoString&, size_type, size_type );
1436  static spline ParseSurfaceSpline( IsoString&, size_type, size_type );
1437  };
1438 
1439  class PlainTextSplineDecoder : public PlainTextDecoder
1440  {
1441  public:
1442 
1443  PlainTextSplineDecoder( spline& S )
1444  : m_S( S )
1445  {
1446  }
1447 
1448  private:
1449 
1450  spline& m_S;
1451 
1452  void ProcessBlock( IsoString&, const IsoString&, size_type, size_type ) override;
1453  };
1454 };
1455 
1456 // ----------------------------------------------------------------------------
1457 
1458 } // pcl
1459 
1460 #endif // __PCL_DrizzleData_h
1461 
1462 // ----------------------------------------------------------------------------
1463 // EOF pcl/DrizzleData.h - Released 2024-05-07T15:27:32Z
Drizzle integration data parser and generator.
Definition: DrizzleData.h:143
XMLDocument * Serialize() const
bool HasImageWeightsData() const
Definition: DrizzleData.h:1072
void Parse(const XMLElement &element, DrizzleParserOptions options=DrizzleParserOptions())
void SetPedestal(double p)
Definition: DrizzleData.h:1018
void SetAlignmentInverseSplines(const vector_spline &Sinv)
Definition: DrizzleData.h:595
void DisableCompression(bool disable=true)
Definition: DrizzleData.h:1309
DrizzleData(DrizzleData &&)=default
const DVector & Weight() const
Definition: DrizzleData.h:1034
void EnableCompression(bool enable=true)
Definition: DrizzleData.h:1299
void ClearIntegrationData()
const String & AlignmentTargetFilePath() const
Definition: DrizzleData.h:419
void SetReferenceDimensions(int width, int height)
Definition: DrizzleData.h:461
void SetSourceFilePath(const String &filePath)
Definition: DrizzleData.h:300
void Parse(const String &filePath, DrizzleParserOptions options=DrizzleParserOptions())
void SetCFASourceChannel(int channel)
Definition: DrizzleData.h:398
void SerializeToFile(const String &path) const
DrizzleData(const String &filePath, DrizzleParserOptions options=DrizzleParserOptions())
Definition: DrizzleData.h:217
void SetLocation(const DVector &v)
Definition: DrizzleData.h:743
const DVector & ReferenceLocation() const
Definition: DrizzleData.h:762
void SetAlignmentMatrix(const Matrix &H)
Definition: DrizzleData.h:522
const vector_spline & AlignmentSplines() const
Definition: DrizzleData.h:546
const MultiVector & AdaptiveNormalizationLocationVectors() const
Definition: DrizzleData.h:868
DrizzleData()=default
void SetAlignmentSplines(const vector_spline &S)
Definition: DrizzleData.h:558
bool HasAlignmentSplines() const
Definition: DrizzleData.h:570
int NumberOfChannels() const
Definition: DrizzleData.h:471
const UI64Vector & RejectionHighCount() const
Definition: DrizzleData.h:1104
int CFASourceChannel() const
Definition: DrizzleData.h:382
void SetRejectionMap(const UInt8Image &map)
Definition: DrizzleData.h:1181
const String & Metadata() const
Definition: DrizzleData.h:701
void SetAdaptiveNormalizationZeroOffsetVectors(const MultiVector &mLow, const MultiVector &mHigh)
Definition: DrizzleData.h:982
DrizzleData(const DrizzleData &)=default
void SetCFASourceFilePath(const String &filePath)
Definition: DrizzleData.h:326
const point_list & AdaptiveNormalizationCoordinates() const
Definition: DrizzleData.h:836
void SetCFASourcePattern(const String &cfaPattern)
Definition: DrizzleData.h:356
bool HasAlignmentMatrix() const
Definition: DrizzleData.h:533
void SetAdaptiveNormalizationCoordinates(const point_list &points)
Definition: DrizzleData.h:848
void SetScale(const DVector &v)
Definition: DrizzleData.h:820
const String & CFASourcePattern() const
Definition: DrizzleData.h:342
const String & SourceFilePath() const
Definition: DrizzleData.h:289
bool IsCompressionEnabled() const
Definition: DrizzleData.h:1289
void GetLocalDistortionModel(point_list &P1, point_list &D2, point_list &P2, point_list &D1, weight_vector &W, int &order, float &regularization, bool &extrapolate)
Definition: DrizzleData.h:664
void SetReferenceLocation(const DVector &v)
Definition: DrizzleData.h:775
void SetWeight(const DVector &v)
Definition: DrizzleData.h:1050
double Pedestal() const
Definition: DrizzleData.h:1008
bool HasLocalDistortionModel() const
Definition: DrizzleData.h:689
const vector_spline & AlignmentInverseSplines() const
Definition: DrizzleData.h:583
bool HasAlignmentInverseSplines() const
Definition: DrizzleData.h:607
bool HasIntegrationData() const
Definition: DrizzleData.h:1061
bool HasAdaptiveNormalizationData() const
Definition: DrizzleData.h:994
const UI64Vector & RejectionLowCount() const
Definition: DrizzleData.h:1088
const Matrix & AlignmentMatrix() const
Definition: DrizzleData.h:511
const DVector & Scale() const
Definition: DrizzleData.h:804
void Parse(const XMLDocument &xml, DrizzleParserOptions options=DrizzleParserOptions())
void SetAlignmentTargetFilePath(const String &filePath)
Definition: DrizzleData.h:430
void SetAdaptiveNormalizationScaleVectors(const MultiVector &sLow, const MultiVector &sHigh)
Definition: DrizzleData.h:946
bool HasRejectionData() const
Definition: DrizzleData.h:1190
const UInt8Image & RejectionMap() const
Definition: DrizzleData.h:1156
void SetAlignmentOrigin(const DPoint &p0)
Definition: DrizzleData.h:499
const DVector & Location() const
Definition: DrizzleData.h:730
bool IsRejected(const Point &position, int channel=0) const
Definition: DrizzleData.h:1167
int ReferenceWidth() const
Definition: DrizzleData.h:440
DrizzleData(const XMLElement &element, DrizzleParserOptions options=DrizzleParserOptions())
Definition: DrizzleData.h:257
const DPoint & AlignmentOrigin() const
Definition: DrizzleData.h:483
DrizzleData(const XMLDocument &xml, DrizzleParserOptions options=DrizzleParserOptions())
Definition: DrizzleData.h:238
void GetAdaptiveNormalizationZeroOffsetVectors(MultiVector &mLow, MultiVector &mHigh) const
Definition: DrizzleData.h:969
const String & CFASourceFilePath() const
Definition: DrizzleData.h:315
TimePoint CreationTime() const
Definition: DrizzleData.h:1199
void GetAdaptiveNormalizationScaleVectors(MultiVector &sLow, MultiVector &sHigh) const
Definition: DrizzleData.h:933
virtual ~DrizzleData()
Definition: DrizzleData.h:265
int ReferenceHeight() const
Definition: DrizzleData.h:450
void SetAdaptiveNormalizationLocationVectors(const MultiVector &m)
Definition: DrizzleData.h:881
void SetMetadata(const String &metadata)
Definition: DrizzleData.h:712
A collection of Drizzle data parsing options.
static String FullPath(const String &path)
A type-safe collection of enumerated flags.
Definition: Flags.h:85
Generic dynamic matrix of arbitrary dimensions.
Definition: Matrix.h:123
Generic array of vectors.
Definition: MultiVector.h:101
A generic point in the two-dimensional space.
Definition: Point.h:100
Generic vector of arbitrary length.
Definition: Vector.h:107
Vector surface spline interpolation/approximation in two dimensions.
Unicode (UTF-16) string.
Definition: String.h:8113
An instant in any timescale.
Definition: TimePoint.h:103
XML document parsing and generation
Definition: XML.h:2641
XML element
Definition: XML.h:1162
#define int32_max
Definition: Defs.h:866
size_t size_type
Definition: Defs.h:609
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
Definition: Utility.h:190
PCL root namespace.
Definition: AbstractImage.h:77