PCL
DrizzleData.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.8.5
6 // ----------------------------------------------------------------------------
7 // pcl/DrizzleData.h - Released 2024-12-28T16:53:48Z
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 
175  DrizzleData() = default;
176 
180  DrizzleData( const DrizzleData& ) = default;
181 
185  DrizzleData( DrizzleData&& ) = default;
186 
207  {
208  Parse( filePath, options );
209  }
210 
228  {
229  Parse( xml, options );
230  }
231 
247  {
248  Parse( element, options );
249  }
250 
254  virtual ~DrizzleData()
255  {
256  }
257 
261  DrizzleData& operator =( const DrizzleData& ) = default;
262 
266  DrizzleData& operator =( DrizzleData&& ) = default;
267 
278  const String& SourceFilePath() const
279  {
280  return m_sourceFilePath;
281  }
282 
289  void SetSourceFilePath( const String& filePath )
290  {
291  m_sourceFilePath = File::FullPath( filePath );
292  }
293 
304  const String& CFASourceFilePath() const
305  {
306  return m_cfaSourceFilePath;
307  }
308 
315  void SetCFASourceFilePath( const String& filePath )
316  {
317  m_cfaSourceFilePath = File::FullPath( filePath );
318  }
319 
331  const String& CFASourcePattern() const
332  {
333  return m_cfaSourcePattern;
334  }
335 
345  void SetCFASourcePattern( const String& cfaPattern )
346  {
347  m_cfaSourcePattern = cfaPattern;
348  }
349 
371  int CFASourceChannel() const
372  {
373  return m_cfaSourceChannel;
374  }
375 
387  void SetCFASourceChannel( int channel )
388  {
389  m_cfaSourceChannel = Range( channel, -1, int( int32_max ) );
390  }
391 
409  {
410  return m_alignTargetFilePath;
411  }
412 
419  void SetAlignmentTargetFilePath( const String& filePath )
420  {
421  m_alignTargetFilePath = File::FullPath( filePath );
422  }
423 
429  int ReferenceWidth() const
430  {
431  return m_referenceWidth;
432  }
433 
439  int ReferenceHeight() const
440  {
441  return m_referenceHeight;
442  }
443 
450  void SetReferenceDimensions( int width, int height )
451  {
452  m_referenceWidth = width;
453  m_referenceHeight = height;
454  }
455 
460  int NumberOfChannels() const
461  {
462  return m_location.Length();
463  }
464 
472  const DPoint& AlignmentOrigin() const
473  {
474  return m_alignmentOrigin;
475  }
476 
488  void SetAlignmentOrigin( const DPoint& p0 )
489  {
490  m_alignmentOrigin = p0;
491  }
492 
500  const Matrix& AlignmentMatrix() const
501  {
502  return m_H;
503  }
504 
511  void SetAlignmentMatrix( const Matrix& H )
512  {
513  m_H = H;
514  }
515 
522  bool HasAlignmentMatrix() const
523  {
524  return !m_H.IsEmpty();
525  }
526 
536  {
537  return m_S;
538  }
539 
548  {
549  m_S = S;
550  }
551 
559  bool HasAlignmentSplines() const
560  {
561  return m_S.IsValid();
562  }
563 
573  {
574  return m_Sinv;
575  }
576 
585  {
586  m_Sinv = Sinv;
587  }
588 
597  {
598  return m_Sinv.IsValid();
599  }
600 
654  point_list& P2, point_list& D1,
655  weight_vector& W,
656  int& order, float& regularization, bool& extrapolate )
657  {
658  P1 = m_LP1;
659  D2 = m_LD2;
660  P2 = m_LP2;
661  D1 = m_LD1;
662  W = m_LW;
663  order = m_localDistortionOrder;
664  regularization = m_localDistortionRegularization;
665  extrapolate = m_localDistortionExtrapolation;
666  }
667 
679  {
680  return !m_LP1.IsEmpty();
681  }
682 
690  const String& Metadata() const
691  {
692  return m_metadata;
693  }
694 
701  void SetMetadata( const String& metadata )
702  {
703  m_metadata = metadata.Trimmed();
704  }
705 
719  const DVector& Location() const
720  {
721  return m_location;
722  }
723 
732  void SetLocation( const DVector& v )
733  {
734  m_location = v;
735  }
736 
751  const DVector& ReferenceLocation() const
752  {
753  return m_referenceLocation;
754  }
755 
764  void SetReferenceLocation( const DVector& v )
765  {
766  m_referenceLocation = v;
767  }
768 
793  const DVector& Scale() const
794  {
795  if ( !m_scale.IsEmpty() )
796  return m_scale;
797  if ( m_unitScale.IsEmpty() )
798  m_unitScale = DVector( 1.0, NumberOfChannels() );
799  return m_unitScale;
800  }
801 
809  void SetScale( const DVector& v )
810  {
811  m_scale = v;
812  }
813 
826  {
827  return m_adaptiveCoordinates;
828  }
829 
838  {
839  m_adaptiveCoordinates = points;
840  }
841 
858  {
859  return m_adaptiveLocation;
860  }
861 
871  {
872  m_adaptiveLocation = m;
873  }
874 
923  {
924  sLow = m_adaptiveScaleLow;
925  sHigh = m_adaptiveScaleHigh;
926  }
927 
936  {
937  m_adaptiveScaleLow = sLow;
938  m_adaptiveScaleHigh = sHigh;
939  }
940 
959  {
960  mLow = m_adaptiveZeroOffsetLow;
961  mHigh = m_adaptiveZeroOffsetHigh;
962  }
963 
972  {
973  m_adaptiveZeroOffsetLow = mLow;
974  m_adaptiveZeroOffsetHigh = mHigh;
975  }
976 
984  {
985  return !m_adaptiveCoordinates.IsEmpty() &&
986  !m_adaptiveLocation.IsEmpty() &&
987  !m_adaptiveScaleLow.IsEmpty() &&
988  !m_adaptiveScaleHigh.IsEmpty() &&
989  !m_adaptiveZeroOffsetLow.IsEmpty() &&
990  !m_adaptiveZeroOffsetHigh.IsEmpty();
991  }
992 
997  double Pedestal() const
998  {
999  return m_pedestal;
1000  }
1001 
1007  void SetPedestal( double p )
1008  {
1009  m_pedestal = Range( p, 0.0, 1.0 );
1010  }
1011 
1023  const DVector& Weight() const
1024  {
1025  if ( !m_weight.IsEmpty() )
1026  return m_weight;
1027  if ( m_unitWeight.IsEmpty() )
1028  m_unitWeight = DVector( 1.0, NumberOfChannels() );
1029  return m_unitWeight;
1030  }
1031 
1039  void SetWeight( const DVector& v )
1040  {
1041  m_weight = v;
1042  }
1043 
1050  bool HasIntegrationData() const
1051  {
1052  return !m_location.IsEmpty();
1053  }
1054 
1061  bool HasImageWeightsData() const
1062  {
1063  return !m_weight.IsEmpty();
1064  }
1065 
1078  {
1079  return m_rejectionLowCount;
1080  }
1081 
1094  {
1095  return m_rejectionHighCount;
1096  }
1097 
1145  const UInt8Image& RejectionMap() const
1146  {
1147  return m_rejectionMap;
1148  }
1149 
1156  bool IsRejected( const Point& position, int channel = 0 ) const
1157  {
1158  return m_rejectionMap.Includes( position )
1159  && m_rejectionMap.IsValidChannelIndex( channel )
1160  && (m_rejectionMap( position, channel ) & 0x3F) != 0;
1161  }
1162 
1170  void SetRejectionMap( const UInt8Image& map )
1171  {
1172  m_rejectionMap = map;
1173  }
1174 
1179  bool HasRejectionData() const
1180  {
1181  return !m_rejectionMap.IsEmpty();
1182  }
1183 
1189  {
1190  return m_creationTime;
1191  }
1192 
1197  void Clear();
1198 
1206 
1227  void Parse( const String& filePath, DrizzleParserOptions options = DrizzleParserOptions() );
1228 
1248 
1266  void Parse( const XMLElement& element, DrizzleParserOptions options = DrizzleParserOptions() );
1267 
1279  {
1280  return m_compressionEnabled;
1281  }
1282 
1288  void EnableCompression( bool enable = true )
1289  {
1290  m_compressionEnabled = enable;
1291  }
1292 
1298  void DisableCompression( bool disable = true )
1299  {
1300  EnableCompression( !disable );
1301  }
1302 
1311 
1320  void SerializeToFile( const String& path ) const;
1321 
1322 private:
1323 
1324  String m_sourceFilePath;
1325  String m_cfaSourceFilePath;
1326  String m_cfaSourcePattern;
1327  int m_cfaSourceChannel = -1;
1328  String m_alignTargetFilePath;
1329  int m_referenceWidth = -1;
1330  int m_referenceHeight = -1;
1331  DPoint m_alignmentOrigin = 0.5;
1332  Matrix m_H;
1333  vector_spline m_S;
1334  vector_spline m_Sinv;
1335  point_list m_LP1; // D* = deprecated
1336  point_list m_LD2; // D*
1337  point_list m_LP2; // D*
1338  point_list m_LD1; // D*
1339  weight_vector m_LW; // D*
1340  int m_localDistortionOrder = 2; // D*
1341  float m_localDistortionRegularization = 0.01F; // D*
1342  bool m_localDistortionExtrapolation = true; // D*
1343  String m_metadata;
1344  double m_pedestal = 0.0;
1345  Vector m_location;
1346  Vector m_referenceLocation;
1347  Vector m_scale;
1348  mutable Vector m_unitScale;
1349  Vector m_weight;
1350  mutable Vector m_unitWeight;
1351  point_list m_adaptiveCoordinates;
1352  MultiVector m_adaptiveLocation;
1353  MultiVector m_adaptiveScaleLow;
1354  MultiVector m_adaptiveScaleHigh;
1355  MultiVector m_adaptiveZeroOffsetLow;
1356  MultiVector m_adaptiveZeroOffsetHigh;
1357  UI64Vector m_rejectionLowCount;
1358  UI64Vector m_rejectionHighCount;
1359  UInt8Image m_rejectionMap;
1360  TimePoint m_creationTime;
1361  bool m_compressionEnabled = true;
1362 
1363  void ParseRejectionMap( const XMLElement& );
1364  void SerializeRejectionMap( XMLElement* ) const;
1365 
1366  static void ParseSpline( spline&, const XMLElement& );
1367  void SerializeSpline( XMLElement*, const spline& ) const;
1368 
1369  static point_list ParsePoints( const XMLElement& );
1370  void SerializePoints( XMLElement*, const point_list& ) const;
1371 
1372  static weight_vector ParseDistortionWeights( const XMLElement& );
1373  void SerializeDistortionWeights( XMLElement*, const weight_vector& ) const;
1374 
1375  static ByteArray ParseMaybeCompressedData( const XMLElement& );
1376  void SerializeMaybeCompressedData( XMLElement* root,
1377  const void* data, size_type size, size_type itemSize = 1 ) const;
1378 
1379  template <typename T>
1380  static GenericVector<T> ParseMaybeCompressedVector( const XMLElement&, size_type = 0, size_type = ~size_type( 0 ) );
1381 
1382  template <typename T>
1383  void SerializeMaybeCompressedVector( XMLElement* root, const GenericVector<T> v ) const
1384  {
1385  SerializeMaybeCompressedData( root, v.Begin(), v.Size(), sizeof( typename GenericVector<T>::item_type ) );
1386  }
1387 
1393  class PlainTextDecoder
1394  {
1395  public:
1396 
1401  using rejection_coordinates = Array<Point>;
1402 
1406  using rejection_data = Array<rejection_coordinates>;
1407 
1408  PlainTextDecoder( DrizzleData* data, bool ignoreIntegrationData )
1409  : m_data( data )
1410  , m_ignoreIntegrationData( ignoreIntegrationData )
1411  {
1412  }
1413 
1414  virtual ~PlainTextDecoder()
1415  {
1416  }
1417 
1418  void Decode( IsoString&, size_type start = 0, size_type end = 0 );
1419 
1420  protected:
1421 
1422  PlainTextDecoder() = default;
1423 
1424  private:
1425 
1426  DrizzleData* m_data = nullptr;
1427  bool m_ignoreIntegrationData = false;
1428 
1429  virtual void ProcessBlock( IsoString&, const IsoString&, size_type, size_type );
1430 
1431  static rejection_coordinates ParseRejectionCoordinates( IsoString&, size_type, size_type );
1432  static rejection_data ParseRejectionData( IsoString&, size_type, size_type );
1433  static spline ParseSurfaceSpline( IsoString&, size_type, size_type );
1434  };
1435 
1436  class PlainTextSplineDecoder : public PlainTextDecoder
1437  {
1438  public:
1439 
1440  PlainTextSplineDecoder( spline& S )
1441  : m_S( S )
1442  {
1443  }
1444 
1445  private:
1446 
1447  spline& m_S;
1448 
1449  void ProcessBlock( IsoString&, const IsoString&, size_type, size_type ) override;
1450  };
1451 
1452  friend class DrizzleDataPrivate;
1453 };
1454 
1455 // ----------------------------------------------------------------------------
1456 
1457 } // pcl
1458 
1459 #endif // __PCL_DrizzleData_h
1460 
1461 // ----------------------------------------------------------------------------
1462 // EOF pcl/DrizzleData.h - Released 2024-12-28T16:53:48Z
Drizzle integration data parser and generator.
Definition: DrizzleData.h:143
XMLDocument * Serialize() const
bool HasImageWeightsData() const
Definition: DrizzleData.h:1061
void Parse(const XMLElement &element, DrizzleParserOptions options=DrizzleParserOptions())
void SetPedestal(double p)
Definition: DrizzleData.h:1007
void SetAlignmentInverseSplines(const vector_spline &Sinv)
Definition: DrizzleData.h:584
void DisableCompression(bool disable=true)
Definition: DrizzleData.h:1298
DrizzleData(DrizzleData &&)=default
const DVector & Weight() const
Definition: DrizzleData.h:1023
void EnableCompression(bool enable=true)
Definition: DrizzleData.h:1288
void ClearIntegrationData()
const String & AlignmentTargetFilePath() const
Definition: DrizzleData.h:408
void SetReferenceDimensions(int width, int height)
Definition: DrizzleData.h:450
void SetSourceFilePath(const String &filePath)
Definition: DrizzleData.h:289
void Parse(const String &filePath, DrizzleParserOptions options=DrizzleParserOptions())
void SetCFASourceChannel(int channel)
Definition: DrizzleData.h:387
void SerializeToFile(const String &path) const
DrizzleData(const String &filePath, DrizzleParserOptions options=DrizzleParserOptions())
Definition: DrizzleData.h:206
void SetLocation(const DVector &v)
Definition: DrizzleData.h:732
const DVector & ReferenceLocation() const
Definition: DrizzleData.h:751
void SetAlignmentMatrix(const Matrix &H)
Definition: DrizzleData.h:511
const vector_spline & AlignmentSplines() const
Definition: DrizzleData.h:535
const MultiVector & AdaptiveNormalizationLocationVectors() const
Definition: DrizzleData.h:857
DrizzleData()=default
void SetAlignmentSplines(const vector_spline &S)
Definition: DrizzleData.h:547
bool HasAlignmentSplines() const
Definition: DrizzleData.h:559
int NumberOfChannels() const
Definition: DrizzleData.h:460
const UI64Vector & RejectionHighCount() const
Definition: DrizzleData.h:1093
int CFASourceChannel() const
Definition: DrizzleData.h:371
void SetRejectionMap(const UInt8Image &map)
Definition: DrizzleData.h:1170
const String & Metadata() const
Definition: DrizzleData.h:690
void SetAdaptiveNormalizationZeroOffsetVectors(const MultiVector &mLow, const MultiVector &mHigh)
Definition: DrizzleData.h:971
DrizzleData(const DrizzleData &)=default
void SetCFASourceFilePath(const String &filePath)
Definition: DrizzleData.h:315
const point_list & AdaptiveNormalizationCoordinates() const
Definition: DrizzleData.h:825
void SetCFASourcePattern(const String &cfaPattern)
Definition: DrizzleData.h:345
bool HasAlignmentMatrix() const
Definition: DrizzleData.h:522
void SetAdaptiveNormalizationCoordinates(const point_list &points)
Definition: DrizzleData.h:837
void SetScale(const DVector &v)
Definition: DrizzleData.h:809
const String & CFASourcePattern() const
Definition: DrizzleData.h:331
const String & SourceFilePath() const
Definition: DrizzleData.h:278
bool IsCompressionEnabled() const
Definition: DrizzleData.h:1278
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:653
void SetReferenceLocation(const DVector &v)
Definition: DrizzleData.h:764
void SetWeight(const DVector &v)
Definition: DrizzleData.h:1039
double Pedestal() const
Definition: DrizzleData.h:997
bool HasLocalDistortionModel() const
Definition: DrizzleData.h:678
const vector_spline & AlignmentInverseSplines() const
Definition: DrizzleData.h:572
bool HasAlignmentInverseSplines() const
Definition: DrizzleData.h:596
bool HasIntegrationData() const
Definition: DrizzleData.h:1050
bool HasAdaptiveNormalizationData() const
Definition: DrizzleData.h:983
const UI64Vector & RejectionLowCount() const
Definition: DrizzleData.h:1077
const Matrix & AlignmentMatrix() const
Definition: DrizzleData.h:500
const DVector & Scale() const
Definition: DrizzleData.h:793
void Parse(const XMLDocument &xml, DrizzleParserOptions options=DrizzleParserOptions())
void SetAlignmentTargetFilePath(const String &filePath)
Definition: DrizzleData.h:419
void SetAdaptiveNormalizationScaleVectors(const MultiVector &sLow, const MultiVector &sHigh)
Definition: DrizzleData.h:935
bool HasRejectionData() const
Definition: DrizzleData.h:1179
const UInt8Image & RejectionMap() const
Definition: DrizzleData.h:1145
void SetAlignmentOrigin(const DPoint &p0)
Definition: DrizzleData.h:488
const DVector & Location() const
Definition: DrizzleData.h:719
bool IsRejected(const Point &position, int channel=0) const
Definition: DrizzleData.h:1156
int ReferenceWidth() const
Definition: DrizzleData.h:429
DrizzleData(const XMLElement &element, DrizzleParserOptions options=DrizzleParserOptions())
Definition: DrizzleData.h:246
const DPoint & AlignmentOrigin() const
Definition: DrizzleData.h:472
DrizzleData(const XMLDocument &xml, DrizzleParserOptions options=DrizzleParserOptions())
Definition: DrizzleData.h:227
void GetAdaptiveNormalizationZeroOffsetVectors(MultiVector &mLow, MultiVector &mHigh) const
Definition: DrizzleData.h:958
const String & CFASourceFilePath() const
Definition: DrizzleData.h:304
TimePoint CreationTime() const
Definition: DrizzleData.h:1188
void GetAdaptiveNormalizationScaleVectors(MultiVector &sLow, MultiVector &sHigh) const
Definition: DrizzleData.h:922
virtual ~DrizzleData()
Definition: DrizzleData.h:254
int ReferenceHeight() const
Definition: DrizzleData.h:439
void SetAdaptiveNormalizationLocationVectors(const MultiVector &m)
Definition: DrizzleData.h:870
void SetMetadata(const String &metadata)
Definition: DrizzleData.h:701
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
typename container_type::item_type item_type
Definition: Vector.h:116
size_type Size() const noexcept
Definition: Vector.h:1811
iterator Begin()
Definition: Vector.h:1918
Vector surface spline interpolation/approximation in two dimensions.
Unicode (UTF-16) string.
Definition: String.h:8146
An instant in any timescale.
Definition: TimePoint.h:103
XML document parsing and generation
Definition: XML.h:2745
XML element
Definition: XML.h:1177
#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